<!--#include file="../../ACT_inc/ACT.User.asp"-->
<!--#include file="../../ACT_inc/MD5.asp"-->
<%
Dim ClassID,Title,Save_SQL,filenametype,isAccept,Content,Keywords,ArticlePic,PicUrl
Dim author,Hits,Hots,IsTop,Mar,Rec,CopyFrom,rank,rev,ModeID,TemplateUrl,ATT
Call LoginCheck
ModeID = ACTCMS.ChkNumeric(Request("ModeID"))
If ModeID = 0 Then ModeID = 1
filenametype=".html"'生成文件格式
isAccept=0
ClassID = ACTCMS.S("ClassID")'所属栏目ID
Title=ACTCMS.S("Title")
Content=ACTCMS.S("Content")
author = ACTCMS.S("author")
Hits = ACTCMS.ChkNumeric(ACTCMS.S("Hits"))
Hots = ACTCMS.ChkNumeric(ACTCMS.S("Hots"))
IsTop = ACTCMS.ChkNumeric(ACTCMS.S("IsTop"))
Mar = ACTCMS.ChkNumeric(ACTCMS.S("Mar"))
Rec = ACTCMS.ChkNumeric(ACTCMS.S("Rec"))
isAccept = ACTCMS.ChkNumeric(ACTCMS.S("isAccept"))
rank = ACTCMS.S("rank")
CopyFrom = ACTCMS.S("CopyFrom")
rev = ACTCMS.ChkNumeric(ACTCMS.S("rev"))
ATT = ACTCMS.ChkNumeric(ACTCMS.S("ATT"))

