<!-- #Include File="../Include/Skin.asp" -->
<!-- #Include File="../Include/Inc_Post.asp" -->
<!-- #Include File="../Include/Cls_UbbCode.asp" -->
<!-- #Include File="../Editor/UBB/Editor.asp" -->
<!-- #Include File="../Include/Inc_Md5.asp" -->
<!-- #Include File="../Include/Cls_PageCute.asp" -->

<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V3.0》，简称“AsaiMHV3”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

Dim Dim_Gbook,Dim_GboOk_Con,Word_Max,Dif_Tim,Page_ShowNum,Word_Key,Dle_User,Word_Bad,Is_Hidden,GboOk_Switch,is_admin
Index_Url="GuestBook"
Cls.ishealth=true
Word_Bad=Cls.Web_AdsFilter
Dim_Gbook=Split(Cls.Web_Gbook,"|")
Dim_GboOk_Con=Split(Dim_Gbook(0),",")
Word_Max=Dim_GboOk_Con(0)
Dif_Tim=Dim_GboOk_Con(1)
Page_ShowNum=Dim_GboOk_Con(2)
Word_Key=Dim_Gbook(1)
Dle_User=Dim_Gbook(2)
GboOk_Switch=Dim_Gbook(3)
Is_Hidden=Dim_Gbook(4)
If GboOk_Switch="0" Then
	Call Format_Redirect(Cls.Web_Dir&"Common/Page_Load.asp?该频道不存在或暂时维护中！")
end if

Select Case LCase(Action)
Case "write"
	tit_fir="网站留言"
	tit="签写留言"
Case else
	tit="网站留言"
End Select

If Action="write" Then
	Call DoWebHead(0,1)
Else
	Call DoWebHead(0,0)
End If

is_admin=false
if (instr(","&Dle_User&",",","&login_username&",")>0 or int(login_modep)=1) and Is_LoginTrue=true then
	is_admin=true
	if action="delete" then
		Call Cls.exec("Delete from AsaiMHGuestBook Where id="&Cls.Code_ID("id"),1)
	end if
	if action="open" then
		Call Cls.exec("Update AsaiMHGuestBook set hidden=1 Where id="&Cls.Code_ID("id"),1)
	end if
	if action="close" then
		Call Cls.exec("Update AsaiMHGuestBook set hidden=0 Where id="&Cls.Code_ID("id"),1)
	end if  
end if

Select Case LCase(Action)
Case "write"
	dim dim_bad
	dim_bad=split(Word_Bad,"|")
	Call GboOk_Write()
Case "reply"
	dim tmp1
	if is_admin=false then 
		tmp1="您没有回复留言的权限！"
		Cls.ReadPage "common"
	        Cls.HtmlRcod "msg",Found_Error(""&tmp1&"",460)
	        Cls.HtmlRcod "tit","回复留言"
	        Cls.HtmlRcod "m_gbook",img_skin("h_gbook")
	        Cls.OutPage
	else
		call Gbook_reply()
	end if
Case Else
	Call GboOk_Main()
End Select

Call DoWebEnd()

