HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/web/secure/csl/bam/admin/apputils.asp
<%

' (SS,3/8/07) Modified EditBooking and SaveBooking to allow AmountToCharge to be editable, because it can go wrong when
' booking is modified manually before Hotel Room records added
' (SS,04/04/13) added function CurrencyAmount(AAmount) and replaced references to GBP with called to CurrencyAmount


Sub ListBookings

  'Dim strSearchBy
  'strSearchField = Request.QueryString("Field")
  gsFocusForm = ""
  gsFocusField = ""


  strHeading = "List of Bookings"

  ' (SS,7/12/14) added join to hotels to lookup hotel name because bookings now holds the Hotel ID instead of Hotel Name
  strSQL = "SELECT * FROM bookings LEFT JOIN hotels ON hotels.HotelID = bookings.HotelID ORDER BY BookingNo"

  OpenQuery(strSQL)
  i = 0

%>
<P>
<strong><%=strHeading%></strong>
</P>

<%


  If EndOfQuery then
    Response.Write("<p>No data found</p>")
  Else

  ' (SS,6/2/02) added strCommand <> "View" so table is only shown if more than one record found
    If strCommand <> "View" Then ' ie. more than one record found
      Dim blnRow1

      blnRow1 = False

  %>
  <TABLE cellspacing="0" cellpadding="2" border="1" COLS=4>
  <TR class=row2>
  <TH ALIGN=LEFT><strong>Booking No</strong></TH>
  <TH ALIGN=LEFT><strong>Title</strong></TH>
  <TH ALIGN=LEFT><strong>First Name</strong></TH>
  <TH ALIGN=LEFT><strong>Surname</strong></TH>
  <TH ALIGN=LEFT><strong>Postcode</strong></TH>
  <TH ALIGN=LEFT><strong>Email</strong></TH>
  <TH ALIGN=LEFT><strong>Hotel</strong></TH>
  </TR>
  <%

      Do While Not EndOfQuery
        blnRow1 = not blnRow1

  %>

  <TR class=<% If blnRow1 then Response.Write("row1") Else Response.Write("row2")%>>
  <td align="center" height="20" nowrap><a href=update.asp?cmd=View&BookingNo=<%=Server.URLEncode(GetQueryValue("BookingNo"))%>><%=GetQueryValue("BookingNo")%></a></td>
  <td><%=GetQueryValue("Title")%>&nbsp;</td>
  <td><%=GetQueryValue("FirstName")%>&nbsp;</td>
  <td><%=GetQueryValue("Surname")%>&nbsp;</td>
  <td><%=GetQueryValue("Postcode")%>&nbsp;</td>
  <td><%=GetQueryValue("Email")%>&nbsp;</td>
  <td><%=GetQueryValue("HotelName")%>&nbsp;</td>
  </tr>

  <%

        NextQueryRecord
      Loop

  %>
  </table>
  <%
    End If

  End If
  CloseQuery
' --- END OF SEARCH FOR ---
End Sub

Sub ViewBooking

' --- VIEW ---
%>
<BR>
<form name="frmUpdate" action="update.asp" method="post">
<%

' (SS,7/12/14) added join to hotels to lookup hotel name because bookings now holds the Hotel ID instead of Hotel Name, also added CleanSQLStr
strSQL = "SELECT * FROM Bookings LEFT JOIN hotels ON hotels.HotelID = bookings.HotelID WHERE BookingNo = '" & CleanSQLStr(strBookingNo) & "'"

OpenQuery(strSQL)
If EndOfQuery Then
  Response.Write("<p>No data found</p>")
  Response.Write("</form>")
Else

%>

<TABLE border=0 cellpadding="0" cellspacing="0" width="310">
<TR>
<TD width="1%" nowrap><strong><H4>Booking No <%=strBookingNo%>&nbsp;&nbsp;</H4></strong></TD>
</TR>
<TR>
<TD colspan="2">
    <input type="hidden" name="cmd" value="">
    <input type="hidden" name="BookingNo" value="<%=GetQueryValue("BookingNo")%>">
    <input type="image" border="0" src="edit.gif" onclick="frmUpdate.cmd.value='Edit'">&nbsp;
    <input type="image" border="0" src="back.gif" onclick="frmUpdate.cmd.value='Back'">&nbsp;
    <input type="image" border="0" src="email.gif" onclick="frmUpdate.cmd.value='Email Booking'">&nbsp;
    <input type="image" border="0" src="email-conf.gif" onclick="frmUpdate.cmd.value='Email Confirmation'">
