<?

include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
# Заголовок
$set['title']='Поиск';
include_once '../sys/inc/thead.php';
title();
aut();

# Форма поиска
$usearch=stripcslashes(htmlspecialchars($usearch));
echo '<div class="block_search">';
echo '<table class="search">';
echo '<form method="post" action="people_search.php?go&amp;sort='.$sort.'&amp;'.$por.'">';
echo '<td><button class="button_search" type="submit"><img src="/img/search.png"></button></td>';
echo '<td><input class="input_search" placeholder="Поиск" type="text" name="usearch" maxlength="30" autocomplete="off"></td>';
echo '</form>';
echo '</table>';
echo '</div>';

$sort='id';
$por='DESC';
if (isset($_GET['ASC']))$por='ASC'; // прямой порядок
if (isset($_GET['DESC']))$por='DESC'; // обратный порядок

$usearch=NULL;

if (isset($_SESSION['usearch']))$usearch=$_SESSION['usearch'];

if (isset($_POST['usearch']))$usearch=$_POST['usearch'];

if ($usearch==NULL)

unset($_SESSION['usearch']);

else

$_SESSION['usearch']=$usearch;
$usearch=preg_replace("#( ){1,}#","",$usearch);
if (isset ($_GET['go']) && $usearch!=NULL){
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `nick` like '%".mysql_real_escape_string($usearch)."%' OR `id` = '".intval($usearch)."'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

# Если ничего не нашло
if ($k_post==0){
echo '<div class="block2"><center>Никого не найдено</center></div>';
}

$q=mysql_query("SELECT `id` FROM `user` WHERE `nick` like '%".mysql_real_escape_string($usearch)."%' OR `id` = '".intval($usearch)."' ORDER BY `$sort` $por LIMIT $start, $set[p_str]");

# Вывод найденых людей
while ($ank = mysql_fetch_assoc($q)){
$ank=get_user($ank['id']);
$uSet = mysql_fetch_array(mysql_query("SELECT * FROM `user_set` WHERE `id_user` = '$ank[id]'  LIMIT 1"));
$frend = mysql_result(mysql_query("SELECT COUNT(*) FROM `frends` WHERE (`user` = '$user[id]' AND `frend` = '$ank[id]') OR (`user` = '$ank[id]' AND `frend` = '$user[id]') LIMIT 1"),0);
$frend_new = mysql_result(mysql_query("SELECT COUNT(*) FROM `frends_new` WHERE (`user` = '$user[id]' AND `to` = '$ank[id]') OR (`user` = '$ank[id]' AND `to` = '$user[id]') LIMIT 1"),0);

echo '<table class="block3">';
echo '<td class="block_avatar">';
echo ''.avatar($ank['id']).'</a> <span class="avatar_icon">'.online($ank['id']).'</span>';
echo '</td>';
echo '<td class="block_info">';
echo '<span class="nick">'.user::nick($ank['id']).'</span>';
echo '<div class="block_msg">';
echo '<span style="color: #828282; font-size: 14px;">';
if ($ank['ank_name']!=NULL){
echo ''.$ank[ank_name].' ';
}else{
}
if ($ank['ank_fam']!=NULL){
echo ''.$ank[ank_fam].'';
}else{
}
echo '</span>';
echo '</div>';
echo '</td>';
echo '</table>';

}


# Навигация
if ($k_page>1)str("people_search.php?go&amp;sort=$sort&amp;$por&amp;",$k_page,$page);

}

include_once '../sys/inc/tfoot.php';

?>