<?
if(isset($_GET['food_all']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'"),0)!=0 && $ku['fooder']>0)
{
$q=mysql_query("SELECT * FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'");
$orat=0;
if(empty($ku['last_food'])){header("Location:/mypetfarm/change_food");exit;}
while($post=mysql_fetch_array($q))
{
$max_time=$time+($post['level']*(3600*4));
$pet=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_pet` 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_food]'"));
if(isset($wh) && $wh['amount']>=3)
{
$rat=$pet['rating'];
$rat_fooder_act=0;
$rat_vet_act=0;
if($ku['vfactory']>0)$vfactory=($rat/100)*($ku['vfactory']*10); 
if(isset($fooder_act))$rat_fooder_act=(($rat/100)*$fooder_act);
if(isset($vet_act))$rat_vet_act=($rat/100)*$vet_ps_r;
if($ku['talent_2']>0)$talent2=(($rat/100)*($ku['talent_2']*10));

if(isset($shmel_act))$rat_fooder_act=$rat_fooder_act*2;
$rat=double_exp(base_exp($rat)+$talent2+$vfactory+$rat_fooder_act+$rat_vet_act);

$orat=$orat+$rat;

mysql_query("UPDATE `kolhoz_user` SET `kormer` = '".($ku['kormer']+1)."' WHERE `id` = '$ku[id]'");
$ku=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$ku[id]'"));


mysql_query("UPDATE `kolhoz_petground` SET `time` = '$korm_time' WHERE `id` = '$post[id]' LIMIT 1");
mysql_query("UPDATE `kolhoz_warehouse` SET `amount` = '".($wh['amount']-3)."' 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:/mypetfarm/".passgen());
exit;
}
}
}
}
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$orat)."' WHERE `id` = '$ku[id]'");
$_SESSION['rating']=$orat;
update_mc($orat);
header("Location:/mypetfarm/".passgen());
exit;
}
?>