<!--#include file="users.asp" -->
<%
if session("user")="" then
	Response.redirect "index.asp"
	response.end
else
	Set admin = Server.CreateObject("ADODB.Recordset")
	asql="SELECT * FROM admin where admin='"&session("user")&"'"
	admin.OPEN asql, Conn,1,1
	if admin.eof and admin.bof then
		Response.redirect "index.asp"
		response.end
	else
		if session("pas")<>admin("pws") then
			Response.redirect "index.asp"
			response.end
		else
			if session("qx")<"2" then
				Response.redirect "index.asp"
				response.end
			end if
		end if
	end if
	admin.close
	set admin=nothing
end if
function strLength(str)
       ON ERROR RESUME NEXT
       dim WINNT_CHINESE
       WINNT_CHINESE    = (len("论坛")=2)
       if WINNT_CHINESE then
          dim l,t,c
          dim i
          l=len(str)
          t=l
          for i=1 to l
             c=asc(mid(str,i,1))
             if c<0 then c=c+65536
             if c>255 then
                t=t+1
             end if
          next
          strLength=t
       else 
          strLength=len(str)
       end if
       if err.number<>0 then err.clear
end function
if request("admin")<>"" then
	call add()
	response.end
end if
if request("edit")<>"" then
	call edit()
	response.end
end if
if request("delete")<>"" then
	call delete()
	response.end
end if
If request.querystring("page")="" Then
	absPageNum = 1
else
	absPageNum=cint(request.querystring("page"))
end if
RecordPerPage = 8
Set rss = Server.CreateObject("ADODB.Recordset")
sqs="SELECT * FROM admin"
rss.CursorType = adOpenStatic
rss.CacheSize = RecordPerPage
rss.OPEN sqs, Conn,1,1
rss.PageSize = RecordPerPage
Tol = rss.PageCount
		If Not(rss.EOF) Then
			rss.AbsolutePage = absPageNum
		End If
Set rs = Server.CreateObject("ADODB.Recordset")
sql="SELECT * FROM download"
rs.OPEN sql, Conn,1,1
%>
<!--#include file="code.asp" -->
<!--#include file="first.asp" -->
<table border=0 cellspacing=0 style='border-collapse:collapse' width=735 height=233 cellpadding=3>
<tr>
<td width=185 valign=top>
<!--#include file="inc.asp" -->
</td>
<td width=550 valign=top>
<center><br><table border=0 cellspacing=0 cellpadding=3 width=90%>
<tr><form action=user.asp?admin=add method=POST><td class=shadow2>
<b>添加用户：</b><br>
</td></tr><tr><td>
用户名 
<input type=text name=username size=12 class=border style='color:#000000; background-color:#efefef'> 
密码 
<input type=text name=password size=12 class=border style='color:#000000; background-color:#efefef'> 
<select size=1 name=groupid style='color:#000000; border-style:solid; border-width:1; background-color:#efefef'><option value='2'> 超级管理员 </option><option selected value='1'> 普通管理员 </option></select> 
<input type=submit value=提交 name=sendadd class=border style='color: #000000; background-color: #efefef'> 
<input type=reset value=重填 class=border style='color: #000000; background-color: #efefef'></td></form></tr></table><br>
<br><table border=0 cellspacing=0 cellpadding=3 width=90%><tr><td colspan=6><b>管理用户：</b></td></tr>
<tr bgcolor=#efefef><td width=10%>编号</td><td width=20%>用户名</td><td width=20%>密码</td><td width=20%>用户组</td><td width=15%> </td><td width=15%> </td></tr>
<%do while not rss.eof%>
<tr><td><%=rss("id")%></td><td><%=rss("admin")%></a></td><td><%=rss("pws")%></td><td><%=rss("qx")%></td><td><a href='user.asp?edit=<%=rss("id")%>'>编辑</a></td><td><a href='user.asp?delete=<%=rss("id")%>'>删除</a></td></tr>
<%
rss.movenext
loop
%>
</table><br><table border=0 cellspacing=0 cellpadding=3 width=500>
<tr><td align=center>
<%
for ppages=1 to rss.pagecount
if ppages=cint(absPageNum) then
%>
<b><font color=#000000>[<%=ppages%>]</font></b>
<%
else
%>
<a href='user.asp?page=<%=ppages%>'>[<%=ppages%>]</a>
<%
end if
next
abcd=absPageNum+1
if abcd>=rss.pagecount then
	abcd=rss.pagecount
