<?php
session_name('search');
session_start();
$title->SetTitle('Маркет - Поиск товаров');
///Подключаем шапку
$title->GetHeader();

echo '<div class="container-fluid page_header"><div class="container"><div class="row"><div class="col-xs-12 col-sm-8 col-md-9 col-lg-9"><h1>Маркет - Поиск товаров </h1><ol class="breadcrumb" xmlns:v="http://'.homeurl.'/#"><li typeof="v:Breadcrumb"><a href="/" rel="v:url" property="v:title">'.homeurl.'</a></li><li typeof="v:Breadcrumb"><a href="/market" rel="v:url" property="v:title">Маркет</a></li><li class="active" typeof="v:Breadcrumb"><span property="v:title">Поиск товаров</span></li></ol></div></div></div></div>';
echo'<div class="container page_body"><div class="row"><div class="col-xs-12 page_content col-lg-9"><div class="navbar page_content_navbar collapse hidden-lg"><div class="container-fluid"><div class="navbar-collapse"></div></div></div><div class="text_box hidden-lg pr_block_small hidden"></div><div class="container-fluid cols_table">';

echo'<div class="catSides"><a href="/market"><i class="md-format-list-bulleted"></i> Маркет</a> - Поиск товаров </div>';
if (isset($_POST['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 `magazin_file` WHERE `opis` LIKE '%$text%' OR `name` LIKE '%$text%'");
if ($look == 0) {
err('Ничего не найдено!');
}
$num = 10;
$k_page = k_page($k_post, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM `magazin_file` WHERE `opis` LIKE '%$text%' OR `name` LIKE '%$text%' ORDER BY `time` ASC LIMIT $start,$num");
while($a = $sql->fetch()) {
$screen = DB::$dbs->queryFetch("SELECT * FROM `magazin_screen` WHERE `file` = ? ORDER BY `id` DESC LIMIT 1",[$a['id']]);
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM magazin_komm WHERE file = ?", [$a['id']]);
$path = $_SERVER['DOCUMENT_ROOT'].'/files/mag_file/'.$a['file'];
echo '<div class="row"><div class="col-xs-3 col-sm-1"><div class="user_brief"><div class="userpic" style="height: 50px;padding: 4px;width: 50px;"><a href="/files/mag_screen/'.$screen['screen'].'"><img class="img-responsive" src="/files/mag_screen/'.$screen['screen'].'" alt="" ></a></div></div></div><div class="col-xs-9 col-sm-8"><a class="title" href="file/'.$a['id'].'"> '.$a['name'].' ('.get_size(filesize($path)).')</a><div class="text-muted"><span> '.slv($mess, 'комментарие','комментария','комментарий').'</span></div></div><div class="col-sm-3 text-muted text-right hidden-xs"><span data-toggle="tooltip" title="Время отправки">('.vr($a['time']).')
</span></div></div>';

}
if ($k_page > 1) {
str('?',$k_page,$page);
}
}
echo '<div class="row text_box"><form action="?" method="POST">Запрос:<br/><input type="text" name="text" class="form-control" placeholder="Введите поисковый запрос"><br/><input type="submit" name="search" class="btn btn-primary" value="Искать"/></form></div>';

?>