<?php
if(isset($_GET['gos']))
{
if(isset($mc))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `$db_base`.`kolhoz_works` WHERE `id` = '$gos[id_plant]' AND (`level` = '$ku[level]' OR `level` < '$ku[level]')"),0)!=0)
mysql_query("UPDATE `$db_base`.`kolhoz_user` SET `last_plant` = '$gos[id_plant]' WHERE `id` = '$ku[id]'");
header("Location:?mywork");
exit;
}
else err_game("Для начала вступите в колхоз.");
}

include_once 'inc/mywork/arend.php';
include_once 'inc/mywork/money_work.php';
include_once 'inc/mywork/works_seat.php';


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

if ($ku['komp']==0){
echo "<div class='event'><h1>Работа
<a href='?mywork&komp'><img title='Компактный вид' width='16' height='16' src='images/icons/down.png' alt='o'></a>

<a href='?mywork&reflesh=".rand(99999,99999999)."'><img title='Обновить' width='16' height='16' src='images/icons/refresh.png' alt='o'></a>&nbsp; ";
if($ku['hydropinics_time']>$time)echo "<a class='epic' href='?shop=hydropinics'><img title='Гидропоника' width='16' height='16' src='images/icons/hydropinics.png' alt='o'></a>&nbsp; ";
if($ku['scarecrow_time']>$time)echo "<a class='epic' href='?shop=scarecrow'><img title='Пугало' width='16' height='16' src='images/icons/scarecrow.png' alt='o'></a>&nbsp; ";
if($ku['time_shmel']>$time)echo "<a href='?shop=helicopter&1'><img title='Шмель' width='16' height='16' alt='o' src='images/icons/heli1n.png'></a>&nbsp; ";
if($ku['time_yastreb']>$time)echo "<a class='epic' href='?shop=helicopter&2'><img title='Ястреб' width='16' height='16' alt='o' src='images/icons/heli2n.png'></a>&nbsp; ";
if($ku['time_drakon']>$time)echo "<a class='epic' href='?shop=helicopter&3'><img title='Дракон' width='16' height='16' alt='o' src='images/icons/heli3n.png'></a> ";
echo "</h1></div>";}


if ($ku['komp']==1){
echo "<div><h1>Работа</h1></div><div class='content'>";
echo "<div class='block'> <img width='16' height='16' src='images/icons/refresh.png' alt='o'> <a href='?mywork&reflesh=".rand(99999,99999999)."'>Обновить</a>";

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'><span> $ku[hydropinics_type]%</span> на <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>";

echo "<li><a href='?mywork&komp'><img width='16' height='16' src='images/icons/up.png' alt='o'> Компактный вид</a></li>";
echo "</div></div>";
}




echo "<div class='content'>";
echo "<div class='block'>";

/*echo "<div><img width='16' height='16' src='images/icons/refresh.png' alt='o'> <a href='?mywork&reflesh=".rand(99999,99999999)."'>Обновить</a></div>";
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_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>";
*/
echo "<ul>";

////ГРЯДКИ


$q=mysql_query("SELECT * FROM `$db_base`.`kolhoz_mest` WHERE `id_user` = '$ku[id]'");
while($post=mysql_fetch_array($q))
{
echo "<li>";
if($post['id_plant']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `$db_base`.`kolhoz_works` WHERE `id` = '$post[id_plant]'"),0)!=0)$plant=mysql_fetch_array(mysql_query("SELECT * FROM `$db_base`.`kolhoz_works` WHERE `id` = '$post[id_plant]'"));

echo "<li><img width='48' height='48' src='".(!isset($plant)?"".($post['cultivator']==1?"images/work.png":"images/work.png")."":"images/works/$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'> <br/>(Конец работы через <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/icons/money.png' alt='o'> <a href='?mywork&harvest=$post[id]'>Получить оплату</a>";
}
}
else
{
echo "<span>";
if($ku['last_work']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `$db_base`.`kolhoz_works` WHERE `id` = '$ku[last_work]'"),0)!=0)$lp=mysql_fetch_array(mysql_query("SELECT * FROM `$db_base`.`kolhoz_works` WHERE `id` = '$ku[last_work]'"));
echo "".($post['cultivator']==1?"<img width='16' height='16' src='images/icons/tick.png' alt='o'> ".(isset($lp)?"<a href='?mywork&seat=$post[id]&select=$lp[id]'><span>".hsc($lp['name'])."</span></a>, <a href='?mywork&seat=$post[id]'><span>другая работа</span></a>":"<a href='?mywork&seat=$post[id]'> выбрать</a>")."":"<img width='16' height='16' src='images/icons/arend.png' alt='o'> <a href='?mywork&cultivator=$post[id]'><span style='title'>Готов!</span></a>")."";
echo "</span>";
}
if(isset($plant))unset($plant);
echo "</div><div style='clear:both'></div></li>";
include_once 'inc/foot.php';
}
//echo "</ul>";
//if($ku['last_plant']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `$db_base`.`kolhoz_works` WHERE `id` = '$ku[last_plant]'"),0)!=0)$lp=mysql_fetch_array(mysql_query("SELECT * FROM `$db_base`.`kolhoz_works` WHERE `id` = '$ku[last_plant]'"));

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `$db_base`.`kolhoz_mest` WHERE `id_user` = '$ku[id]'"),0)<6)echo "<li><img width='48' height='48' src='images/work_clean.gif' 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='?mywork&new_work'>Купить</a> за <span class='title'><img width='16' height='16' src='images/icons/ruby.png' alt='o'><span>".cpw(mysql_result(mysql_query("SELECT COUNT(*) FROM `$db_base`.`kolhoz_mest` WHERE `id_user` = '$ku[id]'"),0))."</span> рубинов</span></div><div style='clear:both'></div></li>";
 if(isset($mc))
{
echo '<br><li><img width="16" height="16" src="images/icons/heli4n.png" alt="o"> <a href="?collective='.$mc['id'].'&hangar">Вызвать вертолеты</a></li>';
}
include_once 'inc/foot.php';
?>