<!--#include file="../FreeJs/Cls_JS.asp" -->
<!--#include file="../Inc/Cls_RefreshJs.asp" -->
<%
'==============================================================================
'软件名称：风讯网站信息管理系统
'当前版本：Foosun Content Manager System 2.0 
'最新更新：2004.12
'==============================================================================
'商业注册联系：028-85098980-601,602 技术支持：028-85098980-606、607,客户支持：608
'产品咨询QQ：159410,655071,66252421
'技术支持:所有程序使用问题，请提问到bbs.foosun.net我们将及时回答您
'程序开发：风讯开发组 & 风讯插件开发组
'论坛支持：风讯在线论坛(http://bbs.foosun.net)
'官方网站：www.Foosun.net  演示站点：test.cooin.com    
'网站建设专区：www.cooin.com
'==============================================================================
'免费版本请在新闻首页保留版权信息，并做上本站LOGO友情连接
'==============================================================================

Dim NewsID,ClassID,DelTypeStr
NewsID = Request("NewsID")
ClassID = Request("ClassID")
Dim DelNewsSysRootDir
if SysRootDir = "" then
	DelNewsSysRootDir = ""
else
	DelNewsSysRootDir = "/" & SysRootDir
end if
if ClassID <> "" then
	DelTypeStr = "栏目"
elseif NewsID <> "" then
	DelTypeStr = "新闻"
else
	%>
	<script language="JavaScript">
	alert('参数传递错误');
	dialogArguments.location.reload();
	window.close();
	</script>
	<%
end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>删除栏目或者新闻</title>
</head>
<link href="../Inc/ModeWindow.css" rel="stylesheet">
<body>
<table width="100%" border="0" cellspacing="8" cellpadding="0">
 <form name="DelForm" method="post" action="">
  <tr> 
    <td width="21%">
<div align="center"><img src="../Images/Question.gif" width="39" height="37"></div></td>
    <td width="79%" colspan="2">彻底删除单击删除按钮，放入回收站单击回收站按钮。
      确定要删除此
        <% = DelTypeStr %>吗?
      <input name="OperateType" type="hidden" id="OperateType">
      <input name="Result" type="hidden" id="Result" value="Submit">
      <input name="NewsID" type="hidden" id="NewsID" value="<% = NewsID %>">
      <input name="ClassID" type="hidden" id="ClassID" value="<% = ClassID %>"></td>
    </tr>
  <tr> 
    <td colspan="3">
<div align="center">
          <input onClick="document.DelForm.OperateType.value='Del';" name="Submitsadf" type="submit" id="Submitsadf" value=" 删 除 ">
          <input onClick="document.DelForm.OperateType.value='Recycle';" type="submit" name="Submit2" value=" 回收站 ">
          <input type="button" onClick="window.close();" name="Submit3" value=" 取 消 ">
      </div></td>
    </tr>
 </form>
</table>
</body>
</html>
<%
Dim Result,MyFile
Set MyFile=Server.CreateObject("Scripting.FileSystemObject")
Result = Request.Form("Result")
if Result = "Submit" then
	Dim OperateType
	OperateType = Request.Form("OperateType")
	if OperateType = "Del" or OperateType = "Recycle" then
		if ClassID <> "" then
			DelClass ClassID,OperateType
		elseif NewsID <> "" then
			DelNews NewsID,OperateType
		else
			Alert "参数传递错误"
		end if
	else
		Alert "参数传递错误"
	end if
