<%@ Language=VBScript%>
<%
Response.Buffer=false
Response.Expires=0
%>
<!-- #include file="../dsn.asp" -->
<!-- #include file="../links.asp" -->
<%
if session("adminusername")="" then
		session("xhy")=1
		Response.Redirect linkwarn
end if
showok=Request.QueryString ("showok")
id=cint(Request.QueryString("id"))
pid=cint(Request.QueryString("pid"))
ppid=cint(Request.QueryString("ppid"))
pageno=Request.QueryString("pageno")
mode=Request.QueryString ("mode")
htmlname=linkadminuser&"?ppid="&ppid&"&pid="&pid
addhtml=linkadmin&"?ppid="&ppid&"&pid="&pid
set cn=Server.CreateObject("ADODB.Connection")
cn.Open mycnstr
set rs=server.CreateObject("ADODB.Recordset")
set rs1=server.CreateObject("ADODB.Recordset")
set rs2=server.CreateObject("ADODB.Recordset")
if ppid<>0 then
		sqltext="select title from scool where id="&ppid
		rs1.Open sqltext,cn,1,1
		if not rs1.EOF then
				scoolname=rs1("title")
		end if
		rs1.Close 
end if
if pid<>0 then
		sqltext="select title from classes where id="&pid
		rs1.Open sqltext,cn,1,1
		if not rs1.EOF then
				classesname=rs1("title")
		end if
		rs1.Close 
end if
htmltitle="基本数据管理"
txtname="名称"
tabname="adminuser"
if id<>0 then
		sqltext1="select * from adminuser where id="&id
		rs1.Open sqltext1,cn,1,1
		username=rs1("username")
		realname=rs1("relname")		
		password=rs1("userpass")
		password2=rs1("userpass")
		authority=rs1("adminflag")
		if authority=1 then
				qxflag="111111111"
			else			
				qxflag=rs1("adminqx")
		end if
		rs1.Close 
	else
		authority="0"
end if
if Request.ServerVariables("REQUEST_METHOD")="POST" and mode<>"999" then
		if not isempty(request("sel")) then
     		idlist=request("sel")
     		if instr(idlist,",")>0 then
				dim idarr
				idArr=split(idlist)
				for i = 0 to ubound(idarr)
	       			delid=clng(idarr(i))
	       			call setupdate(delid,mode)
				next
			else
				delid=clng(idlist)
				call setupdate(delid,mode)
			end if	
		end if
		delid=0
		Response.Redirect htmlname
end if
  sub setupdate(id,mm)
    if mm="888" then
		sqltext3="delete from "+tabname+" where id="&id
		cn.Execute sqltext3
	elseif  mm="777" then
		sqltext3="update "+tabname+" set enable=1 where id="&id
		cn.Execute sqltext3
	elseif  mm="666" then
		sqltext3="update "+tabname+" set enable=0 where id="&id
		cn.Execute sqltext3    
    end if
  end sub  

if Request.ServerVariables("REQUEST_METHOD")="POST" and mode="999" then
	newname=Request.Form("username")
	realname=Request.Form("realname")
	password=Request.Form("password")
	authority=Request.Form("authority")
	password2=password
	sqltext="select * from scool where enable=1 order by pl"
	rs.Open sqltext,cn,1,1
	gs=rs.RecordCount 
	rs.Close 
	gs=gs
		if id=0 then
				sqltext3="select * from adminuser where username='"+newname+"'"
				rs2.Open sqltext3,cn,1,1
				if not rs2.EOF then
						errtxt="用户编号:“"&newname&"”已被别人使用，请换号重试！"
						newname=""
						password=""
						password2=""
					else
							sqltext2="select * from adminuser"
							rs1.Open sqltext2,cn,1,2
							rs1.AddNew
							rs1("username")=newname
							rs1("relname")=realname
							rs1("userpass")=password	
							rs1("adminflag")=authority
							for i=1 to gs
									checksel=Request.Form("qxflag"&i)
									if checksel="1" then
											adminqx=adminqx+"1"
										else
											adminqx=adminqx+"0"
									end if
							next
							rs1("adminqx")=adminqx
							rs1("enable")=1
							rs1.Update
							id=rs1("id") 
							rs1.Close
				end if
				rs2.Close 
			else
				sqltext3="select * from adminuser where id<>"&id&" and username='"+newname+"'" 
				rs2.Open sqltext3,cn,1,1
				if not rs2.EOF then
						errtxt="用户编号:“"&newname&"”已被别人使用，请换号重试！"
						newname=""
						password=""
						password2=""
					else
						sqltext2="select * from adminuser where id="&id
						rs1.Open sqltext2,cn,1,2
						rs1("username")=newname
						rs1("relname")=realname
						rs1("userpass")=password	
						rs1("adminflag")=authority
						for i=1 to gs
								checksel=Request.Form("qxflag"&i)
								if checksel="1" then
										adminqx=adminqx+"1"
									else
										adminqx=adminqx+"0"
								end if
						next
						rs1("adminqx")=adminqx
						rs1.Update 
						rs1.Close 
				end if
				rs2.Close 
		end if
		if err<>1 then Response.Redirect htmlname
