<!--#include file="base.asp"-->
<!--#include file="common.asp"-->
<%
''' EYCMS 区块
''' ==================================================================
	sub adddb()
		dim mode:mode=eycms.enhtml(eycms.fget("mode",0))
		dim t0:t0=eycms.enhtml(eycms.fpost("t0",0))
		dim t1:t1=eycms.enhtml(eycms.fpost("t1",0))
		dim t2:t2=eycms.fpost("t2",1)
		if not(eycms.checkstr(t0,"en")) then
			eycms.ajaxjson "区块名称只能是英文字母",0:exit sub
		end if
		if instr(t0,"isedit") then
			eycms.ajaxjson "区块名称不能包含isedit",0:exit sub
		end if
		if t1="" then
			eycms.ajaxjson "区块说明不能为空",0:exit sub
		end if
		if t2="" then
			eycms.ajaxjson "区块内容不能为空",0:exit sub
		end if
		if mode="editor" then t0=t0&"isedit"
		if eycms.isfile("../theme/"&theme_root&"/block/"&t0&".asp") then
			eycms.ajaxjson "区块已存在",0:exit sub
		end if

		'木马检测开始************************************************
		if chkhack(t2) 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&">"
		t2=replace(t2,is_end,"")
		t2=is_end&t2
		eycms.newfile "../theme/"&theme_root&"/block/",t0&".asp",t2,""
		updateBaseXml theme_root&"/block/"&t0&".asp",t1
		if tempencry then
			dim fileStr:fileStr=getRemoteEncry_new(t2,theme_root,"block")
			if left(fileStr,3)<>"ERR" and eycms.strlen(fileStr)>0 then
				eycms.newfile "../encry/theme/"&theme_root&"/block/",t0&".asp",fileStr,""
				eycms.ajaxjson "保存成功",1
			else
				eycms.ajaxjson "保存失败",0
			end if
		else
			eycms.ajaxjson "保存成功",1
		end if
	end sub
	
	sub editdb()
		dim filename:filename=eycms.fget("filename",0)
		dim t0:t0=eycms.enhtml(eycms.fpost("t0",0))
		dim t1:t1=eycms.fpost("t1",1)
		if not(eycms.checkstr(filename,"en")) then
			eycms.ajaxjson "区块名称只能是英文字母",0:exit sub
		end if
		if not(eycms.isfile("../theme/"&theme_root&"/block/"&filename&".asp")) then
			eycms.ajaxjson "区块不存在",0:exit sub
		end if
		if t0="" then
			eycms.ajaxjson "区块说明不能为空",0:exit sub
		end if

		'木马检测开始************************************************
		if chkhack(t1) 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(t1,is_end)<=0 then
			t1=is_end&t1
		end if
		eycms.newfile "../theme/"&theme_root&"/block/",filename&".asp",t1,""
		updateBaseXml theme_root&"/block/"&filename&".asp",t0
		if tempencry then
			dim fileStr:fileStr=getRemoteEncry_new(t1,theme_root,"block")
			if left(fileStr,3)<>"ERR" and eycms.strlen(fileStr)>0 then
				eycms.newfile "../encry/theme/"&theme_root&"/block/",filename&".asp",fileStr,""
				eycms.ajaxjson "保存成功",1
			else
				eycms.ajaxjson "保存失败",0
			end if
		else
			eycms.ajaxjson "保存成功",1
		end if
	end sub
	
	sub deldb()
		dim id:id=eycms.fget("id",0)
		dim fileon:fileon=0
		if eycms.isfile("../theme/"&theme_root&"/block/"&id&".asp") then
			eycms.delfile "../theme/"&theme_root&"/block/"&id&".asp"
			fileon=1
		end if
		if eycms.isfile("../encry/theme/"&theme_root&"/block/"&id&".asp") then
			eycms.delfile "../encry/theme/"&theme_root&"/block/"&id&".asp"
			fileon=1
		end if
		if fileon=0 then
			eycms.echo "0区块名称错误"
			exit sub
		end if

		if eycms.isfile("../theme/"&theme_root&"/base.xml") Then
			dim xml,i,objNode,rootNode
			set xml=server.createobject("microsoft.xmldom")
			xml.async=false
			xml.load(server.mappath("../theme/"&theme_root&"/base.xml"))
			set objNode = xml.documentElement
				set rootNode = objNode.selectSingleNode("/config/item/seturl[.='block/"&id&".asp']").parentNode
				if rootNode.childNodes.length>0 then
					xml.DocumentElement.RemoveChild(rootNode)
				end if
			xml.save(server.mappath("../theme/"&theme_root&"/base.xml")) 
			set rootNode=nothing
			set objNode=nothing
			set xml=nothing
		end If
		eycms.echo "1"
	end sub

	islogin
	checkpagelever 30
	dim filename,block_txt,temp_content,r_mid
	dim act:act=lcase(eycms.fget("act",0))
	dim islocal:islocal=0
	if eycms.isfolder(webroot&"theme/"&theme_root&"/model") then islocal=1
	select case act
		case "add","add_none":load eval("theme_block_"&act)
		case "adddb":adddb
		case "edit","edit_none"
			filename=eycms.fget("filename",0)
			if not(eycms.checkstr(filename,"en")) then
				eycms.echo "filename is wrong"
				eycms.die
			end if
			if not(eycms.isfile("../theme/"&theme_root&"/block/"&filename&".asp")) then
				eycms.echo "filename is wrong"
				eycms.die
			end if
			block_txt=getblockname("block/"&filename&".asp")
			temp_content=eycms.loadfile("../theme/"&theme_root&"/block/"&filename&".asp")
			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&">"
			temp_content=replace(temp_content,r_mid,"")
			load eval("theme_block_"&act)
		case "editdb":editdb

		case "editremote","editremote_none"
			filename=eycms.fget("filename",0)
			if not(eycms.checkstr(filename,"en")) then
				eycms.echo "filename is wrong"
				eycms.die
			end if
			if not(eycms.isfile("../encry/theme/"&theme_root&"/block/"&filename&".asp")) then
				eycms.echo "filename is wrong"
				eycms.die
			end if
			block_txt=getblockname("block/"&filename&".asp")
			temp_content=getRemoteTheme("block/"&filename&".asp",site_root)

			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&">"
			temp_content=replace(temp_content,r_mid,"")
			load eval("theme_block_"&replace(act,"remote",""))
		case "call":filename=eycms.fget("filename",0):load theme_block_call
		case "del":deldb
		case else
			if not(eycms.isfolder("../encry/theme/"&theme_root&"/block/")) then
				eycms.newfolder "../encry/theme/"&theme_root&"/block/"
			end if
			load theme_block
	end select
	eycms.db.dbclose
%>