<!--#include file="conn.asp"-->
<!--#include file="Admin_Chkpass.asp"-->
<link href="Admin_STYLE.CSS" rel="stylesheet" type="text/css"> 
<body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0" class="bgcolor">
<%
dim action
action=request.QueryString("action")
select case action
	case "addclass"
		call addclass()
	case "del"
		call delclass()
	case "modify"
		call modifyclass()
	case "savemodi"
		call savemodify()
	case "order"
		call order()
	case else
		call main
end select

sub addclass()
	dim classname,rs,ordernum
	classname=Trim(Request.Form("classname"))
	If classname="" Then
		Response.Write("<script language=javascript>alert('名称不能为空！');window.location.replace('admin_class.asp')</script>")
		Response.End()
	End If	 
	if instr(classname,"'") or instr(classname,"select") or instr(classname,"in") or instr(classname,"from") or instr(classname,"len") or instr(classname,"where") or instr(classname,"or") or instr(classname,"and") then
    	Response.Write("<script language=javascript>alert('包含非法字符！');window.location.replace('admin_class.asp');</script>")
		Response.End
	end if
	set rs=conn.execute("select max(ordernum) from classname")
	if not isnull(rs(0)) then
		ordernum=rs(0)+1
	else
		ordernum=1
	end if
	conn.execute("insert into [classname] (classname,ordernum) values ('"&classname&"',"&ordernum&")")
	set rs=nothing
	call PutApplicationValue()
	call closeconn()
	Response.Write("<script language=javascript>alert('成功填加！');window.location.replace('admin_class.asp')</script>")
end sub

sub delclass
	dim id
	id=clng(request.QueryString("id"))
	'on error resume next
   conn.execute("delete from [classname] where id="&id)
   conn.execute("update [blog] set classid=0 where classid="&id)
   call uporder()
   call PutApplicationValue()
   call closeconn()
   response.Redirect "admin_class.asp"
end sub

sub savemodify()
	dim id,classname
	id=clng(request.QueryString("id"))
	classname=Trim(Request.Form("classname"))
	   If classname="" Then
    	  Response.Write("<script language=javascript>alert('名称不能为空！');history.back()</script>")
	      Response.End()
	   End If
   if instr(classname,"'") or instr(classname,"select") or instr(classname,"in") or instr(classname,"from") or instr(classname,"len") or instr(classname,"where") or instr(classname,"or") or instr(classname,"and") then
	   Response.Write("<script language=javascript>alert('包含非法字符！');history.back();</script>")
	   Response.End
   end if                     
   on error resume next
   conn.execute("update [classname] set classname='"&classname&"' where id="&id)
   call PutApplicationValue()
   call closeconn()
	Response.Write("<script language=javascript>alert('修改成功！');window.location.replace('admin_class.asp')</script>")

end sub

sub order()
	dim ordernum,modi,rs
	ordernum=clng(request.QueryString("ordernum"))
	modi=request.QueryString("modi")
	select case modi
		case "up"
			if ordernum-1>0 then
				conn.execute("update [classname] set ordernum=999999 where ordernum="&ordernum-1)
				conn.execute("update [classname] set ordernum=ordernum-1 where ordernum="&ordernum)
				conn.execute("update [classname] set ordernum="&ordernum&" where ordernum=999999")
			end if			
		case "down"
			set rs=conn.execute("select max(ordernum) from classname")
			if ordernum<rs(0) then
				conn.execute("update [classname] set ordernum=999999 where ordernum="&ordernum+1)
				conn.execute("update [classname] set ordernum=ordernum+1 where ordernum="&ordernum)
				conn.execute("update [classname] set ordernum="&ordernum&" where ordernum=999999")
			end if
			set rs=nothing					
	end select
	call PutApplicationValue()
	call closeconn()
	response.Redirect "admin_class.asp"
end sub

sub uporder()
	dim rs,i,n
	n=0
	set rs=conn.execute("select count(id) from [classname]")
	redim ordernum(rs(0))
	set rs=conn.execute("select id from [classname] order by ordernum")
	while not rs.eof
		ordernum(n)=rs(0)
		n=n+1
		rs.movenext		
	wend
	i=1
	for n=0 to ubound(ordernum)
		conn.execute("update classname set ordernum="&i&" where id="&clng(ordernum(n)))
		i=i+1		
	next
	set rs=nothing
end sub

sub main()
%>
<br>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
  <tr valign="middle"> 
    <td height="22" colspan="3" class="topbg"><div align="center"><strong>添加系统日志分类</strong></div></td>
  </tr>
   <tr class="tdbg"><form name="form1" method="post" action="admin_class.asp?action=addclass">
          <td height="20" colspan="3"><div align="center">系统日志分类名称：
			<input name="classname" type="text" id="classname" maxlength="20">
            <input type="submit" name="Submit" value="添加">			             
          </div></td></form>
  </tr>
</table>
		<br><br>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
        <tr class="topbg" height="25">
          <td width="100" >        <div align="center">排序</div></td>
          <td width="200">        <div align="center">系统日志类别名</div></td>
          <td>          <div align="center">系统日志分类管理操作</div></td>
		  </tr>
<%
dim rs
set rs=conn.execute("select * from classname order by ordernum")
while not rs.eof 
%>
  <tr class="tdbg" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#BFDFFF'"> 
  <td > <div align="center"><%=rs("ordernum")%></div></td>
    <td><div align="center"><%=rs("classname")%></div></td>
    <td><div align="center"><a href="admin_class.asp?action=modify&id=<%=rs("id")%>&oldname=<%=rs("classname")%>">修改</a> | <a href="admin_class.asp?action=del&id=<%=rs("id")%>" <%="onClick='return confirm(""确定要删除此分类吗(不可恢复)？"");'"%>>删除</a> |
    <a href="admin_class.asp?action=order&modi=up&ordernum=<%=rs("ordernum")%>">向上移动</a> | <a href="admin_class.asp?action=order&modi=down&ordernum=<%=rs("ordernum")%>">向下移动</a></div></td></tr>
<%
rs.movenext
wend 
set rs=nothing
call closeconn()
%>
</table>
<br>
<%
call copyright()
end sub

sub modifyclass()
dim id,oldname
id=request.QueryString("id")
oldname=request.QueryString("oldname")
%>
<br>
<table width="98%"  border="0" align="center" cellpadding="0" cellspacing="0" class="border">
  <tr>
    <td height="22" class="topbg"><div align="center"><strong>修改系统日志分类</strong></div></td>
  </tr>
  <tr><form name="form1" method="post" action="admin_class.asp?action=savemodi&id=<%=id%>">
    <td height="25"><div align="center">系统日志分类名称：
        <input name="classname" type="text" id="classname" maxlength="20" value="<%=oldname%>">
        <input type="submit" name="Submit" value="修改">
    </div></td></form>
  </tr>
</table>
<br>
<%
call copyright()
end sub%>
</body>

