<?


if(!isset($level['rating']) || $level['rating']<1)$level['rating']=1;
$exp=round($kr/($level['rating']/100));
echo'<div style="margin:0px;background-color:#'.$style.'"> 
<div class="expline" 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($ku['time']>7200 && $_SERVER['HTTP_HOST']=="vkolhoze.com")echo '</div><div class="block"><marquee behavior="scroll" direction="left"><span class="txt-md">Игра подвергается DDOS-атаке, воспользуйтесь резервным адресом <a href="http://188.120.239.246/">ссылка</a>.</span></marquee></div>';
   // $usering1=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `kissCam` = '1'"));
    //$usering2=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `kissCam` = '2'"));

///if($ku['kissCamOpen']<1)echo'<div class="hearts block txt-md"><center><span class="title">Kiss Cam (<a href="/?forum=3431">?</a>):</span><br> <img width="16" src="/pavelgrey/img/girl.png"> '.ncTwo($usering1['id']).' и  '.ncTwo($usering2['id']).' <img width="16" src="/pavelgrey/img/man.png"><br><a href="/?myfarm&kisscam">скрыть</a></div>';

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(isset($_GET['kisscam']))
//{

   // mysql_query("UPDATE `kolhoz_user` SET `kissCamOpen` = '1' WHERE `id` = '$ku[id]'");
    //header("location:$_SERVER[HTTP_REFERER]");
//}    
if($ku['new']==1)
{
echo "<div class='feedback'><div><img width='30' src='/images/newspaper48.png'> <a href='/?myfarm&news1'>Свежие новости</a><br><span class='txt-md title'>Спешите узнать обновления в игре!</sspan></div></div>";
if(isset($_GET['news1']))
{
    $news=mysql_fetch_array(mysql_query("SELECT * FROM `news` WHERE `id` = '1'"));

    mysql_query("UPDATE `kolhoz_user` SET `new` = '0' WHERE `id` = '$ku[id]'");
    header("location:$news[link]");
}

}
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=1000;$rkoef=0.9;}
if($ku['level']>=37 AND $ku['level']<=40){$mkoef=5000;$rkoef=1;}
if($ku['level']>=41 AND $ku['level']<=45){$mkoef=10000;$rkoef=1;}
if($ku['level']>=46 AND $ku['level']<=50){$mkoef=20000;$rkoef=1;}
if($ku['level']>=51 AND $ku['level']<=60){$mkoef=10000;$rkoef=1;}
if($ku['level']>=61 AND $ku['level']<=64){$mkoef=100000;$rkoef=1.4;}
if($ku['level']>=65 AND $ku['level']<=70){$mkoef=1000000;$rkoef=1.6;}
if($ku['level']>=71 AND $ku['level']<=2000){$mkoef=100000000;$rkoef=1.8;}
///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);
if($ku['geroi']==1)
{
    $timee=3600*24;
    mysql_query("UPDATE `kolhoz_user` SET `time_vip` = '".($ku['time_vip']>$time?"".($ku['time_vip']+$timee)."":"".($time+$timee)."")."' WHERE `id` = '$ku[id]'");
   $timee=3600*24;
    mysql_query("UPDATE `kolhoz_user` SET `money2x_time` = '".($ku['money2x_time']>$time?"".($ku['money2x_time']+$timee)."":"".($time+$timee)."")."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']+50000)."' WHERE `id` = '$ku[id]'");

            mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '$ku[id]', `id_kont` = '0', `msg` = 'Поздравляем! Вы выбраны Героем дня! 
            Вам подарки:
                - 50 000 рубинов
                - Двойной доход (1 день)
                - VIP-статус (1 день)
                Приятной игры!', `time` = '" . time() .
                "', `type` = 'to'") or die(mysql_error());
    
}
 if($ku['storona']==1)mysql_query("UPDATE `megabattle` SET `pauk_day` = `pauk_day` + '1' WHERE `id`='1'");
 if($ku['storona']==2)mysql_query("UPDATE `megabattle` SET `scorpion_day` = `scorpion_day` + '1' WHERE `id`='1'");    
        
if($ku['premium_time']>$time)
{
    $ratPremium=floor($ku['rating']/100);
    $textPremium='
    
    [color=yellow]Бонус за премиум карту: '.rating($ratPremium).' опыта[/color]';
    mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$ratPremium)."' WHERE `id` = '$ku[id]'");

}
   $wowrandom=rand(8,8);
if($wowrandom>=8)
{
    $wow=rand(1,4);
    if($wow==1)
    {
        $msql='gold';
    }
    if($wow==2)
        {
            $msql='green';
        }
    if($wow==3)
    {
        $msql='blue';
    }
    if($wow==4)
    {
        $msql='pink';
}
}
mysql_query("UPDATE  `kolhoz_user` SET `$msql` = `$msql` + '3'  WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `rollcall` = `rollcall` + '1', `money` = '".($ku['money']+$bons_money)."',`rubies` = '".($ku['rubies']+$bons_rubies)."' 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']="[li]Спасибо, что Вы играете в нашу игру.[/li]
[li]Вам подарок: [color=yellow][img]/pavelgrey/img/talents/small/".$msql.".png[/img] 3 [img]images/icons/money.png[/img] $bons_money [img]images/icons/ruby.png[/img] $bons_rubies [/color][/li]
[li]Заходите в игру каждый день и получайте подарки![/li]
$textPremium";
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>';


////
?>
