<%
include("language.html")
%>
<noscript><center><H2><%=LANG["error_nojavascript"]%></H2></center></noscript>
<html>
<head>
<title>Wing FTP Server - Uploader</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=320, initial-scale=1.0, maximum-scale=1.0, 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;

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;">

<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;
	background-color: #fafafa;
    font-size: 16px;
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.uploaderDiv {
    position: relative;
    padding: 10px;
    background-color: #fafafa;
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, .05);
}

#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>

<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;" title="<%=LANG["str_closewindow"]%>"> <%=LANG["create_cancel"]%> </button>
            <p id="dragdropLabel"><%=LANG["str_dragdrop_files"]%></p>
		</div>
	</div>
</div>

</body>
</html>
<script>
function CheckUploadError(filename, filesize)
{
	var xmlhttpObj = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();
	xmlhttpObj.open("GET","upload_err.html?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%");
	}

//	if(isEdge || isIE || isIE11)
//	{
//		try
//		{
//			uploader = WebUploader.create({
//				auto: true,
//				compress: false,
//				threads: 2,
//				runtimeOrder: 'flash',
//				swf: '/webuploader/Uploader.swf',
//				server: '/uploaded.html',
//				dnd: '#uploader .queueList',
//				paste: document.body,
//				disableGlobalDnd: true,
//				duplicate: true,
//				pick: '#picker'
//			});
//
//		}
//		catch(e){
//
//			$('#picker').html('&nbsp;&nbsp;<%=LANG["str_browse"]%>&nbsp;&nbsp;');
//
//			uploader = WebUploader.create({
//				auto: true,
//				compress: false,
//				threads: 2,
//				swf: '/webuploader/Uploader.swf',
//				server: '/uploaded.html',
//				dnd: '#uploader .queueList',
//				paste: document.body,
//				disableGlobalDnd: true,
//				duplicate: true,
//				pick: '#picker'
//			});
//
//			$('#swfTester').css('display', '');
//		}
//	}
//	else
//	{
		uploader = WebUploader.create({
			auto: true,
			compress: false,
			threads: 1,
			swf: '/webuploader/Uploader.swf',
			server: '/uploaded.html',
			dnd: '#uploader .queueList',
			paste: document.body,
			disableGlobalDnd: true,
			duplicate: true,
			pick: '#picker'
		});
//	}

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

	$('#picker div:eq(1)').attr('style','position: absolute; top: 0px; left: 0px; width: 82px; height: 39px; overflow: hidden; bottom: auto; right: auto;');

    // 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 ) {
        $( '#'+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")
		{
			$( '#'+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 == "-5")
			{
				strError = "<%=LANG['session_expire']%>";
			}
			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').text(strError);
			$( '#'+file.id ).fadeTo(2000, 1);
			$( '#'+file.id ).fadeOut(1000);
		}
    });

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

    uploader.on( 'uploadFinished', function() {
		try
		{
			//$('#cancelButton').attr('disabled', true);
			$('#cancelButton').attr('title', '<%=LANG["str_closewindow"]%>');
			top.ajaxRequest("dir", "");
		}
		catch(e){}
    });

	uploader.on( 'fileQueued', function( file ) {
		try 
		{
			var result = top.checkOverwrite(file.name, uploader.getFiles("inited", "queued").length);
			if(result == "0")
			{
				$( '#'+file.id ).remove();
				uploader.removeFile(file, true);
			}
		}
		catch(e){}
    });

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

	$('#cancelButton').on( 'click', function() {
		if(uploader.isInProgress() == true)
		{
			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;
			}
		}
		else
		{
			try
			{
				top.closeUploader();
			}
			catch(e){}
		}
    });

});

</script>