<%
'===================================================
' CreateLive CMS Version 3.1
'							Powered by Aspoo.CoM
'===================================================
' File: Cl_Function_Guest.asp
' Date: 2005-10-31
' Mail: aspoo@126.com, Info@aspoo.cn
' Q  Q: 3315263, 596197794
' Msn : aspoo@126.com, Clw866@hotmail.com
' Web : http://www.aspoo.com, http://www.aspoo.net
' Bbs : http://bbs.aspoo.com, http://bbs.aspoo.net
' Copyright (C) 2005 Aspoo.CoM All Rights Reserved.
'===================================================
'显示左侧留言功能
Function GuestBookLeft()
	Dim strTemp
	strTemp="<div align=""center"">"
	if GuestType=1 then
		strTemp=strTemp & Template.Strings(1)
	else
		strTemp=strTemp & Template.Strings(2) 
	end if
	strTemp=strTemp&"<br />"
	if Cl.Web_Setting(6)="Yes" then
		strTemp=strTemp & Template.Strings(3) 
		set rsGuest=Cl.Execute("select count(*) from Cl_Guest where GuestIsPassed=False")
		strTemp=strTemp & "<br />"
		strTemp=strTemp & Replace(Template.Strings(5),"{%nopassednum%}",rsGuest(0))
	else
		strTemp=strTemp & Template.Strings(4)
	end if
	if Cl.UserID>=1 then
		strTemp=strTemp & "<br /><a href='" & strFileName & "?action=user' >"&Template.Strings(6)&"</a>"
		if Cl.UserLevel=1 then strTemp=strTemp & "<br /><a href='" & strFileName & "?action=shownopass' >"&Template.Strings(7)&"</a>" 
	end if
	strTemp=strTemp & "<br /><a href='" & strFileName & "' >"&Template.Strings(8)&"</a>" & vbcrlf
	strTemp=strTemp & "<br /><a href='" & strFileName & "?action=write' >"&Template.Strings(9)&"</a></div>"
	GuestBookLeft=strTemp
End Function
'=================
'修改留言功能面板导航mf +1016
'===================
Function GuestBookBar()
	Dim strTemp
	strTemp=strTemp &"<div class='bar_txt'><ul>" 
	if GuestType=1 then
		strTemp=strTemp & "<li>"& Template.Strings(1)& "</li>"'用户模式
	else
		strTemp=strTemp & "<li>"& Template.Strings(2)& "</li>" '游客模式
	end if
	strTemp=strTemp&""
	if Cl.Web_Setting(6)="Yes" then
		strTemp=strTemp& "<li>" & Template.Strings(3)& "</li>"  '审核发表
		set rsGuest=Cl.Execute("select count(*) from Cl_Guest where GuestIsPassed=False")
		strTemp=strTemp & "<li>" & Replace(Template.Strings(5),"{%nopassednum%}",rsGuest(0))& "</li>" 
	else
		strTemp=strTemp & "<li>"& Template.Strings(4) & "</li>" '直接发表
	end If
		strTemp=strTemp &"</ul></div>"
	
	strTemp=strTemp &"<div class='bar_bt'><ul>" '发表流言
	strTemp=strTemp & "<li><a href='" & strFileName & "?action=write' >"&Template.Strings(9)&"</a></li>"
	strTemp=strTemp & "<li><a href='" & strFileName & "' >"&Template.Strings(8)&"</a></li>" & vbcrlf'查看留言
	if Cl.UserID>=1 then
		strTemp=strTemp & "<li><a href='" & strFileName & "?action=user' >"&Template.Strings(6)&"</a></li>"
		'我的留言
		if Cl.UserLevel=1 then strTemp=strTemp & "<li><a href='" & strFileName & "?action=shownopass' >"&Template.Strings(7)&"</a></li>" '审核留言
	end if
	strTemp=strTemp &"</ul></div>"
	GuestBookBar= replace(strTemp,"'",chr(34))
End Function

'显示留言搜索
Function GuestBookSearch()
	GuestBookSearch=Template.html(11)
	GuestBookSearch=Replace(GuestBookSearch,"{%strfilename%}",strFileName)
End Function

'留言本功能调用
Function GuestBookBody()
	select case Action
		case "write"
			GuestBookBody=WriteGuest()
		case "savewrite"
			call SaveWriteGuest()
		case "reply"
			GuestBookBody=ReplyGuest()
		case "replyadmin"
			GuestBookBody=AdimReplyGuest()
		case "saveadminreply"
			call SaveAdminReplyGuest()
		case "pass"
			call PassGuest()
		case "nopass"
			call PassGuest()
		case "edit"
			GuestBookBody=EditGuest()
		case "del"
			call DelGuest()
		case "user"
			GuestBookBody=ShowAllGuest(3)
		case "shownopass"
			GuestBookBody=ShowAllGuest(4)
		case else
			if GuestType=1 then
				GuestBookBody=ShowAllGuest(1)
			else
				GuestBookBody=ShowAllGuest(2)
			end if
	end select
End Function

