<?
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'])."'"));
$count=100;
$cena=floor(($plant['money']/$plant['count'])*150);
$cena=floor($cena);
if($ku['last_zadanie']==$plant['id'])
{
err_game("Это растение используется для задания! Его нельзя купить!");
} else {
if($ku['money']>=$cena)
{
$ku['money']=minus_money($cena);

$ero=mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `id_plant` = '$plant[id]' AND `arena` = '1' AND `fish` = '1' AND `garden` = '1'"), 0);



if ($ero != 0)
{

$pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `id_plant` = '$plant[id]' AND `arena` = '0' AND `fish` = '0' AND `garden` = '0'"));
$resii = $pw['count']+$count;
echo "cou ".$resii;

mysql_query("UPDATE `kolhoz_warehouse` SET `count` = '".$resii."', `shop` = '1' WHERE `id` = '$pw[id]'");
}
else 
{
mysql_query("INSERT INTO `kolhoz_warehouse` SET `id_plant` = '$plant[id]', `id_user`  = '$ku[id]', `count` = '$count', `arena` = '0', `shop` = '1'");
}
msg_game('Товар успешно куплен.');
}
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']/$post['count'])*150);
$cena=floor($cena);
echo "<li style='padding-bottom:8px'><div><img width='16' height='16' src='images/icons/tomato.png' alt='o'> ".($post['level']<=$ku['level']?"<a href='?buy_plant&select=$post[id]&page=$page'>":"<span>")."".hsc($post['name'])."".($post['level']<=$ku['level']?"</a>":"</span>")."<span class='small minor'>, <span>100</span> шт., цена: <img width='16' height='16' src='images/icons/money.png' alt='o'><span>$cena</span></span></div></li>";
}
echo "</ul>";
if ($k_page>1)str("?buy_plant&",$k_page,$page); // Вывод страниц
echo "</div>";
include_once 'inc/foot.php';
?>