Sub GboOk_Write()
	Dim n_username,n_face,n_email,n_whe,n_GetCode,n_tmptopic
	Dim found_err,drname,drsex,drqq,dremail,drurl,drwhe,drtopic,dricon,drface,drword,drissecret,valcode,readonly
	Dim tmplen,tmpnum1,tmpnum2,tmptopic,tmpword
	If Cls.Chk() Then
		tmplen=Cls.session_get("GboOk_len")
        	tmpnum1=Cls.session_get("GboOk_num1")
        	tmpnum2=Cls.session_get("GboOk_num2")
        	tmptopic=AsaiMHMd5("topic"&tmpnum1&Word_Key,"short")&tmpnum1
        	tmpword=AsaiMHMd5("word"&tmpnum2&Word_Key,"short")&tmpnum2
		drname=Cls.Code_Form("wrname")
		drsex=Cls.Code_Form("wrsex")
		drqq=Cls.Code_Form("wrqq")
		If Cls.Is_Null(drqq)="" Then drqq="nuller"
		dremail=Cls.Code_Form("wremail")
		drurl=Cls.Code_Form("wrurl")
		drurl=Cls.Code_Var(drurl)
		If drurl="http://" Or IsNull(drurl) Then drurl="nuller"
		drwhe=Cls.Code_Form("wrwhe")
		If Cls.Is_Null(drwhe)="" Then drwhe="nuller"
		dricon=Cls.Code_Form("icon")
		drface=Cls.Code_Form("wrface")
		drtopic=Cls.Code_Form(tmptopic)
		drword=Cls.Code_Remark(tmpword)
		drissecret=Cls.Code_Form("wrissecret")
		valcode="AsaiMH"&Cls.Code_Form("valcode")
		found_err=""
		if not Cls.Put_Space("post_tim",Format_Mid_Num(18)) then
			found_err=found_err&"+对不起，留言的间隔时间为 <font class=red>"&int(Format_Mid_Num(18))&"</font> 秒！<br />"
		End If		
		if not Cls.Put_Space("GboOk_tim",Dif_Tim) then
			found_err=found_err&"+留言签写所用时间要大于 <font class=red>"&Dif_Tim&"</font> 秒钟！<br />"
		end if
		if ChkName(drname)="no" then
			found_err=found_err & "+请输入您的 <font class=red>用户名</font>（长度不能大于20）<br />"
		End If
		if drqq<>"nuller" then
			if not(isnumeric(drqq)) then
				found_err=found_err & "+您的 <font class=red>QQ</font> 只能为数字！<br />"
			End If
		End If
		If Not Cls.Is_Email(dremail,50) and dremail<>"@" and dremail<>"" then
			found_err=found_err & "+您输入的 <font class=red>Email</font> 格式有错误！<br />"
		End If
		if drtopic="" then
			found_err=found_err & "+留言的 <font class=red>主题</font> 是必需要的！请输入。<br />"
		End If
		if drword="" then
			found_err=found_err & "+留言的 <font class=red>留言内容</font> 是必需要的！请输入。<br />"
		End If
		if Not Cls.CodeIsTrue() then
			found_err=found_err&"+您输入的 <font class=red>验 证 码</font> 为空或有错误！<br />"
		End If
		if found_err="" then
			if len(drword)> CInt(Word_Max) * 1024 then
				found_err=found_err & "+留言的 <font class=red>留言内容</font> 的长度不能超过"&Word_Max&"KB！<br />"
			end if
		end if
		if found_err="" then
			for i=0 to ubound(dim_bad)
				if instr(drtopic,dim_bad(i))>0 or instr(drword,dim_bad(i))>0 then
					found_err=found_err & "+留言的主题或内容含有<font class=red>违禁</font>字符！<br />"
				end if
			next
		end if
		if found_err<>"" then
			Cls.ReadPage "common"
	        	Cls.HtmlRcod "msg",Found_Error(Found_Err,460)
	        	Cls.HtmlRcod "tit",tit
	        	Cls.OutPage
			exit sub
		End If
		sql="select * From [AsaiMHGuestbook] where (id is null)"
		Call Cls.Exe_Conn(Rs,SQL,3)
		rs.addnew
		rs("nname")=drname
		rs("sex")=drsex
		rs("whe")=drwhe
		rs("qq")=drqq
		rs("email")=dremail
		rs("url")=drurl
		rs("ip")=user_ip
		rs("sys")=user_sys
		rs("icon")=dricon
		rs("face")=drface
		rs("topic")=drtopic
		rs("word")=drword
		rs("tim")=Cls.now_time
                rs("isreply")=0
		if drissecret="yes" then
			rs("issecret")=true
		else
			rs("issecret")=false
		End If
		If Is_Hidden="0" then
			rs("hidden")=true
		else
			rs("hidden")=false
		end if
		rs.update
		rs.close
	        Cls.ReadPage "common"
	        Cls.HtmlRcod "msg",Found_Suc("留言成功,谢谢你的留言!</font><br /><br />（系统将在 <font class=red>"&Format_Mid_Num(25)&"</font> 秒钟后自动返回）<meta http-equiv='refresh' content='"&Format_Mid_Num(25)&"; url=GuestBook.asp'>",460)
	        Cls.HtmlRcod "tit",tit
	        Cls.OutPage
		Call Cls.Session_Del("GboOk_len")
		Call Cls.Session_Del("GboOk_num1")
		Call Cls.Session_Del("GboOk_num2")
		exit sub
	End If
	tmplen=get_len()
	tmpnum1=Cls.rand_num(tmplen-16)
	tmpnum2=Cls.rand_num(tmplen-16)
	tmptopic=AsaiMHMd5("topic"&tmpnum1&Word_Key,"short")&tmpnum1
	tmpword=AsaiMHMd5("word"&tmpnum2&Word_Key,"short")&tmpnum2
	Call Cls.Session_Set("GboOk_len",tmplen)
	Call Cls.Session_Set("GboOk_num1",tmpnum1)
	Call Cls.Session_Set("GboOk_num2",tmpnum2)
	if login_username<>"" then readonly="readonly"
	n_username=login_username
	n_face=face()
	n_email=login_email
	if len(trim(login_whe))>2 then
	n_whe=login_whe
	else
	n_whe=""
	end if
	n_GetCode=Cls.GetCode()
	n_tmptopic=tmptopic
	Cls.ReadPage "write_gbook"
	Cls.HtmlRcod "login_username",n_username
	Cls.HtmlRcod "face",n_face
	Cls.HtmlRcod "login_email",n_email
	Cls.HtmlRcod "login_whe",n_whe
	Cls.HtmlRcod "GetCode",n_GetCode
	Cls.HtmlRcod "tmptopic",n_tmptopic
	Cls.HtmlRcod "icon",LoadIcon(0)
	Cls.HtmlRcod "editor",LoadUBBEditor("gbadd","GboOk_add",tmpword,"","default",560,250)
	Cls.HtmlRcod "tit",tit
	Cls.HtmlRcod "readonly",readonly
	Cls.HtmlRcod "tmplen",tmplen
	Cls.HtmlRcod "dif_tim",dif_tim
	Cls.HtmlRcod "m_gbook",img_skin("h_gbook")
	Cls.OutPage
