<?
//
//
$location = true;
require_once($_SERVER['DOCUMENT_ROOT']."/core/func.php");
head("Снаряжение",$uid); # Голова
//
//
$id = number($_GET['id']);
$us = fch("SELECT * FROM `users` WHERE `id` = ? LIMIT 1", array($id));

if(!$us){
	header('location:?id='.$uid);
	exit();
}


$dat = array('1' => 'Обычное', '2' => 'Редкое', '3' => 'Эпическое', '4' => 'Легендарное', '5' => 'Мифическое');

$dat2 = array('1' => 'Обычная', '2' => 'Редкая', '3' => 'Эпическая', '4' => 'Легендарная', '5' => 'Мифическая');

$color = array('1' => '#32cd32', '2' => '#a335ee', '3' => '#ff8000', '4' => '#05CCFF', '5' => '#f5270d');

$type = array('1' => 'Шлем', '2' => 'Наплечники', '3' => 'Броня', '4' => 'Перчатки', '5' => 'Меч', '6' => 'Щит', '7' => 'Штаны', '8' => 'Сапоги');

if(isset($_GET['view'])){
	$ids = abs(intval($_GET['view']));
	$item = fch("SELECT * FROM `inv` WHERE `id_user` = ? AND `yes` = ? AND `id` = ? LIMIT 1", array($id,1,$ids));

	if(!$item){
		header('location:?r='.$r);
		exit();
	}

	$inv = fch("SELECT * FROM `inv` WHERE `type` = ? AND `yes` = ? AND `id_user` = ? LIMIT 1", array($item['type'],1,$uid));


	$param_1 = $inv['power']+$inv['block']+$inv['health'];
	$param_2 = $item['power']+$item['block']+$item['health'];

	if($param_1 > $param_2){
		$param = "Хуже: <font color='red'>-".($param_1-$param_2)."</font>";
	}
	elseif($param_1 < $param_2){
		$param = "Лучше: <font color='lime'>+".($param_2-$param_1)."</font>";
	}

	$param_11 = $item['power']+$item['block']+$item['health'];
	$param_21 = $inv['power']+$inv['block']+$inv['health'];

	if($param_11 >= $param_21){
		$param2 = "Хуже: <font color='red'>-".($param_11-$param_21)."</font>";
	}
	elseif($param_11 < $param_21){
		$param2 = "Лучше: <font color='lime'>+".($param_21-$param_11)."</font>";
	}

echo "
<div class='tophead'>
<div class='ohh'>
<img class = 'imgItem".$item['set']."' src = '/images/items/".$item['set']."/".$item['type'].".png' width='50' height='50'>
</div>

	<a href = '?view=".$item['id']."'><font color = '".$color[$item['set']]."'>".$item['name']."</font></a> <small>(".$item['smitch']."/".$item['max_smitch'].")</small> 
<small>
	<br><img src='/images/power.png' width='15px' height='15px'> ".$item['power']." 
    <img src='/images/block.png' width='15px' height='15px'> ".$item['block']." 
    <img src='/images/health.png' width='15px' height='15px'> ".$item['health']."<br>".$param."<br>
</small>
	</div>
";




//
	echo "
	<div class = 'tophead'>
        <img src='/images/type".$item['set'].".png'  width='' height=''> <font color = '".$color[$item['set']]."'>".$dat[$item['set']]." качество</font> <br>
";

if($item['rune'] >= 1)echo "<img class='img2' src='/images/type".$item['rune'].".png'> <font color = '".$color[$item['rune']]."'> ".$dat2[$item['rune']]." руна</font> <font color = 'lime'>+".($item['rune_param']*3)."</font>"; else echo "<img src='/images/type0.png'> Руна не установлена"; 

echo "
        <br><img src='/images/shop.png'  width='17' height='17'> Уровень заточки: <a href='/shop.php?loc=2'><span class='orange'>+".$item['smitch']."</span><br>
	</div>
	<div class = 'tophead'>
	<img src='/images/power.png' width='15px' height='15px'> Сила: ".$item['power']."<br>
	<img src='/images/block.png' width='15px' height='15px'> Защита: ".$item['block']."<br>
	<img src='/images/health.png' width='15px' height='15px'> Здоровье: ".$item['health']."<br>
	</div>
	";

	echo "
	<a href = '/item.php?id=".$id."' class='tophead'>Вернуться назад</a>
	";

	foot($uid);
	exit();
}


$count = $BaseConnect->query("SELECT (id) FROM `inv` WHERE `yes` = '0' AND `id_user` = '".$uid."'")->rowCount();


if(isset($_GET['open'])){
	$id2 = abs(intval($_GET['open']));

	$item2 = fch("SELECT * FROM `inv` WHERE `id_user` = ? AND `yes` = ? AND `id` = ? LIMIT 1", array($uid,1,$id2));

	if(!$item2){
		header('location:?r='.$r);
		exit();
	}
	if($count == $user['limit_inv']){
		err2("У вас недостаточно места в рюкзаке, для того чтобы снять вещь!");
		header('location:?');
		exit();
	}

	qry("UPDATE `users` SET `power` = `power` - ?, `block` = `block` - ?, `health` = `health` - ? WHERE `id` = ? LIMIT 1", array($item2['power'],$item2['block'],$item2['health'],$uid));
	qry("UPDATE `inv` SET `yes` = ? WHERE `id` = ? LIMIT 1", array(0,$item2['id']));
	msg2("Вещь успешно снята!");
	header('location:?');
	exit();
}





for($i=1;$i<=8;$i++) {

	$item = fch("SELECT * FROM `inv` WHERE `type` = ? AND `yes` = ? AND `id_user` = ? LIMIT 1", array($i,1,$id));
	$msg = fch("SELECT * FROM `inv` WHERE `type` = ? AND `yes` = ? AND `id_user` = ? LIMIT 1", array($i,1,$uid));

	$param_2 = $item['power']+$item['block']+$item['health'];
	$param_1 = $msg['power']+$msg['block']+$msg['health'];

	if($param_1 > $param_2){
		$param = "Хуже: <font color='red'>-".($param_1-$param_2)."</font>";
	}
	elseif($param_1 < $param_2){
		$param = "Лучше: <font color='lime'>+".($param_2-$param_1)."</font>";
	}



	if($item){

echo "
<div class = 'tophead'>
<div class='ohh'> 
<img class = 'imgItem".$item['set']."' src = '/images/items/".$item['set']."/".$item['type'].".png' width='50' height='50'>
</div> 

    <a href = '?id=".$id."&view=".$item['id']."'><font color = '".$color[$item['set']]."'><u>".$item['name']."</u></font></a> <small>(".$item['smitch']."/".$item['max_smitch'].") ";

if($uid == $id)echo "<span style='float: right;'><a href='?id=".$id."&open=".$item['id']."'>[Снять]</a></span>";

echo "</small>
    "; 

    echo " 
    <br><img src='/images/power.png' width='15px' height='15px'> ".$item['power']." 
    <img src='/images/block.png' width='15px' height='15px'> ".$item['block']." 
    <img src='/images/health.png' width='15px' height='15px'> ".$item['health']."<br> 
<small> ".$param."</small> <br> 

    </div> 

    "; 

	}
	else{



			echo "




		<div class = 'tophead'>

		<table>

		<td class = 'w1px'>
		<span class = 'items-list'>
		<span class = 'items-icons'>
		</span>
		</span>
		</td>

		<td>
		<b>".$type[$i]."</b>
		<br>
		Ничего не надето
		</td>
		</table>
		</div>
		";


	}

}




echo "
<a href = '/profile.php?id=".$id."' class='tophead'>Вернуться назад</a>
";


foot($uid);
?>