<!--#include file="../include/Conn.jsp"-->
<!--#include file="../include/Char.jsp"-->
<!--#include file="../include/md5.jsp"-->
<!--#include file="Admin_Menu.jsp" -->

<%
admin_flag=",0|3|0,"

'Define Variable 
dim i
dim rs,rst
dim mTypeName,mGrade,mSql,mFlag,mBgColor
Set rs=Server.CreateObject("Adodb.RecordSet")

'initialization 
mFlag="insert"

'edit
if request("action")="edit" then 
  mSql="Select * From T_Admin Where F_ID="&Request.QueryString("ModifyID")
  Set rs=Conn.Execute(mSql)
  If not rs.Eof then
    mUserName=rs("F_UserName")
    rs.Close
  End if
  mFlag="edit"
end if

'Insert Records
if request("action")="Insert" then
  mSql="Select * From T_Admin"
  rs.open mSql,conn,1,3
  rs.AddNew
  rs("F_UserName")=Trim(Request.Form("txtUserName"))
  rs("F_Password")=md5(Trim(Request.Form("txtPassword")))
  rs("F_UserGrade")=Trim(Request.Form("selUserGrade"))
  rs.update
  rs.close
  response.redirect "admin_User.jsp?action=IsInsert&pageno="&Request("pageno")
end if

'Modify Records
if request("action")="editsave" then
  mSql="Select * From T_Admin Where F_ID="&Request.QueryString("ModifyID")
  rs.open mSql,conn,1,3
  rs("F_UserName")=Trim(Request.Form("txtUserName"))
  if Trim(Request.Form("txtPassword"))<>"***" then
    rs("F_Password")=md5(Trim(Request.Form("txtPassword")))
  end if
  rs("F_UserGrade")=Trim(Request.Form("selUserGrade"))
  rs.update
  response.redirect "admin_User.jsp?action=IsModify&pageno="&Request.Querystring("pageno")
  mFlag="insert"
end if

'Delect Records
if Request.QueryString("action")="delete" then
  mSql = "DELETE FROM T_Admin WHERE F_ID=" &Request.QueryString("DeleteID")
  conn.execute mSql
  Response.write "<script>location.replace('admin_User.jsp?action=IsDelete&pageno="&Request.Querystring("pageno")&"')</script>"
end if


if Request.QueryString("action")="popedom" then
  ' dim mUserName,super,mFlag
   mSql="select F_UserName,F_Flag from T_Admin where F_ID="&Request("userid")
   set rs=conn.execute(mSql)
   UserName=rs(0)
   Flag=rs(1)
   rs.close
   mFlag="popedom"
end if

if Request.QueryString("action")="update" then
	flag = ","&replace(request.Form("flag")," ","")&","
   mSql="select F_UserName,F_Flag from T_Admin where F_ID="&Request.Form("hidUserID")
   rs.open mSql,conn,1,3
   rs("F_Flag")=flag
   rs.update
   if rs("F_UserName")=session("master") then 
      session("flag")=flag
   end if
   rs.close
   response.redirect "admin_User.jsp"
end if
%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="Images/Style.css" rel="stylesheet" type="text/css">
<SCRIPT language="JavaScript">
function jDelete(url)
{
  if((confirm(" 警告:请确定是否删除,删除后不能恢复! "))==true) 
	self.location=url+'&action=delete';
}
</SCRIPT>
<script language="javascript">
function CheckData(){
  if (document.form1.txtUserName.value=="")
   {
    alert("用户名不能为空，请输入！");
	document.form1.txtUserName.focus();
	return false;
   }
  if (document.form1.txtPassword.value=="")
   {
    alert("密码不能为空，请输入！");
	document.form1.txtPassword.focus();
	return false;
   }

}

function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.name != 'chkall')
       e.checked = form.chkall.checked;
    }
  }
</script>

</head>
<body text="#000000" >
<br>
<table class=tableBorder width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>
	
	<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
       <tr> 
          <th height="22" colspan="8" align="center" sytle="line-height:150%">用户权限管理</th>
        </tr> 
	    <tr style="cursor:hand" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#EBEEF6'" align="center"> 
          <td class=forumHeaderBackgroundAlternate width="5%"><b>ID</b></td>
          <td class=forumHeaderBackgroundAlternate width="11%"><b>用户名</b></td>
          <td class=forumHeaderBackgroundAlternate width="12%"><b>用户级别</b></td>
          <td class=forumHeaderBackgroundAlternate><b>访问IP</b></td>
          <td class=forumHeaderBackgroundAlternate width="22%"><b>登陆时间</b></td>
          <td class=forumHeaderBackgroundAlternate width="7%"><b>登陆</b></td>
          <td class=forumHeaderBackgroundAlternate width="8%"><b>权限</b></td>
          <td class=forumHeaderBackgroundAlternate width="15%"><b>管理<a title="添加记录" href='admin_User.jsp?pageno=<%=mPage%>'><font color="#666666">[添加]</font></a></b></td>
        </tr>
      </table>
      <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
        <%  
	Set rs=Server.createobject("Adodb.RecordSet")
    pageno=request.querystring("pageno")
    pmcount=16  
    mSql="select * from T_Admin where F_ID<>50 order by F_Addtime desc"
	rs.open mSql,conn,1,1

	if rs.eof then
	   'response.write "<br><p  align='center'><font color=red><B> 对不起，数据已清空！</B></font></p>"
    else
    rs.pagesize=pmcount
    mpage=rs.pagecount
    if pageno="" then pageno=1
    if  cint(pageno)<1 or cint(pageno)>mpage then  pageno=1
    rs.absolutepage=pageno

 Dim rc,re
 rc=rs.pagesize
 re=1
 do while not rs.eof and rc>0
 mBgColor=Request.Querystring("BgColor")
 if Trim(rs("F_ID"))=Trim(mBgColor) then mColor= "D6DFFF" else mColor= "ffffff"
