<?
/*=====================#
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($ku['id']!=18043){
echo "<div class='content'><div class='block'>";
echo 'Временный стоп!';
echo "</div></div>";
include_once 'inc/foot.php';
}
*/

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

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

if(isset($_GET['key'])){
$cena=1;
$timee=3600*24*3;
if($ku['zkl']>=$cena){
if(isset($_GET['ok'])){
mysql_querll("UPDATE `kolhoz_user` SET `sh_time` = '".($ku['sh_time']>$time?"".($ku['sh_time']+$timee)."":"".($time+$timee)."")."', `zkl` = '".($ku['zkl']-$cena)."' WHERE `id` = '$ku[id]'");
echo "<div class='feedback'><ul class='feedbackPanel'><li class='feedbackPanelINFO'><span class='feedbackPanelINFO'>Шахты открыты на 3 дня.</span></li></ul></div>";
header("Location:?sh_myfarm");
} else {
echo podtv("?sh_myfarm&key&ok","?sh_myfarm");
include_once 'inc/foot.php';
}
} else {
$_SESSION['no_zkl']=$cena-$ku['zkl'];
header("Location:?sh_myfarm");
}
}


if($ku['sh_time']<$time){
echo "<div class='content'>";echo "<div class='block'>";
echo'<img src="images/smiles/owibochka.gif" alt="*"></img>Шахты закрыты';
echo "<ul><li><a href='?sh_myfarm&key'>Открыть шахты</a> на 3 дня <img width='16' height='16' src='images/icons/zkl.png' alt='o'> 1</li>";
include_once 'inc/foot.php';
exit;
} 

$peremenn = '&page='.$_GET['page'];

include_once 'inc/sh_myfarm/change_plant.php';
include_once 'inc/sh_myfarm/change_soil.php';
include_once 'inc/sh_myfarm/cultivator_all.php';
include_once 'inc/sh_myfarm/cultivator.php';
include_once 'inc/sh_myfarm/harvest_all.php';
include_once 'inc/sh_myfarm/harvest.php';
include_once 'inc/sh_myfarm/seat_all.php';
include_once 'inc/sh_myfarm/seat.php';
include_once 'inc/sh_myfarm/soil_all.php';
include_once 'inc/sh_myfarm/soil.php';
include_once 'inc/sh_myfarm/water_all.php';
include_once 'inc/sh_myfarm/water.php';
include_once 'inc/sh_myfarm/clean_grounds.php';
include_once 'inc/sh_myfarm/new_ground.php';
echo "<div class='event'><h1>Шахты</h1></div>";
$key=time_left($ku[sh_time]-$time);
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 "<li><img src='images/icons/time.png'> Шахты открыты: $key<img width='16' height='16' src='images/icons/zkl.png' alt='o'> <a href='?sh_myfarm&key'>Продлить</a> на 3 дня <img width='16' height='16' src='images/icons/zkl.png' alt='o'> 1</li>";
echo "<div><img width='16' height='16' src='images/icons/refresh.png' alt='o'> <a href='?sh_myfarm".$peremenn."&reflesh=".rand(99999,99999999)."'>Обновить</a></div>";
if($ku['hydropinics_time']>$time)echo "<li><img width='16' height='16' src='images/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='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['garden_time']>$time)echo "<li><img width='16' height='16' alt='' src='images/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='images/shaht/harvest.png' alt='o'> <a href='?sh_myfarm&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='images/shaht/fd6.png' alt='o'> <a href='?sh_myfarm&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='images/icons/water.png' alt='o'> <a href='?sh_myfarm&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='images/icons/dig.png' alt='o'> <a href='?sh_myfarm&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='images/shaht/dig.png' alt='o'> <a href='?sh_myfarm&sh_cultivator_all'>Проветрить все</a></div>";
echo "<ul>";

////ГРЯДКИ