end if
%>
</tr></td></table>
<br><br></td>
</tr>
</table>
<br><hr width=735>
<%
rss.close
set rss=nothing
%>
</body>
</html>
<%
sub add()
if trim(request("username"))<>"" then
	if request("password")<>"" then
		Set radd = Server.CreateObject("ADODB.Recordset")
		sqadd="SELECT * FROM admin"
		radd.OPEN sqadd, Conn,1,3
		radd.addnew
		radd("admin")=trim(request("username"))
		radd("pws")=request("password")
		radd("qx")=request("groupid")
		radd.update
		radd.close
		set radd=nothing
		response.write "添加完成"
		response.write "<a href=""user.asp"">返回</a>"
	else
		response.write "请输入用户密码"
		response.end
	end if
else
	response.write "请输入用户名"
	response.end
end if
end sub
sub edit()
Set rd = Server.CreateObject("ADODB.Recordset")
sqd="SELECT * FROM admin where id="&request("edit")
rd.OPEN sqd, Conn,1,3
if request("eadmin")="" then
%>
<form method="POST" action="user.asp?edit=<%=request("edit")%>&eadmin=yes">
<p>编号：<input type="text" name="adminid" size="3" readonly style="background-color: #C0C0C0; border: 1 solid #000000" value="<%=rd("id")%>"> 
用户名：<input type="text" name="adminname" size="10" readonly style="background-color: #C0C0C0; border: 1 solid #000000" value="<%=rd("admin")%>"> 
密码：<input type="text" name="adminpws" size="10" style="border: 1 solid #000000" value="<%=rd("pws")%>"> 
<select size="1" name="qxid" style="border: 1 solid #000000"> 
  <option value="" selected>更改权限设置</option>
  <option value="1">普通管理员</option>
  <option value="2">超级管理员</option>
</select> <input type="submit" value="提交" name="B1" style="border: 1 solid #000000"></p>
</form>
<%
else
	if request("adminpws")<>"" then
		if strLength(request("adminpws"))>40 then
			response.write "密码过长"
			response.end
		else
			if rd.eof and rd.bof then
				response.write "没有该管理员"
				response.end
			end if
			rd("pws")=request("adminpws")
			if request("qxid")<>"" then
				rd("qx")=request("qxid")
			end if
			rd.update
			response.write "修改完成"
			response.write "<a href=""user.asp"">返回</a>"
		end if
	else
		response.write "请输入用户密码"
		response.end
	end if
end if
rd.close
set rd=nothing
end sub
sub delete()
if request("dadmin")="" then
%>
<body topmargin="120">
<form method="POST" action="user.asp?delete=<%=request("delete")%>&dadmin=yes">

<p align="center">确认删除</p>
<p align="center"><input type="submit" value="提交" name="B1"> <a href="user.asp">返回</a></p>

</form> 
</body>
<%
else
	Set re = Server.CreateObject("ADODB.Recordset")
	sqe="SELECT * FROM admin where id="&request("delete")
	re.OPEN sqe, Conn,1,3
	if re.eof and re.bof then
		response.write "没有该管理员"
		response.end
	end if
	re.delete
	re.close
	set re=nothing
	response.write "删除完成"
	response.write "<a href=""user.asp"">返回</a>"
end if
end sub
rs.close
set rs=nothing
conn.close
set conn=nothing
%>