<?
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_plant2` WHERE `id` = '".intval($_GET['select'])."' AND (`level` < '$ku[level]' OR `level` = '$ku[level]')"),0)!=0)
{
$plant2=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '".intval($_GET['select'])."'"));
$count=100;
$cena=(($plant2['cena']*$count)/100)*115;
$cena=floor($cena);
if($ku['money']>=$cena)
{
$ku['money']=minus_money($cena);
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_market` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '$plant2[id]' AND `arena` = '0'"),0)!=0)
{
$pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_market` WHERE `id_user` = '$ku[id]' AND `id_plant2` = '$plant2[id]' AND `arena` = '0'"),0);
mysql_query("UPDATE `kolhoz_market` SET `count` = '".($pw['count']+$count)."' WHERE `id` = '$pw[id]'");
}
else mysql_query("INSERT INTO `kolhoz_market` SET `id_plant2` = '$plant2[id]', `id_user`  = '$ku[id]', `count` = '$count', `arena` = '0'");
msg_game('Рецепт выбран');
}
else
{
no_money($cena-$ku['money']);
}
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant2`"),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_plant2` ORDER BY `level` ASC LIMIT $start, 10");
echo "<ul>";
while($post=mysql_fetch_array($q))
{
$count=100;
$cena=(($post['cena']*$count)/100)*115;
$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_plant2&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_plant2&",$k_page,$page); // Вывод страниц
echo "</div>";
include_once 'inc/foot.php';
?>