<?php 
class File_Manager_Controller extends Base_Controller {
	function index($targPath=false,$showtype="default"){
		if($targPath){
			$targPath				=	base64_decode($targPath);
		}
		else{
			$targPath				=	"upload/tmp";
		}
		$this->file				=	new file();
		$paths					=	$this->file->scan_dir($targPath);
		switch ($showtype){
			case "thumb":	$tpl=	"manager/thumb";
			break;
			case "list":	$tpl=	"manager/list";
			break;
			default:		$tpl=	"manager/manager";
		}
		$this->view				=	new View($tpl);
		$this->view->targPath	=	$targPath;
		$this->view->paths		=	$paths;
		$this->view->render(true);
	}
	function filelist($targPath=false,$showtype="list"){
		if($targPath){
			$targPath				=	base64_decode($targPath);
		}
		else{
			$targPath				=	"upload/tmp";
		}
		$this->file				=	new file();
		$paths					=	$this->file->scan_dir($targPath);
		switch ($showtype){
			case "thumb":	$tpl=	"manager/thumb";
			break;
			case "list":	$tpl=	"manager/list";
			break;
			default:		$tpl=	"manager/manager";
		}
		$this->view				=	new View($tpl);
		$this->view->targPath	=	$targPath;
		$this->view->paths		=	$paths;
		$this->view->render(true);
	}
	function edit(){
		
	}
	function delete($path=FALSE,$targPath='.'){
		if($this->input->post()){
			$paths	=	$this->input->post('select');
			$targPath=	base64_encode($this->input->post('current-path'));
		}
		else{
			$paths[]=	base64_decode($path);
		}
		foreach ($paths as $path){
			if(is_file($path)){
				unlink($path);
				@unlink(dirname($path)."/thumb_".basename($path));
				
			}
			elseif(is_dir($path)){
				file::deldir($path);
			}
		}
		$this->index($targPath);
	}
	function templates($inputid){
		$targPath				=	"modules/html/views";
		$this->file				=	new file();
		$paths					=	$this->file->scan_dir($targPath);
		$this->view				=	new View("manager/templates");
		$this->view->targPath	=	$targPath;
		$this->view->paths		=	$paths;
		$this->view->render(true);
	}
	function useattach($targPath=false){
		if($targPath){
			$targPath				=	base64_decode($targPath);
		}
		else{
			$targPath				=	"upload/tmp";
		}
		$this->file				=	new file();
		$paths					=	$this->file->scan_dir($targPath);
		$this->view				=	new View("manager/useattach");
		$this->view->targPath	=	$targPath;
		$this->view->paths		=	$paths;
		$this->view->render(true);
	}
	function selectattach($inputid,$targPath=false){
		if($targPath){
			$targPath				=	base64_decode($targPath);
		}
		else{
			$targPath				=	"upload/tmp";
		}
		$this->file				=	new file();
		$paths					=	$this->file->scan_dir($targPath);
		$this->view				=	new View("manager/selectattach");
		$this->view->targPath	=	$targPath;
		$this->view->inputid	=	$inputid;
		$this->view->paths		=	$paths;
		$this->view->render(true);
	}
}