<?php
class SupermanController extends Easy_Controller_Action{
	public function Init(){
		$this->_ModuleModel = new ModuleModel();
		$this->_Group = new SupermanModel();
	}
	public function IndexAction(){
		$this->_View->parents = $this->_Group->listMethod(" name != ''  GROUP BY controller");
		$this->_View->_Group = $this->_Group;
		$this->_View->listGroup = $this->_Group->getAll();
	}
	public function addAction(){
		if (strtolower($license['version']) == 'free' || $_SERVER['HTTP_HOST'] == '127.0.0.1'){
			if ($this->_Request->getPost('num')>10){
				$this->_View->message = _('非企业版无法使用此项功能!');
				exit($this->_View->render('message'));
			}
		}
		if ($this->_Group->Add($this->_Request->getPost())===false){
			$this->_View->subject = _('添加失败!');
			$this->_View->message['content'] = $this->_Group->error;
		}else{
			$this->_View->subject = _('添加管理员组!');
			$this->_View->message = _('添加成功!');
		}
		exit($this->_View->render('message'));
	}
	public function scanAction(){
		$do = $this->_Request->getParam('do');
		$id = $this->_Request->getParam('id');
		if ($do == 'modify'){
			if ($this->_Request->isPost()){
				$this->_Group->modifyMethod($this->_Request->getPost());
				$this->_View->subject = _('修改权限控制');
				$this->_View->message  = _('修改成功!');
				exit($this->_View->render('message'));
			}else{
				$this->_View->modify = $this->_Group->getMethods('id='. $id);
				exit($this->_View->render('superman/superman_scan_modify'));
			}
			
		}elseif ($do == 'delete'){
			$this->_Group->deleteMethod($id);
			$this->_View->message = _('删除成功!');
			exit($this->_View->render('message'));
		}else{
			$this->_Group->scan();
			
			$this->_View->listmethod = $this->_Group->listMethod();
			$this->_View->printpage = $this->_Group->printpage;
		}
	}
	public function modifyAction(){
		if ($this->_Request->isPost()){
			if ( $this->_Group->modify($this->_Request->getPost())===false){
				$this->_View->subject = _('修改组资料');
				$this->_View->message = $this->_Group->error;
			}else{
				$this->_View->subject = _('修改组资料');
				$this->_View->message = _('修改成功!');			
			}
			exit($this->_View->render('message'));
		}else{
			$id = (int)$this->_Request->getParam('id');
			$this->_View->parents = $this->_Group->listMethod(" name != ''  GROUP BY controller");
			$this->_View->_Group = $this->_Group;
			$this->_View->modify = $this->_Group->getRow($id);
		}
		//print_r($this->_View->modify['Permission']['modulecontroller']);
	}
	/*
	删除用户组
	*/
	public function deleteAction(){
		$id = (int)$this->_Request->getParam('id');
		if ($this->_Group->delete($id)===false){
			$this->_View->message = $this->_Group->error;
		}else{
			$this->_View->message = _('删除成功!');
		}
		exit($this->_View->render('message'));	
	}
}?>