<!--#include file="../../Common/Config.asp"-->
<!--#include file="../../Common/Function/Callings.asp"-->
<!--#include file="../../Common/Function/Function.asp"-->
<!--#include file="../../Common/Function/Sub.asp"-->
<!--#include file="../Include/Check.asp"-->
<%
session("nowpage")=Request.ServerVariables("PATH_INFO")
if Request.ServerVariables("QUERY_STRING")<>"" then
	session("nowpage")=session("nowpage")&"?"&Request.ServerVariables("QUERY_STRING")
end if
ClassFID=clng(session("ClassFID"))
%>
<%
'Option Explicit

Dim ModuleID,ModuleName,SqlQueryNum,FoundErr,ErrMsg,SucMsg
Dim InstallDir
ModuleID = request("ModuleID")
ModuleName = "栏目"
If ModuleID=0 Then ModuleID=Web_ModuleID
Dim strClassDir,ClassDir,HtmlFileDir,ChannelDir,ChannelPath
Dim moduleidu
Directory = "article"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=Web_Name%>栏目管理</title>
<link href="<%=Web_Root%>Admin/Css/Style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=Web_Root%>Common/Js/JinCms.all.js"></script>
<script type="text/javascript" src="<%=Web_Root%>Admin/Js/jquery-1.6.2.min.js"></script>

<%Call getValidform("classform",1,0,1)%>
<%call Kindeditormini("editor","Content","SysSet",1)%>
<%call KindeditorPic("editorPic","SysSet",0,"upload","Pic")%>

</head>
<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="../Main/Right.asp">首页</a></li>
    <li><a href="Index.asp">网站栏目管理</a></li>
    </ul>
    </div>
    
    <div id="tab1" style="padding:20px; ">
    
    
    <ul class="umlist" style="height:25px; padding-left:10px">
    <li><a href="?ModuleID=<%=ModuleID%>">栏目管理首页</a></li>
    <li><a href="?action=add&ModuleID=<%=ModuleID%>">新建栏目</a></li>
    <li><a href="?action=Orders&ModuleID=<%=ModuleID%>">一级栏目排序</a></li>
    <li><a href="?action=classOrders&ModuleID=<%=ModuleID%>">N级栏目排序</a></li>
    <li><a href="?action=resume&ModuleID=<%=ModuleID%>"><font color="blue">栏目恢复</font></a></li>
    </ul>
    
    <div class="xline"></div>

<%
Dim Action,Directory


Action = LCase(Request("action"))
Select Case LCase(Action)
Case "savenew"
	Call savenew()
Case "savedit"
	Call savedit()
Case "add"
	Call ClassAdd()
Case "edit"
	Call ClassEdit()
Case "del"
	Call DelClass()
Case "deldir"
	Call DelClassDir()
Case "orders"
	Call orders()
Case "neworders"
	Call updateorders()
Case "restore"
	Call RestoreClass()
Case "classorders"
	Call classorders()
Case "newclassorders"
	Call updateclassorders()
Case "resume"
	Call ResumeClass()
Case "show"
	Call show()
Case "hidden"
	Call hidden()
Case "sy"
	Call sy()
Case "syno"
	Call syno()
Case Else
	Call showmain()
End Select
If FoundErr = True Then
	Response.write(ErrMsg)
End If


Sub showmain()
	Dim Rs,SQL,i,iCount,lCount,AddContentLink
	iCount=1:lCount=2
	Response.Write " <table cellspacing=""1"" class=""tablelist"" cellpadding=""2"" style=""line-height:25px; margin-top:10px;"">"
	Response.Write " <tr>"
	Response.Write " <th width="""">名称</th>"
	Response.Write " <th width="""">标识</th>"
	Response.Write " <th width="""">链接</th>"
	Response.Write " <th width=""90px"">类型</th>"
	Response.Write " <th width=""70px"">是否显示</th>"
	Response.Write " <th width=""130px"">操作</th>"
	Response.Write "</tr>" & vbNewLine
	'If Not IsObject(Conn) Then ConnectionDatabase
	pid=request.QueryString("pid")
	SQL = "SELECT * FROM Jin_Class WHERE ModuleID="& ModuleID &" ORDER BY RootID,Orders"
	Set Rs = Server.CreateObject("ADODB.Recordset")
	Rs.Open SQL, Conn, 1, 1
	SqlQueryNum = SqlQueryNum + 1
	If Rs.BOF And Rs.EOF Then
		Response.Write " <tr> <td colspan=""6"">您还没有添加任何栏目！</td></tr>"
	End If
	Str1=""
	Do While Not Rs.EOF
		If (i mod 2) = 0 Then iCount=1:lCount=2 Else iCount=2:lCount=1
		%>
        <tr class="<%If Rs("Depth")<>0 then%> filter80 <%End If%> <%If Rs("ShowNav")=false then%> filter <%End If%> <%If getParentID(Rs("ID"),1)<>Rs("ID") and getParentID(Rs("ID"),1)<>ClassFID then%> hidden <%End If%>">
        <td <%If Rs("ParentID")=0 Then%><%End If%> style="width:150px; overflow:hidden;">
        <%
		If Rs("Depth") = 0 Then 
			If Rs("Child") > 0 Then Response.Write "<a href=# onclick=""location.href='../System/Sessions.asp?ClassFID_"&rs("ID")&"'"">+</a>&nbsp;" else Response.Write "<font class=filter>+</font>&nbsp;" 
		else  
		Response.Write " &nbsp;&nbsp;"
		End If
		If Rs("Depth") = 1 Then Response.Write "&nbsp;&nbsp;├&nbsp;"
		If Rs("Depth") > 1 Then
			For i = 2 To Rs("Depth")
				Response.Write "&nbsp;&nbsp;│"
			Next
			Response.Write "&nbsp;&nbsp;├&nbsp;"
		End If
		%>
        <input type="text" value="<%=Rs("ClassName")%>" id2="<%=Rs("ID")%>" class="ClassName" style="width:80px; display:inline-block; outline:none; border-bottom:1px dashed #666;" /></td>
        <td><input type="text" value="<%=Rs("ClassName_en")%>" id2="<%=Rs("ID")%>" class="ClassName_en" style="width:100%; outline:none; border-bottom:1px dashed #666;" /></td>
        <td><input type="text" value="<%=Rs("Url")%>" id2="<%=Rs("ID")%>" class="Url" style="width:100%; outline:none; border-bottom:1px dashed #666;" /></td>
        <td>
        <select onChange="window.location.href=this.options[this.selectedIndex].value">
        <%
		Set Rsa=server.createobject("adodb.recordSet")
		Sqla="select * from Jin_ClassType where Show order by SortID asc,sysID desc"
		Rsa.open Sqla,conn,1,3
		For i=1 to Rsa.recordcount
		%>
        <option <%If Rs("ClassType")=Rsa("TypeName_en") Then%>selected<%End If%> value="Ajax.asp?action=CTypeName&id=<%=Rs("ID")%>&value=<%=Rsa("TypeName_en")%>"><%=Rsa("TypeName")%></option>
        <%
		Rsa.movenext
		next
		Rsa.close
		Set Rsa=nothing
		%>
        </select>
        </td>
        <td>
        <%
		If Rs("ShowNav")=True then
		Response.Write " <A href=""?action=hidden&ModuleID="&ModuleID&"&hiddenid="&Rs("ID")&""">隐藏</a>"& vbNewLine
		Else
		Response.Write " <A href=""?action=show&ModuleID="&ModuleID&"&showid="&Rs("ID")&"""><font color=red>显示</font></a>"& vbNewLine
		End If
		%>
        </td>
        <%
		Response.Write " <td> "
		Response.Write "<a href=""?action=add&ModuleID="&ModuleID&"&editid="
		Response.Write Rs("ID")
		Response.Write """>添加</a>"
		Response.Write " | <a href=""?action=edit&ModuleID="&ModuleID&"&editid="
		Response.Write Rs("ID")
		Response.Write """>编辑</a>"
		Response.Write " |"
		Response.Write " "
		If Rs("Child") < 1 Then
			Response.Write " <a href=""?action=del&ModuleID="&ModuleID&"&editid="
			Response.Write Rs("ID")
			Response.Write """ onclick=""return confirm('删除将包括该栏目的所有文章，确定删除吗?')"">删除</a>"
		Else
			Response.Write " <a href=""#"" onclick=""return confirm('该栏目含有下属栏目，必须先删除其下属栏目方能删除本栏目！')"">"
			Response.Write " 删除</a>"
		End If
		Response.Write " </td>" & vbNewLine
		Response.Write "</tr>" & vbNewLine
		Rs.movenext
		i = i + 1
	Loop
	Rs.Close
	Set Rs = Nothing
	Response.Write "</table><br>"
	Response.Write "<div class=welinfo><span><img src=""../images/time.png"" /></span><i>提示：1、首页标识为Index，不可修改。2、Article、Product、Job、Search、Jin为系统标识，不可作为栏目标识。</i></div>"
	%>
	
	<%