If rank="" Then rank="★"
	IF Trim(ClassID) = ""  Then
		response.Write "[err]111请选择栏目或您填写的栏目ID不正确[/err]"
		Response.End
	End if

	IF Trim(Title) = ""  Then
		response.Write "[err]222请填写简短标题[/err]"
		Response.End
	End if
		
		Dim ChkFileName,strFileName
			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))))


		If Right(strFileName,1)="/" Then 
			strFileName=Left(strFileName, Len(strFileName) - 1)
		End If 
	

		set ChkFileName = ACTCMS.ActEXE("select ID From "&ACTCMS.ACT_C(ModeID,2)&" where ClassID ='"& ClassID &"' and FileName='"& strFileName &"' order by ID desc")
		if Not ChkFileName.eof then
			response.Write "[err]333文件名重复[/err]"
			Response.end
		End If
		
		
		set ChkFileName = Conn.execute("select ID From Class_ACT where ClassID ='"& ClassID &"'")
		if ChkFileName.eof then
			response.Write "[err]444错误的栏目ID,找不到栏目[/err]"
			Response.end
		End if

		IF Trim(Content) = ""  Then
			response.Write "[err]555请填写完整内容[/err]"
			Response.End
		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
			response.Write "[err]666文件名重复[/err]"
			Response.end
		End if

	
	
	
	dim picpatrn
	picpatrn="<img [^>]*src *= *(?:""|')?([^""' ]+\.(?:gif|jpg|bmp|png))(?:""|'| |/>|>)+"
	Function Regone(patrn, strng)
	  Dim regEx, Matches,ms,RetStr      ' Create variable.
	  Set regEx = New RegExp         ' Create a regular expression.
	  RetStr=""
	  regEx.Pattern = patrn         ' Set pattern.
	  regEx.IgnoreCase = True         ' Set case insensitivity.
	  regEx.Global = false         ' Set global applicability.

	  Set Matches = regEx.Execute(strng)   ' Execute search.

	  if Matches.count>0 then
		Set ms=Matches(0)
		if not isnull(trim(ms.submatches(0))) then RetStr=trim(ms.submatches(0))
	  end if
	  Regone = RetStr
	End Function
	PicUrl=regone(picpatrn,Content)
	If (trim(PicUrl)="" And ArticlePic=1) Then  ArticlePic=1

		If  TemplateUrl="" Then'继承栏目设置
			TemplateUrl=ACTCMS.ACT_L(ClassID,5)
		Else
			TemplateUrl=TemplateUrl
		End If 

		Dim sqlstr
		Set Save_SQL = server.CreateObject("adodb.recordset")
		SqlStr = "select * from " & ACTCMS.ACT_C(ModeID,2) &" where 1=0"
		Save_SQL.Open SqlStr, conn, 1, 3
		Save_SQL.AddNew

		If ATT="" Then ATT=0
		If (trim(PicUrl)="" And ArticlePic=1) Then  ArticlePic=1
		Save_SQL("ClassID") = ClassID
		Save_SQL("Title") = Title'简短标题
		Save_SQL("author") = author'作者
		Save_SQL("IsTop") = IsTop'置顶
		Save_SQL("isAccept") = 0
		Save_SQL("ATT") = ATT
		Save_SQL("ArticlePic") = ArticlePic
		Save_SQL("TemplateUrl") = TemplateUrl'内容
		Save_SQL("Content") = Content'内容
		Save_SQL("CopyFrom") = CopyFrom'文章来源
		Save_SQL("Keywords") = Keywords'关键字
		Save_SQL("rev") = rev'评论
		If Instr(strFileName,"{id}") > 0 Then strFileName = Replace(strFileName,"{id}",Save_SQL("id"))
		Save_SQL("FileName")=strFileName
		Save_SQL("UpdateTime") = Now()
		Save_SQL("PicUrl") = PicUrl'图片文章地址
		Save_SQL("ArticleInput") = ""
		Save_SQL("ArticlePic") = ArticlePic'是否是图片文章
		Save_SQL.update
		Dim ID:ID = Save_SQL("ID")
		Dim ACTCode
		Set ACTCode =New ACT_Code
		If ACTCMS.ACT_C(ModeID,3)=1 Then 
			Dim R_Sql,R_RS,PrevArticle,PrevArticleRs
			R_Sql="Select  top 1 * from "&ACTCMS.ACT_C(ModeID,2)&" where ID="& ID &""
			Set R_RS = Server.CreateObject("ADODB.RecordSet")
			R_RS.Open R_Sql, Conn, 1, 1
			Call ACTCode.ArticleContent(ModeID,R_RS)
			Set PrevArticleRs = Server.CreateObject("ADODB.RecordSet")
			PrevArticle="Select top 1 * from "&ACTCMS.ACT_C(ModeID,2)&" where ClassID ='"& R_RS("ClassID") &"' and id<"& ID &"  and isAccept=0 AND delif=0 order by ID desc"
				PrevArticleRs.Open PrevArticle, Conn, 1, 1
				If Not PrevArticleRs.eof Then 
			 Call ACTCode.ArticleContent(ModeID,PrevArticleRs)
			 End If 
			conn.execute("update "&ACTCMS.ACT_C(ModeID,2)&" set ismake=1 where id=" & ID)
			 R_RS.Close:Set R_RS=Nothing:PrevArticleRs.Close:Set PrevArticleRs=Nothing
		End If 

		If ACTCMS.ACT_C(ModeID,9) = 2 Then 
			  Dim I,FolderIDArr:FolderIDArr=Split(ACTCMS.GetClassNavStr(ClassID),",")
			  For I=0 To Ubound(FolderIDArr)-1
				Call MakeFolder(Trim(FolderIDArr(i)))
			  Next
		End If

		Sub MakeFolder(ClassID)
		    Dim FolderSql,FolderRS:Set FolderSql=Server.CreateObject("Adodb.Recordset")
			FolderSql = "Select * from Class_ACT where ModeID=" & ModeID &"  and ChangesLinkUrl =''  And classID ='" & ClassID & "'"
			Set FolderRS = Server.CreateObject("ADODB.RecordSet")
			FolderRS.Open FolderSql, Conn, 1, 1
			Call ACTCode.CreateArticleList(ModeID,FolderRS)
			 FolderRS.Close:Set FolderRS=Nothing
		End Sub 

		Public Function LoginCheck()
		on error resume next
		Dim UserName,PassWord
				UserName = ACTCMS.RSQL(Request("UserName"))
				PassWord = ACTCMS.RSQL(Request("PassWord"))
				IF UserName="" Or PassWord = "" Then
					Response.Write("[err]777错误：请填写完整帐户密码[/err]")
					Response.End
				Else
					Dim UserRs
					Set UserRs = ActCMS.ActExe("Select * From Admin_ACT Where Admin_Name='" & UserName & "' And PassWord='" & md5(PassWord) & "'")
					IF  UserRS.Eof  Then
						Response.Write("[err]888错误:\n请检查用户名和密码的正确性[/err]")
						Response.End
					End if
					UserRS.Close:Set UserRS=Nothing
			   End IF
		End Function 
		Save_SQL.Close:Set Save_SQL=Nothing

%>