<%
local all_lang = {"english","french","german","italian","dutch","portuguese","spanish","schinese","tchinese","japanese","czech","romanian","turkish","korean","polish"}
if _GET["lang"] ~= nil then
	for _,val in pairs(all_lang) do
		if _GET["lang"] == val then
			setcookie("client_lang",val,2101702507)
			break
		end
	end

	if _COOKIE["client_lang"] == nil then
		_COOKIE["client_lang"] = "english"
	end
end

include("language.html")

local linkid = _GET["linkid"] or ""
local username, subdir, expiretime, uploadpass, email, sender_email = c_GetUplinkData(linkid)

local owner = username
if sender_email ~= nil and sender_email ~= "" then
	owner = sender_email
end

local bExpired = false
local nExpireTime = tonumber(expiretime) or 0
if nExpireTime > 0 and c_GetTimeUTC() > nExpireTime then
	bExpired = true
end

if username ~= nil and username ~= "" and subdir ~= nil and subdir ~= "" and bExpired == false then
%>
<noscript><center><H2><%=LANG["error_nojavascript"]%></H2></center></noscript>
<html>
<head>
<title>Wing FTP Server - File Request</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
<link rel="apple-touch-icon" href="#">
<link rel="Shortcut Icon" href="images/logo.ico" type="image/x-icon">
<script language="javascript" src="include/common.js"></script>
<script language="javascript">

var isEdge = navigator.userAgent.toLowerCase().indexOf("edge") > -1 && !isIE;
var isIE11 = navigator.userAgent.toLowerCase().indexOf("trident") > -1;

if(navigator.cookieEnabled)
{
	if(getCookie("client_lang") == "")
	{
		var language = null;
		if (navigator.appName == 'Netscape')
			language = navigator.language;
		else
			language = navigator.browserLanguage;

		if (language.indexOf('en') > -1) location = '?linkid=<%=linkid%>&lang=english';
		else if (language.indexOf('fr') > -1) location = '?linkid=<%=linkid%>&lang=french';
		else if (language.indexOf('de') > -1) location = '?linkid=<%=linkid%>&lang=german';
		else if (language.indexOf('it') > -1) location = '?linkid=<%=linkid%>&lang=italian';
		else if (language.indexOf('nl') > -1) location = '?linkid=<%=linkid%>&lang=dutch';
		else if (language.indexOf('pt') > -1) location = '?linkid=<%=linkid%>&lang=portuguese';
		else if (language.indexOf('es') > -1) location = '?linkid=<%=linkid%>&lang=spanish';
		else if (language.indexOf('zh-TW') > -1) location = '?linkid=<%=linkid%>&lang=tchinese';
		else if (language.indexOf('zh-HK') > -1) location = '?linkid=<%=linkid%>&lang=tchinese';
		else if (language.indexOf('zh-MO') > -1) location = '?linkid=<%=linkid%>&lang=tchinese';
		else if (language.indexOf('zh') > -1) location = '?linkid=<%=linkid%>&lang=schinese';
		else if (language.indexOf('ja') > -1) location = '?linkid=<%=linkid%>&lang=japanese';
		else if (language.indexOf('cz') > -1) location = '?linkid=<%=linkid%>&lang=czech'; 
		else if (language.indexOf('ro') > -1) location = '?linkid=<%=linkid%>&lang=romanian';
		else if (language.indexOf('tr') > -1) location = '?linkid=<%=linkid%>&lang=turkish';
		else if (language.indexOf('ko') > -1) location = '?linkid=<%=linkid%>&lang=korean';
		else if (language.indexOf('pl') > -1) location = '?linkid=<%=linkid%>&lang=polish';
		else location = '?linkid=<%=linkid%>&lang=english';
	}
}

function orientationChange()
{
	switch(window.orientation) 
	{
		case 0:
		case 180:
			isPortrait = true;
		break;
		case -90:
		case 90:
			isPortrait = false;
		break;
	}
}
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", orientationChange, false);
orientationChange();

</script>
</head>
<body style="margin:0px;padding:0px;">

<% if uploadpass ~= "" and uploadpass ~= _GET["password"] then %>

