<?
echo "<div class='input_button'><center>Магазин овощей</center></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;
$count2=100*10;
$cena=floor(($plant['money']/$plant['count'])*150);
$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]' AND `arena` = '0'"),0)!=0)
{
$pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `id_plant` = '$plant[id]' AND `arena` = '0'"),0);
mysql_query("UPDATE `kolhoz_warehouse` SET `count` = '".($pw['count']+$count)."' WHERE `id` = '$pw[id]'");
}
else mysql_query("INSERT INTO `kolhoz_warehouse` SET `id_plant` = '$plant[id]', `id_user`  = '$ku[id]', `count` = '$count', `arena` = '0'");
msg_game('Товар успешно куплен.');
}
else
{
no_money($cena-$ku['money']);
}
}
if(isset($_GET['select2']) && intval($_GET['select2'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant` WHERE `id` = '".intval($_GET['select2'])."' AND (`level` < '$ku[level]' OR `level` = '$ku[level]')"),0)!=0)
{
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '".intval($_GET['select2'])."'"));
$count2=100*10;
$cena2=floor(($plant['money']/$plant['count'])*150*10);
$cena2=floor($cena2);
if($ku['money']>=$cena2)
{
$ku['money']=minus_money($cena2);
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `id_plant` = '$plant[id]' AND `arena` = '0'"),0)!=0)
{
$pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_warehouse` WHERE `id_user` = '$ku[id]' AND `id_plant` = '$plant[id]' AND `arena` = '0'"),0);
mysql_query("UPDATE `kolhoz_warehouse` SET `count` = '".($pw['count']+$count2)."' WHERE `id` = '$pw[id]'");
}
else mysql_query("INSERT INTO `kolhoz_warehouse` SET `id_plant` = '$plant[id]', `id_user`  = '$ku[id]', `count` = '$count2', `arena` = '0'");
msg_game('Товар успешно куплен.');
}
else
{
no_money($cena2-$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);
$count2=100*10;
$cena2=floor(($post['money']/$post['count'])*150*10);
$cena2=floor($cena2);
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><div><img width='16' height='16' src='images/icons/tomato.png' alt='o'> ".($post['level']<=$ku['level']?"<a href='?buy_plant&select2=$post[id]&page=$page'>":"<span>")."".hsc($post['name'])."".($post['level']<=$ku['level']?"</a>":"</span>")."<span class='small minor'>, <span>1000</span> шт., цена: <img width='16' height='16' src='images/icons/money.png' alt='o'><span>$cena2</span></span></div></li>";

}
echo "</ul>";
if ($k_page>1)str("?buy_plant&",$k_page,$page); // Вывод страниц
echo "</div>";
include_once 'inc/foot.php';
?>