<?
////////////////////////////////////////////////////
// Conciliación: gestión de conciliación de activos
// Version: 1.0
//
// Copyright (C) 2014  Eustotem Multimedia, S.L.
//
// License: MIT, see LICENSE
////////////////////////////////////////////////////


include("../conf/preferences.php");
session_name(SYS_APP_SESSNAME);
session_start();
include("../conf/langs/".$langs[$_SESSION['userlang']][0]."/MAIN.php");
include("../conf/connections.php");
require_once("../phplib/utils.php");
require_once("../core/plugins.php");


$resId=$_REQUEST['resId'];
$master=simplexml_load_file("../conf/resources/".$langs[$_SESSION['userlang']][0]."/".$_SESSION['conf'][$resId]->masterview);
$detail=simplexml_load_file("../conf/forms/".$langs[$_SESSION['userlang']][0]."/".$_SESSION['conf'][$resId]->detailview);




$form_caption=$action=='insert' ? $detail->formcaption_insert : $detail->formcaption_update;
$page_caption=$detail->pagetitle;
if($_GET['maxSize']=='0' || $_GET['maxSize']==NULL || $_GET['maxSize']==''){
	$mensajeTamano='';
}else{
	$mensajeTamano=FILECTRL_MAX_SIZE . ": " . $_GET['maxSize'] . " kb";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><? echo $_SESSION['application']['title'] ?></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link type="text/css" href="../jslib/jq/ui/css/<? echo UI_THEME ?>/jquery-ui.custom.css" rel="stylesheet" />
	<link href="../resources/themes/default/form_screen.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src = "../jslib/jq/jquery-1.7.2.min.js" ></script>
	<script type="text/javascript" src = "../jslib/jq/ui/js/jquery-ui-1.8.21.custom.min.js" ></script>
	<script type="text/javascript" src="../jslib/utils.js"></script>
	<link rel="stylesheet" type="text/css" media="screen" href="../jslib/elfinder/css/elfinder.min.css">
	<script type="text/javascript" src="../jslib/elfinder/js/elfinder.min.js"></script>
	<script type="text/javascript" src="../jslib/elfinder/js/i18n/elfinder.es.js"></script>
	
	<script type="text/javascript">
	var fileSize=0;				
	var max_fileSize=100000;	
	var types={
		image:["jpg","jpeg","gif","png"],
		docs:["txt","doc","pdf","xls","odt","docx","rtf","htm","html"],
		media:["swf","jpg","gif","png","avi","flv","wmv","wav","mp3"],
		video:["avi","flv","wmv","swf","mov"],
		audio:["wav","mp3","swf","ogg"],
		archive:["zip","rar","lzh","gz"]
	};
	var currentType="<? echo $_GET['subType'] ?>";
	if(currentType.indexOf(",",0)!=-1){
		var t0=currentType.split(",");
		types['other']=t0;
		currentType="other";
	}
	
	function presubmit(archivo){
		var errors="";
		if(archivo==""){
			errors="<? echo FILECTRL_REQUIRED ?>";
		}else{
		}
		if(fileSize>max_fileSize) errors="<? echo FILECTRL_TOOBIG ?>";
		var temp=archivo.split(".");
		var ext=temp[temp.length-1];
		if(currentType.toLowerCase()!="all"){
			var yuyu=types[currentType.toLowerCase()];
			if(yuyu==undefined){
				errors="<? echo FILECTRL_TYPE_NOT_CHOSEN ?>";
			}else{
				var qq=yuyu.join("");
				if(yuyu.join("").indexOf(ext.toLowerCase())==-1) errors="<? echo FILECTRL_INCORRECT ?>";
			}
		}
		
		if(errors==""){
			var destino="uploader3.php?control=<? echo $_GET['control'] ?>&resId=<? echo $_REQUEST['resId'] ?>&subType=<? echo $_GET['subType'] ?>&maxSize=<? echo $_GET['maxSize'] ?>";
			$.post(destino, {url: archivo},function(data){
				if(data.result=="ok"){
					parent.updateFileControl('<? echo $_GET['control'] ?>',data.filename,'11');
					parent.$.fancybox.close();
				}else{
					alert(data.msg);
				}
			},"json");
		}else{
			alert(errors);
		}
	}
	</script>
	<script type="text/javascript">
	$().ready(function() {
		var elf = $('#elfinder').elfinder({
			url : '../jslib/elfinder/php/connector.php?rootfolder=<? echo $_GET['rootfolder'] ?>',
			getfile : {
				onlyURL : true,
				multiple : false,
				folders : false
			},
			getFileCallback: function(url) { 
				presubmit(url);
			},
			resizable: false,
			width: 'auto',
			height: 600
		}).elfinder('instance');			
	});	</script>
</head>

<body style="overflow:hidden">
<div id="elfinder"></div>
</body>
</html>
