<!-- #Include File="Include/AMH_Onlogin.asp" -->
<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V2.0》，简称“AsaiMHV2”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

Dim ccid
ccid=Cls.Code_ID("c_id")
Index_Url="Class"
Call AMH_Master(1,2)
Call AMH_Header(1)
tit=Cls.ChannelTit&tit
tit_fir=Cls.ChannelTit&tit_fir
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?ChannelIDs=<%Response.Write iChannelIDs%>'><%Response.Write tit%></a></td>
  <td width=10></td>
  <td><a href='?ChannelIDs=<%Response.Write iChannelIDs%>&Action=Add'>添加<%Response.Write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?ChannelIDs=<%Response.Write iChannelIDs%>&Action=Mod'>合并<%Response.Write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?ChannelIDs=<%Response.Write iChannelIDs%>&Action=Order' alt='在您发现<%Response.Write tit_fir%>排序等发生不正常时请点击，可进行有效的修覆'>重新排序</a></td>
  <td width=10></td>
  <td><a href='?ChannelIDs=<%Response.Write iChannelIDs%>&Action=update' alt='更新网站菜单'><font class="red2">更新前台菜单JS</font></a></td>
  </tr>
  </table>
</td></tr>
</table>
<%
Call AMH_Table(1)
Select Case LCase(Action)
Case "del"
	AsaiMHClass_Del()
Case "mod"
	AsaiMHClass_Mod()
Case "order"
	AsaiMHClass_Order()
Case "orders"
	AsaiMHClass_Orders()
Case "add"
	AsaiMHClass_Add()
Case "edit"
	AsaiMHClass_Edit()
Case "update"
	AsaiMHClass_Update()
Case Else
	AsaiMHClass_Main()
End Select
Call AMH_Ender(tit)
Sub AsaiMHClass_Del()
	Dim ClassParentStr
	SQL = "Select Top 1 ClassParentStr From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And C_ID="&ccid
	Set Rs = Cls.Exec(SQL,1)
	If Rs.Eof Then
		Rs.Close
		Call AMH_Msg("要删除的分类ID（"&ccid&"）不存在！","?ChannelIDs="&iChannelIDs,1)
		Exit Sub
	End If
	ClassParentStr=Rs("ClassParentStr")
	Rs.Close
	SQL = "Select Count(C_ID) From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassParent="&ccid
	Set Rs = Cls.Exec(SQL,1)
	If Rs(0)>0 Then
		Rs.Close
		Call AMH_Msg("要删除的分类ID（"&ccid&"）含有下级分类！请先删除下级分类。","?ChannelIDs="&iChannelIDs,1)
		Exit Sub
	End If
	Rs.Close
	SQL = "Delete From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And C_ID="&ccid
	Call Cls.Exec(SQL,0)
	If Cls.Is_Null(ClassParentStr)<>"" Then
		SQL = "Update "&Data_Name&" Set ClassChild=ClassChild-1 Where ChannelIDs="&iChannelIDs&" And C_ID In("&ClassParentStr&")"
		Call Cls.Exec(SQL,0)
	End If
	Call Cls.Cache_Del("Class_"&iChannelIDs)
	Call AMH_Msg("成功删除分类ID（"&ccid&"）！","?ChannelIDs="&iChannelIDs,1)
End Sub
Sub AsaiMHClass_Order()
	If Cls.Code_Query("chk")<>"yes" Then
