<?

if($ku['level']<999)
{
echo "<div class='content'>";echo "<div class='block'>";echo'<img src="img/smiles/owibochka.gif" alt="*"></img> Куда зашел?';
include_once 'inc/foot.php';
echo "</div></div>";
exit;
}


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

if(isset($_GET['gos']))
{
if(isset($mc))
{
if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_plant_sh` WHERE `id` = '$gos[id_plant]' AND (`level` = '$ku[level]' OR `level` < '$ku[level]')"),0)!=0)

mysql_querll("UPDATE `kolhoz_user` SET `last_plant_s` = '$gos[id_plant]' WHERE `id` = '$ku[id]'");
header("Location:?sh_skr");
exit;
}
else err_game("Для начала вступите в колхоз.");
}
include_once 'inc/sh_skr/sh_change_plant.php';
include_once 'inc/sh_skr/sh_change_soil.php';
include_once 'inc/sh_skr/sh_cultivator_all.php';
include_once 'inc/sh_skr/sh_cultivator.php';
include_once 'inc/sh_skr/sh_harvest_all.php';
include_once 'inc/sh_skr/sh_harvest.php';
include_once 'inc/sh_skr/sh_seat_all.php';
include_once 'inc/sh_skr/sh_seat.php';
include_once 'inc/sh_skr/sh_soil_all.php';
include_once 'inc/sh_skr/sh_soil.php';
include_once 'inc/sh_skr/sh_water_all.php';
include_once 'inc/sh_skr/sh_water.php';
include_once 'inc/sh_skr/sh_clean_grounds.php';
include_once 'inc/sh_skr/sh_new_ground.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'>Бесплатная очистка грядок будет доступна через ".time_left($ku['time_cp']-$time)."</span></li></ul></div>";
unset($_SESSION['cp']);
}
echo "<div class='content'>";
echo "<div class='block'>";
echo "<div><img width='16' height='16' src='img/icons/refresh.png' alt='o'> <a href='?sh_skr&reflesh=".rand(99999,99999999)."'>Обновить</a></div>";
echo "<div><img width='16' height='16' src='img/icons/down.png' alt='o'> <a href='?sh_skr'>Открыть</a></div>";
if($ku['hydropinics_time']>$time)echo "<li><img width='16' height='16' src='img/icons/hydropinics.png' alt='o'> <a class='epic' href='?shop=hydropinics'>Гидропоника</a><span class='minor'> $ku[hydropinics_type]% на <span>".time_left($ku['hydropinics_time']-$time)."</span></span></li>";
if($ku['scarecrow_time']>$time)echo "<li><img width='16' height='16' src='img/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='img/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='img/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='img/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['garden_time']>$time)echo "<li><img width='16' height='16' alt='' src='img/icons/gardener".$ku[gardener].".png'> <a class='epic' href='?shop=gardener&id=".$ku[gardener]."'>Садовник ".$name."</a><span class='minor'> на <span>".time_left($ku['garden_time']-$time)."</span></span></li>";

if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_ground_sh` WHERE `id_user` = '$ku[id]' AND (`time` < '$time' OR `time` = '$time') AND `id_plant` != '0'"),0)!=0 && $ku['harvester_sh']>0)echo "<div><img width='16' height='16' src='img/shaht/harvest.png' alt='o'> <a href='?sh_skr&sh_harvest_all'>Собрать все</a></div>";

if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_ground_sh` WHERE `id_user` = '$ku[id]' AND `soil` = '0' AND (`time_soil` = '$time' OR `time_soil` < '$time') AND `id_plant` != '0' AND `time` > '$time'"),0)!=0 && $ku['soiler_sh']>0)echo "<div><img width='16' height='16' src='img/shaht/fd6.png' alt='o'> <a href='?sh_skr&sh_soil_all'>Накормить всех</a></div>";

if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_ground_sh` WHERE `id_user` = '$ku[id]' AND `id_plant` != '0' AND (`time_water` = '$time' OR `time_water` < '$time') AND `time` > '$time' AND (`soil` = '0' AND `time_soil` > '$time' OR `soil` = '1')"),0)!=0 && $ku['irregate_sh']>0)echo "<div><img width='16' height='16' src='img/icons/water.png' alt='o'> <a href='?sh_skr&sh_water_all'>Напоить всех</a></div>";

if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_ground_sh` WHERE `id_user` = '$ku[id]' AND `id_plant` = '0' AND `cultivator` = '1'"),0)!=0 && $ku['seeder_sh']>0)echo "<div><img width='16' height='16' src='img/icons/dig.png' alt='o'> <a href='?sh_skr&sh_seat_all'>Добывать все</a></div>";

if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_ground_sh` WHERE `id_user` = '$ku[id]' AND `id_plant` = '0' AND (`time` = '$time' OR `time` < '$time') AND `cultivator` = '0'"),0)!=0 && $ku['cultivator']>0)echo "<div><img width='16' height='16' src='img/shaht/dig.png' alt='o'> <a href='?sh_skr&sh_cultivator_all'>Проветрить все</a></div>";
echo "<ul>";

////ГРЯДКИ


$q=mysql_querll("SELECT * FROM `kolhoz_ground_sh` WHERE `id_user` = '$ku[id]'");
//while($post=mysql_fetch_array($q))
$post=mysql_fetch_array($q);
{
echo "<li>";
if($post['id_plant']!=0 && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_plant_sh` WHERE `id` = '$post[id_plant]'"),0)!=0)$plant=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant_sh` WHERE `id` = '$post[id_plant]'"));

echo "<li><img width='48' height='48' src='".(!isset($plant)?"".($post['cultivator']==1?"img/shaht/dirt1_new.jpg":"img/shaht/dirt2_new.jpg")."":"img/shaht/$plant[id].png")."' alt='o' class='portrait'>";
echo "<div>";
echo "".(!isset($plant)?"<span class='title'>".($post['cultivator']==1?"Шахта, готовая к работе":"Задымленная шахта")."</span>":"<span  class='title'>".hsc($plant['name'])."</span>".($post['time']>$time?"<span class='small minor'> (Добыча через <span> ".time_left($post['time']-$time)."</span>)</span>":null)."")."";
echo "</div>";
echo "<div>";
if(isset($plant))
{
if($post['time']<=$time)
{
echo "<img width='16' height='16' src='img/shaht/harvest.png' alt='o'> <a href='?sh_skr&sh_harvest=$post[id]'>Собрать ископаемые</a>";
}
else
{
if($ku['last_soil_sh']!=0 && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_soil_sh` WHERE `id` = '$ku[last_soil_sh]'"),0)!=0)$ls=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_soil_sh` WHERE `id` = '$ku[last_soil_sh]'"));

echo "<div class='small minor'>".($post['time_soil']<=$time && $post['soil']==0 && $post['time']>$time?"<img width='16' height='16' src='img/shaht/fd6.png' alt='o'> ".(isset($ls)?"<a href='?sh_skr&sh_soil=$post[id]&select=$ls[id]'>Дать шахтеру
<span>".hsc($ls['name'])."</span></a>, <a href='?sh_skr&sh_soil=$post[id]'><span>выбрать
еду</span></a>":"<a href='?sh_skr&sh_soil=$post[id]'>Дать шахтеру</a>")."":"".($post['soil']==0 && $post['time']>$time?"Накормить шахтера через ".time_left($post['time_soil']-$time)."":null)."")."</div>";
echo "<div class='small minor'>".($post['time_water']>$time && $post['time']>$time?"Напоить шахтера через ".time_left($post['time_water']-$time)."":"".($post['time']>$time?"".($post['soil']==0 && $post['time_soil']>$time || $post['soil']==1?"<img alt='' width='16' height='16' src='img/icons/water.png'> <a href='?sh_skr&sh_water=$post[id]'>Напоить шахтера</a>":null)."":null)."")."</div>";
}
}
else
{
echo "<span>";
if($ku['last_plant_sh']!=0 && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_plant_sh` WHERE `id` = '$ku[last_plant_sh]'"),0)!=0)$lp=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant_sh` WHERE `id` = '$ku[last_plant_sh]'"));
echo "".($post['cultivator']==1?"<img width='16' height='16' src='img/icons/dig.png' alt='o'> ".(isset($lp)?"<a href='?sh_skr&sh_seat=$post[id]&select=$lp[id]'>Начать добычу <span>".hsc($lp['name'])."</span></a>, <a href='?sh_skr&sh_seat=$post[id]'><span>выбрать ископаемое</span></a>":"<a href='?sh_skr&sh_seat=$post[id]'>Начать добычу</a>")."":"<img width='16' height='16' src='img/shaht/dig.png' alt='o'> <a href='?sh_skr&sh_cultivator=$post[id]'><span style='title'>Проветрить</span></a>")."";
echo "</span>";
}
if(isset($plant))unset($plant);
echo "</div><div style='clear:both'></div></li>";
}
if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_ground_sh` WHERE `id_user` = '$ku[id]'"),0)<10)echo "<li><img width='48' height='48' src='img/shaht/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='?sh_skr&sh_new_ground'>Купить</a> за <span class='title'><img width='16' height='16' src='img/icons/ruby.png' alt='o'><span>".cpsh(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_ground_sh` WHERE `id_user` = '$ku[id]'"),0))."</span> рубинов</span></div><div style='clear:both'></div></li>";
//echo "</ul>";
if($ku['last_plant_sh']!=0 && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_plant_sh` WHERE `id` = '$ku[last_plant_sh]'"),0)!=0)$lp=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant_sh` WHERE `id` = '$ku[last_plant_sh]'"));

if($ku['last_soil_sh']!=0 && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_soil_sh` WHERE `id` = '$ku[last_soil_sh]'"),0)!=0)$ls=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_soil_sh` WHERE `id` = '$ku[last_soil_sh]'"));

echo "<ul class='ptm'><li><img width='16' height='16' src='img/shaht/harvest.png' alt='o'> <a href='?sh_skr&sh_change_plant'>Сменить ископаемое</a>: <span>".(isset($lp)?"".hsc($lp['name'])."":"-")."</span></li>";

echo "<li><img width='16' height='16' src='img/shaht/fd6.png' alt='o'> <a href='?sh_skr&sh_change_soil'>Сменить еду</a>: <span>".(isset($ls)?"".hsc($ls['name'])."":"-")."</span></li>";
echo "".($ku['time_cp']>$time?"<li><img width='16' height='16' src='img/icons/cross.png' alt='o'> До бесплатной очистки: <span>".time_left($ku['time_cp']-$time)."</span></li><li><span><img width='16' height='16' src='img/icons/tick.png' alt='o'> <a href='?sh_skr&sh_clean_grounds'><span>Очистить шахты</span></a>(<span>Стоимость</span>: <span><img width='16' height='16' src='img/icons/ruby.png' alt='o'> <span
class='title'>".($ku['count_cp']*10)."</span></span>)</span></li>":"<li><img width='16' height='16' src='img/icons/cross.png' alt='o'> <a href='?sh_skr&sh_clean_grounds'>Очистить шахты</a></li>")."</ul>";
if(isset($mc))echo "<li class='pt'><img width='16' height='16' src='img/icons/heli4n.png' alt='o'> <a href='?collective=$mc[id]&hangar'>Вызвать вертолет</a></li>";
echo '</ul></div></div>';
include_once 'inc/foot.php';
?>