diff --git a/src/application/controllers/appointments.php b/src/application/controllers/appointments.php index aef0ae0c..b779f334 100755 --- a/src/application/controllers/appointments.php +++ b/src/application/controllers/appointments.php @@ -62,6 +62,7 @@ class Appointments extends CI_Controller { $available_services = $this->services_model->get_available_services(); $available_providers = $this->providers_model->get_available_providers(); $company_name = $this->settings_model->get_setting('company_name'); + $date_format = $this->settings_model->get_setting('date_format'); // If an appointment hash is provided then it means that the customer // is trying to edit a registered appointment record. @@ -105,6 +106,7 @@ class Appointments extends CI_Controller { 'available_providers' => $available_providers, 'company_name' => $company_name, 'manage_mode' => $manage_mode, + 'date_format' => $date_format, 'appointment_data' => $appointment, 'provider_data' => $provider, 'customer_data' => $customer, diff --git a/src/application/views/appointments/book.php b/src/application/views/appointments/book.php index 90377b83..827acfcf 100644 --- a/src/application/views/appointments/book.php +++ b/src/application/views/appointments/book.php @@ -75,6 +75,7 @@ availableProviders : , baseUrl : config->item('base_url') . '"'; ?>, manageMode : , + dateFormat : , appointmentData : , providerData : , customerData : , diff --git a/src/assets/js/frontend_book.js b/src/assets/js/frontend_book.js index 7a1cbb1d..495bf63d 100644 --- a/src/assets/js/frontend_book.js +++ b/src/assets/js/frontend_book.js @@ -399,7 +399,7 @@ var FrontendBook = { // Appointment Details var selectedDate = $('#select-date').datepicker('getDate'); if (selectedDate !== null) { - selectedDate = Date.parse(selectedDate).toString('dd/MM/yyyy'); + selectedDate = GeneralFunctions.formatDate(selectedDate, GlobalVariables.dateFormat); } var selServiceId = $('#select-service').val(); diff --git a/src/assets/js/general_functions.js b/src/assets/js/general_functions.js index ad052b8b..241aa3e7 100644 --- a/src/assets/js/general_functions.js +++ b/src/assets/js/general_functions.js @@ -112,14 +112,11 @@ var GeneralFunctions = { * @returns {String} Returns the parameter value. */ getUrlParameter: function(url, parameterName) { - parameterName = parameterName.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]'); - var regexS = '[\\#&]' + parameterName + '=([^]*)'; - var regex = new RegExp( regexS ); - var results = regex.exec( url ); - if( results == null ) - return ''; - else - return results[1]; + parameterName = parameterName.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]'); + var regexS = '[\\#&]' + parameterName + '=([^]*)', + regex = new RegExp(regexS), + results = regex.exec(url); + return (results == null) ? '' : results[1]; }, /** @@ -129,8 +126,10 @@ var GeneralFunctions = { * @param {date} dt The given date that will be transformed * @returns {String} Returns the transformed string. */ - ISODateString: function(dt){ - function pad(n) { return n<10 ? '0'+n : n; } + ISODateString: function(dt) { + function pad(n) { + return n<10 ? '0'+n : n; + } return dt.getUTCFullYear()+'-' + pad(dt.getUTCMonth()+1)+'-' @@ -365,5 +364,33 @@ var GeneralFunctions = { */ escapeHtml: function(str) { return $('
').text(str).html(); + }, + + /** + * Format a given date according to the date format setting. + * + * @param {Date]} date The date to be formatted. + * @param {string} dateFormatSetting The setting provided by PHP must be one of + * the "DMY", "MDY" or "YMD". + * @returns {string} Returns the formatted date string. + */ + formatDate: function(date, dateFormatSetting) { + var result; + + switch(dateFormatSetting) { + case 'DMY': + result = Date.parse(date).toString('dd/MM/yyyy'); + break; + case 'MDY': + result = Date.parse(date).toString('MM/dd/yyyy'); + break; + case 'YMD': + result = Date.parse(date).toString('yyyy/MM/dd'); + break; + default: + throw new Error('Invalid date format setting provided!', dateFormatSetting); + } + + return result; } };