<?
include './system/common.php';
include './system/functions.php';
include './system/user.php';
    
if(!$user) {
header('location: /');    
exit;}

$action = _string($_GET['action']);

switch($action) {
default:
    
$title = 'Игроки онлайн';
include './system/h.php';  
echo'<div class="title">'.$title.'</div>';
echo'<table width="100%" border="0" cellpadding="0" cellspacing="0" style="padding-top: 5px;">
<tbody><tr>
<td width="50%" class="bar bar_select">
<a href="/online">Все</a></td>
<td width="50%" class="bar">
<a href=/online/no_clan>Без клана</a></td>
</tr></tbody>
</table>';



$max = 10;
$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `users` WHERE `online` > "'.(time() - 300).'"'),0);
$pages = ceil($count/$max);
$page = _string(_num($_GET['page']));

if($page > $pages) {$page = $pages;}
if($page < 1) {$page = 1;}
    
$start = $page * $max - $max;
$q = mysql_query('SELECT * FROM `users` WHERE `online` > "'.(time() - 300).'" ORDER BY `online` DESC, `level` DESC LIMIT '.$start.', '.$max.'');
while($row = mysql_fetch_array($q)) {
  
echo'<div class="block_link">
<a href="/user/'.$row['id'].'/"> '.nick($row['id']).'
<small> <img src="/images/ico/png/up.png" alt="*" width="14"/>'.$row['level'].' ур</small> </a></div>
<div class="line"></div>';


}


echo''.pages('?').'';
echo'<div class="line"></div>
<div class="block_link"><a href="/online/search/"><img src="/images/ico/png/search.png"> Поиск игроков</a></div>
<div class="line"></div>';

include './system/f.php';
break;



case 'no_clan':
$title = 'Игроки онлайн';
include './system/h.php';  
echo'<div class="title">'.$title.'</div>';
echo'<table width="100%" border="0" cellpadding="0" cellspacing="0" style="padding-top: 5px;">
<tbody><tr>
<td width="50%" class="bar">
<a href="/online">Все</a></td>
<td width="50%" class="bar bar_select">
<a href=/online/no_clan>Без клана</a></td>
</tr></tbody>
</table>';





$max = 10; 
$count = mysql_num_rows(mysql_query("SELECT `id` FROM `users` WHERE (SELECT COUNT(`user`) FROM `clan_memb` WHERE `user` = `users`.`id`)  = 0  and `users`.`online` > '".(time() - 300)."'")); 
$pages = ceil($count/$max); 
$page = _string(_num($_GET['page'])); 
if($page > $pages) { 
$page = $pages; 
} 
if($page < 1) { 
$page = 1; 
} 
$start = $page * $max - $max; 
$q = "SELECT * FROM `users` WHERE (SELECT COUNT(`user`) FROM `clan_memb` WHERE `user` = `users`.`id`)  = 0  and `users`.`online` > '".(time() - 300)."' ORDER BY `online` DESC LIMIT ".$start.", ".$max.""; 
$q = mysql_query($q);
while($row = mysql_fetch_array($q)) {
echo'<div class="block_link">
<a href="/user/'.$row['id'].'/"> '.nick($row['id']).'
<small> <img src="/images/ico/png/up.png" alt="*" width="14"/>'.$row['level'].' ур</small> </a></div>
<div class="line"></div>';
}

if($count == '0'){
echo'<div class="empty_block item_center">	
Нет игроков 
</div><div class="line"></div>';
}
echo''.pages('?').'';
echo'<div class="line"></div>';
include './system/f.php'; 
break; 



case 'search':
$title = 'Поиск игрока';
include './system/h.php';  


$login = _string($_POST['login']);
  if(isset($_REQUEST['search'])){
$users = mysql_query('SELECT * FROM `users` WHERE `login` = "'.$login.'"');
$users = mysql_fetch_array($users);
  
  if($users) {
header('location: /user/'.$users['id'].'/');
}else{
	if(empty($login) or mb_strlen($login,'UTF-8') < 3){
header("Location: ?");
$_SESSION['mes'] = mes('Персонаж с таким именем не был найден!');
exit;}
}
}



echo'<div class="title">'.$title.'</div>';
     echo' '.$_SESSION['mes'].'  ';
    $_SESSION['mes']=NULL; //Удаляем сесию
echo'<div class="empty_block item_center">
  <form action="/online/search/" method="post">
    Имя персонажа:<br/><input name="login"/><br/>
    <input name="search" class="button" type="submit" value="Поиск"/>
  </form>
</div>';

echo'<div class="line"></div>
<div class="block_link"><a href="/online/"><img src="/images/ico/png/back.png"> Вернуться</a></div>
<div class="line"></div>';

include './system/f.php';
break;
  
}
?>