<!--#include file="Include/checklogin.asp"-->
<!--#include file="top.asp"-->
<link href="CSS/right.css" rel="stylesheet" type="text/css">
<%
Function IsObjInstalled(strClassString)
	On Error Resume Next
	IsObjInstalled = False
	Err = 0
	Dim xTestObj
	Set xTestObj = Server.CreateObject(strClassString)
	If 0 = Err Then IsObjInstalled = True
	Set xTestObj = Nothing
	Err = 0
End Function
dim path
dim uploadfolder
dim uploadfiles
dim upname
dim upfilename,sql,ServerObject
ServerObject = "Scripting.FileSystemObject"

dim sfor(30,2)
sFor(0,0)="txt":sFor(0,1)="txt"
sFor(1,0)="chm":sFor(1,1)="chm"
sFor(2,0)="hlp":sFor(2,1)="chm"
sFor(3,0)="doc":sFor(3,1)="doc"
sFor(4,0)="pdf":sFor(4,1)="pdf"
sFor(5,0)="gif":sFor(5,1)="gif"
sFor(6,0)="jpg":sFor(6,1)="jpg"
sFor(7,0)="png":sFor(7,1)="png"
sFor(8,0)="bmp":sFor(8,1)="bmp"
sFor(9,0)="asp":sFor(9,1)="asp"
sFor(10,0)="jsp":sFor(10,1)="asp"
sFor(11,0)="js" :sFor(11,1)="asp"
sFor(12,0)="htm":sFor(12,1)="html"
sFor(13,0)="html":sFor(13,1)="html"
sFor(14,0)="shtml":sFor(14,1)="html"
sFor(15,0)="zip":sFor(15,1)="zip"
sFor(16,0)="rar":sFor(16,1)="rar"
sFor(17,0)="exe":sFor(17,1)="exe"
sFor(18,0)="avi":sFor(18,1)="avi"
sFor(19,0)="mpg":sFor(19,1)="mpg"
sFor(20,0)="ra" :sFor(20,1)="ra"
sFor(21,0)="ram":sFor(21,1)="ra"
sFor(22,0)="mid":sFor(22,1)="mid"
sFor(23,0)="wav":sFor(23,1)="wav"
sFor(24,0)="mp3":sFor(24,1)="mp3"
sFor(25,0)="asf":sFor(25,1)="asf"
sFor(26,0)="php":sFor(26,1)="aspx"
sFor(27,0)="php3":sFor(27,1)="aspx"
sFor(28,0)="aspx":sFor(28,1)="aspx"
sFor(29,0)="xls":sFor(29,1)="xls"
sFor(30,0)="mdb":sFor(30,1)="mdb"
if IsObjInstalled(ServerObject) then
dim ObjFSO,SystemPath,ObjFolder,ObjParentFolder,ParentPath,ObjFile
 		Path=IsFolder(Request.QueryString("Path"))
 		SystemPath=IsFolder(server.MapPath("../"))
        set ObjFSO = Server.CreateObject("scripting.FileSystemObject")
		select case request("action")
         case "del"
		 response.Write("<script>if(confirm('是否删除该文件？')!=0);else history.back()</script>")
		 call DelFile()
		 case else
		 call normal()
		 end select		
         sub normal()
       if Path<>"\" then
 			if InStr(Path,SystemPath)=0 then
 				Path=IsFolder(server.MapPath(Path))
 			end if
 			if Len(Path)<Len(SystemPath) then
 			response.Write("<li>您无权限访问该目录！</li><li>访问路径越出系统路径！</li>")
 			end if
 			set ObjFolder=ObjFSO.GetFolder(Path)
 			set ObjParentFolder=ObjFolder.ParentFolder
 				ParentPath=ObjParentFolder.Path
 			set ObjParentFolder=nothing
 		else
 			set ObjFolder = ObjFSO.GetFolder(SystemPath)
 			Path=SystemPath
 			ParentPath=Path
 		end if
		call CheckFolder(ObjFolder)
        Response.Write "<form name=ActiveFrm id=ActiveFrm method=post><input type=hidden name=ParentPath value="&ParentPath&"></form>"
		end sub
