<!--#include file="../conn.asp"-->
<!--#include file="admin_check.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../inc/function.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>管理页面</title>
<link id="maincss" rel="stylesheet" href="images/css/admin_style_<%= AdminSkin %>.css" type="text/css" media="all" />
<script language="javascript">
function CheckAll()
{
var length = document.formed.checkbox.length;
var tocheck = document.formed.SelectAll.checked;

  if (length>=2)
  {
    for (var i=0; i<length; i++)
	{
	  if(document.formed.checkbox[i].disabled!=true)
	  {document.formed.checkbox[i].checked = tocheck;}
	}
   }
  else
  {
	  if(document.formed.checkbox.disabled!=true)
	  {document.formed.checkbox.checked = tocheck;}
  }
}

function hidflag(n)
{
	if (n=="1")
	{
		if (flag.style.display=="none")
		{
		flag.style.display="block";
		}
		else
		{
		flag.style.display="none";
		}
	}
	else
	{
	flag.style.display="none";
	}
}

function CheckForm()
{
  if (document.formed.adminname.value=="")
   {
	alert("请输入管理员名！");
	document.formed.adminname.focus();
	return false;
   }
  if (document.formed.adminpass.value=="")
   {
	alert("请输入管理密码！");
	document.formed.adminpass.focus();
	return false;
   }
  if (document.formed.adminpass2.value!=document.formed.adminpass.value)
   {
	alert("两次密码不相同！");
	document.formed.adminpass2.focus();
	return false;
   }
   
    var allcheck=true;
    var length = document.formed.checkbox.length;
    for (var i=0; i<length; i++)
	{
	  if(document.formed.checkbox[i].checked==false)
	  {allcheck=false;}
	}
	if(allcheck==true)
	{
	document.formed.SelectAll.checked=true;
	}
}

function allflag()
{
    var allcheck=true;
    var length = document.formed.checkbox.length;
    for (var i=0; i<length; i++)
	{
	  if(document.formed.checkbox[i].checked==false)
	  {allcheck=false;}
	}
	if(allcheck==true)
	{
	document.formed.SelectAll.checked=true;
	}
}

 function chkpwd(obj){
  var t=obj.value;
  var id=getResult(t);
  
  //定义对应的消息提示
  var msg=new Array(4);
  msg[0]="密码过短。";
  msg[1]="密码强度差。";
  msg[2]="密码强度良好。";
  msg[3]="密码强度高。";
  
  var sty=new Array(4);
  sty[0]=-45;
  sty[1]=-30;
  sty[2]=-15;
  sty[3]=0;
  
  var col=new Array(4);
  col[0]="gray";
  col[1]="red";
  col[2]="#ff6600";
  col[3]="Green";
  
  //设置显示效果
  var bImg="images/chkpass.gif";//一张显示用的图片
  var sWidth=300;
  var sHeight=15;
  var Bobj=document.getElementById("chkResult");

  Bobj.style.fontSize="12px";
  Bobj.style.color=col[id];
  Bobj.style.width=sWidth + "px";
  Bobj.style.height=sHeight + "px";
  Bobj.style.lineHeight=sHeight + "px";
  Bobj.style.background="url(" + bImg + ") no-repeat left " + sty[id] + "px";
  Bobj.style.textIndent="20px";
  Bobj.innerHTML="检测提示：" + msg[id];
 }
 
 //定义检测函数,返回0/1/2/3分别代表无效/差/一般/强
 function getResult(s){
  if(s.length < 4){
   return 0;
  }
  var ls = 0;
  if (s.match(/[a-z]/ig)){
   ls++;
  }
  if (s.match(/[0-9]/ig)){
   ls++;
  }
   if (s.match(/(.[^a-z0-9])/ig)){
   ls++;
  }
  if (s.length < 6 && ls > 0){
   ls--;
  }
  return ls
 }
</script>
<style type="text/css">
<!--
#chkResult {
	height: 15px;
	background-image: url(Images/chkpass.gif);
	background-repeat: no-repeat;
	background-position: left -45px;
	text-indent: 20px;
	color: gray;
	line-height: 15px;
}
-->
</style>
</head>
<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="5" marginheight="0" marginwidth="0" bgcolor="#DDEEFF">
<%
Call chkFlag(11)
Dim Act
act=Trim(Request.QueryString("act"))
opendb
select case act
  case "pass"
    call changepass()
  case "savepass"
    call savepass()
  case "flag"
    call changeflag()
  case "saveflag"
    call saveflag()
  case "del"
    call del()
  case "add"
    call add()
  case "save"
    call saveadmin()
  case else
    call main()
end select
closedb

