<?
$q_b=mysql_query("SELECT * FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'");
$post_b=mysql_fetch_array($q_b);
$pet_b=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_pet` WHERE `id` = '$post_b[id_pet]'"));

if(mysql_result(mysql_querll("SELECT COUNT(`id`) FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]'"),0)<4){
mysql_querll("INSERT INTO `kolhoz_petground` SET `id_user` = '$ku[id]'");
mysql_querll("INSERT INTO `kolhoz_petground` SET `id_user` = '$ku[id]'");
mysql_querll("INSERT INTO `kolhoz_petground` SET `id_user` = '$ku[id]'");
mysql_querll("INSERT INTO `kolhoz_petground` SET `id_user` = '$ku[id]'");
}

include_once"inc/zveri/buy_all.php";
include_once"inc/zveri/sell_all.php";
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';
if(isset($_SESSION['err']))
{
echo err_game("Не хватает овощей в амбаре");
unset($_SESSION['err']);
}

if(isset($_SESSION['zp'])){echo "<div class='feedback'><ul class='feedbackPanel'><li class='feedbackPanelINFO'><span class='feedbackPanelINFO'>Бесплатный разгон табуна будет доступен через ".time_left($ku['time_zp']-$time)."</span></li></ul></div>";unset($_SESSION['zp']);}
echo "<div class='event'><h1>Загоны</h1></div>";

if($ku['level']<25)
{
echo "<div class='content'>";
echo "<div class='block'>";
echo'<img src="img/icons/owibochka.gif" alt="*"> Загоны доступны со 25-го уровня!';
include_once 'inc/foot.php';
echo "</div></div>";
exit;
}

if(isset($_GET['mypetfarm']) && $_GET['mypetfarm']=='sv')
{
mysql_querll("UPDATE `kolhoz_user` SET `sv` = '1' WHERE `id` = '$ku[id]'");
header("Location:?mypetfarm");
}
if(isset($_GET['mypetfarm']) && $_GET['mypetfarm']=='rv')
{
mysql_querll("UPDATE `kolhoz_user` SET `sv` = '0' WHERE `id` = '$ku[id]'");
header("Location:?mypetfarm");
}
echo "<div class='content'>";
echo "<div class='block'>";

if(isset($_GET['vidok'])){mysql_query("UPDATE `kolhoz_user` SET `vidok` = '".($ku['vidok']==1?"0":"1")."' WHERE `id` = '$ku[id]'");
header("Location:?mypetfarm");
}

echo "<div class='block'>".($ku['vidok']==0?"<a href='?mypetfarm&vidok'>Компактный вид <img width='16' height='16' src='img/icons/right.png' alt='o'></a>":"<a href='?mypetfarm&vidok'><img width='16' height='16' src='img/icons/left.png' alt='o'>")."</a> ";
if($ku['vidok']==1){
echo "<a href='?mypetfarm&reflesh=".rand(99999,99999999)."'><img width='16' height='16' src='img/icons/obmen.png' alt='o'></a> ";
if($ku['hydropinics_time']>$time)echo "<a class='epic' href='?shop=hydropinics'><img width='16' height='16' src='img/icons/hydropinics.png' alt='o'></a> ";
if($ku['vetriak_time']>$time)echo "<a class='epic' href='?shop=vetriak'><img width='16' height='16' src='img/vetriak.png' alt='o'></a> ";
if($ku['scarecrow_time']>$time)echo "<a class='epic' href='?shop=scarecrow'><img width='16' height='16' src='img/icons/scarecrow.png' alt='o'></a> ";
if($ku['time_shmel']>$time)echo "<a class='epic' href='?shop=helicopter&1'><img width='16' height='16' alt='o' src='img/icons/heli1n.png'></a> ";
if($ku['time_yastreb']>$time)echo "<a class='epic' href='?shop=helicopter&2'><img width='16' height='16' alt='o' src='img/icons/heli2n.png'></a> ";
if($ku['time_drakon']>$time)echo "<a class='epic' href='?shop=helicopter&3'><img width='16' height='16' alt='o' src='img/icons/heli3n.png'></a> ";
if($ku['garden_time']>$time)echo "<a class='epic' href='?shop=gardener&id=".$ku['gardener']."'><img width='16' height='16' alt='' src='img/icons/gardener".$ku['gardener'].".png'></a> ";
}
echo "</div>";
if($ku['vidok']==0){
echo "<a href='?mypetfarm&reflesh=".rand(99999,99999999)."'><div class='block'><img width='16' height='16' src='img/icons/obmen.png' alt='o'> Обновить</a></div>";
//if($ku['garden_time']>$time)echo "<a class='epic' href='?shop=gardener&id=".$ku['gardener']."'><div class='block'><img width='16' height='16' alt='' src='img/icons/gardener".$ku['gardener'].".png'> Садовник ".$name."</a><span class='minor'> <span>".time_left($ku['garden_time']-$time)."</span></span></div>";
//if($ku['hydropinics_time']>$time)echo "<a class='epic' href='?shop=hydropinics'><div class='block'><img width='16' height='16' src='img/icons/hydropinics.png' alt='o'> Гидропоника</a> <span class='minor'> <b>$ku[hydropinics_type]%</b> <span>".time_left($ku['hydropinics_time']-$time)."</span></span></div>";
if($ku['scarecrow_time']>$time)echo "<a class='epic' href='?shop=scarecrow'><div class='block'><img width='16' height='16' src='img/icons/scarecrow.png' alt='o'> Пугало</a><span class='minor'> <span>".time_left($ku['scarecrow_time']-$time)."</span></span></div>";
if($ku['vetriak_time']>$time)echo "<a class='epic' href='?shop=vetriak'><div class='block'><img width='16' height='16' src='img/vetriak.png' alt='o'> Ветряк</a><span class='minor'> <span>".time_left($ku['vetriak_time']-$time)."</span></span></div>";
if($ku['time_shmel']>$time)echo "<a class='epic' href='?shop=helicopter&1'><div class='block'><img width='16' height='16' src='img/icons/heli1n.png' alt='o'> Шмель</a> <span class='minor'> <span>".time_left($ku['time_shmel']-$time)."</span></span></div>";
if($ku['time_yastreb']>$time)echo "<a class='epic' href='?shop=helicopter&2'><div class='block'><img width='16' height='16' src='img/icons/heli2n.png' alt='o'> Ястреб</a><span class='minor'> <span>".time_left($ku['time_yastreb']-$time)."</span></span></div>";
if($ku['time_drakon']>$time)echo "<a class='epic' href='?shop=helicopter&3'><div class='block'><img width='16' height='16' src='img/icons/heli3n.png' alt='o'> Дракон</a><span class='minor'> <span>".time_left($ku['time_drakon']-$time)."</span></span></div>";
}

if($ku['fooder']>0)
{
$q=mysql_querll("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 "<a href='?mypetfarm&food_all'><div class='block'><img width='16' height='16' src='img/icons/plate.png' alt='o'> Накормить всех</div></a>";
}



if($ku['conveyor']>0 && !isset($_GET['moderate']))
{
$q=mysql_querll("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_querll("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($barek>0)echo "<a href='?mypetfarm&buy_all'><div class='block'><img width='16' height='16' src='img/icons/harvest.png' alt='o'> Купить всех сразу</div></a>";




if($money2>0)echo "<div><img width='16' height='16' src='img/icons/harvest.png' alt='o'> <a href='?mypetfarm&money_all'>Продать все</a> за <span><img width='16' height='16' src='img/icons/money.png' alt='o'> <span
class='title'>$money2</span></span></div>";
}
if($ku['sv']==0)echo "<img width='16' height='16' src='img/icons/up.png' alt='o'> <a href='?mypetfarm=sv'>Свернуть</a><br>";
if($ku['sv']==1)echo "<img width='16' height='16' src='img/icons/down.png' alt='o'> <a href='?mypetfarm=rv'>Развернуть</a><br>";
echo "<div class='ptm'><ul>";
if($ku['sv']==1){
$q=mysql_querll("SELECT * FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]' LIMIT 1");
}else{
$q=mysql_querll("SELECT * FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]'");
}
while($post=mysql_fetch_array($q))
{
$pet=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_pet` WHERE `id` = '$post[id_pet]'"));
echo "<li><img width='48' height='48' src='".($post['id_pet']==0?"img/dirt_new.jpg":"img/pets/$pet[id].png")."' alt='o' class='portrait'>";
echo "<div>";
if($post['id_pet']==0)
{
echo "<img alt='o' width='16' height='16' src='img/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']))
{
echo "<li><img alt='' width='16' height='16' src='img/icons/money.png'> <a href='?mypetfarm&sell=$post[id]'>Продать животное</a> за <span><img width='16' height='16' src='img/icons/money.png' alt='o'> <span
class='title'>".($pet['cena']/2)."</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='img/icons/up.png'> <a href='?mypetfarm&level=$post[id]'>Увеличить ёмкость</a> за <span><img
width='16' height='16' src='img/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='img/icons/up.png'> <a href='?mypetfarm&level_all=$post[id]'>Увеличить ёмкость</a> за <span><img
width='16' height='16' src='img/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><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='img/icons/money.png' alt='o'> <a class='' href='?mypetfarm&money=$post[id]'>Продать</a> за <span><img width='16' height='16' src='img/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='img/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_querll("SELECT COUNT(*) FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]'"),0)<200)echo "<li><img width='48' height='48' src='img/dirt_new.jpg' alt='o' class='portrait'><div><span class='title'>Новый загон</span></div><div><img width='16' height='16' src='img/icons/cart.png' alt='o'> <a href='?mypetfarm&new_petground'>Купить</a>
за <span class='title'><img width='16' height='16' src='img/icons/ruby.png' alt='o'> <span>".cpg(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_petground` WHERE `id_user` = '$ku[id]'"),0))."</span> рубинов</span></div><div style='clear:both'></div></li>";
echo "</ul></div>";
echo "<div class='ptm'><img alt='o' width='16' height='16' src='img/icons/moderate.png'> <a href='?mypetfarm&moderate'>Управление</a>";
if($barek_sell>0)echo "<li><img alt='' width='16' height='16' src='img/icons/money.png'> <a href='?mypetfarm&moderate&sell_all'>Продать всех сразу</a> за <span><img width='16' height='16' src='img/icons/money.png' alt='o'> <span class='title'>".($pet_b['cena']*$barek_sell/2)."</span></span></li>";
echo "</div></div";
include_once 'inc/foot.php';
?>