Файл: modules/forum/action/edit_razdel.php
Строк: 165
<?php
/* DCMS Special
* Дата последнего редактирования 12.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 "<ol class='breadcrumb'>";
echo "<li><a href='/'><span class='fa fa-home fa-fw'></span></a></li>";
echo "<li><a href='" . DIR_FORUM . "'>Форум</a></li>";
echo "<li><a href='" . DIR_FORUM . "$forum->id/'>" . toOutput($forum->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li><a href='" . DIR_FORUM . "$forum->id/$razdel->id/'>" . toOutput($razdel->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li class='active'>Удаление</li>";
echo "</ol>";
#Форма удаления раздела
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 btn-success'><span class='fa fa-trash-o fa-fw'></span> Удалить</button> ";
echo "<button name='cancel' class='btn 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 "<ol class='breadcrumb'>";
echo "<li><a href='/'><span class='fa fa-home fa-fw'></span></a></li>";
echo "<li><a href='" . DIR_FORUM . "'>Форум</a></li>";
echo "<li><a href='" . DIR_FORUM . "$forum->id/'>" . toOutput($forum->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li><a href='" . DIR_FORUM . "$forum->id/$razdel->id/'>" . toOutput($razdel->name, 1, 1, 0, 0, 0) . "</a></li>";
echo "<li class='active'>Редактирование</li>";
echo "</ol>";
echo "<form action = '" . DIR_FORUM . "$forum->id/$razdel->id/edit_razdel.html' method='post' class='list-group-item'>";
echo "Название раздела (40 символов):<br />";
echo "<input type='text' class='form-control' name='name' value='$razdel->name' />";
echo "Описание раздела (100 символов):<br />";
echo "<textarea class='form-control' name='description'>$razdel->description</textarea>";
echo "Подфорум:<br />";
echo "<select class='form-control' 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 "Позиция: <br />";
echo "<input type='text' class='form-control' name='number' value='$razdel->number' />";
echo "<div class='hr'></div>";
echo "Могут создавать темы только:<br />";
echo "<label class='c-input c-checkbox'><input type='checkbox' name='type' value='1' " . (($razdel->type == 1) ? 'checked="checked"' : NULL) . " /><span class='c-indicator'></span> Администраторы + модераторы</label><br />";
echo "<div class='hr'></div>";
echo "Вывод раздела:<br />";
echo "<label class='c-input c-checkbox'><input type='checkbox' name='output' value='1' " . (($razdel->output == 1) ? 'checked="checked"' : NULL) . " /><span class='c-indicator'></span> Отображать посл. 3 темы вместо описания</label><br />";
echo "<div class='hr'></div>";
echo "<button name='edit' class='btn btn-success'><span class='fa fa-save fa-fw'></span> Сохранить</button> ";
echo access('forum_for_delete') ? "<button name='delete' class='btn btn-danger'><span class='fa fa-trash-o fa-fw'></span> Удалить</button>" : NULL;
echo "</form>";
require_once H . 'sys/inc/tfoot.php';
} else {
header('Location: ' . DIR_FORUM . $forum->id . '/');
}
exit;