<?php
// $Id: main.php,v 1.1 2004/07/11 10:28:51 Farsus Exp $
// -------------------------------------------------------------------------//
//			       RUNCMS                                                   //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// 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($HTTP_POST_VARS) ) {
	foreach ( $HTTP_POST_VARS as $k => $v ) {
		$$k = $v;
	}
}

if ( isset($HTTP_GET_VARS['op']) ) {
	if ( $HTTP_GET_VARS['op'] == "modify" || $HTTP_GET_VARS['op'] == "del" || $HTTP_GET_VARS['op'] == "delConf" ) {
		$op   = $HTTP_GET_VARS['op'];
		$g_id = $HTTP_GET_VARS['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";
}
?>
