<!-- #include file="conn.asp" -->
<!-- #include file="admin.asp" -->
<!-- #include file="md5.asp" -->
<%
Call Head%>
<%
dim siddd
Function SID_RANDOMIZE()
Dim c,id
randomize 
c="a,A,1,b,B,2,c,C,3,d,D,4,e,E,5,f,F,6,g,G,7,h,H,8,i,I,9,j,J,0,k,K,1,l,L,2,m,M,3,n,N,4,o,O,5,p,P,6,q,Q,7,r,R,8,s,S,9,t,T,0,u,v,w,x,y,z,"
id=split(c,",") 
for i=1 to 10
SID_RANDOMIZE=int(rnd()*36)&SID_RANDOMIZE
Next
SID_RANDOMIZE=SID_RANDOMIZE&minute(now)&second(now)&day(now)&month(now)
End Function
siddd=md5(md5(sjhm+SID_RANDOMIZE,16),32)
myyid=Request.QueryString("myyid")
set rsqq=server.createobject("adodb.recordset")
Sqlqq="select * from [adminguli] where id="&myyid
rsqq.open sqlqq,conn,1,1
KEYiid=rsqq("ID")
keyuuser=rsqq("username")
keyy=rsqq("key")
rsqq.close
set rsqq=Nothing

If keyid<>KEYiid Then
if saytk>1 then
  Call Error("<title>出错</title></head><body><body bgcolor="""&yanse1&"""><p>权限不足！")
else
  Call Error("<card title=""警告""><p>权限不足！")
  end if
End if



		IF  Request.QueryString("Action")="view" Then

			call view
		elseiF  Request.QueryString("Action")="del" Then

			call del
		elseiF  Request.QueryString("Action")="edit" Then

			call edit
		elseiF  Request.QueryString("Action")="add" Then

			call add
		elseiF  Request.QueryString("Action")="save" Then

			call save
		else

			call view
		end if

Function edit
	id=TRim(Request("id"))
	if not isnumeric(id) then id=""
	if id=""  then
if saytk<>1 then
Response.write "<title>出错啦</title></head><body><body bgcolor="""&yanse1&"""><p>"
else%>
	<card id="index" title="出错啦"><p>
<%end if%>ID无效.<br/>
	<%else
			Set Rs = Server.CreateObject("Adodb.Recordset")
			Sql = "SELECT * FROM adminguli where id="&id
			Rs.Open Sql,conn,1,1
if not (rs.bof and rs.eof)  then 
Call saycardc("修改管理")

if saytk>1 then
Response.write "<form name=""form"" method=""post"" action=""Adminabcmm.asp?myyid="&id&"&amp;sid="&sid&"&amp;Action=save&amp;edit=edit&amp;saytk="&saytk&""">"
end if%>
用户:<br/><input name="username" value="<%=rs("username")%>" maxlength="255" /><br/>
密码:<br/><input name="password" value="" /><br/> 
高级密码:<br/><input name="password2" value="" /><br/> 
                <%if id<>1 then%>
管理范围:<br/><select name="key" value="<%=rs("key")%>">
                <option value="0">超级管理员</option>
                <option value="2">文章管理员</option>
                <option value="3">图片管理员</option>
				<option value="4">文件管理员</option>
                </select>
                <%end if%>
我的密码:<br/><input name="passwordmy" value="" /><br/> 
<%if saytk>1 then
response.write "<input type=""hidden"" name=""id"" value="""&id&"""/>"
response.write "<input type=""submit"" name=""Submit"" value=""修改""></form><br/>"
else%>
	<br/><anchor>修改
<go href="Adminabcmm.asp?myyid=<%=id%>&amp;sid=<%=sid%>&amp;Action=save&amp;edit=edit&amp;saytk=<%=saytk%>" method="post">
			<postfield name="username" value="$(username:n)" />
			<postfield name="id" value="<%=id%>" />
			<postfield name="password" value="$(password:n)" />
			<postfield name="password2" value="$(password2:n)" />
			<postfield name="passwordmy" value="$(passwordmy)" />
                <%if id<>1 then%>	
		        <postfield name="key" value="$(key:n)" />
                <%end if%>
			</go>
			</anchor><br/><%end if%>
提示:修改管理员将会提示重新登录.<br/>
<a href="Adminabcmm.asp?sid=<%=sid%>&amp;saytk=<%=saytk%>">[设定管理]</a><br/>
			<%else
if saytk>1 then
Response.write "<title>出错啦</title></head><body><body bgcolor="""&yanse1&"""><p>"
else%>
			<card id="index" title="出错啦"><p>
<%end if%>没有该管理!<br/>
			<%end if
			Rs.close
			set rs=nothing
		end if
end Function
Function view
	id=TRim(Request("id"))
	if not isnumeric(id) then id=""
		if id=""  then
if saytk>1 then
Response.write "<title>出错啦</title></head><body><body bgcolor="""&yanse1&"""><p>"
else%>
	<card id="index" title="出错啦"><p>
<%end if%>ID无效.<br/>
		<%Else
		Call saycardc("设定管理")

			Set Rs = Server.CreateObject("Adodb.Recordset")
			Sql = "SELECT * FROM adminguli where id="&id
			Rs.Open Sql,conn,1,1
			if not (rs.bof and rs.eof)  then %>
				用户:<%=ubb(rs("username"))%><br/>
				密码:<%=ubb(rs("password"))%><br/>
				高密:<%=ubb(rs("twapp_admin"))%><br/>
                   上次管理:<%=ubb(fordate(rs("lastdate")))%><br/>
                   上次IP:<%=ubb(rs("lastip"))%><br/>
				<a href='Adminabcmm.asp?myyid=<%=id%>&amp;sid=<%=sid%>&amp;Action=edit&amp;id=<%=id%>&amp;saytk=<%=saytk%>'>[编辑]</a> <a href='Adminabcmm.asp?myyid=<%=id%>&amp;sid=<%=sid%>&amp;Action=del&amp;id=<%=id%>&amp;saytk=<%=saytk%>'>[删除]</a><br/>
<a href="Adminabcmm.asp?sid=<%=sid%>">[设定管理]</a><br/>
			<%else%>
				暂无管理!<br/>
			<%end if
			Rs.close
			set rs=nothing
		end if
end Function
Function  del
	id=TRim(Request("id"))
	if not isnumeric(id) then id=""
 		if id=""  then
if saytk>1 then
Response.write "<title>出错啦</title></head><body><body bgcolor="""&yanse1&"""><p>"
else%>
	<card id="index" title="出错啦"><p>
<%end if%>ID无效.<br/>
		<%else
			if Request("del")="true" then
				set rs=server.CreateObject("adodb.recordset")
				Sql = "SELECT * FROM adminguli where id="&id
				rs.open sql,conn,1,3
				if not (rs.bof and rs.eof)  then
                                if id=1 then
if saytk>1 then
  Call Error("<title>删除管理员</title></head><body><body bgcolor="""&yanse1&"""><p>站长不能删除！")
else
                                Call Error("<card title='删除管理员'><p>站长不能删除！")
                                end if
end if
				rs.delete
				end if
				Rs.close
				set rs=Nothing
Call saycardc("删除管理员")
%>
		已成功删除该管理员!<br/>
<a href="Adminabcmm.asp?sid=<%=sid%>&amp;saytk=<%=saytk%>">[设定管理]</a><br/>
			<%Else
Call saycardd("删除管理员")
%>
			是否要删除该管理员?<br/>
			<a href='Adminabcmm.asp?sid=<%=sid%>&amp;Action=del&amp;del=true&amp;id=<%=id%>&amp;saytk=<%=saytk%>'>[确定删除]</a><br/><anchor>返回上页<prev/></anchor><br/>
<a href="Adminabcmm.asp?sid=<%=sid%>&amp;saytk=<%=saytk%>">[设定管理]</a><br/>
<%end if
end if
end Function
Function save

Call cardz("修改管理","Adminabcgl.asp?saytk="&saytk&"&amp;sid="&sid&"")
	username=Trim(Request("username"))
	password=Trim(Request("password"))
	password2=Trim(Request("password2"))
	passwordmy=md5(md5(request.form("passwordmy"),16),32)
	key=Trim(Request("key"))
	id=clng(Request("id"))


            if id<>1 then
	if key="" or isnumeric(key) =false then
         Call Error("管理范围无效！")
end if
end If


set Rs=server.createobject("adodb.recordset")
   Sql="select * from [adminguli] where [password]='"&passwordmy&"' and id="&KEYid
Rs.open sql,conn,1,1
if Rs.eof then
rs.close
set rs=nothing
  Call Error("修改失败,验证我的密码不正确！")
  end If
  

		if username=""  then errmsg=errmsg&"管理名称不能为空<br/>":flag=0
		if password=""  then errmsg=errmsg&"管理密码不能为空<br/>":flag=0
		if password2=""  then errmsg=errmsg&"管理高级密码不能为空<br/>":flag=0
		if Request("edit")="edit" then
		if id=""  then errmsg=errmsg&"ID无效<br/>":flag=0
set rs=Server.CreateObject("ADODB.Recordset")
  rs.open"select ID from adminguli where username='"&username&"' and id<>"&id,conn,1,1
if not rs.eof then
errmsg=errmsg&"管理员用户名已被使用<br/>":flag=0
  end if
rs.close
set rs=nothing

		if flag<>"0" then

				set rs=server.CreateObject("adodb.recordset")
				sql="select * from adminguli where id="&id
				rs.open sql,conn,1,3
                                if rs.eof then
errmsg=errmsg&"ID无效<br/>":flag=0
end if
				rs("username")=username
            		        rs("password")=md5(md5(password,16),32)
                                rs("twapp_admin")=md5(md5(password2,16),32)
                                if ID<>1 then
				rs("key")=key
                                end if
				rs("sid")=siddd
				rs.update()
				Rs.close
				set rs=Nothing

%>
修改管理成功<br/>
<a href="Adminabcmm.asp?sid=<%=sid%>&amp;saytk=<%=saytk%>">[设定管理]</a><br/>
<%else
if saytk>1 then
Response.write "<title>添加管理出错</title></head><body><body bgcolor="""&yanse1&"""><p>"
else
Response.Write("<card id='index' title='添加管理出错' ><p>") 
end if
Response.Write(""&errmsg&"<br/><anchor>[返回修改]<prev/></anchor><br/>") 		
		end if
		else
set rs=Server.CreateObject("ADODB.Recordset")
  rs.open"select ID from adminguli where username='"&username&"' and id<>"&id,conn,1,1
if not rs.eof then
errmsg=errmsg&"管理员用户名已被使用<br/>":flag=0
  end if
rs.close
set rs=nothing

			if flag<>"0" then
				set rs=server.CreateObject("adodb.recordset")
				sql="select * from adminguli"
				rs.open sql,conn,1,3
				rs.addnew()
				rs("username")=username
            		        rs("password")=md5(md5(password,16),32)
                                rs("twapp_admin")=md5(md5(password2,16),32)
				rs("sid")=siddd
				rs("key")=key
				rs.update()
				Rs.close
				set rs=Nothing
				Call cardz("添加管理","Adminabcgl.asp?saytk="&saytk&"&amp;sid="&sid&"")%>

添加管理成功<br/><br/>
<a href="Adminabcmm.asp?sid=<%=sid%>&amp;saytk=<%=saytk%>">[设定管理]</a><br/>
<%else
if saytk>1 then
Response.write "<title>添加管理出错</title></head><body><body bgcolor="""&yanse1&"""><p>"
else
Response.Write("<card id='index' title='添加管理出错' ><p>") 
end if
Response.Write(""&errmsg&"<br/><anchor>[返回修改]<prev/></anchor><br/>") 	
		end if
		END IF
end Function

%>
<a href="index.asp?sid=<%=sid%>&amp;saytk=<%=saytk%>">[后台管理]</a>
<%call headsay()%>
