<!--#include file="../lib/base.asp"-->
<!--#include file="../theme.asp"-->
<%
''' EYCMS 表单
''' ==================================================================
	eycms.stophack
	sub adddb()
		dim data:data=eycms.db.dbload(1,"tablename,ispost,iscode","ey_form","islock=1 and id="&id&"","id")
		if ubound(data)<0 then
			eycms.ajaxjson "参数错误",0
			exit sub
		end if
		dim code:code=eycms.enhtml(eycms.fpost("code",0))
		dim userip:userip=eycms.getip
		if data(1,0)=1 then
			if not(eycms.checkpost) then
				eycms.ajaxjson "&#31105;&#27490;&#22806;&#37096;&#25552;&#20132;&#25968;&#25454;",0
				exit sub
			end if
		end if
		if eycms.loadcookie("form_"&id)<>"" then
			if int(datediff("s",eycms.loadcookie("form_"&id),now()))<=60 then
				eycms.ajaxjson "&#35831;&#21247;&#37325;&#22797;&#25552;&#20132;",0
				exit sub
			end if
		end if
		if data(2,0)=1 then
			if eycms.strlen(code)=0 then
				eycms.ajaxjson "验证码不能为空",0
				exit sub
			end if
			if eycms.loadsession("imgcode")="" then
				eycms.ajaxjson "无法获取系统验证码",0
				exit sub
			end if
			if eycms.loadsession("imgcode")<>code then
				eycms.ajaxjson "验证码错误",0
				exit sub
			end if
		end if

		dim fstr:fstr=deal_form_field(id)
		fstr="array(array(""userip"",userip,50,1),array(""createdate"",sqltime,0,0)"&fstr&")"
		eycms.db.insert data(0,0),eval(fstr)
		eycms.setcookie "form_"&id,now()
		eycms.ajaxjson "提交成功",1
	end sub
	
	function deal_form_field(byval t0)
		dim a:a=eycms.get_form_field(t0)
		if not isarray(a) then
			deal_form_field="":exit function
		end if
		dim fi,fstr,istrim,length,fname,fmode,iscn,formstr,rules
		for fi=0 to ubound(a,2)
			fstr=fstr&","
			fname=a(0,fi)
			istrim=a(10,fi)
			length=a(5,fi)
			fmode=a(3,fi)
			iscn=1
			rules=""
			select case a(2,fi)
				case "1"
					select case fmode
						case "2","5":length=10:iscn=0
						case "3":length=50
					end select
					formstr="eycms.enhtml(eycms.fpost("""&fname&""","&istrim&"))"
				case "2":length=0
					formstr="eycms.enhtml(eycms.fpost("""&fname&""","&istrim&"))"
				case "3","4","5":length=255
					formstr="eycms.enhtml(eycms.fpost("""&fname&""","&istrim&"))"
			end select
			fstr=fstr&"array("""&fname&""","&formstr&","&length&","&iscn&")"
			formstr=eval(formstr)
			if a(8,fi)=1 then
				if eycms.strlen(formstr)=0 then eycms.ajaxjson a(1,fi)&"不能为空",0:eycms.die
				select case a(9,fi)
					case "2":rules="int"
					case "3":rules="price"
					case "4":rules="tel"
					case "5":rules="mobile"
					case "6":rules="email"
					case "7":rules="date"
					case "8":rules="zipcode"
					case "9":rules="qq"
					case "10":rules="url"
				end select
				if rules<>"" then
					if not(eycms.checkstr(formstr,rules)) then
						eycms.ajaxjson a(1,fi)&"格式错误",0:eycms.die
					end if
				end if
			end if
		next
		deal_form_field=fstr
	end function
	
	dim act:act=eycms.fget("act",0)
	dim id:id=eycms.getint(eycms.fget("id",0),0)
	select case act
		case "db":adddb
	end select
	eycms.db.dbclose
%>