end if
Function DelClass(DelClassID,OpType)
	if Not JudgePopedomTF(Session("Name"),"P0102") then Call ReturnError()
	Dim DelClassIDArray,D_i
	DelClassIDArray = Array("")
	DelClassIDArray = Split(DelClassID,",")
	For D_i = 0 to UBound(DelClassIDArray)
		if JudgePopedomTF(Session("Name"),""&DelClassIDArray(D_i)&"") then 
			Dim AllClassID,Sql
			AllClassID = "'" & DelClassIDArray(D_i) & "'" & ChildClassIDList(DelClassIDArray(D_i))
			On Error Resume Next
			if OpType = "Del" then
				Sql = "Delete from News where ClassID in (" & AllClassID & ")"
				Conn.Execute(Sql)
				if Err.Number <> 0 then Alert "删除栏目下的新闻失败"
				Sql = "Delete from Contribution where ClassID in (" & AllClassID & ")"
				Conn.Execute(Sql)
				if Err.Number <> 0 then Alert "删除栏目下的投稿失败"
				Sql = "Delete from DownLoad where ClassID in (" & AllClassID & ")"
				Conn.Execute(Sql)
				if Err.Number <> 0 then Alert "删除栏目下的下载失败"
				'----------删除自由js中的相关记录及重新生成相关JS文件(FreeJsFile)----------
				Dim RsDelFreeJsObj,TempClassIDStr,FreeJsArr,FreeJsObj,Free_i
				TempClassIDStr = ""
				Set RsDelFreeJsObj = Conn.Execute("Select distinct JSName from FreeJsFile where ClassID in (" & AllClassID & ") ")
				do while Not RsDelFreeJsObj.eof
					If TempClassIDStr = "" then
						TempClassIDStr = RsDelFreeJsObj("JSName")
					Else
						TempClassIDStr = TempClassIDStr &","&RsDelFreeJsObj("JSName")
					End If
					RsDelFreeJsObj.MoveNext
				Loop
				RsDelFreeJsObj.Close
				Set RsDelFreeJsObj = Nothing
				Conn.Execute("Delete from FreeJsFile where ClassID in (" & AllClassID & ")")
				FreeJsArr = Array("")
				FreeJsArr = split(TempClassIDStr,",")
				For Free_i=0 to UBound(FreeJsArr)
					Set FreeJsObj = Conn.Execute("Select EName,Manner from FreeJS where EName='"&FreeJsArr(Free_i)&"'")
				  Select case FreeJsObj("Manner")
					 case "1"   WCssA FreeJsObj("EName"),True
					 case "2"   WCssB FreeJsObj("EName"),True
					 case "3"   WCssC FreeJsObj("EName"),True
					 case "4"   WCssD FreeJsObj("EName"),True
					 case "5"   WCssE FreeJsObj("EName"),True
					 case "6"   PCssA FreeJsObj("EName"),True
					 case "7"   PCssB FreeJsObj("EName"),True
					 case "8"   PCssC FreeJsObj("EName"),True
					 case "9"   PCssD FreeJsObj("EName"),True
					 case "10"   PCssE FreeJsObj("EName"),True
					 case "11"   PCssF FreeJsObj("EName"),True
					 case "12"   PCssG FreeJsObj("EName"),True
					 case "13"   PCssH FreeJsObj("EName"),True
					 case "14"   PCssI FreeJsObj("EName"),True
					 case "15"   PCssJ FreeJsObj("EName"),True
					 case "16"   PCssK FreeJsObj("EName"),True
					 case "17"   PCssL FreeJsObj("EName"),True
				   End Select
				   FreeJsObj.Close
				   Set FreeJsObj = Nothing
				Next
				if Err.Number <> 0 then Alert "删除栏目下的自由JS新闻失败"
				'---------删除栏目时删除系统JS中的相关记录及文件(SysJs)---------------------
				Dim RsSysJsObj
				Set RsSysJsObj = Conn.Execute("Select FileName,FileSavePath from SysJs where ClassID in ("&AllClassID&")")
				do while Not RsSysJsObj.eof
					If MyFile.FileExists(Server.Mappath(DelNewsSysRootDir&RsSysJsObj("FileSavePath"))&"/"&RsSysJsObj("FileName")&".js") then
						MyFile.DeleteFile(Server.Mappath(DelNewsSysRootDir&RsSysJsObj("FileSavePath"))&"/"&RsSysJsObj("FileName")&".js")
					End if
					RsSysJsObj.MoveNext
				loop
				RsSysJsObj.Close
				Set RsSysJsObj = Nothing
				Conn.Execute("Delete from SysJs where ClassID in ("&AllClassID&")")
				if Err.Number <> 0 then Alert "删除栏目的系统JS信息失败"
				'---------------------物理文件删除-------------------------------------
				Dim DelClassFileObj
				Set DelClassFileObj = Conn.Execute("Select ClassEName,SaveFilePath from NewsClass where ClassID in ("&AllClassID&")")
				Do while Not DelClassFileObj.eof
					If MyFile.FolderExists(Server.Mappath(DelNewsSysRootDir&DelClassFileObj("SaveFilePath")&"/"&DelClassFileObj("ClassEName"))) then
						MyFile.DeleteFolder(Server.Mappath(DelNewsSysRootDir&DelClassFileObj("SaveFilePath")&"/"&DelClassFileObj("ClassEName")))
					End if
					DelClassFileObj.MoveNext
				Loop
				DelClassFileObj.Close
				Set DelClassFileObj = Nothing
				'----------------------------------------------------------------------
				Sql = "Delete from NewsClass where ClassID in (" & AllClassID & ")"
				Conn.Execute(Sql)
				if Err.Number = 0 then
					Alert "删除成功"
				else
					Alert "删除失败"
				end if
			else
				'----------将自由js中的相关记录放入回收站及重新生成相关JS文件(FreeJsFile)----------
				TempClassIDStr = ""
				Set RsDelFreeJsObj = Conn.Execute("Select distinct JSName from FreeJsFile where ClassID in (" & AllClassID & ") ")
				do while Not RsDelFreeJsObj.eof
					If TempClassIDStr = "" then
						TempClassIDStr = RsDelFreeJsObj("JSName")
					Else
						TempClassIDStr = TempClassIDStr &","&RsDelFreeJsObj("JSName")
					End If
					RsDelFreeJsObj.MoveNext
				Loop
				RsDelFreeJsObj.Close
				Set RsDelFreeJsObj = Nothing
				Conn.Execute("Update FreeJsFile Set DelFlag=1 where ClassID in (" & AllClassID & ")")
				FreeJsArr = Array("")
				FreeJsArr = split(TempClassIDStr,",")
				For Free_i=0 to UBound(FreeJsArr)
					Set FreeJsObj = Conn.Execute("Select EName,Manner from FreeJS where EName='"&FreeJsArr(Free_i)&"'")
				  Select case FreeJsObj("Manner")
					 case "1"   WCssA FreeJsObj("EName"),True
					 case "2"   WCssB FreeJsObj("EName"),True
					 case "3"   WCssC FreeJsObj("EName"),True
					 case "4"   WCssD FreeJsObj("EName"),True
					 case "5"   WCssE FreeJsObj("EName"),True
					 case "6"   PCssA FreeJsObj("EName"),True
					 case "7"   PCssB FreeJsObj("EName"),True
					 case "8"   PCssC FreeJsObj("EName"),True
					 case "9"   PCssD FreeJsObj("EName"),True
					 case "10"   PCssE FreeJsObj("EName"),True
					 case "11"   PCssF FreeJsObj("EName"),True
					 case "12"   PCssG FreeJsObj("EName"),True
					 case "13"   PCssH FreeJsObj("EName"),True
					 case "14"   PCssI FreeJsObj("EName"),True
					 case "15"   PCssJ FreeJsObj("EName"),True
					 case "16"   PCssK FreeJsObj("EName"),True
					 case "17"   PCssL FreeJsObj("EName"),True
				   End Select
				   FreeJsObj.Close
				   Set FreeJsObj = Nothing
				Next
				if Err.Number <> 0 then Alert "删除栏目下的自由JS新闻失败"
				'---------删除栏目时删除系统JS中的相关记录及文件(SysJs)--------
				Set RsSysJsObj = Conn.Execute("Select FileName,FileSavePath from SysJs where ClassID in ("&AllClassID&")")
				do while Not RsSysJsObj.eof
					If MyFile.FileExists(Server.Mappath(DelNewsSysRootDir&RsSysJsObj("FileSavePath"))&"/"&RsSysJsObj("FileName")&".js") then
						MyFile.DeleteFile(Server.Mappath(DelNewsSysRootDir&RsSysJsObj("FileSavePath"))&"/"&RsSysJsObj("FileName")&".js")
					End if
					RsSysJsObj.MoveNext
				loop
				RsSysJsObj.Close
				Set RsSysJsObj = Nothing
				Conn.Execute("Delete from SysJs where ClassID in ("&AllClassID&")")
				if Err.Number <> 0 then Alert "删除栏目的系统JS信息失败"
				'-----------------------------------------------------------------
				Sql = "UpDate News Set DelTF=1,DelTime='"&Now()&"' where ClassID in (" & AllClassID & ")"
				Conn.Execute(Sql)
				if Err.Number <> 0 then Alert "栏目下的新闻放入回收站失败"
				Sql = "UpDate NewsClass Set DelFlag=1,DelTime='"&Now()&"' where ClassID in (" & AllClassID & ")"
				Conn.Execute(Sql)
				if Err.Number = 0 then
					Response.Write("<script>dialogArguments.self.location.reload();window.close();</script>")
				else
					Alert "放入回收站失败"
				end if
			end if
		End If
	Next
