<!--#include file="../lib/base.asp"-->
<!--#include file="../theme.asp"-->
<%
''' EYCMS 留言
''' ==================================================================
	eycms.stophack
	dim parentid:parentid=eycms.db.dbloadone("parentid","ey_category","modeid=-2 and right(cateurl,13)='plug/book.asp'")
	dim act:act=eycms.fget("act",0)
	select case act
		case "islogin":userstaus
		case "add":adddb
		case else
			dim config:config=eval(eycms.getsys("expand.book"))
			if not(config(0)) then
				eycms.echo "&#26410;&#24320;&#21551;&#30041;&#35328;"
				eycms.die
			end if
			eycms.show eycms.getsys("theme_book"),""
	end select
	eycms.db.dbclose
	
	sub userstaus()
		if eycms.is_login then
			dim userdata:userdata=eycms.userinfo
			Dim truename:truename=eycms.gettruename(userdata(0))
			If eycms.strlen(truename)=0 Then truename=userdata(1)
			eycms.echo "<input type=""text"" name=""t0"" id=""nicekname"" maxlength=""20"" class=""ip"" value="""&truename&""" readonly=""readonly"" /> (<a href="""&webroot&"user/login.asp?act=out&gourl="&webroot&"plug/book.asp"">匿名发表</a>)"
		else
			eycms.echo "<input type=""text"" name=""t0"" id=""nicekname"" maxlength=""20"" class=""ip"" /> (<a href="""&webroot&"user/login.asp?gourl="&webroot&"plug/book.asp"">登陆发表</a>)"
		end if
	end Sub
	
	sub adddb()
		dim t0,t1,t2,t3,t4,isajax
		t0=eycms.enhtml(eycms.fpost("t0",0))
		t1=eycms.enhtml(eycms.fpost("t1",0))
		t2=eycms.enhtml(eycms.fpost("t2",0))
		t3=eycms.getint(eycms.fpost("t3",0),0)
		t4=eycms.enhtml(eycms.fpost("t4",0))
		isajax=eycms.enhtml(eycms.fpost("isajax",0))
		dim config:config=eval(eycms.getsys("expand.book"))
		if not(config(0)) then
			malert "未开启留言",0,isajax,""
			exit sub
		end if
		dim f,passnum
		if config(1) then
			f=1
			passnum=0
		else
			f=2
			passnum=1
		end if
		if not(eycms.checkpost) then
			malert "禁止外部提交数据",0,isajax,""
			exit sub
		end if
		if eycms.strlen(t0)=0 then
			malert "昵称不能为空",0,isajax,""
			exit sub
		end if
		if eycms.strlen(t1)=0 then
			malert "留言内容不能为空",0,isajax,""
			exit sub
		end if
		if eycms.strlen(t1)<5 then
			malert "留言内容至少输入5个字符",0,isajax,""
			exit sub
		end if
		if t4<>"no" then
			if eycms.strlen(t4)=0 then
				malert "验证码不能为空",0,isajax,""
				exit sub
			end if
			if eycms.loadsession("imgcode")="" then
				malert "系统验证码错误，请点击刷新",0,isajax,""
				exit sub
			end if
			if eycms.loadsession("imgcode")<>t4 then
				malert "验证码错误",0,isajax,""
				exit sub
			end if
		end if
		if eycms.loadcookie("book_add")<>"" then
			if int(datediff("s",eycms.loadcookie("book_add"),now()))<=60 then
				malert "请勿重复提交！",0,isajax,""
				exit sub
			end if
		end if
		dim userid,avatar
		userid=0
		avatar=0
		if eycms.is_login then
			dim userdata:userdata=eycms.userinfo
			userid=userdata(0)
			avatar=userdata(12)
			if t0<>userdata(13) then
				t0=userdata(13)
			end if
		end if
		dim data
		data=array(array("username",t0,20,1),array("content",t1,255,1),array("tel",t2,20,1),array("sex",t3,1,1),array("userid",userid,0,0),array("avatar",avatar,0,0),array("createdate",sqltime,0,0),array("islock",passnum,0,0),array("postip",eycms.getip,0,1))
		eycms.db.insert "ey_expand_book",data
		dim body:body=""
		dim title:title="您有一条新留言(来自网站)"
		body=body&"昵　称："&t0
		body=body&"<br>电　话："&t2
		dim sex
		select case t3
			case "0":sex="保密"
			case "1":sex="男"
			case "2":sex="女"
		end select
		body=body&"<br>性　别："&sex
		body=body&"<br>日　期："&now()
		body=body&"<br>内　容："&t1
		eycms.sendmail eycms.getsys("adminemail"),title,body
		malert "提交成功，我们会尽快给您回复，谢谢！", 1, isajax, eycms.gurl("plug/book.asp","")
		eycms.setcookie "book_add",now()
	end sub

	sub malert(msg,zt,isajax,url)
		if isajax="no" then
			if eycms.strlen(url)>0 then
				eycms.backurl msg, url
			else
				eycms.back msg
			end if
		else
			eycms.ajaxjson msg, zt
		end if
	end sub
%>
