Location: PHPKode > projects > XennoBB > xennobb/admin/cleaning.php
<?php
/*

  Copyright (C) 2005-2011 UserDot
  Visit XennoBB at www.userdot.net/projects/xennobb
  Originally based on PunBB www.punbb.org

  XennoBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  XennoBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA 02110-1301 USA

 */
define('IN_FORUM_ADMIN', 1);
define('DISABLE_BUFFERING', 1);
require dirname(__FILE__) . '/../include/init.php';
if ($forum_user['g_id'] > USER_ADMIN)
    BB_Functions::Message($lang['No permission'], true, 1);
$page = isset($_GET['Page']) ? BB_Input::Htmlspecialchars($_GET['Page']) : null;
$submenu = array($lang['Rebuild index'] => 'cleaning.php?Page=RebuildIndex', $lang['Prune'] => 'cleaning.php?Page=Prune', $lang['Spam clean'] => 'cleaning.php?Page=SpamClean', $lang['Syncronize'] => 'cleaning.php?Page=Syncronize', $lang['Orphans'] => 'cleaning.php?Page=CleanOrphans');
if (isset($_POST['cleanup']))
{
    @set_time_limit(0);
    $ip = "'" . implode("','", array_values(explode(' ', $_POST['ip_addys']))) . "'";
    $db->query('DELETE FROM ' . $db->prefix . 'posts WHERE poster_ip IN(' . $ip . ')') or BB_Functions::Error('Could not delete posts', __FILE__, __LINE__, $db->error());
    $db->query('DELETE FROM ' . $db->prefix . 'users WHERE registration_ip IN(' . $ip . ')') or BB_Functions::Error('Could not delete users', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'forum_posts SELECT t.forum_id, count(*) as posts FROM ' . $db->prefix . 'posts as p LEFT JOIN ' . $db->prefix . 'topics as t on p.topic_id=t.id GROUP BY t.forum_id') or BB_Functions::Error('Creating posts table failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'forums, ' . $db->prefix . 'forum_posts SET num_posts=posts WHERE id=forum_id') or BB_Functions::Error('Could not update post counts', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'forum_topics SELECT forum_id, count(*) as topics FROM ' . $db->prefix . 'topics GROUP BY forum_id') or BB_Functions::Error('Creating topics table failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'forums, ' . $db->prefix . 'forum_topics SET num_topics=topics WHERE id=forum_id') or BB_Functions::Error('Could not update topic counts', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'topic_posts SELECT topic_id, count(*)-1 as replies FROM ' . $db->prefix . 'posts GROUP BY topic_id') or BB_Functions::Error('Creating topics table failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'topics, ' . $db->prefix . 'topic_posts SET num_replies=replies WHERE id=topic_id') or BB_Functions::Error('Could not update topic counts', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'forum_last SELECT p.posted AS n_last_post, p.id AS n_last_post_id, p.poster AS n_last_poster, t.forum_id FROM ' . $db->prefix . 'posts AS p LEFT JOIN ' . $db->prefix . 'topics AS t ON p.topic_id=t.id ORDER BY p.posted DESC') or BB_Functions::Error('Creating last posts table failed', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'forum_lastb SELECT * FROM ' . $db->prefix . 'forum_last WHERE forum_id > 0 GROUP BY forum_id') or BB_Functions::Error('Creating last posts tableb failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'forums, ' . $db->prefix . 'forum_lastb SET last_post_id=n_last_post_id, last_post=n_last_post, last_poster=n_last_poster WHERE id=forum_id') or BB_Functions::Error('Could not update last post', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'topic_last SELECT posted AS n_last_post, id AS n_last_post_id, poster AS n_last_poster, topic_id FROM ' . $db->prefix . 'posts ORDER BY posted DESC') or BB_Functions::Error('Creating last posts table failed', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'topic_lastb SELECT * FROM ' . $db->prefix . 'topic_last WHERE topic_id > 0 GROUP BY topic_id') or BB_Functions::Error('Creating last posts tableb failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'topics, ' . $db->prefix . 'topic_lastb SET last_post_id=n_last_post_id, last_post=n_last_post, last_poster=n_last_poster WHERE id=topic_id') or BB_Functions::Error('Could not update last post', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'orph_topic SELECT t.id as o_id FROM ' . $db->prefix . 'topics AS t LEFT JOIN ' . $db->prefix . 'posts AS p ON p.topic_id = t.id WHERE p.id IS NULL') or BB_Functions::Error('Creating orphaned topics table failed', __FILE__, __LINE__, $db->error());
    $db->query('DELETE ' . $db->prefix . 'topics FROM ' . $db->prefix . 'topics, ' . $db->prefix . 'orph_topic WHERE o_id=id') or xBB_Eerror('Could not delete topics', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'orph_posts SELECT p.id as o_id FROM ' . $db->prefix . 'posts p LEFT JOIN ' . $db->prefix . 'topics t ON p.topic_id=t.id WHERE t.id IS NULL') or BB_Functions::Error('Creating orphaned posts table failed', __FILE__, __LINE__, $db->error());
    $db->query('DELETE ' . $db->prefix . 'posts FROM ' . $db->prefix . 'posts, ' . $db->prefix . 'orph_posts WHERE o_id=id') or BB_Functions::Error('Could not delete posts', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'orph_topics SELECT t.id as o_id FROM ' . $db->prefix . 'topics as t LEFT JOIN ' . $db->prefix . 'forums as f ON t.forum_id=f.id WHERE f.id is NULL') or BB_Functions::Error('Creating orphaned topics table failed', __FILE__, __LINE__, $db->error());
    $db->query('DELETE ' . $db->prefix . 'topics FROM ' . $db->prefix . 'topics, ' . $db->prefix . 'orph_topics WHERE o_id=id') or BB_Functions::Error('Could not delete topics', __FILE__, __LINE__, $db->error());
    BB_Admin_Functions::Log_Action('Forums cleaned', 3);
    BB_Functions::Redirect('cleaning.php?Page=SpamClean', $lang['Forums cleansed']);
}
if (isset($_POST['forum_sync']))
{
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'forum_posts SELECT t.forum_id, count(*) as posts FROM ' . $db->prefix . 'posts as p LEFT JOIN ' . $db->prefix . 'topics as t on p.topic_id=t.id GROUP BY t.forum_id') or BB_Functions::Error('Creating posts table failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'forums, ' . $db->prefix . 'forum_posts SET num_posts=posts WHERE id=forum_id') or BB_Functions::Error('Could not update post counts', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'forum_topics SELECT forum_id, count(*) as topics FROM ' . $db->prefix . 'topics GROUP BY forum_id') or BB_Functions::Error('Creating topics table failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'forums, ' . $db->prefix . 'forum_topics SET num_topics=topics WHERE id=forum_id') or BB_Functions::Error('Could not update topic counts', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'topic_posts SELECT topic_id, count(*)-1 as replies FROM ' . $db->prefix . 'posts GROUP BY topic_id') or BB_Functions::Error('Creating topics table failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'topics, ' . $db->prefix . 'topic_posts SET num_replies=replies WHERE id=topic_id') or BB_Functions::Error('Could not update topic counts', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'user_posts SELECT poster_id, count(*)as posts FROM ' . $db->prefix . 'posts GROUP BY poster_id') or BB_Functions::Error('Creating posts table failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'users, ' . $db->prefix . 'user_posts SET num_posts=posts WHERE id=poster_id') or BB_Functions::Error('Could not update post counts', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'forum_last SELECT p.posted AS n_last_post, p.id AS n_last_post_id, p.poster AS n_last_poster, t.forum_id FROM ' . $db->prefix . 'posts AS p LEFT JOIN ' . $db->prefix . 'topics AS t ON p.topic_id=t.id ORDER BY p.posted DESC') or BB_Functions::Error('Creating last posts table failed', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'forum_lastb SELECT * FROM ' . $db->prefix . 'forum_last WHERE forum_id > 0 GROUP BY forum_id') or BB_Functions::Error('Creating last posts tableb failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'forums, ' . $db->prefix . 'forum_lastb SET last_post_id=n_last_post_id, last_post=n_last_post, last_poster=n_last_poster WHERE id=forum_id') or BB_Functions::Error('Could not update last post', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'topic_last SELECT posted AS n_last_post, id AS n_last_post_id, poster AS n_last_poster, topic_id FROM ' . $db->prefix . 'posts ORDER BY posted DESC') or BB_Functions::Error('Creating last posts table failed', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'topic_lastb SELECT * FROM ' . $db->prefix . 'topic_last WHERE topic_id > 0 GROUP BY topic_id') or BB_Functions::Error('Creating last posts tableb failed', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE ' . $db->prefix . 'topics, ' . $db->prefix . 'topic_lastb SET last_post_id=n_last_post_id, last_post=n_last_post, last_poster=n_last_poster WHERE id=topic_id') or BB_Functions::Error('Could not update last post', __FILE__, __LINE__, $db->error());
    BB_Admin_Functions::Log_Action('Forums syncronized', 3);
    BB_Functions::Redirect('cleaning.php?Page=Syncronize', $lang['Forums syncronized']);
}
elseif (isset($_POST['delete_orphans']))
{
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'orph_topic SELECT t.id as o_id FROM ' . $db->prefix . 'topics AS t LEFT JOIN ' . $db->prefix . 'posts AS p ON p.topic_id = t.id WHERE p.id IS NULL') or BB_Functions::Error('Creating orphaned topics table failed', __FILE__, __LINE__, $db->error());
    $db->query('DELETE ' . $db->prefix . 'topics FROM ' . $db->prefix . 'topics, ' . $db->prefix . 'orph_topic WHERE o_id=id') or BB_Functions::Error('Could not delete topics', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'orph_posts SELECT p.id as o_id FROM ' . $db->prefix . 'posts p LEFT JOIN ' . $db->prefix . 'topics t ON p.topic_id=t.id WHERE t.id IS NULL') or BB_Functions::Error('Creating orphaned posts table failed', __FILE__, __LINE__, $db->error());
    $db->query('DELETE ' . $db->prefix . 'posts FROM ' . $db->prefix . 'posts, ' . $db->prefix . 'orph_posts WHERE o_id=id') or BB_Functions::Error('Could not delete posts', __FILE__, __LINE__, $db->error());
    $db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $db->prefix . 'orph_topics SELECT t.id as o_id FROM ' . $db->prefix . 'topics as t LEFT JOIN ' . $db->prefix . 'forums as f ON t.forum_id=f.id WHERE f.id is NULL') or BB_Functions::Error('Creating orphaned topics table failed', __FILE__, __LINE__, $db->error());
    $db->query('DELETE ' . $db->prefix . 'topics FROM ' . $db->prefix . 'topics, ' . $db->prefix . 'orph_topics WHERE o_id=id') or BB_Functions::Error('Could not delete topics', __FILE__, __LINE__, $db->error());
    BB_Admin_Functions::Log_Action('Orphans deleted', 3);
    BB_Functions::Redirect('cleaning.php?Page=CleanOrphans', $lang['Orphans deleted']);
}
if (isset($_GET['action']) || isset($_POST['prune']) || isset($_POST['prune_comply']))
{
    if (isset($_POST['prune_comply']))
    {
        BB_Input::Confirm_Referrer('cleaning.php');
        $prune_from = $_POST['prune_from'];
        $prune_days = intval($_POST['prune_days']);
        $prune_date = ($prune_days) ? time() - ($prune_days * 86400) : -1;
        @set_time_limit(0);
        if ($prune_from == 'all')
        {
            $result = $db->query('SELECT id FROM ' . $db->prefix . 'forums') or BB_Functions::Error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
            $num_forums = $db->num_rows($result);
            for ($i = 0; $i < $num_forums; ++$i)
            {
                $fid = $db->result($result, $i);
                BB_Admin_Functions::Prune($fid, $_POST['prune_sticky'], $prune_date);
                BB_Core::Update_Forum($fid);
            }
        }
        else
        {
            $prune_from = intval($prune_from);
            BB_Admin_Functions::Prune($prune_from, $_POST['prune_sticky'], $prune_date);
            BB_Core::Update_Forum($prune_from);
        }
        $result = $db->query('SELECT t1.id FROM ' . $db->prefix . 'topics AS t1 LEFT JOIN ' . $db->prefix . 'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or BB_Functions::Error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
        $num_orphans = $db->num_rows($result);
        if ($num_orphans)
        {
            for ($i = 0; $i < $num_orphans; ++$i)
                $orphans[] = $db->result($result, $i);
            $db->query('DELETE FROM ' . $db->prefix . 'topics WHERE id IN(' . implode(',', $orphans) . ')') or BB_Functions::Error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
        }
        BB_Admin_Functions::Log_Action('Forums pruned', 3);
        BB_Functions::Redirect('cleaning.php?Page=Prune', $lang['redirect_posts_pruned']);
    }
    $prune_days = $_POST['req_prune_days'];
    if (!preg_match('#^\d+$#', $prune_days))
        BB_Functions::Message($lang['days_to_prune']);
    $prune_date = time() - ($prune_days * 86400);
    $prune_from = $_POST['prune_from'];
    $sql = 'SELECT COUNT(id) FROM ' . $db->prefix . 'topics WHERE last_post<' . $db->escape($prune_date) . ' AND moved_to IS NULL';
    if ($_POST['prune_sticky'] == '0')
        $sql .= ' AND sticky=\'0\'';
    if ($prune_from != 'all')
    {
        $prune_from = intval($prune_from);
        $sql .= ' AND forum_id=' . $db->escape($prune_from);
        $result = $db->query('SELECT forum_name FROM ' . $db->prefix . 'forums WHERE id=' . $db->escape($prune_from)) or BB_Functions::Error('Unable to fetch forum name', __FILE__, __LINE__, $db->error());
        $forum = '"' . BB_Input::Htmlspecialchars($db->result($result)) . '"';
    }
    else
        $forum = 'all forums';
    $result = $db->query($sql) or BB_Functions::Error('Unable to fetch topic prune count', __FILE__, __LINE__, $db->error());
    $num_topics = $db->result($result);
    if (!$num_topics)
        BB_Functions::Message('There are no topics that are ' . $prune_days . ' days old. Please decrease the value of "Days old" and try again.');
    $page_title = BB_Input::Htmlspecialchars(bb_board_title) . $lang['Admin'] . $lang['Prune'];
    require FORUM_ROOT . 'admin/header.php';
    ?>
    <div class="blockform">
        <h2><span><?php echo $lang['Prune']; ?></span></h2>
        <div class="box">
            <form method="post" action="cleaning.php">
                <div class="inform">
                    <input type="hidden" name="prune_days" value="<?php echo $prune_days ?>" />
                    <input type="hidden" name="prune_sticky" value="<?php echo $_POST['prune_sticky'] ?>" />
                    <input type="hidden" name="prune_from" value="<?php echo $prune_from ?>" />
                    <fieldset>
                        <legend>Confirm prune posts</legend>
                        <div class="infldset">
                            <p>Are you sure that you want to prune all topics older than <?php echo $prune_days ?> days from <?php echo $forum ?>? (<?php echo $num_topics ?> topics)</p>
                            <p>WARNING! Pruning posts deletes them permanently.</p>
                        </div>
                    </fieldset>
                </div>
                <p class="submitend" style="text-align:left;"><input type="button" class="b1" onclick="javascript:history.go(-1)" value="<?php echo $lang['Go back'] ?>"><input class="b1" type="submit" name="prune_comply" value="<?php echo $lang['Prune']; ?>" /></p>
            </form>
        </div>
    </div>
    <?php
    require FORUM_ROOT . 'admin/footer.php';
}
if (isset($_GET['i_per_page']) && isset($_GET['i_start_at']))
{
    $per_page = intval($_GET['i_per_page']);
    $start_at = intval($_GET['i_start_at']);
    if ($per_page < 1 || $start_at < 1)
        BB_Functions::Message($lang['Bad request']);
    @set_time_limit(0);
    if (isset($_GET['i_empty_index']))
    {
        BB_Input::Confirm_Referrer('cleaning.php');
        $truncate_sql = ($db_type != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ';
        $db->query($truncate_sql . $db->prefix . 'search_matches') or BB_Functions::Error('Unable to empty search index match table', __FILE__, __LINE__, $db->error());
        $db->query($truncate_sql . $db->prefix . 'search_words') or BB_Functions::Error('Unable to empty search index words table', __FILE__, __LINE__, $db->error());
        switch ($db_type)
        {
            case 'mysql':
            case 'mysqli':
                $result = $db->query('ALTER TABLE ' . $db->prefix . 'search_words auto_increment=1') or BB_Functions::Error('Unable to update table auto_increment', __FILE__, __LINE__, $db->error());
                break;
            case 'pgsql';
                $result = $db->query('SELECT setval(\'search_words_id_seq\', 1, false)') or BB_Functions::Error('Unable to update sequence', __FILE__, __LINE__, $db->error());
        }
    }
    $end_at = $start_at + $per_page;
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
            <title><?php echo BB_Input::Htmlspecialchars(bb_board_title) ?></title>
            <style type="text/css">
                body {
                    font: 10px Verdana, Arial, Helvetica, sans-serif;
                    color: #333333;
                    background-color: #FFFFFF
                }
            </style>
        </head>
        <body>
            <?php echo $lang['rebuild_index'] ?><br /><br />
            <?php
            $result = $db->query('SELECT DISTINCT t.id, p.id, p.message FROM ' . $db->prefix . 'topics AS t INNER JOIN ' . $db->prefix . 'posts AS p ON t.id=p.topic_id WHERE t.id>=' . $db->escape($start_at) . ' AND t.id<' . $db->escape($end_at) . ' ORDER BY t.id') or BB_Functions::Error('Unable to fetch topic/post info', __FILE__, __LINE__, $db->error());
            $cur_topic = 0;
            while ($cur_post = $db->fetch_row($result))
            {
                if ($cur_post[0] <> $cur_topic)
                {
                    $result2 = $db->query('SELECT p.id, t.subject, MIN(p.posted) AS first FROM ' . $db->prefix . 'posts AS p INNER JOIN ' . $db->prefix . 'topics AS t ON t.id=p.topic_id WHERE t.id=' . $db->escape($cur_post[0]) . ' GROUP BY p.id, t.subject ORDER BY first LIMIT 1') or BB_Functions::Error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
                    list($first_post, $subject) = $db->fetch_row($result2);
                    $cur_topic = $cur_post[0];
                }
                echo 'Processing post <strong>' . $cur_post[1] . '</strong> in topic <strong>' . $cur_post[0] . '</strong><br />' . "\n";
                if ($cur_post[1] == $first_post)
                    BB_Core::Set_Search_Index('post', $cur_post[1], $cur_post[2], $subject);
                else
                    BB_Core::Set_Search_Index('post', $cur_post[1], $cur_post[2]);
            }
            $result = $db->query('SELECT id FROM ' . $db->prefix . 'topics WHERE id>' . $db->escape($end_at)) or BB_Functions::Error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
            $query_str = ($db->num_rows($result)) ? '&i_per_page=' . $per_page . '&i_start_at=' . $end_at : '';
            $db->end_transaction();
            $db->close();
            exit('<script type="text/javascript">window.location="cleaning.php?Page=RebuildIndex' . $query_str . '"</script><br />JavaScript redirect unsuccessful. Click <a href="cleaning.php' . $query_str . '">here</a> to continue.');
        }
        $result = $db->query('SELECT id FROM ' . $db->prefix . 'topics ORDER BY id LIMIT 1') or BB_Functions::Error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
        if ($db->num_rows($result))
            $first_id = $db->result($result);
        $page_title = BB_Input::Htmlspecialchars($lang['Admin'] . $lang['Cleaning']);
        $required_fields = array('req_prune_days' => 'Days old');
        $focus_element = array('prune', 'req_prune_days');
        require FORUM_ROOT . 'admin/header.php';
        if ($page == 'RebuildIndex')
        {
            echo BB_Template::Generate_Menu($submenu);
            ?>
            <div class="blockform">
                <form method="get" action="cleaning.php">
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p><?php echo $lang['help_rebuild_index']; ?></p>
                        </div>
                    </div>
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p></p>
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th class="header"><?php echo $lang['Topics per cycle']; ?></th>
                                    <td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_47']) ?></td>
                                    <td><input type="text" class="textbox" name="i_per_page" size="7" maxlength="7" value="100" tabindex="1" /></td>
                                </tr>
                                <tr>
                                    <th class="header"><?php echo $lang['Starting Topic ID']; ?></th>
                                    <td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_45']) ?></td>
                                    <td><input type="text" class="textbox" name="i_start_at" size="7" maxlength="7" value="<?php echo (isset($first_id)) ? $first_id : 0 ?>" tabindex="2" /></td>
                                </tr>
                                <tr>
                                    <th class="header"><?php echo $lang['Empty index']; ?></th>
                                    <td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_46']) ?></td>
                                    <td class="inputadmin"><span><input type="checkbox" name="i_empty_index" value="1" tabindex="3" checked="checked" /></span></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div><input type="submit" class="b1" name="rebuild_index" value="<?php echo $lang['Go']; ?>" tabindex="4" /></div>
                </form>
            </div>
    <?php
}
else if ($page == 'Prune')
{
    echo BB_Template::Generate_Menu($submenu);
    ?>
            <div class="blockform">
                <form id="prune" method="post" action="cleaning.php" onSubmit="return process_form(this)">
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p><?php echo $lang['help_prune_posts'] ?></p>
                        </div>
                    </div>
                    <div class="inform">
                        <input type="hidden" name="form_sent" value="1" />
                        <div class="infldset file" style="padding:10px">
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th class="header"><?php echo $lang['Days old'] ?></th>
                                    <td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_51']) ?></td>
                                    <td><input type="text" class="textbox" name="req_prune_days" size="3" maxlength="3" tabindex="1" /></td>
                                </tr>
                                <tr>
                                    <th class="header"><?php echo $lang['Prune sticky topics'] ?></th>
                                    <td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_50']) ?></td>
                                    <td><input type="radio" name="prune_sticky" value="1" tabindex="2" checked="checked" />&nbsp;<?php echo $lang['Yes'] ?>&nbsp;&nbsp;&nbsp;<input type="radio" name="prune_sticky" value="0" />&nbsp;<?php echo $lang['No'] ?></td>
                                </tr>
                                <tr>
                                    <th class="header"><?php echo $lang['Prune from forum'] ?></th>
                                    <td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_49']) ?></td>
                                    <td>
                                        <select name="prune_from" tabindex="3">
                                            <option value="all"><?php echo $lang['All forums'] ?></option>
                                            <?php
                                            $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM ' . $db->prefix . 'categories AS c INNER JOIN ' . $db->prefix . 'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or BB_Functions::Error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
                                            $cur_category = 0;
                                            while ($forum = $db->fetch_assoc($result))
                                            {
                                                if ($forum['cid'] != $cur_category)
                                                {
                                                    if ($cur_category)
                                                        echo "\t\t\t\t\t\t\t\t\t\t\t" . '</optgroup>' . "\n";
                                                    echo "\t\t\t\t\t\t\t\t\t\t\t" . '<optgroup label="' . BB_Input::Htmlspecialchars($forum['cat_name']) . '">' . "\n";
                                                    $cur_category = $forum['cid'];
                                                }
                                                echo "\t\t\t\t\t\t\t\t\t\t\t\t" . '<option value="' . $forum['fid'] . '">' . BB_Input::Htmlspecialchars($forum['forum_name']) . '</option>' . "\n";
                                            }
                                            ?>
                                            </optgroup>
                                        </select>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div><input type="submit" class="b1" name="prune" value="<?php echo $lang['Go']; ?>" tabindex="5" /></div>
                </form>
            </div>
    <?php
}
else if ($page == 'SpamClean')
{
    echo BB_Template::Generate_Menu($submenu);
    ?>
            <div class="blockform">
                <form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p><?php echo $lang['help_spam_clean'] ?></p>
                        </div>
                    </div>
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th class="header"><?php echo $lang['IP Addresses'] ?></th>
                                    <td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_48']) ?></td>
                                    <td><input type="text" class="textbox" name="ip_addys" size="30" maxlength="255" /></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div><input type="submit" class="b1" name="cleanup" value="<?php echo $lang['Go']; ?>" tabindex="4" /></div>
                </form>
            </div>
    <?php
}
else if ($page == 'Syncronize')
{
    echo BB_Template::Generate_Menu($submenu);
    ?>
            <div class="blockform">
                <form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p><?php echo $lang['help_syncronize_forum'] ?></p>
                        </div>
                    </div>
                    <div><input type="submit" class="b1" name="forum_sync" value="<?php echo $lang['Go']; ?>" tabindex="4" /></div>
                </form>
            </div>
    <?php
}
else if ($page == 'CleanOrphans')
{
    echo BB_Template::Generate_Menu($submenu);
    ?>
            <div class="blockform">
                <form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                    <div class="inform">
                        <div class="infldset file" style="padding:10px">
                            <p><?php echo $lang['help_clean_orphans'] ?></p>
                        </div>
                    </div>
                    <div><input type="submit" class="b1" name="delete_orphans" value="<?php echo $lang['Go']; ?>" tabindex="4" /></div>
                </form>
            </div>
    <?php
}
else
    BB_Functions::Message($lang['Bad request']);
require FORUM_ROOT . 'admin/footer.php';
?>
Return current item: XennoBB