<?
if(isset($_GET['mywork']) && isset($_GET['seat']) && intval($_GET['seat'])!=NULL && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_mest` WHERE `id` = '".intval($_GET['seat'])."' AND `id_user` = '$ku[id]' AND `id_plant` = '0' AND `cultivator` = '1'"),0)!=0)
{
echo '<div class="event"><h1>Работы</h1></div>';
echo "<div class='content'>";
echo "<div class='block'>";
$ground=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_mest` WHERE `id` = '".intval($_GET['seat'])."' AND `id_user` = '$ku[id]'"));
if(isset($_GET['select']) && intval($_GET['select'])!=NULL && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_works` WHERE `id` = '".intval($_GET['select'])."' AND (`level` = '$ku[level]' OR `level` < '$ku[level]')"),0)!=0)
{
$plant=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_works` WHERE `id` = '".intval($_GET['select'])."'"));
if($ku['rubies']>=$plant['cena'])
{
$money=$plant['cena'];
$rat=$plant['rating'];
$rat_sc_act=0;
$rat_drakon_act=0;
$rat_seeder_act=0;
$rat_school_act=0;
$rat_lib_act=0;
/*
if(isset($sc_act)){$rat_sc_act=$rat*2;
if(isset($vtr_act))$rat_sc_act=$rat*2*4;}else{
if(isset($vtr_act))$rat_sc_act=$rat*4;
}
*/


//Ветряк
if(isset($sc_act)){$rat_sc_act=$rat*2;
if(isset($vtr_act))$rat_sc_act=$rat*2*4;}else{
if(isset($vtr_act))$rat_sc_act=$rat*4;
}
//Ветряк




if(isset($drakon_act))$rat_drakon_act=(($plant['rating']/100)*300);
if(isset($seeder_act))$rat_seeder_act=(($rat/100)*$seeder_act);
if(isset($school_act))$rat_school_act=$rat*2;
if(isset($lib_act))$rat_lib_act=$rat/2;
if(isset($shmel_act))$rat_seeder_act=$rat_seeder_act*2;
$ratt=$rat_drakon_act+$rat_sc_act+$rat_seeder_act+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;

mysql_querll("UPDATE `kolhoz_mest` SET `id_plant` = '$plant[id]', `time_soil` = '".($time+$plant['time_soil'])."', `time_water` = '".($time+120)."', `soil` = '0', `time` = '".($plant['time']+$time)."' WHERE `id` = '$ground[id]' LIMIT 1");
$ku['rubies']=minus_rubies($money);
mysql_querll("UPDATE `kolhoz_user` SET `last_work` = '$plant[id]' WHERE `id` = '$ku[id]'");
mysql_querll("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$rat)."' WHERE `id` = '$ku[id]'");
$_SESSION['rating']=$rat;
update_mc($rat);
}
else
{
$nm=$plant['cena']-$ku['rubies'];
$_SESSION['no_rubies']=$nm;
}
header("Location:?mywork&".passgen());
exit;
}
$k_post = mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_works`"),0);
if ($k_post==0)
{
echo "Пока работ нет...";
}
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_querll("SELECT * FROM `kolhoz_works` ORDER BY `level` ASC LIMIT $start, $set[p_str]");
echo "<ul>";
while($post=mysql_fetch_array($q))
{
echo "<li style='padding-bottom:8px'>"; 
echo "<div class='small'>";

echo "".($ku['level']>=$post['level']?"<a href='?mywork&seat=$ground[id]&select=$post[id]'>":null)."<span>".hsc($post['name'])."</span>".($ku['level']>=$post['level']?"</a>":null)." <span class='minor'>$post[work]<br> ".($ku['level']>=$post['level']?"<img width='16' height='16' src='img/icons/ruby.png' alt='o'> Затраты: </span><span><img width='16' height='16' src='img/icons/ruby.png' alt='o'><span class='title'>$post[cena]</span></span>":"доступно с $post[level] уровня</span>")."
<br><img width='16' height='16' src='img/icons/money.png' alt='o'> <span class='small minor'>Доход монет:</span> <img width='16' height='16' src='img/icons/money.png' alt='o'> <span class='title'>$post[money]</span>";
//echo "<br><img width='16' height='16' src='img/icons/zkl.png' alt='o'> <span class='small minor'>Доход ключей:</span> <img width='16' height='16' src='img/icons/zkl.png' alt='o'> <span class='title'>$post[zkl]</span></div>";

echo "<div class='small minor'> <img width='16' height='16' src='img/icons/time.png' alt='o'> Время работы: <span class='title'>".time_left($post['time'])."</span><br>
<img width='16' height='16' src='img/icons/experience.png' alt='o'> Опыт(аванс): <span class='title'> $post[rating]</span></span></div></li>";
}

if ($k_page>1)str("?mywork&seat=$ground[id]&",$k_page,$page); // Вывод страниц
include_once 'inc/foot.php';
}
?>