<?php
include_once 'sys/inc/start.php';
$doc = new document();
$doc->title = 'Пользователи';

switch (@$_GET['order']) {
case 'group':$order ='group';$sort='DESC';$where="WHERE `group` >= '2'";$doc -> title ='Администрация'; break;
case 'login':$order ='login';$sort='ASC';$where='';break;
case 'balls':$order ='balls';$sort='DESC';$where='';break;
default:$order ='id';$sort='DESC';$where='';break;
}




if (!empty($_GET['search']))$search = text::input_text($_GET['search']);
if (isset($search) && !$search)$doc->err('Пустой запрос');
elseif (isset($search) && $search)
{
$where="WHERE `login` LIKE '%".my_esc($search)."%'";$doc -> title ='Поиск по "'.$search.'"';
}



$posts = array();
$pages = new pages;
$pages -> posts = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` $where"),0);
$pages -> this_page(); // получаем текущую страницу

// меню сортировки
$ord = array();
$ord[]=array("?order=id&amp;page={$pages->this_page}".(isset($search)?'&amp;search='.urlencode($search):''),'ID',$order=='id');
$ord[]=array("?order=login&amp;page={$pages->this_page}".(isset($search)?'&amp;search='.urlencode($search):''),'Логин',$order=='login');
$ord[]=array("?order=balls&amp;page={$pages->this_page}".(isset($search)?'&amp;search='.urlencode($search):''),'Баллы',$order=='balls');
$ord[]=array("?order=group&amp;page={$pages->this_page}".(isset($search)?'&amp;search='.urlencode($search):''),'Статус',$order=='group');
$or = new design();
$or->assign('order',$ord);
$or->display('design.order.tpl');





$q = mysql_query("SELECT * FROM `users` $where ORDER BY `$order` $sort LIMIT {$pages->my_start()}, {$pages->items_per_page}");
while ($ank=mysql_fetch_assoc($q)) {
$p_user = new user($ank['id']);
$info = $order=='id'?'ID: '.$ank['id']."<br />\n":'';

if ($order=='group')$info .= $p_user->group_name."<br />\n";
if ($order=='balls')$info .= 'Баллы: '.((int)$p_user->balls)."<br />\n";
$info .= 'Регистрация: '.date('d-m-Y',$p_user->reg_date)."<br />\n";
$info .= 'Последний визит: '.vremja($p_user->last_visit).'<br />';

$posts[]=array('title'=>$p_user->show(),'icon'=>$p_user->icon(),'post'=>$info);
unset($p_user);
}
if (!$posts)$posts[]=array('icon'=>array('size'=>'small','src'=>'/sys/images/icons/empty.png'),'title'=>'Нет пользователей');

$smarty = new design();
$smarty->assign('method','get');
$smarty->assign('action','?');
$elements=array();
$elements[]=array('type'=>'hidden', 'info'=>array('name'=>'order', 'value' => $order));
$elements[]=array('type'=>'input_text', 'title'=>'Ник или его часть', 'br'=>0, 'info'=>array('name'=>'search', 'value' => @$search));
$elements[]=array('type'=>'submit', 'br'=>0, 'info'=>array('value'=>'Поиск')); // кнопка
$smarty->assign('el',$elements);
$smarty->display('input.form.tpl');

$show = new design();
$show->assign('post',$posts);
$show->display('design.listing.tpl');


$pages->listing("?order=$order&amp;".(isset($search)?'search='.urlencode($search).'&amp;':'')); // вывод страниц





?>
