<!--#include file="conn.asp"-->
<!--#include file="Admin_ChkPass.asp"-->
<!--#include file="inc/md5.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,FoundErr,ErrMsg
dim tmpDays
keyword=trim(request("keyword"))
if keyword<>"" then 
	keyword=ReplaceBadChar(keyword)
end if
strField=trim(request("Field"))
UserSearch=trim(request("UserSearch"))
Action=trim(request("Action"))
UserID=trim(Request("UserID"))
ComeUrl=Request.ServerVariables("HTTP_REFERER")

if UserSearch="" then
	UserSearch=0
else
	UserSearch=Clng(UserSearch)
end if
strFileName="Admin_User.asp?UserSearch=" & UserSearch
if request("page")<>"" then
    currentPage=cint(request("page"))
else
	currentPage=1
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"><select size=1 name="UserSearch" onChange="javascript:submit()">
          <option value="0">列出所有用户</option>
          <option value="1">文章最多TOP100</option>
          <option value="2">文章最少的100个用户</option>
		  <option value="3">VIP用户</option>
		  <option value="4">前台管理员</option>
		  <option value="5">推荐博客</option>
          <option value="6">等待管理员认证的用户</option>
          <option value="7">所有被锁住的用户</option>
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;<a href="admin_user.asp">用户管理首页</a>&nbsp;|&nbsp;<a href="admin_user.asp?Action=Add">添加新用户</a></td>
    </tr>
  </form>
</table>
<br>
<%
if Action="Add" then
	call AddUser()
elseif Action="SaveAdd" then
	call SaveAdd()
elseif Action="Modify" then
	call Modify()
elseif Action="SaveModify" then
	call SaveModify()
elseif Action="Del" then
	call DelUser()
elseif Action="Lock" then
	call LockUser()
elseif Action="UnLock" then
	call UnLockUser()
elseif Action="Move" then
	call MoveUser()
elseif Action="Update" then
	call UpdateUser()
elseif Action="DoUpdate" then
	call DoUpdate()
else
	call main()
end if
if FoundErr=true then
	call WriteErrMsg()
end if
call CloseConn()  

sub main()
	dim strGuide
	strGuide="<table width='100%'><tr><td align='left'>您现在的位置：<a href='Admin_User.asp'>注册用户管理</a>&nbsp;&gt;&gt;&nbsp;"
	select case UserSearch
		case 0
			sql="select * from [User] order by UserID desc"
			strGuide=strGuide & "所有用户"
		case 1
			sql="select top 100 * from [user] order by logcount desc"
			strGuide=strGuide & "发表日志最多的前100个用户"
		case 2
			sql="select top 100 * from  [user] order by logcount"
			strGuide=strGuide & "发表日志最少的100个用户"
		case 3
			sql="select * from  [user] where userlevel=8 order by userid desc"
			strGuide=strGuide & "所有VIP用户"
		case 4
			sql="select * from  [user] where userlevel=9 order by userid desc"
			strGuide=strGuide & "前台管理员"
		case 5
			sql="select * from  [user] where userisbest='true' order by userid desc"
			strGuide=strGuide & "推荐博客"
		case 6
			sql="select * from [user] where UserLevel=6 order by userID  desc"
			strGuide=strGuide & "等待管理认证证的用户"
		case 7
			sql="select * from [user] where  LockUser ='true' order by userID  desc"
			strGuide=strGuide & "所有被锁住的用户"
		case 10
			if Keyword="" then
				sql="select * from [user] order by userID desc"
				strGuide=strGuide & "所有用户"
			else
				select case strField
				case "UserID"
					if IsNumeric(Keyword)=false then
						FoundErr=true
						ErrMsg=ErrMsg & "<br><li>用户ID必须是整数！</li>"
					else
						sql="select * from [user] where userID =" & Clng(Keyword)
						strGuide=strGuide & "用户ID等于<font color=red> " & Clng(Keyword) & " </font>的用户"
					end if
				case "UserName"
					sql="select * from [user] where userName like '%" & Keyword & "%' order by userID  desc"
					strGuide=strGuide & "用户名中含有“ <font color=red>" & Keyword & "</font> ”的用户"
				end select
			end if
		case else
			FoundErr=true
			ErrMsg=ErrMsg & "<br><li>错误的参数！</li>"
	end select
	strGuide=strGuide & "</td><td align='right'>"
	if FoundErr=true then exit sub
	
	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
    i=0
