<% Option Explicit %>
<!--#include file="common.asp" -->
<!--#include file="functions/functions_send_mail.asp" -->
<!--#include file="functions/functions_common.asp" -->
<!--#include file="includes/emoticons_inc.asp" -->
<!--#include file="functions/functions_hash1way.asp" -->
<%
'****************************************************************************************
'**  Copyright Notice    
'**
'**  Web Wiz Guide - Web Wiz Guestbook
'**                                                              
'**  Copyright 2001-2004 Bruce Corkhill All Rights Reserved.                                
'**
'**  This program is free software; you can modify (at your own risk) any part of it 
'**  under the terms of the License that accompanies this software and use it both 
'**  privately and commercially.
'**
'**  All copyright notices must remain in tacked in the scripts and the 
'**  outputted HTML.
'**
'**  You may use parts of this program in your own private work, but you may NOT
'**  redistribute, repackage, or sell the whole or any part of this program even 
'**  if it is modified or reverse engineered in whole or in part without express 
'**  permission from the author.
'**
'**  You may not pass the whole or any part of this application off as your own work.
'**   
'**  All links to Web Wiz Guide and powered by logo's must remain unchanged and in place
'**  and must remain visible when the pages are viewed unless permission is first granted
'**  by the copyright holder.
'**
'**  This program is distributed in the hope that it will be useful,
'**  but WITHOUT ANY WARRANTY; without even the implied warranty of
'**  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR ANY OTHER 
'**  WARRANTIES WHETHER EXPRESSED OR IMPLIED.
'**
'**  You should have received a copy of the License along with this program; 
'**  if not, write to:- Web Wiz Guide, PO Box 4982, Bournemouth, BH8 8XP, United Kingdom.
'**    
'**
'**  No official support is available for this program but you may post support questions at: -
'**  http://www.webwizguide.info/forum
'**
'**  Support questions are NOT answered by e-mail ever!
'**
'**  For correspondence or non support questions contact: -
'**  info@webwizguide.com
'**
'**  or at: -
'**
'**  Web Wiz Guide, PO Box 4982, Bournemouth, BH8 8XP, United Kingdom
'**
'****************************************************************************************


'Set the response buffer to true as we maybe redirecting
Response.Buffer = True



'Dimension variables
Dim strInputName 			'Holds the Users name
Dim strInputCountry 			'Holds the users country
Dim strInputEmailAddress		'Holds the Users e-mail address
Dim strInputHomepage 			'Holds the Users homepage
Dim strInputComments 			'Holds the Users comments
Dim saryCommentWord 			'Array to hold each word in the comments enetred by the user
Dim intCheckWordLengthLoopCounter	'Loop counter
Dim intWordLength			'Holds the length of the word to be checked
Dim blnWordLenthOK			'Boolean set to False if any words in the description are above 30 characters
Dim intLongestWordLength 		'Holds the number of characters in the longest word entered in the description
Dim strEmailSubject			'Holds the subject of the e-mail notification
Dim strEmailBody			'Holds the body of the e-mail
Dim blnEmailSent			'Set to tru if the e-mail is sent
Dim blnAlreadyPostsed			'Set to true if the person has already posted comments in the gb
Dim intLoop				'Loop counter
Dim blnSessionID			'Set to true if the session ID is OK
Dim blnSecurityCodeOK



'Intialise variables
blnAlreadyPostsed = False
blnSessionID = False
blnSecurityCodeOK = true



'Read in user deatils from the guestbook form
strInputName = Trim(Mid(Request.Form("name"), 1, 30))
strInputCountry = Trim(Mid(Request.Form("country"), 1, 40))
strInputEmailAddress = Trim(Mid(Request.Form("email"), 1, 50))
strInputHomepage = Trim(Mid(Request.Form("homepage"), 1, 50))
strInputComments = Trim(Request.Form("comments"))

'Strip HTML tags
strInputName = Replace(strInputName, "<", "&lt;", 1, -1, 1)
strInputName = Replace(strInputName, ">", "&gt;", 1, -1, 1)
strInputComments = Replace(strInputComments, "<", "&lt;", 1, -1, 1)
strInputComments = Replace(strInputComments, ">", "&gt;", 1, -1, 1)

