<?php
include 'system/bd.php';
include 'system/cook.php';
include ("system/gzip.php");
if(isset($_SESSION['auth']) && $_SESSION['auth']==1){
include 'system/head.php';
include 'system/head1.php';
switch($_GET[mod]){
default:
echo"<div class='title'>Инвентарь [".mysql_result(mysql_query("SELECT COUNT(*) FROM `item` WHERE '$user[id]' = `user` and `wearing` = 'no' "),0)."/20] </div>";

$cop=50;
$ca=mysql_result(mysql_query("SELECT COUNT(*) FROM `item` WHERE `user` = '$user[id]' "),0);

$cp=ceil($ca/$cop);
if(isset($_GET['page']) && is_numeric($_GET['page'])){
$page = $_GET['page'];
if($_GET['page']>$cp) $page=$cp;
if($_GET['page']<1)$page=1;
}else{
$page=1;
}
$start=$page*$cop-$cop;
$dlist = 'list1';

$req = mysql_query("SELECT * FROM `item` WHERE `user` = '$user[id]'  and `wearing`='no' ORDER by `id` DESC LIMIT $start,$cop  ");



////////////////////////////
echo"<div class='empty_block'>";
$avto=mysql_num_rows($req);
if($avto>=1){
While($mag = mysql_fetch_array($req))
{

if($mag[quality] == '0'){
$quality= Хлам;
$hone = 5;}
if($mag[quality] == '1'){
$quality= Обычный;
$hone = 10;}
if($mag[quality] == '2'){
$quality= Необычный;
$hone = 15;}
if($mag[quality] == '3'){
$quality= Редкий;
$hone = 25;}
if($mag[quality] == '4'){
$quality= Эпический;
$hone = 30;}
if($mag[quality] == '5'){
$quality= Легендарный;
$hone = 40;}
if($mag[quality] == '6'){
$quality= Мифический;
$hone = 50;}
echo"
 <table>
                            <tbody><tr>
                    <td class='b40px'>
<img src='/img/items/$mag[tip]/$mag[images].png'>
</td><td>";                                                                  
$w=explode("*",$mag[name]);

echo" <img src='img/star/$mag[quality].png'> <a href='inventar.php?mod=info&id=$mag[id]'> $mag[name]</a>";
echo"  [$mag[hone]/$hone]<br>
<span class='c1'> $quality, личное
</span>

</td> </tr>";
}
echo ' </tbody> </table> </div>';


}else{
echo '<center> Нет вещей 
</center> </div>';
}





break;
case 'info_pers':
$req = mysql_query("SELECT * FROM `item` WHERE `user` = '$user[id]' and `id`='".mysql_real_escape_string($_GET['id'])."'");
////////////////////////////
$avto=mysql_num_rows($req);
if($avto==0){
header ("Location: inventar.php?");
exit;
}

$req = mysql_query("SELECT * FROM `item` WHERE `user` = '$user[id]' and `id`='".mysql_real_escape_string($_GET['id'])."'");
////////////////////////////
$avto=mysql_num_rows($req);
if($avto>=1){
$mag= mysql_fetch_array($req);

if($mag[tip] == head){
$tip=Голова;}
if($mag[tip] == shoulder){
$tip=Наплечник;}
if($mag[tip] == body){
$tip=Тело;}
if($mag[tip] == weapon){
$tip=Оружие;}
if($mag[tip] == shield){
$tip=Щит;}

if($mag[quality] == 0){
$star=Хлам;}
if($mag[quality] == 1){
$star=Обычный;}
if($mag[quality] == 2){
$star=Необычный;}
if($mag[quality] == 3){
$star=Редкий;}
if($mag[quality] == 4){
$star=Эпический;}
if($mag[quality] == 5){
$star=легендарный;}
if($mag[quality] == 6){
$star=Мифический;}

if($mag[nev] == 0){
$new=личное;}
if($mag[nev] == 1){
$new=Новое;}
echo" <div class='title'> $mag[name]
</div>
<div class='empty_block'>

<table>
        <tbody><tr>
            <td class='b40px'>
<img src='/img/items/$mag[tip]/$mag[images].png' width='40' height='40'> </td> 
           <td><span class='c1'> <small>
Уровень заточки </span> [$mag[hone]/25]
<br> <img src='../img/star/$mag[quality].png'>
<span class='c1'> 
$star, $new </span>
</br> <span class='c1'> 
$tip, $mag[lvl] уровень </span>
</small> </td>
        </tr><small>
    </tbody></table>
</div>
<div class='block'>
 <img src='../img/icon/hp.png'> Здоровья: <span class='c1'> 
".number_format($mag[hp])." 
</span><br>
 <img src='../img/icon/attack.png'> Атака: <span class='c1'> 
".number_format($mag[attack])." </span> <br>
 <img src='../img/icon/def.png'> Защита: <span class='c1'> 
".number_format($mag[def])."  </span> <br>
<img src='../img/icon/silver.png'> 
Бонус к серебру: 
<span class='c1'> $mag[silver]% </span></br>
<img src='../img/icon/exp.png'> 
Бонус к опыту: 
<span class='c1'> $mag[exp]% 
</span></small>
</div>";





}

echo'<div class="block_link">
<a href="?">
<img src="img/images/arrow.png"> Вернуться</a></div>';


break;
case 'info':
$req = mysql_query("SELECT * FROM `item` WHERE `user` = '$user[id]' and `id`='".mysql_real_escape_string($_GET['id'])."'");
////////////////////////////
$avto=mysql_num_rows($req);
if($avto==0){
header ("Location: inventar.php?");
exit;
}

$req = mysql_query("SELECT * FROM `item` WHERE `user` = '$user[id]' and `id`='".mysql_real_escape_string($_GET['id'])."'");
////////////////////////////

$avto=mysql_num_rows($req);
if($avto>=1){
$mag= mysql_fetch_array($req);
if($mag[tip] == head){
$tip=Голова;}
if($mag[tip] == shoulder){
$tip=Наплечник;}
if($mag[tip] == body){
$tip=Тело;}
if($mag[tip] == weapon){
$tip=Оружие;}
if($mag[tip] == shield){
$tip=Щит;}

if($mag[quality] == 0){
$star=Хлам;}
if($mag[quality] == 1){
$star=Обычный;}
if($mag[quality] == 2){
$star=Необычный;}
if($mag[quality] == 3){
$star=Редкий;}
if($mag[quality] == 4){
$star=Эпический;}
if($mag[quality] == 5){
$star=легендарный;}
if($mag[quality] == 6){
$star=Мифический;}

if($mag[nev] == 0){
$new=личное;}
if($mag[nev] == 1){
$new=Новое;}



echo" <div class='title'> $mag[name]
</div>
<div class='empty_block'>

<table>
        <tbody><tr>
            <td class='b40px'>
<img src='/img/items/$mag[tip]/$mag[images].png' width='40' height='40'> </td> 
           <td><span class='c1'> <small>
Уровень заточки </span> [$mag[hone]/25]
<br> <span class='c1'> 
<img src='../img/star/$mag[quality].png'>
$star, $new </span>
</br> <span class='c1'> 
$tip, $mag[lvl] уровень </span>
</small> </td>
        </tr><small>
    </tbody></table>
</div>
<div class='block'>
 <img src='../img/icon/hp.png'> Здоровья: <span class='c1'> 
".number_format($mag[hp])." 
</span><br>
 <img src='../img/icon/attack.png'> Атака: <span class='c1'> 
".number_format($mag[attack])." </span> <br>
 <img src='../img/icon/def.png'> Защита: <span class='c1'> 
".number_format($mag[def])."  </span> <br>
<img src='../img/icon/silver.png'> 
Бонус к серебру: 
<span class='c1'> $mag[silver]% </span></br>
<img src='../img/icon/exp.png'> 
Бонус к опыту: 
<span class='c1'> $mag[exp]% 
</span></small>

<div class='navbar'>
 <a href='?mod=wearing_yes&id=$mag[id]&tip=$mag[tip]'> <img src='../img/images/arrow.png'> Надеть 
</a></div> 
<div class='navbar'>
<a href='?'> <img src='../img/images/arrow.png'> Разобрать</a></div>  
</div>";

}

echo"<div class='block_link'>
<a href='inventar.php?'> <img src='../img/images/arrow.png'> Вернуться</a></div>";
break;
/////////
case'wearing_no':
$req = mysql_query("SELECT * FROM `item` WHERE `user` = '$user[id]' ||`wearing`='yes' ||
`id`='".mysql_real_escape_string($_GET['id'])."' AND `tip`= '".mysql_real_escape_string($_GET['tip'])."'");
$avto=mysql_num_rows($req);
if($_GET[tip]!=head && $_GET[tip]!=shoulder && $_GET[tip]!=body && $_GET[tip]!=weapon && $_GET[tip]!=shield){
header ("Location: equipment.php"); exit;
}
if($avto==1){
header ("Location: equipment.php"); exit;
exit;
}
$mag = mysql_fetch_array($req);

$attack=$user[attack] -$mag[attack];
$def=$user[def]-$mag[def];
$hp=$user[hpfull]-$mag[hp];

mysql_query("UPDATE `user` SET `attack`= '$attack',
`def`= '$def' ,
`hpfull`= '$hp' WHERE `id`='$user[id]'");

mysql_query("UPDATE `item` SET wearing = 'no' WHERE `user` = '$user[id]' and `tip`='".mysql_real_escape_string($_GET['tip'])."' and `id`='".mysql_real_escape_string($_GET['id'])."' ");

header ("Location: equipment.php"); exit;
break;
//////
case'wearing_yes':
$req = mysql_query("SELECT * FROM `item` WHERE `user` = '$user[id]' AND `wearing`='no' AND
`id`='".mysql_real_escape_string($_GET['id'])."' AND
`tip`='".mysql_real_escape_string($_GET['tip'])."'");

$r = mysql_query("SELECT * FROM `item` WHERE `user` = '$user[id]' AND `wearing`='yes' AND
`id`='".mysql_real_escape_string($_GET['id'])."' AND
`tip`='".mysql_real_escape_string($_GET['tip'])."'");

$avto=mysql_num_rows($req);
if($_GET[tip]!=head && $_GET[tip]!=shoulder && $_GET[tip]!=body && $_GET[tip]!=weapon && $_GET[tip]!=shield){
header ("Location: inventar.php"); exit;
}


$req1 = mysql_query("SELECT * FROM `item` WHERE `user` = '$user[id]' and `tip`='".mysql_real_escape_string($_GET['tip'])."' and `wearing`='yes'");
$avto1=mysql_num_rows($req1);
if($avto1>=1){
echo'<div class="title">Инвентарь </div>
<div class="empty_block item_center"> Вам нужно сначала снять то что на вас одето!</div>';
echo'<div class="block_link"> 
<a href="inventar.php">
<img src="/img/images/arrow.png" alt="*"/> Вернуться</a></div>';
include 'system/foot.php';
exit;
}else{

$mag = mysql_fetch_array($req);


$attack=$mag[attack] + $user[attack];
$def=$mag[def]+$user[def];
$hp=$mag[hp]+$user[hpfull];

mysql_query("UPDATE `user` SET `attack`= '$attack',
`def`= '$def' ,
`hpfull`= '$hp' 
 WHERE `id`='$user[id]'");

mysql_query("UPDATE `item` SET wearing = 'yes' WHERE `user` = '$user[id]' and `tip`='".mysql_real_escape_string($_GET['tip'])."' and `id`='".mysql_real_escape_string($_GET['id'])."'");
header ("Location: inventar.php");
exit;
}
break;


}
}else{
header ("Location: index.php"); exit;

}
include 'system/foot.php';
?>
