<!--#include file="tgzcm_Conn.asp"-->
<!--#include file="tgzcm_Check.asp"-->
<%
dim page,action,class_id,data_type
action=ReplaceBadChar(Trim(Request.QueryString("action"))) 
tgzcmid = cint(Request("id"))
UserName = ReplaceBadChar(Trim(Request("UserName")))
Password = ReplaceBadChar(Trim(Request("Password")))
%><html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<TITLE>管理页面</TITLE>
<link href="skins/css/tgzcm_main.css" rel="stylesheet" type="text/css" />
<script language = "javaScript" src = "../Include/tgzcm.Admin.js" type="text/javascript"></script>
</head>
<body>
<%
Select Case action
    Case "add"
       Call add
    Case "edit"
       Call edit
    Case "del"
       conn.execute("delete from tgzcm_admin where admin_id="&tgzcmid)
	   'Call tgzcm_err_a("删除成功！")
	   response.Redirect"tgzcm_master.asp"
    Case "add_save"
		If UserName = "" Then
			Call tgzcm_err_c("用户名不能为空！")
			Response.End
		End If
		If Password = "" Then
			Call tgzcm_err_c("密码不能为空！")
			Response.End
		End If
        maxid=Max_id("admin")
	    conn.execute("insert into tgzcm_admin (admin_id,admin_name,admin_pass,LastLoginIP,LastLoginTime,RndPassword) values ('"&maxid&"','"&UserName&"','"&MD5(Password, 16)&"','"&UserTrueIP&"','"&Now()&"','"&Password&"')")
	    'Call tgzcm_err_a("添加管理员成功！")
		response.Redirect"tgzcm_master.asp"	
    Case "edit_save"
		If UserName = "" Then
			Call tgzcm_err_c("用户名不能为空！")
			Response.End
		End If
		If Password = "" Then
			Call tgzcm_err_c("密码不能为空！")
			Response.End
		End If
		Set rs = Server.CreateObject("adodb.recordset")
        sql = "select * from tgzcm_admin where admin_id="&tgzcmid&" "
        rs.Open sql, Conn, 1, 3
        If not (rs.bof And rs.EOF) Then
		    rs("admin_name")=UserName
		    if Password<>rs("admin_pass") then
			rs("admin_pass")=MD5(Password, 16)
			end if
			rs.update
            response.Redirect"tgzcm_master.asp"	
        Else
		    Call tgzcm_err_c("参数不正确！")
		End if
		rs.close
		set rs=nothing
	    'conn.execute("update tgzcm_admin set admin_name='"&maxid&"',admin_pass='"&MD5(Password, 16)&"' where admin_id="&tgzcmid&" ")	  
    Case Else
        Call main
End Select
%>
<%Sub main%>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr> 
<th colspan=12 style="text-align:center;">网站管理员列表</th>
</tr>
<tr style="text-align:center;">
  <td width="40" class="td1" style="text-align:left; padding-left:10px;">ID</td>
  <td class="td1" style="padding-left:10px;">管理员名称</td>
  <td width="100" class="td1" style="padding-left:10px;">最后登录IP</td>
  <td width="130" class="td1" style="padding-left:10px;"><span class="td1" style="text-align:left; padding-left:10px;">最后登录时间</span></td>
  <td width="100" class="td1" style="padding-left:10px;">常规操作</td>
</tr>
<%
Set rs = Server.CreateObject("adodb.recordset")
sql = "select * from tgzcm_admin order by admin_id desc"
rs.Open sql, Conn, 1, 1
If rs.bof And rs.EOF Then
  Response.Write("没有分类")
Else
 do while not rs.eof
%>
<tr style="text-align:center;">
  <td width="40" class="td1" style="text-align:left; padding-left:10px;"><%=rs("admin_id")%>.</td>
  <td width="165" class="td1" style="text-align:left; padding-left:10px;"><%=rs("admin_name")%></td>
  <td width="100" class="td1" style="text-align: center;"><%=rs("LastLoginIP")%></td>
  <td width="150" class="td1" style="text-align: center;"><%=rs("LastLoginTime")%></td>
  <td width="100" class="td1" style="text-align:center; padding-left:10px;"><a href="?action=edit&id=<%=rs("admin_id")%>">修改</a> <a href="?action=del&id=<%=rs("admin_id")%>" onClick="return confirm('确定要删除吗?');">删除</a></td>
</tr>
<%
 rs.movenext  
 loop 
End If
rs.Close
set rs=nothing
Call CloseConn()'关闭数据库连接
%>
<tr style="text-align:center;">
  <td colspan="5" class="td1" style="text-align:right; padding-left:10px;"><a href="?action=add">添加新管理员</a></td>
  </tr>
</table>
<%End Sub%>

<%Sub add%>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<form method="post" action="?action=add_save">
<tr> 
<th colspan=8 style="text-align:center;">网站管理员添加</th>
</tr>
<tr style="text-align:center;">
  <td class="td1" style="text-align:left; padding-left:10px;">管理员名称：
    <input type="text" name="UserName"></td>
</tr>
<tr style="text-align:center;">
  <td class="td1" style="text-align:left; padding-left:10px;">管理员密码：
  <input type="text" name="Password"></td>
</tr>
<tr style="text-align:center;">
<td  class="td2" style="text-align: center; padding-left:10px;"><input type="submit" name="Submit" value="提交"> <input type="reset" name="Submit2" value="重置"></td>
</tr>
</form>
</table>
<%End Sub%>

<%Sub edit
set rs=conn.execute("select * from tgzcm_admin where admin_id="&tgzcmid)
%>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<form method="post" action="?action=edit_save?&id=<%=rs("admin_id")%>">
<tr> 
<th colspan=8 style="text-align:center;">网站管理员修改</th>
</tr>
<tr style="text-align:center;">
  <td class="td1" style="text-align:left; padding-left:10px;">管理员名称：
    <input name="UserName" type="text" value="<%=rs("admin_name")%>" style="font-size:12px; width:160px;"></td>
</tr>
<tr style="text-align:center;">
  <td class="td1" style="text-align:left; padding-left:10px;">管理员密码：
  <input name="Password" type="password" value="<%=rs("admin_pass")%>" style="font-size:12px; width:160px;">不修改请直接提交</td>
</tr>
<tr style="text-align:center;">
<td  class="td2" style="text-align: center; padding-left:10px;"><input type="submit" name="Submit" value="提交"> <input type="reset" name="Submit2" value="重置"></td>
</tr>
</form>
</table>
<%
set rs=nothing
End Sub
%>
</body>
</html>