End Sub

Sub ClassAdd()
	Dim NewID
	Dim Rs,SQL,i,TitleColor
	SQL = "SELECT MAX(ID) FROM Jin_Class"
	Set Rs = Conn.Execute(SQL)
	If Rs.BOF And Rs.EOF Then
		NewID = 1
	Else
		NewID = Rs(0) + 1
	End If
	If IsNull(NewID) Then NewID = 1
	Rs.Close
%>


    <br />
    <div class="formtitle"><span>新建栏目</span></div>

    <form name="myform" class="classform" method="POST" action="?action=savenew">
    <input type="hidden" name="NewID" value="<%=NewID%>">
    <input type="hidden" name="ModuleID" value="<%=ModuleID%>">
    <ul class="forminfo">
    <li><label>栏目名称</label><input type="text" class="newinput200" name="ClassName" id="ClassName" style="width:173px;">
    <input type="text" class="newinput200" name="ClassName_en" id="ClassName_en" placeholder="栏目标识" style="width:173px;">
    <i>第二个文本框为栏目标识名</i></li>
    <!--Class.asp?ID=<%'=getClassSysID()%>-->
    <li><label>栏目链接</label><input type="text" class="newinput450" name="Url" style="width:350px;" value=""><i>一级栏目设置即可</i></li>
    
    <li><label>栏目标签</label><input type="text" class="newinput450" name="Readme" style="width:350px;"><i>多个标签,隔开</i></li>
    
    <li><label class="left">栏目类型</label>
    <div class="vocation">
    <select name="ClassType" class="select2">
    <%
    Set Rsa=server.createobject("adodb.recordSet")
    Sqla="select * from Jin_ClassType where Show order by SortID asc,sysID desc"
    Rsa.open Sqla,conn,1,3
    For j=1 to Rsa.recordcount
    %>
    <option value="<%=Rsa("TypeName_en")%>"><%=Rsa("TypeName")%></option>
    <%
    Rsa.movenext
    next
    Rsa.close
    Set Rsa=nothing
    %>
    </select>
    </div>
    </li>
    
    <li><label class="left">所属栏目</label>
    <div class="vocation">
		<%
			Response.Write " <select name=""class""  class=""select1"">"
			Response.Write "<option value=""0"">作为一级栏目</option>"
			SQL = "SELECT ID,Depth,ClassName FROM Jin_Class WHERE ModuleID = "& ModuleID &" ORDER BY RootID,Orders"
			Set Rs = Conn.Execute(SQL)
			Do While Not Rs.EOF
				Response.Write "<option value=""" & Rs("ID") & """ "
				If Request("editid") <> "" And CLng(Request("editid")) = Rs("ID") Then Response.Write "selected"
				Response.Write ">"
				If Rs("Depth") = 1 Then Response.Write "&nbsp;&nbsp;├ "
				If Rs("Depth") > 1 Then
					For i = 2 To Rs("Depth")
						Response.Write "&nbsp;&nbsp;│"
					Next
					Response.Write "&nbsp;&nbsp;├ "
				End If
				Response.Write Rs("ClassName") & "</option>" & vbCrLf
				Rs.movenext
			Loop
			Rs.Close
			Response.Write "</select>"
			Set Rs = Nothing
		%>
    </div>
    </li>
    
    <li><label>&nbsp;</label><input type="submit" value="保存设置" name="B2" class="btn">
    <input type="button" onClick="javascript:history.go(-1)" value="返回上一页" name="B1" class="btn">
    </li>
    
    </ul>
    </form>

<%
End Sub

Sub ClassEdit()
	Dim Rs,SQL,RsObj,i,TitleColor
	Set Rs = Conn.Execute("SELECT * FROM Jin_Class WHERE ModuleID = " & ModuleID & " And ID = " & Request("editid"))
	If Rs.BOF And Rs.EOF Then
		FoundErr = True
		ErrMsg = "数据库出现错误,没有此栏目! <a href=""javascript:history.go(-1);"">返回</a>"
		Rs.Close
		Set Rs = Nothing
		Exit Sub
	End If
%>



    <br />
    <div class="formtitle"><span>编辑栏目</span></div>

    <form name="myform" class="classform" method="POST" action="?action=savedit">
    <input type="hidden" name="editid" value="<%=Request("editid")%>">
    <input type="hidden" name="ModuleID" value="<%=ModuleID%>">
    <ul class="forminfo">
    <li><label>栏目名称</label>
    <input type="text" class="newinput200" name="ClassName" id="ClassName" value="<%=Rs("ClassName")%>" style="width:182px;">
    <i></i></li>
    
    
    <li><label class="left">所属栏目</label>
    <div class="vocation">
	<%
	Response.Write " <select name=""class"" class=""select1"">"
	Response.Write "<option value=""0"">做为一级栏目</option>"
	SQL = "SELECT ID,Depth,ClassName FROM Jin_Class WHERE ModuleID = "& ModuleID &" ORDER BY RootID,Orders"
	Set RsObj = Conn.Execute(SQL)
	Do While Not RsObj.EOF
		Response.Write "<option value=""" & RsObj("ID") & """ "
		If CLng(Rs("ParentID")) = RsObj("ID") Then Response.Write "selected"
		Response.Write ">"
		If RsObj("Depth") = 1 Then Response.Write "&nbsp;&nbsp;├ "
		If RsObj("Depth") > 1 Then
			For i = 2 To RsObj("Depth")
				Response.Write "&nbsp;&nbsp;│"
			Next
			Response.Write "&nbsp;&nbsp;├ "
		End If
		Response.Write RsObj("ClassName") & "</option>" & vbCrLf
		RsObj.movenext
	Loop
	RsObj.Close
	Response.Write "</select>"
	Set RsObj = Nothing
	%>
    </div>
    </li>
    
    <li><label>关键词</label><input type="text" class="newinput450" name="Readme" id="Readme" value="<%=Rs("Readme")%>"></li>
    
    <li><label>图片</label><input type="text" class="newinput450" name="Pic" id="Pic" value="<%=Rs("Pic")%>"><i><a href="#" id="upload">上传</a></i></li>
    
    <%If Rs("ClassType")="SinglePage" Then%>
    <li><label class="left">内容<b></b></label>
    <textarea name="Content" cols="" rows="" class="textinput" style="width:700px;height:320px;" ><%=Rs("Content")%></textarea>
    </li>
    <%Else%>
    <li><label class="left">描述<b></b></label>
    <textarea name="Content" cols="" rows="" class="textinput" style="width:700px;height:120px;" ><%=Rs("Content")%></textarea>
    </li>
	<%End If%>
    
    <li><label>&nbsp;</label><input type="submit" value="保存设置" name="B2" class="btn">
    <input type="button" onClick="javascript:history.go(-1)" value="返回上一页" name="B1" class="btn">
    </li>
    
    </ul>
    </form>

<%
Set Rs = Nothing
End Sub

Sub CheckSave()
	If Trim(Request("ClassName")) = "" Then
		ErrMsg = ErrMsg + "<li>请输入栏目名称。 <a href=""javascript:history.go(-1);"">返回</a></li>"
		Founderr = True
	End If
	If Not IsNumeric(Request("class")) Then
		ErrMsg = ErrMsg + "<li>请选择所属栏目。 <a href=""javascript:history.go(-1);"">返回</a></li>"
		Founderr = True
	End If
	If Len(request_Form("ClassName")) => 25 Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>栏目名称名称不能超过50个字符！ <a href=""javascript:history.go(-1);"">返回</a></li>"
	End If

End Sub

Sub savenew()
	Dim ID,RootID,ParentID,Depth,Orders
	Dim MaxRootID,ParentStr,ChildStr,newOrders
	Dim Rs,SQL
	'保存添加栏目信息
	CheckSave
	If Founderr = True Then Exit Sub
	If Request("class") <> "0" Then
		SQL = "SELECT RootID,ID,Depth,Orders,ParentStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("class")
		Set Rs = Conn.Execute (SQL)
		RootID = Rs(0)
		ParentID = Rs(1)
		Depth = Rs(2)
		Orders = Rs(3)
		If Depth + 1 > 20 Then
			ErrMsg = "<li>本系统限制最多只能有20级子栏目。 <a href=""javascript:history.go(-1);"">返回</a></li>"
			Founderr = True
			Exit Sub
		End If
		ParentStr = Rs(4)
		Rs.Close
	Else
		SQL = "SELECT MAX(RootID) FROM Jin_Class WHERE ModuleID = "& ModuleID
		Set Rs = Conn.Execute (SQL)
		MaxRootID = Rs(0) + 1
		If IsNull(MaxRootID) Then MaxRootID = 1
		Rs.Close
	End If
	SQL = "SELECT ID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("newID")
	Set Rs = Conn.Execute (SQL)
	If Not (Rs.EOF And Rs.BOF) Then
		ErrMsg = "<li>您不能指定和别的栏目一样的序号。 <a href=""javascript:history.go(-1);"">返回</a></li>"
		Founderr = True
		Exit Sub
	Else
		ID = Request("newID")
	End If
	Rs.Close
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM Jin_Class"
	Rs.Open SQL, Conn, 1, 3
	Rs.addnew
	If Request("class") <> "0" Then
		Rs("Depth") = Depth + 1
		Rs("RootID") = RootID
		Rs("ParentID") = request_Form("class")
		If ParentStr = "0" Then
			Rs("ParentStr") = request_Form("class")
		Else
			Rs("ParentStr") = ParentStr & "," & request_Form("class")
		End If
	Else
		Rs("Depth") = 0
		Rs("RootID") = MaxRootID
		Rs("ParentID") = 0
		Rs("ParentStr") = 0
	End If
	Rs("ModuleID") = ModuleID
	Rs("Child") = 0
	Rs("ChildStr") = Trim(request_Form("newID"))
	Rs("ID") = request_Form("newID")
	Rs("Orders") = request_Form("newID")
	Rs("ClassName") = Trim(request_Form("ClassName"))
	Rs("ClassName_en") = Trim(request_Form("ClassName_en"))
	Rs("Url") = Trim(request_Form("Url"))
	Rs("Pic") = sub_str(Trim(request_Form("Pic")),"Upload")
	Rs("Content") = request_Form("Content")
	Rs("ClassType") = Trim(request_Form("ClassType"))
	Rs("Readme") = Trim(request_Form("Readme"))
	Rs("ShowCount") = 0
	Rs.Update
	Rs.Close
	If Request("class") <> "0" Then
		Dim nID
		ParentStr = ParentStr & "," & request_Form("class")
		nID = Trim(request_Form("newID"))
		SQL = "SELECT ID,ParentStr,ChildStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID in (" & ParentStr & ")"
		Set Rs = Conn.Execute (SQL)
		Do While Not Rs.EOF
			ChildStr = Rs("ChildStr") & "," & nID
			Conn.Execute ("UPDATE Jin_Class SET ChildStr='"&ChildStr&"' WHERE ModuleID = "& ModuleID &" And ID = " & Rs("ID"))
		Rs.movenext
		Loop
		Rs.Close
	End If
	CheckAndFixClass 0,1
	
	SucMsg = "<div class=welinfo><span><img src=""../images/time.png"" /></span><i>恭喜您！栏目添加成功。<a href=?ModuleID="&ModuleID&">返回首页</a></i></div>"
	Set Rs = Nothing
	response.write(SucMsg)
	'Response.Write ("<script language=javascript>window.location=document.referrer;;<'/script>")

End Sub

Sub show()
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("showid")
	Rs.Open SQL, Conn, 1, 3
	Rs("ShowNav") = true
	Rs.Update
	Rs.Close
	Set Rs = Nothing
	Response.Write ("<script language=""javascript"">window.location=document.referrer;</script>")
	'SucMsg = "<div class=welinfo><span><img src=""../images/time.png"" /></span><i>首页已显示。</i></div>"
	'response.write(SucMsg)
End Sub
Sub hidden()
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("hiddenid")
	Rs.Open SQL, Conn, 1, 3
	Rs("ShowNav") = false
	Rs.Update
	Rs.Close
	Set Rs = Nothing
	Response.Write ("<script language=""javascript"">window.location=document.referrer;</script>")
	'SucMsg = "<div class=welinfo><span><img src=""../images/time.png"" /></span><i>首页已隐藏。</i></div>"
	'response.write(SucMsg)
End Sub

Sub sy()
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("showid")
	Rs.Open SQL, Conn, 1, 3
	Rs("IndexShow") = true
	Rs.Update
	Rs.Close
	Set Rs = Nothing
	Response.Write ("<script language=""javascript"">window.location=document.referrer;</script>")
	'SucMsg = "<div class=welinfo><span><img src=""../images/time.png"" /></span><i>首页已显示。</i></div>"
	'response.write(SucMsg)
End Sub
Sub syno()
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("hiddenid")
	Rs.Open SQL, Conn, 1, 3
	Rs("IndexShow") = false
	Rs.Update
	Rs.Close
	Set Rs = Nothing
	Response.Write ("<script language=""javascript"">window.location=document.referrer;</script>")
	'SucMsg = "<div class=welinfo><span><img src=""../images/time.png"" /></span><i>首页已隐藏。</i></div>"
	'response.write(SucMsg)
End Sub


Sub savedit()
	Dim newID,MaxRootID,ParentID,Depth,Child
	Dim ParentStr,RootID,iParentID,iParentStr
	Dim trs,brs,mrs,Rsc,Rss,k
	Dim nParentStr,mParentStr,ParentSql,ChildStr,nChildStr
	Dim ArrChildStr,ii,ClassCount
	Dim Rs,SQL,i
	'保存编辑栏目信息
	If CLng(Request("editid")) = CLng(Request("class")) Then
		ErrMsg = "<li>所属栏目不能指定自己。<a href=""javascript:history.go(-1);"">返回上一页</a></li>"
		Founderr = True
		Exit Sub
	End If
	CheckSave
	If Founderr = True Then Exit Sub
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("editid")
	Rs.Open SQL, Conn, 1, 3
	newID = Rs("ID")
	ParentID = Rs("ParentID")
	iParentID = Rs("ParentID")
	ParentStr = Rs("ParentStr")
	ChildStr = Rs("ChildStr")
	Depth = Rs("Depth")
	Child = Rs("Child")
	RootID = Rs("RootID")
	If Child <> 0 And LCase(ClassDir) <> LCase(strClassDir) Then
		ErrMsg = "<li>对不起！该栏目中有下属栏目不能修改栏目目录！<a href=""javascript:history.go(-1);"">返回上一页</a></li>"
		Founderr = True
		Exit Sub
	End If
	If Child <> 0 And ParentID <> Clng(Request("class")) Then
		ErrMsg = "<li>对不起！该栏目中有下属栏目不能移动，请先移动其下属栏目。<a href=""javascript:history.go(-1);"">返回上一页</a></li>"
		Founderr = True
		Exit Sub
	End If

	If ParentID = 0 Then
		If CLng(Request("class")) <> 0 Then
			Set trs = Conn.Execute("SELECT RootID,TurnLink FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("class"))
			If RootID = trs(0) Then
				ErrMsg = "<li>您不能指定该栏目的下属栏目作为所属栏目。<a href=""javascript:history.go(-1);"">返回上一页</a></li>"
				Founderr = True
				Exit Sub
			End If
			If trs(1) = 1 Then
				ErrMsg = "<li>该栏目是外部连接，您不能指定该栏目作为所属栏目。<a href=""javascript:history.go(-1);"">返回上一页</a></li>"
				Founderr = True
				Exit Sub
			End If
		End If
	Else
		Set trs = Conn.Execute("SELECT ID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr like '%" & ParentStr & "%' and ID=" & Request("class"))
		If Not (tRs.EOF And tRs.BOF) Then
			ErrMsg = "<li>您不能指定该栏目的下属栏目作为所属栏目。<a href=""javascript:history.go(-1);"">返回上一页</a></li>"
			Founderr = True
			Exit Sub
		End If
	End If
	If ParentID = 0 Then
		ParentID = Rs("ID")
		iParentID = 0
	End If
	Rs("ClassName") = Trim(request_Form("ClassName"))
	'Rs("ProShuxing") = clng(request_Form("ProShuxing"))
	'Rs("ClassName_en") = Trim(request_Form("ClassName_en"))
	'Rs("Url") = Trim(request_Form("Url"))
	'Rs("ClassType") = Trim(request_Form("ClassType"))
	Rs("Readme") = replace(replace(request_Form("Readme"),"，",",")," ",",")
	Rs("Pic") = sub_str(Trim(request_Form("Pic")),"Upload")
	Rs("Content") = request_Form("Content")
	Rs.Update
	Rs.Close
	Set Rs = Nothing
	Set mrs = Conn.Execute("SELECT MAX(RootID) FROM Jin_Class WHERE ModuleID="& ModuleID)
	MaxRootID = mrs(0) + 1
	'假如更改了所属栏目
	'需要更新其原来所属栏目信息，包括深度、父级ID、栏目数、排序
	'需要更新当前所属栏目信息
	If CLng(ParentID) <> CLng(Request("class")) And Not (iParentID = 0 And CInt(Request("class")) = 0) Then
		'如果原来不是一级栏目改成一级栏目
		If iParentID > 0 And CInt(Request("class")) = 0 Then
			'如果不是一级栏目改成一级栏目,更新子栏目数据
			'开始更新子栏目
			'ChildStr = "," & ChildStr
			Set Rsc = Conn.Execute ("SELECT ID,ChildStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID in (" & ParentStr & ")")
			Do While Not Rsc.EOF
				ArrChildStr = Split(Rsc("ChildStr"), ",")
				nChildStr = ""
				For ii = 0 to Ubound(ArrChildStr)
					If ArrChildStr(ii) <> ChildStr Then
						nChildStr = nChildStr & ArrChildStr(ii) & Chr(32)
					End If
				Next
				nChildStr = Replace(Trim(nChildStr), Chr(32), ",")
				'nChildStr = Replace(Rsc("ChildStr"), ChildStr, "")
				Conn.Execute ("UPDATE Jin_Class SET ChildStr='" & nChildStr & "' WHERE ModuleID = "& ModuleID &" And ID = " & Rsc("ID"))
			Rsc.movenext
			Loop
			Rsc.Close
			Set Rsc = Nothing
			'更新子栏目结束
			'---------------------------------------------------
			'更新当前栏目数据
			Conn.Execute ("UPDATE Jin_Class set Depth=0,Orders=0,RootID=" & MaxRootID & ",ParentID=0,ParentStr='0' WHERE ID=" & newID)
			ParentStr = ParentStr & ","
			Set Rs = Conn.Execute("SELECT COUNT(ID) FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr like '%" & ParentStr & "%'")
			ClassCount = Rs(0)
			If IsNull(ClassCount) Then
				ClassCount = 1
			Else
				ClassCount = ClassCount + 1
			End If
			'更新其原来所属栏目数
			Conn.Execute ("UPDATE Jin_Class SET Child=Child-" & ClassCount & " WHERE ModuleID = "& ModuleID &" And ID=" & iParentID)
			'更新其原来所属栏目数据，排序相当于剪枝而不需考虑
			For i = 1 To Depth
				'得到其父类的父类的ID
				Set Rs = Conn.Execute("SELECT ParentID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & iParentID)
				If Not (Rs.EOF And Rs.BOF) Then
					iParentID = Rs(0)
					Conn.Execute ("UPDATE Jin_Class SET Child=Child-" & ClassCount & " WHERE ModuleID = "& ModuleID &" And ID=" & iParentID)
				End If
			Next
			If Child > 0 Then
				'更新其下属栏目数据
				'有下属栏目，排序不需考虑，更新下属栏目深度和一级排序ID(RootID)数据
				'更新当前栏目数据
				i = 0
				Set Rs = Conn.Execute("SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr LIKE '%" & ParentStr & "%'")
				Do While Not Rs.EOF
					i = i + 1
					mParentStr = Replace(Rs("ParentStr"), ParentStr, "")
					Conn.Execute ("UPDATE Jin_Class SET Depth=Depth-" & Depth & ",RootID=" & MaxRootID & ",ParentStr='" & mParentStr & "' WHERE ModuleID = "& ModuleID &" And ID=" & Rs("ID"))
					Rs.movenext
				Loop
			End If
			'------------------------------------------------------
		ElseIf iParentID > 0 And CInt(Request("class")) > 0 Then
			'将一个栏目移动到其他栏目下
			'开始更新子栏目
			'ChildStr = "," & ChildStr
			Set Rsc = Conn.Execute ("SELECT ID,ChildStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID in (" & ParentStr & ")")
			Do While Not Rsc.EOF
				ArrChildStr = Split(Rsc("ChildStr"), ",")
				nChildStr = ""
				For ii = 0 to Ubound(ArrChildStr)
					If ArrChildStr(ii) <> ChildStr Then
						nChildStr = nChildStr & ArrChildStr(ii) & Chr(32)
					End If
				Next
				nChildStr = Replace(Trim(nChildStr), Chr(32), ",")
				'nChildStr = Replace(Rsc("ChildStr"), ChildStr, "")
				Conn.Execute ("UPDATE Jin_Class SET ChildStr='" & nChildStr & "' WHERE ModuleID = "& ModuleID &" And ID = " & Rsc("ID"))
			Rsc.movenext
			Loop
			Rsc.Close
			Set Rsc = Nothing
			'更新子栏目结束
			'-----------------------------------------------------------
			'获得所指定的栏目的相关信息
			Set trs = Conn.Execute("SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("class"))
			'得到其下属栏目数
			ParentStr = ParentStr & ","
			Set Rs = Conn.Execute("SELECT COUNT(ID) FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr like '%" & ParentStr & "%'")
			ClassCount = Rs(0)
			If IsNull(ClassCount) Then ClassCount = 1
			'在获得移动过来的栏目数后更新排序在指定栏目之后的栏目排序数据
			Conn.Execute ("UPDATE Jin_Class SET Orders=Orders + " & ClassCount & " + 1 WHERE RootID=" & trs("RootID") & " and Orders>" & trs("Orders") & "")
			'更新当前栏目数据
			Conn.Execute ("UPDATE Jin_Class SET Depth=" & trs("Depth") & "+1,Orders=" & trs("Orders") & "+1,RootID=" & trs("RootID") & ",ParentID=" & Request("class") & ",ParentStr='" & trs("ParentStr") & "," & trs("ID") & "' WHERE ModuleID = "& ModuleID &" And ID=" & newID)
			i = 1
			'如果有则更新下属栏目数据
			'深度为原有深度加上当前所属栏目的深度
			Set Rs = Conn.Execute("SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr like '%" & ParentStr & "%' ORDER BY Orders")
			Do While Not Rs.EOF
				i = i + 1
				iParentStr = trs("ParentStr") & "," & trs("ID") & "," & Replace(Rs("ParentStr"), ParentStr, "")
				Conn.Execute ("UPDATE Jin_Class SET Depth=Depth+" & trs("Depth") & "-" & Depth & "+1,Orders=" & trs("Orders") & "+" & i & ",RootID=" & trs("RootID") & ",ParentStr='" & iParentStr & "' WHERE ModuleID = "& ModuleID &" And ID=" & Rs("ID"))
				Rs.movenext
			Loop
			ParentID = Request("class")
			If RootID = trs("RootID") Then
				'在同一栏目下移动
				'更新所指向的上级栏目数，i为本次移动过来的栏目数
				'更新其父类栏目数
				Conn.Execute ("UPDATE Jin_Class SET Child=Child+" & i & " WHERE ModuleID = "& ModuleID &" And (not ParentID=0) and ID=" & ParentID)
				For k = 1 To trs("Depth")
					'得到其父类的父类的栏目ID
					Set Rs = Conn.Execute("SELECT ParentID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And (not ParentID=0) and ID=" & ParentID)
					If Not (Rs.EOF And Rs.BOF) Then
						ParentID = Rs(0)
						'更新其父类的父类栏目数
						Conn.Execute ("UPDATE Jin_Class SET Child=Child+" & i & " WHERE ModuleID = "& ModuleID &" And (not ParentID=0) and  ID=" & ParentID)
					End If
				Next
				'更新其原父类栏目数
				Conn.Execute ("UPDATE Jin_Class SET Child=Child-" & i & " WHERE ModuleID = "& ModuleID &" And (not ParentID=0) and ID=" & iParentID)
				'更新其原来所属栏目数据
				For k = 1 To Depth
					'得到其原父类的父类的栏目ID
					Set Rs = Conn.Execute("SELECT ParentID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And (not ParentID=0) and ID=" & iParentID)
					If Not (Rs.EOF And Rs.BOF) Then
						iParentID = Rs(0)
						'更新其原父类的父类栏目数
						Conn.Execute ("UPDATE Jin_Class SET Child=Child-" & i & " WHERE ModuleID = "& ModuleID &" And (not ParentID=0) and  ID=" & iParentID)
					End If
				Next
			Else
				'更新所指向的上级栏目数，i为本次移动过来的栏目数
				'更新其父类栏目数
				Conn.Execute ("UPDATE Jin_Class SET Child=Child+" & i & " WHERE ModuleID = "& ModuleID &" And ID=" & ParentID)
				For k = 1 To trs("Depth")
					'得到其父类的父类的栏目ID
					Set Rs = Conn.Execute("SELECT ParentID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & ParentID)
					If Not (Rs.EOF And Rs.BOF) Then
						ParentID = Rs(0)
						'更新其父类的父类栏目数
						Conn.Execute ("UPDATE Jin_Class SET Child=Child+" & i & " WHERE ModuleID = "& ModuleID &" And ID=" & ParentID)
					End If
				Next
				'更新其原父类栏目数
				Conn.Execute ("UPDATE Jin_Class SET Child=Child-" & i & " WHERE ModuleID = "& ModuleID &" And ID=" & iParentID)
				For k = 1 To Depth
					'得到其原父类的父类的栏目ID
					Set Rs = Conn.Execute("SELECT ParentID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & iParentID)
					If Not (Rs.EOF And Rs.BOF) Then
						iParentID = Rs(0)
						'更新其原父类的父类栏目数
						Conn.Execute ("UPDATE Jin_Class SET Child=Child-" & i & " WHERE ModuleID = "& ModuleID &" And ID=" & iParentID)
					End If
				Next
			End If
			'-----------------------------------------------
			'开始更新子栏目
			SQL = "SELECT ID,ParentID,ParentStr,ChildStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("class")
			Set Rss = Conn.Execute (SQL)
			If Rss("ParentID") <> 0 Then
				'如果是一级栏目移动到其它一级栏目的子栏目
				nChildStr = Rss("ChildStr") & "," & Request("editid")
				Conn.Execute ("UPDATE Jin_Class SET ChildStr='"&nChildStr&"' WHERE ModuleID = "& ModuleID &" And ID = " & Rss("ID"))
				SQL = "SELECT ID,ParentStr,ChildStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID in (" & Rss("ParentStr") & ")"
				Set Rsc = Conn.Execute (SQL)
				Do While Not Rsc.EOF
					nChildStr = Rsc("ChildStr") & "," & Request("editid")
					Conn.Execute ("UPDATE Jin_Class SET ChildStr='"&nChildStr&"' WHERE ModuleID = "& ModuleID &" And ID = " & Rsc("ID"))
				Rsc.movenext
				Loop
				Rsc.Close
				Set Rsc = Nothing
			Else
				'如果是一级栏目移动到其它一级栏目，执行以下更新
				nChildStr = Rss("ChildStr") & "," & Request("editid")
				Conn.Execute ("UPDATE Jin_Class SET ChildStr='"&nChildStr&"' WHERE ModuleID = "& ModuleID &" And ID = " & Rss("ID"))
			End If
			Rss.Close
			Set Rss = Nothing
			'更新子栏目结束
		Else
			'如果原来是一级栏目改成其他栏目的下属栏目
			'更新一级栏目的子栏目
			'开始更新子栏目
			SQL = "SELECT ID,ParentID,ParentStr,ChildStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & CLng(Request("class"))
			Set Rss = Conn.Execute (SQL)
			If Rss("ParentID") <> 0 Then
				'如果是一级栏目移动到其它一级栏目的子栏目
				nChildStr = Rss("ChildStr") & "," & ChildStr
				Conn.Execute ("UPDATE Jin_Class SET ChildStr='"&nChildStr&"' WHERE ModuleID = "& ModuleID &" And ID = " & Rss("ID"))
				SQL = "SELECT ID,ParentStr,ChildStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID in (" & Rss("ParentStr") & ")"
				Set Rsc = Conn.Execute (SQL)
				Do While Not Rsc.EOF
					nChildStr = Rsc("ChildStr") & "," & ChildStr
					Conn.Execute ("UPDATE Jin_Class SET ChildStr='"&nChildStr&"' WHERE ModuleID = "& ModuleID &" And ID = " & Rsc("ID"))
				Rsc.movenext
				Loop
				Rsc.Close
				Set Rsc = Nothing
			Else
				'如果是一级栏目移动到其它一级栏目，执行以下更新
				nChildStr = Rss("ChildStr") & "," & ChildStr
				Conn.Execute ("UPDATE Jin_Class SET ChildStr='"&nChildStr&"' WHERE ModuleID = "& ModuleID &" And ID = " & Rss("ID"))
			End If
			Rss.Close
			Set Rss = Nothing
			'更新子栏目结束
			'---------------------------------------------------
			'得到所指定的栏目的相关信息
			Set trs = Conn.Execute("SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & CLng(Request("class")))
			Set Rs = Conn.Execute("SELECT COUNT(ID) FROM Jin_Class WHERE ModuleID = "& ModuleID &" And RootID=" & RootID)
			ClassCount = Rs(0)
			Rs.Close
			'更新所指向的上级栏目数，i为本次移动过来的栏目数
			ParentID = Request("class")
			'更新其父类栏目数
			Conn.Execute ("UPDATE Jin_Class SET Child=Child+" & ClassCount & " WHERE ModuleID = "& ModuleID &" And ID=" & ParentID)
			For k = 1 To trs("Depth")
				'得到其父类的父类的栏目ID
				Set Rs = Conn.Execute("SELECT ParentID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & ParentID)
				If Not (Rs.EOF And Rs.BOF) Then
					ParentID = Rs(0)
					'更新其父类的父类栏目数
					Conn.Execute ("UPDATE Jin_Class SET Child=Child+" & ClassCount & " WHERE ModuleID = "& ModuleID &" And ID=" & ParentID)
				End If

			Next
			'在获得移动过来的栏目数后更新排序在指定栏目之后的栏目排序数据
			Conn.Execute ("UPDATE Jin_Class SET Orders=Orders + " & ClassCount & " + 1 WHERE ModuleID = "& ModuleID &" And RootID=" & trs("RootID") & " and Orders>" & trs("Orders") & "")
			i = 0
			Set Rs = Conn.Execute("SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And RootID=" & RootID & " ORDER BY Orders")
			Do While Not Rs.EOF
				i = i + 1
				If Rs("ParentID") = 0 Then
					If trs("ParentStr") = "0" Then
						ParentStr = trs("ID")
					Else
						ParentStr = trs("ParentStr") & "," & trs("ID")
					End If
					Conn.Execute ("UPDATE Jin_Class SET Depth=Depth+" & trs("Depth") & "+1,Orders=" & trs("Orders") & "+" & i & ",RootID=" & trs("RootID") & ",ParentStr='" & ParentStr & "',ParentID=" & CLng(Request("class")) & " WHERE ModuleID = "& ModuleID &" And ID=" & Rs("ID"))
				Else
					If trs("ParentStr") = "0" Then
						ParentStr = trs("ID") & "," & Rs("ParentStr")
					Else
						ParentStr = trs("ParentStr") & "," & trs("ID") & "," & Rs("ParentStr")
					End If
					Conn.Execute ("UPDATE Jin_Class SET Depth=Depth+" & trs("Depth") & "+1,Orders=" & trs("Orders") & "+" & i & ",RootID=" & trs("RootID") & ",ParentStr='" & ParentStr & "' WHERE ModuleID = "& ModuleID &" And ID=" & Rs("ID"))
				End If
				Rs.movenext
			Loop
			'------------------------------------
		End If
	End If
	Set Rs = Nothing
	Set mrs = Nothing
	Set trs = Nothing

	CheckAndFixClass 0,1
	SucMsg = "<div class=welinfo><span><img src=""../images/time.png"" /></span><i>恭喜您！栏目修改成功。<a href=""javascript:history.go(-1);"">返回上一页</a> <a href=?ModuleID="&ModuleID&">返回首页</a></i></div>"
	response.write(SucMsg)

End Sub

Sub DelClass()
	Dim ChildStr,nChildStr
	Dim Rss,Rsc
	Dim Rs,SQL
	'On Error Resume Next
	Set Rs = Conn.Execute("SELECT ParentStr,Child,Depth,ParentID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("editid"))
	If Not (Rs.EOF And Rs.BOF) Then
		If Rs(1) > 0 Then
			ErrMsg = "<li>该栏目含有下属栏目，请删除其下属栏目后再进行删除本栏目的操作。<a href=""javascript:history.go(-1);"">返回上一页</a></li>"
			Founderr = True
			Exit Sub
		End If
		If Rs(3) > 0 Then
			ChildStr = "," & Request("editid")
			SQL = "SELECT ID,ParentStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("editid")
			Set Rss = Conn.Execute (SQL)
			SQL = "SELECT ID,ChildStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID in (" & Rss("ParentStr") & ")"
			Set Rsc = Conn.Execute (SQL)
			Do While Not Rsc.EOF
				nChildStr = Replace(Rsc("ChildStr"), ChildStr, "")
				Conn.Execute ("UPDATE Jin_Class SET ChildStr='"&nChildStr&"' WHERE ModuleID = "& ModuleID &" And ID = " & Rsc("ID"))
			Rsc.movenext
			Loop
			Rsc.Close
			Set Rsc = Nothing
			Set Rss = Nothing
		End If
		If Rs(2) > 0 Then
			Conn.Execute ("UPDATE Jin_Class set Child=Child-1 WHERE ModuleID = "& ModuleID &" And ID in (" & Rs(0) & ")")
		End If
		SQL = "DELETE FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("editid")
		Conn.Execute (SQL)
		Call DelRelated
	End If
	Set Rs = Nothing
	Conn.Execute("UPDATE Jin_Class SET Child=0 WHERE ModuleID="& ModuleID &" And Child<0")
	CheckAndFixClass 0,1
	
	'response.write ("恭喜您！栏目删除成功。")
	Response.Write ("<script language=javascript>window.location=document.referrer;;</script>")
End Sub

Sub ResumeClass()
	CheckAndFixClass 0,1
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub

Sub CheckAndFixClass(ParentID,Orders)
	Dim Rs,Child,ParentStr
	If ParentID=0 Then
		Conn.Execute("UPDATE Jin_Class SET Depth=0,ParentStr='0' WHERE ModuleID="& ModuleID &" And ParentID=0")
	End If
	Set Rs=Conn.Execute("SELECT ID,RootID,ParentStr,Depth FROM Jin_Class WHERE ModuleID="& ModuleID &" And ParentID="&ParentID&" ORDER BY RootID,Orders")
	Do while Not Rs.EOF
		If Rs(2)<>"0" Then
			ParentStr=Rs(2)&","&Rs(0)
		Else
			ParentStr=Rs(0)
		End If
		Conn.Execute "UPDATE Jin_Class SET Depth="&Rs(3)+1&",ParentStr='"&ParentStr&"',RootID="&rs(1)&" WHERE ModuleID="& ModuleID &" And ParentID="&Rs(0)&"",Child
		Conn.Execute("UPDATE Jin_Class SET Child="&Child&",Orders="&Orders&" WHERE ModuleID="& ModuleID &" And ID="&Rs(0)&"")
		Orders=Orders+1
		CheckAndFixClass Rs(0),Orders
		Rs.MoveNext
	Loop
	Set Rs=Nothing
End Sub

Sub DelRelated()
	'On Error Resume Next
	'删除该栏目下的所有文章、评论或其它相关内容
End Sub

Sub DelClassDir()
	'On Error Resume Next
	'删除栏目目录操作
	response.write ("恭喜您！栏目目录删除成功。<a href=""javascript:history.go(-1);"">返回上一页</a>")
End Sub

Sub Orders()
%>

    <div class="welinfo">
    <span><img src="../images/time.png" alt="时间" /></span>
    <i>一级栏目重新排序</i> （请在相应栏目的排序表单内输入相应的排列序号）
    </div>
    <ul class="forminfo">
    <%
	i=0:iCount=1:lCount=1
	SQL = "SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentID=0 ORDER BY RootID"
	Set Rs = Conn.Execute (SQL)
	If Rs.BOF And Rs.EOF Then
		ErrMsg = "<i>还没有相应的" & ModuleName & "栏目。 <a href=""javascript:history.go(-1);"">返回</a></i>"
		Founderr = True
		Exit Sub
	Else
		Do While Not Rs.EOF
			If (i mod 2) = 0 Then iCount=1:lCount=2 Else iCount=2:lCount=1
			Response.Write "<form action=""?action=newOrders"" method=""post"">" & vbCrLf
			%>
            <li><label><%=Rs("ClassName")%></label>
            <input type="hidden" name="ModuleID" value="<%=Rs("ModuleID")%>" class="dfinput" />
            <input type="text" name="OrderID" size="4" value="<%=Rs("RootID")%>" class="newinput60" style="width:60px" />
            <input type="hidden" name="cID" value="<%=Rs("RootID")%>">
            <i><input type="submit" name="submit2" class="scbtn" value="修 改" /></i>
            </li>
            <%
			Response.Write "</form> "
			Rs.movenext
			i=i+1
		Loop
	End If
	Rs.Close
	Set Rs = Nothing
	%>
    </ul>
    <div class="welinfo">
    <span><img src="../images/time.png" alt="时间" /></span>
    <i>请注意，这里一定<b>不能填写相同的序号</b>，否则非常难修复！</i> 
    </div>
    
<%
End Sub

Sub updateOrders()
	Dim cID
	Dim OrderID
	Dim ClassName
	Dim Rs
	cID = Replace(request_Form("cID"), "'", "")
	OrderID = Replace(request_Form("OrderID"), "'", "")
	Set Rs = Conn.Execute("SELECT ID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And RootID=" & OrderID)
	If Rs.BOF And Rs.EOF Then
		Conn.Execute ("UPDATE Jin_Class SET RootID=" & OrderID & " WHERE ModuleID = "& ModuleID &" And RootID=" & cID)
		'response.write ("恭喜您！设置成功，请返回。<a href=""javascript:history.go(-1);"">返回上一页</a>")
		Response.Write ("<script language=javascript>window.location=document.referrer;;</script>")
	Else
		ErrMsg = "<li>请不要和其他栏目设置相同的序号。<a href=""javascript:history.go(-1);"">返回上一页</a></li>"
		Founderr = True
		Exit Sub
	End If
	
	Set Rs = Nothing
End Sub

Sub classOrders()
%>

    <div class="welinfo">
    <span><img src="../images/time.png" alt="时间" /></span>
    <i>N级栏目重新排序</i> （请在相应栏目的排序表单内输入相应的排列序号）
    </div>
    <ul class="forminfo">
    
    <%
	n=0:iCount=1:lCount=2
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM Jin_Class WHERE ModuleID = "& ModuleID &" ORDER BY RootID,Orders"
	Rs.Open SQL, Conn, 1, 1
	If Rs.BOF And Rs.EOF Then
		Response.Write "还没有相应的栏目。 <a href=""javascript:history.go(-1);"">返回</a>"
	Else
		Do While Not Rs.EOF
			If (n mod 2) = 0 Then iCount=1:lCount=2 Else iCount=2:lCount=1
			%>
            <form action="?action=newclassOrders&ModuleID=<%=ModuleID%>" method="post">
            <li><label style="width:200px">
            <%
			'Response.Write "<form action=""?action=newclassOrders&ModuleID=" & ModuleID & """ method=""post"">"
			'Response.Write "<li><label style=width:200px>" & vbCrLf
			If Rs("Depth") = 1 Then Response.Write "&nbsp;&nbsp;├"
			If Rs("Depth") > 1 Then
				For i = 2 To Rs("Depth")
					Response.Write "&nbsp;&nbsp;│"
				Next
				Response.Write "&nbsp;&nbsp;├"
			End If
			'If Rs("ParentID") = 0 Then Response.Write ("<b>")
			Response.Write Rs("ClassName")
			If Rs("Child") > 0 Then Response.Write "(" & Rs("Child") & ")"
			'Response.Write "</label>" & vbCrLf
			%>
            </label>
            <%
			If Rs("ParentID") > 0 Then
				Set trs = Conn.Execute("SELECT COUNT(*) FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentID=" & Rs("ParentID") & " And Orders<" & Rs("Orders") & "")
				upOrders = trs(0)
				If IsNull(upOrders) Then upOrders = 0

				Set trs = Conn.Execute("SELECT COUNT(*) FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentID=" & Rs("ParentID") & " And Orders>" & Rs("Orders") & "")
				doOrders = trs(0)
				If IsNull(doOrders) Then doOrders = 0
				If upOrders > 0 Then
				%>
                    <div class="vocation">
                    <select name="upOrders" size="1" class="select3">
                    <option value="0">↑</option>
                <%
					'Response.Write "<div class=""vocation""><select name=""upOrders"" size=""1"" class=""select3""><option value=""0"">↑</option>" & vbCrLf
					For i = 1 To upOrders
						'Response.Write "<option value=""" & i & """>↑" & i & "</option>" & vbCrLf
					%>
                    <option value="<%=i%>">↑<%=i%></option>
                    <%
					Next
					'Response.Write "</select></div>"
					%>
                    </select>
                    </div>
                    <%
				End If
				If doOrders > 0 Then
					If upOrders > 0 Then Response.Write "&nbsp;"
					'Response.Write "<div class=""vocation""><select name=""doOrders"" size=""1"" class=""select3""><option value=""0"">↓</option>" & vbCrLf
					%>
                    <div class="vocation">
                    <select name="doOrders" size="1" class="select3">
                    <option value="0">↓</option>
                    <%
					For i = 1 To doOrders
						'Response.Write "<option value=""" & i & """>↓" & i & "</option>" & vbCrLf
					%>
                    <option value="<%=i%>">↓<%=i%></option>
					<%
                    Next
					'Response.Write "</select></div>" & vbCrLf
					%>
                    </select>
                    </div>
                    <%
				End If
				If doOrders > 0 Or upOrders > 0 Then
					'Response.Write "<i><input type=""hidden"" name=""editID"" value=""" & Rs("ID") & """>&nbsp;<input type=""submit"" name=""submit2"" class=""btn"" value=""修 改""></i>" & vbCrLf
				%>
                    <i><input type="hidden" name="editID" value="<%=Rs("ID")%>"><input type="submit" name="submit2" value="修 改"></i>
                <%
				End If
			Else
				'Response.Write "&nbsp;"
			End If
			%>
            </li></form>
            <%
			'Response.Write "</form>" & vbCrLf
			upOrders = 0
			doOrders = 0
			Rs.movenext
			n=n+1
		Loop
	End If
	Rs.Close
	Set Rs = Nothing
	
	%>
    </ul>

