<!--#include file="../../lib/base.asp"-->
<!--#include file="../../lib/cmd.asp"-->
<%
''' 自定义系统参数插件
''' ==================================================================
	eycms.stophack
	'注释：插件是否安装
	is_plug_install "eycms.plug.set"
	
	'注释：管理权限检查
	is_plug_login
	
	'注释：定义插件模板路径
	dim theme_admin_root:theme_admin_root="admin_leo"
	dim plug_theme,plug_theme_add,plug_theme_edit
	plug_theme="module/plug_set/list.html"
	plug_theme_add="module/plug_set/add.html"
	plug_theme_edit="module/plug_set/edit.html"
	
	'接收fget传值
	dim act:act=lcase(eycms.fget("act",0))
	dim id:id=eycms.getint(eycms.fget("id",0),0)
	dim data
			
	select case act
		case "add"
			load plug_theme_add
		case "adddb":adddb:delcache
		case "edit"
			data=eycms.db.dbload(1,"setName,setTitle,setType,setmode,fdatatype,flength,setValue,foptions,IsMust,frules,ordnum,isshow","ey_plug_set","id="&id&"","")
			load plug_theme_edit
		case "editdb":editdb:delcache
		case "order":ordernum:delcache	
		case "del":deldb:delcache
		case else
			load plug_theme
	end select	

	'保存新增字段
	sub adddb()
		dim t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t2=eycms.getint(eycms.fpost("t2",0),0)
		t3=eycms.getint(eycms.fpost("t3",0),0)
		t4=eycms.getint(eycms.fpost("t4",0),0)
		t5=eycms.getint(eycms.fpost("t5",0),0)
		t6=eycms.enhtml(eycms.fpost("t6",0))
		t7=eycms.enhtml(eycms.fpost("t7",0))
		t8=eycms.getint(eycms.fpost("t8",0),0)
		t9=eycms.getint(eycms.fpost("t9",0),0)
		t11=eycms.getint(eycms.fpost("t11",0),0)
		t13=eycms.getint(eycms.fpost("t13",0),0)
		if eycms.strlen(t0)=0 then eycms.ajaxjson "参数名称不能为空",0:exit sub
		if eycms.strlen(t1)=0 then eycms.ajaxjson "参数标题不能为空",0:exit sub
		if eycms.strlen(t2)=0 then eycms.ajaxjson "参数类型不能为空",0:exit sub
		t0="my_"&t0
		if t8=0 then t9=0
		
		t0=left(t0,20)
		dim addtime
		addtime=now()
		dim data,ddata
		data=array(array("setName",t0,255,1),array("setTitle",t1,255,1),array("setType",t2,1,0),array("setmode",t3,1,0),array("fdatatype",t4,1,0),array("flength",t5,5,0),array("setValue",t6,255,1),array("foptions",t7,0,1),array("IsMust",t8,1,0),array("frules",t9,1,0),array("ordnum",t11,255,0),array("isshow",t13,1,0),array("AddTime",addtime,50,1))
		if eycms.db.dbnew("ey_plug_set",data,"setName='"&t0&"'")=0 then
			eycms.ajaxjson "字段名称已存在，请换个试试",0:exit sub
		else
			'保存字段到set表
			ddata=array(array("setname","eycms.site",255,1),array("setkey",t0,255,1),array("setvalue",t6,255,1))
			eycms.db.insert "ey_config",ddata
			eycms.ajaxjson "保存成功",1
		end if
	end sub		
	
	'编辑
	sub editdb
		dim t1,t6,t7,t8,t9,t10,t11,t12,t13
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t6=eycms.enhtml(eycms.fpost("t6",0))
		t7=eycms.enhtml(eycms.fpost("t7",0))
		t8=eycms.getint(eycms.fpost("t8",0),0)
		t9=eycms.getint(eycms.fpost("t9",0),0)
		t11=eycms.getint(eycms.fpost("t11",0),0)
		t13=eycms.getint(eycms.fpost("t13",0),0)
		if eycms.strlen(t1)=0 then eycms.ajaxjson "参数标题不能为空",0:exit sub
		if t8=0 then t9=0
		dim data,id,addtime,ddata
		addtime=now()
		id=eycms.getint(eycms.fget("id",0),0)
		data=array(array("setTitle",t1,255,1),array("setValue",t6,255,1),array("foptions",t7,0,1),array("IsMust",t8,1,0),array("frules",t9,1,0),array("ordnum",t11,255,0),array("isshow",t13,1,0),array("AddTime",addtime,50,1))
		if eycms.db.dbupdate("ey_plug_set","id="&id&"",data)=1 then
			eycms.ajaxjson "保存成功",1
		end if
	end sub
	
	'排序
	sub ordernum()
		dim t0,t1,t2,t3,i
		t0=eycms.enhtml(eycms.fpost("fid",0))
		t1=eycms.enhtml(eycms.fpost("ordnum",0))
		t2=split(t0,",")
		t3=split(t1,",")
		if ubound(t2)-ubound(t3)<>0 then eycms.ajaxjson "0&#21442;&#25968;&#38169;&#35823;",0:exit sub
		for i=0 to ubound(t2)
			if eycms.isnum(t2(i)) then
				eycms.db.dbupdate "ey_plug_set","id="&t2(i)&"",array(array("ordnum",t3(i),10,0,0))
			end if
		next
		eycms.ajaxjson "保存成功",1
	end sub
	
	sub delcache()
		eycms.delcache "model_site0"
	end sub
	
	'删除自定义字段
	sub deldb()
		dim fid:fid=eycms.getint(eycms.fget("fid",0),0)
		'查询字段ID、名称及所属模型ID
		dim fdata:fdata=eycms.db.dbload(1,"id,setname","ey_plug_set","id="&fid&"","")
		
		'删除ey_config中的字段
		eycms.db.dbdel "ey_config","setname='eycms.site' and setkey='"&fdata(1,0)&"'"
			
		'删除ey_plug_filed中的字段
		eycms.db.dbdel "ey_plug_set","id="&fid&""
				
		'打印处理结果		
		eycms.echo "1&#21024;&#38500;&#25104;&#21151;"
	end sub
	
	'获取对应的字段类型
	function get_settype(byval t0)
		if not isnumeric(t0) then get_settype="参数不正确":exit function
		select case t0
			case "1":get_settype="单行文本框"
			case "2":get_settype="多行文本框"
			case "3":get_settype="下拉列表"
			case "4":get_settype="单选按钮"
			case "5":get_settype="复选框"
			case "6":get_settype="HTML编辑器"
		end select
	end function

	eycms.db.dbclose
%>