<?
if(isset($_GET['myzavod']) && isset($_GET['obmen']) && intval($_GET['obmen'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zavod` WHERE `id` = '".intval($_GET['obmen'])."' AND `id_user` = '$ku[id]' AND `id_pet` != '0'"),0)!=0)
{
$zavod=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_zavod` WHERE `id` = '".intval($_GET['obmen'])."' AND `id_user` = '$ku[id]'"),0);
$zav=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_zav` WHERE `id` = '$zavod[id_pet]'"));
$max_time=$time+$zavod['level']*(3600*4);
$mezh_time=$max_time-$zavod['time'];
$nt=4*3600;
if($mezh_time>=$nt)
{
echo "<div class='event'><h1>Склад</h1></div>";
echo "<div class='content'><div class='block'><ul>";
if(isset($_GET['select']) && intval($_GET['select'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_warehouse` WHERE `id` = '".intval($_GET['select'])."' AND `id_user` = '$ku[id]'"),0)!=0)
{
$wh=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id` = '".intval($_GET['select'])."'"));
if($wh['count']>=3)
{

$rat=$zav['rating'];
$rat_obmener_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($obmener_act))$rat_obmener_act=(($rat/100)*$obmener_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_obmener_act=$rat_obmener_act*2;
$ratt=$rat_obmener_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;

$korm_time=($zavod['time']<$time?$time+(4*3600):$zavod['time']+(4*3600));
mysql_query("UPDATE `kolhoz_zavod` SET `time` = '$korm_time' WHERE `id` = '$zavod[id]' LIMIT 1");
mysql_query("UPDATE `kolhoz_warehouse` SET `count` = '".($wh['count']-3)."' WHERE `id` = '$wh[id]' LIMIT 1");
mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$rat)."' WHERE `id` = '$ku[id]'");
$_SESSION['rating']=$rat;

update_mc($rat);


header("Location:?myzavod&".passgen());
exit;
}
else echo "<div style='background-color:#114411;padding:4px;border:1px solid red'>Не хватает ".(3-$wh['count'])." шт.</div>";
}
$q=mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `arena` = '0'");
while($post=mysql_fetch_array($q))
{
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$post[id_plant]'"));
echo "<li><img width='16' height='16' src='images/icons/plate.png' alt='o'> <a href='?myzavod&obmen=$zavod[id]&select=$post[id]'>Обменять на шапки:</a> <span class='title'>".hsc($plant['name'])."</span> (<span>$post[count]</span> шт.)</li>";
}
echo "</ul></div>";
include_once 'inc/foot.php';
}
}
?>