<?
if(isset($_GET['food_all']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_garden` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'"),0)!=0 && $ku['fooder']>0)
{
$q=mysql_query("SELECT * FROM `kolhoz_garden` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'");
$orat=0;
if(empty($ku['last_soil_garden'])){header("Location:/mygarden/change_soil");exit;}
while($post=mysql_fetch_array($q))
{
$max_time=$time+($post['level']*(3600*4));
$pet=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_tree` WHERE `id` = '$post[id_pet]'"));
for($kp=1;$kp<=20;$kp++)
{
$mezh_time=$max_time-$post['time'];
if($mezh_time>=4*3600)
{
$korm_time=($post['time']<=$time?$time+(4*3600):$post['time']+(4*3600));
if($korm_time>$max_time)$korm_time=$max_time;
$post['time']=$korm_time;
$wh=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `id_plant`='$ku[last_soil_garden]'"));
if(isset($wh) && $wh['count']>=10)
{
$rat=$pet['rating'];
$rat_fooder_act=0;
$rat_sc_act=0;
$rat_dog_act=0;
$rat_drakon_act=0;
$rat_school_act=0;
$rat_vet_act=0;
$rat_lib_act=0;
$arena_rat=0;
if(isset($sc_act))$rat_sc_act=$rat*2;
if(isset($dog_type))$rat_dog_act=(($rat/100)*$dog_type);
if(isset($drakon_act))$rat_drakon_act=(($rat/100)*300);
if(isset($avtofooder_act))$rat_fooder_act=(($rat/100)*$avtofooder_act);
if(isset($school_act))$rat_school_act=$rat*2;
if($ku['arena_rating']>1000)$arena_rat=floor(($rat/100)*(($ku['arena_rating']-1000)/20));
if(isset($lib_act))$rat_lib_act=$rat/2;
if(isset($shmel_act))$rat_fooder_act=$rat_fooder_act*2;
$ratt=$rat_fooder_act+$rat_sc_act+$rat_drakon_act+$rat_school_act+$rat_vet_act+$rat_lib_act+$rat_dog_act+$arena_rat;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp) AND !isset($dexp3))$rat=$rat*2; elseif(isset($dexp3))$rat=$rat*3;

$orat=$orat+$rat;

$ku=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$ku[id]'"));

mysql_query("UPDATE `kolhoz_garden` SET `time` = '$korm_time' WHERE `id` = '$post[id]' LIMIT 1");
mysql_query("UPDATE `kolhoz_warehouse` SET `count` = '".($wh['count']-10)."' WHERE `id` = '$wh[id]' LIMIT 1");
}
else
{
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$orat)."' WHERE `id` = '$ku[id]'");
if($orat>0)$_SESSION['rating']=$orat;
update_mc($orat);
$_SESSION['err']=1;
header("Location:/mygarden/".passgen());
exit;
}
}
}
}
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$orat)."',`last_food`='$wh[id_plant]' WHERE `id` = '$ku[id]'");
$_SESSION['rating']=$orat;
update_mc($orat);
header("Location:/mygarden/".passgen());
exit;
}
?>