#13392 change timezone alerts graphs

This commit is contained in:
Jonathan 2024-04-10 10:08:52 +02:00
parent 2593241f66
commit 01de1456dc
2 changed files with 42 additions and 0 deletions

View File

@ -1126,3 +1126,29 @@ function user_print_header(int $pure=0, string $tab='user', ?string $title=null)
]
);
}
/**
* Returns the timezone of the user given or the actual one.
*
* @param mixed $id_user Id usuario (No give notingh return current user).
*
* @return string Return timezone of the user.
*/
function user_get_timezone($id_user=null)
{
global $config;
if (empty($id_user)) {
$id_user = $config['id_user'];
}
$timezone = db_get_value(
'timezone',
'tusuario',
'id_user',
$id_user
);
return $timezone;
}

View File

@ -344,6 +344,22 @@ function flot_area_graph(
// Trick to get translated string from javascript.
$return .= html_print_input_hidden('unknown_text', __('Unknown'), true);
if (isset($array_events_alerts)) {
$user_timezone = user_get_timezone();
if (isset($user_timezone) && $user_timezone !== '') {
foreach ($array_events_alerts as $key_event_alert => $event_alert) {
foreach ($event_alert as $key => $row) {
if (isset($row['timestamp']) === true) {
$timezone = new DateTimeZone($user_timezone);
$date = new DateTime();
$date->setTimestamp($row['utimestamp']);
$date->setTimezone($timezone);
$array_events_alerts[$key_event_alert][$key]['timestamp'] = $date->format('Y-m-d H:i:s');
}
}
}
}
}
$values = json_encode($array_data);