<?PHP
$_OPTIMIZATION["title"] = "Аккаунт - Торговая лавка";
$usid = $_SESSION["user_id"];
$usname = $_SESSION["user"];

$db->Query("SELECT * FROM db_users_b WHERE id = '$usid' LIMIT 1");
$user_data = $db->FetchArray();

$db->Query("SELECT * FROM db_config WHERE id = '1' LIMIT 1");
$sonfig_site = $db->FetchArray();

?>
<div class="cl-right">
<div class="s-bk-lf">
	<div class="hst-title">Торговая лавка</div>
</div>
Торговая лавка позволит вам продать все ваши фрукты за серебро, которое можно обменять на реальные 
деньги. Вырученное с продажи серебро распределяется между двумя счетами (счет для покупок и счет 
для вывода) в пропорциях: <?=100-$sonfig_site["percent_sell"]; ?>% на счет для покупок и <?=$sonfig_site["percent_sell"]; ?>% на вывод.<br /><br />
Курс продажи любых плодов: <font color="#f59f97"><?=$sonfig_site["items_per_coin"]; ?> продукции = 1 серебро.</font>
<div class="clr"></div><BR />
<?PHP
# Продажа
if(isset($_POST["sell"])){

$all_items = $user_data["a_b"] + $user_data["b_b"] + $user_data["c_b"] + $user_data["d_b"] + $user_data["e_b"];

	if($all_items > 0){
	
		$money_add = $func->SellItems($all_items, $sonfig_site["items_per_coin"]);
		
		$tomat_b = $user_data["a_b"];
		$straw_b = $user_data["b_b"];
		$pump_b = $user_data["c_b"];
		$pean_b = $user_data["d_b"];
		$peas_b = $user_data["e_b"];
		
		$money_b = ( (100 - $sonfig_site["percent_sell"]) / 100) * $money_add;
		$money_p = ( ($sonfig_site["percent_sell"]) / 100) * $money_add;
		
		# Обновляем юзверя
		$db->Query("UPDATE db_users_b SET money_b = money_b + '$money_b', money_p = money_p + '$money_p', a_b = 0, b_b = 0, c_b = 0, d_b = 0, e_b = 0 
		WHERE id = '$usid'");
		
		$da = time();
		$dd = $da + 60*60*24*15;
		
		# Вставляем запись в статистику
		$db->Query("INSERT INTO db_sell_items (user, user_id, a_s, b_s, c_s, d_s, e_s, amount, all_sell, date_add, date_del) VALUES 
		('$usname','$usid','$tomat_b','$straw_b','$pump_b','$pean_b','$peas_b','$money_add','$all_items','$da','$dd')");
		
		echo "<center><font color = 'green'><b>Вы продали {$all_items} плодов, на сумму {$money_add} серебра</b></font></center><BR />";
		
		$db->Query("SELECT * FROM db_users_b WHERE id = '$usid' LIMIT 1");
		$user_data = $db->FetchArray();
		
	}else echo "<center><font color = 'red'><b>Вам нечего продавать :(</b></font></center><BR />";

}
?>	       




<form action="" method="post">
<table align="center">
	<tbody><tr>
		<td align="center">
		<div class="rinokdiv">
		<table>
			<tbody><tr>
				<td align="center"><span class="h-ferm">Яйца</span><br></td>
			</tr>
			<tr>
				<td align="center" valign="center" height="80"><img src="/img/zver/ico.png"></td>
			</tr>
			<tr>
				<td align="center"><span class="h-ferm"><?=$user_data["a_b"]; ?></span></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td align="center"><span class="naz">На сумму:</span><br>
				<table>
					<tbody><tr>
						<td><img src=""></td>
						<td valign="middle"><span class="naz"><?=$func->SellItems($user_data["a_b"], $sonfig_site["items_per_coin"]); ?></span></td>
					</tr>
				</tbody></table>
				</td>
			</tr>

		</tbody></table>
		</div>
		</td>


		<td align="center">
		<div class="rinokdiv">
		<table>
			<tbody><tr>
				<td align="center"><span class="h-ferm">Свинина</span><br></td>
			</tr>
			<tr>
				<td align="center" valign="center" height="80"><img src="/img/zver/maso.png"></td>
			</tr>
			<tr>
				<td align="center"><span class="h-ferm"><?=$user_data["b_b"]; ?></span></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td align="center"><span class="naz">На сумму:</span><br>
				<table>
					<tbody><tr>
						<td><img src=""></td>
<td valign="middle"><span class="naz"><?=$func->SellItems($user_data["b_b"], $sonfig_site["items_per_coin"]); ?></span></td>
					</tr>
				</tbody></table>
				</td>
			</tr>

		</tbody></table>
		
		</div>
		</td>


		<td align="center">
		<div class="rinokdiv">
		<table>
			<tbody><tr>
				<td align="center"><span class="h-ferm">Молоко</span><br></td>
			</tr>
			<tr>
				<td align="center" valign="center" height="80"><img src="/img/zver/moloko.png"></td>
			</tr>
			<tr>
				<td align="center"><span class="h-ferm"><?=$user_data["c_b"]; ?></span></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td align="center"><span class="naz">На сумму:</span><br>
				<table>
					<tbody><tr>
						<td><img src=""></td>
						<td valign="middle"><span class="naz"><?=$func->SellItems($user_data["c_b"], $sonfig_site["items_per_coin"]); ?></span></td>
					</tr>
				</tbody></table>
				</td>
			</tr>

		</tbody></table>
		</div>
		</td>
	</tr>
</tbody></table>

<table align="center">
	<tbody><tr>
		<td align="center">
		<div class="rinokdiv">
		<table>
			<tbody><tr>
				<td align="center"><span class="h-ferm">Шерсть</span><br></td>
			</tr>
			<tr>
				<td align="center" valign="center" height="80"><img src="/img/zver/vata.png"></td>
			</tr>
			<tr>
				<td align="center"><span class="h-ferm"><?=$user_data["d_b"]; ?></span></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td align="center"><span class="naz">На сумму:</span><br>
				<table>
					<tbody><tr>
						<td><img src=""></td>
						<td valign="middle"><span class="naz"><?=$func->SellItems($user_data["d_b"], $sonfig_site["items_per_coin"]); ?></span></td>
					</tr>
				</tbody></table>
				</td>
			</tr>

		</tbody></table>
		</div>
		</td>

	
		<td align="center">
		<div class="rinokdiv">
		<table>
			<tbody><tr>
				<td align="center"><span class="h-ferm">Говядина</span><br></td>
			</tr>
			<tr>
				<td align="center" valign="center" height="80"><img src="/img/zver/masog.png"></td>
			</tr>
			<tr>
				<td align="center"><span class="h-ferm"><?=$user_data["c_b"]; ?></span></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td align="center"><span class="naz">На сумму:</span><br>
				<table>
					<tbody><tr>
						<td><img src=""></td>
						<td valign="middle"><span class="naz"><?=$func->SellItems($user_data["c_b"], $sonfig_site["items_per_coin"]); ?></span></td>
					</tr>
					
			
   
					
				</tbody></table>
				</td>
	
	
			</tr>
		</tbody></table>
		</div>
		</td>
		
 <table align="center">
	<tbody><tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
		<form action="" method="post"></form>
				<td align="center"><input type="submit" name="sell" value="Продать все" class="btn_reg"></td>
		
			</tr>		
</tbody></table>
		
	</tr>		
</tbody></table>

<div class="clr"></div>	
</div>