<?


include 'connect.php';

if(!$u['id']){
header ("Location: aut.php");
exit;
}

switch($_GET['act'])
{
//Пользователи ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
case 'users':

$title = $title.' | Знакомства';
include 'head.php';

$online = num($_GET['online']);
if($online) {
echo '<div class="title"><img src= "img/love.png"> Знакомства - Сейчас на сайте</div>';
$vzapros = "WHERE `online` > '".(time()-$system['online_time'])."'";
} else {
   $sex = num($_GET['sex']);
   if($sex) {
      if($sex == 1){
      echo '<div class="title"><img src= "img/love.png"> Знакомства - Девушки</div>';
      $vzapros = "WHERE `sex` = 'zh'";
      } else {
      echo '<div class="title"><img src= "img/love.png"> Знакомства - Парни</div>';
      $vzapros = "WHERE `sex` = 'm'";
      }
   }
}

if(!$online && !$sex){
   echo '<div class="title"><img src= "img/love.png"> Знакомства - Все пользователи</div>';
   $vzapros = "";
}

echo '<div class="subtitle"><a href = "love.php">В знакомства</a></div>';

//Пользователей на страницу
if($u['setting_users_list']) $count = $u['setting_users_list']; else $count = 10;

echo '<div class="main_menu">';
$all = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` $vzapros"), 0);
if($all > 0){
   $total = intval(($all - 1) / $count) + 1;
   $page = num($_GET['page']);
   if(empty($page) or $page < 0) $page = 1; 
   if($page > $total) $page = $total;
   $start = $page * $count - $count;
   $result = mysql_query("SELECT * FROM `users` $vzapros ORDER BY `rating` DESC LIMIT $start, $count");
      while($user = mysql_fetch_assoc($result)){
	  echo '<table><tr>';
	     echo '<td VALIGN=top>';
		    ava($user['id'],35);
	     echo '</td>';
		 
		 echo '<td VALIGN=top>';
		    echo ''.ico($user['sex'],$user['admin']).' <a href = "page.php?id='.$user['id'].'">'.$user['login'].'</a> '.online($user['online']).'';
		    echo '<br/>';
			if($user['id'] != $u['id']){
	           echo '<img src = "img/mail.gif"> <a href = "mail.php?act=write&id='.$user['id'].'">Сообщение</a><br/>';
	           //Проверяем не друг ли
               $req = mysql_query("SELECT * FROM `friends` WHERE `user` = '".$u['id']."' and friend = '".$user['id']."' LIMIT 1");
               if(mysql_num_rows($req))
               echo '<img src = "img/friends.gif"> <a href = "friends.php?act=delete&id='.$user['id'].'">Убрать из друзей</a><br/>';
               else 
	           echo '<img src = "img/friends.gif"> <a href = "friends.php?act=adding&id='.$user['id'].'">Добавить в друзья</a><br/>';
	           }
		 echo '</td>';
	  echo '</tr></table>';
	  echo '<hr>';
	  }
	  navigation($page, $total,'love.php?act=users&online='.$online.'&sex='.$sex.'&');
}else{
echo 'Пользователей не найдено!';
}
echo '</div>';
include 'foot.php';
break;
//Главная ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
default:

$title = $title.' | Знакомства';
include 'head.php';

//Подзаголовок
echo '<div class="title"><img src= "img/love.png"> <b>Знакомства</b></div>';

echo '<div class="block_view">';
echo '<b>Активная 5-ка сети</b>';
$cusers_5 = mysql_result(mysql_query("SELECT COUNT(*) FROM `users`"), 0);
if($cusers_5 > 0){
   $result = mysql_query("SELECT * FROM `users` ORDER BY `rating` DESC LIMIT 0, 5");
      echo '<table><tr align="center">';
	  while($user = mysql_fetch_assoc($result)){
	  echo '
      <td>';
	  ava_k($user['id'],30);
	  echo '</td>';
	  }
	  echo '</tr></table>';
	  
}else{
echo 'Пользователей не найдено!';
}
echo '</div>';
$cusers_online = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `online` > '".(time()-$system['online_time'])."'"), 0);
echo '<hr><div class = "block_2"><a href = "search.php?act=go&online=1"><img src = "img/users_online.gif"> Сейчас на сайте ('.$cusers_online.')</a></div>';
$cusers_zh = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `sex` = 'zh'"), 0);
echo '<div class = "block_2"><a href = "search.php?act=go&sex=zh"><img src = "img/0.png"> Девушки ('.$cusers_zh.')</a></div>';
$cusers_m = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `sex` = 'm'"), 0);
echo '<div class = "block_2"><a href = "search.php?act=go&sex=m"><img src = "img/1.png"> Парни ('.$cusers_m.')</a></div>';
$cusers = mysql_result(mysql_query("SELECT COUNT(*) FROM `users`"), 0);
echo '<div class = "block_2"><a href = "search.php?act=go"><img src = "img/users.gif"> Все пользователи ('.$cusers.')</div>';
echo '<div class = "block_2"><a href = "search.php"><img src="img/search.gif"> Поиск</a></div>';

include 'foot.php';
break;

break;
}


?>