<TABLE cellspacing="0" cellpadding="2" border="1" COLS=4 width=320>
  <tr height=22>
    <td>Booking No</td>
    <td colspan=3><%=GetQueryValue("BookingNo")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Booking Date</td>
    <td colspan=3><%=GetQueryValue("BookingDate")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Title</td>
    <td colspan=3><%=GetQueryValue("Title")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>First Name</td>
    <td colspan=3><%=GetQueryValue("FirstName")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Surname</td>
    <td colspan=3><%=GetQueryValue("Surname")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Organisation</td>
    <td colspan=3><%=GetQueryValue("Organisation")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Address 1</td>
    <td colspan=3><%=GetQueryValue("Address1")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Address 2</td>
    <td colspan=3><%=GetQueryValue("Address2")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Address 3</td>
    <td colspan=3><%=GetQueryValue("Address3")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Address 4</td>
    <td colspan=3><%=GetQueryValue("Address4")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Postcode</td>
    <td colspan=3><%=GetQueryValue("Postcode")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Country</td>
    <td colspan=3><%=GetQueryValue("Country")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Telephone</td>
    <td colspan=3><%=GetQueryValue("Telephone")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Mobile</td>
    <td colspan=3><%=GetQueryValue("Mobile")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Email</td>
    <td colspan=3><%=GetQueryValue("Email")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Hotel</td>
    <td colspan=3><%=GetQueryValue("HotelName")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Amount To Charge</td>
    <td colspan=3><%=GetQueryValue("AmountToCharge")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Last Changed</td>
    <td colspan=3><%=GetQueryValue("LastChange")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Cancelled</td>
    <td colspan=3><%=GetQueryValue("Cancelled")%>&nbsp;</td>
  </tr>
  <tr height=22>
    <td nowrap>Date Cancelled</td>
    <td colspan=3><%=GetQueryValue("DateCancelled")%>&nbsp;</td>
  </tr>


</table>

</table>
</td>
</tr>

</form>
<%

CloseQuery


Dim blnRow1

ShowBookingRooms "Normal"



End If
%>



<p>&nbsp;</p>
<%

' --- END OF VIEW ---
End Sub


' AType = "Normal" or "InEdit"
Sub ShowBookingRooms(AType)
  Dim blnRow1

' (SS,7/12/14) added join to l_room_types to lookup room type
OpenQuery("SELECT * FROM bookingrooms LEFT JOIN l_roomtypes ON l_roomtypes.RoomTypeID = bookingrooms.RoomTypeID WHERE BookingNo = " + strBookingNo + " ORDER BY RoomNo")


If AType = "Normal" Then
%>

<TABLE><TR>
<TD nowrap width=50><strong><h5>Rooms</h5></strong></TD>
<TD width=100 align=right>

<form name="frmBookingRoom" action="update.asp?cmd=AddBookingRoom" method="post">
  <input type="submit" name="cmd" value="Add">
  <input type="hidden" name="BookingNo" value="<%=strBookingNo%>">
  <input type="hidden" name="DetailTable" value="JobOps">
</form>
</TD>
</TR>
</TABLE>

<%
End If

If EndOfQuery then
  Response.Write("<p>No Booking Room Records</p>")
else


blnRow1 = False
' (SS,29/4/15) replaced "Full Name" with Title, First Name and Surname

' (SS,27/10/11) removed non smoking references, i.e.
' <TH ALIGN=LEFT><strong>Non Smoking</strong></TH>
' <td height="22"><.=Iif(GetQueryValue("NonSmoking")=True, "Yes", "No").>&nbsp;</td>
%>
<TABLE cellspacing="0" cellpadding="2" border="1" COLS=4>
<TR class=row2>
<TH ALIGN=LEFT><strong>RoomNo</strong></TH>
<TH ALIGN=LEFT><strong>Title</strong></TH>
<TH ALIGN=LEFT><strong>First Name</strong></TH>
<TH ALIGN=LEFT><strong>Surname</strong></TH>
<TH ALIGN=LEFT><strong>Arrival Date</strong></TH>
<TH ALIGN=LEFT><strong>No Of Nights</strong></TH>
<TH ALIGN=LEFT><strong>Room Type</strong></TH>
<TH ALIGN=LEFT><strong>Sharing With</strong></TH>
<TH ALIGN=LEFT><strong>Special Requirements</strong></TH>
</TR>
<%

' (SS,29/4/15) replaced "Full Name" with Title, First Name and Surname

Do While Not EndOfQuery
  blnRow1 = not blnRow1

%>

