<?php

class FileUploadPage extends CMSWebPageBase {

	function doPost(){
		
		$res = $this->run("Entry.UploadFileAction");
		
		echo json_encode($res->getAttribute("result"));
		exit;
	}
    function FileUploadPage($arg) {
    	WebPage::WebPage();
		
		$this->createAdd("prototypejs","HTMLModel",array(
			"type" => "text/JavaScript",
			"src" => SOY2PageController::createRelativeLink("./js/prototype.js")
		));
		$this->createAdd("commonjs","HTMLModel",array(
			"type" => "text/JavaScript",
			"src" => SOY2PageController::createRelativeLink("./js/common.js")
		));
		
		$this->createAdd("applyForm","HTMLForm",array(
			"action"=>SOY2PageController::createLink("Entry.Editor.UploadApply")
		));
		
		$this->createAdd("cancelForm","HTMLForm",array(
			"action"=>SOY2PageController::createLink("Entry.Editor.UploadCancel")
		));
		
		$this->createAdd("uploadForm","HTMLForm");
		
		$this->createAdd("parameters","HTMLScript",array(
			"lang" => "text/JavaScript",
			"script" => 'var remotoURI = "'.UserInfoUtil::getSiteURL().substr($this->getDefaultUpload(),1).'";'.
						((defined('SOYCMS_ASP_MODE')) ? 'var siteURL = "'.UserInfoUtil::getSiteURL().'";' : 'var siteURL = "'.UserInfoUtil::getSiteURLBySiteId("").'";')
		));
		
		$this->createAdd("file_manager_iframe","HTMLModel",array(
			"target_src"=>SOY2PageController::createLink("FileManager.File")
		));

		$sample = "http://www.example.com/path/to/image.jpg または /path/to/picture.jpg";
		$this->createAdd("outer_link","HTMLInput",array(
    		"value" => $sample,
    		"style" => "width:440px;color: grey;",
    		"onfocus" => "if(this.value == '$sample'){ this.value = ''; this.style.color = '';}else{ this.select(); };\$('outer_link_button').disabled='';",
    		"onblur"  => "if(this.value.length == 0){ this.value='$sample'; this.style.color = 'grey';};if(this.value == '$sample'){\$('outer_link_button').disabled='disabled';}else{\$('outer_link_button').disabled='';}"
		));
    }
    
    function getDefaultUpload(){
    	
    	$dao = SOY2DAOFactory::create("cms.SiteConfigDAO");
    	$config = $dao->get();
    	$dir = $config->getUploadDirectory();
    	
    	return $dir;
    }
}
?>