'分页显示所有留言(ShowType)
'0为显示所有
'1为显示已通过审核及用户自己发表的留言
'2为显示已通过审核的留言
'3为显示用户自己发表的留言
'4为显示未通过审核的留言
Function ShowAllGuest(ShowType)
	Select Case ShowType
	Case 1
		if Cl.UserID=0 then
			ShowAllGuest=ShowAllGuest(2)
			Exit Function
		end if
		if Cint(Cl.UserLevel)=1 then
			sqlGuest="select * from Cl_Guest where 1=1"
		else
			sqlGuest="select * from Cl_Guest where (GuestIsPassed=True or GuestName='"&Cl.User_Info(5)&"')"
		end if
	Case 2
		sqlGuest="select * from Cl_Guest where GuestIsPassed=True"
	Case 3
		if Cl.UserID=0 then
			ShowAllGuest=ShowAllGuest(2)
			Exit Function
		end if
		sqlGuest="select * from Cl_Guest where GuestName='"&Cl.User_Info(5)&"'"
	Case 4
		sqlGuest="select * from Cl_Guest where GuestIsPassed=False"
	Case else
		sqlGuest="select * from Cl_Guest where 1=1"
	end Select
	if keyword<>"" then
		sqlGuest=sqlGuest & " and (GuestTitle like '%" & keyword & "%' or GuestContent like '%" & keyword & "%' or GuestName like '%" & keyword & "%' or GuestReply like '%" & keyword & "%') "
	end if
	sqlGuest=sqlGuest&" order by GuestMaxId desc"
	set rsGuest=server.createobject("adodb.recordset")
	OpenConn : rsGuest.open sqlGuest,Conn,1,1
	if rsGuest.bof and rsGuest.eof then
		TotalPut=0
		ShowAllGuest=Template.Strings(12)
	else
		TotalPut=rsGuest.recordcount
		if (TotalPut mod MaxPerPage)=0 then
			TotalPages = TotalPut \ MaxPerPage
		else
			TotalPages = TotalPut \ MaxPerPage + 1
		end if
		if CurrentPage > TotalPages then CurrentPage=TotalPages
		if CurrentPage < 1 then CurrentPage=1
		rsGuest.move (CurrentPage-1)*MaxPerPage
		if Cl.UserLevel=1 and TotalPut>0 then
		ShowAllGuest="<form action='?' name='myform' id='myform'>" & ShowGuestList() & Template.html(6) &"</form>"
		else
		ShowAllGuest=ShowGuestList()
		end if
	end if
	rsGuest.close:Set rsGuest=Nothing
End Function

