<?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");

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']."'"));
if($row['cat_id']==8){
/* Если вакцина используем */
$virr = mysql_fetch_assoc(mysql_query("SELECT `id`,`virus` FROM `inventory` WHERE `id`='".$user['virus']."'"));
if($row_inv['vak']==$virr['virus']){
echo '<div class="row">Вакцина медленно растеклась по венам убирая на своем пути вирусы.</div>';
mysql_query("UPDATE `users` SET `virus`=0 WHERE `id`='".$user['id']."'");
mysql_query("UPDATE `inventory_user` SET
`kol`=`kol`-1
WHERE `id`='".$id."' AND `user_id`='".$user['id']."'");
}else{
echo '<div id="error">Эта вакцина не поможет от вашего вируса</div>';
}

}elseif($row['cat_id']==1){
/*Если зелье выпиваем*/
	if($user['health']+$row_inv['hp_recovery'] >= $user['max_health']){
	mysql_query("UPDATE `users` SET 
	`health`=".$user['max_health']."
	WHERE `id`='".$user['id']."'");
	}else{	
mysql_query("UPDATE `users` SET 
`health`=`health`+".$row_inv['hp_recovery']."
WHERE `id`='".$user['id']."'");
	}
	
	/* ----- */
	if($user['mana']+$row_inv['mp_recovery'] >= $user['max_mana']){
	mysql_query("UPDATE `users` SET 
	`mana`=".$user['max_mana']."
	WHERE `id`='".$user['id']."'");
	}else{	
mysql_query("UPDATE `users` SET 
`mana`=`mana`+".$row_inv['mp_recovery']."
WHERE `id`='".$user['id']."'");
	}
	
	mysql_query("UPDATE `inventory_user` SET
`kol`=`kol`-1
WHERE `id`='".$id."' AND `user_id`='".$user['id']."'");

header("Location: inventory.php?cat=1");
}else{
if($row['cat_id']==2){
mysql_query("UPDATE `users` SET
`armor`='".$row['invent_id']."'
WHERE `id`='".$user['id']."'");
}elseif($row['cat_id']==3){
mysql_query("UPDATE `users` SET
`helmet`='".$row['invent_id']."'
WHERE `id`='".$user['id']."'");
}elseif($row['cat_id']==4){
mysql_query("UPDATE `users` SET
`shoes`='".$row['invent_id']."'
WHERE `id`='".$user['id']."'");
}elseif($row['cat_id']==5){
mysql_query("UPDATE `users` SET
`gloves`='".$row['invent_id']."'
WHERE `id`='".$user['id']."'");
}elseif($row['cat_id']==6){
mysql_query("UPDATE `users` SET
`amulet`='".$row['invent_id']."'
WHERE `id`='".$user['id']."'");
}elseif($row['cat_id']==7){
mysql_query("UPDATE `users` SET
`weapon`='".$row['invent_id']."'
WHERE `id`='".$user['id']."'");
}
header("Location: inventory.php?cat=".$row['cat_id']);
}

?>