<?
if(isset($_GET['mygarden']) && isset($_GET['iseat']) && intval($_GET['iseat'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_sad` WHERE `id` = '".intval($_GET['iseat'])."' AND `id_user` = '$ku[id]' AND `id_tree` = '0' AND `plug` = '1'"),0)!=0)
{
echo '<div class="event"><h1>Магазин саженцев</h1></div>';
echo "<div class='content'>";
echo "<div class='block'>";
$sad=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_sad` WHERE `id` = '".intval($_GET['iseat'])."' AND `id_user` = '$ku[id]'"));
if(isset($_GET['select']) && intval($_GET['select'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_tree` WHERE `id` = '".intval($_GET['select'])."' AND (`level` = '$ku[level]' OR `level` < '$ku[level]')"),0)!=0)
{
$tree=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_tree` WHERE `id` = '".intval($_GET['select'])."'"));
if(!empty($tree['rcena'])){$rubas='rubies';$cetos='rcena';}else{$rubas='money';$cetos='cena';}
if($ku['$rubas']>=$tree['$cetos'])
{
$money="$tree[$cetos]";
if(isset($seeder_act_skid))
{
$money=floor($money-(($money/100)*$seeder_act_skid));
}
/*
$rat=$tree['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($drakon_act))$rat_drakon_act=(($tree['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;

if($gos['id_tree']==$tree['id'] && $gos['type']=='rating' && isset($mc))$rat=$rat*2;*/
mysql_query("UPDATE `kolhoz_sad` SET `id_tree` = '$tree[id]', `time_soil` = '".($time+120)."', `time_sbor` = '".($time+7200)."', `soil` = '0', `time` = '".($tree['time']+$time)."' WHERE `id` = '$sad[id]' LIMIT 1");
mysql_query("UPDATE `kolhoz_user` SET `$rubas` = '$ku[$rubas]'-'$money' WHERE `id` = '$ku[id]'");
//mysql_query("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$rat)."' WHERE `id` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `last_tree` = '$tree[id]' WHERE `id` = '$ku[id]'");
$_SESSION['rating']=$rat;
update_mc($rat);
}
else
{
$nm=$tree['$cetos']-$ku['$rubas'];
$_SESSION['no_$rubas']=$nm;
}
header("Location:?mygarden&".passgen());
exit;
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_tree`"),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_query("SELECT * FROM `kolhoz_tree` ORDER BY `level` ASC LIMIT $start, $set[p_str]");
echo "<ul>";
while($post=mysql_fetch_array($q))
{
echo "<li style='padding-bottom:8px'>";
echo "<img width='48' height='48' src='images/tree/$post[id].png' alt='o' class='portrait'>";
echo "<div class='small'>";
echo "".($ku['level']>=$post['level']?"<a href='?mygarden&change_tree&select=$post[id]'>":null)."<span>".hsc($post['name'])."</span>".($ku['level']>=$post['level']?"</a>":null)." <span class='minor'>, ".($ku['level']>=$post['level']?"цена: </span><span>".(empty($post['rcena'])?"<img width='16' height='16' src='images/icons/money.png' alt='o'><span class='title'> $post[cena]":"<img width='16' height='16' src='images/icons/ruby.png' alt='o'><span class='title'> $post[rcena]")."</span></span>":"доступно с $post[level] уровня</span>")."</div><div class='small minor'> Продукция: <span class='title'>$post[count] кг.</span> /  
<span class='title'>".time_left($post['time'])."</span><br>Доход: <img width='16' height='16' src='images/icons/money.png' alt='o'> <span>$post[money]</span>, Опыт: <img width='16' height='16' src='images/icons/experience.png' alt='o'> <span>$post[rating]</span>. </div></li>";
}
echo "</ul>";
if ($k_page>1)str("?mygarden&iseat=$sad[id]&",$k_page,$page); // Вывод страниц
echo "</div>";
include_once 'inc/foot.php';
}
?>