%>
        <tr bgcolor="<%=mColor%>"  > 
          <td class=forumRow  width="5%" align="center"><%=rs("F_ID")%></td>
          <td class=forumRow width="11%" align="center" ><%=rs("F_UserName")%> </td>
          <td class=forumRow  width="12%" align="center" > 
            <%if rs("F_UserGrade")="1" then response.write "<font color=red>超级管理员</font>" else Response.write "管理员"%>
          </td>
          <td class=forumRow align="center" ><%=rs("F_IPInfo")%>&nbsp;</td>
          <td class=forumRow width="22%" align="center" ><%=rs("F_AddTime")%> </td>
          <td class=forumRow width="7%" align="center" ><%=rs("F_LoginCount")%></td>
          <td class=forumRow width="8%" align="center" ><a href="admin_User.jsp?userid=<%=rs("F_ID")%>&action=popedom"><font color="#FF3300">[权限]</font></a> 
          </td>
          <td class=forumRow width="15%" align="center" ><a title="添加记录" href='admin_User.jsp?pageno=<%=mPage%>'></a><a title="修改记录" href='admin_User.jsp?action=edit&ModifyID=<%=rs("F_ID")%>&BgColor=<%=rs("F_ID")%>&pageno=<%=cstr(pageno)%>'><font color="#666666">[修改]</font></a><%if rs("F_UserGrade")="1" then
			response.write "<font color=#999999 title=超级管理员，不能删除>[删除]</font>"
			else%><a title="请确定是否删除,删除后不能恢复!" href="javascript:jDelete('admin_User.jsp?DeleteID=<%=rs("F_ID")%>&pageno=<%=cstr(pageno)%>')"><font color="#666666">[删除]</font></a> 
            <%end if%>
          </td>
        </tr>
        <%
 rs.movenext
 re=re+1
 rc=rc-1
 loop
 end if
%>
      </table>
      <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="FFFFFF">
        <tr> 
          <td class=forumRow width="37%" height="22"> &nbsp;共 <font color=red><strong>
            <% = rs.recordcount%>
            </strong></font> 条记录 当前第 <font color=red><strong>
            <% = Trim(pageno)%>
            </strong></font>页/共 <font color=red><strong>
            <% = Trim(mpage)%>
            </strong></font>页 </td>
          <td class=forumRow width="63%" align="right"> 
            <%
if pageno>1 then
   response.write "<a href='admin_User.jsp'> <img alt='首页' src='Images/boqb02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='首页' src='Images/boqb02.gif' border=0 width='15' height='14'>"
end if

if pageno>1 then
   response.write "<a href='admin_User.jsp?pageno="&pageno-1&"'><img alt='上一页' src='Images/bob02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='上一页' src='Images/bob02.gif' border=0 width='15' height='14'>"
end if

add=5'数字分页个数+1
if pageno-int(add/2)<=1 then m=1 else m=pageno-int(add/2)
if m+add>mpage then 
   n=mpage
   if mpage-add<=1 then m=1 else m=mpage-add
else
   n=m+add
end if

for pno=m to n
 if pno=cint(pageno) then
   response.write "&nbsp;<font color=red>"&pno&"</font>"
 else
   response.write "<b>&nbsp;<a href='admin_User.jsp?pageno="&pno&"'>"&pno&"</a></b>"
 end if
next
response.write "&nbsp"

if int(pageno) < int(rs.pagecount) then
  response.write "<a href='admin_User.jsp?pageno="&pageno+1&"'><img alt='下一页' src='Images/fbob02.gif' border=0 width='15' height='14'></a>"
else 
  response.write "<img alt='下一页' src='Images/fbob02.gif' border=0 width='15' height='14'>"
end if

if int(pageno) < int(rs.pagecount) then
   response.write "<a href='admin_User.jsp?pageno="&mpage&"'><img alt='末页' src='Images/fboqb02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='末页' src='Images/fboqb02.gif' border=0 width='15' height='14'>"
end if
Response.write "&nbsp;&nbsp;"

%>
          </td>
        </tr>
      </table></td>
  </tr>
</table>
<%if mFlag="insert" then'add%><br>
 <form name="form1" method="post" action="admin_User.jsp?pageno=<%=mpage%>&action=Insert" onSubmit="return CheckData()">
        
