<?
if(isset($_GET['obmen_all']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zavod` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'"),0)!=0 && $ku['obmen']>0)
{
$q=mysql_query("SELECT * FROM `kolhoz_zavod` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'");
$orat=0;
while($post=mysql_fetch_array($q))
{
$max_time=$time+($post['level']*(3600*4));
$zav=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_zav` WHERE `id` = '$post[id_pet]'"));
for($kp=1;$kp<=20;$kp++)
{
$mezh_time=$max_time-$post['time'];
if($mezh_time>=4*3600)
{
$obmen_time=($post['time']<=$time?$time+(4*3600):$post['time']+(4*3600));
if($obmen_time>$max_time)$obmen_time=$max_time;
$post['time']=$obmen_time;
$wh=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND (`count` = '3' OR `count` > '3')"));
if(isset($wh) && $wh['count']>=3)
{
$rat=$zav['rating'];
$rat_obmen_act=0;
$rat_sc_act=0;
$rat_drakon_act=0;
$rat_school_act=0;
$rat_vet_act=0;
$rat_lib_act=0;
if(isset($sc_act))$rat_sc_act=$rat*2;
if(isset($drakon_act))$rat_drakon_act=(($rat/100)*300);
if(isset($obmen_act))$rat_obmen_act=(($rat/100)*$obmen_act);
if(isset($school_act))$rat_school_act=$rat*2;
if(isset($vet_act))$rat_vet_act=($rat/100)*$vet_ps_r;
if(isset($lib_act))$rat_lib_act=$rat/2;
if(isset($shmel_act))$rat_obmen_act=$rat_obmen_act*2;
$ratt=$rat_obmen_act+$rat_sc_act+$rat_drakon_act+$rat_school_act+$rat_vet_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;

$orat=$orat+$rat;

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


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