<?
if(isset($_GET['zags']))
{
$usk=$ank;
if(empty($usk['nick'])){
$_SESSION['msg']='Игрок не найден.';
header("Location:/communication-$usk[id]");
}
elseif($usk['pol']==$ku['pol']){
$_SESSION['msg']='Однополые браки строго запрещены.';
header("Location:/communication-$usk[id]");
}
elseif($ku['pol']==0){
$_SESSION['msg']='Заявка принимается только от жениха.';
header("Location:/communication-$usk[id]");
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zags` WHERE `zenih` = '$ku[id]' AND `status`='0'"),0)!=0)
{
$_SESSION['msg']='Вы уже сделали предложение.';
header("Location:/communication-$usk[id]");
}
elseif(!empty($ku['brak']))
{
$_SESSION['msg']='Вы уже состоите в браке.';
header("Location:/communication-$usk[id]");
}
elseif($ku['time_zags']>$time)
{
$_SESSION['msg']='Вы сможете сделать предложение через '.time_left($ku['time_zags']-$time).'';
header("Location:/communication-$usk[id]");
}
elseif(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zags` WHERE `nevesta` = '$usk[id]' AND `status`='0'"),0)!=0)
{
$_SESSION['msg']='Этому игроку уже зделали заявку';
header("Location:/communication-$usk[id]");
}
elseif(!empty($usk['brak']))
{
$_SESSION['msg']='Этот игрок уже состоит в браке';
header("Location:/communication-$usk[id]");
}
elseif($ku['rubies']<100){
$_SESSION['no_rubies']=100-$ku['rubies'];
header("Location:/communication-$usk[id]");
}
elseif(isset($_GET['act'])){
mysql_query("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']-100)."' WHERE `id` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_zags` SET `zenih` = '$ku[id]', `nevesta` = '$usk[id]', `time`='".(time())."'");
$timee=(3600*24);
mysql_query("UPDATE `kolhoz_user` SET `time_zags` = '".($ku['time_zags']>$time?"".($ku['time_zags']+$timee)."":"".($time+$timee)."")."' WHERE `id` = '$ku[id]'");
$_SESSION['msg']='Вы сделали предложение девушке '.$usk['nick'].'. В случае отказа, вы сможете вернуть 80 рубинов, забрав заявление из ЗАГСа.';
header("Location:/communication-$usk[id]");
}else{
echo '<div class="event"><h1>Подтверждение</h1></div><div class="content"><ul class="block"><li>
Вы оплачиваете подачу заявления в ЗАГС:<br/>
Стоимость: <img alt="" width="16" height="16" src="images/icons/ruby.png"> 100 рубинов. <br/>
</li><li class="pt"><img alt="" width="16" height="16" src="images/icons/tick.png"> <a href="/communication-'.$usk['id'].'/zags/act"><span>Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="images/icons/cross.png"> <a href="/communication-'.$usk['id'].'"><span>
Нет, отказываюсь</span></a></li></ul>';
include_once 'inc/foot.php';exit;
}
}
elseif(isset($_GET['back_invite']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zags` WHERE `nevesta` = '$ank[id]' AND `status`='0' AND `zenih`='$ku[id]'"),0)!=0){
if(isset($_GET['act'])){
mysql_query("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']+80)."' WHERE `id` = '$ku[id]'");
mysql_query("DELETE FROM `kolhoz_zags` WHERE `zenih` = '$ku[id]' AND `status`='0' ");
$_SESSION['msg'] = 'Изменения приняты';
header("Location:/communication-$ank[id]");
}else{
echo '<div class="event"><h1>Подтверждение</h1></div><div class="content"><ul class="block"><li>
Вы действительно хотите забрать заявление?<br/>
На ваш счёт будет возвращено : <img alt="" width="16" height="16" src="images/icons/ruby.png"> 80 рубинов. <br/>
</li><li class="pt"><img alt="" width="16" height="16" src="images/icons/tick.png"> <a href="/communication-'.$ank['id'].'/back_invite/act"><span>Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="images/icons/cross.png"> <a href="/communication-'.$ank['id'].'"><span>
Нет, отказываюсь</span></a></li></ul>';
include_once 'inc/foot.php';exit;
}

}
if(isset($_GET['razvod']))
{
$usk=$ank;
if(isset($_GET['act'])){
if($usk['brak']==$ku['id'] AND $ku['brak']==$usk['id']){
if($ku['pol']==1){$name='zenih';$loname='nevesta';$mctabl='zkh';$umctabl='nkh';$text="Ваш муж $ku[nick] подал заявку на развод";}else{$name='nevesta';$loname='zenih';$mctabl='nkh';$umctabl='zkh';$text="Ваша жена $ku[nick] подала заявку на развод";}
$_SESSION['msg']='Заявка успешно принята!';

mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '$usk[id]', `id_kont` = '0', `msg` = '$text', `time` = '".time()."', `type` = 'to'") or die (mysql_error());
mysql_query("UPDATE `kolhoz_user` SET `brak` = '' WHERE `id` = '$ku[id]' OR `id` = '$usk[id]'");

$uctu=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective_user` WHERE `id_user` = '$usk[id]'"));
if(empty($mc['id']))$mc['id']=0;
if(empty($uctu['id_collective']))$uctu['id_collective']=0;

mysql_query("INSERT INTO `kolhoz_zags` SET `$name` = '$ku[id]', `$loname` = '$usk[id]', `time`='$time', `status`='2',`$mctabl`='$mc[id]',`$umctabl`='$uctu[id_collective]'");
header("Location:/communication-$usk[id]");
}else{
$_SESSION['msg']='Произошла ошибка';
header("Location:/communication-$usk[id]");
}
}else{
echo '<div class="event"><h1>Подтверждение</h1></div><div class="content"><ul class="block"><li>
<span class="title">Вы действительно подтверждаете развод?</span></li><li class="pt"><img alt="" width="16" height="16" src="images/icons/tick.png"> <a href="/communication-'.$usk['id'].'/razvod/act"><span>Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="images/icons/cross.png"> <a href="/communication-'.$usk['id'].'"><span>
Нет, отказываюсь</span></a></li></ul>';}
include_once 'inc/foot.php';exit;
}
if(isset($_GET['friend_collective']) && ($mcu['status']==1))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_friends_collective` WHERE `id_user` = '$ank[id]' AND `collective` = '$mc[id]'"),0)==0)
{
mysql_query("INSERT INTO `kolhoz_friends_collective` SET `id_user` = '$ank[id]', `collective` = '$mc[id]'");
}
else mysql_query("DELETE FROM `kolhoz_friends_collective` WHERE `id_user` = '$ank[id]' AND `collective` = '$mc[id]'");
echo mysql_error();
header("Location:/communication-$ank[id]");
}


if(isset($_GET['friend']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_friends` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]'"),0)==0)
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_blacklist` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]'"),0)!=0)mysql_query("DELETE FROM `kolhoz_blacklist` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]'");
mysql_query("INSERT INTO `kolhoz_friends` SET `id_user` = '$ku[id]', `id_ank` = '$ank[id]'");
//echo "INSERT INTO `kolhoz_friends` SET `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]'";
}
else mysql_query("DELETE FROM `kolhoz_friends` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]'");
echo mysql_error();
header("Location:/communication-$ank[id]");
}
elseif(isset($_GET['blacklist']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_blacklist` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]'"),0)==0)
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_friends` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]'"),0)!=0)mysql_query("DELETE FROM `kolhoz_friends` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]'");
mysql_query("INSERT INTO `kolhoz_blacklist` SET `id_user` = '$ku[id]', `id_ank` = '$ank[id]'");
}
else mysql_query("DELETE FROM `kolhoz_blacklist` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]'");
echo mysql_error();
}
echo "<div class='event'><h1>".($ank['id']==$ku['id']?"Общение":"<a href='/user/$ank[id]'>$anku[nick]</a> / Общение")."</h1></div>";
echo "<div class='content'><div class='block'><ul>";
if($ank['id']!=$ku['id'] && $mcu['status']==1)echo "<li><img alt='' width='16' height='16' src='images/icons/guild.png'> <a href='/communication-$ank[id]/friend_collective'><span>".(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_friends_collective` WHERE `id_user` = '$ank[id]' AND `collective` = '$mc[id]' LIMIT 1"),0)==0?"В друзья":"Из друзей")."</span></a></li>";

if($ank['id']!=$ku['id'])echo "<li><img alt='' width='16' height='16' src='images/icons/pencil.png'> <a href='/mail/new_msg-$ank[id]'>Написать</a></li>";
echo "<li><img alt='' width='16' height='16' src='images/icons/mail_filter_all.png'> <a href='/mail".($ank['id']!=$ku['id']?"/history-$ank[id]":null)."'>Переписка</a></li>";
if($ank['id']!=$ku['id'])echo "<li><img alt='' width='16' height='16' src='images/icons/money.png'> ".($ku['rating']>=$ank['rating']?"<a href='/perevod-$ank[id]'>":null)."Переслать монеты".($ku['rating']>=$ank['rating']?"</a>":null)."</li>";
if($ank['id']!=$ku['id'] && $ku['status']==3)echo "<li><img alt='' width='16' height='16' src='images/icons/ruby.png'> <a href='/perevod2-$ank[id]'>Переслать рубины</a></li>";
if($ank['id']!=$ku['id'])echo "<li><img alt='' width='16' height='16' src='images/icons/gift_plus.png'> <a href='/presents-$ank[id]/do'>Подарить</a></li>";
echo "<li><img alt='' width='16' height='16' src='images/icons/gift.png'> <a href='/presents-$ank[id]'>Подарки</a></li>";
if($ank['id']!=$ku['id'])echo "<li><img alt='' width='16' height='16' src='images/icons/favorite.png'> <a href='/communication-$ank[id]/friend'><span>".(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_friends` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]' LIMIT 1"),0)==0?"В друзья":"Из друзей")."</span></a></li>";

