<?php
class GroupController extends Easy_Controller_Action {
	public function Init(){
		$this->_Group = new GroupModel();
	}
	public function IndexAction(){
		$this->_View->grouplist = $this->_Group->getAll();
	}
	public function AddAction(){
		if ($this->_Request->isPost()){
			if ($this->_Group->add($this->_Request->getPost())){
				$this->_View->message = _('添加成功!');
			}else{
				$this->_View->message = $this->_Group->error;
			}
			exit($this->_View->render('message'));
		}
	}
	public function deleteAction(){
		if ($this->_Request->getParam('id')){
			$this->_Group->delete($this->_Request->getParam('id'));
			$this->_View->message = _('删除成功!');
			exit($this->_View->render('message'));
		}
	}
	public function ModifyAction(){
		if ($this->_Request->getParam('id')){
			$this->_View->modify = $this->_Group->getRow($this->_Request->getParam('id'));
		}elseif ($this->_Request->isPost()){
			if ($this->_Group->modify($this->_Request->getPost()) !==false){
				$this->_View->message = _('修改成功!');
			}else{
				$this->_View->message = $this->_Group->error;
			}
			exit($this->_View->render('message'));
		}
	}
}