<!--#include file="../../fy.Function.asp"-->
<%

	Dim ModeID
	 ModeID = ChkNumeric(Request("ModeID"))
	 if ModeID=0 or ModeID="" Then ModeID=1
	If Not fycms.fycms_QXYZ(ModeID,"","") Then   Call fycms.Alert("对不起，您没有"&fycms.ACT_C(ModeID,1)&"系该项操作权限！","")
	Select Case Request("Action")
			Case "del"
				Call DelClass()
	End Select

	Sub DelClass()
	Dim DelcidStr,DelAllcidStr,Class_Num,Class_i,CheckTopClassRs
	Dim Str_Delcid,ArrC_i,DleClassObj,ArrC_Num
	DelcidStr =  Request("cid")

	If DelcidStr = "" Then
 			Call fycms.ActErr("请选择栏目","","1")
		Response.end
	End If 
		If Instr(DelcidStr,",") > 0 Then
			DelcidStr = Replace(Replace(DelcidStr," ,",","),", ",",")
			Class_Num = Split(DelcidStr,",")
			For Class_i = LBound(Class_Num) To UBound(Class_Num)
				Set CheckTopClassRs = fycms.ACTEXE("Select rootid,cid From bookclass_fy Where cid = " & Class_Num(Class_i) & " Order By OrderID Desc,ID Desc")
				If CheckTopClassRs(0) <> "0" Then
					If InStrTopIDTF(Class_Num(Class_i),DelcidStr) = True Then
						DelcidStr = Replace(DelcidStr,"," & Class_Num(Class_i),"")
					End If
				End If
				CheckTopClassRs.CLose : Set CheckTopClassRs = Nothing	
			Next
			Str_Delcid = DelcidStr
			ArrC_Num = Split(Str_Delcid,",")
			For ArrC_i = LBound(ArrC_Num) To Ubound(ArrC_Num)
				DelAllcidStr = DelAllcidStr & "," & GetAllChildRencid(ArrC_Num(ArrC_i))
			Next
		Else
			DelAllcidStr = GetAllChildRencid(DelcidStr)
		End If
		If Left(DelAllcidStr,1) = "," Then
			DelAllcidStr = Right(DelAllcidStr,Len(DelAllcidStr) - 1)
		End If
			
		Set DleClassObj = fycms.actexe("Select * From bookclass_fy Where cid In(" & DelAllcidStr & ")")
		While Not DleClassObj.Eof
 			fycms.actexe("Delete From  bookclass_fy Where cid =" & DleClassObj("cid") & "")
			DleClassObj.MoveNext		
		Wend
		Call fycms.ActErr("栏目下所有的文件均已删除","Sys_fy/book/index.asp?ModeID="&ModeID&"","")
  	End Sub
	
 
	Function GetAllChildRencid(cid)
	If cid = "" Then Exit Function
	Dim GetcidRs,Allcid
	Set GetcidRs = Conn.ExeCute("Select cid From bookclass_fy Where rootid = "&cid&" Order By OrderID Desc,ID Desc") 
	If GetcidRs.Eof Then
		Allcid =  cid 
	Else
		Allcid = ""
		Do While Not GetcidRs.Eof
			Allcid = Allcid & "," & GetAllChildRencid(GetcidRs(0))
			GetcidRs.MoveNext
		Loop
		Allcid =   cid  & Allcid
	End If
	GetAllChildRencid = Allcid
	GetcidRs.Close
	Set GetcidRs = Nothing				
	End Function


Function InStrTopIDTF(cid,InStrID)
	Dim GetTopIDRs,StrID,ArrIDNum,Arr_i,InstrNum
	Set GetTopIDRs = Conn.ExeCute("Select rootid,cid From bookclass_fy Where cid="& cid &"  Order By OrderID Desc,ID Desc")
	If Not GetTopIDRs.Eof Then
		Do While GetTopIDRs(0) <> "0"
			Set GetTopIDRs = Conn.ExeCute("Select rootid,cid From bookclass_fy Where cid = " & GetTopIDRs(0) & " Order By OrderID Desc,ID Desc")
			StrID = StrID & "," & GetTopIDRs(1)
		Loop
	End If
	GetTopIDRs.Close : Set GetTopIDRs = Nothing
	StrID = Replace(Replace(StrID," ,",","),", ",",")
	If Left(StrID,1) = "," Then
		StrID = Right(StrID,Len(StrID) - 1)
	End If
	If Instr(StrID,",") > 0 Then
		ArrIDNum = Split(StrID,",")
		For Arr_i = LBound(ArrIDNum) To UBound(ArrIDNum)
			InstrNum = Clng(InstrNum + Instr(InStrID,ArrIDNum(Arr_i)))
		Next
	Else
		InstrNum = Instr(InStrID,StrID)
	End If	
	If InstrNum > 0 Then
		InStrTopIDTF = True
	Else
		InStrTopIDTF = False
	End If
End Function


 %>