<!--#include file="base.asp"-->
<%
''' EYCMS 模型
''' ==================================================================

	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)
		t10=eycms.getint(eycms.fpost("t10",0),0)
		t11=eycms.getint(eycms.fpost("t11",0),0)
		t12=eycms.getint(eycms.fpost("t12",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="fm_"&t0
		if t8=0 then t9=0
		'字段类型
		dim dtype
		select case t2
			case "1"
				select case t3
					case "1","4":dtype="文本"
					case "2":dtype="数字"
					case "3":dtype="日期"
					case "5":dtype="货币"
				end select
			case "2","6"
				dtype="备注"
			case "4","5"
				dtype="文本"
				t5=255
			case else
				select case t4
					case "1":dtype="文本"
					'case "2":dtype="数字"
				end select
		end select
		t0=left(t0,20)
		dim sqlstr
		select case dtype
			case "文本":sqlstr=""&t0&" nvarchar("&t5&") null"
			case "数字":sqlstr=""&t0&" int null"
			case "货币":sqlstr=""&t0&" money null"
			case "日期":sqlstr=""&t0&" datetime null"
			case "备注":sqlstr=""&t0&" ntext null"	
		end select
		dim mdata:mdata=eycms.db.dbload(1,"tablename","ey_form","id="&formid&"","id")
		if ubound(mdata)<0 then
			eycms.ajaxjson "模型数据错误"&modelid&"",0:exit sub
		end if
		dim tablename:tablename=mdata(0,0)
		sqlstr="alter table "&tablename&" add "&sqlstr
		dim data
		data=array(array("fname",t0,0),array("falias",t1,9),array("fclass",t2,0),array("fmode",t3,0),array("fdatatype",t4,0),array("flength",t5,5),array("fdefault",t6,255),array("foptions",t7,0),array("fismust",t8,0),array("frules",t9,0),array("fistrim",t10,0),array("ordnum",t11,0),array("islock",t12,0),array("isshow",t13,0),array("formid",formid,0))
		if eycms.db.dbnew("ey_form_field",data,"fname='"&t0&"' and formid="&formid&"")=0 then
			eycms.ajaxjson "字段名称已存在，请换个试试",0:exit sub
		else
			eycms.db.exedb(sqlstr)
			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)
		t10=eycms.getint(eycms.fpost("t10",0),0)
		t11=eycms.getint(eycms.fpost("t11",0),0)
		t12=eycms.getint(eycms.fpost("t12",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
		id=eycms.getint(eycms.fget("id",0),0)
		data=array(array("falias",t1,7,1),array("fdefault",t6,255,1),array("foptions",t7,0,1),array("fismust",t8,0,0),array("frules",t9,0,0),array("fistrim",t10,0,0),array("ordnum",t11,0,0),array("islock",t12,0,0),array("isshow",t13,0,0))
		if eycms.db.dbupdate("ey_form_field","id="&id&"",data)=1 then
			eycms.ajaxjson "保存成功",1
		end if
	end sub
	
	sub orderdb()
		dim t0,t1,t2,t3,i
		t0=eycms.enhtml(eycms.fpost("ordnum",0))
		t1=eycms.enhtml(eycms.fpost("id",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_form_field","id="&t3(i)&"",array(array("ordnum",t2(i),10,0,0))
			end if
		next
		eycms.ajaxjson "保存成功",1
	end sub
	
	sub deldb()
		dim id:id=eycms.getint(eycms.fget("id",0),0)
		dim data:data=eycms.db.dbload(1,"formid,fname","ey_form_field","id="&id&"","")
		if ubound(data)<0 then
			exit sub
		end if
		dim mdata:mdata=eycms.db.dbload(1,"tablename","ey_form","id="&data(0,0)&"","id")
		if ubound(mdata)<0 then
			exit sub
		end if
		dim sqlstr:sqlstr="alter table "&mdata(0,0)&" drop "&data(1,0)
		eycms.db.exedb(sqlstr)
		eycms.db.dbdel "ey_form_field","id="&id
		eycms.echo "1"
	end sub
	
	sub delcache()
		eycms.delcache "form_field"&formid
	end sub
	
	function get_type(byval t0)
		select case t0
			case "1":get_type="单行文本框"
			case "2":get_type="多行文本框"
			case "3":get_type="下拉列表"
			case "4":get_type="单选按钮"
			case "5":get_type="复选框"
		end select
	end function
	
	function get_data(byval t0)
		select case t0
			case "1":get_data="文本"
			case "2":get_data="数字"
			case "3":get_data="货币"
			case "4":get_data="日期"
			case "5":get_data="备注"
		end select
	end function
	
	islogin
	dim act:act=lcase(eycms.fget("act",0))
	dim formid:formid=eycms.getint(eycms.fget("formid",0),0)
	select case act
		case "add":checkpagelever 63:load eval("theme_form_field_"&act)
		case "adddb":checkpagelever 63:adddb:delcache
		case "edit"
			checkpagelever 63
			dim datadb,id
			id=eycms.getint(eycms.fget("id",0),0)
			datadb=eycms.db.dbload("","fname,falias,fclass,fmode,fdatatype,flength,fdefault,foptions,fismust,frules,fistrim,ordnum,islock,isshow","ey_form_field","id="&id&"","")
			load eval("theme_form_field_"&act)
		case "editdb":checkpagelever 63:editdb:delcache
		case "order":checkpagelever 63:orderdb:delcache
		case "del":checkpagelever 63:deldb:delcache
		case else:checkpagelever 63:load theme_form_field
	end select
		
	eycms.db.dbclose
%>
