Файл: modules/forum/action/edit_razdel.php
Строк: 257
<?php
/* DCMS Special
* Дата последнего редактирования 19.12.2015
* Модифицировал densnet
* Автор yadalay
*/
$razdel = mysql_fetch_object(mysql_query('SELECT * FROM `forum_razdels` WHERE `id` = ' . intval($_GET['razdel'])));
if (access('forum_razd_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']);
$forum_id = intval($_POST['id_forum']);
$type = (isset($_POST['type'])) ? 1 : 0;
$output = (isset($_POST['output'])) ? 1 : 0;
$isset_name = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_razdels` WHERE `name` = "' . $name . '" AND `id_forum` = ' . $forum->id . ' AND `id` != ' . $razdel->id), 0);
$razdel_n = ($razdel->number != $number) ? mysql_fetch_object(mysql_query('SELECT `id`, `number` FROM `forum_razdels` WHERE `id_forum` = ' . $forum->id . ' AND `number` = ' . $number . ' AND `id` != ' . $razdel->id)) : NULL;
if ($razdel_n) {
mysql_query('UPDATE `forum_razdels` SET `number` = ' . $number . ' WHERE `id` = ' . $razdel->id);
mysql_query('UPDATE `forum_razdels` SET `number` = ' . $razdel->number . ' WHERE `id` = ' . $razdel_n->id);
}
if (mb_strlen($name) < 3 || mb_strlen($name) > 40) {
echo "<div class='alert alert-danger'>В поле 'Название раздела' можно использовать от 3 до 40 символов.</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 ($razdel->id_forum != $forum_id) {
admin_log('Форум', 'Разделы', 'Раздел "' . $razdel->name . '" перенесён из подфорума "' . $forum->name . '" в "' . $new_forum->name . '".');
}
if ($razdel->name != $name) {
admin_log('Форум', 'Разделы', 'Раздел "' . $razdel->name . '" переименован в "' . $name . '" в подфоруме "' . $forum->name . '".');
} else {
admin_log('Форум', 'Разделы', 'Раздел "' . $razdel->name . '" был изменён.');
}
mysql_query('UPDATE `forum_razdels` SET `id_forum` = ' . $forum_id . ', `name` = "' . $name . '", `description` = "' . $description . '", `number` = ' . $number . ', `type` = ' . $type . ', `output` = ' . $output . ' WHERE `id` = ' . $razdel->id);
$_SESSION['msg'] = "<div class='alert alert-success'><span class='fa fa-save fa-fw'></span> Сохранение... <br />Изменение раздела.</div>";
header('Location: ' . DIR_FORUM . $forum_id . '/');
exit;
}
} elseif (isset($_POST['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' href='" . DIR_FORUM . "$forum->id/$razdel->id/'>" . toOutput($razdel->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 . "$forum->id/$razdel->id/edit_razdel.html' method='post' class='list-group-item'>";
echo "Вы уверены, что хотите удалить этот раздел со всем его содержимым?<br />";
echo "<button name='del' class='btn waves-effect waves-light'><i class='material-icons'>delete</i> Удалить</button> ";
echo "<button name='cancel' class='btn waves-effect waves-light btn-secondary'>Отменить</button>";
echo "</form>";
require_once H . 'sys/inc/tfoot.php';
} elseif (isset($_POST['del'])) {
admin_log('Форум', 'Разделы', 'Раздел "' . $razdel->name . '" был удалён из подфорума "' . $forum->name . '".');
$themes = mysql_query('SELECT `id` FROM `forum_themes` WHERE `id_razdel` = ' . $razdel->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_razdel` = ' . $razdel->id);
$n_razdels = mysql_query('SELECT `id`, `number` FROM `forum_razdels` WHERE `number` > ' . $razdel->number);
while ($n_razdel = mysql_fetch_object($n_razdels)) {
mysql_query('UPDATE `forum_razdels` SET `number` = ' . ($n_razdel->number - 1) . ' WHERE `id` = ' . $n_razdel->id);
}
mysql_query('DELETE FROM `forum_razdels` WHERE `id` = ' . $razdel->id);
$_SESSION['msg'] = '<div class = "msg">Раздел со всем его содержимым успешно удалён.</div>';
header('Location: ' . DIR_FORUM . $forum->id . '/');
exit;
} elseif (isset($_POST['cancel'])) {
header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/edit_razdel.html');
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' href='" . DIR_FORUM . "$forum->id/$razdel->id/'>" . toOutput($razdel->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 . "$forum->id/$razdel->id/edit_razdel.html' method='post' class='list-group-item'>";
echo "<div class='row'>";
echo "<div class='input-field col s12'>";
echo "<input id='name' name='name' length='40' type='text' value='$razdel->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'>$razdel->description</textarea>";
echo "<label for='description'>Описание раздела</label>";
echo "</div>";
echo "</div>";
echo "Подфорум:<br />";
echo "<select class='browser-default' name='id_forum'>";
$forums_s = mysql_query('SELECT `id`, `name` FROM `forum` ORDER BY `number` ASC');
while ($forum_s = mysql_fetch_object($forums_s)) {
if ($forum_s->access == 0 || ($forum_s->access == 1 && $user['group_access'] > 7) || ($forum_s->access == 2 && $user['group_access'] > 2)) {
echo "<option value='$forum_s->id' " . (($forum_s->id == $razdel->id_forum) ? 'selected="selected"' : NULL) . ">$forum_s->name</option>";
} else {
continue;
}
}
echo "</select>";
echo "<div class='row'>";
echo "<div class='input-field col s12'>";
echo "<input id='number' name='number' type='text' value='$razdel->number' class='validate'>";
echo "<label for='number'>Позиция</label>";
echo "</div>";
echo "</div>";
echo "<div class='switch'>";
echo "Могут создавать темы только:<br />";
echo "<label><input type='checkbox' name='type' value='1' " . (($razdel->type == 1) ? 'checked="checked"' : NULL) . "><span class='lever'></span>Администраторы + модераторы</label>";
echo "</div>";
echo "<div class='hr'></div>";
echo "<div class='switch'>";
echo "Вывод раздела:<br />";
echo "<label><input type='checkbox' name='output' value='1' " . (($razdel->output == 1) ? 'checked="checked"' : NULL) . "><span class='lever'></span>Отображать посл. 3 темы</label>";
echo "</div>";
echo "<div class='hr'></div>";
echo "<button name='edit' class='btn waves-effect waves-light'><i class='material-icons'>save</i> Сохранить</button> ";
echo access('forum_for_delete') ? "<button name='delete' class='btn waves-effect waves-light btn-danger'><i class='material-icons'>delete</i> Удалить</button>" : NULL;
echo "</form>";
require_once H . 'sys/inc/tfoot.php';
} else {
header('Location: ' . DIR_FORUM . $forum->id . '/');
}
exit;