%>
<table width='98%' border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
  <form name="myform" method="Post" action="admin_user.asp" onsubmit="return confirm('确定要执行选定的操作吗？');">
     <td>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
          <tr class="title"> 
            <td width="30" align="center"><font color="#FFFFFF">选中</font></td>
            <td width="30" align="center"><font color="#FFFFFF">ID</font></td>
            <td width="80" height="22" align="center"><font color="#FFFFFF"> 用户名</font></td>
            <td height="22" align="center"><font color="#FFFFFF">所属用户组</font></td>
            <td height="22" align="center"><font color="#FFFFFF">最后登录IP</font></td>
            <td align="center"><font color="#FFFFFF">最后登录时间</font></td>
            <td width="60" height="22" align="center"><font color="#FFFFFF">登录次数</font></td>
            <td width="40" height="22" align="center"><font color="#FFFFFF"> 状态</font></td>
            <td width="120" height="22" align="center"><font color="#FFFFFF"> 
              操作</font></td>
          </tr>
          <%do while not rs.EOF %>
          <tr class="tdbg" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#BFDFFF'"> 
            <td width="30" align="center"><input name='UserID' type='checkbox' onclick="unselectall()" id="UserID" value='<%=cstr(rs("userID"))%>'></td>
            <td width="30" align="center"><%=rs("userID")%></td>
            <td width="80" align="center"><%
			response.write "<a href='Admin_User.asp?Action=Modify&UserID=" & rs("userID") & "' title=""======== 用 户 信 息 ========" & vbcrlf & "性别："
			if rs("Sex")=1 then
				response.write "男"
			else
				response.write "女"
			end if
			response.write vbcrlf & "信箱：" & rs("userEmail") & vbcrlf & "ＱＱ："
			if rs("icq")<>"" then
				response.write rs("icq")
			else
				response.write "未填"
			end if
			response.write vbcrlf & "MSN："
			if rs("Msn")<>"" then
				response.write rs("Msn")
			else
				response.write "未填"
			end if
			response.write vbcrlf & "主页："
			if rs("Homepage")<>"" then
				response.write rs("Homepage")
			else
				response.write "未填"
			end if
			response.write vbcrlf & "注册日期：" & rs("addDate")
			
			response.write """>" & rs("userName") & "</a>"
			%> </td>
            <td align="center"> <%
			select case rs("UserLevel")
				case 6
					response.write "<font color=green>等待管理员认证的用户</font>"
				case 7
					response.write "普通注册用户"
				case 8
					response.write "<font color=blue>VIP用户</font>"
				case 9
					response.write "<font color=blue>前台管理员</font>"
				case else
					response.write "<font color=red>异常用户</font>"
			end select
			%> </td>
            <td align="center"> <%
	if rs("LastLoginIP")<>"" then
		response.write rs("LastLoginIP")
	else
		response.write "&nbsp;"
	end if
	%> </td>
            <td align="center"> <%
	if rs("LastLoginTime")<>"" then
		response.write rs("LastLoginTime")
	else
		response.write "&nbsp;"
	end if
	%> </td>
            <td width="60" align="center"> <%
	if rs("LoginTimes")<>"" then
		response.write rs("LoginTimes")
	else
		response.write "0"
	end if
	%> </td>
            <td width="40" align="center"><%
	  if rs("LockUser")="true" then
	  	response.write "<font color=red>已锁定</font>"
	  else
	  	response.write "正常"
	  end if
	  %></td>
            <td width="120" align="center"><%
		response.write "<a href='Admin_User.asp?Action=Modify&UserID=" & rs("userID") & "'>修改</a>&nbsp;"
		if rs("LockUser")="false" then
			response.write "<a href='Admin_User.asp?Action=Lock&UserID=" & rs("userID") & "'>锁定</a>&nbsp;"
		else
            response.write "<a href='Admin_User.asp?Action=UnLock&UserID=" & rs("userID") & "'>解锁</a>&nbsp;"
		end if
        response.write "<a href='Admin_User.asp?Action=Del&UserID=" & rs("userID") & "' onClick='return confirm(""确定要删除此用户吗？"");'>删除</a>&nbsp;"
		%> </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;
              <input name="Action" type="radio" value="Lock" onClick="document.myform.UserLevel.disabled=true">锁定 &nbsp;&nbsp;&nbsp;
              <input name="Action" type="radio" value="UnLock" onClick="document.myform.UserLevel.disabled=true">解锁 &nbsp;&nbsp;&nbsp; 
              <input name="Action" type="radio" value="Move" onClick="document.myform.UserLevel.disabled=false">移动到
              <select name="UserLevel" id="UserLevel" disabled>
                <option value="6">等待管理审核的用户</option>
                <option value="7">注册用户</option>
                <option value="8">VIP用户</option>
                <option value="9">前台管理员</option>
              </select>
              &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_user.asp">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
  <tr class="tdbg">
    <td width="120"><strong>用户高级查询：</strong></td>
    <td width="300">
      <select name="Field" id="Field">
      <option value="UserID" selected>用户ID</option>
      <option value="UserName">用户名</option>
      </select>
      <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>若为空，则查询所有用户</td>
  </tr>
</table>
</form>
<%
end sub

sub AddUser()
%>
<form name="myform" action="admin_user.asp" method="post">
  <table width=98% border=0 align="center" cellpadding=2 cellspacing=1 bgcolor="#FFFFFF" class="border">
    <TR align=center class='title'> 
      <TD height=22 colSpan=2><font color="#FFFFFF" class=en><b>添 加 新 用 户</b></font></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">用户名：<BR>
        不能超过14个字符（7个汉字）</TD>
      <TD width="60%"> <INPUT   maxLength=14 size=30 name=UserName> <font color="#FF0000">*</font></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">密码(至少6位)：<BR>
        请输入密码，区分大小写。 请不要使用任何类似 '*'、' ' 或 HTML 字符 </TD>
      <TD width="60%"> <INPUT   type=password maxLength=12 size=30 name=Password> 
        <font color="#FF0000">*</font> </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">确认密码(至少6位)：<BR>
        请再输一遍确认</TD>
      <TD width="60%"> <INPUT   type=password maxLength=12 size=30 name=PwdConfirm> 
        <font color="#FF0000">*</font> </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">密码问题：<BR>
        忘记密码的提示问题</TD>
      <TD width="60%"> <INPUT   type=text maxLength=50 size=30 name="Question"> 
        <font color="#FF0000">*</font> </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">问题答案：<BR>
        忘记密码的提示问题答案，用于取回密码</TD>
      <TD width="60%"> <INPUT   type=text maxLength=20 size=30 name="Answer"> 
        <font color="#FF0000">*</font> </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">性别：</TD>
      <TD width="60%"> <INPUT type=radio CHECKED value="1" name=sex>
        男 &nbsp;&nbsp; <INPUT type=radio value="0" name=sex>
        女</TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">Email地址：</TD>
      <TD width="60%"> <INPUT   maxLength=50 size=30 name=Email> <font color="#FF0000">*</font></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">主页：</TD>
      <TD width="60%"> <INPUT   maxLength=100 size=30 name=homepage value="http://"></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">QQ号码：</TD>
      <TD width="60%"> <INPUT maxLength=20 size=30 name=OICQ></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">MSN：</TD>
      <TD width="60%"> <INPUT maxLength=50 size=30 name=msn></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">用户级别：</TD>
      <TD width="60%"><select name="UserLevel" id="UserLevel">
          <option value="6">等待审核的用户</option>
          <option value="7" selected>注册用户</option>
          <option value="8">VIP用户</option>
          <option value="9">前台管理员</option>
        </select></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">用户状态：</TD>
      <TD width="60%"><input name="LockUser" type="radio" value="false" checked>
        正常&nbsp;&nbsp; <input type="radio" name="LockUser" value="true">
        锁定</TD>
    </TR>
    <TR align="center" class="tdbg" > 
      <TD colspan="2"><input name="Action" type="hidden" id="Action" value="SaveAdd"> 
        <input type="submit" name="Submit" value=" 添 加 "></TD>
    </TR>
  </TABLE>
</form>
<%
end sub

sub Modify()
	dim UserID
	dim rsUser,sqlUser
	UserID=trim(request("UserID"))
	if UserID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>参数不足！</li>"
		exit sub
	else
		UserID=Clng(UserID)
	end if
	Set rsUser=Server.CreateObject("Adodb.RecordSet")
	sqlUser="select * from [user] where userID=" & UserID
	rsUser.Open sqlUser,Conn,1,3
	if rsUser.bof and rsUser.eof then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>找不到指定的用户！</li>"
		rsUser.close
		set rsUser=nothing
		exit sub
	end if
%>
<FORM name="Form1" action="admin_user.asp" method="post">
  <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
    <TR class='title'> 
      <TD height=22 colSpan=2 align="center"><b><font color="#FFFFFF">修改注册用户信息</font></b></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">用户名：</TD>
      <TD width="60%"><%=rsUser("userName")%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
    </TR>
    <tr class="tdbg" onmouseover="this.style.backgroundColor='#BFDFFF'" onmouseout="this.style.backgroundColor=''">
      <td>blog名：</td>
      <td><input name=blogname   type=text id="blogname" value="<%=rsuser("blogname")%>" size=30 maxlength=20></td>
    </tr>
    <tr class="tdbg" onmouseover="this.style.backgroundColor='#BFDFFF'" onmouseout="this.style.backgroundColor=''">
      <td>blog类别：</td>
      <td><select name="usertype" id="usertype">
          <option value="<%if rsUser("usertypeid")<>"" then response.Write(rsUser("usertypeid"))%>" selected> 
          <%
		if rsUser("usertypeid")<>""  then
			dim rs
	 		set rs=conn.execute("select typename from usertype where id="&rsUser("usertypeid"))
	  		if not rs.eof then
	  		response.Write rs(0)	
	  		end if
	    else
	        response.Write "请选择"
	  	end if		
	  %>
          </option>
          <%
		set rs=conn.execute("select id,typename from usertype")
		do while not rs.eof  %>
          <option value=<%=rs(0)%>><%=rs(1)%></option>
          <%
			rs.movenext
		loop
		set rs=nothing  
	    %>
        </select></td>
    </tr>
    <TR class="tdbg" > 
      <TD width="40%">密码(至少6位)：<BR>
        请输入密码，区分大小写。 请不要使用任何类似 '*'、' ' 或 HTML 字符 </TD>
      <TD width="60%"> <INPUT   type=password maxLength=16 size=30 name=Password> 
        <font color="#FF0000">如果不想修改，请留空</font> </TD>
    </TR>
    <TR class="tdbg" > 
      <TD>确认密码(至少6位)：<br>
        请再输一遍确认</TD>
      <TD><INPUT name=PwdConfirm   type=password id="PwdConfirm" size=30 maxLength=12> 
        <font color="#FF0000">如果不想修改，请留空</font> </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">密码问题：<br>
        忘记密码的提示问题</TD>
      <TD width="60%"> <INPUT name="Question"   type=text value="<%=rsUser("Question")%>" size=30> 
      </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">问题答案：<BR>
        忘记密码的提示问题答案，用于取回密码</TD>
      <TD width="60%"> <INPUT   type=text size=30 name="Answer"> <font color="#FF0000">如果不想修改，请留空</font></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">性别：</TD>
      <TD width="60%"> <INPUT type=radio value="1" name=sex <%if rsUser("Sex")=1 then response.write "CHECKED"%>>
        男 &nbsp;&nbsp; <INPUT type=radio value="0" name=sex <%if rsUser("Sex")=0 then response.write "CHECKED"%>>
        女</TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">Email地址：</TD>
      <TD width="60%"> <INPUT name=Email value="<%=rsUser("userEmail")%>" size=30   maxLength=50> 
        <a href="mailto:<%=rsUser("userEmail")%>">给此用户发一封电子邮件</a> 
      </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">主页：</TD>
      <TD width="60%"> <INPUT   maxLength=100 size=30 name=homepage value="<%=rsUser("Homepage")%>"></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">OICQ号码：</TD>
      <TD width="60%"> <INPUT name=OICQ value="<%=rsUser("oicq")%>" size=30 maxLength=20></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">MSN：</TD>
      <TD width="60%"> <INPUT name=msn value="<%=rsUser("Msn")%>" size=30 maxLength=50></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">用户级别：</TD>
      <TD width="60%"><select name="UserLevel" id="UserLevel">
          <option value="6">等待管理审核的用户</option>
          <option value="7" selected>注册用户</option>
          <option value="8">vip用户</option>
          <option value="9">前台管理员</option>
        </select></TD>
    </TR>
    <tr class="tdbg" onmouseover="this.style.backgroundColor='#BFDFFF'" onmouseout="this.style.backgroundColor=''">
      <td>用户上传文件：</td>
      <td><input name=upfiles   type=text id="upfiles" value="<%=rsuser("upfiles")%>" size=30 maxlength=20></td>
    </tr>
    <tr class="tdbg" onmouseover="this.style.backgroundColor='#BFDFFF'" onmouseout="this.style.backgroundColor=''">
      <td>已上传字节：</td>
      <td><input name=upfiles_size   type=text id="upfiles_size" value="<%=rsuser("upfiles_size")%>" size=20 maxlength=20></td>
    </tr>
    <TR class="tdbg" >
      <TD>是否为推荐博客：</TD>
      <TD><input type="radio" name="isbest" value="true" <%if rsUser("userisbest")="true" then response.write "checked"%>> 
        是        &nbsp;&nbsp;
        <input type="radio" name="isbest" value="false" <%if rsUser("userisbest")<>"true" then response.write "checked"%>>
      否</TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%">用户状态：</TD>
      <TD width="60%"><input type="radio" name="LockUser" value="false" <%if rsUser("LockUser")="false" then response.write "checked"%>>
        正常&nbsp;&nbsp; <input type="radio" name="LockUser" value="true" <%if rsUser("LockUser")="true" then response.write "checked"%>>
        锁定</TD>
    </TR>
    <TR class="tdbg" > 
      <TD height="40" colspan="2" align="center"><input name="Action" type="hidden" id="Action" value="SaveModify"> 
        <input name=Submit   type=submit id="Submit" value="保存修改结果"> <input name="UserID" type="hidden" id="UserID" value="<%=rsUser("userID")%>"></TD>
    </TR>
  </TABLE>
</form>
<%
	rsUser.close
	set rsUser=nothing
end sub


sub UpdateUser()
%>
<FORM name="Form1" action="admin_user.asp" method="post">
  <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
    <tr align="center" class="title"> 
      <td height="22" colspan="2"><strong><font color="#FFFFFF">更 新 用 户 数 据</font></strong></td>
  </tr>
  <tr class="tdbg"> 
      <td colspan="2"><p>说明：<br>
          1、本操作将重新计算用户的日志，评论，留言数。<br>
          2、本操作可能将非常消耗服务器资源，而且更新时间很长，请仔细确认每一步操作后执行。</p>
      </td>
  </tr>
  <tr class="tdbg"> 
    <td height="25">开始用户ID：</td>
    <td height="25"><input name="BeginID" type="text" id="BeginID" value="1" size="10" maxlength="3">
      用户ID，可以填写您想从哪一个ID号开始进行修复</td>
  </tr>
  <tr class="tdbg"> 
    <td height="25">结束用户ID：</td>
    <td height="25"><input name="EndID" type="text" id="EndID" value="1000" size="10" maxlength="3">
      将更新开始到结束ID之间的用户数据，之间的数值最好不要选择过大</td>
  </tr>
  <tr class="tdbg"> 
    <td height="25">&nbsp;</td>
    <td height="25"><input name="Submit" type="submit" id="Submit" value="更新用户数据"> <input name="Action" type="hidden" id="Action" value="DoUpdate"></td>
  </tr>
</table>
</form>
<p>
  <%
end sub
%>
</p>
</body>
</html>
<%
sub SaveAdd()
	dim UserName,Password,PwdConfirm,Question,Answer,Sex,Email,Homepage,OICQ,MSN,UserLevel,LockUser
	UserName=trim(request("UserName"))
	Password=trim(request("Password"))
	PwdConfirm=trim(request("PwdConfirm"))
	Question=trim(request("Question"))
	Answer=trim(request("Answer"))
	Sex=trim(Request("Sex"))
	Email=trim(request("Email"))
	Homepage=trim(request("Homepage"))
	OICQ=trim(request("OICQ"))
	MSN=trim(request("MSN"))
	UserLevel=trim(request("UserLevel"))
	LockUser=trim(request("LockUser"))
		
	if UserName="" or strLength(UserName)>14 or strLength(UserName)<4 then
		founderr=true
		errmsg=errmsg & "<br><li>请输入用户名(不能大于14小于4)</li>"
	else
  		if Instr(UserName,"=")>0 or Instr(UserName,"%")>0 or Instr(UserName,chr(32))>0 or Instr(UserName,"?")>0 or Instr(UserName,"&")>0 or Instr(UserName,";")>0 or Instr(UserName,",")>0 or Instr(UserName,"'")>0 or Instr(UserName,",")>0 or Instr(UserName,chr(34))>0 or Instr(UserName,chr(9))>0 or Instr(UserName,"")>0 or Instr(UserName,"$")>0 then
			errmsg=errmsg+"<br><li>用户名中含有非法字符</li>"
			founderr=true
		end if
	end if
	if Password="" or strLength(Password)>12 or strLength(Password)<6 then
		founderr=true
		errmsg=errmsg & "<br><li>请输入密码(不能大于12小于6)</li>"
	else
		if Instr(Password,"=")>0 or Instr(Password,"%")>0 or Instr(Password,chr(32))>0 or Instr(Password,"?")>0 or Instr(Password,"&")>0 or Instr(Password,";")>0 or Instr(Password,",")>0 or Instr(Password,"'")>0 or Instr(Password,",")>0 or Instr(Password,chr(34))>0 or Instr(Password,chr(9))>0 or Instr(Password,"")>0 or Instr(Password,"$")>0 then
			errmsg=errmsg+"<br><li>密码中含有非法字符</li>"
			founderr=true
		end if
	end if
	if PwdConfirm="" then
		founderr=true
		errmsg=errmsg & "<br><li>请输入确认密码(不能大于12小于6)</li>"
	else
		if Password<>PwdConfirm then
			founderr=true
			errmsg=errmsg & "<br><li>密码和确认密码不一致</li>"
		end if
	end if
	if Question="" then
		founderr=true
		errmsg=errmsg & "<br><li>密码提示问题不能为空</li>"
	end if
	if Answer="" then
		founderr=true
		errmsg=errmsg & "<br><li>密码答案不能为空</li>"
	end if
	if Sex="" then
		founderr=true
		errmsg=errmsg & "<br><li>性别不能为空</li>"
	else
		sex=cint(sex)
		if Sex<>0 and Sex<>1 then
			Sex=1
		end if
	end if
	if Email="" then
		founderr=true
		errmsg=errmsg & "<br><li>Email不能为空</li>"
	else
		if IsValidEmail(Email)=false then
			errmsg=errmsg & "<br><li>您的Email有错误</li>"
   			founderr=true
		end if
	end if
	if OICQ<>"" then
		if not isnumeric(OICQ) or len(cstr(OICQ))>10 then
			errmsg=errmsg & "<br><li>OICQ号码只能是4-10位数字，您可以选择不输入。</li>"
			founderr=true
		end if
	end if
	if MSN<>"" then
		if IsValidEmail(MSN)=false then
			errmsg=errmsg & "<br><li>你的MSN有误。</li>"
			founderr=true
		end if
	end if
	if UserLevel="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>请指定用户级别！</li>"
	else
		UserLevel=CLng(UserLevel)
	end if
	if LockUser="true" then
		LockUser=true
	else
		LockUser=false
	end if
	
	if founderr=true then
		exit sub
	end if
	
	dim sqlReg,rsReg
	sqlReg="select * from [User] where UserName='" & Username & "'"
	set rsReg=server.createobject("adodb.recordset")
	rsReg.open sqlReg,Conn,1,3
	if not(rsReg.bof and rsReg.eof) then
		founderr=true
		errmsg=errmsg & "<br><li>你注册的用户已经存在！请换一个用户名再试试！</li>"
	else
		rsReg.addnew
		rsReg("userName")=UserName
		rsReg("userPassword")=md5(Password)
		rsReg("Question")=Question
		rsReg("Answer")=md5(Answer)
		rsReg("Sex")=Sex
		rsReg("userEmail")=Email
		rsReg("Homepage")=Homepage
		if OICQ="" then
		OICQ=0
		end if
		rsReg("oicq")=OICQ
		rsReg("Msn")=MSN
		rsReg("UserLevel")=UserLevel
		rsReg("LockUser")=LockUser
		rsReg("addDate")=Now()
		rsReg.update
		founderr=false
	end if
	rsReg.close
	set rsReg=nothing
	call CloseConn()
	response.Redirect "Admin_User.asp"
end sub		

sub SaveModify()
	dim UserID,Password,PwdConfirm,Question,Answer,Sex,Email,Homepage,OICQ,MSN,UserLevel,LockUser,isbest
	dim rsUser,sqlUser
	dim blogname,usertype,upfiles,upfiles_size
	Action=trim(request("Action"))
	UserID=trim(request("UserID"))
	if UserID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>参数不足！</li>"
		exit sub
	else
		UserID=Clng(UserID)
	end if
	Password=trim(request("Password"))
	PwdConfirm=trim(request("PwdConfirm"))
	Question=trim(request("Question"))
	Answer=trim(request("Answer"))
	Sex=trim(Request("Sex"))
	Email=trim(request("Email"))
	Homepage=trim(request("Homepage"))
	OICQ=trim(request("OICQ"))
	MSN=trim(request("MSN"))
	UserLevel=trim(request("UserLevel"))
	isbest=trim(request("isbest"))
	LockUser=trim(request("LockUser"))
	blogname=trim(request("blogname"))
	usertype=trim(request("usertype"))
	upfiles=trim(request("upfiles"))
	upfiles_size=trim(request("upfiles_size"))
	
	if Password<>"" then
		if strLength(Password)>12 or strLength(Password)<6 then
			founderr=true
			errmsg=errmsg & "<br><li>密码不能大于12小于6，如果你不想修改密码，请保持为空。</li>"
		end if
		if Instr(Password,"=")>0 or Instr(Password,"%")>0 or Instr(Password,chr(32))>0 or Instr(Password,"?")>0 or Instr(Password,"&")>0 or Instr(Password,";")>0 or Instr(Password,",")>0 or Instr(Password,"'")>0 or Instr(Password,",")>0 or Instr(Password,chr(34))>0 or Instr(Password,chr(9))>0 or Instr(Password,"")>0 or Instr(Password,"$")>0 then
			errmsg=errmsg+"<br><li>密码中含有非法字符，如果你不想修改密码，请保持为空。</li>"
			founderr=true
		end if
	end if
	if Password<>PwdConfirm then
		founderr=true
		errmsg=errmsg & "<br><li>密码和确认密码不一致</li>"
	end if
	if Question="" then
		founderr=true
		errmsg=errmsg & "<br><li>密码提示问题不能为空</li>"
	end if
	if Sex="" then
		founderr=true
		errmsg=errmsg & "<br><li>性别不能为空</li>"
	else
		sex=cint(sex)
		if Sex<>0 and Sex<>1 then
			Sex=1
		end if
	end if
	if Email="" then
		founderr=true
		errmsg=errmsg & "<br><li>Email不能为空</li>"
	else
		if IsValidEmail(Email)=false then
			errmsg=errmsg & "<br><li>您的Email有错误</li>"
   			founderr=true
		end if
	end if
	if OICQ<>"" then
		if not isnumeric(OICQ) or len(cstr(OICQ))>10 then
			errmsg=errmsg & "<br><li>OICQ号码只能是4-10位数字，您可以选择不输入。</li>"
			founderr=true
		end if
	end if
	if MSN<>"" then
		if IsValidEmail(MSN)=false then
			errmsg=errmsg & "<br><li>你的MSN有误。</li>"
			founderr=true
		end if
	end if
	if UserLevel="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>请指定用户级别！</li>"
	else
		UserLevel=CLng(UserLevel)
	end if
	if LockUser="true" then
		LockUser="true"
	else
		LockUser="false"
	end if

	if founderr=true then
		exit sub
	end if
	
	Set rsUser=Server.CreateObject("Adodb.RecordSet")
	sqlUser="select * from [user] where userID=" & UserID
	rsUser.Open sqlUser,Conn,1,3
	if rsUser.bof and rsUser.eof then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>找不到指定的用户！</li>"
		rsUser.close
		set rsUser=nothing
		exit sub
	end if
	if Password<>"" then
		rsUser("userpassword")=md5(Password)
	end if
	rsUser("Question")=Question
	if Answer<>"" then
		rsUser("Answer")=md5(Answer)
	end if
	rsUser("Sex")=Sex
	rsUser("userEmail")=Email
	rsUser("Homepage")=HomePage
	if oicq="" then
	oicq=0
	end if
	rsUser("oicq")=OICQ
	rsUser("Msn")=MSN
	rsUser("UserLevel")=UserLevel
	rsUser("LockUser")=LockUser
	rsuser("userisbest")=isbest
	rsuser("blogname")=blogname
	rsuser("usertypeid")=usertype
	rsuser("upfiles")=upfiles
	rsuser("upfiles_size")=upfiles_size
	rsUser.update
	rsUser.Close
	set rsUser=nothing
	call PutApplicationValue()
	call CloseConn()
	response.redirect "Admin_User.asp"
end sub


sub DelUser()
	dim rs,delname,i
	if UserID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>请指定要删除的用户</li>"
		exit sub
	end if
	if instr(UserID,",")>0 then
		UserID=split(UserID,",")
		for i=0 to ubound(userid)
		set rs=conn.execute("select username from [user] where userid="& Clng(UserID(i)))
		delname=rs(0)
		conn.execute("delete from blog where username='"&delname&"'")
		conn.execute("delete from comment where mainuser='"&delname&"'")
		conn.execute("delete from message where mainuser='"&delname&"'")
		conn.execute("delete from subject where username='"&delname&"'")
		conn.execute("delete from [user] where userID=" & Clng(UserID(i)))
		next		
	else
		set rs=conn.execute("select username from [user] where userid="& Clng(UserID))
		delname=rs(0)
		conn.execute("delete from blog where username='"&delname&"'")
		conn.execute("delete from comment where mainuser='"&delname&"'")
		conn.execute("delete from message where mainuser='"&delname&"'")
		conn.execute("delete from subject where username='"&delname&"'")
		conn.execute("delete from [user] where userID=" & Clng(UserID))
	end if
	call CloseConn()      
	response.redirect ComeUrl
end sub

sub LockUser()
	if UserID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>请选择要锁定的用户</li>"
		exit sub
	end if
	if instr(UserID,",")>0 then
		UserID=replace(UserID," ","")
		sql="Update [user] set LockUser ='true' where userID  in (" & UserID & ")"
	else
		sql="Update [user] set LockUser='true' where userID =" & CLng(UserID)
	end if
	Conn.Execute sql
	call CloseConn()      
	response.Redirect "Admin_User.asp"
end sub

sub UnLockUser()
	if UserID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>请指定要解锁的用户</li>"
		exit sub
	end if
	if instr(UserID,",")>0 then
		UserID=replace(UserID," ","")
		sql="Update [user] set LockUser='false' where userID in (" & UserID& ")"
	else
		sql="Update [user] set LockUser='false' where userID=" & CLng(UserID)
	end if
	Conn.Execute sql
	call CloseConn()      
	response.Redirect "Admin_User.asp"
end sub

sub MoveUser()
	dim msg
	if UserID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>请指定要移动的用户</li>"
		exit sub
	end if
	dim UserLevel
	UserLevel=trim(request("UserLevel"))
	if UserLevel="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>请指定目标用户组</li>"
		exit sub
	else
		UserLevel=Clng(UserLevel)
	end if
	if instr(UserID,",")>0 then
		UserID=replace(UserID," ","")
		if UserLevel=6 then
			msg="&nbsp;&nbsp;&nbsp;&nbsp;已经成功将选定用户设为“<font color=blue>等待管理审核的用户</font>”！"
			sql="Update [user] set UserLevel=6 where userID in (" & UserID & ")"
		elseif UserLevel=7 then
			msg="&nbsp;&nbsp;&nbsp;&nbsp;已经成功将选定用户设为“<font color=blue>普通注册用户</font>”！"
			sql="Update [user] set UserLevel=7 where userID in (" & UserID & ")"
		elseif UserLevel=8 then
			msg="&nbsp;&nbsp;&nbsp;&nbsp;已经成功将选定用户设为“<font color=blue>VIP用户</font>”！"
			sql="Update [user] set UserLevel=8 where userID in (" & UserID & ")"
		elseif UserLevel=9 then
			msg="&nbsp;&nbsp;&nbsp;&nbsp;已经成功将选定用户设为“<font color=blue>前台管理员</font>”！"
			sql="Update [user] set UserLevel=9 where userID in (" & UserID & ")"
		end if
	else
		if UserLevel=6 then
			msg="&nbsp;&nbsp;&nbsp;&nbsp;已经成功将选定用户设为“<font color=blue>等待管理审核的用户</font>”！"
			sql="Update [user] set UserLevel=6 where userID=" & UserID 
		elseif UserLevel=7 then
			msg="&nbsp;&nbsp;&nbsp;&nbsp;已经成功将选定用户设为“<font color=blue>普通注册用户</font>”！"
			sql="Update [user] set UserLevel=7 where userID="& UserID
		elseif UserLevel=8 then
			msg="&nbsp;&nbsp;&nbsp;&nbsp;已经成功将选定用户设为“<font color=blue>VIP用户</font>”！"
			sql="Update [user] set UserLevel=8 where userID=" & UserID 
		elseif UserLevel=9 then
			msg="&nbsp;&nbsp;&nbsp;&nbsp;已经成功将选定用户设为“<font color=blue>前台管理员</font>”！"
			sql="Update [user] set UserLevel=9 where userID=" & UserID
		end if
	end if
	Conn.Execute sql
	response.Redirect "Admin_User.asp"
	'call WriteSuccessMsg(msg)
end sub

sub DoUpdate()
	dim BeginID,EndID,sqlUser,rsUser,trs,subrs
	BeginID=trim(request("BeginID"))
	EndID=trim(request("EndID"))
	if BeginID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>请指定开始ID</li>"
	else
		BeginID=Clng(BeginID)
	end if
	if EndID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br><li>请指定结束ID</li>"
	else
		EndID=Clng(EndID)
	end if
	
	if FoundErr=true then exit sub
	
	Set rsUser=Server.CreateObject("Adodb.RecordSet")
	set subrs=Server.CreateObject("Adodb.RecordSet")
	sqlUser="select * from [user] where userID>=" & BeginID & " and userID<=" & EndID
	rsUser.Open sqlUser,Conn,1,3
	do while not rsUser.eof
		set trs=Conn.execute("select count(ID) from [blog] where username='" & rsUser("username") & "'")
		if isNull(trs(0)) then
			rsUser("logcount")=0
		else
			rsUser("logcount")=trs(0)
		end if
		set trs=Conn.execute("select count(ID) from comment where mainuser='" & rsUser("username") & "'")
		if isNull(trs(0)) then
			rsUser("commentcount")=0
		else
			rsUser("commentcount")=trs(0)
		end if
		set trs=Conn.execute("select count(ID) from message where mainuser='" & rsUser("username") & "'")
		if isNull(trs(0)) then
			rsUser("messagecount")=0
		else
			rsUser("messagecount")=trs(0)
		end if
		subrs.open "select * from subject where username='"&rsuser("username")&"'",conn,1,3
			while not subrs.eof
				set trs=conn.execute("select count(id) from blog where subjectid="&subrs("id"))
				if isnull(trs(0)) then
					subrs("subjectlognum")=0
				else
					subrs("subjectlognum")=trs(0)
				end if
				subrs.update
				subrs.movenext
			wend
		subrs.close
		rsUser.update
		rsUser.movenext
	loop
	rsUser.close
	set rsUser=nothing
	set trs=nothing
	set subrs=nothing
	response.Write("已经成功将用户数据进行了更新！")
end sub

sub WriteErrMsg()
	dim strErr
	strErr=strErr & "<html><head><title>错误信息</title><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbcrlf
	strErr=strErr & "<link href='style.css' rel='stylesheet' type='text/css'></head><body><br><br>" & vbcrlf
	strErr=strErr & "<table cellpadding=2 cellspacing=1 border=0 width=400 class='border' align=center>" & vbcrlf
	strErr=strErr & "  <tr align='center' class='title'><td height='22'><strong>错误信息</strong></td></tr>" & vbcrlf
	strErr=strErr & "  <tr class='tdbg'><td height='100' valign='top'><b>产生错误的可能原因：</b>" & errmsg &"</td></tr>" & vbcrlf
	strErr=strErr & "  <tr align='center' class='tdbg'><td><a href='javascript:history.go(-1)'>&lt;&lt; 返回上一页</a></td></tr>" & vbcrlf
	strErr=strErr & "</table>" & vbcrlf
	strErr=strErr & "</body></html>" & vbcrlf
	response.write strErr
end sub

%>