<!--#include file="../fy.Function.asp"-->
<!--#include file="../../fy_inc/fy.Code.asp"-->
<!--#include file="../../Field.asp"-->
<%
	Dim Save_Rs,ClassIDValue,Save_Rs1,Getrootid,Articleadd,EnName,ShowErr,Save_SQL,Save_SQL1,ClassID
	Dim ClassName,Extension,ClassKeywords,ClassDescription,ChangesLinkUrl 
	dim ismenu,tg,classename,ConTentTemplate,sitepath,moresite,siteurl,ACTlink
	Dim TGGroupID,OrderID,FolderTemplate,ModeID,FilePathName,content,makehtmlname,pageTemplate
	dim ClassPurview,ClassArrGroupID,ClassReadPoint,ClassChargeType ,ClassPitchTime,ClassReadTimes,ClassDividePercent
	Dim SEOtitle,ClassPicUrl,labelfor,classmake 
	 ModeID = ChkNumeric(Request("ModeID"))
	 labelfor= ChkNumeric(Request("labelfor"))
	 if ModeID=0 or ModeID="" Then ModeID=1
		If Not fycms.fycms_QXYZ(ModeID,"","") Then   Call fycms.Alert("对不起，您没有"&fycms.ACT_C(ModeID,1)&"系该项操作权限！","")
	ClassPicUrl=Request.Form("ClassPicUrl")
	TGGroupID=Request.Form("TGGroupID")
	ClassID = Request.form("ClassID")
	SEOtitle=Request.form("SEOtitle")
	OrderID = ChkNumeric(Request.form("OrderID"))
	classmake = ChkNumeric(Request.form("classmake"))
	
	Getrootid = Request.form("rootid")
	ClassName = Trim(Request.Form("ClassName"))
	Extension = Trim(Request.Form("Extension"))
	If Extension<>"" Then Extension="index.html"
	ClassDescription = Request.Form("ClassDescription")
	ClassKeywords = Request.Form("ClassKeywords")
	FolderTemplate = Request.Form("FolderTemplate")
	ChangesLinkUrl = Request.Form("ChangesLinkUrl")
	ismenu = ChkNumeric(Request.Form("ismenu"))
	tg = ChkNumeric(Request.Form("tg"))
	ACTlink = ChkNumeric(Request.Form("ACTlink"))

 
	FolderTemplate = Request.Form("FolderTemplate")
	ConTentTemplate = Request.Form("ConTentTemplate")
	FilePathName = fycms.S("FilePathName")

 
	ClassPurview = ChkNumeric(Request.form("ClassPurview"))
	ClassReadPoint = ChkNumeric(Request.form("ClassReadPoint"))
	ClassChargeType = ChkNumeric(Request.form("ClassChargeType"))
	ClassPitchTime = ChkNumeric(Request.form("ClassPitchTime"))
	ClassReadTimes = ChkNumeric(Request.form("ClassReadTimes"))
	ClassDividePercent = ChkNumeric(Request.form("ClassDividePercent"))
	ClassArrGroupID = Request.form("ClassArrGroupID")
 
	content= fycms.S("content")
	makehtmlname= fycms.S("makehtmlname")
	pageTemplate= fycms.S("pageTemplate")

	If ActLink="2"  Then  makehtmlname=fycms.S("LinkUrl")
 '----------------------------------------------------------
	moresite = ChkNumeric(Request.Form("moresite"))
	siteurl = Request.Form("siteurl")
	sitepath = Request.Form("sitepath")
