<!--#include file="Conn.asp"--><%Checklogin("用户管理")%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理区域</title>
<link rel="stylesheet" href="css/common.css" type="text/css" />
<script language="javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/js.js"></script>
<script>
function chkuserform(){
var id = document.getElementById("id").value,
_loginuser = document.getElementById("loginuser"),
_loginpower = document.getElementById("loginpower"),
_loginpwd = document.getElementById("loginpwd"),
_loginpwd1 = document.getElementById("loginpwd1"),
_loginname = document.getElementById("loginname");
_save = document.getElementById("save");

if(_save.disabled)return false;

if( _loginuser.value =='' ){
alert('请输入用户帐号');
_loginuser.focus();
return false;
}
if( _loginpower.value =='' ){
alert('请选择所属权限');
_loginpower.focus();
return false;
}

if( _loginpwd.value =='' && id =='' ){
alert('请输入用户密码');
_loginpwd.focus();
return false;
}
if( _loginpwd.value != _loginpwd1.value ){
alert('两次密码输入不相同');
_loginpwd1.focus();
return false;
}

if( _loginname.value =='' ){
alert('请输入用户昵称');
_loginname.focus();
return false;
}

_save.disabled = true;

}

</script>
</head>

<body>
<div id="man_zone">
<%
Act = Request.QueryString("act")
If act = "save" Then
isedit = False
id = Request.Form("id")
If id<>"" And IsNumeric(id) Then isedit = True
loginuser = TextEnCode(Request.Form("loginuser"))
loginpower = Request.Form("loginpower")
loginpwd = TextEnCode(Request.Form("loginpwd"))
loginname = TextEnCode(Request.Form("loginname"))

If isedit Then
	If Conn.Execute("Select Count(id) From login Where loginuser = '"&loginuser&"' And id<>"&id)(0)>0 Then Response.Write "<script>alert('Sorry，该用户已经存在，请检查更换');history.back()</script>":Conn.Close:Set Conn=Nothing:Response.End
	Set Rs = Server.CreateObject("ADODB.RecordSet")
	Rs.Open "Select loginuser,loginpower,loginpwd,loginname,loginstate From login Where id="&id,Conn,1,3
	If Not Rs.Bof And Not Rs.Eof Then
		Rs(0)=loginuser
		If loginpower<>"" And IsNumeric(loginpower) Then Rs(1) = loginpower
		If loginpwd<>"" Then Rs(2)=MD5(loginpwd)
		Rs(3) = loginname
	Else
		'特殊情况不能添加
		Response.Write "<script>alert('Sorry，该用户已被删除，请重新添加');location.href='user.asp?act=add'</script>"
		Rs.Close:Set Rs=Nothing:Conn.Close:Set Conn=Nothing:Response.End
	End If
	Rs.Update:Rs.Close:Set Rs=Nothing:Conn.Close:Set Conn=Nothing
	Page = Request.QueryString("Page")
	Keys=Server.UrlEnCode(Request.QueryString("Keys"))
	Ord=Server.UrlEnCode(Request.QueryString("Ord"))
	Response.Redirect "?keys="&Keys&"&Ord="&Ord&"&Page="&Page
Else
	If Conn.Execute("Select Count(id) From login Where loginuser = '"&loginuser&"'")(0)>0 Then Response.Write "<script>alert('Sorry，该用户已经存在，请检查更换');history.back()</script>":Conn.Close:Set Conn=Nothing:Response.End
	If loginpower = "" Or Not IsNumeric(loginpower) Then loginpower = 0
	Conn.Execute("Insert into login(loginuser,loginpower,loginpwd,loginname,loginstate) values('"&loginuser&"',"&loginpower&",'"&MD5(loginpwd)&"','"&loginname&"',1)")
	Conn.Close:Set Conn=Nothing:Response.Redirect "?"
End If
Conn.Close:Set Conn=Nothing

Response.End
End If 'end save


If Act = "add" Or Act = "edit" Then
id = Request.QueryString("id")
isedit = False
If id<>"" And IsNumeric(id) Then isedit=True
If isedit Then
	Set Rs = Server.CreateObject("ADODB.RecordSet")
	Rs.Open "Select loginuser,loginname,loginlasttime,loginlastip,loginthistime,loginthisip,loginpower,logincount From login Where id="&id,Conn,1,1
	If Not Rs.Bof And Not Rs.Eof Then
		loginuser=Rs(0):loginname=Rs(1):loginlasttime=Rs(2):loginlastip=Rs(3):loginthistime=Rs(4):loginthisip=Rs(5):loginpower=Rs(6):logincount=Rs(7)
	Else
		isedit = False
	End If
	Rs.Close:Set Rs=Nothing
