<?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 news WHERE id = ? LIMIT 1", [$id]);
if ($array-> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
$title->SetTitle('Новости - Комментарии к '.$arr['name'].'');
$title->GetHeader();
//echo'<div class="row"><div class="col-sm-6">';
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> :: '.$arr['name'].' :: Комментарии</div></div></div>';
echo'<div class="list-group-item media"><div class="media-body"><div class="list-group-item-heading">'.text($arr['txt']).'<br/>Автор: '.Nick($arr['user']).'</div></div></div>';
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-comment"></i> Обсуждение новости</div></div></div>';
if (isset($_GET['del'])) {
if ($b['level'] < 3) {
header('location: ?');
die();
}
DB::$dbs->query("DELETE FROM news_comm WHERE id = ?", [abs((int)$_GET['del'])]);
header('location: ?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;
$look = DB::$dbs->querySingle("SELECT COUNT(id) FROM news_comm WHERE id_news = ?", [$id]);
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM news_comm WHERE id_news = ? ORDER BY time DESC LIMIT $start,$num", [$id]);
if ($sql->rowCount() == 0) {
err('Комментов нет');
} else {
while($a = $sql -> fetch()) {
$D = ($b['level'] > 2 ? '[<a href="?id='.$id.'&del='.$a['id'].'">Удл</a>] ':NULL);
echo '<div class="list-group-item media"><div class="media-body"><div class="list-group-item-heading">'.Nick($a['user']).' ('.vr($a['time']).') '.(($a['user'] != $b['id']) ? ' <a href="?id='.$id.'&otv='.$a['user'].'">[Отв]</a>':NULL).' '.$D.'</br>'.text($a['txt']).'</div></div></div>';
}
}
if ($b == true) {
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-comment"></i> Добавить комментарий</div></div></div>';
if (isset($_POST['add'])) {
$text = check($_POST['text']);
if (empty($text)) {
err('Введите текст!');
} elseif (DB::$dbs->querySingle("SELECT COUNT(id) FROM news_comm WHERE txt = ? AND id_news = ?", [$text,$id]) > 0) {
err('Такой коммент уже есть :)');
} else {
DB::$dbs->query("UPDATE `blogger` SET `gears` = `gears` + ? WHERE id = ?", [1,$b['id']]);
DB::$dbs->query("INSERT INTO news_comm SET txt = ?, time = ?, user = ?, id_news = ?", [$text,time(),$b['id'],$id]);
if (!empty($otv) && $otv != $b['id']) {
$mess = 'Пользователь [b]'.$b['nick'].'[/b] ответил на ваш комментарий к новости [url=http://'.$_SERVER['HTTP_HOST'].'/news/comm.html?id='.$id.']'.$arr['name'].'[/url]';
jurnal($otv,$mess,3);
}
header('location: ?id='.$id);
die();
}
}
$o = (!empty($otv) ? '&otv='.$otv : NULL);
echo '<div class="list-group-item media"><div class="media-body"><div class="list-group-item-heading"><form name="form" method="post" action="?do=comm&id='.$id.$o.'"><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea name="text" class="form-control" rows="8">'.$reply.'</textarea></br> <input type="submit" name="add" class="btn btn-primary btn-block" value="Добавить"/></div></div></div></form>';
}
if ($k_page>1) {
str('?id='.$id.'&', $k_page,$page);
}
$title->GetMenu();
$title->GetFooter();
?>
