[ticket/14404] Set board & admin timezone based on browser timezone

PHPBB-14404
This commit is contained in:
Marc Alexander 2024-10-06 17:41:17 +02:00
parent ae8a5e791e
commit 36de1a49b1
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
4 changed files with 24 additions and 1 deletions

View file

@ -605,6 +605,8 @@
function interceptFormSubmit($form) {
if (!$form.length) {
return;
} else if ($form.find('input[name="admin_name"]').length > 0) {
setAdminTimezone($form);
}
$form.find(':submit').bind('click', function (event) {
@ -612,4 +614,20 @@
submitForm($form, $(this));
});
}
/**
* Set admin timezone in form
*
* @param $form
*/
function setAdminTimezone($form) {
// Set admin timezone if it does not exist yet
if ($form.find('input[name="admin_timezone"]').length === 0) {
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
// Add timezone as form entry
const timezoneEntry = $('<input type="hidden" name="admin_timezone" value="' + timeZone + '">');
$form.append(timezoneEntry);
}
}
})(jQuery); // Avoid conflicts with other libraries

View file

@ -132,6 +132,7 @@ class add_config_settings extends database_task
$updates = [
'board_startdate' => (string) $current_time,
'board_timezone' => $this->install_config->get('admin_timezone'),
'default_lang' => $this->install_config->get('default_lang'),
'server_name' => $this->install_config->get('server_name'),

View file

@ -114,7 +114,8 @@ class update_user_and_post_data extends database_task
. ' user_lang = :lang,'
. ' user_email = :email,'
. ' user_dateformat = :dateformat,'
. ' username_clean = :clean_username'
. ' username_clean = :clean_username,'
. ' user_timezone = :timezone'
. ' WHERE username = \'Admin\'';
$this->create_and_execute_prepared_stmt($sql, [
@ -125,6 +126,7 @@ class update_user_and_post_data extends database_task
'email' => $this->install_config->get('board_email'),
'dateformat' => $this->language->lang('default_dateformat'),
'clean_username' => utf8_clean_string($this->install_config->get('admin_name')),
'timezone' => $this->install_config->get('admin_timezone'),
]);
$this->exec_sql('UPDATE ' . $this->user_table . ' SET user_regdate = ' . $current_time);

View file

@ -71,6 +71,7 @@ class obtain_admin_data extends \phpbb\install\task_base implements \phpbb\insta
$admin_pass1 = $this->io_handler->get_input('admin_pass1', '', true);
$admin_pass2 = $this->io_handler->get_input('admin_pass2', '', true);
$board_email = $this->io_handler->get_input('board_email', '', true);
$admin_timezone = $this->io_handler->get_input('admin_timezone', 'UTC', true);
$admin_data_valid = $this->check_admin_data($admin_name, $admin_pass1, $admin_pass2, $board_email);
@ -79,6 +80,7 @@ class obtain_admin_data extends \phpbb\install\task_base implements \phpbb\insta
$this->install_config->set('admin_name', $admin_name);
$this->install_config->set('admin_passwd', $admin_pass1);
$this->install_config->set('board_email', $board_email);
$this->install_config->set('admin_timezone', $admin_timezone);
}
else
{