Файл: soc-set/moduls/news/new.php
Строк: 48
<?php
require_once('../../core/start.php');
check_auth();
head('Новости сайта');
if (isset($_GET['id'])) {
$id = num($_GET['id']);
$new = DB::$dbs->queryFetch("SELECT * FROM ".NEWS." WHERE `id` = ? ",array($id));
if (empty($new)) {
echo DIV_TITLE . 'Ошибка!' . CLOSE_DIV;
echo DIV_AUT . 'Новость не найдена' . CLOSE_DIV;
} else {
panel();
echo DIV_BLOCK . '<b>' . $new['title'] . '</b>' . CLOSE_DIV;
switch ($select) {
default:
echo DIV_BLOCK . text($new['new']) . CLOSE_DIV;
echo DIV_LI;
$comm = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".NEWS_COMM." WHERE `new_id` = ?", array($new['id']));
echo '<a href="'.HOME.'/news/comm/'.$new['id'].'/">Комментарии: <b>'.$comm.'</b></a>';
echo CLOSE_DIV;
$array = array('Новости');
nav($array);
break;
case 'comm':
if ($_POST) {
$comm = html($_POST['comm']);
if (empty($comm)) {
$err = 'Комментарий пуст';
}
if (!empty($err)) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
DB::$dbs->query("INSERT INTO ".NEWS_COMM." (`new_id`, `user_id`, `comm`, `time`) VALUES (?, ?, ?, ?)", array($id, $user['user_id'], $comm, time()));
balls_operation(3);
echo DIV_MSG . 'Комментарий добавлен' . CLOSE_DIV;
}
}
$comm = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".NEWS_COMM." WHERE `new_id` = ?", array($new['id']));
echo DIV_LI . '<b>Комментарии к новости:</b>' . CLOSE_DIV;
if (!empty($_GET['del_comm'])) {
DB::$dbs->query("DELETE FROM ".NEWS_COMM." WHERE `id` = ? ", array(num($_GET['del_comm'])));
header("Location: ".HOME."/moduls/news/new.php?select=comm&id=".$id."&p=".(int)$_GET['p']);
}
if (empty($comm)) {
echo DIV_BLOCK . 'Комментарий нет' . CLOSE_DIV;
} else {
$n = new Navigator($comm,$config['write']['news_comm'],'select=comm&id='.$id);
$sql = DB::$dbs->query("SELECT * FROM ".NEWS_COMM." WHERE `new_id` = ? ORDER BY `id` DESC LIMIT {$n->start()}, ".$config['write']['news_comm']."", array($id));
while($comm = $sql -> fetch()) {
echo DIV_LI . userLink($comm['user_id']) . ' [' . vrem($comm['time']) . ']' . (privilegy('news_comm_delete') ? ' <a href="'.HOME.'/moduls/news/new.php?select=comm&id='.$new['id'].'&del_comm='.$comm['id'].'&p='.(int)$_GET['p'].'">[Удал.]</a>' : NULL) . CLOSE_DIV;
echo DIV_BLOCK . text($comm['comm']) . CLOSE_DIV;
}
echo $n->navi();
}
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo 'Комментарий:<br /><textarea name="comm"></textarea><br />';
echo '<input type="submit" value="Добавить" /></form><br />';
echo '<b><a href="'.HOME.'/news/'.$new['id'].'/">К новости</a></b>';
echo CLOSE_DIV;
bbsmile();
$array = array('Новости');
nav($array);
break;
}
}
}
require_once('../../core/stop.php');
?>