<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/function.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
'Server.ScriptTimeout = 999999
on error resume next
response.Charset="GB2312"
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p05")
'''''''''''''''''''''''''''''''''''''''''''''''
dim id,rs1,robotadd
if not isempty(request("id")) then 
	id=Clng(request.QueryString("id"))
else
	id=1
end if

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim pagepath,news_class,photo,author,editor,imgnews,newsfrom,hot,recomm,top,templet,title,keywords,content,title_color,relate_key,classid,parentlist,position,parentid,NewsTempArr,folderCategory,folderArr,pageRealPath,title2,newsmoditime,demons,fieldsarr
set rs1=server.CreateObject("adodb.recordset") 
rs1.open "select id,pagepath,photo,classid,parentid,author,news_edit,news_from,templetid,title,keywords,content,title_color,relate_key,title2,moditime,demons from news where isoutlink=0 and id="&id,conn,3,1		
'获得参数
if not rs1.eof and not rs1.bof then
	NewsTempArr=rs1.GetRows()
else
	response.Write("没有记录")
	response.End()
end if
rs1.close
set rs1=nothing

'for i=0 to ubound(NewsTempArr,2)
i=0
id=NewsTempArr(0,i)
pagepath=NewsTempArr(1,i)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
pagepatharr=left(pagepath,InStrRev(pagepath,"/"))
if(pagepatharr<>"") then
	pageRealPath=replace(pagepatharr,"/","\")	
end if
''''''''''''''''''''''''''''''''''''''''''''''''''
'创建文件夹
folderCategory=server.MapPath("../")	
folderArr=split(pagepatharr,"/")
for fi=0 to ubound(folderArr)
	tempFolder=tempFolder&"\"&folderArr(fi)
	
	call MakeDir(folderCategory&tempFolder)
next	
''''''''''''''''''''''''''''''''''''''''''''''''''	
folder_day=folderCategory&pageRealPath
filenamestr=mid(pagepath,InStrRev(pagepath,"/")+1)
tempid=left(filenamestr,InStrRev(filenamestr,".")-1)
FileExts=mid(filenamestr,InStrRev(filenamestr,".")+1)
'response.Write(FileExts)
photo=NewsTempArr(2,i)
classid=NewsTempArr(3,i)
parentid=NewsTempArr(4,i)
position="<a href="""&SiteUrl&""">"&SiteTitle&"</a>"&getPosition(classid,"-&gt;")
author=NewsTempArr(5,i)
if isnull(author) then
	author=""
end if
editor=NewsTempArr(6,i)
if isnull(editor) then
	editor=""
end if
newsfrom=NewsTempArr(7,i)
if isnull(newsfrom) then
	newsfrom=""
end if
templet=NewsTempArr(8,i)
title=NewsTempArr(9,i)
if isnull(title) then
	title=""
end if
keywords=""&NewsTempArr(10,i)
if isnull(keywords) then
	keywords=""
end if
content=NewsTempArr(11,i)
if isnull(content) then
	content=""
end if
title_color=NewsTempArr(12,i)
relate_key=NewsTempArr(13,i)
if isnull(relate_key) then
	relate_key=""
end if
title2=NewsTempArr(14,i)
demons=NewsTempArr(16,i)
if(demons<>"") then
else
demons=""
end if
newsmoditime=NewsTempArr(15,i)
Dim i,file_name,TempletContent,current_time
'if(application("TemplateCont")=null or application("TemplateCont")=empty) then
'获取模板内容
	set rs2=server.CreateObject("adodb.recordset")  
    rs2.open "select content from templet where id="&templet,conn,3,1
	if not rs2.eof then
		TempletContent=rs2("content")
		'application("TemplateCont")=TempletContent
	else
		response.Write(title&"没有选择正确的模板！请修改后再发布！")
		response.End()
	end if
   rs2.close
   set rs2=nothing
'else
	'TempletContent=application("TemplateCont")
'end if
'response.Write(TempletContent)
'创建文件夹及文件
current_time=now
	
	'TempletContent=replace(TempletContent,"$position$",position)
	TempletContent=replace(TempletContent,"$title$",title)
	if(title2<>"") then
	else
		title2=""
	end if
	TempletContent=replace(TempletContent,"$subhead$",title2)
	
	TempletContent=replace(TempletContent,"$demons$",demons)
	TempletContent=replace(TempletContent,"$keywords$",keywords)
	TempletContent=replace(TempletContent,"$moditime$",newsmoditime)
	TempletContent=replace(TempletContent,"$newsfrom$",newsfrom)
	TempletContent=replace(TempletContent,"$author$",author)
	TempletContent=replace(TempletContent,"$editor$",editor)	
	TempletContent=replace(TempletContent,"$id$",id)
	TempletContent=replace(TempletContent,"$classid$",classid)
	TempletContent=replace(TempletContent,"$PageUrl$",pagepath)
	TempletContent=replace(TempletContent,"$prearticle$",getNewsByPrimaryKey(id-1))
	TempletContent=replace(TempletContent,"$nextarticle$",getNewsByPrimaryKey(id+1))
	if(Instr(TempletContent,"$GetRelateNews$")<>0) then
		TempletContent=replace(TempletContent,"$GetRelateNews$",GetRelateNews(relate_key,"100%",RelateParam(0),RelateParam(1),"news","id","",RelateParam(2),"",RelateParam(3)))
	end if
	'自定义字段
	set rs=server.createobject("adodb.recordset")
	rs.open "select FName,FTitle,FormType,FormTitle,FStyle,FormDefault,IsBindTable,BindPara from t_fields where moduleid=1 order by FSort",conn,3,1
	if not rs.eof then
		fieldsarr=rs.getrows()
	end if
	rs.close
	set rs=nothing
	if isarray(fieldsarr) then
		for j=0 to ubound(fieldsarr,2)
			TempletContent=replace(TempletContent,"$"&fieldsarr(0,j)&"$",request.Form(fieldsarr(0,j)))
		next
	end if
	TempletContent=ReplaceAllLabel(TempletContent,classid)	
	'TempletContent=replace(TempletContent,"$SiteUrl$",SiteUrl)		
	dim pageNums,prePage,nextPage,newsarr
	newsarr=split(content,"$Page_Split$")
	pageNums=Cint(ubound(newsarr))
	'response.Write("total:"&pageNums&":"&len(content)&"<br>")
	'生成新闻页
	for i=0 to pageNums
		if(i=0) then
			pageSplitLists=pageSplitLists&"<a href="""&tempid&"."&FileExt&""">["&(i+1)&"]</a>"
		else
			pageSplitLists=pageSplitLists&"<a href="""&tempid&"_"&i&"."&FileExt&""">["&(i+1)&"]</a>"
		end if		
	next
	'TempletContent=replace(TempletContent,"$PageSplitLists$",pageSplitLists)
	for i=0 to pageNums
		if err.number <>0 then
			response.Write("服务器错误。")
			response.End()
		else
			response.Write("OK ")
		end if
		newstemp=TempletContent
		if(pageNums=0) then
			response.Write("file success save to ->:"&folder_day&tempid&"."&FileExts&"<br>")	
			newstemp=replace(newstemp,"$content$",content)
			newstemp=replace(newstemp,"$PrePage_NextPage$","")
			newstemp=replace(newstemp,"$PageSplitLists$","")
			call SaveTextFile(folder_day&tempid&"."&FileExts,newstemp)
			'Set file_w = fs.CreateTextFile(folder_day&tempid&"."&FileExts,true)
			'file_w.WriteLine(newstemp)
			'file_w.close
			'set file_w=nothing
		else
			dim page_c,page_label,page_pre,page_next
			page_label=""
			for j=0 to pageNums
				if(j=i) then
					page_label=page_label&"<span>"&(j+1)&"</span>"
				else
					if(j=0) then
						page_label=page_label&"<a href="""&tempid&"."&FileExt&""">"&(j+1)&"</a>"
					else
						page_label=page_label&"<a href="""&tempid&"_"&j&"."&FileExt&""">"&(j+1)&"</a>"
					end if
				end if				
			next
			prePage=i-1
			nextPage=i+1
			if(i=0) then
				newstemp=replace(newstemp,"$content$",newsarr(i))
				page_pre=""
				page_next="<a href="""&tempid&"_"&nextPage&"."&FileExts&""">下一页</a>"				
			elseif(i=1) then
				if(pageNums=1) then
					newstemp=replace(newstemp,"$content$",newsarr(i))
		 			page_pre="<a href="""&tempid&"."&FileExts&""">上一页</a>"              
				else
					newstemp=replace(newstemp,"$content$",newsarr(i))
		 			page_pre="<a href="""&tempid&"."&FileExts&""">上一页</a>"
					page_next="<a href="""&tempid&"_"&nextPage&"."&FileExt&""">下一页</a>"
				end if
			elseif(i=pageNums) then
				newstemp=replace(newstemp,"$content$",newsarr(i))
				page_pre="<a href="""&tempid&"_"&prePage&"."&FileExts&""">上一页</a>"
				page_next=""
			else
				newstemp=replace(newstemp,"$content$",newsarr(i))
				page_pre="<a href="""&tempid&"_"&prePage&"."&FileExts&""">上一页</a>"
				page_next="<a href="""&tempid&"_"&nextPage&"."&FileExt&""">下一页</a>"
			end if
			newstemp=replace(newstemp,"$PageSplitLists$",page_pre&page_label&page_next)
			if(i=0) then				
				call SaveTextFile(folder_day&tempid&"."&FileExts,newstemp)				
				response.Write("文件已保存到："&folder_day&tempid&"."&FileExts&"<br>")                
            else
				call SaveTextFile(folder_day&tempid&"_"&i&"."&FileExts,newstemp)				
				response.Write("文件已保存到："&folder_day&tempid&"_"&i&"."&FileExts&"<br>")
                
            end if
		end if
	next	

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