<!--#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 type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></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
em_user=TextEnCode(Request.Form("em_user"))
em_password=TextEnCode(Request.Form("em_password"))
re_password=TextEnCode(Request.Form("re_password"))
em_role=Request.Form("em_role")
em_code=TextEnCode(Request.Form("em_code"))
em_email=TextEnCode(Request.Form("em_email"))
em_tel=TextEnCode(Request.Form("em_tel"))
NullPwd=False

If em_password="" or IsNull(em_password) Then
   NullPwd=True
End If 
 
If em_password<>re_password Then
	conn.close
	Set conn=Nothing
	Response.write "<script>alert('两次密码输入不一致');history.back();</script>"
	Response.End
End If


	If Isedit Then
	  Set Rs=Server.CreateObject("ADODB.RecordSet")
	  Rs.Open "Select * From employee where Id="&Id,conn,1,3
	  If Not Rs.bof and Not Rs.eof Then
		Rs("em_user")=em_user
		If NullPwd Then Rs("em_password")=Rs("em_password") Else Rs("em_password")=MD5(em_password) End If
		Rs("em_role")=em_role
		Rs("em_code")=em_code
		Rs("em_email")=em_email	
		Rs("em_tel")=em_tel
		Rs.Update
	  End If
		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
		Response.End  
	Else

		If NullPwd Then em_password="MTB"&em_code End If
		
		Conn.Execute("Insert into employee(em_user,em_password,em_role,em_code,em_email,em_tel) values('"&em_user&"','"&MD5(em_password)&"',"&em_role&",'"&em_code&"','"&em_email&"','"&em_tel&"')")
		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 * From employee Where id="&id,Conn,1,1
	If Not Rs.Bof And Not Rs.Eof Then
		em_user=TextUnCode(Rs("em_user"))
		em_role=Rs("em_role")
		em_code=TextUnCode(Rs("em_code"))
		em_email=TextUnCode(Rs("em_email"))
		em_tel=TextUnCode(Rs("em_tel"))
	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 subform2();">
	<table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1" >
		<tbody>
			<tr>
				<th width="8%">用户名</th>
				<td><input type="text" id="em_user" name="em_user" value="<%=em_user%>" required class="txt-short" /><input type="hidden" name="id" value="<%=id%>" /></td>
			</tr>
			<tr>
				<th width="8%">密码</th>
				<td><input type="password" id="em_password" name="em_password" value="" class="txt-short"/>
			</tr>	
			<tr>
				<th width="8%">重复密码</th>
				<td><input type="password" id="re_password" name="re_password" value="" class="txt-short"/>
			</tr>				
			<tr>
				<th width="8%">工号</th>
				<td><input type="text" id="em_code" name="em_code" value="<%=em_code%>" class="txt1" /></td>
			</tr>		
			<tr>
				<th width="8%">角色</th>
				<td><select name="em_role">
									<option value="0">组长</option>						
							<%
								Set Rs1=server.CreateObject("ADODB.RecordSet")
								    Rs1.Open "Select id,em_user from employee where em_role=0",conn,1,1
									    Do while not Rs1.bof and not Rs1.eof
							%>
									<option value="<%=Rs1("id")%>"  <%IF Rs1("id")=em_role Then Response.write "selected=""selected"""%>>组长:<%=Rs1("em_user")%></option>
							<%
										Rs1.moveNext
										loop
									Rs1.close
								Set	Rs1=Nothing
							%>
					</select>
				</td>
			</tr>			
			<tr>
				<th width="8%">邮箱</th>
				<td><input type="text" id="em_email" name="em_email" value="<%=em_email%>" class="txt1" /></td>
			</tr>				
			<tr>
				<th width="8%">手机</th>
				<td><input type="text" id="em_tel" name="em_tel" value="<%=em_tel%>" class="txt1" /></td>
			</tr>			

			<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


SqlStr = "Delete From employee"&SqlStr


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")

Set Rs=Server.CreateObject("ADODB.RecordSet")
Rs.Open "Select id,em_user,em_code,em_role from employee where em_user like '%"&Keyscode&"%' or em_code like '%"&Keyscode&"%' Order By 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>姓名</th>				
				<th>工号</th>			
				<th>角色</th>				
				<th>操作</th>				
			</tr>
		</thead>
		<tbody>

<%
If Not Rs.Bof And Not Rs.Eof Then
	Rs.PageSize = 13
	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:classid=Rs(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("em_user")%></td>							
				<td align="center"><%=Rs("em_code")%></td>		
				<td align="center"><%if Rs("em_role")=0 Then response.write "组长" Else response.write "组员"%>
				</td>						
				<th><a class="ico_edit" href="?act=edit&Keys=<%=keys%>&Ord=<%=Ord%>&Page=<%=Page%>&id=<%=Rs("id")%>">修改</a></th>					
			</tr>
<%
		Rs.MoveNext
	Next
Else
	If Keys="" Then
%>
			<tr>
				<td align="center" colspan="6">Sorry,当前暂无信息</td>
			</tr>

<%
	Else
%>
			<tr>
				<td align="center" colspan="6"><a href="?">Sorry,没有找到“<%=Keyscode%>”相关的信息,点击返回</a></td>
			</tr>
<%
	End If
End If
%>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="6">
					<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(1)" class="btn1" />
						<input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
					</div>
				</td>
			</tr>
		</tfoor>
	</table>
	</form>
<%Rs.Close:Set Rs=Nothing:Set Rs1=Nothing:Conn.Close:Set Conn=Nothing%>
</div>
</body>
</html>