From e465b0c40ebfd4eb71952491f6de147ba716baf6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 20 Feb 2018 19:19:27 +0100 Subject: [PATCH] Fix extrafield date or datetime with bad timezone --- htdocs/core/class/commonobject.class.php | 18 ++++++++++++++++-- htdocs/core/class/extrafields.class.php | 4 ++-- htdocs/core/tpl/extrafields_view.tpl.php | 12 ++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8def2194fb3..07993bb1d97 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4481,7 +4481,7 @@ abstract class CommonObject if (! is_array($optionsArray)) { // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. - // TODO Use of existing extrafield is not yet ready (must mutualize code that use extrafields in form first) + // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) // global $extrafields; //if (! is_object($extrafields)) //{ @@ -4496,6 +4496,10 @@ abstract class CommonObject } $optionsArray = $extrafields->attributes[$this->table_element]['label']; } + else + { + dol_syslog("Warning: fetch_optionals was called with param $optionsArray defined when you should pass null now", LOG_WARNING); + } $table_element = $this->table_element; if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility @@ -4529,7 +4533,17 @@ abstract class CommonObject if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) { // we can add this attribute to object - $this->array_options["options_".$key]=$value; + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime'))) + { + //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); + $this->array_options["options_".$key]=$this->db->jdate($value); + } + else + { + $this->array_options["options_".$key]=$value; + } + + //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]); } } } diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index a127ce706e9..ee165ac6808 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1404,12 +1404,12 @@ class ExtraFields if ($type == 'date') { $showsize=10; - $value=dol_print_date($value, 'day', 'tzuser'); + $value=dol_print_date($value, 'day'); } elseif ($type == 'datetime') { $showsize=19; - $value=dol_print_date($value, 'dayhour', 'tzuser'); + $value=dol_print_date($value, 'dayhour'); } elseif ($type == 'int') { diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php index 9d638426bc3..3559df44c9c 100644 --- a/htdocs/core/tpl/extrafields_view.tpl.php +++ b/htdocs/core/tpl/extrafields_view.tpl.php @@ -107,8 +107,16 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][ print ''; // Convert date into timestamp format - if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('date','datetime'))) { - $value = isset($_POST["options_" . $key]) ? dol_mktime($_POST["options_" . $key . "hour"], $_POST["options_" . $key . "min"], 0, $_POST["options_" . $key . "month"], $_POST["options_" . $key . "day"], $_POST["options_" . $key . "year"]) : $db->jdate($object->array_options['options_' . $key]); + if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('date','datetime'))) + { + $datenotinstring = $object->array_options['options_' . $key]; + // print 'X'.$object->array_options['options_' . $key].'-'.$datenotinstring.'x'; + if (! is_numeric($object->array_options['options_' . $key])) // For backward compatibility + { + $datenotinstring = $db->jdate($datenotinstring); + } + //print 'x'.$object->array_options['options_' . $key].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour'); + $value = isset($_POST["options_" . $key]) ? dol_mktime($_POST["options_" . $key . "hour"], $_POST["options_" . $key . "min"], 0, $_POST["options_" . $key . "month"], $_POST["options_" . $key . "day"], $_POST["options_" . $key . "year"]) : $datenotinstring; } //TODO Improve element and rights detection