<?php
define('PROTECTOR', 1);


include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
$textl='Сейф';
going();
//ryd();
include($path.'files/core.php');
include($path.'files/head.php');
include($path.'files/zag.php');

if(isset($_GET['invent'])){
$id=$_GET['id'];
$req = mysql_query("SELECT * FROM `weapon` WHERE `usr` =  '$log' AND `id` =  '".mysql_real_escape_string($id)."' AND `image` = 'sklad' ") or die (mysql_error());
$avto=mysql_num_rows($req);
if($avto==1){
mysql_query("UPDATE `weapon` SET
`image` =  'not' WHERE `usr` = '$log' AND `id` =  '$id'");
echo'<div class="main"><div class="block_zero center"><span style="color: #3c3;"><img src="image/icon/ok.png" alt="*"> Вещь положена в тумбочку!</span></div><div class="mini-line"></div></div>';
}else{
echo'<div class="main"><div class="block_zero center"><span style="color: #ff3434;"><img src="image/icon/error.png" alt="*"> Вещь не положена в тумбочку!</span></div><div class="mini-line"></div></div>';
}
}
//-----
if(isset($_GET['otdat'])){
$id=$_GET['id'];
$req = mysql_query("SELECT * FROM `weapon` WHERE `usr` = '$log' AND `id` = '".mysql_real_escape_string($id)."' AND `image` = 'sklad' ") OR die (mysql_error());
$avto=mysql_num_rows($req);
if($avto==1){
if(empty($_POST['user'])){
echo'<div class="main"><div class="block_zero center">';
echo'<form action="sklad.php?otdat&id='.$id.'" method="POST">';
echo'Кому передать:<br>
<input class="text" type="text" value="" size="25" name="user"><div class="separ"></div>';
echo'<span class="btn"><span class="end"><input class="label" type="submit" value="Передать"></span></span></form></div><div class="mini-line"></div>';
echo'</div>';
}else{
$us=$_POST['user'];
$prov = mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `usr`= '$us' "));
if($prov==0){
echo'<div class="main"><div class="block_zero center"><span style="color: #ff3434;"><img src="image/icon/error.png" alt="*"> Нет такого персонажа!</span></div><div class="mini-line"></div></div>';
}else{
$wep = mysql_query("SELECT name FROM `weapon` WHERE `usr`= '$log' and `id`= '".mysql_real_escape_string($id)."' and `image`='sklad' ") OR die (mysql_error());
$weap = mysql_fetch_array($wep);
mysql_query("UPDATE `weapon` SET
`image` =  'not', `usr`='$us' WHERE `usr` = '$log' and `id`= '$id'");
$time = date("H:i d.m.y");
$text = "Пользователь $log прислал вам вещь $weap[name], посмотрите в тумбочку!";
mysql_query("INSERT INTO `msg_r` SET `user_from` = 'Журнал', `user_to` = '".mysql_real_escape_string($us)."', `time` = '$time', `read` = 1, `mail_msg` = '$text'");
mysql_query("INSERT INTO `logi` SET `userup` = '".mysql_real_escape_string($us)."', `userout` = '$log', `time` = '$time', `log` = 'sklad', `text` = 'Передача $weap[name]'");
echo'<div class="main"><div class="block_zero center"><span style="color: #3c3;"><img src="image/icon/ok.png" alt="*"> Вещь передана игроку '.$us.'!</span></div><div class="mini-line"></div></div>';
}
}
}else{
echo'<div class="main"><div class="block_zero center"><span style="color: #ff3434;"><img src="image/icon/error.png" alt="*"> Такой вещи нет!</span></div><div class="mini-line"></div></div>';
}
}
//-----
if(isset($_GET['del'])){
$id=$_GET['id'];
$req = mysql_query("SELECT * FROM `weapon` WHERE `usr` =  '$log' AND `id` =  '".mysql_real_escape_string($id)."' AND `image` = 'sklad' ") OR die (mysql_error());
$avto=mysql_num_rows($req);
if($avto==1){
mysql_query("DELETE FROM `weapon` WHERE `usr` = '$log' AND `id` = '".mysql_real_escape_string($id)."' AND `image` = 'sklad' ");
echo'<div class="main"><div class="block_zero center"><span style="color: #3c3;"><img src="image/icon/ok.png" alt="*"> Вещь выброшена!</span></div><div class="mini-line"></div></div>';
}else{
echo'<div class="main"><div class="block_zero center"><span style="color: #ff3434;"><img src="image/icon/error.png" alt="*"> Такой вещи нет!</span></div><div class="mini-line"></div></div>';
}
}
echo'<div class="main"><div class="block_zero"><a href="inventar.php?"><img src="image/icon/bag.png" alt="*"> Открыть тумбочку</a></div><div class="mini-line"></div></div>';
$req = mysql_query("SELECT * FROM `weapon` WHERE `usr`= '$log' and `image`= 'sklad' ") or die (mysql_error());
$avto=mysql_num_rows($req);
if($avto==0){
echo'<div class="main"><div class="block_zero center">Сундук пуст</div></div>';
}else{
$am=0;
While($mag = mysql_fetch_array($req)){
if($set['lvl']>=$mag['nlvl']){
$font="#9c9";
$pic="ok.png";
}
if($set['lvl']<$mag['nlvl']){
$font="#c66";
$pic="error.png";
}
$wep = mysql_query("SELECT * FROM `weapon` WHERE `image` = 'yes' AND `usr` = '$log' AND `tip` = '$mag[tip]'") OR die (mysql_error());
$wep = mysql_fetch_array($wep);
$stat = $wep['hp']+$wep['mp']+$wep['krit']+$wep['ukrit']+$wep['sila']+$wep['lovk']+$wep['prot'];
$statmag = $mag['hp']+$mag['mp']+$mag['krit']+$mag['ukrit']+$mag['sila']+$mag['lovk']+$mag['prot'];
if($stat==$statmag){
$tex=" +0";
}
if($statmag-$stat>0){
$sta=$statmag-$stat;
$tex="<font color='#9c9'> +$sta</font>";
}
if($statmag-$stat<0){
$sta=$statmag-$stat;
$tex="<font color='#c66'> $sta</font>";
}
$am=$am+$mag['cena'];
if(!empty($mag['img'])){
$patch="art/$mag[img]";
}else{
$patch="weapon/$mag[kompl]/$mag[tip].png";
}
switch($mag['tip']){
case 'weapon':
$tip='';
break;
case 'body':
$tip='';
break;
case 'golova':
$tip='';
break;
case 'nogi':
$tip='';
break;
case 'shit':
$tip='';
break;
}
echo'<div class="main"><div class="block_zero">';
echo'<img class="float-left" src="image/'.$patch.'" width="50" height="50" style="margin-left:10px; margin-right:10px;" alt="*"><a href="inventar.php?mod=info&id='.$mag['id'].'"><span style="color: '.$font.';"><img src="image/icon/'.$pic.'" alt="*"> '.$tip.' '.$mag['name'].' '.$tex.'</span></a>'; 
echo'<br><small>Небходимо бицухи: '.$mag['nlvl'].'<br>Бонус: '.$mag['proch'].'/10</small><div class="separ"></div>';
echo'<center><a href="sklad.php?otdat&id='.$mag['id'].'"><span class="btn"><span class="end"><input class="label" type="submit" value="Передать"></span></span></a> <a href="sklad.php?invent&id='.$mag['id'].'"><span class="btn"><span class="end"><input class="label" type="submit" value="В тумбочку"></span></span></a> <a href="sklad.php?del&id='.$mag['id'].'"><span class="btn"><span class="end"><input class="label" type="submit" value="Выбросить"></span></span></a></center>';
echo'</div><div class="menuList"><li><li></li></li></div></div>';
}
}
include($path.'files/down.php');
?>