<?php
/*
自动扫描磁盘目录影片到数据库
*/
class ScanController extends Easy_Controller_Action{

	public function init(){
	}
	public function indexAction(){
		if ($this->_Request->isPost()){
			if (strtolower($license['version']) == 'free' || $_SERVER['HTTP_HOST'] == '127.0.0.1'){
				if ($this->_Request->getPost('num')>10){
					$this->_View->message = _('免费版与测试版无法此项功能!');
					exit($this->_View->render('message'));
				}
			}
			$scan = new ScanModel();
			$scan->category = $this->_Request->getPost('category');
			$scan->mode = $this->_Request->getPost('mode');
			$scan->server = $this->_Request->getPost('server');
			$scan->player = $this->_Request->getPost('player');
			$scan->lookgid = $this->_Request->getPost('lookgid');
			$scan->virtual = $this->_Request->getPost('virtual');
			$scan->mode = $this->_Request->getPost('mode');
			$scan->area = $this->_Request->getPost('area');
			$scan->search($this->_Request->getPost('dir'));
			$this->_View->message = _('扫'.$scan->num.'影片');
			$this->_Request->setCookie('dir', base64_encode($this->_Request->getPost('dir')));
			exit($this->_View->render('message'));
		}
		$this->_View->dir = base64_decode($this->_Request->getCookie('dir'));
		$category = new CategoryModel();
		$usergroup = new GroupModel();
		$server = new ServerModel();
		$movie = new MovieModel();
		$this->_View->player = $movie->PlayerOption(0);
		$this->_View->area = $movie->AreaOption(1);
		$this->_View->category = $category->CreateOptions(0,0);
		$this->_View->usergroup = $usergroup->CreateOption(0);
		$this->_View->server = $server->CreateOption(0);
		exit($this->_View->render('plugins/scan_index'));
	}
	public function viewAction(){
		$this->_View->disk = array();
		$dir = $this->_Request->getParam('dir');
		if ($dir){
			$dir = base64_decode($dir);
			$IO = new Easy_Filesystem();
			$this->_View->disk = $IO->scandir($dir);
		}else{
			if ( strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ){
				$div = range('b', 'z');
				foreach($div as $drive){
					if (@is_dir($drive.':/')===true){
						$this->_View->disk[] = strtoupper($drive).':/';
					}
				}
			}else{
				$div = array_slice(scandir('/'),2);
				foreach($div as $drive){
					if (is_dir('/'.$drive)===true){
						$this->_View->disk[] = '/'.$drive;
					}
				}
			}
		}
		$this->_View->dir = $dir;
		exit($this->_View->render('plugins/scan_view'));
	}
}