<?
if(isset($_GET['mytreefarm']) && isset($_GET['food']) && intval($_GET['food'])!=NULL && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_treeground` WHERE `id` = '".intval($_GET['food'])."' AND `id_user` = '$ku[id]' AND `id_pet` != '0'"),0)!=0)
{
$petground=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_treeground` WHERE `id` = '".intval($_GET['food'])."' AND `id_user` = '$ku[id]'")) or die (mysql_error());
$pet=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_tree` WHERE `id` = '$petground[id_pet]'"));
$max_time=$time+$petground['level']*(3600*4);
$mezh_time=$max_time-$petground['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_querll("SELECT COUNT(*) FROM `kolhoz_warehouse` WHERE `id` = '".intval($_GET['select'])."' AND `id_user` = '$ku[id]'"),0)!=0)
{
$wh=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_warehouse` WHERE `id` = '".intval($_GET['select'])."'"));
if($wh['count']>=3)
{

$rat=$pet['rating'];
$rat_fooder_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($vtr_act))$rat_sc_act=$rat*2*4;}else{
if(isset($vtr_act))$rat_sc_act=$rat*4;
}
//Ветряк
if(isset($drakon_act))$rat_drakon_act=(($rat/100)*300);
if(isset($fooder_act))$rat_fooder_act=(($rat/100)*$fooder_act2);
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_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;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;


mysql_querll("UPDATE `kolhoz_user` SET `udob` = '".($ku['udob']+1)."' WHERE `id` = '$ku[id]'");
$ku=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$ku[id]'"));
$korm_time=($petground['time']<$time?$time+(4*3600):$petground['time']+(4*3600));
mysql_querll("UPDATE `kolhoz_treeground` SET `time` = '$korm_time' WHERE `id` = '$petground[id]' LIMIT 1");
mysql_querll("UPDATE `kolhoz_warehouse` SET `count` = '".($wh['count']-3)."' WHERE `id` = '$wh[id]' LIMIT 1");
mysql_querll("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$rat)."' WHERE `id` = '$ku[id]'");
$_SESSION['rating']=$rat;

update_mc($rat);


header("Location:?mytreefarm&".passgen());
exit;
}
else echo "<div style='background-color:#114411;padding:4px;border:1px solid red'>Не хватает ".(3-$wh['count'])." шт.</div>";
}
$q=mysql_querll("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `arena` = '0'");
while($post=mysql_fetch_array($q))
{
$plant=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant` WHERE `id` = '$post[id_plant]'"));
echo "<li><img width='16' height='16' src='img/icons/plate.png' alt='o'> <a href='?mytreefarm&food=$petground[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';
}
}
?>