<?php
session_start();
include ('private/mysql.php');
include ('tmp/head.php');

if($uid!=='7'){
	header('Location: bag.php');
	exit;
}

function mass(){
    
    /** одеть/снять вещь **/
if($_SESSION['odet'] == 'ok'){
    
    echo "Вы надели <b><font color=lightgreen>$_SESSION[o_name]</font></b><hr>";
    $_SESSION['odet'] = null;
    $_SESSION['o_name'] = null;
}

if($_SESSION['sell']!=""){
    echo $_SESSION['sell'];
    $_SESSION['sell']="";
}

if($_SESSION['snyat'] == 'ok'){
    
    echo "Вы сняли <b><font color=lightgreen>$_SESSION[o_name]</font></b><hr>";
    $_SESSION['snyat'] = null;
    $_SESSION['o_name'] = null;
}

if($_SESSION['tipok'] == 'ok'){
    
    echo "<font color=red>Вещь данного типа уже надета</font><hr>";
    $_SESSION['tipok'] = null;
}

/** **/
    
    if($_GET['t'] == '1' or $_GET['t'] == ''){$sh2 = "Оружие";}else{$sh2 = "<a href='inventar.php?sd=weapon&t=1'>Оружие</a>";}
    if($_GET['t'] == '2'){$sh3 = "Шлемы";}else{$sh3 = "<a href='inventar.php?sd=helmet&t=2'>Шлемы</a>";}
    if($_GET['t'] == '3'){$sh4 = "Наплечники";}else{$sh4 = "<a href='inventar.php?sd=ple4i&t=3'>Наплечники</a>";}
    if($_GET['t'] == '4'){$sh5 = "Доспехи";}else{$sh5 = "<a href='inventar.php?sd=armor&t=4'>Доспехи</a>";}
    if($_GET['t'] == '5'){$sh6 = "Перчатки";}else{$sh6 = "<a href='inventar.php?sd=gloves&t=5'>Перчатки</a>";}
    if($_GET['t'] == '6'){$sh7 = "Поножи";}else{$sh7 = "<a href='inventar.php?sd=pants&t=6'>Поножи</a>";}
    if($_GET['t'] == '7'){$sh8 = "Сапоги";}else{$sh8 = "<a href='inventar.php?sd=boots&t=7'>Сапоги</a>";}
    if($_GET['t'] == '8'){$sh9 = "Щиты";}else{$sh9 = "<a href='inventar.php?sd=shield&t=8'>Щиты</a>";}

    if($_GET['t'] == '9'){$sh10 = "Амулеты";}else{$sh10 = "<a href='inventar.php?sd=amulet&t=9'>Амулеты</a>";}
    if($_GET['t'] == '10'){$sh11 = "Серьги";}else{$sh11 = "<a href='inventar.php?sd=ear&t=10'>Серьги</a>";}
    if($_GET['t'] == '11'){$sh12 = "Кольца";}else{$sh12 = "<a href='inventar.php?sd=ring&t=11'>Кольца</a>";}

    if($_GET['t'] == '12'){$sh13 = "Эликсиры";}else{$sh13 = "<a href='inventar.php?sd=elixir&t=12'>Эликсиры</a>";}

    if($_GET['t'] == '13'){$sh14 = "Ресурсы";}else{$sh14 = "<a href='inventar.php?sd=res&t=13'>Ресурсы</a>";}

    echo "<center>$sh2 | $sh3 | $sh4 | $sh5 | $sh6 | $sh7 | $sh8 | $sh9<br>$sh10 | $sh11 | $sh12<br>$sh13 | $sh14</center><hr>";
    
}

switch($sd){
default:

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='weapon'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name]<br>&nbsp;Урон: $w[min_u] - $w[max_u]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}
 
break;

case 'ring':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='ring'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Интеллект: $w[int]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;

case 'ear':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='ear'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Интеллект: $w[int]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;


case 'closebattle':
$q = mysql_query("SELECT * FROM `us_hp_elixir` WHERE `user`='$uid' and `id`='$id'");
$e = mysql_num_rows($q);
if($e=='0'){
    header('Location: inventar.php');
    exit;
}


mysql_query("UPDATE `us_hp_elixir` SET `battle`='0' WHERE `user`='$uid' and `id`='$id'");


header('Location: inventar.php?sd=elixir');
exit;

break;

case 'upbattle':
$q = mysql_query("SELECT * FROM `us_hp_elixir` WHERE `user`='$uid' and `id`='$id'");
$e = mysql_num_rows($q);
if($e=='0'){
    header('Location: inventar.php');
    exit;
}

$mx = mysql_num_rows(mysql_query("SELECT * FROM `us_hp_elixir` WHERE `user`='$uid' and `battle`='1'"));
if($mx>='3'){
    header('Location: inventar.php?sd=elixir');
    exit;
}

mysql_query("UPDATE `us_hp_elixir` SET `battle`='1' WHERE `user`='$uid' and `id`='$id'");


header('Location: inventar.php?sd=elixir');
exit;

break;

case 'elixir':

mass();

