<!--#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
ToUrl = CmsFun.LoadToUrl()
'=============================================================================
Set CmsAdmin = New Cls_Admin
CmsAdmin.SetAdminTitle = CmsSiteName
CmsAdmin.SetBodyCssName = "mainbody"
CmsAdmin.SetAdminPath = CmsAdminMapPath
CmsAdmin.LoadHead()
'=============================================================================
Dim Action
'=============================================================================
Action = Easp.Get("action")
Select Case Action
    Case "pageload"
        Call PageLoad()
    Case "sf"
        Call SelectFile()
    Case "df"
        Call DelFile()
    Case Else
        Call PageLoad()
End Select
CmsAdmin.LoadFooter()
Set CmsAdmin = Nothing

Sub PageLoad()
    ChkSysAdminLevel "sys_templabel", "show"
    '=====================================================================================
    Dim ThemePath, BakThemePath, ListPath, i, StrDir, IsPic, IsFile, EditMemo
    ThemePath = CmsTemplates & CmsTempSkin
    BakThemePath = CmsTemplates & CmsTempSkin
    StrDir = Easp.Get("dirs:s")
    Easp.Use "Fso"
    If StrDir <> "" Then
        ThemePath = StrDir
        If InStr(StrDir, BakThemePath) = 0 Then
            CmsAdmin.JscriptMsg "错误的访问文件夹参数！", "back", "Error", "null"
        End If
    End If
    If Not Easp.Fso.IsFolder(ThemePath) Then
        Exit Sub
    End If
    ListPath = Easp.Fso.List(ThemePath, 0)
    IsPic = ""
    IsFile = ""
