<%@language=vbscript codepage=936 %>
<%
option explicit
response.buffer=true	
Const PurviewLevel=2    '操作权限
%>
<!--#include file="Admin_ChkPurview.asp"-->
<!--#include file="inc/conn.asp"-->
<!--#include file="inc/function.asp"-->
<!--#include file="inc/md5.asp"-->
<%
const MaxPerPage=20
dim strFileName
dim totalPut,CurrentPage,TotalPages
dim rs, sql
dim UserID,UserSearch,Action,FoundErr,ErrMsg
dim ComeUrl
strFileName="Admin_User.asp"
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
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">
<table width="100%" 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" <%if UserSearch=0 then response.write " selected"%>>列出所有用户</option>
          <option value="1" <%if UserSearch=1 then response.write " selected"%>>文章最多TOP100</option>
          <option value="2" <%if UserSearch=2 then response.write " selected"%>>文章最少的100个用户</option>
          <option value="3" <%if UserSearch=3 then response.write " selected"%>>最近24小时内登录的用户</option>
          <option value="4" <%if UserSearch=4 then response.write " selected"%>>最近24小时内注册的用户</option>
          <option value="5" <%if UserSearch=5 then response.write " selected"%>>等待邮件验证的用户</option>
          <option value="6" <%if UserSearch=6 then response.write " selected"%>>等待管理员认证的用户</option>
          <option value="7" <%if UserSearch=7 then response.write " selected"%>>所有被锁住的用户</option>
          <option value="8" <%if UserSearch=8 then response.write " selected"%>>所有收费用户</option>
          <option value="9" <%if UserSearch=9 then response.write " selected"%>>所有VIP用户</option>
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;高级查询&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="Admin_User.asp?Action=Add">添加新用户</a></td>
    </tr>
  </form>
</table>
<br>
<%
if Action="ShowSearch" then
	call ShowSearch()
elseif 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 ArticleChecked desc"
			strGuide=strGuide & "发表文章最多的前100个用户"
		case 2
			sql="select top 100 * from [User] order by ArticleChecked"
			strGuide=strGuide & "发表文章最少的100个用户"
		case 3
			sql="select * from [User] where datediff('h',LastLoginTime,Now())<25 order by LastLoginTime desc"
			strGuide=strGuide & "最近24小时内登录的用户"
		case 4
			sql="select * from [User] where datediff('h',RegDate,Now())<25 order by RegDate desc"
			strGuide=strGuide & "最近24小时内注册的用户"
		case 5
			sql="select * from [User] where UserLevel=3000 order by UserID desc"
			strGuide=strGuide & "等待邮件验证的用户"
		case 6
			sql="select * from [User] where UserLevel=2000 order by UserID desc"
			strGuide=strGuide & "等待管理认证证的用户"
		case 7
			sql="select * from [User] where LockUser=True order by UserID desc"
			strGuide=strGuide & "所有被锁住的用户"
		case 8
			sql="select * from [User] where UserLevel=99 order by UserID desc"
			strGuide=strGuide & "所有收费用户"
		case 9
			sql="select * from [User] where UserLevel=9 order by UserID desc"
			strGuide=strGuide & "所有VIP用户"
		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
end sub

sub showContent()
   	dim i
    i=0
