<!--#include file="conn.asp"-->
<!--#include file="../../inc/filter.asp"-->
<!--#include file="../../inc/md5.asp"-->

<%
Rem 获得管理员列表
sub get_admin_list()
	dim list
	list=""
	set rs_list=Server.CreateObject("ADODB.RecordSet")
	rs_list.open "select * from [fksf_admin]",conn,1,1
	for i=1 to rs_list.recordcount
%>
		<tr class="tdbg" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#cccccc'" style="padding: 0px 2px;">
			<td align="center"><%=rs_list("adminname")%></td>
			<td align="center"><font color="#FF0000">超级管理员</font></td>
			<td align="center"><a href="admin_update_form.asp?id=<%=rs_list("adminname")%>">修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="admin_delete.asp?id=<%=rs_list("adminname")%>">删除</a></td></tr>
<%
		rs_list.movenext()
	next
	rs_list.close()
	set rs_list=nothing
	response.Write(list)
end sub
%>

<%
Rem 管理员管理入口
sub admin_access()
	action=trim(request("action"))
	if(action="") then
		response.Write("<script language=javascript>")
		response.Write("alert('传递判断参数不能为空');")
		response.Write("history.go(-1);")
		response.Write("</script>")
	else
		if(ChkBadWord(action)<>0) then
			response.Write("<script language=javascript>")
			response.Write("alert('传递判断参数包含非法字符');")
			response.Write("history.go(-1);")
			response.Write("</script>")
		else
			if(action="update") then
				call admin_update()'操作管理员更新密码
			else
				if(action="insert") then
					call admin_insert()'操作管理员添加
				else
					if(action="delete") then
						call admin_delete()'操作管理员删除
					end if
				end if
			end if
		end if
	end if
end sub
%>

<%
Rem 管理员更新密码
sub admin_update()
	adminname=trim(request("id"))
	adminpwd=trim(request("pwd"))
	adminpwd2=trim(request("pwd2"))
	
	if(adminname="" or adminpwd="" or adminpwd2="") then
		response.Write("<script language=javascript>")
		response.Write("alert('参数不能为空');")
		response.Write("history.go(-1);")
		response.Write("</script>")
	else
		if(ChkBadWord(adminname)<>0 or ChkBadWord(adminpwd)<>0 or ChkBadWord(adminpwd2)<>0) then
			response.Write("<script language=javascript>")
			response.Write("alert('参数包含非法字符');")
			response.Write("history.go(-1);")
			response.Write("</script>")
		else
		if(adminpwd<>adminpwd2) then
			response.Write("<script language=javascript>")
			response.Write("alert('两次密码输入不一致');")
			response.Write("history.go(-1);")
			response.Write("</script>")
		else
			set rs_admin=Server.CreateObject("ADODB.RecordSet")
			rs_admin.open "select * from [fksf_admin] where adminname='"&adminname&"'",conn,1,3
			if(rs_admin.eof) then
				rs_admin.close()
				set rs_admin=nothing
				response.Write("<script language=javascript>")
				response.Write("alert('本系统无该管理员');")
				response.Write("window.location='main_body.asp';")
				response.Write("</script>")
			else
				rs_admin("adminname")=adminname
				rs_admin("adminpwd")=MD5(adminpwd)
				rs_admin.update()
				rs_admin.close()
				set rs_admin=nothing
				response.Write("<script language=javascript>")
				response.Write("alert('管理员更改密码成功');")
				response.Write("window.location='main_body.asp';")
				response.Write("</script>")
			end if
		end if
		end if
	end if
end sub
%>

<%
Rem 添加管理员
sub admin_insert()
	adminname=trim(request("id"))
	adminpwd=trim(request("pwd"))
	adminpwd2=trim(request("pwd2"))
	
	if(adminname="" or adminpwd="" or adminpwd2="") then
		response.Write("<script language=javascript>")
		response.Write("alert('参数不能为空');")
		response.Write("history.go(-1);")
		response.Write("</script>")
	else
		if(ChkBadWord(adminname)<>0 or ChkBadWord(adminpwd)<>0 or ChkBadWord(adminpwd2)<>0) then
			response.Write("<script language=javascript>")
			response.Write("alert('参数包含非法字符');")
			response.Write("history.go(-1);")
			response.Write("</script>")
		else
		if(adminpwd<>adminpwd2) then
			response.Write("<script language=javascript>")
			response.Write("alert('两次密码输入不一致');")
			response.Write("history.go(-1);")
			response.Write("</script>")
		else
			set rs_admin=Server.CreateObject("ADODB.RecordSet")
			rs_admin.open "select * from [fksf_admin] where adminname='"&adminname&"'",conn,1,3
			if(not rs_admin.eof) then
				rs_admin.close()
				set rs_admin=nothing
				response.Write("<script language=javascript>")
				response.Write("alert('该管理员已存在');")
				response.Write("window.location='main_body.asp';")
				response.Write("</script>")
			else
				rs_admin.addnew()
				rs_admin("adminname")=adminname
				rs_admin("adminpwd")=MD5(adminpwd)
				rs_admin.update()
				rs_admin.close()
				set rs_admin=nothing
				response.Write("<script language=javascript>")
				response.Write("alert('管理员添加成功');")
				response.Write("window.location='main_body.asp';")
				response.Write("</script>")
			end if
		end if
		end if
	end if
end sub
%>

<%
Rem 删除管理员
sub admin_delete()
	adminname=trim(request("id"))
	
	if(adminname="") then
		response.Write("<script language='javascript'>")
		response.Write("alert('输入参数不能为空');")
		response.Write("history.go(-1);")
		response.Write("</script>")
	else
		if(ChkBadWord(adminname)<>0) then
			response.Write("<script language='javascript'>")
			response.Write("alert('输入参数中含有非法字符');")
			response.Write("window.location='main_body.asp';")
			response.Write("</script>")
		else
			conn.execute("delete from [fksf_admin] where adminname='"&adminname&"'")
			response.Write("<script language='javascript'>")
			response.Write("alert('管理员删除成功');")
			response.Write("window.location='main_body.asp';")
			response.Write("</script>")
		end if
	end if
end sub
%>

