<?php
session_name('search');
session_start();
$title->SetTitle('Маркет - Поиск товаров');
$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> :: <a href="/market"style="text-decoration:none; color:white;"> Маркет</a> :: Поиск товаров</div></div></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('Ничего не найдено!');
}
echo'<div class="t-body"><div class="list-group lg-alt">';
$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'];
$ext = strtolower(strrchr($path, '.'));
echo'<a class="list-group-item media" href="/market/file/'.$a['id'].'""><div class="pull-left"><img class="img-circle pull-left" src="/files/mag_screen/'.$screen['screen'].'" alt="" width="40" height="40"></div><div class="media-body"><div class="list-group-item-heading">'.$a['name'].'  ('.$ext.' | '.get_size(filesize($path)).')</div><small class="list-group-item-text">('.vr($a['time']).')</small></div></a>';
}
echo'</div></div>';
if ($k_page > 1) {
str('?',$k_page,$page);
}
}
echo '<div class="list-group-item media"><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>';

?>