<%
End Sub

Sub updateclassOrders()
	Dim ParentID,Orders,ParentStr,Child
	Dim upOrders,doOrders,oldOrders
	Dim trs,ii
	Dim Rs,i
	If Not IsNumeric(Request("editID")) Then
		ErrMsg = ErrMsg & "<li>非法的参数！ <a href=""javascript:history.go(-1);"">返回</a></li>"
		Founderr = True
		Exit Sub
	End If
	If Request("ModuleID") = "" Then
		ErrMsg = ErrMsg & "<li>非法的系统参数！ <a href=""javascript:history.go(-1);"">返回</a></li>"
		Founderr = True
		Exit Sub
	End If
	If Request("uporders") <> "" And Not CInt(Request("uporders")) = 0 Then
		If Not IsNumeric(Request("uporders")) Then
			ErrMsg = ErrMsg & "<li>非法的参数！ <a href=""javascript:history.go(-1);"">返回</a></li>"
			Founderr = True
			Exit Sub
		ElseIf CInt(Request("uporders")) = 0 Then
			ErrMsg = ErrMsg & "<li>请选择要提升的数字！ <a href=""javascript:history.go(-1);"">返回</a></li>"
			Founderr = True
			Exit Sub
		End If
		Set Rs = Conn.Execute("SELECT ParentID,orders,ParentStr,Child FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("editid"))
		ParentID = Rs(0)
		Orders = Rs(1)
		ParentStr = Rs(2) & "," & Request("editid")
		Child = Rs(3)
		i = 0
		If Child > 0 Then
			Set Rs = Conn.Execute("SELECT COUNT(*) FROM Jin_Class WHERE ModuleID="& ModuleID &" And ParentStr like '%" & ParentStr & "%'")
			oldOrders = Rs(0)
		Else
			oldOrders = 0
		End If

		Set Rs = Conn.Execute("SELECT ID,Orders,Child,ParentStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentID=" & ParentID & " and Orders<" & Orders & " ORDER BY Orders desc")
		Do While Not Rs.EOF
			i = i + 1
			If CInt(Request("upOrders")) >= i Then
				If Rs(2) > 0 Then
					ii = 0
					Set trs = Conn.Execute("SELECT ID,Orders FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr like '%" & Rs(3) & "," & Rs(0) & "%' ORDER BY Orders")
					If Not (tRs.EOF And tRs.BOF) Then
						Do While Not tRs.EOF
							ii = ii + 1
							Conn.Execute ("UPDATE Jin_Class SET Orders=" & Orders & "+" & oldOrders & "+" & ii & " WHERE ModuleID = "& ModuleID &" And ID=" & trs(0))
							trs.movenext
						Loop
					End If
				End If
				Conn.Execute ("UPDATE Jin_Class SET Orders=" & Orders & "+" & oldOrders & " WHERE ModuleID = "& ModuleID &" And ID=" & Rs(0))
				If CInt(Request("upOrders")) = i Then upOrders = Rs(1)
			End If
			Orders = Rs(1)
			Rs.movenext
		Loop

		Conn.Execute ("UPDATE Jin_Class SET Orders=" & upOrders & " WHERE ModuleID = "& ModuleID &" And ID=" & Request("editid"))
		If Child > 0 Then
			i = upOrders
			Set Rs = Conn.Execute("SELECT ID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr like '%" & ParentStr & "%' ORDER BY Orders")
			Do While Not Rs.EOF
				i = i + 1
				Conn.Execute ("UPDATE Jin_Class SET Orders=" & i & " WHERE ModuleID = "& ModuleID &" And ID=" & Rs(0))
				Rs.movenext
			Loop
		End If
		Set Rs = Nothing
		Set trs = Nothing
	ElseIf Request("doOrders") <> "" Then
		If Not IsNumeric(Request("doOrders")) Then
			ErrMsg = ErrMsg & "<li>非法的参数！ <a href=""javascript:history.go(-1);"">返回</a></li>"
			Founderr = True
			Exit Sub
		ElseIf CInt(Request("doOrders")) = 0 Then
			ErrMsg = ErrMsg & "<li>请选择要下降的数字！ <a href=""javascript:history.go(-1);"">返回</a></li>"
			Founderr = True
			Exit Sub
		End If
		Set Rs = Conn.Execute("SELECT ParentID,Orders,ParentStr,Child FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ID=" & Request("editID"))
		ParentID = Rs(0)
		Orders = Rs(1)
		ParentStr = Rs(2) & "," & Request("editid")
		Child = Rs(3)
		i = 0
		If Child > 0 Then
			Set Rs = Conn.Execute("SELECT COUNT(*) FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr like '%" & ParentStr & "%'")
			oldOrders = Rs(0)
		Else
			oldOrders = 0
		End If
		Set Rs = Conn.Execute("SELECT ID,Orders,Child,ParentStr FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentID=" & ParentID & " and Orders>" & Orders & " ORDER BY Orders")
		Response.Write "<li>"&ModuleID&" 错误参数！ <a href=""javascript:history.go(-1);"">返回</a></li>"
		Do While Not Rs.EOF
			i = i + 1
			If CInt(Request("doOrders")) >= i Then
				If Rs(2) > 0 Then
					ii = 0
					Set trs = Conn.Execute("SELECT ID,Orders FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr like '%" & Rs(3) & "," & Rs(0) & "%' ORDER BY Orders")
					If Not (tRs.EOF And tRs.BOF) Then
						Do While Not tRs.EOF
							ii = ii + 1
							Conn.Execute ("UPDATE Jin_Class set Orders=" & Orders & "+" & ii & " WHERE ModuleID = "& ModuleID &" And ID=" & trs(0))
							trs.movenext
						Loop
					End If
				End If
				Conn.Execute ("UPDATE Jin_Class SET Orders=" & Orders & " WHERE ModuleID = "& ModuleID &" And ID=" & Rs(0))
				If CInt(Request("doOrders")) = i Then doOrders = Rs(1)
			End If
			Orders = Rs(1)
			Rs.movenext
		Loop
		Conn.Execute ("UPDATE Jin_Class SET Orders=" & doOrders & " WHERE ModuleID = "& ModuleID &" And ID=" & Request("editid"))
		If Child > 0 Then
			i = doOrders
			Set Rs = Conn.Execute("SELECT ID FROM Jin_Class WHERE ModuleID = "& ModuleID &" And ParentStr like '%" & ParentStr & "%' ORDER BY Orders")
			Do While Not Rs.EOF
				i = i + 1
				Conn.Execute ("UPDATE Jin_Class SET Orders=" & i & " WHERE ModuleID = "& ModuleID &" And ID=" & Rs(0))
				Rs.movenext
			Loop
		End If
	End If
	Set Rs = Nothing
	Set trs = Nothing
	
	Response.redirect "?action=classOrders&ModuleID=" & ModuleID
	Response.End
End Sub

Sub RestoreClass()
	Dim Rs,i
	i = 0
	Set Rs = Conn.Execute("SELECT ID FROM Jin_Class WHERE ModuleID="& ModuleID &" ORDER BY RootID,Orders")
	Do While Not Rs.EOF
		i = i + 1
		Conn.Execute ("UPDATE Jin_Class SET RootID=" & i & ",Depth=0,Orders=0,ParentID=0,ParentStr='0',Child=0, ChildStr='"&Rs(0)&"' WHERE ModuleID = "& ModuleID &" And ID=" & Rs(0))
		Rs.movenext
	Loop
	Set Rs = Nothing
	
	response.write("<li>复位成功，请返回做栏目归属设置。 <a href=""javascript:history.go(-1);"">返回</a></li>")
	
End Sub

'Add by Jin 2014-11-03
Function get_TypeName(en)
	Set Rs=server.createobject("adodb.recordSet")
	Sql="select * from Jin_ClassType where TypeName_en='"&en&"'"
	Rs.open Sql,conn,1,1
	If Rs.eof then
	get_TypeName="未设置"
	else
	get_TypeName=Rs("TypeName")
	End If
	Rs.close
	set Rs=nothing
End Function

%>

</div>



<%Call BackFoot()%>

<script>
$(document).ready(function(e){
autoAdd("BNavAdd");
autoAdd("BNavAdd1");
autoSave("ClassName");
autoSave("ClassName_en");
autoSave("Url");
autoDel("BNavDel");
});
</script>