else
		Response.Write "服务器不支持FSO！您无法使用该功能"
end if
sub CheckFolder(ObjFolder)
response.Write("<table border='0' align='center' cellpadding='3' cellspacing='1' class='tablecolor'><tr><td align='center' class='banner'>FSO文件管理</td></tr><tr><td class='tablebody'>&nbsp;注意：<br>&nbsp;本功能必须服务器支持FSO权限方能使用，FSO使用帮助请浏览微软网站。如果您服务器不支持FSO请手动管理。<br>")
		set ObjFile = ObjFolder.Files
		call ChildFolderList(ObjFolder)
dim pagesize,filenum, pagenum
pagesize=20
page=request.querystring("page")
if page="" or not isnumeric(page) then
	page=1
else
	page=int(page)
end if
response.Write("<table  border='0' align=center cellpadding='3' cellspacing='1' style='table-layout:fixed;word-break:break-all' class='tablecolor'><tr  align=center class='banner'><td width='6%'>类型</td><td>文件地址</td><td width='12%'>是否有记录</td><td width='10%'>大小</td><td width='18%'>最后访问</td><td width='18%'>上传日期</td><td width='6%'>管理</td></tr>")
'Set fso = Server.CreateObject("Scripting.FileSystemObject")
on error resume next
Set uploadFolder=ObjFolder
if err.number<>0 then
response.write "<tr><td colspan=7 class=tablebody align=center>"&Err.Description&"</td></tr>"
response.end
end if
Set uploadFiles=uploadFolder.Files

filenum=uploadfiles.count
pagenum=int(filenum/pagesize)
if filenum mod pagesize>0 then
	pagenum=pagenum+1
end if
if page> pagenum then
	page=1
end if

i=0
For Each Upname In uploadFiles
	i=i+1
	if i>(page-1)*pagesize and i<=page*pagesize then
		upfilename=upname.name
		'response.Write("<form method='post' action='?action=del'")
        response.write "<tr class=tablebody><td align=center><img src=""Images/files/"& procGetFormat(upname.name) &".gif"" border=0></td>"
		response.write "<td align=center>"&upfilename&"</td>"
		if instr(path,"pro")>0 then
		sql="select id from products where spic like '%"&upfilename&"%' or bpic like '%"&upfilename&"%'"
		elseif instr(path,"linkimg")>0 then
		sql="select id from img where imgurl like '%"&upfilename&"%'"
		elseif instr(path,"news")>0 then
		sql="select id from news where content like '%"&path&"/"&upfilename&"%'"
		else
		sql=""
		end if
		if sql<>"" then
		dim rs
		set rs=conn.execute(sql)
		if rs.bof or rs.eof then
		response.Write "<td align=center><font color=red>×</font></td>"
		else
		response.Write "<td align=center><font color=red>√</font></td>"
		end if
		rs.close
		set rs=nothing
		else
		response.Write "<td align=center><font color=red>重要文件</font></td>"
		end if
		response.write "<td align=center>"& upname.size &" B </td>"
		response.write "<td align=center>"& upname.datelastaccessed &"</td>"
		response.write "<td align=center>"& upname.datecreated &"</td>"
		response.write "<td align=center><a href='?action=del&filename="&path&""&upname.name&"&path="&path&"'>删除</a></td></tr>"
	elseif i>page*pagesize then
		exit for
	end if
next
set uploadFolder=nothing
set uploadFiles=nothing
response.Write("<tr><td height=25 colspan=7 align=center class='tablebody'>") 
if page>1 then
	response.write "<a href=?path="&path&"&page=1>首页</a>&nbsp;&nbsp;<a href=?path="&path&"&page="& page-1 &">上一页</a>&nbsp;&nbsp;"