%>
<table width='100%' border="0" 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" class="border">
          <tr class="title"> 
            <td width="30" align="center"><strong>选中</strong></td>
            <td width="80" height="22" align="center"><strong> 用户名</strong></td>
            <td height="22" align="center"><strong>所属用户组</strong></td>
            <td width="60" align="center"><strong>文章数</strong></td>
            <td width="100" height="22" align="center"><strong>最后登录IP</strong></td>
            <td width="120" align="center"><strong>最后登录时间</strong></td>
            <td width="60" height="22" align="center"><strong>登录次数</strong></td>
            <td width="40" height="22" align="center"><strong> 状态</strong></td>
            <td width="100" height="22" align="center"><strong> 操作</strong></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="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("Email") & vbcrlf & "ＱＱ："
			if rs("QQ")<>"" then
				response.write rs("QQ")
			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("RegDate")
			
			response.write """>" & rs("username") & "</a>"
			%>
			</td>
            <td align="center">
			<%
			select case rs("UserLevel")
				case 3000
					response.write "等待邮件验证的用户"
				case 2000
					response.write "等待管理员认证的用户"
				case 999
					response.write "普通注册用户"
				case 99
					response.write "收费用户"
				case 9
					response.write "VIP用户"
				case else
					response.write "<font color=red>异常用户</font>"
			end select
			%>	
			</td>
            <td width="60" align="center"><%
			if rs("ArticleChecked")<>"" then
				response.write rs("ArticleChecked")
			else
				response.write "0"
			end if
			response.write "/"
			if rs("ArticleCount")<>"" then
				response.write rs("ArticleCount")
			else
				response.write "0"
			end if
			%>
			</td>
            <td width="100" align="center"> <%
	if rs("LastLoginIP")<>"" then
		response.write rs("LastLoginIP")
	else
		response.write "&nbsp;"
	end if
	%> </td>
            <td width="120" 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="100" 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>"
		%> </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>删除&nbsp;&nbsp;&nbsp;&nbsp;
              <input name="Action" type="radio" value="Lock">锁定 &nbsp;&nbsp;&nbsp;
              <input name="Action" type="radio" value="UnLock">解锁 &nbsp;&nbsp;&nbsp; 
              <input name="Action" type="radio" value="Move">移动到
              <select name="UserLevel" id="UserLevel">
                <option value="3000">等待邮件认证的用户</option>
                <option value="2000">等待管理审核的用户</option>
                <option value="999">注册用户</option>
                <option value="99" selected>收费用户</option>
                <option value="9">VIP用户</option>
              </select>
              &nbsp;&nbsp; 
              <input type="submit" name="Submit" value=" 执 行 "> </td>
  </tr>
</table>
</td>
</form></tr></table>
<%
end sub

sub AddUser()
%>
<form action="Admin_User.asp" method="post">
  <table width=100% border=0 cellpadding=2 cellspacing=1 class="border">
    <TR align=center class='title'> 
      <TD height=22 colSpan=2><font class=en><b>添 加 新 用 户</b></font></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><b>用户名：</b><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%"><B>密码(至少6位)：</B><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%"><strong>确认密码(至少6位)：</strong><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%"><strong>密码问题：</strong><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%"><strong>问题答案：</strong><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%"><strong>性别：</strong></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%"><strong>Email地址：</strong></TD>
      <TD width="60%"> <INPUT   maxLength=50 size=30 name=Email> <font color="#FF0000">*</font></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>主页：</strong></TD>
      <TD width="60%"> <INPUT   maxLength=100 size=30 name=homepage value="http://"></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>QQ号码：</strong></TD>
      <TD width="60%"> <INPUT maxLength=20 size=30 name=QQ></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>MSN：</strong></TD>
      <TD width="60%"> <INPUT maxLength=50 size=30 name=msn></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>用户级别：</strong></TD>
      <TD width="60%"><select name="UserLevel" id="UserLevel">
          <option value="3000">等待邮件认证的用户</option>
          <option value="2000">等待管理审核的用户</option>
          <option value="999" selected>注册用户</option>
          <option value="99">收费用户</option>
          <option value="9">VIP用户</option>
        </select></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>用户状态：</strong></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="100%" border="0" cellspacing="1" cellpadding="2" class="border">
    <TR class='title'> 
      <TD height=22 colSpan=2 align="center"><b>修改注册用户信息</b></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><b>用户名：</b></TD>
      <TD width="60%"><%=rsUser("UserName")%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="Admin_ArticleManage.asp?Field=Editor&Keyword=<%=rsUser("UserName")%>">查看此用户发表的文章</a></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><B>密码(至少6位)：</B><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><strong>确认密码(至少6位)：</strong><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%"><strong>密码问题：</strong><br>
        忘记密码的提示问题</TD>
      <TD width="60%"> <INPUT name="Question"   type=text value="<%=rsUser("Question")%>" size=30> 
      </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>问题答案：</strong><BR>
        忘记密码的提示问题答案，用于取回密码</TD>
      <TD width="60%"> <INPUT   type=text size=30 name="Answer"> <font color="#FF0000">如果不想修改，请留空</font></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>性别：</strong></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%"><strong>Email地址：</strong></TD>
      <TD width="60%"> <INPUT name=Email value="<%=rsUser("Email")%>" size=30   maxLength=50>
        <a href="mailto:<%=rsUser("Email")%>">给此用户发一封电子邮件</a> </TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>主页：</strong></TD>
      <TD width="60%"> <INPUT   maxLength=100 size=30 name=homepage value="<%=rsUser("HomePage")%>"></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>QQ号码：</strong></TD>
      <TD width="60%"> <INPUT name=QQ value="<%=rsUser("QQ")%>" size=30 maxLength=20></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>MSN：</strong></TD>
      <TD width="60%"> <INPUT name=msn value="<%=rsUser("MSN")%>" size=30 maxLength=50></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>用户级别：</strong></TD>
      <TD width="60%"><select name="UserLevel" id="UserLevel">
          <option value="3000" <%if rsUser("UserLevel")=3000 then response.write " selected"%>>等待邮件认证的用户</option>
          <option value="2000" <%if rsUser("UserLevel")=2000 then response.write " selected"%>>等待管理审核的用户</option>
          <option value="999" <%if rsUser("UserLevel")=999 then response.write " selected"%>>注册用户</option>
          <option value="99" <%if rsUser("UserLevel")=99 then response.write " selected"%>>收费用户</option>
          <option value="9" <%if rsUser("UserLevel")=9 then response.write " selected"%>>VIP用户</option>
        </select></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="40%"><strong>用户状态：</strong></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="100%" border="0" cellspacing="1" cellpadding="2" class="border">
  <tr align="center" class="title"> 
    <td height="22" colspan="2"><strong>更 新 用 户 数 据</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>
<%
end sub
%>
</body>
</html>
<%
sub SaveAdd()
	dim UserName,Password,PwdConfirm,Question,Answer,Sex,Email,Homepage,QQ,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"))
	QQ=trim(request("QQ"))
	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 QQ<>"" then
		if not isnumeric(QQ) or len(cstr(QQ))>10 then
			errmsg=errmsg & "<br><li>QQ号码只能是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("Password")=md5(Password)
		rsReg("Question")=Question
		rsReg("Answer")=md5(Answer)
		rsReg("Sex")=Sex
		rsReg("Email")=Email
		rsReg("Homepage")=Homepage
		rsReg("QQ")=QQ
		rsReg("MSN")=MSN
		rsReg("UserLevel")=UserLevel
		rsReg("LockUser")=LockUser
		rsReg("RegDate")=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,QQ,MSN,UserLevel,LockUser
	dim rsUser,sqlUser
	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"))
	QQ=trim(request("QQ"))
	MSN=trim(request("MSN"))
	UserLevel=trim(request("UserLevel"))
	LockUser=trim(request("LockUser"))

	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 QQ<>"" then
		if not isnumeric(QQ) or len(cstr(QQ))>10 then
			errmsg=errmsg & "<br><li>QQ号码只能是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("Password")=md5(Password)
	end if
	rsUser("Question")=Question
	if Answer<>"" then
		rsUser("Answer")=md5(Answer)
	end if
	rsUser("Sex")=Sex
	rsUser("Email")=Email
	rsUser("HomePage")=HomePage
	rsUser("QQ")=QQ
	rsUser("MSN")=MSN
	rsUser("UserLevel")=UserLevel
	rsUser("LockUser")=LockUser
	rsUser.update
	rsUser.Close
	set rsUser=nothing
	call CloseConn()
	response.redirect "Admin_User.asp"
end sub

sub DelUser()
	if UserID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定要删除的用户</li>"
		exit sub
	end if
	if instr(UserID,",")>0 then
		UserID=replace(UserID," ","")
		sql="delete from [User] where UserID in (" & UserID & ")"
	else
		sql="delete from [User] where UserID=" & Clng(UserID)
	end if
	conn.Execute sql
	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 ComeUrl
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 ComeUrl
end sub

sub MoveUser()
	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," ","")
		sql="Update [User] set UserLevel=" & UserLevel & " where UserID in (" & UserID & ")"
	else
		sql="Update [User] set UserLevel=" & UserLevel & " where UserID=" & CLng(UserID)
	end if
	conn.Execute sql
	call CloseConn()      
	response.redirect ComeUrl
end sub

sub DoUpdate()
	dim BeginID,EndID,sqlUser,rsUser,trs
	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")
	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(ArticleID) from Article where Editor='" & rsUser("UserName") & "'")
		if isNull(trs(0)) then
			rsUser("ArticleCount")=0
		else
			rsUser("ArticleCount")=trs(0)
		end if
		set trs=conn.execute("select count(ArticleID) from Article where Passed=True and Editor='" & rsUser("UserName") & "'")
		if isNull(trs(0)) then
			rsUser("ArticleChecked")=0
		else
			rsUser("ArticleChecked")=trs(0)
		end if
		rsUser.update
		rsUser.movenext
	loop
	rsUser.close
	set rsUser=nothing
	call WriteSuccessMsg("已经成功将用户数据进行了更新！")
end sub
%>