<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class usergroup_updateAction extends security_login {
	function action(){
		ModuleLimit(__CLASS__);
		global $conn;
		$userusergroup_id=$_POST['usergroup_id'];
		if($userusergroup_id){
			$usergroup=new model_Usergroup();
			$usergroup->setSubsection('WHERE usergroup_id='.$userusergroup_id);
			$results=$usergroup->doSelectOne();
		}

		
		
		$menus=',';
		$modules=',';
		if(sizeof($_POST['CategoryIdS'])){
			foreach($_POST['CategoryIdS'] as $key=>$value){
				$menus.=$key.',';
				if($value)	$modules.=$value.',';
			}
		}

		$name=$_POST['name'];
		$level=$_POST['level'];
		$intro=$_POST['intro'];

		if($name==""){
			$jsstring='Dialog.alert("组名不能为空",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}
		if($level<=0){
			$jsstring='Dialog.alert("级别必须大于0",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}

		if($results)
		{
			$ins='内容已存在';
			$gid=$results->getUsergroupId();
			$usergroup->setName($name);
			$usergroup->setLevel($level);
			$usergroup->setIntro($intro);
			$usergroup->setMenu($menus);
			$usergroup->setModule($modules);
			$results=$usergroup->doUpdate();
			if($results)
				$exeresult='更新成功';
			else
				$exeresult='更新失败';

		}else{
			$ins='内容已不存在';
			$usergroup=new model_Usergroup();
			$usergroup->setName($name);
			$usergroup->setLevel($level);
			$usergroup->setIntro($intro);
			$usergroup->setMenu($menus);
			$usergroup->setModule($modules);
			$results=$usergroup->doInsert();
			if($results){
				$exeresult='插入成功';
				$gid=$conn->Insert_ID();
			}else
				$exeresult='插入失败';
		}

		if($_POST['goon']==1){
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/usergroup/edit";window.event.returnValue = false;},300,100,"继续添加会员组");';
			MessageBox($jsstring);
		}else{
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/usergroup";window.event.returnValue = false;},300,100,"返回会员组列表");';
			MessageBox($jsstring);
		}
		exit;
	}
}
?>