End Sub

sub Gbook_reply()
	Dim n_GetCode,reword,reicon,id,tmp1,drhidden,dricon,drpassed
	id=trim(request.querystring("id"))
	id=Cls.code_id("id")
	sql="select top 1 * from AsaiMHGuestbook where id="&id&""
	call Cls.exec("",-1)
	rs.open sql,conn,1,3
	if rs.eof then
		rs.close
		call AMH_msg(tit_fir&"ID（"&id&"）不存在！","?",1)
		exit sub
	end if
	if Cls.chk() then
		drpassed=Cls.Code_Form("wrpassed")
		reword=Cls.Code_Form("reply_word")
		reicon=Cls.Code_Form("icon")
		drhidden=Cls.Code_Form("wrhidden")
		dricon=Cls.Code_Form("icon")

		rs("re_word")=reword
		rs("re_tim")=Cls.now_time
		rs("re_icon")=reicon
		rs("isreply")=1
		rs("issecret")=drpassed
		rs("re_icon")=dricon
		if drhidden="yes" then
			rs("hidden")=true
		else
			rs("hidden")=false
		End If
		rs.update
		rs.close
		Cls.ReadPage "common"
		Cls.HtmlRcod "msg",Found_Suc("已成功的回复ID为<font class=red> " & id & " </font>的留言！!</font><br /><br />（系统将在 <font class=red>"&Format_Mid_Num(25)&"</font> 秒钟后自动返回）<meta http-equiv='refresh' content='"&Format_Mid_Num(25)&"; url=GuestBook.asp'>",460)
		Cls.HtmlRcod "tit",tit
		Cls.OutPage
		exit sub
	end if
	n_GetCode=Cls.GetCode()
	Cls.ReadPage "reply_gbook"
	Cls.HtmlRcod "topic",Cls.Code_Html(rs("topic"),1,0)
	Cls.HtmlRcod "nname",Cls.Code_Html(rs("nname"),1,0)
	Cls.HtmlRcod "tit",tit
	Cls.HtmlRcod "word",Ubb.Ubbcode(rs("word"))
	Cls.HtmlRcod "re_word",Cls.Code_Html(rs("re_word"),0,0)
	Cls.HtmlRcod "icon",LoadIcon(0)
	Cls.HtmlRcod "tim",Rs("tim")
	Cls.HtmlRcod "GetCode",n_GetCode
	Cls.HtmlRcod "id",id
	Cls.HtmlRcod "re_tim",Rs("re_tim")
	Cls.HtmlRcod "m_gbook",img_skin("h_gbook")
	Cls.OutPage
	rs.close
end sub

