<!--#include file=../conn.asp-->
<!-- #include file="inc/const.asp" -->
<%Head()
dim admin_flag
dim objFSO
dim uploadfolder
dim uploadfiles
dim upname
dim usernames
dim userface
dim upfilename
	admin_flag=",33,"
	if not master or instr(","&session("flag")&",",admin_flag)=0 then
		Errmsg=ErrMsg + "<BR><li>本页面为管理员专用，请<a href=../"&LoginUrl&" target=_top>登录</a>后进入。<br><li>您没有管理本页面的权限。"
		Call Ms_error()
	end if
	Main(1)
		if Request("action")="list" then
		call search()
		elseif Request("action")="Toset" then
		call Toset()
		elseif Request("action")="viewal" then
		call viewal()
		end if
		Main(0)
		Footer()

sub main(Str)
if Str=1 then%>
<table width="95%" border="0" cellspacing="1" cellpadding="3"  align=center class="tableBorder">
<tr> 
<th height="23" colspan="7" class="tableHeaderText">文章日记上传管理中心</th>
</tr>
<tr>
<td height="25" class="forumrow" width = "18%">注意事项：</td>
<td height="25" colspan="6" class="forumrow">
1、本功能必须服务器支持FSO权限方能使用，FSO使用帮助请浏览微软网站。如果您服务器不支持FSO请手动管理。 <br>
2、新版（Love3.0）之后所有上传文件会自动存放到新自定义的文件夹中，文件目录以当年月明名。（需要空间支持ＦＳＯ读写权限） <br>
3、自动清理文件：将对所有上传文件进行核实，如发现文件没有被相关文章日记等所使用，将执行自动清除命令 <br>
4、文章日记上传默认目录是<%=SaveUpFilesPath%>Art_upload/下，以日期为文件目录的所有文件夹中。<br>
5、本系统列表将会读取服务器文件，将会占用系统资源。
</td>
</tr>
<%
	Else
%>
</table>
<p></p>
<%end if
end sub

sub search()
strFileName="Art_up.asp?action="&Request("action") & ""
call tumppages()
dim sql
sql = " Fid,Username,Filename,Viewname,FileType,FileSize,ViewNum,AddTime "
%>
<tr> 
<th height="23" colspan="7" class="tableHeaderText">搜索结果</th>
</tr>
<FORM METHOD=POST ACTION="?action=Toset">
<tr align=center height=23>
<td class=forumRowHighlight width="16%"><B>用户名</B></td>
<td class=forumRowHighlight width="7%"><B>属性</B></td>
<td class=forumRowHighlight width="38%"><B>图片</B></td>
<td class=forumRowHighlight width="8%"><B>大小</B></td>
<td class=forumRowHighlight width="17%"><B>上传时间</B></td>
<td class=forumRowHighlight width="6%"><B>人气</B></td>
<td class=forumRowHighlight><B>操作</B></td>
</tr>
<%set rs=server.createobject("adodb.recordset")
		Sql = "SELECT " & sql & " from Ms_Upfile where Typeid=3 ORDER BY FID DESC"
		rs.Open sql,conn,1,1