'显示留言
Function ShowGuestList()
	dim GuestTip,TipName,TipSex,isdelUser,strTemp
	Dim strGuestButton,TempDate
	i=0:ShowGuestList=""
	Set ClUbb=New Cls_UbbCode
	'ClUbb.OpenHtml=1
	do while not rsGuest.eof
		isdelUser=0
		if rsGuest("GuestType")=1 then
			sql="select * from " & Db.UserTable & " where " & Db.UserName & "='" & rsGuest("GuestName")&"'"
			set rs=Cl.Execute_U(sql)'server.createobject("adodb.recordset")
			'rs.open sql,Conn_U,1,1
			if not rs.bof and not rs.eof then
				UserGuestName=rs(Db.UserName)
				UserSex=rs(Db.UserSex)
				UserEmail=rs(Db.UserEmail)
				IF UserTableType="Leadbbs" then
				UserQQ=rs(Db.UserQQ)
				UserMsn=rs(Db.UserMsn)
				UserHomepage=rs(Db.UserHomepage)
				Elseif UserTableType="Bbsxp" then
				UserIM=Split(rs(Db.UserIM),"/")
				UserQQ=UserIM(0)
				UserIcq=UserIM(1)
				UserMsn=UserIM(2)
				UserHomepage=rs(Db.UserHomepage)
				Else
				UserIM=Split(rs(Db.UserIM),"|||")
				UserQQ=UserIM(1)
				UserIcq=UserIM(2)
				UserMsn=UserIM(3)
				UserHomepage=UserIM(0)
				End if
			else
				isdelUser=1
			end if
		end if
		if rsGuest("GuestType")<>1 or isdelUser=1 then
			UserGuestName=rsGuest("GuestName")
			UserSex=rsGuest("GuestSex")
			UserEmail=rsGuest("GuestEmail")
			UserQQ=rsGuest("GuestOicq")
			UserIcq=rsGuest("GuestIcq")
			UserMsn=rsGuest("GuestMsn")
			UserHomepage=rsGuest("GuestHomepage")
		end if
		TipName=UserGuestName
		if isdelUser=1 then TipName=TipName&"（已删除）"
		if UserEmail="" or IsNull(UserEmail) then UserEmail="未填"
		if UserQQ="" or IsNull(UserQQ) then UserQQ="未填"
		if UserIcq="" or IsNull(UserIcq) then UserIcq="未填"
		if UserMsn="" or IsNull(UserMsn) then UserMsn="未填"
		if UserHomepage="" or IsNull(UserHomepage) then UserHomepage="未填"
		if UserSex=1 then
			TipSex="(酷哥)"
		elseif UserSex=0 then
			TipSex="(靓妹)"
		else
			TipSex=""
		end if
		GuestTip="姓名："&TipName&" "&TipSex& vbcrlf& "主页："&UserHomepage& vbcrlf& "QQ："& UserQQ& vbcrlf& "信箱："&UserEmail& vbcrlf& "IP："&rsGuest("GuestIP")& vbcrlf& "时间："&rsGuest("GuestDatetime")
		strTemp=Template.html(1)
		strTemp=Replace(strTemp,"{%guesttitle%}",KeywordReplace(rsGuest("GuestTitle")))
		strTemp=Replace(strTemp,"{%guestdatetime%}",rsGuest("GuestDatetime"))
		if rsGuest("GuestIsPassed")=True then
			strTemp=Replace(strTemp,"{%bgcolor%}","")
		else
			strTemp=Replace(strTemp,"{%bgcolor%}","bgcolor='#f0f0f0'")
		end if
		strTemp=Replace(strTemp,"{%guestimages%}",rsGuest("GuestImages"))
		strTemp=Replace(strTemp,"{%guesttip%}",GuestTip)
		if rsGuest("GuestType")=1 then
			strTemp=Replace(strTemp,"{%guesttype%}",Template.Strings(10))
		else
			strTemp=Replace(strTemp,"{%guesttype%}",Template.Strings(11))
		end if
		if rsGuest("GuestIsPrivate")=true then
			if Cl.UserID=0 or Cl.UserLevel=5 then
				strTemp=Replace(strTemp,"{%guestcontent%}",Template.html(3))
			else
				if rsGuest("GuestName")=Cl.User_Info(5) or Clng(Cl.User_Info(21))=1 then
					strTemp=Replace(strTemp,"{%guestcontent%}",Template.html(2))
					strTemp=Replace(strTemp,"{%guestcontent%}","<font color=green>[隐藏]</font>&nbsp;"&KeywordReplace(ClUbb.Ubbcode(Cl.HTMLEncode(rsGuest("GuestContent")))))
				else
					strTemp=Replace(strTemp,"{%guestcontent%}",Template.html(3))
				end if
			end if
		else
			strTemp=Replace(strTemp,"{%guestcontent%}",Template.html(2))
			strTemp=Replace(strTemp,"{%guestcontent%}",KeywordReplace(ClUbb.Ubbcode(Cl.HTMLEncode(rsGuest("GuestContent")))))
		end if
		strTemp=Replace(strTemp,"{%guestface%}",rsGuest("GuestFace"))
		if len(rsGuest("GuestReply")) >0 then
			strTemp=Replace(strTemp,"{%showguestreply%}",Template.html(4))
			strTemp=Replace(strTemp,"{%guestreplyadmin%}",rsGuest("GuestReplyAdmin"))
			strTemp=Replace(strTemp,"{%guestreplydatetime%}",rsGuest("GuestReplyDatetime"))
			strTemp=Replace(strTemp,"{%guestreply%}",KeywordReplace(ClUbb.Ubbcode(Cl.HTMLEncode(rsGuest("GuestReply")))))
		else
			strTemp=Replace(strTemp,"{%showguestreply%}","")
		end if

		TempDate=Split(Template.html(5),"$$$")
		if UserHomepage="未填" then
			strGuestButton=Split(TempDate(0),"||")(0)
		else
			strGuestButton=Replace(Trim(Split(TempDate(0),"||")(1)),"{%userhomepage%}",UserHomepage)
		end if
		if Not IsNumeric(UserQQ) then
			strGuestButton=strGuestButton & Split(TempDate(1),"||")(0)
		else
			strGuestButton=strGuestButton & Replace(Split(TempDate(1),"||")(1),"{%userqq%}",UserQQ)
		end if
		if UserEmail="未填" then
			strGuestButton=strGuestButton & Split(TempDate(2),"||")(0)
		else
			strGuestButton=strGuestButton & Replace(Split(TempDate(2),"||")(1),"{%useremail%}",UserEmail)
		end if
		strGuestButton=strGuestButton & TempDate(3)
		if Cl.UserID>0 And Cl.UserLevel=1 then
			strGuestButton=strGuestButton & Split(Split(TempDate(4),"||")(0),"$")(0)
			if rsGuest("GuestIsPassed")=False then
				strGuestButton=strGuestButton & Split(Split(TempDate(4),"||")(0),"$")(1)
			else
				strGuestButton=strGuestButton & Split(Split(TempDate(4),"||")(0),"$")(2)
			end if
		else
			strGuestButton=strGuestButton & Split(TempDate(4),"||")(1)
		end if
		if Cl.UserID>0 And Cl.UserLevel<>5 then
			if (rsGuest("GuestName")=Cl.User_Info(5) and rsGuest("GuestIsPassed")=False) or Cl.UserLevel=1 then
			strGuestButton=strGuestButton & Split(TempDate(5),"||")(0)
				if Cl.UserLevel=1 then strGuestButton=strGuestButton & Split(TempDate(5),"||")(1)
			end if
		end if
		strGuestButton=Replace(strGuestButton,"{%usericq%}",UserIcq)
		strGuestButton=Replace(strGuestButton,"{%usermsn%}",UserMsn)
		strGuestButton=Replace(strGuestButton,"{%guestip%}",rsGuest("GuestIP"))
		strGuestButton=Replace(strGuestButton,"{%guestid%}",rsGuest("GuestID"))
		strTemp=Replace(strTemp,"{%showguestbutton%}",strGuestButton)
		strTemp=Replace(strTemp,"{%userguestname%}",UserGuestName)
		'strTemp=Replace(strTemp,"{%%}",)
		ShowGuestList=ShowGuestList & strTemp
		rsGuest.movenext
		i=i+1
		if i>=MaxPerPage then exit do
	loop
	ShowGuestList=Replace(ShowGuestList,"{%guestpath%}",GuestPath)
	ShowGuestList=Replace(ShowGuestList,"{%webname%}",Cl.Web_Info(0))
	ShowGuestList=Replace(ShowGuestList,"{%posttime%}",GuestPath&"posttime.gif")
	Set ClUbb=Nothing
End Function

'标示搜索关键字(strChar)
function KeywordReplace(strChar)
	if strChar="" then
		KeywordReplace=""
	else
		KeywordReplace=	replace(strChar,""&keyword&"","<font color=red>"&keyword&"</font>")
	end if