if($ank['id']!=$ku['id'])echo "<li><img alt='' width='16' height='16' src='images/icons/ignore.png'> <a href='/communication-$ank[id]/blacklist'><span>".(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_blacklist` WHERE `id_user` = '$ku[id]' AND `id_ank` = '$ank[id]' LIMIT 1"),0)==0?"В игнор":"Отменить игнор")."</span></a></li>";
if($ku['pol']==1)$name='zenih';else$name='nevesta';

if($ank['id']!=$ku['id'] AND $ank['pol']==0 AND $ku['pol']==1 AND isset($mc) AND empty($ank['brak']) AND mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zags` WHERE `nevesta` = '$ank[id]' AND `status`='0'"),0)==0)echo "<li><img alt='' width='16' height='16' src='images/icons/bank.png'> <a href='/communication-$ank[id]/zags'>Сделать предложение</a></li>";
if($ku['brak']==$ank['id'])echo "<li><img alt='' width='16' height='16' src='images/icons/bank.png'> <a href='/communication-$ank[id]/razvod'>Развестись</a></li>";
if($ku['pol']==1 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zags` WHERE `nevesta` = '$ank[id]' AND `status`='0'"),0)!=0)echo "<li><img alt='' width='16' height='16' src='images/icons/bank.png'> <a href='/communication-$ank[id]/back_invite'>Забрать заявление</a></li>";
echo "</ul></div>";
include_once 'inc/foot.php';
?>