<?php
/*
秀影EasyFramework框架
qq:24498936
msn:jdzcn_net@hotmail.com
website:http://www.vodcms.com
*/
class ModuleController extends Easy_Controller_Action {
	public function Init(){
		$this->_ModuleModel = new ModuleModel();
		$this->_View->mid = $this->_Request->getParam('mid');
	}
	public function IndexAction(){
		$this->_View->listModule = $this->_ModuleModel->getAllModule();	//列出承有菜单数捿
		$this->_View->option = $this->_ModuleModel->CreateOption();
	}
	public function AddAction(){
		$this->_View->topModule = $this->_ModuleModel->listModule(array('parentid'=>0));//列出一级菜单
		//print_r($this->_View->topModule);
		if ($this->_Request->isPost()){
			$array = array();
			$array['name'] = trim($this->_Request->getPost('name'));
			$array['url'] = $this->_Request->getPost('url');
			$array['parentid'] = (int)$this->_Request->getPost('parentid');
			$array['islink'] = $this->_Request->getPost('islink');
			if ($array['name']){
				if($array['parentid']){
					if ($array['url']){
						$this->_View->error = '必须填写链接地址!';
					}
				}
				if ($this->_ModuleModel->addModule($array)===flase){
					$this->_View->error = $this->_ModuleModel->error;
				}else{
					$this->_View->message = _('添加新模块成功!');
					exit($this->_View->render("message"));
				}
			}else{
				$this->_View->error = '必须填写模块吿!';
			}
		}
	}
	/*
	获取一行指定条件的数据记录
	*/
	public function modifyAction(){
		if ($this->_Request->isPost()){
			$array = array();
			$array = $this->_Request->getPost();
			if ($this->_ModuleModel->modifyModule($array, 'id='.(int)$array['id'])===false){
				$this->_View->message = $this->_ModuleModel->error;
				exit($this->_View->render('message'));
			}else{
				$this->_View->message = '修改模块成功!';
				exit($this->_View->render('message'));
			}
		}elseif ($this->_Request->getParam('do') == 'sort'){
			$this->_ModuleModel->sort($this->_Request->getParam('tbl'));
			exit;
		}else{
			$this->_View->topModule = $this->_ModuleModel->listModule(array('parentid'=>0));//列出一级菜单
			$this->_View->modify = $this->_ModuleModel->getModule('id='.$this->_View->mid);
		}
	}
	public function deleteAction(){
		if ($this->_ModuleModel->delete($this->_View->mid)===false){
			$this->_View->message = $this->_ModuleModel->error;
		}else{
			$this->_View->message = _('删除成功!');
		}
		exit($this->_View->render('message'));
	}
}