End If

Page = Request.QueryString("Page")
Keys=Server.UrlEnCode(Request.QueryString("Keys"))
Ord=Server.UrlEnCode(Request.QueryString("Ord"))
hrefstr = "?keys="&Keys&"&Ord="&Ord&"&Page="&Page
%>
	<form name="form1" method="post" action="<%=hrefstr%>&act=save" onsubmit="return chkuserform()">
	<table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
		<tbody>
			<tr>
				<th width="8%">用户帐号</th>
				<td><input type="text" id="loginuser" name="loginuser" value="<%=loginuser%>" class="txt1" /><input type="hidden" id="id" name="id" value="<%=id%>" /></td>
			</tr>
			<tr>
				<th width="8%">权限组</th>
				<td>
					<select id="loginpower" name="loginpower">
						<option value="">请选择所属权限</option>
<%
Set Rs1 = Server.CreateObject("ADODB.RecordSet")
Rs1.Open "Select id,powername From power Where id<>1 Order By id Desc",Conn,1,1
Do While Not Rs1.Bof And Not Rs1.Eof
%>
						<option value="<%=Rs1(0)%>" <%If loginpower=Rs1(0) Then Response.Write "Selected=""Selected"""%>><%=Rs1(1)%></option>
<%
Rs1.MoveNext
Loop
Rs1.Close:Set Rs1=Nothing:Conn.Close:Set Conn=Nothing
%>

					</select>
				</td>
			</tr>
			<tr>
				<th width="8%">用户密码</th>
				<td><input type="password" id="loginpwd" name="loginpwd" class="txt1" /><%If isedit Then Response.Write "<span style=""color:red"">（不修改留空）</span>"%></td>
			</tr>
			<tr>
				<th width="8%">密码确认</th>
				<td><input type="password" id="loginpwd1" name="loginpwd1" class="txt1" /></td>
			</tr>

			<tr>
				<th width="8%">用户昵称</th>
				<td><input type="text" id="loginname" name="loginname" value="<%=loginname%>" class="txt1" /></td>
			</tr>
<%
If isedit Then
%>
			<tr>
				<th width="8%">上次登陆</th>
				<td><input type="text" id="loginlasttime" name="loginlasttime" value="<%=loginlasttime%>" disabled="disabled" class="txt1" /></td>
			</tr>
			<tr>
				<th width="8%">登陆IP</th>
				<td><input type="text" id="loginlastip" name="loginlastip" value="<%=loginlastip%>" disabled="disabled" class="txt1" /></td>
			</tr>
			<tr>
				<th width="8%">最后登陆</th>
				<td><input type="text" id="loginthistime" name="loginthistime" value="<%=loginthistime%>" disabled="disabled" class="txt1" /></td>
			</tr>
			<tr>
				<th width="8%">登陆IP</th>
				<td><input type="text" id="loginthisip" name="loginthisip" value="<%=loginthisip%>" disabled="disabled" class="txt1" /></td>
			</tr>
			<tr>
				<th width="8%">登陆次数</th>
				<td><input type="text" id="logincount" name="logincount" value="<%=logincount%>" disabled="disabled" class="txt1" /></td>
			</tr>
<%End If%>
			<tr>
				<th></th>
				<td><input type="submit" name="save" id="save" value="确定" class="btn1" /> <input type="reset" name="save" id="save" value="重置" class="btn1" /> <input type="button" value="返回" class="btn1" onClick="location.href='<%=hrefstr%>'" /></td>
			</tr>
		</tbody>
	</table>
	</form>
</div>
</body>
</html>
<%
Response.End
End If 'End add


If Act="postchk" Then

Keys = Server.UrlEnCode(Request.QueryString("Keys"))
Ord = Server.UrlEnCode(Request.QueryString("Ord"))
Page = Request.QueryString("Page")
chkact = Request.Form("chkact")
SqlStr = ""
For i = 1 To Request.Form("chkbox").Count
	If SqlStr<>"" Then
		SqlStr = SqlStr & " Or id="&Request.Form("chkbox")(i)
	Else
		SqlStr = " Where id="&Request.Form("chkbox")(i)
	End If
