 <?php
/**
 * [LJCMS] (C)2012-2099 LJdev,Inc.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2013.11.19
*/

class control extends adminbase {
    
	private $_comeurl = NUll;
    private $_urlitem = NULL;
    private $sgroupid = NULL;
    private $susername = NULL; 

   
    private function _getItems() {
        $this->sgroupid = XRequest::getInt('sgroupid');
        $this->susername = XRequest::recArgs('susername');
        $this->_urlitem = "sgroupid=".$this->sgroupid."&susername=".urlencode($this->susername)."";
        $this->_comeurl = $this->_urlitem."&page=".$this->page."";
    }

	
    public function action_run() {
        $this->checkAuth('run');
        $this->_getItems();
        $searchsql = "";
        if ($this->sgroupid>0) {
            $searchsql .= " AND v.groupid='".$this->sgroupid."'";
        }
        if (!empty($this->susername)) {
            $searchsql .= " AND lower(v.name) LIKE '%".strtolower($this->susername)."%'";
        }

        $model = parent::model('admin', 'am');
        list($datacount, $data) = $model->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
        $url = XRequest::getPhpSelf();
        $url .= '?c=admin&'.$this->_urlitem;
        $var_array = array(
            'page'=>$this->page,
            'nextpage'=>$this->page+1,
            'prepage'=>$this->page-1,
            'pagecount'=>ceil($datacount/$this->pagesize),
            'pagesize'=>$this->pagesize,
            'total'=>$datacount,
            'showpage'=>XPage::admin($datacount, $this->pagesize, $this->page, $url, 10),
            'itemurl'=>$this->_urlitem,
            'comeurl'=>$this->_comeurl,
            'sgroupid'=>$this->sgroupid,
            'susername'=>$this->susername,
            'admin'=>$data,
        );
        unset($model);
		TPL::assign($var_array);
		TPL::display($this->cptpl.'admin.tpl');
	}
    
     public function action_user() {
         $this->checkAuth('user');
        $this->_getItems();
        $searchsql = "";

        if (!empty($this->susername)) {
            $searchsql .= "where lower(name) LIKE '%".strtolower($this->susername)."%'";

        }

        $model = parent::model('adminuser', 'am');
        list($datacount, $data) = $model->getListUser(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));

        $url = XRequest::getPhpSelf();
        $url .= '?c=admin&'.$this->_urlitem;
        $var_array = array(
            'page'=>$this->page,
            'nextpage'=>$this->page+1,
            'prepage'=>$this->page-1,
            'pagecount'=>ceil($datacount/$this->pagesize),
            'pagesize'=>$this->pagesize,
            'total'=>$datacount,
            'showpage'=>XPage::admin($datacount, $this->pagesize, $this->page, $url, 10),
            'itemurl'=>$this->_urlitem,
            'comeurl'=>$this->_comeurl,
            'sgroupid'=>$this->sgroupid,
            'susername'=>$this->susername,
            'adminuser'=>$data,
        );

