FIX Timezone management for datetime with modulebuilder and extrafields
This commit is contained in:
parent
5553bae3a1
commit
7bc2e1ffad
@ -71,7 +71,7 @@ if ($action == 'add' && !empty($permissiontoadd))
|
||||
} elseif ($object->fields[$key]['type'] == 'date') {
|
||||
$value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt
|
||||
} elseif ($object->fields[$key]['type'] == 'datetime') {
|
||||
$value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel');
|
||||
$value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel');
|
||||
} elseif ($object->fields[$key]['type'] == 'duration') {
|
||||
$value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int');
|
||||
} elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) {
|
||||
@ -158,9 +158,9 @@ if ($action == 'update' && !empty($permissiontoadd))
|
||||
$value = GETPOST($key, 'restricthtml');
|
||||
}
|
||||
} elseif ($object->fields[$key]['type'] == 'date') {
|
||||
$value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); // for date without hour, we use gmt
|
||||
$value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt
|
||||
} elseif ($object->fields[$key]['type'] == 'datetime') {
|
||||
$value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'), 'tzuserrel');
|
||||
$value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel');
|
||||
} elseif ($object->fields[$key]['type'] == 'duration') {
|
||||
if (GETPOST($key.'hour', 'int') != '' || GETPOST($key.'min', 'int') != '') {
|
||||
$value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int');
|
||||
|
||||
@ -5962,17 +5962,26 @@ abstract class CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($type, array('date', 'datetime'))) {
|
||||
if (in_array($type, array('date'))) {
|
||||
$tmp = explode(',', $size);
|
||||
$newsize = $tmp[0];
|
||||
|
||||
$showtime = in_array($type, array('datetime')) ? 1 : 0;
|
||||
$showtime = 0;
|
||||
|
||||
// Do not show current date when field not required (see selectDate() method)
|
||||
if (!$required && $value == '') $value = '-1';
|
||||
|
||||
// TODO Must also support $moreparam
|
||||
$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
|
||||
} elseif (in_array($type, array('datetime'))) {
|
||||
$tmp = explode(',', $size);
|
||||
$newsize = $tmp[0];
|
||||
$showtime = 1;
|
||||
|
||||
// Do not show current date when field not required (see selectDate() method)
|
||||
if (!$required && $value == '') $value = '-1';
|
||||
|
||||
// TODO Must also support $moreparam
|
||||
$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1, '', '', '', 1, '', '', 'tzuserrel');
|
||||
} elseif (in_array($type, array('duration'))) {
|
||||
$out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0, 'text', 0, 1);
|
||||
} elseif (in_array($type, array('int', 'integer'))) {
|
||||
@ -6911,14 +6920,23 @@ abstract class CommonObject
|
||||
if ($action == 'selectlines') { $colspan++; }
|
||||
|
||||
// Convert date into timestamp format (value in memory must be a timestamp)
|
||||
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime')))
|
||||
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date')))
|
||||
{
|
||||
$datenotinstring = $this->array_options['options_'.$key];
|
||||
if (!is_numeric($this->array_options['options_'.$key])) // For backward compatibility
|
||||
{
|
||||
$datenotinstring = $this->db->jdate($datenotinstring);
|
||||
}
|
||||
$value = (GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) ? dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min", 'int', 3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3)) : $datenotinstring;
|
||||
$value = (GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) ? dol_mktime(12, 0, 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3)) : $datenotinstring;
|
||||
}
|
||||
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('datetime')))
|
||||
{
|
||||
$datenotinstring = $this->array_options['options_'.$key];
|
||||
if (!is_numeric($this->array_options['options_'.$key])) // For backward compatibility
|
||||
{
|
||||
$datenotinstring = $this->db->jdate($datenotinstring);
|
||||
}
|
||||
$value = (GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) ? dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."sec", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3), 'tzuserrel') : $datenotinstring;
|
||||
}
|
||||
// Convert float submited string into real php numeric (value in memory must be a php numeric)
|
||||
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double')))
|
||||
|
||||
@ -1015,17 +1015,26 @@ class ExtraFields
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($type, array('date', 'datetime'))) {
|
||||
if (in_array($type, array('date'))) {
|
||||
$tmp = explode(',', $size);
|
||||
$newsize = $tmp[0];
|
||||
|
||||
$showtime = in_array($type, array('datetime')) ? 1 : 0;
|
||||
$showtime = 0;
|
||||
|
||||
// Do not show current date when field not required (see selectDate() method)
|
||||
if (!$required && $value == '') $value = '-1';
|
||||
|
||||
// TODO Must also support $moreparam
|
||||
$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
|
||||
} elseif (in_array($type, array('datetime'))) {
|
||||
$tmp = explode(',', $size);
|
||||
$newsize = $tmp[0];
|
||||
$showtime = 1;
|
||||
|
||||
// Do not show current date when field not required (see selectDate() method)
|
||||
if (!$required && $value == '') $value = '-1';
|
||||
|
||||
// TODO Must also support $moreparam
|
||||
$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1, '', '', '', 1, '', '', 'tzuserrel');
|
||||
} elseif (in_array($type, array('int', 'integer')))
|
||||
{
|
||||
$tmp = explode(',', $size);
|
||||
@ -1562,11 +1571,11 @@ class ExtraFields
|
||||
if ($type == 'date')
|
||||
{
|
||||
$showsize = 10;
|
||||
$value = dol_print_date($value, 'day');
|
||||
$value = dol_print_date($value, 'day'); // For date without hour, date is always GMT for storage and output
|
||||
} elseif ($type == 'datetime')
|
||||
{
|
||||
$showsize = 19;
|
||||
$value = dol_print_date($value, 'dayhour');
|
||||
$value = dol_print_date($value, 'dayhour', 'tzuserrel');
|
||||
} elseif ($type == 'int')
|
||||
{
|
||||
$showsize = 10;
|
||||
@ -2014,12 +2023,10 @@ class ExtraFields
|
||||
|
||||
if (in_array($key_type, array('date'))) {
|
||||
// Clean parameters
|
||||
// TODO GMT date in memory must be GMT so we should add gm=true in parameters
|
||||
$value_key = dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
|
||||
$value_key = dol_mktime(12, 0, 0, GETPOST("options_".$key."month", 'int'), GETPOST("options_".$key."day", 'int'), GETPOST("options_".$key."year", 'int'));
|
||||
} elseif (in_array($key_type, array('datetime'))) {
|
||||
// Clean parameters
|
||||
// TODO GMT date in memory must be GMT so we should add gm=true in parameters
|
||||
$value_key = dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
|
||||
$value_key = dol_mktime(GETPOST("options_".$key."hour", 'int'), GETPOST("options_".$key."min", 'int'), GETPOST("options_".$key."sec", 'int'), GETPOST("options_".$key."month", 'int'), GETPOST("options_".$key."day", 'int'), GETPOST("options_".$key."year", 'int'), 'tzuserrel');
|
||||
} elseif (in_array($key_type, array('checkbox', 'chkbxlst'))) {
|
||||
$value_arr = GETPOST("options_".$key, 'array'); // check if an array
|
||||
if (!empty($value_arr)) {
|
||||
@ -2086,13 +2093,15 @@ class ExtraFields
|
||||
$key_type = $this->attributes[$extrafieldsobjectkey]['type'][$key];
|
||||
}
|
||||
|
||||
if (in_array($key_type, array('date', 'datetime')))
|
||||
{
|
||||
if (in_array($key_type, array('date'))) {
|
||||
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) continue; // Value was not provided, we should not set it.
|
||||
// Clean parameters
|
||||
$value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'));
|
||||
} elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
|
||||
{
|
||||
$value_key = dol_mktime(12, 0, 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'));
|
||||
} elseif (in_array($key_type, array('datetime'))) {
|
||||
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) continue; // Value was not provided, we should not set it.
|
||||
// Clean parameters
|
||||
$value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."sec", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'), 'tzuserrel');
|
||||
} elseif (in_array($key_type, array('checkbox', 'chkbxlst'))) {
|
||||
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
|
||||
$value_arr = GETPOST($keysuffix."options_".$key.$keyprefix);
|
||||
// Make sure we get an array even if there's only one checkbox
|
||||
|
||||
@ -168,7 +168,7 @@ if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]
|
||||
print '<td id="'.$html_id.'" class="'.$object->element.'_extras_'.$tmpkeyextra.' wordbreak"'.($cols ? ' colspan="'.$cols.'"' : '').'>';
|
||||
|
||||
// Convert date into timestamp format
|
||||
if (in_array($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra], array('date', 'datetime')))
|
||||
if (in_array($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra], array('date')))
|
||||
{
|
||||
$datenotinstring = $object->array_options['options_'.$tmpkeyextra];
|
||||
// print 'X'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.'x';
|
||||
@ -177,7 +177,18 @@ if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]
|
||||
$datenotinstring = $db->jdate($datenotinstring);
|
||||
}
|
||||
//print 'x'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour');
|
||||
$value = GETPOSTISSET("options_".$tmpkeyextra) ? dol_mktime(GETPOST("options_".$tmpkeyextra."hour", 'int'), GETPOST("options_".$tmpkeyextra."min", 'int'), 0, GETPOST("options_".$tmpkeyextra."month", 'int'), GETPOST("options_".$tmpkeyextra."day", 'int'), GETPOST("options_".$tmpkeyextra."year", 'int')) : $datenotinstring;
|
||||
$value = GETPOSTISSET("options_".$tmpkeyextra) ? dol_mktime(12, 0, 0, GETPOST("options_".$tmpkeyextra."month", 'int'), GETPOST("options_".$tmpkeyextra."day", 'int'), GETPOST("options_".$tmpkeyextra."year", 'int')) : $datenotinstring;
|
||||
}
|
||||
if (in_array($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra], array('datetime')))
|
||||
{
|
||||
$datenotinstring = $object->array_options['options_'.$tmpkeyextra];
|
||||
// print 'X'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.'x';
|
||||
if (!is_numeric($object->array_options['options_'.$tmpkeyextra])) // For backward compatibility
|
||||
{
|
||||
$datenotinstring = $db->jdate($datenotinstring);
|
||||
}
|
||||
//print 'x'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour');
|
||||
$value = GETPOSTISSET("options_".$tmpkeyextra) ? dol_mktime(GETPOST("options_".$tmpkeyextra."hour", 'int'), GETPOST("options_".$tmpkeyextra."min", 'int'), GETPOST("options_".$tmpkeyextra."sec", 'int'), GETPOST("options_".$tmpkeyextra."month", 'int'), GETPOST("options_".$tmpkeyextra."day", 'int'), GETPOST("options_".$tmpkeyextra."year", 'int'), 'tzuserrel') : $datenotinstring;
|
||||
}
|
||||
|
||||
//TODO Improve element and rights detection
|
||||
|
||||
Loading…
Reference in New Issue
Block a user