<?

if(isset($_SESSION['harvest']))
{
harvest($_SESSION['harvest']);
unset($_SESSION['harvest']);
}
if(isset($_SESSION['harvest2']))
{
harvest2($_SESSION['harvest2']);
unset($_SESSION['harvest2']);
}
if(isset($_SESSION['rating']))
{
ratingg($_SESSION['rating']);
unset($_SESSION['rating']);
}
if($ku['umoney']!=0)
{
money($ku['umoney']);
}
if(isset($_SESSION['catchfish']))
{
catchfish($_SESSION['catchfish']);
unset($_SESSION['catchfish']);
}
if(isset($_SESSION['no_rubies']))
{
no_rubies($_SESSION['no_rubies']);
unset($_SESSION['no_rubies']);
}
if(isset($_SESSION['no_money']))
{
no_money($_SESSION['no_money']);
unset($_SESSION['no_money']);
}

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_mail` WHERE `id_user` = '$ku[id]' AND `read` = '0' AND `type`='to'"),0)!=0)
{
echo "<div class='feedback'><div>Новая почта <span class='title'>(<span>".mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_mail` WHERE `id_user` = '$ku[id]' AND `read` = '0'"),0)."</span>)</span><br><a href='mail/new'>Читать</a><br></div></div>";
}

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_gifts` WHERE `id_user` = '$ku[id]' AND `read` = '0'"),0)!=0)
{
echo "<div class='feedback'><div>У вас новый подарок<br><a href='?presents=$ku[id]'>Смотреть</a><br></div></div>";
}

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_collective_invite` WHERE `id_user` = '$ku[id]'"),0)!=0)
{
$invite=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective_invite` WHERE `id_user` = '$ku[id]'"));
$cti=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective` WHERE `id` = '$invite[id_collective]'"));
$who=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$invite[id_who]'"));
if(isset($_GET['invite_collective']) && $_GET['invite_collective']=='yes')
{
mysql_query("DELETE FROM `kolhoz_collective_invite` WHERE `id` = '$invite[id]'");
mysql_query("INSERT INTO `kolhoz_collective_user` SET `id_user` = '$ku[id]', `id_collective` = '$cti[id]', `time` = '$time', `status` = '7'");
mysql_query("INSERT INTO `kolhoz_collective_history` SET `id_user` = '$ku[id]', `id_who` = '$who[id]', `id_collective` = '$cti[id]', `time` = '$time', `type` = 'in', `dei` = 'who'");
header("Location:?collective=$cti[id]");
}
elseif(isset($_GET['invite_collective']) && $_GET['invite_collective']=='no')
{
mysql_query("DELETE FROM `kolhoz_collective_invite` WHERE `id` = '$invite[id]'");
}
else
{
echo "<div class='feedback'><div><span>";
echo on_k($who['id']);
echo " <a class='' href='?user=$who[id]'>".nc($who['id'])."</a></span> приглашает Вас в свой колхоз <a href='?collective=$cti[id]'><span>".hsc($cti['name'])."</span></a><br/>";
echo "<img width='16' height='16' src='images/icons/tick.png' alt='o'> <a href='?myfarm&invite_collective=yes'>Принять приглашение</a><br/>";
echo "<img width='16' height='16' src='images/icons/delete.png' alt='o'> <a href='?myfarm&invite_collective=no'>Отказаться</a>";
echo "</div>\n
</div>";
}
}

if($ku['pol']==1)$namez='zenih';else$namez='nevesta';
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zags` WHERE `$namez` = '$ku[id]' AND `status`='0' AND `avtor`!='$ku[id]'"),0)!=0)
{

if(isset($_GET['invite_zags']) && $_GET['invite_zags']=='yes')
{
mysql_query("UPDATE `kolhoz_zags` SET `status`='1' WHERE `$namez` = '$ku[id]'");
header("Location:?");
}
elseif(isset($_GET['invite_zags']) && $_GET['invite_zags']=='no')
{
mysql_query("UPDATE `kolhoz_zags` SET `status`='3' WHERE `$namez` = '$ku[id]'");
header("Location:?");
}
else
{
$in=mysql_query("SELECT * FROM `kolhoz_zags` WHERE `$namez` = '$ku[id]'");
WHILE($invite=mysql_fetch_array($in)){
if($namez=='zenih')$lol='nevesta';else$lol='zenih';
$who=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$invite[$lol]'"));
echo "<div class='feedback'><div><span>";
if($who['pol']==1)$sklo='сделал';else$sklo='сделала';
echo on_k($who['id']);
echo " <a class='' href='?user=$who[id]'>".nc($who['id'])."</a></span> $sklo вам предложение.<br/>";
$vrem=date("H:i",($invite['time'])-600);
echo "Если вы согласны, то в $vrem приходите в загс на свадьбу<br/>";
if($invite['time']-600<$time)echo'Вы опаздываете<br/>';
echo "<img width='16' height='16' src='images/icons/tick.png' alt='o'> <a href='?myfarm&invite_zags=yes'>Принять</a><br/>";
echo "<img width='16' height='16' src='images/icons/delete.png' alt='o'> <a href='?myfarm&invite_zags=no'>Отказаться</a>";
echo "</div>\n
</div>";}
}
}

if(isset($_SESSION['msg']))
{
msg_game($_SESSION['msg']);
unset($_SESSION['msg']);
}

if($ku['keytime']<=$time and $ku['level']>=20){
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_plant2` != '0'"),0)!=0){
$q=mysql_query("SELECT * FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_plant2` != '0'");
$ohv=0;
while($post=mysql_fetch_array($q))
{
$plant2=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$post[id_plant2]'"));

$count=$plant2['count'];
$count_harvester2_act=0;
$count_yastreb2_act=0;
$count_greenhouse_act=0;
if(isset($harvester2_act))$count_harvester2_act=floor(($count/100)*$harvester2_act);
if(isset($yastreb2_act))$count_yastreb2_act=(($count/100)*300);
if(isset($greenhouse_act))$count_greenhouse_act=(($count/100)*$greenhouse_ps);
$count=$count_harvester2_act+$count_yastreb2_act+$count+$count_greenhouse_act;
$count=floor($count);

if($pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_market` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '$plant2[id]' AND `arena` = '0'")))
{
mysql_query("UPDATE `kolhoz_market` SET `count` = '".($pw['count']+$count)."' WHERE `id` = '$pw[id]'");
}
else mysql_query("INSERT INTO `kolhoz_market` SET `id_plant2` = '$plant2[id]', `id_user`  = '$ku[id]', `count` = '$count', `arena` = '0'");
mysql_query("UPDATE `kolhoz_polka2` SET `id_plant2` = '0', `soil2` = '0', `cultivator2` = '0' WHERE `id` = '$post[id]' LIMIT 1");
$ohv=$ohv+$count;
}
$_SESSION['harvest2']=$ohv;
mysql_query("UPDATE `kolhoz_user` SET `sadovod` = '".($ku['sadovod']+$ohv)."' WHERE `id` = '$ku[id]'");
header("Location:?myfarm&".passgen());
exit;
}
}

?>