else
	response.write "首页&nbsp;&nbsp;上一页&nbsp;&nbsp;"
end if
if page<i/pagesize then
	response.write "<a href=?path="&path&"&page="& page+1 &">下一页</a>&nbsp;&nbsp;<a href=?path="&path&"&page="& pagenum &">尾页</a>"
else
	response.write "下一页&nbsp;&nbsp;尾页"
end if

response.write " 共 "&filenum&" 个文件  "&_
		"</td></tr></table>"
end sub

'判断文件夹位置
Function IsFolder(Str)
 	if Right(Str,1)="\" or Str="./" or Str="../" then
	else
 		Str=Str&"\"
 	end if
 	IsFolder=Str
End Function

'判断文件类型
function procGetFormat(sName)
 dim i,str
 procGetFormat=0
 if instrRev(sName,".")=0 then exit function
 str=lcase(mid(sName,instrRev(sName,".")+1))
 for i=0 to uBound(sFor,1)
  if str=sFor(i,0) then 
    procGetFormat=sFor(i,1)
    exit for
  end if
 next
end function


'生成文件夹列表
Sub FolderTree(ChildFolder)
	dim CF
	dim FolderPath
	dim CCFolder
 	for Each CF in ChildFolder
 		FolderPath=Replace(CF.Path,SystemPath,"")
 		FolderPath=Replace(FolderPath,"\","/")
 		Response.Write "<option value=../"&FolderPath&">"&FolderPath&"</option>"
 		set CCFolder= CF.SubFolders
 		if CCFolder.count>0 then
 			Call FolderTree(CCFolder)
 		end if
 		set CCFolder=nothing
 	next
 End Sub
 '输出文件夹列表
 Sub ChildFolderList(ObjFolder)
	dim ObjChildFolder
 	set ObjChildFolder = ObjFolder.SubFolders
	response.Write(" <form name='form2' action='?'><tr><td class=tablebody>")
 	Response.Write "&nbsp;子文件夹：<select name='Path' style='width:160;' onchange="&chr(34)&"javascript:submit();"&chr(34)&">" & _
 				  "<option value='./'>./</option>"
 	call FolderTree(ObjChildFolder)
 	Response.Write "</select> <INPUT type='button' value='返回' onclick="&chr(34)&"javascript:history.go(-1);"&chr(34)&">"
	response.Write("</td></tr></form>")
 	set ObjChildFolder=nothing
 End Sub

'rem条件选择
Function IFS(Term,Opt1,Opt2)
   if TF(Term) then
	  IFS=Opt2
   elseif Term then
      IFS=Opt1
   else
      IFS=Opt2
   end if
End Function

Function TF(Obj)
	if IsArray(Obj) then
		TF=false
	elseif Obj="" or IsEmpty(Obj) or IsNull(Obj) then
		TF=true
	else
		TF=false
	end if
End Function
sub delfile()
response.Write("<table border='0' align='center' cellpadding='3' cellspacing='1' class='tablecolor'><tr><td align='center' class='banner'>FSO文件管理</td></tr><tr><td class='tablebody'>&nbsp;注意：<br>&nbsp;本功能必须服务器支持FSO权限方能使用，FSO使用帮助请浏览微软网站。如果您服务器不支持FSO请手动管理。</td>")
response.Write("<tr><td class=tablebody align='center'>")
      if ObjFSO.fileExists(request("filename")) then
        ObjFSO.DeleteFile(request("filename"))
		response.write "成功删除"&request("filename")&""
       else
        response.write "<script>alert('未找到"&path&request("filename")&"');history.back()</script>"
       end if
	   response.Write("<br><a href='admin_upload.asp?Path="&path&"'><font color=red>返回</font></a></td></tr</table>")
end sub
%>
<!--#include file="end.asp"-->