<!--#include file="admin_start.asp"-->
<%
dim id
dim ids
dim n_ids

id=request("id")
ids=request("ids")
ids=replace(ids," ","")
n_ids=""

if not MySys.check.isInteger(id) and request("action")="edit" then
MySys.error.info="请选择您要操作的项目！"
MySys.error.location="back"
MySys.error.err()
end if

select case request("action")
case "delete"
	if ids="" then
		MySys.error.info="请选择你要删除的用户！"
		MySys.error.location="back"
		MySys.error.err()
	end if

	conn.execute("delete from sys_admin_list where admin_id in ("&ids&") and sort_id in (select sort_id from sys_admin_sort where sort_grade<"&MySys.admin_grade&" ) ")
	
	MySys.error.info="删除用户成功！"
	MySys.error.location="back"
	MySys.error.suc()
	
case "add"
	sql="select * from sys_admin_list "

	rs.open sql,conn,1,3
	'/////////////////////////////////////////////检测
	if not MySys.check.CheckT(request("admin_name")) or request("admin_password")="" or request("admin_password_verify")="" or request("sort_id")="" or request("admin_sex")="" then
		MySys.error.info="请填写完整的符合规范的用户资料"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if len(request("admin_name"))<6 then
		MySys.error.info="用户名长度至少要有6位"
		MySys.error.location="back"
		MySys.error.err()
	end if

	if request("admin_password")<>request("admin_password_verify") then
		MySys.error.info="您填入的密码和确认密码不符！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if not conn.execute("select admin_id from sys_admin_list where admin_name='"&request("admin_name")&"' ").eof then
		MySys.error.info="此用户已经有人注册！请更换用户名！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	set rs_t=conn.execute("select sort_grade from sys_admin_sort where sort_id="&int(request("sort_id"))&" ")
	if rs_t.eof then
		MySys.error.info="您选择的用户类型不存在！"
		MySys.error.location="back"
		MySys.error.err()
	else
	    if rs_t("sort_grade")>=MySys.admin_grade then 
			MySys.error.info="您不能加入比您的用户权限更高或相同的用户类型！"
			MySys.error.location="back"
			MySys.error.err()
		end if
	end if
	set rs_t=nothing
	
	'/////////////////////////////////////////////
	
	rs.addnew
	
	rs("admin_name")=request.form("admin_name")	
	rs("admin_password")=MySys.functions.EncodeMd5(request.form("admin_password") ,16)
	rs("sort_id")=int(request.form("sort_id"))
	rs("admin_open")=1
	rs("admin_sex")=int(request.form("admin_sex"))
	rs("admin_addtime")=now()
	rs("admin_login_ip_lock")=0

	rs.update
	rs.close
	
	MySys.error.info="用户加入成功！"
	MySys.error.location="admin/admin_user_sys_list.asp?sort_id="&request("sort_id")
	MySys.error.suc()

case "edit"

	if request("id")-MySys.admin_id<>0 then sql="select * from sys_admin_list  where admin_id="&id&" and sort_id in (select sort_id from sys_admin_sort where sort_grade<"&MySys.admin_grade&" ) "
	if request("id")-MySys.admin_id=0 then sql="select * from sys_admin_list  where admin_id="&id&"  "
	rs.open sql,conn,1,3
	
	if rs.eof then
		MySys.error.info="您选择的用户不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	set rs_t=conn.execute("select sort_grade from sys_admin_sort where sort_id="&int(request("sort_id"))&" ")
	if rs_t.eof then
		MySys.error.info="您选择的用户类型不存在！"
		MySys.error.location="back"
		MySys.error.err()
	else
	    if rs_t("sort_grade")>=MySys.admin_grade and request("id")-MySys.admin_id<>0 then 
			MySys.error.info="您不能将用户提升到比您的用户权限更高的用户类型！"
			MySys.error.location="back"
			MySys.error.err()
		end if
	end if
	set rs_t=nothing
	
	if request("id")-MySys.admin_id=0 then
		if request.form("admin_login_ip_locked")<>"" then rs("admin_login_ip_locked")=request.form("admin_login_ip_locked")
		if request.form("admin_password_o")<>"" and request.form("admin_password_n")<>"" then
		
			if request.form("admin_password_n")<>request.form("admin_password_n_verify") then
				MySys.error.info="确认密码和新密码不符！"
				MySys.error.location="back"
				MySys.error.err()
			end if
			
			if conn.execute("select admin_id from sys_admin_list where admin_open=1 and admin_name='"&MySys.admin_name&"' and admin_password='"&MySys.functions.EncodeMd5(request.form("admin_password_o") ,16)&"' ").eof then
				MySys.error.info="您的管理员身份确认有误！"
				MySys.error.location="back"
				MySys.error.err()
			end if
			
			rs("admin_password")=MySys.functions.EncodeMd5(request.form("admin_password_n") ,16)
		end if
		MySys.error.info="用户编辑成功,由于您更改了密码，请重新登陆！"
		MySys.error.location="admin/admin_login.asp"
		
	else
	
		if request.form("sort_id")<>"" then rs("sort_id")=int(request.form("sort_id"))
		if request.form("admin_open")<>"" then rs("admin_open")=int(request.form("admin_open"))
	    MySys.error.info="用户编辑成功！"
	    MySys.error.location="back"
	
	end if
	
	if request.form("admin_login_ip_lock")<>"" then rs("admin_login_ip_lock")=int(request.form("admin_login_ip_lock"))
	if request.form("admin_sex")<>"" then rs("admin_sex")=int(request.form("admin_sex"))
	rs.update
	rs.close
	
	MySys.error.suc()

end select
%>
<!--#include file="admin_end.asp"-->
