function IndexForumDeleteTopic()
{
    global $forum_lang;
    if (!System::user()->isAdmin() || !CheckGet('topic', 'ok')) {
        HackOff();
        return;
    }
    $topic_id = SafeEnv($_GET['topic'], 11, int);
    // Подтверждение на удаление
    if (!isset($_GET['ok']) || !isset($_POST['text']) && System::config('forum/basket') || $_GET['ok'] == '0') {
        System::database()->Select('forum_topics', "`id`='" . SafeEnv($_GET['topic'], 11, int) . "'");
        $topic = System::database()->FetchRow();
        $text = $forum_lang['delete_topic'] . ' "' . SafeDB($topic['title'], 255, str) . '"?';
        System::site()->AddTextBox($forum_lang['forum'], '<p align="center">' . $text . '</p>');
        System::site()->AddTemplatedBox('', 'module/forum_delete_post.html');
        System::site()->AddBlock('delete_form', true, false, 'form');
        $vars = array();
        $vars['basket'] = System::config('forum/basket') == true;
        $vars['url'] = 'index.php?name=forum&op=deletetopic&topic=' . SafeEnv($_GET['topic'], 11, int) . '&ok=1';
        // Без UFU
        System::site()->Blocks['delete_form']['vars'] = $vars;
        return;
    }
    // Вытаскиваем тему
    System::database()->Select('forum_topics', "`id`='{$topic_id}'");
    if (System::database()->NumRows() == 0) {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_topic']);
        return;
    }
    $topic = System::database()->FetchRow();
    if ($topic['delete'] == '1') {
        // Удалена в корзину
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['topic_basket']);
        return;
    }
    // Удаление
    if (System::config('forum/basket')) {
        // Удаляем тему в корзину
        $reason = '';
        if (isset($_POST['text'])) {
            $reason = SafeEnv($_POST['text'], 255, str);
        }
        Moderation_Do_Basket_Topic($topic_id, $reason);
    } else {
        ForumAdminDeleteTopic($topic_id);
    }
    // Форум (Изменяем счетчики количества тем и сообщений, устанавливаем информацию о последнем посте)
    $forum_id = SafeEnv($topic['forum_id'], 11, int);
    System::database()->Select('forums', "`id`='{$forum_id}'");
    if (System::database()->NumRows() == 0) {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_forum']);
        return;
    }
    $forum = System::database()->FetchRow();
    // Значения счётчиков форума
    $forum_topics = (int) $forum['topics'] - 1;
    if ($forum_topics < 0) {
        $forum_topics = 0;
    }
    $forum_posts = (int) $forum['posts'] - (int) $topic['posts'];
    if ($forum_posts < 0) {
        $forum_posts = 0;
    }
    $forum_set = "`topics`='{$forum_topics}',`posts`='{$forum_posts}'";
    // Устанавливаем информацию о последнем посте в форуме
    if ($forum['last_id'] == $topic_id) {
        // Только если удалена тема с последним постом
        $forum_set = ForumSetLastTopic($forum_id, $forum_set, true);
    }
    System::database()->Update('forums', $forum_set, "`id`= '{$forum_id}'");
    // Очищаем кэш форума
    ForumCacheClear();
    GO(Ufu('index.php?name=forum&op=showforum&forum=' . $forum_id, 'forum/{forum}/'));
}
function ForumModerationDeleteTopics($topics, $begin)
{
    global $forum_lang;
    if ($begin) {
        $forum = null;
        $forum_id = null;
        $deleted_topics = 0;
        $deleted_posts = 0;
        // TODO: Возможность указывать причину удаления топиков введём позже.
        $reason = '';
        if (isset($_POST['text'])) {
            $reason = SafeEnv($_POST['text'], 255, str);
        }
        $topics = System::database()->Select('forum_topics', '`id`=\'' . implode('\' or `id`=\'', $topics) . '\'');
        foreach ($topics as $topic) {
            $topic_id = SafeEnv($topic['id'], 11, int);
            if ($topic['delete'] == '1') {
                // Удалена в корзину
                continue;
            }
            // Форум
            if (!isset($forum)) {
                $forum_id = SafeEnv($topic['forum_id'], 11, int);
                System::database()->Select('forums', "`id`='{$forum_id}'");
                if (System::database()->NumRows() == 0) {
                    System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_forum'] . ' "' . SafeDB($topic['title'], 255, str) . '"');
                    return false;
                }
                $forum = System::database()->FetchRow();
            }
            $deleted_topics++;
            $deleted_posts += (int) $topic['posts'];
            // Удаление
            if (System::config('forum/basket')) {
                // Удаляем тему в корзину
                Moderation_Do_Basket_Topic($topic_id, $reason);
            } else {
                ForumAdminDeleteTopic($topic_id);
            }
        }
        if ($deleted_topics > 0) {
            // Обновляем форум
            $forum_topics = (int) $forum['topics'] - $deleted_topics;
            if ($forum_topics < 0) {
                $forum_topics = 0;
            }
            $forum_posts = (int) $forum['posts'] - $deleted_posts;
            if ($forum_posts < 0) {
                $forum_posts = 0;
            }
            ForumSetLastTopic($forum_id, "`topics`='{$forum_topics}',`posts`='{$forum_posts}'");
            ForumCacheClear();
        }
        return $forum_lang['delete_topics_success'];
    } else {
        $topics = System::database()->Select('forum_topics', '`id`=\'' . implode('\' or `id`=\'', $topics) . '\'');
        $text = $forum_lang['confirm'] . ':&nbsp;' . $forum_lang['delete_topics'];
        $text .= '<ul style="margin: 10px 0;">';
        foreach ($topics as $topic_id) {
            $text .= '<li>' . SafeDB($topic_id['title'], 255, str) . '</li>';
        }
        $text .= '</ul>';
        return $text;
    }
}