end function

'签写留言
'参  数：无
Function WriteGuest()
	if Not Cl.ChkUserLevel(Cl.Web_Setting(35),Cl.UserLevel) then
		Call Cl.OutErr("<li>你无权限发表留言，您不是“"&Cl.GetUserGroupName(Cl.Web_Setting(35))&"”！</li>")
		Exit Function
	end if
	if SaveEdit<>1 then
		WriteType=GuestType
		WriteName=""
		if Cl.UserID>0 then WriteName=Cl.User_Info(5)
		WriteSex="1"
		WriteFace="1"
		WriteImages="01"
		WriteHomepage="http://"
	end if
	Dim strTemp
	strTemp=Template.html(7)
	strTemp=Replace(strTemp,"{%pagetitle%}",PageTitle)
	if WriteType=0 then
		strTemp=Replace(strTemp,"{%writeuserinfo%}",Template.html(8))
		if WriteSex=1 then
			strTemp=Replace(strTemp,"{%checked_1%}"," checked")
			strTemp=Replace(strTemp,"{%checked_0%}","")
		else
			strTemp=Replace(strTemp,"{%checked_0%}"," checked")
			strTemp=Replace(strTemp,"{%checked_1%}","")
		end if
		strTemp=Replace(strTemp,"{%writeemail%}",WriteEmail)
		strTemp=Replace(strTemp,"{%writeqq%}",WriteQQ)
		strTemp=Replace(strTemp,"{%writeicq%}",WriteIcq)
		strTemp=Replace(strTemp,"{%writemsn%}",WriteMsn)
		strTemp=Replace(strTemp,"{%writehomepage%}",WriteHomepage)
	else
		strTemp=Replace(strTemp,"{%writeuserinfo%}",Template.html(9))
	end if
	strTemp=Replace(strTemp,"{%writename%}",WriteName)
	strTemp=Replace(strTemp,"{%writeimages%}",WriteImages)
	strTemp=Replace(strTemp,"{%writetitle%}",WriteTitle)
	strTemp=Replace(strTemp,"{%showwriteface%}",ShowWriteFace)
	strTemp=Replace(strTemp,"{%showubb%}",ShowUbb)
	strTemp=Replace(strTemp,"{%writecontent%}",WriteContent)
	strTemp=Replace(strTemp,"{%saveedit%}",SaveEdit)
	strTemp=Replace(strTemp,"{%saveeditid%}",SaveEditId)
	strTemp=Replace(strTemp,"{%guestpath%}",GuestPath)
	WriteGuest=strTemp
End Function

'回复留言
Function ReplyGuest()
	dim ReplyId
	ReplyId=Cl.ChkClng(request("guestid"))
	if ReplyId=0 then
		Call Cl.OutErr("<li>请指定要回复的留言ID！</li>")
		Exit Function
	End if
	sqlGuest="select * from Cl_Guest where GuestId=" & ReplyId
	set rsGuest=server.createobject("adodb.recordset")
	OpenConn : rsGuest.open sqlGuest,Conn,1,1
	if rsGuest.bof and rsGuest.eof then
		ReplyGuest=Template.Strings(12)
		Exit Function
	else
		WriteTitle="Re: "&rsGuest("GuestTitle")
		ReplyGuest=ShowGuestList()
	end if
	ReplyGuest=ReplyGuest&WriteGuest()
	rsGuest.close:set rsGuest=Nothing
End Function 

'编辑留言
Function EditGuest()
	if Cl.UserID=0 or Cl.UserLevel=5 then
		Call Cl.OutErr("<li>请先登录后进行操作！</li>")
		Exit Function
	End if
	dim EditId
	EditId=request("guestid")
	if EditId="" then
		Call Cl.OutErr("<li>请指定要编辑的留言ID！</li>")
		exit Function
	else
		EditId=clng(EditId)
		sqlGuest="select * from Cl_Guest where GuestId=" & EditId
	end if
	set rsGuest=server.createobject("adodb.recordset")
	OpenConn : rsGuest.open sqlGuest,Conn,1,1
	if rsGuest.bof and rsGuest.eof then
		Call Cl.OutErr("<br /><li>找不到指定的留言！</li>")
		exit Function
	end if
	if (rsGuest("GuestName")=Cl.User_Info(5) and rsGuest("GuestIsPassed")=False) or Cl.UserLevel=1 then
		WriteName=rsGuest("GuestName")
		WriteType=rsGuest("GuestType")
		WriteSex=rsGuest("GuestSex")
		WriteEmail=rsGuest("GuestEmail")
		WriteQQ=rsGuest("GuestOicq")
		WriteIcq=rsGuest("GuestIcq")
		WriteMsn=rsGuest("GuestMsn")
		WriteHomepage=rsGuest("GuestHomepage")
		WriteFace=rsGuest("GuestFace")
		WriteImages=rsGuest("GuestImages")
		WriteTitle=rsGuest("GuestTitle")
		WriteContent=rsGuest("GuestContent")
		SaveEdit=1
		SaveEditId=EditId
		EditGuest=ShowGuestList()
		EditGuest=EditGuest&WriteGuest()
	else
		Call Cl.OutErr("<li>除管理员外，用户只可以编辑自己发表的留言，且留言未通过审核！</li>")
	end if    
	rsGuest.close:set rsGuest=Nothing
End Function

