<?php
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
$set['title']='Бармен онлайн';
include_once '../sys/inc/thead.php';
title();
aut();

if(!isset($user)){
  echo "Вы не зарегистрированы";
  include_once '../sys/inc/tfoot.php';
  break;
}

include_once 'inc/start.php';

if(isset($_POST['search'])){
$sort=$_POST['sort1'];
$sort_order=$_POST['sort2'];

if(!in_array($sort,array('level','money','exp','nap')))$sort='level';
if(!in_array($sort_order,array('ASC','DESC')))$sort_order='ASC';

$_SESSION['bar_sort']=mysql_real_escape_string($sort);
$_SESSION['bar_sort_order']=mysql_real_escape_string($sort_order);

}


$sort=(isset($_SESSION['bar_sort']) ? $_SESSION['bar_sort'] : 'level');
$sort_order=(isset($_SESSION['bar_sort_order']) ? $_SESSION['bar_sort_order'] : 'ASC');

echo "
<div class='".$diz['main']."'>
<div class='".$diz['title2']."'>Сортировка</div>
<form method='post' action='rate.php?".mt_rand()."'>
<select name='sort1'>
<option value='level' ".($sort=='level' ? "selected='select'" : "").">По уровню</option>
<option value='money' ".($sort=='money' ? "selected='select'" : "").">По деньгам</option>
<option value='exp' ".($sort=='exp' ? "selected='select'" : "").">По опыту</option>
<option value='nap' ".($sort=='nap' ? "selected='select'" : "").">По кол-ву опьянений</option>
</select> 
<select name='sort2'>
<option value='ASC' ".($sort_order=='ASC' ? "selected='select'" : "").">По возрастанию</option>
<option value='DESC' ".($sort_order=='DESC' ? "selected='select'" : "").">По убыванию</option>
</select> 
<input type='submit' name='search' value='&raquo;'/></form>
<div class='".$diz['title2']."'>Рейтинг</div>
";
$total=mysql_result(mysql_query("SELECT COUNT(*) FROM `bar_user`"),0);
$tmp_array=array('level'=>'Уровень','money'=>'Деньги','exp'=>'Опыт','nap'=>'Напился');
if($total>0){
$quert=mysql_query("SELECT * FROM `bar_user` ORDER BY `".$sort."` ".$sort_order." LIMIT ".$start.",5");

$i=0;
while($array=mysql_fetch_array($quert)){

$post=($i%2 ? $diz['post_1'] : $diz['post_2']);
echo '<div class="'.$post.'">
<table cellpadding="0">
<tr>
<td>
<img src="i/user_male.png"/>
</td>
<td>
<a href="profile.php?id='.$array['id_u'].'">'.$array['login'].'</a><br/>
'.$tmp_array[$sort].' : '.$array[$sort].' '.($sort=='nap' ? "раз" : "").'
<br/>
</td></tr></table></div>';
$i++;
}




if ($total > 5){
    echo bar_pagenav('rate.php?', $start, $total, 5);
   }
   }

   

echo "</div>";
ret($diz['ret'],'Мой бар','index.php');
 include_once '../sys/inc/tfoot.php';
?>
