<?
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';
echo "<div class=\"post\"><img src='/style/icons/search.png' alt=''/> Поиск по нику:</div>\n";
echo "<form method=\"post\" action=\"/users.php?go\">";
echo "<input type=\"text\" name=\"usearch\" maxlength=\"16\" value=\"$usearch\" />\n";
echo "<input type=\"submit\" value=\"Искать\" />";
echo "</form>\n";
$sort='id';

$por='DESC';

if (isset($_GET['ASC']))$por='ASC'; // прямой порядок
if (isset($_GET['DESC']))$por='DESC'; // обратный порядок

if (isset($_GET['sort']))
{
switch ($_GET['sort']) {
case 'balls':$sort='balls'; // баллы
break;
case 'level':$sort='level'; // уровень
break;
case 'rating':$sort='rating'; // рейтинг
break;
case 'pol':$sort='pol'; // пол
break;
case 'id':$sort='id'; // ID
break;
}




}



if (!isset($_GET['go']))
{

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `user`"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];



echo "<div style='background-color:#696969;border-top:1px solid #FF8C00;border-bottom:1px solid #FF8C00;padding:2px'>\n";
echo "<u style=\"color: #000000;\"><b>Сортировать по:<br/>\n";
echo "<a href=\"?sort=balls&DESC&page=$page\">баллы</a>| \n";
echo "<a href=\"?sort=rating&DESC&page=$page\">рейтинг</a>| \n";
echo "<a href=\"?sort=id&DESC&page=$page\">новые</a> \n";
echo "</div>\n";


echo "<table class='post'>\n";
if ($k_post==0)
{
echo "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "Нет результатов\n";
echo "  </td>\n";
echo "   </tr>\n";

}
$q=mysql_query("SELECT * FROM `user` ORDER BY `$sort` $por LIMIT $start, $set[p_str]");
while ($ank = mysql_fetch_array($q))
{
echo "   <tr>\n";

if ($set['set_show_icon']==1){
}
elseif ($set['set_show_icon']==1)
echo "  </td>\n";
{
echo "  <td class='menu'>\n";
if(is_file("sys/avatar/$ank[id].gif")){
echo "<img src='/sys/avatar/$ank[id].gif' align='left' width='40' height='50' alt='' style='margin-right:4px;border-right:1px solid #99ccff'>\n";
}else if(is_file("sys/avatar/$ank[id].jpg")){
echo "<img src='/sys/avatar/$ank[id].jpg' align='left' width='40' height='50' alt='' style='margin-right:4px;border-right:1px solid #99ccff'>\n";
}else if(is_file("sys/avatar/$ank[id].png")){
echo "<img src='/sys/avatar/$ank[id].png' align='left' width='40' height='50' alt='' style='margin-right:4px;border-right:1px solid #99ccff'>\n";
}else{
echo '<img src="/sys/avatar/0.png" align="left" width="40" height="50" alt="" style="margin-right:4px;border-right:1px solid #99ccff">';}
}
echo "  <td class='p_t'>\n";
echo "".online($ank['id'])."\n";
echo "<a href='/info.php?id=$ank[id]'>$ank[nick]</a>\n";
echo "<br/>\n";
if ($ank['pol']==1)
echo "Пол: <span class=\"menu\">Муж</span>\n";
else
echo "Пол: <span class=\"menu\">Жен</span>\n";
echo "<br/>\n";
if ($ank['ank_d_r']!=NULL && $ank['ank_m_r']!=NULL && $ank['ank_g_r']!=NULL){
$ank['ank_age']=date("Y")-$ank['ank_g_r'];
if (date("n")<$ank['ank_m_r'])$ank['ank_age']=$ank['ank_age']-1;
elseif (date("n")==$ank['ank_m_r']&& date("j")<$ank['ank_d_r'])$ank['ank_age']=$ank['ank_age']-1;
echo "Возраст: <span class=\"menu\">$ank[ank_age] лет</span>\n";
echo "<br/>\n";
}
if ($ank['ank_city']!=NULL)echo "Откуда: <span class=\"menu\">$ank[ank_city]</span><br />\n";
else
echo "Откуда: неизвестно<br />\n";


if ($sort=='rating')
echo "<span class=\"ank_n\">Рейтинг:</span> <span class=\"ank_d\">$ank[rating]</span><br />\n";
if ($sort=='balls')
echo "<span class=\"ank_n\">Рейтинг:</span> <span class=\"ank_d\">$ank[balls]</span><br />\n";

if ($sort=='pol')
echo "<span class=\"ank_n\">Пол:</span> <span class=\"ank_d\">".(($ank['pol']==1)?'Мужской':'Женский')."</span><br />\n";
}
echo "</table>\n";
if ($k_page>1)str("users.php?sort=$sort&$por&",$k_page,$page); // Вывод страниц

}


