<!--#include file="setup.asp"-->
<!--#include file="../inc/md5.asp"-->
<%
Dim Rs1
Dim i,ii,n
Dim ID
Dim selUserid
Dim CurrentPage
Dim maxperpage
Dim totalnumber
Dim TotalPageNum
Dim keyword
Dim findword
Dim grades
Dim bookmark
Dim filename
Dim WhereSQL
NC_Admin.AdminChk = "41"
NC_Admin.Check
DownsysClass.admin_header
Set Rs = Server.CreateObject("adodb.recordset")
Set Rs1 = Server.CreateObject("adodb.recordset")
Select Case Trim(Request("Action"))
	Case "edit"
		Call userModify
	Case "money"
		Call userMoney
	Case "save"
		Call saveModify
	Case "add"
		Call addMoney
Case Else
	Call Usermain
End Select
If founderr = True Then
	NC_Admin.Error_msg (ErrMsg)
End If
DownsysClass.admin_footer
NothingObject

Private Sub deluser()
	conn.Execute ("delete from [NC_user] where userid in (" & selUserid & ")")
End Sub

Private Sub islock()
	conn.Execute ("update [NC_user] set islock=1 where userid in (" & selUserid & ")")
End Sub

Private Sub nolock()
	conn.Execute ("update [NC_user] set islock=0 where userid in (" & selUserid & ")")
End Sub

