<!--#include file="conn.asp"-->
<!--#include file="user_chkpass.asp"-->
<!--#include file="inc/usercode.asp"-->
<!--#include file="inc/function.asp"-->
<%
if CheckUserLogined()=False then
	response.Redirect "user_login.asp"
end if
call uporder()
%>
<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()
	call uporder()
	dim subjectname,rs,ordernum
	subjectname=Trim(Request.Form("subjectname"))
	If subjectname="" Then
		Response.Write("<script language=javascript>alert('名称不能为空！');window.location.replace('user_subject.asp')</script>")
		Response.End()
	End If	 
	if Instr(subjectname,"=")>0 or Instr(subjectname,"%")>0 or Instr(subjectname,chr(32))>0 or Instr(subjectname,"?")>0 or Instr(subjectname,"&")>0 or Instr(subjectname,";")>0 or Instr(subjectname,",")>0 or Instr(subjectname,"'")>0 or Instr(subjectname,",")>0 or Instr(subjectname,chr(34))>0 or Instr(subjectname,chr(9))>0 or Instr(subjectname,"")>0 or Instr(subjectname,"$")>0 then
    	Response.Write("<script language=javascript>alert('包含非法字符！');window.location.replace('user_subject.asp');</script>")
		Response.End
	end if
	set rs=conn.execute("select max(ordernum) from subject where username='"&username&"'")
	if not isnull(rs(0)) then
		ordernum=rs(0)+1
	else
		ordernum=1
	end if
	conn.execute("insert into [subject] (subjectname,username,ordernum) values ('"&subjectname&"','"&username&"',"&ordernum&")")
	set rs=nothing
	call closeconn()
	response.Redirect "user_subject.asp"
end sub

sub delclass
	dim id
	id=clng(request.QueryString("id"))
   conn.execute("delete  from [subject] where id="&id)
   conn.execute("update [blog] set subjectid=0 where subjectid="&id)
   call uporder()
    response.Redirect "user_subject.asp"
end sub

sub savemodify()
	dim id,subjectname
	id=clng(request.QueryString("id"))
	subjectname=Trim(Request.Form("subjectname"))
	   If subjectname="" Then
    	  Response.Write("<script language=javascript>alert('名称不能为空！');history.back()</script>")
	      Response.End()
	   End If
	if Instr(subjectname,"=")>0 or Instr(subjectname,"%")>0 or Instr(subjectname,chr(32))>0 or Instr(subjectname,"?")>0 or Instr(subjectname,"&")>0 or Instr(subjectname,";")>0 or Instr(subjectname,",")>0 or Instr(subjectname,"'")>0 or Instr(subjectname,",")>0 or Instr(subjectname,chr(34))>0 or Instr(subjectname,chr(9))>0 or Instr(subjectname,"")>0 or Instr(subjectname,"$")>0 then
	   Response.Write("<script language=javascript>alert('包含非法字符！');history.back();</script>")
	   Response.End
   end if                     
   on error resume next
   conn.execute("update [subject] set subjectname='"&subjectname&"' where id="&id)
   call closeconn()
	response.Redirect "user_subject.asp"
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 [subject] set ordernum=999999 where ordernum="&ordernum-1)
				conn.execute("update [subject] set ordernum=ordernum-1 where ordernum="&ordernum)
				conn.execute("update [subject] set ordernum="&ordernum&" where ordernum=999999")
			end if			
		case "down"
			set rs=conn.execute("select max(ordernum) from subject")
			if ordernum<rs(0) then
				conn.execute("update [subject] set ordernum=999999 where ordernum="&ordernum+1)
				conn.execute("update [subject] set ordernum=ordernum+1 where ordernum="&ordernum)
				conn.execute("update [subject] set ordernum="&ordernum&" where ordernum=999999")
			end if
			set rs=nothing
			call closeconn()		
	end select
	response.Redirect "user_subject.asp"
end sub

sub uporder()
	dim rs,i,n
	n=0
	set rs=conn.execute("select count(id) from [subject] where username='"&username&"'")
	redim ordernum(rs(0))
	set rs=conn.execute("select id from [subject] where username='"&username&"' 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 subject 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="user_subject.asp?action=addclass">
          <td height="20" colspan="3"><div align="center">专题(分类)名称：
			  <input name="subjectname" type="text" id="subjectname" 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 subject where username='"&username&"' 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("subjectname")%></div></td>
    <td><div align="center"><a href="user_subject.asp?action=modify&id=<%=rs("id")%>&oldname=<%=rs("subjectname")%>">修改</a> | <a href="user_subject.asp?action=del&id=<%=rs("id")%>" <%="onClick='return confirm(""确定要删除此分类吗(不可恢复)？"");'"%>>删除</a> |
    <a href="user_subject.asp?action=order&modi=up&ordernum=<%=rs("ordernum")%>">向上移动</a> | <a href="user_subject.asp?action=order&modi=down&ordernum=<%=rs("ordernum")%>">向下移动</a></div></td></tr>
<%
rs.movenext
wend 
set rs=nothing
call closeconn()
%>
</table>
<br>
<%
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="user_subject.asp?action=savemodi&id=<%=id%>">
    <td height="25"><div align="center">专题(分类)名称：
        <input name="subjectname" type="text" id="subjectname" maxlength="20" value="<%=oldname%>">
        <input type="submit" name="Submit" value="修改">
    </div></td></form>
  </tr>
</table>
<br>
<%
end sub%>
</body>

