<!--#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
'''''''''''''''''''''''''''''''''''''''''''''''
if(checkIfHasPrevilege(Session("Name"),"p02") or checkIfHasPrevilege(Session("Name"),"pext02")) then
else
	response.Write("<script>alert('您没有此权限!');location.href=""login.asp"";</script>")
	response.End()
end if
'''''''''''''''''''''''''''''''''''''''''''''''
dim id,pagepath,news_class,photo,author,editor,imgnews,newsfrom,hot,recomm,top,templet,specialid,title,title_color,title2,isoutlink,outlinkurl,keywords,relate_key,content,classid,parentlist,position,parentid,isslide,demons
dim pagepatharr,filenamestr,tempid,FileExts,pageSplitLists,folderCategory,folderArr,pageRealPath
'获得参数
current_time=now
id=Clng(request.Form("id"))
classid=Clng(request.Form("newsclass"))
'权限
dim ClassLimitArr,IfHasClassPermit
IfHasClassPermit=false
if(Cint(Session("RoleId"))<>0) then
	if(Cint(Session("classlimit"))<>0) then
		ClassLimitArr=split(Session("classids"),",")
		for si=0 to ubound(ClassLimitArr)
			if(Clng(ClassLimitArr(si))=classid) then
				IfHasClassPermit=true
			end if
		next
	else
		IfHasClassPermit=true
	end if
else
	IfHasClassPermit=true
end if
if(IfHasClassPermit<>true) then
	call alertstr("您没有该栏目的管理权限!",1)
end if
if not isempty(request.Form("isoutlink")) then
	isoutlink=Cint(request.Form("isoutlink"))	
else
	isoutlink=0
end if
pagepath=trim(request.Form("pagepath"))
if(isoutlink=0) then
	pagepatharr=left(pagepath,InStrRev(pagepath,"/"))
	response.Write(pagepatharr)
	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)
end if
photo=trim(request.form("photo"))
parentid=getparentid(classid)
position="<a href="""&SiteUrl&""">"&SiteTitle&"</a>"&getPosition(classid,"-&gt;")
author=trim(request.form("author"))
editor=trim(request.form("editor"))
imgnews=Cint(request.form("imgnews"))
top1=Cint(request.Form("top1"))
newsfrom=trim(request.form("newsfrom"))
hot=Cint(request.form("hot"))
recomm=Cint(request.form("recomm"))
top=Cint(request.form("top"))
isslide=Cint(request.Form("isslide"))
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"))
title2=request.Form("title2")
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("content1")
demons=request.Form("demons")
	if(demons<>"") then
	else
		demons=RemoveHTML(content)
	end if
	demons=left(demons,100)
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)
	'创建文件夹及文件	
	Set fs=Server.CreateObject("Scripting.FileSystemObject")
	TempletContent=replace(TempletContent,"$title$",title)
	TempletContent=replace(TempletContent,"$demons$",demons)
	TempletContent=replace(TempletContent,"$subhead$",title2)
	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$",pagepath)
	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
	TempletContent=ReplaceAllLabel(TempletContent,classid)	
	dim pageNums,prePage,nextPage,newsarr
	newsarr=split(content,"$Page_Split$")
	pageNums=Cint(ubound(newsarr))
	'生成新闻页
	
	'TempletContent=replace(TempletContent,"$PageSplitLists$",pageSplitLists)
	response.Write("<fieldset><legend>文章生成信息：</legend><br />")
	for i=0 to pageNums
		newstemp=TempletContent
		if(pageNums=0) then			
			response.Write("Success!文章修改成功!<br>文件已保存到："&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)
			
		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
	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")=title2
	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")=1
	rs("recommend")=recomm
	rs("moditime")=current_time
	rs("username")=UserName
	rs("isslide")=isslide
	rs("demons")=demons
	rs.update
	rs.close
	set rs=nothing
		
end sub
sub mod_data2()
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select * from news  where id="&id,conn,3,3
	rs("linkurl")=request.Form("outlinkurl")
	rs("title")=title
	rs("title2")=title2
	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")=1
	rs("recommend")=recomm
	rs("moditime")=current_time
	rs("username")=UserName
	rs("isslide")=isslide
	rs("demons")=demons
	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%>&currentid=<%=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="添加" style="font-size:12px" onClick="javascript:location.href='news_add.asp'">
</div>
</fieldset><br />
<fieldset>
<legend>编辑内容如下</legend>
<%=content%>
</fieldset>
</body>
</html>
<%
call connclose()
%>