diff --git a/html/main.php b/html/main.php index 47a3bfe4123867832ceb7b7b73974f2058ed695a..6699dc6ebea0ce867198c7e2fe1afff7c1460952 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 2828f161754d7bd42571521a9b014ae860478ddb..a91087625e3dba2ca2504d0284d26f7cd2ebda97 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -445,6 +445,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/password/class_password.inc b/plugins/personal/password/class_password.inc index 4d2446508c610ba789bf08fd345cfc304933552f..cced3ca9c76cd38493e1675a7577bc22b45a0da2 100644 --- a/plugins/personal/password/class_password.inc +++ b/plugins/personal/password/class_password.inc @@ -230,8 +230,8 @@ class password extends plugin $length = $policy['pwdMinLength'][0]; } if (isset($policy['pwdMinAge'][0]) && isset($attrs['pwdChangedTime'][0])) { - $date = DateTime::createFromFormat('YmdHis\Z', $attrs['pwdChangedTime'][0], new DateTimeZone('UTC')); - $now = new DateTime('now'); + $date = DateTime::createFromFormat('YmdHis\Z', $attrs['pwdChangedTime'][0], timezone::utc()); + $now = new DateTime('now', timezone::utc()); if ($now->getTimeStamp() < $date->getTimeStamp() + $policy['pwdMinAge'][0]) { return sprintf(_('You must wait %d seconds before changing your password again'), $policy['pwdMinAge'][0] - ($now->getTimeStamp() - $date->getTimeStamp())); } diff --git a/plugins/personal/posix/class_posixAccount.inc b/plugins/personal/posix/class_posixAccount.inc index ea039f112b9c09d43fa83793342b499509950d5a..2c09d23d29174c43842f8f9bbde5e2ea36e2ed59 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()); } }