<?
if($ku['theme']==2){$style="404040";}
if(empty($ku['theme']) or $ku['theme']==1){$style="114411";}

if($level['rating']<1)$level['rating']=1;
$exp=round($kr/($level['rating']/100));
echo'</div><div style="margin:0px;background-color:#'.$style.';border-radius:4px;"> 
<div class="expline1" style="width:'.$exp.'%;"></div></div>';

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>";
}
}
////////////ARENA INVITE
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_arena_invite` WHERE `id_user` = '$ku[id]'"),0)!=0)
{
$invite=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_arena_invite` WHERE `id_user` = '$ku[id]'"));
$cta=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_arena_batle` WHERE `id` = '$invite[id_arena]'"));
$who=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$invite[id_who]'"));
if($cta['status']==1)mysql_query("DELETE FROM `kolhoz_arena_invite` WHERE `id_arena` = '$invite[id_arena]'");
if(isset($_GET['invite_arena']) && $_GET['invite_arena']=='no')
{
mysql_query("DELETE FROM `kolhoz_arena_invite` WHERE `id` = '$invite[id]'");
}
elseif($cta['status']==0)
{
echo "<div class='feedback'><div><span>";
echo on_k($who['id']);
echo " <a class='' href='/user/$who[id]'>".nc($who['id'])."</a></span> приглашает Вас на арену! <br/>";
echo "<img width='16' height='16' src='images/icons/tick.png' alt='o'> <a href='/arena/bitva/id-$invite[id_arena]'>Принять приглашение</a><br/>";
echo "<img width='16' height='16' src='images/icons/delete.png' alt='o'> <a href='/myfarm/invite_arena-no'>Отказаться</a>";
echo "</div>\n
</div>";
}
}


if($ku['pol']==0 && empty($ku['brak']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zags` WHERE `status`='0' AND `nevesta` = '$ku[id]'"),0)!=0)
{
$invite=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_zags` WHERE `nevesta` = '$ku[id]' AND `status`='0'"));
$who=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$invite[zenih]'"));

if(isset($_GET['invite_zags']) && $_GET['invite_zags']=='yes')
{
$uctu=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective_user` WHERE `id_user` = '$who[id]'"));
if(empty($mc[id]))$mc['id']=0;
mysql_query("UPDATE `kolhoz_zags` SET `status`='1',`nkh`='$mc[id]',`zkh`='$uctu[id_collective]' WHERE `nevesta` = '$ku[id]' AND `status`='0'");
mysql_query("UPDATE `kolhoz_user` SET `brak` = '$ku[id]' WHERE `id` = '$who[id]'");
mysql_query("UPDATE `kolhoz_user` SET `brak` = '$who[id]' WHERE `id` = '$ku[id]'");

$text=''.$ku['nick'].' приняла ваше предложение. Администрация искренне поздравляет вас, теперь вы муж и жена.';
mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '$who[id]', `id_kont` = '0', `msg` = '$text', `time` = '$time', `type` = 'to'");
$utext = 'Администрация искренне поздравляет вас! Теперь вы муж и жена.';
mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '$ku[id]', `id_kont` = '0', `msg` = '$utext', `time` = '$time', `type` = 'to'");

header("Location:/myfarm");
}
elseif(isset($_GET['invite_zags']) && $_GET['invite_zags']=='no')
{
$text=''.$ku['nick'].' отказалась от вашего предложения, на ваш счет возвращено 80 рубинов.';
mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '$who[id]', `id_kont` = '0', `msg` = '$text', `time` = '$time', `type` = 'to'");
mysql_query("UPDATE `kolhoz_user` SET `rubies` = '".($who['rubies']+80)."' WHERE `id` = '$who[id]'");
mysql_query("DELETE FROM `kolhoz_zags` WHERE `nevesta` = '$ku[id]' AND `status`='0' ");
header("Location: /myfarm");
}
else
{
echo "<div class='feedback'><div><span>";

echo on_k($who['id']);
echo " <a class='' href='/user/$who[id]'>".nc($who['id'])."</a></span> предлагает вам заключить брак.<br/>";

echo "<img width='16' height='16' src='images/icons/tick.png' alt='*'> <a href='/myfarm/invite_zags-yes'>Согласиться</a><br/>";
echo "<img width='16' height='16' src='images/icons/delete.png' alt='*'> <a href='/myfarm/invite_zags-no'>Отказаться</a>";
echo "</div>\n
</div>";
}
}

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

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