$usearch=NULL;
if (isset($_SESSION['usearch']))$usearch=$_SESSION['usearch'];
if (isset($_POST['usearch']))$usearch=$_POST['usearch'];

if ($usearch==NULL)
unset($_SESSION['usearch']);
else
$_SESSION['usearch']=$usearch;
$usearch=ereg_replace("( ){1,}","",$usearch);


if (isset($_GET['go']) && $usearch!=NULL)
{
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `nick` like '%".mysql_escape_string($usearch)."%' OR `id` = '".intval($usearch)."'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
if ($k_post==0)
{
echo "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "Нет результатов\n";
echo "  </td>\n";
echo "   </tr>\n";

}
$q=mysql_query("SELECT * FROM `user` WHERE `nick` like '%".mysql_escape_string($usearch)."%' OR `id` = '".intval($usearch)."' ORDER BY `$sort` $por LIMIT $start, $set[p_str]");
while ($ank = mysql_fetch_array($q))
{
echo "   <tr>\n";

if ($set['set_show_icon']==1){
}
elseif ($set['set_show_icon']==1)
echo "  </td>\n";
{
echo "  <td class='menu'>\n";
if(is_file("sys/avatar/$ank[id].gif")){
echo "<img src='/sys/avatar/$ank[id].gif' align='left' width='40' height='50' alt='' style='margin-right:4px;border-right:1px solid #99ccff'>\n";
}else if(is_file("sys/avatar/$ank[id].jpg")){
echo "<img src='/sys/avatar/$ank[id].jpg' align='left' width='40' height='50' alt='' style='margin-right:4px;border-right:1px solid #99ccff'>\n";
}else if(is_file("sys/avatar/$ank[id].png")){
echo "<img src='/sys/avatar/$ank[id].png' align='left' width='40' height='50' alt='' style='margin-right:4px;border-right:1px solid #99ccff'>\n";
}else{
echo '<img src="/sys/avatar/0.png" align="left" width="40" height="50" alt="" style="margin-right:4px;border-right:1px solid #99ccff">';}
}
echo "  <td class='p_t'>\n";
echo "".online($ank['id'])."\n";
echo "<a href='/info.php?id=$ank[id]'>$ank[nick]</a>\n";
echo "<br/>\n";
if ($ank['pol']==1)
echo "Пол: <span class=\"menu\">Муж</span>\n";
else
echo "Пол: <span class=\"menu\">Жен</span>\n";
echo "<br/>\n";
if ($ank['ank_d_r']!=NULL && $ank['ank_m_r']!=NULL && $ank['ank_g_r']!=NULL){
$ank['ank_age']=date("Y")-$ank['ank_g_r'];
if (date("n")<$ank['ank_m_r'])$ank['ank_age']=$ank['ank_age']-1;
elseif (date("n")==$ank['ank_m_r']&& date("j")<$ank['ank_d_r'])$ank['ank_age']=$ank['ank_age']-1;
echo "Возраст: <span class=\"menu\">$ank[ank_age] лет</span>\n";
echo "<br/>\n";
}
if ($ank['ank_city']!=NULL)echo "Откуда: <span class=\"menu\">$ank[ank_city]</span><br />\n";
else
echo "Откуда: неизвестно<br />\n";
if ($sort=='rating')
echo "<span class=\"ank_n\">Рейтинг:</span> <span class=\"ank_d\">$ank[rating]</span><br />\n";
if ($sort=='balls')
echo "<span class=\"ank_n\">Рейтинг:</span> <span class=\"ank_d\">$ank[balls]</span><br />\n";

if ($sort=='pol')
echo "<span class=\"ank_n\">Пол:</span> <span class=\"ank_d\">".(($ank['pol']==1)?'Мужской':'Женский')."</span><br />\n";
}
if ($k_page>1)str("users.php?go&",$k_page,$page); // Вывод страниц
echo "<br/>\n";
}

include_once 'sys/inc/tfoot.php';
?>
