<!--#include file="Admin_Const.asp"-->
<%
dim Action,ParentID,ParentPath
dim BrowsePurview
Dim strTitleName
Action=Trim(Request("Action"))
ParentID=Cl.ChkClng(Trim(request("ParentID")))
if ChannelID=0 then Admin_ShowErr("<br /><li>请正确指定频道或者模块ID！</li>")
if Not Cl.TrueChannelPurview(1,ChannelID) then Admin_ShowErr("<br /><li>您无此操作权限！</li>")
Cl.GetChannelSetting(ChannelID)
strFileName="Admin_Class.asp?ChannelID=" & ChannelID
Header
%>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
  <tr class="title"> 
    <td height="22" colspan="2" align="center"><strong><%=Cl.Channel_Setting(2)%>栏目管理</strong></td>
  </tr>
  <tr class="tdbg"> 
    <td width="70" height="30"><strong>管理导航：</strong></td>
    <td height="30"><a href="<%=strFileName%>"><%=Cl.Channel_Setting(2)%>栏目首页</a> | <a href="<%=strFileName%>&Action=Order">一级栏目排序</a>&nbsp;|&nbsp;<a href="<%=strFileName%>&Action=OrderN">N级栏目排序</a>&nbsp;|&nbsp;<a href="<%=strFileName%>&Action=Reset">复位所有<%=Cl.Channel_Setting(2)%>栏目</a>&nbsp;|&nbsp;<a href="<%=strFileName%>&Action=Unite"><%=Cl.Channel_Setting(2)%>栏目合并</a>
	<br />
	<a href="<%=strFileName%>&Action=Add">添加<%=Cl.Channel_Setting(2)%>栏目</a>&nbsp;|&nbsp;<a href="<%=strFileName%>&Action=Add2"><font color=#0000ff>添加<%=Cl.Channel_Setting(2)%>栏目(批量)</font></a>&nbsp;|&nbsp;<a href="<%=strFileName%>&Action=UpDateClassData">更新<%=Cl.Channel_Setting(2)%>栏目数据</a>&nbsp;|&nbsp;<a href="<%=strFileName%>&Action=Batch"><font color=#0000ff>批量设置栏目属性</font></a>
	</td>
  </tr>
</table>
<br />
<%
Select Case Action
Case "Add"
	call ClassInfo()
Case "SaveAdd"
	call SaveAdd()
Case "Add2"
	call Add2()
Case "SaveAdd2"
	call SaveAdd2()
Case "Modify"
	call ClassInfo()
Case "SaveModify"
	call SaveModify()
Case "Move"
	call MoveClass()
Case "SaveMove"
	call SaveMove()
Case "Del"
	call DeleteClass()
Case "Clear"
	call ClearClass()
Case "UpOrder"
	call UpOrder() 
Case "DownOrder"
	call DownOrder() 
Case "Order"
	call Order()
Case "UpOrderN"
	call UpOrderN() 
Case "DownOrderN"
	call DownOrderN() 
Case "OrderN"
	call OrderN()
Case "Reset"
	call Reset()
Case "SaveReset"
	call SaveReset()
Case "Unite"
	call Unite()
Case "SaveUnite"
	call SaveUnite()
Case "UpDateClassData"
	call UpDateClassData()
	Response.Write Cl.ShowSuc("恭喜你，更新成功！返回 <a href='"&strFileName&"'>栏目管理首页</a> 。")
Case "RefreshClassJs"
	Call RefreshClassJs()
Case "Batch"
	call Batch()
Case "SaveBatch"
	call SaveBatch()
Case else
	call main()
End Select
if FoundErr=True then Admin_ShowErr(ErrMsg)
Footer

Sub main()
	dim arrID,arrShowLine(10)
	dim sqlClass,rsClass,iDepth,TempName
	arrID=Trim(Request("arrID"))
	arrID=Replace(arrID," ","")
	if Not IsNumeric(Replace(arrID,",","")) then arrID=0
	for i=0 to ubound(arrShowLine)
		arrShowLine(i)=False
	next
	sqlClass="Select * From Cl_Class where (ParentID In ("&arrID&") or Depth=0) and  ChannelID=" & ChannelID & " order by RootID,OrderID"
	Rem ACCESS sqlClass="select * From Cl_Class where ChannelID="&ChannelID&" order by RootID,OrderID"
	set rsClass=server.CreateObject("adodb.recordset")
	OpenConn : rsClass.open sqlClass,Conn,1,1
%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="border">
  <tr class="title">
    <td width="30" align="center"><strong>ID</strong></td>
    <td height="22" align="center"><strong>栏目名称/[目录]</strong></td>
    <td width="40" align="center"><strong>属性</strong></td>
    <td width="300" height="22" align="center"><strong>操作选项</strong></td>
  </tr>
  <% 
do while not rsClass.eof 
%>
  <tr class="tdbg" onMouseOut="this.className='tdbg'" onMouseOver="this.className='tdbg2'"> 
    <td width="30" align="center"><Font Color=#0000ff><%=rsClass("ClassID")%></font></td>
    <td> <% 
		iDepth=rsClass("Depth")
		if rsClass("NextID")>0 then
			arrShowLine(iDepth)=True
		else
			arrShowLine(iDepth)=False
		end if
		if iDepth>0 then
	  		for i=1 to iDepth 
				if i=iDepth then 
					if rsClass("NextID")>0 then 
						response.write "<img src='"&Cl.Webdir&"images/Tree/line1.gif' width='17' height='16' valign='abvmiddle'>" 
					else 
						response.write "<img src='"&Cl.Webdir&"images/Tree/line2.gif' width='17' height='16' valign='abvmiddle'>" 
					end if 
				else 
					if arrShowLine(i)=True then
						response.write "<img src='"&Cl.Webdir&"images/Tree/line3.gif' width='17' height='16' valign='abvmiddle'>" 
					else
						response.write "<img src='"&Cl.Webdir&"images/Tree/line4.gif' width='17' height='16' valign='abvmiddle'>" 
					end if
				end if 
	  		next 
		end if
	Rem ACCESS Begin========================================================================
		'TempName="<a href='"&strFileName&"&Action=Modify&ClassID=" & rsClass("ClassID") & "' title='" & rsClass("ReadMe") & "'>" & rsClass("ClassName") & "</a>"
		'if rsClass("Child")>0 then 
	  	'	response.write "<img src='"&Cl.Webdir&"images/Tree/folder4.gif' width='15' height='15' valign='abvmiddle'>"
		'	TempName = TempName & "(" & rsClass("Child") & ")"
		'else 
	  	'	response.write "<img src='"&Cl.Webdir&"images/Tree/folder3.gif' width='15' height='15' valign='abvmiddle'>" 
		'end if 
		'if rsClass("Depth")=0 then 
	  	'	response.write "<b>" & TempName & "</b>"
		'else
	  	'	response.write TempName
		'end if
	Rem ACCESS End========================================================================
	Rem SQL Begin========================================================================
		if rsClass("Child")>0 then
			if Instr(","&arrID&",",","&rsClass("ParentPath") & "," & rsClass("ClassID")&",")>0 then
	  			response.write "<a href='"&strFileName&"&arrID=" & rsClass("ParentPath") & "' title='点击收起栏目'><img src='"&Cl.Webdir&"images/Tree/folder3.gif' width='15' height='15' valign='abvmiddle' border=0><b>" & rsClass("ClassName") & "</b> (<font color='#ff0033'>" & rsClass("Child") & "</font>)</a>"
			else
	  			response.write "<a href='"&strFileName&"&arrID=" & rsClass("ParentPath") & "," & rsClass("ClassID") & "' title='有子栏目，点击展开栏目'><img src='"&Cl.Webdir&"images/Tree/folder4.gif' width='15' height='15' valign='abvmiddle' border=0><b>" & rsClass("ClassName") & "</b> (<font color='#ff0033'>" & rsClass("Child") & "</font>)</a>"
			end if
		else 
	  		response.write "<a href='"&strFileName&"&Action=Modify&ClassID="&rsClass("ClassID")&"' title='点击修改栏目'><img src='"&Cl.Webdir&"images/Tree/folder3.gif' width='15' height='15' valign='abvmiddle' border=0>" & rsClass("ClassName") & "</a>"
		end if
	Rem SQL End========================================================================
		response.write " <font color='#0066ff'>[" & rsClass("ClassDir") & "]</font>"
	  %> </td>
    <td width="40" align="center"> <%
	if rsClass("IsOuter")=1 then
		response.write "<font color=red>外</font>&nbsp;"
	else
		response.write "<font color=green>内</font>&nbsp;"
	end if
	if rsClass("IsElite")=True then
		response.write "<font color=blue>荐</font>"
	else
		response.write "普"
	end if
	%> </td>
    <td align="center"><a href="<%=strFileName%>&Action=Add&ParentID=<%=rsClass("ClassID")%>">添加子栏目</a> 
      | <a href="<%=strFileName%>&Action=Modify&ClassID=<%=rsClass("ClassID")%>">修改设置</a> 
      | <a href="<%=strFileName%>&Action=Move&ClassID=<%=rsClass("ClassID")%>">移动栏目</a> 
      | <a href="<%=strFileName%>&Action=Clear&ClassID=<%=rsClass("ClassID")%>" onClick="return ConfirmDel3();">清空</a> 
      | <a href="<%=strFileName%>&Action=Del&ClassID=<%=rsClass("ClassID")%>" onClick="<%if rsClass("Child")>0 then%>return ConfirmDel1();<%else%>return ConfirmDel2();<%end if%>">删除</a></td>
  </tr>
  <% 
	rsClass.movenext 
loop 
%>
<form name="form1" method="Post" action="<%=strFileName%>">
   <tr class="tdbg">
      <td height="40" colspan="7" align="center">
		<input name="Action" type="hidden" id="Action" value="RefreshClassJs"> 
        <input name="Submit" type="submit" value=" 刷新<%=Cl.Channel_Setting(2)%>栏目JS "></td>
    </tr>
</form>
</table>
<script language="JavaScript" type="text/JavaScript">
function ConfirmDel1()
{
   alert("此栏目下还有子栏目，必须先删除下属子栏目后才能删除此栏目！");
   return false;
}

function ConfirmDel2()
{
   if(confirm("删除栏目将同时删除此栏目中的所有数据，并且不能恢复！确定要删除此栏目吗？"))
     return true;
   else
     return false;
	 
}
function ConfirmDel3()
{
   if(confirm("清空栏目将把栏目（包括子栏目）的所有数据放入回收站中！确定要清空此栏目吗？"))
     return true;
   else
     return false;
	 
}
</script>
<br /><br />
<b>说明：</b><br />&nbsp;&nbsp;&nbsp;&nbsp;
属性中的各项含义：<font color=red>外</font>---外部栏目，<font color=green>内</font>---内部栏目，<font color=blue>荐</font>---推荐栏目，普---普通栏目
<br /><br />
<%
end sub

Sub ClassInfo()
Dim Prs,ClassID,sAction,SubmitValue,sParentName
Dim sClassName,sClassDir,sReadme,sIsElite,sShowOnTop,sClassPicUrl,sIsOuter,sLinkUrl
Dim sCommentIsChk,sAddIsChk,sCommentGroup,sAddPoint,sMaxLimit,sStyleID,sCssID
Dim sDisabledAdd,sVipUser
if Action="Add" then
	if ParentID>0 then
		Set Prs=Cl.Execute("Select ClassID,ClassName,BrowsePurview,DisabledAdd,AddIsChk,AddPoint,MaxLimit,CommentGroup,CommentIsChk,IsOuter,StyleID,CssID,VipUser From Cl_Class Where ChannelID="&ChannelID&" and ClassID="&ParentID&"")
		if Prs.bof and Prs.eof then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>找不到指定的栏目！</li>"
			exit sub
		End if
		sParentName		= Prs(1) : BrowsePurview	= Prs(2)
		sDisabledAdd	= Prs(3)
		sAddIsChk		= Prs(4) : sAddPoint		= Prs(5)
		sMaxLimit		= Prs(6) : sCommentGroup	= Prs(7)
		sCommentIsChk	= Prs(8) : sIsOuter			= Prs(9)
		sStyleID		= Prs(10) : sCssID			= Prs(11)
		sVipUser		= Prs(12)
		Set Prs=Nothing
	else
		BrowsePurview	= 0 : sDisabledAdd=0
		sCommentGroup	= Cl.Web_Setting(34): sCommentIsChk		= True
		sAddIsChk		= True	: sAddPoint			= 0
		sMaxLimit		= 0		: sIsOuter			= 0
		sStyleID		= -1	: sCssID			= -1
		sVipUser		= ""
	end if
	sClassName		= ""		: sClassDir		= ""
	sReadme			= ""		: sIsElite		= True
	sShowOnTop		= True		: sClassPicUrl	= ""
	sLinkUrl		= ""
	sAction			= "SaveAdd"	: SubmitValue	= "添 加"
elseif Action="Modify" then
	ClassID=Cl.ChkClng(request("ClassID"))
	if ClassID=0 then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>参数不足！</li>"
		exit sub
	end if
	set Prs=Cl.Execute("select * From Cl_Class where ChannelID="&ChannelID&" and ClassID=" & ClassID & "")
	if Prs.bof and Prs.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>找不到指定的栏目！</li>"
		exit sub
	End if
	ParentID		= Prs("ParentID")	: ParentPath	= Prs("ParentPath")
	sClassName		= Prs("ClassName")	: sClassDir		= Prs("ClassDir")
	sReadme			= Prs("Readme")		: sIsElite		= Prs("IsElite")
	sShowOnTop		= Prs("ShowOnTop")
	sLinkUrl		= Prs("LinkUrl")	: BrowsePurview	= Prs("BrowsePurview")
	sDisabledAdd	= Prs("DisabledAdd"): sCommentGroup = Prs("CommentGroup")
	sCommentIsChk	= Prs("CommentIsChk"):sAddIsChk		= Prs("AddIsChk")
	sAddPoint		= Prs("AddPoint")	: sMaxLimit		= Prs("MaxLimit")
	sIsOuter		= Prs("IsOuter")	: sVipUser		= Prs("VipUser")
	sStyleID		= Prs("StyleID")	: sCssID		= Prs("CssID")
	sAction="SaveModify":SubmitValue="修 改"
	Set Prs=Nothing
end if
if Not IsNumeric(sAddPoint) then sAddPoint=0
%>
<form name="form1" method="post" action="<%=strFileName%>" onsubmit="return check()">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <tr class="title"> 
      <td height="22" colspan="2" align="center"><strong><%=SubmitValue%> 栏 目</strong></td>
    </tr>
	<%if Action="Modify" then%>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>所属栏目：</strong></td>
      <td> <%
	if ParentID<=0 then
	  	response.write "无（作为一级栏目）"
	else
    	dim rsParentClass
		set rsParentClass=Cl.Execute("Select * From Cl_Class where ChannelID="&ChannelID&" and ClassID in (" & ParentPath & ") order by Depth")
		do while not rsParentClass.eof
			for i=1 to rsParentClass("Depth")
				response.write "&nbsp;&nbsp;&nbsp;"
			next
			if rsParentClass("Depth")>0 then
				response.write "└"
			end if
			response.write "&nbsp;" & rsParentClass("ClassName") & "<br />"
			rsParentClass.movenext
		loop
		set rsParentClass=Nothing
	end if
	%> <br />&nbsp;<font color="#0000ff">提示：如果你想改变所属栏目，请<a href='<%=strFileName%>&Action=Move&ClassID=<%=ClassID%>'>点此移动栏目</a></font></td>
    </tr>
	<%else%>
	<!--
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>所属栏目：</strong></td>
      <td><Input type="hidden" name="ParentID" id="ParentID" value="<%=ParentID%>"><Input type="text" name="ParentIDv" id="ParentIDv" value="<%
	  'if ParentID>0 then
	'	Response.write ParentID & ":" & sParentName
	'  else
	'	Response.write "0:作为一级栏目"
	'  End if
	  %>" size=45 readonly Onclick="SelectClass('<%=ChannelID%>','ParentID')">&nbsp<Input type="button" Name="selectclassid" Onclick="SelectClass('<%=ChannelID%>','ParentID')" value="选择栏目">
	  </td>
    </tr>-->
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>所属栏目：</strong></td>
      <td> <select name="ParentID">
          <%=ShowClass_Option(ChannelID,ParentID,0,0)%> 
        </select>&nbsp;&nbsp;<font color="#ff0033">注意：不能指定为外部栏目</font></td>
    </tr>
	<%end if%>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>栏目名称：</strong></td>
      <td><input name="ClassName" type="text" value="<%=sClassName%>" size="50" maxlength="20"> <font color=red>*</font>
        <input name="ClassID" type="hidden" id="ClassID" value="<%=ClassID%>"></td>
    </tr>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>外部栏目：</strong></td>
      <td><input name="IsOuter" type="checkbox" id="IsOuter" value="1" OnClick="ChkIsOuter();" <%
	  if sIsOuter=1 then Response.write " Checked"
	  
	  if Action="Modify" and sIsOuter=0 then Response.write " Disabled"
		%>>&nbsp;外部栏目</td>
    </tr>
    <tr class="tdbg" ID="OuterClass" style="DisPlay:none"> 
      <td width="150" align="right"><strong>链接地址：</strong></td>
      <td><input name="LinkUrl" type="text" id="LinkUrl" value="<%=sLinkUrl%>" size="50" maxlength="255">
	  <br /><font color="#0000ff">说明：如果想将栏目链接到外部地址，请输入完整的URL地址，否则请保持为空。</font></td>
    </tr>
