source: branches/rsr.v5.1.dev/web/punbb/admin_ranks.php @ 3

Last change on this file since 3 was 3, checked in by dj3c1t, 12 years ago

passage a Fluxbb 1.4.7

File size: 6.6 KB
RevLine 
[1]1<?php
2
[3]3/**
4 * Copyright (C) 2008-2011 FluxBB
5 * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
6 * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
7 */
[1]8
9// Tell header.php to use the admin template
10define('PUN_ADMIN_CONSOLE', 1);
11
[3]12define('PUN_ROOT', dirname(__FILE__).'/');
[1]13require PUN_ROOT.'include/common.php';
14require PUN_ROOT.'include/common_admin.php';
15
16
[3]17if ($pun_user['g_id'] != PUN_ADMIN)
[1]18        message($lang_common['No permission']);
19
[3]20// Load the admin_ranks.php language file
21require PUN_ROOT.'lang/'.$admin_language.'/admin_ranks.php';
[1]22
23// Add a rank
24if (isset($_POST['add_rank']))
25{
26        confirm_referrer('admin_ranks.php');
27
[3]28        $rank = pun_trim($_POST['new_rank']);
29        $min_posts = trim($_POST['new_min_posts']);
[1]30
31        if ($rank == '')
[3]32                message($lang_admin_ranks['Must enter title message']);
[1]33
[3]34        if ($min_posts == '' || preg_match('%[^0-9]%', $min_posts))
35                message($lang_admin_ranks['Must be integer message']);
[1]36
37        // Make sure there isn't already a rank with the same min_posts value
38        $result = $db->query('SELECT 1 FROM '.$db->prefix.'ranks WHERE min_posts='.$min_posts) or error('Unable to fetch rank info', __FILE__, __LINE__, $db->error());
39        if ($db->num_rows($result))
[3]40                message(sprintf($lang_admin_ranks['Dupe min posts message'], $min_posts));
[1]41
[3]42        $db->query('INSERT INTO '.$db->prefix.'ranks (rank, min_posts) VALUES(\''.$db->escape($rank).'\', '.$min_posts.')') or error('Unable to add rank', __FILE__, __LINE__, $db->error());
[1]43
44        // Regenerate the ranks cache
[3]45        if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
46                require PUN_ROOT.'include/cache.php';
47
[1]48        generate_ranks_cache();
49
[3]50        redirect('admin_ranks.php', $lang_admin_ranks['Rank added redirect']);
[1]51}
52
53
54// Update a rank
55else if (isset($_POST['update']))
56{
57        confirm_referrer('admin_ranks.php');
58
59        $id = intval(key($_POST['update']));
60
[3]61        $rank = pun_trim($_POST['rank'][$id]);
[1]62        $min_posts = trim($_POST['min_posts'][$id]);
63
64        if ($rank == '')
[3]65                message($lang_admin_ranks['Must enter title message']);
[1]66
[3]67        if ($min_posts == '' || preg_match('%[^0-9]%', $min_posts))
68                message($lang_admin_ranks['Must be integer message']);
[1]69
70        // Make sure there isn't already a rank with the same min_posts value
[3]71        $result = $db->query('SELECT 1 FROM '.$db->prefix.'ranks WHERE id!='.$id.' AND min_posts='.$min_posts) or error('Unable to fetch rank info', __FILE__, __LINE__, $db->error());
[1]72        if ($db->num_rows($result))
[3]73                message(sprintf($lang_admin_ranks['Dupe min posts message'], $min_posts));
[1]74
[3]75        $db->query('UPDATE '.$db->prefix.'ranks SET rank=\''.$db->escape($rank).'\', min_posts='.$min_posts.' WHERE id='.$id) or error('Unable to update rank', __FILE__, __LINE__, $db->error());
[1]76
77        // Regenerate the ranks cache
[3]78        if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
79                require PUN_ROOT.'include/cache.php';
80
[1]81        generate_ranks_cache();
82
[3]83        redirect('admin_ranks.php', $lang_admin_ranks['Rank updated redirect']);
[1]84}
85
86
87// Remove a rank
88else if (isset($_POST['remove']))
89{
90        confirm_referrer('admin_ranks.php');
91
92        $id = intval(key($_POST['remove']));
93
[3]94        $db->query('DELETE FROM '.$db->prefix.'ranks WHERE id='.$id) or error('Unable to delete rank', __FILE__, __LINE__, $db->error());
[1]95
96        // Regenerate the ranks cache
[3]97        if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
98                require PUN_ROOT.'include/cache.php';
99
[1]100        generate_ranks_cache();
101
[3]102        redirect('admin_ranks.php', $lang_admin_ranks['Rank removed redirect']);
[1]103}
104
[3]105$page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Ranks']);
[1]106$focus_element = array('ranks', 'new_rank');
[3]107define('PUN_ACTIVE_PAGE', 'admin');
[1]108require PUN_ROOT.'header.php';
109
110generate_admin_menu('ranks');
111
112?>
113        <div class="blockform">
[3]114                <h2><span><?php echo $lang_admin_ranks['Ranks head'] ?></span></h2>
[1]115                <div class="box">
[3]116                        <form id="ranks" method="post" action="admin_ranks.php">
[1]117                                <div class="inform">
118                                        <fieldset>
[3]119                                                <legend><?php echo $lang_admin_ranks['Add rank subhead'] ?></legend>
[1]120                                                <div class="infldset">
[3]121                                                        <p><?php echo $lang_admin_ranks['Add rank info'].' '.($pun_config['o_ranks'] == '1' ? sprintf($lang_admin_ranks['Ranks enabled'], '<a href="admin_options.php#ranks">'.$lang_admin_common['Options'].'</a>') : sprintf($lang_admin_ranks['Ranks disabled'], '<a href="admin_options.php#ranks">'.$lang_admin_common['Options'].'</a>')) ?></p>
122                                                        <table cellspacing="0">
[1]123                                                        <thead>
124                                                                <tr>
[3]125                                                                        <th class="tcl" scope="col"><?php echo $lang_admin_ranks['Rank title label'] ?></th>
126                                                                        <th class="tc2" scope="col"><?php echo $lang_admin_ranks['Minimum posts label'] ?></th>
127                                                                        <th class="hidehead" scope="col"><?php echo $lang_admin_ranks['Actions label'] ?></th>
[1]128                                                                </tr>
129                                                        </thead>
130                                                        <tbody>
131                                                                <tr>
[3]132                                                                        <td class="tcl"><input type="text" name="new_rank" size="24" maxlength="50" tabindex="1" /></td>
133                                                                        <td class="tc2"><input type="text" name="new_min_posts" size="7" maxlength="7" tabindex="2" /></td>
134                                                                        <td><input type="submit" name="add_rank" value="<?php echo $lang_admin_common['Add'] ?>" tabindex="3" /></td>
[1]135                                                                </tr>
136                                                        </tbody>
137                                                        </table>
138                                                </div>
139                                        </fieldset>
140                                </div>
141                                <div class="inform">
142                                        <fieldset>
[3]143                                                <legend><?php echo $lang_admin_ranks['Edit remove subhead'] ?></legend>
[1]144                                                <div class="infldset">
145<?php
146
[3]147$result = $db->query('SELECT id, rank, min_posts FROM '.$db->prefix.'ranks ORDER BY min_posts') or error('Unable to fetch rank list', __FILE__, __LINE__, $db->error());
[1]148if ($db->num_rows($result))
149{
150
151?>
[3]152                                                        <table cellspacing="0">
[1]153                                                        <thead>
154                                                                <tr>
[3]155                                                                        <th class="tcl" scope="col"><?php echo $lang_admin_ranks['Rank title label'] ?></th>
156                                                                        <th class="tc2" scope="col"><?php echo $lang_admin_ranks['Minimum posts label'] ?></th>
157                                                                        <th class="hidehead" scope="col"><?php echo $lang_admin_ranks['Actions label'] ?></th>
[1]158                                                                </tr>
159                                                        </thead>
160                                                        <tbody>
161<?php
162
163        while ($cur_rank = $db->fetch_assoc($result))
[3]164                echo "\t\t\t\t\t\t\t\t".'<tr><td class="tcl"><input type="text" name="rank['.$cur_rank['id'].']" value="'.pun_htmlspecialchars($cur_rank['rank']).'" size="24" maxlength="50" /></td><td class="tc2"><input type="text" name="min_posts['.$cur_rank['id'].']" value="'.$cur_rank['min_posts'].'" size="7" maxlength="7" /></td><td><input type="submit" name="update['.$cur_rank['id'].']" value="'.$lang_admin_common['Update'].'" />&#160;<input type="submit" name="remove['.$cur_rank['id'].']" value="'.$lang_admin_common['Remove'].'" /></td></tr>'."\n";
[1]165
166?>
167                                                        </tbody>
168                                                        </table>
169<?php
170
171}
172else
[3]173        echo "\t\t\t\t\t\t\t".'<p>'.$lang_admin_ranks['No ranks in list'].'</p>'."\n";
[1]174
175?>
176                                                </div>
177                                        </fieldset>
178                                </div>
179                        </form>
180                </div>
181        </div>
182        <div class="clearer"></div>
183</div>
184<?php
185
186require PUN_ROOT.'footer.php';
Note: See TracBrowser for help on using the repository browser.