<%@ language=VBScript CODEPAGE=936%>
<%
Option Explicit
response.buffer= True
%>
<!--#include file = "../Conn.asp"-->
<!--#include file = "../Inc/Cl_ClsSysTem.asp"-->
<!--#include file = "../Inc/Cl_FileIcon.asp"-->
<%
Cl.GetWeb_Setting()
if Not Cl.ChkUserLogin then
	Cl.OutErr("<br /><li>您无此操作权限！</li>")
end if
if Cl.UserLevel>1 then
	Response.write "对不起，此功能只对管理员开放！"
	Response.end
end if
Const MaxPerPage=30
Dim FileType,TopDir,action
Dim Fso,FsoFile,AllFileSize
Dim ThisDir,DirFiles,DirFolder,strTitle
dim TotalPut,CurrentPage,TotalPages
Dim ChannelID,strFileName,sTrSetting
action=LCase(Trim(Request("action")))
ThisDir=Trim(Request("ThisDir"))
ChannelID=Trim(Request("CID"))
FileType=LCase(Trim(Request("Type")))
CurrentPage=Trim(request("page"))
if Not IsNumeric(ChannelID) then
	Response.write "错误，频道ID无效！"
	Response.end
end if
Cl.GetChannelSetting(ChannelID)
sTrSetting=Split(Cl.Channel_Setting(22),"@")
if Not IsNumeric(CurrentPage) then CurrentPage=1
CurrentPage=Clng(CurrentPage)
strFileName="SelFiles.asp?CID=" & ChannelID & "&Type=" & FileType
if Not Cl.ChkAdminLogin then
	TopDir=Cl.UploadDir&"/"&sTrSetting(1)
	TopDir=Replace(TopDir & "/","//","/")
else
	TopDir=Cl.UploadDir
end if
strTitle="选择文件"
if ThisDir<>"" then
	ThisDir=Replace(ThisDir & "/","//","/")
end if

Call Main()

Sub Main()
	On Error Resume Next
	Set Fso=Server.CreateObject(Trim(Cl.Web_Info(13)))
	Set FsoFile = Fso.GetFolder(Server.MapPath(TopDir))
		if Err or TopDir="/" then
			Set	FsoFile = Nothing
			Response.write "找不到目录，可能参数配置错误！"
			Response.end
		end if
		AllFileSize = FsoFile.size
	Set	FsoFile = Nothing
	Set	FsoFile = Fso.GetFolder(Server.MapPath(TopDir & ThisDir))
	Dim FolderNuns,FileNums
	FolderNuns=FsoFile.SubFolders.count
	FileNums=FsoFile.Files.count
	TotalPut=FolderNuns+FileNums
   	if (TotalPut mod MaxPerPage)=0 then
    	TotalPages = TotalPut \ MaxPerPage
	else
	  	TotalPages = TotalPut \ MaxPerPage + 1
	end if
	if CurrentPage > TotalPages then CurrentPage=TotalPages
	if CurrentPage < 1 then CurrentPage=1
%>
<html>
<head>
<title><%=strTitle%>管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../Skins/Admin_Style.Css" rel="stylesheet" type="text/css">
<base target='_self'>
</head>
<body leftmargin="0" topmargin="0">
<table border="0" cellspacing="1" cellpadding="0" align="center" class="Border">
 <tr class="Title"> 
  <td align="center" colspan="2"><B><%=strTitle%>管理</B></td>
 </tr>
 <tr class="Title2" height=23> 
  <td>主&nbsp;目&nbsp;录：<a href="<%=strFileName%>&ThisDir=" title=返回到主目录><font color=FF0000>主目录/<%'=TopDir%></font></a></td><td align="right"><a href="<%=strFileName%>&ThisDir=<%=GetUpDir%>"><font color=FF0000>↑上一目录</font></a> &nbsp;&nbsp;<a href="<%=strFileName%>&ThisDir=" title=返回到主目录><font color=FF0000>主目录</font></a></td>
 </tr>
 <tr class="Tdbg" height=23> 
  <td colspan="2">当前目录：主目录/<%=ThisDir%>&nbsp;&nbsp;&nbsp;&nbsp;文件夹：<font color=blue><%=FolderNuns%></font>&nbsp;个，文件：<font color=blue><%=FileNums%></font>&nbsp;个</td>
 </tr>
</table>
<br />
<%
if action="view" then
	ViewFiles
else
	SelectFiles
end if
%>
</body>
</html>
<%
Set FsoFile = Nothing
Set Fso = Nothing
End Sub

Function GetUpDir()
	Dim strDir,strDir2,i
	strDir=""
	If ThisDir = "" then Exit Function
	strDir2=ThisDir
	strDir2=Split(strDir2,"/")
	for i=0 to Ubound(strDir2)-1
		if i<Ubound(strDir2)-1 then strDir=strDir & strDir2(i) & "/"
	next
	GetUpDir=strDir
End Function

Function GetFileUrl(strUrl)
	dim strSaveUrl
	strSaveUrl=Trim(strUrl)
	if Lcase(left(strSaveUrl,Len(Cl.UpLoadDir)))=Lcase(Cl.UpLoadDir) then
		strSaveUrl="{%uploaddir%}" & mid(strSaveUrl,Len(Cl.UpLoadDir)+1) 
	elseif left(strSaveUrl,1)="/" then
		strSaveUrl="{%webdir%}" & mid(strSaveUrl,2)
	end if
	GetFileUrl=strSaveUrl
End Function

Sub SelectFiles()
	Dim j,k
	j=0
