Файл: modules/forum/action/edit_forum.php
Строк: 232
<?php
/* DCMS Special
* Дата последнего редактирования 19.12.2015
* Модифицировал densnet
* Автор yadalay
*/
$forum = mysql_fetch_object(mysql_query('SELECT * FROM `forum` WHERE `id` = ' . intval($_GET['edit_forum'])));
if (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);
$_SESSION['msg'] = "<div class='alert alert-success'>Подфорум успешно изменен.</div>";
header('Location: ' . DIR_FORUM);
exit;
}
} elseif (isset($_POST['delete']) && access('forum_for_delete')) {
#Навигация
echo "<nav class='navbar navbar-light' style='background-color: #607D8B; color: #fff;'>";
echo "<ul class='nav navbar-nav'>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='/'><i class='material-icons'>home</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "'>Форум</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/'>" . toOutput($forum->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'>Удаление</a></li>";
echo "</ul>";
echo "</nav>";
#Форма удаления подфорума
echo "<form action='" . DIR_FORUM . "?edit_forum=$forum->id' method='post' class='list-group-item'>";
echo "Вы уверены, что хотите удалить этот подфорум со всем его содержимым?<br />";
echo "<button name='del' class='waves-effect waves-light btn'><span class='fa fa-trash-o fa-fw'></span> Удалить</button> ";
echo "<button name='cancel' class='waves-effect waves-light btn btn-secondary'>Отменить</button>";
echo "</form>";
require_once H . 'sys/inc/tfoot.php';
} elseif (isset($_POST['del']) && 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(DIR_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="alert alert-success">Подфорум со всем его содержимым успешно удалён.</div>';
header('Location: ' . DIR_FORUM);
exit;
} elseif (isset($_GET['cancel'])) {
header('Location: ' . DIR_FORUM);
exit;
}
#Навигация
echo "<nav class='navbar navbar-light' style='background-color: #607D8B; color: #fff;'>";
echo "<ul class='nav navbar-nav'>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='/'><i class='material-icons'>home</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "'>Форум</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/'>" . toOutput($forum->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'>Редактирование</a></li>";
echo "</ul>";
echo "</nav>";
#Форма редактирования подфорума
echo "<form action='" . DIR_FORUM . "?edit_forum=$forum->id' method='post' class='list-group-item'>";
echo "<div class='row'>";
echo "<div class='input-field col s12'>";
echo "<input id='name' name='name' length='100' type='text' value='$forum->name' class='validate'>";
echo "<label for='name'>Название подфорума</label>";
echo "</div>";
echo "</div>";
echo "<div class='row'>";
echo "<div class='input-field col s12'>";
echo "<textarea name='description' id='description' length='100' class='materialize-textarea'>$forum->description</textarea>";
echo "<label for='description'>Описание подфорума</label>";
echo "</div>";
echo "</div>";
echo "<div class='row'>";
echo "<div class='input-field col s12'>";
echo "<input id='number' name='number' type='text' value='$forum->number' class='validate'>";
echo "<label for='number'>Позиция</label>";
echo "</div>";
echo "</div>";
echo "Доступ:<br />";
echo "<input class='with-gap' name='access' type='radio' id='access0' value='0' " . (($forum->access == 0) ? " checked='checked'" : NULL) . " /><label for='access0'>Все</label><br />";
echo "<input class='with-gap' name='access' type='radio' id='access1' value='1' " . (($forum->access == 1) ? 'checked="checked"' : NULL) . " /><label for='access1'>Только администраторы</label><br />";
echo "<input class='with-gap' name='access' type='radio' id='access2' value='2' " . (($forum->access == 2) ? 'checked="checked"' : NULL) . " /><label for='access2'>Администраторы + модераторы</label>";
echo "<div class='hr'></div>";
echo "<div class='switch'>";
echo "<label><input type='checkbox' name='output' value='1' " . (($forum->output == 1) ? 'checked="checked"' : NULL) . "><span class='lever'></span>Список разделов</label>";
echo "</div>";
echo "<div class='hr'></div>";
echo "<button name='edit' class='waves-effect waves-light btn'><i class='material-icons'>save</i> Сохранить</button> ";
echo access('forum_for_delete') ? "<button name='delete' class='waves-effect waves-light btn btn-danger'><i class='material-icons'>delete</i> Удалить</button> " : "<button name='cancel' class='waves-effect waves-light btn btn-secondary'>Отменить</button>";
echo "</form>";
require_once H . 'sys/inc/tfoot.php';
} elseif (!access('forum_for_edit') || !$forum) {
header('Location: ' . DIR_FORUM);
}
exit;