<?
include_once 'inc/new_petground.php';
include_once 'inc/level.php';
include_once 'inc/level_all.php';
include_once 'inc/sell_animal.php';
include_once 'inc/buy_animal.php';
include_once 'inc/food.php';
include_once 'inc/food_all.php';
include_once 'inc/money.php';
include_once 'inc/money_all.php';
include_once 'inc/change_food.php';
if(isset($_SESSION['err']))
{
echo err_game("Не хватает овощей в амбаре");
unset($_SESSION['err']);
}
echo "<div class='event'><h1>Загоны</h1></div>";
echo "<div class='content'>";
echo "<div class='block'>";
echo "<div class='feedback'>";
if(isset($_GET['on']))
{
mysql_query("UPDATE `kolhoz_user` SET `kompact` = '0' WHERE `id` = '$ku[id]'");
header("Location:/?mypetfarm");
exit;
}
echo "<li><a href='?mypetfarm&on'><img src='images/icons/down.png'> ";
if($ku['scarecrow_time']>$time)echo "<img width='16' height='16' src='images/icons/scarecrow.png' alt='o'> ";
if($ku['time_vetruk']>$time)echo "<img width='16' height='16' src='images/vetriak.png' alt='o'> ";
if($ku['time_shmel']>$time)echo "<img width='16' height='16' alt='o' src='images/icons/heli1n.png'> ";
if($ku['time_yastreb']>$time)echo "<img width='16' height='16' alt='o' src='images/icons/heli2n.png'> ";
if($ku['time_drakon']>$time)echo "<img width='16' height='16' alt='o' src='images/icons/heli3n.png'> ";
echo "<li class='pt'>";
if($ku['fooder']>0)
{
$q=mysql_query("SELECT * FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'");
$count_gol=0;
while($post=mysql_fetch_array($q))
{
$max_time=$time+$post['level']*(3600*4);
$mezh_time=$max_time-$post['time'];
if($mezh_time>=4*3600)$count_gol++;
}
if($count_gol!=0)echo "<div><img width='16' height='16' src='images/icons/plate.png' alt='o'> <a href='?mypetfarm&food_all'>Накормить всех</a></div>";
}