%>
<%Call AMH_td("重新计数排序")%>
<tr>
<td>注意：</td>
<td height=60 class=htd>现在正在执行重新计算所有分类计数、所属下级分类、分类排序等操作；<br />根据您的服务器情况可能会执行一到两秒钟左右的时间，请在些期间不要关闭本页！</td>
</tr>
<tr><td height=40 colspan=2 align=center><input type=button value='执行重新计数排序操作' onclick="javascript:location.href='?Action=Order&Chk=yes&ChannelIDs=<%=iChannelIDs%>';"></td></tr>
</table>
<%
    	     Exit Sub
	End If
	Dim ClassDepth,ccpa,ccch,cSql,cRs,ci,ccids,ccidss
	SQL = "Select Top 1 ClassDepth From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" Order By ClassDepth"
	Set Rs = Cls.Exec(SQL,1)
	If Rs.Eof Then
		     Rs.Close
		     Call AMH_Msg("暂时还没有分类！","?ChannelIDs="&iChannelIDs,1)
		     Exit Sub
	End If
	ClassDepth=Rs(0)
	Rs.Close
	If Not IsNumeric(ClassDepth) Then ClassDepth=0
	If Int(ClassDepth)>0 Then
		    Call AMH_Msg("分类出现严重错误！请与开发人员联系。","?ChannelIDs="&iChannelIDs,1)
		    Exit Sub
	End If
	classid=1
	SQL = "Select C_ID,ClassID From "&Data_Name&" Where ClassDepth="&ClassDepth&" And ChannelIDs="&iChannelIDs&" Order By ClassID,C_ID"
	Set Rs = Cls.Exec(SQL,1)
	Do While Not Rs.Eof
		    ccid=Rs("C_ID")
		    Call Cls.Exec("update "&Data_Name&" set ClassID="&classid&",ClassParent=0,ClassChild=0,ClassOrder=0,ClassDepth=0,ClassParentStr='"&ccid&"' where C_ID="&ccid,0)
		    Call Class_Order_Setup(classid,ccid,1,ccid,1,1)	
	Rs.MoveNext
	classid=classid+1
	Loop
	Rs.Close
	SQL = "Select c_id,ClassChildStr From "&Data_Name&" Where ChannelIDs="&iChannelIDs
	Call Cls.Exe_Conn(Rs,SQL,3)
    Do While Not Rs.Eof
	    ccids=Rs("C_ID")
        ccidss=""
	    cSQL = "Select C_ID From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" and Instr(','+ClassParentStr+',',',"&ccids&",')>0 Order By C_ID"
	    Set cRs = Cls.Exec(cSQL,1)
	    Do While Not cRs.Eof
		      if ccidss="" then
			  ccidss=cRs("C_ID")
			  else
		      ccidss=ccidss&","&cRs("C_ID")
			  end if
		      cRs.MoveNext
	    Loop
		cRs.Close
    	Rs("ClassChildStr")=ccidss
    	Rs.Update		
	    Rs.MoveNext
	Loop
	Rs.Close
	Call Cls.Cache_Del("Class_"&iChannelIDs)
	Call AMH_Msg("成功对所有分类进行了重新计数排序！","?ChannelIDs="&iChannelIDs,1)
End Sub
Sub Class_Order_Setup(cid,fID,oDepth,fParent,fOrder,fh)
	Dim oRs,oSQL
	Dim nfid,ffp,fhh,nf_id
	ffp=fparent&","
	If fparent="" Then
		ffp=""
	End If
	oSQL = "Select C_ID,ClassDepth From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassParent="&fid&" Order By ClassOrder,C_ID"
	Set oRs = Cls.Exec(oSQL,1)
	Do While Not oRs.Eof
		fhh=fh
	nfid=oRs("C_ID")
		Call Cls.Exec("Update "&Data_Name&" Set ClassID="&cid&",ClassParent="&fid&",ClassChild=0,ClassOrder="&forder&",ClassDepth="&oDepth&",ClassParentStr='"&ffp&nfid&"' Where ChannelIDs="&iChannelIDs&" And C_ID="&nfid,0)
		forder=forder+1
		Call Cls.Exec("Update "&Data_Name&" Set ClassChild=ClassChild+1 Where ChannelIDs="&iChannelIDs&" And ClassID="&cid&" And C_ID In("&fparent&")",0)
		Call Class_Order_Setup(cid,nfid,oDepth+1,ffp&nfid,forder,fhh)
		oRs.MoveNext
	Loop
	oRs.Close
	Set oRs=Nothing
