Location: PHPKode > projects > XennoBB > xennobb/admin/maintenance.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['Regenerate cache'] => 'maintenance.php?Page=RegenerateCache', $lang['Change version'] => 'maintenance.php?Page=ChangeVersion', $lang['Broadcast'] => 'maintenance.php?Page=Broadcast');
if (isset($_POST['regen_cache']))
{
    BB_Cache::Generate_Bans();
    BB_Cache::Generate_Smiley();
    BB_Cache::Generate_Advertising_Config();
    BB_Admin_Functions::Log_Action('Forum cache regenerated', 1);
    BB_Functions::Redirect('maintenance.php?Page=RegenerateCache', $lang['redirect_cache_regenerated']);
}
else if (isset($_POST['update_version']))
{
    if (trim($_POST['to_version']) == '')
        BB_Functions::Message($lang['enter_version_nr']);

    $cms_settings->Set_Namespace('xennobb');
    $res = true;
    $res &= $cms_settings->Save('bb_cur_version', trim($_POST['to_version']));
    if ($res)
        BB_Admin_Functions::Log_Action('Change XennoBB configuration', 2);
    $cms_settings->Set_Namespace('');
    BB_Functions::Redirect('maintenance.php?Page=ChangeVersion', $lang['redirect_version_changed']);
}
else if (isset($_POST['broadcast']))
{
    $gid = intval($_POST['gid']);
    if ($gid == 0)
    {
        $result = $db->query("SELECT username, email FROM " . $db->prefix . "users WHERE username != 'Guest' ORDER BY username") or BB_Functions::Error($lang['error_154'], __FILE__, __LINE__, $db->error());
        while ($row = $db->fetch_assoc($result))
            $addresses[$row['username']] = $row['email'];
        $usercount = count($addresses);
    }
    else
    {
        $result = $db->query("SELECT username, email FROM " . $db->prefix . "users WHERE username != 'Guest' AND gid=" . $gid . " ORDER BY username") or BB_Functions::Error($lang['error_154'], __FILE__, __LINE__, $db->error());
        while ($row = $db->fetch_assoc($result))
            $addresses[$row['username']] = $row['email'];
        $usercount = count($addresses);
    }
    if ($usercount > 0)
    {
        foreach ($addresses as $recipientname => $recipientemail)
        {
            $mail_to = $recipientname . " <" . $recipientemail . ">";
            $mail_subject = BB_Input::Htmlspecialchars($_POST['message_subject']);
            $mail_message = BB_Input::Htmlspecialchars($_POST['message_body']);
            BB_Email::Mail($mail_to, $mail_subject, $mail_message);
        }
        BB_Admin_Functions::Log_Action('Message broadcasted to all users', 3);
        BB_Functions::Redirect('maintenance.php?Page=Broadcast', $lang['broadcast_email_sent']);
    }
    else
        BB_Functions::Message($lang['no_users_in_group']);
}
$page_title = BB_Input::Htmlspecialchars($lang['Admin'] . $lang['Maintenance']);
require FORUM_ROOT . 'admin/header.php';
if ($page == 'RegenerateCache')
{
    echo BB_Template::Generate_Menu($submenu);
    ?>
    <div class="blockform">
        <form id="regenerate" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
            <div class="inform">
                <div class="infldset file" style="padding:10px">
                    <p><?php echo $lang['help_regen_cache'] ?></p>
                </div>
            </div>
            <div><input type="submit" class="b1" name="regen_cache" value="<?php echo $lang['Regenerate cache'] ?>" tabindex="2" /></div>
        </form>
    </div>
    <?php
}
else if ($page == 'ChangeVersion')
{
    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_change_version'] ?></p>
                </div>
            </div>
            <div class="inform">
                <div class="infldset file" style="padding:10px">
                    <table class="aligntop" cellspacing="0">
                        <tr>
                            <th style="width:150px"><?php echo $lang['New version'] ?></th>
                            <td><input type="text" class="textbox" name="to_version" size="10" tabindex="1" value="<?php echo bb_cur_version ?>" /></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div><input type="submit" class="b1" name="update_version" value="<?php echo $lang['Update'] ?>" tabindex="2" /></div>
        </form>
    </div>
    <?php
}
else if ($page == 'Broadcast')
{
    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_broadcast'] ?></p>
                </div>
            </div>
            <div class="inform">
                <div class="infldset file" style="padding:10px">
                    <table class="aligntop" cellspacing="0">
                        <tr>
                            <th style="width:150px" scope="row"><?php echo $lang['User group'] ?></th>
                            <td><select id="gid" name="gid"><option value="0"><?php echo $lang['All users'] ?></option>
                                    <?php
                                    $result = $db->query('SELECT g_id, g_title FROM ' . $db->prefix . 'usergroups WHERE g_id!=' . USER_GUEST . ' ORDER BY g_title') or BB_Functions::Error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
                                    while ($cur_group = $db->fetch_assoc($result))
                                    {
                                        if ($cur_group['g_id'] == $user['g_id'] || ($cur_group['g_id'] == bb_default_user_group && $user['g_id'] == ''))
                                            echo "\t\t\t\t\t\t\t\t" . '<option value="' . $cur_group['g_id'] . '" selected="selected">' . BB_Input::Htmlspecialchars($cur_group['g_title']) . '</option>' . "\n";
                                        else
                                            echo "\t\t\t\t\t\t\t\t" . '<option value="' . $cur_group['g_id'] . '">' . BB_Input::Htmlspecialchars($cur_group['g_title']) . '</option>' . "\n";
                                    }
                                    ?>
                                </select></td>
                        </tr>
                        <tr>
                            <th style="width:150px" scope="row"><?php echo $lang['Subject'] ?></th>
                            <td><input type="text" class="textbox" name="message_subject" style="width:350px" tabindex="1" /></td>
                        </tr>
                        <tr>
                            <th scope="row"><?php echo $lang['Message body'] ?></th>
                            <td><textarea name="message_body" rows="14" style="width:350px" tabindex="2"></textarea></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div><input type="submit" class="b1" name="broadcast" value="<?php echo $lang['Send'] ?>" tabindex="3" /></div>
        </form>
    </div>
    <?php
}
else
    BB_Functions::Message($lang['Bad request']);
require FORUM_ROOT . 'admin/footer.php';
?>
Return current item: XennoBB