$db->sql_query("TRUNCATE " . SEARCH_MATCH_TABLE);
    }
    // Fetch a batch of posts_text entries
    $sql = "SELECT COUNT(*) AS total, MAX(post_id) AS max_post_id, MIN(post_id) AS min_post_id\r\n\t\tFROM " . POSTS_TABLE;
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $totalposts = $row['total'];
    $max_post_id = $row['max_post_id'];
    $batchstart = !$batchstart ? $row['min_post_id'] : $batchstart;
    $batchend = $batchstart + $batchsize;
    $db->sql_freeresult($result);
    $sql = "SELECT *\r\n\t\tFROM " . POSTS_TABLE . "\r\n\t\tWHERE post_id\r\n\t\t\tBETWEEN {$batchstart}\r\n\t\t\t\tAND {$batchend}";
    $result = $db->sql_query($sql);
    if ($row = $db->sql_fetchrow($result)) {
        do {
            $fulltext->add('admin', $row['post_id'], $row['post_text'], $row['post_subject']);
        } while ($row = $db->sql_fetchrow($result));
    }
    $db->sql_freeresult($result);
    $batchcount++;
    if ($batchstart + $batchsize < $max_post_id) {
        redirect(adminlink('forums&amp;file=admin_search&batchstart=' . ($batchstart + $batchsize) . '&batchcount=' . $batchcount), 3);
    } else {
        set_config('board_disable', 0);
        // search tidy
        $fulltext->search_tidy();
        adm_page_header($_CLASS['core_user']->lang['SEARCH_INDEX']);
        ?>

<h1><?php 
        echo $_CLASS['core_user']->lang['SEARCH_INDEX'];
function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)
{
    global $_CLASS, $config;
    // We do not handle erasing posts here
    if ($mode == 'delete') {
        return;
    }
    $current_time = gmtime();
    if ($mode == 'post') {
        $post_mode = 'post';
        $update_message = true;
    } else {
        if ($mode != 'edit') {
            $post_mode = 'reply';
            $update_message = true;
        } else {
            if ($mode == 'edit') {
                $post_mode = $data['topic_first_post_id'] == $data['topic_last_post_id'] ? 'edit_topic' : ($data['topic_first_post_id'] == $data['post_id'] ? 'edit_first_post' : ($data['topic_last_post_id'] == $data['post_id'] ? 'edit_last_post' : 'edit'));
            }
        }
    }
    // Collect some basic informations about which tables and which rows to update/insert
    $sql_data = array();
    $poster_id = $mode == 'edit' ? $data['poster_id'] : (int) $_CLASS['core_user']->data['user_id'];
    // Collect Informations
    switch ($post_mode) {
        case 'post':
        case 'reply':
            $sql_data[FORUMS_POSTS_TABLE]['sql'] = array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'poster_id' => (int) $_CLASS['core_user']->data['user_id'], 'icon_id' => $data['icon_id'], 'poster_ip' => $_CLASS['core_user']->ip, 'post_time' => $current_time, 'post_approved' => $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? 0 : 1, 'enable_bbcode' => $data['enable_bbcode'], 'enable_html' => $data['enable_html'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => !$_CLASS['core_user']->is_user ? stripslashes($username) : '', 'post_subject' => $subject, 'post_text' => $data['message'], 'post_checksum' => $data['message_md5'], 'post_attachment' => isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data']) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_edit_locked' => $data['post_edit_locked']);
            break;
        case 'edit_first_post':
        case 'edit':
            if (!$_CLASS['auth']->acl_gets('m_', 'a_') || $data['post_edit_reason']) {
                $sql_data[FORUMS_POSTS_TABLE]['sql'] = array('post_edit_time' => $current_time);
                $sql_data[FORUMS_POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
            }
        case 'edit_last_post':
        case 'edit_topic':
            if (($post_mode == 'edit_last_post' || $post_mode == 'edit_topic') && $data['post_edit_reason']) {
                $sql_data[FORUMS_POSTS_TABLE]['sql'] = array('post_edit_time' => $current_time);
                $sql_data[FORUMS_POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
            }
            if (!isset($sql_data[FORUMS_POSTS_TABLE]['sql'])) {
                $sql_data[FORUMS_POSTS_TABLE]['sql'] = array();
            }
            $sql_data[FORUMS_POSTS_TABLE]['sql'] = array_merge($sql_data[FORUMS_POSTS_TABLE]['sql'], array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], 'post_approved' => $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? 0 : 1, 'enable_bbcode' => $data['enable_bbcode'], 'enable_html' => $data['enable_html'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => $username && $data['poster_id'] == ANONYMOUS ? stripslashes($username) : '', 'post_subject' => $subject, 'post_edit_reason' => $data['post_edit_reason'], 'post_edit_user' => (int) $data['post_edit_user'], 'post_checksum' => $data['message_md5'], 'post_attachment' => isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data']) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_edit_locked' => $data['post_edit_locked']));
            if ($update_message) {
                $sql_data[FORUMS_POSTS_TABLE]['sql']['post_text'] = $data['message'];
            }
            break;
    }
    // And the topic ladies and gentlemen
    switch ($post_mode) {
        case 'post':
            $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array('topic_poster' => (int) $_CLASS['core_user']->data['user_id'], 'topic_time' => $current_time, 'forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_approved' => $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? 0 : 1, 'topic_title' => $subject, 'topic_first_poster_name' => !$_CLASS['core_user']->is_user && $username ? stripslashes($username) : $_CLASS['core_user']->data['username'], 'topic_type' => $topic_type, 'topic_time_limit' => $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ? $data['topic_time_limit'] * 86400 : 0, 'topic_status' => $data['topic_status'], 'topic_attachment' => isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data']) ? 1 : 0, 'topic_replies_real' => 0, 'topic_replies' => 0, 'topic_views' => 0);
            if (isset($poll['poll_options']) && !empty($poll['poll_options'])) {
                $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array('poll_title' => $poll['poll_title'], 'poll_start' => $poll['poll_start'] ? $poll['poll_start'] : $current_time, 'poll_max_options' => $poll['poll_max_options'], 'poll_length' => $poll['poll_length'] * 86400, 'poll_vote_change' => $poll['poll_vote_change']));
            }
            $sql_data[USERS_TABLE]['stat'][] = "user_last_post_time = {$current_time}" . ($_CLASS['auth']->acl_get('f_postcount', $data['forum_id']) ? ', user_posts = user_posts + 1' : '');
            if ($topic_type != POST_GLOBAL) {
                if (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve')) {
                    $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
                }
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? ', forum_topics = forum_topics + 1' : '');
            }
            break;
        case 'reply':
            $sql_data[FORUMS_TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? ', topic_replies = topic_replies + 1' : '');
            $sql_data[USERS_TABLE]['stat'][] = "user_last_post_time = {$current_time}" . ($_CLASS['auth']->acl_get('f_postcount', $data['forum_id']) ? ', user_posts = user_posts + 1' : '');
            if ((!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve')) && $topic_type != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
            }
            break;
        case 'edit_topic':
        case 'edit_first_post':
            $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_approved' => $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? 0 : 1, 'topic_title' => $subject, 'topic_first_poster_name' => stripslashes($username), 'topic_type' => $topic_type, 'topic_time_limit' => $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ? $data['topic_time_limit'] * 86400 : 0, 'poll_title' => $poll['poll_options'] ? $poll['poll_title'] : '', 'poll_start' => $poll['poll_options'] ? $poll['poll_start'] ? $poll['poll_start'] : $current_time : 0, 'poll_max_options' => $poll['poll_options'] ? $poll['poll_max_options'] : 1, 'poll_length' => $poll['poll_options'] ? $poll['poll_length'] * 86400 : 0, 'poll_vote_change' => $poll['poll_vote_change'], 'topic_attachment' => $post_mode == 'edit_topic' ? isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data']) ? 1 : 0 : $data['topic_attachment']);
            break;
    }
    $_CLASS['core_db']->transaction();
    // Submit new topic
    if ($post_mode == 'post') {
        $sql = 'INSERT INTO ' . FORUMS_TOPICS_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $sql_data[FORUMS_TOPICS_TABLE]['sql']);
        $_CLASS['core_db']->query($sql);
        $data['topic_id'] = $_CLASS['core_db']->insert_id(FORUMS_TOPICS_TABLE, 'topic_id');
        $sql_data[FORUMS_POSTS_TABLE]['sql'] = array_merge($sql_data[FORUMS_POSTS_TABLE]['sql'], array('topic_id' => $data['topic_id']));
        unset($sql_data[FORUMS_TOPICS_TABLE]['sql']);
    }
    // Submit new post
    if ($post_mode == 'post' || $post_mode == 'reply') {
        if ($post_mode == 'reply') {
            $sql_data[FORUMS_POSTS_TABLE]['sql'] = array_merge($sql_data[FORUMS_POSTS_TABLE]['sql'], array('topic_id' => $data['topic_id']));
        }
        $sql = 'INSERT INTO ' . FORUMS_POSTS_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $sql_data[FORUMS_POSTS_TABLE]['sql']);
        $_CLASS['core_db']->query($sql);
        $data['post_id'] = $_CLASS['core_db']->insert_id(FORUMS_POSTS_TABLE, 'post_id');
        if ($post_mode == 'post') {
            $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array('topic_first_post_id' => $data['post_id'], 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, 'topic_last_poster_id' => (int) $_CLASS['core_user']->data['user_id'], 'topic_last_poster_name' => !$_CLASS['core_user']->is_user && $username ? $username : $_CLASS['core_user']->data['username']);
        }
        unset($sql_data[FORUMS_POSTS_TABLE]['sql']);
    }
    $make_global = false;
    // Are we globalising or unglobalising?
    if ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic') {
        $sql = 'SELECT topic_type, topic_replies_real, topic_approved
			FROM ' . FORUMS_TOPICS_TABLE . '
			WHERE topic_id = ' . $data['topic_id'];
        $result = $_CLASS['core_db']->query($sql);
        $row = $_CLASS['core_db']->fetch_row_assoc($result);
        $_CLASS['core_db']->free_result($result);
        // globalise
        if ($row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL) {
            // Decrement topic/post count
            $make_global = true;
            $sql_data[FORUMS_FORUMS_TABLE]['stat'] = array();
            $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($row['topic_replies_real'] + 1);
            $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real - 1' . ($row['topic_approved'] ? ', forum_topics = forum_topics - 1' : '');
            // Update forum_ids for all posts
            $sql = 'UPDATE ' . POSTS_TABLE . '
				SET forum_id = 0
				WHERE topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        } else {
            if ($row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL) {
                // Increment topic/post count
                $make_global = true;
                $sql_data[FORUMS_FORUMS_TABLE]['stat'] = array();
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + ' . ($row['topic_replies_real'] + 1);
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . ($row['topic_approved'] ? ', forum_topics = forum_topics + 1' : '');
                // Update forum_ids for all posts
                $sql = 'UPDATE ' . FORUMS_POSTS_TABLE . '
				SET forum_id = ' . $data['forum_id'] . '
				WHERE topic_id = ' . $data['topic_id'];
                $_CLASS['core_db']->query($sql);
            }
        }
    }
    // Update the topics table
    if (isset($sql_data[FORUMS_TOPICS_TABLE]['sql'])) {
        $_CLASS['core_db']->query('UPDATE ' . FORUMS_TOPICS_TABLE . '
			SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_data[FORUMS_TOPICS_TABLE]['sql']) . '
			WHERE topic_id = ' . $data['topic_id']);
    }
    // Update the posts table
    if (isset($sql_data[FORUMS_POSTS_TABLE]['sql'])) {
        $_CLASS['core_db']->query('UPDATE ' . FORUMS_POSTS_TABLE . '
			SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_data[FORUMS_POSTS_TABLE]['sql']) . '
			WHERE post_id = ' . $data['post_id']);
    }
    // Update Poll Tables
    if (isset($poll['poll_options']) && !empty($poll['poll_options'])) {
        $cur_poll_options = array();
        if ($poll['poll_start'] && $mode == 'edit') {
            $sql = 'SELECT * FROM ' . FORUMS_POLL_OPTIONS_TABLE . '
				WHERE topic_id = ' . $data['topic_id'] . '
				ORDER BY poll_option_id';
            $result = $_CLASS['core_db']->query($sql);
            while ($cur_poll_options[] = $_CLASS['core_db']->fetch_row_assoc($result)) {
            }
            $_CLASS['core_db']->free_result($result);
        }
        $size = sizeof($poll['poll_options']);
        for ($i = 0, $size; $i < $size; $i++) {
            if (trim($poll['poll_options'][$i])) {
                if (!$cur_poll_options[$i]) {
                    $sql = 'INSERT INTO ' . FORUMS_POLL_OPTIONS_TABLE . "  (poll_option_id, topic_id, poll_option_text)\n\t\t\t\t\t\tVALUES ({$i}, " . $data['topic_id'] . ", '" . $_CLASS['core_db']->sql_escape($poll['poll_options'][$i]) . "')";
                    $_CLASS['core_db']->query($sql);
                } else {
                    if ($poll['poll_options'][$i] != $cur_poll_options[$i]) {
                        $sql = "UPDATE " . FORUMS_POLL_OPTIONS_TABLE . "\n\t\t\t\t\t\tSET poll_option_text = '" . $_CLASS['core_db']->sql_escape($poll['poll_options'][$i]) . "'\n\t\t\t\t\t\tWHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . "\n\t\t\t\t\t\t\tAND topic_id = " . $data['topic_id'];
                        $_CLASS['core_db']->query($sql);
                    }
                }
            }
        }
        if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) {
            $sql = 'DELETE FROM ' . FORUMS_POLL_OPTIONS_TABLE . '
				WHERE poll_option_id >= ' . sizeof($poll['poll_options']) . '
					AND topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        }
    }
    // Submit Attachments
    if (sizeof($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit'))) {
        $space_taken = $files_added = 0;
        foreach ($data['attachment_data'] as $pos => $attach_row) {
            if ($attach_row['attach_id']) {
                // update entry in db if attachment already stored in db and filespace
                $sql = 'UPDATE ' . FORUMS_ATTACHMENTS_TABLE . "\n\t\t\t\t\tSET comment = '" . $_CLASS['core_db']->sql_escape($attach_row['comment']) . "'\n\t\t\t\t\tWHERE attach_id = " . (int) $attach_row['attach_id'];
                $_CLASS['core_db']->query($sql);
            } else {
                // insert attachment into db
                if (!@file_exists($config['upload_path'] . '/' . basename($attach_row['physical_filename']))) {
                    continue;
                }
                $attach_sql = array('post_msg_id' => $data['post_id'], 'topic_id' => $data['topic_id'], 'in_message' => 0, 'poster_id' => $poster_id, 'physical_filename' => basename($attach_row['physical_filename']), 'real_filename' => basename($attach_row['real_filename']), 'comment' => $attach_row['comment'], 'extension' => $attach_row['extension'], 'mimetype' => $attach_row['mimetype'], 'filesize' => $attach_row['filesize'], 'filetime' => $attach_row['filetime'], 'thumbnail' => $attach_row['thumbnail']);
                $sql = 'INSERT INTO ' . FORUMS_ATTACHMENTS_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $attach_sql);
                $_CLASS['core_db']->query($sql);
                $space_taken += $attach_row['filesize'];
                $files_added++;
            }
        }
        if (sizeof($data['attachment_data'])) {
            $sql = 'UPDATE ' . FORUMS_POSTS_TABLE . '
				SET post_attachment = 1
				WHERE post_id = ' . $data['post_id'];
            $_CLASS['core_db']->query($sql);
            $sql = 'UPDATE ' . FORUMS_TOPICS_TABLE . '
				SET topic_attachment = 1
				WHERE topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        }
        set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
        set_config('num_files', $config['num_files'] + $files_added, true);
    }
    $_CLASS['core_db']->transaction('commit');
    if ($post_mode == 'post' || $post_mode == 'reply' || $post_mode == 'edit_last_post') {
        if ($topic_type != POST_GLOBAL) {
            $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id']));
        }
        $update = update_last_post_information('topic', $data['topic_id']);
        if (sizeof($update)) {
            $sql_data[FORUMS_TOPICS_TABLE]['stat'][] = implode(', ', $update);
        }
    }
    if ($make_global) {
        $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id']));
    }
    if ($post_mode == 'edit_topic') {
        $update = update_last_post_information('topic', $data['topic_id']);
        if (sizeof($update)) {
            $sql_data[FORUMS_TOPICS_TABLE]['stat'][] = implode(', ', $update);
        }
    }
    // Update total post count, do not consider moderated posts/topics
    if (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve')) {
        if ($post_mode == 'post') {
            set_config('num_topics', $config['num_topics'] + 1, true);
            set_config('num_posts', $config['num_posts'] + 1, true);
        }
        if ($post_mode == 'reply') {
            set_config('num_posts', $config['num_posts'] + 1, true);
        }
    }
    // Update forum stats
    $_CLASS['core_db']->transaction();
    $where_sql = array(FORUMS_POSTS_TABLE => 'post_id = ' . $data['post_id'], FORUMS_TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $_CLASS['core_user']->data['user_id']);
    foreach ($sql_data as $table => $update_ary) {
        if (isset($update_ary['stat']) && implode('', $update_ary['stat'])) {
            $_CLASS['core_db']->query("UPDATE {$table} SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table]);
        }
    }
    // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement
    if ($make_global) {
        $_CLASS['core_db']->query('DELETE FROM ' . FORUMS_TOPICS_TABLE . '
			WHERE topic_moved_id = ' . $data['topic_id']);
    }
    // Fulltext parse
    if ($update_message && $data['enable_indexing']) {
        $search = new fulltext_search();
        $result = $search->add($mode, $data['post_id'], $data['message'], $subject);
    }
    $_CLASS['core_db']->transaction('commit');
    // Delete draft if post was loaded...
    $draft_id = request_var('draft_loaded', 0);
    if ($draft_id) {
        $_CLASS['core_db']->query('DELETE FROM ' . DRAFTS_TABLE . " WHERE draft_id = {$draft_id} AND user_id = " . $_CLASS['core_user']->data['user_id']);
    }
    // Topic Notification
    if (!$data['notify_set'] && $data['notify']) {
        $sql = 'INSERT INTO ' . FORUMS_TOPICS_WATCH_TABLE . ' (user_id, topic_id)
			VALUES (' . $_CLASS['core_user']->data['user_id'] . ', ' . $data['topic_id'] . ')';
        $_CLASS['core_db']->query($sql);
    } else {
        if ($data['notify_set'] && !$data['notify']) {
            $sql = 'DELETE FROM ' . FORUMS_TOPICS_WATCH_TABLE . '
			WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . '
				AND topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        }
    }
    // Mark this topic as read and posted to.
    markread('topic', $data['forum_id'], $data['topic_id'], $data['post_time']);
    // Send Notifications
    if ($mode != 'edit' && $mode != 'delete' && (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve'))) {
        user_notification($mode, stripslashes($subject), stripslashes($data['topic_title']), stripslashes($data['forum_name']), $data['forum_id'], $data['topic_id'], $data['post_id']);
    }
    if ($mode == 'post') {
        $url = !$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? generate_link('Forums&amp;file=viewtopic&amp;f=' . $data['forum_id'] . '&amp;t=' . $data['topic_id']) : generate_link('Forums&amp;file=viewforum&amp;f=' . $data['forum_id']);
    } else {
        $url = !$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? generate_link("Forums&amp;file=viewtopic&amp;f={$data['forum_id']}&amp;t={$data['topic_id']}&amp;p={$data['post_id']}#{$data['post_id']}") : generate_link("Forums&amp;file=viewtopic&amp;f={$data['forum_id']}&amp;t={$data['topic_id']}");
    }
    $_CLASS['core_display']->meta_refresh(3, $url);
    $message = $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? $mode == 'edit' ? 'POST_EDITED_MOD' : 'POST_STORED_MOD' : ($mode == 'edit' ? 'POST_EDITED' : 'POST_STORED');
    $message = $_CLASS['core_user']->lang[$message] . (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? '<br /><br />' . sprintf($_CLASS['core_user']->lang['VIEW_MESSAGE'], '<a href="' . $url . '">', '</a>') : '') . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_FORUM'], '<a href="' . generate_link('Forums&amp;file=viewforum&amp;f=' . $data['forum_id']) . '">', '</a>');
    trigger_error($message);
}