<TR class=<% If blnRow1 then Response.Write("row1") Else Response.Write("row2")%>>
<td height="22" align=center><a href=update.asp?cmd=EditBookingRoom&BookingNo=<%=Server.URLEncode(GetQueryValue("BookingNo"))%>&RoomNo=<%=GetQueryValue("RoomNo")%>><%=GetQueryValue("RoomNo")%></a></td>
<td height="22" align=left><%=GetQueryValue("Title")%>&nbsp;</td>
<td height="22" align=left><%=GetQueryValue("FirstName")%>&nbsp;</td>
<td height="22" align=left><%=GetQueryValue("Surname")%>&nbsp;</td>
<td height="22"><%=GetQueryValue("ArrivalDate")%>&nbsp;</td>
<td height="22"><%=GetQueryValue("NoOfNights")%>&nbsp;</td>
<td height="22"><%=GetQueryValue("RoomType")%>&nbsp;</td>
<td height="22"><%=GetQueryValue("SharingWith")%>&nbsp;</td>
<td height="22"><%=GetQueryValue("SpecialRequirements")%>&nbsp;</td>
</tr>

<%
  NextQueryRecord
Loop
%>
</table>
<%
End if
CloseQuery

' --- END OF Show Booking Rooms --- '
End Sub



Sub EditBooking

  Dim strFooter, strOrder

  strFooter = ""
  strOrder = ""

  If strCommand = "Edit" then
    ' get values from database '
    ' (SS,4/12/14) added GetSQLCreditCardNoDecrypt to get decrypted credit card no
    OpenQuery("SELECT *, " & GetSQLCreditCardNoDecrypt & " FROM Bookings WHERE BookingNo = '" & CleanSQLStr(strBookingNo) & "'")
    If Not EndOfQuery then
      strBookingDate = GetQueryValue("BookingDate")
      strTitle = GetQueryValue("Title")
      strFirstName = GetQueryValue("FirstName")
      strSurname = GetQueryValue("Surname")
      strOrganisation = GetQueryValue("Organisation")
      strAddress1 = GetQueryValue("Address1")
      strAddress2 = GetQueryValue("Address2")
      strAddress3 = GetQueryValue("Address3")
      strAddress4 = GetQueryValue("Address4")
      strPostcode = GetQueryValue("Postcode")
      strCountry = GetQueryValue("Country")
      strTelephone = GetQueryValue("Telephone")
      strMobile = GetQueryValue("Mobile")
      strEmail = GetQueryValue("Email")
      strHotel = GetQueryValue("HotelID")  ' (SS,7/12/14) replaced Hotel with HotelID
      strCreditCardType = GetQueryValue("CreditCardType")
      strCreditCardOther = GetQueryValue("CreditCardOther")
      strNameOnCard = GetQueryValue("NameOnCard")
      strCreditCardNo = GetQueryValue("CreditCardNoDecrypted") ' (SS,4/12/14) replaced CreditCardNo with CreditCardNoDecrypted
      strExpiryMonth = GetQueryValue("ExpiryMonth")
      strExpiryYear = GetQueryValue("ExpiryYear")
      strAmountToCharge = GetQueryValue("AmountToCharge")
      strLastChange = GetQueryValue("LastChange")
      strCancelled = GetQueryValue("Cancelled")
      strDateCancelled = GetQueryValue("DateCancelled")
    End If
    CloseQuery
  End if


  ' --- ADD or EDIT --- '
  If strCommand = "Add" Or strCommand = "Edit" Then

  %>
    <strong><br><br>Edit Booking</strong><br>
    <form name="frmEdit" action="update.asp" method="post">
    <table border="0" cellpadding="0" cellspacing="0">


      <tr>
        <td nowrap height="22">Booking No:&nbsp;</td>
        <td colspan="3">
        <%=strBookingNo%>
        <input type="hidden" name="BookingNo" size=20 value="<%=strBookingNo%>">
        <input type="hidden" name="AddOrEdit" value="<%=strCommand%>">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Booking Date/Time:&nbsp;</td>
        <td colspan="3"><%=strBookingDate%>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Title:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Title" value="<%=strTitle%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">First Name:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="FirstName" value="<%=strFirstName%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Surname:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Surname" value="<%=strSurname%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Organisation:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Organisation" value="<%=strOrganisation%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Address 1:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Address1" value="<%=strAddress1%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Address 2:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Address2" value="<%=strAddress2%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Address 3:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Address3" value="<%=strAddress3%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Address 4:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Address4" value="<%=strAddress4%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Postcode:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Postcode" value="<%=strPostcode%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Country:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Country" value="<%=strCountry%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Telephone:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Telephone" value="<%=strTelephone%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Mobile:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Mobile" value="<%=strMobile%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Email:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Email" value="<%=strEmail%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Hotel:&nbsp;</td>
        <td colspan="3">
        <%Response.Write(GetLookupComboDiffFormField("Hotels", "HotelName", "Hotel", "SortOrder", strHotel, "", "HotelID", "")) ' (SS,6/12/14) added "HotelID" %>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Credit Card Type:&nbsp;</td>
        <td colspan="3">
        <%Response.Write(GetLookupComboDiffFormField("L_CreditCardTypes", "CreditCardType", "CreditCardType", "SortOrder", strCreditCardType, "Blank", "", ""))%>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Other Card:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="CreditCardOther" value="<%=strCreditCardOther%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Name On Card:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="NameOnCard" value="<%=strNameOnCard%>" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Credit Card No:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="CreditCardNo" value="<%=strCreditCardNo%>" autocomplete="off" SIZE="30" MAXLENGTH="50">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">ExpiryMonth/Year:&nbsp;</td>
        <td colspan="3">
        <%Response.Write(GetLookupComboDiffFormField("L_CreditCardMonths", "Month", "ExpiryMonth", "", strExpiryMonth, "Blank", "", ""))%>
        <%Response.Write(GetLookupComboDiffFormField("L_CreditCardYears", "Year", "ExpiryYear", "", strExpiryYear, "Blank", "", ""))%>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Amount To Charge:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="AmountToCharge" value="<%=strAmountToCharge%>" SIZE="15" MAXLENGTH="12">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Last Changed Date:&nbsp;</td>
        <td colspan="3">
        <%=strLastChange%>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Cancelled:&nbsp;</td>
        <td colspan="3">
        <%=strCancelled%>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Date Cancelled:&nbsp;</td>
        <td colspan="3">
        <%=strDateCancelled%>
        </td>
      </tr>


      <tr>
        <td>&nbsp;</td>
        <td colspan="3"> <br>
          <input type="submit" name="cmd" value="Save Record">
          &nbsp;&nbsp;&nbsp;&nbsp;
          <input type="submit" name="cmd" value="Exit Form">
          &nbsp;&nbsp;&nbsp;
          <input type="submit" name="cmd" value="Delete Record">
          &nbsp;&nbsp;&nbsp;
          <input type="submit" name="cmd" value="Cancel Booking">
        </td>
      </tr>


    </table>
    <p>&nbsp;</p>

  </form>


  <%
  End If
  ' --- END OF ADD or EDIT --- '
