<!--#include file="sdcms_check.asp"-->
<%
sub check_supadmin
set sdcms=new Sdcms_Admin
sdcms.Check_lever 12
set sdcms=nothing
End sub
set sdcms=new Sdcms_Admin
sdcms.Check_admin
set sdcms=nothing
select case action
case "add":title="添加帐户"
case "edit":title="修改帐户"
case else:title="帐户管理"
end select
sd_table="sd_admin"
sdcms_head
%>
<div class="sdcms_notice"><span>管理操作：</span><a href="?action=add">添加帐户</a>　┊　<a href="?">帐户管理</a></div>
<br>
<ul id="sdcms_sub_title">
	<li class="sub"><%=title%></li>
</ul>
<div id="sdcms_right_b">
<%
select case action
case "add":check_supadmin:add
case "edit":edit
case "save":save
case "del":check_supadmin:del
case else:check_supadmin:main
end select
closedb
sub main
%>
  <table border="0" align="center" cellpadding="3" cellspacing="1" class="table_b">
    <tr>
      <td width="30" class="title_bg">ID</td>
      <td class="title_bg">帐户</td>
      <td class="title_bg">登录次数</td>
      <td class="title_bg">最后一次IP</td>
      <td class="title_bg">类别</td>
      <td class="title_bg">管理</td>
    </tr>
	<%
	sql="select id,sdcms_name,logintimes,lastip,"
	if Is_sql=0 then
		sql=sql&"(iif((isadmin)=0, '普通管理员','超级管理员'))"
	else
		sql=sql&"(case isadmin when 0 then '普通管理员' else '超级管理员' end)"
	end if
	sql=sql&" from "&sd_table&" order by id desc"
	set rs=conn.execute(sql)
	while not rs.eof
	%>
    <tr onmouseover=this.bgColor='#EBFFDC'; onmouseout=this.bgColor='#ffffff';  bgcolor='#ffffff'>
	 <%for i=0 to 4%>
      <td align="center"><%=rs(i)%></td>
      <%next%>
      <td align="center"><a href="?action=edit&id=<%=rs(0)%>">编辑</a> <a href="?action=del&id=<%=rs(0)%>" onclick='return confirm("真的要删除?不可恢复!");'>删除</a></td>
    </tr>
	<%rs.movenext
	wend%>
  </table>
<%
end sub
sub add
check_info
%>
  <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form name="add" id="add" method="post" action="?action=save&act=add" onSubmit='return checkadd()'>
    <tr>
      <td width="9%" align="center" class="tdbg">帐 户：      </td>
      <td width="91%" class="tdbg"><input name="t0" type="text" class="input" id="t0" size="30"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">密 码：      </td>
      <td><input name="t1" type="text" class="input" id="t1" size="30"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">类 别：</td>
      <td><input name='t2' type='radio' onClick=$('flag').style.display='block'; value='0' >普通管理员 <input name='t2' type='radio' onClick=$('flag').style.display='none'; value='1' checked >超级管理员</td>
    </tr>
    <tr class="tdbg dis" id='flag'>
      <td align="center">权 限：</td>
      <td><%
	  all_lever="系统设置|链接管理|公告管理|单页管理|信息类别|信息管理|评论管理|投票管理|广告管理|模板管理|风格管理|管理权限|系统日志|生成管理|标签管理"
	  all_lever=split(all_lever,"|")
	  for i=0 to ubound(all_lever)
	  %>
	  <input name="t3" type="checkbox" <%if i=4 then%>id="infocheck" onClick="Display('allinfo')"<%end if%> value="<%=i+1%>"><%=all_lever(i)%>
	  <%next%></td>
    </tr>
	<tr class="tdbg" id="allinfo" style="display:none">
      <td align="center">权 限：</td>
      <td>
	  <%set rs1=conn.execute("select id,title from sd_class where followid=0 order by ordnum desc")
	  while not rs1.eof%>
	  <input name="t4" type="checkbox" value="<%=rs1(0)%>"><%=rs1(1)%>
	 <%rs1.movenext
	 wend%>
	  </td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="保 存">
        <input name="Submit2" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%
