<?php
/*
秀影EasyFramework框架
qq:24498936
msn:jdzcn_net@hotmail.com
website:http://www.vodcms.com
*/
class CategoryController extends Easy_Controller_Action {
	public function init(){
		$this->_Category = new CategoryModel();
	}
	public function indexAction(){
		$array = $this->_Category->getLocation((int)$this->_Request->getParam('id'));
		//print_r($array);
		foreach ($array as $row){
			$this->_View->location.= ' >> '. '<a href="'.$this->_View->installdir.'category/index/id/'.$row['id'].'/">'. $row['category'].'</a>';
		}
		$this->_View->category = $this->_Category->getAll('parentid='.(int)$this->_Request->getParam('id'));
	}
	public function addAction(){
		if ($this->_Request->isPost()){
			if ($this->_Category->add($this->_Request->getPost())===false){
				$this->_View->message = $this->_Category->error;
			}else{
				$this->_View->message = _('分类添加成功!');
			}
			exit($this->_View->render('message'));
		}
		$this->_View->option = $this->_Category->CreateOption(0, $this->_Request->getCookie('forget_categoryid'), '&nbsp;');
	}
	public function modifyAction(){
		$this->_View->modify = $this->_Category->getRow('id='.(int)$this->_Request->getParam('id'));
		$this->_View->option = $this->_Category->CreateOption(0, $this->_View->modify['parentid'], '&nbsp;');
		if ($this->_Request->getParam('do') == 'locked'){
			$this->_Category->locked($this->_Request->getParam('id'));
			$this->_View->redirect('category/index');
		}elseif($this->_Request->getParam('do') == 'sort')	//排序
		{
			$this->_Category->sort($this->_Request->getParam('tbl'));
			exit;
		}elseif($this->_Request->getParam('do') == 'move'){
			$this->_View->option = $this->_Category->CreateOptions(0, $this->_Request->getparam('id'), '&nbsp;');
			exit($this->_View->render('category/category_merge'));
		}elseif ($this->_Request->isPost()){
			if ($this->_Category->modify($this->_Request->getPost())===false){
				$this->_View->message = $this->_Category->error;
			}else{
				$this->_View->message = _('分类修改成功!');
			}
			exit($this->_View->render('message'));
		}
	}
	public function deleteAction(){
		if ($this->_Category->delete((int)$this->_Request->getParam('id')) === false){
			$this->_View->message = $this->_Category->error;
			exit($this->_View->render('message'));
		}
		$this->_View->redirect('category/index');
	}
	public function mergeAction(){
		if ($this->_Request->isPost()){
			$sourceid = $this->_Request->getPost('sourceid');
			$targetid = $this->_Request->getPost('targetid');
			$this->_Category->catergoryMerge($sourceid, $targetid);
			$this->_View->message = _('合并影片成功!');
			exit($this->_View->render('message'));
		}
	}
}