<!--#include file="base.asp"-->
<!--#include file="common.asp"-->
<%
''' EYCMS 单页
''' ==================================================================

	sub savedb()
		dim t1
		dim datanum
		t1=eycms.ffpost("t1",0)
		if eycms.strlen(t1)=0 then eycms.ajaxjson "&#20869;&#23481;&#19981;&#33021;&#20026;&#31354;",0:exit sub
		datanum=eycms.db.dbcount("ey_model_page","classid="&classid&"")
		if datanum=0 then
			data=array(array("classid",classid,0,0),array("content",t1,0,1))
			eycms.db.insert "ey_model_page",data
		else
			data=array(array("content",t1,0,1))
			eycms.db.dbupdate "ey_model_page","classid="&classid&"",data
		end if
		delall eycms.getfilelist(t1),classid,2
		eycms.ajaxjson "保存成功",1
	end sub

	sub savehtmldb()
		err.clear
		on error resume next
		dim t0:t0=eycms.fpost("t0",0)
		'木马检测开始************************************************
		if chkhack(t0) Then
			eycms.ajaxjson "模板内容含有疑似木马的代码" & hackstr,0
			exit sub
		end If
		'木马检测结束************************************************
		dim is_end:is_end="<%"
		is_end=is_end&"if not in_eycms then response.write(""template load fail""):response.end() end if"
		is_end=is_end&"%"
		is_end=is_end&">"
		if instr(t0,is_end)<=0 then
			t0=is_end&t0
		end if
		dim filename:filename=theme_root&"/"&cateshow
		dim arr:arr=split(filename,"/")
		dim ffname:ffname=arr(ubound(arr))
		dim ffpath:ffpath=replace("../theme/"&filename,ffname,"")
		dim sname,sfolder,fileStr,saveflag
		if islocal=1 then
			eycms.newfile ffpath,ffname,t0,""
			if tempencry then
				ffpath=replace("../encry/theme/"&filename,ffname,"")
				sname=replace(filename,theme_root&"/","")
				sfolder=replace(sname,ffname,"")
				fileStr=getRemoteEncry_new(t0,theme_root,sfolder)
				if left(fileStr,3)<>"ERR" and eycms.strlen(fileStr)>0 then
					eycms.newfile ffpath,ffname,fileStr,""
				else
					eycms.errlog "函数：getRemoteEncry_new<br>参数："&theme_root&"、"&sfolder,0
				end if
			end if
		else
			ffpath=replace("../encry/theme/"&filename,ffname,"")
			sname=replace(filename,theme_root&"/","")
			saveflag=remoteSaveTheme(sname,site_root,t0)
			if left(saveflag,3)<>"ERR" then
				fileStr=getRemoteEncry_site(sname,site_root)
				if left(fileStr,3)<>"ERR" and eycms.strlen(fileStr)>0 then
					eycms.newfile ffpath,ffname,fileStr,""
				else
					eycms.errlog "函数：getRemoteEncry_site<br>参数："&sname&"、"&site_root,0
				end if
			end if
		end if
		eycms.ajaxjson "保存成功",1
		if err then
			eycms.errlog "文件名：ey_model_page.asp<br>函数：savehtmldb<br>详情："&err.description,1
			err.clear
		end if
	end sub

	function get_tree()
		dim mdata,jj,ji
		if eycms.strlen(eycms.getsys("eycms.plug.lable"))>0 then
			for jj=1 to 4
				get_tree=get_tree&""&eycms.iif(jj=1,"",",")
				get_tree=get_tree&"{id:"&jj&",pId:0,name:"""&lablename(jj)&""",val:""""}"
				mdata=eycms.db.dbload("","id,shuomin,title","ey_plug_lable","classid="&jj&"","")
				if ubound(mdata)>=0 then
					for ji=0 to ubound(mdata,2)
						get_tree=get_tree&",{"
						get_tree=get_tree&"id:"&mdata(0,ji)+4&""
						get_tree=get_tree&",pId:"&jj&""
						get_tree=get_tree&",name:"""&mdata(1,ji)&""""
						get_tree=get_tree&",val:"""&filterCode(mdata(2,ji))&""""
						get_tree=get_tree&"}"
					next
				end if
			next
		end if
	end function

	function lablename(t0)
		if eycms.strlen(t0)=0 then lablename="":exit function
		select case t0
		case 1
			lablename="全局标签"
		case 2
			lablename="列表页标签"
		case 3
			lablename="内容页标签"
		case 4
			lablename="自定义标签"
		end select
	end function

	function filterCode(t0)
		if eycms.strlen(t0)=0 then filterCode="":exit function
		dim t1:t1=t0
		t1=replace(t1,"{","")
		t1=replace(t1,"}","")
		t1=replace(t1,"[","(")
		t1=replace(t1,"]",")")
		filterCode=t1
	end function

	islogin
	dim act:act=lcase(eycms.fget("act",0))
	dim classid:classid=eycms.getint(eycms.fget("classid",0),0)
	dim data
	dim content
	dim catedata,catename,cateshow,isdim
	catedata=eycms.getclassdb(classid)
	if not isarray(catedata) then
		eycms.echo "&#26639;&#30446;&#19981;&#23384;&#22312;&#25110;&#24050;&#34987;&#21024;&#38500;"
		eycms.db.dbclose
		eycms.die
	end if
	catename=catedata(1)
	cateshow=catedata(21)
	isdim=1
	if cateshow="model/page/eycms_page.asp" or eycms.strlen(cateshow)=0 then isdim=0

	dim islocal:islocal=0
	if eycms.isfolder(webroot&"theme/"&theme_root&"/model") then islocal=1

	select case act
		case "savedb":savedb
		case "savehtml":savehtmldb
		case "html"
			dim html_content
			if islocal=1 then
				html_content=eycms.loadfile("../theme/"&theme_root&"/"&cateshow)
			else
				html_content=getRemoteTheme(cateshow,site_root)
			end if
			dim r_mid:r_mid="<%"
			r_mid=r_mid&"if not in_eycms then response.write(""template load fail""):response.end() end if"
			r_mid=r_mid&"%"
			r_mid=r_mid&">"
			html_content=replace(html_content,r_mid,"")
			dim block_txt:block_txt=getblockname(cateshow)

			load theme_pageadd_html
		case else
			data=eycms.db.dbload(1,"content","ey_model_page","classid="&classid&"","")
			if ubound(data)>=0 then
				content=data(0,0)
			end if
			load theme_pageadd
	end select
	
	eycms.db.dbclose
%>
