<?
////////////////////////////////////////////////////
// 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 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/utils.js"></script>
	<script type="text/javascript" src="../jslib/swfobject.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(){
		var el=document.getElementById("Filedata");
		var errors="";
		if(el.value==""){
			errors="<? echo FILECTRL_REQUIRED ?>";
		}else{
		}
		if(fileSize>max_fileSize) errors="<? echo FILECTRL_TOOBIG ?>";
		var archivo=el.value;
		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==""){
			document.getElementById("uploading_layer").style.display="";		
			setTimeout('document.images["pbar"].src = "../resources/themes/default/uploading.gif"', 200); 
			document.getElementById("Submit").onclick=function(){return false};	
			document.forms[0].submit();
		}else{
			alert(errors);
		}
	}
	</script>
</head>

<body>
<form action="uploader2.php?control=<? echo $_GET['control'] ?>&resId=<? echo $_REQUEST['resId'] ?>&subType=<? echo $_GET['subType'] ?>&maxSize=<? echo $_GET['maxSize'] ?>" method="post" name="dataform" id="dataform" onsubmit="return presubmit();" enctype="multipart/form-data">
<table width="100%" height="100" cellspacing="0" cellpadding="0" border="0" id="outer_table">
<thead>
<tr>
	<td class="pageBar" height="1" colspan="2" ><h1><? echo FILECTRL_POPUP_TITLE ?></h1></td>
</tr>
</thead>
<tbody>
<tr class="row1">
	<td width="100" align="right" style="font-size:11px;">
		<div id="uploading_layer" style="position:absolute; text-align:center; width:350px; background-color:#EEEEEE; left:0; top:22px; height:55px; display:none">
			<img src="../resources/themes/default/uploading.gif" style="margin:8px auto 0 auto;" align="absmiddle" id="pbar"/>&nbsp;&nbsp;<? echo FILECTRL_UPLOADING ?>
		</div>
		<? echo FILECTRL_FILE ?>
	</td>
	<td valign="bottom" align="left">
		<input type="file" name="Filedata" id="Filedata" style="file_default" />
	</td>
</tr>
<tr class="row2">
	<td align="left" valign="top" colspan="2" style="font-size:11px;" height="30">
	&nbsp;<? echo FILECTRL_VALID_EXT ?>
	<script type="text/javascript">document.write(<? if($_GET['subType']=="all"){echo "'".FILECTRL_ALL."'";}else{ ?>"." + types[currentType].join(", .")<? } ?>)</script><br />
	&nbsp;<? echo $mensajeTamano ?>: 
	</td>
</tr>

</tbody>
<tfoot>
<tr>
	<td colspan="2">
		<input type="button" id="Submit" name="Submit" value="<? echo BUTTON_SEND ?>" class="but_medium" onclick="javascript:presubmit();" />
		<input type="button" id="Cancel" name="Cancel" value="<? echo BUTTON_CANCEL ?>" class="but_medium" onclick="javascript:parent.$.fancybox.close();;" />
	</td>
</tr>
</tfoot>


</table>
</form>
</body>
</html>
