<?php
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';

$int=intval($_GET['id']);
$set['title']='Моя ферма! - Склад';
include_once '../sys/inc/thead.php';
title();
err();
if(isset($_GET['sell_ok']))msg('Продано!');
aut();

include 'inc/str.php';

if(isset($_GET['id'])){
$post=mysql_fetch_array(mysql_query("select * from `fermer_sclad` WHERE `id`= '$_GET[id]' LIMIT 1"));
$semen=mysql_fetch_array(mysql_query("select * from `fermer_name` WHERE  `id` = '$post[semen]'  LIMIT 1"));
$dohod=$post['kol']*$semen['dohod'];
if(isset($_GET['sell']))
{
mysql_query("UPDATE `user` SET `fermer_money` = `fermer_money`+ $dohod WHERE `id` = $user[id] LIMIT 1");
mysql_query("DELETE FROM `fermer_sclad` WHERE `id` = $_GET[id] ");
header('Location: storage.php?sell_ok');
}
echo "<img src='img/$post[semen].gif' alt=''><br/>f <b>".$semen['name']."</b><br/>";
echo " Количество урожая: <b>".$post['kol']."</b> <br/>";
echo " Цена за единицу: <b>".$semen['dohod']."</b> <br/>";

echo " Общий доход: <b>".$dohod."</b> <br/>";

echo "<form method='post' action='?id=".$int."&sell'>\n";
echo "<input type='submit' name='save' value='Продать!' />\n";
echo "</form>\n";
echo "<div class='foot'>";
echo " <a href='storage.php'>Склад</a><br/>";
echo "</div>";

}else{

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `fermer_sclad` WHERE `id_user` = '$user[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

if($k_post==0){echo "<div class='block'>На складе товаров нет</div>";}

$res = mysql_query("select * from `fermer_sclad` WHERE `id_user` = '$user[id]' LIMIT $start, $set[p_str];");

while ($post = mysql_fetch_array($res)){
$semen=mysql_fetch_array(mysql_query("select * from `fermer_name` WHERE  `id` = '$post[semen]'  LIMIT 1"));

echo "<img src='img/$post[semen].gif' height='20' width='20'><b>f</b> <a href='?id=$post[id]'>".$semen['name']."</a> [".$post['kol']."] ";
echo "(<a href='?id=$post[id]&sell'><span class='off'>Продать!</span></a>)<br />";
}



if ($k_page>1)str('?',$k_page,$page); // Вывод страниц
}
echo "<div class='foot'>";
echo " <a href='index.php'>Назад</a><br/>";
echo "</div>";

include_once '../sys/inc/tfoot.php';

?>