If strInputCountry = "0" Then strInputCountry = "None Given"

'Strip malicious code from the homepage and email links
strInputEmailAddress = characterStrip(LCase(strInputEmailAddress))
strInputHomepage = characterStrip(LCase(strInputHomepage))




'Check to see if the session ID's match then don't save
If blnSessionCheck Then
	If Request.Form("sid") = HashEncode(Session.SessionID) Then blnSessionID = True
Else
	 blnSessionID = True
End If


'Check security code is OK
If blnSecurityImages AND (Session("lngSecurityCode") <> Trim(Mid(Request.Form("securityCode"), 1, 6))) Then 
	'Set the security code OK variable to false
	blnSecurityCodeOK = False
End If



'Split-up each word in the comments from the user to check that no word entered is over 50 characters
saryCommentWord = Split(Trim(strInputComments), " ")
	
'Initialse the word length variable
blnWordLenthOK = True
	
'Loop round to check that each word in the comments entered by the user is not above 50 characters
For intCheckWordLengthLoopCounter = 0 To UBound(saryCommentWord)
	
	'Initialise the intWordLength variable with the length of the word to be searched
	intWordLength = Len(saryCommentWord(intCheckWordLengthLoopCounter))
	
	'Get the number of characters in the longest word
	If intWordLength => intLongestWordLength Then intLongestWordLength = intWordLength
		
	'If the word length to be searched is more than or equal to 50 then set the blnWordLegthOK to false
	If intWordLength => 50 Then blnWordLenthOK = False
Next




'Change my own codes for bold and italic HTML tags back to the normal satndrd HTML tags now that the check for unwated HTML tags is over
strInputComments = Replace(strInputComments, "[B]", "<b>", 1, -1, 1)
strInputComments = Replace(strInputComments, "[/B]", "</b>", 1, -1, 1)
strInputComments = Replace(strInputComments, "[I]", "<i>", 1, -1, 1)
strInputComments = Replace(strInputComments, "[/I]", "</i>", 1, -1, 1)
strInputComments = Replace(strInputComments, "[U]", "<u>", 1, -1, 1)
strInputComments = Replace(strInputComments, "[/U]", "</u>", 1, -1, 1)




