<?php
/*
秀影EasyFramework框架
qq:24498936
msn:jdzcn_net@hotmail.com
website:http://www.vodcms.com
*/
class MakeController extends Easy_Controller_Action {
	public function init(){
		$this->path = $this->_View->getViewRoot();
		$this->_View->setViewRoot('templates');
		$this->_View->skin = $this->config['template'];
		$this->movcfg = new Easy_Config();
		$this->movcfg->set(ROOT.'Config/movie.ini', 'area');
		$this->_View->temporary['moviearea'] = $this->movcfg->data;
		$this->_View->temporary['config'] = $this->config;
		$this->_View->Template = new Template();	//
	}
	public function indexAction(){
		if ($this->_Request->getPost('makeindex')){
			$this->_View->location = _('站点首页');
			$content = $this->_View->render($this->_View->skin.'/index');
			$IO = new Easy_Filesystem();
			$IO->wFile(ROOT.'index.htm', $content);
			unset($content);
			$this->_View->setViewRoot($this->path);
			$this->_View->message = _('首页生成成功!');
			exit($this->_View->render('message'));
		}elseif($this->_Request->getPost('delete')){
			unlink(ROOT.'index.htm');
			$this->_View->message = _('首页删除成功!');
			exit($this->_View->render('message'));
		}
		$this->_View->setViewRoot($this->path);
	}
	public function categoryAction(){
		$category = new CategoryModel();
		$movie = new MovieModel();
		$this->_View->category = $category->CreateOption(0,0);
		if ($this->_Request->getParams('do')){
			if ($this->_Request->getParams('id')){
				$where = ' WHERE locked=0 AND id='.(int)$this->_Request->getParams('id');
			}else{
				$where = ' WHERE locked=0';
			}
			$start = (int)$this->_Request->getParams('start') ;
			$page = new Page();
			$sql = 'SELECT id FROM '.VODCMS_CATEGORY.$where.' LIMIT '.$start.',1';
			foreach( $category->_DB->fetall($sql) as $rss){
				
				$POST['category'] = $rss['id'];
				$sql = 'SELECT DISTINCT(movid) as total FROM '.VODCMS_MCLASSID.' 
				WHERE category in ('.implode(',', $category->getChilds($rss['id'])).')' ;
				$total = $category->_DB->getCount($sql);
				$page->set($total, $this->config['pagesize']);
				$page->PrintBody();
				$row = $category->_DB->fetRow($sql.$page->limit());
				$i= (int)$_GET['page'];
				while ($i<$page->countpage){
					$i++;
					$src = INSTALLDIR.'content/category/id/'.$rss['id'].'/page/'.$i.'/make/yes/';
					
					echo '
					<iframe frameborder="0" scrolling="no" src="'.$src.'" width="500" height="30"></iframe>';
					if ($i % 20 == 0){
						$goto = preg_replace('/yes(.+)/is', 'yes', $_SERVER['REQUEST_URI']);
						$this->_View->jumpurl = $goto.'/start/'.$start.'/page/'.($i+1).'/';
						$this->_View->setViewRoot($this->path);
						exit($this->_View->render('make/make_message'));
						exit;
					}
				}
				$start++;
				$goto = preg_replace('/yes(.+)/is', 'yes', $_SERVER['REQUEST_URI']);
				echo '<div align="left" style="padding:10px">共'.$i.'个页面</div>';
				$this->_View->jumpurl = $goto.'/start/'.$start;
				$this->_View->setViewRoot($this->path);
				exit($this->_View->render('make/make_message'));
			}//end for
			exit;
		}
		$this->_View->setViewRoot($this->path);
	}
	public function viewAction(){
		$cate = new CategoryModel();
		$movie = new MovieModel();
		$this->_View->category = $cate->CreateOption(0,0);
		if ($this->_Request->getParam('do')){
			$pagesize = (int)$this->_Request->getParam('pagesize') ? (int)$this->_Request->getParam('pagesize') : 1;
			if ($this->_Request->getParam('do') == 'category'){
				$POST['category'] = $this->_Request->getParams('category');
				$data = $movie->getMovid($POST);
			}elseif ($this->_Request->getParam('do') == 'top'){
				$data = $movie->getMovid(array('max'=>$this->_Request->getPost('max')));
			}elseif ($this->_Request->getParam('do') == 'all'){
				$data = $movie->getMovid(array('pagesize'=>$pagesize));
			}
			$i=0;
			foreach ($data as $row){
				$i++;
				$src = INSTALLDIR.'content/view/movid/'.$row['movid'].'/make/yes/';
					echo '
					<iframe frameborder="0" scrolling="no" src="'.$src.'" width="500" height="30"></iframe>';
				if ($i % 20 == 0 ){
					$this->_View->setViewRoot($this->path);
					$this->_View->message = _('正在生成'.$pagesize.'-'.($pagesize+20).'个页面');
					$this->_View->jumpurl = preg_replace('/do\/(.+)/is', '', $_SERVER['REQUEST_URI']).'do/'.$this->_Request->getParam('do').'/pagesize/'.($pagesize+1);
					exit($this->_View->render('make/make_message'));
				}
			}
			echo _('<br>页面生成成功');
			echo '<script>window.scrollTo(0,document.body.scrollHeight);</script>';
			exit;
		}
		$this->_View->setViewRoot($this->path);
	}
	public function noteAction(){
		$this->_View->setViewRoot($this->path);
		$note = new AfficheModel();
		$data = null;
		foreach($note->getAll() as $row){
			$data.='<li><a href=\"javascript:vote(\''.INSTALLDIR.'\', '.$row['id'].')\">'.$row['title'].' / '.date('Y-m-d', $row['addtime']).'</a></li>';
		}
		$IO = new Easy_Filesystem(ROOT);
		$data = 'document.write("<div id=\"scrollDiv\"><ul>'.$data.'</ul></div>");';
		$IO->wFile(ROOT.'js/note.js', $data);
	}
}?>