<!--#include file="conn.asp"-->
<!--#include file="Admin_ChkPass.asp"-->
<!--#include file="inc/function.asp"-->
<%
const MaxPerPage=20
dim strFileName
dim totalPut,CurrentPage,TotalPages
dim rs, sql
dim userid,UserSearch,Keyword,strField
dim Action
dim tmpDays
dim uppath,fso,thefile
dim del,moreid,delmore
moreid=trim(request("moreid"))
response.Write moreid
del=trim(request.QueryString("del"))
userid=trim(request.QueryString("userid"))
delmore=trim(request.QueryString("delmore"))
set rs=conn.execute("select upfile_path from bloginfo")
set fso=CreateObject("Scripting.FileSystemObject")
uppath=rs(0)
keyword=trim(request("keyword"))
if keyword<>"" then 
	keyword=ReplaceBadChar(keyword)
end if
UserSearch=trim(request("UserSearch"))
Action=trim(request("Action"))
ComeUrl=Request.ServerVariables("HTTP_REFERER")

if UserSearch="" then
	UserSearch=0
else
	UserSearch=Clng(UserSearch)
end if
strFileName="admin_uploadfile_user.asp?UserSearch=" & UserSearch
if request("page")<>"" then
    currentPage=cint(request("page"))
else
	currentPage=1
end if

dim upstr
if issqldate then
	upstr="where datalength(upfiles)>0"
else
	upstr="where upfiles<>''"
end if
%>
<html>
<head>
<title>上传文件管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="Admin_STYLE.CSS" rel="stylesheet" type="text/css">
<SCRIPT language=javascript>
function unselectall()
{
    if(document.myform.chkAll.checked){
	document.myform.chkAll.checked = document.myform.chkAll.checked&0;
    } 	
}

function CheckAll(form)
{
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.Name != "chkAll")
       e.checked = form.chkAll.checked;
    }
}
</SCRIPT>
</head>
<body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0" class="bgcolor">
<br>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" Class="border">
  <tr class="topbg"> 
    <td height="22" colspan=2 align=center><strong>上传文件管理(用户列表)</strong></td>
  </tr>
  <form name="form1" action="admin_user.asp" method="get">
    <tr class="tdbg"> 
      <td width="100" height="30"><strong>管理导航：</strong></td>
      <td width="687" height="30"> &nbsp;&nbsp;&nbsp;&nbsp;<a href="admin_uploadfile_user.asp">上传文件管理用户列表</a></td>
    </tr>
  </form>
</table>
<br>
<%
if del<>"" then
	Delfile del,userid
	response.Redirect "admin_uploadfile_user.asp"
else
	if delmore="true" then
		call Delfilemore()
	end if
	call main()
end if

call CloseConn()  

sub main()
	dim theFolder,filecount,totalsize
	if fso.FolderExists(Server.MapPath(uppath))=False then
		response.write "找不到文件夹！可能是配置有误！"
		exit sub
	end if

	dim strGuide
	strGuide="<table width='98%' align='center'><tr><td align='left'>您现在的位置：<a href='Admin_Uploadfile_user.asp'>上传文件管理-用户列表</a>&nbsp;&gt;&gt;&nbsp;"

	if Keyword="" then
		sql="select upfiles,upfiles_size,username,userid,userlevel from [user] "&upstr&" order by userID desc"
		strGuide=strGuide & "所有用户"
	else				
		sql="select upfiles,upfiles_size,username,userid,userlevel from [user] "&upstr&" and userName like '%" & Keyword & "%' order by userID  desc"
		strGuide=strGuide & "用户名中含有“ <font color=red>" & Keyword & "</font> ”的用户"
	end if		
	
	strGuide=strGuide & "</td><td align='right'>"
	'response.Write(sql)
	Set rs=Server.CreateObject("Adodb.RecordSet")
	rs.Open sql,Conn,1,1
  	if rs.eof and rs.bof then
		strGuide=strGuide & "共找到 <font color=red>0</font> 个有上传文件的用户</td></tr></table>"
		response.write strGuide
	else
    	totalPut=rs.recordcount
		strGuide=strGuide & "共找到 <font color=red>" & totalPut & "</font> 个有上传文件的用户</td></tr></table>"
		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
        	showpage strFileName,totalput,MaxPerPage,true,true,"个用户"
   	 	else
   	     	if (currentPage-1)*MaxPerPage<totalPut then
         	   	rs.move  (currentPage-1)*MaxPerPage
         		dim bookmark
           		bookmark=rs.bookmark
            	showContent
            	showpage strFileName,totalput,MaxPerPage,true,true,"个用户"
        	else
	        	currentPage=1
           		showContent
           		showpage strFileName,totalput,MaxPerPage,true,true,"个用户"
	    	end if
		end if
	end if
	rs.Close
	set rs=Nothing
	call ShowSearch()

end sub

sub showContent()
	dim i
	dim user_maxsize,vip_maxsize,admin_maxsize
	dim rsmax
    i=0
	set rsmax=conn.execute("select upfile_user_maxsize,upfile_vip_maxsize,upfile_admin_maxsize from bloginfo")
	user_maxsize=rsmax(0)
	vip_maxsize=rsmax(1)
	admin_maxsize=rsmax(2)
