<?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="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="/downs"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 `downs` WHERE `info` 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 `downs` WHERE `info` LIKE '%$text%' OR `name` LIKE '%$text%' ORDER BY `time` DESC LIMIT $start,$num");
while($a = $sql->fetch()) {
$mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM `down_komm` WHERE `file` = ?", [$a['id']]);
$screen = DB::$dbs->queryFetch("SELECT * FROM `down_screen` WHERE `fid` = ? ORDER BY `id` DESC LIMIT 1",[$a['id']]);
echo'<a href="file.html?id='.$a['id'].'" class="list-group-item media"><div class="pull-left"><img class="img-circle pull-left" src="/'.$screen['file'].'" alt="" width="40" height="40"></div><div class="media-body"><div class="list-group-item-heading">'.$a['name'].' ('.get_size($a['size']).')  </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" class="form-control" name="text" placeholder="Введите поисковый запрос"><br/><input type="submit" class="btn btn-primary" name="search" value="Искать"/></form></div>';

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