Location: PHPKode > projects > XennoBB > xennobb/admin/ranks.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);
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['Configure'] => 'ranks.php?Page=Configure', $lang['Add'] => 'ranks.php?Page=Add', $lang['Edit'] => 'ranks.php?Page=Edit');
if (isset($_POST['form_sent']))
{
    if (!isset($_SERVER['HTTP_REFERER']) || !preg_match('#/ranks\.php#i', $_SERVER['HTTP_REFERER']))
        BB_Functions::Message($lang['Bad referrer']);
    $form = array_map('trim', $_POST['form']);
    $cms_settings->Set_Namespace('xennobb');
    $res = true;
    while (list($key, $input) = @each($form))
    {
        $key = 'bb_' . $key;
        if ($input != '' || is_int($input))
            $value = $input;
        else
            $value = 'NULL';
        $res &= $cms_settings->Save($key, $value);
        if ($res)
            BB_Admin_Functions::Log_Action('Change XennoBB configuration', 2);
    }
    $cms_settings->Set_Namespace('');
    BB_Functions::Redirect('ranks.php?Page=Configure', $lang['ranks_activated']);
}
if (isset($_POST['add_rank']))
{
    BB_Input::Confirm_Referrer('ranks.php');
    $rank = trim($_POST['new_rank']);
    $min_posts = $_POST['new_min_posts'];
    if ($rank == '')
        BB_Functions::Message($lang['rank_no_title']);
    if (!preg_match('#^\d+$#', $min_posts))
        BB_Functions::Message($lang['rank_min_integer']);
    $result = $db->query('SELECT 1 FROM ' . $db->prefix . 'ranks WHERE min_posts=' . $db->escape($min_posts)) or BB_Functions::Error($lang['error_18'], __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result))
        BB_Functions::Message($lang['rank_exists'] . $min_posts . '.');
    $db->query('INSERT INTO ' . $db->prefix . 'ranks (rank, min_posts) VALUES(\'' . $db->escape($rank) . '\', ' . $db->escape($min_posts) . ')') or BB_Functions::Error($lang['error_19'], __FILE__, __LINE__, $db->error());
    BB_Cache::Generate_Ranks();
    BB_Admin_Functions::Log_Action('New rank added', 0);
    BB_Functions::Redirect('ranks.php?Page=Add', $lang['redirect_rank_added']);
}
else if (isset($_POST['update']))
{
    BB_Input::Confirm_Referrer('ranks.php');
    $id = intval(key($_POST['update']));
    $rank = trim($_POST['rank'][$id]);
    $min_posts = trim($_POST['min_posts'][$id]);
    if ($rank == '')
        BB_Functions::Message($lang['rank_no_title']);
    if (!preg_match('#^\d+$#', $min_posts))
        BB_Functions::Message($lang['rank_min_integer']);
    $result = $db->query('SELECT 1 FROM ' . $db->prefix . 'ranks WHERE id!=' . $db->escape($id) . ' && min_posts=' . $db->escape($min_posts)) or BB_Functions::Error($lang['error_18'], __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result))
        BB_Functions::Message($lang['rank_exists'] . $min_posts . '.');
    $db->query('UPDATE ' . $db->prefix . 'ranks SET rank=\'' . $db->escape($rank) . '\', min_posts=' . $db->escape($min_posts) . ' WHERE id=' . $db->escape($id)) or BB_Functions::Error($lang['error_20'], __FILE__, __LINE__, $db->error());
    BB_Cache::Generate_Ranks();
    BB_Functions::Redirect('ranks.php?Page=Edit', $lang['redirect_rank_updated']);
}
else if (isset($_POST['remove']))
{
    BB_Input::Confirm_Referrer('ranks.php');
    $id = intval(key($_POST['remove']));
    $db->query('DELETE FROM ' . $db->prefix . 'ranks WHERE id=' . $db->escape($id)) or BB_Functions::Error($lang['error_21'], __FILE__, __LINE__, $db->error());
    BB_Cache::Generate_Ranks();
    BB_Admin_Functions::Log_Action('Rank removed', 1);
    BB_Functions::Redirect('ranks.php?Page=Edit', $lang['redirect_rank_removed']);
}
$page_title = BB_Input::Htmlspecialchars($lang['Admin'] . $lang['Ranks']);
require FORUM_ROOT . 'admin/header.php';
if ($page == 'Configure')
{
    echo BB_Template::Generate_Menu($submenu);
    ?>
    <div class="blockform">
        <form id="ranks" method="post" action="ranks.php">
            <input type="hidden" name="form_sent" value="1" />
            <div class="inform">
                <div class="infldset file" style="padding:10px">
                    <table class="aligntop" cellspacing="0">
                        <tr>
                            <th class="header"><?php echo $lang['Activate user ranks'] ?></th>
                            <td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_6']) ?></td>
                            <td><input type="radio" class="radio_yes" name="form[ranks]" value="1"<?php if (bb_ranks == '1')
        echo ' checked="checked"' ?> />&nbsp;<?php echo $lang['Yes'] ?>&nbsp;&nbsp;&nbsp;<input type="radio" class="radio_no" name="form[ranks]" value="0"<?php if (bb_ranks == '0')
        echo ' checked="checked"' ?> />&nbsp;<?php echo $lang['No'] ?></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div><input type="submit" class="b1" name="save" value="<?php echo $lang['Save'] ?>" tabindex="2" /></div>
        </form>
    </div>
    <?php
}
else if ($page == 'Add')
{
    echo BB_Template::Generate_Menu($submenu);
    $focus_element = array('ranks', 'new_rank');
    ?>
    <div class="blockform">
        <form id="ranks" method="post" action="ranks.php">
            <div class="inform">
                <div class="infldset file" style="padding:0px">
                    <table>
                        <thead>
                            <tr>
                                <th class="tcl"><?php echo $lang['Rank title']; ?></th>
                                <th class="tc2"><?php echo $lang['Minimum posts']; ?></th>
                                <th class="hidehead">&nbsp;</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><input type="text" class="textbox" name="new_rank" size="24" maxlength="50" tabindex="1" /></td>
                                <td><input type="text" class="textbox" name="new_min_posts" size="7" maxlength="7" tabindex="2" /></td>
                                <td><input type="submit" name="add_rank" class="b1" value="<?php echo $lang['Add'] ?>" tabindex="3" /></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </form>
    </div>
                    <?php
                }
                else if ($page == 'Edit')
                {
                    echo BB_Template::Generate_Menu($submenu);
                    ?>
    <div class="blockform">
        <form id="ranks" method="post" action="ranks.php">
            <div class="inform">
                <div class="infldset file" style="padding:0px">
                            <?php
                            $result = $db->query('SELECT id, rank, min_posts FROM ' . $db->prefix . 'ranks ORDER BY min_posts') or BB_Functions::Error($lang['error_22'], __FILE__, __LINE__, $db->error());
                            if ($db->num_rows($result))
                            {
                                ?>
                        <table>
                            <thead>
                                <tr>
                                    <th class="tcl"><?php echo $lang['Rank title']; ?></th>
                                    <th class="tc2"><?php echo $lang['Minimum posts']; ?></th>
                                    <th class="hidehead">&nbsp;</th>
                                </tr>
                            </thead>
                            <tbody>
        <?php
        while ($cur_rank = $db->fetch_assoc($result))
            echo "\t\t\t\t\t\t\t\t" . '<tr><td><input type="text" class="textbox" name="rank[' . $cur_rank['id'] . ']" value="' . BB_Input::Htmlspecialchars($cur_rank['rank']) . '" size="24" maxlength="50" /></td><td><input type="text" class="textbox" name="min_posts[' . $cur_rank['id'] . ']" value="' . $cur_rank['min_posts'] . '" size="7" maxlength="7" /></td><td><input type="submit" class="b1" name="update[' . $cur_rank['id'] . ']" value="' . $lang['Update'] . '" />&nbsp;<input type="submit" class="b1" name="remove[' . $cur_rank['id'] . ']" value="' . $lang['Remove'] . '" /></td></tr>' . "\n";
        ?>
                            </tbody>
                        </table>
        <?php
    }
    else
        echo "\t\t\t\t\t\t\t" . '<p>' . $lang['no_ranks'] . '</p>' . "\n";
    ?>
                </div>
            </div>
        </form>
    </div>
    <?php
}
else
    BB_Functions::Message($lang['Bad request']);
require FORUM_ROOT . 'admin/footer.php';
?>
Return current item: XennoBB