%>
<table width='98%' border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
  <form name="myform" method="Post" action="admin_uploadfile_user.asp?delmore=true" onsubmit="return confirm('确定要执行选定的操作吗？');">
     <td>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
          <tr class="title"> 
            <td width="28" align="center"><font color="#FFFFFF">选中</font></td>
            <td width="96" align="center"><font color="#FFFFFF">ID</font></td>
            <td width="68" height="22" align="center"><font color="#FFFFFF">上传文件数</font></td>
            <td width="68" height="22" align="center"><font color="#FFFFFF">总计大小</font></td>
            <td width="68" align="center"><font color="#FFFFFF">剩余空间</font></td>
            <td width="68" height="22" align="center"><font color="#FFFFFF">分配空间</font></td>
            <td width="275" align="center"><font color="#FFFFFF">百分比</font></td>
            <td width="70" height="22" align="center"><font color="#FFFFFF"> 
              操作</font></td>
          </tr>
          <%do while not rs.EOF
		  dim sfile,n
		  if rs("upfiles")<>"" then
			  sfile=split(rs("upfiles"),"|")		 
		 n=ubound(sfile)+1
		 end if
		   %>
          <tr class="tdbg" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#BFDFFF'"> 
            <td width="28" align="center"><input name='moreid' type='checkbox' onclick="unselectall()" id="moreid" value='<%=rs("userid")%>'>
			</td>
            <td width="96" align="center"><a href=blog.asp?name=<%=rs("username")%> target="_blank"><%=rs("username")%></a></td>
            <td width="68" align="center"><%=n%></td>
            <td align="center"><%=round(rs("upfiles_size")/1024)&"KB"%></td>
            <td align="center"><%
			select case rs("userlevel")
				case 7
				response.Write round(user_maxsize-rs("upfiles_size")/1024)&"KB"
				case 8
				response.Write round(vip_maxsize-rs("upfiles_size")/1024)&"KB"
				case 9
				response.Write round(admin_maxsize-rs("upfiles_size")/1024)&"KB"
			end select			
			%></td>
            <td align="center"><%
			select case rs("userlevel")
				case 7
				response.Write user_maxsize&"KB"
				case 8
				response.Write vip_maxsize&"KB"
				case 9
				response.Write admin_maxsize&"KB"
			end select				
			%> </td>
            <td align="center"><div align="left"><img src="images/bar.gif" width=<%
			select case rs("userlevel")
				case 7
				response.Write ((rs("upfiles_size")/1024)/user_maxsize)*100&"%"
				case 8
				response.Write ((rs("upfiles_size")/1024)/vip_maxsize)*100&"%"
				case 9
				response.Write ((rs("upfiles_size")/1024)/admin_maxsize)*100&"%"
			end select					
			
			%> height=10></div></td>
            <td width="70" align="center"><%		
        response.write "<a href='admin_uploadfile.asp?usermore="&rs("userid")&"'>详细</a>&nbsp;"
        response.write "<a href='admin_uploadfile_user.asp?del="&rs("upfiles")&"&userid="&rs("userid")&"'>清空</a>"

		%> </td>
          </tr>
          <%
		  	i=i+1
			if i>=MaxPerPage then exit do
			
	rs.movenext
loop
%>
        </table>  
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="200" height="30"><input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox">
              选中本页显示的所有用户</td>
            <td> <strong>操作：</strong> 
              <input name="Action" type="radio" value="Del" checked onClick="document.myform.UserLevel.disabled=true"> 
              清空              &nbsp;&nbsp;&nbsp;              &nbsp;&nbsp; 
              <input type="submit" name="Submit" value=" 执 行 "> </td>
  </tr>
</table>
</td>
</form></tr></table>
<%

end sub

sub showsearch()
%>
<form name="form2" method="post" action="admin_uploadfile_user.asp">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
  <tr class="tdbg">
    <td width="184">按用户查询上传文件<strong>：</strong></td>
    <td width="236">
      <input name="Keyword" type="text" id="Keyword" size="20" maxlength="30">
      <input type="submit" name="Submit2" value=" 查 询 ">
      <input name="UserSearch" type="hidden" id="UserSearch" value="10">
	</td>
    <td width="346">若为空，则查询所有用户</td>
  </tr>
</table>
</form>
<%end sub

function delfile(filenames,uid)
	dim str_del,i
	str_del=split(filenames,"|")
	for i=0 to ubound(str_del)
		if fso.FileExists(Server.MapPath(uppath&"/"&trim(str_del(i)))) then 
			fso.DeleteFile Server.MapPath(uppath&"/"&trim(str_del(i)))
		end if
	next
	conn.execute("update [user] set upfiles='' where userid="&uid)
	conn.execute("update [user] set upfiles_size=0 where userid="&uid)	
end function

sub Delfilemore()
	dim more_userid
	dim i
	more_userid=split(moreid,",")
	for i=0 to ubound(more_userid)
		set rs=conn.execute("select upfiles from [user] where userid="&more_userid(i))
		if not rs.eof then
			delfile rs(0),more_userid(i)
		end if					
	next
	response.Redirect "admin_uploadfile_user.asp"
end sub

%>
</p>
</body>
</html>
