<?
error_reporting(E_ALL^E_NOTICE);
?>
<div class="event"><h1>Ювелирная лавка</h1></div>
<?
echo "<div class='content'>";
echo "<div class='block'>";
if(isset($_GET['sh_sell_all']) && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_warehouse_sh` WHERE `id_user` = '$ku[id]'"),0)!=0)
{
	if(isset($_GET[fish]))
	{
		$fish=1;$base="fish";}else{$fish=0;$base="plant";
	}
	$q=mysql_querll("SELECT * FROM `kolhoz_warehouse_sh` WHERE `id_user` = '$ku[id]' AND `fish`='$fish'");
	$cm=0;
	while($post=mysql_fetch_array($q))
	{
		$plant=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant_sh` WHERE `id` = '$post[id_plant]'"));
		$m=floor(($plant['money']/$plant['count'])*$post['count']);
		$d=1;
		if($ku['double_res']>time())
		{
			$d=2;
		}
		$cm=floor(($cm+$m)*$d);
	}
	mysql_querll("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']+$cm)."' WHERE `id` = '$ku[id]'");
	mysql_querll("DELETE FROM `kolhoz_warehouse_sh` WHERE `id_user` = '$ku[id]' AND `fish`='$fish'");
	mysql_querll("UPDATE `kolhoz_user` SET `umoney` = '$cm' WHERE `id` = '$ku[id]'");
	//if(isset($mc) && $mc['nalog']>0)
	header("Location:?sh_warehouse&".passgen());
	exit;
}
$ant=mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_warehouse_sh` WHERE `id_user` = '$ku[id]' AND `id` = '".intval($_GET['sh_sell'])."'"), 0);
if(isset($_GET['s_sell']) && intval($_GET['s_sell'])!=NULL && $ant!==0)
{
	$pw=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_warehouse_sh` WHERE `id_user` = '$ku[id]' AND `id` = '".intval($_GET['sh_sell'])."'"));
	if(isset($_GET[fish]))
	{
		$fish=1;$base="fish";}else{$fish=0;$base="plant";
	}
	$plant=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant_sh` WHERE `id` = '$pw[id_plant]'"));
	if($plant[count]==0)
	{
		$plant[count]=1;
	}
	$d=1;
	if($ku['double_res']>time())
	{
		$d=2;
	}
	$m=floor((($plant['money']/$plant['count'])*$pw['count'])*$d);
	mysql_querll("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']+$m)."' WHERE `id` = '$ku[id]'");
	mysql_querll("DELETE FROM `kolhoz_warehouse_sh` WHERE `id` = '$pw[id]'");
	mysql_querll("UPDATE `kolhoz_user` SET `umoney` = '$m' WHERE `id` = '$ku[id]'");
	
	header("Location:?sh_warehouse&".passgen());
	exit;
}
echo "<div><h3>Витрина</h3>";
echo "<ul class='ptm'>";
$q=mysql_querll("SELECT * FROM `kolhoz_warehouse_sh` WHERE `id_user` = '$ku[id]' AND `arena` = '0' AND `fish` = '0'");
if(mysql_num_rows($q)==0)
	echo "<li>Витрина пуста</li>";
$cm=0;
while($post=mysql_fetch_array($q))
{
	$plant=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant_sh` WHERE `id` = '$post[id_plant]'"));
	$d=1;
	if($ku['double_res']>time())
	{
		$d=2;
	}
	$m=floor((($plant['money']/$plant['count'])*$post['count'])*$d);
	echo "<li><div><img width='16' height='16' src='img/shaht/harvest.png' alt='o'><span class='title'>".hsc($plant['name'])."</span> (<span>$post[count]</span>): 
	<a href='?sh_warehouse&sh_sell=$post[id]'>Продать</a> за <img width='16' height='16' src='img/icons/ruby.png' alt='o'><span>$m</span>
	</div></li>";
	$d=1;
	if($ku['double_res']>time())
	{
		$d=2;
	}
	$cm=floor(($cm+$m)*$d);
}
if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_warehouse_sh` WHERE `id_user` = '$ku[id]'"),0)!=0)
	echo "<li><img alt='*' width='16' height='16' src='img/icons/ruby.png'> <a href='?sh_warehouse&sh_sell_all'>Продать всё</a> за <img width='16' height='16' src='img/icons/ruby.png' alt='o'><span>$cm</span></li>";
echo "</ul></div>";
//echo "<div class='pt'><img width='16' height='16' src='img/icons/tomato.png' alt='*'> <a href='?sh_buy_plant'>Купить фруктов</a></div></div>";

echo "<div class='block'>";


include_once 'inc/foot.php';
?>