end if
%>
<html>
<head>
<title><%=htmltitle%></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {font-size: 12px; color: #000000; font-family: 宋体}
td {font-size: 12px; color: #000000; font-family: 宋体;line-height:130%}
.t1 {font:12px 宋体;color=000000} 
.t2 {font:12px 宋体;color:ffffff} 
.t3 {font:12px 宋体;color:336699} 
.t4 {font:12px 宋体;color:ff0000} 
.t5 {font:12px 宋体;color:ff6600} 


.bt1 {font:14px 宋体;color=000000} 
.bt2 {font:12px 宋体;color:ffffff} 
.bt3 {font:14px 宋体;color:336699} 
.bt4 {font:14px 宋体;color:ff0000} 
.bt5 {font:14px 宋体;color:0000ff}
.bt10 {font:14px 宋体;color:0000ff}

.td1 {font-size:12px;background-color:#3388bb;color:#ffffff}
.td2 {font-size:12px;background-color:#ffffff;color:#000000;}

A:link {color: #000077}
A:visited {color: #000077}
A:hover {color: #ff0000}

A.r1:link {text-decoration:none;color:#304556;}
A.r1:visited {text-decoration:none;color:#304556;}
A.r1:hover {text-decoration:underline;color:ff6600;}

A.r2:link {text-decoration:none;color:#ffffff;}
A.r2:visited {text-decoration:none;color:#ffffff;}
A.r2:hover {text-decoration:underline;color:cccc00;}

-->
</style>
</head>
<body topmargin=5>
<table width="100%" align=center>
	<tr>
	<td valign="top" align="left" width="100%">
		<table width="100%" height="20" border="0">
			<tr>
			<td style="font-size:12px;"></td>
			<td><font class="t5">当前位置： <%Response.Write (scoolname)%>→  <%Response.Write (classesname)%></font>
			</td>
			<td align="right">
			</td>
			</tr>
			</table>
			</td>
			</tr>
			</table>
		<table width="100%" height="20" border="0">
			<form action="<%=htmlname%>&mode=888" method=post name="listform">
			<tr>
		<%
		sqltext1="select * from "+tabname+" order by id"
		'Response.Write sqltext1
		rs1.Open sqltext1,cn,1,1
		listcs=8
		rs1.PageSize=listcs
		if pageno="" then 
			pageno=1
		else
			pageno=cint(pageno)	
		end if	
		if rs1.PageCount>0 then rs1.AbsolutePage=pageno%>
				<td class=t1 align="left" width=340>
			<a href="Javascript:window.location.reload()">[刷新列表]</a>
			<a href="<%=htmlname%>&showok=1">[增加]</a>
			<a href="javascript:delrows()">[删除]</a>
			<a href="javascript:shows()">[有效]</a>
			<a href="javascript:noshows()">[无效]</a>
		</td>
		<td>
		<%if rs1.PageCount>1 then%>
			[第<b><font color=ff6600><%=pageno%></font></b>页, 共<b><font color=ff6600><%=rs1.PageCount%></font></b>页<b><font color=ff6600><%=rs1.RecordCount%></font></b>条记录]	              	
			<%if pageno>1 then%>
				<a class=r href="<%=htmlname%>&pageno=1">首页</a>              
				<a class=r href="<%=htmlname%>&pageno=<%=pageno-1%>">上页</a>              
			<%end if              
			if pageno<rs1.PageCount then%>              
				<a class=r href="<%=htmlname%>&pageno=<%=pageno+1%>">下页</a>              
				<a class=r href="<%=htmlname%>&pageno=<%=rs1.PageCount%>">末页</a>              
			<%end if%>              
		<%end if              
		%>              
		</td></tr>
		</table>
       <table width="100%" border="0" cellspacing="1" cellpadding="1" style="font-size:14.5px;line-height:100%" height=250 valign=top>
        <tr><td height=100% valign=top>		
		<table width="100%" border="0" cellspacing="1" cellpadding="1" style="font-size:14.5px;line-height:100%">
			<tr bgcolor="666699" style="color:#ffffff" align="center">
				<td class=bt2>&nbsp;</td>
				<td class=bt2>ID号</td>
				<td class=bt2>是否有效</td>
				<td class=bt2>用户帐号</td>
				<td class=bt2>用户名称</td>
				<td class=bt2>管理权限</td>
				<td class=bt2>最后上线</td>
				<td class=bt2>IP</td>
				<td class=bt2>上线次数</td>
			</tr>
		<%
		i=0
		do while not rs1.EOF and i<listcs 
			if (i mod 2)=1 then
				Response.Write("<tr bgcolor=fefefe>")
			else
				Response.Write("<tr bgcolor=efefef>")
			end if	
		%>
		<td width="20" align="center">
		<%if trim(rs1("username"))<>"admin" then%>
				<input type="checkbox" name="sel" value="<%=(rs1("id"))%>">
		<%end if%>		
		</td>
		<td width=50 align="center"><%=rs1("id")%></td>
		<td width="70" align="center">
			<%if rs1("enable")=1 then 
				Response.Write "有效"
		    else
				Response.Write "<font color=red>无效</font>"
			end if%>
		</td>
		<td width="100" align="left"><a href="<%=htmlname%>&id=<%=rs1("id")%>&showok=1"><%=rs1("username")%></a></td>
		<td align=left><%=trim(rs1("relname"))%></td>
		<td width="80" align="center">
				<%Select Case trim(rs1("adminflag"))
					case "0"
						Response.Write("<font color=black>普通管理员</font>")
					case "1"
						Response.Write("<font color=red>高级管理员</font>")
				 end select		
				%>
		</td>
		<td width=200 align="left"><%=rs1("logindate")%></td>
		<td width="110" align=center><%=trim(rs1("loginip"))%></td>
		<td width=60 align="right"><%=rs1("logincount")%></td>
		</tr>
	    <%rs1.MoveNext 
			i=i+1
	    loop%>
	    </form>
		</table>
	  </td></tr>
	 </table>	
	 <%if showok="1" then%>
		<table width="100%" border="0" cellspacing="1" cellpadding="1">
		  <tr bgcolor="666699" style="color:#ffffff" align="center">
		    <td>
		    </td>
		  </tr>
		</table>
		<table width="100%" border="0" cellspacing="1" cellpadding="1" style="font-size:14.5px;line-height:100%">
		  <tr bgcolor="ffffff" style="color:#ffffff" align="center">
		    <td height=20 align=left><font color=red><b><%=errtxt%></b></font></td>
		  </tr>
		</table>
		<table width="100%" border="0" cellspacing="1" cellpadding="1" style="font-size:14.5px;line-height:100%">
		  <form action="<%=htmlname%>&id=<%=id%>&mode=999&showok=1" method=post name=editform onsubmit="return checkinput(editform)">
				<tr ><td colspan=3 align=center><font size=3 color="red"><b><%=errtxt%></b></font></td></tr>

	<tr><td width=70 align=right>用户编号：</td>
		<td class=td2><INPUT type="text" value="<%=username%>" name=username maxlength=15 size=20 <%if username<>"" then Response.Write ("STYLE=background-color:efefef readonly")%>><font color=red>*</font>
	<tr><td align=right>真实姓名：</td>
		<td class=td2><INPUT type="text" value="<%=realname%>" name=realname maxlength=12 size=20><font color=red>*</font>
		</td></tr>
	<tr><td align=right>密码：</td>
		<td class=td2><INPUT type="password" value="<%=password%>" name=password maxlength=15 size=15><font color=red>*</font>
		<font class=td3>不分大小写</font>
		</td></tr>
	<tr><td align=right>确认密码：</td>
		<td class=td2><INPUT type="password" value="<%=password2%>" name=password2 maxlength=15 size=15><font color=red>*</font>
		<font class=td3>请再次输入密码(两次密码需一致)</font>
		</td></tr>
	<tr><td align=right>管理权限：</td>
		<td class=td2>
			<input type=radio name=authority value="1" <%if authority="1" then Response.Write("checked")%>>高级管理员
			<%if username<>"admin" then%>
					<input type=radio name=authority value="0" <%if authority="0" then Response.Write("checked")%>>普通管理员
			<%end if%>
  	    </td>
	</tr>
	<tr><td align=right valign=top>权限分配：</td>
		<td class=td2>
		  <table>
		    <%sqltext="select * from scool where enable=1 order by pl"
		      rs.Open sqltext,cn,1,1
		      m=1
		      colzs=5
		      if rs.RecordCount mod colzs=0 then
						rowzs=int(rs.RecordCount/colzs)
					else
						rowzs=int(rs.RecordCount/colzs)+1
			  end if
			  for j=1 to rowzs%>
			  <tr>
		      <%for i=1 to colzs %>
		         <%if not rs.EOF then%>
						<td><input type=checkbox name=qxflag<%=m%> value="1" <%if mid(qxflag,m,1)="1" then Response.Write("checked")%>><%=trim(rs("title"))%></td>
				 <%
				 rs.MoveNext 
				 m=m+1
				 else%>
						<td>&nbsp;</td>		
				 <%end if%>
			  <%next%>	 		
			  </tr>
			  <%next
			  rs.Close %>
			  </table>
	    </td>
	</tr>
	<tr><td class=td2></td>
		<td class=td2><font color=ff0000>注：高级管理员具有完全权限</font>
  	    </td>
	</tr>
			<tr><td>&nbsp;</td><td><input type="submit" value="确定提交" name=s1>&nbsp;&nbsp;<input type="button" value="取消返回" name=re1 onClick="window.location.href='<%=htmlname%>'"></td></tr>
		 </form>
		</table>	
		<table width="100%" border="0" cellspacing="1" cellpadding="1">
		  <tr bgcolor="ffffff" style="color:#ffffff" align="center">
		    <td height=20 align=left></td>
		  </tr>
		</table>
	<%end if%>	
</body>
</html>
<script language="Javascript">
	
    function delrows()
    {
        if (confirm('您确认要删除你所选中的项目吗？')==true)
        {
			document.listform.action="<%=htmlname%>&mode=888";
			document.listform.submit();
		}	
    }
    function shows()
    {
		listform.action="<%=htmlname%>&mode=777";
        document.listform.submit();
    }
    function noshows()
    {
        document.listform.action="<%=htmlname%>&mode=666";
        document.listform.submit();
    }
	
	function checkinput(form)
	{
		var flag=true;
		if(form("username").value=="")
			{alert("请输入用户编号!");form("username").focus();flag=false;return flag}else{flag=true}	
		if(form("realname").value=="")
			{alert("请输入真实名称!");form("realname").focus();flag=false;return flag}else{flag=true}

		if(form("password").value=="")
			{alert("密码不能为空!");form("password").focus();flag=false;return flag}else{flag=true}
		if(form("password2").value!=form("password").value)
			{alert("两次密码不一致!");
			form("password").value="";
			form("password2").value="";
			form("password").focus();flag=false;return flag}else{flag=true}
		return flag;
			
	}	
</script>
