<?php
SOY2::import("util.CMSFileManager");
class FilePage extends CMSWebPageBase{
	
	function FilePage(){
		
		WebPage::WebPage();
		
		include_once(dirname(__FILE__) ."/FileActionPage.class.php");
		
		$this->createAdd("uploaddialogform","HTMLForm",array(
			"action" => $this->createLink(FileActionPage::ACTION_UPLOAD),
			"name" => "upload_dialog_form",
			"onsubmit" => "document.upload_dialog_form.soy2_token.value = CMS_FileManager.soy2_token;"
		));
		
		$root = str_replace("\\",'/',realpath(UserInfoUtil::getSiteDirectory()));
		
		ob_start();
		$file = CMSFileManager::printTree($root);
		$buff = ob_get_contents();
		ob_end_clean();
		
		//ツリーの出力
		$this->createAdd("filetree","HTMLLabel",array(
			"html" => $buff
		));	
		
		//スクリプトの出力
		$script = file_get_contents(dirname(__FILE__)."/cms_script.js");
		$script = str_replace("__AJAX__ROOT_PATH__",$this->createLink(FileActionPage::ACTION_LIST),$script);
		$script = str_replace("__AJAX__TREE_PATH__",$this->createLink(FileActionPage::ACTION_TREE),$script);
		$script = str_replace("__AJAX__DETAIL_PATH__",$this->createLink(FileActionPage::ACTION_DETAIL),$script);
		$script = str_replace("__AJAX__MKDIR_PATH__",$this->createLink(FileActionPage::ACTION_MKDIR),$script);
		$script = str_replace("__AJAX__DELETE_PATH__",$this->createLink(FileActionPage::ACTION_DELETE),$script);
		$script = str_replace("__AJAX__RENAME_PATH__",$this->createLink(FileActionPage::ACTION_RENAME),$script);
		$script = str_replace("__AJAX__SEARCH_PATH__",$this->createLink(FileActionPage::ACTION_SEARCH),$script);
		$script = str_replace("__AJAX__RELOAD_PATH__",$this->createLink(FileActionPage::ACTION_RELOAD),$script);
		
		$script = str_replace("__AJAX__SITE_ID__",UserInfoUtil::getSite()->getSiteId(),$script);
		
		$script = str_ireplace("_AJAX_FILEMANAGER_IMAGE_ROOT_",'"'.SOY2PageController::createRelativeLink("./js/FileManager/images/").'"',$script);

		$script = str_replace("__AJAX_SOY2_TOKEN__",soy2_get_token(),$script);
		
		$script .= "showList(\"file:".$file->getId()."\");";
				
		$this->createAdd("cmsscript","HTMLScript",array(
			"script" => $script			
		));
		
		CMSFileManager::debug();
				
		
		
	}
	
	function createLink($id){
		return SOY2PageController::createLink("FileManager.FileAction.".$id);
	}    
}

?>