End Sub
Sub AsaiMHClass_Orders()
	Dim oDepth,Actions
	Dim ClassParent,ClassOrder,ClassDepth,ClassParentStr
	Dim num1,num2,num3
	Actions=Cls.Code_Query("actions")
	If ccid<1 Or (Actions<>"up" And actions<>"Down") Then
		Call AMH_Msg("分类排序参数出错！","?ChannelIDs="&iChannelIDs,1)
		Exit Sub
	End If
	Call Cls.Cache_Del("Class_"&iChannelIDs)
	SQL = "Select Top 1 ClassID,ClassParent,ClassOrder,ClassDepth,ClassParentStr From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And C_ID="&ccid
	Set Rs = Cls.Exec(SQL,1)
	If Rs.Eof Then
		Rs.Close
		Call AMH_Msg("分类ID（"&ccid&"）不存在！","?ChannelIDs="&iChannelIDs,1)
		Exit Sub
	End If
	classid=rs("ClassID")
	ClassParent=rs("ClassParent")
	ClassOrder=rs("ClassOrder")
	ClassDepth=rs("ClassDepth")
	ClassParentStr=rs("ClassParentStr")
	Rs.Close
	SQL = "Select Top 1 ClassDepth From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" Order By ClassDepth"
	Set Rs = Cls.Exec(SQL,1)
	oDepth = Rs(0)
	Rs.Close
	If Int(ClassDepth)=Int(oDepth) Then
		num1=classid
		SQL="Select Top 1 ClassID From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassID>"&classid&" Order By ClassID"
		If Actions="up" Then
			SQL="Select Top 1 ClassID From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassID<"&classid&" Order By ClassID Desc"
		End If
		Set Rs=Cls.Exec(SQL,1)
		If Rs.Eof Then
			Rs.Close
			Call AsaiMHClass_Main()
			Exit Sub
		End If
		num2=Rs(0)
		Rs.Close
		SQL="Select Top 1 ClassID From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" Order By ClassID Desc"
		Set Rs=Cls.Exec(SQL,1)
		num3=Rs(0)+10000
		Rs.Close
		SQL="Update "&Data_Name&" Set ClassID="&num3&" Where ChannelIDs="&iChannelIDs&" And ClassID="&classid
		Call Cls.Exec(SQL,0)
		SQL="Update "&Data_Name&" Set ClassID="&classid&" Where ChannelIDs="&iChannelIDs&" And ClassID="&num2
		Call Cls.Exec(SQL,0)
		SQL="Update "&Data_Name&" Set ClassID="&num2&" Where ChannelIDs="&iChannelIDs&" And ClassID="&num3
		Call Cls.Exec(SQL,0)
		Call AsaiMHClass_Main()
		Exit Sub
	End If
	Dim ccid2,ClassOrder2,ClassParentStr2,fOrder1,fOrder2
	SQL="Select Top 1 C_ID,ClassOrder,ClassParentStr From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And ClassParent="&ClassParent&" And ClassDepth="&ClassDepth&" And C_ID<>"&ccid&" And ClassOrder>"&ClassOrder&" Order By ClassOrder"
	If Actions="up" Then
		SQL="Select Top 1 C_ID,ClassOrder,ClassParentStr From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And ClassParent="&ClassParent&" And ClassDepth="&ClassDepth&" And C_ID<>"&ccid&" And ClassOrder<"&ClassOrder&" Order By ClassOrder Desc"
	End If
	Set Rs=Cls.Exec(SQL,1)
	If Rs.Eof Then
		Rs.Close
		Call AsaiMHClass_Main()
		Exit Sub
	End If
	ccid2=rs("C_ID")
	ClassOrder2=rs("ClassOrder")
	ClassParentStr2=rs("ClassParentStr")
	Rs.Close
	SQL="Select Top 1 ClassOrder From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And ( Left(ClassParentStr,"&Len(ClassParentStr2)+1&")='"&ClassParentStr2&",' Or C_ID="&ccid2&" ) Order By ClassOrder Desc"
	Set Rs=Cls.Exec(SQL,1)
	fOrder2=Rs(0)
	Rs.Close
	SQL="Select Top 1 ClassOrder From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And ( Left(ClassParentStr,"&Len(ClassParentStr)+1&")='"&ClassParentStr&",' Or C_ID="&ccid&" ) Order By ClassOrder Desc"
	Set Rs=Cls.Exec(SQL,1)
	fOrder1=Rs(0)
	Rs.Close
	num1=fOrder1-ClassOrder+1
	num2=fOrder2-ClassOrder2+1
	SQL="Update "&Data_Name&" Set ClassOrder=ClassOrder"
	If Actions="up" Then
		SQL=SQL&"-"
	Else
		SQL=SQL&"+"
	End If
	SQL=SQL&num2&" Where ChannelIDs="&iChannelIDs&" And Left(ClassParentStr,"&Len(ClassParentStr)+1&")='"&ClassParentStr&",' Or C_ID="&ccid
	Call Cls.Exec(SQL,0)
	SQL="Update "&Data_Name&" Set ClassOrder=ClassOrder"
	If Actions="up" Then
		SQL=SQL&"+"
	Else
		SQL=SQL&"-"
	End If
	SQL=SQL&num1&" Where ChannelIDs="&iChannelIDs&" And Left(ClassParentStr,"&Len(ClassParentStr2)+1&")='"&ClassParentStr2&",' Or C_ID="&ccid2
	Call Cls.Exec(SQL,0)
	Call AsaiMHClass_Main()
End Sub

Sub AsaiMHClass_Update()
  If iChannelIDs<0 then Call AMH_Msg("错误的ID，请返回！","?ChannelIDs="&iChannelIDs,1)
  Dim CF,ClassJs
  Set Cf=New Cls_FileSystem
  ClassJs = Cls.GetClassMenu(iChannelIDs)
  Cf.Create_File Cls.Web_Dir&Cls.ChannelDir&"/Menu.js",ClassJs
  Call AMH_Msg("成功更新的网站分类菜单！","?ChannelIDs="&iChannelIDs,1)