$q = mysql_query("SELECT * FROM `us_hp_elixir` WHERE `user`='$uid'");
$e = mysql_num_rows($q);
if($e == '0'){
    echo "У вас нет эликсиров.";
}else{
      
        While($w = mysql_fetch_assoc($q)){
        
        if($w['battle']=='0'){$battle="[<a href='inventar.php?sd=upbattle&id=$w[id]'>Одеть</a>]";}else{$battle="[<a href='inventar.php?sd=closebattle&id=$w[id]'>Снять</a>]";}
        
        echo "<span style='float:left'><img src='img/elixir/$w[img]' width='55'></span>&nbsp;$w[name] ($w[kol] шт.)<br>&nbsp;Восстанавливает <font color=red>$w[hp]%</font> здоровья<br>&nbsp;$battle<br><hr>";
        
    }
    
}

break;

case 'amulet':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='amulet'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Живучесть: $w[hp]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;

case 'res':

mass();

$q = mysql_query("SELECT * FROM `res` WHERE `user`='$uid'");
$e = mysql_num_rows($q);
if($e == '0'){
    echo "У вас нет ресурсов.";
}else{
    
    if(isset($_GET['throw'])){
        $q1 = mysql_num_rows(mysql_query("SELECT * FROM `res` WHERE `id`='$id' and `user`='$uid'"));
        if($q1 == '0'){
            header('Location: inventar.php?sd=res&t=13');
            exit;
        }
        mysql_query("DELETE FROM `res` WHERE `id`='$id' and `user`='$uid'");
        header('Location: inventar.php?sd=res&t=13');
        exit;
    }
    
    
    While($w = mysql_fetch_assoc($q)){
        
        echo "<span style='float:left'><img src='img/res/$w[img]' width='55'></span>&nbsp;$w[name]<br>&nbsp;Количество: $w[kol]<br>&nbsp;[<a href='inventar.php?sd=res&t=13&id=$w[id]&throw'>Выкинуть</a>]<br><hr>";
        
    }
    
}

break;


case 'weapon':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='weapon'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Урон: $w[min_u] - $w[max_u] <br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;


case 'helmet':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='helmet'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Живучесть: $w[hp]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;

case 'ple4i':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='ple4i'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Живучесть: $w[hp]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;

case 'armor':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='armor'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Живучесть: $w[hp]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;

case 'gloves':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='gloves'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Живучесть: $w[hp]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;

case 'pants':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='pants'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Живучесть: $w[hp]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;

case 'boots':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='boots'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Живучесть: $w[hp]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;

case 'shield':

mass();

$q = mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='shield'");
$e = mysql_num_rows($q);
if($e == 0){
    echo "У вас нет вещей.";
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        if($w['status'] == 'odet'){$status = "[Надето] [<a href='inventar.php?sd=snyat&id=$w[id]'>Снять</a>]";}else{$status = "[<a href='inventar.php?sd=odet&id=$w[id]'>Надеть</a>]";}
        
        if($w['imp']>='1'){$imp="+$w[imp]";}else{$imp="";}
        
        echo "<span style='float:left'><img src='/img/shmot/$w[img]' width='50'></span>&nbsp;$w[name] $imp $w[level] ур.<br>&nbsp;Живучесть: $w[hp]<br>&nbsp;$status [<a href='sell.php?sd=inv&id=$w[id]'>Продать</a>]<hr>";
        
    }
    
}

break;



case 'odet':

$q = mysql_query("SELECT * FROM `item` WHERE `id`='$id' and `user`='$uid'");
$e = mysql_num_rows($q);
$w = mysql_fetch_assoc($q);
if($e == 0){
    header('Location: inventar.php');
    exit;
}

$q1 = mysql_num_rows(mysql_query("SELECT * FROM `item` WHERE `user`='$uid' and `tip`='$w[tip]' and `status`='odet'"));
if($q1 >= '1'){
    $_SESSION['tipok'] = "ok";
    header('Location: inventar.php');
    exit;
}

if($user['level'] < $w['level']){
    header('Location: inventar.php');
    exit;
}

mysql_query("UPDATE `item` SET `status`='odet' WHERE `user`='$uid' and `id`='$w[id]'");

$int = $user['int']+$w['int'];
$hp = $user['hpall']+$w['hp'];
$mp = $user['mpall']+$w['mp'];
$min_u = $user['min_u']+$w['min_u'];
$max_u = $user['max_u']+$w['max_u'];

mysql_query("UPDATE `users` SET `int`='$int',`hpall`='$hp',`mpall`='$mp',`min_u`='$min_u',`max_u`='$max_u' WHERE `id`='$uid'");


$_SESSION['odet'] = "ok";
$_SESSION['o_name'] = "$w[name]";
header('Location: inventar.php?');
exit;

break;


case 'snyat':

$q = mysql_query("SELECT * FROM `item` WHERE `id`='$id' and `user`='$uid'");
$e = mysql_num_rows($q);
$w = mysql_fetch_assoc($q);
if($e == 0){
    header('Location: inventar.php');
    exit;
}


mysql_query("UPDATE `item` SET `status`='not' WHERE `user`='$uid' and `id`='$w[id]'");

$int = $user['int']-$w['int'];
$hp = $user['hpall']-$w['hp'];
$mp = $user['mpall']-$w['mp'];
$min_u = $user['min_u']-$w['min_u'];
$max_u = $user['max_u']-$w['max_u'];

mysql_query("UPDATE `users` SET `int`='$int',`hpall`='$hp',`mpall`='$mp',`min_u`='$min_u',`max_u`='$max_u' WHERE `id`='$uid'");


$_SESSION['snyat'] = "ok";
$_SESSION['o_name'] = "$w[name]";
header('Location: inventar.php?');
exit;

break;




}
include ('tmp/foot.php');
?>