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

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

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

if($slot > 0 AND $slot < 4){
	if($skill > 0){
		$skill = $base -> query("SELECT * FROM `users_skills` WHERE `id` = '".$skill."' AND `user` = '".$u['id']."' LIMIT 1") -> fetch_assoc();
		if($skill > 0 AND $skill['id'] != $u['skill_slot_1'] AND $skill['id'] != $u['skill_slot_2'] AND $skill['id'] != $u['skill_slot_3']){
			$base -> query("UPDATE `users` SET `skill_slot_".$slot."` = '".$skill['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_skills` WHERE `id` != '".$u['skill_slot_1']."' AND `id` != '".$u['skill_slot_2']."' AND `id` != '".$u['skill_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_skills` WHERE `id` != '".$u['skill_slot_1']."' AND `id` != '".$u['skill_slot_2']."' AND `id` != '".$u['skill_slot_3']."' AND `user` = '".$u['id']."' ORDER BY `id` DESC LIMIT $start,10");
	if($count > 0){
		while($skill = $sql->fetch_assoc()){
			if($skill['book'] == 'fire') $type_color = 'orangered';
			if($skill['book'] == 'earth') $type_color = 'limegreen';
			if($skill['book'] == 'water') $type_color = 'dodgerblue';
			echo '<div class="event_item">
			<table cellpadding="0" cellspacing="0"><tr>
			<td><img src="/images/skills/'.$skill['image'].'.png" width="50px" style="border: 1px solid '.$type_color.';"></td>
			<td valign="top" style="padding-left: 5px;"><a href="/uskill/'.$skill['id'].'/">'.$skill['name'].'</a> <small><font color="#B1B1B1">'.$skill['level'].' ур.</font></small><br/><a class="btn_small" href="/skillslot/'.$slot.'/'.$skill['id'].'/">Выбрать</a></td></tr></table>
			</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;
}

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