<?php
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.6 www.exoops.info 2006/03 
// $Id: admin_priv_forums.php,v 1.5 2003/07/07 09:07:18 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Based on:
// phpBB: http://www.phpBB.com
// License type: GPL
// ------------------------------------------------------------------------- //
include_once("admin_header.php");
include_once("../functions.php");
include_once("../config.php");
$op = !empty($_POST['op']) ? $_POST['op'] : $_GET['op'];
if ( empty($op) ) {
?>
<form action="./admin_priv_forums.php" method="post">
<table border="0" cellpadding="1" cellspacing="0" align="center" valign="top" width="95%"><tr>
<td class="bg2">
<table border="0" cellpadding="1" cellspacing="1" width="100%"><tr class="bg3" align="left">
<td align="center" colspan="2">
<b><?php _MD_A_SAFTE;?></b>
</td>
</tr><tr class="bg1" align="left">
<td align="center" colspan="2">
<select class="select" name="forum" size="0">
<?php
$sql = "SELECT forum_name, forum_id FROM ".$db->prefix("bb_forums")." WHERE forum_type=1 ORDER BY forum_id";
if (!$result = $db->query($sql)) {
	CloseTable();
	xoops_cp_footer();
	exit();
}
if ($myrow = $db->fetchArray($result)) {
	do {
		$name = $myts->makeTboxData4Show($myrow['forum_name']);
		echo "<option value='".$myrow['forum_id']."'>$name</option>";
		} while ($myrow = $db->fetchArray($result));
	} else {
		echo "<option value='-1'>"._MD_A_NFID."</option>";
	}
?>
</select></td>
</tr><tr class="bg3" Align="left">
<td align="center" colspan="2">
<input type="hidden" name="op" value="showform" />
<input type="submit" class="button" name="submit" value="<?php echo _EDIT;?>" />
</td>
</tr></table>
</td>
</tr></table>
<?php
} else {
	// Opcode exists. See what it is, do stuff.
	if ($op == "adduser") {
		// Add user(s) to the list for this forum.
		if ($userids) {
			while (list($null, $curr_userid) = each($_POST["userids"])) {
				$sql = "INSERT INTO ".$db->prefix("bb_forum_access")." SET forum_id=$forum, user_id=$curr_userid, can_post=0";
				if (!$result = $db->query($sql)) {
					CloseTable();
					xoops_cp_footer();
					exit();
				}
			}
		}
	$op = "showform";
	} elseif ($op == "deluser") {
		// Remove a user from the list for this forum.
		$sql = "DELETE FROM ".$db->prefix("bb_forum_access")." WHERE forum_id=$forum AND user_id=$op_userid";
		if (!$result = $db->query($sql)) {
			CloseTable();
			xoops_cp_footer();
			exit();
		}
	$op = "showform";
	} elseif ($op == "clearusers") {
		// Remove all users from the list for this forum.
		$sql = "DELETE FROM ".$db->prefix("bb_forum_access")." WHERE forum_id=$forum";
		if (!$result = $db->query($sql)) {
			CloseTable();
			xoops_cp_footer();
			exit();
		}
	$op = "showform";
	} elseif ($op == "grantuserpost") {
		// Add posting rights for this user in this forum.
		$sql = "UPDATE ".$db->prefix("bb_forum_access")." SET can_post=1 WHERE forum_id=$forum AND user_id=$op_userid";
		if (!$result = $db->query($sql)) {
			CloseTable();
			xoops_cp_footer();
			exit();
		}
	$op = "showform";
	} elseif ($op == "revokeuserpost") {
		// Revoke posting rights for this user in this forum.
		$sql = "UPDATE ".$db->prefix("bb_forum_access")." SET can_post=0 WHERE forum_id=$forum AND user_id=$op_userid";
		if (!$result = $db->query($sql)) {
			CloseTable();
			xoops_cp_footer();
			exit();
		}
	$op = "showform";
	}
// We want this one to be available even after one of the above blocks has executed.
// The above blocks will set $op to "showform" on success, so it goes right back to the form.
// Neato. This is really slick.
if ($op == "showform") {
	// Show the form for the given forum.
	$sql = "SELECT forum_name FROM ".$db->prefix("bb_forums")." WHERE forum_id=$forum";
	if ((!$result = $db->query($sql)) || ($forum == -1)) {
		CloseTable();
		xoops_cp_footer();
		exit();
	}
$forum_name = "";
if ($row = $db->fetchArray($result)) {
	$forum_name = $myts->makeTboxData4Show($row['forum_name']);
}
?>
<table border="0" cellpadding="1" cellspacing="0" align="center" valign="top" width="95%"><tr>
<td class="bg2">
<table border="0" cellpadding="1" cellspacing="1" width="100%"><tr class="bg3" align="left">
<td colspan="2" align="center"><?php printf(_MD_A_EFPF, $forum_name);?></td>
</tr><tr>
<td class="bg3" align="center">
<form action="./admin_priv_forums.php" method="post">
<b><?php echo _MD_A_UWA;?></b></td>
<td class="bg3" align="center"><b><?php echo _MD_A_UWA;?></b></td>
</tr><tr>
<td valign="top" class="bg3" align="center" width="40%">
<select class="select" name="userids[]" size="10" multiple="multiple">
<?php
$sql = "SELECT u.uid FROM ".$db->prefix("users")." u, ".$db->prefix("bb_forum_access")." f WHERE u.uid=f.user_id AND f.forum_id=$forum";
if (!$result = $db->query($sql)) {
	CloseTable();
	xoops_cp_footer();
	exit();
}
$current_users = array();
while ($row = $db->fetchArray($result)) {
	$current_users[] = $row[uid];
}
$sql = "SELECT uid, uname FROM ".$db->prefix("users")." WHERE uid <> 0 AND level <> -1 ";
while (list($null, $curr_userid) = each($current_users)) {
	$sql .= "AND (uid != $curr_userid) ";
}
$sql .= "ORDER BY uname ASC";
if (!$result = $db->query($sql)) {
	CloseTable();
	xoops_cp_footer();
	exit();
}
while ($row = $db->fetchArray($result)) {
	?>
	<option value="<?php echo $row['uid'] ?>"><?php echo $row['uname'] ?></option>
	<?php
}
?>
</select>
<br /><br />
<input type="hidden" name="op" value="adduser" />
<input type="hidden" name="forum" value="<?php echo $forum ?>" />
<input type="submit" class="button" name="submit" value="<?php echo _MD_A_ADDUSERS;?>" />
</form>
<?php
$link = "./admin_priv_forums.php?forum=".$forum."&amp;op=clearusers";
echo myTextForm($link, _MD_A_CLEARALLUSERS);
?>
<td valign="top" class="bg3" align="center">
<?php
$sql = "SELECT u.uname, u.uid, f.can_post FROM ".$db->prefix("users")." u, ".$db->prefix("bb_forum_access")." f WHERE u.uid=f.user_id AND f.forum_id=$forum ORDER BY u.uname ASC";
if (!$result = $db->query($sql)) {
	CloseTable();
	xoops_cp_footer();
	exit();
}
?>
<table border="0" cellpadding="10" cellspacing="0">
<?php
while ($row = $db->fetchArray($result)) {
	$post_text = ($row['can_post']) ? "can" : "can't";
	$post_text .= " post";
	$post_toggle_link = XOOPS_URL."/modules/newbb/admin/admin_priv_forums.php?forum=$forum&op_userid=".$row['uid']."&op=";
	if ($row['can_post']) {
		$post_toggle_link .= "revokeuserpost";
		$post_toggle_link = myTextForm($post_toggle_link, _MD_A_REVOKEPOSTING);
		} else {
			$post_toggle_link .= "grantuserpost";
			$post_toggle_link = myTextForm($post_toggle_link, _MD_A_GRANTPOSTING);
		}
	$remove_link = myTextForm(XOOPS_URL."/modules/newbb/admin/admin_priv_forums.php?forum=$forum&op=deluser&op_userid=".$row['uid'], _MD_A_REMOVE);
	?>
	<tr>
	<td valign="top"><b><?php echo $row['uname']?></b></td>
	<td valign="top" nowrap><?php echo $post_text ?></td>
	<td valign="top"><?php echo $post_toggle_link ?></td>
	<td valign="top"><?php echo $remove_link ?></td>
	<tr>
	<?php
}
?>
</table>
</td>
</tr></table>
</form>
</table></td>
</tr></table>
<?php
}
}
CloseTable();
xoops_cp_footer();
?>
