<?php
// www.bcoos.net 2006-09 1.0.2 GPL
// $Id: main.php,v 1.3 2003/03/19 07:03:27 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
if ( !preg_match("/admin\.php/i", _PHP_SELF) ) {
	exit();
	}
include_once(XOOPS_ROOT_PATH."/modules/system/admin/groups/groups.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsgroup.php");
if( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
$op = "display";
if ( isset($_POST) ) {
	foreach ( $_POST as $k => $v ) {
		$$k = $v;
	}
}
if ( isset($_GET['op']) ) {
	if ( $_GET['op'] == "modify" || $_GET['op'] == "del" || $_GET['op'] == "delConf" ) {
		$op   = $_GET['op'];
		$g_id = $_GET['g_id'];
	}
}
// from finduser section
if ( !empty($memberslist_id) && is_array($memberslist_id) ) {
	$op   = "addUser";
	$uids =& $memberslist_id;
}
switch($op) {
case "modify":
	include_once(XOOPS_ROOT_PATH.'/class/xoopspagenav.php');
	modifyGroup($g_id);
	break;
case "update":
	$admin_mids = empty($admin_mids) ? array() : $admin_mids;
	$read_mids  = empty($read_mids)  ? array() : $read_mids;
	$read_bids  = empty($read_bids)  ? array() : $read_bids;
	updateGroup($g_id, $name, $desc, $admin_mids, $read_mids, $read_bids);
	break;
case "add":
	if (!$name) {
		xoops_cp_header();
		echo _AM_UNEED2ENTER;
		xoops_cp_footer();
		exit();
	}
	$admin_mids = empty($admin_mids) ? array() : $admin_mids;
	$read_mids  = empty($read_mids)  ? array() : $read_mids;
	$read_bids  = empty($read_bids)  ? array() : $read_bids;
	$xoopsgroup = new XoopsGroup();
	$xoopsgroup->setVar("name", $name);
	$xoopsgroup->setVar("description", $desc);
	$xoopsgroup->setAdminRightModules($admin_mids);
	array_push($read_mids, 1);
	$xoopsgroup->setReadRightModules($read_mids);
	$xoopsgroup->setReadRightBlocks($read_bids);
	if (!$xoopsgroup->store()) {
		xoops_cp_header();
		echo $xoopsgroup->getErrors();
		xoops_cp_footer();
		} else {
			redirect_header("admin.php?fct=groups&op=adminMain",1,_UPDATED);
		}
	break;
case "del":
	xoops_cp_header();
	echo "<b> "._AM_DELETEADG."</b><br /><br />";
	printf(_AM_AREUSUREDEL,$name);
	echo "<table><tr><td>";
	echo myTextForm("admin.php?fct=groups&op=delConf&g_id=$g_id", _YES);
	echo "</td><td>";
	echo myTextForm("admin.php?fct=groups&op=adminMain" , _NO);
	echo "</td></tr></table>";
	xoops_cp_footer();
	break;
case "delConf":
	$xoopsgroup = new XoopsGroup($g_id);
	$xoopsgroup->delete();
	redirect_header("admin.php?fct=groups&op=adminMain",1,_UPDATED);
	break;
case "addUser":
	$size = count($uids);
	for ( $i = 0; $i < $size; $i++ ) {
		$sql = "INSERT INTO ".$db->prefix("groups_users_link")." SET groupid=".$groupid.", uid=".$uids[$i]."";
		$db->query($sql);
	}
	redirect_header("admin.php?fct=groups&op=modify&g_id=".$groupid."",0,_UPDATED);
	break;
case "delUser":
	$size = count($uids);
	for ( $i = 0; $i < $size; $i++ ) {
		$sql = "DELETE FROM ".$db->prefix("groups_users_link")." WHERE uid=".$uids[$i]." AND groupid=".$groupid."";
		$db->query($sql);
	}
	redirect_header('admin.php?fct=groups&op=modify&g_id='.$groupid.'&amp;adminstart='.$adminstart,0,_UPDATED);
	break;
case "display":
	default:
	displayGroups();
	break;
}
// ------------------------------------------------------------------------- //
} else {
	echo "Access Denied";
}
?>
