<?php

require '../system/start.php';
require '../system/functions.php';
$users = mysql_result(mysql_query("select count(*) from `users`"),0); 
$str['mesto'] = 'Обитатели';
$str['block'] = $set['site'].' / Обитатели';
include '../style/'.$style.'/head.php';
reg();
$boy = mysql_result(mysql_query("select count(*) from `users` where gender=1"),0); 
$girls = mysql_result(mysql_query("select count(*) from `users` where gender=2"),0);
echo '<div class="where">Сортировка<br/><a href="users.php?sort=name">Имя</a> | <a href="users.php?sort=on">Онлайн</a> | <a href="users.php?sort=date">Новички</a> | <a href="users.php?sort=rate">Рейтинг</a> | <a href="users.php?sort=man">Мальчики</a> ('.$boy.') | <a href="users.php?sort=woman">Девочки</a> ('.$girls.')</div>';
# Сортировка

if(!isset($_GET['sort']) or empty($_GET['sort']) or $_GET['sort'] == 'date')
{
	$sort = 'date';
	$users = mysql_query("select * from `users` order by `reg_time` desc limit ".$page.",".$set['str']."");
	$total = mysql_result(mysql_query("select count(*) from `users`"),0);
}
if(isset($_GET['sort']) && $_GET['sort']== 'name')
{
	$sort = 'name';
    $users = mysql_query("select * from `users` order by `name` limit ".$page.",".$set['str']."");
    $total = mysql_result(mysql_query("select count(*) from `users`"),0);
}
if(isset($_GET['sort']) && $_GET['sort']== 'on')
{
	$sort = 'on';
    $users = mysql_query("select * from `users` order by `time` desc limit ".$page.",".$set['str']."");
    $total = mysql_result(mysql_query("select count(*) from `users`"),0);
}
if(isset($_GET['sort']) && $_GET['sort']== 'rate')
{
	$sort = 'rate';
    $users = mysql_query("select * from `users` order by `rate` desc limit ".$page.",".$set['str']."");
    $total = mysql_result(mysql_query("select count(*) from `users`"),0);
}
if(isset($_GET['sort']) && $_GET['sort']== 'da')
{
	$sort = 'da';
    $users = mysql_query("select * from `users` where `zna` = da order by `rate` limit ".$page.",".$set['str']."");
	$total = mysql_result(mysql_query("select count(*) from `users` where `zna` = da"),0);
}
if(isset($_GET['sort']) && $_GET['sort'] == 'woman')
{
	$sort = 'woman';
    $users = mysql_query("select * from `users` where `gender` = 2 order by `rate` limit ".$page.",".$set['str']."");
	$total = mysql_result(mysql_query("select count(*) from `users` where `gender` = 2"),0);
}

# Конец сортировки


# Вывод юзера в онлайне
while($row = mysql_fetch_assoc($users))
{
	$i++;
	if($i%2)
	{
		echo '<div class="forum1"><div class="row4">';
	} else
	{
		echo '<div class="forum2"><div class="row4">';
	}
	if(empty($row['foto']))
	{
		echo '<img src="../style/'.$style.'/'.$row['gender'].'.png"  width="60" height="60" align="left" alt="" style="margin-right:4px;border-right:1px solid #99ccff"/>';
    }
    elseif(!empty($row['foto']))
	{
		echo '<img src="../files/avatars/'.$row['foto'].'"  width="60" height="60" align="left" alt="" style="margin-right:4px;border-right:1px solid #99ccff"/>';
    }


                            if ($row['gender'] == 1)
			$pol = '<img class="ico" src="../style/'.$style.'/ico/m.png" alt="" />';
		if ($row['gender'] == 2)
			$pol = '<img class="ico" src="../style/'.$style.'/ico/w.png" alt="" />';
	echo $pol.'<a href="../p/'.$row['login'].'">'.$row['login'].'</a>';
	echo status($row['id']);
echo'<br/>';

	echo '<div class="ftext">';
if($user['id'] != $row['id']):
echo  '<a href="../pages/mail.php?act=send&amp;login='.$row['login'].'"><img align="right" class="ico" src="../style/'.$style.'/ico/mess.png" alt="" /></a>';
endif;
echo '
	Имя: '.$row['name'].'<br/>'; 
          
              if(!empty($row['birthday_day']) and !empty($row['birthday_month']) and !empty($row['birthday_year'])) 
{ 
 echo 'Возраст: '.age($row['birthday_day'], $row['birthday_month'], $row['birthday_year']).' лет<br/>'; 
} 
if(!empty($row['city'])) 
{ 
 echo 'Город:  '.$row['city'].'<br />'; 
} 
if(!empty($row['rate'])) 
{
echo '	Рейтинг: '.$row['rate'].' %<br/>';
}
else
{
echo '	Рейтинг: 0 %<br/>';
}
echo '
	Последний вход: '.clock($row['time']).'<br/>
	</div>
	<div class="clear"></div>
	</div>';

$status = mysql_fetch_assoc(mysql_query("SELECT * FROM `statuses` WHERE `user` = '" . $row['id'] . "' AND `type` = 'status' ORDER by `time` DESC LIMIT 1"));
if ($status['text'])
echo'<div class="status"><b><!-- clear --></b>
'.text($status['text']); 
echo'</div>';
echo'</div>';
}


if($total > $set['str'])
{
	pages($page, $total, 'users.php?sort='.$sort.'&amp;', $set['str']);
}
echo 'Введите логин юзера<br />';
echo '<div class="mess"><form action="usersearch.php" method="post"><div><input name="login" type="text" value=""/>
<input type="submit" value="Поиск"/></div></form></div>';
include '../style/'.$style.'/foot.php'; ?>