'删除留言
sub DelGuest()
	if Cl.UserID=0 or Cl.UserLevel=5 then
		Call Cl.OutErr("<li>请先登录后进行操作！</li>")
		Exit sub
	End if
	dim delid
	delid=Trim(Request("guestid"))
	if delid="" then
		Call Cl.OutErr("<li>未指定要删除的留言ID，或者你不是管理员！</li>")
		exit sub
	end if
	if instr(delid,",")>0 then
		delid=replace(delid," ","")
		sql="Select * from Cl_Guest where GuestID in (" & delid & ")"
	else
		delid=clng(delid)
		sql="select * from Cl_Guest where GuestID=" & delid
	end if
	Set rs=Server.CreateObject("Adodb.RecordSet")
	OpenConn : rs.Open sql,Conn,1,3
	if rs.bof and rs.eof then
		Call Cl.OutErr("<br /><li>找不到您指定的留言！</li>")
		exit sub
	end if

	if rs("GuestName")<>Cl.User_Info(5) and rs("GuestIsPassed")=True and Cl.UserLevel<>1 then
		Call Cl.OutErr("<li>您没有使用此功能的权限！</li>")
	else
		do while not rs.eof
			rs.delete
			rs.update
			rs.movenext
		loop
		rs.close:set rs=Nothing
		Call Cl.OutMsg("恭喜你，删除留言成功！",ComeUrl)
	end if    
end sub

'审核留言
sub PassGuest()
	if Cl.UserID=0 or Cl.UserLevel=5 then
		Call Cl.OutErr("<li>请先登录后进行操作！</li>")
		Exit sub
	End if
	dim passid
	passid=Trim(Request("guestid"))
	if passid="" or Cl.UserLevel<>1 then
		Call Cl.OutErr("<li>未指定要审核的留言ID，或者你不是管理员！</li>")
		exit sub
	end if
	if instr(passid,",")>0 then
		passid=replace(passid," ","")
		sql="Select * from Cl_Guest where GuestID in (" & passid & ")"
	else
		passid=clng(passid)
		sql="select * from Cl_Guest where GuestID=" & passid
	end if
	Set rs=Server.CreateObject("Adodb.RecordSet")
	OpenConn : rs.Open sql,Conn,1,3
	do while not rs.eof
		if Action="pass" then
			rs("GuestIsPassed")=True
			Cl.DelCahe("ShowGuest")
		else
			rs("GuestIsPassed")=False
		end if
		rs.update
		rs.movenext
	loop
	rs.close:set rs=Nothing
	Call Cl.OutMsg("恭喜你，操作成功！",ComeUrl)
	'response.redirect ComeUrl
end sub

'管理员回复留言
Function AdimReplyGuest()
	if Cl.UserID=0 or Cl.UserLevel=5 then
		Call Cl.OutErr("<li>请先登录后进行操作！</li>")
		Exit Function
	End if
	dim AdminReplyId
	AdminReplyId=request("guestid")
	if AdminReplyId="" or Cl.UserLevel<>1 then
		Call Cl.OutErr("<li>未指定要回复的留言ID，或者你不是管理员！</li>")
		Exit Function
	else
		AdminReplyId=clng(AdminReplyId)
		sqlGuest="select * from Cl_Guest where GuestId=" & AdminReplyId
	end if
	set rsGuest=server.createobject("adodb.recordset")
	OpenConn : rsGuest.open sqlGuest,Conn,1,1
	if rsGuest.bof and rsGuest.eof then
		Call Cl.OutErr("<br /><li>找不到您指定的留言！</li>")
		exit Function
	else
		AdminReplyContent=rsGuest("GuestReply")
		if IsNull(AdminReplyContent) then AdminReplyContent=""
		AdimReplyGuest=ShowGuestList()
	end if
	rsGuest.close:set rsGuest=Nothing
	AdimReplyGuest=AdimReplyGuest & Template.html(10)
	AdimReplyGuest=Replace(AdimReplyGuest,"{%pagetitle%}",PageTitle)
	AdimReplyGuest=Replace(AdimReplyGuest,"{%showubb%}",ShowUbb)
	AdimReplyGuest=Replace(AdimReplyGuest,"{%adminreplycontent%}",AdminReplyContent)
	AdimReplyGuest=Replace(AdimReplyGuest,"{%guestid%}",AdminReplyId)
	AdimReplyGuest=Replace(AdimReplyGuest,"{%comeurl%}",ComeUrl)
End Function

'保存管理员回复留言
Sub SaveAdminReplyGuest()
	dim GuestReply,SaveAdminReplyId
	dim sqlMaxId,rsMaxId,MaxId
	GuestReply=request("GuestContent")
	SaveAdminReplyId=request("guestid")
	if SaveAdminReplyId="" or Cl.UserLevel<>1 then
		Call Cl.OutErr("<li>未指定要回复的留言ID，或者你不是管理员！</li>")
		exit Sub
	end if
	sqlMaxId="select max(GuestMaxId) as MaxId from Cl_Guest"
	set rsMaxId=Cl.Execute(sqlMaxId)
	MaxId=rsMaxId("MaxId")
	if MaxId="" or isnull(MaxId) then MaxId=0
	set rsGuest=server.createobject("adodb.recordset")
	sql="select * from Cl_Guest where GuestId="&SaveAdminReplyId
	OpenConn : rsGuest.open sql,Conn,3,3
	if rsGuest.bof and rsGuest.eof then
		Call Cl.OutErr("<br /><li>找不到您指定的留言！</li>")
		exit sub
	else
		rsGuest("GuestMaxId")=MaxId+1
		rsGuest("GuestReply")=GuestReply
		rsGuest("GuestReplyAdmin")=Cl.User_Info(5)
		rsGuest("GuestReplyDatetime")=now()
		rsGuest.update
	end if
	rsGuest.close
	Set rsGuest=Nothing
	Call Cl.OutMsg("您的回复留言已经发送成功！",ComeUrl)
