Require bookings to be at least 5 days ahead

Guests could previously book for the same day or tomorrow. The earliest
selectable date is now today + 5 days, configured in one place via the
BOOKING_MIN_LEAD_DAYS constant.

- constants.php: new BOOKING_MIN_LEAD_DAYS define (5)
- Service_model::getAvailableTimes(): optional $minLeadDays param, returns
  no slots for dates closer than that; defaults to 0 so existing callers
  are unaffected
- Pages::ajax(): guest actions (getAvailableTimes, isTimeAvailable) pass the
  constant. The admin action getAvailableTimeOptions deliberately does not,
  so staff can still enter phone bookings for tomorrow.
- Pages::booking_process(): rejects an early booking_date POST and redirects
  back to /booking, guarding against a stale page or a crafted request
- booking-form.php: datepicker minDate/defaultDate and the hidden
  booking_date default all derive from the constant

Deployed and verified on test, dev and prod.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MyYsTAAA1kJLMLCResmgTE
This commit is contained in:
Astral04
2026-08-06 11:01:44 +00:00
co-authored by Claude Opus 5
parent 4e1a69c8d4
commit 69ec9e62a6
4 changed files with 31 additions and 5 deletions
+9 -2
View File
@@ -197,7 +197,7 @@ class Pages extends CI_Controller {
}
if(isset($_POST['action']) && $_POST['action'] == 'isTimeAvailable' && isset($_POST['selectedDate'])){
$results = $this->Service_model->getAvailableTimes($_POST['group_id'], $_POST['selectedDate'], $_POST['servicelength']);
$results = $this->Service_model->getAvailableTimes($_POST['group_id'], $_POST['selectedDate'], $_POST['servicelength'], BOOKING_MIN_LEAD_DAYS);
$timeIsAvailable = 0;
if(is_array($results)){
@@ -215,7 +215,7 @@ class Pages extends CI_Controller {
}
if(isset($_POST['action']) && $_POST['action'] == 'getAvailableTimes' && isset($_POST['selectedDate'])){
$results = $this->Service_model->getAvailableTimes($_POST['group_id'], $_POST['selectedDate'], $_POST['servicelength'].':00');
$results = $this->Service_model->getAvailableTimes($_POST['group_id'], $_POST['selectedDate'], $_POST['servicelength'].':00', BOOKING_MIN_LEAD_DAYS);
$rowIndex = 1;
if(!empty($results)){
@@ -515,6 +515,13 @@ class Pages extends CI_Controller {
if(isset($_POST['sendBooking'])){
//guest bookings must be at least BOOKING_MIN_LEAD_DAYS days ahead
$earliestBookingDate = date('Y-m-d', strtotime('+'.BOOKING_MIN_LEAD_DAYS.' days'));
if(!isset($_POST['booking_date']) || $_POST['booking_date'] < $earliestBookingDate){
header('Location:'.SITEURL.'booking');
exit;
}
//calculate finish time
$serviceStartTime = date("H:i:s", strtotime($_POST['booking_start_time']));
$serviceLengthTime = date("H:i:s", strtotime($_POST['servicelength']));