sub savepass()
  dim adminpass,adminpass2,id,oldpass,rs,sql
  id=Trim(Request.Form("id"))
  oldpass=Trim(Request.Form("oldpass"))
  adminpass=Trim(Request.Form("adminpass"))
  adminpass2=Trim(Request.Form("adminpass2"))
  if oldpass="" or adminpass="" or adminpass<>adminpass2 then
     Response.Write("<script>history.go(-1);</script>")
  else
    set rs= Server.CreateObject("adodb.recordset")
    sql="select * from "&predb&"admin where adminpsd='"&md5(oldpass,32)&"' and id="&id
    rs.open sql,conn,1,3
	  if not(rs.bof and rs.eof) then
		 rs("adminpsd")=md5(adminpass,32)
		 rs.update
		 rs.close
		 set rs=nothing
		 Response.Redirect("?")
	  else
		 rs.close
		 set rs=nothing
	   Call SendMsg("旧密码不正确")
	   Response.Write("<script>setTimeout(""history.go(-1)"",2000)</script>")
	   Response.End()
	  end if
  end if
end sub

sub saveflag()
  dim id,adminflag,SelectAll,rs,sql
  id=Trim(Request.Form("id"))
  adminflag=replace(Trim(Request.Form("checkbox"))," ","")
  adminflag=","&adminflag&","
  SelectAll=Trim(Request.Form("SelectAll"))
  if SelectAll="1" then adminflag="0"
  
  set rs= Server.CreateObject("adodb.recordset")
  sql="select adminflag from "&predb&"admin where id="&id
  rs.open sql,conn,1,3
  rs("adminflag")=adminflag
  rs.update
  rs.close
  set rs=nothing
  Response.Redirect("?")
end sub

sub changepass()
dim rs,id
id=Trim(Request.QueryString("id"))
set rs=conn.execute("select adminname from "&predb&"admin where id="&id)
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <form action="?act=savepass" method="post" name="formed" onSubmit="return CheckForm();"><input name="id" type="hidden" value="<%=id%>">
  <tr>
	<th height="25" colspan="2" align="left">管理员密码修改</th>
  </tr>  
  <tr>
    <td width="19%" align="right" class="TableRow1"><strong>管理员名：</strong></td>
    <td width="81%" class="TableRow1"><input type="text" name="adminname" id="adminname" value="<%= rs("adminname") %>" readonly></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1"><strong>旧密码：</strong></td>
    <td class="TableRow1"><input type="password" name="oldpass" id="oldpass"></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1"><strong>新密码：</strong></td>
    <td class="TableRow1"><input type="password" name="adminpass" id="adminpass" onPropertyChange="chkpwd(this);" onBlur="chkpwd(this);"></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1"><strong>密码强度：</strong></td>
    <td class="TableRow1"><div id="chkResult">检测提示：请输入密码</div></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1"><strong>确认密码：</strong></td>
    <td class="TableRow1"><input type="password" name="adminpass2" id="adminpass2"></td>
  </tr>
  
  <tr>
    <td class="TableRow1">&nbsp;</td>
    <td class="TableRow1"><input type="submit" name="button3" id="button3" value=" 修 改 ">
      &nbsp; <input type="button" name="button4" id="button4" value=" 取 消 " onClick="location.href='?'"></td>
  </tr>
  </form>
</table>
<%
set rs=nothing
end sub

Sub Del()
  dim adminID
  adminID=Trim(Request.Form("checkbox"))
  if adminID<>"" then
  conn.execute("delete from "&predb&"admin where id in("&adminID&")")
  end if
	  Call SendMsg("删除管理员成功")
	  Response.Write("<script>setTimeout(""location.href='?'"",2000)</script>")
End Sub

sub saveadmin()
  dim adminname,adminpass,adminpass2,admintype,adminflag,SelectAll,rs,sql
  adminname=Trim(Request.Form("adminname"))
  adminpass=Trim(Request.Form("adminpass"))
  adminpass2=Trim(Request.Form("adminpass2"))
  admintype=Trim(Request.Form("admintype"))
  adminflag=replace(Trim(Request.Form("checkbox"))," ","")
  adminflag=","&adminflag&","
  SelectAll=Trim(Request.Form("SelectAll"))
  if admintype="0" then adminflag="0"
  if SelectAll="1" then adminflag="0"
  
  if adminname="" or adminpass="" or adminpass<>adminpass2 then
     Response.Write("<script>history.go(-1);</script>")
  else
  
  set rs= Server.CreateObject("adodb.recordset")
  sql="select * from "&predb&"admin where adminname='"&adminname&"'"
  rs.open sql,conn,1,3
  if rs.bof and rs.eof then
  rs.addnew()
  rs("adminname")=adminname
  rs("adminpsd")=md5(adminpass,32)
  rs("adminflag")=adminflag
  rs.update
  end if
  rs.close
  set rs=nothing
  Response.Redirect("?")
  end if
end sub

