punbb/admin_forums.php
changeset 6 5e1f1e916419
parent 5 e3d7322305bf
child 7 98bbc533541c
equal deleted inserted replaced
5:e3d7322305bf 6:5e1f1e916419
     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 
       
    32 global $pun_db, $pun_user, $pun_config, $lang_common;
       
    33 
       
    34 require PUN_ROOT.'include/common_admin.php';
       
    35 
       
    36 
       
    37 if ($pun_user['g_id'] < PUN_ADMIN)
       
    38 	message($lang_common['No permission']);
       
    39 
       
    40 
       
    41 // Add a "default" forum
       
    42 if (isset($_POST['add_forum']))
       
    43 {
       
    44 	confirm_referrer('admin_forums.php');
       
    45 
       
    46 	$add_to_cat = intval($_POST['add_to_cat']);
       
    47 	if ($add_to_cat < 1)
       
    48 		message($lang_common['Bad request']);
       
    49 
       
    50 	$pun_db->query('INSERT INTO '.$pun_db->prefix.'forums (cat_id) VALUES('.$add_to_cat.')') or error('Unable to create forum', __FILE__, __LINE__, $pun_db->error());
       
    51 
       
    52 	// Regenerate the quickjump cache
       
    53 	require_once PUN_ROOT.'include/cache.php';
       
    54 	generate_quickjump_cache();
       
    55 
       
    56 	pun_redirect('admin_forums.php', 'Forum added. Redirecting &hellip;');
       
    57 }
       
    58 
       
    59 
       
    60 // Delete a forum
       
    61 else if (isset($_GET['del_forum']))
       
    62 {
       
    63 	confirm_referrer('admin_forums.php');
       
    64 
       
    65 	$forum_id = intval($_GET['del_forum']);
       
    66 	if ($forum_id < 1)
       
    67 		message($lang_common['Bad request']);
       
    68 
       
    69 	if (isset($_POST['del_forum_comply']))	// Delete a forum with all posts
       
    70 	{
       
    71 		@set_time_limit(0);
       
    72 
       
    73 		// Prune all posts and topics
       
    74 		prune($forum_id, 1, -1);
       
    75 
       
    76 		// Locate any "orphaned redirect topics" and delete them
       
    77 		$result = $pun_db->query('SELECT t1.id FROM '.$pun_db->prefix.'topics AS t1 LEFT JOIN '.$pun_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__, $pun_db->error());
       
    78 		$num_orphans = $pun_db->num_rows($result);
       
    79 
       
    80 		if ($num_orphans)
       
    81 		{
       
    82 			for ($i = 0; $i < $num_orphans; ++$i)
       
    83 				$orphans[] = $pun_db->result($result, $i);
       
    84 
       
    85 			$pun_db->query('DELETE FROM '.$pun_db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $pun_db->error());
       
    86 		}
       
    87 
       
    88 		// Delete the forum and any forum specific group permissions
       
    89 		$pun_db->query('DELETE FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to delete forum', __FILE__, __LINE__, $pun_db->error());
       
    90 		$pun_db->query('DELETE FROM '.$pun_db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $pun_db->error());
       
    91 
       
    92 		// Regenerate the quickjump cache
       
    93 		require_once PUN_ROOT.'include/cache.php';
       
    94 		generate_quickjump_cache();
       
    95 
       
    96 		pun_redirect('admin_forums.php', 'Forum deleted. Redirecting &hellip;');
       
    97 	}
       
    98 	else	// If the user hasn't confirmed the delete
       
    99 	{
       
   100 		$result = $pun_db->query('SELECT forum_name FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $pun_db->error());
       
   101 		$forum_name = pun_htmlspecialchars($pun_db->result($result));
       
   102 
       
   103 
       
   104 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums';
       
   105 		require PUN_ROOT.'header.php';
       
   106 
       
   107 		generate_admin_menu('forums');
       
   108 
       
   109 ?>
       
   110 	<div class="blockform">
       
   111 		<h2><span>Confirm delete forum</span></h2>
       
   112 		<div class="box">
       
   113 			<form method="post" action="<?php echo makeUrlNS('Special', 'Forum/Admin_forums', 'del_forum=' . $forum_id, true); ?>">
       
   114 				<div class="inform">
       
   115 					<fieldset>
       
   116 						<legend>Important! Read before deleting</legend>
       
   117 						<div class="infldset">
       
   118 							<p>Are you sure that you want to delete the forum "<?php echo $forum_name ?>"?</p>
       
   119 							<p>WARNING! Deleting a forum will delete all posts (if any) in that forum!</p>
       
   120 						</div>
       
   121 					</fieldset>
       
   122 				</div>
       
   123 				<p><input type="submit" name="del_forum_comply" value="Delete" /><a href="javascript:history.go(-1)">Go back</a></p>
       
   124 			</form>
       
   125 		</div>
       
   126 	</div>
       
   127 	<div class="clearer"></div>
       
   128 </div>
       
   129 <?php
       
   130 
       
   131 		require PUN_ROOT.'footer.php';
       
   132 	}
       
   133 }
       
   134 
       
   135 
       
   136 // Update forum positions
       
   137 else if (isset($_POST['update_positions']))
       
   138 {
       
   139 	confirm_referrer('admin_forums.php');
       
   140 
       
   141 	while (list($forum_id, $disp_position) = @each($_POST['position']))
       
   142 	{
       
   143 		if (!@preg_match('#^\d+$#', $disp_position))
       
   144 			message('Position must be a positive integer value.');
       
   145 
       
   146 		$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET disp_position='.$disp_position.' WHERE id='.intval($forum_id)) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error());
       
   147 	}
       
   148 
       
   149 	// Regenerate the quickjump cache
       
   150 	require_once PUN_ROOT.'include/cache.php';
       
   151 	generate_quickjump_cache();
       
   152 
       
   153 	pun_redirect('admin_forums.php', 'Forums updated. Redirecting &hellip;');
       
   154 }
       
   155 
       
   156 
       
   157 else if (isset($_GET['edit_forum']))
       
   158 {
       
   159 	$forum_id = intval($_GET['edit_forum']);
       
   160 	if ($forum_id < 1)
       
   161 		message($lang_common['Bad request']);
       
   162 
       
   163 	// Update group permissions for $forum_id
       
   164 	if (isset($_POST['save']))
       
   165 	{
       
   166 		confirm_referrer('admin_forums.php');
       
   167 
       
   168 		// Start with the forum details
       
   169 		$forum_name = trim($_POST['forum_name']);
       
   170 		$forum_desc = pun_linebreaks(trim($_POST['forum_desc']));
       
   171 		$cat_id = intval($_POST['cat_id']);
       
   172 		$sort_by = intval($_POST['sort_by']);
       
   173 		$redirect_url = isset($_POST['redirect_url']) ? trim($_POST['redirect_url']) : null;
       
   174 
       
   175 		if ($forum_name == '')
       
   176 			message('You must enter a forum name.');
       
   177 
       
   178 		if ($cat_id < 1)
       
   179 			message($lang_common['Bad request']);
       
   180 
       
   181 		$forum_desc = ($forum_desc != '') ? '\''.$pun_db->escape($forum_desc).'\'' : 'NULL';
       
   182 		$redirect_url = ($redirect_url != '') ? '\''.$pun_db->escape($redirect_url).'\'' : 'NULL';
       
   183 
       
   184 		$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET forum_name=\''.$pun_db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error());
       
   185 
       
   186 		// Now let's deal with the permissions
       
   187 		if (isset($_POST['read_forum_old']))
       
   188 		{
       
   189 			$result = $pun_db->query('SELECT g_id, g_read_board, g_post_replies, g_post_topics FROM '.$pun_db->prefix.'groups WHERE g_id!='.PUN_ADMIN) or error('Unable to fetch user group list', __FILE__, __LINE__, $pun_db->error());
       
   190 			while ($cur_group = $pun_db->fetch_assoc($result))
       
   191 			{
       
   192 				$read_forum_new = ($cur_group['g_read_board'] == '1') ? isset($_POST['read_forum_new'][$cur_group['g_id']]) ? '1' : '0' : intval($_POST['read_forum_old'][$cur_group['g_id']]);
       
   193 				$post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? '1' : '0';
       
   194 				$post_topics_new = isset($_POST['post_topics_new'][$cur_group['g_id']]) ? '1' : '0';
       
   195 
       
   196 				// Check if the new settings differ from the old
       
   197 				if ($read_forum_new != $_POST['read_forum_old'][$cur_group['g_id']] || $post_replies_new != $_POST['post_replies_old'][$cur_group['g_id']] || $post_topics_new != $_POST['post_topics_old'][$cur_group['g_id']])
       
   198 				{
       
   199 					// If the new settings are identical to the default settings for this group, delete it's row in forum_perms
       
   200 					if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics'])
       
   201 						$pun_db->query('DELETE FROM '.$pun_db->prefix.'forum_perms WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $pun_db->error());
       
   202 					else
       
   203 					{
       
   204 						// Run an UPDATE and see if it affected a row, if not, INSERT
       
   205 						$pun_db->query('UPDATE '.$pun_db->prefix.'forum_perms SET read_forum='.$read_forum_new.', post_replies='.$post_replies_new.', post_topics='.$post_topics_new.' WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to insert group forum permissions', __FILE__, __LINE__, $pun_db->error());
       
   206 						if (!$pun_db->affected_rows())
       
   207 							$pun_db->query('INSERT INTO '.$pun_db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new.')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $pun_db->error());
       
   208 					}
       
   209 				}
       
   210 			}
       
   211 		}
       
   212 
       
   213 		// Regenerate the quickjump cache
       
   214 		require_once PUN_ROOT.'include/cache.php';
       
   215 		generate_quickjump_cache();
       
   216 
       
   217 		pun_redirect('admin_forums.php', 'Forum updated. Redirecting &hellip;');
       
   218 	}
       
   219 	else if (isset($_POST['revert_perms']))
       
   220 	{
       
   221 		confirm_referrer('admin_forums.php');
       
   222 
       
   223 		$pun_db->query('DELETE FROM '.$pun_db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $pun_db->error());
       
   224 
       
   225 		// Regenerate the quickjump cache
       
   226 		require_once PUN_ROOT.'include/cache.php';
       
   227 		generate_quickjump_cache();
       
   228 
       
   229 		pun_redirect('admin_forums.php?edit_forum='.$forum_id, 'Permissions reverted to defaults. Redirecting &hellip;');
       
   230 	}
       
   231 
       
   232 
       
   233 	// Fetch forum info
       
   234 	$result = $pun_db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $pun_db->error());
       
   235 	if (!$pun_db->num_rows($result))
       
   236 		message($lang_common['Bad request']);
       
   237 
       
   238 	$cur_forum = $pun_db->fetch_assoc($result);
       
   239 
       
   240 
       
   241 	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums';
       
   242 	require PUN_ROOT.'header.php';
       
   243 
       
   244 	generate_admin_menu('forums');
       
   245 
       
   246 ?>
       
   247 	<div class="blockform">
       
   248 		<h2><span>Edit forum</span></h2>
       
   249 		<div class="box">
       
   250 			<form id="edit_forum" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Admin_forums', 'edit_forum=' . $forum_id, true); ?>">
       
   251 				<p class="submittop"><input type="submit" name="save" value="Save changes" tabindex="6" /></p>
       
   252 				<div class="inform">
       
   253 					<fieldset>
       
   254 						<legend>Edit forum details</legend>
       
   255 						<div class="infldset">
       
   256 							<table class="aligntop" cellspacing="0">
       
   257 								<tr>
       
   258 									<th scope="row">Forum name</th>
       
   259 									<td><input type="text" name="forum_name" size="35" maxlength="80" value="<?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?>" tabindex="1" /></td>
       
   260 								</tr>
       
   261 								<tr>
       
   262 									<th scope="row">Description (HTML)</th>
       
   263 									<td><textarea name="forum_desc" rows="3" cols="50" tabindex="2"><?php echo pun_htmlspecialchars($cur_forum['forum_desc']) ?></textarea></td>
       
   264 								</tr>
       
   265 								<tr>
       
   266 									<th scope="row">Category</th>
       
   267 									<td>
       
   268 										<select name="cat_id" tabindex="3">
       
   269 <?php
       
   270 
       
   271 	$result = $pun_db->query('SELECT id, cat_name FROM '.$pun_db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $pun_db->error());
       
   272 	while ($cur_cat = $pun_db->fetch_assoc($result))
       
   273 	{
       
   274 		$selected = ($cur_cat['id'] == $cur_forum['cat_id']) ? ' selected="selected"' : '';
       
   275 		echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'"'.$selected.'>'.pun_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
       
   276 	}
       
   277 
       
   278 ?>
       
   279 										</select>
       
   280 									</td>
       
   281 								</tr>
       
   282 								<tr>
       
   283 									<th scope="row">Sort topics by</th>
       
   284 									<td>
       
   285 										<select name="sort_by" tabindex="4">
       
   286 											<option value="0"<?php if ($cur_forum['sort_by'] == '0') echo ' selected="selected"' ?>>Last post</option>
       
   287 											<option value="1"<?php if ($cur_forum['sort_by'] == '1') echo ' selected="selected"' ?>>Topic start</option>
       
   288 										</select>
       
   289 									</td>
       
   290 								</tr>
       
   291 								<tr>
       
   292 									<th scope="row">Redirect URL</th>
       
   293 									<td><?php echo ($cur_forum['num_topics']) ? 'Only available in empty forums' : '<input type="text" name="redirect_url" size="45" maxlength="100" value="'.pun_htmlspecialchars($cur_forum['redirect_url']).'" tabindex="5" />'; ?></td>
       
   294 								</tr>
       
   295 							</table>
       
   296 						</div>
       
   297 					</fieldset>
       
   298 				</div>
       
   299 				<div class="inform">
       
   300 					<fieldset>
       
   301 						<legend>Edit group permissions for this forum</legend>
       
   302 						<div class="infldset">
       
   303 							<p>In this form, you can set the forum specific permissions for the different user groups. If you haven't made any changes to this forums group permissions, what you see below is the default based on settings in <a href="admin_groups.php">User groups</a>. Administrators always have full permissions and are thus excluded. Permission settings that differ from the default permissions for the user group are marked red. The "Read forum" permission checkbox will be disabled if the group in question lacks the "Read board" permission. For redirect forums, only the "Read forum" permission is editable.</p>
       
   304 							<table id="forumperms" cellspacing="0">
       
   305 							<thead>
       
   306 								<tr>
       
   307 									<th class="atcl">&nbsp;</th>
       
   308 									<th>Read forum</th>
       
   309 									<th>Post replies</th>
       
   310 									<th>Post topics</th>
       
   311 								</tr>
       
   312 							</thead>
       
   313 							<tbody>
       
   314 <?php
       
   315 
       
   316 	$result = $pun_db->query('SELECT g.g_id, g.g_title, g.g_read_board, g.g_post_replies, g.g_post_topics, fp.read_forum, fp.post_replies, fp.post_topics FROM '.$pun_db->prefix.'groups AS g LEFT JOIN '.$pun_db->prefix.'forum_perms AS fp ON (g.g_id=fp.group_id AND fp.forum_id='.$forum_id.') WHERE g.g_id!='.PUN_ADMIN.' ORDER BY g.g_id') or error('Unable to fetch group forum permission list', __FILE__, __LINE__, $pun_db->error());
       
   317 
       
   318 	while ($cur_perm = $pun_db->fetch_assoc($result))
       
   319 	{
       
   320 		$read_forum = ($cur_perm['read_forum'] != '0') ? true : false;
       
   321 		$post_replies = (($cur_perm['g_post_replies'] == '0' && $cur_perm['post_replies'] == '1') || ($cur_perm['g_post_replies'] == '1' && $cur_perm['post_replies'] != '0')) ? true : false;
       
   322 		$post_topics = (($cur_perm['g_post_topics'] == '0' && $cur_perm['post_topics'] == '1') || ($cur_perm['g_post_topics'] == '1' && $cur_perm['post_topics'] != '0')) ? true : false;
       
   323 
       
   324 		// Determine if the current sittings differ from the default or not
       
   325 		$read_forum_def = ($cur_perm['read_forum'] == '0') ? false : true;
       
   326 		$post_replies_def = (($post_replies && $cur_perm['g_post_replies'] == '0') || (!$post_replies && ($cur_perm['g_post_replies'] == '' || $cur_perm['g_post_replies'] == '1'))) ? false : true;
       
   327 		$post_topics_def = (($post_topics && $cur_perm['g_post_topics'] == '0') || (!$post_topics && ($cur_perm['g_post_topics'] == '' || $cur_perm['g_post_topics'] == '1'))) ? false : true;
       
   328 
       
   329 ?>
       
   330 								<tr>
       
   331 									<th class="atcl"><?php echo pun_htmlspecialchars($cur_perm['g_title']) ?></th>
       
   332 									<td<?php if (!$read_forum_def) echo ' class="nodefault"'; ?>>
       
   333 										<input type="hidden" name="read_forum_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($read_forum) ? '1' : '0'; ?>" />
       
   334 										<input type="checkbox" name="read_forum_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($read_forum) ? ' checked="checked"' : ''; ?><?php echo ($cur_perm['g_read_board'] == '0') ? ' disabled="disabled"' : ''; ?> />
       
   335 									</td>
       
   336 									<td<?php if (!$post_replies_def && $cur_forum['redirect_url'] == '') echo ' class="nodefault"'; ?>>
       
   337 										<input type="hidden" name="post_replies_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_replies) ? '1' : '0'; ?>" />
       
   338 										<input type="checkbox" name="post_replies_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_replies) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> />
       
   339 									</td>
       
   340 									<td<?php if (!$post_topics_def && $cur_forum['redirect_url'] == '') echo ' class="nodefault"'; ?>>
       
   341 										<input type="hidden" name="post_topics_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_topics) ? '1' : '0'; ?>" />
       
   342 										<input type="checkbox" name="post_topics_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_topics) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> />
       
   343 									</td>
       
   344 								</tr>
       
   345 <?php
       
   346 
       
   347 	}
       
   348 
       
   349 ?>
       
   350 							</tbody>
       
   351 							</table>
       
   352 							<div class="fsetsubmit"><input type="submit" name="revert_perms" value="Revert to default" /></div>
       
   353 						</div>
       
   354 					</fieldset>
       
   355 				</div>
       
   356 				<p class="submitend"><input type="submit" name="save" value="Save changes" /></p>
       
   357 			</form>
       
   358 		</div>
       
   359 	</div>
       
   360 	<div class="clearer"></div>
       
   361 </div>
       
   362 
       
   363 <?php
       
   364 
       
   365 	require PUN_ROOT.'footer.php';
       
   366 }
       
   367 
       
   368 
       
   369 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums';
       
   370 require PUN_ROOT.'header.php';
       
   371 
       
   372 generate_admin_menu('forums');
       
   373 
       
   374 ?>
       
   375 	<div class="blockform">
       
   376 		<h2><span>Add forum</span></h2>
       
   377 		<div class="box">
       
   378 			<form method="post" action="<?php echo makeUrlNS('Special', 'Forum/Admin_forums', 'action=adddel', true); ?>">
       
   379 				<div class="inform">
       
   380 					<fieldset>
       
   381 						<legend>Create a new forum</legend>
       
   382 						<div class="infldset">
       
   383 							<table class="aligntop" cellspacing="0">
       
   384 								<tr>
       
   385 									<th scope="row">Add forum to category<div><input type="submit" name="add_forum" value=" Add " tabindex="2" /></div></th>
       
   386 									<td>
       
   387 										<select name="add_to_cat" tabindex="1">
       
   388 <?php
       
   389 
       
   390 	$result = $pun_db->query('SELECT id, cat_name FROM '.$pun_db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $pun_db->error());
       
   391 	while ($cur_cat = $pun_db->fetch_assoc($result))
       
   392 		echo "\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'">'.pun_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
       
   393 
       
   394 ?>
       
   395 										</select>
       
   396 										<span>Select the category to which you wish to add a new forum.</span>
       
   397 									</td>
       
   398 								</tr>
       
   399 							</table>
       
   400 						</div>
       
   401 					</fieldset>
       
   402 				</div>
       
   403 			</form>
       
   404 		</div>
       
   405 
       
   406 		<h2 class="block2"><span>Edit forums</span></h2>
       
   407 		<div class="box">
       
   408 			<form id="edforum" method="post" action="<?php echo makeUrlNS('Special', 'Forum/Admin_forums', 'action=edit', true); ?>">
       
   409 				<p class="submittop"><input type="submit" name="update_positions" value="Update positions" tabindex="3" /></p>
       
   410 <?php
       
   411 
       
   412 $tabindex_count = 4;
       
   413 
       
   414 // Display all the categories and forums
       
   415 $result = $pun_db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.disp_position FROM '.$pun_db->prefix.'categories AS c INNER JOIN '.$pun_db->prefix.'forums AS f ON c.id=f.cat_id ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $pun_db->error());
       
   416 
       
   417 $cur_category = 0;
       
   418 while ($cur_forum = $pun_db->fetch_assoc($result))
       
   419 {
       
   420 	if ($cur_forum['cid'] != $cur_category)	// A new category since last iteration?
       
   421 	{
       
   422 		if ($cur_category != 0)
       
   423 			echo "\t\t\t\t\t\t\t".'</table>'."\n\t\t\t\t\t\t".'</div>'."\n\t\t\t\t\t".'</fieldset>'."\n\t\t\t\t".'</div>'."\n";
       
   424 
       
   425 ?>
       
   426 				<div class="inform">
       
   427 					<fieldset>
       
   428 						<legend>Category: <?php echo pun_htmlspecialchars($cur_forum['cat_name']) ?></legend>
       
   429 						<div class="infldset">
       
   430 							<table cellspacing="0">
       
   431 <?php
       
   432 
       
   433 		$cur_category = $cur_forum['cid'];
       
   434 	}
       
   435 
       
   436 ?>
       
   437 								<tr>
       
   438 									<th><a href="<?php echo makeUrlNS('Special', 'Forum/Admin_forums', 'edit_forum=' . $cur_forum['fid'], true); ?>">Edit</a> - <a href="<?php echo makeUrlNS('Special', 'Forum/Admin_forums', 'del_forum=' . $cur_forum['fid'], true); ?>">Delete</a></th>
       
   439 									<td>Position&nbsp;&nbsp;<input type="text" name="position[<?php echo $cur_forum['fid'] ?>]" size="3" maxlength="3" value="<?php echo $cur_forum['disp_position'] ?>" tabindex="<?php echo $tabindex_count ?>" />
       
   440 									&nbsp;&nbsp;<strong><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></strong></td>
       
   441 								</tr>
       
   442 <?php
       
   443 
       
   444 	$tabindex_count += 2;
       
   445 }
       
   446 
       
   447 ?>
       
   448 							</table>
       
   449 						</div>
       
   450 					</fieldset>
       
   451 				</div>
       
   452 				<p class="submitend"><input type="submit" name="update_positions" value="Update positions" tabindex="<?php echo $tabindex_count ?>" /></p>
       
   453 			</form>
       
   454 		</div>
       
   455 	</div>
       
   456 	<div class="clearer"></div>
       
   457 </div>
       
   458 <?php
       
   459 
       
   460 require PUN_ROOT.'footer.php';