punbb/admin_categories.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 3 c0c445d4a13e
--- a/punbb/admin_categories.php	Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/admin_categories.php	Thu Jul 12 01:04:01 2007 -0400
@@ -26,12 +26,15 @@
 // Tell header.php to use the admin template
 define('PUN_ADMIN_CONSOLE', 1);
 
-define('PUN_ROOT', './');
-require PUN_ROOT.'include/common.php';
+//define('PUN_ROOT', './');
+//require PUN_ROOT.'include/common.php';
+
+global $pun_db, $pun_user, $pun_config, $lang_common;
+
 require PUN_ROOT.'include/common_admin.php';
 
 
-if ($pun_user['g_id'] > PUN_ADMIN)
+if ($pun_user['g_id'] < PUN_ADMIN)
 	message($lang_common['No permission']);
 
 
@@ -44,9 +47,9 @@
 	if ($new_cat_name == '')
 		message('You must enter a name for the category.');
 
-	$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());
+	$pun_db->query('INSERT INTO '.$pun_db->prefix.'categories (cat_name) VALUES(\''.$pun_db->escape($new_cat_name).'\')') or error('Unable to create category', __FILE__, __LINE__, $pun_db->error());
 
-	redirect('admin_categories.php', 'Category added. Redirecting &hellip;');
+	pun_redirect('admin_categories.php', 'Category added. Redirecting &hellip;');
 }
 
 
@@ -63,45 +66,45 @@
 	{
 		@set_time_limit(0);
 
-		$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());
-		$num_forums = $db->num_rows($result);
+		$result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
+		$num_forums = $pun_db->num_rows($result);
 
 		for ($i = 0; $i < $num_forums; ++$i)
 		{
-			$cur_forum = $db->result($result, $i);
+			$cur_forum = $pun_db->result($result, $i);
 
 			// Prune all posts and topics
 			prune($cur_forum, 1, -1);
 
 			// Delete the forum
-			$db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $db->error());
+			$pun_db->query('DELETE FROM '.$pun_db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $pun_db->error());
 		}
 
 		// Locate any "orphaned redirect topics" and delete them
-		$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());
-		$num_orphans = $db->num_rows($result);
+		$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());
+		$num_orphans = $pun_db->num_rows($result);
 
 		if ($num_orphans)
 		{
 			for ($i = 0; $i < $num_orphans; ++$i)
-				$orphans[] = $db->result($result, $i);
+				$orphans[] = $pun_db->result($result, $i);
 
-			$db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
+			$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());
 		}
 
 		// Delete the category
-		$db->query('DELETE FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $db->error());
+		$pun_db->query('DELETE FROM '.$pun_db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $pun_db->error());
 
 		// Regenerate the quickjump cache
 		require_once PUN_ROOT.'include/cache.php';
 		generate_quickjump_cache();
 
-		redirect('admin_categories.php', 'Category deleted. Redirecting &hellip;');
+		pun_redirect('admin_categories.php', 'Category deleted. Redirecting &hellip;');
 	}
 	else	// If the user hasn't comfirmed the delete
 	{
-		$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());
-		$cat_name = $db->result($result);
+		$result = $pun_db->query('SELECT cat_name FROM '.$pun_db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to fetch category info', __FILE__, __LINE__, $pun_db->error());
+		$cat_name = $pun_db->result($result);
 
 		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories';
 		require PUN_ROOT.'header.php';
@@ -143,8 +146,8 @@
 	$cat_order = $_POST['cat_order'];
 	$cat_name = $_POST['cat_name'];
 
-	$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());
-	$num_cats = $db->num_rows($result);
+	$result = $pun_db->query('SELECT id, disp_position FROM '.$pun_db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $pun_db->error());
+	$num_cats = $pun_db->num_rows($result);
 
 	for ($i = 0; $i < $num_cats; ++$i)
 	{
@@ -154,25 +157,25 @@
 		if (!@preg_match('#^\d+$#', $cat_order[$i]))
 			message('Position must be an integer value.');
 
-		list($cat_id, $position) = $db->fetch_row($result);
+		list($cat_id, $position) = $pun_db->fetch_row($result);
 
-		$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());
+		$pun_db->query('UPDATE '.$pun_db->prefix.'categories SET cat_name=\''.$pun_db->escape($cat_name[$i]).'\', disp_position='.$cat_order[$i].' WHERE id='.$cat_id) or error('Unable to update category', __FILE__, __LINE__, $pun_db->error());
 	}
 
 	// Regenerate the quickjump cache
 	require_once PUN_ROOT.'include/cache.php';
 	generate_quickjump_cache();
 
-	redirect('admin_categories.php', 'Categories updated. Redirecting &hellip;');
+	pun_redirect('admin_categories.php', 'Categories updated. Redirecting &hellip;');
 }
 
 
 // Generate an array with all categories
-$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());
-$num_cats = $db->num_rows($result);
+$result = $pun_db->query('SELECT id, cat_name, disp_position FROM '.$pun_db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $pun_db->error());
+$num_cats = $pun_db->num_rows($result);
 
 for ($i = 0; $i < $num_cats; ++$i)
-	$cat_list[] = $db->fetch_row($result);
+	$cat_list[] = $pun_db->fetch_row($result);
 
 
 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories';