<?php

/*
 *	W-AGORA 4.0
 *	-----------
 *	$Id: reorder_forums.php,v 1.10 2004/10/06 13:52:26 mdruilhe Exp $
 *	Usage:		allows to change the order that the forums are displayed in the forum listing
 *	Author:		Marc Druilhe <mdruilhe@w-agora.net>
 *
 */

require ("init_admin.inc");

# read site administration configuration
# --------------------------------------
require ("$site_cfg_file");	
require ("$bn_dir/$bn_fields");
if (empty($bn_msgs) ) {
	include ("$bn_dir_default/site_msgs.$ext");
} else {
	include "$bn_dir/$bn_msgs";
}

display_header (TITLE_REORDER_FORUM . "'$site'");

# --------------------------------------------------
# check if this user is authorized to edit this site
# --------------------------------------------------
if ($auth->level < ADMIN) {
	MsgForm (ERROR_NO_ADMIN, "admin_site.$ext?site=$site&force_login=1", "", "_top");
	echo "</body></html>";
	exit;
}

# -----------------------------------------------------
#  Creation form have been submitted => do the stuff
# -----------------------------------------------------
if (isset($go)) {
	if (is_array($ranks)) {
		reset($ranks);
		while (list($forum, $rank) = each($ranks)) {
##			echo "$forum -> $rank <br>";
			$fields["rank"] = $rank;
			$db->updateForum ($site, $forum, $fields);
		}
	}
} // End $go


# ------------------------------------------------
# list forums 
# ------------------------------------------------
	$forums = $db->listForums ($site);
	if (!is_array($forums)) {
		msgForm (sprintf(ERROR_NO_FORUM_ADMIN, $site), "create_forum.${ext}?site=$site");
		exit;
	}

	table_header(LABEL_CHANGE_FORUM_ORDER);

	echo "<FORM ACTION=\"$WA_SELF\" METHOD=\"post\">";
	hiddenField ("site", $site);
	hiddenField ("bn", $bn);
	hiddenField ("bn_name", $bn);

	echo "<TABLE BORDER='0' WIDTH='100%' CELLPADDING='4' CELLSPACING='0'>\n";
	echo "<TR><TD align=left>" . COLUMN_ORDER . "</TD><TD align=left>" . COLUMN_NAME . "</TD><TD align=left width='60%'>" . COLUMN_FORUM_TITLE . "</TD></TR>\n";
	$curcat = 0;
	reset($forums);
	while (list($name, $forum) = each($forums)) {
		if ($forum["parent"] != $curcat) {
			// new category
			$curcat = $forum["parent"];
			$cat = $db->getCategory ($site, $forum["parent"]);
			printf ("\n<TR><td bgcolor=#e0eaf6 colspan=3><font color=black>%s</font></TD></TR>", $cat["cat_title"]);
		}
		$bn_name = $forum["bn_name"];
		print ("<TR><td>");
		textField ("ranks[$bn_name]", $forum["rank"], 2);
		printf ("</td><TD class=label>%s</td><td class=label>%s</td></tr>\n", $name, $forum["bn_title"]);
	}
	echo "</table>\n";

?>
<br>
<CENTER>
 <INPUT NAME="go" TYPE="submit" VALUE="<?echo COLUMN_CHANGE_ORDER ?>">
</CENTER>
<?php	table_footer(); ?>
</FORM>
</BODY>
</HTML>
