aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/adm/admin_forums.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/adm/admin_forums.php')
-rw-r--r--phpBB/adm/admin_forums.php1455
1 files changed, 849 insertions, 606 deletions
diff --git a/phpBB/adm/admin_forums.php b/phpBB/adm/admin_forums.php
index 528c124649..4e4c92fa47 100644
--- a/phpBB/adm/admin_forums.php
+++ b/phpBB/adm/admin_forums.php
@@ -37,545 +37,454 @@ require($phpbb_root_path . 'extension.inc');
require('pagestart.' . $phpEx);
// Get mode
-$mode = (isset($_REQUEST['mode'])) ? $_REQUEST['mode'] : '';
+$mode = (isset($_REQUEST['mode'])) ? htmlspecialchars($_REQUEST['mode']) : '';
// Do we have permissions?
switch ($mode)
{
case 'add':
- if (!$auth->acl_get('a_forumadd'))
- {
- trigger_error($user->lang['NO_ADMIN']);
- }
- case 'del':
- if (!$auth->acl_get('a_forumdel'))
- {
- trigger_error($user->lang['NO_ADMIN']);
- }
-
+ $acl = 'a_forumadd';
+ break;
+ case 'delete':
+ $acl = 'a_forumdel';
+ break;
default:
- if (!$auth->acl_get('a_forum'))
- {
- trigger_error($user->lang['NO_ADMIN']);
- }
+ $acl = 'a_forum';
}
-// Major routines
-switch ($mode)
+if (!$auth->acl_get($acl))
{
- case 'move_up':
- case 'move_down':
- $show_index = TRUE;
- $forum_id = intval($_GET['this_f']);
-
- $sql = 'SELECT parent_id, left_id, right_id
- FROM ' . FORUMS_TABLE . "
- WHERE forum_id = $forum_id";
- $result = $db->sql_query($sql);
-
- if (!($row = $db->sql_fetchrow($result)))
- {
- trigger_error($user->lang['NO_FORUM']);
- }
- $db->sql_freeresult($result);
-
- extract($row);
-
- $forum_info = array($forum_id => $row);
-
- // Get the adjacent forum
- $sql = 'SELECT forum_id, left_id, right_id
- FROM ' . FORUMS_TABLE . "
- WHERE parent_id = $parent_id";
- $sql .= ($mode == 'move_up') ? " AND right_id < $right_id ORDER BY right_id DESC" : " 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;
- }
- $db->sql_freeresult($result);
-
- 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'];
-
- $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'];
- }
- $db->sql_freeresult($result);
-
- // Start transaction
- $db->sql_transaction();
-
- $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);
-
- $db->sql_transaction('commit');
- break;
+ trigger_error($user->lang['NO_ADMIN']);
+}
- case 'create':
- if (!trim($_POST['forum_name']))
- {
- trigger_error('Cannot create a forum without a name'); // Needs to be a lang string
- }
- $parent_id = (!empty($_POST['parent_id'])) ? intval($_POST['parent_id']) : 0;
+// Major routines
+switch ($mode)
+{
+ case 'add':
+ case 'edit':
- if ($parent_id)
+ $action = (isset($_POST['action'])) ? htmlspecialchars($_POST['action']) : '';
+ $forum_id = (isset($_REQUEST['this_f'])) ? intval($_REQUEST['this_f']) : ((isset($_REQUEST['f'])) ? intval($_REQUEST['f']) : 0);
+ $parent_id = (isset($_REQUEST['parent_id'])) ? intval($_REQUEST['parent_id']) : 0;
+
+ $forum_type = (isset($_POST['forum_type'])) ? intval($_POST['forum_type']) : FORUM_POST;
+ $forum_status = (isset($_POST['forum_status'])) ? intval($_POST['forum_status']) : ITEM_UNLOCKED;
+ $forum_name = (isset($_POST['forum_name'])) ? htmlspecialchars($_POST['forum_name']) : '';
+ $forum_link = (isset($_POST['forum_link'])) ? htmlspecialchars($_POST['forum_link']) : '';
+ $forum_link_track = (!empty($_POST['forum_link_track'])) ? 1 : 0;
+ $forum_desc = (isset($_POST['forum_desc'])) ? str_replace("\n", '<br />', $_POST['forum_desc']) : '';
+ $forum_image = (isset($_POST['forum_image'])) ? htmlspecialchars($_POST['forum_image']) : '';
+ $forum_style = (isset($_POST['forum_style'])) ? intval($_POST['forum_style']) : 0;
+ $display_on_index = (!empty($_POST['display_on_index'])) ? 1 : 0;
+ $forum_topics_per_page = (isset($_POST['topics_per_page'])) ? intval($_POST['topics_per_page']) : 0;
+ $enable_icons = (!empty($_POST['enable_icons'])) ? 1 : 0;
+ $enable_prune = (!empty($_POST['enable_prune'])) ? 1 : 0;
+ $prune_days = (isset($_POST['prune_days'])) ? intval($_POST['prune_days']) : 7;
+ $prune_freq = (isset($_POST['prune_freq'])) ? intval($_POST['prune_freq']) : 1;
+ $forum_password = (isset($_POST['forum_password'])) ? intval($_POST['forum_password']) : '';
+ $forum_password_confirm = (isset($_POST['forum_password_confirm'])) ? intval($_POST['forum_password_confirm']) : '';
+
+ if (isset($_POST['update']))
{
- $sql = 'SELECT left_id, right_id
- FROM ' . FORUMS_TABLE . "
- WHERE forum_id = $parent_id";
- $result = $db->sql_query($sql);
-
- if (!($row = $db->sql_fetchrow($result)))
+ $error = array();
+ if (!trim($_POST['forum_name']))
{
- trigger_error('Parent does not exist', E_USER_ERROR);
+ $error[] = $user->lang['FORUM_NAME_EMPTY'];
}
- $db->sql_freeresult($result);
- 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");
+ if (!empty($password) || !empty($password_confirm))
+ {
+ if ($password != $password_confirm)
+ {
+ $error[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
+ }
+ }
- $left_id = $right_id;
- ++$right_id;
- }
- else
- {
- $sql = 'SELECT MAX(right_id) AS right_id
- FROM ' . FORUMS_TABLE;
- $result = $db->sql_query($sql);
+ if ($prune_days < 0 || $prune_freq < 0)
+ {
+ $error[] = $user->lang['FORUM_DATA_NEGATIVE'];
+ }
- $left_id = $db->sql_fetchfield('right_id', 0, $result) + 1;
- $db->sql_freeresult($result);
+ // What are we going to do tonight Brain? The same thing we do everynight,
+ // try to take over the world ... or decide whether to continue update
+ // and if so, whether it's a new forum/cat/link or an existing one
+ if (sizeof($error))
+ {
+ $error = implode('<br />', $error);
+ }
+ else if (!$forum_id)
+ {
+ if ($parent_id)
+ {
+ $sql = 'SELECT left_id, right_id
+ FROM ' . FORUMS_TABLE . "
+ WHERE forum_id = $parent_id";
+ $result = $db->sql_query($sql);
+
+ if (!($row = $db->sql_fetchrow($result)))
+ {
+ trigger_error('Parent does not exist', E_USER_ERROR);
+ }
+ $db->sql_freeresult($result);
+
+ extract($row);
+ unset($row);
+
+ $sql = 'UPDATE ' . FORUMS_TABLE . "
+ SET left_id = left_id + 2, right_id = right_id + 2
+ WHERE left_id > $right_id";
+ $db->sql_query($sql);
+
+ $sql = 'UPDATE ' . FORUMS_TABLE . "
+ SET right_id = right_id + 2
+ WHERE $left_id BETWEEN left_id AND right_id";
+ $db->sql_query($sql);
+
+ $left_id = $right_id;
+ ++$right_id;
+ }
+ else
+ {
+ $sql = 'SELECT MAX(right_id) AS right_id
+ FROM ' . FORUMS_TABLE;
+ $result = $db->sql_query($sql);
- $right_id = $left_id + 1;
- }
+ $left_id = $db->sql_fetchfield('right_id', 0, $result) + 1;
+ $db->sql_freeresult($result);
- $sql = array(
- 'parent_id' => $parent_id,
- 'left_id' => $left_id,
- 'right_id' => $right_id,
- 'forum_status' => intval($_POST['forum_status']),
- 'forum_postable' => (!empty($_POST['forum_postable'])) ? 1 : 0,
- 'forum_name' => $_POST['forum_name'],
- 'forum_desc' => $_POST['forum_desc'],
- 'forum_style' => (!empty($_POST['forum_style'])) ? intval($_POST['forum_style']) : 'NULL',
- 'enable_icons' => (!empty($_POST['enable_icons'])) ? 1 : 0,
- 'enable_prune' => (!empty($_POST['prune_enable'])) ? 1 : 0,
- 'prune_days' => intval($_POST['prune_days']),
- 'prune_freq' => intval($_POST['prune_freq'])
- );
- $db->sql_query('INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql));
-
- $forum_id = $db->sql_nextid();
+ $right_id = $left_id + 1;
+ }
- // Redirect to permissions
- redirect('adm/admin_permissions.' . $phpEx . $SID . '&mode=forums&f=' . $forum_id);
+ $sql = array(
+ 'parent_id' => $parent_id,
+ 'left_id' => $left_id,
+ 'right_id' => $right_id,
+
+ 'forum_name' => $forum_name,
+ 'forum_desc' => $forum_desc,
+ 'forum_type' => $forum_type,
+ 'forum_status' => $forum_status,
+ 'forum_link' => $forum_link,
+ 'forum_link_track' => $forum_link_track,
+ 'forum_password' => $forum_password,
+ 'forum_topics_per_page' => $forum_topics_per_page,
+ 'forum_style' => $forum_style,
+ 'forum_image' => $forum_image,
+ 'display_on_index' => $display_on_index,
+ 'enable_icons' => $enable_icons,
+ 'enable_prune' => $enable_prune,
+ 'prune_days' => $prune_days,
+ 'prune_freq' => $prune_freq,
+ );
+
+ $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
+ $db->sql_query($sql);
+
+ $forum_id = $db->sql_nextid();
+
+ add_log('admin', 'LOG_FORUM_ADD', $forum_name);
+
+ // Redirect to permissions
+ $message = $user->lang['FORUM_UPDATED'] . '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], "<a href=\"admin_permissions.$phpEx$SID&amp;mode=forum&amp;submit_usergroups=true&amp;ug_type=forum&amp;action=usergroups&amp;f[forum][]=$forum_id\">", '</a>');
+ trigger_error($message);
- break;
+ }
+ else
+ {
+ $row = get_forum_info($forum_id);
- case 'modify':
- if (!($forum_id = intval($_POST['f'])))
- {
- trigger_error('No forum specified'); // lang string
- }
+ if ($row['forum_type'] != $forum_type && $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;
+ }
- $row = get_forum_info($forum_id);
- $parent_id = intval($_POST['parent_id']);
- $action = (!empty($_POST['action'])) ? $_POST['action'] : '';
+ if ($row['parent_id'] != $parent_id)
+ {
+ move_forum($forum_id, $parent_id);
+ }
+ elseif ($row['forum_name'] != $forum_name)
+ {
+ $sql = 'UPDATE ' . FORUMS_TABLE . "
+ SET forum_parents = ''
+ WHERE left_id > " . $row['left_id'] . '
+ AND right_id < ' . $row['right_id'];
+ $db->sql_query($sql);
+ }
- if (($row['parent_id'] != $parent_id) && ($parent_id != -1))
- {
- move_forum($forum_id, $parent_id);
- }
- elseif ($row['forum_name'] != $_POST['forum_name'])
- {
- $sql = 'UPDATE ' . FORUMS_TABLE . "
- SET forum_parents = ''
- WHERE left_id > " . $row['left_id'] . '
- AND right_id < ' . $row['right_id'];
- $db->sql_query($sql);
+ $sql = array(
+ 'parent_id' => $parent_id,
+
+ 'forum_name' => $forum_name,
+ 'forum_desc' => $forum_desc,
+ 'forum_type' => $forum_type,
+ 'forum_status' => $forum_status,
+ 'forum_link' => $forum_link,
+ 'forum_link_track' => $forum_link_track,
+ 'forum_topics_per_page' => $forum_topics_per_page,
+ 'forum_password' => $forum_password,
+ 'forum_style' => $forum_style,
+ 'forum_image' => $forum_image,
+ 'display_on_index' => $display_on_index,
+ 'enable_icons' => $enable_icons,
+ 'enable_prune' => $enable_prune,
+ 'prune_days' => $prune_days,
+ 'prune_freq' => $prune_freq,
+ );
+
+ $sql = 'UPDATE ' . FORUMS_TABLE . '
+ SET ' . $db->sql_build_array('UPDATE', $sql) . "
+ WHERE forum_id = $forum_id";
+ $db->sql_query($sql);
+
+ add_log('admin', 'LOG_FORUM_EDIT', $forum_name);
+
+ trigger_error($user->lang['FORUM_UPDATED']);
+ }
}
- $sql = array(
- 'parent_id' => $parent_id,
- 'forum_name' => (!empty($_POST['forum_name'])) ? $_POST['forum_name'] : $row['forum_name'],
- 'forum_desc' => (!empty($_POST['forum_desc'])) ? $_POST['forum_desc'] : $row['forum_desc'],
- 'forum_status' => intval($_POST['forum_status']),
- 'forum_postable' => (!empty($_POST['is_postable'])) ? 1 : 0,
- 'forum_style' => (!empty($_POST['forum_style'])) ? $_POST['forum_style'] : NULL,
- 'forum_image' => (!empty($_POST['forum_image'])) ? $_POST['forum_image'] : '',
- 'display_on_index' => (!empty($_POST['display_on_index'])) ? 1 : 0,
- 'enable_icons' => (!empty($_POST['enable_icons'])) ? 1 : 0,
- 'enable_prune' => (!empty($_POST['prune_enable'])) ? 1 : 0,
- 'prune_days' => intval($_POST['prune_days']),
- 'prune_freq' => intval($_POST['prune_freq']),
- );
-
- if (!empty($_POST['set_nonpostable']) && $action)
+ // Show form to create/modify a forum
+ if ($mode == 'edit')
{
- if ($action == 'move' && $_POST['to_forum_id'])
+ $l_title = $user->lang['EDIT_FORUM'];
+
+ $forum_data = get_forum_info($forum_id);
+ if (!isset($_POST['forum_type']))
{
- move_forum_content($forum_id, $_POST['to_forum_id']);
+ extract($forum_data);
}
- elseif ($action == 'delete')
+ else
{
- delete_forum_content($forum_id);
+ $old_forum_type = $forum_data['forum_type'];
}
+ unset($forum_data);
- $sql['forum_posts'] = 0;
- $sql['forum_topics'] = 0;
- }
-
- $db->sql_query('UPDATE ' . FORUMS_TABLE . '
- SET ' . $db->sql_build_array('UPDATE', $sql) . "
- WHERE forum_id = $forum_id");
-
- trigger_error($user->lang['FORUM_UPDATED']);
-
- break;
-
- case 'remove':
-
- $action_subforums = (!empty($_POST['action_subforums'])) ? $_POST['action_subforums'] : '';
- $action_posts = (!empty($_POST['action_posts'])) ? $_POST['action_posts'] : '';
-
- $row = get_forum_info(intval($_GET['f']));
- extract($row);
-
- if ($action_posts == 'delete')
- {
- delete_forum_content($forum_id);
+ $parents_list = make_forum_select($parent_id, $forum_id, false, false, false);
+ $forums_list = make_forum_select($parent_id, $forum_id, false, true, false);
+
}
- elseif ($action_posts == 'move')
+ else
{
- if (empty($_POST['posts_to_id']))
- {
- trigger_error($user->lang['No_destination_forum']);
- }
+ $l_title = $user->lang['CREATE_FORUM'];
- move_forum_content($forum_id, $_POST['posts_to_id']);
+ $forum_id = $parent_id;
+ $parents_list = make_forum_select($parent_id);
}
- if ($action_subforums == 'delete')
+ $forum_type_options = '';
+ $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
+ foreach ($forum_type_ary as $value => $lang)
{
- $forum_ids = array($forum_id);
- $rows = get_forum_branch($forum_id, 'children', 'descending', FALSE);
+ $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_type) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
+ }
- foreach ($rows as $row)
- {
- $forum_ids[] = $row['forum_id'];
- delete_forum_content($row['forum_id']);
- }
+ $styles_list = style_select($forum_style);
- $diff = count($forum_ids) * 2;
+ $statuslist = '<option value="' . ITEM_UNLOCKED . '"' . (($forum_status == ITEM_UNLOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['UNLOCKED'] . '</option><option value="' . ITEM_LOCKED . '"' . (($forum_status == ITEM_LOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['LOCKED'] . '</option>';
- $sql = 'DELETE FROM ' . FORUMS_TABLE . '
- WHERE forum_id IN (' . implode(', ', $forum_ids) . ')';
- $db->sql_query($sql);
- }
- elseif ($action_subforums == 'move')
- {
- if (empty($_POST['subforums_to_id']))
- {
- trigger_error($user->lang['No_destination_forum']);
- }
+ $topic_icons_yes = ($enable_icons) ? 'checked="checked"' : '';
+ $topic_icons_no = (!$enable_icons) ? 'checked="checked"' : '';
- $sql = 'SELECT forum_id
- FROM ' . FORUMS_TABLE . "
- WHERE parent_id = $forum_id";
- $result = $db->sql_query($sql);
+ $display_index_yes = ($display_on_index) ? 'checked="checked"' : '';
+ $display_index_no = (!$display_on_index) ? 'checked="checked"' : '';
- while ($row = $db->sql_fetchrow($result))
- {
- move_forum($row['forum_id'], $_POST['subforums_to_id']);
- }
- $db->sql_freeresult($result);
+ $prune_enable_yes = ($prune_enabled) ? 'checked="checked"' : '';
+ $prune_enable_no = (!$prune_enabled) ? 'checked="checked"' : '';
- $sql = 'UPDATE ' . FORUMS_TABLE . '
- SET parent_id = ' . $_POST['subforums_to_id'] . "
- WHERE parent_id = $forum_id";
- $db->sql_query($sql);
+ $forum_link_track_yes = ($forum_link_track) ? 'checked="checked"' : '';
+ $forum_link_track_no = (!$forum_link_track) ? 'checked="checked"' : '';
- $diff = 2;
+ $navigation = '<a href="admin_forums.' . $phpEx . $SID . '">' . $user->lang['FORUM_INDEX'] . '</a>';
- $sql = 'DELETE FROM ' . FORUMS_TABLE . "
- WHERE forum_id = $forum_id";
- $db->sql_query($sql);
- }
- else
+ $forums_nav = get_forum_branch($forum_id, 'parents', 'descending');
+ foreach ($forums_nav as $row)
{
- $diff = 2;
- $db->sql_query('DELETE FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id");
+ $navigation .= ($row['forum_id'] == $forum_id) ? ' -&gt; ' . $row['forum_name'] : ' -&gt; <a href="admin_forums.' . $phpEx . $SID . '&amp;f=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
}
- // 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);
-
- trigger_error($user->lang['Forum_deleted']);
- break;
+ page_header($l_title);
- case 'sync':
- sync('forum', 'forum_id', intval($_GET['this_f']));
- break;
+?>
- case 'add':
- case 'edit':
- // Show form to create/modify a forum
- if ($mode == 'edit')
- {
- $forum_id = intval($_GET['this_f']);
+<p><?php echo $user->lang['FORUM_ADMIN_EXPLAIN'] ?></p>
- $row = get_forum_info($forum_id);
- extract($row);
+<h1><?php echo $l_title ?></h1>
- $subforums_id = array();
- $subforums = get_forum_branch($forum_id, 'children');
- foreach ($subforums as $row)
- {
- $subforums_id[] = $row['forum_id'];
- }
+<p><?php echo $user->lang['FORUM_EDIT_EXPLAIN'] ?></p>
- $parents_list = make_forums_list('all', $parent_id, $subforums_id);
+<form method="post" name="edit" action="<?php echo "admin_forums.$phpEx$SID&amp;mode=$mode" . (($forum_id) ? "&amp;f=$forum_id" : ''); ?>"><table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
+ <tr>
+ <td class="nav"><?php echo $navigation ?></td>
+ </tr>
+</table>
- $l_title = $user->lang['Edit_forum'];
- $newmode = 'modify';
- $buttonvalue = $user->lang['Update'];
- $prune_enabled = ($prune_enable) ? 'checked="checked" ' : '';
+<table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0" align="center">
+ <tr>
+ <th colspan="2"><?php echo $user->lang['FORUM_SETTINGS'] ?></th>
+ </tr>
+<?php
- $forums_list = make_forums_list('forums', 0, $forum_id);
- }
- else
+ if (!empty($error))
{
- $parent_id = (!empty($_POST['parent_id'])) ? $_POST['parent_id'] : 0;
- $parents_list = make_forums_list('all', $parent_id);
-
- $l_title = $user->lang['Create_forum'];
- $newmode = 'create';
- $buttonvalue = $user->lang['Create_forum'];
- $forum_id = $parent_id;
- $forum_desc = '';
- $forum_style = '';
- $forum_status = ITEM_UNLOCKED;
- $forum_name = (!empty($_POST['forum_name'])) ? htmlspecialchars($_POST['forum_name']) : '';
-
- $enable_icons = TRUE;
+?>
+ <tr>
+ <td class="row3" colspan="2" align="center"><span style="color:red"><?php echo $error; ?></span></td>
+ </tr>
+<?php
- $prune_enabled = '';
- $prune_days = 7;
- $prune_freq = 1;
}
- $styles_list = make_styles_list($forum_style);
+?>
+ <tr>
+ <td class="row1" width="33%"><?php echo $user->lang['FORUM_TYPE'] ?>: </td>
+ <td class="row2"><select name="forum_type" onchange="this.form.submit();"><?php echo $forum_type_options; ?></select><?php
+
+ if ($old_forum_type == FORUM_POST && $forum_type == FORUM_CAT)
+ {
- $forumlocked = ($forum_status == ITEM_LOCKED) ? ' selected="selected"' : '';
- $forumunlocked = ($forum_status == ITEM_UNLOCKED) ? ' selected="selected"' : '';
+?><br /><input type="radio" name="action" value="delete" checked="checked" /> <?php echo $user->lang['Delete_all_posts'] ?> &nbsp;<input type="radio" name="action" value="move" /> <?php echo $user->lang['Move_posts_to'] ?> <select name="to_forum_id"><?php echo $forums_list ?></select><?php
- $postable_checked = ($forum_postable) ? 'checked="checked" ' : '';
- $nonpostable_checked = (!$forum_postable) ? 'checked="checked" ' : '';
+ }
- $statuslist = '<option value="' . ITEM_UNLOCKED . '"' . $forumunlocked . '>' . $user->lang['Unlocked'] . "</option>\n";
- $statuslist .= '<option value="' . ITEM_LOCKED . '"' . $forumlocked . '>' . $user->lang['Locked'] . "</option>\n";
+?></td>
+ </tr>
+<?php
- page_header($l_title);
+ if ($forum_type == FORUM_POST)
+ {
?>
-<h1><?php echo $l_title ?></h1>
-
-<p><?php echo $user->lang['Forum_edit_delete_explain'] ?></p>
-
-<form action="<?php echo "admin_forums.$phpEx$SID" ?>" method="post"><table class="bg" width="100%" cellpadding="4" cellspacing="1" border="0" align="center">
- <tr>
- <th colspan="2"><?php echo $user->lang['General_settings'] ?></th>
- </tr>
- <tr>
- <td class="row1"><?php echo $user->lang['Parent'] ?></td>
- <td class="row2"><select name="parent_id"><option value="0"><?php echo $user->lang['No_parent'] ?></option><?php echo $parents_list ?></select></td>
- </tr>
- <tr>
- <td class="row1"><?php echo $user->lang['Forum_name']; ?></td>
- <td class="row2"><input class="post" type="text" size="25" name="forum_name" value="<?php echo $forum_name ?>" /></td>
- </tr>
<tr>
- <td class="row1"><?php echo $user->lang['Forum_desc'] ?></td>
- <td class="row2"><textarea class="post" rows="5" cols="45" wrap="virtual" name="forum_desc"><?php echo $forum_desc ?></textarea></td>
+ <td class="row1"><?php echo $user->lang['FORUM_STATUS'] ?>: </td>
+ <td class="row2"><select name="forum_status"><?php echo $statuslist ?></select></td>
</tr>
<?php
- if ($forum_postable && $mode == 'edit')
- {
+ }
?>
<tr>
- <td class="row1"><?php echo $user->lang['FORUM_TYPE'] ?></td>
- <td class="row2"><table width="100%" cellspacing="0" cellpadding="0" border="0">
- <tr>
- <td><input type="checkbox" name="set_nonpostable" /> <?php echo $user->lang['SET_NON_POSTABLE'] ?></td>
- </tr>
- <tr>
- <td>&nbsp; &nbsp; &nbsp;<input type="radio" name="action" value="delete" checked="checked" /> <?php echo $user->lang['Delete_all_posts'] ?></td>
- </tr>
- <tr>
- <td>&nbsp; &nbsp; &nbsp;<input type="radio" name="action" value="move" /> <?php echo $user->lang['Move_posts_to'] ?> <select name="to_forum_id"><?php echo $forums_list ?></select></td>
- </tr>
- </table></td>
+ <td class="row1" width="40%"><?php echo $user->lang['FORUM_PARENT'] ?>: </td>
+ <td class="row2"><select name="parent_id"><option value="0"><?php echo $user->lang['NO_PARENT'] ?></option><?php echo $parents_list ?></select></td>
</tr>
<?php
- }
- else
- {
+ if ($forum_type == FORUM_LINK)
+ {
?>
<tr>
- <td class="row1"><?php echo $user->lang['FORUM_TYPE'] ?></td>
- <td class="row2"><input type="radio" name="is_postable" value="1" <?php echo $postable_checked ?>/><?php echo $user->lang['IS_POSTABLE'] ?> &nbsp; <input type="radio" name="is_postable" value="0" <?php echo $nonpostable_checked ?>/><?php echo $user->lang['NOT_POSTABLE'] ?></td>
+ <td class="row1"><?php echo $user->lang['FORUM_LINK'] ?>: <br /><span class="gensmall"><?php echo $user->lang['FORUM_LINK_EXPLAIN']; ?></span></td>
+ <td class="row2"><input class="post" type="text" size="25" name="forum_link" value="<?php echo $forum_link; ?>" /></td>
+ </tr>
+ <tr>
+ <td class="row1"><?php echo $user->lang['FORUM_LINK_TRACK'] ?>: <br /><span class="gensmall"><?php echo $user->lang['FORUM_LINK_TRACK_EXPLAIN']; ?></span></td>
+ <td class="row2"><input type="radio" name="forum_link_track" value="1"<?php echo $forum_link_track_yes; ?> /> <?php echo $user->lang['YES']; ?> &nbsp; <input type="radio" name="forum_link_track" value="0"<?php echo $forum_link_track_no; ?> /> <?php echo $user->lang['NO']; ?></td>
</tr>
<?php
- }
+ }
?>
<tr>
- <th colspan="2"><?php echo $user->lang['Forum_settings'] ?></th>
+ <td class="row1"><?php echo $user->lang['FORUM_NAME']; ?>: </td>
+ <td class="row2"><input class="post" type="text" size="25" name="forum_name" value="<?php echo $forum_name ?>" /></td>
+ </tr>
+ <tr>
+ <td class="row1"><?php echo $user->lang['FORUM_DESC'] ?>: <br /><span class="gensmall"><?php echo $user->lang['FORUM_DESC_EXPLAIN']; ?></span> </td>
+ <td class="row2"><textarea class="post" rows="5" cols="45" wrap="virtual" name="forum_desc"><?php echo htmlspecialchars(str_replace('<br />', "\n", $forum_desc)); ?></textarea></td>
+ </tr>
+ <tr>
+ <td class="row1"><?php echo $user->lang['FORUM_IMAGE']; ?>: <br /><span class="gensmall"><?php echo $user->lang['FORUM_IMAGE_EXPLAIN']; ?></span></td>
+ <td class="row2"><input class="post" type="text" size="25" name="forum_image" value="<?php echo $forum_image ?>" /><br /><?php
+
+ if ($forum_image != '')
+ {
+
+ echo '<img src="../' . $forum_image . '" alt="" />';
+
+ }
+
+?></td>
</tr>
<?php
- if ($forum_postable || $mode == 'add')
- {
+ if ($forum_type == FORUM_POST)
+ {
?>
<tr>
- <td class="row1"><?php echo $user->lang['FORUM_STATUS'] ?></td>
- <td class="row2"><select name="forum_status"><?php echo $statuslist ?></select></td>
+ <td class="row1"><?php echo $user->lang['FORUM_STYLE'] ?>: </td>
+ <td class="row2"><select name="forum_style"><option value="0"><?php echo $user->lang['DEFAULT_STYLE'] ?></option><?php echo $styles_list ?></select></td>
</tr>
<tr>
- <td class="row1"><?php echo $user->lang['FORUM_STYLE'] ?></td>
- <td class="row2"><select name="forum_style"><option value="0"><?php echo $user->lang['Default_style'] ?></option><?php echo $styles_list ?></select></td>
+ <td class="row1"><?php echo $user->lang['ENABLE_TOPIC_ICONS'] ?>: </td>
+ <td class="row2"><input type="radio" name="enable_icons" value="1"<?php echo $topic_icons_yes; ?> /> <?php echo $user->lang['YES']; ?> &nbsp; <input type="radio" name="enable_icons" value="0"<?php echo $topic_icons_no; ?> /> <?php echo $user->lang['NO']; ?></td>
</tr>
- <tr>
- <td class="row1"><?php echo $user->lang['OPTIONS'] ?></td>
- <td class="row2"><table width="100%" cellspacing="0" cellpadding="0" border="0">
- <tr>
- <td><input type="checkbox" name="enable_icons"<?php echo ((!empty($enable_icons)) ? 'checked="checked" ' : ' ') ?>/> <?php echo $user->lang['ENABLE_TOPIC_ICONS']; ?></td>
- </tr>
<?php
- if ($mode == 'edit' && $parent_id > 0)
- {
- // if this forum is a subforum put the "display on index" checkbox
- if ($parent_info = get_forum_info($parent_id))
+ if ($mode == 'edit' && $parent_id > 0)
{
- if ($parent_info['parent_id'] > 0 || !$parent_info['forum_postable'])
+ // if this forum is a subforum put the "display on index" checkbox
+ if ($parent_info = get_forum_info($parent_id))
{
+ if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
+ {
?>
- <tr>
- <td><input type="checkbox" name="display_on_index"<?php echo ((!empty($display_on_index)) ? 'checked="checked" ' : ' ') ?>/> <?php echo $user->lang['Display_on_index'] ?></td>
- </tr>
+ <tr>
+ <td class="row1"><?php echo $user->lang['LIST_INDEX'] ?>: <br /><span class="gensmall"><?php echo $user->lang['LIST_INDEX_EXPLAIN']; ?></span></td>
+ <td class="row2"><input type="radio" name="display_on_index" value="1"<?php echo $display_index_yes; ?> /> <?php echo $user->lang['YES']; ?> &nbsp; <input type="radio" name="display_on_index" value="0"<?php echo $display_index_no; ?> /> <?php echo $user->lang['NO']; ?></td>
+ </tr>
<?php
+ }
}
}
- }
?>
- </td></table>
+ <tr>
+ <td class="row1"><?php echo $user->lang['FORUM_AUTO_PRUNE'] ?>: <br /><span class="gensmall"><?php echo $user->lang['FORUM_AUTO_PRUNE_EXPLAIN']; ?></span></td>
+ <td class="row2"><input type="radio" name="enable_prune" value="1"<?php echo $prune_enable_yes; ?> /> <?php echo $user->lang['YES']; ?> &nbsp; <input type="radio" name="enable_prune" value="0"<?php echo $prune_enable_no; ?> /> <?php echo $user->lang['NO']; ?></td>
</tr>
<tr>
- <td class="row1"><?php echo $user->lang['Forum_pruning'] ?></td>
- <td class="row2"><table cellspacing="0" cellpadding="1" border="0">
- <tr>
- <td align="right" valign="middle"><?php echo $user->lang['Enabled'] ?></td>
- <td align="left" valign="middle"><input type="checkbox" name="prune_enable" value="1" <?php echo $prune_enabled ?>/></td>
- </tr>
- <tr>
- <td align="right" valign="middle"><?php echo $user->lang['prune_days'] ?></td>
- <td align="left" valign="middle">&nbsp;<input class="post" type="text" name="prune_days" value="<?php echo $prune_days ?>" size="5" />&nbsp;<?php echo $user->lang['Days'] ?></td>
- </tr>
- <tr>
- <td align="right" valign="middle"><?php echo $user->lang['prune_freq'] ?></td>
- <td align="left" valign="middle">&nbsp;<input class="post" type="text" name="prune_freq" value="<?php echo $prune_freq ?>" size="5" />&nbsp;<?php echo $user->lang['Days'] ?></td>
- </tr>
- </table></td>
+ <td class="row1"><?php echo $user->lang['AUTO_PRUNE_FREQ'] ?>: <br /><span class="gensmall"><?php echo $user->lang['AUTO_PRUNE_FREQ_EXPLAIN']; ?></span></td>
+ <td class="row2"><input class="post" type="text" name="prune_freq" value="<?php echo $prune_freq ?>" size="5" /> <?php echo $user->lang['DAYS']; ?></td>
+ </tr>
+ <tr>
+ <td class="row1"><?php echo $user->lang['AUTO_PRUNE_DAYS'] ?>: <br /><span class="gensmall"><?php echo $user->lang['AUTO_PRUNE_DAYS_EXPLAIN']; ?></span></td>
+ <td class="row2"><input class="post" type="text" name="prune_days" value="<?php echo $prune_days ?>" size="5" /> <?php echo $user->lang['DAYS']; ?></td>
+ </tr>
+ <tr>
+ <td class="row1"><?php echo $user->lang['FORUM_TOPICS_PAGE'] ?>: <br /><span class="gensmall"><?php echo $user->lang['FORUM_TOPICS_PAGE_EXPLAIN']; ?></span></td>
+ <td class="row2"><input type="text" name="topics_per_page" value="<?php echo $forum_topics_per_page; ?>" size="3" maxlength="3" /></td>
+ </tr>
+ <tr>
+ <td class="row1"><?php echo $user->lang['FORUM_PASSWORD'] ?>: <br /><span class="gensmall"><?php echo $user->lang['FORUM_PASSWORD_EXPLAIN']; ?></span></td>
+ <td class="row2"><input type="password" name="forum_password" value="<?php echo $password; ?>" size="25" maxlength="200" /></td>
</tr>
-<?php
-
- }
- else
- {
-
-?>
<tr>
- <td class="row1"><?php echo $user->lang['FORUM_IMAGE']; ?></td>
- <td class="row2"><input class="post" type="text" size="25" name="forum_image" value="<?php echo $forum_image ?>" /></td>
+ <td class="row1"><?php echo $user->lang['FORUM_PASSWORD_CONFIRM'] ?>: <br /><span class="gensmall"><?php echo $user->lang['FORUM_PASSWORD_CONFIRM_EXPLAIN']; ?></span></td>
+ <td class="row2"><input type="password" name="forum_password_confirm" value="<?php echo $password_confirm; ?>" size="25" maxlength="200" /></td>
</tr>
<?php
- }
+ }
?>
<tr>
- <td class="cat" colspan="2" align="center"><input type="hidden" name="mode" value="<?php echo $newmode ?>" /><input type="hidden" name="f" value="<?php echo $forum_id ?>" /><input class="mainoption" type="submit" name="submit" value="<?php echo $buttonvalue ?>" /></td>
+ <td class="cat" colspan="2" align="center"><input class="mainoption" name="update" type="submit" value="<?php echo $user->lang['SUBMIT']; ?>" /> &nbsp;<input class="liteoption" type="reset" value="<?php echo $user->lang['RESET']; ?>" /></td>
</tr>
</table></form>
@@ -584,11 +493,172 @@ switch ($mode)
<?php
page_footer();
- break;
+ break;
case 'delete':
- page_header($user->lang['Forum_delete']);
- extract(get_forum_info(intval($_GET['this_f'])));
+
+ $forum_id = (isset($_REQUEST['this_f'])) ? intval($_REQUEST['this_f']) : ((isset($_REQUEST['f'])) ? intval($_REQUEST['f']) : 0);
+
+ if (isset($_POST['update']))
+ {
+
+ $action_subforums = (!empty($_POST['action_subforums'])) ? $_POST['action_subforums'] : '';
+ $action_posts = (!empty($_POST['action_posts'])) ? $_POST['action_posts'] : '';
+
+ $row = get_forum_info($forum_id);
+ extract($row);
+
+ $log_action_posts = $log_action_forums = '';
+ if ($action_posts == 'delete')
+ {
+ $log_action_posts = 'POSTS';
+ delete_forum_content($forum_id);
+ }
+ elseif ($action_posts == 'move')
+ {
+ if (empty($_POST['posts_to_id']))
+ {
+ trigger_error($user->lang['NO_DESTINATION_FORUM']);
+ }
+
+ $log_action_posts = 'MOVE_POSTS';
+
+ $sql = 'SELECT forum_name
+ FROM ' . FORUMS_TABLE . "
+ WHERE forum_id = " . intval($_POST['posts_to_id']);
+ $result = $db->sql_query($sql);
+
+ if (!($row = $db->sql_fetchrow($result)))
+ {
+ trigger_error($user->lang['NO_FORUM']);
+ }
+ $db->sql_freeresult($result);
+
+ $posts_to_name = $row['forum_name'];
+ unset($row);
+
+ move_forum_content($forum_id, intval($_POST['posts_to_id']));
+ }
+
+ if ($action_subforums == 'delete')
+ {
+ $log_action_forums = 'FORUMS';
+
+ $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;
+
+ $sql = 'DELETE FROM ' . FORUMS_TABLE . '
+ WHERE forum_id IN (' . implode(', ', $forum_ids) . ')';
+ $db->sql_query($sql);
+ }
+ elseif ($action_subforums == 'move')
+ {
+ if (empty($_POST['subforums_to_id']))
+ {
+ trigger_error($user->lang['NO_DESTINATION_FORUM']);
+ }
+
+ $log_action_forums = 'MOVE_FORUMS';
+
+ $sql = 'SELECT forum_name
+ FROM ' . FORUMS_TABLE . "
+ WHERE forum_id = " . intval($_POST['subforums_to_id']);
+ $result = $db->sql_query($sql);
+
+ if (!($row = $db->sql_fetchrow($result)))
+ {
+ trigger_error($user->lang['NO_FORUM']);
+ }
+ $db->sql_freeresult($result);
+
+ $subforums_to_name = $row['forum_name'];
+ unset($row);
+
+ $sql = 'SELECT forum_id
+ FROM ' . FORUMS_TABLE . "
+ WHERE parent_id = $forum_id";
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ move_forum($row['forum_id'], intval($_POST['subforums_to_id']));
+ }
+ $db->sql_freeresult($result);
+
+ $sql = 'UPDATE ' . FORUMS_TABLE . '
+ SET parent_id = ' . $_POST['subforums_to_id'] . "
+ WHERE parent_id = $forum_id";
+ $db->sql_query($sql);
+
+ $diff = 2;
+
+ $sql = 'DELETE FROM ' . FORUMS_TABLE . "
+ WHERE forum_id = $forum_id";
+ $db->sql_query($sql);
+ }
+ else
+ {
+ $diff = 2;
+ $sql = 'DELETE FROM ' . FORUMS_TABLE . "
+ WHERE forum_id = $forum_id";
+ $db->sql_query($sql);
+ }
+
+ // 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);
+
+ $log_action = implode('_', array($log_action_posts, $log_action_forums));
+
+ switch ($log_action)
+ {
+ case 'MOVE_POSTS_MOVE_FORUMS':
+ add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_name);
+ break;
+ case 'MOVE_POSTS_FORUMS':
+ add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_name);
+ break;
+ case 'POSTS_MOVE_FORUMS':
+ add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS',$subforums_to_name, $forum_name);
+ break;
+ case '_MOVE_FORUMS':
+ add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_name);
+ break;
+ case 'MOVE_POSTS_':
+ add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_name);
+ break;
+ case 'POSTS_FORUMS':
+ add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_name);
+ break;
+ case '_FORUMS':
+ add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_name);
+ break;
+ case 'POSTS_':
+ add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_name);
+ break;
+ }
+
+ trigger_error($user->lang['FORUM_DELETED']);
+ }
+
+
+ page_header($user->lang['MANAGE']);
+ extract(get_forum_info($forum_id));
$subforums_id = array();
$subforums = get_forum_branch($forum_id, 'children');
@@ -597,35 +667,41 @@ switch ($mode)
$subforums_id[] = $row['forum_id'];
}
- $forums_list = make_forums_list('all', $parent_id, $subforums_id);
- $move_posts_list = make_forums_list('forums', $parent_id, $subforums_id);
+ $forums_list = make_forum_select($parent_id, $subforums_id);
+ $move_posts_list = make_forum_select($parent_id, $subforums_id);
?>
-<h1><?php echo $user->lang['Forum_delete'] ?></h1>
-<p><?php echo $user->lang['Forum_delete_explain'] ?></p>
+<p><?php echo $user->lang['FORUM_ADMIN_EXPLAIN']; ?></p>
+
+<h1><?php echo $user->lang['FORUM_DELETE'] ?></h1>
-<form action="admin_forums.<?php echo $phpEx . $SID ?>&mode=remove&amp;f=<?php echo $forum_id ?>" method="post"><table class="bg" cellspacing="1" cellpadding="4" border="0" align="center">
+<p><?php echo $user->lang['FORUM_DELETE_EXPLAIN'] ?></p>
+
+<form action="admin_forums.<?php echo $phpEx . $SID ?>&mode=delete&amp;f=<?php echo $forum_id ?>" method="post"><table class="bg" cellspacing="1" cellpadding="4" border="0" align="center">
<tr>
- <th colspan="2"><?php echo $user->lang['Forum_delete'] ?></th>
- </tr>
+ <th colspan="2"><?php echo $user->lang['FORUM_DELETE'] ?></th>
+ </tr>
<tr>
- <td class="row1"><?php echo $user->lang['Forum_name']; ?></td>
- <td class="row1"><span class="row1"><?php echo $forum_name ?></span></td>
+ <td class="row1"><?php echo $user->lang['FORUM_NAME']; ?>: </td>
+ <td class="row1"><b><?php echo $forum_name ?></b></td>
</tr>
<?php
- if ($forum_postable)
+ if ($forum_type == FORUM_POST)
{
?>
<tr>
- <td class="row1"><?php echo $user->lang['Action'] ?></td>
- <td class="row1"><input type="radio" name="action_posts" value="delete" checked="checked" /> <?php echo $user->lang['Delete_all_posts'] ?></td>
- </tr>
- <tr>
- <td class="row1"></td>
- <td class="row1"><input type="radio" name="action_posts" value="move" /> <?php echo $user->lang['Move_posts_to'] ?> <select name="posts_to_id" ?><option value="0"></option><?php echo $move_posts_list ?></select></td>
+ <td class="row1"><?php echo $user->lang['ACTION'] ?>: </td>
+ <td class="row1"><table cellspacing="0" cellpadding="2" border="0">
+ <tr>
+ <td><input type="radio" name="action_posts" value="delete" checked="checked" /> <?php echo $user->lang['DELETE_ALL_POSTS'] ?></td>
+ </tr>
+ <tr>
+ <td><input type="radio" name="action_posts" value="move" /> <?php echo $user->lang['MOVE_POSTS_TO'] ?> <select name="posts_to_id" ?><?php echo $move_posts_list ?></select></td>
+ </tr>
+ </table></td>
</tr>
<?php
@@ -636,12 +712,15 @@ switch ($mode)
?>
<tr>
- <td class="row1"><?php echo $user->lang['Action'] ?></td>
- <td class="row1"><input type="radio" name="action_subforums" value="delete" checked="checked" /> <?php echo $user->lang['Delete_subforums'] ?></td>
- </tr>
- <tr>
- <td class="row1"></td>
- <td class="row1"><input type="radio" name="action_subforums" value="move" /> <?php echo $user->lang['Move_subforums_to'] ?> <select name="subforums_to_id" ?><option value="0"></option><?php echo $forums_list ?></select></td>
+ <td class="row1"><?php echo $user->lang['ACTION'] ?>:</td>
+ <td class="row1"><table cellspacing="0" cellpadding="2" border="0">
+ <tr>
+ <td><input type="radio" name="action_subforums" value="delete" checked="checked" /> <?php echo $user->lang['DELETE_SUBFORUMS'] ?></td>
+ </tr>
+ <tr>
+ <td><input type="radio" name="action_subforums" value="move" /> <?php echo $user->lang['MOVE_SUBFORUMS_TO'] ?> <select name="subforums_to_id" ?><?php echo $forums_list ?></select></td>
+ </tr>
+ </table></td>
</tr>
<?php
@@ -649,26 +728,148 @@ switch ($mode)
?>
<tr>
- <td class="cat" colspan="2" align="center"><input type="submit" name="submit" value="<?php echo $user->lang['Move_and_Delete'] ?>" class="mainoption" /></td>
+ <td class="cat" colspan="2" align="center"><input type="submit" name="update" value="<?php echo $user->lang['SUBMIT'] ?>" class="mainoption" /></td>
</tr>
- </table>
-</form>
+</table></form>
<?php
page_footer();
+ break;
+
+ case 'move_up':
+ case 'move_down':
+ $forum_id = intval($_GET['this_f']);
+
+ $sql = 'SELECT parent_id, left_id, right_id
+ FROM ' . FORUMS_TABLE . "
+ WHERE forum_id = $forum_id";
+ $result = $db->sql_query($sql);
+
+ if (!($row = $db->sql_fetchrow($result)))
+ {
+ trigger_error($user->lang['NO_FORUM']);
+ }
+ $db->sql_freeresult($result);
+
+ extract($row);
+
+ $forum_info = array($forum_id => $row);
+
+ // Get the adjacent forum
+ $sql = 'SELECT forum_id, forum_name, left_id, right_id
+ FROM ' . FORUMS_TABLE . "
+ WHERE parent_id = $parent_id
+ AND " . (($mode == 'move_up') ? "right_id < $right_id ORDER BY right_id DESC" : "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;
+ }
+ $db->sql_freeresult($result);
+
+ if ($mode == 'move_up')
+ {
+ $log_action = 'UP';
+ $up_id = $forum_id;
+ $down_id = $row['forum_id'];
+ }
+ else
+ {
+ $log_action = 'DOWN';
+ $up_id = $row['forum_id'];
+ $down_id = $forum_id;
+ }
+
+ $move_forum_name = $row['forum_name'];
+ $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'];
+
+ $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'];
+ }
+ $db->sql_freeresult($result);
+
+ // Start transaction
+ $db->sql_transaction();
+
+ $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);
+
+ $db->sql_transaction('commit');
+
+ $forum_data = get_forum_info($forum_id);
+ add_log('admin', 'LOG_FORUM_MOVE_' . $log_action, $forum_data['forum_name'], $move_forum_name);
+ unset($forum_data);
+ break;
+
+ case 'sync':
+ $forum_id = (isset($_REQUEST['this_f'])) ? intval($_REQUEST['this_f']) : ((isset($_REQUEST['f'])) ? intval($_REQUEST['f']) : 0);
+
+ if (!$forum_id)
+ {
+ trigger_error($user->lang['NO_FORUM']);
+ }
+
+ $sql = "SELECT forum_name
+ FROM " . FORUMS_TABLE . "
+ WHERE forum_id = $forum_id";
+ $result = $db->sql_query($sql);
+
+ if (!($row = $db->sql_fetchrow($result)))
+ {
+ trigger_error($user->lang['NO_FORUM']);
+ }
+ $db->sql_freeresult($result);
+
+ add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
- break;
+ sync('forum', 'forum_id', $forum_id);
+ break;
}
+// Default management page
+
$forum_id = (!empty($_GET['f'])) ? intval($_GET['f']) : 0;
if (!$forum_id)
{
- $navigation = $user->lang['INDEX'];
+ $navigation = $user->lang['FORUM_INDEX'];
}
else
{
- $navigation = '<a href="admin_forums.' . $phpEx . $SID . '">' . $user->lang['INDEX'] . '</a>';
+ $navigation = '<a href="admin_forums.' . $phpEx . $SID . '">' . $user->lang['FORUM_INDEX'] . '</a>';
$forums_nav = get_forum_branch($forum_id, 'parents', 'descending');
foreach ($forums_nav as $row)
@@ -694,60 +895,87 @@ page_header($user->lang['MANAGE']);
<h1><?php echo $user->lang['MANAGE']; ?></h1>
-<p><?php echo $user->lang['Forum_admin_explain']; ?></p>
+<p><?php echo $user->lang['FORUM_ADMIN_EXPLAIN']; ?></p>
-<form method="post" action="<?php echo "admin_forums.$phpEx$SID&amp;mode=add" ?>"><table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
+<form method="post" action="<?php echo "admin_forums.$phpEx$SID" ?>"><table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
<tr>
- <td><?php echo $navigation ?></td>
+ <td class="nav"><?php echo $navigation ?></td>
</tr>
</table>
-<table class="bg" width="100%" cellspacing="1" cellpadding="3" border="0" align="center">
+<table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0" align="center">
<tr>
- <th colspan="6"><?php echo $user->lang['Forum_admin'] ?></th>
+ <th colspan="6"><?php echo $user->lang['FORUM_ADMIN'] ?></th>
</tr>
<?php
-$result = $db->sql_query('SELECT * FROM ' . FORUMS_TABLE . " WHERE parent_id = $forum_id ORDER BY left_id");
+$sql = 'SELECT *
+ FROM ' . FORUMS_TABLE . "
+ WHERE parent_id = $forum_id
+ ORDER BY left_id";
+$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
- // DEBUG
- $parent_id = $row['parent_id'];
- $forum_title = $row['forum_name'];
- $forum_desc = $row['forum_desc'];
+ $forum_type = $row['forum_type'];
- if ($row['forum_status'] != ITEM_LOCKED)
+ if ($row['forum_status'] == ITEM_LOCKED)
{
- if ($row['left_id'] + 1 != $row['right_id'])
- {
- $folder_image = '<img src="images/icon_subfolder.gif" width="46" height="25" alt="' . $user->lang['SUBFORUM'] . '" alt="' . $user->lang['SUBFORUM'] . '" />';
- }
- else
- {
- $folder_image = '<img src="images/icon_folder.gif" width="46" height="25" alt="' . $user->lang['FOLDER'] . '" alt="' . $user->lang['FOLDER'] . '" />';
- }
+ $folder_image = '<img src="images/icon_folder_lock.gif" width="46" height="25" alt="' . $user->lang['LOCKED'] . '" alt="' . $user->lang['LOCKED'] . '" />';
}
else
{
- $folder_image = '<img src="images/icon_folder_lock.gif" width="46" height="25" alt="' . $user->lang['LOCKED'] . '" alt="' . $user->lang['LOCKED'] . '" />';
- }
+ switch ($forum_type)
+ {
+ case FORUM_LINK:
+ $folder_image = '<img src="images/icon_folder_link.gif" width="46" height="25" alt="' . $user->lang['LINK'] . '" alt="' . $user->lang['LINK'] . '" />';
+ break;
- $url = $phpEx . $SID . '&amp;f=' . $forum_id . '&amp;this_f=' . $row['forum_id'];
+ default:
+ $folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" width="46" height="25" alt="' . $user->lang['SUBFORUM'] . '" alt="' . $user->lang['SUBFORUM'] . '" />' : '<img src="images/icon_folder.gif" width="46" height="25" alt="' . $user->lang['FOLDER'] . '" alt="' . $user->lang['FOLDER'] . '" />';
+ }
+ }
- $forum_title = '<a href="admin_forums.' . $phpEx . $SID . '&amp;f=' . $row['forum_id'] . '">' . $forum_title . '</a>';
+ $forum_title = ($forum_type != FORUM_LINK) ? "<a href=\"admin_forums.$phpEx$SID&amp;f=" . $row['forum_id'] . '">' : '';
+ $forum_title .= $row['forum_name'];
+ $forum_title .= ($forum_type != FORUM_LINK) ? '</a>' : '';
+ $url = "$phpEx$SID&amp;f=$forum_id&amp;this_f=" . $row['forum_id'];
?>
<tr>
<td class="row1" width="5%"><?php echo $folder_image; ?></td>
- <td class="row2" width="50%"><span class="gen"><?php echo $forum_title ?></span><br /><span class="gensmall"><?php echo $forum_desc ?></span></td>
+ <td class="row1" width="50%"><table width="100%" cellspacing="0" cellpadding="0" border="0">
+ <tr>
+ <td><span class="forumlink"><?php echo $forum_title ?></span></td><?php
- <td class="row1" width="5%" align="center" valign="middle" title="<?php echo $user->lang['TOPICS']; ?>"><span class="gen"><?php echo $row['forum_topics'] ?></span></td>
- <td class="row2" width="5%" align="center" valign="middle" title="<?php echo $user->lang['POSTS']; ?>"><span class="gen"><?php echo $row['forum_posts'] ?></span></td>
+ if ($forum_type == FORUM_POST)
+ {
+
+?>
+ <td class="gensmall" align="right">&nbsp;<?php echo $user->lang['TOPICS']; ?>: <b><?php echo $row['forum_topics'] ?></b> / <?php echo $user->lang['POSTS']; ?>: <b><?php echo $row['forum_posts'] ?></b></td><?php
+
+ }
+
+?>
+ </tr>
+ </table>
+ <table cellspacing="5" cellpadding="0" border="0">
+ <tr>
+ <td class="gensmall"><?php echo $row['forum_desc'] ?></td>
+ </tr>
+ </table></td>
+ <td class="row2" width="15%" align="center" valign="middle" nowrap="nowrap"><a href="admin_forums.<?php echo $url ?>&amp;mode=move_up"><?php echo $user->lang['MOVE_UP'] ?></a><br /><a href="admin_forums.<?php echo $url ?>&amp;mode=move_down"><?php echo $user->lang['MOVE_DOWN'] ?></a></td>
+ <td class="row2" width="20%" align="center" valign="middle" nowrap="nowrap">&nbsp;<a href="admin_forums.<?php echo $url ?>&amp;mode=edit"><?php echo $user->lang['EDIT'] ?></a> | <a href="admin_forums.<?php echo $url ?>&amp;mode=delete"><?php echo $user->lang['DELETE'] ?></a><?php
+
+ if ($forum_type != FORUM_LINK)
+ {
- <td class="row2" width="15%" align="center" valign="middle" nowrap="nowrap"><span class="gen"><a href="admin_forums.<?php echo $url ?>&amp;mode=move_up"><?php echo $user->lang['MOVE_UP'] ?></a> <br /> <a href="admin_forums.<?php echo $url ?>&amp;mode=move_down"><?php echo $user->lang['MOVE_DOWN'] ?></a></span></td>
+?> | <a href="admin_forums.<?php echo $url ?>&amp;mode=sync"><?php echo $user->lang['RESYNC'] ?></a><?php
+
- <td class="row2" width="20%" align="center" valign="middle" nowrap="nowrap">&nbsp;<span class="gen"><a href="admin_forums.<?php echo $url ?>&amp;mode=edit"><?php echo $user->lang['EDIT'] ?></a> | <a href="admin_forums.<?php echo $url ?>&amp;mode=delete"><?php echo $user->lang['DELETE'] ?></a> | <a href="admin_forums.<?php echo $url ?>&amp;mode=sync"><?php echo $user->lang['Resync'] ?></a></span>&nbsp;</td>
+ }
+
+?>&nbsp;</td>
</tr>
<?php
@@ -755,16 +983,15 @@ while ($row = $db->sql_fetchrow($result))
?>
<tr>
- <td width="100%" colspan="6" class="cat"><input type="hidden" name="mode" value="add" /><input type="hidden" name="parent_id" value="<? echo $forum_id ?>" /><input type="text" name="forum_name" /> <input class="liteoption" type="submit" name="submit" value="<?php echo $user->lang['Create_forum'] ?>" /></td>
+ <td width="100%" colspan="6" class="cat"><input type="hidden" name="mode" value="add" /><input type="hidden" name="parent_id" value="<? echo $forum_id ?>" /><input type="text" name="forum_name" /> <input class="liteoption" type="submit" value="<?php echo $user->lang['CREATE_FORUM'] ?>" /></td>
</tr>
</table></form>
<form method="get" action="admin_forums.<?php echo $phpEx,$SID ?>"><table width="100%" cellpadding="1" cellspacing="1" border="0">
<tr>
- <td align="right"><?php echo $user->lang['Select_forum']; ?>: <select name="f" onchange="if(this.options[this.selectedIndex].value != -1){ this.form.submit() }"><?php echo $forum_box; ?></select> <input class="liteoption" type="submit" value="<?php echo $user->lang['Go']; ?>" /><input type="hidden" name="sid" value="<?php echo $user->session_id; ?>" /></td>
+ <td align="right"><?php echo $user->lang['SELECT_FORUM']; ?>: <select name="f" onchange="if(this.options[this.selectedIndex].value != -1){ this.form.submit(); }"><?php echo $forum_box; ?></select> <input class="liteoption" type="submit" value="<?php echo $user->lang['GO']; ?>" /><input type="hidden" name="sid" value="<?php echo $user->session_id; ?>" /></td>
</tr>
</table></form>
-
<?php
page_footer();
@@ -773,95 +1000,38 @@ page_footer();
// END
//
-// ------------------
-// Begin function block
-//
-function get_forum_info($forum_id)
-{
- global $db;
- $sql = 'SELECT *
- FROM ' . FORUMS_TABLE . "
- WHERE forum_id = $forum_id";
- $result = $db->sql_query($sql);
- if (!$row = $db->sql_fetchrow($result))
- {
- trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
- }
- return $row;
-}
-function make_forums_list($mode = 'all', $selected_id = 0, $exclude_id = array())
-{
- global $db;
- if (!is_array($exclude_id))
- {
- $exclude_id = array($exclude_id);
- }
- $sql = 'SELECT f2.*
- FROM ' . FORUMS_TABLE . ' f1, ' . FORUMS_TABLE . ' f2
- WHERE f1.parent_id = 0
- AND f2.left_id BETWEEN f1.left_id AND f1.right_id
- ORDER BY f2.left_id';
- $result = $db->sql_query($sql);
- $list = '';
- $indent = array();
- $current_indent = 0;
- while ($row = $db->sql_fetchrow($result))
- {
- if ($row['parent_id'] == 0)
- {
- $current_indent = 0;
- }
- elseif (!isset($indent[$row['parent_id']]))
- {
- ++$current_indent;
- $indent[$row['parent_id']] = $current_indent;
- }
- else
- {
- $current_indent = $indent[$row['parent_id']];
- }
- if (($mode == 'forums' && !$row['forum_postable'])
- || ($mode == 'categories' && $row['forum_postable'])
- || (in_array($row['forum_id'], $exclude_id)))
- {
- continue;
- }
- if ($mode == 'all' && !$row['parent_id'])
- {
- $list .= "<option value=\"-1\">&nbsp;</option>\n";
- }
- $list .= '<option value="' . $row['forum_id'] . '"';
- $list .= ($row['forum_id'] == $selected_id) ? ' selected="selected">' : '>';
- $list .= str_repeat('--', $current_indent) . (($indent) ? ' ' : '') . $row['forum_name'] . "</option>\n";
- }
- return $list;
-}
+// ------------------
+// Begin function block
+//
-function make_styles_list($selected_id = 0)
+function get_forum_info($forum_id)
{
global $db;
- $list = '';
- $result = $db->sql_query('SELECT style_id, style_name FROM ' . STYLES_TABLE . ' ORDER BY style_name');
+ $sql = 'SELECT *
+ FROM ' . FORUMS_TABLE . "
+ WHERE forum_id = $forum_id";
+ $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
+ if (!$row = $db->sql_fetchrow($result))
{
- $list .= '<option value="' . $row['style_id'] . '"' . (($row['style_id'] == $selected_id) ? ' selected="selected">' : '>') . htmlspecialchars($row['style_name']) . "</option>\n";
+ trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
}
- return $list;
+
+ return $row;
}
function move_forum($from_id, $to_id)
@@ -922,15 +1092,20 @@ function move_forum($from_id, $to_id)
}
else
{
- $result = $db->sql_query('SELECT MAX(right_id) AS right_id FROM ' . FORUMS_TABLE . ' WHERE forum_id NOT IN (' . implode(', ', $moved_ids) . ')');
- $right_id = $db->sql_fetchfield('right_id', 0, $result);
+ $sql = 'SELECT MAX(right_id) AS right_id
+ FROM ' . FORUMS_TABLE . '
+ WHERE forum_id NOT IN (' . implode(', ', $moved_ids) . ')';
+ $result = $db->sql_query($sql);
+
+ $row = $db->sql_fetchtrow($result);
+ $db->sql_freeresult($result);
- $diff = '+ ' . ($right_id - $from_data['left_id'] + 1);
+ $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
}
$sql = 'UPDATE ' . FORUMS_TABLE . "
- SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
- WHERE forum_id IN (" . implode(', ', $moved_ids) . ')';
+ SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
+ WHERE forum_id IN (" . implode(', ', $moved_ids) . ')';
$db->sql_query($sql);
}
@@ -938,86 +1113,154 @@ function move_forum_content($from_id, $to_id)
{
global $db;
- $db->sql_query('UPDATE ' . ACL_GROUPS_TABLE . " SET forum_id = $to_id WHERE forum_id = $from_id");
- $db->sql_query('UPDATE ' . MODERATOR_TABLE . " SET forum_id = $to_id WHERE forum_id = $from_id");
- $db->sql_query('UPDATE ' . LOG_MOD_TABLE . " SET forum_id = $to_id WHERE forum_id = $from_id");
- $db->sql_query('UPDATE ' . POSTS_TABLE . " SET forum_id = $to_id WHERE forum_id = $from_id");
- $db->sql_query('UPDATE ' . TOPICS_TABLE . " SET forum_id = $to_id WHERE forum_id = $from_id");
+ $table_ary = array(LOG_MOD_TABLE, POSTS_TABLE, TOPICS_TABLE);
+ foreach ($sql_ary as $table)
+ {
+ $sql = "UPDATE $table
+ SET forum_id = $to_id
+ WHERE forum_id = $from_id";
+ $db->sql_query($sql);
+ }
+ unset($table_ary);
- //
- // TODO: untested yet
- //
$sql = 'SELECT t1.topic_id
- FROM ' .TOPICS_TABLE . ' t1
- LEFT JOIN ' . TOPICS_TABLE . " t2 ON t1.topic_moved_id = t2.topic_id AND t1.forum_id = t2.forum_id
- WHERE t1.forum_id = $to_id";
+ FROM ' .TOPICS_TABLE . ' t1, ' . TOPICS_TABLE . " t2
+ WHERE t2.forum_id = $to_id
+ AND t1.topic_moved_id = t2.topic_id
+ AND t1.forum_id = t2.forum_id";
$result = $db->sql_query($result);
- $topic_ids = array();
- while ($row = $db->sql_fetchrow($result))
+ if ($row = $db->sql_fetchrow($result))
{
- $topic_ids[] = $row['topic_id'];
- }
- if (count($topic_ids))
- {
- $db->sql_query('DELETE FROM ' . TOPICS_TABLE . ' WHERE topic_id IN (' . implode(', ', $topic_ids) . ')');
+ $topic_id_ary = array();
+ do
+ {
+ $topic_id_ary[] = $row['topic_id'];
+ }
+ while ($row = $db->sql_fetchrow($result));
+
+ $sql = 'DELETE FROM ' . TOPICS_TABLE . '
+ WHERE topic_id IN (' . implode(', ', $topic_id_ary) . ')';
+ $db->sql_query($sql);
+ unset($topic_id_ary);
}
- sync('forum', 'forum_id', $to_id);
+ $db->sql_freeresult($result);
- //
- // TODO: there might be conflicts in ACL tables =\
- // make sure that the query that retrieves shadow topics uses the correct index (topic_type or topic_moved_id)
- //
+ sync('forum', 'forum_id', $to_id);
}
function delete_forum_content($forum_id)
{
global $db;
- $db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . " WHERE forum_id = $forum_id");
- $db->sql_query('DELETE FROM ' . MODERATOR_TABLE . " WHERE forum_id = $forum_id");
- $db->sql_query('DELETE FROM ' . LOG_MOD_TABLE . " WHERE forum_id = $forum_id");
- $db->sql_query('DELETE FROM ' . FORUMS_WATCH_TABLE . " WHERE forum_id = $forum_id");
+ $db->sql_transaction();
- $ids = array();
- $result = $db->sql_query('SELECT post_id FROM ' . POSTS_TABLE . " WHERE forum_id = $forum_id");
+ $sql = 'SELECT post_id
+ FROM ' . POSTS_TABLE . "
+ WHERE forum_id = $forum_id";
+ $result = $db->sql_query();
- while ($row = $db->sql_fetchrow($result))
+ if ($row = $db->sql_fetchrow($result))
{
- $ids[] = $row['post_id'];
+ $id_ary = array();
+
+ do
+ {
+ $id_ary[] = $row['post_id'];
+ }
+ while ($row = $db->sql_fetchrow($result));
+
+ // TODO
+ // Could be problematical with large forums ... should split array
+ // if large
+ $sql = 'DELETE FROM ' . SEARCH_MATCH_TABLE . '
+ WHERE post_id IN (' . implode(', ', $id_ary) . ')';
+ $db->sql_query($sql);
+ unset($id_ary);
}
- $ids = implode(',', $ids);
$db->sql_freeresult();
- if ($ids)
+ $sql = 'SELECT topic_id
+ FROM ' . TOPICS_TABLE . "
+ WHERE forum_id = $forum_id";
+ $result = $db->sql_query();
+
+ if ($row = $db->sql_fetchrow($result))
{
- $db->sql_query('DELETE FROM ' . SEARCH_MATCH_TABLE . " WHERE post_id IN ($ids)");
- $db->sql_query('DELETE FROM ' . POSTS_TABLE . " WHERE forum_id = $forum_id");
- $db->sql_query('DELETE FROM ' . POSTS_TEXT_TABLE . " WHERE post_id IN ($ids)");
- }
+ $id_ary = array();
+ do
+ {
+ $id_ary[] = $row['topic_id'];
+ }
+ while ($row = $db->sql_fetchrow($result));
- $ids = array();
- $result = $db->sql_query('SELECT topic_id FROM ' . TOPICS_TABLE . " WHERE forum_id = $forum_id");
+ $sql_in = implode(', ', $id_ary);
+ unset($id_ary);
- while ($row = $db->sql_fetchrow($result))
- {
- $ids[] = $row['topic_id'];
+ $table_ary = array(TOPICS_WATCH_TABLE, POLL_OPTIONS_TABLE, POLL_VOTES_TABLE);
+ foreach ($sql_ary as $table)
+ {
+ $sql = "DELETE FROM $table
+ WHERE topic_id IN ($sql_in)";
+ $db->sql_query($sql);
+ }
+ unset($table_ary);
+
+ $sql = 'DELETE FROM ' . TOPICS_TABLE . "
+ WHERE topic_moved_id IN ($sql_in)";
+ $db->sql_query($sql);
+
+ unset($sql_in);
}
- $ids = implode(',', $ids);
$db->sql_freeresult();
- if ($ids)
+ $table_ary = array(TOPICS_TABLE, POSTS_TABLE, ACL_GROUPS_TABLE, ACL_USERS_TABLE, MODERATOR_TABLE, LOG_MOD_TABLE, FORUMS_WATCH_TABLE);
+ foreach ($sql_ary as $table)
{
- $db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . " WHERE topic_id IN ($ids)");
- $db->sql_query('DELETE FROM ' . TOPICS_TABLE . " WHERE forum_id = $forum_id");
- $db->sql_query('DELETE FROM ' . TOPICS_TABLE . " WHERE topic_moved_id IN ($ids)");
+ $sql = "DELETE FROM $table
+ WHERE forum_id = $forum_id";
+ $db->sql_query($sql);
+ }
+ unset($table_ary);
+
+ switch (SQL_LAYER)
+ {
+ case 'mysql':
+ case 'mysql4':
+/* $sql = 'SHOW TABLES';
+ $result = $db->sql_query($sql);
+
+ $field_name = 'Tables_in_' . $db->dbname;
+ $table_ary = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if (preg_match('#^' . preg_quote($phpEx, '#') . '#', $row[$field_name]))
+ {
+ $table_ary[] = $row[$field_name];
+ }
+ }
+ $db->sql_freeresult($result);
+
+ if (sizeof($table_ary))
+ {*/
+ $table_ary = array(TOPICS_TABLE, POSTS_TABLE, ACL_GROUPS_TABLE, ACL_USERS_TABLE, MODERATOR_TABLE, LOG_MOD_TABLE, FORUMS_WATCH_TABLE, TOPICS_WATCH_TABLE, POLL_OPTIONS_TABLE, POLL_VOTES_TABLE, SEARCH_MATCH_TABLE);
+ $sql = 'OPTIMIZE TABLE ' . implode(', ', $table_ary);
+ $db->sql_query($sql);
+// }
+ unset($table_ary);
+
+ break;
+
+ case 'postgresql':
+ $db->sql_query('VACUUM');
+ break;
}
//
// TODO: delete attachments
- // delete polls
- // OPTIMIZE / VACUUM table ?
//
+
+ $db->sql_transaction('commit');
}
//