Файл: modules/forum/action/edit_forum.php
Строк: 143
<?php
/* Мод "Форум"
* Версия v0.0.1
* Дата последнего редактирования 15.01.2015
* Двиг 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: ' . DIR_FORUM);
exit;
}
} elseif (isset($_POST['delete']) && user::access('forum_for_delete')) {
echo "<form action = '" . DIR_FORUM . "?edit_forum=$forum->id' method = 'post' class = 'razd'>";
echo "Вы уверены, что хотите удалить этот подфорум со всем его содержимым?<br />";
echo "<button name = 'del' class = 'button sign-ins'>Удалить";
echo "</button>";
echo "<button name = 'cancel' class = 'button sign-ins'>Отменить";
echo "</button></form>";
require_once H . '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('/sys/forum/' . $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 "<form action = '" . DIR_FORUM . "?edit_forum=$forum->id' method = 'post' class = 'razd'>";
echo "<b>Название подфорума (40 символов)</b><br />";
echo "<div class = 'inputs'>";
echo "<input type = 'text' name = 'name' value = '$forum->name' /><br />";
echo "<div class = 'input-icon'>" . img16('pen.png') . "</div>";
echo "</div>";
echo "<b>Описание подфорума (100 символов)</b><br />";
echo "<textarea name = 'description'>$forum->description</textarea><br />";
echo "<b>Позиция</b><br />";
echo "<div class = 'inputs'>";
echo "<input type = 'text' name = 'number' value = '$forum->number' size = '3' /><br />";
echo "<div class = 'input-icon'>" . img16('verh_niz.png') . "</div>";
echo "</div>";
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 = 'button sign-ins'>Сохранить</button>";
echo user::access('forum_for_delete') ? "<button name = 'delete' class = 'button sign-ins'>Удалить</button>" : "<button name = 'cancel' class = 'button sign-ins'>Отменить</button>";
echo "</form>";
echo "<div class = 'razd'><a href = '" . DIR_FORUM . "' class = 'add'>" . img16('left.png') . " Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
} elseif (!user::access('forum_for_edit') || !$forum) {
header('Location: ' . DIR_FORUM);
}
exit;