<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="admin.asp"-->
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<%
if session("type")="1" then
   response.Write("<script>alert('Sorry,普通管理员没有权限操作!'); location.href='cw_right.asp'</script>")
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>管理员管理</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function checkpass(fr)
{
  if(fr.pass1.value=="")
  {
     alert('原密码不能为空！');
	 fr.pass1.focus();
	 return false
  }
  if(fr.pass2.value=="")
  {
    alert('新密码不能为空！');
	fr.pass2.focus();
	return false
  }
  if(fr.pass3.value=="")
  {
    alert('确认密码不能为空！');
	fr.pass3.focus();
	return false
  }
  if((fr.pass2.value)!==(fr.pass3.value))
  {
     alert("新密码与确认密码不一致！");
	 fr.pass3.focus();
	 fr.pass3.select();
	 return false
  }
  return true
}
function checkpro(fr)
{
  if(fr.user.value=="")
  {
    alert('用户名不能为空！');
	fr.user.focus();
	return false
  }
  if(fr.pass.value=="")
  {
    alert('用户密码不能为空！')
	fr.pass.focus();
	return false
  }
  if(fr.pass2.value=="")
  {
    alert('确认密码不能为空！')
	fr.pass.focus();
	return false
  }
  if((fr.pass.value)!==(fr.pass2.value))
  {
     alert('两次输入的密码不一致！')
	 fr.pass2.focus();
	 fr.pass2.select();
	 return false
  }
  return true
}
</script>
</head>
<%
if request("action")=1 then
set rs=server.CreateObject("adodb.recordset")
sql="select * from cw_admin where id="&request("id")
rs.open sql,conn,1,3
if md5(request("pass1"))<>rs("pass") then
   response.Write("<script>alert('原密码错误！');history.back();</script>")
   response.End()
else
   rs("pass")=md5(request("pass3"))
end if
rs.update
rs.close
set rs=nothing
response.Write("<script>alert('密码修改成功!');location.href='cw_pro.asp';</script>")
response.End()
end if

If request("act")=2 then
   set rs=server.CreateObject("adodb.recordset")
   sql="select * from cw_admin where [user]='"&request("user")&"'"
   rs.open sql,conn,1,3
   If not rs.eof then
       Response.Write("<script>alert('此用户名己经存在了！');localhost.href='cw_pro.asp';</script>")
	   Response.End()
   Else
      rs.addnew
	  rs("user")=trim(request("user"))
	  rs("pass")=md5(trim(request("pass")))
	  rs("type")=request("type")
	  rs.update
   End If
   rs.close
   set rs=nothing
   response.Write("<script>alert('添加用户成功！');location.href='cw_pro.asp';</script>")
End If


If request("act")=3 then
Select Case Request("sub")
   Case 0
      conn.execute("update cw_admin set type="&Request("sub")&" where id in("&Request("cid")&")")
   Case 1
      conn.execute("update cw_admin set type="&Request("sub")&" where id in("&Request("cid")&")")
   Case 2
      If trim(request("cid"))=1 then
	  response.Write("<script>alert('高级用户不能删除！');history.back();</script>")
	  Response.End()
	  Else
      conn.execute("delete from cw_admin where id in("&request("cid")&")")
	  End If
End Select
Response.Redirect"cw_pro.asp"
End if
%>
<body id="page">
<h2 class="title">用户管理</h2>
<table width="99%" border="0" align="center" class="nav">
  <tr>
    <td height="20">&nbsp;网站后台管理 &gt;&gt; <a href="cw_pro.asp">管理员</a> 【<a href="cw_pro.asp?act=6">添加管理员</a>】</td>
  </tr>
