Файл: modules/forum/action/edit_razdel.php
Строк: 150
<?php
/* Мод "Форум"
* Версия v0.0.1
* Дата последнего редактирования 15.01.2015
* Двиг DCMS Special
* Модифицировал densnet
* Автор yadalay
* Файл edit_razdel.php
* Описание: редактирование разделов
*/
$razdel = mysql_fetch_object(mysql_query('SELECT * FROM `forum_razdels` WHERE `id` = ' . intval($_GET['razdel'])));
if (user::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 = 'errs'>В поле 'Название раздела' можно использовать от 3 до 40 символов.</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 ($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 = "msgs">Раздел успешно изменён.</div>';
header('Location: /modules/forum/' . $forum_id . '/');
exit;
}
} elseif (isset($_POST['delete'])) {
echo "<form action = '" . DIR_FORUM . "$forum->id/$razdel->id/edit_razdel.html' 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'])) {
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('/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_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: /modules/forum/' . $forum->id . '/');
exit;
} elseif (isset($_POST['cancel'])) {
header('Location: /modules/forum/' . $forum->id . '/' . $razdel->id . '/edit_razdel.html');
exit;
}
echo "<form action = '" . DIR_FORUM . "$forum->id/$razdel->id/edit_razdel.html' method = 'post' class = 'razd'>";
echo "<b>Название раздела (40 символов):</b><br />";
echo "<div class = 'inputs'>";
echo "<input type = 'text' name = 'name' value = '$razdel->name' /><br />";
echo "<div class = 'input-icon'>" . img16('pen.png') . "</div>";
echo "</div>";
echo "<b>Описание раздела (100 символов):</b><br />";
echo "<textarea name = 'description'>$razdel->description</textarea><br />";
echo "<b>Подфорум:</b><br />";
echo "<div class = 'inputs'>";
echo "<select 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><br />";
echo "<div class = 'input-icon'>" . img16('folder.png') . "</div>";
echo "</div>";
echo "<b>Позиция</b><br />";
echo "<div class = 'inputs'>";
echo "<input type = 'text' name = 'number' value = '$razdel->number' size = '3' /><br />";
echo "<div class = 'input-icon'>" . img16('verh_niz.png') . "</div>";
echo "</div>";
echo "<b>Могут создавать темы только:</b><br />";
echo "<label><input type = 'checkbox' name = 'type' value = '1' " . (($razdel->type == 1) ? 'checked = "checked"' : NULL) . " /> Администраторы + модераторы</label><br />";
echo "<b>Вывод раздела:</b><br />";
echo "<label><input type = 'checkbox' name = 'output' value = '1' " . (($razdel->output == 1) ? 'checked = "checked"' : NULL) . " /> Отображать посл. 3 темы вместо описания</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>" : NULL;
echo "</form>";
echo "<div class = 'razd'><a class = 'add' href = '" . DIR_FORUM . "$forum->id/'>" . img16('left.png') . " Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
} else {
header('Location: /modules/forum/' . $forum->id . '/');
}
exit;