<!--==================================================================-->
    <tr class="tdbg" id="NoOuterClass">
      <td width="150" align="right"><strong>栏目参数：</strong></td>
      <td>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>栏目目录(英文名)：</strong></td>
      <td><input name="ClassDir" type="text" value="<%=sClassDir%>" size="50" maxlength="20"> <font color=red>*</font><br /><font color="#ff0033">注意：只能是英文，不能带空格或“\”、“/”等符号，此项更改后，请重新生成此栏目所有内容。</font></td>
    </tr>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>栏 目 说 明：</strong></td>
      <td><textarea name="Readme" cols="42" rows="4" id="Readme"><%=sReadMe%></textarea><br /> <font color="#ff0033">注意：不支持HTML，不能有回车，说明可为留空。</font></td>
    </tr>
    <tr class="tdbg">
      <td align="right"><strong>是否设为推荐栏目：</strong></td>
      <td>
		<input name="IsElite" type="radio" value="Yes" <%if sIsElite=True then response.write " checked"%>> 是&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="IsElite" value="No" <%if sIsElite=False then response.write " checked"%>> 否
	  <br /><font color="#0000ff">说明：推荐栏目将在首页及此栏目的父栏目上显示列表</font></td>
    </tr>
    <tr class="tdbg">
      <td align="right"><strong>是否顶部导航显示：</strong></td>
      <td>
		<input name="ShowOnTop" type="radio" value="Yes" <%if sShowOnTop=True then response.write " checked"%>> 是&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="ShowOnTop" value="No" <%if sShowOnTop=False then response.write " checked"%>> 否</td>
    </tr>
    <tr class="tdbg">
      <td width="150" align="right"><strong>栏目浏览权限设置：</strong></td>
      <td>
		<input name="BrowsePurview" type="radio" value="0" <%if BrowsePurview=0 then response.write " checked"%> onclick="document.getElementById('VipUser').style.display='none';"> 开放栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目任何人都可浏览或下载，包括游客</font><br />
		<input name="BrowsePurview" type="radio" value="1" <%if BrowsePurview=1 then response.write " checked"%> onclick="document.getElementById('VipUser').style.display='none';"> 限制栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目只有相应权限的用户能浏览或下载</font><br />
		<input name="BrowsePurview" type="radio" value="2" <%if BrowsePurview=2 then response.write " checked"%> onclick="document.getElementById('VipUser').style.display='';"> 认证栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目只有认证会员或管理员能浏览或下载</font><br />
		<input name="BrowsePurview" type="radio" value="3" <%if BrowsePurview=3 then response.write " checked"%> onclick="document.getElementById('VipUser').style.display='none';"> 禁用栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目任何人都不能浏览或下载</font>
		</td>
    </tr>
    <tr class="tdbg" <%if BrowsePurview<>2 then%>style="display:none;"<%end if%> id="VipUser">
      <td width="150" align="right"><strong>栏目认证用户设置：</strong></td>
      <td><textarea name="VipUser" cols="42" rows="4"><%
		if Instr(sVipUser,"|")>0 then
			sVipUser=Split(sVipUser,"|")
			For i=0 to Ubound(sVipUser)
				Response.write sVipUser(i)
				if i< Ubound(sVipUser) then Response.write VbCrlf
			Next
		else
			Response.write sVipUser
		end if
		%></textarea><br /> <font color="#ff0033">注意：每个认证用户用回车分开。</font></td>
    </tr>
    <tr class="tdbg">
      <td align="right"><strong>是否禁止录入资料：</strong></td>
      <td>
		<input name="DisabledAdd" type="radio" value="0" <%if sDisabledAdd=0 then response.write " checked"%>> 允许&nbsp;&nbsp;&nbsp;&nbsp; 
		<input name="DisabledAdd" type="radio" value="1" <%if sDisabledAdd=1 then response.write " checked"%>> 禁止</td>
    </tr>
    <tr class="tdbg">
      <td align="right"><strong>录入资料是否审核：</strong></td>
      <td>
		<input name="AddIsChk" type="radio" value="Yes" <%if sAddIsChk=True then response.write " checked"%>> 审核&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="AddIsChk" value="No" <%if sAddIsChk=False then response.write " checked"%>> 不审核
	  <br /><font color="#0000ff">说明：如果选择审核，那么用户添加资料后需要管理员审核后方在前台显示。</font></td>
    </tr>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>录入资料<%=Cl.Web_Setting(28)%>设置：</strong></td>
      <td>在此栏目录入资料可得到：<input name="AddPoint" type="text" id="AddPoint" value="<%=sAddPoint%>" size="10" maxlength="8"> <%=Cl.Web_Setting(29)%><%=Cl.Web_Setting(28)%><br /><font color="#0000ff">说明：如果为0时，则不添加<%=Cl.Web_Setting(28)%>！</font></td>
    </tr>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>录入资料最大限制：</strong></td>
      <td>在此栏目添加资料最大限制为： <input name="MaxLimit" type="text" id="MaxLimit" value="<%=sMaxLimit%>" size="10" maxlength="10"> 字节<br /><font color="#0000ff">说明：如果为0时，则不限制大小！</font></td>
    </tr>
    <tr class="tdbg">
      <td align="right"><strong>发表评论是否审核：</strong></td>
      <td>
		<input name="CommentIsChk" type="radio" value="Yes" <%if sCommentIsChk=True then response.write " checked"%>> 审核&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="CommentIsChk" value="No" <%if sCommentIsChk=False then response.write " checked"%>> 不审核
	  <br /><font color="#0000ff">说明：如果选择审核，那么用户发表评论后需要管理员审核后方在前台显示。</font></td>
    </tr>
    <tr class="tdbg">
      <td width="150" align="right"><strong>允许评论的用户组：</strong></td>
      <td>
		<input name="CommentGroup" type="hidden" id="CommentGroup" value="<%=sCommentGroup%>">
		<input name="CommentGroupView" type="text" id="CommentGroupView" value="<%=Cl.GetUserGroupName(sCommentGroup)%>" size="50" onclick="SelectUserGroup('CommentGroup');" Readonly>
		</td>
    </tr>

    <tr class="tdbg"> 
      <td width="150" align="right"><strong>栏目风格模版选择：</strong></td>
      <td>模板：<select name="StyleID">
		<option value="-1" selected>使用频道模版</option>
		<%
		Dim rs_s, sTempCss, sCssName
		set rs_s = Cl.Execute("Select ID,StyleName from Cl_Style Order by ID")
		do while not rs_s.eof
			response.write "<option value="""&rs_s(0)&""""
			If sStyleID = rs_s(0) Then response.write " selected"
			response.write ">"&rs_s(1)&"</option>"
			rs_s.MoveNext
		Loop
		Set rs_s = Nothing
		%>
		</select>&nbsp;&nbsp;CSS风格：<select name="CssID">
		<option value="-1" selected>使用频道CSS</option>
		<%
		sTempCss = Split(Cl.CacheData(15,0),"@@@")(0)
		sCssName = Split(sTempCss,"|||")
		for i=0 to ubound(sCssName)-1
			response.write "<option value="""&i&""""
			If sCssID = i Then response.write " selected"
			response.write ">"&sCssName(i)&"</option>"
		next%>
		</select></td>
    </tr>
  </table>
		</td>
    </tr>
<!--==================================================================-->
    <tr class="tdbg"> 
      <td height="40" colspan="2" align="center"><input name="Action" type="hidden" id="Action" value="<%=sAction%>"> 
        <input name="Submit" type="submit" value=" <%=SubmitValue%> "> 
        &nbsp; <input name="Cancel" type="button" id="Cancel" value=" 取 消 " onClick="window.location.href='<%=strFileName%>'"></td>
    </tr>
</table>
</form>
<script language="JavaScript" type="text/JavaScript">
<%if sIsOuter=1 then%>
document.getElementById('OuterClass').style.display = '';
document.getElementById('NoOuterClass').style.display = 'none';
<%end if%>
function ChkIsOuter(){
if (document.getElementById('IsOuter').checked == true) {
	document.getElementById('OuterClass').style.display = '';
	document.getElementById('NoOuterClass').style.display = 'none';
}else{
	document.getElementById('OuterClass').style.display = 'none';
	document.getElementById('NoOuterClass').style.display = '';
}
}
function check()
{
  if (document.form1.ClassName.value=="")
  {
    alert("栏目名称不能为空！");
	document.form1.ClassName.focus();
	return false;
  }
}
</script>
<%
end sub

sub MoveClass()
	dim ClassID,rsClass,i
	ClassID=Trim(request("ClassID"))
	if ClassID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>参数不足！</li>"
		exit sub
	else
		ClassID=CLng(ClassID)
	end if
	sql="select * From Cl_Class where ChannelID="&ChannelID&" and ClassID=" & ClassID
	set rsClass=server.CreateObject ("Adodb.recordset")
	OpenConn : rsClass.open sql,Conn,1,3
	if rsClass.bof and rsClass.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>找不到指定的栏目！</li>"
	else
%>
<form name="form1" method="post" action="<%=strFileName%>">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <tr class="title"> 
      <td height="22" colspan="2" align="center"><strong>移 动 栏 目</strong></td>
    </tr>
    <tr class="tdbg"> 
      <td width="200"><strong>栏目名称：</strong></td>
      <td><%=rsClass("ClassName")%> <input name="ClassID" type="hidden" id="ClassID" value="<%=rsClass("ClassID")%>"></td>
    </tr>
    <tr class="tdbg">
      <td width="200"><strong>当前所属栏目：</strong></td>
      <td>
        <%
	if rsClass("ParentID")<=0 then
	  	response.write "无（作为一级栏目）"
	else
    	dim rsParent,sqlParent
		sqlParent="Select * From Cl_Class where ChannelID="&ChannelID&" and ClassID in (" & rsClass("ParentPath") & ") order by Depth"
		set rsParent=server.CreateObject("adodb.recordset")
		OpenConn : rsParent.open sqlParent,Conn,1,1
		do while not rsParent.eof
			for i=1 to rsParent("Depth")
				response.write "&nbsp;&nbsp;&nbsp;"
			next
			if rsParent("Depth")>0 then
				response.write "└"
			end if
			response.write "&nbsp;" & rsParent("ClassName") & "<br />"
			rsParent.movenext
		loop
		rsParent.close
		set rsParent=Nothing
	end if
	%>
      </td>
    </tr>
    <tr class="tdbg"> 
      <td width="200"><strong>移动到：</strong><br />
        不能指定为当前栏目的下属子栏目<br />
        不能指定为外部栏目</td>
      <td><select name="ParentID" size="2" style="height:300px;width:500px;"><%=ShowClass_Option(ChannelID,rsClass("ParentID"),0,0)%></select></td>
    </tr>
    <tr class="tdbg"> 
      <td height="40" colspan="2" align="center"><input name="Action" type="hidden" id="Action" value="SaveMove"> 
        <input name="Submit" type="submit" value=" 保存移动结果 " style="cursor:hand;">
        &nbsp; 
        <input name="Cancel" type="button" id="Cancel" value=" 取 消 " onClick="window.location.href='<%=strFileName%>'" style="cursor:hand;"></td></tr>
  </table>
</form>
<%
	end if
	rsClass.close
	set rsClass=Nothing
end sub

sub Order() 
	dim sqlClass,rsClass,iCount,j
	sqlClass="select * From Cl_Class where ChannelID="&ChannelID&" and ParentID=0 order by RootID" 
	set rsClass=server.CreateObject("adodb.recordset") 
	OpenConn : rsClass.open sqlClass,Conn,1,1 
	iCount=rsClass.recordcount 
%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="border"> 
  <tr class="title">  
    <td height="22" colspan="4" align="center"><strong>一 级 栏 目 排 序</strong></td> 
  </tr> 
  <% 
j=1 
do while not rsClass.eof 
%> 
    <tr class="tdbg" onMouseOut="this.className='tdbg'" onMouseOver="this.className='tdbg2'">  
      <td width="200">&nbsp;<%=rsClass("ClassName")%></td> 
<% 
	if j>1 then 
  		response.write "<form action='" & strFileName & "&Action=UpOrder' method='post'><td width='150'>" 
		response.write "<select name=MoveNum size=1><option value=0>向上移动</option>" 
		for i=1 to j-1 
			response.write "<option value="&i&">"&i&"</option>" 
		next 
		response.write "</select>" 
		response.write "<input type=hidden name=ClassID value="&rsClass("ClassID")&">"
		response.write "<input type=hidden name=cRootID value="&rsClass("RootID")&">&nbsp;<input type=submit name=Submit value=修改>" 
		response.write "</td></form>" 
	else 
		response.write "<td width='150'>&nbsp;</td>" 
	end if 
	if iCount>j then 
  		response.write "<form action='"&strFileName&"&Action=DownOrder' method='post'><td width='150'>" 
		response.write "<select name=MoveNum size=1><option value=0>向下移动</option>" 
		for i=1 to iCount-j 
			response.write "<option value="&i&">"&i&"</option>" 
		next 
		response.write "</select>" 
		response.write "<input type=hidden name=ClassID value="&rsClass("ClassID")&">"
		response.write "<input type=hidden name=cRootID value="&rsClass("RootID")&">&nbsp;<input type=submit name=Submit value=修改>" 
		response.write "</td></form>" 
	else 
		response.write "<td width='150'>&nbsp;</td>" 
	end if 
%> 
      <td>&nbsp;</td>
	</tr> 
  <% 
	j=j+1 
	rsClass.movenext 
loop 
%> 
</table> 
<% 
	rsClass.close 
	set rsClass=Nothing 
end sub 

sub OrderN() 
	dim sqlClass,rsClass,iCount,trs,UpMoveNum,DownMoveNum
	sqlClass="select * From Cl_Class where ChannelID="&ChannelID&" order by RootID,OrderID" 
	set rsClass=server.CreateObject("adodb.recordset") 
	OpenConn : rsClass.open sqlClass,Conn,1,1 
%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="border"> 
  <tr class="title">  
    <td height="22" colspan="4" align="center"><strong>N 级 栏 目 排 序</strong></td> 
  </tr> 
  <% 
do while not rsClass.eof 
%> 
    <tr class="tdbg" onMouseOut="this.className='tdbg'" onMouseOver="this.className='tdbg2'">  
      <td width="300"> 
	  <% 
	for i=1 to rsClass("Depth") 
	  	response.write "&nbsp;&nbsp;&nbsp;" 
	next 
	if rsClass("Child")>0 then 
		response.write "<img src='../images/Tree/folder4.gif' width='15' height='15' valign='abvmiddle'>" 
	else 
	  	response.write "<img src='../images/Tree/folder3.gif' width='15' height='15' valign='abvmiddle'>" 
	end if 
	if rsClass("ParentID")=0 then 
		response.write "<b>" 
	end if 
	response.write rsClass("ClassName") 
	if rsClass("Child")>0 then 
		response.write "(" & rsClass("Child") & ")" 
	end if 
	%></td> 
<% 
	if rsClass("ParentID")>0 then   '如果不是一级栏目，则算出相同深度的栏目数目，得到该栏目在相同深度的栏目中所处位置（之上或者之下的栏目数） 
		'所能提升最大幅度应为For i=1 to 该版之上的版面数 
		set trs=Cl.Execute("select count(ClassID) From Cl_Class where ChannelID="&ChannelID&" and ParentID="&rsClass("ParentID")&" and OrderID<"&rsClass("OrderID")&"") 
		UpMoveNum=trs(0) 
		if isnull(UpMoveNum) then UpMoveNum=0 
		if UpMoveNum>0 then 
  			response.write "<form action='"&strFileName&"&Action=UpOrderN' method='post'><td width='150'>" 
			response.write "<select name=MoveNum size=1><option value=0>向上移动</option>" 
			for i=1 to UpMoveNum 
				response.write "<option value="&i&">"&i&"</option>" 
			next 
			response.write "</select>" 
			response.write "<input type=hidden name=ClassID value="&rsClass("ClassID")&">&nbsp;<input type=submit name=Submit value=修改>" 
			response.write "</td></form>" 
		else 
			response.write "<td width='150'>&nbsp;</td>" 
		end if 
		trs.close 
		'所能降低最大幅度应为For i=1 to 该版之下的版面数 
		set trs=Cl.Execute("select count(ClassID) From Cl_Class where ChannelID="&ChannelID&" and ParentID="&rsClass("ParentID")&" and orderID>"&rsClass("orderID")&"") 
		DownMoveNum=trs(0) 
		if isnull(DownMoveNum) then DownMoveNum=0 
		if DownMoveNum>0 then 
  			response.write "<form action='"&strFileName&"&Action=DownOrderN' method='post'><td width='150'>" 
			response.write "<select name=MoveNum size=1><option value=0>向下移动</option>" 
			for i=1 to DownMoveNum 
				response.write "<option value="&i&">"&i&"</option>" 
			next 
			response.write "</select>" 
			response.write "<input type=hidden name=ClassID value="&rsClass("ClassID")&">&nbsp;<input type=submit name=Submit value=修改>" 
			response.write "</td></form>" 
		else 
			response.write "<td width='150'>&nbsp;</td>" 
		end if 
		trs.close 
	else 
		response.write "<td colspan=2>&nbsp;</td>" 
	end if 
%> 
      <td>&nbsp;</td>
	</tr> 
  <% 
	UpMoveNum=0 
	DownMoveNum=0 
	rsClass.movenext 
loop 
%> 
</table> 
<% 
	rsClass.close 
	set rsClass=Nothing 
end sub 

sub Reset() 
%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="border"> 
  <tr class="title">  
    <td height="22" colspan="3" align="center"><strong>复 位 所 有 栏 目</strong></td> 
  </tr> 
    <tr class="tdbg">  
    <td align="center">  
      <form name="form1" method="post" action="<%=strFileName%>&Action=SaveReset"> 
        <table width="80%" border="0" cellspacing="0" cellpadding="0"> 
          <tr>  
            <td height="150"><font color="#FF0000"><strong>注意：</strong></font><br /> 
              &nbsp;&nbsp;&nbsp;&nbsp;如果选择复位所有栏目，则所有栏目都将作为一级栏目，这时您需要重新对各个栏目进行归属的基本设置。不要轻易使用该功能，仅在做出了错误的设置而无法复原栏目之间的关系和排序的时候使用。  
            </td> 
          </tr> 
        </table> 
        <input type="submit" name="Submit" value="复位所有栏目"> &nbsp; <input name="Cancel" type="button" id="Cancel" value=" 取 消 " onClick="window.location.href='<%=strFileName%>'" style="cursor:hand;">
      </form></td>
    </tr>
</table>
<%
end sub

sub Unite()
%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="border">
  <tr class="title"> 
    <td height="22" colspan="3" align="center"><strong>栏 目 合 并</strong></td>
  </tr>
  <tr class="tdbg"> 
    <td height="100"><form name="myform" method="post" action="<%=strFileName%>" onSubmit="return ConfirmUnite();">
        &nbsp;&nbsp;将栏目 
        <select name="ClassID" id="ClassID">
        <%=ShowClass_Option(ChannelID,0,0,1)%>
        </select>
        合并到
        <select name="TargetClassID" id="TargetClassID">
        <%=ShowClass_Option(ChannelID,0,0,1)%>
        </select>
        <br /> <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        <input name="Action" type="hidden" id="Action" value="SaveUnite">
        <input type="submit" name="Submit" value=" 合并栏目 " style="cursor:hand;">
        &nbsp;&nbsp; 
        <input name="Cancel" type="button" id="Cancel" value=" 取 消 " onClick="window.location.href='<%=strFileName%>'" style="cursor:hand;">
      </form>
	</td>
  </tr>
  <tr class="tdbg"> 
    <td height="60"><strong>注意事项：</strong><br />
      &nbsp;&nbsp;&nbsp;&nbsp;所有操作不可逆，请慎重操作！！！<br />
      &nbsp;&nbsp;&nbsp;&nbsp;不能在同一个栏目内进行操作，不能将一个栏目合并到其下属栏目中。目标栏目中不能含有子栏目。<br />
      &nbsp;&nbsp;&nbsp;&nbsp;合并后您所指定的栏目（或者包括其下属栏目）将被删除，所有数据将转移到目标栏目中。</td>
  </tr>
</table> 
<script language="JavaScript" type="text/JavaScript">
function ConfirmUnite()
{
  if (document.myform.ClassID.value==document.myform.TargetClassID.value)
  {
    alert("请不要在相同栏目内进行操作！");
	document.myform.TargetClassID.focus();
	return false;
  }
  if (document.myform.TargetClassID.value=="")
  {
    alert("目标栏目不能指定为含有子栏目的栏目！");
	document.myform.TargetClassID.focus();
	return false;
  }
}
</script>
<% 
end sub

sub SaveAdd()
	dim ClassID,ClassName,ClassDir,ParentDir,IsElite,ShowOnTop,Readme,ClassPicUrl,PrevOrderID
	dim trs,CommentGroup,CommentIsChk,AddIsChk,AddPoint,MaxLimit
	dim RootID,ParentDepth,ParentPath,ParentStr,ParentName,MaxClassID,MaxRootID
	dim PrevID,NextID,Child,DisabledAdd,VipUser
	Dim IsOuter,LinkUrl,StyleID,CssID
	ClassName		= Trim(request("ClassName"))
	ClassDir		= Trim(request("ClassDir"))
	IsElite			= Trim(request("IsElite"))
	ShowOnTop		= Trim(request("ShowOnTop"))
	CommentIsChk	= Trim(request("CommentIsChk"))
	AddIsChk		= Trim(request("AddIsChk"))
	Readme			= Trim(request("Readme"))
	'ClassPicUrl		= Trim(request("ClassPicUrl"))
	BrowsePurview	= Cl.ChkClng(request("BrowsePurview"))
	CommentGroup	= Trim(request("CommentGroup"))
	AddPoint		= Cl.ChkClng(request("AddPoint"))
	MaxLimit		= Cl.ChkClng(request("MaxLimit"))
	IsOuter			= Cl.ChkClng(request("IsOuter"))
	LinkUrl			= Trim(request("LinkUrl"))
	StyleID			= Cl.ChkClng(request("StyleID"))
	CssID			= Cl.ChkClng(request("CssID"))
	DisabledAdd		= Cl.ChkClng(request("DisabledAdd"))
	VipUser			= Trim(request("VipUser"))
	if Not IsNull(VipUser) then VipUser	= Replace(VipUser,VbCrlf,"|")
	if ClassName="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>栏目名称不能为空！</li>"
	end if
	if IsOuter=0 then
		if ClassDir="" then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>栏目目录不能为空！</li>"
		end if
	else
		IsOuter=1
		if LinkUrl="" then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>栏目链接地址不能为空！</li>"
		end if
	end if
	if FoundErr=True then exit sub
	set rs = Cl.Execute("select Max(ClassID) From Cl_Class")
	MaxClassID=rs(0)
	if Isnull(MaxClassID) then MaxClassID=0
	rs.close
	ClassID=MaxClassID+1
	if IsOuter=1 then ClassDir="Class"&ClassID
	set rs=Cl.Execute("select max(rootid) From Cl_Class where ChannelID="&ChannelID&" and Depth=0")
	MaxRootID=rs(0)
	if Isnull(MaxRootID) then MaxRootID=0
	rs.close
	RootID=MaxRootID+1
	if ParentID>0 then
		sql="select * From Cl_Class where ChannelID="&ChannelID&" and ClassID=" & ParentID & ""
		OpenConn : rs.open sql,Conn,1,1
		if rs.bof and rs.eof then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>所属栏目已经被删除！</li>"
		else
			if rs("IsOuter")=1 and IsOuter=0 then
				FoundErr=True
				ErrMsg=ErrMsg & "<br /><li>不能在外部栏目内添加内部栏目！</li>"
			end if
		end if
		if FoundErr=True then
			rs.close : set rs=Nothing : exit sub
		else	
			RootID		= rs("RootID")
			ParentName	= rs("ClassName")
			ParentDepth	= rs("Depth")
			ParentPath	= rs("ParentPath")
			Child		= rs("Child")
			ParentPath	= ParentPath & "," & ParentID     '得到此栏目的父级栏目路径
			ParentDir	= rs("ParentDir") & rs("ClassDir") & "/"      '得到此栏目的父级栏目目录
			PrevOrderID	= rs("OrderID")
			if Child>0 then
				dim rsPrevOrderID
				'得到与本栏目同级的最后一个栏目的OrderID
				set rsPrevOrderID=Cl.Execute("select Max(OrderID) From Cl_Class where ChannelID="&ChannelID&" and ParentID=" & ParentID)
				PrevOrderID=rsPrevOrderID(0)
				set trs=Cl.Execute("select ClassID from Cl_Class where ChannelID="&ChannelID&" and ParentID=" & ParentID & " and OrderID=" & PrevOrderID)
				PrevID=trs(0)
				'得到同一父栏目但比本栏目级数大的子栏目的最大OrderID，如果比前一个值大，则改用这个值。
				set rsPrevOrderID=Cl.Execute("select Max(OrderID) From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '" & ParentPath & ",%'")
				if not(rsPrevOrderID.bof and rsPrevOrderID.eof) then
					if not IsNull(rsPrevOrderID(0))  then
				 		if rsPrevOrderID(0)>PrevOrderID then
							PrevOrderID=rsPrevOrderID(0)
						end if
					end if
				end if
			else
				PrevID=0
			end if
		end if
		rs.close
	else
		if MaxRootID>0 then
			set trs=Cl.Execute("select ClassID from Cl_Class where ChannelID="&ChannelID&" and RootID=" & MaxRootID & " and Depth=0")
			PrevID=trs(0)
			trs.close
		else
			PrevID=0
		end if
		PrevOrderID=0
		ParentPath="0"
		ParentDir="/"
	end if

	sql="Select * From Cl_Class where ChannelID="&ChannelID&" and ParentID=" & ParentID & " And (ClassName='" & ClassName & "' or ClassDir='"&ClassDir&"')"
	set rs=server.CreateObject("adodb.recordset")
	OpenConn : rs.open sql,Conn,1,1
	if not(rs.bof and rs.eof) then
		FoundErr=True
		if ParentID=0 then
			ErrMsg=ErrMsg & "<br /><li>已经存在一级栏目名：" & ClassName & " 或者已经存在目录：" & ClassDir & "。</li>"
		else
			ErrMsg=ErrMsg & "<br /><li>“" & ParentName & "”中已经存在子栏目“" & ClassName & "” 或者已经存在目录：" & ClassDir & "。</li>"
		end if
		rs.close : set rs=Nothing : exit sub
	end if
	rs.close

	if IsElite="Yes" then
		IsElite=True
	else
		IsElite=False
	end if
	if ShowOnTop="Yes" then
		ShowOnTop=True
	else
		ShowOnTop=False
	end if
	if CommentIsChk="Yes" then
		CommentIsChk=True
	else
		CommentIsChk=False
	end if
	if AddIsChk="Yes" then
		AddIsChk=True
	else
		AddIsChk=False
	end if
	if Readme<>"" or Not IsNull(Readme) then Readme=Replace(Readme,VbCrlf,"")
	sql="Select top 1 * From Cl_Class"
	OpenConn : rs.open sql,Conn,1,3
    rs.addnew
	rs("ClassID")		= ClassID
	rs("ChannelID")		= ChannelID
   	rs("ClassName")		= ClassName
	rs("ParentID")		= ParentID
	rs("ParentPath")	= ParentPath
	rs("ClassDir")		= ClassDir
	rs("ParentDir")		= ParentDir
	if ParentID>0 then
		rs("Depth")		= ParentDepth+1
	else
		rs("Depth")		= 0
	end if
	rs("RootID")		= RootID
	rs("Child")			= 0
	rs("arrChildID")	= ClassID
	rs("PrevID")		= PrevID
	rs("NextID")		= 0
	rs("OrderID")		= PrevOrderID
	rs("Readme")		= Readme
	'rs("ClassPicUrl")	= ClassPicUrl
	rs("BrowsePurview")	= BrowsePurview
	rs("AddPoint")		= AddPoint
	rs("CommentGroup")	= CommentGroup
	rs("IsElite")		= IsElite
	rs("ShowOnTop")		= ShowOnTop
	rs("CommentIsChk")	= CommentIsChk
	rs("AddIsChk")		= AddIsChk
	rs("MaxLimit")		= MaxLimit
	rs("IsOuter")		= IsOuter
	rs("LinkUrl")		= LinkUrl
	rs("StyleID")		= StyleID
	rs("CssID")			= CssID
	rs("DisabledAdd")	= DisabledAdd
	rs("VipUser")		= VipUser
	rs.update
	rs.Close : Set rs=Nothing
	'更新与本栏目同一父栏目的上一个栏目的“NextID”字段值
	if PrevID>0 then
		Cl.Execute("Update Cl_Class set NextID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & PrevID)
	end if
	if ParentID>0 then
		'更新其父类的子栏目数
		Cl.Execute("Update Cl_Class set child=child+1 where ChannelID="&ChannelID&" and ClassID="&ParentID)
		'更新其父类以上栏目的“arrChildID”
		Dim rsParentID
		Set rsParentID=server.CreateObject("Adodb.recordset")
		OpenConn : rsParentID.open "Select ClassID,arrChildID From Cl_Class where ChannelID="&ChannelID&" and ClassID in ("&ParentPath&")",conn,1,3
		do While not rsParentID.Eof
			rsParentID("arrChildID")=""&rsParentID(1)&","&ClassID&""
			rsParentID.UpDate
			rsParentID.movenext
		Loop
		rsParentID.Close : Set rsParentID=Nothing
		'更新该栏目排序以及大于本需要和同在本分类下的栏目排序序号
		Cl.Execute("Update Cl_Class set OrderID=OrderID+1 where ChannelID="&ChannelID&" and rootid=" & rootid & " and OrderID>" & PrevOrderID)
		Cl.Execute("Update Cl_Class set OrderID=" & PrevOrderID & "+1 where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	end if
	CreateClassJs(ChannelID)
	Cl.SaveAdminLog
	Response.Write Cl.ShowSuc("恭喜你，栏目添加成功！返回 <a href='"&strFileName&"'>栏目管理首页</a> 。")
end sub

Sub SaveModify()
	Dim ClassName,ClassDir,Readme,IsElite,ShowOnTop,ClassPicUrl
	Dim trs,rs,CommentGroup,CommentIsChk,AddIsChk,AddPoint,MaxLimit
	Dim ClassID,rsClass,i,sChind,TClassDir
	Dim IsOuter,LinkUrl,StyleID,CssID,DisabledAdd,VipUser
	ClassID			= Cl.ChkClng(request("ClassID"))
	ClassName		= Trim(request("ClassName"))
	ClassDir		= Trim(request("ClassDir"))
	IsElite			= Trim(request("IsElite"))
	ShowOnTop		= Trim(request("ShowOnTop"))
	CommentIsChk	= Trim(request("CommentIsChk"))
	AddIsChk		= Trim(request("AddIsChk"))
	Readme			= Trim(request("Readme"))
	'ClassPicUrl		= Trim(request("ClassPicUrl"))
	BrowsePurview	= Cl.ChkClng(request("BrowsePurview"))
	CommentGroup	= Trim(request("CommentGroup"))
	AddPoint		= Cl.ChkClng(request("AddPoint"))
	MaxLimit		= Cl.ChkClng(request("MaxLimit"))
	IsOuter			= Cl.ChkClng(request("IsOuter"))
	LinkUrl			= Trim(request("LinkUrl"))
	StyleID			= Cl.ChkClng(request("StyleID"))
	CssID			= Cl.ChkClng(request("CssID"))
	DisabledAdd		= Cl.ChkClng(request("DisabledAdd"))
	VipUser			= Trim(request("VipUser"))
	if Not IsNull(VipUser) then VipUser	= Replace(VipUser,VbCrlf,"|")
	if ClassID=0 then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>参数不足！</li>"
	end if
	if ClassName="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>栏目名称不能为空！</li>"
	end if
	if IsOuter=0 then
		if ClassDir="" then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>栏目目录不能为空！</li>"
		end if
	else
		IsOuter=1
		if LinkUrl="" then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>栏目链接地址不能为空！</li>"
		end if
		ClassDir="Class" & ClassID
	end if
	
	if FoundErr=True then exit sub

	sql="select * From Cl_Class where ChannelID="&ChannelID&" and ClassID=" & ClassID
	set rsClass=server.CreateObject ("Adodb.recordset")
	OpenConn : rsClass.open sql,Conn,1,3
	if rsClass.bof and rsClass.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>找不到指定的栏目！</li>"
		rsClass.close:set rsClass=Nothing
		exit sub
	end if
	sChind=rsClass("Child")
	if rsClass("IsOuter")<>IsOuter then
		if rsClass("IsOuter")=0 and IsOuter=1 then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>此栏目为内部栏目，所以，不能再设为外部栏目。</li>"
			rsClass.close:Set rsClass=Nothing
			exit sub
		end if
		if sChind>0 then
			FoundErr=True
			if IsOuter=1 then
			ErrMsg=ErrMsg & "<br /><li>本栏目有子栏目，所以不能设为外部链接地址。</li>"
			else
			ErrMsg=ErrMsg & "<br /><li>本栏目有子栏目，所以不能设为内部栏目。</li>"
			end if
			rsClass.close:Set rsClass=Nothing
			exit sub
		end if
		if rsClass("ParentID")>0 then
			Dim sParent
			Set sParent=Cl.Execute("Select IsOuter From Cl_Class Where ClassID=" & rsClass("ParentID"))
			if Not (sParent.Bof and sParent.Eof) then
				if sParent(0)=1 and IsOuter=0 then
					FoundErr=True
					ErrMsg=ErrMsg & "<br /><li>本栏目父栏目为外部栏目，所以不能设为内部栏目。</li>"
					rsClass.close
					rsClass.close:Set rsClass=Nothing
					exit sub
				end if
			end if
		end if
	end if

	if FoundErr=True then exit sub

	if IsElite="Yes" then
		IsElite=True
	else
		IsElite=False
	end if
	if ShowOnTop="Yes" then
		ShowOnTop=True
	else
		ShowOnTop=False
	end if
	if CommentIsChk="Yes" then
		CommentIsChk=True
	else
		CommentIsChk=False
	end if
	if AddIsChk="Yes" then
		AddIsChk=True
	else
		AddIsChk=False
	end if
	TClassDir=rsClass("ClassDir")
	if Readme<>"" or Not IsNull(Readme) then Readme=Replace(Readme,VbCrlf,"")
   	rsClass("ClassName")	= ClassName
	rsClass("ClassDir")		= ClassDir
	rsClass("Readme")		= Readme
	'rsClass("ClassPicUrl")	= ClassPicUrl
	rsClass("BrowsePurview")= BrowsePurview
	rsClass("CommentGroup")	= CommentGroup
	rsClass("AddPoint")		= AddPoint
	rsClass("IsElite")		= IsElite
	rsClass("ShowOnTop")	= ShowOnTop
	rsClass("CommentIsChk")	= CommentIsChk
	rsClass("AddIsChk")		= AddIsChk
	rsClass("MaxLimit")		= MaxLimit
	rsClass("IsOuter")		= IsOuter
	rsClass("LinkUrl")		= LinkUrl
	rsClass("StyleID")		= StyleID
	rsClass("CssID")		= CssID
	rsClass("DisabledAdd")	= DisabledAdd
	rsClass("VipUser")		= VipUser
	rsClass.update
	rsClass.close : set rsClass=Nothing
	if sChind>0 and TClassDir<>ClassDir then UpDateClassData
	CreateClassJs(ChannelID)
	Cl.SaveAdminLog
	Response.Write Cl.ShowSuc("恭喜你，栏目修改成功！返回 <a href='"&strFileName&"'>栏目管理首页</a> 。")
end sub

sub DeleteClass()
	dim PrevID,NextID,ParentPath,ClassID
	ClassID=Cl.ChkClng(Trim(Request("ClassID")))
	if ClassID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>参数不足！</li>"
		exit sub
	end if
	sql="select ClassID,RootID,Depth,ParentID,ParentPath,Child,PrevID,NextID From Cl_Class where ChannelID="&ChannelID&" and ClassID="&ClassID
	set rs=server.CreateObject ("Adodb.recordset")
	OpenConn : rs.open sql,Conn,1,3
	if rs.bof and rs.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>栏目不存在，或者已经被删除</li>"
	else
		if rs("Child")>0 then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>该栏目含有子栏目，请删除其子栏目后再进行删除本栏目的操作</li>"
		end if
	end if
	if FoundErr=True then
		rs.close:set rs=Nothing
		exit sub
	end if
	PrevID=rs("PrevID")
	NextID=rs("NextID")
	ParentPath=rs("ParentPath")
	if rs("Depth")>0 then
		Cl.Execute("Update Cl_Class set child=child-1 where ChannelID="&ChannelID&" and ClassID=" & rs("ParentID"))
	end if
	rs.delete
	rs.update
	rs.close:set rs=Nothing

	'更新其父类以上栏目的“arrChildID”
	Dim rsParentID
	Set rsParentID=server.CreateObject("Adodb.recordset")
	OpenConn : rsParentID.open "Select ClassID,arrChildID From Cl_Class where ChannelID="&ChannelID&" and ClassID in ("&ParentPath&")",conn,1,3
	do While not rsParentID.Eof
		rsParentID("arrChildID")=""&Replace(rsParentID(1),","&ClassID&"","")&""
		rsParentID.UpDate
		rsParentID.movenext
	Loop
	rsParentID.Close:Set rsParentID=Nothing
	'删除本栏目的所有内容
	Select Case Clng(Cl.Channel_Setting(20))
	Case 1
	Cl.Execute("delete * from Cl_Article where ClassID=" & ClassID)
	Case 2
	Cl.Execute("delete * from Cl_Soft where ClassID=" & ClassID)
	Case 3
	Cl.Execute("delete * from Cl_Photo where ClassID=" & ClassID)
	Case 4
	Cl.Execute("delete * from Cl_Movie where ClassID=" & ClassID)
	Case 5
	Cl.Execute("delete * from Cl_Product where ClassID=" & ClassID)
	Case 6
	Cl.Execute("delete * from Cl_Topic where ClassID=" & ClassID)
	End Select

	Cl.Execute("delete * from Cl_Comment where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	
	'修改上一栏目的NextID和下一栏目的PrevID
	if PrevID>0 then
		Cl.Execute "Update Cl_Class set NextID=" & NextID & " where ChannelID="&ChannelID&" and ClassID=" & PrevID
	end if
	if NextID>0 then
		Cl.Execute "Update Cl_Class set PrevID=" & PrevID & " where ChannelID="&ChannelID&" and ClassID=" & NextID
	end if
	Cl.SaveAdminLog
	response.redirect strFileName
end sub

sub ClearClass()
	dim strClassID,rs,trs,SuccessMsg,ClassID
	ClassID=Trim(Request("ClassID"))
	if ClassID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>参数不足！</li>"
		exit sub
	else
		ClassID=CLng(ClassID)
	end if
	strClassID=cstr(ClassID)
	set rs=Cl.Execute("select ClassID,Child,ParentPath,arrChildID from Cl_Class where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	if rs.bof and rs.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>栏目不存在，或者已经被删除</li>"
		exit sub
	end if
	if rs(1)>0 then
		strClassID=rs(3)
	end if
	rs.close:set rs=Nothing
	Select Case Clng(Cl.Channel_Setting(20))
	Case 1
	Cl.Execute("Update Cl_Article set Deleted=True where ClassID in (" & strClassID & ")")
	Case 2
	Cl.Execute("Update Cl_Soft set Deleted=True where ClassID in (" & strClassID & ")")
	Case 3
	Cl.Execute("Update Cl_Photo set Deleted=True where ClassID in (" & strClassID & ")")
	Case 4
	Cl.Execute("Update Cl_Movie set Deleted=True where ClassID in (" & strClassID & ")")
	Case 5
	Cl.Execute("Update Cl_Product set Deleted=True where ClassID in (" & strClassID & ")")
	Case 6
	Cl.Execute("Update Cl_ToPic set Deleted=True where ClassID in (" & strClassID & ")")
	End Select
	Cl.SaveAdminLog
	'Cl.Execute("delete * from Cl_Article where ClassID in (" & strClassID & ")")	
	SuccessMsg="此栏目（包括子栏目）的所有内容已经被移到回收站中！"
	Response.Write Cl.ShowSuc(SuccessMsg)
end sub


sub SaveMove()
	dim ClassID,rsClass,i
	dim rParentID
	dim trs,rs
	dim ParentID,RootID,Depth,Child,ParentPath,ParentName,iParentID,iParentPath,PrevOrderID,PrevID,NextID,arrChildID,marrChildID
	ClassID=Cl.ChkClng(Trim(request("ClassID")))
	if ClassID=0 then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>参数不足！</li>"
		exit sub
	end if
	sql="select * From Cl_Class where ChannelID="&ChannelID&" and ClassID=" & ClassID
	set rsClass=server.CreateObject ("Adodb.recordset")
	OpenConn : rsClass.open sql,Conn,1,3
	if rsClass.bof and rsClass.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>找不到指定的栏目！</li>"
		rsClass.close:set rsClass=Nothing
		exit sub
	end if

	rParentID=Trim(request("ParentID"))
	if rParentID="" then
		rParentID=0
	else
		rParentID=CLng(rParentID)
	end if
	
	if rsClass("ParentID")<>rParentID then   '更改了所属栏目，则要做一系列检查
		if rParentID=rsClass("ClassID") then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>所属栏目不能为自己！</li>"
		end if
		'判断所指定的栏目是否为外部栏目或本栏目的下属栏目
		'if rsClass("ParentID")=0 then
			if rParentID>0 then
				set trs=Cl.Execute("select rootid,IsOuter From Cl_Class where ChannelID="&ChannelID&" and ClassID="&rParentID)
				if trs.bof and trs.eof then
					FoundErr=True
					ErrMsg=ErrMsg & "<br /><li>找不到指定的所属栏目</li>"
				else
					if rsClass("IsOuter")=0 and trs(1)=1 then
						FoundErr=True
						ErrMsg=ErrMsg & "<br /><li>此栏目为内部栏目，所以不能指定该栏目的所属栏目为外部栏目</li>"
					end if
					if rsClass("rootid")=trs(0) then
						FoundErr=True
						ErrMsg=ErrMsg & "<br /><li>不能指定该栏目的下属栏目作为所属栏目</li>"
					end if
				end if
				trs.close
				set trs=Nothing
			end if
		'else
			'set trs=Cl.Execute("select ClassID From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '"&rsClass("ParentPath")&"," & rsClass("ClassID") & "%' and ClassID="&rParentID)
			'if not (trs.eof and trs.bof) then
				'FoundErr=True
				'ErrMsg=ErrMsg & "<br /><li>您不能指定该栏目的下属栏目作为所属栏目</li>"
			'end if
			'trs.close
			'set trs=Nothing
		'end if
	end if

	if FoundErr=True then
		rsClass.close : set rsClass=Nothing : exit sub
	end if
	
	if rsClass("ParentID")=0 then
		ParentID	= rsClass("ClassID")
		iParentID	= 0
	else
		ParentID	= rsClass("ParentID")
		iParentID	= rsClass("ParentID")
	end if
	Depth		= rsClass("Depth")
	Child		= rsClass("Child")
	RootID		= rsClass("RootID")
	ParentPath	= rsClass("ParentPath")
	arrChildID	= rsClass("arrChildID")
	PrevID		= rsClass("PrevID")
	NextID		= rsClass("NextID")
	rsClass.close : set rsClass=Nothing
	
  '假如更改了所属栏目
  '需要更新其原来所属栏目信息，包括深度、父级ID、栏目数、排序、继承版主等数据
  '需要更新当前所属栏目信息
  '继承版主数据需要另写函数进行更新--取消，在前台可用ClassID in ParentPath来获得
  dim mrs,MaxRootID
  set mrs=Cl.Execute("select max(rootid) From Cl_Class where ChannelID="&ChannelID&"")
  MaxRootID=mrs(0)
  set mrs=Nothing
  if isnull(MaxRootID) then
	MaxRootID=0
  end if
  dim k,nParentPath,mParentPath
  dim ParentSql,ClassCount
  dim rsPrevOrderID
  if clng(parentid)<>rParentID and not (iParentID=0 and rParentID=0) then  '假如更改了所属栏目
	'更新原来同一父栏目的上一个栏目的NextID和下一个栏目的PrevID
	if PrevID>0 then
		Cl.Execute "Update Cl_Class set NextID=" & NextID & " where ChannelID="&ChannelID&" and ClassID=" & PrevID
	end if
	if NextID>0 then
		Cl.Execute "Update Cl_Class set PrevID=" & PrevID & " where ChannelID="&ChannelID&" and ClassID=" & NextID
	end if
	
	if iParentID>0 and rParentID=0 then  	'如果原来不是一级分类改成一级分类
		'得到上一个一级分类栏目
		sql="select ClassID,NextID from Cl_Class where ChannelID="&ChannelID&" and RootID=" & MaxRootID & " and Depth=0"
		set rs=server.CreateObject("Adodb.recordset")
		OpenConn : rs.open sql,Conn,1,3
		PrevID	= rs(0)      '得到新的PrevID
		rs(1)	= ClassID     '更新上一个一级分类栏目的NextID的值
		rs.update
		rs.close : set rs=Nothing
		
		MaxRootID=MaxRootID+1
		'更新当前栏目数据
		Cl.Execute("Update Cl_Class set depth=0,OrderID=0,rootid="&maxrootid&",parentid=0,ParentPath='0',arrChildID='"&ClassID&"',PrevID=" & PrevID & ",NextID=0 where ChannelID="&ChannelID&" and ClassID="&ClassID)

		'如果有下属栏目，则更新其下属栏目数据。下属栏目的排序不需考虑，只需更新下属栏目深度和一级排序ID(rootid)数据
		if child>0 then
			i=0
			set rs=Cl.Execute("select * From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '%"&ParentPath & "," & ClassID&"%'")
			do while not rs.eof
				i=i+1
				mParentPath=replace(rs("ParentPath"),ParentPath,"")
				Cl.Execute("Update Cl_Class set depth=depth-"&depth&",rootid="&maxrootid&",ParentPath='"&mParentPath&"' where ChannelID="&ChannelID&" and ClassID="&rs("ClassID"))
				rs.movenext
			loop
			set rs=Nothing
		end if
		'更新其原来所属栏目的栏目数，排序相当于剪枝而不需考虑
		Cl.Execute("Update Cl_Class set child=child-1 where ChannelID="&ChannelID&" and ClassID="&iParentID)
		
	elseif iParentID>0 and rParentID>0 then    '如果是将一个分栏目移动到其他分栏目下
		'得到当前栏目的下属子栏目数
		ParentPath=ParentPath & ","
		set rs=Cl.Execute("select count(*) From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '%"&ParentPath & ClassID&"%'")
		ClassCount=rs(0)
		if isnull(ClassCount) then
			ClassCount=1
		end if
		rs.close
		set rs=Nothing
		'获得目标栏目的相关信息		
		set trs=Cl.Execute("select * From Cl_Class where ChannelID="&ChannelID&" and ClassID="&rParentID)
		if trs("Child")>0 then		
			'得到与本栏目同级的最后一个栏目的OrderID
			set rsPrevOrderID=Cl.Execute("select Max(OrderID) From Cl_Class where ChannelID="&ChannelID&" and ParentID=" & trs("ClassID"))
			PrevOrderID=rsPrevOrderID(0)
			'得到与本栏目同级的最后一个栏目的ClassID
			sql="select ClassID,NextID from Cl_Class where ChannelID="&ChannelID&" and ParentID=" & trs("ClassID") & " and OrderID=" & PrevOrderID
			set rs=server.createobject("adodb.recordset")
			OpenConn : rs.open sql,Conn,1,3
			PrevID=rs(0)    '得到新的PrevID
			rs(1)=ClassID     '更新上一个栏目的NextID的值
			rs.update
			rs.close
			set rs=Nothing
			
			'得到同一父栏目但比本栏目级数大的子栏目的最大OrderID，如果比前一个值大，则改用这个值。
			set rsPrevOrderID=Cl.Execute("select Max(OrderID) From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '" & trs("ParentPath") & "," & trs("ClassID") & ",%'")
			if (not(rsPrevOrderID.bof and rsPrevOrderID.eof)) then
				if not IsNull(rsPrevOrderID(0))  then
			 		if rsPrevOrderID(0)>PrevOrderID then
						PrevOrderID=rsPrevOrderID(0)
					end if
				end if
			end if
		else
			PrevID=0
			PrevOrderID=trs("OrderID")
		end if
		
		'在获得移动过来的栏目数后更新排序在指定栏目之后的栏目排序数据
		Cl.Execute("Update Cl_Class set OrderID=OrderID+" & ClassCount & "+1 where ChannelID="&ChannelID&" and rootid=" & trs("rootid") & " and OrderID>" & PrevOrderID)
		
		'更新当前栏目数据
		Cl.Execute("Update Cl_Class set depth="&trs("depth")&"+1,OrderID="&PrevOrderID&"+1,rootid="&trs("rootid")&",ParentID="&rParentID&",ParentPath='" & trs("ParentPath") & "," & trs("ClassID") & "',PrevID=" & PrevID & ",NextID=0 where ChannelID="&ChannelID&" and ClassID="&ClassID)
		
		'如果有子栏目则更新子栏目数据，深度为原来的相对深度加上当前所属栏目的深度
		set rs=Cl.Execute("select * From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '%"&ParentPath&ClassID&"%' order by OrderID")
		i=1
		do while not rs.eof
			i=i+1
			iParentPath=trs("ParentPath") & "," & trs("ClassID") & "," & replace(rs("ParentPath"),ParentPath,"")
			Cl.Execute("Update Cl_Class set depth=depth-"&depth&"+"&trs("depth")&"+1,OrderID="&PrevOrderID&"+"&i&",rootid="&trs("rootid")&",ParentPath='"&iParentPath&"' where ChannelID="&ChannelID&" and ClassID="&rs("ClassID"))
			rs.movenext
		loop
		rs.close : set rs=Nothing
		trs.close : set trs=Nothing
		
		'更新所指向的上级栏目的子栏目数
		Cl.Execute("Update Cl_Class set child=child+1 where ChannelID="&ChannelID&" and ClassID="&rParentID)
		
		'更新其原父类的子栏目数			
		Cl.Execute("Update Cl_Class set child=child-1 where ChannelID="&ChannelID&" and ClassID="&iParentID)
	else    '如果原来是一级栏目改成其他栏目的下属栏目
		'得到移动的栏目总数
		set rs=Cl.Execute("select count(*) From Cl_Class where ChannelID="&ChannelID&" and rootid="&rootid)
		ClassCount=rs(0)
		rs.close:set rs=Nothing
		
		'获得目标栏目的相关信息		
		set trs=Cl.Execute("select * From Cl_Class where ChannelID="&ChannelID&" and ClassID="&rParentID)
		if trs("Child")>0 then		
			'得到与本栏目同级的最后一个栏目的OrderID
			set rsPrevOrderID=Cl.Execute("select Max(OrderID) From Cl_Class where ChannelID="&ChannelID&" and ParentID=" & trs("ClassID"))
			PrevOrderID=rsPrevOrderID(0)
			sql="select ClassID,NextID from Cl_Class where ChannelID="&ChannelID&" and ParentID=" & trs("ClassID") & " and OrderID=" & PrevOrderID
			set rs=server.createobject("adodb.recordset")
			OpenConn : rs.open sql,Conn,1,3
			PrevID	= rs(0) : rs(1)	= ClassID
			rs.update : set rs=Nothing
			'得到同一父栏目但比本栏目级数大的子栏目的最大OrderID，如果比前一个值大，则改用这个值
			set rsPrevOrderID=Cl.Execute("select Max(OrderID) From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '" & trs("ParentPath") & "," & trs("ClassID") & ",%'")
			if (not(rsPrevOrderID.bof and rsPrevOrderID.eof)) then
				if not IsNull(rsPrevOrderID(0))  then
			 		if rsPrevOrderID(0)>PrevOrderID then
						PrevOrderID=rsPrevOrderID(0)
					end if
				end if
			end if
		else
			PrevID=0
			PrevOrderID=trs("OrderID")
		end if

		'在获得移动过来的栏目数后更新排序在指定栏目之后的栏目排序数据
		Cl.Execute("Update Cl_Class set OrderID=OrderID+" & ClassCount &"+1 where ChannelID="&ChannelID&" and rootid=" & trs("rootid") & " and OrderID>" & PrevOrderID)
		
		Cl.Execute("Update Cl_Class set PrevID=" & PrevID & ",NextID=0 where ChannelID="&ChannelID&" and ClassID=" & ClassID)
		set rs=Cl.Execute("select * From Cl_Class where ChannelID="&ChannelID&" and rootid="&rootid&" order by OrderID")
		i=0
		do while not rs.eof
			i=i+1
			if rs("parentid")=0 then
				ParentPath=trs("ParentPath") & "," & trs("ClassID")
				Cl.Execute("Update Cl_Class set depth=depth+"&trs("depth")&"+1,OrderID="&PrevOrderID&"+"&i&",rootid="&trs("rootid")&",ParentPath='"&ParentPath&"',parentid="&rParentID&" where ChannelID="&ChannelID&" and ClassID="&rs("ClassID"))
			else
				ParentPath=trs("ParentPath") & "," & trs("ClassID") & "," & replace(rs("ParentPath"),"0,","")
				Cl.Execute("Update Cl_Class set depth=depth+"&trs("depth")&"+1,OrderID="&PrevOrderID&"+"&i&",rootid="&trs("rootid")&",ParentPath='"&ParentPath&"' where ChannelID="&ChannelID&" and ClassID="&rs("ClassID"))
			end if
			rs.movenext
		loop
		rs.close:set rs=Nothing
		trs.close
		set trs=Nothing
		'更新所指向的上级栏目栏目数		
		Cl.Execute("Update Cl_Class set child=child+1 where ChannelID="&ChannelID&" and ClassID="&rParentID)
	end if
	UpDateClassData '更新所有栏目数据
  end if
  Cl.SaveAdminLog
  Response.Redirect strFileName
end sub

sub UpOrder()
	dim ClassID,sqlOrder,rsOrder,MoveNum,cRootID,tRootID,PrevID,NextID
	ClassID=Cl.ChkClng(request("ClassID"))
	cRootID=Cl.ChkClng(request("cRootID"))
	MoveNum=Cl.ChkClng(request("MoveNum"))
	if ClassID=0 or cRootID=0 or MoveNum=0 then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>参数不足！</li>"
		Exit sub
	end if
	'得到本栏目的PrevID,NextID
	set rs=Cl.Execute("select PrevID,NextID from Cl_Class where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	PrevID = rs(0) : NextID = rs(1)
	rs.close : set rs=Nothing
	'先修改上一栏目的NextID和下一栏目的PrevID
	if PrevID>0 then
		Cl.Execute "Update Cl_Class set NextID=" & NextID & " where ChannelID="&ChannelID&" and ClassID=" & PrevID
	end if
	if NextID>0 then
		Cl.Execute "Update Cl_Class set PrevID=" & PrevID & " where ChannelID="&ChannelID&" and ClassID=" & NextID
	end if
	dim mrs,MaxRootID
	set mrs=Cl.Execute("select max(rootid) From Cl_Class where ChannelID="&ChannelID&"")
	MaxRootID=mrs(0)+1
	'先将当前栏目移至最后，包括子栏目
	Cl.Execute("Update Cl_Class set RootID=" & MaxRootID & " where ChannelID="&ChannelID&" and RootID=" & cRootID)
	'然后将位于当前栏目以上的栏目的RootID依次加一，范围为要提升的数字
	sqlOrder="select * From Cl_Class where ChannelID="&ChannelID&" and ParentID=0 and RootID<" & cRootID & " order by RootID desc"
	set rsOrder=server.CreateObject("adodb.recordset")
	OpenConn : rsOrder.open sqlOrder,Conn,1,3
	if rsOrder.bof and rsOrder.eof then
		exit sub        '如果当前栏目已经在最上面，则无需移动
	end if
	i=1
	do while not rsOrder.eof
		tRootID=rsOrder("RootID")       '得到要提升位置的RootID，包括子栏目
		Cl.Execute("Update Cl_Class set RootID=RootID+1 where ChannelID="&ChannelID&" and RootID=" & tRootID)
		i=i+1
		if i>MoveNum then
			Cl.Execute("Update Cl_Class set PrevID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
			Cl.Execute("Update Cl_Class set NextID=" & rsOrder("ClassID") & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
			exit do
		end if
		rsOrder.movenext
	loop
	rsOrder.movenext
	if rsOrder.eof then
		Cl.Execute("Update Cl_Class set PrevID=0 where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	else
		Cl.Execute("Update Cl_Class set NextID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
		Cl.Execute("Update Cl_Class set PrevID=" & rsOrder("ClassID") & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	end if	
	rsOrder.close
	set rsOrder=Nothing
	
	'然后再将当前栏目从最后移到相应位置，包括子栏目
	Cl.Execute("Update Cl_Class set RootID=" & tRootID & " where ChannelID="&ChannelID&" and RootID=" & MaxRootID)
	Cl.SaveAdminLog
	response.Redirect strFileName & "&Action=Order"
end sub

sub DownOrder()
	dim ClassID,sqlOrder,rsOrder,MoveNum,cRootID,tRootID,PrevID,NextID
	ClassID=Cl.ChkClng(request("ClassID"))
	cRootID=Cl.ChkClng(request("cRootID"))
	MoveNum=Cl.ChkClng(request("MoveNum"))
	if ClassID=0 or cRootID=0 or MoveNum=0 then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>参数不足！</li>"
		Exit Sub
	end if
	'得到本栏目的PrevID,NextID
	set rs=Cl.Execute("select PrevID,NextID from Cl_Class where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	PrevID = rs(0) : NextID = rs(1)
	rs.close : set rs=Nothing
	'先修改上一栏目的NextID和下一栏目的PrevID
	if PrevID>0 then
		Cl.Execute "Update Cl_Class set NextID=" & NextID & " where ChannelID="&ChannelID&" and ClassID=" & PrevID
	end if
	if NextID>0 then
		Cl.Execute "Update Cl_Class set PrevID=" & PrevID & " where ChannelID="&ChannelID&" and ClassID=" & NextID
	end if
	dim mrs,MaxRootID
	set mrs=Cl.Execute("select max(rootid) From Cl_Class where ChannelID="&ChannelID&"")
	MaxRootID=mrs(0)+1
	'先将当前栏目移至最后，包括子栏目
	Cl.Execute("Update Cl_Class set RootID=" & MaxRootID & " where ChannelID="&ChannelID&" and RootID=" & cRootID)
	'然后将位于当前栏目以下的栏目的RootID依次减一，范围为要下降的数字
	sqlOrder="select * From Cl_Class where ChannelID="&ChannelID&" and ParentID=0 and RootID>" & cRootID & " order by RootID"
	set rsOrder=server.CreateObject("adodb.recordset")
	OpenConn : rsOrder.open sqlOrder,Conn,1,3
	if rsOrder.bof and rsOrder.eof then
		exit sub        '如果当前栏目已经在最下面，则无需移动
	end if
	i=1
	do while not rsOrder.eof
		tRootID=rsOrder("RootID")       '得到要提升位置的RootID，包括子栏目
		Cl.Execute("Update Cl_Class set RootID=RootID-1 where ChannelID="&ChannelID&" and RootID=" & tRootID)
		i=i+1
		if i>MoveNum then
			Cl.Execute("Update Cl_Class set NextID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
			Cl.Execute("Update Cl_Class set PrevID=" & rsOrder("ClassID") & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
			exit do
		end if
		rsOrder.movenext
	loop
	rsOrder.movenext
	if rsOrder.eof then
		Cl.Execute("Update Cl_Class set NextID=0 where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	else
		Cl.Execute("Update Cl_Class set PrevID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
		Cl.Execute("Update Cl_Class set NextID=" & rsOrder("ClassID") & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	end if	
	rsOrder.close
	set rsOrder=Nothing
	
	'然后再将当前栏目从最后移到相应位置，包括子栏目
	Cl.Execute("Update Cl_Class set RootID=" & tRootID & " where ChannelID="&ChannelID&" and RootID=" & MaxRootID)
	Cl.SaveAdminLog
	response.Redirect strFileName & "&Action=Order"
end sub

sub UpOrderN()
	dim sqlOrder,rsOrder,MoveNum,ClassID,i
	dim ParentID,OrderID,ParentPath,Child,PrevID,NextID
	ClassID=Cl.ChkClng(request("ClassID"))
	MoveNum=Cl.ChkClng(request("MoveNum"))
	if ClassID=0 then
		FoundErr=true
		ErrMsg=ErrMsg & "<br /><li>错误参数！</li>"
	end if
	if MoveNum=0 then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>请选择要提升的数字！</li>"
	end if
	if FoundErr=True then exit sub

	dim oldorders,ii,trs,tOrderID
	'要移动的栏目信息
	set rs=Cl.Execute("select ParentID,OrderID,ParentPath,child,PrevID,NextID From Cl_Class where ChannelID="&ChannelID&" and ClassID="&ClassID)
	ParentID	=rs(0) : OrderID		=rs(1)
	ParentPath	=rs(2) & "," & ClassID
	child		=rs(3) : PrevID		=rs(4)
	NextID		=rs(5)
	rs.close
	set rs=Nothing
	if child>0 then
		set rs=Cl.Execute("select count(*) From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '%"&ParentPath&"%'")
		oldorders=rs(0)
		rs.close
		set rs=Nothing
	else
		oldorders=0
	end if
	'先修改上一栏目的NextID和下一栏目的PrevID
	if PrevID>0 then
		Cl.Execute "Update Cl_Class set NextID=" & NextID & " where ChannelID="&ChannelID&" and ClassID=" & PrevID
	end if
	if NextID>0 then
		Cl.Execute "Update Cl_Class set PrevID=" & PrevID & " where ChannelID="&ChannelID&" and ClassID=" & NextID
	end if
	
	'和该栏目同级且排序在其之上的栏目------更新其排序，范围为要提升的数字
	sql="select ClassID,OrderID,child,ParentPath,PrevID,NextID From Cl_Class where ChannelID="&ChannelID&" and ParentID="&ParentID&" and OrderID<"&OrderID&" order by OrderID desc"
	set rs=server.CreateObject("adodb.recordset")
	OpenConn : rs.open sql,Conn,1,3
	i=1
	do while not rs.eof
		tOrderID=rs(1)
		Cl.Execute("Update Cl_Class set OrderID="&tOrderID+oldorders+i&" where ChannelID="&ChannelID&" and ClassID="&rs(0))
		if rs(2)>0 then
			ii=i+1
			set trs=Cl.Execute("select ClassID,OrderID From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '%"&rs(3)&","&rs(0)&"%' order by OrderID")
			if not (trs.eof and trs.bof) then
				do while not trs.eof
					Cl.Execute("Update Cl_Class set OrderID="&tOrderID+oldorders+ii&" where ChannelID="&ChannelID&" and ClassID="&trs(0))
					ii=ii+1
					trs.movenext
				loop
			end if
			trs.close
			set trs=Nothing
		end if
		i=i+1
		if i>MoveNum then
			Cl.Execute("Update Cl_Class set PrevID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & rs(0))
			Cl.Execute("Update Cl_Class set NextID=" & rs(0) & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)		
			exit do
		end if
		rs.movenext
	loop
	rs.movenext
	if rs.eof then
		Cl.Execute("Update Cl_Class set PrevID=0 where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	else
		Cl.Execute("Update Cl_Class set NextID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & rs(0))
		Cl.Execute("Update Cl_Class set PrevID=" & rs(0) & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	end if	
	rs.close
	set rs=Nothing
	
	'更新所要排序的栏目的序号
	Cl.Execute("Update Cl_Class set OrderID="&tOrderID&" where ChannelID="&ChannelID&" and ClassID="&ClassID)
	'如果有下属栏目，则更新其下属栏目排序
	if child>0 then
		i=1
		set rs=Cl.Execute("select ClassID From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '%"&ParentPath&"%' order by OrderID")
		do while not rs.eof
			Cl.Execute("Update Cl_Class set OrderID="&tOrderID+i&" where ChannelID="&ChannelID&" and ClassID="&rs(0))
			i=i+1
			rs.movenext
		loop
		rs.close
		set rs=Nothing
	end if
	Cl.SaveAdminLog
	response.Redirect strFileName & "&Action=OrderN"
end sub

sub DownOrderN()
	dim sqlOrder,rsOrder,MoveNum,ClassID,i
	dim ParentID,OrderID,ParentPath,Child,PrevID,NextID
	ClassID=Trim(request("ClassID"))
	MoveNum=Trim(request("MoveNum"))
	if ClassID="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br /><li>错误参数！</li>"
		exit sub
	else
		ClassID=Cint(ClassID)
	end if
	if MoveNum="" then
		FoundErr=true
		ErrMsg=ErrMsg & "<br /><li>错误参数！</li>"
		exit sub
	else
		MoveNum=Cint(MoveNum)
		if MoveNum=0 then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>请选择要下降的数字！</li>"
			exit sub
		end if
	end if

	dim oldorders,ii,trs,tOrderID
	'要移动的栏目信息
	set rs=Cl.Execute("select ParentID,OrderID,ParentPath,child,PrevID,NextID From Cl_Class where ChannelID="&ChannelID&" and ClassID="&ClassID)
	ParentID=rs(0)
	OrderID=rs(1)
	ParentPath=rs(2) & "," & ClassID
	child=rs(3)
	PrevID=rs(4)
	NextID=rs(5)
	rs.close
	set rs=Nothing

	'先修改上一栏目的NextID和下一栏目的PrevID
	if PrevID>0 then
		Cl.Execute "Update Cl_Class set NextID=" & NextID & " where ChannelID="&ChannelID&" and ClassID=" & PrevID
	end if
	if NextID>0 then
		Cl.Execute "Update Cl_Class set PrevID=" & PrevID & " where ChannelID="&ChannelID&" and ClassID=" & NextID
	end if
	'和该栏目同级且排序在其之下的栏目------更新其排序，范围为要下降的数字
	sql="select ClassID,OrderID,child,ParentPath,PrevID,NextID From Cl_Class where ChannelID="&ChannelID&" and ParentID="&ParentID&" and OrderID>"&OrderID&" order by OrderID"
	set rs=server.CreateObject("adodb.recordset")
	OpenConn : rs.open sql,Conn,1,3
	i=0      '同级栏目
	ii=0     '同级栏目和子栏目
	do while not rs.eof
		Cl.Execute("Update Cl_Class set OrderID="&OrderID+ii&" where ChannelID="&ChannelID&" and ClassID="&rs(0))
		if rs(2)>0 then
			set trs=Cl.Execute("select ClassID,OrderID From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '%"&rs(3)&","&rs(0)&"%' order by OrderID")
			if not (trs.eof and trs.bof) then
				do while not trs.eof
					ii=ii+1
					Cl.Execute("Update Cl_Class set OrderID="&OrderID+ii&" where ChannelID="&ChannelID&" and ClassID="&trs(0))
					trs.movenext
				loop
			end if
			trs.close
			set trs=Nothing
		end if
		ii=ii+1
		i=i+1
		if i>=MoveNum then
			Cl.Execute("Update Cl_Class set NextID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & rs(0))
			Cl.Execute("Update Cl_Class set PrevID=" & rs(0) & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)		
			exit do
		end if
		rs.movenext
	loop
	rs.movenext
	if rs.eof then
		Cl.Execute("Update Cl_Class set NextID=0 where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	else
		Cl.Execute("Update Cl_Class set PrevID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & rs(0))
		Cl.Execute("Update Cl_Class set NextID=" & rs(0) & " where ChannelID="&ChannelID&" and ClassID=" & ClassID)
	end if	
	rs.close
	set rs=Nothing
	
	'更新所要排序的栏目的序号
	Cl.Execute("Update Cl_Class set OrderID="&OrderID+ii&" where ChannelID="&ChannelID&" and ClassID="&ClassID)
	'如果有下属栏目，则更新其下属栏目排序
	if child>0 then
		i=1
		set rs=Cl.Execute("select ClassID From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '%"&ParentPath&"%' order by OrderID")
		do while not rs.eof
			Cl.Execute("Update Cl_Class set OrderID="&OrderID+ii+i&" where ChannelID="&ChannelID&" and ClassID="&rs(0))
			i=i+1
			rs.movenext
		loop
		rs.close
		set rs=Nothing
	end if
	Cl.SaveAdminLog
	response.Redirect strFileName & "&Action=OrderN"
end sub

sub SaveReset()
	dim SuccessMsg,iCount,PrevID,NextID
	sql="select ClassID From Cl_Class where ChannelID="&ChannelID&" order by RootID,OrderID"
	set rs=server.CreateObject("adodb.recordset")
	OpenConn : rs.open sql,Conn,1,1
	iCount=rs.recordcount
	i=1
	PrevID=0
	do while not rs.eof
		rs.movenext
		if rs.eof then
			NextID=0
		else
			NextID=rs(0)
		end if
		rs.moveprevious
		Cl.Execute("Update Cl_Class set RootID=" & i & ",OrderID=0,ParentID=0,Child=0,ParentPath='0',Depth=0,PrevID=" & PrevID & ",NextID=" & NextID & " where ChannelID="&ChannelID&" and ClassID=" & rs(0))
		PrevID=rs(0)
		i=i+1
		rs.movenext
	loop
	rs.close
	set rs=Nothing	
	Cl.SaveAdminLog
	SuccessMsg="复位成功！请返回 <a href='"&strFileName&"'>栏目管理首页</a> 做栏目的归属设置。"
	Response.Write Cl.ShowSuc(SuccessMsg)
end sub

sub SaveUnite()
	dim ClassID,TargetClassID,ParentPath,iParentPath,Depth,iParentID,Child,PrevID,NextID
	dim rs,trs,SuccessMsg
	ClassID=Trim(request("ClassID"))
	TargetClassID=Trim(request("TargetClassID"))
	if ClassID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>请指定要合并的栏目！</li>"
	else
		ClassID=CLng(ClassID)
	end if
	if TargetClassID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>请指定目标栏目！</li>"
	else
		TargetClassID=CLng(TargetClassID)
	end if
	if ClassID=TargetClassID then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>请不要在相同栏目内进行操作</li>"
	end if
	if FoundErr=True then exit sub

	'判断目标栏目是否有子栏目，如果有，则报错。
	set rs=Cl.Execute("select Child from Cl_Class where ChannelID="&ChannelID&" and ClassID=" & TargetClassID)
	if rs.bof and rs.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br /><li>目标栏目不存在，可能已经被删除！</li>"
	else
		if rs(0)>0 then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>目标栏目中含有子栏目，不能合并！</li>"
		end if
	end if
	if FoundErr=True then exit sub

	'得到当前栏目信息
	set rs=Cl.Execute("select ClassID,ParentID,ParentPath,PrevID,NextID,Depth from Cl_Class where ChannelID="&ChannelID&" and ClassID="&ClassID)
	iParentID=rs(1)
	Depth=rs(5)
	if iParentID=0 then
		ParentPath=rs(0)
	else
		ParentPath=rs(2) & "," & rs(0)
	end if
	iParentPath=rs(0)
	PrevID=rs(3)
	NextID=rs(4)
	
	'判断是否是合并到其下属栏目中
	set rs=Cl.Execute("select ClassID from Cl_Class where ChannelID="&ChannelID&" and ClassID="&TargetClassID&" and ParentPath like '"&ParentPath&"%'")
	if not (rs.eof and rs.bof) then
		FoundErr=true
		ErrMsg=ErrMsg & "<br /><li>不能将一个栏目合并到其下属子栏目中</li>"
		exit sub
	end if
	
	'得到当前栏目的下属栏目ID
	set rs=Cl.Execute("select ClassID from Cl_Class where ChannelID="&ChannelID&" and ParentPath like '"&ParentPath&"%'")
	i=0
	if not (rs.eof and rs.bof) then
		do while not rs.eof
			iParentPath=iParentPath & "," & rs(0)
			i=i+1
			rs.movenext
		loop
	end if
	if i>0 then
		ParentPath=iParentPath
	else
		ParentPath=ClassID
	end if
	
	'先修改上一栏目的NextID和下一栏目的PrevID
	if PrevID>0 then
		Cl.Execute "Update Cl_Class set NextID=" & NextID & " where ChannelID="&ChannelID&" and ClassID=" & PrevID
	end if
	if NextID>0 then
		Cl.Execute "Update Cl_Class set PrevID=" & PrevID & " where ChannelID="&ChannelID&" and ClassID=" & NextID
	end if
	
	'更新数据及评论所属栏目
	Select Case Clng(Cl.Channel_Setting(20))
	Case 1
	Cl.Execute("Update Cl_Article set ClassID="&TargetClassID&" where ClassID in ("&ParentPath&")")
	Case 2
	Cl.Execute("Update Cl_Soft set ClassID="&TargetClassID&" where ClassID in ("&ParentPath&")")
	Case 3
	Cl.Execute("Update Cl_Photo set ClassID="&TargetClassID&" where ClassID in ("&ParentPath&")")
	Case 4
	Cl.Execute("Update Cl_Movie set ClassID="&TargetClassID&" where ClassID in ("&ParentPath&")")
	Case 5
	Cl.Execute("Update Cl_Produte set ClassID="&TargetClassID&" where ClassID in ("&ParentPath&")")
	Case 6
	Cl.Execute("Update Cl_ToPic set ClassID="&TargetClassID&" where ClassID in ("&ParentPath&")")
	End Select
	Cl.Execute("Update Cl_Comment set ClassID="&TargetClassID&" where ChannelID="&ChannelID&" and ClassID in ("&ParentPath&")")
	
	'删除被合并栏目及其下属栏目
	Cl.Execute("delete * from Cl_Class where ChannelID="&ChannelID&" and ClassID in ("&ParentPath&")")
	
	'更新其原来所属栏目的子栏目数，排序相当于剪枝而不需考虑
	if Depth>0 then
		Cl.Execute("Update Cl_Class set Child=Child-1 where ChannelID="&ChannelID&" and ClassID="&iParentID)
	end if
	set rs=Nothing
	set trs=Nothing
	Cl.SaveAdminLog
	SuccessMsg="栏目合并成功！已经将被合并栏目及其下属子栏目的所有数据转入目标栏目中。<br /><br />同时删除了被合并的栏目及其子栏目。"
	Response.Write Cl.ShowSuc(SuccessMsg)
end sub

sub UpDateClassData()
	Server.ScriptTimeOut=9999
	dim rs,arrChildID,trs,TempClassDir,TempPath,ParentDir,sOuter
	dim arrParentID(20),arrParentDir(20),arrPrevID(20),arrNextID(20)
	Dim sClassID,Childs
	set rs=server.createobject("adodb.recordset")
	OpenConn : rs.open "select * from Cl_Class where ChannelID=" & ChannelID & " order by RootID Asc,OrderID Asc",Conn,1,3
	if rs.bof and rs.eof then
		rs.Close:Set rs=Nothing
		Exit Sub
	end if
	for i=0 to 19
		arrParentID(i)=0
		arrParentDir(i)=""
		arrPrevID(i)=0
		arrNextID(i)=0
	next
	do while not rs.eof
		sClassID=rs("ClassID")
		arrParentID(rs("Depth"))=sClassID
		arrParentDir(rs("Depth"))=rs("ClassDir")
		if rs("ParentID")=0 then
			rs("ParentPath")="0"
			rs("ParentDir")="/"
		else
			ParentPath="0"
			ParentDir="/"
			for i=0 to rs("Depth")-1
				ParentPath=ParentPath & "," & arrParentID(i)
				ParentDir=ParentDir & arrParentDir(i) & "/"
			next
			rs("ParentPath")=ParentPath
			rs("ParentDir")=ParentDir
		end if
		if rs("PrevID")<>0 then
			rs("PrevID")=arrPrevID(rs("Depth"))
		end if
		rs("NextID")=0
		if arrNextID(rs("Depth"))>0 then
			Cl.Execute("update Cl_Class set NextID=" & sClassID & " where ClassID=" & arrPrevID(rs("Depth")) & " and ChannelID="&ChannelID&"")
		end if
		arrPrevID(rs("Depth"))=sClassID
		arrNextID(rs("Depth"))=rs("NextID")
		sOuter=rs("IsOuter")
		if ISNull(sOuter) or Not IsNumeric(sOuter) or sOuter<>1 then
			rs("IsOuter")=0
		else
			rs("IsOuter")=1
		end if
		rs.update
		rs.movenext
	loop
	rs.movefirst
	do while not rs.eof
		Set tRs=Cl.Execute("Select Count(ClassID) from Cl_Class Where ChannelID=" & ChannelID & " and ParentID=" & Rs("ClassID") & "")
		Childs=tRs(0)
		if Not IsNumeric(Childs) then Childs=0
		Rs("Child")=Childs
		Set tRs=nothing
		if Childs=0 then
			rs("arrChildID")=rs("ClassID")
		else
			arrChildID=rs("ClassID")
			set trs=Cl.Execute("select ClassID from Cl_Class where ChannelID=" & ChannelID & " and (ParentID=" & rs("ClassID") & " or ParentPath like '%" & rs("ParentPath") & "," & rs("ClassID") & ",%')")
			do while not trs.eof
				arrChildID=arrChildID & "," & trs(0)
				trs.movenext
			loop
			set trs=Nothing
			rs("arrChildID")=arrChildID
		end if
		rs.update
		rs.movenext
	loop
	rs.Close:Set rs=Nothing
end sub

Sub RefreshClassJs()
	CreateClassJs(ChannelID)
	Response.Write Cl.ShowSuc("恭喜你，JS刷新成功！返回 <a href='"&strFileName&"'>栏目管理首页</a> 。")
End Sub

Sub Batch()
%>
<script language="JavaScript" type="text/javascript">
function SelectAll(){
  for(var i=0;i<document.form1.ClassID.length;i++){
    document.form1.ClassID.options[i].selected=true;}
}
function UnSelectAll(){
  for(var i=0;i<document.form1.ClassID.length;i++){
    document.form1.ClassID.options[i].selected=false;}
}
</script>
<form name="form1" method="post" action="<%=strFileName%>" onsubmit="return check()">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <tr class="title"> 
      <td height="22" colspan="2" align="center"><strong>批 量 设 置 栏 目</strong></td>
    </tr>
    <tr class="tdbg">
      <td width="210" align="center"><font color="red">提示：</font>可以按住“Shift”<br />或“Ctrl”键进行多个栏目的选择<br /><select name="ClassID" size="2" multiple style="height:300px;width:200px;">
          <%=ShowClass_Option(ChannelID,0,0,3)%> 
        </select><br /><input type="button" name="Submit" value="  选定所有栏目  " onclick="SelectAll()"><br /><input type="button" name="Submit" value="取消选定所有栏目" onclick="UnSelectAll()"></td>
      <td>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <tr class="tdbg">
      <td width="30" align="center"><input type="checkbox" name="MIsElite" value="Yes"></td> 
      <td align="right"><strong>是否设为推荐栏目：</strong></td>
      <td>
		<input name="IsElite" type="radio" value="Yes" checked> 是&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="IsElite" value="No"> 否
	  <br /><font color="#0000ff">说明：推荐栏目将在首页及此栏目的父栏目上显示列表</font></td>
    </tr>
    <tr class="tdbg">
      <td width="30" align="center"><input type="checkbox" name="MShowOnTop" value="Yes"></td> 
      <td align="right"><strong>是否顶部导航显示：</strong></td>
      <td>
		<input name="ShowOnTop" type="radio" value="Yes" checked> 是&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="ShowOnTop" value="No"> 否</td>
    </tr>

    <tr class="tdbg">
      <td width="30" align="center"><input type="checkbox" name="MBrowsePurview" value="Yes"></td>
      <td width="150" align="right"><strong>栏目浏览权限设置：</strong></td>
      <td>
		<input name="BrowsePurview" type="radio" value="0" onclick="document.getElementById('VipUser').style.display='none';"> 开放栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目任何人都可浏览或下载，包括游客</font><br />
		<input name="BrowsePurview" type="radio" value="1" onclick="document.getElementById('VipUser').style.display='none';"> 限制栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目只有相应权限的用户能浏览或下载</font><br />
		<input name="BrowsePurview" type="radio" value="2" onclick="document.getElementById('VipUser').style.display='';"> 认证栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目只有认证会员或管理员能浏览或下载</font><br />
		<input name="BrowsePurview" type="radio" value="3" onclick="document.getElementById('VipUser').style.display='none';"> 禁用栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目任何人都不能浏览或下载</font>
		</td>
    </tr>
   <tr class="tdbg" style="display:none;" id="VipUser">
      <td width="30" align="center">&nbsp;</td>
      <td width="150" align="right"><strong>栏目认证用户设置：</strong></td>
      <td><textarea name="VipUser" cols="42" rows="4"></textarea><br /> <font color="#ff0033">注意：每个认证用户用回车分开。</font></td>
    </tr>
    <tr class="tdbg">
      <td width="30" align="center"><input type="checkbox" name="MDisabledAdd" value="Yes"></td>
      <td align="right"><strong>是否禁止录入资料：</strong></td>
      <td>
		<input name="DisabledAdd" type="radio" value="0" checked> 允许&nbsp;&nbsp;&nbsp;&nbsp; 
		<input name="DisabledAdd" type="radio" value="1"> 禁止</td>
    </tr>
    <tr class="tdbg">
      <td width="30" align="center"><input type="checkbox" name="MAddIsChk" value="Yes"></td>
      <td align="right"><strong>录入资料是否审核：</strong></td>
      <td>
		<input name="AddIsChk" type="radio" value="Yes" checked> 审核&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="AddIsChk" value="No"> 不审核
	  <br /><font color="#0000ff">说明：如果选择审核，那么用户添加资料后需要管理员审核后方在前台显示。</font></td>
    </tr>
    <tr class="tdbg"> 
      <td width="30" align="center"><input type="checkbox" name="MAddPoint" value="Yes"></td>
      <td width="150" align="right"><strong>录入资料<%=Cl.Web_Setting(28)%>设置：</strong></td>
      <td>在此栏目录入资料可得到：<input name="AddPoint" type="text" id="AddPoint" value="0" size="10" maxlength="8"> <%=Cl.Web_Setting(29)%><%=Cl.Web_Setting(28)%><br /><font color="#0000ff">说明：如果为0时，则不添加<%=Cl.Web_Setting(28)%>！</font></td>
    </tr>
    <tr class="tdbg"> 
      <td width="30" align="center"><input type="checkbox" name="MMaxLimit" value="Yes"></td>
      <td width="150" align="right"><strong>录入资料最大限制：</strong></td>
      <td>在此栏目添加资料最大限制为： <input name="MaxLimit" type="text" id="MaxLimit" value="0" size="10" maxlength="10"> 字节<br /><font color="#0000ff">说明：如果为0时，则不限制大小！</font></td>
    </tr>
    <tr class="tdbg">
      <td width="30" align="center"><input type="checkbox" name="MCommentIsChk" value="Yes"></td> 
      <td align="right"><strong>发表评论是否审核：</strong></td>
      <td>
	  	<input name="CommentIsChk" type="radio" value="Yes" checked> 审核&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="CommentIsChk" value="No"> 不审核
	  <br /><font color="#0000ff">说明：如果选择审核，那么用户发表评论后需要管理员审核后方在前台显示。</font></td>
    </tr>
    <tr class="tdbg">
      <td width="30" align="center"><input type="checkbox" name="MCommentGroup" value="Yes"></td> 
      <td width="150" align="right"><strong>允许评论的用户组：</strong></td>
      <td>
		<input name="CommentGroup" type="text" id="CommentGroup" value="5" size="50" onclick="SelectUserGroup('CommentGroup');" Readonly>
		</td>
    </tr>
    <tr class="tdbg">
      <td width="30" align="center"><input type="checkbox" name="MStyle" value="Yes"></td> 
      <td width="150" align="right"><strong>栏目风格模版选择：</strong></td>
      <td>模板：<select name="StyleID">
		<option value="-1" selected>使用频道模版</option>
		<%
		Dim rs_s, sTempCss, sCssName
		set rs_s = Cl.Execute("Select ID,StyleName from Cl_Style Order by ID")
		do while not rs_s.eof
			response.write "<option value="""&rs_s(0)&""">"&rs_s(1)&"</option>"
			rs_s.MoveNext
		Loop
		Set rs_s = Nothing
		%>
		</select>&nbsp;&nbsp;CSS风格：<select name="CssID">
		<option value="-1" selected>使用频道CSS</option>
		<%
		sTempCss = Split(Cl.CacheData(15,0),"@@@")(0)
		sCssName = Split(sTempCss,"|||")
		for i=0 to ubound(sCssName)-1
			response.write "<option value="""&i&""">"&sCssName(i)&"</option>"
		next%>
		</select></td>
    </tr>
  </table>
		</td>
    </tr>
    <tr class="tdbg"> 
      <td height="40" colspan="2" align="center"><input name="Action" type="hidden" id="Action" value="SaveBatch"> 
        <input name="Submit" type="submit" value=" 执行批处理 "> 
        &nbsp; <input name="Cancel" type="button" id="Cancel" value=" 取 消 " onClick="window.location.href='<%=strFileName%>'"></td>
    </tr>
</table>
</form>
<%
End Sub

Sub SaveBatch()
	Dim TempClassID,sSQL
	TempClassID=Trim(Request("ClassID"))
	if TempClassID="" or Not IsNumeric(Replace(Replace(TempClassID,",","")," ","")) then
		Admin_ShowErr("参数中含有非法ID！")
	end if
	TempClassID=Replace(TempClassID," ","")
	Dim MIsElite,MShowOnTop,MBrowsePurview,MDisabledAdd,MAddIsChk,MAddPoint,MMaxLimit,MCommentIsChk,MCommentGroup,MStyle
	Dim IsElite,ShowOnTop,BrowsePurview,VipUser,DisabledAdd,AddIsChk,AddPoint,MaxLimit,CommentIsChk,CommentGroup,StyleID,CssID
	MIsElite		= Trim(request("MIsElite"))
	MShowOnTop		= Trim(request("MShowOnTop"))
	MBrowsePurview	= Trim(request("MBrowsePurview"))
	MDisabledAdd	= Trim(request("MDisabledAdd"))
	MAddIsChk		= Trim(request("MAddIsChk"))
	MAddPoint		= Trim(request("MAddPoint"))
	MMaxLimit		= Trim(request("MMaxLimit"))
	MCommentIsChk	= Trim(request("MCommentIsChk"))
	MCommentGroup	= Trim(request("MCommentGroup"))
	MStyle			= Trim(request("MStyle"))

	IsElite			= Trim(request("IsElite"))
	ShowOnTop		= Trim(request("ShowOnTop"))
	BrowsePurview	= Cl.ChkClng(request("BrowsePurview"))
	VipUser			= Trim(request("VipUser"))
	DisabledAdd		= Trim(request("DisabledAdd"))
	AddIsChk		= Trim(request("AddIsChk"))
	AddPoint		= Cl.ChkClng(request("AddPoint"))
	MaxLimit		= Cl.ChkClng(request("MaxLimit"))
	CommentIsChk	= Trim(request("CommentIsChk"))
	CommentGroup	= Trim(request("CommentGroup"))
	StyleID			= Cl.ChkClng(request("StyleID"))
	CssID			= Cl.ChkClng(request("CssID"))

	if MIsElite<>"Yes" and MShowOnTop<>"Yes" and MBrowsePurview<>"Yes" and MDisabledAdd<>"Yes" and MAddIsChk<>"Yes" and MAddPoint<>"Yes" and MMaxLimit<>"Yes" and MCommentIsChk<>"Yes" and MCommentGroup<>"Yes" and MStyle<>"Yes" then
		Admin_ShowErr("请正确选择要设置的参数！")
	end if
	if Not IsNull(VipUser) then VipUser	= Replace(VipUser,VbCrlf,"|")
	if IsElite="Yes" then
		IsElite=TrueType
	else
		IsElite=FalseType
	end if
	if ShowOnTop="Yes" then
		ShowOnTop=TrueType
	else
		ShowOnTop=FalseType
	end if
	if CommentIsChk="Yes" then
		CommentIsChk=TrueType
	else
		CommentIsChk=FalseType
	end if
	if AddIsChk="Yes" then
		AddIsChk=TrueType
	else
		AddIsChk=FalseType
	end if
	sSQL="Update Cl_Class Set "
	if MIsElite="Yes" then sSQL=sSQL & " IsElite="&IsElite&","
	if MShowOnTop="Yes" then sSQL=sSQL & " ShowOnTop="&ShowOnTop&","
	if MBrowsePurview="Yes" then sSQL=sSQL & " BrowsePurview="&BrowsePurview&",VipUser='"&VipUser&"',"
	if MDisabledAdd="Yes" then sSQL=sSQL & " DisabledAdd="&DisabledAdd&","
	if MAddIsChk="Yes" then sSQL=sSQL & " AddIsChk="&AddIsChk&","
	if MAddPoint="Yes" then sSQL=sSQL & " AddPoint="&AddPoint&","
	if MMaxLimit="Yes" then sSQL=sSQL & " MaxLimit="&MaxLimit&","
	if MCommentIsChk="Yes" then sSQL=sSQL & " CommentIsChk="&CommentIsChk&","
	if MCommentGroup="Yes" then sSQL=sSQL & " CommentGroup='"&CommentGroup&"',"
	if MStyle="Yes" then sSQL=sSQL & " StyleID="&StyleID&",CssID="&CssID&","
	sSQL=sSQL & ",$$ where ClassID In ("&TempClassID&")"
	sSQL=Replace(sSQL,",,$$","")
	Cl.Execute(sSQL)
	Cl.SaveAdminLog
	Response.Write Cl.ShowSuc("恭喜您，批量设置成功！请返回 <a href='"&strFileName&"'>栏目管理首页</a>")
End Sub

sub Add2()
%>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" Class="border">
<form method="POST" action="<%=strFileName%>">
    <tr class="title"> 
      <td height="22" class="title" colspan=2 align=center><b>批 量 添 加 栏 目</b></td>
    </tr>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>栏目名|英文名：</strong></td>
      <td><font color=red>注：每个栏目名用“回车”分隔，如要加上英文名，请在每个栏目名后面用“|”分隔。<br />英文名只能是英文，不能带空格或“\”、“/”等符号，此项更改后，请重新生成此栏目所有内容。</font>
	  <textarea name="Content" style="width:95%" rows="15"></textarea>
		<br /><a href="javascript:admin_Size(-5,'Content')"><img src="images/minus.gif" unselectable="on" border='0'></a> <a href="javascript:admin_Size(5,'Content')"><img src="images/plus.gif" unselectable="on" border='0'></a>
      </td>
    </tr>
	<!--
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>所属栏目：</strong></td>
      <td><Input type="hidden" name="ParentID" id="ParentID" value="0"><Input type="text" name="ParentIDv" id="ParentIDv" value="0:作为一级栏目" size=45 readonly Onclick="SelectClass('<%=ChannelID%>','ParentID')">&nbsp<Input type="button" Name="selectclassid" Onclick="SelectClass('<%=ChannelID%>','ParentID')" value="选择栏目">
	  </td>
    </tr>
	if IsSQLDataBase=1 then
	-->
	<tr class="tdbg"> 
      <td width="150" align="right"><strong>所属栏目：</strong></td>
      <td> <select name="ParentID">
          <%=ShowClass_Option(ChannelID,ParentID,0,0)%> 
        </select>&nbsp;&nbsp;<font color="#ff0033">注意：不能指定为外部栏目</font></td>
    </tr>
<!--==================================================================-->
    <tr class="tdbg" id="NoOuterClass">
      <td width="150" align="right"><strong>内部栏目参数：</strong></td>
      <td>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
<!--
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>栏目说明：</strong></td>
      <td><textarea name="Readme" cols="42" rows="4" id="Readme"></textarea><br /> <font color="#ff0033">注意：（不支持HTML，不能有回车，说明可为留空。）</font></td>
    </tr>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>栏目图片地址：</strong><br />
        图片会显示在栏目前面。注意图片大小。</td>
      <td><input name="ClassPicUrl" type="text" id="ClassPicUrl" value="" size="50" maxlength="255"> （预留功能）</td>
    </tr>
-->
    <tr class="tdbg">
      <td align="right"><strong>是否设为推荐栏目：</strong></td>
      <td>
		<input name="IsElite" type="radio" value="Yes" checked> 是&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="IsElite" value="No"> 否
	  <br /><font color="#0000ff">说明：推荐栏目将在首页及此栏目的父栏目上显示列表</font></td>
    </tr>
    <tr class="tdbg">
      <td align="right"><strong>是否顶部导航显示：</strong></td>
      <td>
		<input name="ShowOnTop" type="radio" value="Yes" checked> 是&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="ShowOnTop" value="No"> 否</td>
    </tr>
    <tr class="tdbg">
      <td width="150" align="right"><strong>栏目浏览权限设置：</strong></td>
      <td>
		<input name="BrowsePurview" type="radio" value="0" onclick="document.getElementById('VipUser').style.display='none';"> 开放栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目任何人都可浏览或下载，包括游客</font><br />
		<input name="BrowsePurview" type="radio" value="1" onclick="document.getElementById('VipUser').style.display='none';"> 限制栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目只有相应权限的用户能浏览或下载</font><br />
		<input name="BrowsePurview" type="radio" value="2" onclick="document.getElementById('VipUser').style.display='';"> 认证栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目只有认证会员或管理员能浏览或下载</font><br />
		<input name="BrowsePurview" type="radio" value="3" onclick="document.getElementById('VipUser').style.display='none';"> 禁用栏目&nbsp;&nbsp;<font color="#0000ff">说明：此栏目任何人都不能浏览或下载</font>
		</td>
    </tr>
    <tr class="tdbg" style="display:none;" id="VipUser">
      <td width="150" align="right"><strong>栏目认证用户设置：</strong></td>
      <td><textarea name="VipUser" cols="42" rows="4"></textarea><br /> <font color="#ff0033">注意：每个认证用户用回车分开。</font></td>
    </tr>
    <tr class="tdbg">
      <td align="right"><strong>是否禁止录入资料：</strong></td>
      <td>
		<input name="DisabledAdd" type="radio" value="0" checked> 允许&nbsp;&nbsp;&nbsp;&nbsp; 
		<input name="DisabledAdd" type="radio" value="1"> 禁止</td>
    </tr>
    <tr class="tdbg">
      <td align="right"><strong>录入资料是否审核：</strong></td>
      <td>
		<input name="AddIsChk" type="radio" value="Yes" checked> 审核&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="AddIsChk" value="No"> 不审核
	  <br /><font color="#0000ff">说明：如果选择审核，那么用户添加资料后需要管理员审核后方在前台显示。</font></td>
    </tr>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>录入资料<%=Cl.Web_Setting(28)%>设置：</strong></td>
      <td>在此栏目录入资料可得到：<input name="AddPoint" type="text" id="AddPoint" value="0" size="10" maxlength="8"> <%=Cl.Web_Setting(29)%><%=Cl.Web_Setting(28)%><br /><font color="#0000ff">说明：如果为0时，则不添加<%=Cl.Web_Setting(28)%>！</font></td>
    </tr>
    <tr class="tdbg"> 
      <td width="150" align="right"><strong>录入资料最大限制：</strong></td>
      <td>在此栏目添加资料最大限制为： <input name="MaxLimit" type="text" id="MaxLimit" value="0" size="10" maxlength="10"> 字节<br /><font color="#0000ff">说明：如果为0时，则不限制大小！</font></td>
    </tr>
    <tr class="tdbg">
      <td align="right"><strong>发表评论是否审核：</strong></td>
      <td>
		<input name="CommentIsChk" type="radio" value="Yes" checked> 审核&nbsp;&nbsp;&nbsp;&nbsp; 
		<input type="radio" name="CommentIsChk" value="No"> 不审核
	  <br /><font color="#0000ff">说明：如果选择审核，那么用户发表评论后需要管理员审核后方在前台显示。</font></td>
    </tr>
    <tr class="tdbg">
      <td width="150" align="right"><strong>允许评论的用户组：</strong></td>
      <td>
		<input name="CommentGroup" type="text" id="CommentGroup" value="5" size="50" onclick="SelectUserGroup('CommentGroup');" Readonly>
		</td>
    </tr>

    <tr class="tdbg"> 
      <td width="150" align="right"><strong>栏目风格模版选择：</strong></td>
      <td>模板：<select name="StyleID">
		<option value="-1" selected>使用频道模版</option>
		<%
		Dim rs_s, sTempCss, sCssName
		set rs_s = Cl.Execute("Select ID,StyleName from Cl_Style Order by ID")
		do while not rs_s.eof
			response.write "<option value="""&rs_s(0)&""">"&rs_s(1)&"</option>"
			rs_s.MoveNext
		Loop
		Set rs_s = Nothing
		%>
		</select>&nbsp;&nbsp;CSS风格：<select name="CssID">
		<option value="-1" selected>使用频道CSS</option>
		<%
		sTempCss = Split(Cl.CacheData(15,0),"@@@")(0)
		sCssName = Split(sTempCss,"|||")
		for i=0 to ubound(sCssName)-1
			response.write "<option value="""&i&""">"&sCssName(i)&"</option>"
		next%>
		</select></td>
    </tr>
  </table>
		</td>
    </tr>
    <tr class="tdbg"> 
      <td height="40" colspan="2" align="center"><input name="Action" type="hidden" id="Action" value="SaveAdd2"> 
        <input name="Submit" type="submit" value=" 批量添加 "> 
        &nbsp; <input name="Cancel" type="button" id="Cancel" value=" 取 消 " onClick="window.location.href='<%=strFileName%>'"></td>
    </tr>
</form>
  </table>
<script language="JavaScript" type="text/JavaScript">
function check()
{
  if (document.form1.ClassName.value=="")
  {
    alert("栏目名称不能为空！");
	document.form1.ClassName.focus();
	return false;
  }
}
</script>
<%
end sub

sub SaveAdd2()
	dim ClassID,ClassName,ClassDir,ParentDir,IsElite,ShowOnTop,Readme,ClassPicUrl,PrevOrderID
	dim trs,CommentGroup,CommentIsChk,AddIsChk,AddPoint,MaxLimit
	dim RootID,ParentDepth,ParentPath,ParentStr,ParentName,MaxClassID,MaxRootID
	dim PrevID,NextID,Child
	Dim IsOuter,LinkUrl,StyleID,CssID,DisabledAdd,VipUser
	Dim TData
	TData			= Trim(request.form("Content"))
	'ClassName		= Trim(request("ClassName"))
	'ClassDir		= Trim(request("ClassDir"))
	IsElite			= Trim(request("IsElite"))
	ShowOnTop		= Trim(request("ShowOnTop"))
	CommentIsChk	= Trim(request("CommentIsChk"))
	AddIsChk		= Trim(request("AddIsChk"))
	Readme			= Trim(request("Readme"))
	'ClassPicUrl		= Trim(request("ClassPicUrl"))
	BrowsePurview	= Cl.ChkClng(request("BrowsePurview"))
	CommentGroup	= Trim(request("CommentGroup"))
	AddPoint		= Cl.ChkClng(request("AddPoint"))
	MaxLimit		= Cl.ChkClng(request("MaxLimit"))
	'IsOuter			= Cl.ChkClng(request("IsOuter"))
	'LinkUrl			= Trim(request("LinkUrl"))
	StyleID			= Cl.ChkClng(request("StyleID"))
	CssID			= Cl.ChkClng(request("CssID"))
	DisabledAdd		= Cl.ChkClng(request("DisabledAdd"))
	VipUser			= Trim(request("VipUser"))
	if Not IsNull(VipUser) then VipUser	= Replace(VipUser,VbCrlf,"|")
	if TData="" then
		Admin_ShowErr("<br /><li>栏目名称不能为空！</li>")
	end if
	set rs = Cl.Execute("select Max(ClassID) From Cl_Class")
	MaxClassID=rs(0)
	if isnull(MaxClassID) then
		MaxClassID=0
	end if
	rs.close
	ClassID=MaxClassID+1
	set rs=Cl.Execute("select max(rootid) From Cl_Class where ChannelID="&ChannelID&"")
	MaxRootID=rs(0)
	if isnull(MaxRootID) then
		MaxRootID=0
	end if
	rs.close
	RootID=MaxRootID
	if ParentID>0 then
		sql="select * From Cl_Class where ChannelID="&ChannelID&" and ClassID=" & ParentID & ""
		OpenConn : rs.open sql,Conn,1,1
		if rs.bof and rs.eof then
			FoundErr=True
			ErrMsg=ErrMsg & "<br /><li>所属栏目已经被删除！</li>"
		else
			if rs("IsOuter")=1 then
				FoundErr=True
				ErrMsg=ErrMsg & "<br /><li>不能在外部栏目内添加内部栏目！</li>"
			end if
		end if
		if FoundErr=True then
			rs.close : set rs=Nothing
			Exit Sub
		else	
			RootID=rs("RootID")
			ParentName=rs("ClassName")
			ParentDepth=rs("Depth")
			ParentPath=rs("ParentPath")
			Child=rs("Child")
			ParentPath=ParentPath & "," & ParentID     '得到此栏目的父级栏目路径
			ParentDir=rs("ParentDir") & rs("ClassDir") & "/"      '得到此栏目的父级栏目目录
			PrevOrderID=rs("OrderID")
			if Child>0 then
				dim rsPrevOrderID
				'得到与本栏目同级的最后一个栏目的OrderID
				set rsPrevOrderID=Cl.Execute("select Max(OrderID) From Cl_Class where ChannelID="&ChannelID&" and ParentID=" & ParentID)
				PrevOrderID=rsPrevOrderID(0)
				set trs=Cl.Execute("select ClassID from Cl_Class where ChannelID="&ChannelID&" and ParentID=" & ParentID & " and OrderID=" & PrevOrderID)
				PrevID=trs(0)
				'得到同一父栏目但比本栏目级数大的子栏目的最大OrderID，如果比前一个值大，则改用这个值。
				set rsPrevOrderID=Cl.Execute("select Max(OrderID) From Cl_Class where ChannelID="&ChannelID&" and ParentPath like '" & ParentPath & ",%'")
				if not(rsPrevOrderID.bof and rsPrevOrderID.eof) then
					if not IsNull(rsPrevOrderID(0))  then
				 		if rsPrevOrderID(0)>PrevOrderID then
							PrevOrderID=rsPrevOrderID(0)
						end if
					end if
				end if
			else
				PrevID=0
			end if
		end if
		rs.close
	else
		if MaxRootID>0 then
			set trs=Cl.Execute("select ClassID from Cl_Class where ChannelID="&ChannelID&" and RootID=" & MaxRootID & " and Depth=0")
			PrevID=trs(0)
			trs.close
		else
			PrevID=0
		end if
		PrevOrderID=0
		ParentPath="0"
		ParentDir="/"
		RootID=RootID+1
	end if

	if IsElite="Yes" then
		IsElite=True
	else
		IsElite=False
	end if
	if ShowOnTop="Yes" then
		ShowOnTop=True
	else
		ShowOnTop=False
	end if
	if CommentIsChk="Yes" then
		CommentIsChk=True
	else
		CommentIsChk=False
	end if
	if AddIsChk="Yes" then
		AddIsChk=True
	else
		AddIsChk=False
	end if
	if Not IsNumeric(AddPoint) then AddPoint=0
	if Not IsNumeric(MaxLimit) then MaxLimit=0
	'if Not IsNumeric(BrowsePurview) then BrowsePurview=5
	'if Not IsNumeric(CommentGroup) then CommentGroup=5
'====================================================
	TData=Split(TData,vbcrlf)
	for i=0 to Ubound(TData)
		if Instr(TData(i),"|")>0 then
			TData(i)=Split(TData(i),"|")
			ClassName=Trim(TData(i)(0))
			ClassDir=TData(i)(1)
		else
			ClassName=Trim(TData(i))
			ClassDir="Class"&ClassID
		end if
		if ClassName<>"" then '判断栏目名是否为空
			sql="Select * From Cl_Class where ChannelID="&ChannelID&" and ParentID=" & ParentID & " And (ClassName='" & ClassName & "' or ClassDir='"&ClassDir&"')"
			set Rs=Cl.Execute(sql)
			if not(rs.bof and rs.eof) then
				FoundErr=True
				if ParentID=0 then
				ErrMsg=ErrMsg & "<br /><li>已经存在一级栏目名：" & ClassName & " 或者已经存在目录：" & ClassDir & "。</li>"
				else
				ErrMsg=ErrMsg & "<br /><li>“" & ParentName & "”中已经存在子栏目“" & ClassName & "” 或者已经存在目录：" & ClassDir & "。</li>"
				end if
				set rs=Nothing
				exit sub
			end if
			set rs=Nothing

			set Rs=server.CreateObject("adodb.recordset")
			OpenConn : rs.open "Select top 1 * From Cl_Class",Conn,1,3
			rs.addnew
			rs("ClassID")		= ClassID
			rs("ChannelID")		= ChannelID
   			rs("ClassName")		= ClassName
			rs("ParentID")		= ParentID
			rs("ParentPath")	= ParentPath
			rs("ClassDir")		= ClassDir
			rs("ParentDir")		= ParentDir
			if ParentID>0 then
				rs("Depth")		= ParentDepth+1
			else
				rs("Depth")		= 0
			end if
			rs("RootID")		= RootID
			rs("Child")			= 0
			rs("arrChildID")	= ClassID
			rs("PrevID")		= PrevID
			rs("NextID")		= 0
			rs("OrderID")		= PrevOrderID
			rs("Readme")		= ""'Readme
			'rs("ClassPicUrl")	= ClassPicUrl
			rs("BrowsePurview")	= BrowsePurview
			rs("AddPoint")		= Clng(AddPoint)
			rs("CommentGroup")	= CommentGroup
			rs("IsElite")		= IsElite
			rs("ShowOnTop")		= ShowOnTop
			rs("CommentIsChk")	= CommentIsChk
			rs("AddIsChk")		= AddIsChk
			rs("MaxLimit")		= Clng(MaxLimit)
			rs("IsOuter")		= 0
			rs("LinkUrl")		= ""
			rs("StyleID")		= StyleID
			rs("CssID")			= CssID
			rs("DisabledAdd")	= DisabledAdd
			rs("VipUser")		= VipUser
			rs.update
			rs.Close:set rs=Nothing
	
			'更新与本栏目同一父栏目的上一个栏目的“NextID”字段值
			if PrevID>0 then
				Cl.Execute("Update Cl_Class set NextID=" & ClassID & " where ChannelID="&ChannelID&" and ClassID=" & PrevID)
			end if
	
			if ParentID>0 then
				'更新其父类的子栏目数
				Cl.Execute("Update Cl_Class set child=child+1 where ChannelID="&ChannelID&" and ClassID="&ParentID)
				'更新其父类以上栏目的“arrChildID”
				Dim rsParentID
				Set rsParentID=server.CreateObject("Adodb.recordset")
				OpenConn : rsParentID.open "Select ClassID,arrChildID From Cl_Class where ChannelID="&ChannelID&" and ClassID in ("&ParentPath&")",conn,1,3
				do While not rsParentID.Eof
				rsParentID("arrChildID")=""&rsParentID(1)&","&ClassID&""
				rsParentID.UpDate
				rsParentID.movenext
				Loop
				rsParentID.Close:Set rsParentID=Nothing
				'更新该栏目排序以及大于本需要和同在本分类下的栏目排序序号
				Cl.Execute("Update Cl_Class set OrderID=OrderID+1 where ChannelID="&ChannelID&" and rootid=" & rootid & " and OrderID>" & PrevOrderID)
				Cl.Execute("Update Cl_Class set OrderID=" & PrevOrderID & "+1 where ChannelID="&ChannelID&" and ClassID=" & ClassID)
			end if
			ClassID=ClassID+1:PrevOrderID=PrevOrderID+1:PrevID=PrevID+1
			if ParentID=0 then RootID=RootID+1
		end if   '判断栏目名是否为空 end
	Next
'====================================================
	CreateClassJs(ChannelID)
	Cl.SaveAdminLog
	Response.Write Cl.ShowSuc("恭喜你，栏目添加成功！返回 <a href='"&strFileName&"'>栏目管理首页</a> 。")
end sub
%> 
<%
'<!--
'┌───────────────────────────────────────────────────────┐
'│														 │
'│		CreateLive CMS Version 3.1						 │
'│　　　　　　　　				Powered by Aspoo.CN	 	 │
'│　		　　　　　　　　　　						 │
'│　	邮箱: aspoo@126.com			Info@aspoo.cn　　	 │
'│		ＱＱ: 3315263				596197794			 │
'│		网站: www.aspoo.cn			www.aspoo.com		 │
'│		论坛: bbs.aspoo.cn			bbs.aspoo.com		 │
'│														 │
'│	Copyright (C) 2005 Aspoo.CN All Rights Reserved.	 │
'└───────────────────────────────────────────────────────┘
'-->
%>