<?php
if(!defined('MOD'))  die("access die");
if($admin_info['groupid'] > 2 ) qbase::purviewCheckDie();
$action = $_GET['action'];
qbase::checkAction( $action);
require_once(R_P . "/include/class.group.php");
$group = new group();
switch($action){
	case 'manage':
		$data = $group->manage();
	break;

	case 'add':
		if($_POST['update']){
			$group->add();
			qbase::showmsg("操作成功", 'default', "system.php?sys=group&action=manage");
		}else{
			
		}
	break;

	case 'edit':
		$gid = intval($_GET['gid']);
		$g = qdb::queryFirst("select * from ".TABLEPRE."user_group where gid = '{$gid}'");
		if(empty($g) || $gid == 1) qbase::showmsg("提交了错误的请求");
		if($_POST['update']){
			$group->edit($gid);
			qbase::showmsg("操作成功", 'default', "system.php?sys=group&action=manage");
		}
		$g['purview'] = @unserialize($g['purview']);
	break;

	case 'delete':
		checkAdminReferer();
		$gid = intval($_GET['gid']);
		if(empty($gid) || empty($usergroup[$gid]) || $usergroup[$gid]['type'] == 1) qbase::showmsg("提交了错误的请求");
		$num = qdb::queryAlone("select count(*) as num from ".TABLEPRE."user_extend where gid = '{$gid}' ");
		if($num > 0) qbase::showmsg("出错了，此用户组下还有用户，不能删除");
		$group->del($gid);
		qbase::showmsg("操作成功", 'default', "system.php?sys=group&action=manage");
	break;

	case 'cache':
		checkAdminReferer();
		$group->cache();
		qbase::showmsg("用户组缓存刷新成功");
	break;
}
include qbase::template($path . 'group');
?>
