<!--#include file="../inc/config.asp" -->
<!--#include file="../inc/conn.asp" -->
<!--#include file="inc/function.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p01")
'''''''''''''''''''''''''''''''''''''''''''''''
Dim id,newsarr,newsid,savepath
Dim catalogSaveUrl,catalogType,catalogFileExt
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if(request.QueryString("id")<>"") then
	id=Cint(request.QueryString("id"))
	set rs=server.createobject("adodb.recordset")
	rs.open "select flag,savedir from catalogs where id="&id,conn,3,1
	if not rs.eof and not rs.bof then
		catalogType=Cbool(rs("flag"))
		if(catalogType=true) then
			catalogFileExt="index.htm"
		else
			catalogFileExt="index_1.htm"
		end if
		catalogSaveUrl=rs("savedir")
	end if
	rs.close
	set rs=nothing
	'删除栏目生成的目录及文件
	if catalogSaveUrl<>"" and catalogSaveUrl<>"/" then
		if(fso.FileExists(server.MapPath(catalogSaveUrl&"/"&catalogFileExt))) then
			fso.DeleteFile(server.MapPath(catalogSaveUrl&"/"&catalogFileExt))		
		end if
		if(fso.FolderExists(server.MapPath(catalogSaveUrl))) then
			fso.DeleteFolder server.MapPath(catalogSaveUrl)
		end if
	end if
	conn.execute("delete from catalogs where id="&id)
	set rs=server.createobject("adodb.recordset")
	rs.open "select id,pagepath,isoutlink from news where classid="&id,conn,3,1
	if not rs.eof and not rs.bof then
		newsarr=rs.GetRows()
		rs.close
		set rs=nothing
		
		for i=0 to ubound(newsarr,2)
			newsid=newsarr(0,i)
			savepath=newsarr(1,i)
			isoutlink=newsarr(2,i)
			if(isoutlink=0) then
				if not fso.FileExists(server.MapPath("../"&savepath)) then  
 					Response.Write("<h1>Error:</h1>" & server.MapPath("../"&savepath)&" does not exist<p>") 							
 				else
 					fso.DeleteFile(server.MapPath("../"&savepath))
 					'Response.Write("<h1>成功删除文件:</h1>" & server.MapPath("../"&savepath))
 				end if
			end if
			conn.execute("delete from news where id="&newsid)
		next
		
	else
		rs.close
		set rs=nothing
	end if
	response.Write("<script>alert(""成功删除栏目！"");location.href=""tree.asp"";</script>")
else
	response.Write("<script>alert(""没有此栏目！"");location.href=""tree.asp"";</script>")
end if
set fso=nothing	
%>
<!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>

<body>
</body>
</html>
<%
call connclose()
%>