punbb/admin_prune.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 3 c0c445d4a13e
--- a/punbb/admin_prune.php	Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/admin_prune.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']);
 
 
@@ -49,12 +52,12 @@
 
 		if ($prune_from == 'all')
 		{
-			$result = $db->query('SELECT id FROM '.$db->prefix.'forums') 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') 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)
 			{
-				$fid = $db->result($result, $i);
+				$fid = $pun_db->result($result, $i);
 
 				prune($fid, $_POST['prune_sticky'], $prune_date);
 				update_forum($fid);
@@ -68,18 +71,18 @@
 		}
 
 		// 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());
 		}
 
-		redirect('admin_prune.php', 'Posts pruned. Redirecting &hellip;');
+		pun_redirect('admin_prune.php', 'Posts pruned. Redirecting &hellip;');
 	}
 
 
@@ -91,7 +94,7 @@
 	$prune_from = $_POST['prune_from'];
 
 	// Concatenate together the query for counting number or topics to prune
-	$sql = 'SELECT COUNT(id) FROM '.$db->prefix.'topics WHERE last_post<'.$prune_date.' AND moved_to IS NULL';
+	$sql = 'SELECT COUNT(id) FROM '.$pun_db->prefix.'topics WHERE last_post<'.$prune_date.' AND moved_to IS NULL';
 
 	if ($_POST['prune_sticky'] == '0')
 		$sql .= ' AND sticky=\'0\'';
@@ -102,14 +105,14 @@
 		$sql .= ' AND forum_id='.$prune_from;
 
 		// Fetch the forum name (just for cosmetic reasons)
-		$result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$prune_from) or error('Unable to fetch forum name', __FILE__, __LINE__, $db->error());
-		$forum = '"'.pun_htmlspecialchars($db->result($result)).'"';
+		$result = $pun_db->query('SELECT forum_name FROM '.$pun_db->prefix.'forums WHERE id='.$prune_from) or error('Unable to fetch forum name', __FILE__, __LINE__, $pun_db->error());
+		$forum = '"'.pun_htmlspecialchars($pun_db->result($result)).'"';
 	}
 	else
 		$forum = 'all forums';
 
-	$result = $db->query($sql) or error('Unable to fetch topic prune count', __FILE__, __LINE__, $db->error());
-	$num_topics = $db->result($result);
+	$result = $pun_db->query($sql) or error('Unable to fetch topic prune count', __FILE__, __LINE__, $pun_db->error());
+	$num_topics = $pun_db->result($result);
 
 	if (!$num_topics)
 		message('There are no topics that are '.$prune_days.' days old. Please decrease the value of "Days old" and try again.');
@@ -190,10 +193,10 @@
 											<option value="all">All forums</option>
 <?php
 
-	$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
+	$result = $pun_db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$pun_db->prefix.'categories AS c INNER JOIN '.$pun_db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $pun_db->error());
 
 	$cur_category = 0;
-	while ($forum = $db->fetch_assoc($result))
+	while ($forum = $pun_db->fetch_assoc($result))
 	{
 		if ($forum['cid'] != $cur_category)	// Are we still in the same category?
 		{