<?php
include_once ('./core/base.php');
falseauth();

include_once ('./core/head.php');

$slot = fl($_GET['slot']);
$item = fl($_GET['item']);

echo '<div style="position: relative;">';

if($u['training_step'] == 11){
	if($u['belt_slot_1'] == 0){
		$slot = 1;
		echo '<div style="position: absolute; top: 47%; left: 14%; z-index: 9000;"><img src="/images/cursor.gif"></div>';
	}
	if($u['belt_slot_1'] != 0 AND $u['belt_slot_2'] == 0){
		$slot = 2;
		echo '<div style="position: absolute; top: 66%; left: 14%; z-index: 9000;"><img src="/images/cursor.gif"></div>';
	}
}

if($slot > 0 AND $slot < 4){
	if($item > 0){
		$item = $base -> query("SELECT * FROM `users_items` WHERE `id` = '".$item."' AND `user` = '".$u['id']."' LIMIT 1") -> fetch_assoc();
		if($item > 0 AND $item['id'] != $u['belt_slot_1'] AND $item['id'] != $u['belt_slot_2'] AND $item['id'] != $u['belt_slot_3']){
			$base -> query("UPDATE `users` SET `belt_slot_".$slot."` = '".$item['id']."' WHERE `id` = '".$u['id']."' LIMIT 1");
			$_SESSION['message'] = 'Предмет успешно заменен.';
			header('Location: /user/'.$u['id'].'/');
			exit;
		}else{
			$_SESSION['message'] = 'Ошибка.';
			header('Location: /user/'.$u['id'].'/');
			exit;
		}
	}

	if($slot == 1) $slot_name = 'Первая';
	if($slot == 2) $slot_name = 'Вторая';
	if($slot == 3) $slot_name = 'Третья';
	echo '<div class="b">';

	echo '<div class="title">'.$slot_name.' ячейка пояса</div>';
	echo '<div class="event"><center>Здесь вы можете изменить предмет, который будет находиться в этой ячейке.</center></div>';

	$count = $base->query("SELECT * FROM `users_items` WHERE `what` = 'potion' AND `id` != '".$u['belt_slot_1']."' AND `id` != '".$u['belt_slot_2']."' AND `id` != '".$u['belt_slot_3']."' AND `user` = '".$u['id']."'") -> num_rows;
	$k_page = k_page($count,10);
	$page = page($k_page);
	$start = 10*$page-10;
	$sql = $base->query("SELECT * FROM `users_items` WHERE `what` = 'potion' AND `id` != '".$u['belt_slot_1']."' AND `id` != '".$u['belt_slot_2']."' AND `id` != '".$u['belt_slot_3']."' AND `user` = '".$u['id']."' ORDER BY `id` DESC LIMIT $start,10");
	if($count > 0){
		while($res = $sql -> fetch_assoc()){
			if($res['mark'] == '0') $mark = '<font color="#B1B1B1">Обычный';
			if($res['mark'] == '1') $mark = '<font color="#30C030">Редкий';
			if($res['mark'] == '2') $mark = '<font color="#68A8F9">Эпический';
			if($res['mark'] == '3') $mark = '<font color="#D8CD32">Легендарный';
			if($res['mark'] == '4') $mark = '<font color="#DD4FFF">Мифический';

			if($res['mark'] == '0') $border_color = 'B1B1B1';
			if($res['mark'] == '1') $border_color = '30C030';
			if($res['mark'] == '2') $border_color = '68A8F9';
			if($res['mark'] == '3') $border_color = 'D8CD32';
			if($res['mark'] == '4') $border_color = 'DD4FFF';

			echo '<div class="event_item">
			<table cellpadding="0" cellspacing="0"><tr>
			<td><img src="/images/items/resource/'.$res['image'].'.png" width="50px" style="border: 1px solid #'.$border_color.';"></td>
			<td valign="top" style="padding-left: 5px;"><a href="/res/'.$res['id'].'/">'.$res['name'].'</a><br/>
			<small>'.$mark.'</font><br/>
			<font color="#FFF">Количество: '.$res['amount'].'</font></small></td></tr></table>';
			echo ' <a class="btn_small" href="/beltslot/'.$slot.'/'.$res['id'].'/">Выбрать</a>';
			echo '</div>';
		}
		if($count > '10'){
			echo str('?',$k_page,$page);
		}
	}else{
		echo '<br/><center>Пусто...</center><br/>';
	}

	echo '<br/><a class="btn" href="javascript:history.go(-1)"><img src="/images/icons/back.png"> Назад</a>';
	echo '</div>';
}else{
	header('Location: /user/'.$u['id'].'/');
	exit;
}

echo '</div>';

include_once ('./core/foot.php');
?>