End Function
Function DelNews(DelNewsID,OpType)
	if Not JudgePopedomTF(Session("Name"),"P0110") then Call ReturnError()
	Dim Sql,RikerClassIDObj,TempRikerID,RikerFileName,RikerFreeJsFileObj,RikerCreaFreeJsEName,RikerCreaFreeJsManner
	On Error Resume Next
	Dim DelNewsIDArray,DN_i
	DelNewsIDArray = Array("")
	DelNewsIDArray = Split(DelNewsID,",")
	For DN_i = 0 to UBound(DelNewsIDArray)
		if OpType = "Del" then
		Sql = "Delete from News where NewsID='" & DelNewsIDArray(DN_i) & "'"
		'------------------------删除新闻物理文件-------------------
		Dim DelNewsClassFileObj,DelNewsFileObj
		Set DelNewsFileObj = Conn.Execute("Select FileName,FileExtName,ClassID from News where NewsID='"&DelNewsIDArray(DN_i)&"'")
		If Not DelNewsFileObj.eof then
			Set DelNewsClassFileObj = Conn.execute("Select ClassEName,SaveFilePath from NewsClass where ClassID='"&DelNewsFileObj("ClassID")&"'")
			If Not DelNewsFileObj.eof then
				If MyFile.FileExists(Server.Mappath(DelNewsSysRootDir&DelNewsClassFileObj("SaveFilePath")&"/"&DelNewsClassFileObj("ClassEName"))&"/"&DelNewsFileObj("FileName")&"."&DelNewsFileObj("FileExtName")) then
				   MyFile.DeleteFile(Server.Mappath(DelNewsSysRootDir&DelNewsClassFileObj("SaveFilePath")&"/"&DelNewsClassFileObj("ClassEName"))&"/"&DelNewsFileObj("FileName")&"."&DelNewsFileObj("FileExtName"))
				End if
			End If
		End If
		'------------自由JS相关删除及重新生成----------------
		Set RikerClassIDObj = Conn.Execute("Select ClassID,FileName from News where NewsID='"&DelNewsIDArray(DN_i)&"'")
		If Not RikerClassIDObj.eof then
			TempRikerID = RikerClassIDObj("ClassID")
			RikerFileName = RikerClassIDObj("FileName")
		End If
		RikerClassIDObj.Close
		Set RikerClassIDObj = Nothing
		
		Conn.Execute(Sql) '删除新闻
		
		Set RikerFreeJsFileObj = Conn.Execute("Select EName,Manner from FreeJS where EName in (Select JSName from FreeJsFile where FileName='"&RikerFileName&"')")
		RikerCreaFreeJsEName = ""
		RikerCreaFreeJsManner = ""
		do while Not RikerFreeJsFileObj.eof
		If RikerCreaFreeJsEName = "" then
			RikerCreaFreeJsEName = RikerFreeJsFileObj("EName")
			RikerCreaFreeJsManner = RikerFreeJsFileObj("Manner")
		Else
			RikerCreaFreeJsEName = RikerCreaFreeJsEName &","& RikerFreeJsFileObj("EName")
			RikerCreaFreeJsManner = RikerCreaFreeJsManner &","& RikerFreeJsFileObj("Manner")
		End If
			RikerFreeJsFileObj.MoveNext
		loop
		RikerFreeJsFileObj.Close
		Set RikerFreeJsFileObj = Nothing
		Conn.execute("Delete from FreeJsFile where FileName='"&RikerFileName&"'")
		Dim RikerENameArr,RikerMannerArr,Riker_i
		RikerENameArr = Array("")
		RikerMannerArr = Array("")
		RikerENameArr = split(RikerCreaFreeJsEName,",")
		RikerMannerArr = split(RikerCreaFreeJsManner,",")
		For Riker_i=0 to UBound(RikerMannerArr)
			Select case RikerMannerArr(Riker_i)
				case "1"   WCssA RikerENameArr(Riker_i),True
				case "2"   WCssB RikerENameArr(Riker_i),True
				case "3"   WCssC RikerENameArr(Riker_i),True
				case "4"   WCssD RikerENameArr(Riker_i),True
				case "5"   WCssE RikerENameArr(Riker_i),True
				case "6"   PCssA RikerENameArr(Riker_i),True
				case "7"   PCssB RikerENameArr(Riker_i),True
				case "8"   PCssC RikerENameArr(Riker_i),True
				case "9"   PCssD RikerENameArr(Riker_i),True
				case "10"   PCssE RikerENameArr(Riker_i),True
				case "11"   PCssF RikerENameArr(Riker_i),True
				case "12"   PCssG RikerENameArr(Riker_i),True
				case "13"   PCssH RikerENameArr(Riker_i),True
				case "14"   PCssI RikerENameArr(Riker_i),True
				case "15"   PCssJ RikerENameArr(Riker_i),True
				case "16"   PCssK RikerENameArr(Riker_i),True
				case "17"   PCssL RikerENameArr(Riker_i),True
			End Select
		Next
		'-----------------------------------------------------------
		else
			Sql = "Update News Set DelTF=1,DelTime='"&Now()&"' where NewsID='" & DelNewsIDArray(DN_i) & "'"
			Conn.Execute(Sql)
			'------------自由JS相关删除及重新生成----------------
			Set RikerClassIDObj = Conn.Execute("Select ClassID,FileName from News where NewsID='"&DelNewsIDArray(DN_i)&"'")
			If Not RikerClassIDObj.eof then
				TempRikerID = RikerClassIDObj("ClassID")
				RikerFileName = RikerClassIDObj("FileName")
				Conn.execute("Update FreeJsFile set DelFlag=1 where FileName='"&RikerFileName&"'")
				'------------------重新生成相关系统栏目JS------------
				Dim RikerSysObj
				Set RikerSysObj = Conn.Execute("Select FileName from SysJs where ClassID='"&TempRikerID&"'")
				If Not RikerSysObj.eof then
					CreateSysJS(RikerSysObj("FileName"))
				End If
				'------------------系统总JS相关------------
				'考虑中......
				'------------------自由JS------------------
				Set RikerFreeJsFileObj = Conn.Execute("Select EName,Manner from FreeJS where EName in (Select JSName from FreeJsFile where FileName='"&RikerFileName&"')")
				Do while Not RikerFreeJsFileObj.eof
					RikerCreaFreeJsEName = RikerFreeJsFileObj("EName")
					RikerCreaFreeJsManner = RikerFreeJsFileObj("Manner")
					Select case RikerCreaFreeJsManner
						case "1"   WCssA RikerCreaFreeJsEName,True
						case "2"   WCssB RikerCreaFreeJsEName,True
						case "3"   WCssC RikerCreaFreeJsEName,True
						case "4"   WCssD RikerCreaFreeJsEName,True
						case "5"   WCssE RikerCreaFreeJsEName,True
						case "6"   PCssA RikerCreaFreeJsEName,True
						case "7"   PCssB RikerCreaFreeJsEName,True
						case "8"   PCssC RikerCreaFreeJsEName,True
						case "9"   PCssD RikerCreaFreeJsEName,True
						case "10"   PCssE RikerCreaFreeJsEName,True
						case "11"   PCssF RikerCreaFreeJsEName,True
						case "12"   PCssG RikerCreaFreeJsEName,True
						case "13"   PCssH RikerCreaFreeJsEName,True
						case "14"   PCssI RikerCreaFreeJsEName,True
						case "15"   PCssJ RikerCreaFreeJsEName,True
						case "16"   PCssK RikerCreaFreeJsEName,True
						case "17"   PCssL RikerCreaFreeJsEName,True
					End Select
					RikerFreeJsFileObj.MoveNext
				Loop
				RikerFreeJsFileObj.Close
				Set RikerFreeJsFileObj = Nothing
			End If
			RikerClassIDObj.Close
			Set RikerClassIDObj = Nothing
		end if
	Next
	'------------------------------------------
	if Err.Number = 0 then
		Response.Write("<script>dialogArguments.location.reload();window.close();</script>")
		Response.End
	else
		Response.Write("<script>alert(""删除失败"");window.close();</script>")
		Response.End
	end if
End Function
Function ChildClassIDList(ClassID)
	Dim TempRs,TempStr
	Set TempRs = Conn.Execute("Select ClassID from NewsClass where ParentID = '" & ClassID & "'")
	do while Not TempRs.Eof
		ChildClassIDList = ChildClassIDList & ",'" & TempRs("ClassID") & "'"
		ChildClassIDList = ChildClassIDList & ChildClassIDList(TempRs("ClassID"))
		TempRs.MoveNext
	loop
	TempRs.Close
	Set TempRs = Nothing
End Function
Function Alert(InfoStr)
%>
<script language="JavaScript">
alert('<% = InfoStr %>');
dialogArguments.self.location.reload();
window.close();
</script>
<%
End Function
Set MyFile=nothing
Set Conn = Nothing
%>