Private Sub Usermain()
	If Not IsEmpty(Request("page")) Then
		CurrentPage = CInt(Request("page"))
	Else
		CurrentPage = 1
	End If
	maxperpage = 30 '###每页显示数
	If Not IsEmpty(Request("selUserid")) Then
		selUserid = Request("selUserid")
		If Request("action") = "删除用户" Then
			Call deluser
			ElseIf Request("action") = "激活用户" Then
			Call nolock
			ElseIf Request("action") = "锁定用户" Then
			Call islock
		Else
			Response.Write "无效参数！"
			Err.Raise -19691969
		End If
	End If
	Response.Write "<table width=""100%"" border=""0"" align=""center"" cellpadding=""2"" cellspacing=""1"" class=""tableBorder"">" & vbCrLf
	Response.Write " <tr>" & vbCrLf
	Response.Write " <th>用户管理</th></tr>" & vbCrLf
	Response.Write "<tr> " & vbCrLf
	Response.Write "<td height=""23"" class=forumrow><B>说明</B>：<BR>点击用户名可以查看及修改用户信息。<BR>" & vbCrLf
	Response.Write "</td></tr>" & vbCrLf
	Response.Write "<form method=Post name=""myform"" action=""admin_user.asp"" onSubmit=""return Juge(this)"">" & vbCrLf
	Response.Write " <tr>" & vbCrLf
	Response.Write " <td height=""22"" class=forumrow>查询： <input align=""absmiddle"" name=""keyword"" type=""text"" id=""keyword"" size=""30""> &nbsp;查询方法:" & vbCrLf
	Response.Write " <select size=""1"" name=""key"">" & vbCrLf
	Response.Write " <option value=""username"">按用户名名</option>" & vbCrLf
	Response.Write " <option value=""truename"">真实姓名</option>" & vbCrLf
	Response.Write " <option value="""">不限查询条件</option>" & vbCrLf
	Response.Write " </select>" & vbCrLf
	Response.Write " <input type=""submit"" name=""Submit"" align=""absmiddle"" value=""查 询..."" class=button>" & vbCrLf
	Response.Write "</td></tr></form>" & vbCrLf
	Response.Write "<tr> " & vbCrLf
	Response.Write "<td height=""23"" align=""center"" class=forumrow>" & vbCrLf
	Set Rs1 = conn.Execute("select * from NC_UserGroup order by groupid")
	Rs1.movenext
	Do While Not Rs1.EOF
		Response.Write " <a href=admin_user.asp?grade=" & Rs1("grades") & ">" & Rs1("GroupName") & "</a> "
		Rs1.movenext
	Loop
	Rs1.Close
	Response.Write "</td></tr>" & vbCrLf
	Response.Write "</table><BR>" & vbCrLf
	Response.Write "<table width=""100%"" border=""0"" align=""center"" cellpadding=""2"" cellspacing=""1"" class=""tableBorder"">" & vbCrLf
	Response.Write " <tr nowrap>" & vbCrLf
	Response.Write " <th nowrap width=""5%"">操作</th><th width=""25%"">用户名</th><th width=""20%"">真实姓名</th><th width=""10%"">邮 箱</th><th width=""15%"">用户点数</th><th nowrap width=""12%"">增加点数</th><th nowrap width=""12%"">上次登陆时间</th><th nowrap width=""6%"">状态</th></tr>" & vbCrLf
	keyword = Server.HTMLEncode(Request("keyword"))
	If Not IsNumeric(Request("grade")) And Request("grade") <> "" Then
		Response.Write "错误的系统参数!请输入整数"
		Err.Raise -19691969
	End If
	If Request("grade") <> "" Then
		grades = "where grade=" & Request("grade") & ""
	Else
		grades = ""
	End If
	If Not IsNull(keyword) And keyword <> "" Then
		keyword = Replace(Replace(Replace(keyword, "'", "‘"), "<", "&lt;"), ">", "&gt;")
		If Request("key") = "username" Then
			findword = "Where username like '%" & keyword & "%'"
		ElseIf Request("key") = "truename" Then
			findword = "Where truename like '%" & keyword & "%'"
		Else
			findword = "Where username like '%" & keyword & "%' or truename like '%" & keyword & "%'"
		End If
		WhereSQL = findword
	Else
		WhereSQL = grades
	End If
	TotalNumber = Conn.Execute("Select count(userid) from [NC_user] "& WhereSQL &"")(0)
	TotalPageNum = CInt(TotalNumber / maxperpage)  '得到总页数
	If TotalPageNum < TotalNumber / maxperpage Then TotalPageNum = TotalPageNum + 1
	If CurrentPage < 1 Then CurrentPage = 1
	If CurrentPage > TotalPageNum Then CurrentPage = TotalPageNum
	SQL = "select * from [NC_user] " & WhereSQL & " order by userid desc"
	Rs.Open SQL, Conn, 1
	If Rs.bof And Rs.EOF Then
		Response.Write "<tr><td colspan=8 class=forumrow>你还没有任何数据！</td></tr>"
	Else
		If TotalPageNum > 1 then Rs.Move (CurrentPage - 1) * maxperpage
			i = 0
		Do While Not Rs.EOF And i < CLng(maxperpage)
			Response.Write " <form name=""form"" method=""post"" action="""">" & vbCrLf
			Response.Write " <tr>" & vbCrLf
			Response.Write " <td class=forumrow align=""center""><input type=""checkbox"" name=""selUserid"" value="""
			Response.Write Rs("userid")
			Response.Write """></td>" & vbCrLf
			Response.Write " <td class=forumrow nowrap align=""center""><a href=?action=edit&userid="
			Response.Write Rs("userid")
			Response.Write ">"
			Response.Write Rs("username")
			Response.Write "<a></td>" & vbCrLf
			Response.Write " <td height=""22"" align=""center"" nowrap class=""forumrow"">"
			Response.Write Rs("truename")
			Response.Write "</td>" & vbCrLf
			Response.Write " <td class=forumrow nowrap align=""center""><a href=admin_mailist.asp?action=mail&useremail="
			Response.Write Rs("usermail")
			Response.Write "><img src=""images/email.gif"" border=0></a></td>" & vbCrLf
			Response.Write " <td class=forumrow nowrap align=""center""><font COLOR=#FF0000>"
			Response.Write Rs("money")
			Response.Write "</font> 点</td>" & vbCrLf
			Response.Write " <td class=forumRowHighlight nowrap align=""center""><a href=?action=money&userid="
			Response.Write Rs("userid")
			Response.Write ">操 作</a></td>" & vbCrLf
			Response.Write " <td class=forumrow nowrap align=""center"">"
			Response.Write Rs("logintime")
			Response.Write "</td>" & vbCrLf
			Response.Write " <td class=forumrow align=""center""><font COLOR=#FF0000>"
			If Rs("isLock") = 0 Then
				Response.Write "<B>√</B>"
			Else
				Response.Write "<B>×</B>"
			End If
			Response.Write "</font></td>" & vbCrLf
			Response.Write "</tr>" & vbCrLf
			Rs.movenext
			i = i + 1
		Loop
	End If
	Rs.Close
	Response.Write " <tr>" & vbCrLf
	Response.Write " <td height=""22"" colspan=""8"" class=""forumRowHighlight"">" & vbCrLf
	Response.Write "管理操作：选择/反选 " & vbCrLf
	Response.Write " <input type=""checkbox"" name=""checkbox"" value=""checkbox"" onclick=CheckAll(this.form)> " & vbCrLf
	Response.Write " <input class=""button"" onClick=""{if(confirm('确定删除选定的用户吗?')){this.document.form.submit();return true;}return false;}"" type=submit value=""删除用户"" name=action> " & vbCrLf
	Response.Write " <input class=""button"" onClick=""{if(confirm('确定激活选定的用户吗?')){this.document.form.submit();return true;}return false;}"" type=submit value=""激活用户"" name=action> " & vbCrLf
	Response.Write " <input class=""button"" onClick=""{if(confirm('确定锁定选定的用户吗?')){this.document.form.submit();return true;}return false;}"" type=submit value=""锁定用户"" name=action> " & vbCrLf
	Response.Write " </td></tr></form>" & vbCrLf
	Response.Write " <tr><form method=Post action=?grade=" & Request("grade") & ">" & vbCrLf
	Response.Write " <td height=""22"" align=""center"" colspan=""8"" class=""forumrow"">" & vbCrLf
	filename = "admin_user.asp"
	If totalnumber Mod maxperpage = 0 Then
		n = totalnumber \ maxperpage
	Else
		n = totalnumber \ maxperpage + 1
	End If
	If CurrentPage < 2 Then
		Response.Write " 共有 <font COLOR=#FF0000>" & totalnumber & "</font> 位用户&nbsp;&nbsp;首 页&nbsp;&nbsp;上一页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
	Else
		Response.Write "共有 <font COLOR=#FF0000>" & totalnumber & "</font> 位用户&nbsp;&nbsp;<a href=" & filename & "?page=1&grade=" & Request("grade") & ">首 页</a>&nbsp;&nbsp;"
		Response.Write "<a href=" & filename & "?page=" & CurrentPage - 1 & "&grade=" & Request("grade") & ">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
	End If
	If n - CurrentPage < 1 Then
		Response.Write "下一页&nbsp;&nbsp;尾 页 "
	Else
		Response.Write "<a href=" & filename & "?page=" & (CurrentPage + 1) & "&grade=" & Request("grade") & ">下一页</a>"
		Response.Write "&nbsp;&nbsp;<a href=" & filename & "?page=" & n & "&grade=" & Request("grade") & ">尾 页</a>"
	End If
			Response.Write " 转到&nbsp;<select name='page' size='1' style=""font-size: 9pt"" onChange='javascript:submit()'>" & vbCrLf
			For ii = 1 To n
				Response.Write "<option value='" & ii & "' "
				If CurrentPage = CInt(ii) Then
					Response.Write "selected "
				End If
				Response.Write ">第" & ii & "页</option>"
			Next
			Response.Write "</select> " & vbCrLf
	Response.Write "</td></tr></FORM></table>" & vbCrLf
End Sub

Private Sub deldata()
	conn.Execute ("delete from user where userid=" & Request.QueryString("userid"))
	Response.Redirect ("admin_user.asp")
	 Err.Raise -19691969
End Sub

Private Sub userModify()
	SQL = "select * from [NC_user] where userid=" & Request("userid")
	Rs.Open SQL, conn, 1, 1
	Response.Write "<form method=Post name=""myform"" action=""admin_user.asp?action=save"">" & vbCrLf
	Response.Write "<table width=""85%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""1"" class=""tableBorder"">" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <th colspan=""2"">"
	Response.Write Rs("username")
	Response.Write " 的详细资料</th>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td width=""25%"" height=""22"" align=""right"" nowrap class=""forumRowHighlight"">用户名：</td>" & vbCrLf
	Response.Write " <td width=""75%"" class=""forumRow"">　<font COLOR=#FF0000>"
	Response.Write Rs("username")
	Response.Write "</font></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">真实姓名：</td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　"
	Response.Write Rs("truename")
	Response.Write " </td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">联系电话：</td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　"
	Response.Write Rs("usertel")
	Response.Write "</td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">OICQ： </td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　"
	Response.Write Rs("oicq")
	Response.Write "</td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">邮政编码：</td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　"
	Response.Write Rs("postcode")
	Response.Write "</td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">联系地址：</td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　"
	Response.Write Rs("address")
	Response.Write "</td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">登陆次数： </td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　<font COLOR=#FF0000>"
	Response.Write Rs("loginum")
	Response.Write "</font> 次</td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">最后登陆IP地址： </td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　<font COLOR=#FF0000>"
	Response.Write Rs("userip")
	Response.Write "</font></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">最后登陆时间： </td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　<font COLOR=#FF0000>"
	Response.Write Rs("logintime")
	Response.Write "</font> </td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">用户注册时间： </td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　"
	Response.Write Rs("regtime")
	Response.Write "</td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">用户状态： </td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　<font COLOR=#FF0000>"
	If Rs("islock") = 0 Then
		Response.Write "<B>正常</B>"
	Else
		Response.Write "<B>锁定</B>"
	End If
	Response.Write "</font></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <th colspan=""2"">修改 "
	Response.Write Rs("username")
	Response.Write " 的相关资料 如果不修改的部分请留空</th>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">账户身份： </td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　<select name=""grade"">" & vbCrLf
	Set Rs1 = Server.CreateObject("adodb.recordset")
	Set Rs1 = conn.Execute("select * from NC_UserGroup order by groupid")
	Do While Not Rs1.EOF
		Response.Write "<option value="""
		Response.Write Rs1("Grades")
		Response.Write """ "
		If Trim(Rs1("grades")) = "" & Rs("Grade") & "" Then
			Response.Write " selected"
		End If
		Response.Write ">"
		Response.Write Rs1("GroupName")
		Response.Write "</option>" & vbCrLf
		Rs1.movenext
	Loop
	Rs1.Close
	Set Rs1 = Nothing
	Response.Write " </select></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">账户点数： </td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　<input name=""money"" type=""text"" size=""10"" value="""
	Response.Write Rs("money")
	Response.Write """></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">用户邮箱：</td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　<input name=""usermail"" type=""text"" size=""25"" value="""
	Response.Write Rs("usermail")
	Response.Write """></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">用户答案：</td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　<input name=""answer"" type=""text"" size=""25"" value=""""></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" nowrap class=""forumRowHighlight"">用户密码：</td>" & vbCrLf
	Response.Write " <td class=""forumRow"">　<input name=""password"" type=""text"" size=""25"" value=""""></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""center"" colspan=""2"" class=""forumRow"">" & vbCrLf
	Response.Write "<INPUT type=hidden name=userid value="""
	Response.Write Rs("userid")
	Response.Write """>" & vbCrLf
	Response.Write "<INPUT type=hidden name=username value="""
	Response.Write Rs("username")
	Response.Write """>　" & vbCrLf
	Response.Write "<INPUT onclick=javascript:history.go(-1) type=button value="" 返回上一页"" class=button>　" & vbCrLf
	Response.Write "<input type=""submit"" name=""Submit"" class=button value=""确认修改""></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write "</table></form>" & vbCrLf
	Rs.Close
End Sub

Private Sub saveModify()
	If founderr = False Then
		SQL = "select * from [NC_user] where userid=" & Request("userid")
		Rs.Open SQL, conn, 1, 3
		If Request.Form("password") <> "" Then
			Rs("password") = md5(Request.Form("password"))
		End If
		If Request.Form("grade") <> "" Then
			Rs("grade") = Request.Form("grade")
		End If
		If Request.Form("money") <> "" Then
			Rs("money") = Request.Form("money")
		End If
		If Request.Form("usermail") <> "" Then
			Rs("usermail") = Request.Form("usermail")
		End If
		If Request.Form("answer") <> "" Then
			Rs("answer") = md5(Request.Form("answer"))
		End If
		Rs.update
		Rs.Close
		Set Rs = Nothing
		NC_Admin.Succeed_Msg ("<li>用户 " & Request.Form("username") & " 的资料已经修改成功!</li>")
		Err.Raise -19691969
	End If
End Sub

Private Sub addMoney()
	If founderr = False Then
		SQL = "select * from [NC_user] where userid=" & Request("userid")
		Rs.Open SQL, conn, 1, 3
		If Request.Form("money") <> "" Then
			Rs("money") = Request.Form("money")
		End If
		Rs.update
		Rs.Close
		Set Rs = Nothing
		NC_Admin.Succeed_Msg ("<li>您已经在 " & Request.Form("username") & " 的账户上面成功添加点数:" & Request.Form("money") & " </li>")
		Err.Raise -19691969
	End If
End Sub

Private Sub userMoney()
	SQL = "select * from [NC_user] where userid=" & Request("userid")
	Rs.Open SQL, conn, 1, 1
	Response.Write "<form method=Post name=""myform"" action=""admin_user.asp?action=add"">" & vbCrLf
	Response.Write "<table width=""85%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""1"" class=""tableBorder"">" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <th colspan=""2"">为 "
	Response.Write Rs("username")
	Response.Write " 增加点数</th>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td width=""30%"" height=""22"" align=""right"" nowrap class=""forumRowHighlight"">请输入要添加的金钱数</td>" & vbCrLf
	Response.Write " <td width=""70%"" class=""forumRow"">　<input name=""money"" type=""text"" size=""10"" value="""
	Response.Write Rs("money")
	Response.Write """> 元</td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""center"" colspan=""2"" class=""forumRow"">" & vbCrLf
	Response.Write "<INPUT type=hidden name=userid value="""
	Response.Write Rs("userid")
	Response.Write """>" & vbCrLf
	Response.Write "<INPUT type=hidden name=username value="""
	Response.Write Rs("username")
	Response.Write """>　" & vbCrLf
	Response.Write "<INPUT onclick=javascript:history.go(-1) type=button value="" 返回上一页"" class=button>　" & vbCrLf
	Response.Write "<input type=""submit"" name=""Submit"" class=button value=""确认添加""></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write "</table></form>" & vbCrLf
	Rs.Close
End Sub
%>
