diff --git a/app/classes/user.php b/app/classes/user.php index ed6120a..9c2e11e 100644 --- a/app/classes/user.php +++ b/app/classes/user.php @@ -191,6 +191,7 @@ class User { $sql = 'UPDATE users_meta SET name = :name, email = :email, + timezone = :timezone, bio = :bio WHERE user_id = :user_id'; $query = $this->db->prepare($sql); @@ -198,6 +199,7 @@ class User { ':user_id' => $user_id, ':name' => $updatedUser['name'], ':email' => $updatedUser['email'], + ':timezone' => $updatedUser['timezone'], ':bio' => $updatedUser['bio'] ]); diff --git a/app/helpers/profile.php b/app/helpers/profile.php index c6f4ba8..ad4f53c 100644 --- a/app/helpers/profile.php +++ b/app/helpers/profile.php @@ -2,14 +2,19 @@ // get the UTC offset of a specified timezone function getUTCOffset($timezone) { - $datetime = new DateTime("now", new DateTimeZone($timezone)); - $offsetInSeconds = $datetime->getOffset(); + $formattedOffset = ''; + if (isset($timezone)) { - $hours = intdiv($offsetInSeconds, 3600); - $minutes = ($offsetInSeconds % 3600) / 60; - $formattedOffset = sprintf("UTC%+03d:%02d", $hours, $minutes); // Format UTC+01:00 + $datetime = new DateTime("now", new DateTimeZone($timezone)); + $offsetInSeconds = $datetime->getOffset(); + + $hours = intdiv($offsetInSeconds, 3600); + $minutes = ($offsetInSeconds % 3600) / 60; + $formattedOffset = sprintf("UTC%+03d:%02d", $hours, $minutes); // Format UTC+01:00 + } return $formattedOffset; + } ?> diff --git a/app/pages/profile.php b/app/pages/profile.php index ef944e1..879cc57 100644 --- a/app/pages/profile.php +++ b/app/pages/profile.php @@ -1,13 +1,6 @@ getUserId($user)[0]['id']; -//$userDetails = $userObject->getUserDetails($user_id); -//$userRights = $userObject->getUserRights($user_id); // if a form is submitted, it's from the edit page if ($_SERVER['REQUEST_METHOD'] == 'POST') { @@ -31,6 +24,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { $updatedUser = [ 'name' => $_POST['name'] ?? '', 'email' => $_POST['email'] ?? '', + 'timezone' => $_POST['timezone'] ?? '', 'bio' => $_POST['bio'] ?? '', ]; $result = $userObject->editUser($user_id, $updatedUser); @@ -76,6 +70,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { case 'edit': $allRights = $userObject->getAllRights(); + $allTimezones = timezone_identifiers_list(); + // if timezone is already set, we pass a flag for JS to not autodetect browser timezone + $isTimezoneSet = !empty($userDetails[0]['timezone']); include '../app/templates/profile-edit.php'; break; diff --git a/app/templates/page-sidebar.php b/app/templates/page-sidebar.php index cc40e0f..a9dc145 100644 --- a/app/templates/page-sidebar.php +++ b/app/templates/page-sidebar.php @@ -4,10 +4,7 @@
+