<?
if($ku['time_key']>$time)
{
include_once 'inc/cellar/change_plant2.php';
include_once 'inc/cellar/change_soil2.php';
include_once 'inc/cellar/cultivator_all2.php';
include_once 'inc/cellar/cultivator2.php';
include_once 'inc/cellar/harvest_all2.php';
include_once 'inc/cellar/harvest2.php';
include_once 'inc/cellar/seat_all2.php';
include_once 'inc/cellar/seat2.php';
include_once 'inc/cellar/soil_all2.php';
include_once 'inc/cellar/soil2.php';
include_once 'inc/cellar/water_all2.php';
include_once 'inc/cellar/water2.php';
include_once 'inc/cellar/clean_polks.php';
include_once 'inc/cellar/new_polka2.php';
echo "<div class='event'><h1>Погреб</h1></div>";
if(isset($_SESSION['cp']))
{
echo "<div class='feedback'><ul class='feedbackPanel'><li class='feedbackPanelINFO'><span class='feedbackPanelINFO'>Полки теперь свободны, но сначала протрите их</span></li></ul></div>";
unset($_SESSION['cp']);
}
if(isset($_GET['on']))
{
mysql_query("UPDATE `kolhoz_user` SET `kompact` = '0' WHERE `id` = '$ku[id]'");
header("Location:/?mycellar2");
exit;
}
echo "<div class='content'>";
echo "<div class='block'>";
echo "<li><a href='?mycellar2&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'> </a>";
if($ku['worker1_time']>$time)echo "<img width='16' height='16' alt='' src='images/icons/worker".$ku['worker1'].".png'></a></li>";
echo "<div><img width='16' height='16' src='images/icons/refresh.png' alt='o'> <a href='?mycellar2&reflesh=".rand(99999,99999999)."'>Обновить</a>";
echo "<li class='pt'>";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_plant2` != '0'"),0)!=0 && $ku['harvester2']>0)echo "<div><img width='16' height='16' src='images/icons/warehouse.png' alt='o'> <a href='?mycellar2&harvest_all2'>Все в амбар</a></div>";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '0' AND (`time` = '$time' OR `time` < '$time') AND `cultivator2` = '0'"),0)!=0 && $ku['cultivator2']>0)echo "<div><img width='16' height='16' src='images/icons/clear.png' alt='o'> <a href='?mycellar2&cultivator_all2'>Протереть всё</a></div>";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '0' AND `cultivator2` = '1'"),0)!=0 && $ku['seeder2']>0)echo "<div><img width='16' height='16' src='images/icons/cellar_put.png' alt='o'> <a href='?mycellar2&seat_all2'>Заготовить всё</a></div>";
echo "</li>";
echo "<ul>";

////ГРЯДКИ

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` 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_polka2` WHERE `id_user` = '$ku[id]' ORDER BY `id` DESC LIMIT $start, 5");
while($post=mysql_fetch_array($q))
{
echo "<li>";
if($post['id_plant2']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant2` WHERE `id` = '$post[id_plant2]'"),0)!=0)$plant2=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$post[id_plant2]'"));

echo "<li><img width='48' height='48' src='".(!isset($plant2)?"".($post['cultivator']==1?"images/polka.png":"images/polka.png")."":"images/plants/$plant2[id].png")."' alt='o' class='portrait'>";
echo "<div>";
echo "".(!isset($plant2)?"<span class='title'>".($post['cultivator2']==1?"Чистая полка":"Пыльная полка")."</span>":"<span  class='title'>".hsc($plant2['name'])."</span>".($post['time']>$time?"<span class='small minor'> (Будет готово через <span> ".time_left($post['time']-$time)."</span>)</span>":null)."")."";
echo "</div>";
echo "<div>";
if(isset($plant2))
{
if($post['time']<=$time)
{
echo "<img width='16' height='16' src='images/icons/warehouse.png' alt='o'> <a href='?mycellar2&harvest2=$post[id]'>В амбар</a>";
}
else
{
if($ku['last_soil2']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_soil2` WHERE `id` = '$ku[last_soil2]'"),0)!=0)$ls=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_soil2` WHERE `id` = '$ku[last_soil2]'"));
}
}
else
{
echo "<span>";
if($ku['last_plant2']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant2` WHERE `id` = '$ku[last_plant2]'"),0)!=0)$lp=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$ku[last_plant2]'"));
echo "".($post['cultivator2']==1?"<img width='16' height='16' src='images/icons/cellar_put.png' alt='o'> ".(isset($lp)?"<a href='?mycellar2&seat2=$post[id]&select=$lp[id]'>Поставить <span>".hsc($lp['name'])."</span></a> <a href='?mycellar2&seat2=$post[id]'><span></span></a>":"<a href='?mycellar2&seat2=$post[id]'>Заготовить</a>")."":"<img width='16' height='16' src='images/icons/clear.png' alt='o'> <a href='?mycellar2&cultivator2=$post[id]'><span style='title'>Протереть</span></a>")."";
echo "</span>";
}
if(isset($plant2))unset($plant2);
echo "</div><div style='clear:both'></div></li>";
}
if($ku['last_plant2']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant2` WHERE `id` = '$ku[last_plant2]'"),0)!=0)$lp=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$ku[last_plant2]'"));
if($ku['last_soil2']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_soil2` WHERE `id` = '$ku[last_soil2]'"),0)!=0)$ls=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_soil2` WHERE `id` = '$ku[last_soil2]'"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_polka2` WHERE `id_user` = '$ku[id]'"),0)<20)echo "<li><img width='48' height='48' src='images/polka.png' 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='?mycellar2&new_polka2'>Купить</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_polka2` WHERE `id_user` = '$ku[id]'"),0))."</span> рубинов</span></div><div style='clear:both'></div></li>";
if ($k_page>1)str("?mycellar2&",$k_page,$page); // Вывод страниц 
echo " <li><img width='16' height='16' src='images/icons/cross.png' alt='o'> <a href='?mycellar2&clean_polks'>Освободить полки</a></li>";
echo " <li><img width='16' height='16' src='images/icons/last_recipes.png' alt='o'> <a href='?mycellar2&change_plant2'>Последняя заготовка</a>: <span>".(isset($lp)?"".hsc($lp['name'])."":"отсутствует")."</span></li>";
echo "<li><img width='16' height='16' src='images/icons/book.png' alt='o'> <a href='?help=recipes2'>Книга рецептов</a></li>";
echo "<li class='pt'><img width='16' height='16' src='images/icons/heli4n.png' alt='o'> <a href='?collective=$mc[id]&hangar&arend=$mc[id]&page=$mc[id]'>Вызвать вертолет</a></li>";
echo '<li><img width="16" height="16" src="images/icons/pkey.png" alt="o"> <a href="?nk">Ключи</a></li>';
echo "</ul>";
echo "</div></div>";
}
else
{
header("Location:?nk");
}

include_once 'inc/foot.php';
?>