Sub add()
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <form action="?act=save" method="post" name="formed" onSubmit="return CheckForm();">
  <tr>
	<th height="25" colspan="2" align="left">管理员设置</th>
  </tr>  
  <tr>
    <td width="19%" align="right" class="TableRow1"><strong>管理员名：</strong></td>
    <td width="81%" class="TableRow1"><input type="text" name="adminname" id="adminname"></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1"><strong>初始密码：</strong></td>
    <td class="TableRow1"><input type="password" name="adminpass" id="adminpass" onPropertyChange="chkpwd(this);" onBlur="chkpwd(this);"></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1"><strong>密码强度：</strong></td>
    <td class="TableRow1"><div id="chkResult">检测提示：请输入密码</div></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1"><strong>确认密码：</strong></td>
    <td class="TableRow1"><input type="password" name="adminpass2" id="adminpass2"></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1"><strong>权限设置：</strong></td>
    <td class="TableRow1"><input type="radio" name="admintype" id="radio" value="0" onClick="hidflag(0)">
      超级管理员 
        <input name="admintype" type="radio" id="radio2" onClick="hidflag(1)" value="1" checked>
普通管理员</td>
  </tr>
<%call adminflag()%>
  <tr>
    <td class="TableRow1">&nbsp;</td>
    <td class="TableRow1"><input type="submit" name="button3" id="button3" value=" 增 加 ">
      &nbsp; <input type="button" name="button4" id="button4" value=" 取 消 " onClick="location.href='?'"></td>
  </tr>
  </form>
</table>
<% 
end sub

Sub changeflag()
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <form action="?act=saveflag" method="post" name="formed" onSubmit="return allflag();"><input name="id" type="hidden" value="<%= Trim(Request.QueryString("id")) %>">
  <tr>
	<th height="25" colspan="2" align="left">修改管理员权限</th>
  </tr>  
<%call adminflag()%>
  <tr>
    <td width="19%" class="TableRow1">&nbsp;</td>
    <td width="81%" class="TableRow1"><input type="submit" name="button3" id="button3" value=" 修 改 ">
      &nbsp; <input type="button" name="button4" id="button4" value=" 取 消 " onClick="location.href='?'"></td>
  </tr>
  </form>
</table>
<% 
end sub

sub adminflag()
dim rs,id,adminname,adminflag
id=Trim(Request.QueryString("id"))
if id<>"" then
   set rs=conn.execute("select adminname,adminflag from "&predb&"admin where id ="&id)
   adminname=rs("adminname")
   adminflag=rs("adminflag")
   set rs=nothing
end if
%>
<tbody  id="flag">
  <tr>
    <td colspan="2" align="center" class="TableRow1"><font color="#008800"><b><%= adminname %></b> 管理员权限详细设置</font></td>
  </tr>
  <tr>
    <td colspan="2" class="TableRow1">
<fieldset>
<legend> <font color="#FF0000">权限设置</font>&nbsp; 
<input name="SelectAll" type="checkbox" onClick="CheckAll()" value="1"> 选取所有权限</legend>
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="1" <% If adminflag="0" or instr(adminflag,",1,")>0 Then %>checked<% End If %>>
      问答管理</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="2" <% If adminflag="0" or instr(adminflag,",2,")>0 Then %>checked<% End If %>>
分类管理</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="3" <% If adminflag="0" or instr(adminflag,",3,")>0 Then %>checked<% End If %>>
调用管理</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="4" <% If adminflag="0" or instr(adminflag,",4,")>0 Then %>checked<% End If %>>
      推荐管理</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="5" <% If adminflag="0" or instr(adminflag,",5,")>0 Then %>checked<% End If %>>
      举报管理</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="6" <% If adminflag="0" or instr(adminflag,",6,")>0 Then %>checked<% End If %>>
      用户管理</td>
  </tr>
  <tr>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="7" <% If adminflag="0" or instr(adminflag,",7,")>0 Then %>checked<% End If %>>
      专家管理</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="8" <% If adminflag="0" or instr(adminflag,",8,")>0 Then %>checked<% End If %>>
      统计管理</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="9" <% If adminflag="0" or instr(adminflag,",9,")>0 Then %>checked<% End If %>>
      用户权限</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="10" <% If adminflag="0" or instr(adminflag,",10,")>0 Then %>checked<% End If %>>
      注册控制</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="11" <% If adminflag="0" or instr(adminflag,",11,")>0 Then %>checked<% End If %>>
      管 理 员</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="12" <% If adminflag="0" or instr(adminflag,",12,")>0 Then %>checked<% End If %>>
      等级方案</td>
  </tr>
  <tr>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="13" <% If adminflag="0" or instr(adminflag,",13,")>0 Then %>checked<% End If %>>
      等级分值</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="14" <% If adminflag="0" or instr(adminflag,",14,")>0 Then %>checked<% End If %>>
      奖惩项目</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="15" <% If adminflag="0" or instr(adminflag,",15,")>0 Then %>checked<% End If %>>
      积分明细</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="16" <% If adminflag="0" or instr(adminflag,",16,")>0 Then %>checked<% End If %>>
      站内短信</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="17" <% If adminflag="0" or instr(adminflag,",17,")>0 Then %>checked<% End If %>>
      邮件发送</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="18" <% If adminflag="0" or instr(adminflag,",18,")>0 Then %>checked<% End If %>>
      系统设置</td>
  </tr>
  <tr>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="19" <% If adminflag="0" or instr(adminflag,",19,")>0 Then %>checked<% End If %>>
      导航设置</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="20" <% If adminflag="0" or instr(adminflag,",20,")>0 Then %>checked<% End If %>>
      模板选择</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="21" <% If adminflag="0" or instr(adminflag,",21,")>0 Then %>checked<% End If %>>
      公告管理</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="22" <% If adminflag="0" or instr(adminflag,",22,")>0 Then %>checked<% End If %>>
      缓存管理</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="23" <% If adminflag="0" or instr(adminflag,",23,")>0 Then %>checked<% End If %>>
      站内链接</td>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="24" <% If adminflag="0" or instr(adminflag,",24,")>0 Then %>checked<% End If %>>
      友情链接</td>
  </tr>
  <tr>
    <td><input name="checkbox" type="checkbox" id="checkbox" value="25" <% If adminflag="0" or instr(adminflag,",25,")>0 Then %>checked<% End If %>>
      字符过滤</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>
