Fix extrafield date or datetime with bad timezone

This commit is contained in:
Laurent Destailleur 2018-02-20 19:19:27 +01:00
parent 71cbcce3a2
commit e465b0c40e
3 changed files with 28 additions and 6 deletions

View File

@ -4481,7 +4481,7 @@ abstract class CommonObject
if (! is_array($optionsArray)) 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. // 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; // global $extrafields;
//if (! is_object($extrafields)) //if (! is_object($extrafields))
//{ //{
@ -4496,6 +4496,10 @@ abstract class CommonObject
} }
$optionsArray = $extrafields->attributes[$this->table_element]['label']; $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; $table_element = $this->table_element;
if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
@ -4529,8 +4533,18 @@ abstract class CommonObject
if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key))
{ {
// we can add this attribute to object // we can add this attribute to object
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; $this->array_options["options_".$key]=$value;
} }
//var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]);
}
} }
} }

View File

@ -1404,12 +1404,12 @@ class ExtraFields
if ($type == 'date') if ($type == 'date')
{ {
$showsize=10; $showsize=10;
$value=dol_print_date($value, 'day', 'tzuser'); $value=dol_print_date($value, 'day');
} }
elseif ($type == 'datetime') elseif ($type == 'datetime')
{ {
$showsize=19; $showsize=19;
$value=dol_print_date($value, 'dayhour', 'tzuser'); $value=dol_print_date($value, 'dayhour');
} }
elseif ($type == 'int') elseif ($type == 'int')
{ {

View File

@ -107,8 +107,16 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][
print '<td id="'.$html_id.'" class="'.$object->element.'_extras_'.$key.'" colspan="'.$cols.'">'; print '<td id="'.$html_id.'" class="'.$object->element.'_extras_'.$key.'" colspan="'.$cols.'">';
// Convert date into timestamp format // Convert date into timestamp format
if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('date','datetime'))) { 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]); {
$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 //TODO Improve element and rights detection