Файл: soc-set/panel/news.php
Строк: 182
<?php
require_once('../core/start.php');
check_auth();
head('Новости сайта');
if (privilegy('news') == FALSE) {
header("Location: ".HOME."/panel");
exit();
}
echo DIV_TITLE . 'Новости сайта' . CLOSE_DIV;
if (privilegy('news')) {
switch ($select) {
default:
if ($_GET['del']) {
$del = num($_GET['del']);
DB::$dbs->query("DELETE FROM ".NEWS." WHERE `id` = ?",array($del));
DB::$dbs->query("DELETE FROM ".NEWS_COMM." WHERE `new_id` = ?",array($del));
echo DIV_MSG . 'Новость удалена' . CLOSE_DIV;
}
if (!empty($_POST['sett'])) {
$news = num($_POST['news']);
$comm = num($_POST['comm']);
if (empty($news) || empty($comm)) {
echo DIV_ERROR . 'Пустое значение' . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".CONFIG." SET `write_news` = ?, `write_news_comm` = ? ", array($news, $comm));
header("Location: ".HOME."/panel/news/");
}
}
if ($_POST['add']) {
$title = html($_POST['title']);
$afisha = html($_POST['afisha']);
$new = html($_POST['new']);
if (strlen($title) < 10) {
$err .= 'Слишком короткий заголовок. Минимум 10 символов<br />';
}
if (strlen($new) < 20) {
$err .= 'Слишком короткая новость. Минимум 20 символов<br />';
}
if (empty($afisha)) {
$err .= 'Не заполнено поле Вывод на главной<br />';
}
if ($err) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
DB::$dbs->query("INSERT INTO ".NEWS." (`title`, `afisha`, `new`, `time`, `user_id`) VALUES (?, ?, ?, ?, ?)", array($title, $afisha, $new, time(), $user['user_id']));
echo DIV_MSG . 'Новость добавлена' . CLOSE_DIV;
}
}
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo 'Заголовок: [max. 100]<br /><input type="text" name="title" /><br /><br />';
echo 'Вывод на главной:<br /><textarea name="afisha" cols="30" rows="6"></textarea><br />';
echo 'Новость:<br /><textarea name="new" cols="30" rows="6"></textarea><br />';
echo '<input type="submit" name="add" value="Добавить" /></form>';
echo CLOSE_DIV;
echo DIV_AUT;
echo '<b>Новостей на страницу:</b><br />';
echo '<form action="#" method="POST">';
echo '<select name="news">';
echo '<option '.(1 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="1">1</option>';
echo '<option '.(3 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="3">3</option>';
echo '<option '.(5 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="5">5</option>';
echo '<option '.(10 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="10">10</option>';
echo '<option '.(20 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="20">20</option>';
echo '<option '.(30 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="30">30</option>';
echo '</select><br /><br />';
echo '<b>Комментарий на страницу:</b><br />';
echo '<select name="comm">';
echo '<option '.(5 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="5">5</option>';
echo '<option '.(10 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="10">10</option>';
echo '<option '.(15 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="15">15</option>';
echo '<option '.(20 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="20">20</option>';
echo '<option '.(30 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="30">30</option>';
echo '<option '.(40 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="40">40</option>';
echo '<option '.(50 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="50">50</option>';
echo '</select><br /><br />';
echo '<input type="submit" name="sett" value="Сохранить" /></form>';
echo CLOSE_DIV;
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".NEWS."");
if ($all == 0) {
echo DIV_AUT . 'Новостей нет' . CLOSE_DIV;
} else {
$n = new Navigator($all,$config['write']['news'],'');
$sql = DB::$dbs->query("SELECT * FROM ".NEWS." ORDER BY `id` DESC LIMIT {$n->start()}, ".$config['write']['news']."");
while($new = $sql -> fetch()) {
echo DIV_AUT;
echo '<b>Заголовок:</b> ' . $new['title'] . '<br /><br />';
echo '<b>Вывод на главной:</b> ' . text($new['afisha']) . '<br /><br />';
echo '<b>Новость:</b> ' . text($new['new']) . '<br /><br />';
echo 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.'/panel/news/comm/'.$new['id'].'/">Комментарий: <b>'.$comm.'</b></a>';
echo CLOSE_DIV;
echo DIV_LI;
echo '<a href="'.HOME.'/panel/news/?del='.$new['id'].'">[Удалить]</a> <a href="'.HOME.'/panel/news/edit/'.$new['id'].'/">[Редактировать]</a>';
echo CLOSE_DIV;
}
echo $n->navi();
}
break;
case 'edit':
$id = num($_GET['id']);
if ($_POST) {
$title = html($_POST['title']);
$afisha = html($_POST['afisha']);
$new = html($_POST['new']);
if (strlen($title) < 10) {
$err .= 'Слишком короткий заголовок. Минимум 10 символов<br />';
}
if (strlen($new) < 20) {
$err .= 'Слишком короткая новость. Минимум 20 символов<br />';
}
if (empty($afisha)) {
$err .= 'Не заполнено поле Вывод на главной<br />';
}
if ($err) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".NEWS." SET `title` = ?, `afisha` = ?, `new` = ? WHERE `id` = ?", array($title, $afisha, $new, $id));
echo DIV_MSG . 'Новость изменена' . CLOSE_DIV;
}
}
$new = DB::$dbs->queryFetch("SELECT `title`, `afisha`, `new` FROM ".NEWS." WHERE `id` = ?",array($id));
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo 'Заголовок: [max. 100]<br /><input type="text" value="'.$new['title'].'" name="title" /><br /><br />';
echo 'Вывод на главной:<br /><textarea name="afisha" cols="30" rows="6">'.$new['afisha'].'</textarea><br />';
echo 'Новость:<br /><textarea name="new" cols="30" rows="6">'.$new['new'].'</textarea><br />';
echo '<input type="submit" value="Изменить" /></form>';
echo CLOSE_DIV;
break;
case 'comm':
$id = num($_GET['id']);
$new = DB::$dbs->queryFetch("SELECT * FROM ".NEWS." WHERE `id` = ? ",array($id));
$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."/panel/news.php?select=comm&id=".$id."&p=".(int)$_GET['p']);
}
if (!empty($_GET['edit_comm'])) {
$comm2 = DB::$dbs->queryFetch("SELECT * FROM ".NEWS_COMM." WHERE `id` = ?",array(num($_GET['edit_comm'])));
if ($_POST) {
$msg = html($_POST['comm']);
DB::$dbs->query("UPDATE ".NEWS_COMM." SET `comm` = ? WHERE `id` = ?", array($msg, num($_GET['edit_comm'])));
header("Location: ".HOME."/panel/news.php?select=comm&id=".$id."&p=".(int)$_GET['p']);
}
echo DIV_AUT;
echo '<form action="news.php?select=comm&id='.$new['id'].'&edit_comm='.$comm2['id'].'&p='.(int)$_GET['p'].'" method="POST">';
echo 'Изменение комментария:<br /><textarea name="comm">'.$comm2['comm'].'</textarea><br />';
echo '<input type="submit" value="Изменить" /></form>';
echo CLOSE_DIV;
}
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="news.php?select=comm&id='.$new['id'].'&del_comm='.$comm['id'].'&p='.(int)$_GET['p'].'">[Удал.]</a> <a href="news.php?select=comm&id='.$new['id'].'&edit_comm='.$comm['id'].'&p='.(int)$_GET['p'].'">[Изм.]</a>' : NULL) . CLOSE_DIV;
echo DIV_BLOCK . text($comm['comm']) . CLOSE_DIV;
}
echo $n->navi();
}
break;
}
} else {
echo DIV_BLOCK . 'Ошибка доступа' . CLOSE_DIV;
}
echo DIV_GO . '<a href="'.HOME.'/">Главная</a> / <a href="'.HOME.'/panel">Панель управления</a> / <b>Новости сайта</b>' . CLOSE_DIV;
require_once('../core/stop.php');
?>