<?php
class ServerController extends Easy_Controller_Action {
	public function init(){
		$this->_Server = new ServerModel();
	}
	public function IndexAction(){
		$this->_View->server = $this->_Server->getAll();
		$this->_View->PrintPage = $this->_Server->PrintPage;
		$this->_View->Option = $this->_Server->CreateOption();
	}
	public function AddAction(){
		if ($this->_Request->isPost()){
			if ($this->_Server->add($this->_Request->getPost()) === false){
				$this->_View->message = $this->_Server->error;
			}else{
				$this->_View->message = _('服务器添加成功!');
			}
			exit($this->_View->render('message'));
		}else{
			$this->_View->redirect('server/index');
		}
	}
	public function modifyAction(){
		$id = intval($this->_Request->getParam('id'));
		$this->_View->modify = $this->_Server->getRow($id);
		$this->_View->Option = $this->_Server->CreateOption($this->_View->modify['parentid']);
		if ($this->_Request->getParam('do') == 'locked'){
			$this->_Server->locked($id);
			$this->_View->redirect('server/index');
		}
		elseif($this->_Request->isPost()){
			if ($this->_Server->modify($this->_Request->getPost())===false){
				$this->_View->message = $this->_Server->error;
			}else{
				$this->_View->message = _('服务器修改成功!');
			}
			exit($this->_View->render('message'));
		}
	}
	public function deleteAction(){
		$id = intval($this->_Request->getParam('id'));
		$this->_Server->delete($id);
		$this->_View->redirect('server/index');
	}
}