%>
<table border="0" cellspacing="1" cellpadding="0" align="center" class="Border">
	<form name="form" method="post" >
	 <tr class="title">
	  <td width="*" align="center">文件/文件夹名</td>
	  <td width="80" align="center">文件大小</td>
	  <td width="120" align="center">修改时间</td>
	  <td width="80" align="center">可用操作</td>
	 </tr>
	 <%
	For Each DirFolder in FsoFile.SubFolders%>
	 <tr class="tdbg"> 
	  <td width="*">&nbsp;<a href="<%=strFileName%>&ThisDir=<%=ThisDir & DirFolder.name%>"><img src="<%=Cl.WebDir%>images/fileicon/folder.gif" border=0 width="16" height="16" align="absmiddle"></a>&nbsp;<a href="<%=strFileName%>&ThisDir=<%=ThisDir & DirFolder.name%>"><%=DirFolder.name%></a></td>
	  <td align="center" width="80"><%=Cl.GetSize(DirFolder.size,"b")%></td>
	  <td align="center" width="120">&nbsp;<%=DirFolder.DateLastModified%></td>
	  <td align="center" width="80"><a href="<%=strFileName%>&ThisDir=<%=ThisDir & DirFolder.name%>">打开</a></td>
	 </tr>
	 <%
	Next

	For Each DirFiles in FsoFile.Files
	k=k+1
	if j>=MaxPerPage then
		exit for
	elseif k>MaxPerPage*(CurrentPage-1) then
	%>
	 <tr class="tdbg"> 
	  <td width="*">&nbsp;
	  <a href="#" onClick="window.returnValue='<%=TopDir & ThisDir & DirFiles.name%>|<%=int(DirFiles.size/1000)%>';window.close();">
	  <img src="<%=Cl.WebDir%>images/fileicon/<%=GetFileIcon(DirFiles.name)%>" border=0 width="16" height="16" align="absmiddle" alt="<%=DirFiles.type%>">&nbsp;<%=DirFiles.name%></a></td>
	  <td align="center" width="80"><%=Cl.GetSize(DirFiles.size,"b")%></td>
	  <td align="center" width="120"><%=DirFiles.DateLastModified%></td>
	  <td align="center" width="80">
	  <a href="#" onClick="window.returnValue='<%=TopDir & ThisDir & DirFiles.name%>|<%=int(DirFiles.size/1000)%>';window.close();">选择</a> | <a href="<%=strFileName%>&action=View&name=<%=DirFiles.name%>&ThisDir=<%=ThisDir%>">查看</a>
	  </td>
	 </tr>
	 <%
	j=j+1
	end if
	Next
	%>
	<tr class="tdbg"> 
	  <td width="100%" align="center" colspan="4"> 
		<%=Cl.ShowPage(strFileName&"&ThisDir="&ThisDir,TotalPut,MaxPerPage,"个","文件")%>
	   </td>
	 </tr> 
	</form>
</table>
<%
End Sub

Sub ViewFiles()
	Dim sName,sFileExt,sUrl,s
	sName=Trim(Request("Name"))
	sFileExt = Lcase(Mid(sName, InstrRev(sName, ".") + 1))
	'Response.write Server.MapPath(TopDir & ThisDir & sName)
	Set DirFiles = Fso.GetFile(Server.MapPath(TopDir & ThisDir & sName))
%>
<table border="0" cellspacing="1" cellpadding="0" align="center" class="Border">
	<tr class="tdbg">
		<td rowspan=5 align="center" width=200>
		<a href="#" onClick="window.returnValue='<%=TopDir & ThisDir & DirFiles.name%>|<%=int(DirFiles.size/1000)%>';window.close();">
		<%
		select case sFileExt
		case "jpg","gif","bmp","png"
			sUrl=TopDir & ThisDir & DirFiles.name
		case "swf"
			sUrl="../Images/FileIcon/b_flash.gif"
		case "wmv","avi","asf","mpg"
			sUrl="../Images/FileIcon/b_media.gif"
		case "rm","ra","ram"
			sUrl="../Images/FileIcon/b_rm.gif"
		case "rar"
			sUrl="../Images/FileIcon/b_rar.gif"
		case "zip"
			sUrl="../Images/FileIcon/b_zip.gif"
		case "exe"
			sUrl="../Images/FileIcon/b_exe.gif"
		case else
			sUrl="../Images/FileIcon/b_other.gif"
		end select
		response.write "<img src='" & sUrl & "' width='200' border='0' title='点此图片将选中！'></a>"
		  %>
		</td>
		<td align="right" width=100>文 件 名：</td>
		<td><a href="<%=TopDir & ThisDir & DirFiles.name%>" target="_blank"><%=DirFiles.name%></a></td>
	</tr>
	<tr class="tdbg">
		<td align="right" width=100>文件大小：</td>
		<td><%=Cl.GetSize(DirFiles.size,"b")%></td>
	</tr>
	<tr class="tdbg">
		<td align="right" width=100>文件类型：</td>
		<td><%=DirFiles.type%></td>
	</tr>
	<tr class="tdbg">
		<td align="right" width=100>修改时间：</td>
		<td><%=DirFiles.DateLastModified%></td>
	</tr>
	<tr class="tdbg">
		<td align="right" width=100>可用操作：</td>
		<td><a href="#" onClick="window.returnValue='<%=TopDir & ThisDir & DirFiles.name%>|<%=int(DirFiles.size/1000)%>';window.close();">选中</a> | <a href="<%=strFileName%>&ThisDir=<%=ThisDir%>">返回</a></td>
	</tr>
</table>
<%
End Sub
%>