'----------------------------------------------------------


 
   Function checkclassValueOnly(ID,ModeID,cField,cFieldName,istype)
	Dim editsql:If ID<>0 Then editsql=" and classid<>"&id&" "
	Dim cf:Set cf=fycms.actexe("Select top 1 id From class_fy  Where "&cField&"='"&rsql(fycms.s(cField))&"' "&editsql&"")
	If istype="NumberType" Then 
		Set cf=fycms.actexe("Select top 1 id From class_fy  Where "&cField&"="&ChkNumeric(fycms.s(cField))&" "&editsql&"")
	Else 
		Set cf=fycms.actexe("Select top 1 id From class_fy  Where "&cField&"='"&rsql(fycms.s(cField))&"' "&editsql&"")
	End If 
	If Not cf.eof Then Call  fycms.ALERT(cFieldName&"不能有重复","")
    End Function


	Dim IF_NULL
	IF_NULL=fycms.Act_MX_Arr(888,5)

  	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 checkclassValueOnly(classid,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  Call  fycms.ALERT(IF_NULL(1,I)&"不能为空","")
		Next
	End If


 



	If Trim(TGGroupID)="" Then TGGroupID=0
	IF Trim(ClassName) = ""  Then
		ShowErr = "请填写文章分类名称"
		Call fycms.ActErr(ShowErr,"","1")
		Response.End
	End If

	IF Trim(FolderTemplate) = ""  Then
 		ShowErr = "栏目模板地址不能为空"
		Call fycms.ActErr(ShowErr,"","1")
		Response.End
 	End If

	IF Trim(ConTentTemplate) = ""  Then
 		ShowErr = "内容页模板地址不能为空"
		Call fycms.ActErr(ShowErr,"","1")
		Response.End
	 
	End If

	IF fycms.s("ChangesLink") = "1"  Then 
		IF Trim(ChangesLinkUrl) = ""  Then
			ShowErr = "请填写转向链接地址"
			Call fycms.ActErr(ShowErr,"","1")
			Response.End
		End If
	Else
		ChangesLinkUrl=""
	End If
	

  	ClassIDValue = fycms.GetRand&fycms.MakeRandom(3)'随机生成15位字符
	Set Save_SQL = server.CreateObject("adodb.recordset")
 	
		Dim TemplateContent,makenames
		Dim MakePage,namearr,i,namearrs
		Set MakePage =New ACT_Code
	IF Request("Action") = "add" Then
		If  Request.Form("IFPinYin") = "1" Then
			EnName = fycms.GetEn(fycms.PinYin(ClassName))
		Else
			IF fycms.Chkchars(Request.Form("EnName")) = False  Then
				ShowErr = "栏目目录只能为英文、数字及下划线"
				Call fycms.ActErr(ShowErr,"","1")
				Response.End
			Else
				EnName = Trim(Request.Form("EnName"))
			End if
		End If
		
		
 		Dim gtf
		Call fycms.getran(ClassIDValue)
		ClassIDValue=gtf
		If ClassID <> "" Then
			Set Save_Rs = server.CreateObject("adodb.recordset")
			Save_Rs.Open "Select ID,ClassEname from Class_fy where ClassID="& ClassID &" order by id desc",Conn,1,3
			'ClassEname = Save_Rs("ClassEname")&EnName&"/"
			ClassEname = request("onEnName")&EnName&"/"
 		Else 
			ClassEname = EnName&"/"
			Set Save_Rs = nothing
		End IF
		
		Set Save_Rs1 = server.CreateObject("adodb.recordset")
		
		
		If Getrootid="0" Then 
			Articleadd ="Select ID from Class_fy where EnName='"& trim(EnName) &"' And rootid=0 and ModeID="&ModeID&""
			'添加根目录
		Else
			Articleadd ="Select ID from Class_fy where rootid="&Getrootid&" and EnName='"& trim(EnName) &"' and ModeID="&ModeID&""
			'下级分类
		End If
 		Save_Rs1.Open Articleadd,Conn,1,3
		if Not (Save_Rs1.eof and Save_Rs1.bof)  then
			if trim(request("ChangesLink"))<>"0" then
				ShowErr = "栏目英文名称重复，请重新输入"
				Call fycms.ActErr(ShowErr,"","1")
				Response.end
			End  If 
		End if
		set Save_Rs1 = nothing
		Save_SQL1 = "Select * from Class_fy where 1=2"
		Save_SQL.Open Save_SQL1,Conn,1,3
		Save_SQL.AddNew
		Save_SQL("ClassName") = ClassName
		Save_SQL("ClassEName") = ClassEName
		Save_SQL("EnName") = EnName
		Save_SQL("ModeID") = ModeID
		Save_SQL("ClassID") = ClassIDValue
		Save_SQL("rootid") = Getrootid
		Save_SQL("OrderID") = OrderID
		Save_SQL("Extension") = Extension
		Save_SQL("ClassKeywords") = ClassKeywords
		Save_SQL("ClassDescription") = ClassDescription
 		Save_SQL("ConTentTemplate") = ConTentTemplate
 		Save_SQL("ismenu") = ismenu
 		Save_SQL("SEOtitle") = SEOtitle
		Save_SQL("tg") = tg
		Save_SQL("ModeID") = ModeID
		Save_SQL("TGGroupID") = TGGroupID
		Save_SQL("moresite") = moresite
		Save_SQL("siteurl") = siteurl
		Save_SQL("sitepath") = sitepath
		Save_SQL("FilePathName")=FilePathName
		Save_SQL("content")=content
		Save_SQL("makehtmlname")=makehtmlname
		Save_SQL("ClassPurview")=ClassPurview
		Save_SQL("ClassReadPoint")=ClassReadPoint
		Save_SQL("ClassChargeType")=ClassChargeType
		Save_SQL("ClassPitchTime")=ClassPitchTime
		Save_SQL("ClassReadTimes")=ClassReadTimes
		Save_SQL("ClassDividePercent")=ClassDividePercent
		Save_SQL("ClassArrGroupID")=ClassArrGroupID
		Save_SQL("ClassPicUrl")=ClassPicUrl
		Save_SQL("labelfor")=labelfor
 		Save_SQL("FolderTemplate")=FolderTemplate
 		Save_SQL("ACTlink")=ACTlink
 		Save_SQL("classmake")=classmake
 
		




	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
		Application.Contents.RemoveAll
  		Dim rs:Set rs=fycms.actexe("Select top 1 * from Class_fy order by id desc")
		If Not rs.eof Then ClassID = rs("ClassID")
   		If ActLink=3 Then 
 			makenames=makehtmlname
			Application(fycmsN & "fycms_TCJ_Type")= "Folder"
			Application(fycmsN & "classid")=  ClassID
			Application(fycmsN & "modeid")= fycms.ACT_L(ClassID,10)
 			TemplateContent = MakePage.CreateArticleList(ModeID,rs)
	    End If 
   		
 		Call fycms.ActErr("栏目添加成功","fy_Mode/fy.Class.asp?ModeID="&ModeID&"","")
 	ElseIF  Request("Action") = "edit" Then
  		Save_SQL1 = "Select * from Class_fy where ClassID="&ClassID &""
		Save_SQL.Open Save_SQL1,Conn,1,3
		Save_SQL("ClassName") = ClassName
		Save_SQL("Extension") = Extension
		Save_SQL("ClassKeywords") = ClassKeywords
		Save_SQL("ClassDescription") = ClassDescription
 		Save_SQL("ConTentTemplate") = ConTentTemplate
		Save_SQL("ismenu") = ismenu
 		Save_SQL("SEOtitle") = SEOtitle
		Save_SQL("tg") = tg
		Save_SQL("TGGroupID") = TGGroupID
		Save_SQL("OrderID") = OrderID
		Save_SQL("ModeID") = ModeID
		Save_SQL("moresite") = moresite
		Save_SQL("siteurl") = siteurl
		Save_SQL("sitepath") = sitepath
		Save_SQL("FilePathName")=FilePathName
 		Save_SQL("content")=content
		Save_SQL("makehtmlname")=makehtmlname
		Save_SQL("ClassPurview")=ClassPurview
		Save_SQL("ClassReadPoint")=ClassReadPoint
		Save_SQL("ClassChargeType")=ClassChargeType
		Save_SQL("ClassPitchTime")=ClassPitchTime
		Save_SQL("ClassReadTimes")=ClassReadTimes
		Save_SQL("ClassDividePercent")=ClassDividePercent
		Save_SQL("ClassArrGroupID")=ClassArrGroupID
		Save_SQL("ClassPicUrl")=ClassPicUrl
		Save_SQL("labelfor")=labelfor
 		Save_SQL("FolderTemplate")=FolderTemplate
 		Save_SQL("ACTlink")=ACTlink

 		
		If  ChkNumeric(Request.form("EditEname"))=1 Then 
  			If Right(Request.form("EnName"),1)<>"/" Then 
				Save_SQL("ClassEName")=request("EnName")&"/"
			Else 
				Save_SQL("ClassEName")=request("EnName")
			End If 
  		End if
 		ModeID=Save_SQL("ModeID") 
 		Save_SQL("classmake")=classmake







		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) & "" )= 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
		ShowErr = "栏目保存成功"
	End If

	If ActLink=3 Then 
			Application(fycmsN & "fycms_TCJ_Type")= "Folder"
			Application(fycmsN & "classid")=  ClassID
			Application(fycmsN & "modeid")= fycms.ACT_L(ClassID,10)



   		If ActLink=3 Then 
 			Set rs=fycms.actexe("Select top 1 * from Class_fy where classid="&classid&" order by id desc")
			If Not rs.eof then
 				TemplateContent = MakePage.CreateArticleList(ModeID,rs)
 			End If 
		End If 
   	End If 
	
	Application.Contents.RemoveAll
	Save_SQL.close:set Save_SQL = Nothing
	Call fycms.ActErr(ShowErr,"fy_Mode/fy.Class.asp?ModeID="&ModeID&"","")
   %>