";
}
diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php
index a1800e03980..3191e5edd47 100644
--- a/htdocs/core/class/conf.class.php
+++ b/htdocs/core/class/conf.class.php
@@ -102,6 +102,8 @@ class Conf
public $liste_limit;
+ public $tzuserinputkey = 'tzserver'; // Use 'tzuserrel' to always store date in GMT and show date in time zone of user.
+
/**
* Constructor
@@ -693,6 +695,8 @@ class Conf
if (defined('MAIN_ANTIVIRUS_COMMAND')) $this->global->MAIN_ANTIVIRUS_COMMAND = constant('MAIN_ANTIVIRUS_COMMAND');
if (defined('MAIN_ANTIVIRUS_PARAM')) $this->global->MAIN_ANTIVIRUS_PARAM = constant('MAIN_ANTIVIRUS_PARAM');
+ if (!empty($this->global->MAIN_TZUSERINPUTKEY)) $this->tzuserinputkey = $this->global->MAIN_TZUSERINPUTKEY; // 'tzserver' or 'tzuserrel'
+
// For backward compatibility
if (isset($this->product)) $this->produit = $this->product;
if (isset($this->facture)) $this->invoice = $this->facture;
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 20721b8ea05..6f2cbcd1955 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -5532,13 +5532,18 @@ class Form
* @param int $stepminutes Specify step for minutes between 1 and 30
* @param string $labeladddateof Label to use for the $adddateof parameter.
* @param string $placeholder Placeholder
+ * @param mixed $gm 'auto', 'gmt' or 'tzserver' or 'tzuserrel'
* @return string Html for selectDate
* @see form_date(), select_month(), select_year(), select_dayofweek()
*/
- public function selectDate($set_time = '', $prefix = 're', $h = 0, $m = 0, $empty = 0, $form_name = "", $d = 1, $addnowlink = 0, $disabled = 0, $fullday = '', $addplusone = '', $adddateof = '', $openinghours = '', $stepminutes = 1, $labeladddateof = '', $placeholder = '')
+ public function selectDate($set_time = '', $prefix = 're', $h = 0, $m = 0, $empty = 0, $form_name = "", $d = 1, $addnowlink = 0, $disabled = 0, $fullday = '', $addplusone = '', $adddateof = '', $openinghours = '', $stepminutes = 1, $labeladddateof = '', $placeholder = '', $gm = 'auto')
{
global $conf, $langs;
+ if ($gm == 'auto') {
+ $gm = $conf->tzuserinputkey;
+ }
+
$retstring = '';
if ($prefix == '') $prefix = 're';
@@ -5554,7 +5559,11 @@ class Form
if ($set_time === '' && $emptydate == 0)
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
- $set_time = dol_now('tzuser') - (getServerTimeZoneInt('now') * 3600); // set_time must be relative to PHP server timezone
+ if ($gm == 'tzuser' || $gm == 'tzuserrel') {
+ $set_time = dol_now($gm);
+ } else {
+ $set_time = dol_now('tzuser') - (getServerTimeZoneInt('now') * 3600); // set_time must be relative to PHP server timezone
+ }
}
// Analysis of the pre-selection date
@@ -5570,14 +5579,14 @@ class Form
} elseif (strval($set_time) != '' && $set_time != -1)
{
// set_time est un timestamps (0 possible)
- $syear = dol_print_date($set_time, "%Y");
- $smonth = dol_print_date($set_time, "%m");
- $sday = dol_print_date($set_time, "%d");
+ $syear = dol_print_date($set_time, "%Y", $gm);
+ $smonth = dol_print_date($set_time, "%m", $gm);
+ $sday = dol_print_date($set_time, "%d", $gm);
if ($orig_set_time != '')
{
- $shour = dol_print_date($set_time, "%H");
- $smin = dol_print_date($set_time, "%M");
- $ssec = dol_print_date($set_time, "%S");
+ $shour = dol_print_date($set_time, "%H", $gm);
+ $smin = dol_print_date($set_time, "%M", $gm);
+ $ssec = dol_print_date($set_time, "%S", $gm);
} else {
$shour = '';
$smin = '';
diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php
index 48bcbab6f3e..e900af925f4 100644
--- a/htdocs/core/db/DoliDB.class.php
+++ b/htdocs/core/db/DoliDB.class.php
@@ -84,13 +84,14 @@ abstract class DoliDB implements Database
* Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
* Function to use to build INSERT, UPDATE or WHERE predica
*
- * @param int $param Date TMS to convert
- * @return string Date in a string YYYY-MM-DD HH:MM:SS
+ * @param int $param Date TMS to convert
+ * @param mixed $gm 'gmt'=Input informations are GMT values, 'tzserver'=Local to server TZ
+ * @return string Date in a string YYYY-MM-DD HH:MM:SS
*/
- public function idate($param)
+ public function idate($param, $gm = 'tzserver')
{
- // TODO GMT $param should be gmt, so we should add tzouptut to 'gmt'
- return dol_print_date($param, "%Y-%m-%d %H:%M:%S", 'tzserver');
+ // TODO $param should be gmt, so we should add $gm to 'gmt' instead of default 'tzserver'
+ return dol_print_date($param, "%Y-%m-%d %H:%M:%S", $gm);
}
/**
@@ -285,12 +286,12 @@ abstract class DoliDB implements Database
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
- * @param bool $gm 1=Input informations are GMT values, otherwise local to server TZ
+ * @param mixed $gm 'gmt'=Input informations are GMT values, 'tzserver'=Local to server TZ
* @return int|string Date TMS or ''
*/
- public function jdate($string, $gm = false)
+ public function jdate($string, $gm = 'tzserver')
{
- // TODO GMT must set param gm to true by default
+ // TODO $string should be converted into a GMT timestamp, so param gm should be set to true by default instead of false
if ($string == 0 || $string == "0000-00-00 00:00:00") return '';
$string = preg_replace('/([^0-9])/i', '', $string);
$tmp = $string.'000000';
diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php
index b393945eeb3..fe80f1ad28e 100644
--- a/htdocs/core/db/pgsql.class.php
+++ b/htdocs/core/db/pgsql.class.php
@@ -685,18 +685,6 @@ class DoliDBPgsql extends DoliDB
return pg_escape_string($stringtoencode);
}
- /**
- * Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field.
- * Function to use to build INSERT, UPDATE or WHERE predica
- *
- * @param string $param Date TMS to convert
- * @return string Date in a string YYYY-MM-DD HH:MM:SS
- */
- public function idate($param)
- {
- return dol_print_date($param, "%Y-%m-%d %H:%M:%S");
- }
-
/**
* Format a SQL IF
*
diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php
index 13f59c45ba8..f3faeda4b3a 100644
--- a/htdocs/core/lib/admin.lib.php
+++ b/htdocs/core/lib/admin.lib.php
@@ -1438,9 +1438,15 @@ function complete_elementList_with_modules(&$elementList)
$dirmod[$i] = $dir;
//print "x".$modName." ".$orders[$i]."\n ";
- if (!empty($objMod->module_parts['contactelement'])) {
- $elementList[$objMod->name] = $langs->trans($objMod->name);
- }
+ if (!empty($objMod->module_parts['contactelement'])) {
+ if (is_array($objMod->module_parts['contactelement'])) {
+ foreach ($objMod->module_parts['contactelement'] as $elem => $title) {
+ $elementList[$elem] = $langs->trans($title);
+ }
+ } else {
+ $elementList[$objMod->name] = $langs->trans($objMod->name);
+ }
+ }
$j++;
$i++;
diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php
index 163f6d85b6d..3a889367dc1 100644
--- a/htdocs/core/lib/date.lib.php
+++ b/htdocs/core/lib/date.lib.php
@@ -465,9 +465,10 @@ function dol_get_next_week($day, $week, $month, $year)
*
* @param int $year Year
* @param int $month Month
- * @param mixed $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
- * Exemple: dol_get_first_day(1970,1,false) will return -3600 with TZ+1, a dol_print_date on it will return 1970-01-01 00:00:00
- * Exemple: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, a dol_print_date on it will return 1970-01-01 00:00:00
+ * @param mixed $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
+ * True or 1 or 'gmt' to compare with GMT date.
+ * Example: dol_get_first_day(1970,1,false) will return -3600 with TZ+1, a dol_print_date on it will return 1970-01-01 00:00:00
+ * Example: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, a dol_print_date on it will return 1970-01-01 00:00:00
* @return int Date for first day, '' if error
*/
function dol_get_first_day($year, $month = 1, $gm = false)
@@ -481,7 +482,8 @@ function dol_get_first_day($year, $month = 1, $gm = false)
*
* @param int $year Year
* @param int $month Month
- * @param boolean $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
+ * @param mixed $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
+ * True or 1 or 'gmt' to compare with GMT date.
* @return int Date for first day, '' if error
*/
function dol_get_last_day($year, $month = 12, $gm = false)
@@ -529,7 +531,8 @@ function dol_get_first_hour($date)
* @param int $day Day
* @param int $month Month
* @param int $year Year
- * @param int $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
+ * @param mixed $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
+ * True or 1 or 'gmt' to compare with GMT date.
* @return array year,month,week,first_day,first_month,first_year,prev_day,prev_month,prev_year
*/
function dol_get_first_day_week($day, $month, $year, $gm = false)
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 8c1765620ec..e1d64da77f1 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -1971,10 +1971,14 @@ function dol_strftime($fmt, $ts = false, $is_gmt = false)
*
* @see dol_mktime(), dol_stringtotime(), dol_getdate()
*/
-function dol_print_date($time, $format = '', $tzoutput = 'tzserver', $outputlangs = '', $encodetooutput = false)
+function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = '', $encodetooutput = false)
{
global $conf, $langs;
+ if ($tzoutput == 'auto') {
+ $tzoutput = $conf->tzuserinputkey;
+ }
+
// Clean parameters
$to_gmt = false;
$offsettz = $offsetdst = 0;
@@ -2183,18 +2187,24 @@ function dol_getdate($timestamp, $fast = false, $forcetimezone = '')
* @param int $day Day (1 to 31)
* @param int $year Year
* @param mixed $gm True or 1 or 'gmt'=Input informations are GMT values
- * False or 0 or 'server' = local to server TZ
- * 'user' = local to user TZ
+ * False or 0 or 'tzserver' = local to server TZ
+ * 'auto'
+ * 'tzuser' = local to user TZ taking dst into account at the current date. Not yet implemented.
+ * 'tzuserrel' = local to user TZ taking dst into account at the given date. Use this one to convert date input from user.
* 'tz,TimeZone' = use specified timezone
* @param int $check 0=No check on parameters (Can use day 32, etc...)
* @return int|string Date as a timestamp, '' or false if error
* @see dol_print_date(), dol_stringtotime(), dol_getdate()
*/
-function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = false, $check = 1)
+function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = 'auto', $check = 1)
{
global $conf;
//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
+ if ($gm == 'auto') {
+ $gm = $conf->tzuserinputkey;
+ }
+
// Clean parameters
if ($hour == -1 || empty($hour)) $hour = 0;
if ($minute == -1 || empty($minute)) $minute = 0;
@@ -2211,11 +2221,11 @@ function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = false, $
if ($second < 0 || $second > 60) return '';
}
- if (empty($gm) || $gm === 'server')
+ if (empty($gm) || ($gm === 'server' || $gm === 'tzserver'))
{
$default_timezone = @date_default_timezone_get(); // Example 'Europe/Berlin'
$localtz = new DateTimeZone($default_timezone);
- } elseif ($gm === 'user')
+ } elseif ($gm === 'user' || $gm === 'tzuser' || $gm === 'tzuserrel')
{
// We use dol_tz_string first because it is more reliable.
$default_timezone = (empty($_SESSION["dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION["dol_tz_string"]); // Example 'Europe/Berlin'
@@ -2254,16 +2264,21 @@ function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = false, $
/**
* Return date for now. In most cases, we use this function without parameters (that means GMT time).
*
- * @param string $mode 'gmt' => we return GMT timestamp,
+ * @param string $mode 'auto'
+ * 'gmt' => we return GMT timestamp,
* 'tzserver' => we add the PHP server timezone
- * 'tzref' => we add the company timezone
- * 'tzuser' => we add the user timezone
+ * 'tzref' => we add the company timezone. Not implemented.
+ * 'tzuser' or 'tzuserrel' => we add the user timezone
* @return int $date Timestamp
*/
-function dol_now($mode = 'gmt')
+function dol_now($mode = 'auto')
{
$ret = 0;
+ if ($mode == 'auto') {
+ $mode = 'tzserver';
+ }
+
if ($mode == 'gmt') $ret = time(); // Time for now at greenwich.
elseif ($mode == 'tzserver') // Time for now with PHP server timezone added
{
@@ -2276,7 +2291,7 @@ function dol_now($mode = 'gmt')
$tzsecond=getParentCompanyTimeZoneInt(); // Contains tz+dayling saving time
$ret=dol_now('gmt')+($tzsecond*3600);
}*/
- elseif ($mode == 'tzuser') // Time for now with user timezone added
+ elseif ($mode == 'tzuser' || $mode == 'tzuserrel') // Time for now with user timezone added
{
//print 'time: '.time();
$offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60;
diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php
index a77f38f8f66..ffc79b8f4b4 100644
--- a/htdocs/core/lib/functions2.lib.php
+++ b/htdocs/core/lib/functions2.lib.php
@@ -246,8 +246,8 @@ function dol_print_object_info($object, $usetable = 0)
print $langs->trans("DateCreation");
if ($usetable) print '