<!--#include file="user_top.asp"-->
<!--#include file="inc/class_blog.asp"-->
<div id="main">
  <div class="submenu">
  	<div class="side_c1 side11"></div>
    <div class="side_c2 side21"></div>
	<div class="submenu_content">
		
	</div>
  </div>
  <div class="content">
  	<div class="content_top">
		  	<div class="side_d1 side11"></div>
		    <div class="side_d2 side21"></div>
			<%=tName%>类别管理
	</div>
	
    <div class="content_body">
<%
const MaxPerPage=20
dim strFileName
dim totalPut,TotalPages
dim rs,sql,blog
dim id,action
action=trim(request("action"))
id=oblog.filt_badstr(trim(Request("id")))
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
set rs=nothing
%>
	</div>
	
    <div class="content_bot">
		  	<div class="side_e1 side12"></div>
   			<div class="side_e2 side22"></div>
 	</div>
	
  </div>
</div>  
  
  
  <div id="bottom"><%=oblog.user_copyright%></div>

</body>
</html>
<%


sub addclass()
	call uporder()
	dim subjectname,rs,ordernum
	subjectname=Trim(Request.Form("subjectname"))
	If subjectname="" or oblog.strLength(subjectname)>50 then oblog.adderrstr("分类名不能为空且不能大于50字符)！")
	if oblog.chk_badword(subjectname)>0 then oblog.adderrstr("分类名中含有系统不允许的字符！")
	oblog.showusererr
	set rs=oblog.execute("select max(ordernum) from oblog_subject where userid="&oblog.logined_uid & " And SubjectType=" & t)
	if not isnull(rs(0)) then
		ordernum=rs(0)+1
	else
		ordernum=1
	end if
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select top 1 * from [oblog_subject] Where SubjectType=" & t,conn,1,3
	rs.addnew
	rs("subjectname")=subjectname
	rs("userid")=oblog.logined_uid
	rs("ordernum")=ordernum
	rs("subjectType")=t
	rs.update
	rs.close
	set rs=nothing
	oblog.showok "添加分类成功!","user_subject.asp?t=" & t
end sub

sub delclass
	dim id
	id=clng(request.QueryString("id"))
	oblog.execute("delete  from [oblog_subject] where subjectid="&id&" and userid="&oblog.logined_uid)
	oblog.execute("update [oblog_log] set subjectid=0 where subjectid="&id&" and userid="&oblog.logined_uid)
	call uporder()
    oblog.showok "删除分类成功!",""
end sub

sub savemodify()
	dim subjectname,rs
	id=clng(id)
	subjectname=Trim(Request.Form("subjectname"))
	If subjectname="" or oblog.strLength(subjectname)>50 then oblog.adderrstr("分类名不能为空且不能大于50字符)！")
	if oblog.chk_badword(subjectname)>0 then oblog.adderrstr("分类名中含有系统不允许的字符！")
	if oblog.errstr<>"" then oblog.showusererr:exit sub
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select subjectname from [oblog_subject] where subjectid="&id&" and userid="&oblog.logined_uid,conn,1,3
	if not rs.eof then
		rs("subjectname")=subjectname
		rs.update
	end if
	rs.close
	set rs=nothing
	oblog.showok "修改分类名称成功!","user_subject.asp?t=" & t
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
				oblog.execute("update [oblog_subject] set ordernum=9999999 where ordernum="&ordernum-1&" and userid="&oblog.logined_uid & " And SubjectType=" & t)
				oblog.execute("update [oblog_subject] set ordernum=ordernum-1 where ordernum="&ordernum&" and userid="&oblog.logined_uid & " And SubjectType=" & t)
				oblog.execute("update [oblog_subject] set ordernum="&ordernum&" where ordernum=9999999"&" and userid="&oblog.logined_uid & " And SubjectType=" & t)
			end if			
		case "down"
			set rs=oblog.execute("select max(ordernum) from oblog_subject where userid="&oblog.logined_uid)
			if ordernum<rs(0) then
				oblog.execute("update [oblog_subject] set ordernum=9999999 where ordernum="&ordernum+1&" and userid="&oblog.logined_uid & " And SubjectType=" & t)
				oblog.execute("update [oblog_subject] set ordernum=ordernum+1 where ordernum="&ordernum&" and userid="&oblog.logined_uid & " And SubjectType=" & t)			
				oblog.execute("update [oblog_subject] set ordernum="&ordernum&" where ordernum=9999999 and userid=" & oblog.logined_uid & " And SubjectType=" & t)
			end if
			set rs=nothing
	end select
	'uporder()
	response.Redirect "user_subject.asp?t=" & t