%>
<div class="navigation">控制面板 &gt; 系统模板管理</div>
<div class="tools_box">
  <div class="tools_bar">
    <ul>
      <li><a href="Admin.Add.Asp" class="tools_btn"><span><b class="add">添加模板</b></span></a></li>
      <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=del');" class="tools_btn"><span><b class="delete">批量删除</b></span></a></li>
      <li><a href="Admin.Index.Asp" class="tools_btn"><span><b class="refresh">刷新列表</b></span></a></li>
    </ul>
  </div>
  <div class="select_box"> 当前目录-><%=ThemePath%><%=Easp.IIf(StrDir <> "" And StrDir <> BakThemePath, "，<a href=""?dirs="& FileCode(GetBackDir(ThemePath)) &""">↑返回上一层目录</a>", "")%></div>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">
  <tr>
    <th width="35%" align="left">文件/文件夹名</th>
    <th width="10%">类 型</th>
    <th width="15%">文件大小</th>
    <th width="25%">最后修改时间</th>
    <th width="15%">操 作</th>
  </tr>
  <%
  For i = 0 To UBound(ListPath, 2)
      EditMemo = ""
      If (CmsFun.IsImages(ListPath(0, i)) Or Easp.Fso.ExtOf(LCase(ListPath(0, i))) = ".swf") Then
          IsPic = "<a href="""& ThemePath & ListPath(0, i) &""" target=""_blank"" title=""点击查看："& ListPath(0, i) &""">"& ListPath(0, i) &"</a>"
          EditMemo = "<a href="""& ThemePath & ListPath(0, i) &""" target=""_blank"" title=""点击查看："& ListPath(0, i) &""">点击查看</a>"
      Else
          Dim FileExt
          FileExt = LCase(Easp.Fso.ExtOf(ListPath(0, i)))
          If (FileExt = ".html" Or FileExt = ".js" Or FileExt = ".css") Then
              IsPic = "<a href=""Admin.Edit.Asp?f="& FileCode(ThemePath & ListPath(0, i)) &""">"& ListPath(0, i) &"</a>"
              EditMemo = "<a href=""Admin.Edit.Asp?f="& FileCode(ThemePath & ListPath(0, i)) &""">编辑</a> | <a href=""?action=df&f="& FileCode(ThemePath & ListPath(0, i)) &""" onclick=""ExeConfirm('您确定要删除，删除后无法恢复',0,'?action=df&f="& FileCode(ThemePath & ListPath(0, i)) &"');return false;"">删除</a>"
          Else
              IsPic = "<a href=""?dirs="& FileCode(ThemePath & ListPath(0, i)) &""" title=""进入该文件夹"">"& ListPath(0, i) &"</a>"
              EditMemo = "<a href=""?dirs="& FileCode(ThemePath & ListPath(0, i)) &""" title=""进入该文件夹"">进入该文件夹</a>"
          End If
      End If
      If ListPath(4, i) = "文件夹" Then
          IsFile = "<img src=""../images/icon/16/folder.png"" border=""0"" width=""16"" height=""16"" title="""& Replace(ListPath(0, i), "/", "，文件夹") &""" alt="""& ListPath(0, i) &""" />"
      Else
          IsFile = GetFileIcon("16", ListPath(0, i), ListPath(4, i))
      End If
  %>
  <tr align="center">
    <td align="left"><%=IsPic%></td>
    <td><%=IsFile%></td>
    <td><%=ListPath(1,i)%></td>
    <td><%=CmsFun.TimeToString(ListPath(2,i), "yyyy-mm-dd hh:ii:ss")%></td>
    <td><%=EditMemo%></td>
  </tr>
  <%
  Next
  %>
</table>
<%
End Sub

Sub SelectFile()
    Dim ReturnId, UrlLinks, ThemePath, BakThemePath, ListPath, i, StrDir, IsPic, IsFile, EditMemo
    ThemePath = CmsTemplates & CmsTempSkin
    BakThemePath = CmsTemplates & CmsTempSkin
    StrDir = Easp.Get("dirs:s")
    ReturnId = Trim(Easp.Get("ReturnId:s"))
    Easp.Use "Fso"
    If StrDir <> "" Then
        ThemePath = StrDir
        If InStr(StrDir, BakThemePath) = 0 Then
            CmsAdmin.JscriptMsg "错误的访问文件夹参数！", "back", "Error", "null"
        End If
    End If
    If Not Easp.Fso.IsFolder(ThemePath) Then
        Exit Sub
    End If
    ListPath = Easp.Fso.List(ThemePath, 0)
    IsPic = ""
    IsFile = ""
    UrlLinks = "?action=sf&ReturnId="& ReturnId &"&dirs="
%>
<div class="navigation">控制面板 &gt; 选择系统模板</div>
<div class="tools_box">
  <div class="tools_bar">
    <ul>
      <li><a href="Admin.Index.Asp<%=UrlLinks%>" class="tools_btn"><span><b class="refresh">刷新列表</b></span></a></li>
    </ul>
  </div>
  <div class="select_box"> 当前目录-><%=ThemePath%><%=Easp.IIF(StrDir <> "" And StrDir <> BakThemePath,",<a href="""& UrlLinks & FileCode(GetBackDir(ThemePath)) &""">↑返回上一层目录</a>","")%></div>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">
  <tr align="center">
    <th width="40%" align="left">文件/文件夹名</th>
    <th width="20%">类 型</th>
    <th width="15%">文件大小</th>
    <th width="25%">操 作</th>
  </tr>
  <%
  For i = 0 To UBound(ListPath, 2)
      EditMemo = ""
      If (CmsFun.IsImages(ListPath(0, i)) Or Easp.Fso.ExtOf(LCase(ListPath(0, i))) = ".swf") Then
          IsPic = "<a href="""& ThemePath & ListPath(0, i) &""" target=""_blank"" title=""点击查看："& ListPath(0, i) &""">"& ListPath(0, i) &"</a>"
          EditMemo = "<a href="""& ThemePath & ListPath(0, i) &""" target=""_blank"" title=""点击查看："& ListPath(0, i) &""">点击查看</a>"
      Else
          Dim FileExt
          FileExt = LCase(Easp.Fso.ExtOf(ListPath(0, i)))
          If (FileExt = ".html" Or FileExt = ".js" Or FileExt = ".css") Then
              IsPic = "<a href=""javascript:void(0);"" onclick=""ReturnDialogVal('"& ReturnId &"','"& Replace(ThemePath & ListPath(0, i), BakThemePath, "") &"');return false;"">"& ListPath(0, i) &"</a>"
              EditMemo = "<a href=""javascript:void(0);"" onclick=""ReturnDialogVal('"& ReturnId &"','"& Replace(ThemePath & ListPath(0, i), BakThemePath, "") &"');return false;"">选择</a>"
          Else
              IsPic = "<a href="""& UrlLinks & ThemePath & ListPath(0, i) &""" title=""进入该文件夹"">"& ListPath(0, i) &"</a>"
              EditMemo = "<a href="""& UrlLinks & ThemePath & ListPath(0, i) &""" title=""进入该文件夹"">进入该文件夹</a>"
          End If
      End If
      If ListPath(4, i) = "文件夹" Then
          IsFile = "<img src=""../images/icon/16/folder.png"" border=""0"" width=""16"" height=""16"" title="""& ListPath(0, i) &""" alt="""& ListPath(0, i) &""" />"
      Else
          IsFile = GetFileIcon("16", ListPath(0, i), ListPath(4, i))
      End If
  %>
  <tr align="center">
    <td align="left"><%=IsPic%></td>
    <td><%=IsFile%></td>
    <td><%=ListPath(1,i)%></td>
    <td><%=EditMemo%></td>
  </tr>
  <%
  Next
  %>
</table>
<%
End Sub

'==============================================================================
' 删除文件
'==============================================================================

Sub DelFile()
    ChkSysAdminLevel "sys_upload", "del"
    '=====================================================================
    Dim ThemePath, FileUrl, Result
    ThemePath = CmsTemplates & CmsTempSkin
    FileUrl = Trim(Easp.Get("f"))
    If Easp.IsN(FileUrl) Then
        CmsAdmin.JscriptMsg "缺少删除对象！", "back", "Error", "null"
    End If
    Easp.Use "Fso"
    If InStr(FileUrl, ThemePath) = 0 Then
        CmsAdmin.JscriptMsg "删除失败,无效的模版文件目录！", "back", "Error", "null"
    End If
    Result = Easp.Fso.DelFile(FileUrl)
    If Result Then
        CmsAdmin.JscriptMsg "删除文件："& FileUrl &"，成功！", Easp.IIf(Easp.IsN(CmsFun.LoadToUrl()), "Admin.Index.Asp", CmsFun.LoadToUrl()), "Success", "null"
    Else
        CmsAdmin.JscriptMsg "删除失败！", "back", "Error", "null"
    End If
End Sub

'=================================================
'函数名：GetFileIcon
'作  用：获取文件图标
'=================================================
Function GetFileIcon(ByVal fPath, ByVal fName, ByVal sTitle)
    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"" title="""& sTitle &""" alt="""& sTitle &""" />"
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

Function FileCode(ByVal Str)
    FileCode = Server.URLEncode(Str)
End Function
%>