if not (rs.eof and rs.bof) then
call rspages()
do while not rs.eof and page_count<Cint(MaxPerPage)%>
<tr align=center height=23>
<td class=forumrow width="16%"><a href="admin_user.asp?action=modify&username=<%=rs(1)%>"><%=rs(1)%></a></td>
    <td class=forumrow width="7%"><img src="../images/files/<%=rs(4)%>.gif" border=0></td>
    <td class=forumrow width="38%" align="left">
	<%response.write("<a href=""?action=viewal&id="&rs(0)&""" Title=""查看图片"">")
	response.write(rs(3)&"</a>")%></td>
<td class=forumrow width="8%"><%=rs(5)%></td>
<td class=forumrow width="17%"><%=rs(7)%></td>
<td class=forumrow width="6%"><%=rs(6)%></td>
<td class=forumrow><input type="checkbox" name="id" value="<%=rs(0)%>"></td>
</tr>
<%page_count=page_count+1
  rs.movenext
  loop
  else
  response.Write("<tr><td colspan=7 class=forumrow>暂时数据。</td></tr>")
  end if
  if totalrec>0 then%>
<tr align="center"> 
      <td height="24" colspan="7" class=forumrow><%
		  	call showpage(strFileName)
		  %></td>
    </tr>
	<%end if%>
<tr align="center"> 
      <td height="24" colspan="7" class=forumrow align="right"><input type="radio" name="paction" value="1">删除文件
	  <input type="radio" name="paction" value="2">删除未完成记录
	  <input type="radio" name="paction" value=3>清理目录中未记录文件
	  <select name="Pset">
	  <option value="">选择目录</option>
	  <%
Dim uploadpath,ii
for ii=0 to datediff("m","2005-1",now())
uploadpath=DateAdd("m",-ii,now())
uploadpath=year(uploadpath)&"-"&month(uploadpath)
response.write "<option value="""&uploadpath&""">"&uploadpath&"</option>"
next
%>
	  </select>
	  
全部选定<input type=checkbox value="on" name="chkall" onclick="CheckAll(this.form)"></td>
    </tr>
	<tr align="center"> 
      <td height="24" colspan="7" class=forumRowHighlight><input type=submit name=submit value="执行操作"  onclick="{if(confirm('确定执行操作吗?')){return true;}return false;}"></td>
    </tr>
</form>
<%end sub

sub Toset()''批量执行操作
dim delid,fixid,objFSO,path,delfile,i,D_Filename,D_Viewname
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
response.write "<tr><th colspan=7 height=23 align=left>执行结果</th></tr>"
	if request("paction")="" then
		response.write "<tr><td colspan=7 class=forumrow>请指定相关参数。</td></tr>"
		founderr=true
	end if
	delid=replace(request.form("id"),"'","")
	delid=replace(delid,";","")
	delid=replace(delid,"--","")
	delid=replace(delid,")","")
	fixid=replace(delid,",","")
	fixid=Trim(replace(fixid," ",""))
if not founderr then
		if request("paction")=1 then''删除文件操作
			set rs=Conn.Execute("select Fid,Filename,Viewname from Ms_Upfile where Fid in ("&delid&")")
				if not (rs.eof and rs.bof) then
				i=0
					do while not rs.eof
					i=i+1
						D_Filename=rs(1)
						D_Viewname=rs(2)
						if objFSO.fileExists(Server.MapPath("../"&SaveUpFilesPath&D_Filename)) then
							objFSO.DeleteFile(Server.MapPath("../"&SaveUpFilesPath&D_Filename))
						End if
						if objFSO.fileExists(Server.MapPath("../"&UpfilePreview&D_Viewname)) then
							objFSO.DeleteFile(Server.MapPath("../"&UpfilePreview&D_Viewname))
						End if
						Conn.Execute("delete from Ms_Upfile where Fid="&rs(0)&"")
					rs.movenext
					loop
					else
					response.write "<tr><td colspan=7 class=forumrow>不存在记录。</td></tr>"
				end if
				rs.close
				response.write "<tr><td colspan=7 class=forumrow>删除成功，本次操作共删除"&i&"个文件。</td></tr>"
		elseif request("paction")=2 then''删除未完成记录
		set rs=Conn.Execute("select Fid,Filename,Viewname from Ms_Upfile where Typeid=3")
			if not (rs.eof and rs.bof) then
			i=0
					do while not rs.eof
					i=i+1
						D_Filename=rs(1)
						D_Viewname=rs(2)
						if objFSO.fileExists(Server.MapPath("../"&SaveUpFilesPath&D_Filename)) then
							objFSO.DeleteFile(Server.MapPath("../"&SaveUpFilesPath&D_Filename))
						End if
						if objFSO.fileExists(Server.MapPath("../"&UpfilePreview&D_Viewname)) then
							objFSO.DeleteFile(Server.MapPath("../"&UpfilePreview&D_Viewname))
						End if
						Conn.Execute("delete from Ms_Upfile where Fid="&rs(0)&"")
					rs.movenext
					loop
					response.write "<tr><td colspan=8 class=forumrow>删除成功，本次操作共删除"&i&"个文件。</td></tr>"
					else
					response.write "<tr><td colspan=8 class=forumrow>没有未完成记录。</td></tr>"
				end if
				rs.close
		elseif request("paction")=3 then''清除目录未记录文件
		dim paths,delprefile
		path=SaveUpFilesPath&"Art_upload/"&request("Pset")&"/"
		paths="Art_upload/"&request("Pset")&"/"
			Set uploadFolder = objFSO.GetFolder(Server.MapPath("../"&path))
			Set uploadFiles = uploadFolder.Files
			i=0
			For Each Upname In uploadFiles
			upfilename = paths&upname.name
			delfile= path&upname.name
			delprefile=UpfilePreview&"Art_upload/"&request("Pset")&"/Pre"&upname.name
			set rs = conn.Execute("select top 1 Fid from Ms_Upfile where Filename = '"&upfilename&"'")
			if rs.eof then
				i=i+1
				objFSO.DeleteFile(Server.MapPath("../"&delfile))''删除大图
				objFSO.DeleteFile(Server.MapPath("../"&delprefile))''删除预览图
			end if
			rs.close
			set rs=nothing
			next
			response.write"共删除　"&i&"　个无用文件 ［<a href=?action=list >返回</a>］"
		set uploadFolder=nothing
		set uploadFiles=nothing
		else
			response.write "<tr><td colspan=8 class=forumrow>错误的参数。</td></tr>"	
		end if
	end if
	set objFSO=nothing
end sub

sub viewal()
sql="select Username,Filename,FileType,FileSize from [Ms_Upfile] where Fid="&request("id")&""
		set rs=conn.execute(Sql)
		if not (rs.eof and rs.bof) then%>
<tr><th colspan=7 height=23 align=center><%=rs(0)%> 上传的图片</th></tr>
<tr>
<td width=80% class=forumrow colspan=7 align=center>
<%
response.write("<img src=../"&SaveUpFilesPath&""&rs(1)&" border=0 onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333"">")
%>
</td>
</tr>
<tr>
<td width=20% class=forumrow align=right>文件格式</td>
<td width=80% class=forumrow colspan=6><img src="../images/files/<%=rs(2)%>.gif" border=0></td>
</tr>
<tr>
<td width=20% class=forumrow align=right>文件大小</td>
<td width=80% class=forumrow colspan=6><%=rs(3)%>
</td>
</tr>
<%end if
rs.close
end sub%>