<?
echo "<div class='event'><h1>Магазин овощей</h1></div>";
echo "<div class='content'>";
echo "<div class='block'>";
if(isset($_GET['select']) && intval($_GET['select'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant` WHERE `id` = '".intval($_GET['select'])."' AND (`level` < '$ku[level]' OR `level` = '$ku[level]')"),0)!=0)
{
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '".intval($_GET['select'])."'"));
if(isset($_GET['1000'])){$procien=1500;$count=1000;} else {$procien=150;$count=100;}
$cena=floor(($plant['money'])*$procien);
$cena=floor($cena);
if($ku['money']>=$cena)
{
$ku['money']=minus_money($cena);
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `id_plant` = '$plant[id]'"),0)!=0)
{
$pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `id_plant` = '$plant[id]'"));
mysql_query("UPDATE `kolhoz_warehouse` SET `amount` = '".($pw['amount']+$count)."' WHERE `id` = '$pw[id]'");
}
else mysql_query("INSERT INTO `kolhoz_warehouse` SET `id_plant` = '$plant[id]', `id_user`  = '$ku[id]', `amount` = '$count'");
$_SESSION['msg'] = 'Товар успешно куплен.';
header("Location: /buy_plant/page-".(intval($_GET['page']))."");
}
else
{
no_money($cena-$ku['money']);
}
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant`"),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_plant` ORDER BY `level` ASC LIMIT $start, 10");
echo "<ul>";
while($post=mysql_fetch_array($q))
{
$count=100;
$cena=floor(($post['money'])*200);
$cena=floor($cena);
$cena2=floor(($post['money'])*2000);
echo "<li style='padding-bottom:8px'><img width='16' height='16' src='images/icons/tomato.png' alt='*'> ".($post['level']<=$ku['level']?"<a href='/buy_plant/select-$post[id]/page-$page'>":"<span>")."".hsc($post['name'])."".($post['level']<=$ku['level']?"</a><span class='small minor'>, <span>100</span> шт., цена: <img width='16' height='16' src='images/icons/money.png' alt='o'><span>$cena</span></span>":"</span><span class='small minor'> доступно с $post[level] уровня</span>")."".($post['level']>=19?"<img width='16' height='16' src='images/icons/arena_type_$post[type].png' alt='*'>":null)."<br/>";
echo "<img width='16' height='16' src='images/icons/tomato.png' alt='*'> ".($post['level']<=$ku['level']?"<a href='/buy_plant/select-$post[id]/page-$page/1000'>":"<span>")."".hsc($post['name'])."".($post['level']<=$ku['level']?"</a><span class='small minor'>, <span>1000</span> шт., цена: <img width='16' height='16' src='images/icons/money.png' alt='o'><span>$cena2</span></span>":"</span><span class='small minor'> доступно с $post[level] уровня</span>")."".($post['level']>=19?"<img width='16' height='16' src='images/icons/arena_type_$post[type].png' alt='*'>":null)."</li>";
}
echo "</ul>";
if ($k_page>1)new_str("buy_plant/",$k_page,$page); // Вывод страниц
echo "</div>";
include_once 'inc/foot.php';
?>