<!--#include file="user_top.asp"-->
<!--#include file="inc/class_blog.asp"-->
<div id="main">
  <div class="submenu">
  	<div class="side_c1 side11"></div>
    <div class="side_c2 side21"></div>
	<div class="submenu_content">
		&#8226; <a href='user_files.asp'>所有文件</a>
		&#8226; <a href='user_files.asp?usersearch=1'>图片文件<%If C_User_ViewUploadFiles=1 Then Response.Write "(可预览)"%></a>
		&#8226; <a href='user_files.asp?usersearch=2'>压缩文件</a>
		&#8226; <a href='user_files.asp?usersearch=3'>文档文件</a>
		&#8226; <a href='user_files.asp?usersearch=4'>媒体文件</a>
		
	</div>
  </div>
  <div class="content">
  	<div class="content_top">
		  	<div class="side_d1 side11"></div>
		    <div class="side_d2 side21"></div>
			文件及相册管理
	</div>
	
    <div class="content_body">
<%const MaxPerPage=24
dim strFileName,totalPut,TotalPages
dim rs, sql,action
dim id,usersearch,Keyword,strField
keyword=trim(request("keyword"))
if keyword<>"" then 
	keyword=oblog.filt_badstr(keyword)
end if
strField=trim(request("Field"))
usersearch=trim(request("usersearch"))
action=trim(request("action"))
id=oblog.filt_badstr(trim(Request("id")))
if usersearch="" then
	usersearch=0
else
	usersearch=Clng(usersearch)
end if
strFileName="user_files.asp?usersearch=" & usersearch
if request("page")<>"" then
    currentPage=cint(request("page"))
else
	currentPage=1
end if
select case action
	case "modifyphoto"
	call modify()
	case "savemodify"
	call Savemodify()
	case "delfile" 
	call delfile()
	case else
	call main()
end select
set rs=nothing
%>
	</div>
	
    <div class="content_bot">
		  	<div class="side_e1 side12"></div>
   			<div class="side_e2 side22"></div>
 	</div>
	
  </div>
</div>  
  
  
  <div id="bottom"><%=oblog.user_copyright%></div>

