<?php
$id = protect($_GET['id']);
$select = mysql_query("SELECT * FROM `inventory_user` WHERE `id`='".$id."' AND `user_id`='".$user['id']."' AND `kol`>0 LIMIT 1");
echo '<div class="name"><a href="inventory.php">Инвентарь</a></div>';
if(mysql_num_rows($select)==0){
	echo '<div id="error">Инвентарь пуст!</div>';
	foot();
	exit;
}
$row = mysql_fetch_assoc($select);
$row_inv = mysql_fetch_assoc(mysql_query("SELECT * FROM `inventory` WHERE `id` = '".$row['invent_id']."'"));
$money = round($row_inv['money']/20);
	if($row['kol'] == 0){
	echo '<div id="error">Не верное кол-во товара.</div>';
	foot();
	exit;
	}
	echo '<div class="row">
	<img src="'.$row_inv['img'].'"><br>
	Уверены, что хотите продать <br><b>'.$row_inv['name'].'</b> за <img src="img/money/money.png"> '.$money .'?<br>
	<a id="link_button" href="inventory.php?sell&id='.$id.'&ok">Да</a><a style="float: right;" id="link_button" href="inventory.php">Нет,я промазал :(</a></div>';
if(isset($_GET['ok'])){
	echo '<div class="row">Продано за '.$money.' золотых.</div>';
mysql_query("UPDATE `users` SET `money`=`money`+".$money." WHERE `id`='".$user['id']."'");
mysql_query("UPDATE `inventory_user` SET `kol`=`kol`-1 WHERE `id`='".$id."'");
/* проверяем одето ли И удаляем если 1 в остатке */
	if($row['kol'] == 1){

	if($row['invent_id'] ==  $user['armor']){
	mysql_query("UPDATE `users` SET
	`armor`=0
	WHERE `id`='".$user['id']."'");
	}elseif($row['invent_id'] ==  $user['helmet']){
	mysql_query("UPDATE `users` SET
	`helmet`=0
	WHERE `id`='".$user['id']."'");
	}elseif($row['invent_id'] ==  $user['shoes']){
	mysql_query("UPDATE `users` SET
	`shoes`=0
	WHERE `id`='".$user['id']."'");
	}
	elseif($row['invent_id'] ==  $user['gloves']){
	mysql_query("UPDATE `users` SET
	`gloves`=0
	WHERE `id`='".$user['id']."'");
	}
	elseif($row['invent_id'] ==  $user['amulet']){
	mysql_query("UPDATE `users` SET
	`amulet`=0
	WHERE `id`='".$user['id']."'");
	}
	elseif($row['invent_id'] ==  $user['weapon']){
	mysql_query("UPDATE `users` SET
	`weapon`=0
	WHERE `id`='".$user['id']."'");
	}
		}
	header("Location: inventory.php");
}

?>