<?php
session_start();
require_once('classes/body.class.php');
require_once('classes/db.class.php');
require_once('classes/system.class.php');
$title= new Body;
$title->SetTitle(homeurl.' - Поиск пользователей');
$title->GetHeader();

echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: Поиск пользователей</div></div>';
 echo'<div class="tile-body">
                                <div class="count-box bg-blue">
                                    <div class="row text-center">

<a href="/peoples"style="text-decoration:none; color:white;"><div class="col-sm-3 col-xs-6"><div class="cb-item"><small>Пользователи</small></div></div></a>
<a href="/last"style="text-decoration:none; color:white;"><div class="col-sm-3 col-xs-6"><div class="cb-item"><small>Посетили</small></div></div></a>
<a href="/search"style="text-decoration:none; color:white;"><div class="col-sm-3 col-xs-6"><div class="cb-item"><small>Поиск</small></div></div></a>
<a href="/birth"style="text-decoration:none; color:white;"><div class="col-sm-3 col-xs-6"><div class="cb-item"><small>Именинники</small></div></div></a>

                       </div></div><div class="rounded-thumbs"><div class="row">';
if (empty($_GET[zx]) or !empty($_POST['text'])) {
unset($_SESSION['text']);
unset($_SESSION['sear']);
} else {
$_POST['text']= $_SESSION['text'];
}
if (isset($_GET['search'])) {
$text = str_replace('%','',$_POST['text']);
$text = str_replace("'",'',$_POST['text']);
$text = str_replace('"','',$_POST['text']);
$text = str_replace('-','',$_POST['text']);
$text = check($text);
$_SESSION['text'] = $text;
$text = (!empty($_SESSION['text']) ? $_SESSION['text'] : NULL);
if (isset($_POST['sear'])) $sear = check($_POST['sear']);
if (isset($_SESSION['sear'])) $sear = check($_SESSION['sear']);

$_SESSION['sear'] = $sear;
if ($sear == 'spec') {

if ($text == 'Мастер') {
$var = 0;
} elseif ($text == 'Кодер') {
$var = 1;
} elseif ($text == 'Дизайнер') {
$var = 2;
} elseif ($text == 'Хостер') {
$var = 3;
} elseif ($text == 'Продавец') {
$var = 4;
}
$var = abs((int)$var);
$look = DB::$dbs->querySingle("SELECT COUNT(id) FROM blogger WHERE spec LIKE '%$var%'");
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM blogger WHERE spec LIKE '%$var%' ORDER BY id LIMIT $start,$num", [$id]);
if ($sql -> rowCount() == 0) {
err('Пусто!');
} else {
while($a = $sql->fetch()) {
echo'<a class="col-xs-3 col-sm-2" href="/users/'.$a['id'].'">';
if (!empty($a['ava'])) {echo'<img class="img-avatar" src="/' . $a['ava'] . '" width="45" height="45">';} else {echo'<img class="img-avatar" src="/assets/img/4.jpg"  width="45" height="45">';}
                 echo'</br><small>'.$a[ 'nick' ].'</small></br></br></a>';
}
}
if ($k_page>1) {
str('?zx=1&search&', $k_page, $page);
}

$title->GetMenu();
$title->GetFooter();
die();
} elseif ($sear == 'hist') {
$look = DB::$dbs->querySingle("SELECT COUNT(id) FROM nicks WHERE old LIKE '%$text%'");
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM nicks WHERE old LIKE '%$text%' ORDER BY us LIMIT $start,$num", [$id]);
if ($sql -> rowCount() == 0) {
err('Пусто!');
} else {
while($a = $sql->fetch()) {
echo'<a class="col-xs-3 col-sm-2" href="/users/'.$a['id'].'">';
if (!empty($a['ava'])) {echo'<img class="img-avatar" src="/' . $a['ava'] . '" width="45" height="45">';} else {echo'<img class="img-avatar" src="/assets/img/4.jpg"  width="45" height="45">';}
                 echo'</br><small>'.$a[ 'nick' ].'</small></br></br></a>';

}
}
echo'</div></div>';

if ($k_page>1) {
str('?zx=1&search&', $k_page, $page);
}

$title->GetMenu();
$title->GetFooter();
die();
} else {
if ($sear == 'id') {
$var = 'id';
} elseif ($sear == 'nick') {
$var = 'nick';
} elseif ($sear == 'city') {
$var = 'city';
} elseif ($sear == 'icq') {
$var = 'icq';
} elseif ($sear == 'wmid') {
$var = 'wmid';
} elseif ($sear == 'wmr') {
$var = 'wmr';
} elseif ($sear == 'email') {
$var = 'email';
} elseif ($sear == 'country') {
$var = 'country';
} elseif ($sear == 'name') {
$var = 'name';
}
$look = DB::$dbs->querySingle("SELECT COUNT(id) FROM blogger WHERE ".$var." = ?", [$text]);
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM blogger WHERE ".$var." = ? ORDER BY id LIMIT $start,$num", [$text]);
if ($sql -> rowCount() == 0) {
err('Пусто!');
} else {
while($a = $sql->fetch()) {
echo'<a class="col-xs-3 col-sm-2" href="/users/'.$a['id'].'">';
if (!empty($a['ava'])) {echo'<img class="img-avatar" src="/' . $a['ava'] . '" width="45" height="45">';} else {echo'<img class="img-avatar" src="/assets/img/4.jpg"  width="45" height="45">';}
                 echo'</br><small>'.$a[ 'nick' ].'</small></br></br></a>';
}
}
echo'</div></div>';
if ($k_page>1) {
str('?zx=1&search&', $k_page, $page);
}

$title->GetMenu();
$title->GetFooter();
die();
}
}
echo '<form action="?zx=1&search" method="POST">Критерий:<br/><select class="form-control" name="sear">
<option value="id">ID</option>
<option value="nick">Ник</option>
<option value="hist">История ников</option>
<option value="icq">ICQ</option>
<option value="name">Имя</option>
<option value="city">Город</option>
<option value="country">Страна</option>
<option value="email">E-mail</option>
<option value="wmid">WMID</option>
<option value="wmr">WMR</option>
<option value="spec">Специальность</option>
</select><br/>Запрос:<br/><input type="text" class="form-control" name="text"/><br/><input type="submit" class="btn btn-primary" value="Искать"/></form></br></div></div>';


$title->GetMenu();
$title->GetFooter();

?>