<table class=tableBorder  width="95%" border="0" align="center" cellpadding="2" cellspacing="1" >
  <tr> 
    <th height="22" colspan="8" align="center" sytle="line-height:150%">功能：添加记录</th>
  </tr>
  <tr> 
    <td width="14%" height="17" class=forumRow>用户名称：</td>
    <td class=forumRowHighlight width="88%"><input name="txtUserName" type="text"class='INPUT' value="" size="18" maxlength="20"></td>
  </tr>
  <tr> 
    <td class=forumRow>用户密码： </td>
    <td class=forumRowHighlight><input name="txtPassword" type="password"class='INPUT' value="" size="18" maxlength="20"></td>
  </tr>
  <tr> 
    <td class=forumRow>用户极别：</td>
    <td class=forumRowHighlight><select name="selUserGrade" >
        <option value="0">普通管理员</option>
        <option value="1">超级管理员</option>
      </select></td>
  </tr>
  <tr> 
    <td class=forumRowHighlight height="37" colspan="2"><input type="submit" name="Submit32" value="提交" class="button"> 
        <input type="reSet" name="Submit222" value="重置" class="button"></td>
  </tr>
</table>
</form>
<%end if
		if mFlag="edit" then
		%>
<br>
<form name="form1" method="post" action="admin_User.jsp?pageno=<%=request("pageno")%>&action=editsave&ModifyID=<%=request("ModifyID")%>" onSubmit="return CheckData()">
<table class=tableBorder width="95%" border="0" align="center" cellpadding="2" cellspacing="1">
  <tr> 
    <th height="22" colspan="8" align="center" sytle="line-height:150%">功能：修改记录</th>
  </tr>
  <tr> 
    <td class=forumRow width="14%">用户名称：</td>
    <td class=forumRowHighlight width="88%"><input name="txtUserName" type="text"class='INPUT' value="<%=mUserName%>" size="18" maxlength="20"></td>
  </tr>
  <tr> 
    <td class=forumRow>用户密码： </td>
    <td class=forumRowHighlight><input name="txtPassword" type="password" class='INPUT' value="***" size="18" maxlength="20"></td>
  </tr>
  <tr> 
    <td class=forumRow>用户极别：</td>
    <td class=forumRowHighlight><select name="selUserGrade" >
        <option value="0">普通管理员</option>
        <option value="1">超级管理员</option>
      </select></td>
  </tr>
  <tr > 
    <td class=forumRowHighlight height="37" colspan="2"><input type="submit" name="Submit3" value="提交" class="button"> 
        <input type="reSet" name="Submit22" value="重置" class="button"></td>
  </tr>
</table>
</form>
<%end if
		
		if mFlag="popedom" then
		%>
        <form name="flag" method="post" action="admin_User.jsp?action=update"> 
        <table class=tableBorder  width="95%" border="0" align="center" cellpadding="2" cellspacing="1">
          <tr > 
            <th height="22"> 功能：给 <font color="red"><%=UserName%></font> 分配管理员权限</span></th>
          </tr>
          <tr> 
            
      <td class=forumRow valign="top" bgcolor="fcfcfc">
        <%
dim tmpmenu,menuname,menurl
for i=0 to ubound(admin_menu,1)
%>
<b><%=admin_menu(i,0,0)%></b><br>
        <%
on error resume next
for j=1 to ubound(admin_menu,2)
if isempty(admin_menu(i,j,0)) then exit for
tmpmenu=split(admin_menu(i,j,0),",")
menuname=tmpmenu(0)
%>
        <input type="checkbox" name="flag"<%if instr(session("flag"),",0|3|0,")=0 then response.write "disabled=true"%> value="<%=i&"|"&j&"|0"%>"<%if instr(flag,i&"|"&j&"|0")<>0 then response.write "checked"%>><%=menuname%><font color="#FF0000">(<%=i&"|"&j&"|0"%>)</font>
<%
if i>1 then Response.Write "<br>└─"
for z=1 to ubound(admin_menu,3)
if admin_menu(i,j,z)<>"" then
%><input type="checkbox" name="flag"<%if instr(session("flag"),",0|3|0,")=0 then response.write "disabled=true"%> value="<%=i&"|"&j&"|"&z&""%>"<%if instr(flag,i&"|"&j&"|"&z&"")<>0 then response.write "checked"%>><%=admin_menu(i,j,z)%><font color="#FF0000">(<%=i&"|"&j&"|"&z&""%>)</font>
<%
end if
next
if i>1 then Response.Write "<br>"
%><%next%>
<br><br><%next%>
        <input type=hidden name=hidUserID value="<%=request("userid")%>"> <input type="submit" name="Submit" value="更新" class='button'> 
        <input name=chkall type=checkbox value=on onClick=CheckAll(this.form)>
        选择所有权限 </td>
          </tr>
        </table> 
        </form>
        <%end if%>


</body>
</html>
<%
 rs.close
 set rs = nothing
 CloseDatabase
%>
