acl_get('a_forum'))
{
return;
}
$file = basename(__FILE__);
$module['Forums']['Manage'] = $file . $SID;
return;
}
define('IN_PHPBB', 1);
//
// Include files
//
$phpbb_root_path = '../';
require($phpbb_root_path . 'extension.inc');
require('pagestart.' . $phpEx);
include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
//
// Do we have forum admin permissions?
//
if (!$auth->acl_get('a_forum'))
{
message_die(MESSAGE, $lang['No_admin']);
}
//
// Mode setting
//
if (isset($_POST['mode']) || isset($_GET['mode']))
{
$mode = (!empty($_POST['mode'])) ? $_POST['mode'] : $_GET['mode'];
}
else
{
$mode = '';
}
switch ($mode)
{
case 'move_up':
case 'move_down':
$show_index = TRUE;
$forum_id = intval($_GET['f']);
$result = $db->sql_query('SELECT parent_id, left_id, right_id FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id");
if (!$row = $db->sql_fetchrow($result))
{
message_die(ERROR, 'Forum does not exist');
}
extract($row);
$forum_info = array($forum_id => $row);
//
// Get the adjacent forum
//
if ($mode == 'move_up')
{
$sql = 'SELECT forum_id, left_id, right_id
FROM ' . FORUMS_TABLE . "
WHERE parent_id = $parent_id AND right_id < $right_id
ORDER BY right_id DESC";
}
else
{
$sql = 'SELECT forum_id, left_id, right_id
FROM ' . FORUMS_TABLE . "
WHERE parent_id = $parent_id AND left_id > $left_id
ORDER BY left_id ASC";
}
$result = $db->sql_query_limit($sql, 1);
if (!$row = $db->sql_fetchrow($result))
{
//
// already on top or at bottom
//
break;
}
if ($mode == 'move_up')
{
$up_id = $forum_id;
$down_id = $row['forum_id'];
}
else
{
$up_id = $row['forum_id'];
$down_id = $forum_id;
}
$forum_info[$row['forum_id']] = $row;
$diff_up = $forum_info[$up_id]['right_id'] - $forum_info[$up_id]['left_id'];
$diff_down = $forum_info[$down_id]['right_id'] - $forum_info[$down_id]['left_id'];
//
// I should consider using transactions here
//
$forum_ids = array();
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE . '
WHERE left_id > ' . $forum_info[$up_id]['left_id'] . ' AND right_id < ' . $forum_info[$up_id]['right_id'];
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$forum_ids[] = $row['forum_id'];
}
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET left_id = left_id + ' . ($diff_up + 1) . ', right_id = right_id + ' . ($diff_up + 1) . '
WHERE left_id > ' . $forum_info[$down_id]['left_id'] . ' AND right_id < ' . $forum_info[$down_id]['right_id'];
$db->sql_query($sql);
if (count($forum_ids))
{
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET left_id = left_id - ' . ($diff_down + 1) . ', right_id = right_id - ' . ($diff_down + 1) . '
WHERE forum_id IN (' . implode(', ', $forum_ids) . ')';
$db->sql_query($sql);
}
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET left_id = ' . $forum_info[$down_id]['left_id'] . ', right_id = ' . ($forum_info[$down_id]['left_id'] + $diff_up) . '
WHERE forum_id = ' . $up_id;
$db->sql_query($sql);
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET left_id = ' . ($forum_info[$up_id]['right_id'] - $diff_down) . ', right_id = ' . $forum_info[$up_id]['right_id'] . '
WHERE forum_id = ' . $down_id;
$db->sql_query($sql);
break;
case 'create':
if (!trim($_POST['forum_name']))
{
message_die(ERROR, 'Cannot create a forum without a name');
}
$parent_id = (!empty($_POST['parent_id'])) ? $_POST['parent_id'] : 0;
$forum_status = (!empty($_POST['is_category'])) ? ITEM_CATEGORY : $_POST['forum_status'];
$forum_name = str_replace("\'", "''", $_POST['forum_name']);
$forum_desc = str_replace("\'", "''", $_POST['forum_desc']);
$forum_style = (!empty($_POST['forum_style'])) ? intval($_POST['forum_style']) : 'NULL';
$post_count_inc = (!empty($_POST['disable_post_count'])) ? 0 : 1;
$prune_enable = (!empty($_POST['prune_enable'])) ? 1 : 0;
$prune_days = intval($_POST['prune_days']);
$prune_freq = intval($_POST['prune_freq']);
$result = $db->sql_query('SELECT MAX(forum_id) AS max_id FROM ' . FORUMS_TABLE);
$forum_id = $db->sql_fetchfield('max_id', 0, $result) + 1;
if ($parent_id)
{
$result = $db->sql_query('SELECT left_id, right_id FROM ' . FORUMS_TABLE . " WHERE forum_id = $parent_id");
if (!$row = $db->sql_fetchrow($result))
{
message_die(ERROR, 'Parent does not exist');
}
extract($row);
$db->sql_query('UPDATE ' . FORUMS_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 WHERE left_id > $right_id");
$db->sql_query('UPDATE ' . FORUMS_TABLE . " SET right_id = right_id + 2 WHERE $left_id BETWEEN left_id AND right_id");
$left_id = $right_id;
++$right_id;
}
else
{
$result = $db->sql_query('SELECT MAX(right_id) AS right_id FROM ' . FORUMS_TABLE);
$left_id = $db->sql_fetchfield('right_id', 0, $result) + 1;
$right_id = $left_id + 1;
}
$sql = 'INSERT INTO ' . FORUMS_TABLE . " (forum_id, forum_name, forum_desc, parent_id, left_id, right_id, forum_status, forum_style, post_count_inc, prune_enable, prune_days, prune_freq)
VALUES ($forum_id, '$forum_name', '$forum_desc', $parent_id, $left_id, $right_id, $forum_status, $forum_style, $post_count_inc, $prune_enable, $prune_days, $prune_freq)";
$db->sql_query($sql);
$message = $lang['Forums_updated'] . "
" . sprintf($lang['Click_return_forumadmin'], '', '') . '
' . sprintf($lang['Click_return_admin_index'], '', '');
message_die(MESSAGE, $message);
break;
case 'modify':
if (!$forum_id = intval($_POST['forum_id']))
{
message_die(ERROR, 'No forum specified');
}
$row = get_forum_info($forum_id);
$parent_id = intval($_POST['parent_id']);
$action = (!empty($_POST['action'])) ? $_POST['action'] : '';
if (($row['parent_id'] != $parent_id) && ($parent_id != -1))
{
move_forum($forum_id, $parent_id);
}
$sql = array(
'forum_name' => (!empty($_POST['forum_name'])) ? stripslashes($_POST['forum_name']) : $row['forum_name'],
'forum_desc' => (!empty($_POST['forum_desc'])) ? stripslashes($_POST['forum_desc']) : $row['forum_desc'],
'forum_status' => (!empty($_POST['set_category']) && $action) ? ITEM_CATEGORY : intval($_POST['forum_status']),
'forum_style' => (!empty($_POST['forum_style'])) ? $_POST['forum_style'] : NULL,
'parent_id' => $parent_id,
'prune_enable' => (!empty($_POST['prune_enable'])) ? 1 : 0,
'prune_days' => intval($_POST['prune_days']),
'prune_freq' => intval($_POST['prune_freq']),
'display_on_index' => (!isset($_POST['display_on_index']) || !empty($_POST['display_on_index'])) ? 1 : 0,
'post_count_inc' => (!empty($_POST['disable_post_count'])) ? 0 : 1
);
if (!empty($_POST['set_category']) && $action)
{
if ($action == 'move' && $_POST['to_forum_id'])
{
move_forum_content($forum_id, $_POST['to_forum_id']);
}
elseif ($action == 'delete')
{
delete_forum_content($forum_id);
}
$sql['forum_posts'] = 0;
$sql['forum_topics'] = 0;
}
$db->sql_query_array('UPDATE ' . FORUMS_TABLE . " SET WHERE forum_id = $forum_id", $sql);
$message = $lang['Forums_updated'] . "
" . sprintf($lang['Click_return_forumadmin'], '', '') . '
' . sprintf($lang['Click_return_admin_index'], '', '');
message_die(MESSAGE, $message);
break;
case 'remove':
if (empty($_POST['submit']))
{
//
// wasn't this form submitted? is anyone trying to remotely delete forums
//
message_die(ERROR, 'Did not submit');
}
$action_subforums = (!empty($_POST['action_subforums'])) ? $_POST['action_subforums'] : '';
$action_posts = (!empty($_POST['action_posts'])) ? $_POST['action_posts'] : '';
$row = get_forum_info($_GET['f']);
extract($row);
if ($action_posts == 'delete')
{
delete_forum_content($forum_id);
}
elseif ($action_posts == 'move')
{
if (empty($_POST['posts_to_id']))
{
$message = $lang['No_destination_forum'] . '
' . sprintf($lang['Click_return_forumadmin'], '', '');
message_die(ERROR, $message);
}
move_forum_content($forum_id, $_POST['posts_to_id']);
}
if ($action_subforums == 'delete')
{
$forum_ids = array($forum_id);
$rows = get_forum_branch($forum_id, 'children', 'descending', FALSE);
foreach ($rows as $row)
{
$forum_ids[] = $row['forum_id'];
delete_forum_content($row['forum_id']);
}
$diff = count($forum_ids) * 2;
$db->sql_query('DELETE FROM ' . FORUMS_TABLE . ' WHERE forum_id IN (' . implode(', ', $forum_ids) . ')');
}
elseif ($action_subforums == 'move')
{
if (empty($_POST['subforums_to_id']))
{
$message = $lang['No_destination_forum'] . '
' . sprintf($lang['Click_return_forumadmin'], '', '');
message_die(ERROR, $message);
}
$result = $db->sql_query('SELECT forum_id FROM ' . FORUMS_TABLE . " WHERE parent_id = $forum_id");
while ($row = $db->sql_fetchrow($result))
{
move_forum($row['forum_id'], $_POST['subforums_to_id']);
}
$db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET parent_id = ' . $_POST['subforums_to_id'] . " WHERE parent_id = $forum_id");
$diff = 2;
$db->sql_query('DELETE FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id");
}
else
{
$diff = 2;
$db->sql_query('DELETE FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id");
}
//
// Resync tree
//
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET right_id = right_id - $diff
WHERE left_id < $right_id AND right_id > $right_id";
$db->sql_query($sql);
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET left_id = left_id - $diff, right_id = right_id - $diff
WHERE left_id > $right_id";
$db->sql_query($sql);
$return_id = (!empty($_POST['subforums_to_id'])) ? $_POST['subforums_to_id'] : $parent_id;
$message = $lang['Forum_deleted'] . '
' . sprintf($lang['Click_return_forumadmin'], '', '');
message_die(MESSAGE, $message);
break;
case 'forum_sync':
sync('forum', intval($_GET[POST_FORUM_URL]));
$show_index = TRUE;
break;
case 'add':
case 'edit':
//
// Show form to create/modify a forum
//
if ($mode == 'edit')
{
$forum_id = intval($_GET['f']);
$row = get_forum_info($forum_id);
extract($row);
$subforums_id = array();
$subforums = get_forum_branch($forum_id, 'children');
foreach ($subforums as $row)
{
$subforums_id[] = $row['forum_id'];
}
$parents_list = make_forums_list('all', $parent_id, $subforums_id);
$l_title = ($forum_status != ITEM_CATEGORY) ? $lang['Edit_forum'] : $lang['Edit_category'];
$newmode = 'modify';
$buttonvalue = $lang['Update'];
$prune_enabled = ($prune_enable) ? 'checked="checked" ' : '';
if ($forum_status != ITEM_CATEGORY)
{
$forums_list = make_forums_list('forums', 0, $forum_id);
}
}
else
{
$parent_id = 0;
if (!empty($_POST['parent_id']))
{
list($parent_id) = each($_POST['parent_id']);
}
$parents_list = make_forums_list('all', $parent_id);
$l_title = $lang['Create_forum'];
$newmode = 'create';
$buttonvalue = $lang['Create_forum'];
$forum_desc = '';
$forum_style = '';
$forum_status = ITEM_UNLOCKED;
$forum_name = (!empty($_POST['forum_name'][$parent_id])) ? htmlspecialchars($_POST['forum_name'][$parent_id]) : '';
$post_count_inc = TRUE;
$prune_enabled = '';
$prune_days = 7;
$prune_freq = 1;
}
$styles_list = make_styles_list($forum_style);
$forumlocked = ($forum_status == ITEM_LOCKED) ? ' selected="selected"' : '';
$forumunlocked = ($forum_status == ITEM_UNLOCKED || $forum_status == ITEM_CATEGORY) ? ' selected="selected"' : '';
$forum_checked = ($forum_status != ITEM_CATEGORY) ? 'checked="checked" ' : '';
$category_checked = ($forum_status == ITEM_CATEGORY) ? 'checked="checked" ' : '';
$statuslist = '\n";
$statuslist .= '\n";
page_header($l_title);
?>
Here you can add, edit, delete, lock, unlock individual forums as well as set certain additional controls. If your posts and topics have got out of sync you can also resynchronise a forum. In phpBB 2.2 there are no categories, everything is forum based. Each forum can have an unlimited number of sub-forums and you can determine whether each may be posted to or not (i.e. whether it acts like an old category).