<!--#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" -->
<%
' 如果编辑的内容很多，上传速度太慢，请设置以下的时间，单位秒
Server.ScriptTimeout = 999999
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p02")
'''''''''''''''''''''''''''''''''''''''''''''''
dim id,pagepath,news_class,photo,author,editor,imgnews,newsfrom,hot,recomm,top,templet,specialid,title,title_color,isoutlink,outlinkurl,keywords,relate_key,content,classid,parentlist,position,parentid
dim pagepatharr,filenamestr,tempid,FileExts,filepathArr,filepathtempstr
'获得参数
current_time=now
id=Clng(request.Form("id"))
if not isempty(request.Form("isoutlink")) then
	isoutlink=Cint(request.Form("isoutlink"))	
else
	isoutlink=0
end if
pagepath=trim(request.Form("pagepath"))
Set fs=Server.CreateObject("Scripting.FileSystemObject")	
if(isoutlink=0) then
	pagepatharr=left(pagepath,InStrRev(pagepath,"/"))
	filepathArr=split(pagepatharr,"/")
	for pathi=0 to ubound(filepathArr)
		filepathtempstr=filepathtempstr&"\"&filepathArr(pathi)
		If (fs.FolderExists(server.MapPath("../")&filepathtempstr)) Then
		Else
			fs.CreateFolder(server.MapPath("../")&filepathtempstr)
		End If
	next
	folder_day=server.MapPath("../"&pagepatharr)
	filenamestr=mid(pagepath,InStrRev(pagepath,"/")+1)
	tempid=left(filenamestr,InStrRev(filenamestr,".")-1)
	FileExts=mid(filenamestr,InStrRev(filenamestr,".")+1)
end if
photo=trim(request.form("photo"))
classid=Cint(request.Form("newsclass"))
parentid=getparentid(classid)
position="<a href="""&SiteUrl&""">"&SiteTitle&"</a>"&getPosition(classid,"-&gt;")
author=trim(request.form("author"))
editor=trim(request.form("editor"))
author=trim(request.form("author"))
imgnews=Cint(request.form("imgnews"))
top1=Cint(request.Form("top1"))
if(top1=1) then
	top1=1
else
	top1=0
end if
if(imgnews=1) then
	imgnews=true
else
	imgnews=false
end if
newsfrom=trim(request.form("newsfrom"))
hot=Cint(request.form("hot"))
if(hot<1) then
	hot=0
end if
recomm=Cint(request.form("recomm"))
if(recomm=1) then
	recomm=true
else
	recomm=false
end if
top=Cint(request.form("top"))
if(top<1) then
	top=0
end if
templet=Cint(request.form("templet"))
if not isempty(request.Form("specialid")) then
	specialid=Cint(request.Form("specialid"))
else
	specialid=0
end if
title=trim(request.form("title"))
title_color=trim(request.Form("title_color"))
keywords=trim(request.Form("keywords"))
relate_key=trim(request.Form("related_key"))
if not isempty(request.Form("saveremoteimg")) then
	saveremoteimg=Cint(request.Form("saveremoteimg"))
else
	saveremoteimg=0
end if
content=Request.Form("content")
if(isoutlink=0) then
	Dim i,file_name,TempletContent,current_time
	'获取模板内容
	set rs=server.CreateObject("adodb.recordset")  
    rs.open "select content from templet where id="&templet,conn,3,1
	if not rs.eof then
		TempletContent=rs("content")
	else
		response.Write("请选择正确的模板！")
	end if
   rs.close
   set rs=nothing
	'response.Write(TempletContent)
	'创建文件夹及文件	
	TempletContent=replace(TempletContent,"$title$",title)
	TempletContent=replace(TempletContent,"$keywords$",keywords)
	TempletContent=replace(TempletContent,"$moditime$",current_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,"$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,RelateNews,"news","id","",36,"",0))
	end if	
	TempletContent=ReplaceAllLabel(TempletContent,classid)			
	dim pageNums,prePage,nextPage,newsarr
	newsarr=split(content,"$Page_Split$")
	pageNums=Cint(ubound(newsarr))	
	'生成新闻页
	dim pageSplitLists
	pageSplitLists=""
	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)
	response.Write("<fieldset><legend>文章生成信息：</legend><br />")
	for i=0 to pageNums
		newstemp=TempletContent
		if(pageNums=0) then
			files=server.MapPath("../"&pagepath)
			response.Write("Success!文章修改成功!<br>文件已保存到："&files&"<br>")	
			newstemp=replace(newstemp,"$content$",content)
			Set file_w = fs.CreateTextFile(files)
			file_w.WriteLine(newstemp)
			file_w.close
			set file_w=nothing
		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("文件已保存到："&folder_day&"\"&tempid&"."&FileExts&"<br>")
                file_w.WriteLine(newstemp)
				file_w.close
			set file_w=nothing
            else
				Set file_w = fs.CreateTextFile(folder_day&"\"&tempid&"_"&i&"."&FileExts)
				response.Write("文件已保存到："&folder_day&"\"&tempid&"_"&i&"."&FileExts&"<br>")
                file_w.WriteLine(newstemp)
				file_w.close
			set file_w=nothing
            end if
		end if
	next
	response.Write("</fieldset")
	set fs=nothing
	call mod_data(file_path)
else
	if(len(request.Form("outlinkurl"))<1) then
		call alertstr("外部链接不能为空",1)
	else
		outlinkurl=request.Form("outlinkurl")
	end if
	call mod_data2()
	Response.Write "成功添加外部链接,标题："&title&"Link:" & outlinkurl
end if

'===================================================================
'                          修改数据库
'===================================================================
sub mod_data(filepath)
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select * from news  where id="&id,conn,3,3		
	rs("title")=title
	rs("title2")=title
	rs("title_color")=title_color
	rs("isoutlink")=isoutlink	
	rs("keywords")=keywords
	rs("relate_key")=relate_key
	rs("photo")=photo
	rs("content")=content
	rs("parentid")=parentid
	rs("classid")=classid
	rs("specialid")=specialid
	rs("templetid")=templet
	rs("top1")=top1
	rs("totop")=top
	rs("tohot")=hot
	rs("author")=author
	rs("news_edit")=editor
	rs("news_from")=newsfrom
	rs("imgnews")=imgnews
	rs("checked")=true
	rs("recommend")=recomm
	rs("moditime")=current_time	
	rs.update
	rs.close
	set rs=nothing
		
end sub
sub mod_data2()
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select top 1 * from news order by id desc",conn,3,3
	rs("pagepath")=outlinkurl
	rs("title")=title
	rs("title2")=title
	rs("title_color")=title_color
	rs("isoutlink")=isoutlink	
	rs("photo")=photo	
	rs("parentid")=parentid
	rs("classid")=classid
	rs("specialid")=specialid
	rs("templetid")=templet
	rs("top1")=top1
	rs("totop")=top
	rs("tohot")=hot
	rs("author")=author
	rs("news_edit")=editor
	rs("news_from")=newsfrom
	rs("imgnews")=imgnews
	rs("checked")=true
	rs("recommend")=recomm
	rs("moditime")=current_time
	rs.update
	rs.close
	set rs=nothing	
end sub
%>
<html>
<head><title>修改文章</title>
<link href="cs.css" rel="stylesheet" type="text/css" />
</head>
<body>
<br>
<fieldset>
<legend>是否现在发布栏目：</legend><br />
<div align="center">
  <input type="button" name="button1" value=" 是 " onClick="javascript:location.href='send.asp?classid=<%=parentid%>&curid=<%=classid%>'">
    &nbsp;
    <input type="button" name="button2" value=" 否 " onClick="javascript:location.href='news_manage.asp'">
</div>
</fieldset><br>
<fieldset>
<legend>下一步操作</legend>
<div align="center">
  	<input type=button value=' 退回 ' onclick='history.back()'> &nbsp;
	<input type=button value=' 继续修改 ' onclick='history.go(-2)'> &nbsp;
	<input type="button" name="Submit2" value="添加新文章" onClick="javascript:location.href='news_add.asp'">
</div>
</fieldset><br />
<fieldset>
<legend>编辑内容如下</legend>
<%=content%>
<%
response.Write("<iframe src=""reset_htm.asp?id="&(id-1)&""" height=""0"" width=""0""></iframe>")
response.Write("<iframe src=""reset_htm.asp?id="&(id+1)&""" height=""0"" width=""0""></iframe>")
%>
</fieldset>
</body>
</html>
<%
call connclose()
%>