File: D:/web/secure/itpplates/from bam/apputils.asp
<%
' (SS,31/08/11) removed Non Smoking tick box as requested by Ruth (Sub ShowAccommodationDetails)
' (SS,04/04/13) added function CurrencyAmount(AAmount) and replaced references to GBP with called to CurrencyAmount
' (SS,18/04/14) added Application("TotalCostSuffix")
' (SS,30/11/15) changed Sub EmailAvailabilityWarning to remove font face definition which was creating long email and issue
Function CheckValidPersonalDetails
If strFirstName = "" Then strError = strError + IIf(strError = "", "", ", ") + "First Name"
If strSurname = "" Then strError = strError + IIf(strError = "", "", ", ") + "Surname"
' (SS,3/10/14) added If Application("AddressEnabled") to only force if address is enabled because form can now be without the address
If Application("AddressEnabled") Then
If strAddress1 = "" Then strError = strError + IIf(strError = "", "", ", ") + "Address1"
If strPostcode = "" Then strError = strError + IIf(strError = "", "", ", ") + "Postcode/Zip"
If strCountry = "" Then strError = strError + IIf(strError = "", "", ", ") + "Country"
End If
' (SS,3/10/14)
If strOrganisation = "" And Application("OrganisationRequired") Then strError = strError + IIf(strError = "", "", ", ") + Application("OrganisationLabel")
If strEmail = "" Then strError = strError + IIf(strError = "", "", ", ") + "Email"
If strError <> "" Then strError = "Following fields must be filled in: " + strError + "."
' check that email and confirm email matches
If strError = "" Then
If strEmail <> strEmailConfirm Then strError = "Email and Retyped Email must match."
End If
CheckValidPersonalDetails = (strError = "")
End Function
' (SS,29/4/15) replaced strFullName with strFirstNameArray and added strSurnameArray
Function CheckValidAccommodationDetails
If strHotelID = "" Or strHotelID = "--> Please choose" Then strError = strError + IIf(strError = "", "", ", ") + "Hotel"
For i = 1 To MAX_ROOMS
If strFirstNameArray(i) <> "" Or strSurnameArray(i) <> "" Then
If strFirstNameArray(i) = "" Then strError = strError + IIf(strError = "", "", ", ") + "First Name " & i
If strSurnameArray(i) = "" Then strError = strError + IIf(strError = "", "", ", ") + "Surname " & i
If strArrivalDate(i) = "" Then strError = strError + IIf(strError = "", "", ", ") + "Arrival Date " & i
If strNoOfNights(i) = "" Then strError = strError + IIf(strError = "", "", ", ") + "No of Nights " & i
If strRoomType(i) = "" Then strError = strError + IIf(strError = "", "", ", ") + "Room Type " & i
End If
Next
If strError <> "" Then strError = "Following fields must be filled in: " + strError + "."
CheckValidAccommodationDetails = (strError = "")
End Function
Function CheckValidCreditCardDetails
If strCreditCardType = "" Or strCreditCardType = "--> Please choose" Then strError = strError + IIf(strError = "", "", ", ") + "Type of Credit Card"
If strCreditCardType = "Other" And strCreditCardOther = "" Then strError = strError + IIf(strError = "", "", ", ") + "Other card"
If strCreditCardNo = "" Then strError = strError + IIf(strError = "", "", ", ") + "Credit Card Number"
If strCreditCardName = "" Then strError = strError + IIf(strError = "", "", ", ") + "Name on Credit Card"
If strExpiryMonth = "" Then strError = strError + IIf(strError = "", "", ", ") + "Expiry Month"
If strExpiryYear = "" Then strError = strError + IIf(strError = "", "", ", ") + "Expiry Year"
If strError <> "" Then strError = "Following fields must be filled in: " + strError + "."
CheckValidCreditCardDetails = (strError = "")
End Function
' booking flag handing routines to prevent duplicate bookings
' (SS,7/12/14) new versions of CreateBookingFlag, CheckBookingFlag and DeleteBookingFlag that uses session variable instead of BookingFlags table which has now been deleted
Sub CreateBookingFlag
'DeleteBookingFlag ' delete it first in case it already exists '
'ExecuteQuery("INSERT INTO BookingFlags (SessionID) VALUES (" & Session.SessionID & ")")
Session("BookingFlag") = True
End Sub
Function CheckBookingFlag
'OpenQuery("SELECT * FROM BookingFlags WHERE SessionID = " & Session.SessionID)
'CheckBookingFlag = Not EndOfQuery
'CloseQuery
CheckBookingFlag = Session("BookingFlag") = True
End Function
Sub DeleteBookingFlag
'ExecuteQuery("DELETE FROM BookingFlags WHERE SessionID = " & Session.SessionID)
Session("BookingFlag") = False
End Sub
Sub ShowAvailability
Dim strPreviousHotel, strClass
%>
<TABLE border=0 cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<TD bgColor=#000000 colSpan=3><IMG height=1 src="space.gif" width=1 border=0></TD>
</TR>
<TR>
<TD width=1 bgColor=#000000><IMG height=1 src="space.gif" width=1 border=0></TD>
<TD vAlign=top>
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="2" WIDTH="100%">
<TR>
<TD class="tableheader" COLSPAN=5>Accommodation Available</TD>
</TR>
<TR>
<TD class="formheader">Hotel</TD>
<TD class="formheader" ALIGN="CENTER">Date Available</TD>
<TD class="formheader" ALIGN="CENTER">Rooms Available</TD>
</TR>
<%
OpenQuery("SELECT * FROM qryRoomsAvailableTotal WHERE Remaining > 0")
strPreviousHotel = ""
strClass = "forminput"
Do While Not EndOfQuery
If GetFieldValue("HotelName") <> strPreviousHotel Then
If strClass = "forminput" Then strClass = "forminput2" Else strClass = "forminput"
End If
strPreviousHotel = GetFieldValue("HotelName")
%>
<TR>
<TD class="<%=strClass%>" NOWRAP><%=GetFieldValue("HotelName")%></TD>
<TD class="<%=strClass%>" ALIGN="CENTER"><%=GetFieldValue("DateAvailable")%></TD>
<TD class="<%=strClass%>" ALIGN="CENTER"><%=GetFieldValue("Remaining")%></TD>
</TR>
<%
NextQueryRecord
Loop
%>
</TABLE>
</TD>
<TD width=1 bgColor=#000000><IMG height=1 src="space.gif" width=1 border=0></TD>
</TR>
<TR>
<TD bgColor=#000000 colSpan=3><IMG height=1 src="space.gif" width=1 border=0></TD>
</TR>
</TBODY>
</TABLE>
<%
CloseQuery
End Sub
Sub ShowPersonalDetails
%>
<TABLE border=0 cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<TD bgColor=#000000 colSpan=3><IMG height=1 src="space.gif" width=1 border=0></TD>
</TR>
<TR>
<TD width=1 bgColor=#000000><IMG height=1 src="space.gif" width=1 border=0></TD>
<TD vAlign=top>
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="2" WIDTH="100%">
<TR>
<TD class="tableheader" COLSPAN=2>Personal Details</TD>
</TR>
<TR>
<TD class="forminput" width="%">Title</TD>
<TD class="forminput" width="100%"><b><%=strTitle%></b></TD>
</TR>
<TR>
<TD class="forminput">First Name</TD>
<TD class="forminput"><b><%=strFirstName%></b></TD>
</TR>
<TR>
<TD class="forminput">Surname</TD>
<TD class="forminput"><b><%=strSurname%></b></TD>
</TR>
<TR>
<TD class="forminput"><%=Application("OrganisationLabel")%></TD>
<TD class="forminput"><b><%=strOrganisation%></b></TD>
</TR>
<%If Application("AddressEnabled") Then%>
<TR>
<TD class="forminput">Address1</TD>
<TD class="forminput"><b><%=strAddress1%></b></TD>
</TR>
<TR>
<TD class="forminput">Address2</TD>
<TD class="forminput"><b><%=strAddress2%></b></TD>
</TR>
<TR>
<TD class="forminput">Address3</TD>
<TD class="forminput"><b><%=strAddress3%></b></TD>
</TR>
<TR>
<TD class="forminput">Address4</TD>
<TD class="forminput"><b><%=strAddress4%></b></TD>
</TR>
<TR>
<TD class="forminput">Postcode/Zip</TD>
<TD class="forminput"><b><%=strPostcode%></b></TD>
</TR>
<TR>
<TD class="forminput">Country</TD>
<TD class="forminput"><b><%=strCountry%></b></TD>
</TR>
<%End If%>
<TR>
<TD class="forminput">Telephone</TD>
<TD class="forminput"><b><%=strTelephone%></b></TD>
</TR>
<TR>
<TD class="forminput">Mobile</TD>
<TD class="forminput"><b><%=strMobile%></b></TD>
</TR>
<TR>
<TD class="forminput">Email</TD>
<TD class="forminput"><b><%=strEmail%></b></TD>
</TR>
</TABLE>
</TD>
<TD width=1 bgColor=#000000><IMG height=1 src="space.gif" width=1 border=0></TD>
</TR>
<TR>
<TD bgColor=#000000 colSpan=3><IMG height=1 src="space.gif" width=1 border=0></TD>
</TR>
</TBODY>
</TABLE>
<%
End Sub
' (SS,31/8/11) removed Non Smoking tick box as requested by Ruth
Sub ShowAccommodationDetails
Dim i
%>
<TABLE border=0 cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<TD bgColor=#000000 colSpan=3><IMG height=1 src="space.gif" width=1 border=0></TD>
</TR>
<TR>
<TD width=1 bgColor=#000000><IMG height=1 src="space.gif" width=1 border=0></TD>
<TD vAlign=top>
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="2" WIDTH="100%">
<TR>
<TD class="tableheader" COLSPAN="7">Accommodation Details</TD>
</TR>
<TR>
<TD class="forminput" align="center">Hotel</TD>
<TD class="forminput" COLSPAN="6"><b><%=GetHotelNameForID(strHotelID)%></b></TD>
</TR>
<TR>
<TD class="forminput" align="center">Full Name</TD>
<TD class="forminput" align="center">Arrival Date</TD>
<TD class="forminput" align="center">No. of Nights</TD>
<TD class="forminput" align="center">Room Type</TD>
<TD class="forminput" align="center">Name of person sharing</TD>
<!--<TD class="forminput" align="center">Non-smoking Preferred</TD>-->
<TD class="forminput" align="center">Special Requirements</TD>
</TR>
<%
' (SS,29/4/15) replaced strFullName(i) with strFirstNameArray(i) and strSurnameArray(i), also added title
' (SS,5/11/15) added GetRoomTypeNameForID to get room type name, it was showing ID, due to it being normalised when moved to MySQL
For i = 1 To MAX_ROOMS
If strFirstNameArray(i) <> "" And strSurnameArray(i) <> "" Then
%>
<TR>
<TD class="forminput" align="center" nowrap><b><%=Trim(strTitleArray(i) & " " & Trim(strFirstNameArray(i) & " " & strSurnameArray(i)))%></b></TD>
<TD class="forminput" align="center"><b><%=strArrivalDate(i)%></b></TD>
<TD class="forminput" align="center"><b><%=strNoOfNights(i)%></b></TD>
<TD class="forminput" align="center"><b><%=GetRoomTypeNameForID(strRoomType(i))%></b></TD>
<TD class="forminput" align="center"><b><%=strSharingWith(i)%></b></TD>
<!--<TD class="forminput" align="center"><b><%=strNonSmoking(i)%></b></TD>-->
<TD class="forminput" align="center"><b><%=strSpecialReq(i)%></b></TD>
</TR>
<%
End If
Next
%>
</TABLE>
</TD>
<TD width=1 bgColor=#000000><IMG height=1 src="space.gif" width=1 border=0></TD>
</TR>
<TR>
<TD bgColor=#000000 colSpan=3><IMG height=1 src="space.gif" width=1 border=0></TD>
</TR>
</TBODY>
</TABLE>
<%
End Sub
Function AddBooking
DeleteBookingFlag
AddBooking = False
OpenTable("Bookings")
AddRecord
PutFieldValue "BookingDate", Now()
PutFieldValue "Title", strTitle
PutFieldValue "FirstName", strFirstName
PutFieldValue "Surname", strSurname
PutFieldValue "Organisation", strOrganisation
PutFieldValue "Address1", strAddress1
PutFieldValue "Address2", strAddress2
PutFieldValue "Address3", strAddress3
PutFieldValue "Address4", strAddress4
PutFieldValue "Postcode", strPostcode
PutFieldValue "Country", strCountry
PutFieldValue "Telephone", strTelephone
PutFieldValue "Mobile", strMobile
PutFieldValue "Email", strEmail
PutFieldValue "HotelID", strHotelID ' (SS,6/12/14) replaced Hotel with HotelID and strHotelName with strHotelID
PutFieldValue "CreditCardType", strCreditCardType
PutFieldValue "CreditCardOther", strCreditCardOther
PutFieldValue "NameOnCard", strCreditCardName
' PutFieldValue "CreditCardNo", strCreditCardNo
PutFieldValue "ExpiryMonth", strExpiryMonth
PutFieldValue "ExpiryYear", strExpiryYear
PutFieldValue "AmountToCharge", dblTotalCost
PostRecord
' (SS,3/12/14) save the credit card number, encrypted
' ExecuteQuery "UPDATE bookings SET CreditCardNo = HEX(AES_ENCRYPT('" & CleanSQLStr(strCreditCardNo) & "', CONCAT('" & CleanSQLStr(ENCRYPTION_PASSWORD) & "', BookingNo))) WHERE BookingNo = " & GetSQLLastInsertID
ExecuteQuery "UPDATE bookings SET " & GetSQLCreditCardNoEncrypt(strCreditCardNo) & " WHERE BookingNo = " & GetSQLLastInsertID
If gsADOErrors <> "" Then
Response.Write("<Strong><B>Following error occurred while booking Personal: " & gsADOErrors & "</Strong></B>" & "<P></P>")
End If
' get the booking number for next stage
intBookingNo = GetSQLLastInsertID ' (SS,x/12/14)
CloseTable
' if no error then continue '
If gsADOErrors = "" Then
' add the booking room records '
OpenTable("BookingRooms")
For i = 1 To MAX_ROOMS
' (SS,29/4/15) replaced strFullName(i) with strFirstNameArray(i) and strSurnameArray(i)
If strFirstNameArray(i) <> "" And strSurnameArray(i) <> "" Then
AddRecord
PutFieldValue "BookingNo", intBookingNo
PutFieldValue "RoomNo", i
' (SS,29/4/15) replaced FullName with Title, FirstName, Surname
PutFieldValue "Title", strTitleArray(i)
PutFieldValue "FirstName", strFirstNameArray(i)
PutFieldValue "Surname", strSurnameArray(i)
PutFieldValue "ArrivalDate", strArrivalDate(i)
PutFieldValue "NoOfNights", strNoOfNights(i)
PutFieldValue "RoomTypeID", strRoomType(i) ' (SS,7/12/14) was RoomType
If strNonSmoking(i) = "Yes" Then
PutFieldValue "NonSmoking", True
Else
PutFieldValue "NonSmoking", False
End If
PutFieldValue "SharingWith", strSharingWith(i)
PutFieldValue "SpecialRequirements", strSpecialReq(i)
PostRecord
If gsADOErrors <> "" Then
Response.Write("<Strong><B>Following error occurred while booking Accommodation: " & gsADOErrors & "</Strong></B>" & "<P></P>")
Exit For
End If
End If
Next
CloseTable
' if no error then continue '
If gsADOErrors = "" Then
' make the temp booking room night records permanent by adding to BookingNights (only the ones from this session)
' (SS,29/11/14) added `` to Date for MySQL
' (SS,6/12/14) replaced HotelName with HotelID and RoomType with RoomTypeID
strSQL = "INSERT INTO BookingNights ( BookingNo, RoomNo, `Date`, HotelID, RoomTypeID ) " _
& "SELECT " & intBookingNo & " AS BookingNo, RoomNo, `Date`, HotelID, RoomTypeID " _
& "FROM BookingNightsTemp WHERE SessionID = " & Session.SessionID
ExecuteQuery(strSQL)
If gsADOErrors <> "" Then
Response.Write("<Strong><B>Following error occurred while booking Accommodation: " & gsADOErrors & "</Strong></B>" & "<P></P>")
End If
' if no error then continue '
If gsADOErrors = "" Then
AddBooking = True ' booking successful '
' Delete existing temp room records '
ExecuteQuery("DELETE FROM BookingNightsTemp WHERE SessionID = " & Session.SessionID)
If gsADOErrors <> "" Then
Response.Write("<Strong><B>Following error occurred while confirming: " & gsADOErrors & "</Strong></B>" & "<P></P>")
End If
End If
End If
End If
End Function
Sub EmailAvailabilityWarning
Dim strBody, strFont, nRemaining, blnDoEmail, LAvailabilityWarningThreshold
' (SS,5/11/15)
LAvailabilityWarningThreshold = CInt(GetSetting("AvailabilityWarningThreshold"))
' check if any are below or equal to zero '
' OpenQuery("SELECT * FROM qryRoomsAvailableWarning WHERE Remaining <= 0")
' (SS,5/11/15) replaced above with following to send warning when it falls below threshold set in settings
OpenQuery("SELECT * FROM qryRoomsAvailableWarning WHERE Remaining <= " & LAvailabilityWarningThreshold)
blnDoEmail = Not EndOfQuery
CloseQuery
If blnDoEmail Then
' (SS,30/11/15) removed font face, causing issues due to size of email created, also </font> from end of appropriate lines
' strFont = "<FONT FACE=""Verdana,Arial,Helvetica"" SIZE=""1"" COLOR=""#000000"">"
strFont = ""
OpenQuery("SELECT * FROM qryRoomsAvailable")
strBody = "<table BORDER=""0"" CELLSPACING=""1"" CELLPADDING=""2"" WIDTH=""100%""><tr bgcolor=""#c2cfdf"">"
strBody = strBody + "<td>" + strFont + "Hotel Name</font></td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont + "Date Available</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont + "Room Type</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont + "Room Cost</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont + "Max Available</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont + "Taken</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont + "Remaining</td>"
strBody = strBody + "</tr>"
Do While Not EndOfQuery
strBody = strBody + "<tr bgcolor=""#dfe6ef"">"
strBody = strBody + "<td NOWRAP>" + strFont & GetFieldValue("HotelName") & "</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont & GetFieldValue("DateAvailable") & "</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont & GetFieldValue("RoomType") & "</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont & GetFieldValue("RoomCost") & "</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont & GetFieldValue("MaxAvailable") & "</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont & GetFieldValue("Taken") & "</td>"
strBody = strBody + "<td ALIGN=""CENTER"">" + strFont
nRemaining = GetFieldValue("Remaining")
If nRemaining <= LAvailabilityWarningThreshold Then ' (SS,5/11/15) replaced 0 with LAvailabilityWarningThreshold
strBody = strBody + "<FONT COLOR = ""red"">" &GetFieldValue("Remaining") & "</font></td>"
Else
strBody = strBody + "<FONT COLOR = ""black"">" &GetFieldValue("Remaining") & "</font></td>"
End If
strBody = strBody + "</tr>"
NextQueryRecord
Loop
strBody = strBody + "</table>"
CloseQuery
' send the email using Dundas Mailer Control
Dim objEmail 'Mailer control
Set objEmail = Server.CreateObject("Dundas.Mailer")
objEmail.SMTPRelayServers.Add "mail.itpartnership.com"
'set Mailer control properties and collection items
' (SS,5/12/14) replaced fixed email addresses with Application
objEmail.TOs.Add Application("BCCEmailAddress1")
if Application("BCCEmailAddress2") <> "" Then objEmail.BCCs.Add Application("BCCEmailAddress2")
objEmail.FromAddress = Application("FromEmailAddress")
objEmail.Subject = Application("ConferenceName") + " Availability Warning"
objEmail.Body = Mid(strBody, 1, 32767) ' (SS,2/12/04) to avoid Message body too big. Maximum size 32768 characters
objEmail.HTMLBody = "<html><head></head><body>" & Mid(strBody, 1, 32700) & "</body></html>"
objEmail.SendMail
'you can test for the success/failure of the operation by examining VBScript's Err object here
Set objEmail = Nothing
End If
End Sub
Sub CreateBookingNightTempRecords
' Delete existing temp room records '
ExecuteQuery("DELETE FROM BookingNightsTemp WHERE SessionID = " & Session.SessionID)
If gsADOErrors <> "" Then
Response.Write("<Strong><B>Following error occurred while confirming: " & gsADOErrors & "</Strong></B>" & "<P></P>")
End If
' Add new booking night temp records '
OpenTable("BookingNightsTemp")
For i = 1 To MAX_ROOMS
' If strFullName(i) <> "" Then
' (SS,29/4/15) replaced above with following
If strFirstNameArray(i) <> "" And strSurnameArray(i) <> "" Then
For n = 1 To strNoOfNights(i)
AddRecord
PutFieldValue "SessionID", Session.SessionID
PutFieldValue "RoomNo", i
PutFieldValue "Date", strArrivalDate(i)
PutFieldValue "Date", GetFieldValue("Date") + n - 1 ' add no of nights to date
' PutFieldValue "HotelName", strHotelName
' (SS,6/12/14) replaced above with following
PutFieldValue "HotelID", strHotelID
PutFieldValue "RoomTypeID", strRoomType(i) ' (SS,6/12/14) replaced RoomType with RoomTypeID
PostRecord
If gsADOErrors <> "" Then
Response.Write("<Strong><B>Following error occurred while confirming: " & gsADOErrors & "</Strong></B>" & "<P></P>")
End If
Next
End If
Next
CloseTable
End Sub
Function CheckAvailabilityAndCost
Dim strSQL, dblTotalCost, blnRoomsAvailable
' check availability and determine total cost '
strSQL = "SELECT * FROM qryBookingNightsAvailablePerSession WHERE SessionID = " & Session.SessionID
OpenQuery(strSQL)
If gsADOErrors <> "" Then
Response.Write("<Strong><B>Following error occurred while checking availability: " & gsADOErrors & "</Strong></B>" & "<P></P>")
End If
dblTotalCost = 0
blnRoomsAvailable = True
Do While Not EndOfQuery
If IsNull(GetQueryValue("Remaining")) Then
blnRoomsAvailable = False
End If
If GetQueryValue("Required") > GetQueryValue("Remaining") Then
blnRoomsAvailable = False
End If
If Not IsNull(GetQueryValue("RoomCost")) Then
dblTotalCost = dblTotalCost + GetQueryValue("RoomCost") * GetQueryValue("Required")
End If
NextQueryRecord
Loop
CloseQuery
If blnRoomsAvailable = False Then
CheckAvailabilityAndCost = -1
Else
CheckAvailabilityAndCost = dblTotalCost
End If
End Function
' (SS,5/11/15) to lookup room type name for given RoomTypeID (because it was normalised and showing as number in comfirmation page
Function GetRoomTypeNameForID(ARoomTypeID)
GetRoomTypeNameForID = GetSQLValueAsString("SELECT RoomType FROM l_roomtypes WHERE RoomTypeID = '" & CleanSQLStr(ARoomTypeID) & "'")
End Function
' (SS,28/10/16) check if single hotel, used to not show combo if single hotel, returns true if single hotel, also HotelID of single hotel
Function IsSingleHotel(ByRef AHotelID)
Dim LCount
If GetSQL2Values("SELECT COUNT(*), HotelID FROM qryhotelsavailable WHERE ShowOnWeb = 'Yes'", LCount, AHotelID) Then
IsSingleHotel = CLng(LCount = 1)
Else
IsSingleHotel = False
End If
End Function
%>