if($ku['keytime']<=$time and $ku['level']>=20){
if($ku['darja_time']>$time){
$gtime=$ku['darja_time']-$time;
mysql_query("UPDATE `kolhoz_user` SET `darja_leave` = '$gtime',`darja_time` = '' WHERE `id` = '$ku[id]' LIMIT 1");
}
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;
}
}

//$ku['time_start']<=$time-86400 AND 
if($ku['time_start']<=$time-86400 AND date("j")!==$conf['present_day']){
if($ku['level']>=1 AND $ku['level']<=5){$mkoef=100;$rkoef=1;}
if($ku['level']>=6 AND $ku['level']<=11){$mkoef=500;$rkoef=0.7;}
if($ku['level']>=12 AND $ku['level']<=20){$mkoef=1000;$rkoef=0.7;}
if($ku['level']>=21 AND $ku['level']<=29){$mkoef=5000;$rkoef=0.8;}
if($ku['level']>=30 AND $ku['level']<=36){$mkoef=10000;$rkoef=0.9;}
if($ku['level']>=37 AND $ku['level']<=40){$mkoef=50000;$rkoef=1;}
if($ku['level']>=41 AND $ku['level']<=45){$mkoef=100000;$rkoef=1;}
if($ku['level']>=46 AND $ku['level']<=50){$mkoef=200000;$rkoef=1;}
if($ku['level']>=51 AND $ku['level']<=60){$mkoef=1000000;$rkoef=1;}
if($ku['level']>=61 AND $ku['level']<=70){$mkoef=10000000;$rkoef=1.4;}
///hidra
$timee=3600*1;
$ps=50;
if($ku['hydropinics_time']>$time)
{
$ps=$ku['hydropinics_type']+$ps;
if($ps>400)$ps=400;
}
///
if($conf['present_time']>=$time-93600)$present_bon=$conf['present_bon']+1; else $present_bon=$conf['present_bon']-(3*round(($time-$conf['present_time'])/86400));
if($present_bon<=0)$present_bon=0;
$bons_money=$ku['level']*$mkoef;
if($present_bon>=40)$present_bon=40;
$bons_rubies=round($ku['level']*$rkoef+$present_bon);

mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$bons_money)."',`rubies` = '".($ku['rubies']+$bons_rubies)."',`hydropinics_time` = '".($ku['hydropinics_time']>$time?"".($ku['hydropinics_time']+$timee)."":"".($time+$timee)."")."', `hydropinics_type` = '$ps', `botanik` = '".($ku['botanik']+floor($timee/3600))."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_setting` SET `present_day` = '".(date("j"))."',`present_time` = '$time',`present_bon` = 'present_bon'+'$present_bon' WHERE `id_user` = '$ku[id]'");
$_SESSION['msg']="Спасибо, что Вы играете в нашу игру.\n
Вам подарок: [img]images/icons/money.png[/img] $bons_money [img]images/icons/ruby.png[/img] $bons_rubies 
Монеты и рубины в подарок выдаются каждый день.
[img]images/icons/hydropinics.png[/img] Активирована гидропоника.";
header("Location:/myfarm/".passgen());
}
///Арена
if(!empty($conf['battle_arena']) AND mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_arena_batle` WHERE `id` = '$conf[battle_arena]' AND `status`='1'"),0)!=0 AND !isset($_GET['arena']))
echo '<div class="feedback">
Вы участвуете в бою на Арене.<br/>
<a href="/arena/list">Войти на Арену</a>
</div>';
////
?>