//========================
if($ku['sh_myfarm_komp']==1){

if(isset($_GET['sh_myfarm_kompq'])){
mysql_querll('UPDATE `kolhoz_user` SET `sh_myfarm_komp`="0" WHERE `id`="'.$ku['id'].'"');
header('location:?sh_myfarm'); exit;
}

$na_vivod = 5; // Колличество сообщений на страницу
$k_post = mysql_result(mysql_querll('SELECT COUNT(`id`) FROM `kolhoz_ground_sh` WHERE `id_user`="'.$ku['id'].'"'),0);
if($k_post==0){echo 'Список пуст...';}
$k_page=k_page($k_post,$na_vivod);
$page=page($k_page);
$start=$na_vivod*$page-$na_vivod;

$sh_myfarm_komp = ' LIMIT '.$start.', '.$na_vivod;
echo '<li><a href="?sh_myfarm&sh_myfarm_kompq='.rand(1000,9999).'"><img width="16" height="16" alt="o" src="images/icons/down.png"/> Развернуть</a></li>';

}
if($ku['sh_myfarm_komp']==0){

$sh_myfarm_komp = '';

if(isset($_GET['sh_myfarm_kompp'])){
mysql_querll('UPDATE `kolhoz_user` SET `sh_myfarm_komp`="1" WHERE `id`="'.$ku['id'].'"');
header('location:?sh_myfarm'); exit;
}

echo '<li><a href="?sh_myfarm&sh_myfarm_kompp='.rand(1000,9999).'"><img width="16" height="16" alt="o" src="images/icons/up.png"/> Свернуть</a></li>';
}
//========================

$q = mysql_querll('SELECT * FROM `kolhoz_ground_sh` WHERE `id_user`="'.$ku['id'].'"'.$sh_myfarm_komp.'');
while($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?"images/shaht/dirt1_new.jpg":"images/shaht/dirt2_new.jpg")."":"images/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='images/shaht/harvest.png' alt='o'> <a href='?sh_myfarm".$peremenn."&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='images/shaht/fd6.png' alt='o'> ".(isset($ls)?"<a href='?sh_myfarm".$peremenn."&sh_soil=$post[id]&select=$ls[id]'>Дать шахтеру
<span>".hsc($ls['name'])."</span></a>, <a href='?sh_myfarm&sh_soil=$post[id]'><span>выбрать
еду</span></a>":"<a href='?sh_myfarm".$peremenn."&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='images/icons/water.png'> <a href='?sh_myfarm".$peremenn."&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='images/icons/dig.png' alt='o'> ".(isset($lp)?"<a href='?sh_myfarm".$peremenn."&sh_seat=$post[id]&select=$lp[id]'>Начать добычу <span>".hsc($lp['name'])."</span></a>, <a href='?sh_myfarm".$peremenn."&sh_seat=$post[id]'><span>выбрать ископаемое</span></a>":"<a href='?sh_myfarm".$peremenn."&sh_seat=$post[id]'>Начать добычу</a>")."":"<img width='16' height='16' src='images/shaht/dig.png' alt='o'> <a href='?sh_myfarm".$peremenn."&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)<200)echo "<li><img width='48' height='48' src='images/shaht/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='?sh_myfarm&page=end&sh_new_ground'>Купить</a> за <span class='title'><img width='16' height='16' src='images/icons/ruby.png' alt='o'><span>".razdelen(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>";

//========================
if($ku['sh_myfarm_komp']==1){
if($k_page>1){echo '<li>'; str("?sh_myfarm&",$k_page,$page); echo '</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='images/shaht/harvest.png' alt='o'> <a href='?sh_myfarm".$peremenn."&sh_change_plant'>Сменить ископаемое</a>: <span>".(isset($lp)?"".hsc($lp['name'])."":"-")."</span></li>";

echo "<li><img width='16' height='16' src='images/shaht/fd6.png' alt='o'> <a href='?sh_myfarm".$peremenn."&sh_change_soil'>Сменить еду</a>: <span>".(isset($ls)?"".hsc($ls['name'])."":"-")."</span></li>";
echo "".($ku['time_cp']>$time?"<li><img width='16' height='16' src='images/icons/cross.png' alt='o'> До бесплатной очистки: <span>".time_left($ku['time_cp']-$time)."</span></li><li><span><img width='16' height='16' src='images/icons/tick.png' alt='o'> <a href='?sh_myfarm".$peremenn."&sh_clean_grounds'><span>Очистить шахты</span></a>(<span>Стоимость</span>: <span><img width='16' height='16' src='images/icons/ruby.png' alt='o'> <span
class='title'>".($ku['count_cp']*10)."</span></span>)</span></li>":"<li><img width='16' height='16' src='images/icons/cross.png' alt='o'> <a href='?sh_myfarm&sh_clean_grounds'>Очистить шахты</a></li>")."</ul>";
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';
?>