End Sub

Function ShowWriteFace()
	ShowWriteFace=""
	for i=1 to 20
		ShowWriteFace=ShowWriteFace&"<input type=""radio"" name=""GuestFace"" value="&i&""
		if i=clng(WriteFace) then ShowWriteFace = ShowWriteFace & " checked"
		ShowWriteFace=ShowWriteFace&"><img src="""&GuestPath&"face"&i&".gif"" width=""19"" height=""19"">"& vbcrlf
		if i mod 10 =0 then ShowWriteFace=ShowWriteFace&"<br />"
	next
End Function

'显示留言底部分页
Function ShowGuestPage()
	dim PageFileName
	PageFileName=strFileName
	if keyword<>"" then
		PageFileName=PageFileName&"?keyword="&keyword
	end if
	if action<>"" then
		PageFileName=PageFileName&"?action="&action
	end if
	if TotalPut>0 then
		ShowGuestPage=Cl.ShowPage(PageFileName,TotalPut,MaxPerPage,"条","留言")
	end if
End Function

'保存留言
sub SaveWriteGuest()
	if Not Cl.ChkUserLevel(Cl.Web_Setting(35),Cl.UserLevel) then
		Call Cl.OutErr("<li>留言发送失败！</li><li>你无权限发表留言，您不是“"&Cl.GetUserGroupName(Cl.Web_Setting(35))&"”！</li>")
		exit sub
	end if
	if Cint(Cl.UserLevel)>1 and Not Cl.CodeIsTrue(Trim(request("Guest_ChkCode")),"Guest_ChkCode") and Cl.Web_Setting(41)="Yes" then
		Call Cl.OutErr("<li>留言发送失败！</li><li>验证码错误！</li><li>请返回刷新页面后重新输入！</li>")
		exit sub
	end if
	dim SaveEditId,GuestName,GuestSex,GuestQQ,GuestEmail,GuestHomepage,GuestFace,GuestImages,GuestIcq,GuestMsn
	dim GuestTitle,GuestContent,GuestIsPrivate,GuestIsPassed
	dim GuestPassword,GuestPasswordConfirm,GuestQuestion,GuestAnswer,GuestUserlevel
	dim sqlMaxId,rsMaxId,MaxId,Saveinfo,sqlReg,rsReg

	GuestContent=Trim(request("GuestContent"))
	GuestTitle=Trim(request("GuestTitle"))
	if GuestType=0 then
		GuestName=Trim(request("GuestName"))
		GuestSex=Trim(request("GuestSex"))
		GuestQQ=Trim(request("GuestQQ"))
		GuestIcq=Trim(request("GuestIcq"))
		GuestMsn=Trim(request("GuestMsn"))
		GuestEmail=Trim(request("GuestEmail"))
		GuestHomepage=Trim(request("GuestHomepage"))
		if GuestHomepage="http://" or isnull(GuestHomepage) then GuestHomepage=""
		if GuestSex="" then
			Call Cl.OutErr("<li>留言发送失败！</li><li>性别不能为空！</li>")
			exit sub
		else
			GuestSex=cint(GuestSex)
		end if
		if GuestSex<>"1" and GuestSex<>"0" then GuestSex="1"
	else
		GuestName=Trim(request("GuestName"))'Cl.User_Info(5)
	end if
	GuestImages=Trim(request("GuestImages"))
	GuestFace=Trim(request("GuestFace"))


	GuestIsPrivate=Trim(request("GuestIsPrivate"))
	if GuestIsPrivate="yes" then
		if Not Cl.ChkUserLogin then
			Call Cl.OutErr("<li>留言发送失败！</li><li>您未登录，不能使用隐藏留言功能！</li>")
			exit sub
		else
		GuestIsPrivate=True
		end if
	else
		GuestIsPrivate=False
	end if
	if Cl.Web_Setting(6)="Yes" then
		GuestIsPassed=False
	else
		GuestIsPassed=True
	end if
	SaveEdit=request("saveedit")
		
	if GuestName="" or GuestTitle="" or GuestContent="" then
		Call Cl.OutErr("<li>留言发送失败！</li><li>请将必要的信息填写完整！</li>")
		exit sub
	end if
	GuestContent=Left(GuestContent,500)
	GuestTitle=Left(GuestTitle,100)
	if Cl.Web_Setting(5)="Yes" then  '脏话过滤
		GuestContent=Cl.ChkBadWords(GuestContent)
		GuestTitle=Cl.ChkBadWords(GuestTitle)
	end if

	if SaveEdit=1 then
		SaveEditId=request("saveeditid")
		if SaveEditId="" then
			Call Cl.OutErr("<li>请指定要编辑的留言ID！</li>")
			exit sub
		else
			sqlMaxId="select max(GuestMaxId) as MaxId from Cl_Guest"
			set rsMaxId=Cl.Execute(sqlMaxId)
			MaxId=rsMaxId("MaxId")
			if MaxId="" or isnull(MaxId) then MaxId=0
			set rsGuest=server.createobject("adodb.recordset")
			sql="select * from Cl_Guest where GuestID="&SaveEditId
			OpenConn : rsGuest.open sql,Conn,1,3
			rsGuest("GuestName")=GuestName
			rsGuest("GuestSex")=GuestSex
			rsGuest("GuestOicq")=GuestQQ
			rsGuest("GuestIcq")=GuestIcq
			rsGuest("GuestMsn")=GuestMsn
			rsGuest("GuestEmail")=GuestEmail
			rsGuest("GuestHomepage")=GuestHomepage
			rsGuest("GuestIP")=Request.ServerVariables("REMOTE_ADDR")
			rsGuest("GuestTitle")=GuestTitle
			rsGuest("GuestFace")=GuestFace
			rsGuest("GuestContent")=GuestContent
			rsGuest("GuestDatetime")=now()
			rsGuest("GuestImages")=GuestImages
			rsGuest("GuestMaxId")=MaxId+1
			rsGuest("GuestIsPrivate")=GuestIsPrivate
			rsGuest("GuestIsPassed")=GuestIsPassed
			rsGuest.update
			if Cl.Web_Setting(6)="Yes" then
				Call Cl.OutMsg("留言编辑成功！\n只有管理员审核通过的留言才会显示出来。",strFileName)
			else
				Cl.DelCahe("ShowGuest")
				Call Cl.OutMsg("留言编辑成功！",strFileName)
			end if
		end if
	else
		if GuestContent<>Session("OldGuestContent") then 
			Session("OldGuestContent")=GuestContent
			sqlMaxId="select max(GuestMaxId) as MaxId from Cl_Guest"
			set rsMaxId=Cl.Execute(sqlMaxId)
			MaxId=rsMaxId("MaxId")
			if MaxId="" or isnull(MaxId) then MaxId=0
			set rsGuest=server.createobject("adodb.recordset")
			sql="select Top 1 * from Cl_Guest"
			OpenConn : rsGuest.open sql,Conn,1,3
			rsGuest.addnew
			rsGuest("GuestType")=GuestType
			rsGuest("GuestName")=GuestName
			rsGuest("GuestSex")=GuestSex
			rsGuest("GuestOicq")=GuestQQ
			rsGuest("GuestIcq")=GuestIcq
			rsGuest("GuestMsn")=GuestMsn
			rsGuest("GuestEmail")=GuestEmail
			rsGuest("GuestHomepage")=GuestHomepage
			rsGuest("GuestIP")=Request.ServerVariables("REMOTE_ADDR")
			rsGuest("GuestTitle")=GuestTitle
			rsGuest("GuestFace")=GuestFace
			rsGuest("GuestContent")=GuestContent
			rsGuest("GuestDatetime")=now()
			rsGuest("GuestImages")=GuestImages
			rsGuest("GuestMaxId")=MaxId+1
			rsGuest("GuestIsPrivate")=GuestIsPrivate
			rsGuest("GuestIsPassed")=GuestIsPassed
			rsGuest.update
			if Cl.Web_Setting(6)="Yes" then
				Saveinfo="您的留言已经发送成功！\n只有管理员审核通过的留言才会显示出来。"
			else
				Cl.DelCahe("ShowGuest")
				Saveinfo="您的留言已经发送成功！"
			end if
			Call Cl.OutMsg(Saveinfo,strFileName)
		else
			Call Cl.OutErr("<li>请不要连续发送内容相同的留言或空留言！</li>")
		end if
	end if
