<?php
  
//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Пользователи')."</a>";
ECHO "</div>";

ECHO "<div class='tmenu_body'>";

IF (GET('type') == 'online'){
  
  $sql = "WHERE `DATE_VISIT` > '".(TIME()-CONFIG('ONLINE_TIME_USERS'))."' ORDER BY `DATE_VISIT` DESC";
  $url = "&type=online";
  
  ECHO "<a href='/modules/?path=users&type=online' class='tmenu-33 tmenu-33-o'>".LG('Онлайн')."</a>";
  ECHO "<a href='/modules/?path=users' class='tmenu-33'>".LG('Все')."</a>";
  ECHO "<a href='/modules/?path=users&type=rating' class='tmenu-33'>".LG('Рейтинг')."</a>";
  
}ELSEIF (GET('type') == 'rating'){
  
  $sql = "ORDER BY `RATING` DESC";
  $url = "&type=rating";
  
  ECHO "<a href='/modules/?path=users&type=online' class='tmenu-33'>".LG('Онлайн')."</a>";
  ECHO "<a href='/modules/?path=users' class='tmenu-33'>".LG('Все')."</a>";
  ECHO "<a href='/modules/?path=users&type=rating' class='tmenu-33 tmenu-33-o'>".LG('Рейтинг')."</a>";
  
}ELSE{
  
  $sql = "ORDER BY `ID` DESC";
  $url = NULL;
  
  ECHO "<a href='/modules/?path=users&type=online' class='tmenu-33'>".LG('Онлайн')."</a>";
  ECHO "<a href='/modules/?path=users' class='tmenu-33 tmenu-33-o'>".LG('Все')."</a>";
  ECHO "<a href='/modules/?path=users&type=rating' class='tmenu-33'>".LG('Рейтинг')."</a>";
  
}

ECHO "</div>";

//Поиск
REQUIRE (ROOT.'/modules/search/plugins/form/users.php');

ECHO "<div class='list'>";

ECHO "<a class='h1 h' href='/modules/?path=users&type=online'>".LG('Пользователи')."</a>";
ECHO "<a class='h1' href='/modules/?path=users&section=guests'>".LG('Гости')."</a>";

ECHO "</div>";

$column = DB::GET_COLUMN("SELECT COUNT(*) FROM `USERS` ".$sql."");
$spage = SPAGE($column, $page_settings);
$page = PAGE($spage);
$limit = $page_settings * $page - $page_settings;

IF ($column == 0){ 
  
  HTML::EMPTY();
  
}ELSE{
  
  ECHO "<div class='list-body'>"; 
  
}

IF (GET('type') == 'rating'){
  
  $s = 0;

}

$data = DB::GET_STRING_ALL("SELECT * FROM `USERS` ".$sql." LIMIT ".$limit.", ".$page_settings."");

WHILE ($list = $data->FETCH())
{
  
  $account_settings = DB::GET_STRING("SELECT * FROM `USERS_SETTINGS` WHERE `USER_ID` = '".$list['ID']."' LIMIT 1");
  
  ECHO "<div class='list-menu'>"; 
  
  ECHO "<a href='/id".$list['ID']."'><table style='width: 100%;'><tr>";
  
  ECHO "<td class='us-avatar'>";
  ECHO USER::AVATAR($list['ID'], 50, 0, 1)."";
  ECHO "</td>";
  
  $c_f = DB::GET_STRING("SELECT * FROM `COUNTRY` WHERE `NAME` = '".TEXT_ABSOLUTE($account_settings['COUNTRY'])."' LIMIT 1");
  
  IF ($account_settings['COUNTRY'] > NULL || $account_settings['CITY'] > NULL){
    
    $crc = TEXT_ABSOLUTE($account_settings['CITY']).", ".TEXT_ABSOLUTE($account_settings['COUNTRY']);
  
  }ELSE{
    
    $crc = NULL;
  
  }
  
  $age = _AGE($list['ID'], AGE($list['ID'], $account_settings['G_R'], $account_settings['M_R'], $account_settings['D_R']), ARRAY(LG('год'), LG('года'), LG('лет')));
  
  ECHO "<td class='us-info'>";
  ECHO "".USER::LOGIN($list['ID'])."<br /><small>".$crc." ".($c_f['ID'] != NULL ? '<img src="/style/country/'.$c_f['ID'].'.png"><br />' : NULL)."";
  ECHO TEXT_ABSOLUTE($age);

  ECHO "<br /><font color='black'>".LG('Посл. визит').": ".FTIME($list['DATE_VISIT'])."</font>";
  
  IF (GET('type') == 'rating'){
    
    $s++;
    
    ECHO "<br /><br /><b><font color='black'>".LG('Рейтинг').": ".$list['RATING']."</b> - ".$s." ".LG('место')."</font>";
    
  }
  
  ECHO "</small></td>";
  
  ECHO "</tr></table></a>";
  
  IF (ISSET($user)){
    
    IF ($list['ID'] != $user['ID']){
      
      //Дружба + подписка
      REQUIRE (ROOT.'/modules/users/plugins/friends_and_subscribers.php');
      
      ECHO "<a class='btn' href='/users/profile/?path=mail&section=write&id=".$list['ID']."'>".ICONS('envelope', 15, 'fa-fw')." ".LG('Написать')."</a>";
      
    }
    
  }
  
  ECHO "</div>";
  
}

IF ($column > 0){

  ECHO "</div>";
  
}

IF ($spage > 1){ ECHO STR_PAGE('/modules/?path=users'.$url.'&', $spage, $page); }

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Пользователи')."</a>";
ECHO "</div>";
  
?>