End Sub

Sub AsaiMHClass_Edit()
    Dim rs3
	Dim funder,ftrue,fir_true,fDepth
	Dim ClassName,ClassDir,ClassParent,ClassParentStr,ClassOrder,ClassParentStr2,fDepth2,ClassOrder2,ClassOrders
	Dim Bbstype,Bbspro,Bbshidden,fhidden,rs2,cFir,ccid2,classid2,fhn,HtmlFileDir,CHtmlFileDir,QHtmlFileDir,QHtmlFileDir2
	fhidden=False
	funder=False
	ftrue=False
	fir_true=false
	SQL="Select Count(C_ID) From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassParent="&ccid
	Set Rs=Cls.Exec(SQL,1)
	If Int(Rs(0))>0 Then funder=True
	Rs.Close
	SQL="Select Top 1 * From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And C_ID="&ccid
	Call Cls.Exe_Conn(Rs,SQL,3)
	If Rs.Eof Then
		Rs.Close
		Call AMH_Msg("分类ID（"&ccid&"）不存在！","?ChannelIDs="&iChannelIDs,1)
		Exit Sub
	End If
	ClassName=Rs("ClassName")
	CHtmlFileDir=rs("ClassDir")
	QHtmlFileDir=Trim(rs("HtmlFileDir"))
	QHtmlFileDir2=Left(QHtmlFileDir,(len(QHtmlFileDir)-len(CHtmlFileDir)-1))
	If Rs("ClassDepth")=0 And Cstr(Rs("ClassDepth"))="0" Then fir_true=True '一级分类
	If Chk() Then
		classid=rs("ClassID")
		ClassParent=rs("ClassParent")
		ClassParentStr=rs("ClassParentStr")
		ClassOrders=rs("ClassOrder")
		ccid2=Cls.Code_Int("c_id",ccid) '新的父类
		ClassName=Cls.Code_Admin("classname",1,20)
		ClassDir=Cls.Code_Admin("ClassDir",1,0)
		If ClassName="" or ClassDir="" Then
			Rs.Close
			Call AMH_Error("分类名称不能为空！")
			Exit Sub
		End If
    	HtmlFileDir = Replace(Replace(Replace(trim(ClassDir), "\","/"), " ",""), "'","")
        If Not Cls.IsValidChar(HtmlFileDir) Then
		    Rs.Close
			Call AMH_Error("分类目录为空或者含有非英文字符！")
			Exit Sub
		End If
	    If Right(HtmlFileDir, 1) <> "/" Then
		HtmlFileDir = HtmlFileDir
	    Else
		HtmlFileDir = Left(HtmlFileDir,Len(HtmlFileDir)-1)
	    End If
	    If Left(HtmlFileDir, 1) = "/" Then
		    Rs.Close
			Call AMH_Error("目录前面不能有“/”，请认真填写分类目录！")
			Exit Sub		
	    End If		
		Rs("ClassName")=ClassName
		Rs("ClassDir")=HtmlFileDir
		HtmlFileDir = QHtmlFileDir2 & HtmlFileDir & "/"
	    Rs("HtmlFileDir")=HtmlFileDir
		'一级分类
		If ccid2=0 then
		SQL="Select Max(ClassID) From "&Data_Name&" Where ChannelIDs="&iChannelIDs
			Set Rs3=Cls.Exec(SQL,1)
			If Not Rs3.Eof Then Classid2=Rs3(0)
			Rs3.Close
			Rs("ClassOrder")=0
			Rs("ClassDepth")=0
			Rs("ClassID")=Classid2+1
			Rs("ClassParent")=0
			Rs("ClassChild")=0
			Rs("ClassParentStr")=ccid
			Rs("ClassChildStr")=ccid
			ClassOrder=0		
		End if
		Rs.Update
		Rs.Close
		If fTrue=True Then
		  If ccid2>0 then
		    '更新子类数量(当前)
			Call Cls.Exec("Update "&Data_Name&" Set ClassChild=ClassChild+1 Where ChannelIDs="&iChannelIDs&" And ClassID="&classid2&" And C_ID In("&ClassParentStr2&")",0)
		  End if
		    '更新子类数量（原来）
			Call Cls.Exec("Update "&Data_Name&" Set ClassChild=ClassChild-1 Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And C_ID In("&ClassParentStr&")",0)
			'更新子分类
			dim ccids,ccidss,cSQL,cRs
	SQL = "Select c_id,ClassChildStr From "&Data_Name&" Where (ClassID="&classid&" or ClassID="&classid2&") And ChannelIDs="&iChannelIDs
	Call Cls.Exe_Conn(Rs,SQL,3)
    Do While Not Rs.Eof
	    ccids=Rs("C_ID")
        ccidss=""
	    cSQL = "Select C_ID From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" and Instr(','+ClassParentStr+',',',"&ccids&",')>0 Order By C_ID"
	    Set cRs = Cls.Exec(cSQL,1)
	    Do While Not cRs.Eof
		      if ccidss="" then
			  ccidss=cRs("C_ID")
			  else
		      ccidss=ccidss&","&cRs("C_ID")
			  end if
		      cRs.MoveNext
	    Loop
		cRs.Close
    	Rs("ClassChildStr")=ccidss
    	Rs.Update		
	    Rs.MoveNext
	Loop
	Rs.Close
			'更新原分类的排序
		  Call Cls.Exec("Update "&Data_Name&" Set ClassOrder=ClassOrder-1 Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And ClassOrder>"&ClassOrders,0)
		End If
		'转移目录
		If lcase(QHtmlFileDir) <> lcase(HtmlFileDir) then
		    Dim Cfs
		    Set Cfs=New Cls_FileSystem
		        Cfs.Move_Folder Cls.Web_Dir & Cls.ChannelDir&"/"&QHtmlFileDir,Cls.Web_Dir & Cls.ChannelDir&"/"&HtmlFileDir
		    Set Cfs=Nothing
        End If
		Call AMH_Msg("成功编辑了分类（"&ClassName&"）信息！","?ChannelIDs="&iChannelIDs,1)
		Exit Sub
	End If
	Call Form_First()
%>
<form action='?Action=Edit&ChannelIDs=<%Response.Write iChannelIDs%>&C_ID=<%Response.Write ccid%>' method=post>
<input type=hidden name='chk' value='yes'>
<tr><td><%Response.Write Cls.ChannelName%>分类名称：</td><td><input type=text name=classname value='<%Response.Write ClassName%>' size=30 maxlength=20></td></tr>
<tr><td><%Response.Write Cls.ChannelName%>分类目录：</td><td><input type=text name=ClassDir Value="<%=CHtmlFileDir%>" size=30 maxlength=20></td></tr>
<tr><td>所属分类：</td><td>
<%
	If funder=True Then
		Response.Write "<font class=red2>本分类有下级分类，不可更改所属分类</font><input type=hidden name=C_ID value='"&ccid&"'>"
	Else
	    if fir_true then ccid=0
		Call Class_Add_Edit_List(ccid)
	End If
%></td></tr>
<%
	Call Submit_Edit()
	Rs.Close
End Sub
Sub Class_Add_Edit_List(fid)
	Dim temp1,nfid,ncid,ClassChild,rsf,sqlf
	ncid=0
	temp1="<select name=c_id size=1><option value='0'>作为一级分类</option>"
	sqlf="select C_ID,ClassID,ClassName,ClassChild,ClassDepth from "&Data_Name&" where ChannelIDs="&iChannelIDs&" order by ClassID,ClassOrder,ClassDepth"
	set rsf=Cls.exec(sqlf,1)
	do while not rsf.eof
		classid=rsf("ClassID")
		nfid=rsf("C_ID")
		if int(ncid)<>int(classid) then
			temp1=temp1&vbcrlf&"<option class=bg_2 value='"&nfid&"'"
			if int(nfid)=int(fid) then temp1=temp1&" selected"
			temp1=temp1&">"&rsf("ClassName")&"</option>"
			ncid=classid
		else
			'ClassChild=rsf("ClassChild")
			temp1=temp1&vbcrlf&"<option value='"&nfid&"'"
			if int(nfid)=int(fid) then temp1=temp1&" selected"
			temp1=temp1&">"
			for i=1 to rsf("ClassDepth")-1
				temp1=temp1&"│"
			next
			temp1=temp1&"├"&rsf("ClassName")
			temp1=temp1&"</option>"
		End If
		rsf.movenext
	loop
	rsf.close
	set rsf=nothing
	temp1=temp1&"</select>"
	Response.Write temp1
End Sub
Sub AsaiMHClass_Add()
	Dim NewClassID,Pid
	Pid=Cls.Code_ID("Pid")
	SQL = "SELECT MAX(C_ID) FROM AsaiMHClass"
	Set Rs = Cls.Exec(SQL,1)
	If Rs.bof And Rs.EOF Then
		NewClassID = 1
	Else
		NewClassID = Rs(0) + 1
	End If
	If IsNull(NewClassID) Then NewClassID = 1
	Rs.Close	
	Dim ClassName,cFir,ClassDepth,ClassParentStr,ClassOrder,fo_id,firid,HtmlFileDir,CHtmlFileDir
	classid=1
	SQL="Select Top 1 ClassID From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" Order By ClassID"
	Set Rs=Cls.Exec(SQL,1)
	If Not Rs.Eof Then classid=Rs(0)-1
	Rs.Close
	ClassParentStr=""
	ClassOrder=-1
	cFir=0
	Call AMH_Td("添加"&Tit_fir)
	If Chk() Then
		classid=0
		ccid=Cls.Code_Form("c_id")
		If Not Cls.Is_Int(ccid) Then ccid=0
		If Int(ccid)<1 Then
			SQL="Select Top 1 ClassID From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" Order By ClassID Desc"
			Set Rs=Cls.Exec(SQL,1)
			If Not Rs.Eof Then classid=Rs(0)
			Rs.Close
			classid=classid+1
		Else
			SQL="Select Top 1 ClassID,ClassOrder,ClassDepth,ClassParentStr,HtmlFileDir From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And C_ID="&ccid
			Set Rs=Cls.Exec(SQL,1)
			If Rs.Eof Then
				Rs.Close
				Call AMH_Msg("所属分类ID（"&ccid&"）不存在！","?ChannelIDs="&iChannelIDs,1)
				Exit Sub
			End If
			classid=Rs("ClassID")
			ClassOrder=Rs("ClassOrder")
			ClassDepth=Rs("ClassDepth")
			ClassParentStr=Rs("ClassParentStr")
			CHtmlFileDir=Rs("HtmlFileDir")
			Rs.close
			cFir=ccid
			fo_id=ccid
			SQL="Select Top 1 C_ID,ClassOrder From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And Left(ClassParentStr,"&(Len(ClassParentStr)+1)&")='"&ClassParentStr&",' Order By ClassOrder Desc"
			Set Rs=Cls.Exec(SQL,1)
			If Not Rs.Eof Then
				fo_id=Rs(0)
				ClassOrder=Rs(1)
			End If
			Rs.Close
		End If
	    ClassName=Cls.Code_Admin("ClassName",1,20)
		If ClassName="" Then
			Call AMH_Error("分类名称不能为空！")
			Exit Sub
		End If
    	HtmlFileDir = Replace(Replace(Replace(Request.Form("ClassDir"), "\","/"), " ",""), "'","")
        If Not Cls.IsValidChar(HtmlFileDir) Then
			Call AMH_Error("分类目录为空或者含有非英文字符！")
			Exit Sub
		End If
	    If Right(HtmlFileDir, 1) <> "/" Then
		HtmlFileDir = HtmlFileDir
	    Else
		HtmlFileDir = Left(HtmlFileDir,Len(HtmlFileDir)-1)
	    End If
	    If Left(HtmlFileDir, 1) = "/" Then
			Call AMH_Error("目录前面不能有“/”，请认真填写分类目录！")
			Exit Sub		
	    End If		
		If Int(ccid)>0 Then
			SQL="Select Top 1 ClassOrder From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And ClassParent="&fo_id&" Order By ClassOrder Desc"
			Set Rs=Cls.Exec(SQL,1)
			If Not Rs.Eof Then ClassOrder=Rs(0)
			Rs.Close
			If Int(ccid)>0 Then Call Cls.Exec("Update "&Data_Name&" Set ClassOrder=ClassOrder+1 Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And ClassOrder>"&ClassOrder,0)
		End If
		SQL="Select * From "&Data_Name&""
		Call Cls.Exe_Conn(Rs,SQL,3)
		Rs.AddNew
		Rs("ClassID")=classid
		Rs("ClassOrder")=ClassOrder+1
		Rs("ClassParent")=cFir
		Rs("ClassChild")=0
		If Int(cFir)=0 Then
			Rs("ClassDepth")=0
		Else
			Rs("ClassDepth")=ClassDepth+1
		End If
		Rs("ClassName")=ClassName
		Rs("ChannelIDs")=iChannelIDs
		Rs("ClassDir")=Trim(HtmlFileDir)
		HtmlFileDir = CHtmlFileDir & HtmlFileDir & "/"
		Rs("HtmlFileDir")=Trim(HtmlFileDir)
		Rs("isUpdate")=True
		Rs.Update
		Rs.Close
	    firid=first_id(Data_Name,"C_ID")
		If Cls.Is_Null(ClassParentStr)<>"" Then
			Call Cls.Exec("Update "&Data_Name&" Set ClassParentStr='"&ClassParentStr&","&firid&"' Where ChannelIDs="&iChannelIDs&" And C_ID="&firid,0)
		Else
			Call Cls.Exec("Update "&Data_Name&" Set ClassParentStr='"&firid&"' Where ChannelIDs="&iChannelIDs&" And C_ID="&firid,0)
		End If
		If Cls.Is_Null(ClassParentStr)<>"" Then
			Call Cls.Exec("Update "&Data_Name&" Set ClassChild=ClassChild+1 Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And C_ID in ("&ClassParentStr&")",0)
		End If
		'更新子分类
		If Cls.Is_Null(ClassParentStr)<>"" Then
		Call Cls.Exec("Update "&Data_Name&" Set ClassChildStr=ClassChildStr+',"&firid&"' Where ChannelIDs="&iChannelIDs&" And ClassID="&classid&" And  C_ID in ("&ClassParentStr&")",0)
		End If
		Call Cls.Exec("Update "&Data_Name&" Set ClassChildStr='"&firid&"' Where ChannelIDs="&iChannelIDs&" And C_ID="&firid,0)
		Call Cls.Cache_Del("Class_"&iChannelIDs)
		'创建目录
		'Dim Cfs
		'Set Cfs=New Cls_FileSystem
		'If  Cfs.Chk_Exist(Cls.Web_Dir & Cls.ChannelDir&"/"&Trim(HtmlFileDir),0)=False Then Cfs.Make_Dir(Cls.Web_Dir & Cls.ChannelDir&"/"&Trim(HtmlFileDir))
		'Set Cfs=Nothing
		Call AMH_Msg("成功添加一个新的分类（"&ClassName&"）！","?ChannelIDs="&iChannelIDs,1)
		Exit Sub
	End If
	Call Form_First()
%>
<form action='?Action=Add&ChannelIDs=<%Response.Write iChannelIDs%>&c_id=<%Response.Write ccid%>' method=post>
<input type=hidden name='chk' value='yes'>
<tr><td><%Response.Write Cls.ChannelName%>分类名称：</td><td><input type=text name=ClassName size=30 maxlength=20></td></tr>
<tr><td><%Response.Write Cls.ChannelName%>分类目录：</td><td><input type=text name=ClassDir Value=<%=NewClassID%> size=30 maxlength=20></td></tr>
<tr><td>所属分类：</td><td><%Call Class_Add_Edit_List(Pid)%></td></tr>
<%
	Call Submit_Add()
End Sub
Sub AsaiMHClass_Main()
	Dim ClassName,nccid,ClassChild,ClassDepth,oclassid,foo,fi,cc,oFolder,up_Down,fos
	Dim iClassDepth
	oClassid=0
	iClassDepth = Int(Cls.Get_ChannelRes(iChannelIDs,19))
	If iClassDepth = 0 Then
		iClassDepth = "前台无限级分类模式"
	Else
		iClassDepth = "前台"&Cstr(iClassDepth)&" 级分类模式"
	End If
%>
<tr align=center>
<td width='60%' class=td>分类名称（<%=iClassDepth%>）</td>
<td width='40%' class=td>相关操作</td>
</tr>
<%
	SQL="Select C_ID,ClassID,ClassName,ClassChild,ClassDepth From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" Order By ClassID,ClassOrder,ClassDepth"
	Set Rs=Cls.Exec(SQL,1)
	Do While Not Rs.Eof
		nccid=Rs("C_ID")
		Classid=Rs("ClassID")
		ClassName=Rs("ClassName")
		ClassChild=Rs("ClassChild")
		ClassDepth=Rs("ClassDepth")
		fos=""
		foo=""
		up_Down=2
		cc="tr"
		If ClassDepth=0 Then
			up_Down=1
			cc="tr3"
			oFolder=img_admin("tree_folder0","")
		Else
			If ClassChild=0 Then
				foo=foo&img_admin("tree_minus","")
			Else
				foo=foo&img_admin("tree_plus","")
			End If
			For fi=2 To ClassDepth
				fos=fos&img_admin("tree_empty","")
			Next
			oFolder=img_admin("tree_folder1","")
		End If
		foo=fos&foo&oFolder
%>
<tr class=<%Response.Write cc%> align=center>
<td align=left><b><%Response.Write foo&ClassName%></b></font><%Response.Write "&nbsp;&nbsp;<font class=tims>("&ClassChild&")</font>"%></td>
<td>
<a href='?Action=Add&ChannelIDs=<%Response.Write iChannelIDs%>&Pid=<%Response.Write nccid%>'>添加子分类</a>&nbsp;
<a href='?Action=Edit&ChannelIDs=<%Response.Write iChannelIDs%>&c_id=<%Response.Write nccid%>'>编辑分类</a>&nbsp;
<a href='?Action=Del&ChannelIDs=<%Response.Write iChannelIDs%>&c_id=<%Response.Write nccid%>' onclick="javascript:return click_return('删除分类（<%Response.Write Cls.Code_Js(ClassName,1)%>）及其下属分类',0);">删除分类</a>&nbsp;&nbsp;
<a href='?c_id=<%Response.Write nccid%>&Action=Orders&ChannelIDs=<%Response.Write iChannelIDs%>&Actions=up'><%Response.Write img_admin("up_"&up_Down,"向上移动此分类")%></a>&nbsp;
<a href='?c_id=<%Response.Write nccid%>&Action=Orders&ChannelIDs=<%Response.Write iChannelIDs%>&Actions=Down'><%Response.Write img_admin("Down_"&up_Down,"向下移动此分类")%></a>
</td>
</tr>
<%
		Rs.MoveNext
	Loop
	Rs.Close
End Sub
Sub AsaiMHClass_Mod()
	Dim temp1,ftrue,fname1,fname2
	Dim iChannelDataName
	iChannelDataName = Cls.Get_ChannelRes(iChannelIDs,14)
	If iChannelDataName = "" Then
		Call AMH_Msg("无法确定频道所在数据库位置！","?ChannelIDs="&iChannelIDs,1)
		Exit Sub
	End If
	Call AMH_td("合并"&Cls.ChannelName&"分类数据")
	If Chk() Then
		Dim sel1,sel2
		sel1=Cls.Code_Form("sel_1")
		sel2=Cls.Code_Form("sel_2")
		If Not(IsNumeric(sel1)) Or Not(IsNumeric(sel2)) Then
			Response.Write "<tr><td align=center height=50 colspan=2><font class=red2>您没有选择要合并的分类！</font></td></tr>"
		Else
			sel1=Int(sel1)
			sel2=Int(sel2)
			ftrue=True
			SQL="Select ClassName From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And C_ID="&sel2
			Set Rs=Cls.Exec(SQL,1)
			If Rs.Eof Then
				ftrue=False
				Response.Write "<tr><td align=center height=50 colspan=2><font class=red2>转移分类ID（"&sel1&"）不存在！</font></td></tr>"
			Else
				fname1=rs(0)
			End If
			Rs.Close
			If ftrue=True Then
				SQL="Select ClassName From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" And C_ID="&sel1
				Set Rs=Cls.Exec(SQL,1)
				If Rs.Eof Then
					ftrue=False
					Response.Write "<tr><td align=center height=50 colspan=2><font class=red2>主分类ID（"&sel1&"）不存在！</font></td></tr>"
				Else
					fname2=rs(0)
				End If
				Rs.Close
			End If
			If ftrue=True Then
				sql="update "&ichanneldataname&" set classid="&sel2&" where classid="&sel1
				Call Cls.Exec(SQL,0)
				Call AMH_Msg("成功将分类（"&fname2&"）数据合并到分类（"&fname1&"）中！","?Action=Mod&ChannelIDs="&iChannelIDs,1)
				Exit Sub
			End If
		End If
		Response.Write "</table>"
	End If
	Call Form_First()
	temp1=Class_Mod_List()
%>
<form action='?Action=Mod&ChannelIDs=<%=iChannelIDs%>' method=post>
<input type=hidden name='chk' value='yes'>
<tr>
<td width='20%'>从分类：</td>
<td width='80%'><select name=sel_1><%Response.Write temp1%></select></td>
</tr>
<tr>
<td>合并到分类：</td>
<td><select name=sel_2><%Response.Write temp1%></select></td>
</tr>
<tr class=tr3>
<td></td>
<td><input type=submit value='开始合并'></td>
</tr>
</form>
<%
End Sub
Function Class_Mod_List()
	Dim temp1,ncid,ClassChild
	ncid=0
	SQL="Select C_ID,ClassID,ClassName,ClassChild,ClassDepth From "&Data_Name&" Where ChannelIDs="&iChannelIDs&" Order By ClassID,ClassOrder,ClassDepth"
	Set Rs=Cls.Exec(SQL,1)
	Do While Not Rs.Eof
		classid=Rs("ClassID")
		If Int(ncid)<>Int(classid) Then
			temp1=temp1&vbcrlf&"<option class=bg_2 value='"&Rs("C_ID")&"'>╋"&Rs("ClassName")&"</option>"
			ncid=classid
		Else
			temp1=temp1&vbcrlf&"<option value='"&Rs("C_ID")&"'>"
			For i=1 To Rs("ClassDepth")-1
				temp1=temp1&"│"
			Next
			temp1=temp1&"├"&Rs("ClassName")
			temp1=temp1&"</option>"
		End If
		Rs.MoveNext
	Loop
	Rs.Close
	Class_Mod_List=temp1
End Function
%>