End Sub


Sub SaveBooking
  Dim LNewRecord, strBookingNo

  strBookingNo = Request.Form("BookingNo")

  strTitle = RTrim(Request.Form("Title"))
  strFirstName = RTrim(Request.Form("FirstName"))
  strSurname = RTrim(Request.Form("Surname"))
  strOrganisation = RTrim(Request.Form("Organisation"))
  strAddress1 = RTrim(Request.Form("Address1"))
  strAddress2 = RTrim(Request.Form("Address2"))
  strAddress3 = RTrim(Request.Form("Address3"))
  strAddress4 = RTrim(Request.Form("Address4"))
  strPostcode = RTrim(Request.Form("Postcode"))
  strCountry = RTrim(Request.Form("Country"))
  strTelephone = RTrim(Request.Form("Telephone"))
  strMobile = RTrim(Request.Form("Mobile"))
  strEmail = RTrim(Request.Form("Email"))
  strHotel = RTrim(Request.Form("Hotel"))
  strCreditCardType = RTrim(Request.Form("CreditCardType"))
  strCreditCardOther = RTrim(Request.Form("CreditCardOther"))
  strNameOnCard = RTrim(Request.Form("NameOnCard"))
  strCreditCardNo = RTrim(Request.Form("CreditCardNo"))
  strExpiryMonth = RTrim(Request.Form("ExpiryMonth"))
  strExpiryYear = RTrim(Request.Form("ExpiryYear"))
  strAmountToCharge = RTrim(Request.Form("AmountToCharge")) ' (SS,3/8/07)

  LNewRecord = Request.Form("AddOrEdit") = "Add"

  If LNewRecord Then
    OpenTable("Bookings")
    AddRecord
   ' PutFieldValue "BookingNo", strBookingNo ' only in new record, other related record error will occur ''
    PutFieldValue "BookingDate", Now()
  Else
    OpenTableRecordForEdit "Bookings", "BookingNo=" & strBookingNo
    EditRecord
  End If

  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", strHotel
  PutFieldValue "CreditCardType", strCreditCardType
  PutFieldValue "CreditCardOther", strCreditCardOther
  PutFieldValue "NameOnCard", strNameOnCard
  ' PutFieldValue "CreditCardNo", strCreditCardNo ' (SS,4/12/14) replaced below with UPDATE SQL to saved encrypted version of credit card no
  PutFieldValue "ExpiryMonth", strExpiryMonth
  PutFieldValue "ExpiryYear", strExpiryYear
  PutFieldValue "AmountToCharge", strAmountToCharge ' (SS,3/8/07)
  PutFieldValue "LastChange", Now

  PostRecord
  If gsADOErrors = "" Then
    If LNewRecord Then
      Response.Write("<p><strong>New record added</strong></p>")
    Else
      Response.Write("<p><strong>Record saved</strong></p>")
    End If
  Else
    Response.Write("<p><strong>" + gsADOErrors + "</strong></p>")
  End If

  CloseTable
  
  ' (SS,3/12/14) save the credit card number, encrypted
  ExecuteQuery "UPDATE bookings SET " & GetSQLCreditCardNoEncrypt(strCreditCardNo) & " WHERE BookingNo = '" & CleanSQLStr(strBookingNo) & "'"

  UpdateHotelForBookingNights strBookingNo, strHotel

