From e21f6f0712cb7377d3926290b289390393d66cd1 Mon Sep 17 00:00:00 2001 From: Luke A Date: Sun, 1 Dec 2019 11:28:09 -0500 Subject: [PATCH 1/4] cherrypick #582 PR changes --- common/common_directory.php | 11 +++++++++++ js/common.js | 1 - licensing/templates/header.php | 3 +++ management/templates/header.php | 3 +++ organizations/templates/header.php | 3 +++ reports/templates/header.php | 3 +++ resources/templates/header.php | 3 +++ usage/templates/header.php | 3 +++ 8 files changed, 29 insertions(+), 1 deletion(-) diff --git a/common/common_directory.php b/common/common_directory.php index 5a44fe4a6..020dc4edc 100644 --- a/common/common_directory.php +++ b/common/common_directory.php @@ -74,6 +74,17 @@ function return_date_format() { return $date_format; } +function return_datepicker_date_format() { + $config = new Configuration(); + $config_date_format = $config->settings->datepicker_date_format; + if (isset($config_date_format) && $config_date_format != '') { + $date_format = $config_date_format; + } else { + $date_format = "mm/dd/yyyy"; + } + return $date_format; +} + function format_date($mysqlDate) { //see http://php.net/manual/en/function.date.php for options diff --git a/js/common.js b/js/common.js index fa1aea256..83081cc08 100644 --- a/js/common.js +++ b/js/common.js @@ -34,7 +34,6 @@ //Required for date picker Date.firstDayOfWeek = 0; -Date.format = 'mm/dd/yyyy'; // 1 visible, 0 hidden diff --git a/licensing/templates/header.php b/licensing/templates/header.php index bfaec75cd..86f29acaf 100644 --- a/licensing/templates/header.php +++ b/licensing/templates/header.php @@ -81,6 +81,9 @@ + diff --git a/management/templates/header.php b/management/templates/header.php index 4142af7ee..d21e8b7da 100644 --- a/management/templates/header.php +++ b/management/templates/header.php @@ -80,6 +80,9 @@ + diff --git a/organizations/templates/header.php b/organizations/templates/header.php index 97810a0cb..d94c9b10b 100644 --- a/organizations/templates/header.php +++ b/organizations/templates/header.php @@ -74,6 +74,9 @@ + diff --git a/reports/templates/header.php b/reports/templates/header.php index 9e720d20c..53afbd26f 100644 --- a/reports/templates/header.php +++ b/reports/templates/header.php @@ -67,6 +67,9 @@ + " . _("JavaScript must be enabled in order for you to use CORAL. However, it seems JavaScript is either disabled or not supported by your browser. To use CORAL, enable JavaScript by changing your browser options, then") . " " . _("try again") . ". ";?> diff --git a/resources/templates/header.php b/resources/templates/header.php index f18445662..d5d36aa8c 100644 --- a/resources/templates/header.php +++ b/resources/templates/header.php @@ -72,6 +72,9 @@ + diff --git a/usage/templates/header.php b/usage/templates/header.php index b78b2fa78..6b55a0846 100755 --- a/usage/templates/header.php +++ b/usage/templates/header.php @@ -67,6 +67,9 @@ ?> + From c156f78315ecf41ee2beded9018809a10b759166 Mon Sep 17 00:00:00 2001 From: Luke A Date: Sun, 1 Dec 2019 11:35:51 -0500 Subject: [PATCH 2/4] add datepicker config to configuration sample --- common/configuration_sample.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/common/configuration_sample.ini b/common/configuration_sample.ini index 0f8057514..fc396148f 100644 --- a/common/configuration_sample.ini +++ b/common/configuration_sample.ini @@ -56,3 +56,4 @@ installed = "Y" [settings] environment = "prod" date_format = "%m/%d/%Y" +datepicker_date_format = "mm/dd/yyyy"; From 7ca8102de13127318d239cd9f1a3dba1e051ca18 Mon Sep 17 00:00:00 2001 From: Luke A Date: Sun, 1 Dec 2019 12:46:46 -0500 Subject: [PATCH 3/4] create js string to php date functions --- common/common_directory.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/common/common_directory.php b/common/common_directory.php index 020dc4edc..cb85e3551 100644 --- a/common/common_directory.php +++ b/common/common_directory.php @@ -98,6 +98,38 @@ function format_date($mysqlDate) { } +function create_php_date_format_from_js_format($input_string) { + + // Note the js format strings are specific to the datepicker plugin + $js_formats = array('/yyyy/','/yy/','/mmmm/','/mmm/','/mm/','/dd/'); + // php format strings https://www.php.net/manual/en/function.date.php + $php_formats = array('Y','y','F','M','m','d'); + + return preg_replace($js_formats, $php_formats, $input_string); +} + +function create_date_from_js_format($formdate) { + /* + * see https://andy-carter.com/blog/php-date-formats for overview of different php date formatters + * Coral utilizes strftime() and strtotime(), but strtotime expects dates to be formatted in US English + * + * Thus, while the above format_date() function works for mysql dates (which are stored as YYYY/MM/DD HH:MM:SS, + * it does not work for formatting form input dates, which are formatted via the datepiccker_date_format in common/configuration.ini + * + * E.g. a UK date of 26/11/2019 will return an error when using strtotime + * + * This function turns an input date into php Date object, which can then be utilized by strftime() + * + * To do so, it must convert datepicker format strings (e.g. 'dd' & 'mm') into php date format strings (e.g. 'd', 'm') + * using the create_php_date_format_from_js_format() function above + */ + + $datepicker_format = return_datepicker_date_format(); + $php_format = create_php_date_format_from_js_format($datepicker_format); + return date_create_from_format($php_format, $formdate); + +} + function debug($value) { echo '
'.print_r($value, true).'
'; } From f561a4c8f80752cef81be690237d9ac26906378e Mon Sep 17 00:00:00 2001 From: Luke A Date: Sun, 1 Dec 2019 17:26:15 -0500 Subject: [PATCH 4/4] update instances of strtotime from input forms --- common/common_directory.php | 4 ++-- licensing/ajax_processing.php | 6 +++--- management/ajax_processing.php | 10 +++++----- organizations/ajax_processing.php | 14 +++++++------- resources/ajax_processing/insertDowntime.php | 4 ++-- resources/ajax_processing/submitAcquisitions.php | 4 ++-- resources/ajax_processing/submitCost.php | 4 ++-- resources/ajax_processing/updateDowntime.php | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/common/common_directory.php b/common/common_directory.php index cb85e3551..04e10c6a6 100644 --- a/common/common_directory.php +++ b/common/common_directory.php @@ -108,7 +108,7 @@ function create_php_date_format_from_js_format($input_string) { return preg_replace($js_formats, $php_formats, $input_string); } -function create_date_from_js_format($formdate) { +function create_date_from_js_format($input) { /* * see https://andy-carter.com/blog/php-date-formats for overview of different php date formatters * Coral utilizes strftime() and strtotime(), but strtotime expects dates to be formatted in US English @@ -126,7 +126,7 @@ function create_date_from_js_format($formdate) { $datepicker_format = return_datepicker_date_format(); $php_format = create_php_date_format_from_js_format($datepicker_format); - return date_create_from_format($php_format, $formdate); + return date_create_from_format($php_format, $input); } diff --git a/licensing/ajax_processing.php b/licensing/ajax_processing.php index aa95f1260..93b847e14 100644 --- a/licensing/ajax_processing.php +++ b/licensing/ajax_processing.php @@ -59,7 +59,7 @@ //first set effective Date for proper saving if ((isset($_POST['effectiveDate'])) && ($_POST['effectiveDate'] != '')){ - $document->effectiveDate = date("Y-m-d", strtotime($_POST['effectiveDate'])); + $document->effectiveDate = create_date_from_js_format($_POST['effectiveDate'])->format('Y-m-d'); }else{ $document->effectiveDate= 'null'; } @@ -212,7 +212,7 @@ case 'submitSignature': //set date for proper saving if ((isset($_POST['signatureDate'])) && ($_POST['signatureDate'] != '')){ - $signatureDate = date("Y-m-d", strtotime($_POST['signatureDate'])); + $signatureDate = create_date_from_js_format($_POST['signatureDate'])->format('Y-m-d'); }else{ $signatureDate = ""; } @@ -976,7 +976,7 @@ } if ((isset($_POST['sentDate'])) && ($_POST['sentDate'] <> "")){ - $attachment->sentDate = date("Y-m-d", strtotime($_POST['sentDate'])); + $attachment->sentDate = create_date_from_js_format($_POST['sentDate'])->format('Y-m-d'); }else{ $attachment->sentDate = ""; } diff --git a/management/ajax_processing.php b/management/ajax_processing.php index 8c0fc8289..ddcc0ff9f 100644 --- a/management/ajax_processing.php +++ b/management/ajax_processing.php @@ -56,13 +56,13 @@ //first set effective Date for proper saving if ((isset($_POST['effectiveDate'])) && ($_POST['effectiveDate'] != '')){ - $document->effectiveDate = date("Y-m-d", strtotime($_POST['effectiveDate'])); + $document->effectiveDate = create_date_from_js_format($_POST['effectiveDate'])->format('Y-m-d'); }else{ $document->effectiveDate= 'null'; } if ((isset($_POST['revisionDate'])) && ($_POST['revisionDate'] != '')) { - $document->revisionDate = date("Y-m-d", strtotime($_POST['revisionDate'])); + $document->revisionDate = create_date_from_js_format($_POST['revisionDate'])->format('Y-m-d'); } @@ -217,7 +217,7 @@ case 'submitSignature': //set date for proper saving if ((isset($_POST['signatureDate'])) && ($_POST['signatureDate'] != '')){ - $signatureDate = date("Y-m-d", strtotime($_POST['signatureDate'])); + $signatureDate = create_date_from_js_format($_POST['signatureDate'])->format('Y-m-d'); }else{ $signatureDate = ""; } @@ -513,7 +513,7 @@ $document->documentID = ''; $document->effectiveDate = date( 'Y-m-d H:i:s' ); if ((isset($_POST['revisionDate'])) && ($_POST['revisionDate'] != '')) { - $document->revisionDate = date("Y-m-d", strtotime($_POST['revisionDate'])); + $document->revisionDate = create_date_from_js_format($_POST['revisionDate'])->format('Y-m-d'); } @@ -1094,7 +1094,7 @@ } if ((isset($_POST['sentDate'])) && ($_POST['sentDate'] <> "")){ - $attachment->sentDate = date("Y-m-d", strtotime($_POST['sentDate'])); + $attachment->sentDate = create_date_from_js_format($_POST['sentDate'])->format('Y-m-d'); }else{ $attachment->sentDate = ""; } diff --git a/organizations/ajax_processing.php b/organizations/ajax_processing.php index d433419ab..a8bdb13b3 100644 --- a/organizations/ajax_processing.php +++ b/organizations/ajax_processing.php @@ -94,7 +94,7 @@ // Create vendor in ILS if ($organization->ilsID == null) { $ilsID = $ilsClient->addVendor(array( - "name" => $organization->name, + "name" => $organization->name, "companyURL" => $organization->companyURL, "noteText" => $organization->noteText, "accountDetailText" => $organization->accountDetailText, @@ -113,7 +113,7 @@ $organization->accountDetailText = $ilsVendor['accountDetailText']; } $organization->save(); - } + } } catch (Exception $e) { echo $e->getMessage(); @@ -361,7 +361,7 @@ case 'updateDowntime': if (is_numeric($_POST['downtimeID'])) { $downtime = new Downtime(new NamedArguments(array('primaryKey' => $_POST['downtimeID']))); - $downtime->endDate = ($_POST['endDate']) ? date('Y-m-d H:i:s', strtotime($_POST['endDate']." ".$_POST['endTime']['hour'].":".$_POST['endTime']['minute'].$_POST['endTime']['meridian'])):null; + $downtime->endDate = ($_POST['endDate']) ? date('Y-m-d H:i:s', create_date_from_js_format($_POST['endDate'])->format('Y-m-d')." ".$_POST['endTime']['hour'].":".$_POST['endTime']['minute'].$_POST['endTime']['meridian']) : null; $downtime->note = ($_POST['note']) ? $_POST['note']:null; $downtime->save(); } @@ -373,8 +373,8 @@ $newDowntime->downtimeTypeID = $_POST['downtimeType']; $newDowntime->issueID = $_POST['issueID']; - $newDowntime->startDate = date('Y-m-d H:i:s', strtotime($_POST['startDate']." ".$_POST['startTime']['hour'].":".$_POST['startTime']['minute'].$_POST['startTime']['meridian'])); - $newDowntime->endDate = ($_POST['endDate']) ? date('Y-m-d H:i:s', strtotime($_POST['endDate']." ".$_POST['endTime']['hour'].":".$_POST['endTime']['minute'].$_POST['endTime']['meridian'])):null; + $newDowntime->startDate = date('Y-m-d H:i:s', create_date_from_js_format($_POST['statDate'])->format('Y-m-d')." ".$_POST['startTime']['hour'].":".$_POST['startTime']['minute'].$_POST['startTime']['meridian']); + $newDowntime->endDate = ($_POST['endDate']) ? date('Y-m-d H:i:s', create_date_from_js_format($_POST['endDate'])->format('Y-m-d')." ".$_POST['endTime']['hour'].":".$_POST['endTime']['minute'].$_POST['endTime']['meridian']):null; $newDowntime->dateCreated = date( 'Y-m-d H:i:s'); $newDowntime->entityTypeID = 1; @@ -395,13 +395,13 @@ } if ($_POST['issueStartDate']){ - $issueLog->issueStartDate = date("Y-m-d", strtotime($_POST['issueStartDate'])); + $issueLog->issueStartDate = create_date_from_js_format($_POST['issueStartDate'])->format('Y-m-d'); }else{ $issueLog->issueStartDate = ''; } if ($_POST['issueEndDate']){ - $issueLog->issueEndDate = date("Y-m-d", strtotime($_POST['issueEndDate'])); + $issueLog->issueEndDate = create_date_from_js_format($_POST['issueEndDate'])->format('Y-m-d'); }else{ $issueLog->issueEndDate = ''; } diff --git a/resources/ajax_processing/insertDowntime.php b/resources/ajax_processing/insertDowntime.php index 842b5a517..29b653b0f 100644 --- a/resources/ajax_processing/insertDowntime.php +++ b/resources/ajax_processing/insertDowntime.php @@ -15,8 +15,8 @@ $newDowntime->downtimeTypeID = $_POST['downtimeType']; $newDowntime->issueID = $_POST['issueID']; -$newDowntime->startDate = date('Y-m-d H:i:s', strtotime($_POST['startDate']." ".$_POST['startTime']['hour'].":".$_POST['startTime']['minute'].$_POST['startTime']['meridian'])); -$newDowntime->endDate = ($_POST['endDate']) ? date('Y-m-d H:i:s', strtotime($_POST['endDate']." ".$_POST['endTime']['hour'].":".$_POST['endTime']['minute'].$_POST['endTime']['meridian'])):null; +$newDowntime->startDate = date('Y-m-d H:i:s', create_date_from_js_format($_POST['startDate'])->format('Y-m-d')." ".$_POST['startTime']['hour'].":".$_POST['startTime']['minute'].$_POST['startTime']['meridian']); +$newDowntime->endDate = ($_POST['endDate']) ? date('Y-m-d H:i:s', create_date_from_js_format($_POST['endDate'])->format('Y-m-d')." ".$_POST['endTime']['hour'].":".$_POST['endTime']['minute'].$_POST['endTime']['meridian']) : null; $newDowntime->dateCreated = date( 'Y-m-d H:i:s'); $newDowntime->note = ($_POST['note']) ? $_POST['note']:null; diff --git a/resources/ajax_processing/submitAcquisitions.php b/resources/ajax_processing/submitAcquisitions.php index ae50a9a34..7cc2e6f56 100644 --- a/resources/ajax_processing/submitAcquisitions.php +++ b/resources/ajax_processing/submitAcquisitions.php @@ -9,14 +9,14 @@ //first set current start Date for proper saving if ((isset($_POST['currentStartDate'])) && ($_POST['currentStartDate'] != '')){ - $resourceAcquisition->subscriptionStartDate = date("Y-m-d", strtotime($_POST['currentStartDate'])); + $resourceAcquisition->subscriptionStartDate = create_date_from_js_format($_POST['currentStartDate'])->format('Y-m-d'); }else{ $resourceAcquisition->subscriptionStartDate = ''; } //first set current end Date for proper saving if ((isset($_POST['currentEndDate'])) && ($_POST['currentEndDate'] != '')){ - $resourceAcquisition->subscriptionEndDate = date("Y-m-d", strtotime($_POST['currentEndDate'])); + $resourceAcquisition->subscriptionEndDate = create_date_from_js_format($_POST['currentEndDate'])->format('Y-m-d'); }else{ $resourceAcquisition->subscriptionEndDate = ''; } diff --git a/resources/ajax_processing/submitCost.php b/resources/ajax_processing/submitCost.php index ddb9c2e1f..05c699f34 100644 --- a/resources/ajax_processing/submitCost.php +++ b/resources/ajax_processing/submitCost.php @@ -27,8 +27,8 @@ $resourcePayment = new ResourcePayment(); $resourcePayment->resourceAcquisitionID = $resourceAcquisitionID; $resourcePayment->year = $yearArray[$key]; - $start = $subStartArray[$key] ? date("Y-m-d", strtotime($subStartArray[$key])) : null; - $end = $subEndArray[$key] ? date("Y-m-d", strtotime($subEndArray[$key])) : null; + $start = $subStartArray[$key] ? create_date_from_js_format($subStartArray[$key])->format('Y-m-d') : null; + $end = $subEndArray[$key] ? create_date_from_js_format($subEndArray[$key])->format('Y-m-d') : null; $resourcePayment->subscriptionStartDate = $start; $resourcePayment->subscriptionEndDate = $end; $resourcePayment->fundID = $fundIDArray[$key]; diff --git a/resources/ajax_processing/updateDowntime.php b/resources/ajax_processing/updateDowntime.php index d40542d4a..ba21eb26f 100644 --- a/resources/ajax_processing/updateDowntime.php +++ b/resources/ajax_processing/updateDowntime.php @@ -2,7 +2,7 @@ if (is_numeric($_POST['downtimeID'])) { $downtime = new Downtime(new NamedArguments(array('primaryKey' => $_POST['downtimeID']))); - $downtime->endDate = ($_POST['endDate']) ? date('Y-m-d H:i:s', strtotime($_POST['endDate']." ".$_POST['endTime']['hour'].":".$_POST['endTime']['minute'].$_POST['endTime']['meridian'])):null; + $downtime->endDate = ($_POST['endDate']) ? date('Y-m-d H:i:s', create_date_from_js_format($_POST['endDate'])->format('Y-m-d')." ".$_POST['endTime']['hour'].":".$_POST['endTime']['minute'].$_POST['endTime']['meridian']):null; $downtime->note = ($_POST['note']) ? $_POST['note']:null;