openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 572ea0aba8c5c5b7854bcf89ddd6cabe8c38c6a7
parent 8dd082a65643add93c0944302fb3ea542ee1e057
Author: dankert <openrat@jandankert.de>
Date:   Wed,  9 Mar 2022 00:53:10 +0100

Fix: Setting the correct timezone from the user property.

Diffstat:
Mmodules/cms/action/Action.class.php | 6------
Mmodules/cms/action/profile/ProfileEditAction.class.php | 2+-
Mmodules/cms/action/user/UserPropAction.class.php | 2+-
Mmodules/cms/model/User.class.php | 4++--
Mmodules/cms/output/UIOutput.class.php | 45+++++++++++++++++++++++++++++++++++++++++----
Mmodules/template_engine/components/html/component_date/component-date.php | 7-------
6 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/modules/cms/action/Action.class.php b/modules/cms/action/Action.class.php @@ -315,12 +315,6 @@ abstract class Action const COOKIE_DB_ID = 'or_dbid'; /** - * Timezone offset - */ - const COOKIE_TIMEZONE_OFFSET = 'or_timezone_offset'; - - - /** * Sets a cookie. * * @param $name string cookie name diff --git a/modules/cms/action/profile/ProfileEditAction.class.php b/modules/cms/action/profile/ProfileEditAction.class.php @@ -22,7 +22,7 @@ class ProfileEditAction extends ProfileAction implements Method { $this->setTemplateVar( 'allstyles',$this->user->getAvailableStyles() ); - $this->setTemplateVar('timezone_list',timezone_identifiers_list() ); + $this->setTemplateVar('timezone_list',array_combine(timezone_identifiers_list(),timezone_identifiers_list()) ); $languageList = []; diff --git a/modules/cms/action/user/UserPropAction.class.php b/modules/cms/action/user/UserPropAction.class.php @@ -30,7 +30,7 @@ class UserPropAction extends UserAction implements Method { $this->setTemplateVar( 'allstyles',$this->user->getAvailableStyles() ); - $this->setTemplateVar('timezone_list',timezone_identifiers_list() ); + $this->setTemplateVar('timezone_list',array_combine(timezone_identifiers_list(),timezone_identifiers_list() )); $languages = Messages::$AVAILABLE_LANGUAGES; foreach($languages as $id=>$name) diff --git a/modules/cms/model/User.class.php b/modules/cms/model/User.class.php @@ -531,8 +531,8 @@ SQL $sql->setString ( 'desc' ,$this->desc ); $sql->setString ( 'mail' ,$this->mail ); $sql->setString ( 'style' ,$this->style ); - $sql->setString ( 'language',$this->language); - $sql->setString ( 'timezone',$this->timezone); + $sql->setStringOrNull( 'language',$this->language); + $sql->setStringOrNull( 'timezone',$this->timezone); $sql->setBoolean( 'isAdmin' ,$this->isAdmin ); $sql->setBoolean( 'totp' ,$this->totp ); $sql->setBoolean( 'hotp' ,$this->hotp ); diff --git a/modules/cms/output/UIOutput.class.php b/modules/cms/output/UIOutput.class.php @@ -4,7 +4,7 @@ namespace cms\output; use BadMethodCallException; use cms\action\RequestParams; -use cms\base\Language as L; +use cms\base\Configuration;use cms\base\Language as L; use cms\base\Startup;use cms\Dispatcher; use cms\output\BaseOutput; use Exception; @@ -57,8 +57,39 @@ class UIOutput extends BaseOutput } + + /** + * Sets the timezone so that dates in the UI are displayed in the correct timezone. + */ + protected static function setTimezone() { + + if ( $timezone = self::getCustomTimezone() ) { + + date_default_timezone_set( $timezone ); + + if ( DEVELOPMENT ) + header('X-OR-custom-timezone: '.$timezone ); + } + + // Default: Unchanged, so /etc/timezone or /etc/localtime is used by PHP. + } + + /** - * Executes and outputs a HTML template. + * Gets the custom timezone of the user or the configured timezone. + */ + protected static function getCustomTimezone() { + + $user = Session::getUser(); // the user timezone has precedence. + if ( $user && $user->timezone ) // user is set and a timezone is set + return( $user->timezone ); + else + return Configuration::subset('ui')->get('timezone'); + } + + + /** + * Executes and outputs an HTML template. * * @param $request RequestParams * @param $action string action @@ -75,8 +106,14 @@ class UIOutput extends BaseOutput $templateFile = Startup::MODULE_DIR . 'cms/ui/themes/default/html/views/' . $action.'/'.$subaction . '.php'; - if ( DEVELOPMENT ) - header('X-OR-Template: '.$templateFile); + if ( DEVELOPMENT ) { + header('X-OR-Template: '.$templateFile ); + + echo "<!-- \n".var_export($outputData,true)."\n-->"; + } + + + self::setTimezone(); $engine = new TemplateRunner(); //$engine->request = $request; diff --git a/modules/template_engine/components/html/component_date/component-date.php b/modules/template_engine/components/html/component_date/component-date.php @@ -11,13 +11,6 @@ function component_date($time ) echo Output::lang(Messages::UNKNOWN ); else { - // Benutzereinstellung 'Zeitzonen-Offset' auswerten. - if ( Cookie::has(Action::COOKIE_TIMEZONE_OFFSET) ) - { - $time -= (int)date('Z'); - $time += ( ((int)Cookie::get(Action::COOKIE_TIMEZONE_OFFSET))*60); - } - echo '<span class="or-table-sort-value">'.str_pad($time, 20, "0", STR_PAD_LEFT).'</span>'; // For sorting a table. echo '<time title="';