<!--#include file="user_top.asp"-->
<!--#include file="inc/class_blog.asp"-->
<%
'----------------------------------------
'Oblog4改造文件
'应用于所有模块中的用户分类，只支持一级类
'日志/相册/通讯录/网摘
'----------------------------------------
%>
</head>
<body scroll="no" style="overflow:auto!important;overflow:hidden;background:#fff;">

<%
Dim rs, sql, blog
Dim id, action
action = Trim(request("action"))
id = Int(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
%>
</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.l_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.l_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.l_uid)
    oblog.execute("update [oblog_log] set subjectid=0 where subjectid="&id&" and userid="&oblog.l_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.l_uid,conn,1,3
    If Not rs.EOF Then
        rs("subjectname") = subjectname
        rs.Update
    End If
    rs.Close
    Set rs = Nothing
    %>
    <script language="javascript">
    	//alert("修改分类名称成功!");
    	parent.location.href="user_subject.asp?t=<%=t%>";
  	</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
                oblog.execute("update [oblog_subject] set ordernum=9999999 where ordernum="&ordernum-1&" and userid="&oblog.l_uid & " And SubjectType=" & t)
                oblog.execute("update [oblog_subject] set ordernum=ordernum-1 where ordernum="&ordernum&" and userid="&oblog.l_uid & " And SubjectType=" & t)
                oblog.execute("update [oblog_subject] set ordernum="&ordernum&" where ordernum=9999999"&" and userid="&oblog.l_uid & " And SubjectType=" & t)
            End If
        Case "down"
            Set rs = oblog.execute("select max(ordernum) from oblog_subject where userid=" & oblog.l_uid)
            If ordernum < rs(0) Then
                oblog.execute("update [oblog_subject] set ordernum=9999999 where ordernum="&ordernum+1&" and userid="&oblog.l_uid & " And SubjectType=" & t)
                oblog.execute("update [oblog_subject] set ordernum=ordernum+1 where ordernum="&ordernum&" and userid="&oblog.l_uid & " And SubjectType=" & t)
                oblog.execute("update [oblog_subject] set ordernum="&ordernum&" where ordernum=9999999 and userid=" & oblog.l_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.l_uid & " And SubjectType=" & t)
    ReDim ordernum(rs(0))
    Set rs = oblog.execute("select subjectid from [oblog_subject] where userid=" & oblog.l_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()
%>
<script language="javascript">
	/* 发表页面弹出窗口 */
function doMenu1(MenuName,URL){
//	alert("测试 ");
	document.getElementById("chgClass").src=URL;
	document.getElementById(MenuName).style.display = "block";
//	alert("测试2 ");
//	if(document.getElementById(MenuName).style.display == "block"){
//		document.getElementById(MenuName).style.display = "none";
//	}
//	else{
//		document.getElementById(MenuName).style.display == "block";
//		}
	}
</script>
<style type="text/css">
<!--
	.content_li_top .t1 {padding-left:3px;}
	.content_li_top .tt2 {width:40%;margin-right:-4px;}
	.content_li_top .tt3 {width:200px}
	.content_li_conten .t1 {font-weight:600;}
	.content_li_conten .t3 {width:40%!important;}
	.content_li_conten .tt3 {width:200px}

-->
</style>
<ul id="user_page_top">
	<li id="p9"><a href="#" onClick="return doMenu('swin1');">添加分类</a></li>
</ul>
<div id="user_page_content">
		<ul class="content_li_top">
			<li class="t1">排序</li>
			<li class="tt2"><%=tName%>分类名</li>
			<li class="tt3">管理</li>
		</ul>
		<div id="content_li">
<%
Dim rs
Set rs = oblog.execute("select * from oblog_subject where userid=" & oblog.l_uid & " And SubjectType=" & t & " order by ordernum")
While Not rs.EOF
%>
			<ul class="content_li_conten">
				<li class="t1"><span><%=rs("ordernum")%></span></li>
				<li class="t3"><%="<a href='"&blogdir&oblog.l_udir&"/"&oblog.l_ufolder&"/cmd."&f_ext&"?uid="&oblog.l_uid&"&do=blogs&id="&rs("subjectid")&"' target='_blank'>"&oblog.filt_html(rs("subjectname"))&"</a>"%></li>
				<li class="tt3"><a onClick="return doMenu1('swin2','user_subject.asp?action=modify&id=<%=rs("subjectid")%>&oldname=<%=rs("subjectname")%>&t=<%=t%>');" href="#">修改</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>
</div>
<div id="swin1" style="display:none;position:absolute;top:41px;left:10px;z-index:100;">
	<table class='win_table' align='center' border='0' cellpadding='0' cellspacing='1'>
		<tr>
			<td colspan='2' align='center' class='win_table_top'>添加<%=tName%>分类</td>
		</tr>
		<tr>
			<td colspan='2'><%If t=0 Or t=1 Or t="" Then %>
				添加<%=tName%>分类后，只有在此分类发表<%=tName%>才会在首页显示出来!
				<%End If%>
			</td>
		</tr>
		<tr>
			<td class='win_table_td'><%=tName%>分类名称：</td>
			<td>
				<form name="form1" method="post" action="user_subject.asp?action=addclass&t=<%=t%>">
				<input name="subjectname" type="text" id="subjectname" maxlength="50" /> <input type="submit" value="添加" /></form>
			</td>
		</tr>
		<tr>
			<td colspan='2' class="win_table_end"><input type="submit" onClick="return doMenu('swin1');" value="关闭" title="关闭" /></td>
		</tr>
	</table>
</div>
<div id="swin2" style="display:none;position:absolute;top:50px;left:50px;z-index:100;">
<iframe class="FrmID" id="chgClass"  style="width:400px;height:122px;" src="" frameborder="0" scrolling="auto" onunload="parent.location.href='user_subject.asp?t=<%=t%>'"></iframe>
</div>
<div id="swin3"></div>
<div id="swin4"></div>
<div id="swin5"></div>
<iframe id="DivShim" scrolling="no" frameborder="0" style="position:absolute;top:0px; left:0px;display:none"></iframe>
</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.l_uid)
    If Not rs.EOF Then
    oldname = oblog.filt_html(rs(0))
%>
	<table class='win_table' align='center' border='0' cellpadding='0' cellspacing='1'>
		<tr>
			<td colspan='2' align='center' class='win_table_top'>修改<%=tName%>分类</td>
		</tr>
		<tr>
			<td colspan='2'>更改<%=tName%>分类名后，需要更新首页才会使修改生效!</td>
		</tr>
		<tr>
			<td class='win_table_td'><%=tName%>分类名称：</td>
			<td>
				<form name="form1" method="post" action="user_subject.asp?action=savemodi&id=<%=id%>&t=<%=t%>">
				<input name="subjectname" type="text" id="subjectname" maxlength="20" value="<%=oldname%>" /> <input type="submit" value="修改" />
				</form>
			</td>
		</tr>
		<tr>
			<td colspan='2' class="win_table_end"><input type="button" onClick="return parent.doMenu('swin2');" value="关闭" title="关闭" /></td>
		</tr>
	</table>
<%
    Set rs = Nothing
    End If
End Sub

%>