<!--#include file="../ACT.Function.asp"-->
<%
	Dim Save_Rs,ClassIDValue,Save_Rs1,GetParentID,Articleadd,EnName,ShowErr,Save_SQL,Save_SQL1,ClassID
	Dim ClassName,Extension,ClassKeywords,ClassDescription,ChangesLinkUrl 
	dim dh,tg,classename,ConTentTemplate
	Dim TGGroupID,OrderID,GroupIDClass,FolderTemplate,ModeID
	 ModeID = ACTCMS.ChkNumeric(Request("ModeID"))
	 if ModeID=0 or ModeID="" Then ModeID=1
		If Not ACTCMS.ACTCMS_QXYZ(ModeID,"","") Then   Call Actcms.Alert("对不起，您没有"&ACTCMS.ACT_C(ModeID,1)&"系该项操作权限！","")

	TGGroupID=Request.Form("TGGroupID")
	ClassID = Request.form("ClassID")
	GroupIDClass=ACTCMS.s("GroupIDClass")
	OrderID = ACTCMS.ChkNumeric(Request.form("OrderID"))
	GetParentID = Request.form("ParentID")
	ClassName = Trim(Request.Form("ClassName"))
	Extension = Trim(Request.Form("Extension"))
	ClassDescription = Request.Form("ClassDescription")
	ClassKeywords = Request.Form("ClassKeywords")
	FolderTemplate = Request.Form("FolderTemplate")
	ChangesLinkUrl = Request.Form("ChangesLinkUrl")
	dh = ACTCMS.ChkNumeric(Request.Form("dh"))
	tg = ACTCMS.ChkNumeric(Request.Form("tg"))
	FolderTemplate = Request.Form("FolderTemplate")
	ConTentTemplate = Request.Form("ConTentTemplate")
	If Trim(TGGroupID)="" Then TGGroupID=0
	IF Trim(ClassName) = ""  Then
		ShowErr = "<li>请填写文章分类名称</li>"
		Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
		Response.End
	End If

	IF Trim(FolderTemplate) = ""  Then
		ShowErr = "<li>栏目模板地址不能为空</li>"
		Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
		Response.End
	End If
	IF Trim(ConTentTemplate) = ""  Then
		ShowErr = "<li>内容页模板地址不能为空</li>"
		Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
		Response.End
	End If

	IF ACTCMS.s("ChangesLink") = "1"  Then 
		IF Trim(ChangesLinkUrl) = ""  Then
			ShowErr = "<li>请填写转向链接地址</li>"
			Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
			Response.End
		End If
	Else
		ChangesLinkUrl=""
	End IF
	
	ClassIDValue = ACTCMS.MakeRandom(10)'随机生成15位字符
	Set Save_SQL = server.CreateObject("adodb.recordset")
	IF Request("Action") = "add" Then
		If  Request.Form("IFPinYin") = "1" Then
			EnName = ACTCMS.GetEn(ACTCMS.PinYin(ClassName))
		Else
			IF ACTCMS.Chkchars(Request.Form("EnName")) = False  Then
				ShowErr = "<li>英文名称只能为英文、数字及下划线</li>"
				Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
				Response.End
			Else
				EnName = Trim(Request.Form("EnName"))
			End if
		End If
		
		Set Save_Rs = server.CreateObject("adodb.recordset")
		Save_Rs.Open "Select ID from Class_Act where ClassID='"& ClassIDValue &"' order by id desc",Conn,1,3
		if  Not Save_Rs.eof then
				ShowErr = "<li>栏目ClassID意外出现重复，请重新输入</li>"
				Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
				Response.end
		End if
		Set Save_Rs = nothing
		
	
		If ClassID <> "" Then
		Set Save_Rs = server.CreateObject("adodb.recordset")
		Save_Rs.Open "Select ID,ClassEname from Class_Act where ClassID='"& ClassID &"' order by id desc",Conn,1,3
		ClassEname = Save_Rs("ClassEname")&EnName&"/"
		else
		ClassEname = EnName&"/"
		Set Save_Rs = nothing
		End IF
		
		Set Save_Rs1 = server.CreateObject("adodb.recordset")
		
		If GetParentID="0" Then 
			Articleadd ="Select ID from Class_Act where EnName='"& trim(EnName) &"' And ParentID='0' and ModeID="&ModeID&""
			'添加根目录
		Else
			Articleadd ="Select ID from Class_Act where ParentID='"&GetParentID&"' 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 = "<li>栏目英文名称重复，请重新输入</li>"
				Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl="&"&Title=1")
				Response.end
			End  If 
		End if
		set Save_Rs1 = nothing
		Save_SQL1 = "Select * from Class_Act 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("ParentID") = GetParentID
		Save_SQL("OrderID") = OrderID
		Save_SQL("Extension") = Extension
		Save_SQL("ClassKeywords") = ClassKeywords
		Save_SQL("ClassDescription") = ClassDescription
		Save_SQL("FolderTemplate") = FolderTemplate
		Save_SQL("ConTentTemplate") = ConTentTemplate
		Save_SQL("ChangesLinkUrl") = ChangesLinkUrl
		Save_SQL("dh") = dh
		Save_SQL("tg") = tg
		Save_SQL("ModeID") = ModeID
		Save_SQL("GroupIDClass") = GroupIDClass
		Save_SQL("TGGroupID") = TGGroupID
		Save_SQL.update
		Application.Contents.RemoveAll
		ShowErr = "<li>栏目添加成功 </li>"
		Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl=Article/ACT.Class.asp"&"&Title=")
	ElseIF  Request("Action") = "edit" Then
		Save_SQL1 = "Select * from Class_Act 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("FolderTemplate") = FolderTemplate
		Save_SQL("ConTentTemplate") = ConTentTemplate
		Save_SQL("dh") = dh
		Save_SQL("tg") = tg
		Save_SQL("GroupIDClass") = GroupIDClass
		Save_SQL("TGGroupID") = TGGroupID
		Save_SQL("OrderID") = OrderID
		Save_SQL("ChangesLinkUrl") = Request.Form("ChangesLinkUrl")

		Save_SQL.update
		ShowErr = "<li>栏目保存成功 </li>"
	End If
	Application.Contents.RemoveAll
Save_SQL.close:set Save_SQL = Nothing
Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl=Article/ACT.Class.asp"&"&Title=")
 %>