<!-- #include file="../conn.asp" -->
<!-- #include file="../cls_main.asp" -->
<% MyDbPath = "../"
dim obj
set obj = New admin_cms_catalog
	obj.AspInit()
set obj = nothing

Class admin_cms_catalog
	Private sql, Rs, Founderr, str, i,Mesky
	Private Sub Class_Initialize()
		Set Mesky = New Cls_Main
	End Sub
	Private Sub Class_Terminate()
		Set Mesky = Nothing
	End Sub
	Public Sub AspInit()
		Response.Write "<HTML><HEAD><TITLE>下载资源分类管理</TITLE>" & vbCrLf
		Response.Write "<META http-equiv=Content-Type content=""text/html; charset=gb2312"">" & vbCrLf
		Response.Write "<LINK href=""admin.css"" type=text/css rel=stylesheet>" & vbCrLf
		Response.Write "</HEAD>" & vbCrLf
		Response.Write "<BODY leftmargin=""1"" topmargin=""1"">" & vbCrLf
	
			If Mesky.adminName = "" Then
				Mesky.strMsg = "<li>非法操作：登录超时或你没有以管理员身份登录系统，<a href=""../admin_login.asp"" target=_top>点此进入管理员登录界面</a>。"
				Call Mesky.SystemMsg
			ElseIf Mesky.checkPermission(Mesky.adminName, "11") = False Then
				Mesky.strMsg = "<li>非法操作：你没有权限进行此项操作，请联系管理员！"
				Call Mesky.SystemMsg
			Else
				Call Main
			End If
		Response.Write "</BODY></HTML>" & vbCrLf
	
	End Sub

	Private Sub Main()
		
		Response.Write "<fieldset><legend>版面管理 </legend><table border=""0"" cellspacing=""1"" cellpadding=""3""  align=center>" & vbCrLf
		Response.Write "        <tr class=""tdbg2""> " & vbCrLf
		Response.Write "          <td class=""forumrow"" colspan=2> <B>注意</B>：<BR>" & vbCrLf
		Response.Write "              ①删除版面同时将删除该版面下所有资源！删除分类同时删除下属版面和其中资源！ 操作时请完整填写表单信息。<BR>" & vbCrLf
		Response.Write "              ②如果选择<B>复位所有版面</B>，则所有版面都将作为一级版面（分类），这时您需要重新对各个版面进行归属的基本设置，<B>不要轻易使用该功能</B>，仅在做出了错误的设置而无法复原版面之间的关系和排序的时候使用<br>" & vbCrLf
		Response.Write "              ③ID号为红色是是根分类的rootID的值，其他则是catalogID的值。</td>" & vbCrLf
		Response.Write "        </tr>" & vbCrLf
		Response.Write "        <tr class=""tdbg3""> " & vbCrLf
		Response.Write "          <td width=""80""> <B>版面操作选项</B></td>" & vbCrLf
		Response.Write "          <td><a href=""admin_Cms_catalog.asp"">版面管理首页</a> | <a href=""admin_Cms_catalog.asp?action=add"">新建版面</a> " & vbCrLf
		Response.Write "            | <a href=""?action=orders"">一级分类排序</a> | <a href=""?action=catalogorders"">N级分类排序</a> " & vbCrLf
		Response.Write "            | <a href=""?action=RestoreBoard"" onclick=""{if(confirm('复位所有版面将把所有版面恢复成为一级大分类，复位后要对所有版面重新进行归属的基本设置，请慎重操作，确定复位吗?')){return true;}return false;}"">复位所有版面</a> " & vbCrLf
		Response.Write "          </td>" & vbCrLf
		Response.Write "        </tr>" & vbCrLf
		Response.Write "      </table>" & vbCrLf
		Response.Write "</fieldset>" & vbCrLf
		Response.Write "      <p></p>" & vbCrLf
		
		Select Case Request("action")
		Case "add"
			Call add
		Case "edit"
			Call edit
		Case "savenew"
			Call savenew
		Case "savedit"
			Call savedit
		Case "del"
			Call del
		Case "orders"
			Call orders
		Case "updatorders"
			Call updateorders
		Case "catalogorders"
			Call catalogorders
		Case "updatcatalogorders"
			Call updatecatalogorders
		Case "RestoreBoard"
			Call RestoreBoard
		Case Else
			Call CatalogInfo
		End Select
	End Sub
	
	Private Sub CatalogInfo()
		Response.Write "<fieldset><legend>版面列表</legend><table width=""100%"" align=""center"" cellpadding=""1"" cellspacing=""1"">" & vbCrLf
		Response.Write "  <tr class=""tdbg2"">" & vbCrLf
		Response.Write "    <th width=""5%"">ID</th>" & vbCrLf
		Response.Write "          <th width=""35%"" height=25>版面名称 </th>" & vbCrLf
		Response.Write "          <th width=""35%"" height=25>操作 </th>" & vbCrLf
		Response.Write "  </tr>" & vbCrLf
		
		Set Rs = Mesky.Execute("select * from Mesky_Cms_Catalog order by rootid,orders")
		'set rs=server.createobject("adodb.recordset")
		'rs.open sql,conn,1,1
		Do While Not Rs.EOF
		
		Response.Write "        <tr class=""tdbg3"" onmouseover=""this.style.backgroundColor='#CEE7FF';this.style.color='blue'"" onmouseout=""this.style.backgroundColor='';this.style.color=''"">" & vbCrLf
		Response.Write "          <td width=""5%"" align=""center"">"
		
		If Rs("depth") = 0 Then
			Response.Write ("<font color=red><b>" & Rs("rootID") & "</b></font>")
		Else
			Response.Write (Rs("catalogID"))
		End If
		Response.Write "</td> " & vbCrLf
		Response.Write "          <td height=""25"" width=""35%"">"
		If Rs("depth") = 1 Then Response.Write "&nbsp;&nbsp;<font color=""#666666"">├</font>"
		If Rs("depth") > 1 Then
			For i = 2 To Rs("depth")
				Response.Write "&nbsp;&nbsp;<font color=""#666666"">│</font>"
			Next
			Response.Write "&nbsp;&nbsp;<font color=""#666666"">├</font> "
		End If
		If Rs("parentid") = 0 Then Response.Write ("<b>")
		Response.Write Rs("CatalogName")
		If Rs("child") > 0 Then Response.Write "(" & Rs("child") & ")"
		Response.Write "</td>" & vbCrLf
		Response.Write "          <td width=65% align=right><a href=""admin_Cms_catalog.asp?action=add&editid=" & Rs("CatalogID") & """><U>添加版面</U></a> " & vbCrLf
		Response.Write "            | <a href=""admin_Cms_catalog.asp?action=edit&editid=" & Rs("CatalogID") & """><U>基本设置</U></a> " & vbCrLf
		Response.Write "            | <U>高级设置</U> | " & vbCrLf
		If Rs("child") = 0 Then
			Response.Write "            <a href=""admin_Cms_catalog.asp?action=del&editid=" & Rs("CatalogID") & """ onclick=""{if(confirm('删除将包括该版面的所有资源，确定删除吗?')){return true;}return false;}""><U>删除</U></a> " & vbCrLf
		Else
			Response.Write "            <a href=""#"" onclick=""{if(confirm('该版面含有下属版面，必须先删除其下属版面方能删除本版面！')){return true;}return false;}""><U>删除</U></a>" & vbCrLf
		End If
		Response.Write "</td>" & vbCrLf
		Response.Write "        </tr>" & vbCrLf
	Rs.MoveNext
	Loop
	Set Rs = Nothing
	Response.Write "</table>" & vbCrLf
	Response.Write "</fieldset>" & vbCrLf
	End Sub
	
	Private Sub add()
	Dim rs_c
	Set rs_c = Mesky.Execute("select * from Mesky_Cms_Catalog order by rootid,orders")
		Dim catalognum
		Set Rs = Mesky.Execute("select Max(CatalogID) from Mesky_Cms_Catalog")
		If Rs.EOF And Rs.BOF Then
		catalognum = 1
		Else
		catalognum = Rs(0) + 1
		End If
		If IsNull(catalognum) Then catalognum = 1
		
		Response.Write "<form action =""admin_Cms_catalog.asp?action=savenew"" method=post>" & vbCrLf
		Response.Write "<input type=""hidden"" name=""newCatalogID"" value=" & catalognum & ">" & vbCrLf
		Response.Write "  <fieldset><legend>添加新版面</legend><table width=""100%"" border=""0""  align=""center"" cellpadding=""3"" cellspacing=""1"">" & vbCrLf
		Response.Write "    <COLGROUP>" & vbCrLf
		Response.Write "    <COL width=""25%"">" & vbCrLf
		Response.Write "    <COL width=""*"">" & vbCrLf
		Response.Write "          <tr class=""tdbg2""> " & vbCrLf
		Response.Write "            <td height=30>版面名称</td>" & vbCrLf
		Response.Write "            <td> <input type=""text"" name=""CatalogName"" size=""35""> " & vbCrLf
		Response.Write "            </td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg3""> " & vbCrLf
		Response.Write "            <td height=24>版面说明<BR>" & vbCrLf
		Response.Write "            可以使用HTML代码</td>" & vbCrLf
		Response.Write "            <td> <textarea name=""Readme"" cols=""40"" rows=""3""></textarea> " & vbCrLf
		Response.Write "            </td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg2""> " & vbCrLf
		Response.Write "            <td height=30>所属类别</td>" & vbCrLf
		Response.Write "            <td> <select name=class>" & vbCrLf
		Response.Write "                <option value=""0"">做为栏目分类</option>" & vbCrLf
		Do While Not rs_c.EOF
			Response.Write "<option value=""" & rs_c("CatalogID") & """ "
			If Request("editid") <> "" And CLng(Request("editid")) = rs_c("CatalogID") Then Response.Write "selected"
			Response.Write ">"
			If rs_c("depth") = 1 Then Response.Write "&nbsp;&nbsp;├ "
			If rs_c("depth") > 1 Then
				For i = 2 To rs_c("depth")
					Response.Write "&nbsp;&nbsp;│"
				Next
				Response.Write "&nbsp;&nbsp;├ "
			End If
			Response.Write rs_c("CatalogName") & "</option>" & vbCrLf
		rs_c.MoveNext
		Loop
		Response.Write "</select> </td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg3"">" & vbCrLf
		Response.Write "            <td height=24>是否在下载导航栏中显示</td>" & vbCrLf
		Response.Write "            <td><input name=""isShowOnTop"" type=""radio"" value=""1"" checked>是" & vbCrLf
		Response.Write "                <input type=""radio"" name=""isShowOnTop"" value=""0"">否" & vbCrLf
		Response.Write "          此选项只对一级栏目有效</td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg2"">" & vbCrLf
		Response.Write "            <td height=24>是否显示全部子级资源</td>" & vbCrLf
		Response.Write "            <td><input type=""radio"" name=""isShowAllRes"" value=""1"" checked>是" & vbCrLf
		Response.Write "                <input type=""radio"" name=""isShowAllRes"" value=""0"">否</td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg3""> " & vbCrLf
		Response.Write "            <td height=24>&nbsp;</td>" & vbCrLf
		Response.Write "            <td> <input type=""submit"" name=""Submit"" value=""添加版面""> " & vbCrLf
		Response.Write "            </td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "        </table>" & vbCrLf
		Response.Write "  </fieldset>" & vbCrLf
		Response.Write "      </form>" & vbCrLf
	Set rs_c = Nothing
	Set Rs = Nothing
	End Sub
	
	Private Sub edit()
		Dim rs_c
		sql = "select * from Mesky_Cms_Catalog order by rootid,orders"
		Set rs_c = Mesky.Execute(sql)
		sql = "select * from Mesky_Cms_Catalog where CatalogID=" & Request("editid")
		Set Rs = Mesky.Execute(sql)
		
		Response.Write "<form action =""admin_Cms_catalog.asp?action=savedit"" method=post>" & vbCrLf
		Response.Write "<input type=""hidden"" name=editid value=""" & Request("editid") & " "">        " & vbCrLf
		Response.Write "  <fieldset><legend>编辑版面：" & Rs("CatalogName") & " </legend><table width=""100%"" border=""0"" cellpadding=""3"" cellspacing=""1"">" & vbCrLf
		Response.Write "    <COLGROUP>" & vbCrLf
		Response.Write "    <COL width=""25%"">" & vbCrLf
		Response.Write "    <COL width=""*"">" & vbCrLf
		Response.Write "          <tr class=""tdbg2""> " & vbCrLf
		Response.Write "            <td height=30>版面名称</td>" & vbCrLf
		Response.Write "            <td> " & vbCrLf
		Response.Write "              <input type=""text"" name=""CatalogName"" size=""35""  value=""" & Rs("CatalogName") & " ""> " & vbCrLf
		Response.Write "            </td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg3""> " & vbCrLf
		Response.Write "            <td height=24>版面说明<BR>" & vbCrLf
		Response.Write "            可以使用HTML代码</td>" & vbCrLf
		Response.Write "            <td> " & vbCrLf
		Response.Write "              <textarea name=""Readme"" cols=""40"" rows=""3"">" & Rs("readme") & " </textarea> " & vbCrLf
		Response.Write "            </td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg2""> " & vbCrLf
		Response.Write "            <td height=30>所属类别<BR>" & vbCrLf
		Response.Write "              所属版面不能指定为当前版面<BR>" & vbCrLf
		Response.Write "            所属版面不能指定为当前版面的下属版面</td>" & vbCrLf
		Response.Write "            <td> " & vbCrLf
		Response.Write "              <select name=class>" & vbCrLf
		Response.Write "                <option value=""0"">做为版面分类</option>" & vbCrLf
		Do While Not rs_c.EOF
		Response.Write "<option value=""" & rs_c("CatalogID") & """"
		If CInt(Rs("parentid")) = rs_c("CatalogID") Then Response.Write " selected"
		Response.Write ">"
		If rs_c("depth") = 1 Then Response.Write "&nbsp;&nbsp;├ "
		If rs_c("depth") > 1 Then
			For i = 2 To rs_c("depth")
				Response.Write "&nbsp;&nbsp;│"
			Next
			Response.Write "&nbsp;&nbsp;├ "
		End If
		Response.Write rs_c("CatalogName") & "</option>" & vbCrLf
		rs_c.MoveNext
		Loop
		Response.Write "</select> </td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg3"">" & vbCrLf
		Response.Write "            <td height=24>是否在下载导航栏中显示</td>" & vbCrLf
		Response.Write "            <td><input name=""isShowOnTop"" type=""radio"" value=""1"" "
		If Rs("isShowOnTop") = 1 Then Response.Write ("checked")
		Response.Write ">是" & vbCrLf
		Response.Write "                <input type=""radio"" name=""isShowOnTop"" value=""0"" "
		If Rs("isShowOnTop") = 0 Then Response.Write ("checked")
		Response.Write ">否" & vbCrLf
		Response.Write "          此选项只对一级栏目有效</td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg2"">" & vbCrLf
		Response.Write "            <td height=24>是否显示全部子级资源</td>" & vbCrLf
		Response.Write "            <td><input type=""radio"" name=""isShowAllRes"" value=""1"" "
		If Rs("isShowAllRes") = 1 Then Response.Write ("checked")
		Response.Write ">是" & vbCrLf
		Response.Write "                <input type=""radio"" name=""isShowAllRes"" value=""0"" "
		If Rs("isShowAllRes") = 0 Then Response.Write ("checked")
		Response.Write ">否</td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=""tdbg3""> " & vbCrLf
		Response.Write "            <td height=24>&nbsp;</td>" & vbCrLf
		Response.Write "            <td> " & vbCrLf
		Response.Write "              <input type=""submit"" name=""Submit"" value=""提交修改""> " & vbCrLf
		Response.Write "            </td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "        </table></fieldset>" & vbCrLf
		Response.Write "      </form>" & vbCrLf
		Set Rs = Nothing
		Set rs_c = Nothing
	End Sub
	
	
	'保存添加版面信息
	Private Sub savenew()
		If Request("CatalogName") = "" Then
			errmsg = errmsg + "<br>" + "<li>请输入版面名称。"
			Founderr = True
		End If
		If Request("class") = "" Then
			errmsg = errmsg + "<br>" + "<li>请选择版面分类。"
			Founderr = True
		End If
		If Request("readme") = "" Then
			errmsg = errmsg + "<br>" + "<li>请输入版面说明。"
			Founderr = True
		End If
		If Founderr = True Then
			Response.Write errmsg
			Exit Sub
		End If
		Dim catalogID
		Dim rootID
		Dim ParentID
		Dim depth
		Dim orders
		Dim FCatalogMaster
		Dim maxrootid
		Dim ParentStr
		If Request("class") <> "0" Then
			Set Rs = Mesky.Execute("select rootid,CatalogID,depth,orders,ParentStr from Mesky_Cms_Catalog where CatalogID=" & Request("class"))
			rootID = Rs(0)
			ParentID = Rs(1)
			depth = Rs(2)
			orders = Rs(3)
			If depth + 1 > 20 Then
				Response.Write "本版面限制最多只能有20级分类"
				Exit Sub
			End If
			ParentStr = Rs(4)
		Else
			Set Rs = Mesky.Execute("select max(rootid) from Mesky_Cms_Catalog")
			maxrootid = Rs(0) + 1
			If IsNull(maxrootid) Then maxrootid = 1
		End If
		Set Rs = Nothing
		
		sql = "select CatalogID from Mesky_Cms_Catalog where CatalogID=" & Request("newCatalogID")
		Set Rs = Mesky.Execute(sql)
		If Not (Rs.EOF And Rs.BOF) Then
			Response.Write "您不能指定和别的版面一样的序号。"
			Exit Sub
		Else
			catalogID = Request("newCatalogID")
		End If
		Set Rs = Nothing
		
		If Not IsObject(Conn) Then ConnectionDatabase
		Set Rs = Server.CreateObject("adodb.recordset")
		sql = "select * from Mesky_Cms_Catalog"
		Rs.open sql, Conn, 1, 3
		Rs.AddNew
		If Request("class") <> "0" Then
			Rs("depth") = depth + 1
			Rs("rootid") = rootID
			Rs("orders") = Request.Form("newCatalogID")
			Rs("parentid") = Request.Form("class")
			If ParentStr = "0" Then
				Rs("ParentStr") = Request.Form("class")
			Else
				Rs("ParentStr") = ParentStr & "," & Request.Form("class")
			End If
			Rs("isShowAllRes") = Request.Form("isShowAllRes")
		Else
			Rs("depth") = 0
			Rs("rootid") = maxrootid
			Rs("orders") = 0
			Rs("parentid") = 0
			Rs("child") = 0
			Rs("parentstr") = 0
			Rs("isShowOnTop") = Request.Form("isShowOnTop")
			Rs("isShowAllRes") = 1
		End If
		Rs("CatalogID") = Request.Form("newCatalogID")
		Rs("CatalogName") = Request.Form("CatalogName")
		Rs("readme") = Request.Form("readme")
		
		'rs("SkinID")=Request.Form("SinkID")
		'if Request("CatalogMaster")<>"" then rs("CatalogMaster") = Request.form("CatalogMaster")
		'if request.form("indexIMG")<>"" then rs("indexIMG")=request.form("indexIMG")
		'if Request("LinkURL")<>"" then rs("LinkURL")=Request.form("LinkURL")
		Rs.Update
		Rs.Close
		'if Request("CatalogMaster")<>"" then call addmaster(Request("CatalogMaster"),"none",0)
		If Request("class") <> "0" Then
		If depth > 0 Then
			'当上级分类深度大于0的时候要更新其父类（或父类的父类）的版面数和相关排序
			For i = 1 To depth
				'更新其父类版面数
				If ParentID <> "" Then
				Mesky.Execute ("update Mesky_Cms_Catalog set child=child+1 where CatalogID=" & ParentID)
				End If
				'得到其父类的父类的版面ID
				Set Rs = Mesky.Execute("select parentid from Mesky_Cms_Catalog where CatalogID=" & ParentID)
				If Not (Rs.EOF And Rs.BOF) Then
					ParentID = Rs(0)
				End If
				'当循环次数大于1并且运行到最后一次循环的时候直接进行更新
				If i = depth And ParentID <> "" Then
				Mesky.Execute ("update Mesky_Cms_Catalog set child=child+1 where CatalogID=" & ParentID)
				End If
			Next
			'更新该版面排序以及大于本需要和同在本分类下的版面排序序号
			Mesky.Execute ("update Mesky_Cms_Catalog set orders=orders+1 where rootid=" & rootID & " and orders>" & orders)
			Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+1 where CatalogID=" & Request.Form("newCatalogID"))
		Else
			'当上级分类深度为0的时候只要更新上级分类版面数和该版面排序序号即可
			Mesky.Execute ("update Mesky_Cms_Catalog set child=child+1 where CatalogID=" & Request("class"))
			Set Rs = Mesky.Execute("select max(orders) from Mesky_Cms_Catalog where CatalogID=" & Request.Form("newCatalogID"))
			Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & Rs(0) & "+1 where CatalogID=" & Request.Form("newCatalogID"))
		End If
		End If
		Response.Write "<p>版面添加成功！<br><B>该版面目前高级设置为默认选项，建议您返回版面管理中心重新设置该版面的高级选项</B><BR><br>" & str
		Set Rs = Nothing
	End Sub
	
	'保存编辑版面信息
	Private Sub savedit()
		If Not IsObject(Conn) Then ConnectionDatabase
		If CLng(Request("editid")) = CLng(Request("class")) Then
			Response.Write "所属版面不能指定自己"
			Exit Sub
		End If
		Dim newCatalogID, maxrootid
		Dim ParentID, CatalogMaster, depth, child, ParentStr, rootID, iparentid, iParentStr
		Dim tRs, brs, mrs
		Call ConnectionDatabase
		Set Rs = Server.CreateObject("adodb.recordset")
		sql = "select * from Mesky_Cms_Catalog where CatalogID=" & Request("editid")
		Rs.open sql, Conn, 1, 3
		newCatalogID = Rs("CatalogID")
		ParentID = Rs("parentid")
		iparentid = Rs("parentid")
		'CatalogMaster=rs("CatalogMaster")
		ParentStr = Rs("ParentStr")
		depth = Rs("depth")
		child = Rs("child")
		rootID = Rs("rootid")
		'判断所指定的版面是否其下属版面
		If ParentID = 0 Then
			If CLng(Request("class")) <> 0 Then
				Set tRs = Mesky.Execute("select rootid from Mesky_Cms_Catalog where CatalogID=" & Request("class"))
				If rootID = tRs(0) Then
					Response.Write "您不能指定该版面的下属栏目作为所属栏目1"
					Exit Sub
				End If
			End If
		Else
			Set tRs = Mesky.Execute("select CatalogID from Mesky_Cms_Catalog where ParentStr like '%" & ParentStr & ",%' and CatalogID=" & Request("class"))
			If Not (tRs.EOF And tRs.BOF) Then
				'response.write "select CatalogID from board where ParentStr like '%" & ParentStr & "%' and CatalogID=" & request("class")
				Response.Write "您不能指定该版面的下属栏目作为所属栏目2"
				Response.End
			End If
		End If
		If ParentID = 0 Then
			ParentID = Rs("CatalogID")
			iparentid = 0
		End If
		If Request("class") <> "0" Then
			Rs("isShowAllRes") = Request.Form("isShowAllRes")
		Else
			Rs("isShowOnTop") = Request.Form("isShowOnTop")
			Rs("isShowAllRes") = 1
		End If
		Rs("CatalogName") = Request.Form("CatalogName")
		'rs("parentid") = Request.Form("class")
		'rs("CatalogMaster") = Request("CatalogMaster")
		Rs("readme") = Request("readme")
		'rs("indexIMG")=request.form("indexIMG")
		'rs("LinkURL")=Request.Form("LinkURL")
		'rs("SkinID")=request.form("SkinID")
		Rs.Update
		Rs.Close
		Set Rs = Nothing
		'if request("oldCatalogMaster")<>Request("CatalogMaster") then call addmaster(Request("CatalogMaster"),request("oldCatalogMaster"),1)
		
		Set mrs = Mesky.Execute("select max(rootid) from Mesky_Cms_Catalog")
		maxrootid = mrs(0) + 1
		'假如更改了所属版面
		'需要更新其原来所属版面信息，包括深度、父级ID、版面数、排序、继承版主等数据
		'需要更新当前所属版面信息
		'继承版主数据需要另写函数进行更新--取消，在前台可用CatalogID in parentstr来获得
		Dim k, nParentStr, mParentStr
		Dim ParentSql, catalogcount
		If CLng(ParentID) <> CLng(Request("class")) And Not (iparentid = 0 And CInt(Request("class")) = 0) Then
			'如果原来不是一级分类改成一级分类
			If iparentid > 0 And CInt(Request("class")) = 0 Then
				'更新当前版面数据
				Mesky.Execute ("update Mesky_Cms_Catalog set depth=0,orders=0,rootid=" & maxrootid & ",parentid=0,parentstr='0' where CatalogID=" & newCatalogID)
				ParentStr = ParentStr & ","
				Set Rs = Mesky.Execute("select count(*) from Mesky_Cms_Catalog where ParentStr like '%" & ParentStr & "%'")
				catalogcount = Rs(0)
				If IsNull(catalogcount) Then
				catalogcount = 1
				Else
				catalogcount = catalogcount + 1
				End If
				'更新其原来所属版面版面数
				Mesky.Execute ("update Mesky_Cms_Catalog set child=child-" & catalogcount & " where CatalogID=" & iparentid)
				'更新其原来所属版面数据，排序相当于剪枝而不需考虑
				For i = 1 To depth
					'得到其父类的父类的版面ID
					Set Rs = Mesky.Execute("select parentid from Mesky_Cms_Catalog where CatalogID=" & iparentid)
					If Not (Rs.EOF And Rs.BOF) Then
						iparentid = Rs(0)
						Mesky.Execute ("update Mesky_Cms_Catalog set child=child-" & catalogcount & " where CatalogID=" & iparentid)
					End If
				Next
				If child > 0 Then
				'更新其下属版面数据
				'有下属版面，排序不需考虑，更新下属版面深度和一级排序ID(rootid)数据
				'更新当前版面数据
				'ParentStr=ParentStr & ","
				i = 0
				Set Rs = Mesky.Execute("select * from Mesky_Cms_Catalog where ParentStr like '%" & ParentStr & "%'")
				Do While Not Rs.EOF
				i = i + 1
				mParentStr = Replace(Rs("ParentStr"), ParentStr, "")
				Mesky.Execute ("update Mesky_Cms_Catalog set depth=depth-" & depth & ",rootid=" & maxrootid & ",ParentStr='" & mParentStr & "' where CatalogID=" & Rs("CatalogID"))
				Rs.MoveNext
				Loop
				End If
			ElseIf iparentid > 0 And CInt(Request("class")) > 0 Then
			'将一个分版面移动到其他分版面下
			'获得所指定的版面的相关信息
			Set tRs = Mesky.Execute("select * from Mesky_Cms_Catalog where CatalogID=" & Request("class"))
			'得到其下属版面数
			ParentStr = ParentStr & ","
	
			Set Rs = Mesky.Execute("select count(*) from Mesky_Cms_Catalog where ParentStr like '%" & ParentStr & newCatalogID & "%'")
			catalogcount = Rs(0)
			If IsNull(catalogcount) Then catalogcount = 1
			'在获得移动过来的版面数后更新排序在指定版面之后的版面排序数据
			Mesky.Execute ("update Mesky_Cms_Catalog set orders=orders + " & catalogcount & " + 1 where rootid=" & tRs("rootid") & " and orders>" & tRs("orders") & "")
			'更新当前版面数据
			If tRs("parentstr") = "0" Then
			Mesky.Execute ("update Mesky_Cms_Catalog set depth=" & tRs("depth") & "+1,orders=" & tRs("orders") & "+1,rootid=" & tRs("rootid") & ",ParentID=" & Request("class") & ",ParentStr='" & tRs("CatalogID") & "' where CatalogID=" & newCatalogID)
			Else
			Mesky.Execute ("update Mesky_Cms_Catalog set depth=" & tRs("depth") & "+1,orders=" & tRs("orders") & "+1,rootid=" & tRs("rootid") & ",ParentID=" & Request("class") & ",ParentStr='" & tRs("parentstr") & "," & tRs("CatalogID") & "' where CatalogID=" & newCatalogID)
			End If
			i = 1
			'如果有则更新下属版面数据
			'深度为原有深度加上当前所属版面的深度
			Set Rs = Mesky.Execute("select * from Mesky_Cms_Catalog where ParentStr like '%" & ParentStr & newCatalogID & "%' order by orders")
			Do While Not Rs.EOF
			i = i + 1
			If tRs("parentstr") = "0" Then
			iParentStr = tRs("CatalogID") & "," & Replace(Rs("parentstr"), ParentStr, "")
			Else
			iParentStr = tRs("parentstr") & "," & tRs("CatalogID") & "," & Replace(Rs("parentstr"), ParentStr, "")
			End If
			Mesky.Execute ("update Mesky_Cms_Catalog set depth=depth+" & tRs("depth") & "-" & depth & "+1,orders=" & tRs("orders") & "+" & i & ",rootid=" & tRs("rootid") & ",ParentStr='" & iParentStr & "' where CatalogID=" & Rs("CatalogID"))
			Rs.MoveNext
			Loop
			ParentID = Request("class")
			If rootID = tRs("rootid") Then
			'在同一分类下移动
			'更新所指向的上级版面版面数，i为本次移动过来的版面数
			'更新其父类版面数
			Mesky.Execute ("update Mesky_Cms_Catalog set child=child+" & i & " where (not ParentID=0) and CatalogID=" & ParentID)
			For k = 1 To tRs("depth")
				'得到其父类的父类的版面ID
				Set Rs = Mesky.Execute("select parentid from Mesky_Cms_Catalog where (not ParentID=0) and CatalogID=" & ParentID)
				If Not (Rs.EOF And Rs.BOF) Then
					ParentID = Rs(0)
					'更新其父类的父类版面数
					Mesky.Execute ("update Mesky_Cms_Catalog set child=child+" & i & " where (not ParentID=0) and  CatalogID=" & ParentID)
				End If
			Next
			'更新其原父类版面数
			Mesky.Execute ("update Mesky_Cms_Catalog set child=child-" & i & " where (not ParentID=0) and CatalogID=" & iparentid)
			'更新其原来所属版面数据
			'response.write iparentid & "<br>"
			For k = 1 To depth
				'得到其原父类的父类的版面ID
				Set Rs = Mesky.Execute("select parentid from Mesky_Cms_Catalog where (not ParentID=0) and CatalogID=" & iparentid)
				If Not (Rs.EOF And Rs.BOF) Then
					iparentid = Rs(0)
					'response.write iparentid & "<br>"
					'更新其原父类的父类版面数
					Mesky.Execute ("update Mesky_Cms_Catalog set child=child-" & i & " where (not ParentID=0) and  CatalogID=" & iparentid)
				End If
			Next
			Else
			'更新所指向的上级版面版面数，i为本次移动过来的版面数
			'更新其父类版面数
			Mesky.Execute ("update Mesky_Cms_Catalog set child=child+" & i & " where CatalogID=" & ParentID)
			For k = 1 To tRs("depth")
				'得到其父类的父类的版面ID
				Set Rs = Mesky.Execute("select parentid from Mesky_Cms_Catalog where CatalogID=" & ParentID)
				If Not (Rs.EOF And Rs.BOF) Then
					ParentID = Rs(0)
					'更新其父类的父类版面数
					Mesky.Execute ("update Mesky_Cms_Catalog set child=child+" & i & " where CatalogID=" & ParentID)
				End If
			Next
			'更新其原父类版面数
			Mesky.Execute ("update Mesky_Cms_Catalog set child=child-" & i & " where CatalogID=" & iparentid)
			'更新其原来所属版面数据
			For k = 1 To depth
				'得到其原父类的父类的版面ID
				Set Rs = Mesky.Execute("select parentid from Mesky_Cms_Catalog where CatalogID=" & iparentid)
				If Not (Rs.EOF And Rs.BOF) Then
					iparentid = Rs(0)
					'更新其原父类的父类版面数
					Mesky.Execute ("update Mesky_Cms_Catalog set child=child-" & i & " where CatalogID=" & iparentid)
				End If
			Next
			End If 'end if rootid=trs("rootid") then
			Else
			'如果原来是一级版面改成其他版面的下属版面
			'得到所指定的版面的相关信息
			Set tRs = Mesky.Execute("select * from Mesky_Cms_Catalog where CatalogID=" & Request("class"))
			Set Rs = Mesky.Execute("select count(*) from Mesky_Cms_Catalog where rootid=" & rootID)
			catalogcount = Rs(0)
			'更新所指向的上级版面版面数，i为本次移动过来的版面数
			ParentID = Request("class")
			'更新其父类版面数
			Mesky.Execute ("update Mesky_Cms_Catalog set child=child+" & catalogcount & " where CatalogID=" & ParentID)
			'response.write parentid & "-" & catalogcount & "<br>"
			For k = 1 To tRs("depth")
				'得到其父类的父类的版面ID
				Set Rs = Mesky.Execute("select parentid from Mesky_Cms_Catalog where CatalogID=" & ParentID)
				If Not (Rs.EOF And Rs.BOF) Then
					ParentID = Rs(0)
					'更新其父类的父类版面数
					Mesky.Execute ("update Mesky_Cms_Catalog set child=child+" & catalogcount & " where CatalogID=" & ParentID)
				End If
			'response.write parentid & "-" & catalogcount & "<br>"
			Next
			'在获得移动过来的版面数后更新排序在指定版面之后的版面排序数据
			Mesky.Execute ("update Mesky_Cms_Catalog set orders=orders + " & catalogcount & " + 1 where rootid=" & tRs("rootid") & " and orders>" & tRs("orders") & "")
			i = 0
			Set Rs = Mesky.Execute("select * from Mesky_Cms_Catalog where rootid=" & rootID & " order by orders")
			Do While Not Rs.EOF
			i = i + 1
			If Rs("parentid") = 0 Then
				If tRs("ParentStr") = "0" Then
				ParentStr = tRs("CatalogID")
				Else
				ParentStr = tRs("parentstr") & "," & tRs("CatalogID")
				End If
			Mesky.Execute ("update Mesky_Cms_Catalog set depth=depth+" & tRs("depth") & "+1,orders=" & tRs("orders") & "+" & i & ",rootid=" & tRs("rootid") & ",ParentStr='" & ParentStr & "',parentid=" & Request("class") & " where CatalogID=" & Rs("CatalogID"))
			Else
				If tRs("ParentStr") = "0" Then
				ParentStr = tRs("CatalogID") & "," & Rs("parentstr")
				Else
				ParentStr = tRs("parentstr") & "," & tRs("CatalogID") & "," & Rs("parentstr")
				End If
			Mesky.Execute ("update Mesky_Cms_Catalog set depth=depth+" & tRs("depth") & "+1,orders=" & tRs("orders") & "+" & i & ",rootid=" & tRs("rootid") & ",ParentStr='" & ParentStr & "' where CatalogID=" & Rs("CatalogID"))
			End If
			Rs.MoveNext
			Loop
			End If
		End If
		Set Rs = Nothing
		Set mrs = Nothing
		Set tRs = Nothing
		Response.Write "<p>版面修改成功！<br><br>" & str
	End Sub
	
	'删除版面，删除版面资源，入口：版面ID
	Private Sub del()
		'更新其上级版面版面数，如果该版面含有下级版面则不允许删除
		Set Rs = Mesky.Execute("select ParentStr,child,depth from Mesky_Cms_Catalog where CatalogID=" & Request("editid"))
		If Not (Rs.EOF And Rs.BOF) Then
		If Rs(1) > 0 Then
			Response.Write "该版面含有下属版面，请删除其下属版面后再进行删除本版面的操作"
			Exit Sub
		End If
		'如果有上级版面，则更新数据
		If Rs(2) > 0 Then
			Mesky.Execute ("update Mesky_Cms_Catalog set child=child-1 where CatalogID in (" & Rs(0) & ")")
		End If
		sql = "delete from Mesky_Cms_Catalog where CatalogID=" & Request("editid")
		Mesky.Execute (sql)
		
		sql = "delete from Mesky_Cms_Resource where CatalogID=" & Request("editid")
		Mesky.Execute (sql)
		
		End If
		Set Rs = Nothing
		Response.Write "<p>版面删除成功！"
	End Sub
	
	Private Sub orders()
	
		Response.Write "<fieldset><legend>一级分类排序</legend><table width=""100%"" border=""0""  align=center cellpadding=""3"" cellspacing=""1"">" & vbCrLf
		Response.Write "  <tr> " & vbCrLf
		Response.Write "          <th height=""22"" class=""tdbg2"">版面一级分类重新排序修改(请在相应版面分类的排序表单内输入相应的排列序号) " & vbCrLf
		Response.Write "          </th>" & vbCrLf
		Response.Write "  </tr>" & vbCrLf
		Response.Write "        <tr> " & vbCrLf
		Response.Write "          <td class=""tdbg3"">" & vbCrLf
		Response.Write "<table width=""50%"">" & vbCrLf
	
		sql = "select * from Mesky_Cms_Catalog where ParentID=0 order by RootID"
		Set Rs = Mesky.Execute(sql)
		If Rs.EOF And Rs.BOF Then
			Response.Write "还没有相应的栏目分类。"
		Else
			Do While Not Rs.EOF
			Response.Write "<form action=admin_Cms_catalog.asp?action=updatorders method=post><tr><td width=""50%"">" & Rs("CatalogName") & "</td>"
			Response.Write "<td width=""50%""><input type=text name=""OrderID"" size=4 value=""" & Rs("rootid") & """><input type=hidden name=""cID"" value=""" & Rs("rootid") & """>&nbsp;&nbsp;<input type=submit name=Submit value=修改></td></tr></form>"
			Rs.MoveNext
			Loop
			Response.Write "            </table>" & vbCrLf
			Response.Write "            <BR>" & vbCrLf
			Response.Write "            &nbsp;<font color=red>请注意，这里一定<B>不能填写相同的序号</B>，否则非常难修复！</font> " & vbCrLf
		End If
		Set Rs = Nothing
		Response.Write "          </td>" & vbCrLf
		Response.Write "        </tr>" & vbCrLf
		Response.Write "</table></fieldset>" & vbCrLf
	End Sub
	
	Private Sub updateorders()
		Dim cID, OrderID, ClassName
		cID = Replace(Request.Form("cID"), "'", "")
		OrderID = Replace(Request.Form("OrderID"), "'", "")
		Set Rs = Mesky.Execute("select CatalogID from Mesky_Cms_Catalog where rootid=" & OrderID)
		If Rs.EOF And Rs.BOF Then
		Response.Write "设置成功，请返回。"
		Set Rs = Nothing
		Mesky.Execute ("update Mesky_Cms_Catalog set rootid=" & OrderID & " where rootid=" & cID)
		Else
		Response.Write "请不要和其他版面设置相同的序号"
		End If
	End Sub
	
	
	Private Sub catalogorders()
		Response.Write "<table border=""0""  align=center cellpadding=""0"" cellspacing=""0"" class=""tablebg"">" & vbCrLf
		Response.Write "  <tr> " & vbCrLf
		Response.Write "          <th height=""22"" class=""tdbg1"">栏目N级分类重新排序修改(请在相应栏目分类的排序表单内输入相应的排列序号) " & vbCrLf
		Response.Write "          </th>" & vbCrLf
		Response.Write "  </tr>" & vbCrLf
		Response.Write "        <tr> " & vbCrLf
		Response.Write "          <td><table width=""100%"" cellpadding=""3"" cellspacing=""1"">" & vbCrLf
		
		Dim tRs, uporders, doorders
		sql = "select * from Mesky_Cms_Catalog order by RootID,orders"
		Set Rs = Mesky.Execute(sql)
		If Rs.EOF And Rs.BOF Then
			Response.Write "还没有相应的版面分类。"
		Else
			Do While Not Rs.EOF
			Response.Write "<form action=admin_Cms_catalog.asp?action=updatcatalogorders method=post><tr><td width=""40%"" class=""tdbg2"">"
			If Rs("depth") = 1 Then Response.Write "&nbsp;&nbsp;<font color=""#666666"">├</font>"
			If Rs("depth") > 1 Then
				For i = 2 To Rs("depth")
					Response.Write "&nbsp;&nbsp;<font color=""#666666"">│</font>"
				Next
				Response.Write "&nbsp;&nbsp;<font color=""#666666"">├</font> "
			End If
			
			If Rs("parentid") = 0 Then Response.Write "<b>"
			Response.Write Rs("CatalogName")
			If Rs("child") > 0 Then Response.Write "(" & Rs("child") & ")"
			Response.Write "</td><td  class=""tdbg2"">"
			If Rs("ParentID") > 0 Then
			'算出相同深度的版面数目，得到该版面在相同深度的版面中所处位置（之上或者之下的版面数）
			'所能提升最大幅度应为For i=1 to 该版之上的版面数
			Set tRs = Mesky.Execute("select count(*) from Mesky_Cms_Catalog where ParentID=" & Rs("ParentID") & " and orders<" & Rs("orders") & "")
			uporders = tRs(0)
			If IsNull(uporders) Then uporders = 0
			'所能降低最大幅度应为For i=1 to 该版之下的版面数
			Set tRs = Mesky.Execute("select count(*) from Mesky_Cms_Catalog where ParentID=" & Rs("ParentID") & " and orders>" & Rs("orders") & "")
			doorders = tRs(0)
			If IsNull(doorders) Then doorders = 0
			If uporders > 0 Then
				Response.Write "<select name=uporders size=1><option value=0>向上移动</option>"
				For i = 1 To uporders
				Response.Write "<option value=" & i & ">" & i & "</option>"
				Next
				Response.Write "</select>"
			End If
			If doorders > 0 Then
				If uporders > 0 Then Response.Write "&nbsp;"
				Response.Write "<select name=doorders size=1><option value=0>向下移动</option>"
				For i = 1 To doorders
				Response.Write "<option value=" & i & ">" & i & "</option>"
				Next
				Response.Write "</select>"
			End If
			If doorders > 0 Or uporders > 0 Then
			Response.Write "<input type=hidden name=""editID"" value=""" & Rs("CatalogID") & """>&nbsp;<input type=submit name=Submit value=修改>"
			End If
			End If
			Response.Write "</td></tr></form>"
			uporders = 0
			doorders = 0
			Rs.MoveNext
			Loop
			Response.Write "</table>"
		End If
		Set Rs = Nothing
		Response.Write "            </table></td>" & vbCrLf
		Response.Write "        </tr>" & vbCrLf
		Response.Write "</table>" & vbCrLf
	End Sub
	
	Private Sub updatecatalogorders()
		Dim ParentID, orders, ParentStr, child
		Dim uporders, doorders, oldorders, tRs, ii
		If Not IsNumeric(Request("editID")) Then
			Response.Write "非法的参数！"
			Exit Sub
		End If
		If Request("uporders") <> "" And Not CInt(Request("uporders")) = 0 Then
			If Not IsNumeric(Request("uporders")) Then
			Response.Write "非法的参数！"
			Exit Sub
			ElseIf CInt(Request("uporders")) = 0 Then
			Response.Write "请选择要提升的数字！"
			Exit Sub
			End If
			'向上移动
			'要移动的版面信息 加入rootid和depth作为更新所有相关版面的依据
			Dim rootID, depth
			Set Rs = Mesky.Execute("select ParentID,orders,ParentStr,child,rootid,depth from Mesky_Cms_Catalog where CatalogID=" & Request("editID"))
			ParentID = Rs(0)
			orders = Rs(1)
			ParentStr = Rs(2) & "," & Request("editID")
			child = Rs(3)
			rootID = Rs(4)
			depth = Rs(5)
			i = 0
			'response.write "select CatalogID,orders from board where ParentID=" & ParentID & " and orders<" & orders & " order by orders desc<br>"
			If child > 0 Then
			Set Rs = Mesky.Execute("select count(*) from Mesky_Cms_Catalog where ParentStr like '%" & ParentStr & "%' and rootid=" & rootID)
			oldorders = Rs(0)
			Else
			oldorders = 0
			End If
		'加入变量shin和shinlast记录更新后版面最大的orders
			Dim shin, shinlast
			shin = 0
			shinlast = 0
			'和该版面同级且排序在其之上的版面－更新其排序，最末者为当前版面排序号
			Set Rs = Mesky.Execute("select CatalogID,orders,child,ParentStr from Mesky_Cms_Catalog where ParentID=" & ParentID & " and orders<" & orders & " order by orders desc")
			Do While Not Rs.EOF
			i = i + 1
			If CInt(Request("uporders")) >= i Then
				'response.write "update board set orders=" & orders & " where CatalogID="&rs(0)&"<br>"
				If Rs(2) > 0 Then
				ii = 0
				Set tRs = Mesky.Execute("select CatalogID,orders from Mesky_Cms_Catalog where ParentStr like '%" & Rs(3) & "," & Rs(0) & "%' order by orders")
				If Not (tRs.EOF And tRs.BOF) Then
				Do While Not tRs.EOF
				ii = ii + 1
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & oldorders & "+" & ii & " where CatalogID=" & tRs(0))
				shin = orders + oldorders + ii
				If shin > shinlast Then shinlast = shin
				tRs.MoveNext
				Loop
				End If
				End If
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & oldorders & " where CatalogID=" & Rs(0))
				shin = orders + oldorders
				If shin > shinlast Then shinlast = shin
				If CInt(Request("uporders")) = i Then uporders = Rs(1)
			End If
			orders = Rs(1)
			Rs.MoveNext
			Loop
			'response.write "update board set orders="&uporders&" where CatalogID=" & request("editID")
			'更新所要排序的版面的序号
			Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & uporders & " where CatalogID=" & Request("editID"))
			'如果有下属版面，则更新其下属版面排序
			If child > 0 Then
			i = uporders
			Set Rs = Mesky.Execute("select CatalogID from Mesky_Cms_Catalog where ParentStr like '%" & ParentStr & "%' and depth>" & depth & " order by orders")
			Do While Not Rs.EOF
			i = i + 1
			Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & i & " where CatalogID=" & Rs(0))
			shin = i
			If shin > shinlast Then shinlast = shin
			Rs.MoveNext
			Loop
			End If
			'response.end
		'加入更新被提升版面之下所有同级版面的orders，避免和被更新版面的下级版面重复
			Dim shin1, shinlast1
			shin1 = 0
			shinlast1 = 0
			Set Rs = Mesky.Execute("select CatalogID,orders,child,ParentStr from Mesky_Cms_Catalog where ParentID=" & ParentID & " and orders>" & uporders & " order by orders")
			Do While Not Rs.EOF
				If Rs(2) > 0 Then
				ii = 0
				Set tRs = Mesky.Execute("select CatalogID,orders from Mesky_Cms_Catalog where ParentStr like '%" & Rs(3) & "," & Rs(0) & "%' order by orders")
				If Not (tRs.EOF And tRs.BOF) Then
				Do While Not tRs.EOF
				ii = ii + 1
				'response.write "update board set orders=" & orders & "+" & ii & " where CatalogID="&trs(0)&"－a<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & ii & "+" & shinlast & " where CatalogID=" & tRs(0))
				shin1 = orders + oldorders + ii + shinlast
				If shin1 > shinlast1 Then shinlast1 = shin1
				tRs.MoveNext
				Loop
				End If
				End If
				'response.write "update board set orders=" & orders & " where CatalogID="&rs(0)&"<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & shinlast & " where CatalogID=" & Rs(0))
				shin1 = orders + oldorders + shinlast
				If shin1 > shinlast1 Then shinlast1 = shin1
			orders = Rs(1)
			Rs.MoveNext
			Loop
		'加入更新被提升版面上一级的orders在被更新版面之后的版面orders，防止orders互相交叉
			Set Rs = Mesky.Execute("select CatalogID,orders,child,ParentStr from Mesky_Cms_Catalog where rootID=" & rootID & " and orders>" & uporders & " and depth<" & depth & " order by orders")
			Do While Not Rs.EOF
				If Rs(2) > 0 Then
				ii = 0
				Set tRs = Mesky.Execute("select CatalogID,orders from Mesky_Cms_Catalog where ParentStr like '%" & Rs(3) & "," & Rs(0) & "%' order by orders")
				If Not (tRs.EOF And tRs.BOF) Then
				Do While Not tRs.EOF
				ii = ii + 1
				'response.write "update board set orders=" & orders & "+" & ii & " where CatalogID="&trs(0)&"－a<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & ii & "+" & shinlast1 & " where CatalogID=" & tRs(0))
				tRs.MoveNext
				Loop
				End If
				End If
				'response.write "update board set orders=" & orders & " where CatalogID="&rs(0)&"<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & shinlast1 & " where CatalogID=" & Rs(0))
			orders = Rs(1)
			Rs.MoveNext
			Loop
		'对提升版面的更新结束
			Set Rs = Nothing
			Set tRs = Nothing
		ElseIf Request("doorders") <> "" Then
			If Not IsNumeric(Request("doorders")) Then
			Response.Write "非法的参数！"
			Exit Sub
			ElseIf CInt(Request("doorders")) = 0 Then
			Response.Write "请选择要下降的数字！"
			Exit Sub
			End If
		'要移动的版面信息 加入rootid和depth作为更新所有相关版面的依据
			Set Rs = Mesky.Execute("select ParentID,orders,ParentStr,child,rootid,depth from Mesky_Cms_Catalog where CatalogID=" & Request("editID"))
			ParentID = Rs(0)
			orders = Rs(1)
			ParentStr = Rs(2) & "," & Request("editID")
			child = Rs(3)
	
			rootID = Rs(4)
			depth = Rs(5)
			i = 0
			shin = 0
			shinlast = 0
			Set Rs = Mesky.Execute("select CatalogID,orders,child,ParentStr from Mesky_Cms_Catalog where ParentID=" & ParentID & " and orders>" & orders & " order by orders")
			Do While Not Rs.EOF
			i = i + 1
			If CInt(Request("doorders")) >= i Then
				If Rs(2) > 0 Then
				ii = 0
				Set tRs = Mesky.Execute("select CatalogID,orders from Mesky_Cms_Catalog where ParentStr like '%" & Rs(3) & "," & Rs(0) & "%' order by orders")
				If Not (tRs.EOF And tRs.BOF) Then
				Do While Not tRs.EOF
				ii = ii + 1
				'response.write "update board set orders=" & orders & "+" & ii & " where CatalogID="&trs(0)&"－a<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & ii & " where CatalogID=" & tRs(0))
				shin = orders + ii
				If shin > shinlast Then shinlast = shin
				tRs.MoveNext
				Loop
				End If
				End If
				'response.write "update board set orders=" & orders & " where CatalogID="&rs(0)&"<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & " where CatalogID=" & Rs(0))
				shin = orders
				If shin > shinlast Then shinlast = shin
				If CInt(Request("doorders")) = i Then doorders = Rs(1)
			End If
			orders = Rs(1)
			Rs.MoveNext
			Loop
			'response.write "update board set orders=" & doorders & " where CatalogID=" & request("editID")&"<br>"
			Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & shinlast + 1 & " where CatalogID=" & Request("editID"))
			'如果有下属版面，则更新其下属版面排序
			If child > 0 Then
			i = shinlast + 1
			Set Rs = Mesky.Execute("select CatalogID from Mesky_Cms_Catalog where ParentStr like '%" & ParentStr & "%' and depth>" & depth & " order by orders")
			Do While Not Rs.EOF
			i = i + 1
			'response.write "update board set orders=" & i & " where CatalogID="&rs(0)&"－b<br>"
			Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & i & " where CatalogID=" & Rs(0))
			shin = i
			If shin > shinlast Then shinlast = shin
			Rs.MoveNext
			Loop
			End If
			'l加入更新被下降版面之下所有同级版面的orders，避免和被更新版面的下级版面重复
			shin1 = 0
			shinlast1 = 0
			Set Rs = Mesky.Execute("select CatalogID,orders,child,ParentStr from Mesky_Cms_Catalog where ParentID=" & ParentID & " and orders>" & doorders & " order by orders")
			Do While Not Rs.EOF
				orders = Rs(1)
				If Rs(2) > 0 Then
				ii = 0
				Set tRs = Mesky.Execute("select CatalogID,orders from Mesky_Cms_Catalog where ParentStr like '%" & Rs(3) & "," & Rs(0) & "%' order by orders")
				If Not (tRs.EOF And tRs.BOF) Then
				Do While Not tRs.EOF
				ii = ii + 1
				'response.write "update board set orders=" & orders & "+" & ii & " where CatalogID="&trs(0)&"－a<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & ii & "+" & shinlast & " where CatalogID=" & tRs(0))
				shin1 = orders + ii + shinlast
				If shin1 > shinlast1 Then shinlast1 = shin1
				tRs.MoveNext
				Loop
				End If
				End If
				'response.write "update board set orders=" & orders & " where CatalogID="&rs(0)&"<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & shinlast & " where CatalogID=" & Rs(0))
				shin1 = orders + shinlast
				If shin1 > shinlast1 Then shinlast1 = shin1
			Rs.MoveNext
			Loop
		'加入更新被下降版面上一级的orders在被更新版面之后的版面orders，防止orders互相交叉
			Set Rs = Mesky.Execute("select CatalogID,orders,child,ParentStr from Mesky_Cms_Catalog where rootID=" & rootID & " and orders>" & doorders & " and depth<" & depth & " order by orders")
			Do While Not Rs.EOF
				orders = Rs(1)
				If Rs(2) > 0 Then
				ii = 0
				Set tRs = Mesky.Execute("select CatalogID,orders from Mesky_Cms_Catalog where ParentStr like '%" & Rs(3) & "," & Rs(0) & "%' order by orders")
				If Not (tRs.EOF And tRs.BOF) Then
				Do While Not tRs.EOF
				ii = ii + 1
				'response.write "update board set orders=" & orders & "+" & ii & " where CatalogID="&trs(0)&"－a<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & ii & "+" & shinlast1 & " where CatalogID=" & tRs(0))
				tRs.MoveNext
				Loop
				End If
				End If
				'response.write "update board set orders=" & orders & " where CatalogID="&rs(0)&"<br>"
				Mesky.Execute ("update Mesky_Cms_Catalog set orders=" & orders & "+" & shinlast1 & " where CatalogID=" & Rs(0))
			Rs.MoveNext
			Loop
		'对下降版面的更新结束
			'response.end
			Set Rs = Nothing
			Set tRs = Nothing
		End If
		Response.Redirect "admin_Cms_catalog.asp?action=catalogorders"
	End Sub
	
	Private Sub RestoreBoard()
		'按照目前的排序循环i数值更新rootid
		'还原所有版面的depth,orders,parentid,parentstr,child为0
		i = 0
		Set Rs = Mesky.Execute("select CatalogID from Mesky_Cms_Catalog order by rootid,orders")
		Do While Not Rs.EOF
		i = i + 1
		Mesky.Execute ("update Mesky_Cms_Catalog set rootid=" & i & ",depth=0,orders=0,ParentID=0,ParentStr='0',child=0 where CatalogID=" & Rs(0))
		Rs.MoveNext
		Loop
		Set Rs = Nothing
		Response.Write "复位成功，请返回做版面归属设置。"
	End Sub
	Public Sub OnEndPage()
		Response.Write Mesky.CopyRight
	End Sub ' OnEndPage
End Class
 %>