<!--#include file="../../fy_inc/fy.User.asp"-->

<%
'echo md5("dd")
Dim ClassID,Title,Save_SQL,filenametype,isAccept,Content,Keywords,ArticlePic,PicUrl
Dim author,Hits,Hots,IsTop,Mar,Rec,CopyFrom,rank,rev,ModeID,TemplateUrl,ATT,ArticleInput 
Call LoginCheck
ModeID = ChkNumeric(Request("ModeID"))
If ModeID = 0 Then ModeID = 1
filenametype=".html"'生成文件格式
ClassID = fycms.S("ClassID")'所属栏目ID
Title=fycms.S("Title")
Content=fycms.S("Content")
author = fycms.S("author")
PicUrl = fycms.S("PicUrl")
ArticleInput = fycms.S("ArticleInput")
KeyWords = fycms.S("KeyWords")
Hits = ChkNumeric(fycms.S("Hits"))
Hots = ChkNumeric(fycms.S("Hots"))
IsTop = ChkNumeric(fycms.S("IsTop"))
isAccept = ChkNumeric(fycms.S("isAccept"))
rank = fycms.S("rank")
CopyFrom = fycms.S("CopyFrom")
rev = ChkNumeric(fycms.S("rev"))
ATT = ChkNumeric(fycms.S("ATT"))


	Dim IF_NULL:IF_NULL=fycms.Act_MX_Arr(ModeID,1)
	Dim i
  	If IsArray(IF_NULL) Then
		For I=0 To Ubound(IF_NULL,2)
		 If IF_NULL(8,I)=0  And Trim(fycms.S(IF_NULL(0,I)))<>""  Then  Call fycms.checkValueOnly(ID,ModeID,IF_NULL(0,I),IF_NULL(1,I),IF_NULL(3,I))
 		 If IF_NULL(2,I)=0 And Trim(fycms.S(IF_NULL(0,I)))="" Then  echo "[err]"&IF_NULL(1,I)&"不能为空"&"[/err]"  
		Next
	End If



 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
		If  Request.Form("FileName")="" Then '获取文件名并且解析
			strFileName=fycms.ACT_L(ClassID,16)
			If Instr(strFileName,"{y}") > 0 Then strFileName = Replace(strFileName,"{y}",Right("0" & Year(Now), 2))
			If Instr(strFileName,"{yy}") > 0 Then strFileName = Replace(strFileName,"{yy}", Year(Now))
			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,"{enname}") > 0 Then strFileName = Replace(strFileName,"{enname}",fycms.ACT_L(classid,3))
			If Instr(strFileName,"{md5}") > 0 Then strFileName = Replace(strFileName,"{md5}",MD5(Now))
			If Instr(strFileName,"{rnd}") > 0 Then strFileName = Replace(strFileName,"{rnd}",fycms.GetRandomize(10))
			If Instr(strFileName,"{pinyin}") > 0 Then strFileName = Replace(strFileName,"{pinyin}",fycms.GetEn(fycms.PinYin(fycms.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 = fycms.ActEXE("select ID From "&fycms.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_fy 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 "&fycms.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

	
	
	
	 

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

		Dim sqlstr
		Set Save_SQL = server.CreateObject("adodb.recordset")
		SqlStr = "select * from " & fycms.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") = Title'完整标题
 		Save_SQL("IsTop") = IsTop'置顶
		Save_SQL("author") = author'作者
		Save_SQL("isAccept") = 0
 	        Save_SQL("userid") = 0
		Save_SQL("ATT") = ATT
		Save_SQL("Hits") = Hits
		Save_SQL("delif") = 0
		
			Save_SQL("actlink") = 0
			Save_SQL("FileName") = strFileName'文件名
 			Save_SQL("TemplateUrl") = TemplateUrl'内容
			Save_SQL("Content") = Content'内容
			Save_SQL("CopyFrom") = CopyFrom'文章来源
			Save_SQL("Keywords") = Keywords'关键字
			Save_SQL("rev") = rev'评论
			Save_SQL("uptime") = Now()
			Save_SQL("addtime") = Now()
			Save_SQL("publishtime") = Date()			
			Save_SQL("PicUrl") = PicUrl'图片文章地址
			Save_SQL("ArticleInput") = ArticleInput
			Save_SQL("pinyin") = fycms.GetEn(fycms.PinYin(title))
			
  			
		
			If IsArray(IF_NULL) Then
 				For I=0 To Ubound(IF_NULL,2)
 					Select Case IF_NULL(3,I)
						Case "NumberType"
 						   If fycms.regexField(fycms.S(IF_NULL(0,I)),"^\d+$")=True Then 
							   Save_SQL("" & IF_NULL(0,I) & "" )= ChkNumeric(fycms.S(IF_NULL(0,I)))
						   End If 
						Case "DateType"
							If IsDate(fycms.S(IF_NULL(0,I)))=False Then 
								Save_SQL("" & IF_NULL(0,I) & "")= Now()
							Else 
								Save_SQL("" & IF_NULL(0,I) & "")=fycms.S(IF_NULL(0,I))
							End If
						Case "PicType"
							If IF_NULL(7,I)="1" Then
  							   Save_SQL("" & IF_NULL(0,I) & "")=IF_NULL(0,I)
  							 Else 
  									Save_SQL("" & IF_NULL(0,I) & "")=fycms.S(IF_NULL(0,I))
							 End If 
 						
						Case Else 
 							  If IF_NULL(4,I)="2" Then 
										If fycms.regexField(fycms.S(IF_NULL(0,I)),IF_NULL(5,I))=True Then 
											Save_SQL("" & IF_NULL(0,I) & "")=fycms.S(IF_NULL(0,I))
										Else 
											Call fycms.Alert(IF_NULL(6,I),"")
										End If 
								Else 
									Save_SQL("" & IF_NULL(0,I) & "")=fycms.S(IF_NULL(0,I))
								End If 

 					End Select 
 
					actField=""
 				Next
			End If			
			Save_SQL.update
			Dim rs,id
			Set rs=fycms.actexe("Select top 1 id,classid,FileName from "&fycms.ACT_C(ModeID,2)&"  order by id desc")
			If Not rs.eof Then ID = rs("ID")
			If Instr(strFileName,"{id}") > 0 Then 
				strFileName = Replace(rs("FileName"),"{id}",rs("id"))
				fycms.actexe("Update "&fycms.ACT_C(ModeID,2)&" set FileName='"&strFileName&"' where id="&id)
			End If 
		
		
		
	 

 
		Public Function LoginCheck()
		on error resume next
		Dim UserName,PassWord
				UserName = RSQL(Request("UserName"))
				PassWord = RSQL(Request("PassWord"))
				IF UserName = "" Or PassWord = "" Then
					Response.Write("[err]777错误：请填写完整帐户密码[/err]")
					Response.End
				Else
					Dim UserRs
					Set UserRs = fycms.ActExe("Select * From Admin_fy Where Admin_Name='" & UserName & "' And PassWord='" & md5(PassWord,64) & "'")
					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
		Response.Write("[ok]")'返回成功信息

%>