Updated the booking page so that it works with the new html_vars and script_vars helper functions.
This commit is contained in:
parent
74c48e8a9a
commit
5420ef1389
2 changed files with 119 additions and 72 deletions
|
@ -44,51 +44,27 @@ class Booking extends EA_Controller {
|
||||||
$this->load->library('availability');
|
$this->load->library('availability');
|
||||||
|
|
||||||
$this->load->driver('cache', ['adapter' => 'file']);
|
$this->load->driver('cache', ['adapter' => 'file']);
|
||||||
|
|
||||||
|
$this->preload();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default callback method of the application.
|
* Preload the page config and variables.
|
||||||
*
|
|
||||||
* This method creates the appointment book wizard. If an appointment hash is provided then it means that the
|
|
||||||
* customer followed the appointment manage link that was sent with the book success email.
|
|
||||||
*
|
|
||||||
* @param string $appointment_hash The appointment hash identifier.
|
|
||||||
*/
|
*/
|
||||||
public function index(string $appointment_hash = '')
|
protected function preload()
|
||||||
{
|
{
|
||||||
if ( ! is_app_installed())
|
if ( ! is_callback('booking', 'index') && ! is_callback('booking', 'reschedule'))
|
||||||
{
|
{
|
||||||
redirect('installation');
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$available_services = $this->services_model->get_available_services();
|
$available_services = $this->services_model->get_available_services();
|
||||||
$available_providers = $this->providers_model->get_available_providers();
|
$available_providers = $this->providers_model->get_available_providers();
|
||||||
$company_name = setting('company_name');
|
|
||||||
$book_advance_timeout = setting('book_advance_timeout');
|
|
||||||
$date_format = setting('date_format');
|
|
||||||
$time_format = setting('time_format');
|
|
||||||
$first_weekday = setting('first_weekday');
|
|
||||||
$require_phone_number = setting('require_phone_number');
|
|
||||||
$show_field['phone-number'] = setting('show_phone_number');
|
|
||||||
$show_field['address'] = setting('show_address');
|
|
||||||
$show_field['city'] = setting('show_city');
|
|
||||||
$show_field['zip-code'] = setting('show_zip_code');
|
|
||||||
$show_field['notes'] = setting('show_notes');
|
|
||||||
$display_cookie_notice = setting('display_cookie_notice');
|
|
||||||
$cookie_notice_content = setting('cookie_notice_content');
|
|
||||||
$display_terms_and_conditions = setting('display_terms_and_conditions');
|
|
||||||
$terms_and_conditions_content = setting('terms_and_conditions_content');
|
|
||||||
$display_privacy_policy = setting('display_privacy_policy');
|
|
||||||
$privacy_policy_content = setting('privacy_policy_content');
|
|
||||||
$display_any_provider = setting('display_any_provider');
|
|
||||||
$timezones = $this->timezones->to_array();
|
|
||||||
$grouped_timezones = $this->timezones->to_grouped_array();
|
|
||||||
|
|
||||||
// Remove the data that are not needed inside the $available_providers array.
|
|
||||||
foreach ($available_providers as &$available_provider)
|
foreach ($available_providers as &$available_provider)
|
||||||
{
|
{
|
||||||
|
// Only expose the required provider data.
|
||||||
|
|
||||||
$this->providers_model->only($available_provider, [
|
$this->providers_model->only($available_provider, [
|
||||||
'id',
|
'id',
|
||||||
'first_name',
|
'first_name',
|
||||||
|
@ -98,19 +74,43 @@ class Booking extends EA_Controller {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an appointment hash is provided then it means that the customer is trying to edit a registered appointment
|
$company_name = setting('company_name');
|
||||||
// record.
|
$date_format = setting('date_format');
|
||||||
if ($appointment_hash !== '')
|
$time_format = setting('time_format');
|
||||||
|
$first_weekday = setting('first_weekday');
|
||||||
|
$require_phone_number = setting('require_phone_number');
|
||||||
|
$show_phone_number = setting('show_phone_number');
|
||||||
|
$show_address = setting('show_address');
|
||||||
|
$show_city = setting('show_city');
|
||||||
|
$show_zip_code = setting('show_zip_code');
|
||||||
|
$show_notes = setting('show_notes');
|
||||||
|
$display_cookie_notice = setting('display_cookie_notice');
|
||||||
|
$cookie_notice_content = setting('cookie_notice_content');
|
||||||
|
$display_terms_and_conditions = setting('display_terms_and_conditions');
|
||||||
|
$terms_and_conditions_content = setting('terms_and_conditions_content');
|
||||||
|
$display_privacy_policy = setting('display_privacy_policy');
|
||||||
|
$privacy_policy_content = setting('privacy_policy_content');
|
||||||
|
$display_any_provider = setting('display_any_provider');
|
||||||
|
$book_advance_timeout = setting('book_advance_timeout');
|
||||||
|
|
||||||
|
$timezones = $this->timezones->to_array();
|
||||||
|
$grouped_timezones = $this->timezones->to_grouped_array();
|
||||||
|
|
||||||
|
if (is_callback('booking', 'reschedule'))
|
||||||
{
|
{
|
||||||
// Load the appointments data and enable the manage mode of the page.
|
// Load the appointments data and enable the manage mode of the booking page.
|
||||||
|
|
||||||
|
$appointment_hash = $this->uri->segment(3);
|
||||||
|
|
||||||
$manage_mode = TRUE;
|
$manage_mode = TRUE;
|
||||||
|
|
||||||
$results = $this->appointments_model->get(['hash' => $appointment_hash]);
|
$results = $this->appointments_model->get(['hash' => $appointment_hash]);
|
||||||
|
|
||||||
if (empty($results))
|
if (empty($results))
|
||||||
{
|
{
|
||||||
// The requested appointment was not found in the database.
|
html_vars([
|
||||||
$this->load->view('pages/booking_message', [
|
'show_message' => TRUE,
|
||||||
|
'page_title' => lang('page_title') . ' ' . $company_name,
|
||||||
'message_title' => lang('appointment_not_found'),
|
'message_title' => lang('appointment_not_found'),
|
||||||
'message_text' => lang('appointment_does_not_exist_in_db'),
|
'message_text' => lang('appointment_does_not_exist_in_db'),
|
||||||
'message_icon' => base_url('assets/img/error.png')
|
'message_icon' => base_url('assets/img/error.png')
|
||||||
|
@ -119,8 +119,8 @@ class Booking extends EA_Controller {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the requested appointment begin date is lower than book_advance_timeout. Display a message to the
|
// Make sure the appointment can still be rescheduled.
|
||||||
// customer.
|
|
||||||
$start_datetime = strtotime($results[0]['start_datetime']);
|
$start_datetime = strtotime($results[0]['start_datetime']);
|
||||||
|
|
||||||
$limit = strtotime('+' . $book_advance_timeout . ' minutes', strtotime('now'));
|
$limit = strtotime('+' . $book_advance_timeout . ' minutes', strtotime('now'));
|
||||||
|
@ -128,9 +128,12 @@ class Booking extends EA_Controller {
|
||||||
if ($start_datetime < $limit)
|
if ($start_datetime < $limit)
|
||||||
{
|
{
|
||||||
$hours = floor($book_advance_timeout / 60);
|
$hours = floor($book_advance_timeout / 60);
|
||||||
|
|
||||||
$minutes = ($book_advance_timeout % 60);
|
$minutes = ($book_advance_timeout % 60);
|
||||||
|
|
||||||
$this->load->view('pages/booking_message', [
|
html_vars([
|
||||||
|
'show_message' => TRUE,
|
||||||
|
'page_title' => lang('page_title') . ' ' . $company_name,
|
||||||
'message_title' => lang('appointment_locked'),
|
'message_title' => lang('appointment_locked'),
|
||||||
'message_text' => strtr(lang('appointment_locked_message'), [
|
'message_text' => strtr(lang('appointment_locked_message'), [
|
||||||
'{$limit}' => sprintf('%02d:%02d', $hours, $minutes)
|
'{$limit}' => sprintf('%02d:%02d', $hours, $minutes)
|
||||||
|
@ -142,11 +145,8 @@ class Booking extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
$appointment = $results[0];
|
$appointment = $results[0];
|
||||||
|
|
||||||
$provider = $this->providers_model->find($appointment['id_users_provider']);
|
$provider = $this->providers_model->find($appointment['id_users_provider']);
|
||||||
|
|
||||||
$customer = $this->customers_model->find($appointment['id_users_customer']);
|
$customer = $this->customers_model->find($appointment['id_users_customer']);
|
||||||
|
|
||||||
$customer_token = md5(uniqid(mt_rand(), TRUE));
|
$customer_token = md5(uniqid(mt_rand(), TRUE));
|
||||||
|
|
||||||
// Cache the token for 10 minutes.
|
// Cache the token for 10 minutes.
|
||||||
|
@ -154,41 +154,88 @@ class Booking extends EA_Controller {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The customer is going to book a new appointment so there is no need for the manage functionality to
|
|
||||||
// be initialized.
|
|
||||||
$manage_mode = FALSE;
|
$manage_mode = FALSE;
|
||||||
$customer_token = FALSE;
|
$customer_token = FALSE;
|
||||||
$appointment = [];
|
$appointment = NULL;
|
||||||
$provider = [];
|
$provider = NULL;
|
||||||
$customer = [];
|
$customer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->load->view('pages/booking', [
|
script_vars([
|
||||||
'available_services' => $available_services,
|
'available_services' => $available_services,
|
||||||
'available_providers' => $available_providers,
|
'available_providers' => $available_providers,
|
||||||
'company_name' => $company_name,
|
|
||||||
'manage_mode' => $manage_mode,
|
|
||||||
'customer_token' => $customer_token,
|
|
||||||
'date_format' => $date_format,
|
'date_format' => $date_format,
|
||||||
'time_format' => $time_format,
|
'time_format' => $time_format,
|
||||||
'first_weekday' => $first_weekday,
|
'first_weekday' => $first_weekday,
|
||||||
'require_phone_number' => $require_phone_number,
|
'display_cookie_notice' => $display_cookie_notice,
|
||||||
'show_field' => $show_field,
|
'display_any_provider' => setting('display_any_provider'),
|
||||||
'appointment_data' => $appointment,
|
]);
|
||||||
'provider_data' => $provider,
|
|
||||||
'customer_data' => $customer,
|
html_vars([
|
||||||
|
'available_services' => $available_services,
|
||||||
|
'available_providers' => $available_providers,
|
||||||
|
'company_name' => $company_name,
|
||||||
|
'date_format' => $date_format,
|
||||||
|
'time_format' => $time_format,
|
||||||
|
'first_weekday' => $first_weekday,
|
||||||
'display_cookie_notice' => $display_cookie_notice,
|
'display_cookie_notice' => $display_cookie_notice,
|
||||||
'cookie_notice_content' => $cookie_notice_content,
|
'cookie_notice_content' => $cookie_notice_content,
|
||||||
'display_terms_and_conditions' => $display_terms_and_conditions,
|
'display_terms_and_conditions' => $display_terms_and_conditions,
|
||||||
'terms_and_conditions_content' => $terms_and_conditions_content,
|
'terms_and_conditions_content' => $terms_and_conditions_content,
|
||||||
'display_privacy_policy' => $display_privacy_policy,
|
'display_privacy_policy' => $display_privacy_policy,
|
||||||
'privacy_policy_content' => $privacy_policy_content,
|
'privacy_policy_content' => $privacy_policy_content,
|
||||||
|
'require_phone_number' => $require_phone_number,
|
||||||
|
'show_phone_number' => $show_phone_number,
|
||||||
|
'show_address' => $show_address,
|
||||||
|
'show_city' => $show_city,
|
||||||
|
'show_zip_code' => $show_zip_code,
|
||||||
|
'show_notes' => $show_notes,
|
||||||
|
'display_any_provider' => $display_any_provider,
|
||||||
'timezones' => $timezones,
|
'timezones' => $timezones,
|
||||||
'grouped_timezones' => $grouped_timezones,
|
'grouped_timezones' => $grouped_timezones,
|
||||||
'display_any_provider' => $display_any_provider,
|
'manage_mode' => $manage_mode,
|
||||||
|
'customer_token' => $customer_token,
|
||||||
|
'appointment_data' => $appointment,
|
||||||
|
'provider_data' => $provider,
|
||||||
|
'customer_data' => $customer,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the booking page.
|
||||||
|
*
|
||||||
|
* This method creates the appointment book wizard.
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
if ( ! is_app_installed())
|
||||||
|
{
|
||||||
|
redirect('installation');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (html_vars('show_message'))
|
||||||
|
{
|
||||||
|
// The requested appointment was not found in the database.
|
||||||
|
$this->load->view('pages/booking_message', html_vars());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->load->view('pages/booking', html_vars());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the booking page and display the selected appointment.
|
||||||
|
*
|
||||||
|
* This method will call the "index" callback to handle the page rendering.
|
||||||
|
*/
|
||||||
|
public function reschedule()
|
||||||
|
{
|
||||||
|
$this->index();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the available appointment hours for the selected date.
|
* Get the available appointment hours for the selected date.
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,20 +26,20 @@
|
||||||
</label>
|
</label>
|
||||||
<input type="text" id="email" class="required form-control" maxlength="120"/>
|
<input type="text" id="email" class="required form-control" maxlength="120"/>
|
||||||
</div>
|
</div>
|
||||||
<?php if ($show_field['phone-number']) : ?>
|
<?php if ($show_phone_number): ?>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="phone-number" class="form-label">
|
<label for="phone-number" class="form-label">
|
||||||
<?= lang('phone_number') ?>
|
<?= lang('phone_number') ?>
|
||||||
<?= $require_phone_number === '1' ? '<span class="text-danger">*</span>' : '' ?>
|
<?= $require_phone_number ? '<span class="text-danger">*</span>' : '' ?>
|
||||||
</label>
|
</label>
|
||||||
<input type="text" id="phone-number" maxlength="60"
|
<input type="text" id="phone-number" maxlength="60"
|
||||||
class="<?= $require_phone_number === '1' ? 'required' : '' ?> form-control"/>
|
class="<?= $require_phone_number ? 'required' : '' ?> form-control"/>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 col-md-6">
|
<div class="col-12 col-md-6">
|
||||||
<?php if ($show_field['address']) : ?>
|
<?php if ($show_address) : ?>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="address" class="form-label">
|
<label for="address" class="form-label">
|
||||||
<?= lang('address') ?>
|
<?= lang('address') ?>
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
<input type="text" id="address" class="form-control" maxlength="120"/>
|
<input type="text" id="address" class="form-control" maxlength="120"/>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if ($show_field['city']): ?>
|
<?php if ($show_city): ?>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="city" class="form-label">
|
<label for="city" class="form-label">
|
||||||
<?= lang('city') ?>
|
<?= lang('city') ?>
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
<input type="text" id="city" class="form-control" maxlength="120"/>
|
<input type="text" id="city" class="form-control" maxlength="120"/>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if ($show_field['zip-code']) : ?>
|
<?php if ($show_zip_code): ?>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="zip-code" class="form-label">
|
<label for="zip-code" class="form-label">
|
||||||
<?= lang('zip_code') ?>
|
<?= lang('zip_code') ?>
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
<input type="text" id="zip-code" class="form-control" maxlength="120"/>
|
<input type="text" id="zip-code" class="form-control" maxlength="120"/>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if ($show_field['notes']) : ?>
|
<?php if ($show_notes): ?>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="notes" class="form-label">
|
<label for="notes" class="form-label">
|
||||||
<?= lang('notes') ?>
|
<?= lang('notes') ?>
|
||||||
|
|
Loading…
Reference in a new issue