</body>
</html>
<%
sub main()
	dim strGuide,ssql
	ssql="userid,file_name,file_path,file_size,fileid,file_readme,file_ext,isphoto,logid"
	strGuide="<h1>当前文件类型&nbsp;&gt;&gt;&nbsp;"
	select case usersearch
		case 0
			if oblog.logined_ulevel=9 then
				sql="select top 500 "&ssql&" from [oblog_upfile] order by fileid desc"
			else
				sql="select "&ssql&" from [oblog_upfile] where userid="&oblog.logined_uid&" order by fileid desc"
			end if
			strGuide=strGuide & "所有文件"
		case 1
			if oblog.logined_ulevel=9 then
				sql="select top 500 "&ssql&" from [oblog_upfile] where file_ext='gif' or file_ext='jpg' or file_ext='bmp' or file_ext='png' or file_ext='psd' or file_ext='pcx' order by fileid desc"
			else
				sql="select "&ssql&" from [oblog_upfile] where userid="&oblog.logined_uid&" and ( file_ext='gif' or file_ext='jpg' or file_ext='bmp' or file_ext='png' or file_ext='psd' or file_ext='pcx' ) order by fileid desc"
			end if
			strGuide=strGuide & "图片文件"
		case 2
			if oblog.logined_ulevel=9 then
				sql="select top 500 "&ssql&" from [oblog_upfile] where file_ext='rar' or file_ext='zip' or file_ext='arj' or file_ext='sit' order by fileid desc"
			else
				sql="select "&ssql&" from [oblog_upfile] where userid="&oblog.logined_uid&" and ( file_ext='rar' or file_ext='zip' or file_ext='arj' or file_ext='sit') order by fileid desc"
			end if
			strGuide=strGuide & "压缩文件"
		case 3
			if oblog.logined_ulevel=9 then
				sql="select top 500 "&ssql&" from [oblog_upfile] where file_ext='doc' or file_ext='xsl' or file_ext='txt' order by fileid desc"
			else
				sql="select "&ssql&" from [oblog_upfile] where userid="&oblog.logined_uid&" and ( file_ext='doc' or file_ext='xsl' or file_ext='txt') order by fileid desc"
			end if
			strGuide=strGuide & "文档文件"
		case 4
			if oblog.logined_ulevel=9 then
				sql="select top 500 "&ssql&" from [oblog_upfile] where  file_ext='mp3' or file_ext='wmv' or file_ext='wma' or file_ext='rm' or file_ext='swf' order by fileid desc"
			else
				sql="select "&ssql&" from [oblog_upfile] where userid="&oblog.logined_uid&" and ( file_ext='mp3' or file_ext='wmv' or file_ext='wma' or file_ext='rm' or file_ext='swf') order by fileid desc"
			end if
			strGuide=strGuide & "媒体文件"
		case 5
			if oblog.logined_ulevel=9 then
				sql="select top 500 "&ssql&" from [oblog_upfile] where isphoto=1 order by fileid desc"
			else
				sql="select "&ssql&" from [oblog_upfile] where userid="&oblog.logined_uid&" and isphoto=1 order by fileid desc"
			end if
			strGuide=strGuide & "相册"
		case else
	end select
	'strGuide=strGuide & "</td><td align='right'>"
	Set rs=Server.CreateObject("Adodb.RecordSet")
	'response.Write(sql)
	rs.Open sql,Conn,1,1
  	if rs.eof and rs.bof then
		strGuide=strGuide & " (共有0个文件)</h1><div id=""list"">"
		response.write strGuide
		showContent
	else
    	totalPut=rs.recordcount
		strGuide=strGuide & " (共有" & totalPut & "个文件)</form></h1><div id=""list"">"
		response.write strGuide
		if currentpage<1 then
       		currentpage=1
    	end if
    	if (currentpage-1)*MaxPerPage>totalput then
	   		if (totalPut mod MaxPerPage)=0 then
	     		currentpage= totalPut \ MaxPerPage
		  	else
		      	currentpage= totalPut \ MaxPerPage + 1
	   		end if
    	end if
	    if currentPage=1 then
        	showContent
        	response.write oblog.showpage(strFileName,totalput,MaxPerPage,true,true,"个文件")
   	 	else
   	     	if (currentPage-1)*MaxPerPage<totalPut then
         	   	rs.move  (currentPage-1)*MaxPerPage
         		dim bookmark
           		bookmark=rs.bookmark
            	showContent
            	response.write oblog.showpage(strFileName,totalput,MaxPerPage,true,true,"个文件")
        	else
	        	currentPage=1
           		showContent
           		response.write oblog.showpage(strFileName,totalput,MaxPerPage,true,true,"个文件")
	    	end if
		end if
	end if
	rs.Close
	set rs=Nothing
end sub

sub showContent()
   	dim i,n,ext
    i=0
	dim freesize,maxsize
	select case oblog.logined_ulevel
		case 7
		maxsize=oblog.setup(36,0)
		case 8
		maxsize=oblog.setup(40,0)
		case 9
		maxsize=oblog.setup(44,0)
	end select
	if  oblog.logined_uupfilemax>0 then	maxsize=oblog.logined_uupfilemax
	maxsize=maxsize*1024
	freesize=int(maxsize-oblog.logined_uupfilesize)

