<?php
/*
Copyright (C) 2005-2011 UserDot
Visit XennoBB at www.userdot.net/projects/xennobb
Originally based on PunBB www.punbb.org
XennoBB is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
XennoBB is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA
*/
define('IN_FORUM_ADMIN', 1);
require dirname(__FILE__) . '/../include/init.php';
if ($forum_user['g_id'] > USER_ADMIN)
BB_Functions::Message($lang['No permission'], true, 1);
$page = isset($_GET['Page']) ? BB_Input::Htmlspecialchars($_GET['Page']) : null;
$submenu = array($lang['Add'] => 'forums.php?Page=Add', $lang['Edit'] => 'forums.php?Page=Edit', $lang['Merge'] => 'forums.php?Page=Merge');
if (isset($_POST['add_forum']))
{
BB_Input::Confirm_Referrer('forums.php');
$add_to_cat = intval($_POST['add_to_cat']);
if ($add_to_cat < 1)
BB_Functions::Message($lang['Bad request']);
$db->query('INSERT INTO ' . $db->prefix . 'forums (cat_id) VALUES(' . $db->escape($add_to_cat) . ')') or BB_Functions::Error('Unable to create forum', __FILE__, __LINE__, $db->error());
$new_id = $db->insert_id();
BB_Admin_Functions::Log_Action('New forum added ' . $new_id, 2);
BB_Functions::Redirect('forums.php?edit_forum=' . $new_id, $lang['redirect_forum_added']);
}
else if (isset($_POST['run_merge']))
{
$forum1 = intval($_POST['forum1']);
$forum2 = intval($_POST['forum2']);
if (trim($forum1) == '')
BB_Functions::Message('You never specified a forum to merge from.');
if (trim($forum2) == '')
BB_Functions::Message('You never specified a forum to merge to.');
$result = $db->query("SELECT * FROM " . $db->prefix . "forums WHERE id=" . $db->escape($forum1));
if ($db->num_rows($result) == '0')
BB_Functions::Message('The forum you specified to merge from does not exist.');
$result = $db->query("SELECT * FROM " . $db->prefix . "forums WHERE id=" . $db->escape($forum2));
if ($db->num_rows($result) == '0')
BB_Functions::Message('The forum you specified to merge to does not exist.');
if ($forum1 == $forum2)
BB_Functions::Message('The forums you specified are the same.');
$db->query("UPDATE " . $db->prefix . "topics set forum_id=" . $db->escape($forum2) . " where forum_id=" . $db->escape($forum1));
$db->query("DELETE FROM " . $db->prefix . "forums WHERE id = " . $db->escape($forum1));
BB_Core::Update_Forum($forum2);
BB_Admin_Functions::Log_Action('Forums merged ', 2);
BB_Functions::Redirect('forums.php?Page=Merge', $lang['redirect_forums_merged']);
}
else if (isset($_GET['del_forum']))
{
BB_Input::Confirm_Referrer('forums.php');
$forum_id = intval($_GET['del_forum']);
if ($forum_id < 1)
BB_Functions::Message($lang['Bad request']);
if (isset($_POST['del_forum_comply']))
{
@set_time_limit(0);
BB_Admin_Functions::Prune($forum_id, 1, -1);
$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 BB_Functions::Error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
$num_orphans = $db->num_rows($result);
if ($num_orphans)
{
for ($i = 0; $i < $num_orphans; ++$i)
$orphans[] = $db->result($result, $i);
$db->query('DELETE FROM ' . $db->prefix . 'topics WHERE id IN(' . implode(',', $orphans) . ')') or BB_Functions::Error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
}
$db->query('DELETE FROM ' . $db->prefix . 'forums WHERE id=' . $db->escape($forum_id)) or BB_Functions::Error('Unable to delete forum', __FILE__, __LINE__, $db->error());
$db->query('DELETE FROM ' . $db->prefix . 'permissions WHERE forum_id=' . $db->escape($forum_id)) or BB_Functions::Error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
BB_Admin_Functions::Log_Action('Forum removed ' . $forum_id, 3);
BB_Functions::Redirect('forums.php?Page=Edit', $lang['redirect_forum_deleted']);
}
else
{
$result = $db->query('SELECT forum_name FROM ' . $db->prefix . 'forums WHERE id=' . $db->escape($forum_id)) or BB_Functions::Error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
$forum_name = BB_Input::Htmlspecialchars($db->result($result));
$page_title = BB_Input::Htmlspecialchars($lang['Admin'] . $lang['Forums']);
require FORUM_ROOT . 'admin/header.php';
?>
<div class="blockform">
<h2><span><?php echo $lang['Conf_del_forum'] ?></span></h2>
<form method="post" action="forums.php?del_forum=<?php echo $forum_id ?>">
<div class="inform">
<div class="infldset file" style="padding:10px">
<p><?php echo $lang['Conf_delete_forum'] ?> "<?php echo $forum_name ?>"?</p>
<p><?php echo $lang['Delete_forum_warn'] ?></p>
</div>
</div>
<div><input type="button" class="b1" onclick="javascript:history.go(-1)" value="<?php echo $lang['Go back'] ?>" /> <input type="submit" class="b1" name="del_forum_comply" value="<?php echo $lang['Remove']; ?>" /></div>
</form>
</div>
<?php
require FORUM_ROOT . 'admin/footer.php';
}
}
else if (isset($_POST['update_positions']))
{
BB_Input::Confirm_Referrer('forums.php');
while (list($forum_id, $disp_position) = @each($_POST['position']))
{
if (!preg_match('#^\d+$#', $disp_position))
BB_Functions::Message($lang['position_positive']);
$db->query('UPDATE ' . $db->prefix . 'forums SET disp_position=' . intval($disp_position) . ' WHERE id=' . intval($forum_id)) or BB_Functions::Error('Unable to update forum', __FILE__, __LINE__, $db->error());
}
BB_Functions::Redirect('forums.php?Page=Edit', $lang['redirect_forums_updated']);
}
else if (isset($_GET['edit_forum']))
{
$forum_id = intval($_GET['edit_forum']);
if ($forum_id < 1)
BB_Functions::Message($lang['Bad request']);
if (isset($_POST['save']))
{
BB_Input::Confirm_Referrer('forums.php');
$forum_name = trim($_POST['forum_name']);
$forum_desc = BB_Input::Linebreaks(trim($_POST['forum_desc']));
$cat_id = intval($_POST['cat_id']);
$sort_by = intval($_POST['sort_by']);
$redirect_url = isset($_POST['redirect_url']) ? trim($_POST['redirect_url']) : null;
$parent_forum_id = intval($_POST['parent_forum']);
if ($forum_name == '')
BB_Functions::Message('You must enter a forum name.');
if ($cat_id < 1)
BB_Functions::Message($lang['Bad request']);
$forum_desc = ($forum_desc != '') ? '\'' . $db->escape($forum_desc) . '\'' : 'NULL';
$redirect_url = ($redirect_url != '') ? '\'' . $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=' . $db->escape($sort_by) . ', cat_id=' . $db->escape($cat_id) . ', parent_forum_id=' . $db->escape($parent_forum_id) . ' WHERE id=' . $db->escape($forum_id)) or BB_Functions::Error('Unable to update forum', __FILE__, __LINE__, $db->error());
if (isset($_POST['read_forum_old']))
{
$result = $db->query('SELECT g_id, g_read_board, g_post_replies, g_post_topics FROM ' . $db->prefix . 'usergroups WHERE g_id!=' . USER_ADMIN) or BB_Functions::Error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
while ($cur_group = $db->fetch_assoc($result))
{
$read_forum_new = ($cur_group['g_read_board'] == '1') ? isset($_POST['read_forum_new'][$cur_group['g_id']]) ? intval($_POST['read_forum_new'][$cur_group['g_id']]) : '0' : intval($_POST['read_forum_old'][$cur_group['g_id']]);
$post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? intval($_POST['post_replies_new'][$cur_group['g_id']]) : '0';
$post_topics_new = isset($_POST['post_topics_new'][$cur_group['g_id']]) ? intval($_POST['post_topics_new'][$cur_group['g_id']]) : '0';
$image_upload_new = isset($_POST['image_upload_new'][$cur_group['g_id']]) ? intval($_POST['image_upload_new'][$cur_group['g_id']]) : '0';
if ($read_forum_new != $_POST['read_forum_old'][$cur_group['g_id']] || $post_replies_new != $_POST['post_replies_old'][$cur_group['g_id']] || $post_topics_new != $_POST['post_topics_old'][$cur_group['g_id']] || $image_upload_new != $_POST['image_upload_old'][$cur_group['g_id']])
{
if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics'] && $image_upload_new == '0')
$db->query('DELETE FROM ' . $db->prefix . 'permissions WHERE gid=' . $db->escape($cur_group['g_id']) . ' AND forum_id=' . $db->escape($forum_id)) or BB_Functions::Error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
else
{
$db->query('UPDATE ' . $db->prefix . 'permissions SET read_forum=' . $db->escape($read_forum_new) . ', post_replies=' . $db->escape($post_replies_new) . ', post_topics=' . $db->escape($post_topics_new) . ', image_upload=' . $db->escape($image_upload_new) . ' WHERE gid=' . $db->escape($cur_group['g_id']) . ' AND forum_id=' . $db->escape($forum_id)) or BB_Functions::Error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
if (!$db->affected_rows())
$db->query('INSERT INTO ' . $db->prefix . 'permissions (gid, forum_id, read_forum, post_replies, post_topics, image_upload) VALUES(' . $db->escape($cur_group['g_id']) . ', ' . $db->escape($forum_id) . ', ' . $db->escape($read_forum_new) . ', ' . $db->escape($post_replies_new) . ', ' . $db->escape($post_topics_new) . ', ' . $db->escape($image_upload_new) . ')') or BB_Functions::Error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
}
}
}
}
BB_Admin_Functions::Log_Action('Forum edited ' . $forum_id, 3);
BB_Functions::Redirect('forums.php?Page=Edit', $lang['redirect_forums_updated']);
}
else if (isset($_POST['revert_perms']))
{
BB_Input::Confirm_Referrer('forums.php');
$db->query('DELETE FROM ' . $db->prefix . 'permissions WHERE forum_id=' . $db->escape($forum_id)) or BB_Functions::Error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
BB_Functions::Redirect('forums.php?Page=Edit', $lang['permission_reverted_default']);
}
$result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id, parent_forum_id FROM ' . $db->prefix . 'forums WHERE id=' . $db->escape($forum_id)) or BB_Functions::Error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
BB_Functions::Message($lang['Bad request']);
$cur_forum = $db->fetch_assoc($result);
$parent_forums = Array();
$result = $db->query('SELECT DISTINCT parent_forum_id FROM ' . $db->prefix . 'forums WHERE parent_forum_id != 0');
while ($r = $db->fetch_row($result))
$parent_forums[] = $r[0];
$page_title = BB_Input::Htmlspecialchars($lang['Admin'] . $lang['Forums']);
require FORUM_ROOT . 'admin/header.php';
?>
<div class="blockform">
<h2><?php echo $lang['Edit_forum_details'] ?></h2>
<form id="edit_forum" method="post" action="forums.php?edit_forum=<?php echo $forum_id ?>">
<div class="inform">
<div class="infldset file" style="padding:10px">
<p><?php echo $lang['Edit_group_perms_desc'] ?></p>
</div>
</div>
<div class="inform">
<div class="infldset file" style="padding:10px">
<table class="aligntop" cellspacing="0">
<tr>
<th class="header"><?php echo $lang['Forum_name'] ?></th>
<td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_52']) ?></td>
<td><input type="text" class="textbox" name="forum_name" size="50" maxlength="80" value="<?php echo BB_Input::Htmlspecialchars($cur_forum['forum_name']) ?>" tabindex="1" /></td>
</tr>
<tr>
<th class="header"><?php echo $lang['Desc_html'] ?></th>
<td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_53']) ?></td>
<td><textarea name="forum_desc" rows="4" cols="40" tabindex="2"><?php echo BB_Input::Htmlspecialchars($cur_forum['forum_desc']); ?></textarea></td>
</tr>
<tr>
<th class="header"><?php echo $lang['Category'] ?></th>
<td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_54']) ?></td>
<td><select name="cat_id" tabindex="3">
<?php
$result = $db->query('SELECT id, cat_name FROM ' . $db->prefix . 'categories ORDER BY disp_position') or BB_Functions::Error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
while ($cur_cat = $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 . '>' . BB_Input::Htmlspecialchars($cur_cat['cat_name']) . '</option>' . "\n";
}
?>
</select></td>
</tr>
<tr>
<th class="header"><?php echo $lang['Sort_by'] ?></th>
<td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_55']) ?></td>
<td><select name="sort_by" tabindex="4"><option value="0"<?php if ($cur_forum['sort_by'] == '0')
echo ' selected="selected"' ?>><?php echo $lang['Last_post'] ?></option><option value="1"<?php if ($cur_forum['sort_by'] == '1')
echo ' selected="selected"' ?>><?php echo $lang['Topic_start'] ?></option></select></td>
</tr>
<tr>
<th class="header"><?php echo $lang['Redir_url'] ?></th>
<td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_56']) ?></td>
<td><?php echo ($cur_forum['num_topics']) ? 'Only available in empty forums' : '<input type="text" class="textbox" name="redirect_url" size="40" maxlength="100" value="' . BB_Input::Htmlspecialchars($cur_forum['redirect_url']) . '" tabindex="5" />'; ?></td>
</tr>
<tr>
<th class="header"><?php echo $lang['Parent forum'] ?></th>
<td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_60']) ?></td>
<td><select name="parent_forum"><option value="0"><?php echo $lang['No parent forum'] ?></option>
<?php
if (!in_array($cur_forum['id'], $parent_forums))
{
$result = $db->query('SELECT id, forum_name, parent_forum_id FROM ' . $db->prefix . 'forums ORDER BY disp_position') or BB_Functions::Error('Unable to fetch forum lise', __FILE__, __LINE__, $db->error());
while ($forum_list = $db->fetch_assoc($result))
{
$selected = ($forum_list['id'] == $cur_forum['parent_forum_id']) ? ' selected="selected"' : '';
if (!$forum_list['parent_forum_id'] && $forum_list['id'] != $cur_forum['id'])
echo "\t\t\t\t\t\t\t\t\t\t\t" . '<option value="' . $forum_list['id'] . '"' . $selected . '>' . BB_Input::Htmlspecialchars($forum_list['forum_name']) . '</option>' . "\n";
}
}
?>
</select></td>
</tr>
</table>
</div>
</div>
<div class="inform">
<h2><?php echo $lang['Edit_group_perms'] ?></h2>
<div class="infldset file" style="padding:10px">
<table id="forumperms" cellspacing="0">
<thead>
<tr>
<th class="atcl"> </th>
<th><?php echo $lang['Read_forum'] ?></th>
<th><?php echo $lang['Post_replies'] ?></th>
<th><?php echo $lang['Post_topics'] ?></th>
<th><?php echo $lang['Image_upload'] ?></th>
</tr>
</thead>
<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, fp.image_upload FROM ' . $db->prefix . 'usergroups AS g LEFT JOIN ' . $db->prefix . 'permissions AS fp ON (g.g_id=fp.gid AND fp.forum_id=' . $db->escape($forum_id) . ') WHERE g.g_id!=' . USER_ADMIN . ' ORDER BY g.g_id') or BB_Functions::Error('Unable to fetch group forum permission list', __FILE__, __LINE__, $db->error());
while ($cur_perm = $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;
$post_topics = (($cur_perm['g_post_topics'] == '0' && $cur_perm['post_topics'] == '1') || ($cur_perm['g_post_topics'] == '1' && $cur_perm['post_topics'] != '0')) ? true : false;
$image_upload = (isset($cur_perm['image_upload']) && $cur_perm['image_upload'] == '1' && $cur_perm['g_id'] != '3') ? true : false;
$read_forum_def = ($cur_perm['read_forum'] == '0') ? false : true;
$post_replies_def = (($post_replies && $cur_perm['g_post_replies'] == '0') || (!$post_replies && ($cur_perm['g_post_replies'] == '' || $cur_perm['g_post_replies'] == '1'))) ? false : true;
$post_topics_def = (($post_topics && $cur_perm['g_post_topics'] == '0') || (!$post_topics && ($cur_perm['g_post_topics'] == '' || $cur_perm['g_post_topics'] == '1'))) ? false : true;
?>
<tr>
<th class="atcl" style="width:200px"><?php echo BB_Input::Htmlspecialchars($cur_perm['g_title']) ?></th>
<td<?php if (!$read_forum_def)
echo ' class="nodefault"'; ?>><input type="hidden" name="read_forum_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($read_forum) ? '1' : '0'; ?>" /><input type="checkbox" name="read_forum_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($read_forum) ? ' checked="checked"' : ''; ?><?php echo ($cur_perm['g_read_board'] == '0') ? ' disabled="disabled"' : ''; ?> /></td>
<td<?php if (!$post_replies_def && $cur_forum['redirect_url'] == '')
echo ' class="nodefault"'; ?>><input type="hidden" name="post_replies_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_replies) ? '1' : '0'; ?>" /><input type="checkbox" name="post_replies_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_replies) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> /></td>
<td<?php if (!$post_topics_def && $cur_forum['redirect_url'] == '')
echo ' class="nodefault"'; ?>><input type="hidden" name="post_topics_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_topics) ? '1' : '0'; ?>" /><input type="checkbox" name="post_topics_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_topics) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> /></td>
<td<?php if ($image_upload)
echo ' class="nodefault"'; ?>><input type="hidden" name="image_upload_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($image_upload) ? '1' : '0'; ?>" /><input type="checkbox" name="image_upload_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($image_upload) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '' || $cur_perm['g_id'] == '3') ? ' disabled="disabled"' : ''; ?> /></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<div><input type="button" class="b1" onclick="javascript:history.go(-1)" value="<?php echo $lang['Go back'] ?>"> <input type="submit" class="b1" name="revert_perms" value="<?php echo $lang['Revert to default'] ?>" /> <input type="submit" class="b1" name="save" value="<?php echo $lang['Save'] ?>" /></div>
</form>
</div>
<?php
require FORUM_ROOT . 'admin/footer.php';
}
$page_title = BB_Input::Htmlspecialchars($lang['Admin'] . $lang['Forums']);
require FORUM_ROOT . 'admin/header.php';
if ($page == 'Add')
{
echo BB_Template::Generate_Menu($submenu);
?>
<div class="blockform">
<form method="post" action="forums.php?action=adddel">
<div class="inform">
<div class="infldset file" style="padding:10px">
<table class="aligntop" cellspacing="0">
<tr>
<th class="header"><?php echo $lang['Add_forum_cat']; ?></th>
<td class="tips"><?php BB_Template::Print_Tooltip($lang['tip_61']) ?></td>
<td><select name="add_to_cat" tabindex="1">
<?php
$result = $db->query('SELECT id, cat_name FROM ' . $db->prefix . 'categories ORDER BY disp_position') or BB_Functions::Error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
while ($cur_cat = $db->fetch_assoc($result))
echo "\t\t\t\t\t\t\t\t\t" . '<option value="' . $cur_cat['id'] . '">' . BB_Input::Htmlspecialchars($cur_cat['cat_name']) . '</option>' . "\n";
?>
</select></td>
</tr>
</table>
</div>
</div>
<div><input class="b1" class="b1" type="submit" name="add_forum" value="<?php echo $lang['Add'] ?>" tabindex="2" /></div>
</form>
</div>
<?php
}
else if ($page == 'Edit')
{
echo BB_Template::Generate_Menu($submenu);
?>
<div class="blockform">
<?php
$toskip = array();
$result = $db->query('SELECT f.id AS fid FROM ' . $db->prefix . 'forums AS f WHERE f.parent_forum_id != 0') or BB_Functions::Error('Cannot retrieve list of subforums', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result) != 0)
{
while ($results = $db->fetch_array($result))
$toskip[] = $results['fid'];
}
$result = $db->query('SELECT COUNT(id) FROM ' . $db->prefix . 'forums') or BB_Functions::Error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$numforums = $db->result($result);
if ($numforums > 0)
{
?>
<form id="edforum" method="post" action="forums.php?action=edit">
<?php
$tabindex_count = 4;
$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.disp_position, f.parent_forum_id 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 BB_Functions::Error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
$cur_category = 0;
while ($cur_forum = $db->fetch_assoc($result))
{
if ($cur_forum['cid'] != $cur_category)
{
if ($cur_category != 0)
echo "\t\t\t\t\t\t\t" . '</table>' . "\n\t\t\t\t\t\t" . '</div>' . "\n\t\t\t\t\t" . '</fieldset>' . "\n\t\t\t\t" . '</div>' . "\n";
?>
<div class="inform">
<h2><?php echo $lang['Category']; ?> <?php echo BB_Input::Htmlspecialchars($cur_forum['cat_name']) ?></h2>
<div class="infldset file" style="padding:0px">
<table cellspacing="0">
<thead>
<tr>
<th class="header"> </th>
<th><strong><?php echo $lang['Position']; ?></strong></th>
<th class="tcl"><strong><?php echo $lang['Name']; ?></strong></th>
</tr>
</thead>
<tbody>
<?php
$cur_category = $cur_forum['cid'];
}
if (!in_array($cur_forum['fid'], $toskip))
{
?>
<tr>
<th><a href="forums.php?edit_forum=<?php echo $cur_forum['fid'] ?>"><?php echo $lang['Edit']; ?></a> - <a href="forums.php?del_forum=<?php echo $cur_forum['fid'] ?>"><?php echo $lang['Delete']; ?></a></th>
<td><input type="text" class="textbox" name="position[<?php echo $cur_forum['fid'] ?>]" size="3" maxlength="2" value="<?php echo $cur_forum['disp_position'] ?>" tabindex="<?php echo $tabindex_count ?>" /></td>
<td><?php echo BB_Input::Htmlspecialchars($cur_forum['forum_name']) ?></td>
</tr>
<?php
}
$result2 = $db->query('SELECT f.id AS fid, f.forum_name, f.disp_position, f.parent_forum_id FROM ' . $db->prefix . 'forums AS f WHERE f.parent_forum_id = ' . $db->escape($cur_forum['fid']) . ' ORDER BY f.disp_position') or BB_Functions::Error('Cannot retrieve list of forums', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result2))
{
while ($cur_ss_forum = $db->fetch_assoc($result2))
{
?>
<tr>
<th><a href="forums.php?edit_forum=<?php echo $cur_ss_forum['fid'] ?>"><?php echo $lang['Edit']; ?></a> - <a href="forums.php?del_forum=<?php echo $cur_ss_forum['fid'] ?>"><?php echo $lang['Delete']; ?></a></th>
<td><input type="text" class="textbox" name="position[<?php echo $cur_ss_forum['fid'] ?>]" size="3" maxlength="2" value="<?php echo $cur_ss_forum['disp_position'] ?>" /></td>
<td> » <?php echo BB_Input::Htmlspecialchars($cur_ss_forum['forum_name']) ?></td>
</tr>
<?php
}
}
$tabindex_count += 2;
}
?>
</tbody>
</table>
</div>
</div>
<div><input type="submit" class="b1" name="update_positions" value="<?php echo $lang['Update'] ?>" tabindex="<?php echo $tabindex_count ?>" /></div>
</form>
</div>
<?php
}
else
{
?>
<div class="inform">
<p><br /><?php echo $lang['board_no_forums'] ?><br /></p>
</div>
</div>
<?php
}
}
else if ($page == 'Merge')
{
echo BB_Template::Generate_Menu($submenu);
?>
<div class="blockform">
<form id="merge" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<h2><?php echo $lang['Select_forum_merge']; ?></h2>
<div class="infldset file" style="padding:10px">
<table class="aligntop" cellspacing="0">
<tr>
<td><select name="forum1">
<?php
$categories_result = $db->query("SELECT id, cat_name FROM " . $db->prefix . "categories WHERE 1=1 ORDER BY id ASC");
$forums_result = $db->query("SELECT id, forum_name, cat_id FROM " . $db->prefix . "forums WHERE 1=1 ORDER BY cat_id ASC");
$cat_now = 0;
while ($forums = $db->fetch_assoc($forums_result))
{
if ($forums['cat_id'] != $cat_now)
{
$categories = $db->fetch_assoc($categories_result);
echo "<option value='blargh' disabled='disabled'>" . BB_Input::Htmlspecialchars($categories['cat_id']) . "</option>";
$cat_now = $categories['id'];
}
echo "<option value='" . BB_Input::Htmlspecialchars($forums['id']) . "'>" . BB_Input::Htmlspecialchars($forums['forum_name']) . "</option>";
}
?>
</select><?php BB_Template::Print_Tooltip($lang['Select_forum_to_merge']) ?></td>
<td><select name="forum2">
<?php
$categories_result = $db->query("SELECT id, cat_name FROM " . $db->prefix . "categories WHERE 1=1 ORDER BY id ASC");
$forums_result = $db->query("SELECT id, forum_name, cat_id FROM " . $db->prefix . "forums WHERE 1=1 ORDER BY cat_id ASC");
$cat_now = 0;
while ($forums = $db->fetch_assoc($forums_result))
{
if ($forums['cat_id'] != $cat_now)
{
$categories = $db->fetch_assoc($categories_result);
echo "<option value='blargh' disabled='disabled'>" . BB_Input::Htmlspecialchars($categories['cat_id']) . "</option>";
$cat_now = $categories['id'];
}
echo "<option value='" . BB_Input::Htmlspecialchars($forums['id']) . "'>" . BB_Input::Htmlspecialchars($forums['forum_name']) . "</option>";
}
?>
</select><?php BB_Template::Print_Tooltip($lang['Choose_forum_to_merge']) ?></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</div>
</div>
<div><input class="b1" type="submit" name="run_merge" value="<?php echo $lang['Merge']; ?>" tabindex="3" /></div>
</form>
</div>
<?php
}
else
BB_Functions::Message($lang['Bad request']);
require FORUM_ROOT . 'admin/footer.php';
?>