<!--#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" -->
<%
response.Charset="gb2312"
%>
<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
'''''''''''''''''''''''''''''''''''''''''''''''
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,pub_time
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,moditime from news where id="&id,conn,3,1		
'获得参数
if not rs1.eof then
	NewsTempArr=rs1.GetRows()
else
	response.Write("没有记录")
	response.End()
end if
rs1.close
set rs1=nothing

i=0
id=NewsTempArr(0,i)
pagepath=NewsTempArr(1,i)
'生成目录
dim splitPathArr,j,splitpathStr
if(pagepath<>"") then
	splitPathArr=split(pagepath,"/")
	Set fs=Server.CreateObject("Scripting.FileSystemObject")
	for j=0 to ubound(splitPathArr)-1
		splitpathStr=splitpathStr&"/"&splitPathArr(j)
		'创建文件夹
		If (fs.FolderExists(server.MapPath(splitpathStr))) Then
		Else
			fs.CreateFolder(server.MapPath(splitpathStr))
		End If
	next
	set fs=nothing
end if
'
pagepatharr=left(pagepath,InStrRev(pagepath,"/"))
folder_day=server.MapPath("../"&pagepatharr)
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)
editor=NewsTempArr(6,i)
newsfrom=NewsTempArr(7,i)
templet=NewsTempArr(8,i)
title=NewsTempArr(9,i)
keywords=""&NewsTempArr(10,i)
content=NewsTempArr(11,i)
title_color=NewsTempArr(12,i)
relate_key=NewsTempArr(13,i)
pub_time=NewsTempArr(14,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("请选择正确的模板！")
		response.End()
	end if
   rs2.close
   set rs2=nothing
'else
	'TempletContent=application("TemplateCont")
'end if
'response.Write(TempletContent)
'创建文件夹及文件
current_time=now
Set fs=Server.CreateObject("Scripting.FileSystemObject")		
	TempletContent=replace(TempletContent,"$position$",position)
	TempletContent=replace(TempletContent,"$title$",title)
	TempletContent=replace(TempletContent,"$keywords$",keywords)
	TempletContent=replace(TempletContent,"$moditime$",pub_time)
	TempletContent=replace(TempletContent,"$newsfrom$",newsfrom)
	TempletContent=replace(TempletContent,"$author$",author)
	TempletContent=replace(TempletContent,"$editor$",editor)	
	TempletContent=replace(TempletContent,"$id$",id)
	TempletContent=replace(TempletContent,"$pageurl$",siteurl&"/"&pagepath)
	TempletContent=replace(TempletContent,"$classid$",classid)
	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%",22,10,"news","id","",36,"",0))
	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>")
	'生成新闻页
	dim pageSplitLists
	pageSplitLists=""
	for i=0 to pageNums
		if(i=0) then
			pageSplitLists=pageSplitLists&"<a href="""&tempid&"."&FileExts&""">["&(i+1)&"]</a>"
		else
			pageSplitLists=pageSplitLists&"<a href="""&tempid&"_"&i&"."&FileExts&""">["&(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
			files=server.MapPath("../"&pagepath)
			response.Write("file success save to ->:"&files&"<br>")	
			newstemp=replace(newstemp,"$content$",content)
			Set file_w = fs.CreateTextFile(files)
			file_w.WriteLine(newstemp)
		else
			prePage=i-1
			nextPage=i+1
			if(i=0) then
				newstemp=replace(newstemp,"$content$",newsarr(i)&"<p><div align=""center""><a href="""&tempid&"_"&nextPage&"."&FileExts&""">下一页</a></div></p>")
			end if
			if(i=1) then
				if(pageNums=1) then
                     newstemp=replace(newstemp,"$content$",newsarr(i)&"<p><div align=""center""><a href="""&tempid&"."&FileExts&""">上一页</a></div></p>")                    
                else
                     newstemp=replace(newstemp,"$content$",newsarr(i)&"<p><div align=""center""><a href="""&tempid&"."&FileExts&""">上一页</a>&nbsp;&nbsp;<a href="""&tempid&"_"&nextPage&"."&FileExt&""">下一页</a></div></p>")
                end if
			end if
			if(i=pageNums) then
				newstemp=replace(newstemp,"$content$",newsarr(i)&"<p><div align=""center""><a href="""&tempid&"_"&prePage&"."&FileExts&""">上一页</a></div></p>")
			else
				newstemp=replace(newstemp,"$content$",newsarr(i)&"<p><div align=""center""><a href="""&tempid&"_"&prePage&"."&FileExts&""">上一页</a>&nbsp;&nbsp;<a href="""&tempid&"_"&nextPage&"."&FileExt&""">下一页</a></div></p>")
			end if
			if(i=0) then
				Set file_w = fs.CreateTextFile(folder_day&"\"&tempid&"."&FileExts)					
				response.Write("file success save to ->:"&folder_day&"\"&tempid&"."&FileExts&"<br>")
                file_w.WriteLine(newstemp)
            else
				Set file_w = fs.CreateTextFile(folder_day&"\"&tempid&"_"&i&"."&FileExts)
				response.Write("file success save to ->:"&folder_day&"\"&tempid&"_"&i&"."&FileExts&"<br>")
                file_w.WriteLine(newstemp)
            end if
		end if
	next
	file_w.close
	set file_w=nothing
set fs=nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
call connclose()
%>
</body>
</html>