<?php
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;
$array = DB::$dbs->query("SELECT * FROM album_foto WHERE id = ? LIMIT 1", [$id]);
if ($array-> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
$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="/gallery"style="text-decoration:none; color:white;">Галерея</a> :: '.($arr['cid'] != 0 ? '<a href="viewalb.html?id='.$arr['cid'].'"style="text-decoration:none; color:white;">'.$arr['name'].'</a>':'<a href="personal.html?id='.$arr['user_id'].'"style="text-decoration:none; color:white;">'.$arr['name'].'</a>').'</div></div></div>';

if (isset($_POST['add'])) {
$type = abs((int)$_POST['type']);
if (empty($type)) {
err('Выберите оценку');
} else {
if (DB::$dbs->querySingle("SELECT COUNT(id) FROM album_rating WHERE user_id = ? AND fid = ?", [$b['id'],$id]) == 0) {
DB::$dbs->query("INSERT INTO album_rating SET user_id = ?, type = ?, fid = ?", [$b['id'],$type,$id]);
DB::$dbs->query("UPDATE `album_foto` SET `rat` = `rat` + ? WHERE `id` = ? LIMIT 1", [$type,$id]);
if ($type>5) {
$gears = '1';
DB::$dbs->query("UPDATE `blogger` SET `gears` = `gears` + ? WHERE `id` = ? LIMIT 1", [$gears,$arr['user_id']]);
}
if ($arr['user_id'] != $b['id']) {
$mess = 'Пользователь [b]'.$b['nick'].'[/b] оценил ваше фото [b]'.$arr['name'].'[/b] на [b]'.$type.'[/b] баллов!';
jurnal($arr['user_id'],$mess,4);
}
echo '<div class="list-group-item media">Ваш голос принят. Спасибо за оценку!</div>'.($arr['cid'] != 0 ? '
<div class="list-group-item media"><a href="viewalb.html?id='.$arr['cid'].'"><i class="zmdi zmdi-home"></i> Вернуться в альбом</a></div>':'
<div class="list-group-item media"><a href="personal.html?id='.$arr['user_id'].'"><i class="zmdi zmdi-home"></i> Вернуться назад</a></div>').'';
$title->GetMenu();
$title->GetFooter();
die();
}
}
}
if (DB::$dbs->querySingle("SELECT COUNT(id) FROM album_rating WHERE user_id = ? AND fid = ?", [$b['id'],$id]) == 0) {
echo '<div class="list-group-item media"><form action="rating.html?id='.$id.'" method="post">Выберите оценку:<br/><select class="form-control" name="type">';
$for = [1,2,3,4,5,6,7,8,9,10];
foreach($for as $value) {
echo '<option value="'.$value.'">'.$value.'</option>';
}
echo '</select><br/><input type="submit" name="add" class="btn btn-primary" value="Оценить"/></div></form>';
} else {
err('Вы уже оценивали это изображение!');
}

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