<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="LMN.Web.Admin.FileManager.Default" %>

<%@ Import Namespace="LMN.Common" %>
<!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>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<link href="../css/filemanager.css" rel="stylesheet" type="text/css" />
<title>FileManager</title>
</head>
<body>
<form id="form1" runat="server" target="iframe">
<input type="hidden" id="action" name="action" value="upload" /> <input type="hidden" id="name" name="name" />
<table id="Table3" width="100%">
  <tr>
    <td colspan="2" style="text-align: left;"><img src="img/GoUp.gif" alt="上传文件" />上传文件：&lt;
      <%=Utils.FileSizeFormat(Utils.GetConfigInt("UploadLimit"))%>，允许类型“<%=Utils.GetConfigString("FileAllowed")%>”</td>
  </tr>
  <tr>
    <th style="text-align: left;" colspan="2"><input name="fileup" type="file" id="fileup" style="width: 160px;" runat="server" /> <input type="checkbox" id="rename" name="rename" checked="checked" value="1" /><label for="rename">改名</label> <%--<input type="checkbox" id="thumb" name="thumb" value="1" /><label for="thumb" title="按配置文件中设置处理图片">处理</label>--%><input type="button" name="upload" value="上传" id="upload" /></th>
  </tr>
  <tr>
    <td><img src="img/OpenFolder.gif" alt="">当前路径：<%=current %>
      共
      <%=dt.Rows.Count.ToString() %>
      个对象，其中文件夹
      <%=DirCount.ToString() %>
      个，文件
      <%=FileCount.ToString() %>
      个，共
      <%=Utils.FileSizeFormat(SizeTotal) %></td>
    <td style="white-space: nowrap; text-align: right;"><a href="./Default.aspx?path=<%=Utils.UrlEncode(parent) %>&target=<%=Totarget %>" title="返回上级目录"><img src="img/ParentFolder.gif" alt="上级目录" /></a>&nbsp;<a id="creation" href="javascript:;" title="新建文件夹"><img alt="新建文件夹" src="img/NewFolder.gif" /></a>&nbsp;<a href="javascript:;" id="multidele" title="删除选中"><img alt="删除选中" src="img/Delete.gif" /></a></td>
  </tr>
</table>
<table width="100%">
  <tr>
    <th style="width: 15px;"><input name="all" type="checkbox" id="all" value="true" /></th>
    <th>名称</th>
    <th>大小</th>
    <th>建立时间</th>
    <th>最后修改时间</th>
    <th>操作</th>
  </tr>
  <asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
      <tr>
        <td><input id="id_<%# Utils.UrlEncode(Eval("Name").ToString()) %>" type="checkbox" name="<%#Eval("Type").ToString() == "0"?"folder":"file"%>" value="<%#Utils.UrlEncode(Eval("Name").ToString()) %>" /></td>
        <td>
          <%#Eval("Type").ToString() == "0" ? "<img src=\"img/ClosedFolder.gif\" alt=\"文件夹\" />" : "<img src=\"img/GoDown.gif\" alt=\"文件\" />"%>&nbsp;<%#(Eval("Type").ToString() == "0" ? "<a href=\"Default.aspx?path=" + Utils.UrlEncode(current + Eval("Name")) + "&target=" + Totarget + "\">" : "<a href=\"" + current + Eval("Name") + "\" title=\"选择此文件\" onclick=\"chooseFile(" + Eval("Type") + ",'" + current + Eval("Name") + "')\">") + (".jpg.gif.png.bmp.jpeg".IndexOf(Utils.FileExt(Eval("Name").ToString())) == -1 || Eval("Type").ToString() == "0" ? Eval("Name") : "<img src=\"" + current + Eval("Name") + "\" width=\"100\" alt=" + Eval("Name") + " />") + "</a>"%>
        </td>
        <td class="right">
          <%#Eval("Type").ToString() == "0" ? "-" :Utils.FileSizeFormat(long.Parse(Eval("Length").ToString()))%></td>
        <td class="center">
          <%#Eval("CreationTime") %></td>
        <td class="center">
          <%#Eval("LastWriteTime") %></td>
        <td class="center"><%#Eval("Type").ToString() == "0" ? "-" : "<a href=\"" + current + Eval("Name") + "\" target=\"_blank\">查看</a>"%><!--&nbsp;<a title="重命名" href="javascript:;"><img src="img/Rename.gif" alt="重命名" /></a>&nbsp;<a href="#" onclick="javascript:return confirm('确认删除？');" title="删除文件"><img src="img/Delete.gif" alt="" /></a>--></td>
      </tr>
    </ItemTemplate>
  </asp:Repeater>
</table>
</form>
<iframe id="iframe" name="iframe" src="about:blank" style="display: none;"></iframe>
<script type="text/javascript">
$("#all").click(function(){
  var b = $(this).attr("checked");
  $("input[name=folder]").each(function(){
    $(this).attr("checked", b);
  });
  $("input[name=file]").each(function(){
    $(this).attr("checked", b);
  });
});
$("#upload").click(function () {
  var sfile = $("#fileup").val();
  if (sfile == "" || sfile.indexOf(".") == -1) {
    alert("请先选择文件！");
    return false;
  }
  var sext = sfile.substring(sfile.lastIndexOf(".")).toLowerCase();
  if("<%=Utils.GetConfigString("FileAllowed")%>".toLowerCase().indexOf(sext) == -1) {
    alert(sext+"不是允许上传的类型！");
    return false;
  }
  // alert(sext);
  $("#action").val("upload");
  $("#form1").submit();
  return true;
});
$("#creation").click(function () {
  var newName = window.prompt("请输入新文件夹名称：", "");
  alert(newName);
  if (newName == "" || newName == null) {
    alert("请输入文件名！");
    return false;
  }
  if (/[\/\\:;\*\?"\<\>|\s]+|(^[\.]+$)/.test(newName)) {
    alert("文件名格式不正确！");
    return false;
  }
  $("#action").val("create");
  $("#name").val(newName);
  $("#form1").submit();
  return true;
});
$("#multidele").click(function () {
  if ($("input[name=file]:checked").length == 0 && $("input[name=folder]:checked").length == 0) {
    alert("没有选择要删除的项！");
    return false;
  }
  if (confirm("确认删除选中的文件、文件夹？")) {
    $("#action").val("delete");
    $("#form1").submit();
  }
  return true;
});
function chooseFile(t, p) {
  if (t == 0) {
    alert("请选择文件进行操作！");
    return false;
  }
  //alert($("#<%=Totarget %>", parent.document).length);
  $("#<%=Totarget %>", parent.document).val(p);
  parent.wBox.close();
  return false;
}
function reName(filepath) {
  var newName = prompt("请输入新文件名：", "newName.ext");
  $("#action").val("rename");
  $("#filename").val(filepath);
  $("#newname").val(newName);
  $("#form1").submit();
}
</script>
</body>
</html>
