From ad9935b14fea8411d5b117b269659c430f5de7cc Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 30 Oct 2013 14:16:51 +0000
Subject: [PATCH] Use system date format for datepicker

Previously the American date format (m/d/Y) was used exclusively for
formatting dates in the datepicker widget. This patch enables the widget to
be formatted based on the format set in the admin panel.

Fixes #829
---
 include/ajax.config.php  |  1 +
 include/class.ticket.php |  6 +++++-
 scp/js/scp.js            | 29 +++++++++++++++++++++++------
 3 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/include/ajax.config.php b/include/ajax.config.php
index 2a01e2840..9cb046c7d 100644
--- a/include/ajax.config.php
+++ b/include/ajax.config.php
@@ -24,6 +24,7 @@ class ConfigAjaxAPI extends AjaxController {
 
         $config=array(
                       'lock_time'       => ($cfg->getLockTime()*3600),
+                      'date_format'     => ($cfg->getDateFormat()),
                       'max_file_uploads'=> (int) $cfg->getStaffMaxFileUploads()
                       );
         return $this->json_encode($config);
diff --git a/include/class.ticket.php b/include/class.ticket.php
index c3eb29d8d..8398710cf 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -287,6 +287,7 @@ class Ticket {
     }
 
     function getUpdateInfo() {
+        global $cfg;
 
         $info=array('name'  =>  $this->getName(),
                     'email' =>  $this->getEmail(),
@@ -297,7 +298,10 @@ class Ticket {
                     'topicId'   =>  $this->getTopicId(),
                     'priorityId'    =>  $this->getPriorityId(),
                     'slaId' =>  $this->getSLAId(),
-                    'duedate'   =>  $this->getDueDate()?(Format::userdate('m/d/Y', Misc::db2gmtime($this->getDueDate()))):'',
+                    'duedate'   =>  $this->getDueDate()
+                        ? Format::userdate($cfg->getDateFormat(),
+                            Misc::db2gmtime($this->getDueDate()))
+                        :'',
                     'time'  =>  $this->getDueDate()?(Format::userdate('G:i', Misc::db2gmtime($this->getDueDate()))):'',
                     );
 
diff --git a/scp/js/scp.js b/scp/js/scp.js
index ec2daf542..386b128da 100644
--- a/scp/js/scp.js
+++ b/scp/js/scp.js
@@ -278,12 +278,29 @@ $(document).ready(function(){
     }
 
     /* Datepicker */
-    $('.dp').datepicker({
-        numberOfMonths: 2,
-        showButtonPanel: true,
-        buttonImage: './images/cal.png',
-        showOn:'both'
-     });
+    getConfig().then(function(c) {
+        var df = c.date_format||'m/d/Y',
+            translation = {
+                'd':'dd',
+                'j':'d',
+                'z':'o',
+                'm':'mm',
+                'F':'MM',
+                'n':'m',
+                'Y':'yy'
+            };
+        // Change PHP formats to datepicker ones
+        $.each(translation, function(php, jqdp) {
+            df = df.replace(php, jqdp);
+        });
+        $('.dp').datepicker({
+            numberOfMonths: 2,
+            showButtonPanel: true,
+            buttonImage: './images/cal.png',
+            showOn:'both',
+            dateFormat: df,
+         });
+    });
 
     /* NicEdit richtext init */
     var rtes = $('.richtext');
-- 
GitLab