From fbcd756c9d4523aee3d1d13c3719a3e80c10671a Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Fri, 4 Mar 2016 05:37:37 +0000
Subject: [PATCH] datepicker: Use consistent date format

To avoid date format ambiguity the datepicker replaces entered date with a
standard 'ISO 8601' date format on form submission. The system however fails
to use datepicker's format on post-back, resulting in invalid date on
subsequent submit.

This pull request addresses the issue by making sure reflected date uses the
format datepicker expects.
---
 include/class.report.php        | 25 ++++++++++++++++++++++++-
 include/staff/dashboard.inc.php |  7 ++++---
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/include/class.report.php b/include/class.report.php
index 49ee202b5..d65fd1cc5 100644
--- a/include/class.report.php
+++ b/include/class.report.php
@@ -24,11 +24,34 @@ class OverviewReport {
     var $start;
     var $end;
 
-    function __construct($start, $end='now') {
+    var $format;
+
+    function __construct($start, $end='now', $format=null) {
+        global $cfg;
+
         $this->start = $start;
         $this->end = $end;
+        $this->format = $format ?: $cfg->getDateFormat(true);
     }
 
+
+    function getStartDate($format=null, $translate=true) {
+
+        if (!$this->start)
+            return '';
+
+        $format =  $format ?: $this->format;
+        if ($translate) {
+            $format = str_replace(
+                    array('y', 'Y', 'm'),
+                    array('yy', 'yyyy', 'mm'),
+                    $format);
+        }
+
+        return Format::date(Misc::dbtime($this->start), false, $format);
+    }
+
+
     function getDateRange() {
         global $cfg;
 
diff --git a/include/staff/dashboard.inc.php b/include/staff/dashboard.inc.php
index 0feb3f9d9..d7b35af5e 100644
--- a/include/staff/dashboard.inc.php
+++ b/include/staff/dashboard.inc.php
@@ -19,9 +19,10 @@ $plots = $report->getPlotData();
             <label>
                 <?php echo __( 'Report timeframe'); ?>:
                 <input type="text" class="dp input-medium search-query"
-                    name="start" placeholder="<?php echo __('Last month');?>"i
-                    value="<?php echo $_POST['start'] ?
-                    Format::htmlchars($_POST['start']) : ''; ?>" />
+                    name="start" placeholder="<?php echo __('Last month');?>"
+                    value="<?php
+                        echo Format::htmlchars($report->getStartDate());
+                    ?>" />
             </label>
             <label>
                 <?php echo __( 'period');?>:
-- 
GitLab