mirror of
https://github.com/itflow-org/itflow
synced 2026-03-19 04:04:51 +00:00
SET SQL TIMEZONE on Session, this fixes the issue where created,deleted,updated,archived_ats using SQLs current_timestamp() are set to UTC-0 in SQL causing issues with displaying data in ITFlow as PHP is set to the timezone selected. Note its optional to set system timezone
This commit is contained in:
@@ -1,13 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Set Timezone to the companies timezone
|
// Check if timezone and offset are set in session
|
||||||
// 2024-02-08 JQ - The option to set the timezone in PHP was disabled to prevent inconsistencies with MariaDB/MySQL, which utilize the system's timezone, It is now consdered best practice to set the timezone on system itself
|
if (!isset($_SESSION['session_timezone']) || !isset($_SESSION['session_utc_offset'])) {
|
||||||
//date_default_timezone_set($session_timezone);
|
$result = mysqli_query($mysqli, "SELECT config_timezone FROM settings WHERE company_id = 1");
|
||||||
|
$row = mysqli_fetch_array($result);
|
||||||
|
$_SESSION['session_timezone'] = $row['config_timezone'];
|
||||||
|
|
||||||
// 2024-03-21 JQ - Re-Enabled Timezone setting as new PHP update does not respect System Time but defaulted to UTC
|
// Set PHP timezone
|
||||||
|
date_default_timezone_set($_SESSION['session_timezone']);
|
||||||
|
|
||||||
$sql_timezone = mysqli_query($mysqli, "SELECT config_timezone FROM settings WHERE company_id = 1");
|
// Calculate UTC offset and store it in session
|
||||||
$row_timezone = mysqli_fetch_array($sql_timezone);
|
$session_datetime = new DateTime('now', new DateTimeZone($_SESSION['session_timezone']));
|
||||||
$session_timezone = $row_timezone['config_timezone'];
|
$_SESSION['session_utc_offset'] = $session_datetime->format('P');
|
||||||
|
}
|
||||||
|
|
||||||
date_default_timezone_set($session_timezone);
|
// Use the stored timezone and offset
|
||||||
|
$session_timezone = $_SESSION['session_timezone'];
|
||||||
|
date_default_timezone_set($session_timezone);
|
||||||
|
|
||||||
|
// Set MySQL session time zone
|
||||||
|
mysqli_query($mysqli, "SET time_zone = '{$_SESSION['session_utc_offset']}'");
|
||||||
|
|||||||
Reference in New Issue
Block a user