sub GboOk_Main()
	dim id,nname,sex,qq,email,url,whe,topic,ip,re_word,issecret,IsHidden,sTmpl
	dim obj_page
	set obj_page=new Cls_PageCute
	obj_page.pageurl="?"
	obj_page.nummer=Page_ShowNum
	obj_page.page_t=1
	obj_page.page_p=5
	obj_page.page_unit="个"
	obj_page.page_tit="留言"
	obj_page.v_id="id"
	Call obj_page.p_init("*","AsaiMHGuestbook","","id desc")
	sql=obj_page.sql_count
	set rs=Cls.exec(sql,1)
	obj_page.rssum=rs(0)
	rs.close
	if int(obj_page.rssum)<1 then
		set obj_page=nothing
		Call GboOk_write()
		exit sub
	End If
	Cls.ReadPage "main_gbook"
	call obj_page.p_main("*","AsaiMHGuestbook","","id desc")
	for i=1 to obj_page.page_num
	id=rs("id")
	nname=rs("nname")
	sex="<img align=absmiddle border=0 src='"&Cls.Web_SkinDir&"sys/boy.gif' title='"&nname&" 是 "&Cls.Web_Boy&"'>"
	if rs("sex")="girl" then sex="<img align=absmiddle border=0 src='"&Cls.Web_SkinDir&"sys/girl.gif' title='"&nname&" 是 "&Cls.Web_girl&"'>"
	qq=rs("qq")
	email=rs("email")
	url=Cls.code_html(rs("url"),1,0)
	whe=rs("whe")
	topic=rs("topic")
	ip=rs("ip")
	re_word=Ubb.Ubbcode(rs("re_word"))
	issecret=rs("issecret")
	IsHidden=rs("hidden")
		
If IsHidden=False And Is_Hidden="1" and is_admin=false then
sTmpl=sTmpl&vbcrlf&"<p class=asgts>第"&i+obj_page.page_now&"楼留言 : <font color=red>此留言尚未被审核，不能查看！^_^ </font></p>"
Else

if issecret=true and is_admin=false and login_username<>nname then
sTmpl=sTmpl&vbcrlf&"<p class=asgts>第"&i+obj_page.page_now&"楼留言 : <font color=red>此条留言只有管理员才可以看！</font></p>"
else
	
sTmpl=sTmpl&"<table width='100%' border='0' cellspacing='0' cellpadding='5' title='第"&i+obj_page.page_now&"楼留言'><tr class='asghs'><td align='center' class='asgmz'>"

sTmpl=sTmpl&vbcrlf&""&sex&" "&format_user_name(nname,1,"")&"</td><td class='asgtt'>"

sTmpl=sTmpl&vbcrlf&"<img src='"&Cls.Web_Dir&"Images/Em/icon/"&rs("icon")&".gif' border=0 align=absmiddle> <font title='"&Cls.code_html(topic,1,0)&"'>"&Cls.code_html(topic,1,36)&"</font>"
sTmpl=sTmpl&vbcrlf&"</td><td class='asgtm'>"
sTmpl=sTmpl&vbcrlf&"<img src='"&Cls.Web_SkinDir&"sys/tim.gif' border=0 align=absmiddle> "&Cls.time_type(rs("tim"),3)&""
sTmpl=sTmpl&vbcrlf&"</td><td rowspan='3' width='10' class='asghs'></td></tr>"
sTmpl=sTmpl&vbcrlf&"<tr><td class='asghs' align='center' valign='top'>"
sTmpl=sTmpl&vbcrlf&"<img src='"&Cls.Web_Dir&"Images/Face/"&rs("face")&".gif' border=0>"
sTmpl=sTmpl&vbcrlf&"</td><td colspan='2'>"
sTmpl=sTmpl&vbcrlf&Ubb.Ubbcode(rs("word"))
if rs("isreply")=true then
sTmpl=sTmpl&vbcrlf&"<p class=asghf><font color=red>管理员回复 "&rs("re_tim")&"</font><br>" & _
vbcrlf&"<img src='"&Cls.Web_Dir&"Images/Em/icon/"&rs("re_icon")&".gif' border=0 align=absmiddle> "&re_word&"" & _
vbcrlf&"</p>"
End If
if issecret=true then sTmpl=sTmpl&vbcrlf&"<p align=right><font color=red>[此为隐藏留言]</font></p>"
if IsHidden=False then sTmpl=sTmpl&vbcrlf&"<p align=right><font color=blue>[此为未审核留言]</font></p>"
sTmpl=sTmpl&vbcrlf&"</td></tr>"
sTmpl=sTmpl&vbcrlf&"<tr class='asghs'><td align='center'>"
if whe<>"null" then
sTmpl=sTmpl&vbcrlf&"<font title='"&Cls.code_html(whe,1,0)&"'>"&Cls.code_html(whe,1,5)&"</font>"
else
sTmpl=sTmpl&vbcrlf&"位置地域"
End If
sTmpl=sTmpl&vbcrlf&"</td><td colspan='2' align=right>"

