<!--#include file="../ACT.Function.asp"-->
<!--#include file="../../act_Inc/Md5.asp"-->
<!--#include file="../../ACT_inc/ACT.SLT.asp"-->
<%
response.Write "<link href=""../Images/css1/css.css"" rel=""stylesheet"" type=""text/css"">"
Dim Save_SQL,ShowErr
Dim Title,IntactTitle,ChangesLinkUrl,ChangesLink,Intro,Content
Dim Hits,Keywords,author,CopyFrom,UpdateTime,TypeTitleFont,rs3
Dim IsTop,rev,StrMakeHtml,SpecialID,ClassID,FileName,filenametype
Dim ArticlePic,PicUrl,TemplateUrl,SavePic,Slide,authorRs,Field2,Field
Dim Tags,binding,IF_NULL,ModeID,ID,I,ATT
Dim Tmps,TmpUs
Dim url,GroupID_ACT,Score_ACT
	 ModeID = ACTCMS.ChkNumeric(Request("ModeID"))
	 if ModeID=0 or ModeID="" Then ModeID=1
	ID = ACTCMS.ChkNumeric(Request("ID"))
	IF_NULL=ACTCMS.Act_MX_Arr(ModeID)
	If IsArray(IF_NULL) Then
		For I=0 To Ubound(IF_NULL,2)
		 If IF_NULL(2,I)=0 And Trim(ACTCMS.S(IF_NULL(0,I)))="" Then  Call  ACTCMS.ALERT(IF_NULL(1,I)&"不能为空","")
		Next
	End If
	Tags = ACTCMS.ChkNumeric(Request.Form("Tags"))
	Title = Request.Form("Title")'简短标题
	IntactTitle = Request.Form("IntactTitle")'完整标题
	ChangesLinkUrl = Request.Form("ChangesLinkUrl")'转向链接地址
	ChangesLink = ACTCMS.ChkNumeric(Request.Form("ChangesLink"))'是否使用转向链接
	ClassID = Request.Form("ClassID")'所属栏目ID
	IsTop = ACTCMS.ChkNumeric(Request.Form("IsTop"))'固顶
	rev = ACTCMS.ChkNumeric(Request.Form("rev"))'是否允许评论
	FileName = Request.Form("FileName")'生成文件名
	StrMakeHtml = ACTCMS.ChkNumeric(Request.Form("MakeHtml"))
	Intro = Request.Form("Intro")'文章导读
	Content = Request.Form("Content")'文章内容
	Hits = ACTCMS.ChkNumeric(Request.Form("Hits"))'初始点击数
	Keywords = Request.Form("Keywords")'关键字
	author = Request.Form("author")'文章作者
	CopyFrom = Request.Form("CopyFrom")'文章来源
	UpdateTime = Request.Form("UpdateTime")'添加日期
	filenametype = Request.Form("filenametype")
	PicUrl = Request("PicUrl")'图片地址
	TemplateUrl = Request("TemplateUrl")'模板ID
	Slide = ACTCMS.ChkNumeric(Request("Slide"))
	ArticlePic = ACTCMS.ChkNumeric(Request("ArticlePic"))
	ATT = ACTCMS.ChkNumeric(Request("ATT"))
	GroupID_ACT = Trim(ACTCMS.S("GroupID_ACT"))
	Score_ACT = ACTCMS.ChkNumeric(Request("Score_ACT"))
	SavePic = ACTCMS.ChkNumeric(Request("SavePic"))'是否远程存图
	If IsDate(UpdateTime) =False Then UpdateTime=Date()
	If Keywords="" Then Keywords="0"
	If Actcms.ACT_C(ModeID,12) > 0 Then 
		Content=Replace(Content,"[NextPage]","")
		Content=actcms.AutoSplitPage(Content,"[NextPage]", Actcms.ACT_C(ModeID,12))
	End If 
	Dim WatermarkSetting,WatermarName
		WatermarkSetting = Actcms.ACTEXE("Select ActCMS_WatermarkSetting from Config_Act")(0)
		WatermarkSetting=Split(WatermarkSetting,"^@*&*@^")(0)
	If ArticlePic=1 And ACTCMS.ChkNumeric(Request("slt"))="1" And WatermarkSetting<"3" Then 
		Select Case WatermarkSetting
			Case "1":WatermarName="Persits.Jpeg"'组建名称
			Case "2":WatermarName="wsImage.Resize"'组建名称
			Case "3":WatermarName="SoftArtisans.ImageGen"'组建名称
		End Select 
		If WatermarName=True Then 
			Dim Path,DateDir,Tmpss,TmpUss,PicPreview
			If Instr(PicUrl,".")>0 Then '截取扩展名
				Tmpss = Split(PicUrl,".") : TmpUss = Tmpss(Ubound(Tmpss))
			End If 
			Dim rndpic
			rndpic=ACTCMS.GetRandomize(10)
			Path = ACTCMS.ReturnChannelUpFilesDir(ModeID)
			DateDir = Year(Now()) & Right("0" & Month(Now()), 2) & "/"
			Path =ACTCMS.ActSys& Path & "/" & DateDir
			Call ACTCMS.CreateFolder(Path)
			PicPreview=Path&ModeID&rndpic&Year(Now()) & Right("0" & Month(Now()), 2) &"_Pic."&TmpUss
			Dim W:Set W=New Watermark
			Call W.CreateThumbs(PicUrl,PicPreview)
			Set W=Nothing
			PicUrl=	Path&ModeID&rndpic&Year(Now()) & Right("0" & Month(Now()), 2) &"_Pic."&TmpUss
		End If 
	End If 

	IF Trim(Title) = ""  Then
		ShowErr = "<li>请填写简短标题</li>"
		Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
		Response.End
	End if

	IF Trim(ClassID) = ""  Then
		ShowErr = "<li>请选择一个栏目</li>"
		Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
		Response.End
	End if


    If ACTCMS.ChkNumeric(Request("addauthor")) = 1 And  author<>"" Then 
		 Set authorRs = Server.createobject("Adodb.Recordset")
		 Field = Split(author,"-")
		 If UBound(Field)>0 Then author=Field(0):Field2=Field(1)
		 authorRs.Open "Select * From AC_ACT Where Field1 ='" & author & "' And Types =1",Conn,1,3
		 If authorRs.Eof Then
			 authorRs.AddNew
			 authorRs("Field1") =author
			 authorRs("Field2") = Field2
			 authorRs("Types") = 1
			 authorRs.Update
		 End If:authorRs.Close
	End If 


	If ACTCMS.ChkNumeric(Request("addCopyFrom")) = 1 And CopyFrom<>"" Then 
		 Set authorRs = Server.createobject("Adodb.Recordset")
		 Field = Split(CopyFrom,"-")
		 If UBound(Field)>0 Then CopyFrom=Field(0):Field2=Field(1)
		 authorRs.Open "Select * From AC_ACT Where Field1 ='" & CopyFrom & "' And Types =0",Conn,1,3
		 If authorRs.Eof Then
			 authorRs.AddNew
			 authorRs("Field1") = CopyFrom
			 authorRs("Field2") = Field2
			 authorRs("Types") = 0
			 authorRs.Update
		 End If:authorRs.Close
	End If 

	If Tags = 1 Then Call ACTCMS.AddTags(1,Keywords)
	If  TemplateUrl="" Then'继承栏目设置
		TemplateUrl=ACTCMS.ACT_L(ClassID,5)
	Else
		TemplateUrl=TemplateUrl
	End If 
	If filenametype="0" Then filenametype=ACTCMS.ACT_L(ClassID,7)

	If CInt(SavePic) = 1 And CInt(ChangesLink) <> 1 Then
		Dim SaveFilePath
		If CStr(ActCMS.ActCMS_Other(7)) = "0" Then
		  SaveFilePath = ACTCMS.actsys & ActCMS.ActCMS_Other(6) & Year(Now()) & "-" & Right("0" & Month(Now()), 2) & "/"
		Else
		  SaveFilePath = ACTCMS.actsys & ActCMS.ActCMS_Other(6)
		End If
		  Call ACTCMS.CreateFolder(SaveFilePath)
		  Content = ACTCMS.ReplaceUrl(Content, SaveFilePath)
	End If


	If ACTCMS.ChkNumeric(Request("dellink")) =1  Then Content=RemoveHref(Content)

    
	Function RemoveHref(HTMLstr)
		Dim ra
		Set ra = New RegExp
		ra.IgnoreCase = True
		ra.Global = True
		ra.Pattern = "<a[^>]+>(.+?)<\/a>"
		RemoveHref= ra.replace(HTMLstr,"$1")
	End Function

	
	Set Save_SQL = server.CreateObject("adodb.recordset")
	IF Request("Action") = "add" Then '添加
		If Not ACTCMS.ACTCMS_QXYZ(ModeID,"2",ClassID) Then  Call Actcms.Alert("对不起，您没有该栏目下添加内容的权限！","")
		Dim ChkFileName,strFileName
		If  Request.Form("FileName")="" Then '获取文件名并且解析
			strFileName=ACTCMS.ACT_C(ModeID,10)
			If Instr(strFileName,"{y}") > 0 Then strFileName = Replace(strFileName,"{y}",Right("0" & Year(Now), 2))
			If Instr(strFileName,"{m}") > 0 Then strFileName = Replace(strFileName,"{m}",Right("0" & Month(Now), 2))
			If Instr(strFileName,"{d}") > 0 Then strFileName = Replace(strFileName,"{d}",Right("0" & Day(Now), 2))
			If Instr(strFileName,"{date}") > 0 Then strFileName = Replace(strFileName,"{date}",Year(Now) & "-" & Month(Now) & "-" & Day(Now))
			If Instr(strFileName,"{classid}") > 0 Then strFileName = Replace(strFileName,"{classid}",Actcms.ACT_L(classid,3))
			If Instr(strFileName,"{enname}") > 0 Then strFileName = Replace(strFileName,"{enname}",Actcms.ACT_L(classid,1))
			If Instr(strFileName,"{md5}") > 0 Then strFileName = Replace(strFileName,"{md5}",MD5(Now))
			If Instr(strFileName,"{rnd}") > 0 Then strFileName = Replace(strFileName,"{rnd}",ACTCMS.GetRandomize(10))
			If Instr(strFileName,"{pinyin}") > 0 Then strFileName = Replace(strFileName,"{pinyin}",ACTCMS.GetEn(ACTCMS.PinYin(ACTCMS.CloseHtml(Title))))
		Else
			strFileName=Request.Form("FileName")
		If Instr(strFileName,".")>0 Then '截取扩展名
			Tmps = Split(strFileName,".") : TmpUs = Tmps(Ubound(Tmps)-1)
			strFileName=TmpUs
		Else
			strFileName=strFileName
		End If 

		End If 
		If Right(strFileName,1)="/" Then 
			strFileName=Left(strFileName, Len(strFileName) - 1)
		End If 
	
		If InStr(strFileName, "//") > 0   Then
			strFileName = Replace(strFileName, "//","/")
		End If 
		set ChkFileName = conn.execute("select ID From "&ACTCMS.ACT_C(ModeID,2)&" where ClassID ='"& ClassID &"' and FileName='"& strFileName &"' order by ID desc")
		if Not ChkFileName.eof then
			ShowErr = "<li>文件名意外重复,请返回保存,如果还发现这种情况,请确认生成规则是否正确</li>"
			Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
			Response.end
		End If
		Dim sqlstr
		SqlStr = "select * from " & ACTCMS.ACT_C(ModeID,2) &" where 1=0"
		Save_SQL.Open SqlStr, conn, 1, 3
		Save_SQL.AddNew
		Save_SQL("ClassID") = ClassID
		Save_SQL("Title") = Title'简短标题
		Save_SQL("IntactTitle")= IntactTitle'完整标题
		Save_SQL("Intro") = Intro'文章导读
		Save_SQL("author") = author'作者
		Save_SQL("IsTop") = IsTop'置顶
		Save_SQL("isAccept") = 0
		Save_SQL("userid") = 0
		Save_SQL("Slide") = Slide'幻灯片
		Save_SQL("ATT") = ATT
		Save_SQL("Hits") = Hits
		Save_SQL("ArticlePic") = ArticlePic
		Save_SQL("Score_ACT") = Score_ACT
		Save_SQL("GroupID_ACT") = GroupID_ACT
		if Clng(ChangesLink) = 1 then '如果是转向链接,则文件名是转向地址
			Save_SQL("ChangesLink") = 1
			Save_SQL("FileName") = ChangesLinkUrl
		Else
			If Instr(strFileName,"{id}") > 0 Then strFileName = Replace(strFileName,"{id}",Save_SQL("id"))
			Save_SQL("FileName") = strFileName'文件名
		 End IF
			Save_SQL("TemplateUrl") = TemplateUrl'内容
			Save_SQL("Content") = Content'内容
			Save_SQL("CopyFrom") = CopyFrom'文章来源
			Save_SQL("Keywords") = Keywords'关键字
			Save_SQL("rev") = rev'评论
			Save_SQL("UpdateTime") = UpdateTime
			Save_SQL("PicUrl") = PicUrl'图片文章地址
			Save_SQL("ArticleInput") = ACTCMS.RSQL(Request.Cookies(AcTCMSN)("AdminName"))
			If IsArray(IF_NULL) Then
				For I=0 To Ubound(IF_NULL,2)
					If IF_NULL(3,I)="NumberType" Then 
					   Save_SQL("" & IF_NULL(0,I) & "" )= ACTCMS.ChkNumeric(ACTCMS.S(IF_NULL(0,I)))
					ElseIf IF_NULL(3,I)="DateType" Then 
						If IsDate(ACTCMS.S(IF_NULL(0,I)))=False Then 
							Save_SQL("" & IF_NULL(0,I) & "")= Now()
						Else 
							Save_SQL("" & IF_NULL(0,I) & "")=ACTCMS.S(IF_NULL(0,I))
						End If 
					Else 
						Save_SQL("" & IF_NULL(0,I) & "")=ACTCMS.S(IF_NULL(0,I))
					End If 
				Next
			End If
		Save_SQL.update
		Session("ClassName")=AcTCMS.CloseHtml(ACTCMS.ACT_L(ClassID,2))
		Session("ClassID")=ClassID
	ElseIF  Request("Action") = "edit" Then
		If Not ACTCMS.ACTCMS_QXYZ(ModeID,"3",ClassID) Then  Call Actcms.Alert("对不起，您没有该栏目下修改内容的权限！","")
		dim Save_SQL1
		Save_SQL1= "Select * from "&ACTCMS.ACT_C(ModeID,2)&" where ID="& ACTCMS.ChkNumeric(ID) &""
		Save_SQL.Open Save_SQL1,Conn,1,3
		Save_SQL("ClassID") = ClassID
		Save_SQL("Title") = Title'简短标题
		Save_SQL("IntactTitle")= IntactTitle'完整标题
		Save_SQL("Intro") = Intro'文章导读
		Save_SQL("IsTop") = IsTop'置顶
		Save_SQL("author") = author'作者
		Save_SQL("Slide") = Slide'幻灯片
		Save_SQL("ATT") = ATT
		Save_SQL("Hits") = Hits
		Save_SQL("ArticlePic") = ArticlePic
		Save_SQL("Score_ACT") = Score_ACT
		Save_SQL("GroupID_ACT") = GroupID_ACT
		if Clng(ChangesLink) = 1 then '如果是转向链接,则文件名是转向地址
			Save_SQL("ChangesLink") = 1
			Save_SQL("FileName") = ChangesLinkUrl
		Else
			If  Save_SQL("ChangesLink") = 1 And Clng(ChangesLink) = 0 then '如果是转向链接,则文件名是转向地址
				Save_SQL("ChangesLink") = 0
			End If
		End IF
			Save_SQL("TemplateUrl") = TemplateUrl'内容
			Save_SQL("Content") = Content'内容
			Save_SQL("CopyFrom") = CopyFrom'文章来源
			Save_SQL("Keywords") = Keywords'关键字
			Save_SQL("rev") = rev'评论
			Save_SQL("UpdateTime") = UpdateTime
			Save_SQL("PicUrl") = PicUrl'图片文章地址
			If Request.QueryString("actcms")="sh" Then 
				Call ACTCMS.isAcceptOK(ModeID,Save_SQL("userid"),Save_SQL("ArticleInput"),Save_SQL("Title"))
				Save_SQL("isAccept") = 0
				Save_SQL("userid") = 0
			End If
			ClassID=Save_SQL("ClassID")
			If IsArray(IF_NULL) Then
				For I=0 To Ubound(IF_NULL,2)
					If IF_NULL(3,I)="NumberType" Then 
					   Save_SQL("" & IF_NULL(0,I) & "" )= ACTCMS.ChkNumeric(ACTCMS.S(IF_NULL(0,I)))
					ElseIf IF_NULL(3,I)="DateType" Then 
						If IsDate(ACTCMS.S(IF_NULL(0,I)))=False Then 
							Save_SQL("" & IF_NULL(0,I) & "")= Now()
						Else 
							Save_SQL("" & IF_NULL(0,I) & "")=ACTCMS.S(IF_NULL(0,I))
						End If 
					Else 
						Save_SQL("" & IF_NULL(0,I) & "")=ACTCMS.S(IF_NULL(0,I))
					End If 
				Next
			End If
			Save_SQL.update
	End If

	ID = Save_SQL("ID")
	Call UpDateFile(Content ,id ,ClassID)
	Function UpDateFile(Byval ContentHTML,Byval ArtileID,Byval ClassID)
		Dim RegEx,Matches,Match,Save_SQL2,Save_SQL3,ext
		Set RegEx = New RegExp
		RegEx.Ignorecase = True
		RegEx.Global = True
		RegEx.Pattern = ACTCMS.ACT_C(ModeID,8)&  "(.+?)\.(jpeg|gif|jpg|png|bmp|mp3|wma|rmvb|rm|rar|asf|avi|wmv|swf|ra|exe|zip|doc|xls)"
		Set Save_SQL3 = server.CreateObject("adodb.recordset")
		Set Matches = RegEx.Execute(ContentHtml)
			Save_SQL2= "Select * from Upload_Act where ArtileID="& ArtileID
			Save_SQL3.Open Save_SQL2,Conn,1,3
		For Each Match In Matches
			If Len(Match.Value) > 0 Then
				IF Request("Action") = "add" Then Save_SQL3.AddNew
				If Save_SQL3.eof  Then Save_SQL3.AddNew
				ext=Split(Match.Value,".")
				Save_SQL3("ArtileID") = ArtileID'内容
				Save_SQL3("UpfileDir") = ACTCMS.ActSys&Replace(Match.Value,"'","")
				Save_SQL3("Extension") =ext(1)
				Save_SQL3("ModeID") =ModeID
				Save_SQL3("UpdateTime") =Now()
				Save_SQL3.update
			End If
		Next
	Save_SQL3.close:set Save_SQL3 = Nothing
	End Function

	If CLng(StrMakeHtml) = 1  Then '立即生成Html
			response.Write "<div style=""margin-top:15px;border: #E7E7E7;height:296; overflow: auto; width:100%"">" 
			If ACTCMS.ACT_C(ModeID,3) = 0 Then 
			  response.Write "<div style=""margin-left:179;height:25px""><li>由于文章中心没有启用生成HTML的功能，所以ID号为 <font color=red>" & Save_SQL("ID") & "</font>  的文章没有生成!</li></div> "
			  response.Write "<div style=""margin-left:179;height:25px""><li>由于文章中心没有启用生成HTML的功能，所以ID号为 <font color=red>" & Save_SQL("classid") & "</font>  的栏目没有生成!</li></div> "
				URL=ACTCMS.ActCMS_Sys(2)&ACTCMS.ActSys&"Article/TypeArticle.asp?ModeID="&ModeID&"&ID="&Save_SQL("ID")
			Else 
				If ChangesLink = 0 Then
					  response.Write "<div align=center><iframe src=""../include/ACT.MakeMode.asp?ModeID="&ModeID&"&"" width=""0"" height=""0"" frameborder=""0""></iframe></div>"
					  Response.Write "<div align=center><iframe src=""../Include/ACT.C.asp?ModeID="&ModeID&"&RefreshFlag=ID&ID=" & Save_SQL("ID") &""" width=""100%"" height=""40"" frameborder=""0""></iframe></div>"
					Dim PrevArticle
					  set PrevArticle = Conn.execute("select ID From Article_ACT where ClassID ='"& Save_SQL("classid") &"' and id<"& Save_SQL("ID") &"  and isAccept=0 AND delif=0 order by ID desc")
					  If Not PrevArticle.eof Then
						  Response.Write "<div align=center><iframe src=""../Include/ACT.C.asp?ModeID="&ModeID&"&RefreshFlag=ID&ID=" & PrevArticle("id") &""" width=""98%"" height=""0"" frameborder=""0""></iframe></div>"
						  response.Write "<div style=""margin-left:179;height:25px""><li>系统已经生成了静态文件.同时更新了上一篇文章链接</li></div> "
					  End If 
					  URL = Save_SQL("FileName")
			
				 If Right(ACTCMS.ACT_C(ModeID,10),1)<>"/" Then 
						 URL= ACTCMS.ActCMS_Sys(2)&ACTCMS.ActCMS_Sys(3)&ACTCMS.ACT_C(ModeID,6)&URL&ACTCMS.ACT_C(ModeID,11)
				 Else
						 URL= ACTCMS.ActCMS_Sys(2)&ACTCMS.ActCMS_Sys(3)&ACTCMS.ACT_C(ModeID,6)&URL&"/"
				 End If 
		
				Else	
					 response.Write "<div style=""margin-left:179;height:25px""><li>文章是转向链接.系统没有生成</li></div> "
					  URL = Save_SQL("FileName")
				End If 
				If ACTCMS.ACT_C(ModeID,9) = 2 Then 
					  Dim FolderIDArr:FolderIDArr=Split(ACTCMS.GetClassNavStr(Save_SQL("ClassID")),",")
					  For I=0 To Ubound(FolderIDArr)
						response.Write "<div align=center><iframe src=""../Include/ACT.L.asp?ModeID="&ModeID&"&RefreshFlag=ID&ClassID=" & FolderIDArr(i) &""" width=""0"" height=""0"" frameborder=""0""></iframe></div>"
					  Next
				End If
			End If
			response.write "<div style=""margin-left:179;height:25px""><li>地址:<a target=""_blank"" href="&URL&">"&URL&"</a></div>"
		ElseIf  CLng(StrMakeHtml) = 0 Then
		 response.Write "<div style=""margin-left:179;height:25px""><li>系统没有选中立即生成 ID号为<font color=red>" & ID & "</font>  的文章没有生成!</li></div> "
		Else 
		 response.Write "<div style=""margin-left:179;height:25px""><li>系统未知错误</li></div> "
		End If
			if ACTCMS.ACT_C(ModeID,9)=>2 And Split(ACTCMS.ActCMS_Sys(4),".")(1)<>"asp" Then
			response.Write "<div align=center><iframe src=""../include/MakeIndex.asp"" width=""0"" height=""0"" frameborder=""0""></iframe></div>"
			End If 
		response.write "<div style=""margin-left:179;height:25px""><li>文章保存成功! <a href=ACT.Add.asp?ModeID="&ModeID&"><b>添加新文章</b></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=ACT.Manage.asp?ModeID="&ModeID&"><b><font color=red>返回管理首页</font></b></a></li></div>"
		Save_SQL.close:set Save_SQL = Nothing
%>