--- a/punbb/admin_forums.php Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/admin_forums.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,13 +47,13 @@
if ($add_to_cat < 1)
message($lang_common['Bad request']);
- $db->query('INSERT INTO '.$db->prefix.'forums (cat_id) VALUES('.$add_to_cat.')') or error('Unable to create forum', __FILE__, __LINE__, $db->error());
+ $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());
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php', 'Forum added. Redirecting …');
+ pun_redirect('admin_forums.php', 'Forum added. Redirecting …');
}
@@ -71,31 +74,31 @@
prune($forum_id, 1, -1);
// 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 forum and any forum specific group permissions
- $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to delete forum', __FILE__, __LINE__, $db->error());
- $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to delete forum', __FILE__, __LINE__, $pun_db->error());
+ $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());
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php', 'Forum deleted. Redirecting …');
+ pun_redirect('admin_forums.php', 'Forum deleted. Redirecting …');
}
else // If the user hasn't confirmed the delete
{
- $result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
- $forum_name = pun_htmlspecialchars($db->result($result));
+ $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());
+ $forum_name = pun_htmlspecialchars($pun_db->result($result));
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums';
@@ -140,14 +143,14 @@
if (!@preg_match('#^\d+$#', $disp_position))
message('Position must be a positive integer value.');
- $db->query('UPDATE '.$db->prefix.'forums SET disp_position='.$disp_position.' WHERE id='.intval($forum_id)) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
+ $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());
}
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php', 'Forums updated. Redirecting …');
+ pun_redirect('admin_forums.php', 'Forums updated. Redirecting …');
}
@@ -175,16 +178,16 @@
if ($cat_id < 1)
message($lang_common['Bad request']);
- $forum_desc = ($forum_desc != '') ? '\''.$db->escape($forum_desc).'\'' : 'NULL';
- $redirect_url = ($redirect_url != '') ? '\''.$db->escape($redirect_url).'\'' : 'NULL';
+ $forum_desc = ($forum_desc != '') ? '\''.$pun_db->escape($forum_desc).'\'' : 'NULL';
+ $redirect_url = ($redirect_url != '') ? '\''.$pun_db->escape($redirect_url).'\'' : 'NULL';
- $db->query('UPDATE '.$db->prefix.'forums SET forum_name=\''.$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__, $db->error());
+ $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());
// Now let's deal with the permissions
if (isset($_POST['read_forum_old']))
{
- $result = $db->query('SELECT g_id, g_read_board, g_post_replies, g_post_topics FROM '.$db->prefix.'groups WHERE g_id!='.PUN_ADMIN) or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
- while ($cur_group = $db->fetch_assoc($result))
+ $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());
+ while ($cur_group = $pun_db->fetch_assoc($result))
{
$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']]);
$post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? '1' : '0';
@@ -195,13 +198,13 @@
{
// If the new settings are identical to the default settings for this group, delete it's row in forum_perms
if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics'])
- $db->query('DELETE FROM '.$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__, $db->error());
+ $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());
else
{
// Run an UPDATE and see if it affected a row, if not, INSERT
- $db->query('UPDATE '.$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__, $db->error());
- if (!$db->affected_rows())
- $db->query('INSERT INTO '.$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__, $db->error());
+ $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());
+ if (!$pun_db->affected_rows())
+ $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());
}
}
}
@@ -211,28 +214,28 @@
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php', 'Forum updated. Redirecting …');
+ pun_redirect('admin_forums.php', 'Forum updated. Redirecting …');
}
else if (isset($_POST['revert_perms']))
{
confirm_referrer('admin_forums.php');
- $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
+ $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());
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php?edit_forum='.$forum_id, 'Permissions reverted to defaults. Redirecting …');
+ pun_redirect('admin_forums.php?edit_forum='.$forum_id, 'Permissions reverted to defaults. Redirecting …');
}
// Fetch forum info
- $result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
- if (!$db->num_rows($result))
+ $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());
+ if (!$pun_db->num_rows($result))
message($lang_common['Bad request']);
- $cur_forum = $db->fetch_assoc($result);
+ $cur_forum = $pun_db->fetch_assoc($result);
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums';
@@ -265,8 +268,8 @@
<select name="cat_id" tabindex="3">
<?php
- $result = $db->query('SELECT id, cat_name FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
- while ($cur_cat = $db->fetch_assoc($result))
+ $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());
+ while ($cur_cat = $pun_db->fetch_assoc($result))
{
$selected = ($cur_cat['id'] == $cur_forum['cat_id']) ? ' selected="selected"' : '';
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";
@@ -310,9 +313,9 @@
<tbody>
<?php
- $result = $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 '.$db->prefix.'groups AS g LEFT JOIN '.$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__, $db->error());
+ $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());
- while ($cur_perm = $db->fetch_assoc($result))
+ while ($cur_perm = $pun_db->fetch_assoc($result))
{
$read_forum = ($cur_perm['read_forum'] != '0') ? true : false;
$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;
@@ -384,8 +387,8 @@
<select name="add_to_cat" tabindex="1">
<?php
- $result = $db->query('SELECT id, cat_name FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
- while ($cur_cat = $db->fetch_assoc($result))
+ $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());
+ while ($cur_cat = $pun_db->fetch_assoc($result))
echo "\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'">'.pun_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
?>
@@ -409,10 +412,10 @@
$tabindex_count = 4;
// Display all the categories and forums
-$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.disp_position FROM '.$db->prefix.'categories AS c INNER JOIN '.$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__, $db->error());
+$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());
$cur_category = 0;
-while ($cur_forum = $db->fetch_assoc($result))
+while ($cur_forum = $pun_db->fetch_assoc($result))
{
if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
{