<link rel="stylesheet" type="text/css" href="css/style.css">
<style type="text/css">
<!--
body{
background:#60605E;
font-family: Tahoma, sans-serif;
text-align: center;
font-size:11px;
font-weight:bold;
color:#000000;
overflow: auto;
}
a:link,a:visited,a:active,a:hover{color: #FFF;text-decoration:none;}
.font{
font-size:12px;
font-weight:bold;
color:#000000;
}
-->
</style>

<script language="javascript">

function addUrlParam(param, value) 
{  
	var query = location.search.substring(1);  
	var p = new RegExp("(^|)" + param + "=([^&]*)(|$)");  
	if (p.test(query)) 
	{  
		var firstParam = query.split(param)[0];  
		var secondParam = query.split(param)[1];  
		if (secondParam.indexOf("&") > -1) 
		{  
			var lastPraam = secondParam.substring(secondParam.indexOf('&')+1);  
			return '?' + firstParam + param + '=' + value + '&' + lastPraam;  
		} 
		else 
		{  
			if (firstParam) 
			{  
				return '?' + firstParam + param + '=' + value;  
			} 
			else 
			{  
				return '?' + param + '=' + value;  
			}  
		}  
	} 
	else 
	{  
		if (query == '') 
		{  
			return '?' + param + '=' + value;  
		} 
		else 
		{  
			return '?' + query + '&' + param + '=' + value;  
		}  
	}  
}

function ch()
{
	if($("password").value != "")
	{
		window.location = addUrlParam("password", urlEncode($("password").value) );

		$("submit_btn").disabled = true;
		$("uploadpass_error").style.display = "none";

		return true;
	}
	else
	{
		return false;
	}
}

function handleKeyDown(e)
{
	if(!e){//if IE
		e=event;
	}
	if(e.keyCode == 13)
	{
		$("submit_btn").click();
		return false;
	}
	return true;
}

var isOpera = navigator.userAgent.indexOf('Opera')==-1? 0:1;
if(isOpera)
	document.onkeypress= handleKeyDown;
else
	document.onkeydown= handleKeyDown;

</script>

<form name="frm_upload" method="get" onsubmit="return ch();">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td align="center" valign="top" style="padding-top:60px;"> 
	<table width="520" height="410" border="0" align="center" cellpadding="0" cellspacing="0">
		<tr>
			<td style="background:#FFF;" height="88">
				<a href="https://www.wftpserver.com/" target="_blank"><img src="images/logo_s.png" title="Wing FTP Server" border="0"></a>
				<hr />
			</td>
        </tr>
        <tr> 
          <td style="background:#FFF;" valign="top">
				<table width="100%" border="0" cellpadding="0" cellspacing="3" style="padding-top:60px; padding-left:10px;">
                    <tr> 
                      <td height="30"><%=LANG["str_uploadpass_tip"]%>:</td>
                    </tr>
                    <tr>
                      <td>
					  <input name="password" id="password" type="password" maxlength="64" tabindex="1" style="width:180px;height:30px;" />
					  <input type="button" name="submit_btn" id="submit_btn" value="<%=LANG["calendar_static_submit"]%>" style="width:120px;height:30px;" tabindex="2" onclick="return ch();" />
					 </td>
                    </tr>
					<% if _GET["password"] ~= nil and _GET["password"] ~= "" then %>
                    <tr> 
                      <td height="60"><span style="font-size:16px; color:#FF0000;" id="uploadpass_error"><%=LANG["str_uploadpass_error"]%></span></td>
                    </tr>
					<% end %>
				</table>
			</td>
        </tr>
        <tr> 
        <td height="35" style="font-size:12px;color:white;">
		  <a href="https://www.wftpserver.com/" target="_blank">Wing FTP Server</a> ©2003-2026 <b>wftpserver.com</b> All Rights Reserved
		</td>
        </tr>
      </table>
	  </td>
  </tr>
</table>
</form>

</body>
</html>

<% else %>

<link rel="stylesheet" type="text/css" href="webuploader/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="webuploader/webuploader.css">
<style type="text/css">
<!--
body {
    margin-top: 50px;
    font-size: 16px;
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.uploaderDiv {
    position: relative;
    padding: 10px 10px 10px 20px;
}

#picker {
    display: inline-block;
    vertical-align: middle;
    padding: 5px;
	max-width: 220px;
	_width: 220px;
}
-->
</style>
<script language="javascript" src="include/common.js"></script>
<script language="javascript" src="webuploader/jquery.js"></script>
<script language="javascript" src="webuploader/bootstrap.min.js"></script>
<script language="javascript" src="webuploader/webuploader.min.js"></script>


<div id="swfTester" style="display:none;">
<embed id="swfObj" src='webuploader/Uploader.swf' width='100%' play='true' loop='false' quality='high' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer'></embed>
</div>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td align="center" valign="top" style="padding-top:20px;"> 
	<table width="720" height="580" border="0" align="center" cellpadding="0" cellspacing="0" id="mainTable">
		<tr>
			<td height="88">
				<a href="https://www.wftpserver.com/" target="_blank"><img src="images/logo_s.png" title="Wing FTP Server" border="0"></a>
				<hr />
			</td>
        </tr>
        <tr> 
			<td style="padding: 10px;">
				<b><%=owner%></b> <%=LANG["request_file_tip"]%>
			</td>
        </tr>
        <tr> 
			<td valign="top">
				<div id="uploader" class="uploaderDiv">
					<div class="queueList">
						<div id="filelist" class="uploader-list"></div>

						<div id="dndArea" class="placeholder">
							<div id="picker">&nbsp;&nbsp;<%=LANG["str_browse"]%>&nbsp;&nbsp;</div>
							<button id="cancelButton" class="btn btn-default" style="height: 30px;" disabled> <%=LANG["create_cancel"]%> </button>
							<p id="dragdropLabel"><%=LANG["str_dragdrop_files"]%></p>
							<p id="infoDiv"></p>
						</div>
					</div>
				</div>
			</td>
        </tr>
      </table>
	  </td>
  </tr>
</table>


</body>
</html>
<script>

if(getBrowerWidth() < 720)
{
	document.getElementById("mainTable").style.width = "100%";
}

if(isIphone || isAndroid || isWindowsPhone)
{
	document.getElementById("mainTable").style.width = "100%";
}

function CheckUploadError(filename, filesize)
{
	var xmlhttpObj = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();
	xmlhttpObj.open("GET","uploadlink_err.html?linkid=<%=linkid%>&filename="+urlEncode(filename)+"&filesize="+urlEncode(filesize)+"&r="+Math.random(), false);
	xmlhttpObj.send("");

	return trim(xmlhttpObj.responseText);
}

if ( !WebUploader.Uploader.support() ) 
{
	alert('<%=LANG["str_webuploader_tips"]%>');
}

// upload file
jQuery(function() {
    var $ = jQuery,
        $list = $('#filelist'),
        state = 'pending',
        uploader;

	if($('#swfTester').height() >= 50)
	{
		$('#swfObj').height("100%");
	}

	uploader = WebUploader.create({
		auto: true,
		compress: false,
		threads: 1,
		swf: '/webuploader/Uploader.swf',
		server: '/uploaded.html?UID=<%=linkid%>&password=<%=urlencode(uploadpass)%>',
		dnd: $("*"),
		paste: document.body,
		disableGlobalDnd: true,
		duplicate: true,
		pick: '#picker'
	});

	var uploadedFiles = 0;

	if(uploader.predictRuntimeType() == "flash")
	{
		$('#dragdropLabel').html('');
	}

    // file Queued
    uploader.on( 'fileQueued', function( file ) {
        $list.append( '<div id="' + file.id + '" style="width:95%;padding-left:10px;">' +
            '<h4 class="info"><img src="images/cancel.gif" class="remove-this" title="<%=LANG["create_cancel"]%>" style="cursor:default;margin:3px;"> ' + file.name + ' (' + fileSize(file.size) + ')</h4>' +
        '</div>' );

		var $li = $( '#'+file.id );
		$li.on('click', '.remove-this', function() {
			uploader.cancelFile( file );
			$li.remove();
		})
    });

    uploader.on( 'uploadStart', function( file ) {
		//WIN10 edge browser can't trigger uploadProgress
		if(isEdge && uploader.predictRuntimeType() != "flash")
		{
			var $li = $( '#'+file.id );
			var $percent = $li.find('.progress .progress-bar');

			if ( !$percent.length ) {
				$li.append('<div class="progress progress-striped active"><div class="progress-bar" role="progressbar" style="width:100%; text-align:left; padding-left:10px; color:#333; word-break:keep-all;"><%=LANG["upload_ready"]%>...</div></div>');
			}
		}
    });

    // upload Progress
    uploader.on( 'uploadProgress', function( file, percentage ) {
        var $li = $( '#'+file.id );
		var $percent = $li.find('.progress .progress-bar');

        if ( !$percent.length ) {
			$li.append('<div class="progress progress-striped active"><div class="progress-bar" role="progressbar" style="text-align:left; padding-left:10px; color:#333; word-break:keep-all;"></div></div>');
			$percent = $li.find('.progress .progress-bar');
        }

		var strText = "<%=LANG['uploadstat_nowsize']%>"+round(percentage * 100, 0)+"%"
        $percent.text(strText);
        $percent.css( 'width', round(percentage * 100, 0) + '%' );
    });

    uploader.on( 'uploadSuccess', function( file ) {
		uploadedFiles++;
        $( '#'+file.id ).find('.progress .progress-bar').text('<%=LANG["upload_ok"]%>');
		$( '#'+file.id ).fadeOut(1000);
    });

    uploader.on( 'uploadError', function( file, reason ) {
		var result = CheckUploadError(file.name, file.size);
		if(result == "1")
		{
			if(reason.substr(0,7) == "server-")
			{
				$( '#'+file.id ).find('.progress .progress-bar').addClass("progress-bar-danger");
				$( '#'+file.id ).find('.progress .progress-bar').css("color","#FFF");
				$( '#'+file.id ).find('.progress .progress-bar').text("You have exceeded max sessions permitted.");
				$( '#'+file.id ).fadeTo(5000, 1);
				$( '#'+file.id ).fadeOut(2000);
			}
			else
			{
				$( '#'+file.id ).fadeOut(1000);
			}
		}
		else
		{
			var strError = "<%=LANG['upload_failed']%>";
			if(result == "-1")
			{
				strError = "<%=LANG['error_upload']%>";
			}
			else if(result == "-2")
			{
				strError = "<%=LANG['upload_failed']..' '..RESULT_STR[-3]%>";
			}
			else if(result == "-3")
			{
				strError = "<%=LANG['error_upload3']%>";
			}
			else if(result == "-4")
			{
				strError = "<%=LANG['error_upload4']%>";
			}
			else if(result == "0")
			{
				strError = "<%=LANG['upload_failed']..' '..RESULT_STR[-1]%>";
			}
			$( '#'+file.id ).find('.progress .progress-bar').addClass("progress-bar-danger");
			$( '#'+file.id ).find('.progress .progress-bar').css("color","#FFF");
			$( '#'+file.id ).find('.progress .progress-bar').text(strError);
			$( '#'+file.id ).fadeTo(5000, 1);
			$( '#'+file.id ).fadeOut(2000);
		}
    });

    uploader.on( 'startUpload', function() {
		$('#cancelButton').attr('disabled', false);
		$('#cancelButton').attr('title', '<%=LANG["str_cancelupload"]%>');
		$('#infoDiv').html('');
		uploadedFiles = 0;
    });

    uploader.on( 'uploadFinished', function() {
		$('#cancelButton').attr('disabled', true);
		$('#cancelButton').attr('title', '');

		if(uploadedFiles > 0)
			$('#infoDiv').html("<span style='color:#1F7FF8'><%=LANG["str_complete"]%> <%=LANG["str_totalfile"]%>: "+uploadedFiles+"</span>");
    });

    uploader.on( 'uploadComplete', function( file ) {
		//$( '#'+file.id ).fadeOut();
    });

	$('#cancelButton').on( 'click', function() {
		if(confirm("<%=LANG['uploadclose_confirm']%>"))
		{
			var allFiles = uploader.getFiles();
			for(var i=0; i<allFiles.length; i++)
			{
				$( '#'+allFiles[i].id ).remove();
				uploader.removeFile(allFiles[i], true);
			}
			return true;
		}
		else
		{
			return false;
		}
    });

});

</script>

<% end %>

<% 
else
	if bExpired == false then
		print("<h3>The file request link does not exist</h3>")
	else
		print("<h3>The file request link has expired</h3>")
	end
end 
%>