<?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="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>Загруз-центр - '.$file['name'].' </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="/downs" rel="v:url" property="v:title">Загруз-центр</a></li><li typeof="v:Breadcrumb"><a href="show_dir.html?id='.$raz['id'].'" rel="v:url" property="v:title">'.$raz['name'].'</a></li><li typeof="v:Breadcrumb"><a href="show_kat.html?id='.$praz['id'].'" rel="v:url" property="v:title">'.$praz['name'].'</a></li><li class="active" typeof="v:Breadcrumb"><span property="v:title"><b>'.$file['name'].'</b></span></li></ol></div><div class="col-xs-12 col-sm-4 col-md-3 col-lg-3 text-right page_header_sidebar"></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">';
if ($file['user_id'] == $b['id'] || $b['level'] > 1) {
echo '<div class="catSides"><a href="/downs"><i class="md-format-list-bulleted"></i> Загруз-центр</a> - Действие с файлом</div><div class="row text_box"><a href="admin.php?id='.$id.'"><i class="md-settings"></i>  <a href="admin.php?id='.$id.'">[Изменить]</a> <a href="admin.php?do=screen&id='.$id.'">[Скриншоты]</a></div>';
}

echo '<div class="catSides"><i class="md-format-list-bulleted"></i> Файл "'.$file['name'].'"</div>';

$vote = check($_GET['vote']);
if (empty($vote)) {
header('location: file.html?id='.$id);
die();
}
if (DB::$dbs->querySingle("SELECT COUNT(id) FROM `down_votes` WHERE `user_id` = ? AND `id_file` = ?", array($b['id'],$id)) > 0) {
header('location: file.html?id='.$id);
die();
}
if (isset($_POST['vote'])) {
$text = check($_POST['text']);
if (empty($text)) {
header('location: file.html?id='.$id);
die();
}

if ($vote = 'za') {
DB::$dbs->query("INSERT INTO `down_votes` SET `user_id` = ?, `id_file` = ?, `text` = ?, `type` = ?, `time` = ?", array($b['id'],$id,$text,'za',time()));
DB::$dbs->query("INSERT INTO `log_votes` SET `user_id` = ?, `id_file` = ?, `text` = ?, `type` = ?, `time` = ?", array($b['id'],$id,$text,'za',time()));
} elseif ($vote = 'protiv') {
DB::$dbs->query("INSERT INTO `down_votes` SET `user_id` = ?, `id_file` = ?, `text` = ?, `type` = ?, `time` = ?", array($b['id'],$id,$text,'protiv',time()));
DB::$dbs->query("INSERT INTO `log_votes` SET `user_id` = ?, `id_file` = ?, `text` = ?, `type` = ?, `time` = ?", array($b['id'],$id,$text,'protiv',time()));
}
$mess = Nick($b['id']).' оценил [b]'.($vote = 'za' ? 'положительно':'отрицатально').'[/b] Ваш файл <a href="/downs/file.html?id='.$id.'">'.$file['name'].'</a>';
jurnal($file['user_id'],$mess,4);
header('location: file.html?id='.$id);
die();
}
echo '<div class="row text_box"><form action="?id='.$id.'&vote='.$vote.'" method="POST">Комментарий (max.: 250):<br/><textarea class="form-control" rows="3" name="text"></textarea><br/><input name="vote" type="submit" class="btn btn-primary" value="Дальше"/></form></div>';
echo '<ul class="nav nav-pills nav-stacked"><li><a href="file.html?id='.$id.'"><i class="md-apps"></i> Вернуться к файлу</a></li></ul>';

///Подключаем меню
$title->GetMenu();


///Подключаем футер
$title->GetFooter();
?>