<?php
/*
Автор скрипта: RooD
ICQ: 8428023
Скрипт нельзя 
кидать в паблик, 
барыжить(продавать) им, 
давать друзьям!
*/
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']='Моя ферма! - Склад';
error_reporting (0);
include_once '../sys/inc/thead.php';
title();
err();
if(isset($_GET['sell_ok']))msg('Продано!');
aut();
//header("Content-type: application/vnd.wap.xhtml+xml");
header("Content-type: text/html");
echo "<link rel='stylesheet' href='style.css' type='text/css' /><center>";
echo "<div class='grad32'><img src='fermer.gif'></div><div class='ferm3'><img src='warehouse.gif'><br/><div class='grad16'>Склад</div>";

include 'inc/str.php';
echo"</div></center><div class='ferm3'>";
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/>&raquo; <b>".$semen['name']."</b><br/>";
echo "&raquo; Количество урожая: <b>".$post['kol']."</b> <br/>";
echo "&raquo; Цена за единицу: <b>".$semen['dohod']."</b> <br/>";

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

echo "<form method='post' action='?id=".$int."&amp;sell'>\n";
echo "<input type='submit' name='save' value='Продать!' />\n";
echo "</form>\n";
echo "<div class='foot'>";
echo "&laquo; <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='30' width='30'><b> </b> <a href='?id=$post[id]'>".$semen['name']."</a> [".$post['kol']."] ";
echo "(<a href='?id=$post[id]&amp;sell'><span class='off'>Продать!</span></a>)<br />";
}



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

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

?>