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

$change = fl($_GET['change']);

if($change){
	$uskin = $base -> query("SELECT * FROM `users_skins` WHERE `user` = '".$u['id']."' AND `skin` = '".$change."' LIMIT 1");
	$skin_nr = $uskin -> num_rows;
	if($skin_nr > 0){
		$skin = $base -> query("SELECT * FROM `skins` WHERE `id` = '".$change."' LIMIT 1") -> fetch_assoc();
		if($u['skin'] == $skin['skin']){
			$_SESSION['message'] = 'Этот образ уже используется.';
			header('Location: /skins/');
			exit;
		}
		$base -> query("UPDATE `users` SET `skin` = '".$skin['skin']."' WHERE `id` = '".$u['id']."' LIMIT 1");
		$_SESSION['message'] = 'Образ успешно изменён.';
		header('Location: /skins/');
		exit;
	}else{
		$_SESSION['message'] = 'Ошибка.';
		header('Location: /skins/');
		exit;
	}
}

echo '<div class="b"><div class="title">Мои образы</div>';

echo '<div class="event"><center>Вы можете получить образы в награду за участие в событиях Авалора, либо купив их в разделе <img src="/images/icons/gold.png"><a href="/gold/skin/"><font color="gold"><b>Золото</b></font></a>.</center></div>';

$count = $base->query("SELECT * FROM `users_skins` WHERE `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_skins` WHERE `user` = '".$u['id']."' ORDER BY `id` ASC LIMIT $start,10");
if($count > 0){
	echo '<table width="100%">';
	$i = 1;
	while($uskin = $sql->fetch_assoc()){
		$skin = $base -> query("SELECT * FROM `skins` WHERE `id` = '".$uskin['skin']."' LIMIT 1") -> fetch_assoc();
		if($skin['sex'] == 1) $sex = 'Мужской';
		elseif($skin['sex'] == 2) $sex = 'Женский';
		if($skin['skin'] == $u['skin']) $used = '<br/><img src="/images/icons/yes.png" height="12px"><font style="font-size: 11px; color: limegreen;">Используется</font>';
		else $used = '';
		if($i == 1) echo '<tr>';
		echo '<td width="50%"><a class="btn" style="height: 62px; margin: 0px; font-size: 12px" href="/skins/change/'.$skin['id'].'/"><img style="float: left;" src="/images/skins/'.$skin['skin'].'.gif"> <b>'.$skin['name'].'</b><br/>
		<font style="font-size: 11px; color:#B1B1B1;">'.$sex.'</font>
		'.$used.'</a></td>';
		if($i == 2){
			$i = 0;
			echo '</tr>';
		}
		$i ++;
	}
	echo '<td width="50%"><a class="btn" style="margin: 0px;" href="/gold/skin/"><img src="/images/skins/13.gif"> <font style="font-size: 11px; color:gold;"><b>Купить образ</b></font></a></td>';
	echo '</table>';
	if($count > '10'){
		echo str('?',$k_page,$page);
	}
}else{
	echo '<a class="btn" href="/gold/skin/"><img src="/images/skins/13.gif"> <font color="gold"><b>Купить образы</b></font></a>';
}
echo '<br/><a class="btn" href="/user/'.$u['id'].'/"><img src="/images/icons/back.png"> Назад</a>';

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