</table>
<%if request("act")="" then%>
<form action="cw_pro.asp?act=3" method="post" name="form">
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
      <tr>
        <td width="3%" align="center" bgcolor="#F0F3F5">&nbsp;</td>
        <td width="6%" align="center" bgcolor="#F0F3F5"><b>ID</b></td>
        <td width="18%" align="center" bgcolor="#F0F3F5"><b>用户名</b></td>
        <td width="12%" align="center" bgcolor="#F0F3F5"><b>类型</b></td>
        <td width="10%" align="center" bgcolor="#F0F3F5"><b>管理</b></td>
      </tr>
    <%
		set rs1=server.CreateObject("adodb.recordset")
		sql="select * from cw_admin order by id asc"
		rs1.open sql,conn,1,1
		if not rs1.eof then
		         page_count=15
  				 if Request("page")="" or Request("page")="0" then
   				  page=1
  				 else
    				 page=cint(Request("page"))
  				 End if 
					 totalcount=rs1.RecordCount
   				  totalpage=int(totalcount/page_count+(page_count-1)/page_count)
  				 if page>totalpage then page=totalpage
  				 if rs1.EOF then    
   				  else
   				  for i = 1 to (page-1)*page_count
    				   rs1.MoveNext
   				  Next
   				  if page<totalpage then
    				   psize=page_count
   				  else
   				    psize=totalcount-(page-1)*page_count
   				  End if
   				  for i = 1 to psize
		%>
      <tr>
        <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="cid" id="cid" value="<%=rs1("id")%>" /></td>
        <td align="center" bgcolor="#FFFFFF"><%=rs1("id")%></td>
        <td bgcolor="#FFFFFF">&nbsp;<%=rs1("user")%></td>
        <td align="center" bgcolor="#FFFFFF"><%if rs1("type")=0 then%>高级管理员<%else%>普通管理员<%end if%></td>
	<td align="center" bgcolor="#FFFFFF" ><a href="cw_pro.asp?act=5&id=<%=rs1("id")%>" target="_self">修改密码</a> | <a href="cw_pro.asp?sub=2&cid=<%=rs1("id")%>&act=3" onclick="return confirm('你确定要删除？')">删除</a></td>
      </tr>
	      <%
		 rs1.MoveNext
 		next
		end if
		end if
		rs1.close
		set rs1=nothing
		%>
      <tr >
        <td colspan="8" align="center" bgcolor="#FFFFFF">
		<div style="float:left">
		<input name="button" type="button" onclick="qxbox(this.form.cid)" value="全 选" />
        &nbsp;&nbsp;
        <input name="button" type="button"  onclick="fxbox(this.form.cid)" value="反 选" />
        &nbsp;&nbsp;
        <select name="sub" id="sub">
          <option value="">请选择操作</option>
          <option value="0">设为高级管理员</option>
		  <option value="1">设为普通管理员</option>
		  <optgroup label="&nbsp;&nbsp;"></optgroup>
		   <option value="2">删除用户</option>
        </select>
        <input type="submit" name="Submit" value="批量执行操作" onclick="return confirm('你确定要执行？')" />
		</div>
		<!--#include file="../inc/page.asp"--></td>
    </tr>
  </table>
</form>
	<%end if%>
	<%if request("act")=5 then%>
  <table width="99%" border="0">
<form method="post" name="form1" action="cw_pro.asp?action=1" onsubmit="return checkpass(this)">
  
  <tr>
    <td height="20" align="right">&nbsp;</td>
    <td>用户密码修改</td>
  </tr>
  <tr>
    <td width="100" height="20" align="right">原密码：</td>
    <td><input name="pass1" type="password" id="pass1" maxlength="100" /> 
    *区分大小写 </td>
  </tr>
    
  
  <tr>
    <td height="20" align="right">新密码：</td>
    <td><input name="pass2" type="password" id="pass2" maxlength="30" /></td>
  </tr>
  <tr>
    <td height="20" align="right">确认密码：</td>
    <td><input name="pass3" type="password" id="pass3" maxlength="11" /></td>
  </tr>
  <tr>
    <td height="20" align="right">&nbsp;</td>
    <td><input name="Submit3" type="submit" class="btn" value="修改密码"  />
      <input name="id" type="hidden" id="id" value="<%=request("id")%>" /></td>
  </tr>
  </form>
</table>
<%end if%>
<%if request("act")=6 then%>
  <table width="99%" border="0">
<form method="post" name="form1" action="cw_pro.asp?act=2" onsubmit="return checkpro(this)">
  
  <tr>
    <td height="20" align="right">&nbsp;</td>
    <td>添加管理用户</td>
  </tr>
  <tr>
    <td width="100" height="20" align="right">用 户 名：</td>
    <td><input name="user" type="text" id="user" size="20" maxlength="20" /> 
    *区分大小写 </td>
  </tr>
    
  
  <tr>
    <td height="20" align="right">用户密码：</td>
    <td><input name="pass" type="password" id="pass" size="21" maxlength="20" /> 
    *区分大小写 </td>
  </tr>
  <tr>
    <td height="20" align="right">确认密码：</td>
    <td><input name="pass2" type="password" id="pass2" size="21" maxlength="20" /></td>
  </tr>
  <tr>
    <td height="20" align="right">用户类型：</td>
    <td><input name="type" type="radio" value="0" checked="checked" />
      高级管理员
        <input type="radio" name="type" value="1" />
      普通管理员</td>
  </tr>
  <tr>
    <td height="20" align="right">&nbsp;</td>
    <td><input name="Submit3" type="submit" class="btn" value="添加用户"  /></td>
  </tr>
  </form>
</table>
<%end if%>
<%

call closes()
%>
</body>
</html>
