<!--#include file="../Inc/Cls_Main.Asp"-->
<!--#include file="inc/Cls_Admin.Asp"-->
<!--#include file="inc/Cls_MapPath.Asp"-->
<!--#include file="Admin_Check.Asp"-->
<%
Dim CmsAdmin, ToUrl, UpLoadFilePath
'=============================================================================
ToUrl = CmsFun.LoadToUrl()
If Easp.IsN(CmsUpLoadFile) Then
    UpLoadFilePath = "/UpFile/"
Else
    UpLoadFilePath = CmsUpLoadFile
End If
'=============================================================================
Set CmsAdmin = New Cls_Admin
CmsAdmin.SetAdminTitle = CmsSiteName
CmsAdmin.SetBodyCssName = "mainbody"
CmsAdmin.SetAdminPath = ""
CmsAdmin.LoadHead()
'=============================================================================
Dim Action
'=============================================================================
Action = Easp.Get("action")
Select Case Action
    Case "pageload"
        Call PageLoad()
    Case "sf"
        Call SelFile()
    Case "df"
        Call DelAllFile()
    Case Else
        Call PageLoad()
End Select
CmsAdmin.LoadFooter()
Set CmsAdmin = Nothing

Sub PageLoad()
    ChkSysAdminLevel "sys_upload", "show"
    Dim TempUpPath, BakUpPath, UploadDir, ChannelId
    Dim UrlLink, UrlLinks, PageIndex, TotalPage, PageNum
    '====================================================================
    ChannelId = Easp.Get("ChannelId:n:0")
    TempUpPath = CmsUpLoadFile & Easp.IIf(ChannelId > 0, ChannelId & "/", "")
    BakUpPath = TempUpPath
    UploadDir = Easp.Get("UploadDir:s")
    PageIndex = Easp.Get("p:n:0")
    PageIndex = Easp.IIf(PageIndex = 0, 1, PageIndex)
    PageNum = 20 '设定每页的显示数量
    '====================================================================
    Easp.Use "fso"
    Easp.Fso.SizeFormat = ""
    If Not Easp.IsN(UploadDir) Then
        If UploadDir = "/" Then
            CmsAdmin.JscriptMsg "错误的访问文件夹参数！", "back", "Error", "null"
        Else
            TempUpPath = UploadDir
            If InStr(UploadDir, BakUpPath) = 0 Then
                CmsAdmin.JscriptMsg "错误的访问文件夹参数！", "back", "Error", "null"
            End If
        End If
    End If
    If Not Easp.Fso.IsFolder(TempUpPath) Then
        Easp.Fso.CreateFolder TempUpPath
    End If
    '====================================================================
    UrlLink = "?ChannelId=" & ChannelId & "&UploadDir=" & Server.URLEncode(TempUpPath) & "&"
    UrlLinks = "?ChannelId=" & ChannelId & "&UploadDir=" & Server.URLEncode(GetBackDir(TempUpPath))
