<?php
session_name('search');
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('Свежие новости - Поиск новостей');
$title->GetHeader();

//echo'<div class="row"><div class="col-sm-6">';
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> :: <a href="/allnews"style="text-decoration:none; color:white;">Свежие новости</a> :: Поиск</div></div></div>';
echo '<div class="list-group-item media"><form action="?search" method="POST">Запрос:<br/><input type="text" class="form-control" name="text" placeholder="Введите поисковый запрос"><br/><input type="submit" name="search" class="btn btn-primary" value="Искать"/></form></div>';


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);
$look = DB::$dbs->querySingle("SELECT COUNT(id) FROM `gazeta_article` WHERE `name` LIKE '%$text%'");
if ($look == 0) {
err('Ничего не найдено!');
}
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></div>';
echo'<div class="t-body"><div class="list-group lg-alt">';
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM `gazeta_article` WHERE `name` LIKE '%$text%' ORDER BY `id` DESC LIMIT $start,$num");
while($a = $sql->fetch()) {
echo '<a class="list-group-item media" href="news.html?id='.$a['id'].'"><div class="pull-left"><img class="img-circle pull-left" src="/'.(user_inf($a['user_id'], 'ava') != NULL ? user_inf($a['user_id'], 'ava') : 'assets/img/4.jpg').'" alt="" width="40" height="40"></div><div class="media-body"><div class="list-group-item-heading">  '.$a['name'].'  </div><small class="list-group-item-text">('.vr($a['time']).')</small></div></a>';
}
echo'</div></div>';
if ($k_page > 1) {
str('?search&',$k_page,$page);
}
}

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