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('acg_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 new category
|
|
48 |
if (isset($_POST['add_cat']))
|
|
49 |
{
|
|
50 |
$new_cat_name = trim($_POST['new_cat_name']);
|
|
51 |
if ($new_cat_name == '')
|
|
52 |
message($lang_admin['Must name category']);
|
|
53 |
|
|
54 |
($hook = get_hook('acg_add_cat_form_submitted')) ? eval($hook) : null;
|
|
55 |
|
|
56 |
$query = array(
|
|
57 |
'INSERT' => 'cat_name',
|
|
58 |
'INTO' => 'categories',
|
|
59 |
'VALUES' => '\''.$pun_db->escape($new_cat_name).'\''
|
|
60 |
);
|
|
61 |
|
|
62 |
($hook = get_hook('acg_qr_add_category')) ? eval($hook) : null;
|
|
63 |
$pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
64 |
|
|
65 |
pun_redirect(pun_link($pun_url['admin_categories']), $lang_admin['Category added'].' '.$lang_admin['Redirect']);
|
|
66 |
}
|
|
67 |
|
|
68 |
|
|
69 |
// Delete a category
|
|
70 |
else if (isset($_POST['del_cat']) || isset($_POST['del_cat_comply']))
|
|
71 |
{
|
|
72 |
$cat_to_delete = intval($_POST['cat_to_delete']);
|
|
73 |
if ($cat_to_delete < 1)
|
|
74 |
message($lang_common['Bad request']);
|
|
75 |
|
|
76 |
// User pressed the cancel button
|
|
77 |
if (isset($_POST['del_cat_cancel']))
|
|
78 |
pun_redirect(pun_link($pun_url['admin_categories']), $lang_admin['Cancel redirect']);
|
|
79 |
|
|
80 |
($hook = get_hook('acg_del_cat_form_submitted')) ? eval($hook) : null;
|
|
81 |
|
|
82 |
if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts
|
|
83 |
{
|
|
84 |
@set_time_limit(0);
|
|
85 |
|
|
86 |
$query = array(
|
|
87 |
'SELECT' => 'f.id',
|
|
88 |
'FROM' => 'forums AS f',
|
|
89 |
'WHERE' => 'cat_id='.$cat_to_delete
|
|
90 |
);
|
|
91 |
|
|
92 |
($hook = get_hook('acg_qr_get_forums_to_delete')) ? eval($hook) : null;
|
|
93 |
$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
94 |
$num_forums = $pun_db->num_rows($result);
|
|
95 |
|
|
96 |
for ($i = 0; $i < $num_forums; ++$i)
|
|
97 |
{
|
|
98 |
$cur_forum = $pun_db->result($result, $i);
|
|
99 |
|
|
100 |
// Prune all posts and topics
|
|
101 |
prune($cur_forum, 1, -1);
|
|
102 |
|
|
103 |
// Delete the forum
|
|
104 |
$query = array(
|
|
105 |
'DELETE' => 'forums',
|
|
106 |
'WHERE' => 'id='.$cur_forum
|
|
107 |
);
|
|
108 |
|
|
109 |
($hook = get_hook('acg_qr_delete_forum')) ? eval($hook) : null;
|
|
110 |
$pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
111 |
}
|
|
112 |
|
|
113 |
delete_orphans();
|
|
114 |
|
|
115 |
// Delete the category
|
|
116 |
$query = array(
|
|
117 |
'DELETE' => 'categories',
|
|
118 |
'WHERE' => 'id='.$cat_to_delete
|
|
119 |
);
|
|
120 |
|
|
121 |
($hook = get_hook('acg_qr_delete_category')) ? eval($hook) : null;
|
|
122 |
$pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
123 |
|
|
124 |
// Regenerate the quickjump cache
|
|
125 |
require_once PUN_ROOT.'include/cache.php';
|
|
126 |
generate_quickjump_cache();
|
|
127 |
|
|
128 |
pun_redirect(pun_link($pun_url['admin_categories']), $lang_admin['Category deleted'].' '.$lang_admin['Redirect']);
|
|
129 |
}
|
|
130 |
else // If the user hasn't comfirmed the delete
|
|
131 |
{
|
|
132 |
$query = array(
|
|
133 |
'SELECT' => 'c.cat_name',
|
|
134 |
'FROM' => 'categories AS c',
|
|
135 |
'WHERE' => 'c.id='.$cat_to_delete
|
|
136 |
);
|
|
137 |
|
|
138 |
($hook = get_hook('acg_qr_get_category_name')) ? eval($hook) : null;
|
|
139 |
$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
140 |
$cat_name = $pun_db->result($result);
|
|
141 |
|
|
142 |
|
|
143 |
// Setup breadcrumbs
|
|
144 |
$pun_page['crumbs'] = array(
|
|
145 |
array($pun_config['o_board_title'], pun_link($pun_url['index'])),
|
|
146 |
array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])),
|
|
147 |
array($lang_admin['Categories'], pun_link($pun_url['admin_categories'])),
|
|
148 |
$lang_admin['Delete category']
|
|
149 |
);
|
|
150 |
|
|
151 |
($hook = get_hook('acg_del_cat_pre_header_load')) ? eval($hook) : null;
|
|
152 |
|
|
153 |
define('PUN_PAGE_SECTION', 'start');
|
|
154 |
define('PUN_PAGE', 'admin-categories');
|
|
155 |
require PUN_ROOT.'header.php';
|
|
156 |
|
|
157 |
?>
|
|
158 |
<div id="pun-main" class="main sectioned admin">
|
|
159 |
|
|
160 |
|
|
161 |
<?php echo generate_admin_menu(); ?>
|
|
162 |
|
|
163 |
<div class="main-head">
|
|
164 |
<h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1>
|
|
165 |
</div>
|
|
166 |
|
|
167 |
<div class="main-content frm">
|
|
168 |
<div class="frm-head">
|
|
169 |
<h2><span><?php printf($lang_admin['Confirm delete cat'], htmlspecialchars($cat_name)) ?></span></h2>
|
|
170 |
</div>
|
|
171 |
<div class="frm-info">
|
|
172 |
<p class="warn"><?php echo $lang_admin['Delete category warning'] ?></p>
|
|
173 |
</div>
|
|
174 |
<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_categories']) ?>">
|
|
175 |
<div class="hidden">
|
|
176 |
<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_categories'])) ?>" />
|
|
177 |
<input type="hidden" name="cat_to_delete" value="<?php echo $cat_to_delete ?>" />
|
|
178 |
</div>
|
|
179 |
<div class="frm-buttons">
|
|
180 |
<span class="submit"><input type="submit" name="del_cat_comply" value="<?php echo $lang_admin['Delete'] ?>" /></span>
|
|
181 |
<span class="cancel"><input type="submit" name="del_cat_cancel" value="<?php echo $lang_admin['Cancel'] ?>" /></span>
|
|
182 |
</div>
|
|
183 |
</form>
|
|
184 |
</div>
|
|
185 |
|
|
186 |
</div>
|
|
187 |
<?php
|
|
188 |
|
|
189 |
require PUN_ROOT.'footer.php';
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
|
|
194 |
else if (isset($_POST['update'])) // Change position and name of the categories
|
|
195 |
{
|
|
196 |
$cat_order = array_map('intval', $_POST['cat_order']);
|
|
197 |
$cat_name = array_map('trim', $_POST['cat_name']);
|
|
198 |
|
|
199 |
($hook = get_hook('acg_update_cats_form_submitted')) ? eval($hook) : null;
|
|
200 |
|
|
201 |
$query = array(
|
|
202 |
'SELECT' => 'c.id, c.cat_name, c.disp_position',
|
|
203 |
'FROM' => 'categories AS c',
|
|
204 |
'ORDER BY' => 'c.id'
|
|
205 |
);
|
|
206 |
|
|
207 |
($hook = get_hook('acg_qr_get_categories')) ? eval($hook) : null;
|
|
208 |
$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
209 |
while ($cur_cat = $pun_db->fetch_assoc($result))
|
|
210 |
{
|
|
211 |
// If these aren't set, we're looking at a category that was added after
|
|
212 |
// the admin started editing: we don't want to mess with it
|
|
213 |
if (isset($cat_name[$cur_cat['id']]) && isset($cat_order[$cur_cat['id']]))
|
|
214 |
{
|
|
215 |
if ($cat_name[$cur_cat['id']] == '')
|
|
216 |
message($lang_admin['Must enter category']);
|
|
217 |
|
|
218 |
if ($cat_order[$cur_cat['id']] < 0)
|
|
219 |
message($lang_admin['Must be integer']);
|
|
220 |
|
|
221 |
// We only want to update if we changed anything
|
|
222 |
if ($cur_cat['cat_name'] != $cat_name[$cur_cat['id']] || $cur_cat['disp_position'] != $cat_order[$cur_cat['id']])
|
|
223 |
{
|
|
224 |
$query = array(
|
|
225 |
'UPDATE' => 'categories',
|
|
226 |
'SET' => 'cat_name=\''.$pun_db->escape($cat_name[$cur_cat['id']]).'\', disp_position='.$cat_order[$cur_cat['id']],
|
|
227 |
'WHERE' => 'id='.$cur_cat['id']
|
|
228 |
);
|
|
229 |
|
|
230 |
($hook = get_hook('acg_qr_update_category')) ? eval($hook) : null;
|
|
231 |
$pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
232 |
}
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
|
236 |
// Regenerate the quickjump cache
|
|
237 |
require_once PUN_ROOT.'include/cache.php';
|
|
238 |
generate_quickjump_cache();
|
|
239 |
|
|
240 |
pun_redirect(pun_link($pun_url['admin_categories']), $lang_admin['Categories updated'].' '.$lang_admin['Redirect']);
|
|
241 |
}
|
|
242 |
|
|
243 |
|
|
244 |
// Generate an array with all categories
|
|
245 |
$query = array(
|
|
246 |
'SELECT' => 'c.id, c.cat_name, c.disp_position',
|
|
247 |
'FROM' => 'categories AS c',
|
|
248 |
'ORDER BY' => 'c.disp_position'
|
|
249 |
);
|
|
250 |
|
|
251 |
($hook = get_hook('acg_qr_get_categories2')) ? eval($hook) : null;
|
|
252 |
$result = $pun_db->query_build($query) or error(__FILE__, __LINE__);
|
|
253 |
$num_cats = $pun_db->num_rows($result);
|
|
254 |
|
|
255 |
for ($i = 0; $i < $num_cats; ++$i)
|
|
256 |
$cat_list[] = $pun_db->fetch_row($result);
|
|
257 |
|
|
258 |
// Setup the form
|
|
259 |
$pun_page['fld_count'] = $pun_page['set_count'] = $pun_page['part_count'] = 0;
|
|
260 |
|
|
261 |
|
|
262 |
// Setup breadcrumbs
|
|
263 |
$pun_page['crumbs'] = array(
|
|
264 |
array($pun_config['o_board_title'], pun_link($pun_url['index'])),
|
|
265 |
array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])),
|
|
266 |
$lang_admin['Categories']
|
|
267 |
);
|
|
268 |
|
|
269 |
($hook = get_hook('acg_cat_header_load')) ? eval($hook) : null;
|
|
270 |
|
|
271 |
define('PUN_PAGE_SECTION', 'start');
|
|
272 |
define('PUN_PAGE', 'admin-categories');
|
|
273 |
require PUN_ROOT.'header.php';
|
|
274 |
|
|
275 |
?>
|
|
276 |
<div id="pun-main" class="main sectioned admin">
|
|
277 |
|
|
278 |
|
|
279 |
<?php echo generate_admin_menu(); ?>
|
|
280 |
|
|
281 |
<div class="main-head">
|
|
282 |
<h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1>
|
|
283 |
</div>
|
|
284 |
|
|
285 |
<div class="main-content frm">
|
|
286 |
<div class="frm-head">
|
|
287 |
<h2><span><?php printf($lang_admin['Add category head'], '<strong>'.$lang_admin['Add category'].'</strong>') ?></span></h2>
|
|
288 |
</div>
|
|
289 |
<div class="frm-info">
|
|
290 |
<p><?php printf($lang_admin['Add category info'], '<a href="'.pun_link($pun_url['admin_forums']).'">'.strtolower($lang_admin['Forums']).'</a>') ?></p>
|
|
291 |
</div>
|
|
292 |
<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_categories']) ?>&action=foo">
|
|
293 |
<div class="hidden">
|
|
294 |
<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_categories']).'&action=foo') ?>" />
|
|
295 |
</div>
|
|
296 |
<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
|
|
297 |
<legend class="frm-legend"><strong><?php echo $lang_admin['Add category'] ?></strong></legend>
|
|
298 |
<div class="frm-fld text">
|
|
299 |
<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
|
|
300 |
<span class="fld-label"><?php echo $lang_admin['New category name'] ?></span><br />
|
|
301 |
<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="new_cat_name" size="35" maxlength="80" /></span>
|
|
302 |
</label>
|
|
303 |
</div>
|
|
304 |
<div class="frm-fld text">
|
|
305 |
<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
|
|
306 |
<span class="fld-label"><?php echo $lang_admin['Position'] ?></span><br />
|
|
307 |
<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="position" size="3" maxlength="3" /></span>
|
|
308 |
<span class="fld-extra"><?php echo $lang_admin['Category position help'] ?></span>
|
|
309 |
</label>
|
|
310 |
</div>
|
|
311 |
<?php ($hook = get_hook('acg_add_cat_fieldset_end')) ? eval($hook) : null; ?>
|
|
312 |
</fieldset>
|
|
313 |
<div class="frm-buttons">
|
|
314 |
<span class="submit"><input type="submit" name="add_cat" value="<?php echo $lang_admin['Add category'] ?>" /></span>
|
|
315 |
</div>
|
|
316 |
</form>
|
|
317 |
</div>
|
|
318 |
<?php
|
|
319 |
|
|
320 |
($hook = get_hook('acg_new_form')) ? eval($hook) : null;
|
|
321 |
|
|
322 |
// Reset fieldset counter
|
|
323 |
$pun_page['set_count'] = 0;
|
|
324 |
|
|
325 |
if ($num_cats)
|
|
326 |
{
|
|
327 |
|
|
328 |
?>
|
|
329 |
<div class="main-content frm">
|
|
330 |
<div class="frm-head">
|
|
331 |
<h2><span><?php printf($lang_admin['Del category head'], '<strong>'.$lang_admin['Delete category'].'</strong>') ?></span></h2>
|
|
332 |
</div>
|
|
333 |
<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_categories']) ?>&action=foo">
|
|
334 |
<div class="hidden">
|
|
335 |
<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_categories']).'&action=foo') ?>" />
|
|
336 |
</div>
|
|
337 |
<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
|
|
338 |
<legend class="frm-legend"><strong><?php echo $lang_admin['Delete category'] ?></strong></legend>
|
|
339 |
<div class="frm-fld select">
|
|
340 |
<label for="fld<?php echo ++$pun_page['fld_count'] ?>">
|
|
341 |
<span class="fld-label"><?php echo $lang_admin['Category to delete'] ?></span><br />
|
|
342 |
<span class="fld-input"><select id="fld<?php echo $pun_page['fld_count'] ?>" name="cat_to_delete">
|
|
343 |
<?php
|
|
344 |
|
|
345 |
while (list(, list($cat_id, $cat_name, ,)) = @each($cat_list))
|
|
346 |
echo "\t\t\t\t\t\t\t".'<option value="'.$cat_id.'">'.htmlspecialchars($cat_name).'</option>'."\n";
|
|
347 |
|
|
348 |
?>
|
|
349 |
</select></span>
|
|
350 |
<span class="fld-help"><?php echo $lang_admin['Requires confirmation'] ?></span>
|
|
351 |
</label>
|
|
352 |
</div>
|
|
353 |
<?php ($hook = get_hook('acg_del_cat_fieldset_end')) ? eval($hook) : null; ?>
|
|
354 |
</fieldset>
|
|
355 |
<div class="frm-buttons">
|
|
356 |
<span class="submit"><input type="submit" name="del_cat" value="<?php echo $lang_admin['Delete category'] ?>" /></span>
|
|
357 |
</div>
|
|
358 |
</form>
|
|
359 |
</div>
|
|
360 |
|
|
361 |
<div class="main-content frm">
|
|
362 |
<div class="frm-head">
|
|
363 |
<h2><span><?php printf($lang_admin['Edit categories head'], '<strong>'.$lang_admin['Edit categories'].'</strong>') ?></span></h2>
|
|
364 |
</div>
|
|
365 |
<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_categories']) ?>&action=foo">
|
|
366 |
<div class="hidden">
|
|
367 |
<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_categories']).'&action=foo') ?>" />
|
|
368 |
</div>
|
|
369 |
|
|
370 |
<?php
|
|
371 |
|
|
372 |
@reset($cat_list);
|
|
373 |
for ($i = 0; $i < $num_cats; ++$i)
|
|
374 |
{
|
|
375 |
list(, list($cat_id, $cat_name, $position)) = @each($cat_list);
|
|
376 |
// Reset fieldset counter
|
|
377 |
$pun_page['set_count'] = 0;
|
|
378 |
|
|
379 |
?>
|
|
380 |
<fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>">
|
|
381 |
<legend class="frm-legend"><strong><?php echo htmlspecialchars($cat_name) ?>: </strong></legend>
|
|
382 |
<div class="frm-fld text twin">
|
|
383 |
<label for="fld<?php echo ++$pun_page['fld_count'] ?>" class="twin1">
|
|
384 |
<span class="fld-label"><?php echo $lang_admin['Edit category name'] ?></span><br />
|
|
385 |
<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="cat_name[<?php echo $cat_id ?>]" value="<?php echo htmlspecialchars($cat_name) ?>" size="35" maxlength="80" /></span>
|
|
386 |
</label><br />
|
|
387 |
<label for="fld<?php echo ++$pun_page['fld_count'] ?>" class="twin2">
|
|
388 |
<span class="fld-label"><?php echo $lang_admin['Change category position'] ?></span><br />
|
|
389 |
<span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="cat_order[<?php echo $cat_id ?>]" value="<?php echo $position ?>" size="3" maxlength="3" /></span>
|
|
390 |
</label>
|
|
391 |
</div>
|
|
392 |
<?php ($hook = get_hook('acg_edit_cat_fieldset_end')) ? eval($hook) : null; ?>
|
|
393 |
</fieldset>
|
|
394 |
<?php
|
|
395 |
|
|
396 |
}
|
|
397 |
|
|
398 |
?>
|
|
399 |
<div class="frm-buttons">
|
|
400 |
<span class="submit"><input type="submit" class="button" name="update" value="<?php echo $lang_admin['Update all'] ?>" /></span>
|
|
401 |
</div>
|
|
402 |
</form>
|
|
403 |
</div>
|
|
404 |
<?php
|
|
405 |
|
|
406 |
($hook = get_hook('acg_has_cats_new_form')) ? eval($hook) : null;
|
|
407 |
}
|
|
408 |
|
|
409 |
?>
|
|
410 |
|
|
411 |
</div>
|
|
412 |
<?php
|
|
413 |
|
|
414 |
require PUN_ROOT.'footer.php';
|