End Sub


Sub DeleteBooking
  ExecuteQuery("DELETE FROM Bookings WHERE BookingNo = " + strBookingNo)

  If gsADOErrors = "" Then
    Response.Write("<p><strong>Record deleted</strong></p>")
  Else
    Response.Write("<p><strong>" + gsADOErrors + "</strong></p>")
  End If
End Sub


' (SS,9/5/03) '
Sub CancelBooking

  Dim LCancelled

  OpenQuery("SELECT * FROM Bookings WHERE BookingNo = " & strBookingNo)
  LCancelled = GetQueryValue("Cancelled")
  CloseQuery

  If LCancelled Then
    Response.Write("<p><strong>Booking " & strBookingNo & " has already been cancelled.</strong></p>")
  Else


    ' delete booking records for this booking and room no '
    ExecuteQuery("DELETE FROM BookingNights WHERE BookingNo=" & strBookingNo)
    If gsADOErrors <> "" Then Response.Write("<p><strong>" + gsADOErrors + "</strong></p>")

    ' delete booking room records '
    ExecuteQuery("DELETE FROM BookingRooms WHERE BookingNo=" & strBookingNo)
    If gsADOErrors <> "" Then Response.Write("<p><strong>" + gsADOErrors + "</strong></p>")

    ' set the new values in AmountToCharge, DateLastChanged, Cancelled, DateCancelled '
    ExecuteQuery("UPDATE Bookings SET AmountToCharge = 0, LastChange=NOW(), Cancelled = True, DateCancelled = NOW() WHERE (((BookingNo)=" & strBookingNo & "))")
    If gsADOErrors <> "" Then Response.Write("<p><strong>" + gsADOErrors + "</strong></p>")

    Response.Write("<p><strong>Booking " & strBookingNo & " has been cancelled.</strong></p>")
  End If

  strCommand = "View"

End Sub

