<!--#include file="admin_start.asp"-->

<%
dim id
dim ids
dim n_ids

id=request("id")
ids=request("ids")
ids=replace(ids," ","")
n_ids=""


if not MySys.check.isInteger(id) and request("action")="edit" then
MySys.error.info="请选择您要操作的项目！"
MySys.error.location="back"
MySys.error.err()
end if

function FarmatLabelArgument(s)

	s=replace(s,"{$$","{##")
	s=replace(s,"{$","{#")
	s=replace(s,"$}","#}")
	s=replace(s,"""","""""")
	s=replace(s,vbcrlf,"""&vbcrlf&""")
	FarmatLabelArgument=s
	
end function

select case request("action")
case "delete"

	dim i
	if ids="" then
		MySys.error.info="请选择你要删除的标签！"
		MySys.error.location="back"
		MySys.error.err()
	end if		
	
	conn.execute("delete from jins_template_label where label_id in ("&ids&") ")

	MySys.error.info="删除标签成功！"
	MySys.error.location="back"
	MySys.error.suc()
	
case else

	if request("label_project")<>"" then label_project=int(request("label_project")) else label_project=0
	
	if request("action")="add" then
	    sql="select * from jins_template_label "
		if not conn.execute("select label_name from jins_template_label where label_project="&label_project&" and label_name='"&trim(request("label_name"))&"' ").eof then
			MySys.error.info="此模版方案下已经存在同名的自定义标签！请重新输入自定义标签的名称"
			MySys.error.location="back"
			MySys.error.suc()
		end if
	else
	    sql="select * from jins_template_label where label_id="&id&" "
	end if
	
	rs.open sql,conn,1,3
	
	'/////////////////////////////////////////////检测
	
	if request("action")="add" then
	    rs.addnew
		MySys.error.info="标签添加成功！"
	    MySys.error.location="admin/admin_template_label_list.asp"
	else
		MySys.error.info="标签编辑成功！"
	    MySys.error.location="back"
	end if

	if request("action")="edit" and rs.eof then
		MySys.error.info="您选择的标签不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if request("action")="edit" then
		if rs("label_project")=label_project then
			if rs("label_name")<>trim(request("label_name")) then
				if not conn.execute("select label_name from jins_template_label where label_project="&label_project&" and label_name='"&trim(request("label_name"))&"' ").eof then
						MySys.error.info="此模版方案下已经存在同名的自定义标签！请重新输入自定义标签的名称"
						MySys.error.location="back"
						MySys.error.suc()
				end if
			end if
		else
			if not conn.execute("select label_name from jins_template_label where label_project="&label_project&" and label_name='"&trim(request("label_name"))&"' ").eof then
						MySys.error.info="此模版方案下已经存在同名的自定义标签！请重新输入自定义标签的名称"
						MySys.error.location="back"
						MySys.error.suc()
			end if
		end if
	end if
	
	if request("label_name")=""  or request("label_type")=""then 	
		MySys.error.info="请完整填写相关项目！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if request("label_type")=1 and (request("label_argument_0")="" or  request("label_sql")="")then 	
		MySys.error.info="您选择的是动态标签，请完整填写相关项目！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	label_content=trim(request("label_content"))
	
	if request("label_type")=1 then
	
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		'label_sql=trim(request("label_sql"))
		'label_sql=replace(label_sql,"{$","{#")
		'label_sql=replace(label_sql,"$}","#}")
		'label_sql=replace(label_sql,vbcrlf,"")
		
		'label_argument_0=trim(request("label_argument_0"))
		'label_argument_0=replace(label_argument_0,"{$$","{##")
		'label_argument_0=replace(label_argument_0,"{$","{#")
		'label_argument_0=replace(label_argument_0,"$}","#}")
		'label_argument_0=replace(label_argument_0,"""","""""")
		'label_argument_0=replace(label_argument_0,vbcrlf,"""&vbcrlf&""")
		
		'label_argument_2=trim(request("label_argument_2"))
		'label_argument_3=trim(request("label_argument_3"))
		'label_argument_4=trim(request("label_argument_4"))
		'label_argument_5=trim(request("label_argument_5"))
		'if label_argument_4<>"" then label_argument_4=replace(label_argument_4,vbcrlf,"""&vbcrlf&""")
		'if label_argument_5<>"" then label_argument_5=replace(label_argument_5,vbcrlf,"""&vbcrlf&""")
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		label_sql=FarmatLabelArgument(trim(request("label_sql")))
		label_argument_0=FarmatLabelArgument(trim(request("label_argument_0")))
		label_argument_1=FarmatLabelArgument(trim(request("label_argument_1")))
		label_argument_2=FarmatLabelArgument(trim(request("label_argument_2")))
		label_argument_3=FarmatLabelArgument(trim(request("label_argument_3")))
		label_argument_4=FarmatLabelArgument(trim(request("label_argument_4")))
		label_argument_5=FarmatLabelArgument(trim(request("label_argument_5")))
		'label_argument_6=FarmatLabelArgument(trim(request("label_argument_6")))
		
		'if instr(1,label_sql,"select",1)>0 then label_sql=""""&label_sql&"""" else label=label
		label_content_loop="{$Handle_Label_Loop("""&label_sql&""","""&label_argument_1&""","""&label_argument_2&""","""&label_argument_0&""","""&label_argument_3&""","""&label_argument_4&""","""&label_argument_5&""")$}"
		label_content=replace(label_content,"{$loop$}",label_content_loop)
		
	end if
	
	'/////普通项
	if request("label_name")<>"" then rs("label_name")=trim(request("label_name"))
	rs("label_link")=int(request("label_link"))
	if request("label_type")<>"" then rs("label_type")=int(request("label_type"))
	if request("label_description")<>"" then rs("label_description")=trim(request("label_description"))
	if request("label_addtime")<>"" then rs("label_addtime")=trim(request("label_addtime"))
	rs("label_project")=label_project
	if label_content<>"" then rs("label_content")=label_content
	if label_sql<>"" then rs("label_sql")=trim(request("label_sql"))
	if request("label_type")=1 then rs("label_argument")=request("label_argument_0")&"<#>"&request("label_argument_1")&"<#>"&request("label_argument_2")&"<#>"&request("label_argument_3")&"<#>"&request("label_argument_4")&"<#>"&request("label_argument_5")
	if request("action")="add" then rs("label_cache_timeout")=int(trim(request("label_cache_timeout")))
	rs.update
	
	rs.close

	MySys.error.suc()

	'/////////////////////////////////////////////
end select

%>
<!--#include file="admin_end.asp"-->
