Файл: modules/forum/action/edit_forum.php
Строк: 157
<?php
/* DCMS S (Special)
* Версия файла 0.0.1
* Дата последнего редактирования 23.11.2015
* Модифицировал densnet
* Автор yadalay
*/
$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 = 'alert alert-danger'>В поле 'Название подфорума' можно использовать от 3 до 40 символов.</div>";
} elseif ($isset_name != 0) {
echo "<div class = 'alert alert-danger'>Подфорум с таким названием уже существует.</div>";
} elseif ($number < 0 || $number == NULL || $number == 0) {
echo "<div class = 'alert alert-danger'>Введите уровень.</div>";
} elseif (mb_strlen($description) > 100) {
echo "<div class = 'alert alert-danger'>Слишком длинное описание подфорума.</div>";
} elseif ($isset_number != 0) {
echo "<div class = 'alert alert-danger'>Данный уровень уже использует другой подфорум.</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);
msg('Подфорум успешно изменён.');
header('Location: ' . DIR_FORUM);
exit;
}
} elseif (isset($_POST['delete']) && user::access('forum_for_delete')) {
echo "<form action = '/modules/forum/?edit_forum=$forum->id' method = 'post' class = 'card-block'>";
echo "Вы уверены, что хотите удалить этот подфорум со всем его содержимым?<br />";
echo "<button name='del' class='btn btn-success'>Удалить</button> ";
echo "<button name='cancel' class='btn btn-default'>Отменить</button>";
echo "</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('/modules/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);
msg('Подфорум со всем его содержимым успешно удалён.');
header('Location: ' . DIR_FORUM);
exit;
} elseif (isset($_GET['cancel'])) {
header('Location: ' . DIR_FORUM);
exit;
}
echo "<form action = '/modules/forum/?edit_forum=$forum->id' method = 'post' class = 'card-block'>";
echo "Название подфорума (40 символов):<br />";
echo "<input class='form-control' type = 'text' name = 'name' value = '$forum->name' />";
echo "Описание подфорума (100 символов):<br />";
echo "<textarea class='form-control' rows='3' name = 'description'>$forum->description</textarea>";
echo "Позиция: <input class='form-control' type = 'text' name = 'number' value = '$forum->number' />";
echo "Доступ:<br />";
echo "<label class='c-input c-radio'><input type = 'radio' name = 'access' value = '0' " . (($forum->access == 0) ? " checked = 'checked'" : NULL) . " /><span class='c-indicator'></span> Все</label><br />";
echo "<label class='c-input c-radio'><input type = 'radio' name = 'access' value = '1' " . (($forum->access == 1) ? 'checked = "checked"' : NULL) . " /><span class='c-indicator'></span> Только администраторы</label><br />";
echo "<label class='c-input c-radio'><input type = 'radio' name = 'access' value = '2' " . (($forum->access == 2) ? 'checked = "checked"' : NULL) . " /><span class='c-indicator'></span> Администраторы + модераторы</label><br />";
echo "Вывод подфорума:<br />";
echo "<label class='c-input c-checkbox'><input type = 'checkbox' name = 'output' value = '1' " . (($forum->output == 1) ? 'checked = "checked"' : NULL) . " /><span class='c-indicator'></span> Отображать список разделов вместо описания</label><br />";
echo "<button name = 'edit' class = 'btn btn-success'><span class='fa fa-save'></span> Сохранить</button> ";
echo user::access('forum_for_delete') ? "<button name = 'delete' class = 'btn btn-default'><span class='fa fa-trash-o'></span> Удалить</button> " : "<button name = 'cancel' class = 'btn btn-default'>Отменить</button>";
echo "</form>";
echo "<div class = 'card-block'><a href = '" . DIR_FORUM . "'><span class='fa fa-arrow-left'></span> Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
} elseif (!user::access('forum_for_edit') || !$forum) {
header('Location: ' . DIR_FORUM);
}
exit;