Next

Select Case chkact
Case "0":SqlStr = "Update login Set loginstate="&chkact&SqlStr
Case "1":SqlStr = "Update login Set loginstate="&chkact&SqlStr
Case Else:SqlStr = "Delete From login"&SqlStr
End Select

Conn.Execute(SqlStr):Conn.Close:Set Conn=Nothing
Response.Redirect "?Keys="&Keys&"&Ord="&Ord&"&Page="&Page
Response.End
End If	'End postchk


Keys=Request.QueryString("Keys")
Keyscode=TextEnCode(Keys)
Ord=Request.QueryString("Ord")
Page = Request.QueryString("Page")
If Ord="nstitle" Or Ord="nstitle Desc" Or Ord="nsaddtime" Or Ord="nsaddtime Desc" Or Ord="loginstate" Or Ord="loginstate Desc" Or Ord="nsord" Or Ord="nsord Desc" Then
	OrdStr=Ord&","
Else
	OrdStr=""
End If
Set Rs=Server.CreateObject("ADODB.RecordSet")
Rs.Open "Select id,loginuser,loginstate,loginname,(Select powername From power Where id=loginpower),logincount From login Where id<>1 And (loginuser like '%"&Keyscode&"%' Or loginname like '%"&Keyscode&"%') Order By "&OrdStr&"Id Desc",Conn,1,1
Keys=Server.UrlEnCode(Keys)
Ord=Server.UrlEnCode(Ord)
hrefstr = "?keys="&Keys
%>	
	<form id="form1" method="post" action="?act=postchk&Keys=<%=keys%>&Ord=<%=Ord%>&Page=<%=Page%>" onSubmit="return false" />
	<table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
		<thead>
			<tr>
				<th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
				<th width="6%">序号</th>
				<th width="20%"><a href="<%=hrefstr%><%If ord="loginuser" Then Response.Write "&ord=loginuser+Desc" Else Response.Write "&ord=loginuser"%>">用户帐号<%If Ord="loginuser" Then Response.Write "↓" Else If Ord="loginuser+Desc" Then Response.Write "↑"%></a></th>
				<th width="20%"><a href="<%=hrefstr%><%If ord="loginname" Then Response.Write "&ord=loginname+Desc" Else Response.Write "&ord=loginname"%>">用户昵称<%If Ord="loginname" Then Response.Write "↓" Else If Ord="loginname+Desc" Then Response.Write "↑"%></a></th>
				<th width="20%"><a href="<%=hrefstr%><%If ord="loginpower" Then Response.Write "&ord=loginpower+Desc" Else Response.Write "&ord=loginpower"%>">所在权限<%If Ord="loginpower" Then Response.Write "↓" Else If Ord="loginpower+Desc" Then Response.Write "↑"%></a></th>
				<th width="14%"><a href="<%=hrefstr%><%If ord="logincount" Then Response.Write "&ord=logincount+Desc" Else Response.Write "&ord=logincount"%>">登陆次数<%If Ord="logincount" Then Response.Write "↓" Else If Ord="logincount+Desc" Then Response.Write "↑"%></a></th>
				<th width="8%"><a href="<%=hrefstr%><%If ord="loginstate" Then Response.Write "&ord=loginstate+Desc" Else Response.Write "&ord=loginstate"%>">状态<%If Ord="loginstate" Then Response.Write "↓" Else If Ord="loginstate+Desc" Then Response.Write "↑"%></a></th>
				<th width="8%">操作</th>
			</tr>
		</thead>
		<tbody>

<%
If Not Rs.Bof And Not Rs.Eof Then
	Rs.PageSize = 10
	If Page = "" Then Page = 1
	If Page = "end" Then Page = Rs.PageCount
	If Not IsNumeric(Page) Or Page < 1 Then Page = 1
	Page = Cint(Page)
	If Page > Rs.PageCount Then Page = Rs.PageCount
	Rs.AbsolutePage = Page
	TempNum = Rs.PageSize * (Page - 1)
	
	Set Rs1=Server.CreateObject("ADODB.RecordSet")

	For i=1 To Rs.PageSize
		If Rs.Bof Or Rs.Eof Then Exit For
		TempNum=TempNum+1
