<?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('Галерея - Комментарии к '.$arr['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="/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>';
$R = $arr['rat'];
echo '<div class="list-group-item media"> &#187; Название: '.$arr['name'].'<br/>&#187; Описание: '.$arr['text'].'<br/><br/><a href="/'.$arr['path'].'"><img width="380" height="250"  src="/'.$arr['path'].'" alt="not found"/></a><br/><br/>&#187; Автор: '.Nick($arr['user_id']).'<br/>&#187; Добавлено: '.vr($arr['time']).'<br/>';
if ($b == true){ echo'&#187; <a href="rating.html?id='.$arr['id'].'">Оценка</a>: '.($R == 0 ? 'Не оценено': $R).''; } echo'</div>';
echo '<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-comments"></i> Комментарии</div></div></div>';
if (isset($_GET['del'])) {
if ($b['level'] < 3) {
header('location: ?');
die();
}
DB::$dbs->query("DELETE FROM album_comm WHERE id = ?", [abs((int)$_GET['del'])]);
header('location: comm.html?id='.$id);
die();
}
if (isset($_GET['otv'])) {
$t = DB::$dbs->queryFetch("SELECT * FROM blogger WHERE id = ?", [abs((int)$_GET['otv'])]);
if (empty($t['id'])) {
header('location: /');
}
$reply = $t['nick'].', ';
} else {
$reply = '';
}
$otv = isset($_GET['otv']) ? abs((int)$_GET['otv']) : false;
$k_mess = DB::$dbs->querySingle("SELECT COUNT(id) FROM album_comm WHERE fid = ?", [$id]);
$num = 10;
$k_page = k_page($k_mess, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM album_comm WHERE fid = ? ORDER BY time DESC LIMIT $start,$num", [$id]);
if ($sql->rowCount() == 0) {
err('Комментов нет');
} else {
while($a = $sql -> fetch()) {
$D = ($b['level'] > 2 ? '[<a href=comm.html?id='.$id.'&del='.$a['id'].'">Удл</a>] ':NULL);
echo '<div class="list-group-item media">'.$D.Nick($a['user_id']).' ('.vr($a['time']).') '.(($a['user_id'] != $b['id']) ? ' <a href="comm.html?id='.$id.'&otv='.$a['user_id'].'">[Отв]</a>':NULL).'</br>'.text($a['text']).'</div>';
}
}
if ($k_page>1) {
str('comm.html?id='.$id.'&', $k_page,$page);
}
if ($b == true) {
echo '<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-comments"></i> Добавить комментарий</div></div></div>';
if (isset($_POST['add'])) {
$text = check($_POST['text']);
if (empty($text)) {
err('Введите текст!');
} elseif (DB::$dbs->querySingle("SELECT COUNT(id) FROM album_comm WHERE text = ? AND fid = ?", [$text,$id]) > 0) {
err('Такой коммент уже есть :)');
} else {
DB::$dbs->query("INSERT INTO album_comm SET text = ?, time = ?, user_id = ?, fid= ?", [$text,time(),$b['id'],$id]);
if (!empty($otv) && $otv != $b['id']) {
$mess = 'Пользователь [b]'.$b['nick'].'[/b] ответил на ваш комментарий к фото [url=http://'.$_SERVER['HTTP_HOST'].'/gallery/comm.html?id='.$id.']'.$arr['name'].'[/url]';
jurnal($otv,$mess,3);
}
if ($arr['user_id'] != $b['id']) {
$mess = 'Пользователь [b]'.$b['nick'].'[/b] оставил комментарий к вашему фото [url=http://'.$_SERVER['HTTP_HOST'].'/gallery/comm.html?id='.$id.']'.$arr['name'].'[/url]';
jurnal($arr['user_id'],$mess,3);
}
header('location: comm.html?id='.$id);
die();
}
}
$o = (!empty($otv) ? '&otv='.$otv : NULL);
echo '<div class="list-group-item media"><form name="form" method="post" action="comm.html?id='.$id.$o.'">Комментарий:<br/><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea class="form-control" rows="8" name="text">'.$reply.'</textarea> </br><input type="submit" name="add" class="btn btn-primary btn-lg btn-block" value="Добавить"/></div></form>';
}

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