<?php
session_start();
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
if (empty($id)) {
header ('location: /');
exit;
}
$query = DB :: $dbs -> query ("SELECT * FROM `downs` WHERE `id`= ?", [$id]);
if ($query -> rowCount () == 0) {
header ('location: /');
exit;
}
$file = $query -> fetch();
$raz = DB :: $dbs -> queryFetch("SELECT * FROM `down_r` WHERE `id`= ?", [$file['rid']]);
$praz = DB :: $dbs -> queryFetch("SELECT * FROM `down_pr` WHERE `id`= ?", [$file['prid']]);
$url = $_SERVER['DOCUMENT_ROOT'].'/'.$file['url'];
$ext = pathinfo($url);
$ext = $ext['extension'];
$title->SetTitle('Голосовавшие за файл '.$file['name']);
$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> :: <a href="show_dir.html?id='.$raz['id'].'"style="text-decoration:none; color:white;">'.$raz['name'].'</a> :: <a href="show_kat.html?id='.$praz['id'].'"style="text-decoration:none; color:white;">'.$praz['name'].'</a> :: '.$file['name'].'</div></div></div>';

if ($file['user_id'] == $b['id'] || $b['level'] > 1) {
echo '<div class="list-group-item media"><a href="admin.php?id='.$id.'"><i class="zmdi zmdi-settings"></i>  <a href="admin.php?id='.$id.'">[Изменить]</a> <a href="admin.php?do=screen&id='.$id.'">[Скриншоты]</a>';
}
if ($b['level'] > 1) {
echo '  '.($file['block'] == 0 ? '<a href="?id='.$id.'&block">[Блокировать файл]</a>':'<a href="?id='.$id.'&unblock">[Разблокировать файл]</a>').' <a href="admin.php?do=per&id='.$id.'">[Перенести]</a>';
}
if ($file['user_id'] == $b['id'] || $b['level'] > 1) {
echo '</div>';
}
$k_post = DB::$dbs->querySingle("SELECT COUNT(id) FROM `down_votes` WHERE `id_file` = ?", [$id]);
if ($k_post == 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;
$array = DB::$dbs->query("SELECT * FROM `down_votes` WHERE `id_file` = ? ORDER BY time DESC LIMIT $start,$num",array($id));
while($arr = $array -> fetch()) {
echo'<a class="list-group-item media"href="/users/'.$arr['user_id'].'"><div class="pull-left"><img class="img-circle pull-left" src="/'.(user_inf($arr['user_id'], 'ava') != NULL ? user_inf($arr['user_id'], 'ava') : 'assets/img/4.jpg').'" alt="" width="40" height="40"></div><div class="media-body"><div class="list-group-item-heading">'.NickN($arr['user_id']).' ('.vr($arr['time']).') '. ($arr['type'] == 'za' ? '<font color="green"><b>+1</b></font>':'<font color="red"><b>-1</b></font>').'  </div><small class="list-group-item-text">Комментарий: '.text($arr['text']).' </small></div></a>';
}
echo'</div></div>';
if ($k_page > 1) {
str('?id='.$id.'&',$k_page,$page);
}
echo '<div class="tile"><ul class="nav nav-pills nav-stacked"><li><a href="file.html?id='.$id.'"><i class="zmdi zmdi-home"></i> Вернуться к файлу</a></li></ul></div>';
$title->GetMenu();
$title->GetFooter();
?>