<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBHosting Version 2                                              # ||
|| # ---------------------------------------------------------------- # ||
|| # All PHP code in this file is ©2004 GameCrash.org.                # ||
|| # http://www.gamecrash.org (soon) | http://www.letzplay.de         # ||
|| # ---------------------------------------------------------------- # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);

// #################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array();
$specialtemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

// ############################# LOG ACTION ###############################
vbhosting_log();

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

if (!vbhosting_haspermission('manageforums'))
{
	print_cp_no_permission();
}

if (empty($_REQUEST['do']))
{
	$_REQUEST['do'] = 'modify';
}

print_cp_header($vbphrase['vbhosting_manage_forums']);

$pruneoptions = array(
	'1' => $vbphrase['show_threads_from_last_day'],
	'2' => construct_phrase($vbphrase['show_threads_from_last_x_days'], 2),
	'7' => $vbphrase['show_threads_from_last_week'],
	'10' => construct_phrase($vbphrase['show_threads_from_last_x_days'], 10),
	'14' => construct_phrase($vbphrase['show_threads_from_last_x_weeks'], 2),
	'30' => $vbphrase['show_threads_from_last_month'],
	'45' => construct_phrase($vbphrase['show_threads_from_last_x_days'], 45),
	'60' => construct_phrase($vbphrase['show_threads_from_last_x_months'], 2),
	'75' => construct_phrase($vbphrase['show_threads_from_last_x_days'], 75),
	'100' => construct_phrase($vbphrase['show_threads_from_last_x_days'], 100),
	'365' => $vbphrase['show_threads_from_last_year'],
	'-1' => $vbphrase['show_all_threads']
);

if ($_REQUEST['do'] == 'createforum')
{
	print_form_header('forum', 'insertforum');
	construct_hidden_code('hostedid', $hostedid);
	print_table_header($vbphrase['vbhosting_create_new_forum']);
	
	print_input_row($vbphrase['vbhosting_forum_title'], 'forumtitle', '');
	print_input_row($vbphrase['vbhosting_forum_description'], 'forumdesc', '');

	print_yes_no_row($vbphrase['vbhosting_forum_is_open'], 'allowposting', 1);
	print_select_row($vbphrase['default_view_age'], 'daysprune', $pruneoptions, 30);
		
	print_table_header($vbphrase['vbhosting_posting_options']);
	print_yes_no_row($vbphrase['allow_bbcode'], 'allowbbcode', 1);
	print_yes_no_row($vbphrase['allow_img_code'], 'allowimages', 1);
	print_yes_no_row($vbphrase['allow_smilies'], 'allowsmilies', 1);
	
	print_table_header($vbphrase['vbhosting_security_settings']);
	print_yes_no_row($vbphrase['vbhosting_is_private_forum'], 'private', 0);
	print_input_row($vbphrase['vbhosting_forum_password'], 'password', '');
	
	print_submit_row();
}

if ($_REQUEST['do'] == 'createcategory')
{
	print_form_header('forum', 'insertcategory');
	construct_hidden_code('hostedid', $hostedid);
	print_table_header($vbphrase['vbhosting_create_new_category']);
	
	print_input_row($vbphrase['vbhosting_forum_title'], 'forumtitle', '');
	print_input_row($vbphrase['vbhosting_forum_description'], 'forumdesc', '');

	print_table_header($vbphrase['vbhosting_security_settings']);
	print_yes_no_row($vbphrase['vbhosting_is_private_forum'], 'private', ß);
	print_input_row($vbphrase['vbhosting_forum_password'], 'password', '');
	
	print_submit_row();
}

if ($_REQUEST['do'] == 'insertforum' || $_REQUEST['do'] == 'insertcategory')
{
	globalize($_REQUEST, array(
		'forumtitle' => STR
	));
	
	if (empty($forumtitle))
	{
		print_cp_message($vbphrase['vbhosting_you_must_at_least_specify_a_title_for_your_new_forum']);
	}
	
	$parentinfo = $DB_site->query_first("SELECT forumid, styleid FROM " . TABLE_PREFIX . "vbhosting_hosted WHERE hostedid={$hostedid}");
	$_REQUEST['forumid'] = vbhosting_create_board($parentinfo['forumid'], $parentinfo['styleid'], '', '', iif($_REQUEST['do'] == 'insertcategory', true, false));
	
	$_REQUEST['do'] = 'update';
}