%>
	
   <div class="list_left">
   <form name="myform1" method="post" action="user_files.asp">
   <select size=1 name='usersearch' onChange='javascript:submit()'>
	<option value=10 selected>请选择文件类型</option> 
	<option value=0>列出所有文件</option>
	<option value=1>图片文件<%If C_User_ViewUploadFiles=1 Then Response.Write "(可预览)"%></option>
	<option value=2>压缩文件</option> 
	<option value=3>文档文件</option> 
	<option value=4>媒体文件</option>
	<option value=5>相册照片</option>           
	</select>
	</form>
	<img align=absmiddle src='images/touming.gif' border="1" width='10' height='10' style='background:#cccccc;'>&nbsp;已用空间:<%=oblog.showsize(oblog.logined_uupfilesize)%><br />
	<img align=absmiddle src='images/touming.gif' border="1" width='10' height='10' style='background:#ffffff;'>&nbsp;可用空间:<%=oblog.showsize(freesize)%><br />
	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="150" height="150">
	<param name=movie value="images/chart.swf?in6=<%=int((freesize/maxsize)*100)%>&in6=<%=int((oblog.logined_uupfilesize/maxsize)*100)%>">
	<param name=quality value=high>
	<param name="wmode" value="transparent">
	<embed src="images/chart.swf?in6=<%=int((freesize/maxsize)*100)%>&in6=<%=int(((maxsize-freesize)/maxsize)*100)%>" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="150">
	</embed> </object>
	</div>
    <div class="list_right"><iframe id=d_file frameborder=0 src="upload.asp?re=no" width="100%" height="30" scrolling=no></iframe><hr>
	<form name="myform" method="post" action="user_files.asp" onSubmit="return confirm('确定要删除选定的文件吗？');">
    <% do while not rs.eof 
		ext=rs("file_ext")%>
	<div class="filepic">
		<div class="fileimg">
			<a href='<%=rs("file_path")%>' target=_blank>
				<%
				if rs("isphoto")=1 then 
					If C_User_ViewUploadfiles=1 And (usersearch=1 OR usersearch=5 )Then
						response.Write("<img src="""&rs("file_path")&""" width=100 height=100 class=""fileimg"" alt=""相册文件"" />") 
					Else
						response.Write("<img src=""images/filetype/photo.gif"" class=""fileimg"" alt=""相册文件"" />") 
					End If
				else 
					Response.Write showfilepic(rs("file_ext"),rs("file_path"))
				End If
				%>
				</a></div>
	<span class="en"><%=oblog.showsize(rs("file_size"))%></span><br />
	<a href="user_files.asp?action=delfile&id=<%=rs("fileid")%>" onClick="return confirm('确定要删除这个文件吗？');">删除</a><br/>
<%
'-----------------------------------
'ATFLAG
if  (ext="jpg" or ext="gif" or ext="pcx" or ext="bmp" or ext="png" or ext="psd") and en_photo=1 then
	if rs("isphoto")=0 then
		response.Write("<a href=""user_post.asp?t=1&photofile="&rs("file_path")&""">加入相册</a>")
	else
		response.Write("<a href=""user_post.asp?logid="&rs("logid")&"&t=1"">修改相片</a>")
	end if
end if
'-----------------------------------
%>
	<br /><input name='id' type='checkbox' onClick="unselectall()" id="id" value='<%=cstr(rs("fileid"))%>'><span class="en"><%="<a href="&rs("file_path")&" target=_blank>"&rs("file_name")&"</a>"%></span>
	</div>
<%  
	i=i+1
	If i Mod 6= 0 Then Response.Write "<div class=""width:100%""><hr width=100% size=0></div>"
	if i>=MaxPerPage then exit do
	rs.movenext
loop
%>
	<ul class="list_bot"> <input name="chkAll" type="checkbox" id="chkAll" onClick=CheckAll(this.form) value="checkbox" />全选
	<input name="action"  type="hidden" value="delfile" />
	<input type="submit" name="Submit" value="删除选定的文件" />
	</ul>
	</form>
  </div>  
 </div>
<%
end sub

function showfilepic(ext,filepath)
	Dim sReturn
	ext=lcase(ext)
	Select Case ext
		Case "jpg" 
			sReturn="<img src=""images/filetype/jpg.gif"" class=""fileimg"" alt=""JPG文件"" />"
		Case "gif"
			sReturn="<img src=""images/filetype/gif.gif"" class=""fileimg"" alt=""GIF文件"" />"
		Case "bmp" 
			sReturn="<img src=""images/filetype/bmp.gif"" class=""fileimg"" alt=""BMP文件"" />"
		Case "png" 
			sReturn="<img src=""images/filetype/png.gif"" class=""fileimg"" alt=""PNG文件"" />"
		Case "psd" 
			sReturn="<img src=""images/filetype/psd.gif"" class=""fileimg"" alt=""PSD文件"" />"
		Case "rar" ,"zip","arj","sit" 
			sReturn="<img src=""images/filetype/rar.gif"" class=""fileimg"" alt=""压缩文件"" />"
		Case "xsl" 
			sReturn="<img src=""images/filetype/excel.gif"" class=""fileimg"" alt=""Excel文件"" />"
		Case "doc" 
			sReturn="<img src=""images/filetype/word.gif"" class=""fileimg"" alt=""Word文件"" />"
		Case "mp3" 
			sReturn="<img src=""images/filetype/mp3.gif"" class=""fileimg"" alt=""mp3文件"" />"
		Case "rm","ram" 
			sReturn="<img src=""images/filetype/rm.gif"" class=""fileimg"" alt=""Real文件"" />"
		Case "wmv" ,"wma","mpg" ,"avi" 
			sReturn="<img src=""images/filetype/media.gif"" class=""fileimg"" alt=""媒体文件"" />"
		Case else
			sReturn="<img src=""images/filetype/blank.gif"" class=""fileimg"" alt=""其他文件"" />"
	end Select
	If C_User_ViewUploadfiles=1 And (usersearch=1 OR usersearch=5 )Then
		If InStr("jpg,gif,bmp,png,psd",ext) Then sReturn="<img src="""&filepath&""" width=64 height=64 />"
	End If
	showfilepic=sReturn
end function

sub delfile()
	if id="" then
		oblog.adderrstr( "错误：请指定要删除的文件！")
		oblog.showusererr
		exit sub
	end if
	if instr(id,",")>0 then
		dim n,i
		id=FilterIDs(id)
		n=split(id,",")
		for i=0 to ubound(n)
			delonefile(n(i))
		next
	else
		delonefile(id)
	end if
	set rs=nothing
	oblog.showok "删除文件成功！",""
end sub

sub delonefile(id)
	id=clng(id)
	dim userid,filesize,filepath,fso,photofile,isphoto,imgsrc
	if oblog.logined_ulevel=9 then
		sql="select * from [oblog_upfile] where fileid=" & id
	else
		sql="select * from [oblog_upfile] where fileid=" & id&" and userid="&oblog.logined_uid
	end if
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,3
	if not rs.eof then
		userid=rs("userid")
		filesize=clng(rs("file_size"))
		filepath=rs("file_path")
		photofile=rs("photofile")
		isphoto=rs("isphoto")
		rs.delete
		rs.update
		rs.close
		oblog.execute("update [oblog_user] set user_upfiles_num=user_upfiles_num-1,user_upfiles_size=user_upfiles_size-"&filesize&" where userid="&userid)
		if filepath<>"" then 
			imgsrc=filepath
			Set fso = server.CreateObject("Scripting.FileSystemObject")
			if instr("jpg,bmp,gif,png,pcx",right(imgsrc,3))>0 then
				imgsrc=replace(imgsrc,right(imgsrc,3),"jpg")
				imgsrc=replace(imgsrc,right(imgsrc,len(imgsrc)-InstrRev(imgsrc,"/")),"pre"&right(imgsrc,len(imgsrc)-InstrRev(imgsrc,"/")))
				if  fso.FileExists(Server.MapPath(imgsrc)) then
					fso.DeleteFile Server.MapPath(imgsrc)
				end if
			end if
			if fso.FileExists(Server.MapPath(filepath)) then 
				fso.DeleteFile Server.MapPath(filepath)
			end if
			set fso=nothing
		end if	
	else
		rs.close
	end if
end sub
%>