<?php
/*
秀影6.x系统管理控制器
qq:24498936
*/
class VodcmsController extends Easy_Controller_Action {
	public function Init(){
		$this->_Vodcms = new VodcmsModel();
	}
	public function backupAction(){
		$this->_View->files = $this->_Vodcms->view($this->_Request->getParam('path'));
		$this->_View->path = $this->_Vodcms->path;
		$this->_View->printpage = $this->_Vodcms->printpage;
		if ($this->_Request->isPost()){
			$this->_Vodcms->export();
			$this->_View->message = _('备份成功!');
			exit($this->_View->render('message'));
		}elseif ($this->_Request->getParam('table')){
			$this->_Vodcms->exportData($this->_Request->getParam('table'));
			$this->_View->message = _($this->_Request->getParam('table').'表备份成功!');
			exit($this->_View->render('message'));
		}
	}
	public function downAction(){
		$filename = base64_decode($this->_Request->getParam('filename'));
		$IO = new Easy_Filesystem();
		$IO->attachment($filename);
		exit;
	}
	public function importAction(){//导入数据库
		$filename = base64_decode($this->_Request->getParam('filename'));
		$num = $this->_Vodcms->import($filename);
		if($num===false){
			$this->_View->message = _('数据库还原成功!');
		}else{
			$uri = $_SERVER['REQUEST_URI'].'num/'.$num.'/';
			$this->_View->jumpurl = $uri;
			$this->_View->meta = '<meta http-equiv="Refresh" content="3;URL='.$uri.'" />';
			$this->_View->message = _('还原文件'.$this->_Vodcms->sqlfile.'成功.3秒后自动还原下一个分卷');
			$this->_View->button = _('点击手动导入下一个分卷');
		}
		exit($this->_View->render('message'));
		exit;
	}
	public function deleteAction(){
		$filename = base64_decode($this->_Request->getParam('filename'));
		$rows = $this->_Vodcms->delete($filename);
		$this->_View->message = _('删除'.$rows.'个文件成功!');
		exit($this->_View->render('message'));
	}
	public function optimzerAction(){
		if ($this->_Request->isPost()){
			if(count($this->_Request->getPost('table'))>0){
				if ($this->_Request->getPost('select') == 'optimize'){
					$this->_Vodcms->optimize($this->_Request->getPost('table'));
					$this->_View->message = _('优化成功');
				}else{
					$this->_Vodcms->repair($this->_Request->getPost('table'));
					$this->_View->message = _('修复成功');
				}
				
			}else{
				$this->_View->message = _('请选择表');
			}
			exit($this->_View->render('message'));
		}
		$this->_View->tableStat = $this->_Vodcms->getStat();
		//print_r($this->_View->tableStat);
	}
	/*
	图片管理
	*/
	public function clearupAction(){
		$this->_View->pic = $this->_Vodcms->getPic();
	}
	/*sql*/
	public function  sqlAction(){
		if ($this->_Request->isPost()){
			if ($this->_Vodcms->exec($this->_Request->getPost('sql'))){
				$this->_View->message = _('命令执行成功');
			}else{
				$this->_View->message = _('命令执行失败');
			}
			$this->_View->jumpurl = $this->_View->installdir.'vodcms/sql/string/'.base64_encode($this->_Request->getPost('sql'));
			exit($this->_View->render('message'));
		}else{
			if ($this->_Request->getParam('string')){
			$this->_View->sql = base64_decode($this->_Request->getParam('string'));
			}
		}
	}
	/*
	*/
	public function clearAction(){
		if ($this->_Request->isPost()){
			$this->_Vodcms->clean();
			$this->_View->message = _('缓存清理成功');
			exit($this->_View->render('message'));
		}
	}
}
?>