' (SS,3/12/15) field SpecialRequirements, changed maxlength from 50 to 100 (field itself is now VARCHAR(200) so can be increased to 200)
Sub EditBookingRoom
  Dim strRoomNo

  strRoomNo = Request.QueryString("RoomNo")
  If strRoomNo = "" Then strRoomNo = Request.Form("RoomNo")

  strBookingNo = Request.Form("BookingNo")
  If strBookingNo = "" Then strBookingNo = Request.QueryString("BookingNo")

  'strFullName = ""
  ' (SS,29/4/15) replaced above with following
  strTitle = ""
  strFirstName = ""
  strSurname = ""
  
  strArrivalDate = ""
  strNoOfNights = ""
  strRoomType = ""
  strNonSmoking = ""
  strSharingWith = ""
  strSpecialRequirements = ""

  gsFocusForm = "frmEdit"
  gsFocusField = "FullName"


  If strCommand = "Edit" then
    ' get values from database '
    OpenQuery("SELECT * FROM BookingRooms WHERE BookingNo = " + strBookingNo + " AND RoomNo = " + strRoomNo)
    If Not EndOfQuery then
      'strFullName = GetQueryValue("FullName")
      ' (SS,29/4/15) replaced above with following
      strTitle = GetQueryValue("Title")
      strFirstName = GetQueryValue("FirstName")
      strSurname = GetQueryValue("Surname")
      
      strArrivalDate = GetQueryValue("ArrivalDate")
      strNoOfNights = GetQueryValue("NoOfNights")
      strRoomType = GetQueryValue("RoomTypeID") ' (SS,7/12/14) replaced RoomType with RoomTypeID
      strNonSmoking = GetQueryValue("NonSmoking")
      If strNonSmoking = "True" Then strNonSmoking = "Yes" Else strNonSmoking = "No"
      strSharingWith = GetQueryValue("SharingWith")
      strSpecialRequirements = GetQueryValue("SpecialRequirements")
    End If
    CloseQuery
  End if


  ' --- ADD or EDIT --- '
  ' (SS,29/4/15) replaced FullName with Title, FirstName and Surname
  If strCommand = "Add" Or strCommand = "Edit" Then
    
    ' (SS,27/10/11) removed non smoking
    '<tr>
    '<td nowrap height="22">Non Smoking:&nbsp;</td>
    '<td colspan="3">
    '<.Response.Write(GetYesNoCombo("NonSmoking", strNonSmoking)).>
    '</td>
    '</tr>
    
  %>
    <strong><br><br>Edit Result</strong><br>
    <form name="frmEdit" action="update.asp" method="post" autocomplete="off">
    <table border="0" cellpadding="0" cellspacing="0">

      <tr>
        <td nowrap height="22">Booking No:&nbsp;</td>
        <td colspan="3">
          <font size="2" face="Arial"><b><%=strBookingNo%></b></font>
          <input type="hidden" name="AddOrEdit" value="<%=strCommand%>">
          <input type="hidden" name="DetailTable" value="BookingRooms">
          <input type="hidden" name="RoomNo" value="<%=strRoomNo%>">
          <input type="hidden" name="BookingNo" value="<%=strBookingNo%>">
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Room No:&nbsp;</td>
        <td colspan="3">
          <font size="2" face="Arial"><b><%=strRoomNo%></b></font>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Title:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Title" size=10 value="<%=strTitle%>" maxlength="50">
        </td>
      </tr>
      <tr>
        <td nowrap height="22">First Name:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="FirstName" size=20 value="<%=strFirstName%>" maxlength="50">
        </td>
      </tr>
      <tr>
        <td nowrap height="22">Full Name:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="Surname" size=20 value="<%=strSurname%>" maxlength="50">
        </td>
      </tr>      

      <tr>
        <td nowrap height="22">Arrival Date:&nbsp;</td>
        <td colspan="3">
        <%Response.Write(GetLookupComboDiffFormField("L_ArrivalDates", "ArrivalDate", "ArrivalDate", "ArrivalDate", strArrivalDate, "", "", ""))%>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">No of Nights:&nbsp;</td>
        <td colspan="3">
        <%Response.Write(GetLookupComboDiffFormField("L_NoOfNights", "NoOfNights", "NoOfNights", "NoOfNights", strNoOfNights, "", "", ""))%>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Room Type:&nbsp;</td>
        <td colspan="3">
        <%Response.Write(GetLookupComboDiffFormField("L_RoomTypes", "RoomType", "RoomType", "SortOrder", strRoomType, "", "RoomTypeID", ""))%>
        </td>
      </tr>

      <tr>
        <td nowrap height="22">Sharing With:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="SharingWith" size=30 value="<%=strSharingWith%>" maxlength="50">
        </td>
      </tr>


      <tr>
        <td nowrap height="22">Special Requirements:&nbsp;</td>
        <td colspan="3">
        <input type="text" name="SpecialRequirements" size=30 value="<%=strSpecialRequirements%>" maxlength="100">
        </td>
      </tr>

      <tr>
        <td>&nbsp;</td>
        <td colspan="3"> <br>
          <input type="submit" name="cmd" value="Save Record">
          &nbsp;&nbsp;&nbsp;&nbsp;
          <input type="submit" name="cmd" value="Exit Form">
          &nbsp;&nbsp;&nbsp;
          <input type="submit" name="cmd" value="Delete Record">
        </td>
      </tr>

    </table>
    <p>&nbsp;</p>

  </form>


  <%
  End If
  ' --- END OF ADD or EDIT --- '

End Sub

' (SS,29/4/15) replaced FullName with Title, FirstName and Surname
Sub SaveBookingRoom
  Dim LNewRecord, strRoomNo, strBookingNo

  strRoomNo = Request.Form("RoomNo")
  strBookingNo = Request.Form("BookingNo")

  strTitle = ""
  strFirstName = ""
  strSurname = ""
  strArrivalDate = ""
  strNoOfNights = ""
  strRoomType = ""
  strNonSmoking = ""
  strSharingWith = ""
  strSpecialRequirements = ""

  strTitle = RTrim(Request.Form("Title"))
  strFirstName = RTrim(Request.Form("FirstName"))
  strSurname = RTrim(Request.Form("Surname"))
  strArrivalDate = RTrim(Request.Form("ArrivalDate"))
  strNoOfNights = RTrim(Request.Form("NoOfNights"))
  strRoomType = RTrim(Request.Form("RoomType"))
  strNonSmoking = RTrim(Request.Form("NonSmoking"))
  strSharingWith = RTrim(Request.Form("SharingWith"))
  strSpecialRequirements = RTrim(Request.Form("SpecialRequirements"))

  LNewRecord = Request.Form("AddOrEdit") = "Add"

  If LNewRecord Then

    ' find next available room no here '
    strRoomNo = GetNextRoomNo(strBookingNo)

    OpenTable("BookingRooms")
    AddRecord
    Response.Write("<p><strong>New record added</strong></p>")

    PutFieldValue "BookingNo", strBookingNo
    PutFieldValue "RoomNo", strRoomNo
  Else
    OpenTableRecordForEdit "BookingRooms", "BookingNo=" & strBookingNo & " AND RoomNo=" & strRoomNo
    EditRecord
    Response.Write("<p><strong>Record saved</strong></p>")
  End If

  PutFieldValue "Title", strTitle
  PutFieldValue "FirstName", strFirstName
  PutFieldValue "Surname", strSurname
  PutFieldValue "ArrivalDate", strArrivalDate
  PutFieldValue "NoOfNights", strNoOfNights
  PutFieldValue "RoomTypeID", strRoomType ' (SS,7/12/14) replaced RoomType with RoomTypeID
  If strNonSmoking = "Yes" Then
    PutFieldValue "NonSmoking", True
  Else
    PutFieldValue "NonSmoking", False
  End If
  PutFieldValue "SharingWith", strSharingWith
  PutFieldValue "SpecialRequirements", strSpecialRequirements

  PostRecord
  If gsADOErrors <> "" Then Response.Write(gsADOErrors)

  CloseTable

  ' recreate booking night records because they may have changed for this room '
  RecreateBookingNightRecords strBookingNo, strRoomNo

  RecalculateBookingCost strBookingNo

  ' make sure cancelled flag is set to false and date cancelled cleared
  ' set the new values in AmountToCharge, DateLastChanged, Cancelled, DateCancelled '
  ExecuteQuery("UPDATE bookings SET Cancelled = False, DateCancelled = Null WHERE BookingNo = '" & CleanSQLStr(strBookingNo) & "'")
  If gsADOErrors <> "" Then Response.Write("<p><strong>" + gsADOErrors + "</strong></p>")

