<?
include '../system/sys.php';
include '../system/funcs.php';

if (!isset ($us['id'])) {
exit;
}
H('Поиск пользователей','Поиск пользователей');
method="post">
Критерий поиска:<br/><select name="krit"><option
value="id">ID</option>
<option value="nick">Ник</option>
<option value="hist">История ников</option>
<option value="icq">ICQ</option>
<option value="name">Имя</option>
<option value="gorod">Город</option>
<option value="country">Страна</option>
<option value="email">E-mail</option>
</select><br>Ищем:<br>
<input type="text" name="text"/><input type="submit"
value="Поиск"/>
</form></div>';
} else {
$text = htmlspecialchars (addslashes (trim ($_POST['text'])));
$krit = htmlspecialchars (addslashes (trim ($_POST['krit'])));
if (empty ($text)) {
echo '<div class="list1">Введите поисковый запрос!</div>';
require_once('system/footer.php');
die();
}
if (empty ($krit)) {
echo '<div class="list1">Выберите критерий поиска!</div>';
require_once('system/footer.php');
die();
}
$_SESSION['text'] = $text;
$_SESSION['krit'] = $krit;

if ($krit == 'id') {
$type = '`id`';
} elseif ($krit == 'nick') {
$type = '`nick`';
} elseif ($krit == 'name') {
$type = '`name`';
} elseif ($krit == 'icq') {
$type = '`icq`';
} elseif ($krit == 'gorod') {
$type = '`gorod`';
} elseif ($krit == 'country') {
$type = '`country`';
} elseif ($krit == 'email') {
$type = '`email`';
}

if ($krit == 'hist') {

$arr = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `nicks` WHERE (`old` LIKE '%" . $_SESSION['text'] . "%') AND (`new` LIKE '%" . $_SESSION['text'] . "%')");

$items_per_page = 10;
$pages = ceil ( $arr / $items_per_page );

if ($page < 1)
$page = 1;

if ($page > $pages)
$page = $pages;

$start = $page * $items_per_page - $items_per_page;

if ($arr==0) {
echo '<div class="error">По вашему запросу ничего не найдено!</div>';
}
else {

$query = DB :: $dbs -> query ("SELECT * FROM `nicks` WHERE (`old` LIKE '%" . $_SESSION['text'] . "%') AND (`new` LIKE '%" . $_SESSION['text'] . "%') ORDER BY `id` DESC LIMIT $start, $items_per_page");
while ($t = $query -> fetch()) {
echo '<div class="navg">';
echo Nick ($t['id']);
echo '</div>';

}
}
if ($pages>1) {
echo '<div class="list1">' . page ('?go') . '</div>';
}
require_once('system/footer.php');
die();
}
$count = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `us` WHERE ($type LIKE '%" . $_SESSION['text'] . "%')");

$items_per_page = 10;
$pages = ceil ( $count / $items_per_page );
$page = (int) $_GET['page'];

if ($page < 1)
$page = 1;

if ($page > $pages)
$page = $pages;

$start = $page * $items_per_page - $items_per_page;

if ($count==0) {
echo '<div class="error">По вашему запросу ничего не найдено!</div>';
}
else {

$query = DB :: $dbs -> query ("SELECT * FROM `us` WHERE ($type LIKE '%" . $_SESSION['text'] . "%') ORDER BY `id` DESC LIMIT $start, $items_per_page");
while ($t = $query -> fetch()) {
echo '<div class="block">';
echo Nick ($t['id']);
echo '</div>';

}
}
if ($pages>1) {
echo '<div class="list1">' . page ('?go') . '</div>';
}

}
require_once('includes/Footers.php');

?>