<?php
if(isset($_GET['mycellar']) && isset($_GET['soil_all2']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `$db_base`.`kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `soil2` = '0' AND (`time_soil2` = '$time' OR `time_soil2` < '$time') AND `id_plant2` != '0' AND `time` > '$time'"),0)!=0 && $ku['soiler2']>0)
{
echo '<div class="event"><h1>Магазин удобрений</h1></div>';
echo "<div class='content'>";
echo "<div class='block'>";
if($ku['last_soil']!=0)
{
$soil2=mysql_fetch_array(mysql_query("SELECT * FROM `$db_base`.`kolhoz_soil2` WHERE `id` = '$ku[last_soil2]'"));
$cg=mysql_result(mysql_query("SELECT COUNT(*) FROM `$db_base`.`kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `soil2` = '0' AND (`time_soil2` = '$time' OR `time_soil2` < '$time') AND `id_plant2` != '0' AND `time` > '$time'"),0);
$sc=$cg*$soil2['cena'];
if($ku['money']>=$sc)
{
$rat=$soil2['rating'];
$rat_sc_act=0;
$rat_hp_act=0;
$rat_mc_hp_act=0;
$rat_drakon_act=0;
$rat_soiler2_act=0;
$rat_school_act=0;
$rat_lib_act=0;
if(isset($hp_act))$rat_hp_act=(($rat/100)*$hp_ps);
if(isset($mc_hp_act))$rat_mc_hp_act=(($rat/100)*$mc_hp_ps);
if(isset($sc_act))$rat_sc_act=$rat*2;
if(isset($drakon_act))$rat_drakon_act=(($rat/100)*300);
if(isset($soiler2_act))$rat_soiler2_act=(($rat/100)*$soiler2_act);
if(isset($school_act))$rat_school_act=$rat*2;
if(isset($lib_act))$rat_lib_act=$rat/2;
if(isset($shmel_act))$rat_soiler2_act=$rat_soiler2_act*2;
if(isset($shmel_act))$rat_hp_act=$rat_hp_act*2;
$ratt=$rat_mc_hp_act+$rat_sc_act+$rat_hp_act+$rat_drakon_act+$rat_soiler2_act+$rat_school_act+$rat_lib_act;
if($ratt==0)$rat=$rat;
else $rat=$ratt;
if(isset($dexp))$rat=$rat*2;

$st=$soil2['time'];
$st_hp_act=0;
$st_mc_hp_act=0;
$st_soiler2_act=0;
if(isset($hp_act))$st_hp_act=($st/100)*$hp_ps;
if(isset($mc_hp_act))$st_mc_hp_act=($st/100)*$mc_hp_ps;
if($soiler2_act)$st_soiler2_act=($st/100)*$soiler2_act;
$st=$st_hp_act+$st_soiler2_act+$st+$st_mc_hp_act;

$q=mysql_query("SELECT * FROM `$db_base`.`kolhoz_polka2` WHERE `id_user` = '$ku[id]' AND `soil2` = '0' AND (`time_soil2` = '$time' OR `time_soil2` < '$time') AND `id_plant2` != '0' AND `time` > '$time'");
$orat=0;
$vc=0;
while($post=mysql_fetch_array($q))
{
$orat=$orat+$rat;
mysql_query("UPDATE `$db_base`.`kolhoz_polka2` SET `time` = '".($post['time']-$st)."', `soil2` = '1' WHERE `id` = '$post[id]' LIMIT 1");
$vc=$vc+1;
}
mysql_query("UPDATE `$db_base`.`kolhoz_user` SET `agronom` = '".($ku['agronom']+$vc)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `$db_base`.`kolhoz_user` SET `money` = '".($ku['money']-$sc)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `$db_base`.`kolhoz_user` SET `rating` = '".($ku['rating']+$orat)."' WHERE `id` = '$ku[id]'");
$_SESSION['rating']=$orat;
update_mc($orat);
}
else $_SESSION['no_money']=$sc-$ku['money'];
header("Location:?mycellar&".passgen());
exit;
}
if(isset($_GET['select']) && intval($_GET['select'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `$db_base`.`kolhoz_soil2` WHERE `id` = '".intval($_GET['select'])."' AND (`level` = '$ku[level]' OR `level` < '$ku[level]')"),0)!=0)
{
mysql_query("UPDATE `$db_base`.`kolhoz_user` SET `last_soil2` = '".intval($_GET['select'])."' WHERE `id` = '$ku[id]'");
header("Location:?mycellar&soil_all2");
exit;
}
echo "<h3>Выбери Удобрение</h3>";
$q=mysql_query("SELECT * FROM `$db_base`.`kolhoz_soil2`");
echo "<ul>";
while($post=mysql_fetch_array($q))
{
echo "<li style='padding-bottom:8px'>";
echo "<img width='48' height='48' src='images/soils/$post[id].png' alt='o' class='portrait'><div>".($ku['level']>=$post['level']?"<a href='?mycellar&soil_all2&select=$post[id]'>":null)."<span>".hsc($post['name'])."</span>".($ku['level']>=$post['level']?"</a>":null)."<span class='minor'>, ".($ku['level']>=$post['level']?"цена: </span><span><img width='16' height='16' src='images/icons/money.png' alt='o'><span class='title'>$post[cena]</span></span>":"доступно с $post[level] уровня</span>")."</div><div class='minor small'>Ускоряет рост на <span class='title'>".time_left($post['time'])."</span>,опыт: <img width='16' height='16' src='images/icons/experience.png' alt='o'> <span class='title'>$post[rating]</span></div><div style='clear:both'></div></li>";
}
echo "</ul></div>";
include_once 'inc/foot.php';
}
?>