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

<%sub search()''搜索列表
strFileName="Face_up.asp?action="&Request("action") & ""
call tumppages()
dim sql
sql = " Userid,Username,UserFace "
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
%>
<tr> 
<th height="23" colspan="6" class="tableHeaderText" align="left">所有上传头像列表</th>
</tr>
<FORM METHOD=POST ACTION="?action=ToSet">
<tr align = center>
<td width = "18%" class=forumRowHighlight>所属用户</td>
<td width = "40%" height = 25 class=forumRowHighlight>文件名</td> 
<td width = "8%" class=forumRowHighlight>大小</td>
<td width = "11%" class=forumRowHighlight>最后访问</td>
<td width = "17%" class=forumRowHighlight>上传日期</td>
<td class=forumRowHighlight>管理</td>
</tr>
<%set rs=server.createobject("adodb.recordset")
	Sql = "SELECT " & sql & " from Ms_user where left(UserFace,2)='Up' or left(UserFace,2)='Pr' ORDER BY userID 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>
<td width = "18%" class=forumrow><a href="admin_user.asp?action=modify&username=<%=rs(1)%>"><%=rs(1)%></a></td>
<td width = "40%" height=25 class=forumrow align="left"><a href=../<%=rs(2)%>><%=rs(2)%></a></td> 
<%upfilename=server.mappath("../"&rs(2))		 		
	set upname=objFSO.getfile(upfilename)%>
<td width = "8%" class=forumrow><%=upname.size%></td>
<td width = "11%" class=forumrow><%=upname.datelastaccessed%></td>
<td width = "17%" class=forumrow><%=upname.datecreated%></td>
<td class=forumrow><input type="checkbox" name="id" value="<%=rs("userid")%>"></td>
</tr>
<%page_count=page_count+1
  rs.movenext
  loop
  end if
  %>
    <tr align="center"> 
      <td height="24" colspan="8" class=forumrow> <%if totalrec>0 then
		  	call showpage(strFileName)
		  end if%></td>
    </tr>
<tr align="center"> 
      <td height="24" colspan="8" class=forumrow><input type="radio" name="paction" value=1>删除选定文件
	  <input type="radio" name="paction" value=2>清理目录中未记录文件
	  <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="8" 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,Pathpre
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
response.write "<tr><th colspan=8 height=23 align=left>执行结果</th></tr>"
	if request("paction")="" then
		response.write "<tr><td colspan=8 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''删除文件操作
		dim Uface,splitf,delUplpath
			set rs=Conn.Execute("select Userid,Userface from Ms_user where userid in ("&delid&")")
				if not (rs.eof and rs.bof) then
				do while not rs.eof
				Uface=rs(0)
				if Uface<>"" and left(Uface,2)="Up" then
					if objFSO.fileExists(Server.MapPath("../"&Uface)) then
						objFSO.DeleteFile(Server.MapPath("../"&Uface))
					End if
				elseif left(Uface,2)="Pr" then''有预览必须清除大图
					if objFSO.fileExists(Server.MapPath("../"&Uface)) then
						objFSO.DeleteFile(Server.MapPath("../"&Uface))
					End if
					splitf=split(Uface,"/")
					delUplpath="../"&SaveUpFilesPath&splitf(1)&"/"&mid(splitf(2),4,len(splitf(2)))
					if objFSO.fileExists(Server.MapPath(delUplpath)) then''删除大图
						objFSO.DeleteFile(Server.MapPath(delUplpath))
					End if
				end if
				Conn.Execute("update [Ms_user] set Userface='' where userid="&rs(0)&"")
				Conn.Execute("Delete from Ms_upfile where Typeid=1 and Filename='"&Uface&"'")
				rs.movenext
				loop
				end if
				rs.close
				response.write "<tr><td colspan=8 class=forumrow>删除文件成功。</td></tr>"
		elseif request("paction")=2 then''清理目录中未记录文件 
			path=SaveUpFilesPath&"Fac_upload/"&request("Pset")&"/"
			Pathpre=UpfilePreview&"Fac_upload/"&request("Pset")&"/"
			Set uploadFolder = objFSO.GetFolder(Server.MapPath("../"&path))
			Set uploadFiles = uploadFolder.Files
			i=0
			For Each Upname In uploadFiles
			upfilename = path&upname.name
			set rs = conn.Execute("select top 1 Userid from [Ms_user] where userface = '"&upfilename&"'")
			if rs.eof then
				i=i+1
				objFSO.DeleteFile(Server.MapPath("../"&upfilename))
				objFSO.DeleteFile(Server.MapPath("../"&Pathpre&"Pre"&upname.name))
			end if
			rs.close
			set rs=nothing
			Conn.Execute("Delete from Ms_upfile where Typeid=1 and Filename='"&upfilename&"'")
			next
			response.write"共删除　"&i&"　个无用文件 ［<a href=?action=list >返回</a>］"
		set uploadFolder=nothing
		set uploadFiles=nothing
		end if
	end if
	set objFSO=nothing
end sub%>