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

$header = 'Онлайн';
include_once ('core/head.php');

echo '<div class="b">';

switch($_GET['case']){
	default:

	echo '<div class="title">Онлайн</div>';

	$k_post = $base -> query("SELECT * FROM `users` WHERE `date_online` > '".(time()-600)."'")->num_rows;

	$k_page = k_page($k_post,10);

	$page = page($k_page);

	$start = 10*$page-10;

	$sql  = $base -> query("SELECT * FROM `users` WHERE `date_online` > '".(time()-600)."' ORDER BY `level` DESC LIMIT $start, 10");

	while($row = $sql -> fetch_assoc()){
			$row_avatar = '/images/skins/'.$row['skin'].'_big.png';
			echo '<a class="btn" href="/user/'.$row['id'].'/"><img src="'.$row_avatar.'" width="24px"> '.nolinkname($row['id']).'</a>';
	}

	if($k_post < 1){
		echo '<br/><center>Список игроков онлайн пуст.</center><br/>';
	}

	if ($k_page > 1){
	echo str('?id=&',$k_page,$page); // Вывод страниц
	}

	echo '<br/><a class="btn" href="/online/search/"><img src="/images/icons/magic_ball.png"> Поиск игроков</a>';

	break;

	case 'search':

	echo '<div class="title">Поиск</div>';

	echo '<center>
			<form action="/online/search/view" method="post">
				<input type="text" name="search" placeholder="Введите ник игрока."><br/>
				<input type="submit" name="success" value="Найти">
			</form>
		</center>';

	break;
	case 'resultsearch':

	echo '<div class="title">Результат поиска</div>';

	$search = fl($_POST['search']);
	if(empty($search)) error('Введён пустой запрос.');
	else{
		$count = $base -> query("SELECT * FROM `users` WHERE `login` = '".$search."'") -> num_rows;
		$k_page = k_page($count,10);
		$page = page($k_page);
		$start = 10*$page-10;
		$sql2  = $base -> query("SELECT * FROM `users` WHERE `login` = '".$search."' ORDER BY `id` ASC LIMIT $start, 10");
		if($count > 0){
			while($row = $sql2->fetch_assoc()){
				$row_avatar = '/images/skins/'.$row['skin'].'_big.png';
				echo '<a class="btn" href="/user/'.$row['id'].'/"><img src="'.$row_avatar.'" width="24px"> '.nolinkname($row['id']).'</a>';
			}
			if($count > '10') echo str('?',$k_page,$page);
			echo '<br/>';
		}else{
			echo '<br/><center>По данному запросу никого не найдено.</center><br/>';
		}
	}
	break;
}

echo '<a class="btn" href="javascript:history.go(-1)"><img src="/images/icons/back.png"> Назад</a>';

echo '</div>';

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