if($ku['conveyor']>0 && !isset($_GET['moderate']))
{
$q=mysql_query("SELECT * FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'");
$money2=0;
while($post=mysql_fetch_array($q))
{
$pet=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_pet` WHERE `id` = '$post[id_pet]'"));
$d_money=floor($post['time_money2']/(4*3600));
if($d_money>0)
{
$nt=$post['time_money2']-($d_money*14400);
$count=1;
$count_conveyor_act=0;
$count_vet_act=0;
if(isset($conveyor_act))$count_conveyor_act=($count/100)*$conveyor_act;
if(isset($vet_act))$count_vet_act=($count/100)*$vet_ps_m;
$count=$count_conveyor_act+$count_vet_act+$count;

$money=($count*$pet['money'])*$d_money;
$money2=$money2+$money;
}
}
if($money2>0)echo "<div><img width='16' height='16' src='images/icons/harvest.png' alt='o'> <a href='?mypetfarm&money_all'>Продать все</a> за <span><img width='16' height='16' src='images/icons/money.png' alt='o'> <span
class='title'>$money2</span></span></div>";
}
echo "</li>";
echo "<div class='ptm'><ul>";
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]'"),0); 
if ($k_post==0) 
{ 
echo "Список пуст..."; 
} 
$k_page=k_page($k_post,5);
$page=page($k_page);
$start=5*$page-5;

$q=mysql_query("SELECT * FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]'  ORDER BY `id` DESC LIMIT $start, 5");
while($post=mysql_fetch_array($q))
{
$pet=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_pet` WHERE `id` = '$post[id_pet]'"));
echo "<li><img width='48' height='48' src='".($post['id_pet']==0?"images/dirt_new.jpg":"images/pets/$pet[id].png")."' alt='o' class='portrait'>";
echo "<div>";
if($post['id_pet']==0)
{
echo "<img alt='o' width='16' height='16' src='images/icons/animal.png'> <a href='?mypetfarm&buy=$post[id]'>Купить животное</a>";
}
else
{
if(!isset($_GET['moderate']))
{
echo "<span class='title'>".hsc($pet['name'])."</span>";
if($post['time']>$time)echo "<span class='small minor'> (Сытость на ".time_left($post['time']-$time).")</span>";
}
if(isset($_GET['moderate']))
{
if($pet['rub']=='0'){$c=$pet['cena']/2;}else{$c=$pet['cena_rub']/2;}
$cena=$c;
echo "<li><img alt='' width='16' height='16' src='images/icons/money.png'> <a href='?mypetfarm&sell=$post[id]'>Продать животное</a> за <span><img width='16' height='16' src='images/icons/".($pet['rub']=='0'?"money.png":"ruby.png")."' alt='o'> <span class='title'>".($cena)."</span></span></li>";
if($post['level']<20)
{
$post['next_level']=$post['level']+1;
$money_all_levels=0;
for($kp=$post['next_level'];$kp<=20;$kp++)
{
$money_all_levels=$money_all_levels+$kp;
}
echo "<li><img alt='' width='16' height='16' src='images/icons/up.png'> <a href='?mypetfarm&level=$post[id]'>Увеличить ёмкость</a> за <span><img
width='16' height='16' src='images/icons/money.png' alt='o'> <span class='title'>$post[next_level] тыс.</span></span>
<span class='small minor'>(с $post[level] до $post[next_level])</span></li>
<li><img alt='' width='16' height='16' src='images/icons/up.png'> <a href='?mypetfarm&level_all=$post[id]'>Увеличить ёмкость</a> за <span><img
width='16' height='16' src='images/icons/money.png' alt='o'> <span class='title'>$money_all_levels тыс.</span></span>
<span class='small minor'>(с $post[level] до 20)</span></li>";
}
}
else
{
echo "<div>";
$d_money=floor($post['time_money2']/(4*3600));
if($d_money>0)
{
$nt=$post['time_money2']-($d_money*14400);
$count=1;
$count_conveyor_act=0;
$count_vet_act=0;
if(isset($conveyor_act))$count_conveyor_act=($count/100)*$conveyor_act;
if(isset($vet_act))$count_vet_act=($count/100)*$vet_ps_m;
$count=$count_conveyor_act+$count_vet_act+$count;

$money=($count*$pet['money'])*$d_money;
echo "<img width='16' height='16' src='images/icons/money.png' alt='o'> <a class='' href='?mypetfarm&money=$post[id]'>Продать</a> за <span><img width='16' height='16' src='images/icons/money.png' alt='o'> <span
class='title'>$money</span></span>";
}
else
{
$max_time=$time+$post['level']*(3600*4);
$mezh_time=$max_time-$post['time'];
if($mezh_time>=4*3600)echo "<img width='16' height='16' src='images/icons/plate.png' alt='o'> <a class='' href='?mypetfarm&food=$post[id]'><span>Покормить</span></a>";
}
}
}
echo "</div>";
echo "<div style='clear:both'></div></li>";
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]'"),0)<20)echo "<li><img width='48' height='48' src='images/dirt_new.jpg' alt='o' class='portrait'><div><span class='title'>Новый загон</span></div><div><img width='16' height='16' src='images/icons/cart.png' alt='o'> <a href='?mypetfarm&new_petground'>Купить</a>
за <span class='title'><img width='16' height='16' src='images/icons/ruby.png' alt='o'> <span>".cpg(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]'"),0))."</span> рубинов</span></div><div style='clear:both'></div></li>";
echo "</ul></div>";
if ($k_page>1)str("?mypetfarm&",$k_page,$page); // Вывод страниц 
if($ku['last_food']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant` WHERE `id` = '$ku[last_food]'"),0)!=0)$lpf=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$ku[last_food]'"));
echo "<ul class='ptm'><li><img width='16' height='16' src='images/icons/plate.png' alt='o'> <a href='?mypetfarm&change_food'>Сменить корм</a>: <span>".(isset($lpf)?"".hsc($lpf['name'])."":"-")."</span></li>";
echo '<li><img width="16" height="16" src="images/icons/animal.png" alt=""> <a href="?help=animals">Животные</a></li>';
echo "<div class='ptm'><img width='16' height='16' src='images/icons/refresh.png' alt='o'> <a href='?mypetfarm&reflesh=".rand(99999,99999999)."'>Обновить</a><img alt='o' width='16' height='16' src='images/icons/moderate.png'> <a href='?mypetfarm&moderate'>Управление</a></li>";
if(isset($mc))echo "<li class='pt'><img width='16' height='16' src='images/icons/heli4n.png' alt='o'> <a href='?collective=$mc[id]&hangar'>Вызвать вертолет</a></li>";
echo '</ul></div></div>';
include_once 'inc/foot.php';
?>