end sub
sub edit
check_info
set rs=conn.execute("select id,sdcms_name,isadmin,alllever,infolever from "&sd_table&" where id="&id&"")
if rs.eof then
echo "请勿非法提交参数":Died
end if
%>
  <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form  name="add" method="post" action="?action=save&act=save&id=<%=id%>">
    <tr>
      <td width="9%" align="center" class="tdbg">帐 户：      </td>
      <td width="91%" class="tdbg"><%=rs(1)%></td>
    </tr>
    <tr class="tdbg">
      <td align="center">密 码：      </td>
      <td><input name="t1" type="text" class="input" id="t1" size="30"> <span>不修改请留空</span></td>
    </tr>
	<%if session(sdcms_cookies&"sdcms_admin")=1 then%>
    <tr class="tdbg">
      <td align="center">类 别：</td>
      <td><input name='t2' type='radio' onClick=$('flag').style.display='block'; value='0' <%=w_check(rs(2),0)%>>普通管理员 <input name='t2' type='radio' onClick=$('flag').style.display='none';allinfo.style.display='none' value='1' <%=w_check(rs(2),1)%>>超级管理员</td>
    </tr>
    <tr class="tdbg<%if rs(2)=1 then%> dis<%end if%>" id="flag">
      <td align="center">权 限：</td>
      <td>
	  <%
	  if instr(", "&rs(3)&", ",", 5, ")>0 then
	  tt=1
	  else
	  tt=0
	  end if
	  all_lever="系统设置|链接管理|公告管理|单页管理|信息类别|信息管理|评论管理|投票管理|广告管理|模板管理|风格管理|管理权限|系统日志|生成管理|标签管理"
	  all_lever=split(all_lever,"|")
	  for i=0 to ubound(all_lever)
	  %>
	  <input name="t3" type="checkbox" <%if i=4 then%>id="infocheck" onClick="Display('allinfo')"<%end if%> value="<%=i+1%>" <%if instr(", "&rs(3)&", "&", ",", "&i+1&", ")>0 then echo "checked" end if%>><%=all_lever(i)%>
	  <%next%>
	  </td>
    </tr>
	<tr class="tdbg" id="allinfo" <%if not(rs(2)=0 and tt=1) then%>style="display:none;"<%end if%>>
      <td align="center">分 类：</td>
      <td>
	  <%set rs1=conn.execute("select id,title from sd_class where followid=0 order by ordnum desc")
	  while not rs1.eof%>
	  <input name="t4" type="checkbox" value="<%=rs1(0)%>" <%if instr(", "&rs(4)&", "&", ",", "&rs1(0)&", ")>0 then echo "checked" end if%>><%=rs1(1)%>
	 <%rs1.movenext
	 wend%>
	  </td>
    </tr>
	<%end if%>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="保 存">
        <input name="Submit22" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%
end sub
sub save

t0=trim(request("t0"))
t1=trim(request("t1"))
t2=trim(request("t2"))
t3=trim(request("t3"))
t4=trim(request("t4"))
set rs=server.CreateObject("adodb.recordset")
sql="select sdcms_name,sdcms_pwd,isadmin,alllever,infolever from "&sd_table&""
if act="add" then 
 sql=sql&" where sdcms_name='"&t0&"'"
else
 sql=sql&" where id="&id&""
end if
rs.open sql,conn,1,3
if act="add" then 
  if not rs.eof then
  echo "该用户名已存在，请换个试试":Died
  end if
end if
if act="add" then 
  rs.addnew
else
  rs.update
end if
if act="add" then 
rs(0)=t0
end if
if act="add" then 
rs(1)=md5(t1)
else
  if t1<>"" then
  rs(1)=md5(t1)
      if sdcms_adminid=id then response.Cookies(sdcms_cookies&"sdcms_pwd")=md5(t1)
  end if
end if
if session(sdcms_cookies&"sdcms_admin")=1 then
	rs(2)=t2
	if t2=1 then
	rs(3)=""
	else
	rs(3)=t3
	end if
	if t2=1 then
	rs(4)=""
	elseif t2=0 and instr(", "&t3&", ",", 5, ")>0 then  
	rs(4)=t4
	else
	rs(4)=""
	end if
end if
set sdcms=new sdcms_function
if act="save" then
response.Cookies(sdcms_cookies&"sdcms_all_lever")=t3
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','修改管理帐户："&rs(0)&"')")
else
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','添加管理帐户："&rs(0)&"')")
end if
set sdcms=nothing
rs.update
rs.close
set rs=nothing
if session(sdcms_cookies&"sdcms_admin")=1 then
response.Redirect("?")
else
echo "<script>alert('密码修改成功');location.href='?id="&id&"&action=edit';</script>"
end if
end sub
sub del
if clng(sdcms_adminid)=clng(id) then
echo "不能删除自己":Died
else
  conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除管理帐户："&conn.execute("select sdcms_name from "&sd_table&" where id="&id&"")(0)&"')")
  conn.execute("delete from "&sd_table&" where id="&id&"")
  response.Redirect("?")
end if
end sub

sub check_info
with response
.write("	<script>")
if action="add" then
.write("	function checkadd()")
.write("	{")
.write("	if (document.add.t0.value=='')")
.write("	{")
.write("	alert('帐户名称不能为空');")
.write("	document.add.t0.focus();")
.write("	return false")
.write("	}")
.write("	if (document.add.t1.value=='')")
.write("	{")
.write("	alert('帐户密码不能为空');")
.write("	document.add.t1.focus();")
.write("	return false")
.write("	}")
.write("	}")
end if
.write("	</script>")
end with
end sub
%>  
</div>
</body>
</html>