6
|
1 |
<?php
|
|
2 |
/***********************************************************************
|
|
3 |
|
|
4 |
Copyright (C) 2002-2008 PunBB.org
|
|
5 |
|
|
6 |
This file is part of PunBB.
|
|
7 |
|
|
8 |
PunBB is free software; you can redistribute it and/or modify it
|
|
9 |
under the terms of the GNU General Public License as published
|
|
10 |
by the Free Software Foundation; either version 2 of the License,
|
|
11 |
or (at your option) any later version.
|
|
12 |
|
|
13 |
PunBB is distributed in the hope that it will be useful, but
|
|
14 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
GNU General Public License for more details.
|
|
17 |
|
|
18 |
You should have received a copy of the GNU General Public License
|
|
19 |
along with this program; if not, write to the Free Software
|
|
20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
21 |
MA 02111-1307 USA
|
|
22 |
|
|
23 |
************************************************************************/
|
|
24 |
|
|
25 |
|
|
26 |
// if (!defined('PUN_ROOT'))
|
|
27 |
// define('PUN_ROOT', '../');
|
|
28 |
// require PUN_ROOT.'include/common.php';
|
|
29 |
require PUN_ROOT.'include/common_admin.php';
|
|
30 |
|
|
31 |
// import globals (I really hope this isn't dangerous)
|
|
32 |
foreach ( $GLOBALS as $key => $_ )
|
|
33 |
{
|
|
34 |
$$key =& $GLOBALS[$key];
|
|
35 |
}
|
|
36 |
|
|
37 |
($hook = get_hook('ark_start')) ? eval($hook) : null;
|
|
38 |
|
|
39 |
if ($session->user_level < USER_LEVEL_ADMIN)
|
|
40 |
message($lang_common['No permission']);
|
|
41 |
|
|
42 |
// Load the admin.php language file
|
|
43 |
require PUN_ROOT.'lang/'.$pun_user['language'].'/admin.php';
|
|
44 |
$GLOBALS['lang_admin'] = $lang_admin;
|
|
45 |
|
|
46 |
|
|
47 |
// Add a rank
|
|
48 |
if (isset($_POST['add_rank']))
|
|
49 |
{
|
|
50 |
$rank = trim($_POST['new_rank']);
|
|
51 |
$min_posts = intval($_POST['new_min_posts']);
|
|
52 |
|
|
53 |
if ($rank == '')
|
|
54 |
message($lang_admin['Title message']);
|
|
55 |
|
|
56 |
if ($min_posts < 0)
|
|
57 |
message($lang_admin['Min posts message']);
|
|
58 |
|
|
59 |
($hook = get_hook('ark_add_rank_form_submitted')) ? eval($hook) : null;
|
|
60 |
|
|
61 |
// Make sure there isn't already a rank with the same min_posts value
|
|
62 |
$query = array(
|
|
63 |
'SELECT' => '1',
|
|
64 |
'FROM' => 'ranks AS r',
|
|
65 |
'WHERE' => 'min_posts='.$min_posts
|
|
66 |
);
|
|
67 |
|
|
68 |
($hook = get_hook('ark_qr_check_rank_collision')) ? eval($hook) : null;
|
|
69 |
$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
70 |
if ($pun_db->num_rows($result))
|
|
71 |
message(sprintf($lang_admin['Min posts occupied message'], $min_posts));
|
|
72 |
|
|
73 |
$query = array(
|
|
74 |
'INSERT' => 'rank, min_posts',
|
|
75 |
'INTO' => 'ranks',
|
|
76 |
'VALUES' => '\''.$pun_db->escape($rank).'\', '.$min_posts
|
|
77 |
);
|
|
78 |
|
|
79 |
($hook = get_hook('ark_qr_add_rank')) ? eval($hook) : null;
|
|
80 |
$pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
81 |
|
|
82 |
// Regenerate the ranks cache
|
|
83 |
require_once PUN_ROOT.'include/cache.php';
|
|
84 |
generate_ranks_cache();
|
|
85 |
|
|
86 |
pun_redirect(pun_link($pun_url['admin_ranks']), $lang_admin['Rank added'].' '.$lang_admin['Redirect']);
|
|
87 |
}
|
|
88 |
|
|
89 |
|
|
90 |
// Update a rank
|
|
91 |
else if (isset($_POST['update']))
|
|
92 |
{
|
|
93 |
$id = intval(key($_POST['update']));
|
|
94 |
|
|
95 |
$rank = trim($_POST['rank'][$id]);
|
|
96 |
$min_posts = intval($_POST['min_posts'][$id]);
|
|
97 |
|
|
98 |
if ($rank == '')
|
|
99 |
message($lang_admin['Title message']);
|
|
100 |
|
|
101 |
if ($min_posts < 0)
|
|
102 |
message($lang_admin['Min posts message']);
|
|
103 |
|
|
104 |
($hook = get_hook('ark_update_form_submitted')) ? eval($hook) : null;
|
|
105 |
|
|
106 |
// Make sure there isn't already a rank with the same min_posts value
|
|
107 |
$query = array(
|
|
108 |
'SELECT' => '1',
|
|
109 |
'FROM' => 'ranks AS r',
|
|
110 |
'WHERE' => 'id!='.$id.' AND min_posts='.$min_posts
|
|
111 |
);
|
|
112 |
|
|
113 |
($hook = get_hook('ark_qr_check_rank_collision2')) ? eval($hook) : null;
|
|
114 |
$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
115 |
if ($pun_db->num_rows($result))
|
|
116 |
message(sprintf($lang_admin['Min posts occupied message'], $min_posts));
|
|
117 |
|
|
118 |
$query = array(
|
|
119 |
'UPDATE' => 'ranks',
|
|
120 |
'SET' => 'rank=\''.$pun_db->escape($rank).'\', min_posts='.$min_posts,
|
|
121 |
'WHERE' => 'id='.$id
|
|
122 |
);
|
|
123 |
|
|
124 |
($hook = get_hook('ark_qr_update_rank')) ? eval($hook) : null;
|
|
125 |
$pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
126 |
|
|
127 |
// Regenerate the ranks cache
|
|
128 |
require_once PUN_ROOT.'include/cache.php';
|
|
129 |
generate_ranks_cache();
|
|
130 |
|
|
131 |
pun_redirect(pun_link($pun_url['admin_ranks']), $lang_admin['Rank updated'].' '.$lang_admin['Redirect']);
|
|
132 |
}
|
|
133 |
|
|
134 |
|
|
135 |
// Remove a rank
|
|
136 |
else if (isset($_POST['remove']))
|
|
137 |
{
|
|
138 |
$id = intval(key($_POST['remove']));
|
|
139 |
|
|
140 |
($hook = get_hook('ark_remove_form_submitted')) ? eval($hook) : null;
|
|
141 |
|
|
142 |
$query = array(
|
|
143 |
'DELETE' => 'ranks',
|
|
144 |
'WHERE' => 'id='.$id
|
|
145 |
);
|
|
146 |
|
|
147 |
($hook = get_hook('ark_qr_delete_rank')) ? eval($hook) : null;
|
|
148 |
$pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
149 |
|
|
150 |
// Regenerate the ranks cache
|
|
151 |
require_once PUN_ROOT.'include/cache.php';
|
|
152 |
generate_ranks_cache();
|
|
153 |
|
|
154 |
pun_redirect(pun_link($pun_url['admin_ranks']), $lang_admin['Rank removed'].' '.$lang_admin['Redirect']);
|
|
155 |
}
|
|
156 |
|
|
157 |
|
|
158 |
// Load the cached ranks
|
|
159 |
if (file_exists(PUN_CACHE_DIR.'cache_ranks.php'))
|
|
160 |
include PUN_CACHE_DIR.'cache_ranks.php';
|
|
161 |
|
|
162 |
if (!defined('PUN_RANKS_LOADED'))
|
|
163 |
{
|
|
164 |
require_once PUN_ROOT.'include/cache.php';
|
|
165 |
generate_ranks_cache();
|
|
166 |
require PUN_CACHE_DIR.'cache_ranks.php';
|
|
167 |
}
|
|
168 |
|
|
169 |
|
|
170 |
// Setup the form
|
|
171 |
$pun_page['fld_count'] = $pun_page['set_count'] = 0;
|
|
172 |
|
|
173 |
// Setup breadcrumbs
|
|
174 |
$pun_page['crumbs'] = array(
|
|
175 |
array($pun_config['o_board_title'], pun_link($pun_url['index'])),
|
|
176 |
array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])),
|
|
177 |
$lang_admin['Ranks']
|
|
178 |
);
|
|
179 |
|
|
180 |
($hook = get_hook('ark_pre_header_load')) ? eval($hook) : null;
|
|
181 |
|
|
182 |
define('PUN_PAGE_SECTION', 'users');
|
|
183 |
define('PUN_PAGE', 'admin-ranks');
|
|
184 |
require PUN_ROOT.'header.php';
|
|
185 |
|
|
186 |
?>
|
|
187 |
<div id="pun-main" class="main sectioned admin">
|
|
188 |
|
|
189 |
<?php echo generate_admin_menu(); ?>
|
|
190 |
|
|
191 |
<div class="main-head">
|
|
192 |
<h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1>
|
|
193 |
</div>
|
|
194 |
|
|
195 |
<div class="main-content frm">
|
|
196 |
<div class="frm-head">
|
|
197 |
<h2><span><?php echo $lang_admin['Add new rank'] ?></span></h2>
|
|
198 |
</div>
|
|
199 |
<div class="frm-info">
|
|
200 |
<p><?php printf($lang_admin['Add rank intro'], '<strong><a href="'.pun_link($pun_url['admin_options_features']).'#fs4">'.$lang_admin['Settings'].' - '.$lang_admin['Features'].'</a></strong>') ?></p>
|
|
201 |
</div>
|
|
202 |
<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_ranks']) ?>&action=foo">
|
|
203 |
<div class="hidden">
|
|
204 |
<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_ranks']).'&action=foo') ?>" />
|
|
205 |
</div>
|
|
206 |
<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
|
|
207 |
<legend class="frm-legend"><strong><?php echo $lang_admin['Add rank legend'] ?></strong></legend>
|
|
208 |
<?php ($hook = get_hook('ark_add_rank_pre_rank')) ? eval($hook) : null; ?>
|
|
209 |
<div class="frm-fld text">
|
|
210 |
<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
|
|
211 |
<span class="fld-label"><?php echo $lang_admin['Rank title'] ?></span><br />
|
|
212 |
<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="new_rank" size="24" maxlength="50" /></span>
|
|
213 |
</label>
|
|
214 |
</div>
|
|
215 |
<?php ($hook = get_hook('ark_add_rank_pre_min_posts')) ? eval($hook) : null; ?>
|
|
216 |
<div class="frm-fld">
|
|
217 |
<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
|
|
218 |
<span class="fld-label"><?php echo $lang_admin['Min posts'] ?></span><br />
|
|
219 |
<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="new_min_posts" size="7" maxlength="7" /></span>
|
|
220 |
</label>
|
|
221 |
</div>
|
|
222 |
<?php ($hook = get_hook('ark_add_rank_end')) ? eval($hook) : null; ?>
|
|
223 |
</fieldset>
|
|
224 |
<div class="frm-buttons">
|
|
225 |
<span class="submit"><input type="submit" name="add_rank" value="<?php echo $lang_admin['Add rank'] ?>" /></span>
|
|
226 |
</div>
|
|
227 |
</form>
|
|
228 |
</div>
|
|
229 |
<?php
|
|
230 |
|
|
231 |
if (!empty($pun_ranks))
|
|
232 |
{
|
|
233 |
// Reset fieldset counter
|
|
234 |
$pun_page['set_count'] = 0;
|
|
235 |
|
|
236 |
?>
|
|
237 |
<div class="main-content frm">
|
|
238 |
<div class="frm-head">
|
|
239 |
<h2><span><?php echo $lang_admin['Existing ranks intro'] ?></span></h2>
|
|
240 |
</div>
|
|
241 |
<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_ranks']) ?>&action=foo">
|
|
242 |
<div class="hidden">
|
|
243 |
<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_ranks']).'&action=foo') ?>" />
|
|
244 |
</div>
|
|
245 |
<?php
|
|
246 |
|
|
247 |
foreach ($pun_ranks as $rank_key => $cur_rank)
|
|
248 |
{
|
|
249 |
|
|
250 |
?>
|
|
251 |
<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
|
|
252 |
<legend class="frm-legend"><span><?php echo $lang_admin['Rank'].' '.($rank_key + 1) ?></span></legend>
|
|
253 |
<?php ($hook = get_hook('ark_edit_rank_pre_rank')) ? eval($hook) : null; ?>
|
|
254 |
<div class="frm-fld text">
|
|
255 |
<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
|
|
256 |
<span class="fld-label"><?php echo $lang_admin['Rank title'] ?></span><br />
|
|
257 |
<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="rank[<?php echo $cur_rank['id'] ?>]" value="<?php echo htmlspecialchars($cur_rank['rank']) ?>" size="24" maxlength="50" /></span>
|
|
258 |
</label>
|
|
259 |
</div>
|
|
260 |
<?php ($hook = get_hook('ark_edit_rank_pre_min_posts')) ? eval($hook) : null; ?>
|
|
261 |
<div class="frm-fld text">
|
|
262 |
<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
|
|
263 |
<span class="fld-label"><?php echo $lang_admin['Min posts'] ?></span><br />
|
|
264 |
<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="min_posts[<?php echo $cur_rank['id'] ?>]" value="<?php echo $cur_rank['min_posts'] ?>" size="7" maxlength="7" /></span>
|
|
265 |
</label>
|
|
266 |
<span class="submit"><input type="submit" name="update[<?php echo $cur_rank['id'] ?>]" value="<?php echo $lang_admin['Update'] ?>" /> <input type="submit" name="remove[<?php echo $cur_rank['id'] ?>]" value="<?php echo $lang_admin['Remove'] ?>" /></span>
|
|
267 |
</div>
|
|
268 |
<?php ($hook = get_hook('ark_edit_rank_end')) ? eval($hook) : null; ?>
|
|
269 |
</fieldset>
|
|
270 |
<?php
|
|
271 |
|
|
272 |
}
|
|
273 |
|
|
274 |
?>
|
|
275 |
</form>
|
|
276 |
</div>
|
|
277 |
<?php
|
|
278 |
|
|
279 |
}
|
|
280 |
else
|
|
281 |
{
|
|
282 |
|
|
283 |
?>
|
|
284 |
<div class="main-content frm">
|
|
285 |
<div class="frm-head">
|
|
286 |
<h2><span><?php echo $lang_admin['Existing ranks intro'] ?></span></h2>
|
|
287 |
</div>
|
|
288 |
<div class="frm-form">
|
|
289 |
<div class="frm-info">
|
|
290 |
<p><?php echo $lang_admin['No ranks'] ?></p>
|
|
291 |
</div>
|
|
292 |
</div>
|
|
293 |
</div>
|
|
294 |
<?php
|
|
295 |
|
|
296 |
}
|
|
297 |
|
|
298 |
?>
|
|
299 |
</div>
|
|
300 |
<?php
|
|
301 |
|
|
302 |
require PUN_ROOT.'footer.php';
|