End Sub


Function GetNextRoomNo(ABookingNo)
  Dim sSQL, vMaxRoomNo
  GetNextRoomNo = 0
  sSQL = "SELECT Max(RoomNo) AS MaxRoomNo FROM BookingRooms WHERE (((BookingNo)=" + ABookingNo + "))"
  OpenQuery(sSQL)

  vMaxRoomNo = GetQueryValue("MaxRoomNo")
  CloseQuery
  If IsNull(vMaxRoomNo) Then
    GetNextRoomNo = 1
  Else
    GetNextRoomNo = vMaxRoomNo + 1
  End If

End Function

' (SS,7/10/14) replaced HotelName with HotelID
Sub RecreateBookingNightRecords(ABookingNo, ARoomNo)
  Dim i, sSQL, nNoOfNights, dArrivalDate, strHotelID, strRoomTypeID

  ' delete existing booking night records for this booking and room no '
  ExecuteQuery("DELETE FROM bookingnights WHERE BookingNo = '" & CleanSQLStr(ABookingNo) & "' AND RoomNo = '" & CleanSQLStr(ARoomNo) & "'")

  ' get hotel name '
  OpenQuery("SELECT * FROM bookings WHERE BookingNo = '" & CleanSQLStr(ABookingNo) & "'")
  strHotelID = GetQueryValue("HotelID") ' (SS,7/12/14) replaced Hotel with HotelID
  CloseQuery

  ' get no of nights, arrival, room type
  OpenQuery("SELECT * FROM bookingrooms WHERE BookingNo = '" & CleanSQLStr(ABookingNo) & "' AND RoomNo = '" & CleanSQLStr(ARoomNo) & "'")
  nNoOfNights = GetQueryValue("NoOfNights")
  dArrivalDate = GetQueryValue("ArrivalDate")
  strRoomTypeID = GetQueryValue("RoomTypeID") ' (SS,7/12/14) replaced RoomType with RoomTypeID
  CloseQuery

  OpenTable("BookingNights")

  ' create new booking night records '
  For i = 1 To strNoOfNights
    AddRecord
    PutFieldValue "BookingNo", ABookingNo
    PutFieldValue "RoomNo", ARoomNo
    PutFieldValue "Date", dArrivalDate + i - 1
    PutFieldValue "HotelID", strHotelID
    PutFieldValue "RoomTypeID", strRoomTypeID ' (SS,7/12/14) replaced RoomType with RoomTypeID
    PostRecord
  Next

  CloseTable

  ' (SS,3/7/03) added warning if user has booked rooms that are not available
  ' get no of nights, arrival, room type
  OpenQuery("SELECT * FROM qryProblemBookings WHERE BookingNo = '" & CleanSQLStr(ABookingNo) & "'")
  If Not EndOfQuery Then ' EndOfQuery not used because there will always be one record
    Response.Write("<strong><font color=red>There was a problem with booking this room.<br>Please check that rooms exist in Hotel Rooms table and then correct.<br>")
    Response.Write("The total amount shown here will be incorrect.<br>And room will have been booked on nights that don't exist.<br></font></strong>")
  End If
  CloseQuery

End Sub


