2 /***********************************************************************
4 Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org)
6 This file is part of PunBB.
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.
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.
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,
23 ************************************************************************/
26 // Tell header.php to use the admin template
27 define('PUN_ADMIN_CONSOLE', 1);
29 define('PUN_ROOT', './');
30 require PUN_ROOT
.'include/common.php';
31 require PUN_ROOT
.'include/common_admin.php';
34 if ($pun_user['g_id'] > PUN_ADMIN
)
35 message($lang_common['No permission']);
39 if (isset($_POST['add_cat']))
41 confirm_referrer('admin_categories.php');
43 $new_cat_name = trim($_POST['new_cat_name']);
44 if ($new_cat_name == '')
45 message('You must enter a name for the category.');
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());
49 redirect('admin_categories.php', 'Category added. Redirecting …');
54 else if (isset($_POST['del_cat']) ||
isset($_POST['del_cat_comply']))
56 confirm_referrer('admin_categories.php');
58 $cat_to_delete = intval($_POST['cat_to_delete']);
59 if ($cat_to_delete < 1)
60 message($lang_common['Bad request']);
62 if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts
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);
69 for ($i = 0; $i < $num_forums; ++
$i)
71 $cur_forum = $db->result($result, $i);
73 // Prune all posts and topics
74 prune($cur_forum, 1, -1);
77 $db->query('DELETE FROM '.$db->prefix
.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__
, __LINE__
, $db->error());
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);
86 for ($i = 0; $i < $num_orphans; ++
$i)
87 $orphans[] = $db->result($result, $i);
89 $db->query('DELETE FROM '.$db->prefix
.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__
, __LINE__
, $db->error());
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());
95 // Regenerate the quickjump cache
96 require_once PUN_ROOT
.'include/cache.php';
97 generate_quickjump_cache();
99 redirect('admin_categories.php', 'Category deleted. Redirecting …');
101 else // If the user hasn't comfirmed the delete
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);
106 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories';
107 require PUN_ROOT
.'header.php';
109 generate_admin_menu('categories');
112 <div
class="blockform">
113 <h2
><span
>Category delete
</span
></h2
>
115 <form method
="post" action
="admin_categories.php">
117 <input type
="hidden" name
="cat_to_delete" value
="<?php echo $cat_to_delete ?>" />
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
>
126 <p
><input type
="submit" name
="del_cat_comply" value
="Delete" /><a href
="javascript:history.go(-1)">Go back
</a
></p
>
130 <div
class="clearer"></div
>
134 require PUN_ROOT
.'footer.php';
139 else if (isset($_POST['update'])) // Change position and name of the categories
141 confirm_referrer('admin_categories.php');
143 $cat_order = $_POST['cat_order'];
144 $cat_name = $_POST['cat_name'];
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);
149 for ($i = 0; $i < $num_cats; ++
$i)
151 if ($cat_name[$i] == '')
152 message('You must enter a category name.');
154 if (!@preg_match
('#^\d+$#', $cat_order[$i]))
155 message('Position must be an integer value.');
157 list($cat_id, $position) = $db->fetch_row($result);
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());
162 // Regenerate the quickjump cache
163 require_once PUN_ROOT
.'include/cache.php';
164 generate_quickjump_cache();
166 redirect('admin_categories.php', 'Categories updated. Redirecting …');
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);
174 for ($i = 0; $i < $num_cats; ++
$i)
175 $cat_list[] = $db->fetch_row($result);
178 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories';
179 require PUN_ROOT
.'header.php';
181 generate_admin_menu('categories');
184 <div
class="blockform">
185 <h2
><span
>Add
/remove
/edit categories
</span
></h2
>
187 <form method
="post" action
="admin_categories.php?action=foo">
190 <legend
>Add
/delete categories
</legend
>
191 <div
class="infldset">
192 <table
class="aligntop" cellspacing
="0">
194 <th scope
="row">Add a
new category
<div
><input type
="submit" name
="add_cat" value
="Add New" tabindex
="2" /></div
></th
>
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
>
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
>
203 <select name
="cat_to_delete" tabindex
="3">
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";
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
>
214 <?php
endif; ?
> </table
>
218 <?php
if ($num_cats): ?
> <div
class="inform">
220 <legend
>Edit categories
</legend
>
221 <div
class="infldset">
222 <table id
="categoryedit" cellspacing
="0" >
225 <th
class="tcl" scope
="col">Name
</th
>
226 <th scope
="col">Position
</th
>
234 for ($i = 0; $i < $num_cats; ++
$i)
236 list(, list($cat_id, $cat_name, $position)) = @each
($cat_list);
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
>
247 <div
class="fsetsubmit"><input type
="submit" name
="update" value
="Update" /></div
>
251 <?php
endif; ?
> </form
>
254 <div
class="clearer"></div
>
258 require PUN_ROOT
.'footer.php';