<%@ Page language="c#" Codebehind="upload.aspx.cs" AutoEventWireup="True" Inherits="Webdisk.upload" %>
<%@ Register Src="~/userleft.ascx" TagPrefix="uc1" TagName="userleft" %>
<%@ Register Src="~/usertop.ascx" TagPrefix="uc1" TagName="usertop" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>上传文件</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
	<link rel="stylesheet" href="css/atlantis.css">
     <link rel="stylesheet" href="css/fileinput.min.css" type="text/css">
     <link rel="stylesheet" href="css/glyphicon.css" type="text/css">
<style type=text/css>.STYLE1 { COLOR: #0000ff }
	.ProgressBar { BORDER-RIGHT: 0px; PADDING-RIGHT: 0px; BORDER-TOP: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; BORDER-LEFT: 0px; WIDTH: 100%; PADDING-TOP: 0px; BORDER-BOTTOM: 0px; HEIGHT: 3em }
	</style>	
</head>
<body>
 <div class="wrapper">
        <uc1:usertop runat="server" ID="usertop" />
    <!-- begin::navigation -->
    <uc1:userleft runat="server" ID="userleft" />
    <!-- end::navigation -->
   <div class="main-panel">

        <div class="content">
            <div class="page-inner">

        <div >

           <div class="card">
			    <div class="card-body">
						<div class="row">&nbsp;&nbsp;&nbsp;&nbsp;<img src="pics/pick.gif" width="16" height="16" align="absMiddle">&nbsp;&nbsp;&nbsp;&nbsp;<h5><b>上传文件</b></h5>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:history.go(-1);"><img src="pics/link_back.gif" border="0" align="absMiddle"></a></div>
					<form id="form1" method="post" runat="server">
 <H4>路径: <asp:label id=txtpath runat="server"></asp:label></H4>
 <fieldset class="form-group">
      <div class="row">
      <legend class="col-form-label col-sm-2 pt-0">指定上传方式：</legend>
      <div class="col-sm-10">
         <div class="custom-control custom-radio custom-control-inline">
    <input type="radio" id="click1" name="customRadioInline2" class="custom-control-input" CHECKED value=1 onclick=show1()>
    <label class="custom-control-label" for="click1">选择文件</label>
</div>
            <div class="custom-control custom-radio custom-control-inline">
    <input type="radio" id="click4" name="customRadioInline2" class="custom-control-input" value=1 onclick=show4()>
    <label class="custom-control-label" for="click4">选择文件夹（商业版）</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
    <input type="radio" id="click2" name="customRadioInline2" class="custom-control-input" onclick=show2() value=2>
    <label class="custom-control-label" for="click2">链接网址（商业版）</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
    <input type="radio" id="click3" name="customRadioInline2" class="custom-control-input" onclick=show3() value=3>
    <label class="custom-control-label" for="click3">外部下载（商业版）</label>
</div>
      </div></div>
  </fieldset>
                        <div id="type2" style="DISPLAY: none">
 <div class="form-group row">
    <label for="recommend" class="col-sm-2 col-form-label">需添加的个数</label>
    <div class="col">
        <div class="row">
		<input class="form-control w-25" id=upcount type=text size=7 value=5 name=upcount>&nbsp;&nbsp;&nbsp;&nbsp;<input class="btn btn-outline-light" onclick=setid(); type=button value=" 设 定 " name=Button> </div>
                  
    </div>
  </div></div>
 <div class="custom-control custom-checkbox mr-3">
												&nbsp;<input type="checkbox" class="custom-control-input" id="autorename" checked name="autorename" runat="server" onchange="EditOpt();">
												<label class="custom-control-label" for="autorename"><font color="#0000ff">重名文件自动更名</font></label>
											</div><br>
<div id="type1" >
<div id="upid">
 <input type="file" name="model_file" id="model_file" multiple class="file-loading" />
</div>
    </div><br>
<INPUT id=Hidpath2 type=hidden size=1 name=Hidpath runat="server">
  <div id="type7"> <div class="alert alert-warning" role="alert" id="notype2" runat="server"><asp:label id=notype runat="server"></asp:label></div> </div> 
  <INPUT id=maxsize type=hidden name=maxsize  runat="server"> 

<div id="type3" style="DISPLAY: none">
<div id="upid1">
<div class="row align-items-center">
标题： <INPUT class="form-control w-25" id=Text3 
                  type=text name=url> &nbsp;&nbsp;网址： 
                  <INPUT class="form-control w-25" id=Text1 type=text name=url >
    </div>
    </div></div>
<div id="type4" style="DISPLAY: none">
    <INPUT class="btn btn-primary" id=Submit onclick=outlink(); type=button value=" 添 加 " name=Submit runat="server" onserverclick="Submit_ServerClick"> 
                  &nbsp;&nbsp;&nbsp;&nbsp;<INPUT class="btn btn-light" id=btn_return1 onclick=javascript:history.go(-1); type=button value=" 返 回 " name=btn_return1> 
                  <INPUT id=hidurl type=hidden name=hidurl 
                  runat="server">
</div>
<div id="type5" style="DISPLAY: none">
<div id="upid2">
 <div class="row align-items-center">
   下载地址：<INPUT class="form-control w-25" 
                  id=textBoxFileURL type=text size=52 name=textBoxFileURL 
                   runat="server">&nbsp;&nbsp;文件描述：<input id=note2 name=note2 type=text class="form-control w-25" size="30">
    
</div>
</div></div>
<div id="type6" style="DISPLAY: none">
<INPUT class="btn btn-primary" id=progressStartButton onclick=StartEverything(this); type=button value=" 下 载 " name=progressStartButton> 
                  &nbsp;&nbsp;&nbsp;&nbsp;<INPUT class="btn btn-light" id=btn_return2 onclick=javascript:history.go(-1); type=button value=" 返 回 " name=btn_return1> 
                  （填写外部要下载到空间中的文件地址，为直接下载地址，如：http://www.xxx.com/xxx.zip） 
                  <p>
                  <p><asp:literal id=progressVariables 
                   runat="server"></asp:literal></p>
                  <div id=progressNotices 
                  style="FONT-WEIGHT: bold; FONT-SIZE: 12px; FONT-FAMILY: Verdana; HEIGHT: 14px" 
                  ></div>
                  <div id=progressBarArea style="DISPLAY: none" 
                  >
                  <div 
                  style="BORDER-RIGHT: gray 1px inset; PADDING-RIGHT: 1px; BORDER-TOP: gray 1px inset; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; MARGIN: 14px; BORDER-LEFT: gray 1px inset; PADDING-TOP: 1px; BORDER-BOTTOM: gray 1px inset" 
                  >
                  <div id=progressBar 
                  style="WIDTH: 0%; COLOR: navy; HEIGHT: 22px; BACKGROUND-COLOR: navy" 
                  ></div></div><asp:literal id=progressAlert 
                   
                  runat="server"></asp:literal></div><iframe id=progressIFrame 
                  style="POSITION: absolute" name=progressIFrame 
                  src="about:blank" frameBorder=0 width=0 scrolling=no 
                  height=0></iframe>
                  <DIV></DIV>
                  <DIV 
        ></DIV>
 </div></form>
			    </div>
			    </div>

    </div> </div> </div>
    <!-- end::main content -->
</body>
</html>			
<!-- Plugin scripts -->
	<script src="js/jquery.3.2.1.min.js"></script>
	<script src="js/popper.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<!-- jQuery UI -->
	<script src="js/jquery-ui.min.js"></script>
	<script src="js/jquery.ui.touch-punch.min.js"></script>
	<script src="js/sweetalert.min.js"></script>
	<!-- jQuery Scrollbar -->
	<script src="js/jquery.scrollbar.min.js"></script>
	<!-- Atlantis JS -->
    <script src="js/webfont.min.js"></script>
	<script src="js/atlantis.js"></script>
<script src="js/fileinput.min.js"></script>
<script src="js/zh.js"></script>
<script>
    $(function () {
		var currint = 0;
		var isend = 0;
		var isendcount = 0;

        var control = $("#model_file");
        var uploadrul = "uploadserver.aspx";
        var currpath = encodeURI($('#txtpath').text());
        var upObj = {
            language: 'zh', //设置语言
            uploadUrl: uploadrul, //上传的地址
            uploadExtraData: { "path": currpath, "DiLength": <%=DiLength%>, "out": getUrlParam('out')},//上传至服务器的参数，非常重要
            //allowedFileExtensions: ['xml', 'docx', 'jpg', 'png', 'gif','doc'],//接收的文件后缀
            showUpload: true, //显示批量上传按钮
            showCaption: false,
            showClose: false,
            //showPreview: false,
            browseClass: "btn btn-primary", //按钮样式
            dropZoneEnabled: true,//是否显示拖拽区域
            maxFileSize: <%=maxsizestr%>,//单位为kb，如果为0表示不限制文件大小
            //enctype: 'multipart/form-data',
            //textEncoding: "GB2312",
            msgSizeTooLarge: " \"{name}\" 大小为({size} KB) 最大文件大小为 {maxSize} KB.请重新上传!",//文件的实际大小有些许偏差
           // enctype: 'multipart/form-data',
            validateInitialCount: true,
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
            allowedPreviewTypes: ['image', 'html', 'text']//能够预览的文件类型，如果不限制。文件预览时可能很慢
        };
        control.fileinput(upObj);

        //导入文件上传成功之后的事件
        $("#model_file").on("fileuploaded", function (event, data, previewId, index) {
			isendcount = isendcount + 1;
					if (isend==0) isend = data.filescount;
					if (isend == isendcount) {
            window.location = 'ContentPane.aspx?path=' + $('#txtpath').text();
			}
        });
        //导入文件上传失败之后的事件
        $('#model_file').on('fileuploaderror', function (event, data, msg) {
            //alert('上传失败！'+data.response.message);
        });
    });

    function getUrlParam(paramName) {
        var s = location.search;
        if (s != null) {
            var sarr = s.substr(1).split("&");
            var tarr;
            for (i = 0; i < sarr.length; i++) {
                tarr = sarr[i].split("=");
                if (tarr.length == 2 && tarr[0].toLowerCase() == paramName) {
                    return tarr[1];
                }
            }
            return "";
        }
    }
    function isNumber(oNum) {
        if (!oNum) return false;
        var strP = /^\d+(\.\d+)?$/;
        if (!strP.test(oNum)) return false;
        try {
            if (parseFloat(oNum) != oNum) return false;
        }
        catch (ex) {
            return false;
        }
        return true;
    }
    function setid() {
        if (document.getElementById("type1").style.display == '') {
            str = '';
            if (!isNumber(document.getElementById("upcount").value)) {
                alert('请输入数字！');
                return false;
            }
            if (!document.getElementById("upcount").value)
                document.getElementById("upcount").value = 1;
            if (document.getElementById("upcount").value > 20) {
                alert('上传数目不能大于20！');
                return false;
            }
            var tmp = "";
            if (getUrlParam('path') != null) tmp += "&path=" + getUrlParam('path');
            if (getUrlParam('code') != null) tmp += "&code=" + getUrlParam('code');
            if (getUrlParam('out') != null) tmp += "&out=" + getUrlParam('out');
            if (getUrlParam('rtn') != null) tmp += "&rtn=" + getUrlParam('rtn');
            window.location = 'upload.aspx?count=' + parseInt(document.getElementById("upcount").value) + tmp;
        }
        else if (document.getElementById("type3").style.display == '') {
            str = '';
            if (!document.getElementById("upcount").value)
                document.getElementById("upcount").value = 1;
            if (document.getElementById("upcount").value > 20) {
                alert('添加数目不能大于20！');
                return false;
            }
            for (i = 1; i <= document.getElementById("upcount").value; i++)
                str += '<div class="row pl-3 pb-2">标题：<INPUT class="form-control w-25" id=Text3 type=text name=url>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;网址：<INPUT class="form-control w-25" id=Text1 type=text name=url></div>';
            document.getElementById("upid1").innerHTML = str + '<br>';
        }
        else {
            str = '';
            if (!document.getElementById("upcount").value)
                document.getElementById("upcount").value = 1;
            if (document.getElementById("upcount").value > 20) {
                alert('添加数目不能大于20！');
                return false;
            }
            for (i = 1; i <= document.getElementById("upcount").value; i++)
                str += '<div class="row align-items-center pl-3 pb-2">下载地址：<INPUT class="form-control w-25" id=textBoxFileURL type=text name=textBoxFileURL size=52>&nbsp;&nbsp;文件描述：<input id=note2 name=note2 type=text class="form-control w-25" size=30></div>';
            document.getElementById("upid2").innerHTML = str + '<br>';
        }
    }
    function filenote() {
        var valueStr = "";
        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {

            if (inputs[i].name == "note") {
                valueStr += inputs[i].value + ",";
            }
        }
        document.getElementById("hidurl").value = valueStr;
    }
    function outlink() {
        var valueStr = "";
        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {

            if (inputs[i].name == "url") {
                valueStr += inputs[i].value + ",";
            }
        }
        document.getElementById("hidurl").value = valueStr;
    }
    function show1() {
        document.getElementById("type1").style.display = '';
        document.getElementById("type2").style.display = 'none';
        document.getElementById("type3").style.display = 'none';
        document.getElementById("type4").style.display = 'none';
        document.getElementById("type5").style.display = 'none';
        document.getElementById("type6").style.display = 'none';
        document.getElementById("type7").style.display = '';
        $("#model_file").removeAttr("webkitdirectory");
    }
    function show2() {
        alert('仅商业版提供');document.getElementById("click1").checked = true;
    }
    function show3() {
        alert('仅商业版提供');document.getElementById("click1").checked = true;
    }
    function show4() {
        alert('仅商业版提供');document.getElementById("click1").checked = true;
    }
    function EditOpt() {
        $.post(
            "ajax.aspx",
            { action: "EditOpt3", str: document.getElementById("autorename").checked}
        )
       // Webdisk.upload.EditOpt(document.getElementById("autorename").checked);
    }
    function getUrlParam(paramName) {
        var s = location.search;
        if (s != null && s.length > 1) {
            var sarr = s.substr(1).split("&");
            var tarr;
            for (i = 0; i < sarr.length; i++) {
                tarr = sarr[i].split("=");
                if (tarr.length == 2 && tarr[0].toLowerCase() == paramName) {
                    return tarr[1];
                }
            }
            return null;
        }
    }
    function StartEverything(callingButton) {
        if (document.getElementById('progressStartButton').value == ' 停 止 ') {
            document.getElementById('progressStartButton').value = ' 下 载 ';
            document.getElementById('progressNotices').innerHTML = '';
            document.getElementById('progressBarArea').style.display = 'none';
            window.frames['progressIFrame'].location.href = 'about:blank';
        }
        else {
            document.getElementById('progressNotices').innerHTML = '正在处理，请稍候……';
            window.frames['progressIFrame'].location.href = UniqueUrl(AppendArgument("downworker.aspx"));
        }
    }
    var objMessage = null;
    var objBar = null;
    var maxReached = false;
    function SetProgress(percentage, message) {
        if (percentage <= 100) {
            if (objMessage == null) {
                objMessage = document.getElementById('progressNotices');
            }
            if (objBar == null) {
                objBar = document.getElementById('progressBar');
            }
            if (message != null && message != '') {
                objMessage.innerHTML = message;
            }
            if (percentage > 0) {
                objBar.innerHTML = '.';
            } else {
                objBar.innerHTML = '';

            }
            objBar.style.width = percentage.toString() + '%';
            if (percentage == 100) {
                SetDisplay(false);
            }
        } else {
            maxReached = true;
        }
    }
    function SetDisplay(progressIsRunning) {
        var progressBarArea = document.getElementById('progressBarArea');
        progressBarArea.style.display = (progressIsRunning ? 'block' : 'none');
        document.getElementById('progressStartButton').value = (progressIsRunning ? ' 停 止 ' : ' 下 载 ');
    }
    function Say(message) {
        if (message == null || message == '') {
            message = '(null)';
        }
        alert(message);
    }
    function AppendArgument(url) {
        if (url.indexOf('?') > 0) {
            url += '&';
        } else {
            url += '?';
        }
        url += "file";
        var argValue = '';
        var argNote = '';
        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].id == "textBoxFileURL") argValue += inputs[i].value + ",";
            if (inputs[i].id == "note2") argNote += inputs[i].value + ",";
        }
        if (argValue != null && argValue != '') {
            if (url.indexOf('=') != (url.length - 1)) {
                url += '=';
            }
            url += escape(argValue);
        }
        else {
            alert('请输入下载文件的外部地址！');
            return;
        }
        url += '&path=' + getUrlParam('path');
        url += '&note=' + escape(argNote);
        if (getUrlParam('out') != null) url += '&out=' + getUrlParam('out');
        if (document.all.autorename.checked) url += '&auto=1';
        SetDisplay(true);
        return url;
    }
    function UniqueUrl(url) {
        var randomNum, uniqifier;
        if (url == null || url == '') {
            url = 'UrlUndefined';
        } else if (url.indexOf('Unique') > 0) {
            randomNum = Math.random();
            url = ReplaceArgumentValue(url, 'Unique', randomNum.toString().substr(2));
        } else {
            randomNum = Math.random();
            uniqifier = 'Unique=' + randomNum.toString().substr(2);
            if (url.indexOf('?') > 0) {
                url += '&' + uniqifier;
            } else {
                url += '?' + uniqifier;
            }
        }
        return url;
    }
    function ReplaceArgumentValue(searchArgs, argName, newArgValue) {
        var newSearchArgs;
        argName += '=';
        var indexStart = searchArgs.indexOf(argName);
        if (indexStart >= 0) {
            var indexEnd = searchArgs.indexOf('&', indexStart);
            newSearchArgs = searchArgs.substr(0, indexStart + argName.length);
            newSearchArgs += newArgValue;
            if (indexEnd > indexStart) {
                newSearchArgs += searchArgs.substr(indexEnd);
            }
            return newSearchArgs;
        } else {
            return searchArgs;
        }
    }
</script>