0
|
1 |
<?php
|
|
2 |
/***********************************************************************
|
|
3 |
|
|
4 |
Copyright (C) 2002-2005 Rickard Andersson (rickard@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 |
// Tell header.php to use the admin template
|
|
27 |
define('PUN_ADMIN_CONSOLE', 1);
|
|
28 |
|
|
29 |
define('PUN_ROOT', './');
|
|
30 |
require PUN_ROOT.'include/common.php';
|
|
31 |
require PUN_ROOT.'include/common_admin.php';
|
|
32 |
|
|
33 |
|
|
34 |
if ($pun_user['g_id'] > PUN_ADMIN)
|
|
35 |
message($lang_common['No permission']);
|
|
36 |
|
|
37 |
|
|
38 |
// Add a new category
|
|
39 |
if (isset($_POST['add_cat']))
|
|
40 |
{
|
|
41 |
confirm_referrer('admin_categories.php');
|
|
42 |
|
|
43 |
$new_cat_name = trim($_POST['new_cat_name']);
|
|
44 |
if ($new_cat_name == '')
|
|
45 |
message('You must enter a name for the category.');
|
|
46 |
|
|
47 |
$db->query('INSERT INTO '.$db->prefix.'categories (cat_name) VALUES(\''.$db->escape($new_cat_name).'\')') or error('Unable to create category', __FILE__, __LINE__, $db->error());
|
|
48 |
|
|
49 |
redirect('admin_categories.php', 'Category added. Redirecting …');
|
|
50 |
}
|
|
51 |
|
|
52 |
|
|
53 |
// Delete a category
|
|
54 |
else if (isset($_POST['del_cat']) || isset($_POST['del_cat_comply']))
|
|
55 |
{
|
|
56 |
confirm_referrer('admin_categories.php');
|
|
57 |
|
|
58 |
$cat_to_delete = intval($_POST['cat_to_delete']);
|
|
59 |
if ($cat_to_delete < 1)
|
|
60 |
message($lang_common['Bad request']);
|
|
61 |
|
|
62 |
if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts
|
|
63 |
{
|
|
64 |
@set_time_limit(0);
|
|
65 |
|
|
66 |
$result = $db->query('SELECT id FROM '.$db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
|
|
67 |
$num_forums = $db->num_rows($result);
|
|
68 |
|
|
69 |
for ($i = 0; $i < $num_forums; ++$i)
|
|
70 |
{
|
|
71 |
$cur_forum = $db->result($result, $i);
|
|
72 |
|
|
73 |
// Prune all posts and topics
|
|
74 |
prune($cur_forum, 1, -1);
|
|
75 |
|
|
76 |
// Delete the forum
|
|
77 |
$db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $db->error());
|
|
78 |
}
|
|
79 |
|
|
80 |
// Locate any "orphaned redirect topics" and delete them
|
|
81 |
$result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
|
|
82 |
$num_orphans = $db->num_rows($result);
|
|
83 |
|
|
84 |
if ($num_orphans)
|
|
85 |
{
|
|
86 |
for ($i = 0; $i < $num_orphans; ++$i)
|
|
87 |
$orphans[] = $db->result($result, $i);
|
|
88 |
|
|
89 |
$db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
|
|
90 |
}
|
|
91 |
|
|
92 |
// Delete the category
|
|
93 |
$db->query('DELETE FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $db->error());
|
|
94 |
|
|
95 |
// Regenerate the quickjump cache
|
|
96 |
require_once PUN_ROOT.'include/cache.php';
|
|
97 |
generate_quickjump_cache();
|
|
98 |
|
|
99 |
redirect('admin_categories.php', 'Category deleted. Redirecting …');
|
|
100 |
}
|
|
101 |
else // If the user hasn't comfirmed the delete
|
|
102 |
{
|
|
103 |
$result = $db->query('SELECT cat_name FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to fetch category info', __FILE__, __LINE__, $db->error());
|
|
104 |
$cat_name = $db->result($result);
|
|
105 |
|
|
106 |
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories';
|
|
107 |
require PUN_ROOT.'header.php';
|
|
108 |
|
|
109 |
generate_admin_menu('categories');
|
|
110 |
|
|
111 |
?>
|
|
112 |
<div class="blockform">
|
|
113 |
<h2><span>Category delete</span></h2>
|
|
114 |
<div class="box">
|
|
115 |
<form method="post" action="admin_categories.php">
|
|
116 |
<div class="inform">
|
|
117 |
<input type="hidden" name="cat_to_delete" value="<?php echo $cat_to_delete ?>" />
|
|
118 |
<fieldset>
|
|
119 |
<legend>Confirm delete category</legend>
|
|
120 |
<div class="infldset">
|
|
121 |
<p>Are you sure that you want to delete the category "<?php echo pun_htmlspecialchars($cat_name) ?>"?</p>
|
|
122 |
<p>WARNING! Deleting a category will delete all forums and posts (if any) in that category!</p>
|
|
123 |
</div>
|
|
124 |
</fieldset>
|
|
125 |
</div>
|
|
126 |
<p><input type="submit" name="del_cat_comply" value="Delete" /><a href="javascript:history.go(-1)">Go back</a></p>
|
|
127 |
</form>
|
|
128 |
</div>
|
|
129 |
</div>
|
|
130 |
<div class="clearer"></div>
|
|
131 |
</div>
|
|
132 |
<?php
|
|
133 |
|
|
134 |
require PUN_ROOT.'footer.php';
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
|
|
139 |
else if (isset($_POST['update'])) // Change position and name of the categories
|
|
140 |
{
|
|
141 |
confirm_referrer('admin_categories.php');
|
|
142 |
|
|
143 |
$cat_order = $_POST['cat_order'];
|
|
144 |
$cat_name = $_POST['cat_name'];
|
|
145 |
|
|
146 |
$result = $db->query('SELECT id, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
|
|
147 |
$num_cats = $db->num_rows($result);
|
|
148 |
|
|
149 |
for ($i = 0; $i < $num_cats; ++$i)
|
|
150 |
{
|
|
151 |
if ($cat_name[$i] == '')
|
|
152 |
message('You must enter a category name.');
|
|
153 |
|
|
154 |
if (!@preg_match('#^\d+$#', $cat_order[$i]))
|
|
155 |
message('Position must be an integer value.');
|
|
156 |
|
|
157 |
list($cat_id, $position) = $db->fetch_row($result);
|
|
158 |
|
|
159 |
$db->query('UPDATE '.$db->prefix.'categories SET cat_name=\''.$db->escape($cat_name[$i]).'\', disp_position='.$cat_order[$i].' WHERE id='.$cat_id) or error('Unable to update category', __FILE__, __LINE__, $db->error());
|
|
160 |
}
|
|
161 |
|
|
162 |
// Regenerate the quickjump cache
|
|
163 |
require_once PUN_ROOT.'include/cache.php';
|
|
164 |
generate_quickjump_cache();
|
|
165 |
|
|
166 |
redirect('admin_categories.php', 'Categories updated. Redirecting …');
|
|
167 |
}
|
|
168 |
|
|
169 |
|
|
170 |
// Generate an array with all categories
|
|
171 |
$result = $db->query('SELECT id, cat_name, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
|
|
172 |
$num_cats = $db->num_rows($result);
|
|
173 |
|
|
174 |
for ($i = 0; $i < $num_cats; ++$i)
|
|
175 |
$cat_list[] = $db->fetch_row($result);
|
|
176 |
|
|
177 |
|
|
178 |
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories';
|
|
179 |
require PUN_ROOT.'header.php';
|
|
180 |
|
|
181 |
generate_admin_menu('categories');
|
|
182 |
|
|
183 |
?>
|
|
184 |
<div class="blockform">
|
|
185 |
<h2><span>Add/remove/edit categories</span></h2>
|
|
186 |
<div class="box">
|
|
187 |
<form method="post" action="admin_categories.php?action=foo">
|
|
188 |
<div class="inform">
|
|
189 |
<fieldset>
|
|
190 |
<legend>Add/delete categories</legend>
|
|
191 |
<div class="infldset">
|
|
192 |
<table class="aligntop" cellspacing="0">
|
|
193 |
<tr>
|
|
194 |
<th scope="row">Add a new category<div><input type="submit" name="add_cat" value="Add New" tabindex="2" /></div></th>
|
|
195 |
<td>
|
|
196 |
<input type="text" name="new_cat_name" size="35" maxlength="80" tabindex="1" />
|
|
197 |
<span>The name of the new category you want to add. You can edit the name of the category later (see below).Go to <a href="admin_forums.php">Forums</a> to add forums to your new category.</span>
|
|
198 |
</td>
|
|
199 |
</tr>
|
|
200 |
<?php if ($num_cats): ?> <tr>
|
|
201 |
<th scope="row">Delete a category<div><input type="submit" name="del_cat" value="Delete" tabindex="4" /></div></th>
|
|
202 |
<td>
|
|
203 |
<select name="cat_to_delete" tabindex="3">
|
|
204 |
<?php
|
|
205 |
|
|
206 |
while (list(, list($cat_id, $cat_name, ,)) = @each($cat_list))
|
|
207 |
echo "\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cat_id.'">'.pun_htmlspecialchars($cat_name).'</option>'."\n";
|
|
208 |
|
|
209 |
?>
|
|
210 |
</select>
|
|
211 |
<span>Select the name of the category you want to delete. You will be asked to confirm your choice of category for deletion before it is deleted.</span>
|
|
212 |
</td>
|
|
213 |
</tr>
|
|
214 |
<?php endif; ?> </table>
|
|
215 |
</div>
|
|
216 |
</fieldset>
|
|
217 |
</div>
|
|
218 |
<?php if ($num_cats): ?> <div class="inform">
|
|
219 |
<fieldset>
|
|
220 |
<legend>Edit categories</legend>
|
|
221 |
<div class="infldset">
|
|
222 |
<table id="categoryedit" cellspacing="0" >
|
|
223 |
<thead>
|
|
224 |
<tr>
|
|
225 |
<th class="tcl" scope="col">Name</th>
|
|
226 |
<th scope="col">Position</th>
|
|
227 |
<th> </th>
|
|
228 |
</tr>
|
|
229 |
</thead>
|
|
230 |
<tbody>
|
|
231 |
<?php
|
|
232 |
|
|
233 |
@reset($cat_list);
|
|
234 |
for ($i = 0; $i < $num_cats; ++$i)
|
|
235 |
{
|
|
236 |
list(, list($cat_id, $cat_name, $position)) = @each($cat_list);
|
|
237 |
|
|
238 |
?>
|
|
239 |
<tr><td><input type="text" name="cat_name[<?php echo $i ?>]" value="<?php echo pun_htmlspecialchars($cat_name) ?>" size="35" maxlength="80" /></td><td><input type="text" name="cat_order[<?php echo $i ?>]" value="<?php echo $position ?>" size="3" maxlength="3" /></td><td> </td></tr>
|
|
240 |
<?php
|
|
241 |
|
|
242 |
}
|
|
243 |
|
|
244 |
?>
|
|
245 |
</tbody>
|
|
246 |
</table>
|
|
247 |
<div class="fsetsubmit"><input type="submit" name="update" value="Update" /></div>
|
|
248 |
</div>
|
|
249 |
</fieldset>
|
|
250 |
</div>
|
|
251 |
<?php endif; ?> </form>
|
|
252 |
</div>
|
|
253 |
</div>
|
|
254 |
<div class="clearer"></div>
|
|
255 |
</div>
|
|
256 |
<?php
|
|
257 |
|
|
258 |
require PUN_ROOT.'footer.php';
|