%>
			<tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
				<td align="center"><input type="checkbox" name="chkbox" value="<%=Rs(0)%>" /></td>
				<td align="center"><%=TempNum%></td>
				<td align="center"><%=Rs(1)%></td>
				<td align="center"><%=Rs(3)%></td>
				<td align="center"><%=Rs(4)%></td>
				<td align="center"><%=Rs(5)%></td>
				<td align="center"><%If Rs(2)=1 Then Response.Write "正常" Else Response.Write "停用" End If%></td>
				<td align="center"><a href="?Keys=<%=keys%>&Ord=<%=Ord%>&Page=<%=Page%>&act=edit&id=<%=Rs(0)%>" class="ico_edit">修改</a></td>
			</tr>
<%
		Rs.MoveNext
	Next
Else
	If Keys="" Then
%>
			<tr>
				<td align="center" colspan="8">Sorry，当前暂无用户</td>
			</tr>

<%
	Else
%>
			<tr>
				<td align="center" colspan="8"><a href="?">Sorry，没有找到“<%=Keyscode%>”相关的用户，点击返回</a></td>
			</tr>
<%
	End If
End If
%>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="8">
					<div class="showpagebox">
<%
If Rs.PageCount > 1 Then
	PageName="?Keys="&Keys&"&Ord="&Ord&"&"
	Pagelen=3
	If Page>1 Then
		Response.Write "<a href="""&PageName&"Page=1"">首页</a>"
		Response.Write "<a href="""&PageName&"Page="&Page-1&""">上一页</a>"
	End If

	If Pagelen*2+1 >= Rs.PageCount Then
		StartPage=1:EndPage=Rs.PageCount
	Else
		If Page<=Pagelen+1 Then
			StartPage=1
			EndPage=Pagelen*2+1
		Else
			StartPage=Page-Pagelen
			EndPage=Page+Pagelen
		End If
		If Page+Pagelen>Rs.PageCount Then StartPage=Rs.PageCount-Pagelen*2:EndPage=Rs.PageCount
	End If

	For i = StartPage To EndPage
		If i = Page Then
			Response.Write "<a class=""current"">"&i&"</a>"
		Else
			Response.Write "<a href="""&PageName&"Page="&i&""">"&i&"</a>"
		End If
	Next

	If Page<Rs.PageCount Then
		If Rs.PageCount - Page > Pagelen Then Response.Write "<a href="""&PageName&"Page="&Rs.PageCount&""">..."&Rs.PageCount&"</a>"
		Response.Write "<a href="""&PageName&"Page="&Page+1&""">下一页</a>"
		Response.Write "<a href="""&PageName&"Page="&Rs.PageCount&""">尾页</a>"
	End If

	Response.Write "<input type=""text"" id=""Pagego"" value="""&Page&""" onFocus=""if(this.value == '"&Page&"'){this.value='';}"" onBlur=""if(this.value == ''){this.value='"&Page&"';}"" onKeyUp=""this.value=this.value.replace(/\D/g,'')"" onKeyDown=""if(event.keyCode==13){location.href='"&PageName&"Page='+document.getElementById('Pagego').value}"" />"
End If
%>					</div>
					<div class="searchbox"><input type="text" id="keys" value="<%If Keyscode="" Then Response.Write "请输入搜索关键词" Else Response.Write Keyscode%>" onFocus="if(this.value == '<%If Keyscode="" Then Response.Write "请输入搜索关键词" Else Response.Write Keyscode%>'){this.value='';}" onBlur="if(this.value == ''){this.value='<%If Keyscode="" Then Response.Write "请输入搜索关键词" Else Response.Write Keyscode%>';}" onKeyDown="if(event.keyCode==13){location.href='?Keys='+escape(document.getElementById('keys').value)}" /><input type="button" id="searchgo" value="go" onClick="location.href='?Keys='+escape(document.getElementById('keys').value)" /></div>
					<div class="postchkbox">
						<select id="chkact" name="chkact">
							<option value="1">正常</option>
							<option value="0">停用</option>
							<option value="-1">删除</option>
						</select>
						<input type="button" value="执行" onClick="postchk(2)" class="btn1" />
						<input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
					</div>
				</td>
			</tr>
		</tfoor>
	</table>
	</form>
<%Rs.Close:Set Rs=Nothing:Conn.Close:Set Conn=Nothing%>
</div>
</body>
</html>
