<?php

/* DCMS Special
 * Дата последнего редактирования 14.01.2016
 * Модифицировал densnet
 * Автор yadalay
 */

if (!access('forum_post_ed')) {
    header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
    exit;
} else {
    if (isset($_POST['clear'])) {
        $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);

        $msg_sys = "[url=/info.php?id=$user[id]]$user[nick][/url] " . ($user['sex'] ? '' . lang('почистил') . '' : '' . lang('почистила') . '') . " " . lang('всю тему') . ".";

        mysql_query('INSERT INTO `forum_posts` SET `id_theme` = ' . $theme->id . ', `id_user` = "0", `id_admin` = "0", `text` = "' . mysql_real_escape_string($msg_sys) . '", `time` = ' . $time);

        $_SESSION['message'] = lang('Тема успешно очищена');

        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
        exit;
    } elseif (isset($_POST['cancel'])) {
        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
        exit;
    } else {
        echo "<form class='list-group-item' action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/cleare_theme.html' method='post'>";
        echo lang('Вы уверены, что хотите очистить эту тему от сообщений?') . "<br />";

        $doc->Button('btn btn-primary btn-sm', 'clear', 'trash-o', 'Очистить');
        $doc->Button('btn btn-secondary btn-sm', 'cancel', null, 'Отменить');
        echo "</form>";
    }
}
