Файл: modules/forum/action/edit_forum.php
Строк: 147
<?php
/* Мод "Форум"
* Версия v0.0.1
* Дата последнего редактирования 27.11.2014
* Двиг DCMS Special
* Модифицировал densnet
* Автор yadalay
* Файл edit_forum.php
* Описание: редактирование подфорумов
*/
$forum = mysql_fetch_object(mysql_query('SELECT * FROM `forum` WHERE `id` = ' . intval($_GET['edit_forum'])));
if (user::access('forum_for_edit')) {
if (isset($_POST['edit'])) {
$name = mysql_real_escape_string(trim($_POST['name']));
$description = mysql_real_escape_string(trim($_POST['description']));
$number = intval($_POST['number']);
$access = intval($_POST['access']);
$output = (isset($_POST['output'])) ? 1 : 0;
$isset_name = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum` WHERE `name` = "' . $name . '" AND `id` != ' . $forum->id), 0);
$forum_n = ($forum->number != $number) ? mysql_fetch_object(mysql_query('SELECT `id`, `number` FROM `forum` WHERE `number` = ' . $number . ' AND `id` != ' . $forum->id)) : NULL;
if ($forum_n) {
mysql_query('UPDATE `forum` SET `number` = ' . $number . ' WHERE `id` = ' . $forum->id);
mysql_query('UPDATE `forum` SET `number` = ' . $forum->number . ' WHERE `id` = ' . $forum_n->id);
}
if (mb_strlen($name) < 3 || mb_strlen($name) > 40) {
echo "<div class = 'errs'>В поле 'Название подфорума' можно использовать от 3 до 40 символов.</div>";
} elseif ($isset_name != 0) {
echo "<div class = 'errs'>Подфорум с таким названием уже существует.</div>";
} elseif ($number < 0 || $number == NULL || $number == 0) {
echo "<div class = 'errs'>Введите уровень.</div>";
} elseif (mb_strlen($description) > 100) {
echo "<div class = 'errs'>Слишком длинное описание подфорума.</div>";
} elseif ($isset_number != 0) {
echo "<div class = 'errs'>Данный уровень уже использует другой подфорум.</div>";
} else {
if ($forum->name != $name) {
admin_log('Форум', 'Подфорумы', 'Подфорум "' . $forum->name . '" переименован в "' . $name . '".');
} else {
admin_log('Форум', 'Подфорумы', 'Подфорум "' . $forum->name . '" был изменён.');
}
mysql_query('UPDATE `forum` SET `name` = "' . $name . '", `description` = "' . $description . '", `number` = ' . $number . ', `access` = ' . $access . ', `output` = ' . $output . ' WHERE `id` = ' . $forum->id);
$_SESSION['msg'] = '<div class = "msgs">Подфорум успешно изменён.</div>';
header('Location: /forum/');
exit;
}
} elseif (isset($_POST['delete']) && user_access('forum_for_delete')) {
#Навигация
echo "<div class = 'navigation'><a href = '/index.php'>Главная</a> > <a href = '" . DIR_FORUM . "'>Форум</a> > <a href = '" . DIR_FORUM . "$forum->id/'>" . text::toOutput($forum->name) . "</a> > <b>Удаление подфорума</b></div>";
echo "<form action = '/forum/?edit_forum=$forum->id' method = 'post' class = 'razd'>";
echo "Вы уверены, что хотите удалить этот подфорум со всем его содержимым?<br />";
echo "<button name = 'del' class = 'action'>";
echo "<span class = 'label'><span class = 'icon icon44' /> Удалить</span>";
echo "</button>";
echo "<button name = 'cancel' class = 'action'>";
echo "<span class = 'label'> Отменить</span>";
echo "</button></form>";
require_once '../sys/inc/tfoot.php';
} elseif (isset($_POST['del']) && user_access('forum_for_delete')) {
admin_log('Форум', 'Подфорумы', 'Подфорум "' . $forum->name . '" был удалён.');
$themes = mysql_query('SELECT `id` FROM `forum_themes` WHERE `id_forum` = ' . $forum->id);
while ($theme = mysql_fetch_object($themes)) {
$files = mysql_query('SELECT `name` FROM `forum_post_files` WHERE `id_theme` = ' . $theme->id);
while ($file = mysql_fetch_object($files)) {
unlink('/forum/files/' . $file->name);
}
mysql_query('DELETE FROM `forum_post_rating` WHERE `id_theme` = ' . $theme->id);
mysql_query('DELETE FROM `forum_posts` WHERE `id_theme` = ' . $theme->id);
mysql_query('DELETE FROM `forum_post_files` WHERE `id_theme` = ' . $theme->id);
mysql_query('DELETE FROM `forum_votes_var` WHERE `id_theme` = ' . $theme->id);
$votes = mysql_query('SELECT `id` FROM `forum_votes` WHERE `id_theme` = ' . $theme->id);
while ($vote = mysql_fetch_object($votes)) {
mysql_query('DELETE FROM `forum_vote_voices` WHERE `id_vote` = ' . $vote->id);
}
mysql_query('DELETE FROM `forum_votes` WHERE `id_theme` = ' . $theme->id);
}
mysql_query('DELETE FROM `forum_themes` WHERE `id_forum` = ' . $forum->id);
mysql_query('DELETE FROM `forum_razdels` WHERE `id_forum` = ' . $forum->id);
$n_forums = mysql_query('SELECT `id`, `number` FROM `forum` WHERE `number` > ' . $forum->number);
while ($n_forum = mysql_fetch_object($n_forums)) {
mysql_query('UPDATE `forum` SET `number` = ' . ($n_forum->number - 1) . ' WHERE `id` = ' . $n_forum->id);
}
mysql_query('DELETE FROM `forum` WHERE `id` = ' . $forum->id);
$_SESSION['msg'] = '<div class = "msgs">Подфорум со всем его содержимым успешно удалён.</div>';
header('Location: ' . DIR_FORUM);
exit;
} elseif (isset($_GET['cancel'])) {
header('Location: ' . DIR_FORUM);
exit;
}
#Навигация
echo "<div class = 'navigation'><a href = '/index.php'>Главная</a> > <a href = '" . DIR_FORUM . "'>Форум</a> > <a href = '" . DIR_FORUM . "$forum->id/'>" . text::toOutput($forum->name) . "</a> > <b>Редактирование подфорума</b></div>";
echo "<form action = '" . DIR_FORUM . "?edit_forum=$forum->id' method = 'post' class = 'razd'>";
echo "<b>Название подфорума (40 символов):</b><br />";
echo "<input type = 'text' name = 'name' value = '$forum->name' /><br />";
echo "<b>Описание подфорума (100 символов):</b><br />";
echo L . "<textarea name = 'description'>$forum->description</textarea><br />";
echo "<b>Позиция:</b> <input type = 'text' name = 'number' value = '$forum->number' size = '3' /><br />";
echo "<b>Доступ:</b><br />";
echo "<label><input type = 'radio' name = 'access' value = '0' " . (($forum->access == 0) ? " checked = 'checked'" : NULL) . " /> Все</label><br />";
echo "<label><input type = 'radio' name = 'access' value = '1' " . (($forum->access == 1) ? 'checked = "checked"' : NULL) . " /> Только администраторы</label><br />";
echo "<label><input type = 'radio' name = 'access' value = '2' " . (($forum->access == 2) ? 'checked = "checked"' : NULL) . " /> Администраторы + модераторы</label><br />";
echo "<b>Вывод подфорума:</b><br />";
echo "<label><input type = 'checkbox' name = 'output' value = '1' " . (($forum->output == 1) ? 'checked = "checked"' : NULL) . " /> Отображать список разделов вместо описания</label><br />";
echo "<button name = 'edit' class = 'action'>";
echo "<span class = 'label'><span class = 'icon icon67' /> Сохранить</span>";
echo "</button>";
echo user::access('forum_for_delete') ? "<button name = 'delete' class = 'action'>
<span class = 'label'> Удалить</span></button>" : "<button name = 'cancel' class = 'action'>
<span class = 'label'> Отменить</span></button>";
echo "</form>";
echo "<div class = 'razd'>" . img('left.png') . " <a href = '" . DIR_FORUM . "'>Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
} elseif (!user_access('forum_for_edit') || !$forum) {
header('Location: ' . DIR_FORUM);
}
exit;