Sub DeleteBookingRoom
  Dim strRoomNo, strBookingNo

  strRoomNo = Request.Form("RoomNo")
  strBookingNo = Request.Form("BookingNo")

    ' delete booking night records for this booking and room no '
  ExecuteQuery("DELETE FROM BookingNights WHERE BookingNo=" & strBookingNo & " AND RoomNo=" & strRoomNo)

  If gsADOErrors = "" Then
    Response.Write("<p><strong>Record deleted</strong></p>")
  Else
    Response.Write("<p><strong>" + gsADOErrors + "</strong></p>")
  End If

  ' delete main booking record
  ExecuteQuery("DELETE FROM BookingRooms WHERE BookingNo=" & strBookingNo & " AND RoomNo=" & strRoomNo)

  If gsADOErrors <> "" Then
    Response.Write("<p><strong>" + gsADOErrors + "</strong></p>")
  End If

  RecalculateBookingCost strBookingNo

  If gsADOErrors <> "" Then
    Response.Write("<p><strong>" + gsADOErrors + "</strong></p>")
  End If

End Sub


' updates hotel name in booking night table
' (SS,7/12/14) was called UpdateHotelNameForBookingNights, now updates the HotelID
Sub UpdateHotelForBookingNights(ABookingNo, AHotelID)
  ExecuteQuery("UPDATE BookingNights SET HotelID = '" & CleanSQLStr(AHotelID) & "' WHERE BookingNo = '" & CleanSQLStr(ABookingNo) & "'")
End Sub


Sub RecalculateBookingCost(ABookingNo)
  Dim nTotalCost
  OpenQuery("SELECT * FROM qryBookingTotalCost WHERE BookingNo=" & ABookingNo)
  If EndOfQuery Then
    nTotalCost = 0
  Else
    nTotalCost = GetQueryValue("TotalCost")
  End If
  If IsNull(nTotalCost) Then nTotalCost = 0
  CloseQuery

  ExecuteQuery("UPDATE Bookings SET AmountToCharge = " & nTotalCost & ", LastChange=NOW() WHERE (((BookingNo)=" & ABookingNo & "))")

End Sub


' -------------------------------------------
' Start of Custom Grouping Routines
' -------------------------------------------

' called from Sub ShowTableView in editutils.asp

' (SS,28/10/16)
Dim FPrevHotel, FPrevDateAvailable, FTotalMaxAvailable, FTotalTaken, FTotalRemaining

FPrevHotel = ""
FPrevDateAvailable = ""

' (SS,28/10/16) custom hook routine called from editutils.asp to add group totals
Function CustomShowTableViewCurrentRecordHook(ATableName)
  If ATableName <> "qryRoomsAvailable" Then Exit Function
  
  Dim LCurrentHotel, LCurrentDateAvailable
  LCurrentHotel = GetQueryValue("HotelName")
  LCurrentDateAvailable = GetQueryValue("DateAvailable")
  
  If FPrevHotel <> LCurrentHotel Or FPrevDateAvailable <> LCurrentDateAvailable Then
    FTotalMaxAvailable = 0
    FTotalTaken = 0
    FTotalRemaining = 0
  End If
  
  FTotalMaxAvailable = FTotalMaxAvailable + NZL(GetQueryValue("MaxAvailable"))
  FTotalTaken = FTotalTaken + NZL(GetQueryValue("Taken"))
  FTotalRemaining = FTotalRemaining + NZL(GetQueryValue("Remaining"))
  
  FPrevHotel = LCurrentHotel
  FPrevDateAvailable = LCurrentDateAvailable
  
End Function

' (SS,28/10/16) custom hook routine called from editutils.asp to add group totals
Function CustomShowTableViewNextRecordHook(ATableName)
  If ATableName <> "qryRoomsAvailable" Then Exit Function  
 
  ' if add end or change
  If EndOfQuery Then
    CustomShowTableViewGroupFooter(ATableName)
  ElseIf FPrevHotel <> GetQueryValue("HotelName") Or FPrevDateAvailable <> GetQueryValue("DateAvailable") Then
    CustomShowTableViewGroupFooter(ATableName)
  End If 
  
End Function

Function CustomShowTableViewGroupFooter(ATableName)
  If ATableName <> "qryRoomsAvailable" Then Exit Function
  %>
  <tr style="background-color:lemonchiffon"><td>&nbsp;</td><td>Total Rooms</td><td><%=FPrevDateAvailable%></td><td>&nbsp;</td><td>&nbsp;</td><td align="right"><%=FTotalMaxAvailable%></td><td align="right"><%=FTotalTaken%></td><td align="right"><%=FTotalRemaining%></td><td>&nbsp;</td>
  </tr>
  <tr><td colspan="9">&nbsp;</td></tr>
  <%
End Function

' -------------------------------------------
' End of Custom Grouping Routines
' -------------------------------------------

%>