end sub

sub uporder()
	dim rs,i,n
	n=0
	set rs=oblog.execute("select count(subjectid) from [oblog_subject] where userid="&oblog.logined_uid & " And SubjectType=" & t)
	redim ordernum(rs(0))
	set rs=oblog.execute("select subjectid from [oblog_subject] where userid=" & oblog.logined_uid & " And SubjectType=" & t & " 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)
		oblog.execute("update oblog_subject set ordernum="&i&" where subjectid="&clng(ordernum(n)))
		i=i+1
		'response.Write(i)		
	next
	set rs=nothing	
end sub

sub main()
%>
<h1>添加<%=tName%>分类</h1>
<div id="list">
	<ul class="list_edit" style="margin-left:0px">
	添加<%=tName%>分类后，只有在此分类发表<%=tName%>才会在首页显示出来!<hr />
   <form name="form1" method="post" action="user_subject.asp?action=addclass&t=<%=t%>">
		<%=tName%>分类名称：
		<input name="subjectname" type="text" id="subjectname" maxlength="50" />
		<input type="submit" value="添加" />			             
		</form>
  </ul>
</div>
<style type="text/css">
<!--
	#list ul{ width: 85%;display:block;clear:both;margin:0px;} 
	li.t1 { width: 50px;} 
	li.t2 { width: 220px;} 
	li.t3 { width: 300px;}
-->
</style> 

<h1><%=tName%>分类管理操作</h1>
<div id="list">
	<ul class="list_edit" style="margin-left:0px">
  更改分类排行,或者删除分类后，需要手动更新首页才会有效!<hr />
  </ul>
	<ul class="list_top">
	<li class="t1">排序</li>
	<li class="t2"><%=tName%>分类名</li>
	<li class="t3">管理</li>
	</ul>
<%
dim rs
set rs=oblog.execute("select * from oblog_subject where userid=" & oblog.logined_uid & " And SubjectType=" & t & " order by ordernum")
while not rs.eof 
%>
  <ul class="list_content" style="float:none">
  <li class="t1"><%=rs("ordernum")%></li>
    <li class="t2"><%="<a href='"&blogdir&oblog.logined_udir&"/"&oblog.logined_ufolder&"/cmd."&f_ext&"?uid="&oblog.logined_uid&"&do=blogs&id="&rs("subjectid")&"' target='_blank'>"&oblog.filt_html(rs("subjectname"))&"</a>"%></li>
    <li class="t3"><a href="user_subject.asp?action=modify&id=<%=rs("subjectid")%>&oldname=<%=rs("subjectname")%>&t=<%=t%>">修改</a> <a href="user_subject.asp?action=del&id=<%=rs("subjectid")%>&t=<%=t%>" <%="onClick='return confirm(""确定要删除此分类吗(不可恢复)？"");'"%>>删除</a>
	 <a href="user_subject.asp?action=order&modi=up&ordernum=<%=rs("ordernum")%>&t=<%=t%>">向上移动</a> <a href="user_subject.asp?action=order&modi=down&ordernum=<%=rs("ordernum")%>&t=<%=t%>">向下移动</a></li></ul>
<%
rs.movenext
wend 
set rs=nothing
%>
</div>
<%
end sub

sub modifyclass()
	dim oldname,rs
	id=clng(id)
	set rs=oblog.execute("select subjectname from oblog_subject where subjectid="&id&" and userid="&oblog.logined_uid)
	if not rs.eof then
	oldname=oblog.filt_html(rs(0))
%>

<h1>修改<%=tName%>分类</h1>
<div id="list">
	<ul class="list_edit">
	更改<%=tName%>分类名后，需要更新首页才会使修改生效!<hr />	
	<form name="form1" method="post" action="user_subject.asp?action=savemodi&id=<%=id%>&t=<%=t%>">
		<%=tName%>分类名称：
		<input name="subjectname" type="text" id="subjectname" maxlength="20" value="<%=oldname%>" />
        <input type="submit" value="修改" />
    	</form>
	</ul>
</div>
<%
	set rs=nothing
	end if
end sub
%>