'Loop through the emoticons array and change codes to emoticons
For intLoop = 1 to UBound(saryEmoticons)
	strInputComments = Replace(strInputComments, saryEmoticons(intLoop,2), "<img border=""0"" src=""" & saryEmoticons(intLoop,3) & """>", 1, -1, 1)
Next



'Replace the vb new line code for the HTML new break code
strInputComments = Replace(strInputComments, vbCrLf, "<br>")


'Get rid of repeated return key hits so there arn't two many new lines going half way down the page (<br> is the HTML tag for new line)
'Loop though the comments entered by the user till all cases of two new lines togather are replaced by one new line
Do While InStr(1, strInputComments, "<br><br>" ,vbTextCompare) > 0
	
	'Replace <br><br> with one case of <br>
	strInputComments = Replace(strInputComments , "<br><br>", "<br>")
Loop





'Replace swear words with other words with ***	
'Initalise the SQL string with a query to read in all the words from the smut table
strSQL = "SELECT " & strDbTable & "Smut.* FROM " & strDbTable & "Smut;"

'Open the recordset
rsCommon.Open strSQL, adoCon

'Loop through all the words to check for
Do While NOT rsCommon.EOF
	
	'Replace the swear words with the words in the database the swear words
	strInputComments = Replace(strInputComments, rsCommon("Smut"), rsCommon("Word_replace"), 1, -1, 1)
	strInputName = Replace(strInputName, rsCommon("Smut"), rsCommon("Word_replace"), 1, -1, 1)
	strInputCountry = Replace(strInputCountry, rsCommon("Smut"), rsCommon("Word_replace"), 1, -1, 1)
	strInputHomepage = Replace(strInputHomepage, rsCommon("Smut"), rsCommon("Word_replace"), 1, -1, 1)

	'Move to the next word in the recordset
	rsCommon.MoveNext
Loop

'Reset recordset
rsCommon.Close




	


'Initalise the SQL string with a query to read in all the comments from the database
strSQL = "SELECT TOP 1 " & strDbTable & "Comments.* FROM " & strDbTable & "Comments ORDER BY " & strDbTable & "Comments.MessageID DESC;"
		
'Set the cursor type property of the record set to Dynamic so we can navigate through the record set
rsCommon.CursorType = 2
		
'Set the Lock Type for the records so that the record set is only locked when it is updated
rsCommon.LockType = 3
		
'Open the recordset
rsCommon.Open strSQL, adoCon




'If cookies anti spam settings are enabled check a cookie has not already been set
If blnCookieSet = True Then
	If CBool(Request.Cookies("WWGBook")("Signed")) = True Then blnAlreadyPostsed = True
End If

'If IP blooking ant-spam settings are enabled check the IP address of the last poster
If blnIPBlocking = True Then
	If NOT rsCommon.EOF Then 
		If rsCommon("IP") = Request.ServerVariables("REMOTE_ADDR") Then blnAlreadyPostsed = True 
	End If
End If


'If there is no comments then display an error message
If strInputComments = "" AND strInputName = "" Then blnAlreadyPostsed = True 




'Write to the database if there are no unwanted HTML tags or the word lengths in the commets entered by the user are OK
If blnWordLenthOK AND blnSessionID AND blnAlreadyPostsed = False AND blnSecurityCodeOK Then
	
	
		
	'Add a new record to the recordset
	rsCommon.AddNew
	
	rsCommon.Fields("Name") =  strInputName
	rsCommon.Fields("Country") = strInputCountry
	rsCommon.Fields("EMail") = strInputEmailAddress
	rsCommon.Fields("Homepage") = strInputHomepage
	rsCommon.Fields("Comments") = strInputComments
	rsCommon.Fields("IP") = Request.ServerVariables("REMOTE_ADDR")
	
	'If the comments need to be authirsed first don't display them
	If blnAuthorise Then 
		rsCommon.Fields("Authorised") = false
	Else
		rsCommon.Fields("Authorised") = true
	End If
	
				
	'Update the database with the new recordset
	rsCommon.Update
	
	'Requery the database to make sure that the new comments have been added 
	'This will make the script wait until Database has updated itself as sometimes Access can be a little slow at updating
	rsCommon.Requery
	
	
	'If cookies anti-spam settings are enabled set a cookie on the users machine
	If blnCookieSet = True Then
		Response.Cookies("WWGBook")("Signed") = True
		Response.Cookies("WWGBook").Expires = DateAdd("n", 30, Now())
	End If
		
	
	
	'If the guestbook is configured to send an e-mail then send one
	If blnEmail = True Then
		
		'Turn the smiley image paths back into text :)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley1.gif"" border=""0"">", ":)", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley2.gif"" border=""0"">", ";)", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley3.gif"" border=""0"">", ":o", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley4.gif"" border=""0"">", ":D", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley5.gif"" border=""0"">", ":errr:", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley6.gif"" border=""0"">", ":(", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley7.gif"" border=""0"">", ":x", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley8.gif"" border=""0"">", ":o)", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley9.gif"" border=""0"">", "[:oops:]", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley10.gif"" border=""0"">", ":X:", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley11.gif"" border=""0"">", "xx(", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley12.gif"" border=""0"">", "|)", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley13.gif"" border=""0"">", ":V:", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley14.gif"" border=""0"">", ":^:", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley15.gif"" border=""0"">", "}:)", 1, -1, 1)
		strInputComments = Replace(strInputComments, "<img src=""guestbook_images/smiley16.gif"" border=""0"">", "8D", 1, -1, 1)
	
		'Initilise the subject of the e-mail
		strEmailSubject = "Guestbook comment notification"
	
		'Initailise the e-mail body variable with the body of the e-mail
		strEmailBody = "Hi "
		strEmailBody = strEmailBody & "<br><br>This e-mail is automactically generated by the Guestbook on your web site."
		strEmailBody = strEmailBody & "<br>The following comment has been posted in the Guestbook: -"
		strEmailBody = strEmailBody & "<br><br><b>Name: </b>" & strInputName
		strEmailBody = strEmailBody & "<br><b>E-Mail: </b>" & strInputEmailAddress
		strEmailBody = strEmailBody & "<br><b>Country: </b>" & strInputCountry
		strEmailBody = strEmailBody & "<br><b>Homepage: </b>" & strInputHomepage
		strEmailBody = strEmailBody & "<br><b>Comments: -</b><br>" & strInputComments
		
	
		'Call the funtion to send the e-mail
		blnEmailSent = SendMail(strEmailBody, strWebSiteEmailAddress, strEmailSubject, strMailComponent)
	End If

	'Return to the guestbook
	If blnAuthorise = false Then
		
		'Reset Server Variables
		rsCommon.Close
		Set rsCommon = Nothing	
		adoCon.Close
		Set adoCon = Nothing
		
		Response.Redirect "default.asp?PagePosition=1"
	End If
End If


'Reset Server Variables
rsCommon.Close
Set rsCommon = Nothing	
adoCon.Close
Set adoCon = Nothing
%>
<HTML> 
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Sign the Guest Book</TITLE>

<!-- The Web Wiz Guestbook v. <% = strVersion %> is written by Bruce Corkhill ©2001-2004
    	 If you want your Guestbook then goto http://www.webwizguestbook.com --> 

<!--#include file="includes/header.asp" -->
<div align="center"><span class="heading">Sign the Guestbook</span><br>
<a href="default.asp?PagePosition=<% = Server.URLEncode(Request.QueryString("PagePosition")) %>" target="_self"> Return to the the Guestbook</a></div>
<div align="center">
 <table width="100%" height="178" border="0" cellpadding="1" cellspacing="0">
  <tr>
   <td align="center"><% 
'If the session ID's don't match make sure the user has cookies enabled
If blnSessionID = False Then %>
	 <span class="bold">An authentication error occurred.<br />
	 Please ensure that cookies are enabled on your browser.</span><br /><%

'Else If the security code is incorrect let the use know
ElseIf blnSecurityCodeOK = False Then %>
   <span class="bold">A security  error occurred.<br />
    Please ensure that the security code entered matches that displayed.</span><br />
   <br />
   <a href="sign.asp">Re-enter my comments</a><br /><%	

'If word length is to long display an error message
ElseIf blnAlreadyPostsed Then %>
   <span class="bold">Our records show that you have already posted comments in the Guestbook</span><br /><%

'If authrisation of posts is enabled let the user know that there post will need to be authorised first
ElseIf blnAuthorise Then %>
	<span class="heading">Your comments have been saved.</span><br /><br />
	<span class="bold">Your comments will need to be approved by the Guestbook administrator before they are displayed to others visiting the site.</span><br /><%

'If the user has already posted display an error message
Else %>
    <span class="bold">Sorry, one or more of the words used in your Comments where to long</span><br />
    <br />
    <a href="javascript:history.back(1);">Edit my comments</a><br /><%
End If %>
    <br><br><br>
   </td>
  </tr>
 </table>
 <br>
 <%
'***** START WARNING - REMOVAL OR MODIFICATION OF THIS CODE WILL VIOLATE THE LICENSE AGREEMENT ******
If blnLCode = True Then
	Response.Write("<span class=""smText"">Powered by <a href=""http://www.webwizguestbook.com"" target=""_blank"" class=""smLink"">Web Wiz Guestbook</a> version " & strVersion & "</span>")
	Response.Write("<br><span class=""smText"">Copyright &copy;2001-2004 <a href=""http://www.webwizguide.info"" target=""_blank"" class=""smLink"">Web Wiz Guide</a></span>")
End If 
'***** END WARNING - REMOVAL OR MODIFICATION OF THIS CODE WILL VIOLATE THE LICENSE AGREEMENT ******
 %>
 <br>
</div>
<!--#include file="includes/footer.asp" -->