<?
/*=====================#
echo '<div class="event"><h1>Ждите, проходит тест</h1></div>'."\n";
echo '<div class="content"><div class="block">'."\n";
echo 'Несколько минут'."\n";
echo '</div></div>'."\n";
include_once 'inc/foot.php';
exit;
#=====================*/

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

if(isset($_GET['mytreefarm']) && $_GET['mytreefarm']=='sv')
{
mysql_querll("UPDATE `kolhoz_user` SET `sv` = '1' WHERE `id` = '$ku[id]'");
header("Location:?mytreefarm");
}
if(isset($_GET['mytreefarm']) && $_GET['mytreefarm']=='rv')
{
mysql_querll("UPDATE `kolhoz_user` SET `sv` = '0' WHERE `id` = '$ku[id]'");
header("Location:?mytreefarm");
}
include_once 'inc/new_treeground.php';
include_once 'inc/t_level.php';
include_once 'inc/t_level_all.php';
include_once 'inc/sell_tree.php';
include_once 'inc/buy_tree.php';
include_once 'inc/ydob.php';
include_once 'inc/ydob_all.php';
include_once 'inc/t_money.php';
include_once 'inc/t_money_all.php';
include_once 'inc/t_animals.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'>";
if($ku['scarecrow_time']>$time)echo "<li><img width='16' height='16' src='images/icons/scarecrow.png' alt='o'> <a class='epic' href='?shop=scarecrow'>Пугало</a><span class='minor'> на <span>".time_left($ku['scarecrow_time']-$time)."</span></span></li>";
if($ku['time_shmel']>$time)echo "<li><img width='16' height='16' alt='o' src='images/icons/heli1n.png'> <a class='epic' href='?shop=helicopter&1'>Шмель</a><span class='minor'> на <span>".time_left($ku['time_shmel']-$time)."</span></span></li>";
if($ku['time_yastreb']>$time)echo "<li><img width='16' height='16' alt='o' src='images/icons/heli2n.png'> <a class='epic' href='?shop=helicopter&2'>Ястреб</a><span class='minor'> на <span>".time_left($ku['time_yastreb']-$time)."</span></span></li>";
if($ku['time_drakon']>$time)echo "<li><img width='16' height='16' alt='o' src='images/icons/heli3n.png'> <a class='epic' href='?shop=helicopter&3'>Дракон</a><span class='minor'> на <span>".time_left($ku['time_drakon']-$time)."</span></span></li>";

if($ku['fooder2']>0)
{
$q=mysql_querll("SELECT * FROM `kolhoz_treeground` 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 "<img width='16' height='16' src='images/udobritel.png' alt='o'> <a href='?mytreefarm&ydob_all'>Удобрить все деревья</a>";
}

if($ku['conveyor2']>0 && !isset($_GET['moderate']))
{
$q=mysql_querll("SELECT * FROM `kolhoz_treeground` 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_tree` 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_act2=0;
if(isset($conveyor_act2))$count_conveyor_act2=($count/100)*$conveyor_act2;
$count=$count_conveyor_act2+$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='?mytreefarm&money_all'>Собрать у всех урожай</a> за <span><img width='16' height='16' src='images/icons/money.png' alt='o'> <span
class='title'>$money2</span></span></div>";
}
if($ku['sv']==0)echo "<img width='16' height='16' src='images/icons/down.png' alt='o'> <a href='?mytreefarm=sv'>Свернуть</a><br>";
if($ku['sv']==1)echo "<img width='16' height='16' src='images/icons/up.png' alt='o'> <a href='?mytreefarm=rv'>Развернуть</a><br>";
echo "<div class='ptm'><ul>";
if($ku['sv']==1){
$q=mysql_querll("SELECT * FROM `kolhoz_treeground` WHERE `id_user` = '$ku[id]' LIMIT 1");
}else{
$q=mysql_querll("SELECT * FROM `kolhoz_treeground` WHERE `id_user` = '$ku[id]'");
}

while($post=mysql_fetch_array($q))
{
$pet=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_tree` WHERE `id` = '$post[id_pet]'"));
echo "<li><img width='48' height='48' src='".($post['id_pet']==0?"images/dirt_new.jpg":"images/trees/$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/tree.png'> <a href='?mytreefarm&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><br/>";
}
if(isset($_GET['moderate']))
{
echo "<li><img alt='' width='16' height='16' src='images/icons/money.png'> <a href='?mytreefarm&sell=$post[id]'>Продать дерево</a> за <span><img width='16' height='16' src='images/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='images/icons/up.png'> <a href='?mytreefarm&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='?mytreefarm&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
{
$d_money=floor($post['time_money2']/(4*3600));
if($d_money>0)
{
$nt=$post['time_money2']-($d_money*14400);
$count=1;
$count_conveyor_act2=0;
if(isset($conveyor_act2))$count_conveyor_act2=($count/100)*$conveyor_act2;
$count=$count_conveyor_act2+$count;

$money=($count*$pet['money'])*$d_money;
echo " <img width='16' height='16' src='images/icons/money.png' alt='o'> <a class='' href='?mytreefarm&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/udobritel.png' alt='o'> <a class='' href='?mytreefarm&food=$post[id]'><span>Удобрить</span></a>";
}
}
}
echo "</div>";
echo "<div style='clear:both'></div></li>";
}
if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_treeground` WHERE `id_user` = '$ku[id]'"),0)<200)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='?mytreefarm&new_petground'>Купить</a> за <span class='title'><img width='16' height='16' src='images/icons/ruby.png' alt='o'> <span>".cpg(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_treeground` WHERE `id_user` = '$ku[id]'"),0))."</span> рубинов</span></div><div style='clear:both'></div></li>";
echo "</ul>";
echo "<div class='ptm'><img width='16' height='16' src='images/icons/refresh.png' alt='o'> <a href='?mytreefarm&reflesh=".rand(99999,99999999)."'>Обновить</a><img alt='o' width='16' height='16' src='images/icons/moderate.png'> <a href='?mytreefarm&moderate'>Управление</a></div></div>";
include_once 'inc/foot.php';
?>