<% Option Explicit %>
<!--#include file="../../Inc/Const.asp" -->
<!--#include file="../../Inc/Cls_DB.asp" -->
<%
Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P0107") then Call ReturnError()
Dim OperateType,ID
Dim Sql,RsTempObj,PromptInfo
OperateType = Request("OperateType")
ID = Request("ID")
Dim RecSysRootDir
if SysRootDir = "" then
	RecSysRootDir = ""
else
	RecSysRootDir = "/" & SysRootDir
end if

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<link href="../Inc/ModeWindow.css" rel="stylesheet">
<body scrolling=no>
<table width="100%" border="0" cellspacing="5" cellpadding="0">
  <tr> 
    <td width="30%" align="center"><img src="../Images/Question.gif" width="39" height="37"> 
</td>
    <td width="70%" align="center"><div align="left">
        <%
if OperateType = "Class" then
	Response.Write("确定要删除此栏目吗？")
elseif OperateType = "News" then
	Response.Write("确定要删除此新闻吗？")
else
	Alert "参数传递错误"
end if
%>
    </div></td>
  </tr>
  <tr> 
    <td colspan="2"><div align="center"> 
        <input onClick="SubmitFun();" type="button" name="Submit" value=" 确 定 ">
        <input type="button" onClick="window.close();" name="Submit2" value=" 取 消 ">
      </div></td>
  </tr>
</table>
</body>
</html>
<%
Dim Result
Result = Request("Result")
if Result = "Submit" then
	if OperateType = "Class" then
		DelClass ID
	elseif OperateType = "News" then
		DelNews ID
	else
		Alert "参数传递错误"
	end if
end if
Set RsTempObj = Nothing
Set Conn = Nothing
%>
<script language="JavaScript">
function SubmitFun()
{
	window.location='?OperateType=<% = OperateType%>&ID=<% = ID %>&Result=Submit';
}
</script>
<%
Function DelClass(DelClassID)
	Dim AllClassID,Sql
	AllClassID = "'" & DelClassID & "'" & ChildClassIDList(DelClassID)
	On Error Resume Next
	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 "删除栏目下的下载失败"
	Conn.Execute("Delete from SysJs where ClassID in ("& AllClassID &")")
	If Err.Number <> 0 then Alert "删除栏目的系统JS失败"
	Conn.Execute("Delete from FreeJsFile where ClassID in (" & AllClassID & ")")
	If Err.Number <> 0 then Alert "删除栏目的相关自由JS失败"
	'-------------删除物理文件-----------
	Dim MyFile,DDelClassObj
	Set MyFile=Server.CreateObject("Scripting.FileSystemObject")
	Set DDelClassObj = Conn.Execute("Select SaveFilePath,ClassEName from NewsClass where ClassID in (" & AllClassID & ")")
	Do while Not DDelClassObj.eof
		If MyFile.FolderExists(Server.Mappath(RecSysRootDir&DDelClassObj("SaveFilePath")&"/"&DDelClassObj("ClassEName"))) then
			MyFile.DeleteFolder(Server.Mappath(RecSysRootDir&DDelClassObj("SaveFilePath")&"/"&DDelClassObj("ClassEName")))
		End if
		DDelClassObj.MoveNext
	Loop
	DDelClassObj.Close
	Set DDelClassObj = Nothing
	Set MyFile = Nothing
	'------------------------------------
	Sql = "Delete from NewsClass where ClassID in (" & AllClassID & ")"
	Conn.Execute(Sql)
	if Err.Number = 0 then
		Alert "删除成功"
	else
		Alert "删除失败"
	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 DelNews(DelNewsID)
	Dim Sql,MyFile
	Set MyFile=Server.CreateObject("Scripting.FileSystemObject")
	Sql = "Delete from News where NewsID='" & DelNewsID & "'"
	On Error Resume Next
	Conn.Execute("Delete from FreeJsFile where FileName=(Select FileName from News where NewsID='" & DelNewsID & "')")
	
	'------------------------删除新闻物理文件-------------------
	Dim DelNewsClassFileObj,DelNewsFileObj
	Set DelNewsFileObj = Conn.Execute("Select FileName,FileExtName,ClassID from News where NewsID='"&DelNewsID&"'")
	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(RecSysRootDir&DelNewsClassFileObj("SaveFilePath")&"/"&DelNewsClassFileObj("ClassEName"))&"/"&DelNewsFileObj("FileName")&"."&DelNewsFileObj("FileExtName")) then
			   MyFile.DeleteFile(Server.Mappath(RecSysRootDir&DelNewsClassFileObj("SaveFilePath")&"/"&DelNewsClassFileObj("ClassEName"))&"/"&DelNewsFileObj("FileName")&"."&DelNewsFileObj("FileExtName"))
			End if
		End If
	End If
	
	Conn.Execute(Sql)
	if Err.Number = 0 then
		Alert "删除成功"
	else
		Alert "删除失败"
	end if
	Set MyFile = Nothing
End Function
Function Alert(InfoStr)
%>
<script language="JavaScript">
alert('<% = InfoStr %>');
dialogArguments.location.reload();
window.close();
</script>
<%
End Function
%>