diff --git a/main/admin/user_edit.php b/main/admin/user_edit.php index 88627130a5..3caef7025a 100755 --- a/main/admin/user_edit.php +++ b/main/admin/user_edit.php @@ -1,6 +1,8 @@ validate()) { api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id ); + Session::erase('system_timezone'); + Display::addFlash(Display::return_message($message, 'normal', false)); header('Location: user_list.php'); exit(); diff --git a/main/auth/profile.php b/main/auth/profile.php index 016a084d21..1fffd48523 100755 --- a/main/auth/profile.php +++ b/main/auth/profile.php @@ -26,7 +26,6 @@ $logInfo = [ 'tool_id' => 0, 'tool_id_detail' => 0, 'action' => $this_section, - 'info' => '', ]; Event::registerLog($logInfo); @@ -651,21 +650,19 @@ if ($form->validate()) { Session::write('_user', $userInfo); if ($hook) { - Database::getManager()->clear(User::class); //Avoid cache issue (user entity is used before) - - $user = api_get_user_entity(api_get_user_id()); //Get updated user info for hook event - + Database::getManager()->clear(User::class); // Avoid cache issue (user entity is used before) + $user = api_get_user_entity(api_get_user_id()); // Get updated user info for hook event $hook->setEventData(['user' => $user]); $hook->notifyUpdateUser(HOOK_EVENT_TYPE_POST); } + Session::erase('system_timezone'); + $url = api_get_self(); - header("Location: ".$url); + header("Location: $url"); exit; } -// the header - $actions = ''; if ($allowSocialTool) { if (api_get_setting('extended_profile') === 'true') { diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index 5f71e2ae6a..c0149895d9 100755 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -2,6 +2,7 @@ /* For licensing terms, see /license.txt */ use Patchwork\Utf8; +use ChamiloSession as Session; /** * File: internationalization.lib.php @@ -386,30 +387,33 @@ function api_get_timezones() */ function api_get_timezone() { - // First, get the default timezone of the server - $to_timezone = date_default_timezone_get(); - // Second, see if a timezone has been chosen for the platform - $timezone_value = api_get_setting('timezone_value', 'timezones'); + $timezone = Session::read('system_timezone'); + if (empty($timezone)) { + // First, get the default timezone of the server + $timezone = date_default_timezone_get(); + // Second, see if a timezone has been chosen for the platform + $timezoneFromSettings = api_get_setting('timezone_value', 'timezones'); - if ($timezone_value != null) { - $to_timezone = $timezone_value; - } - // If allowed by the administrator - $use_users_timezone = api_get_setting('use_users_timezone', 'timezones'); + if ($timezoneFromSettings != null) { + $timezone = $timezoneFromSettings; + } - if ($use_users_timezone === 'true') { - $userId = api_get_user_id(); - // Get the timezone based on user preference, if it exists - $timezone_user = UserManager::get_extra_user_data_by_field( - $userId, - 'timezone' - ); - if (isset($timezone_user['timezone']) && $timezone_user['timezone'] != null) { - $to_timezone = $timezone_user['timezone']; + // If allowed by the administrator + $allowUserTimezones = api_get_setting('use_users_timezone', 'timezones'); + + if ($allowUserTimezones === 'true') { + $userId = api_get_user_id(); + // Get the timezone based on user preference, if it exists + $newExtraField = new ExtraFieldValue('user'); + $data = $newExtraField->get_values_by_handler_and_field_variable($userId, 'timezone'); + if (!empty($data) && isset($data['timezone']) && !empty($data['timezone'])) { + $timezone = $data['timezone']; + } } + Session::write('system_timezone', $timezone); } - return $to_timezone; + return $timezone; } /**