%>
<div class="navigation">插件管理 &gt; 上传文件管理</div>
<div class="tools_box">
  <div class="tools_bar">
    <ul>
      <li><a href="javascript:void(0);" onclick="checkAll(this);" class="tools_btn"><span><b class="all">全选</b></span></a></li>
      <li><a href="javascript:void(0);" onclick="return ExePostBack('确定要批量删除吗？','myform','?action=df');" class="tools_btn"><span><b class="delete">批量删除</b></span></a></li>
      <li><a href="Admin_File.Asp<%=UrlLink%>zjjcms=1" class="tools_btn"><span><b class="refresh">刷新列表</b></span></a></li>
    </ul>
  </div>
  <div class="select_box"> 文件目录-><%=ShowChildFolder("", ChannelId, TempUpPath)%>,当前目录-><%=TempUpPath%><%=Easp.IIF(TempUpPath <> "" And TempUpPath <> BakUpPath,"，<a href="""& UrlLinks &""">↑返回上一层目录</a>","")%></div>
</div>
<form id="myform" action="?action=df" method="post">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">
    <tr>
      <th width="5%">选择</th>
      <th width="50%" align="left">文件名(带：s.*的图片文件为生成的缩略图)</th>
      <th width="15%">类型</th>
      <th width="10%">文件大小</th>
      <th width="20%">上传时间</th>
    </tr>
    <%
    Dim Fso, FsoFile, UpFile, TotalNum, i, UpFileList, FileName
    Set Fso = Server.CreateObject(Easp.FsoName)
    Set FsoFile = Fso.GetFolder(Easp.Fso.MapPath(TempUpPath))
    Set UpFile = FsoFile.Files
    TotalNum = CmsFun.ChkNumEric(UpFile.Count)
    If TotalNum Mod PageNum = 0 Then
        TotalPage = (TotalNum \ PageNum)
    Else
        TotalPage = (TotalNum \ PageNum) + 1
    End If
    If CmsFun.ChkNumEric(PageIndex) > CmsFun.ChkNumEric(TotalPage) Then
        PageIndex = 1
    End If
    i = 0
    For Each UpFileList in UpFile
        i = i + 1
        If i>(PageIndex - 1) * PageNum And i<= PageIndex * PageNum Then
            FileName = TempUpPath & UpFileList.Name
    %>
    <tr align="center">
      <td><input type="checkbox" name="ChkBoxId" value="<%=FileName%>" /></td>
      <td align="left"><a href="<%=FileName%>" target="_blank" title="<%=FileName%>"><%=UpFileList.Name%></a></td>
      <td><%=GetFileIcon(16,UpFileList.Name)%></td>
      <td><%=CmsFun.GetSize(UpFileList.Size)%></td>
      <td><%=CmsFun.TimeToString(UpFileList.datecreated, "yyyy-mm-dd hh:ii:ss")%></td>
    </tr>
    <%
        Else
            If i>PageIndex * PageNum Then
                Exit For
            End If
        End If
    Next
    %>
  </table>
  <div class="line15"> </div>
  <div class="page_box">
    <div class="flickr right"><%=ShowPageInfo(TotalPage, TotalNum, PageIndex, PageNum, UrlLink)%></div>
  </div>
</form>
<%
End Sub

Sub SelFile()
    Dim TempUpPath, BakUpPath, UploadDir, ChannelId
    Dim UrlLink, UrlLinks, PageIndex, TotalPage, PageNum
    Dim ReturnId
    '====================================================================
    ChannelId = Easp.Get("ChannelId:n:0")
    TempUpPath = CmsUpLoadFile & ChannelId & "/"
    BakUpPath = TempUpPath
    UploadDir = Easp.Get("UploadDir:s")
    ReturnId = Easp.Get("ReturnId:s")
    PageIndex = Easp.Get("p:n:0")
    PageIndex = Easp.IIf(PageIndex = 0, 1, PageIndex)
    PageNum = 20 '设定每页的显示数量
    '====================================================================
    Easp.Use "fso"
    Easp.Fso.SizeFormat = ""
    If Not Easp.IsN(UploadDir) Then
        TempUpPath = UploadDir
        If InStr(UploadDir, BakUpPath) = 0 Then
            CmsAdmin.JscriptMsg "错误的访问文件夹参数！", "back", "Error", "null"
        End If
    End If
    If Not Easp.Fso.IsFolder(TempUpPath) Then
        Easp.Fso.CreateFolder TempUpPath
    End If
    '====================================================================
    UrlLink = "?action=sf&ChannelId=" & ChannelId & "&ReturnId="& ReturnId &"&UploadDir=" & Server.URLEncode(TempUpPath) & "&"
    UrlLinks = "?action=sf&ChannelId=" & ChannelId & "&ReturnId="& ReturnId &"&UploadDir=" & Server.URLEncode(GetBackDir(TempUpPath))
%>
<div class="navigation">插件管理 &gt; 选择上传文件</div>
<div class="tools_box">
  <div class="select_box"> 文件目录-><%=ShowChildFolder("action=sf&ReturnId="& ReturnId &"&", ChannelId, TempUpPath)%>,当前目录-><%=TempUpPath%><%=Easp.IIF(TempUpPath <> "" And TempUpPath <> BakUpPath,"，<a href="""& UrlLinks &""">↑返回上一层目录</a>","")%></div>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">
  <tr>
    <th width="40%" align="left">文件名(带：s.*的图片文件为生成的缩略图)</th>
    <th width="10%">打开文件</th>
    <th width="15%">类型</th>
    <th width="15%">文件大小</th>
    <th width="20%">上传时间</th>
  </tr>
  <%
  Dim Fso, FsoFile, UpFile, TotalNum, i, ii, UpFileList, FileName
  Set Fso = Server.CreateObject(Easp.FsoName)
  Set FsoFile = Fso.GetFolder(Easp.Fso.MapPath(TempUpPath))
  Set UpFile = FsoFile.Files
  TotalNum = CmsFun.ChkNumEric(UpFile.Count)
  If TotalNum Mod PageNum = 0 Then
      TotalPage = TotalNum \ PageNum
  Else
      TotalPage = TotalNum \ PageNum + 1
  End If
  If CmsFun.ChkNumEric(PageIndex) > CmsFun.ChkNumEric(TotalPage) Then
      PageIndex = 1
  End If
  i = 0
  For Each UpFileList in UpFile
      i = i + 1
      If i>(PageIndex - 1) * PageNum And i<= PageIndex * PageNum Then
          FileName = TempUpPath & UpFileList.Name
  %>
  <tr align="center">
    <td align="left">·<a href="javascript:void(0);" onclick="ReturnDialogVal('<%=ReturnId%>','<%=FileName%>');return false;" title="点此即可返回到文本框"><%=UpFileList.name%></a></td>
    <td><a href="<%=FileName%>" target="_blank" title="点此打开文件:<%=FileName%>">打开</a></td>
    <td><%=GetFileIcon(16,UpFileList.name)%></td>
    <td><%=CmsFun.GetSize(UpFileList.size)%></td>
    <td><%=CmsFun.TimeToString(UpFileList.datecreated, "yyyy-mm-dd hh:ii:ss")%></td>
  </tr>
  <%
      Else
          If i>PageIndex * PageNum Then
              Exit For
          End If
      End If
      ii = ii + 1
      If ii = 3 Then
          ii = 1
      End If
  Next
  %>
</table>
<div class="line15"> </div>
<div class="page_box">
  <div class="flickr right"><%=ShowPageInfo(TotalPage, TotalNum, PageIndex, PageNum, UrlLink)%></div>
</div>
<%
End Sub

Sub DelAllFile()
    ChkSysAdminLevel "sys_upload", "del"
    Dim BoxListId, i, FileList
    BoxListId = Trim(Replace(Easp.Post("ChkBoxId:s") & "", ", ", ","))
    If Easp.IsN(BoxListId) Then
        CmsAdmin.JscriptMsg "未选择文件！", "back", "Error", "null"
    Else
        FileList = Split(BoxListId, ",")
        For i = 0 To UBound(FileList)
            If Easp.Fso.IsFile(FileList(i)) Then
                Easp.Fso.DelFile FileList(i)
            End If
        Next
        CmsAdmin.JscriptMsg "批量删除文件成功！", CmsFun.LoadToUrl(), "Success", "null"
    End If
End Sub

Function ShowPageInfo(ByVal TotalPage, ByVal TotalCount, ByVal PageIndex, ByVal PageSizeNum, ByVal LinkFile)
    Dim retval, j, pageNumber, BasePage, iPageIndex
    retval = "<span class=""disableds"">第" & PageIndex & "页/总" & TotalPage & "页</span>"
    retval = retval & "<span class=""disableds"">/每页" & PageSizeNum & "条/总" & TotalCount & "条</span>"
    If CmsFun.ChkNumEric(PageIndex) = 1 Then
        retval = retval & "<span class=""disabled"">首　页</span><span class=""disabled"">上一页</span>"
    Else
        retval = retval & "<a href=""" & LinkFile & "p=1"">首　页</a> <a href=""" & LinkFile & "p=" & CStr(PageIndex - 1) & """>上一页</a>"
    End If
    BasePage = (PageIndex \ 10) * 10
    For j = 1 To 10
        pageNumber = BasePage + j
        If PageNumber > TotalPage Then
            Exit For
        End If
        If CmsFun.ChkNumEric(PageNumber) = CmsFun.ChkNumEric(PageIndex) Then
            retval = retval & "<span class=""current"">" & pageNumber & "</span>"
        Else
            retval = retval & "<a href=""" & LinkFile & "p=" & pageNumber & """>" & pageNumber & "</a>"
        End If
    Next
    If (CmsFun.ChkNumEric(TotalPage) = 0 Or CmsFun.ChkNumEric(PageIndex) = CmsFun.ChkNumEric(TotalPage)) Then
        retval = retval & "<span class=""disabled"">下一页</span><span class=""disabled"">尾　页</span>"
    Else
        retval = retval & "<a href=""" & LinkFile & "p=" & CStr(PageIndex + 1) & """>下一页</a> <a href=""" & LinkFile & "p=" & CStr(TotalPage) & """>尾　页</a>"
    End If
    ShowPageInfo = retval
End Function

'=================================================
'过程名：ShowChildFolder
'作  用：显示子目录菜单
'=================================================

Function ShowChildFolder(ByVal LinkFile, ByVal ChannelId, ByVal UploadDir)
    Dim Flist, i, FolderPath, strTemp
    strTemp = ""
    If Easp.Fso.IsFolder(UploadDir) Then
        Flist = Easp.Fso.List(UploadDir, 2)
        If UBound(Flist, 2) >= 0 Then
            For i = 0 To UBound(Flist, 2)
                FolderPath = UploadDir & Flist(0, i)
                strTemp = strTemp & "<a href=""?"& LinkFile & "ChannelId=" & ChannelId & "&UploadDir=" & FolderPath & """><img src=""images/icon/16/folder.png"" border=""0"" alt=""修改时间：" & Flist(2, i) & """ align=""absMiddle"">"& Replace(Flist(0, i) & "", "/", "") & "</a>"
            Next
        Else
            strTemp = strTemp & "该目录没有文件夹!"
        End If
    End If
    ShowChildFolder = strTemp
End Function

'=================================================
'函数名：GetFileIcon
'作  用：获取文件图标
'=================================================

Function GetFileIcon(ByVal fPath, ByVal fName)
    Dim filename, Icon
    filename = LCase(Easp.Fso.ExtOf(fName))
    Select Case filename
        Case ".ai"
            Icon = "ai.gif"
        Case ".asp", ".asa"
            Icon = "asp.gif"
        Case ".avi", ".mid", ".mp3", ".rm", ".rmvb", ".wma", ".mov", ".wmv"
            Icon = "avi.gif"
        Case ".bmp"
            Icon = "bmp.gif"
        Case ".chm"
            Icon = "chm.gif"
        Case ".aspx", ".asax", ".ascx", ".ashx"
            Icon = "cs.gif"
        Case ".css"
            Icon = "css.png"
        Case ".dll"
            Icon = "dll.gif"
        Case ".doc", ".docx"
            Icon = "doc.gif"
        Case ".exe"
            Icon = "exe.gif"
        Case ".fla", ".flv"
            Icon = "fla.gif"
        Case ".gif"
            Icon = "gif.png"
        Case ".html", ".htm", ".shtml" , ".shtm"
            Icon = "html.gif"
        Case ".jpg", ".png", ".jpge"
            Icon = "jpg.png"
        Case ".js"
            Icon = "js.png"
        Case ".mdb"
            Icon = "mdb.gif"
        Case ".pdf"
            Icon = "pdf.gif"
        Case ".php"
            Icon = "php.png"
        Case ".ppt", ".pptx"
            Icon = "ppt.gif"
        Case ".psd"
            Icon = "psd.gif"
        Case ".rar", ".7z", ".zip"
            Icon = "rar.gif"
        Case ".swf"
            Icon = "swf.gif"
        Case ".txt"
            Icon = "txt.gif"
        Case ".xls", ".xlsx"
            Icon = "xls.gif"
        Case ".xml"
            Icon = "xml.gif"
        Case Else
            Icon = "default.gif"
    End Select
    GetFileIcon = "<img src=""images/icon/"& fPath &"/" & Icon & """ border=""0"" alt="""" />"
End Function

Function GetBackDir(strDir)
    If Len(strDir) = 0 Then
        Exit Function
    End If
    If InStr(strDir, "/") = 0 Then
        GetBackDir = strDir
    Else
        Dim Path, SpPath, i, PathTemp
        SpPath = Split(strDir, "/")
        For i = 0 To UBound(SpPath) - 2
            PathTemp = PathTemp & SpPath(i) &"/"
        Next
        GetBackDir = PathTemp
    End If
End Function
%>
