Файл: modules/forum/action/edit_razdel.php
Строк: 154
<?php
/* DCMS S (Special)
* Версия файла 0.0.1
* Дата последнего редактирования 23.11.2015
* Модифицировал densnet
* Автор yadalay
*/
$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 = '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);
msg('Раздел успешно изменён.');
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 = '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'])) {
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('/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_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);
msg('Раздел со всем его содержимым успешно удалён.');
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='card-block'>";
echo "Название раздела (40 символов):<br />";
echo "<input class='form-control' type='text' 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 "Позиция: <input class='form-control' type='text' name='number' value='$razdel->number' />";
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 "Вывод раздела:<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 "<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-danger'><span class='fa fa-trash-o'></span> Удалить</button>" : NULL;
echo "</form>";
echo "<div class='card-block'><a href='" . DIR_FORUM . "$forum->id/'><span class='fa fa-arrow-left'></span> Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
} else {
header('Location: /modules/forum/' . $forum->id . '/');
}
exit;