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

$header = 'Друзья';
include_once ('./core/head.php');

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

if($_GET['delete'] != ''){
	$fr_nr = $base -> query('SELECT * FROM `friends` WHERE `user` = "'.$u['id'].'" AND `friend` = "'.$_GET['delete'].'" LIMIT 1') -> num_rows;
	if($fr_nr > 0){
		$base -> query('DELETE FROM `friends` WHERE `user` = "'.$u['id'].'" AND `friend` = "'.$_GET['delete'].'" LIMIT 1');
		$_SESSION['message'] = 'Игрок удалён из списка друзей.';
		header('Location: /friends/');
		exit;
	}else{
		header('Location: /friends/');
		exit;
	}
}

echo '<div class="b"><div class="title">Друзья</div>';

$count = $base -> query("SELECT * FROM `friends` 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 `friends` WHERE `user` = '".$u['id']."' ORDER BY `id` DESC LIMIT $start,10");
if($count > 0){
	while($friends = $sql -> fetch_assoc()){
		$friend = $base -> query('SELECT * FROM `users` WHERE `id` = "'.$friends['friend'].'" LIMIT 1') -> fetch_assoc();
		$friend_avatar='/images/skins/'.$friend['skin'].'_big.png';
		echo '<table width="100%" style="margin-top: 5px; border-spacing: 0px;"><tr><td style="padding: 0px; margin-right: 25px;" width="89%"><a class = "btn_table" href="/user/'.$friend['id'].'/"><img src="'.$friend_avatar.'" width="24px"> '.nolinkname($friend['id']).'</a></td>
		<td width="1%"></td><td style="padding: 0px;" width="10%"><center><a class = "btn_table" href="/friends/delete/'.$friend['id'].'/"><img src="/images/icons/no.png"></a></center></td></tr></table>';
		}
	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>';

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