</fieldset><br>
    </td>
  </tr>
</tbody>
<%
end sub

Sub main()
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <tr>
		<th height="25" colspan="8" align="left">管理员设置</th>
  </tr>  
  <tr>
    <td align="center" class="TableRow1"><strong>选中</strong></td>
    <td align="center" class="TableRow1"><strong>序列号</strong></td>
    <td align="center" class="TableRow1"><strong>管理员名</strong></td>
    <td align="center" class="TableRow1"><strong>权限</strong></td>
    <td align="center" class="TableRow1"><strong>上次登录IP</strong></td>
    <td align="center" class="TableRow1"><strong>上次登录时间</strong></td>
    <td align="center" class="TableRow1"><strong>登录次数</strong></td>
    <td align="center" class="TableRow1"><strong>操作</strong></td>
  </tr>
  <form method="post" action="?act=del" name="formed" onSubmit="return confirm('确定要删除选中的管理员吗？');">
<%
dim rs
set rs=conn.execute("select * from "&predb&"admin")
do while not rs.eof
%>
  <tr>
    <td align="center" class="TableRow1"><input name="checkbox" type="checkbox" id="checkbox" value="<%= rs("id") %>" <% If Request.Cookies("adminname")=rs("adminname") Then %>disabled><% End If %></td>
    <td align="center" class="TableRow1"><%= rs("id") %></td>
    <td align="center" class="TableRow1"><% If Request.Cookies("adminname")=rs("adminname") Then %><font color="#FF0000"><%= rs("adminname") %></font><% Else Response.Write(rs("adminname")) End If %></td>
    <td align="center" class="TableRow1"><% If rs("adminflag")="0" Then %><font color="#0000FF">超级管理员</font><% Else Response.Write("普通管理员") End If %></td>
    <td align="center" class="TableRow1"><%= rs("Previousip") %></td>
    <td align="center" class="TableRow1"><%= rs("Previoustime") %></td>
    <td align="center" class="TableRow1"><%= rs("loginsum") %></td>
    <td align="center" class="TableRow1">
	<% If Request.Cookies("adminname")=rs("adminname") Then %>
    <a href="?act=pass&id=<%= rs("id") %>">修改密码</a>&nbsp; 
    <% Else %>
    <font color="gray">修改密码</font>&nbsp; 
	<% End If %>
    <%IF Request.Cookies("adminflag")=0 Then%>
    <a href="?act=flag&id=<%= rs("id") %>"<% If Request.Cookies("adminname")=rs("adminname") Then %> onClick="return confirm('确认修改自己的权限?')"<%end if%>>修改权限</a>
	<% Else %>
    <font color="gray">修改权限</font>
	<% End If %>
    </td>
  </tr>

<%
rs.movenext
loop
set rs=nothing
%>  
  <tr>
    <td colspan="8" class="TableRow1"><input type="checkbox" name="SelectAll" id="SelectAll" onClick="CheckAll()">
      选中所有管理员&nbsp; <input type="submit" name="button" id="button" value="删除选中的管理员">
      &nbsp; <input type="button" name="button2" id="button2" value="增加管理员" onClick="location.href='?act=add'"></td>
  </tr>
 </form>
</table>
<% 
end sub
%>
<br>
</body>
</html>