if ($_REQUEST['do'] == 'edit')
{
	globalize($_REQUEST, array(
		'forumid' => INT
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND (f.forumid=h.forumid OR f.parentid=h.forumid)");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	$permissions = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forumpermission WHERE forumid={$forumid} AND usergroupid=2");
	$isprivate = 0;
	if ($permissions && !($permissions['forumpermissions'] & $_BITFIELD['usergroup']['forumpermissions']['canview']))
	{
		$isprivate = 1;
	}
	
	print_form_header('forum', 'update');
	construct_hidden_code('hostedid', $hostedid);
	construct_hidden_code('forumid', $forumid);
	print_table_header(construct_phrase($vbphrase['vbhosting_edit_forum_x'], $foruminfo['title']));
	
	print_input_row($vbphrase['vbhosting_forum_title'], 'forumtitle', $foruminfo['title']);
	print_input_row($vbphrase['vbhosting_forum_description'], 'forumdesc', $foruminfo['description']);

	if ($foruminfo['options'] & $_FORUMOPTIONS['cancontainthreads'])
	{
		print_yes_no_row($vbphrase['vbhosting_forum_is_open'], 'allowposting', iif($foruminfo['options'] & $_FORUMOPTIONS['allowposting'], 1, 0));
		print_select_row($vbphrase['default_view_age'], 'daysprune', $pruneoptions, $foruminfo['daysprune']);
		
		print_table_header($vbphrase['vbhosting_posting_options']);
		print_yes_no_row($vbphrase['allow_bbcode'], 'allowbbcode', iif($foruminfo['options'] & $_FORUMOPTIONS['allowbbcode'], 1, 0));
		print_yes_no_row($vbphrase['allow_img_code'], 'allowimages', iif($foruminfo['options'] & $_FORUMOPTIONS['allowimages'], 1, 0));
		print_yes_no_row($vbphrase['allow_smilies'], 'allowsmilies', iif($foruminfo['options'] & $_FORUMOPTIONS['allowsmilies'], 1, 0));
	}
	else
	{
		// Nothing yet
	}
	
	print_table_header($vbphrase['vbhosting_security_settings']);
	print_yes_no_row($vbphrase['vbhosting_is_private_forum'], 'private', $isprivate);
	print_input_row($vbphrase['vbhosting_forum_password'], 'password', $foruminfo['password']);
	
	print_submit_row();
}

if ($_REQUEST['do'] == 'update')
{
	globalize($_REQUEST, array(
		'forumid' => INT,
		'forumtitle' => STR_NOHTML,
		'forumdesc' => STR_NOHTML,
		'allowposting' => INT,
		'daysprune' => INT,
		'allowbbcode' => INT,
		'allowimages' => INT,
		'allowsmilies' => INT,
		'private' => INT,
		'password' => STR
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND (f.forumid=h.forumid OR f.parentid=h.forumid)");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	$permissions = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forumpermission WHERE forumid={$forumid} AND usergroupid=2");
	$isprivate = false;
	if ($permissions && !($permissions['forumpermissions'] & $_BITFIELD['usergroup']['forumpermissions']['canview']))
	{
		$isprivate = true;
	}
	
	$newoptions = $foruminfo['options'];
	
	if ($allowposting && !($foruminfo['options'] & $_FORUMOPTIONS['allowposting']))
	{
		$newoptions += $_FORUMOPTIONS['allowposting'];
	}
	elseif (!$allowposting && ($foruminfo['options'] & $_FORUMOPTIONS['allowposting']))
	{
		$newoptions -= $_FORUMOPTIONS['allowposting'];
	}
	
	if ($allowbbcode && !($foruminfo['options'] & $_FORUMOPTIONS['allowbbcode']))
	{
		$newoptions += $_FORUMOPTIONS['allowbbcode'];
	}
	elseif (!$allowbbcode && ($foruminfo['options'] & $_FORUMOPTIONS['allowbbcode']))
	{
		$newoptions -= $_FORUMOPTIONS['allowbbcode'];
	}
	
	if ($allowimages && !($foruminfo['options'] & $_FORUMOPTIONS['allowimages']))
	{
		$newoptions += $_FORUMOPTIONS['allowimages'];
	}
	elseif (!$allowimages && ($foruminfo['options'] & $_FORUMOPTIONS['allowimages']))
	{
		$newoptions -= $_FORUMOPTIONS['allowimages'];
	}
	
	if ($allowsmilies && !($foruminfo['options'] & $_FORUMOPTIONS['allowsmilies']))
	{
		$newoptions += $_FORUMOPTIONS['allowsmilies'];
	}
	elseif (!$allowsmilies && ($foruminfo['options'] & $_FORUMOPTIONS['allowsmilies']))
	{
		$newoptions -= $_FORUMOPTIONS['allowsmilies'];
	}
	
	$DB_site->query("UPDATE " . TABLE_PREFIX . "forum SET " . 
		iif(!empty($forumtitle), "title='" . addslashes(htmlspecialchars_uni($forumtitle)) . "', ") . 
		iif(!empty($forumdesc), "description='" . addslashes(htmlspecialchars_uni($forumdesc)) . "', ") .
		iif($daysprune > 0, "daysprune={$daysprune}, ") . "password='" . addslashes($password) . "', " .
		"options={$newoptions} WHERE forumid={$forumid}");
	
	if ($isprivate && !$private)
	{
		$DB_site->query("DELETE FROM " . TABLE_PREFIX . "forumpermission WHERE forumid={$forumid}");
	}
	elseif (!$isprivate && $private)
	{
		// 5 = builtin Super Moderator
		// 6 = builtin Administrator
		$usergroups = $DB_site->query("SELECT usergroupid FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid < 5 OR usergroupid > 6");
		while ($usergroup = $DB_site->fetch_array($usergroups))
		{
			$DB_site->query("INSERT INTO " . TABLE_PREFIX . "forumpermission (forumid, usergroupid, forumpermissions) VALUES ({$forumid}, {$usergroup['usergroupid']}, 0)");
		}
	}

	build_forum_parentlists();
	build_forum_child_lists();
	build_forum_permissions();

	print_cp_message($vbphrase['vbhosting_your_forum_has_been_updated'], "forum.php?hostedid={$hostedid}&do=modify");
}

if ($_REQUEST['do'] == 'delete')
{
	globalize($_REQUEST, array(
		'forumid' => INT
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND f.parentid=h.forumid");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	print_form_header('forum', 'kill');
	construct_hidden_code('hostedid', $hostedid);
	construct_hidden_code('forumid', $forumid);
	
	print_table_header($vbphrase['vbhosting_delete_forum']);
	print_description_row(construct_phrase($vbphrase['vbhosting_are_you_sure_you_want_to_delete_forum_x'], htmlspecialchars_uni($foruminfo['title'])));
	print_table_footer(2, '<input type="submit" class="button" tabindex="1" value="' . $vbphrase['delete'] . '" accesskey="s" />');
}

if ($_REQUEST['do'] == 'kill')
{
	globalize($_REQUEST, array(
		'forumid' => INT
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND f.parentid=h.forumid");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	$DB_site->query("DELETE FROM " . TABLE_PREFIX . "forum WHERE forumid={$forumid}");

	$threads = $DB_site->query("SELECT threadid FROM " . TABLE_PREFIX . "thread WHERE forumid={$forumid}");
	require_once('./includes/functions_databuild.php');
	while ($thread = $DB_site->fetch_array($threads))
	{
		delete_thread($thread['threadid']);
	}

	$DB_site->query("DELETE FROM " . TABLE_PREFIX . "forumpermission WHERE forumid={$forumid}");
	$DB_site->query("DELETE FROM " . TABLE_PREFIX . "access WHERE forumid={$forumid}");
	$DB_site->query("DELETE FROM " . TABLE_PREFIX . "moderator WHERE forumid={$forumid}");
	$DB_site->query("DELETE FROM " . TABLE_PREFIX . "announcement WHERE forumid={$forumid}");
	$DB_site->query("DELETE FROM " . TABLE_PREFIX . "subscribeforum WHERE forumid={$forumid}");

	build_forum_parentlists();
	build_forum_child_lists();
	build_forum_permissions();

	print_cp_message($vbphrase['vbhosting_your_forum_has_been_updated'], "forum.php?hostedid={$hostedid}&do=modify");
}

if ($_REQUEST['do'] == 'moderators')
{
	globalize($_REQUEST, array(
		'forumid' => INT
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND (f.forumid=h.forumid OR f.parentid=h.forumid)");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	print_form_header('forum', 'insertmoderator');
	construct_hidden_code('hostedid', $hostedid);
	construct_hidden_code('forumid', $forumid);
	print_table_header(construct_phrase($vbphrase['vbhosting_moderators_for_forum_x'], $foruminfo['title']));
	print_cells_row(array($vbphrase['username'], $vbphrase['vbhosting_possible_actions']),1,'tcat');
	
	$moderators = $DB_site->query("SELECT m.moderatorid, u.username FROM " . TABLE_PREFIX . "moderator m, " . TABLE_PREFIX . "user u, " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE m.userid=u.userid AND h.hostedid={$hostedid} AND m.forumid=f.forumid AND (h.forumid=f.forumid OR h.forumid=f.parentid)");
	while ($moderator = $DB_site->fetch_array($moderators))
	{
		print_label_row($moderator['username'], "<a href=\"forum.php?hostedid={$hostedid}&do=killmoderator&forumid={$foruminfo['forumid']}&moderatorid={$moderator['moderatorid']}\">[{$vbphrase['delete']}]</a>");
	}
	
	print_table_break();
	
	print_table_header($vbphrase['vbhosting_create_new_moderator']);
	print_input_row($vbphrase['username'], 'username', '');
	print_submit_row();
}

if ($_REQUEST['do'] == 'insertmoderator')
{
	globalize($_REQUEST, array(
		'forumid' => INT,
		'username' => STR_NOHTML
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND (f.forumid=h.forumid OR f.parentid=h.forumid)");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	$moderatorinfo = $DB_site->query_first("SELECT userid FROM " . TABLE_PREFIX . "user WHERE username='" . addslashes($username) . "'");
	if (intval($moderatorinfo['userid']) < 1)
	{
		print_cp_message(construct_phrase($vbphrase['vbhosting_could_not_find_user_x'], $username));
	}
	
	if ($DB_site->query_first("SELECT moderatorid FROM " . TABLE_PREFIX . "moderator WHERE userid={$moderatorinfo['userid']} AND forumid IN ({$foruminfo['parentlist']})"))
	{
		print_cp_message(construct_phrase($vbphrase['vbhosting_user_x_has_already_moderation_permissions_in_this_forums'], $username));
	}
	
	// NOTE TO MYSELF: The permissions should be generated dynamically
	$DB_site->query("INSERT INTO " . TABLE_PREFIX . "moderator (userid, forumid, permissions) VALUES ({$moderatorinfo['userid']}, {$forumid}, 1049599)");
	
	print_cp_message($vbphrase['vbhosting_your_forum_has_been_updated'], "forum.php?hostedid={$hostedid}&forumid={$forumid}&do=moderators");
}

if ($_REQUEST['do'] == 'killmoderator')
{
	globalize($_REQUEST, array(
		'forumid' => INT,
		'moderatorid' => INT
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND (f.forumid=h.forumid OR f.parentid=h.forumid)");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	$DB_site->query("DELETE FROM " . TABLE_PREFIX . "moderator WHERE moderatorid={$moderatorid} AND forumid={$forumid}");
	
	print_cp_message($vbphrase['vbhosting_your_forum_has_been_updated'], "forum.php?hostedid={$hostedid}&forumid={$forumid}&do=moderators");
}

if ($_REQUEST['do'] == 'access')
{
	globalize($_REQUEST, array(
		'forumid' => INT
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND (f.forumid=h.forumid OR f.parentid=h.forumid)");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	print_form_header('forum', 'insertaccess');
	construct_hidden_code('hostedid', $hostedid);
	construct_hidden_code('forumid', $forumid);
	print_table_header(construct_phrase($vbphrase['vbhosting_access_masks_for_forum_x'], $foruminfo['title']));
	print_description_row($vbphrase['vbhosting_access_masks_description']);
	
	print_table_break();
	
	print_table_header($vbphrase['vbhosting_current_access_masks'], 3);
	print_cells_row(array($vbphrase['username'], $vbphrase['vbhosting_has_access'], $vbphrase['vbhosting_possible_actions']),1,'tcat');

	$accessmasks = $DB_site->query("SELECT a.accessmask, u.username, u.userid FROM " . TABLE_PREFIX . "access a, " . TABLE_PREFIX . "user u WHERE a.userid=u.userid AND a.forumid={$forumid} ORDER BY u.username");
	while ($accessmask = $DB_site->fetch_array($accessmasks))
	{
		print_cells_row(array($accessmask['username'], iif($accessmask['accessmask'], $vbphrase['yes'], $vbphrase['no']), "<a href=\"forum.php?hostedid={$hostedid}&do=killaccess&forumid={$forumid}&userid={$accessmask['userid']}\">[{$vbphrase['delete']}]</a>"));
	}
	
	print_table_break();
	
	print_table_header($vbphrase['vbhosting_create_new_access_mask']);
	print_input_row($vbphrase['username'], 'username', '');
	print_yes_no_row($vbphrase['vbhosting_has_access'], 'accessmask', 1);
	print_submit_row();
}

if ($_REQUEST['do'] == 'insertaccess')
{
	globalize($_REQUEST, array(
		'forumid' => INT,
		'username' => STR_NOHTML,
		'accessmask' => INT
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND (f.forumid=h.forumid OR f.parentid=h.forumid)");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	$accessinfo = $DB_site->query_first("SELECT userid FROM " . TABLE_PREFIX . "user WHERE username='" . addslashes($username) . "'");
	if (intval($accessinfo['userid']) < 1)
	{
		print_cp_message(construct_phrase($vbphrase['vbhosting_could_not_find_user_x'], $username));
	}
	
	if ($accessmask != 1)
	{
		$accessmask = 0;
	}
	
	$DB_site->query("REPLACE INTO " . TABLE_PREFIX . "access (userid, forumid, accessmask) VALUES ({$accessinfo['userid']}, {$forumid}, {$accessmask})");
	
	print_cp_message($vbphrase['vbhosting_your_forum_has_been_updated'], "forum.php?hostedid={$hostedid}&forumid={$forumid}&do=access");
}

if ($_REQUEST['do'] == 'killaccess')
{
	globalize($_REQUEST, array(
		'forumid' => INT,
		'userid' => INT
	));
	
	$foruminfo = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND (f.forumid=h.forumid OR f.parentid=h.forumid)");
	if (!$foruminfo)
	{
		print_cp_message($vbphrase['vbhosting_you_have_not_provided_a_correct_forumid']);
	}
	
	$DB_site->query("DELETE FROM " . TABLE_PREFIX . "access WHERE userid={$userid} AND forumid={$forumid}");
	
	print_cp_message($vbphrase['vbhosting_your_forum_has_been_updated'], "forum.php?hostedid={$hostedid}&forumid={$forumid}&do=moderators");
}

if ($_REQUEST['do'] == 'reorder')
{
	globalize($_REQUEST, array(
		'displayorder' => 'ARRAY'
	));
	
	if (is_array($displayorder))
	{
		foreach ($displayorder as $forumid => $order)
		{
			$forumid = intval($forumid);
			$order = intval($order);
			
			if ($forumid > 0 && $order > 0)
			{
				$DB_site->query("UPDATE " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h SET f.displayorder={$order} WHERE f.forumid={$forumid} AND h.hostedid={$hostedid} AND (h.forumid=f.forumid OR h.forumid=f.parentid)");
			}
		}
		
		build_forum_parentlists();
		build_forum_child_lists();
		build_forum_permissions();
	}

	print_cp_message($vbphrase['vbhosting_your_forum_has_been_updated'], "forum.php?hostedid={$hostedid}&do=modify");
}

if ($_REQUEST['do'] == 'modify')
{
	print_form_header('forum', 'reorder');
	construct_hidden_code('hostedid', $hostedid);
	print_column_style_code(array('', 'width:350px'));
	print_table_header($vbphrase['vbhosting_main_forum'], 2);
	print_cells_row(array($vbphrase['vbhosting_forum_title'], $vbphrase['vbhosting_possible_actions']),1,'tcat', -1);
	
	$foruminfo = $DB_site->query_first("SELECT f.forumid, f.title, f.options FROM " . TABLE_PREFIX . "forum f, " . TABLE_PREFIX . "vbhosting_hosted h WHERE h.hostedid={$hostedid} AND h.forumid=f.forumid");
	$cells = array();
	$cells[] = '<strong>' . $foruminfo['title'] . '</strong>';
	$cells[] = "<a href=\"forum.php?hostedid={$hostedid}&do=edit&forumid={$foruminfo['forumid']}\">[{$vbphrase['edit']}]</a> &nbsp; <a href=\"forum.php?hostedid={$hostedid}&do=moderators&forumid={$foruminfo['forumid']}\">[{$vbphrase['moderators']}]</a> &nbsp; <a href=\"forum.php?hostedid={$hostedid}&do=access&forumid={$foruminfo['forumid']}\">[{$vbphrase['access_masks']}]</a>";
	print_cells_row($cells, 0, 0, -1);
	
	print_table_break();
	print_column_style_code(array('', 'width:50px', 'width:350px'));
	print_table_header($vbphrase['vbhosting_subforums'], 3);
	print_cells_row(array($vbphrase['vbhosting_forum_title'], $vbphrase['vbhosting_order'], $vbphrase['vbhosting_possible_actions']),1,'tcat', -2);
	
	$forums = $DB_site->query("SELECT forumid, title, options, displayorder FROM " . TABLE_PREFIX . "forum WHERE parentid={$foruminfo['forumid']} ORDER BY displayorder");
	while($foruminfo = $DB_site->fetch_array($forums))
	{
		$cells = array();
		$cells[] = '<strong>' . $foruminfo['title'] . '</strong> (' . iif($foruminfo['options'] & $_FORUMOPTIONS['cancontainthreads'], $vbphrase['vbhosting_forum'], $vbphrase['vbhosting_category']) . ')';
		$cells[] = '<input type="text" class="bginput" name="displayorder[' . $foruminfo['forumid'] . ']" value="' . $foruminfo['displayorder'] . '" size="3" maxlength="3" dir="' . $direction . '" tabindex="1" />';
		$cells[] = "<a href=\"forum.php?hostedid={$hostedid}&do=edit&forumid={$foruminfo['forumid']}\">[{$vbphrase['edit']}]</a> &nbsp; <a href=\"forum.php?hostedid={$hostedid}&do=moderators&forumid={$foruminfo['forumid']}\">[{$vbphrase['moderators']}]</a> &nbsp; <a href=\"forum.php?hostedid={$hostedid}&do=access&forumid={$foruminfo['forumid']}\">[{$vbphrase['access_masks']}]</a> &nbsp; <a href=\"forum.php?hostedid={$hostedid}&do=delete&forumid={$foruminfo['forumid']}\">[{$vbphrase['delete']}]</a>";
		print_cells_row($cells, 0, 0, -2);
	}
	
	print_table_footer(3, '<input type="submit" class="button" tabindex="1" value="' . $vbphrase['save_display_order'] . '" accesskey="s" />');
}

print_cp_footer();

?>