<?php

  include 'system/core.php';
  include 'system/header.php';

  if(!$user['id']){
  header('Location: /index.php/?m=guest'); exit;
  }
 
echo '<div class="tegi"><b>Список мастеров</b></div></div>';
echo '</div>';

    echo '
  <div class="men"><span>
  
  <a href="/users.php?sort=0">По ID</a> |  <a href="?sort=1">Новенькие</a> | <a href="/users.php?m=search">Поиск</a></span> </span>
 </div> </div>
  ';



  switch($_GET['m']){
  
  default:
    
  $cop = 10;
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `user`"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  
  $sort = trim($_GET['sort']);
  if(empty($sort) or !is_numeric($sort) or $sort < 0 or $sort > 2){
  
  $sort2 = 'id';
  $sort = 0;
  
  }elseif($sort == 1){
  
  $sort2 = 'registration';
  $desc  = 'DESC';
  
  }elseif($sort == 2){
  
  $sort2 = 'rating';
  $desc  = 'DESC';

  }
  
  $users = mysql_query("SELECT * FROM `user` ORDER BY `$sort2` $desc LIMIT $start,$cop");

  while($users2 = mysql_fetch_assoc($users)){
 echo '<div class="post2"><table cellpadding="0" cellspacing="4"><tr><td style="width: 40px; vertical-align: top; height: 40px; margin: 0; padding:0; border: 0;" id="mail_avatar"><img src="/modules/profile/';
  if(empty($users2['ava'])) echo 'images/noava.png'; else echo 'ava/'.$users2['ava'];
  echo '"style="max-width:40px;"/>';
echo '</td><td style="vertical-align: top;" id="mail_textarea">'.ustatus($users2['id']).' <a href="/us'.$users2['id'].'">'.uname($users2['id']).' </a>'.ced($users2['id']).''.uaccess($users2['id']);
  if(empty($sort)) echo ' (ID '.$users2['id'].')';
  if($sort == 1) echo ' ('.times($users2['registration']).')';
  elseif($sort == 2) echo ' ('.$users2['rating'].')';
echo '<br/>Рейтинг: <font color="green">'.$users2['rating'].'</font><br/>Активность: '.times($users2['online']).'';
echo '</td></tr></table></div>';

}

  echo '<div class="levo">Стр. ';
  if($p-2>0) echo '<a href="/users.php?p=1"><<</a> ';
  if($p-1>0) echo '<a href="/users.php?p='.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/users.php?p='.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/users.php?p='.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/users.php?p='.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/users.php?p='.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/users.php?p='.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/users.php?p='.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/users.php?p='.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/users.php?p='.ceil($ca/$cop).'">>></a>';
 
 echo '</div>'; 
  break;
 /////////////////////// 
  
 case 'search':

if(isset($who)){
$type = TextGuard($type);
  $who = TextGuard($who);
  if(empty($who)) $err[] = 'ID или ник осталось пыстым';
  if(!empty($who)) if($type == 1 && !is_numeric($who)) $err[] = 'В ID разрешено вводить только цифры'; 
  if($type == 1){
  $users = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$who.'"'));
  }else{
  $users = mysql_fetch_array(mysql_query('select * from `user` where `login` = "'.$who.'"'));
  }
 
  if(!empty($who)) if($users == 0) $err[] = 'Такого пользователя не существует';
  

  if($err){
  echo '<div class="err"><b>';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</b></div>';  
  }else{

  
  
  echo '<div class="post2">'.ustatus($users['id']).' <a href="/us'.$users['id'].'">'.uname($users['id']).'</a> '.uaccess($users['id']).'</div>';




  }
  }else{


  echo '
  <div class="post">
  <form action="" method="post">
 
  Тип поиска: </br><input type="radio" name="type" value="1" checked="checked" /> ID
<input type="radio" name="type" value="2" /> Ник<br/></br>Запрос:</br>
  <input name="who"/><br><br>
  <input type="submit" value="Искать"/>
  </form></div>';
  }

break;  
 /////////////////  
  
  }

  include 'system/footer.php';

?>