diff --git a/html/main.php b/html/main.php index a9f26ab05d0df2b6746a7d424828e2bf8f7fa550..bedec82dc198cf06411d8a2b5f545b95d30575ab 100644 --- a/html/main.php +++ b/html/main.php @@ -69,7 +69,7 @@ if (($config->get_cfg_value("forcessl") == "TRUE") && ($ssl != '')) { exit; } -timezone::get_default_timezone(); +timezone::setDefaultTimezoneFromConfig(); /* Check for invalid sessions */ if (session::global_get('_LAST_PAGE_REQUEST') == "") { diff --git a/include/class_config.inc b/include/class_config.inc index 2d14b25ab1d0702c98edcd62a66b0898aa096354..b8ec47f86ea1f949d1ed6a8a0c9d6b2a236e8d40 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -448,6 +448,8 @@ class config { session::global_set('DEBUGLEVEL', $debugLevel); IconTheme::loadThemes('themes'); + + timezone::setDefaultTimezoneFromConfig(); } diff --git a/include/class_timezone.inc b/include/class_timezone.inc index 9c371b240309aa5c0854abf99ee724cf34d7964a..5758ec1511a7cc25f8e2f6c6387e3f0043eeb3f7 100644 --- a/include/class_timezone.inc +++ b/include/class_timezone.inc @@ -29,44 +29,60 @@ * \brief This class contains all the function needed to manage the * timezones */ -class timezone { +class timezone +{ + /* + * \brief This function sets the default timezone according to fusiondirectory configuration. + * + * \return TRUE upon success, FALSEĆ otherwise + */ + static public function setDefaultTimezoneFromConfig() + { + global $config; + + /* Is there a timezone set in the fusiondirectory configuration */ + if ($config->get_cfg_value('timezone') != '') { + $tz = $config->get_cfg_value('timezone'); + + if (@date_default_timezone_set($tz)) { + return TRUE; + } else { + msg_dialog::display( + _('Configuration error'), + sprintf(_('The timezone setting "%s" in your configuration is not valid.'), $tz), + ERROR_DIALOG + ); + } + } + return FALSE; + } /* * \brief This function returns the offset for the default timezone. * + * deprecated * \param $stamp is used to detect summer or winter time. - * In case of PHP5, the integrated timezone functions are used. */ static public function get_default_timezone($stamp = NULL) { global $config; - $tz = ""; - - /* Default return value if zone could not be detected */ - $zone = array("name" => "unconfigured", "value" => 0); /* Use current timestamp if $stamp is not set */ if ($stamp === NULL) { $stamp = time(); } - /* Is there a timezone configured in the fusiondirectory configuration (fusiondirectory.conf) */ - if ($config->get_cfg_value("timezone") != "") { - /* Get zonename */ - $tz = $config->get_cfg_value("timezone"); - - if (!@date_default_timezone_set($tz)) { - msg_dialog::display(_("Configuration error"), sprintf(_("The timezone setting '%s' in your configuration is not valid. Cannot calculate correct timezone offset."), $tz), ERROR_DIALOG); - } - $tz_delta = date("Z", $stamp); + /* Is there a correct timezone set in the fusiondirectory configuration */ + if (self::setDefaultTimezoneFromConfig()) { + $tz = $config->get_cfg_value('timezone'); + $tz_delta = date('Z', $stamp); $tz_delta = $tz_delta / 3600; - return array("name" => $tz, "value" => $tz_delta); - + return array('name' => $tz, 'value' => $tz_delta); + } else { + return array('name' => 'unconfigured', 'value' => 0); } - return $zone; } - /* * \brief Get the time zone informations * @@ -76,5 +92,21 @@ class timezone { { return DateTimeZone::listIdentifiers(); } + + /* \brief Return default timezone as a DateTimeZone object */ + static public function getDefaultTimeZone() + { + return new DateTimeZone(date_default_timezone_get()); + } + + /* \brief Return UTC timezone as a DateTimeZone object */ + static public function utc() + { + static $utc; + if (!isset($utc)) { + $utc = new DateTimeZone('UTC'); + } + return $utc; + } } ?> diff --git a/plugins/personal/posix/class_posixAccount.inc b/plugins/personal/posix/class_posixAccount.inc index e7be445703fc2ff09740a0f813cddbcee0b90583..3baedc3cfa309eb7795dcbb09d7d84eacdc33b5f 100644 --- a/plugins/personal/posix/class_posixAccount.inc +++ b/plugins/personal/posix/class_posixAccount.inc @@ -41,12 +41,12 @@ class EpochDaysDateAttribute extends DateAttribute protected function ldapToDate($ldapValue) { - $date = DateTime::createFromFormat('U', $ldapValue * self::$secondsPerDay, new DateTimeZone('UTC')); + $date = DateTime::createFromFormat('U', $ldapValue * self::$secondsPerDay, timezone::utc()); if ($date !== FALSE) { return $date; } else { trigger_error('LDAP value for '.$this->getLdapName().' was not in the right date format.'); - return new DateTime($ldapValue, new DateTimeZone('UTC')); + return new DateTime($ldapValue, timezone::utc()); } }