<?
define('PROTECTOR', 1);

$headmod = 'dress';//фикс. места

$textl='Инвентарь';
include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
going();
include($path.'files/core.php');
include($path.'files/head.php');
include($path.'files/zag.php');

$req = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `id`='$_GET[id]' and `image`='not'");

$avto=mysql_num_rows($req);
if($_GET[tip]=='kolco'){
$req1 = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `image`='yes'");
$avto1=mysql_num_rows($req1);
if($avto1>=2){
echo'Сначала снимите то что на вас!';
include($path.'files/down.php');
exit;
}
}
if($avto==0){
echo'Ошибка, такой вещи нет!';
include($path.'files/down.php');
exit;
}
$mag = mysql_fetch_array($req);
if($mag[klas]!='not' and $mag[klas]!=$udata[klas]){
echo'Эта вещь не для вашего класса!';
include($path.'files/down.php');
exit;
}
if($mag[nsila] > $udata[sila] or $mag[num] > $udata[um] or $mag[nlovk] > $udata[lovk] or $mag[nlvl] > $udata[lvl]){
echo'Вещь неподходит по вашим скилам!';
include($path.'files/down.php');
exit;
}
////////////Тестирование
$proverka = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `tip` != 'kolco'  and `image`='yes'");
$kolvo=mysql_num_rows($proverka);
if($kolvo>=1){
$odeto = mysql_fetch_array($proverka);
mysql_query("UPDATE item SET image = 'not' WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `image`='yes'");
}
///////////Конец
$numin=$mag[umin]+$udata[umin]-$odeto[umin];
$numax=$mag[umax]+$udata[umax]-$odeto[umax];

$npgolova=$mag[pgolova]+$udata[pgolova]-$odeto[pgolova];
$npbody=$mag[pbody]+$udata[pbody]-$odeto[pbody];
$npnogi=$mag[pnogi]+$udata[pnogi]-$odeto[pnogi];


$nhp=$mag[hp]+$udata[hpall]-$odeto[hp];
$nmp=$mag[mp]+$udata[mpall]-$odeto[mp];
$nkrit=$mag[krit]+$udata[krit]-$odeto[krit];
$nukrit=$mag[ukrit]+$udata[ukrit]-$odeto[ukrit];

$nsila=$mag[sila]+$udata[sila]-$odeto[sila];
$nlovk=$mag[lovk]+$udata[lovk]-$odeto[lovk];
$nprot=$mag[prot]+$udata[prot]-$odeto[prot];
$num=$mag[um]+$udata[um]-$odeto[um];
$nanti=$mag[antikrit]+$udata[antikrit]-$odeto[antikrit];

mysql_query("UPDATE `users` SET
         `umin` = '$numin',
         `umax` = '$numax',
         `pgolova` = '$npgolova',
         `pbody` = '$npbody',
         `pnogi` = '$npnogi',
         `hpall` = '$nhp',
         `mpall` = '$nmp',
         `krit` = '$nkrit',
         `ukrit` = '$nukrit',
         `antikrit` = '$nanti',
         `sila` = '$nsila',
         `lovk` = '$nlovk',
         `um` = '$num',
         `prot` = '$nprot'
          WHERE usr = '$log'");

mysql_query("UPDATE item SET image = 'yes' WHERE `usr` = '$log' and `tip`='$_GET[tip]' and `id`='$_GET[id]'");

echo"Вы одели $mag[name]!<br/>";
echo"<a href=\"inventar.php?\">Назад</a>";

include($path.'files/down.php');
?>