        unset($model);
        TPL::assign($var_array);
        TPL::display($this->cptpl.'adminuser.tpl');
        // var_dump($var_array);
        // die();
    }

      public function action_notify() {
         $this->checkAuth('notify');
        $this->_getItems();
        $searchsql = "";
        if ($this->sgroupid>0) {
            $searchsql .= " AND v.groupid='".$this->sgroupid."'";
        }
        if (!empty($this->susername)) {
            $searchsql .= " AND lower(v.adminname) LIKE '%".strtolower($this->susername)."%'";
        }
        $model = parent::model('notify', 'am');
        list($datacount, $data) = $model->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
        $url = XRequest::getPhpSelf();
        $url .= '?c=admin&'.$this->_urlitem;
        $var_array = array(
            'page'=>$this->page,
            'nextpage'=>$this->page+1,
            'prepage'=>$this->page-1,
            'pagecount'=>ceil($datacount/$this->pagesize),
            'pagesize'=>$this->pagesize,
            'total'=>$datacount,
            'showpage'=>XPage::admin($datacount, $this->pagesize, $this->page, $url, 10),
            'itemurl'=>$this->_urlitem,
            'comeurl'=>$this->_comeurl,
            'sgroupid'=>$this->sgroupid,
            'susername'=>$this->susername,
            'notify'=>$data,
        );
        unset($model);
        // var_dump($var_array);
        TPL::assign($var_array);
        TPL::display($this->cptpl.'notify.tpl');
    }

    public function action_add() {
        $this->checkAuth('add');
        $model = parent::model('admin', 'am');
        list($datacount, $data) = $model->getroleList(array('page'=>$this->page, 'pagesize'=>$this->pagesize,));
        $var_array = array(
            'data'=>$data,
        );
        unset($model);
        // var_dump($var_array);
        TPL::assign($var_array);
        TPL::display($this->cptpl.'admin.tpl'); 
    }
    
    
    public function action_edit() {
        $this->checkAuth('edit');
        $id = XRequest::getInt('id');
        $this->_validID($id);
        $this->_getItems();
        $model = parent::model('admin', 'am');
        list($datacount, $group) = $model->getroleList(array('page'=>$this->page, 'pagesize'=>$this->pagesize,));
        $data = $model->getData($id);
        if (empty($data)) {
            XHandle::halt('对不起，读取数据不存在！', '', 1);
        }
        else {
            parent::loadLib('mod');
            $var_array = array(
                'admin'=>$data,
                'id'=>$id,
                'comeurl'=>$this->_comeurl,
                'group'=>$group
            );
            TPL::assign($var_array);
            TPL::display($this->cptpl.'admin.tpl');
        }
        unset($model);
    }
    
     
    public function action_editpassword() {
        $this->checkAuth('editpassword');
        $var_array = array(
            'uc_adminname'=>parent::$wrap_admin['adminname'],
        );
        TPL::assign($var_array);
        TPL::display($this->cptpl.'admin.tpl'); 
    }

    public function action_useredit() {
        $this->checkAuth('useredit');
        $id = XRequest::getInt('id');
        $this->_validID($id);
        $this->_getItems();
        $model = parent::model('adminuser', 'am');
        $data = $model->getuserDataid($id);
        if (empty($data)) {
            XHandle::halt('对不起，读取数据不存在！', '', 1);
        }
        else {
            parent::loadLib('mod');
            $var_array = array(
                'admin'=>$data,
                'id'=>$id,
                'comeurl'=>$this->_comeurl,
            );
            TPL::assign($var_array);
            TPL::display($this->cptpl.'adminuser.tpl');
        }
        unset($model);
    }
    
     
    public function action_usereditpassword() {
        $this->checkAuth('usereditpassword');
        $var_array = array(
            'uc_adminname'=>parent::$wrap_admin['adminname'],
        );
        TPL::assign($var_array);
        TPL::display($this->cptpl.'adminuser.tpl'); 
    }
  
    public function action_saveadd() {
        $this->checkAuth('saveadd');
		$args = XRequest::getGpc(
            array('adminname', 'password', 'confirmpassword', 
                'groupid', 'super', 'flag', 'memo')
        );
        $args = $this->_validAdd($args);
        if($args['groupid']=='0'){
           $args['super']=1;
        }
        $model = parent::model('admin', 'am');
        if (true === $model->doCheckUserName($args['adminname'])) {
            XHandle::halt('对不起，该帐号已存在，请填写另外一个。', '', 1);
        }
        else {
            $result = $model->doAdd($args);
            if (true === $result) {
                $this->log('admin_add', '', 1);
                XHandle::halt('添加成功', $this->cpfile.'?c=admin', 0);
            }
            else {
                $this->log('admin_add', '', 0);
                XHandle::halt('添加失败', '', 1);
            }
        }
        unset($model);	
	}
    
    public function action_saveedit() {
        $this->checkAuth('saveedit');
        $id = XRequest::getInt('id');
        $args = XRequest::getGpc(
            array(
                'password', 'confirmpassword', 'groupid', 'super', 'flag', 'memo'
            )
        );
        $args = $this->_validEdit($id, $args);
if($args['groupid']=='0'){
           $args['super']=1;
        }
        $this->_getItems();
        $model = parent::model('admin', 'am');
        $result = $model->doEdit($id, $args);
        if (true === $result) {
            $this->log('admin_edit', "id={$id}", 1);
            XHandle::halt('编辑成功', $this->cpfile.'?c=admin&'.$this->_comeurl.'', 0);
        }
        else {
            $this->log('admin_edit', "id={$id}", 0);
            XHandle::halt('编辑失败', '', 1);
        }
        unset($model);
    }
     public function action_saveedit1() {
       
        $this->checkAuth('saveedit1');
        $id = XRequest::getInt('id');
      
        $args = XRequest::getGpc(
            array(
                'password', 'email'
            )
        );
        unset($args['remark']);
//        $args = $this->_validEdit($id, $args);

        $this->_getItems();
        $model = parent::model('adminuser', 'am');
        $result = $model->doEditUser($id, $args);
        if (true === $result) {
            $this->log('admin_edit', "id={$id}", 1);
            XHandle::halt('编辑成功', $this->cpfile.'?c=admin&a=user', 0);
        }
        else {
            $this->log('admin_edit', "id={$id}", 0);
            XHandle::halt('编辑失败', '', 1);
        }
        unset($model);
    }     
    
    public function action_del() {
        $this->checkAuth('del');
        $array_id = XRequest::getArray('id');
        $this->_validID($array_id);
        $model = parent::model('admin', 'am');
        for($ii=0; $ii<count($array_id); $ii++){
            $id = intval($array_id[$ii]);
            if (true === $model->doCheckUid($id)){
                XHandle::halt('对不起，您不能删除自己的帐号！', '', 1);
            }
            $result = $model->doDel($id);            
        }
        
        if (true === $result) {
            $this->log('admin_del', "id={$array_id}", 1);
            XHandle::halt('删除成功', $this->cpfile.'?c=admin', 0);
        }
        else {
            $this->log('admin_del', "id={$array_id}", 0);
            XHandle::halt('删除失败', '', 1);
        }
        unset($model); 
    }

    public function action_delete() {
        $this->checkAuth('delete');
        $array_id = XRequest::getArray('id');
       
        $this->_validID($array_id);
        $model = parent::model('adminuser', 'am');
        for($ii=0; $ii<count($array_id); $ii++){
            $id = intval($array_id[$ii]);
            $result = $model->deluser($id);
        }
        
        if (true === $result) {
            $this->log('admin_del', "id={$array_id}", 1);
            XHandle::halt('删除成功', $this->cpfile.'?c=admin&a=user', 0);
        }
        else {
            $this->log('admin_del', "id={$array_id}", 0);
            XHandle::halt('删除失败', '', 1);
        }
        unset($model); 
    }
        public function action_nodelete() {
        $this->checkAuth('nodelete');
        $array_id = XRequest::getArray('id');
        $this->_validID($array_id);
        $model = parent::model('notify', 'am');
        for($ii=0; $ii<count($array_id); $ii++){
            $id = intval($array_id[$ii]);
            $result = $model->doDel($id);            
        }
        
        if (true === $result) {
            $this->log('admin_del', "id={$array_id}", 1);
            XHandle::halt('删除成功', $this->cpfile.'?c=admin&a=notify', 0);
        }
        else {
            $this->log('admin_del', "id={$array_id}", 0);
            XHandle::halt('删除失败', '', 1);
        }
        unset($model); 
    }
    
    
    public function action_savepassword() {
        $this->checkAuth('savepassword');
        $args = array(
            'oldpassword'=>XRequest::recArgs('oldpassword'),
            'password'=>XRequest::recArgs('password'),
            'confirmpassword'=>XRequest::recArgs('confirmpassword'),
        );
        $args = $this->_validPassword($args);
        $model = parent::model('admin', 'am');
        if (true === $model->doEditPass($args['password'])){
            $this->log('admin_editpassword', '', 1);
            XHandle::halt('恭喜你，修改密码成功，请记住新密码。', $this->cpfile.'?c=admin&a=editpassword', 0);
        } 
        else {
            $this->log('admin_editpassword', '', 0);
            XHandle::halt('对不起，修改密码失败！', '', 1);
        } 
        unset($model);            
    }
    
    
    public function action_update() {
       
        $this->checkAuth('update');
        $args = XRequest::getGpc(array('id', 'type','lei'));
         //echo intval($args['lei']);die;
        $model = parent::model('admin', 'am');
        $model->doUpdate(intval($args['id']), trim($args['type']),intval($args['lei']));
        unset($model);
    }
    
    
    private function _validAdd($array) {
        if (!XValid::isUserArgs($array['adminname'])) {
            XHandle::halt('帐号格式不正确，只能由字母、数字、下横线、中文组成', '', 1);
        }
        if (!XValid::isLength($array['adminname'], 4, 16)){
            XHandle::halt('帐号长度不正确，必须为4-16个字符', '', 1);
        }
        if (!XValid::isLength($array['password'], 4, 16)){
            XHandle::halt('密码长度不正确，必须为4-16个字符', '', 1);
        }
        if ($array['confirmpassword'] != $array['password']){
            XHandle::halt('确认密码不正确', '', 1);
        }
        $array['groupid'] = intval($array['groupid']);
        $array['super'] = intval($array['super']); 
        $array['flag'] = intval($array['flag']);
        unset($array['confirmpassword']);
        return $array;
    }
    
    
    private function _validEdit($id, $array) {
        if ($id<1) {
            XHandle::halt('ID丢失', '', 1);
        }
        if (!empty($array['password'])) {
            if (!XValid::isLength($array['password'], 4, 16)){
                XHandle::halt('密码长度不正确，必须为4-16个字符', '', 1);
            }
            if ($array['confirmpassword'] != $array['password']){
                XHandle::halt('确认密码不正确', '', 1);
            }
            
            unset($array['confirmpassword']);
        }
        else {
            unset($array['password']);
            unset($array['confirmpassword']);
        }
        $array['groupid'] = intval($array['groupid']);
        $array['super'] = intval($array['super']); 
        $array['flag'] = intval($array['flag']); 
        return $array;
    }
    
    
    private function _validID($id) {
        if (empty($id)) {
            XHandle::halt('ID丢失，请选择要操作的ID', '', 1);
        }
    }
    
    
    private function _validPassword($array) {
        if (empty($array['oldpassword'])) {
            XHandle::halt('请输入原密码', '', 1);
        }
        else {
            $model = parent::model('admin', 'am');
            if (false === $model->doCheckPassword($array['oldpassword'])) {
                XHandle::halt('对不起，原密码不正确！', '', 1);
            }
            unset($model);
        }
        if (!XValid::isLength($array['password'], 4, 16)){
            XHandle::halt('新密码长度不正确，必须为4-16个字符', '', 1);
        }
        if ($array['confirmpassword'] != $array['password']){
            XHandle::halt('确认密码不正确', '', 1);
        }    
        return $array;
        $this->_getItems();
    }
    
    //角色管理列表
    public function action_role(){
        $this->checkAuth('role');
      $this->_getItems();
        $searchsql = "";
        
        if (!empty($this->susername)) {
            $searchsql .= " AND lower(v.name) LIKE '%".strtolower($this->susername)."%'";
        }
        $model = parent::model('admin', 'am');
        list($datacount, $data) = $model->getroleList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
        $url = XRequest::getPhpSelf();
        $url .= '?c=admin&'.$this->_urlitem;
        $var_array = array(
            'page'=>$this->page,
            'nextpage'=>$this->page+1,
            'prepage'=>$this->page-1,
            'pagecount'=>ceil($datacount/$this->pagesize),
            'pagesize'=>$this->pagesize,
            'total'=>$datacount,
            'showpage'=>XPage::admin($datacount, $this->pagesize, $this->page, $url, 10),
            'itemurl'=>$this->_urlitem,
            'comeurl'=>$this->_comeurl,
            'sgroupid'=>$this->sgroupid,
            'susername'=>$this->susername,
            'admin'=>$data,
        );
        unset($model);
		TPL::assign($var_array);              
        TPL::display($this->cptpl.'role.tpl');
    }
    //角色管理列表
    public function action_addrole(){
        $this->checkAuth('addrole');
         $model = parent::model('admin', 'am');
        $detail = array();
//    	if($role_id){
//    		$detail = M('admin_role')->where("role_id",$role_id)->find();
//    		$detail['act_list'] = explode(',', $detail['act_list']);
//    		$this->assign('detail',$detail);
//    	}
        list($datacount, $data) = $model->getgroupList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
       
		foreach ($data as $val){
			if(!empty($detail)){
			     $val['enable'] = in_array($val['id'], $detail['act_list']);
                        }
                        
			$modules[$val['group']][] = $val;
                        
		}
                $group = array('system'=>'系统设置','category'=>'模块管理','skin'=>'界面模板','plugin'=>'插件应用','mynav'=>'我的导航'  		
                            );
                   //         print_r($modules);
        $var_array = array(
                'group'=>$group,
                'modules'=>$modules
        );
         TPL::assign($var_array);     
        TPL::display($this->cptpl.'role.tpl');
    }
        //角色管理列表
    public function action_editrole(){
        $this->checkAuth('editrole');
         $model = parent::model('admin', 'am');
        $detail = array();
        $id = $_REQUEST['id'];
     	if($id){
                $model = parent::model('admin', 'am');
     		$detail = $model->getRole($id);        
                 
    		$detail['auths'] = explode(',', $detail['auths']);

     	}
        list($datacount, $data) = $model->getgroupList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
       
		foreach ($data as $val){
			if(!empty($detail)){
			     $val['enable'] = in_array($val['id'], $detail['auths']);
                        }
                        
			$modules[$val['group']][] = $val;
                        
		}
                $group = array('system'=>'系统设置','category'=>'模块管理','skin'=>'界面模板','plugin'=>'插件应用','mynav'=>'我的导航'  		
                            );
                   //         print_r($modules);
        $var_array = array(
                'detail'=>$detail,
                'modules'=>$modules
        );
         TPL::assign($var_array);            
        TPL::display($this->cptpl.'role.tpl');
    }
       public function action_saveaddrole() {
        $this->checkAuth('saveaddrole');
      
       $args['groupname']=$_POST['role_name'];
       $args['auths']=is_array($_POST['right']) ? implode(',', $_POST['right']) : '';         
       $args['role_desc'] = $_POST['desc'];
       $args['addtime']= time();
        $model = parent::model('admin', 'am');
        if (true === $model->doCheckGroupName($args['groupname'])) {
            XHandle::halt('对不起，该角色名称已添加，请填写另外一个。', '', 1);
        }
        else {
            $result = $model->doAddRole($args);
            if (true === $result) {
                $this->log('saveaddrole', '', 1);
                XHandle::halt('添加成功', $this->cpfile.'?c=admin&a=role', 0);
            }
            else {
                $this->log('saveaddrole', '', 0);
                XHandle::halt('添加失败', '', 1);
            }
        }
        unset($model);	
	}
    
    public function action_saveeditrole() {
        $this->checkAuth('saveeditrole');
        $id = $_POST['id'];

       $args['groupname']=$_POST['role_name'];
       $args['auths']=is_array($_POST['right']) ? implode(',', $_POST['right']) : '';         
       $args['role_desc'] = $_POST['desc'];
        $model = parent::model('admin', 'am');
            $result = $model->dosaveRole($id,$args);
            if (true === $result) {
                $this->log('saveeditrole', '', 1);
                XHandle::halt('修改成功', $this->cpfile.'?c=admin&a=role', 0);
            }
            else {
                $this->log('saveeditrole', '', 0);
                XHandle::halt('修改失败', '', 1);
            }
        
        unset($model);
    }
        public function action_delrole() {
        $this->checkAuth('delrole');
        $array_id = XRequest::getArray('id');
        
        $this->_validID($array_id);
        $model = parent::model('admin', 'am');
        for($ii=0; $ii<count($array_id); $ii++){
            $id = intval($array_id[$ii]);
            $result = $model->doRoleDel($id);            
        }
        
        if (true === $result) {
            $this->log('doRoleDel', "id={$array_id}", 1);
            XHandle::halt('删除成功', $this->cpfile.'?c=admin&a=role', 0);
        }
        else {
            $this->log('doRoleDel', "id={$array_id}", 0);
            XHandle::halt('删除失败', '', 1);
        } 
    }
        //权限管理列表
    public function action_group(){
        $this->checkAuth('group');
         $this->_getItems();
        $searchsql = "";
        
        if (!empty($this->susername)) {
            $searchsql .= " AND lower(v.name) LIKE '%".strtolower($this->susername)."%'";
        }
        $model = parent::model('admin', 'am');
        list($datacount, $data) = $model->getgroupList1(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
        $url = XRequest::getPhpSelf();
        $url .= '?c=admin&a=group';

        $var_array = array(
            'page'=>$this->page,
            'nextpage'=>$this->page+1,
            'prepage'=>$this->page-1,
            'pagecount'=>ceil($datacount/$this->pagesize),
            'pagesize'=>$this->pagesize,
            'total'=>$datacount,
            'showpage'=>XPage::admin($datacount, $this->pagesize, $this->page, $url, 10),
            'itemurl'=>$this->_urlitem,
            'comeurl'=>$this->_comeurl,
            'sgroupid'=>$this->sgroupid,
            'susername'=>$this->susername,
            'admin'=>$data,
        );
        unset($model);
		TPL::assign($var_array);        
        TPL::display($this->cptpl.'group.tpl');
    }
    //角色管理列表
    public function action_addgroup(){
        $this->checkAuth('addgroup');
        $group = array('system'=>'系统设置','category'=>'模块管理','skin'=>'界面模板','plugin'=>'插件应用','mynav'=>'我的导航'  		
     	);
        $planPath = 'source/control/admincp';
     	$planList = array();
     	$dirRes   = opendir($planPath);
     	while($dir = readdir($dirRes))
     	{
     		if(!in_array($dir,array('.','..','.svn')))
     		{
     			$planList[] = basename($dir,'.php');
     		}
     	}
        $var_array = array(
                'group'=>$group,
                'planList'=>$planList
        );
         TPL::assign($var_array);
        TPL::display($this->cptpl.'group.tpl');
    }
        //角色管理列表
    public function action_editgroup(){
        $this->checkAuth('editgroup');
         $group = array('system'=>'系统设置','category'=>'模块管理','skin'=>'界面模板','plugin'=>'插件应用','mynav'=>'我的导航'  		
     	);
        $id = $_REQUEST['id'];
     	if($id){
                $model = parent::model('admin', 'am');
     		$info = $model->getGroup($id);
     		$info['right'] = explode(',', $info['right']);
     		
     	}
         $planPath = 'source/control/admincp';
     	$planList = array();
     	$dirRes   = opendir($planPath);
     	while($dir = readdir($dirRes))
     	{
     		if(!in_array($dir,array('.','..','.svn')))
     		{
     			$planList[] = basename($dir,'.php');
     		}
     	}
        $var_array = array(
                'group'=>$group,
                'planList'=>$planList,
                'info'=>$info
        );
         TPL::assign($var_array);
        TPL::display($this->cptpl.'group.tpl');
    }
    public function action_ajax_get_action()
     {     
     	$advContrl = get_class_methods('control');
   
        
     	$html = '';
     	foreach ($advContrl as $val){
            if(strpos($val,'action') !== false){
                   
               $html .= "<option value='".$val."'>".$val."</option>";
                    
            } else {
               
            }
     		
     	}
     	exit($html);
     }
        public function action_saveaddgroup() {
        $this->checkAuth('saveaddgroup');
      
       $args['`name`']=$_POST['name'];
       $args['`group`']=$_POST['group'];           
      $args['`right`'] = implode(',',$_POST['right']);
        $model = parent::model('admin', 'am');
        if (true === $model->doCheckGroupName($args['`name`'])) {
            XHandle::halt('对不起，该权限名称已添加，请填写另外一个。', '', 1);
        }
        else {
            $result = $model->doAddGroup($args);
            if (true === $result) {
                $this->log('saveaddgroup', '', 1);
                XHandle::halt('添加成功', $this->cpfile.'?c=admin&a=group', 0);
            }
            else {
                $this->log('admin_add', '', 0);
                XHandle::halt('添加失败', '', 1);
            }
        }
        unset($model);	
	}
    
    public function action_saveeditgroup() {
        $this->checkAuth('saveeditgroup');
        $id = $_POST['id'];
        $args['`name`']=$_POST['name'];
        $args['`group`']=$_POST['group'];           
        $args['`right`'] = implode(',',$_POST['right']);
        $model = parent::model('admin', 'am');
            $result = $model->dosaveGroup($id,$args);
            if (true === $result) {
                $this->log('saveeditgroup', '', 1);
                XHandle::halt('修改成功', $this->cpfile.'?c=admin&a=group', 0);
            }
            else {
                $this->log('saveeditgroup', '', 0);
                XHandle::halt('修改失败', '', 1);
            }
        
        unset($model);
    }
        public function action_delgroup() {
        $this->checkAuth('elgroup');
        $array_id = XRequest::getArray('id');
        
        $this->_validID($array_id);
        $model = parent::model('admin', 'am');
        for($ii=0; $ii<count($array_id); $ii++){
            $id = intval($array_id[$ii]);
            $result = $model->doGroupDel($id);            
        }
        
        if (true === $result) {
            $this->log('delgroup', "id={$array_id}", 1);
            XHandle::halt('删除成功', $this->cpfile.'?c=admin&a=group', 0);
        }
        else {
            $this->log('delgroup', "id={$array_id}", 0);
            XHandle::halt('删除失败', '', 1);
        } 
    }
}
?>