end sub

'显示Ubb标签
Function ShowUbb()
	Dim sTemp,UbbImagePath
	UbbImagePath=Cl.WebDir & "images/Ubb/"
	sTemp="<script type=""text/javascript"" src=""" & Cl.WebDir & "Inc/js/Ubb.js""></script>"
	sTemp=sTemp & "<img onclick=bold() align=absmiddle src=""" & UbbImagePath & "Ubb_bold.gif"" width=""22"" height=""22"" alt=""粗体"" border=""0"">"
	sTemp=sTemp & "<img onclick=italicize() align=absmiddle src=""" & UbbImagePath & "Ubb_italicize.gif"" width=""23"" height=""22"" alt=""斜体"" border=""0"">"
	sTemp=sTemp & "<img onclick=underline() align=absmiddle src=""" & UbbImagePath & "Ubb_underline.gif"" width=""23"" height=""22"" alt=""下划线"" border=""0"">"
	sTemp=sTemp & "<img onclick=center() align=absmiddle src=""" & UbbImagePath & "Ubb_center.gif"" width=""22"" height=""22"" alt=""居中"" border=""0"">"
	sTemp=sTemp & "<img onclick=hyperlink() align=absmiddle src=""" & UbbImagePath & "Ubb_url.gif"" width=""22"" height=""22"" alt=""超级链接"" border=""0"">"
	sTemp=sTemp & "<img onclick=emails() align=absmiddle src=""" & UbbImagePath & "Ubb_email.gif"" width=""23"" height=""22"" alt=""Email链接"" border=""0"">"
	sTemp=sTemp & "<img onclick=image() align=absmiddle src=""" & UbbImagePath & "Ubb_image.gif"" width=""23"" height=""22"" alt=""图片"" border=""0"">"
	sTemp=sTemp & "<img onclick=flash() align=absmiddle src=""" & UbbImagePath & "Ubb_swf.gif"" width=""23"" height=""22"" alt=""Flash图片"" border=""0"">"
	sTemp=sTemp & "<img onclick=Cdir() align=absmiddle src=""" & UbbImagePath & "Ubb_Shockwave.gif"" width=""23"" height=""22"" alt=""Shockwave文件"" border=""0"">"
	sTemp=sTemp & "<img onclick=Crm() align=absmiddle src=""" & UbbImagePath & "Ubb_rm.gif"" width=""23"" height=""22"" alt=""realplay视频文件"" border=""0"">"
	sTemp=sTemp & "<img onclick=Cwmv() align=absmiddle src=""" & UbbImagePath & "Ubb_mp.gif"" width=""23"" height=""22"" alt=""Media Player视频文件"" border=""0"">"
	sTemp=sTemp & "<img onclick=Cmov() align=absmiddle src=""" & UbbImagePath & "Ubb_qt.gif"" width=""23"" height=""22"" alt=""QuickTime视频文件"" border=""0"">"
	sTemp=sTemp & "<img onclick=showcode() align=absmiddle src=""" & UbbImagePath & "Ubb_code.gif"" width=""22"" height=""22"" alt=""代码"" border=""0"">"
	sTemp=sTemp & "<img onclick=quote() align=absmiddle src=""" & UbbImagePath & "Ubb_quote.gif"" width=""23"" height=""22"" alt=""引用"" border=""0"">"
	sTemp=sTemp & "<IMG onclick=setfly() align=absmiddle height=""22"" alt=""飞行字"" src=""" & UbbImagePath & "Ubb_fly.gif"" width=""23"" border=""0"">"
	sTemp=sTemp & "<IMG onclick=move() align=absmiddle height=""22"" alt=""移动字"" src=""" & UbbImagePath & "Ubb_move.gif"" width=""23"" border=""0"">"
	sTemp=sTemp & "<IMG onclick=glow() align=absmiddle height=""22"" alt=""发光字"" src=""" & UbbImagePath & "Ubb_glow.gif"" width=""23"" border=""0"">"
	sTemp=sTemp & "<IMG onclick=shadow() align=absmiddle height=""22"" alt=""阴影字"" src=""" & UbbImagePath & "Ubb_shadow.gif"" width=""23"" border=""0"">"
	sTemp=sTemp & "<img onclick=openhelp() align=absmiddle src=""" & UbbImagePath & "Ubb_Help.gif"" width=""23"" height=""22"" alt=""帮助"" border=""0"">"
	sTemp=sTemp & "<br />"
	sTemp=sTemp & "字体："
	sTemp=sTemp & "<SELECT onchange=showfont(this.options[this.selectedIndex].value) name=font>"
	sTemp=sTemp & "<option value=""宋体"" selected>宋体</option>"
	sTemp=sTemp & "<option value=""楷体_GB2312"">楷体</option>"
	sTemp=sTemp & "<option value=""新宋体"">新宋体</option>"
	sTemp=sTemp & "<option value=""黑体"">黑体</option>"
	sTemp=sTemp & "<option value=""隶书"">隶书</option>"
	sTemp=sTemp & "<OPTION value=""Andale Mono"">Andale Mono</OPTION>"
	sTemp=sTemp & "<OPTION value=""Arial"">Arial</OPTION>"
	sTemp=sTemp & "<OPTION value=""Arial Black"">Arial Black</OPTION>"
	sTemp=sTemp & "<OPTION value=""Book Antiqua"">Book Antiqua</OPTION>"
	sTemp=sTemp & "<OPTION value=""Century Gothic"">Century Gothic</OPTION>"
	sTemp=sTemp & "<OPTION value=""Comic Sans MS"">Comic Sans MS</OPTION>"
	sTemp=sTemp & "<OPTION value=""Courier New"">Courier New</OPTION>"
	sTemp=sTemp & "<OPTION value=""Georgia"">Georgia</OPTION>"
	sTemp=sTemp & "<OPTION value=""Impact"">Impact</OPTION>"
	sTemp=sTemp & "<OPTION value=""Tahoma"">Tahoma</OPTION>"
	sTemp=sTemp & "<OPTION value=""Times New Roman"" >Times New Roman</OPTION>"
	sTemp=sTemp & "<OPTION value=""Trebuchet MS"">Trebuchet MS</OPTION>"
	sTemp=sTemp & "<OPTION value=""Script MT Bold"">Script MT Bold</OPTION>"
	sTemp=sTemp & "<OPTION value=""Stencil"">Stencil</OPTION>"
	sTemp=sTemp & "<OPTION value=""Verdana"">Verdana</OPTION>"
	sTemp=sTemp & "<OPTION value=""Lucida Console"">Lucida Console</OPTION>"
	sTemp=sTemp & "</SELECT>"
	sTemp=sTemp & "字体大小"
	sTemp=sTemp & "<select name=""size"" onChange=""showsize(this.options[this.selectedIndex].value)"">"
	sTemp=sTemp & "<option value=""1"">1</option>"
	sTemp=sTemp & "<option value=""2"">2</option>"
	sTemp=sTemp & "<option value=""3"" selected>3</option>"
	sTemp=sTemp & "<option value=""4"">4</option>"
	sTemp=sTemp & "</select>"
	sTemp=sTemp & "颜色：<a href=""javascript:fontColor('TitleFontColor')""><img src=""" & Cl.WebDir & "images/fgcolor.gif"" alt=""字体颜色"" border=""0"" align=""absmiddle""></a>"
	sTemp=sTemp & "&nbsp;"
	sTemp=sTemp & "<IMG align=absmiddle onclick=openemot() src=""" & UbbImagePath & "emot.gif"" border=0 alt=选择心情图标 style=""cursor:hand"">"
	ShowUbb=sTemp
End Function
%>