if Cls.Is_Null(url)<>"" and url<>"nuller" and url<>"http://" then
sTmpl=sTmpl&"<a href='"&Cls.code_html(url,1,0)&"' target=_blank><img src='"&Cls.Web_SkinDir&"sys/url.gif' title='访问 "&nname&" 的主页' border=0></a> "
End If
if qq<>"nuller" then
sTmpl=sTmpl&"<a href='http://"&qq&".qzone.qq.com' target=_blank><img src='"&Cls.Web_SkinDir&"sys/qq.gif' title='"&nname&" 的QQ是："&qq&"' border=0></a> "
End If
if Cls.Is_Email(email,50) then
sTmpl=sTmpl&"<a href='mailto:"&email&"'><img src='"&Cls.Web_SkinDir&"sys/email.gif' title='给 "&nname&" 发电子邮件' border=0></a> "
End If

if is_admin then
sTmpl=sTmpl&"<a href=Ip_Address.asp?ip="&ip&"><img src='"&Cls.Web_SkinDir&"sys/ip.gif' border=0 align=absMiddle title='点击查看 "&nname&" 的IP地址'></a> <img src='"&Cls.Web_SkinDir&"sys/sys.gif' align=absMiddle title='"&nname&" 的 "&user_sys_type(rs("sys"))&"' border=0> "
if Ishidden=True then
sTmpl=sTmpl&"<a href='?action=close&id="&id&"'><img src='"&Cls.Web_SkinDir&"sys/close.gif' align=absMiddle title='设此条留言为未审核' border=0></a> "
else
sTmpl=sTmpl&"<a href='?action=open&id="&id&"'><img src='"&Cls.Web_SkinDir&"sys/open.gif' align=absMiddle title='审核此条留言' border=0></a> "
end if
sTmpl=sTmpl&"<a href='?action=delete&id="&id&"' onclick=""javascript:javascript:return click_return('删除本条留言',0);""><img src='"&Cls.Web_SkinDir&"sys/del.gif' align=absMiddle title='删除此条留言' border=0></a> <a href='?action=reply&id="&id&"'><img src='"&Cls.Web_SkinDir&"sys/reply.gif' align=absMiddle title='回复此条留言' border=0></a> "
end if

sTmpl=sTmpl&vbcrlf&"</td></tr>"
sTmpl=sTmpl&vbcrlf&"<tr><td colspan='4' height='10'></td></tr></table>"

End If
End If


	sTmpl=sTmpl&vbcrlf&""&vbcrlf
	rs.movenext
	next
	rs.close
	sTmpl = sTmpl &"<div id=""asaipage""> "&obj_page.page_var&" "&obj_page.page_cute&" "&obj_page.page_shortcut&"</div>"
	Cls.HtmlRcod "tit",tit
	Cls.HtmlRcod "m_gbook",img_skin("h_gbook")
	Cls.HtmlRcod "body",sTmpl
	Cls.OutPage
	set obj_page=nothing
End Sub

function get_len()
	dim tmplen,n
	tmplen=Cls.rand_num(2)
	for n=1 to 3
	if tmplen<=22 then exit for
	tmplen=tmplen-4
	n=n-1
	next
	if tmplen<18 then tmplen=18
	get_len=tmplen
end function

function face()
	dim sTmp,i
	sTmp= "<select size=1 name=wrface style=""width： 50; border： 1px solid #C0C0C0"" onChange=""show_face()"">" & _
vbcrlf&"<option value=0 selected>0</option>"
	for i=1 to Format_Mid_Num(19)
	sTmp=sTmp&"<option value='"&i&"'>"&i&"</option>"
	next
	sTmp=sTmp&"</select>"
	face=sTmp
end function
%>
