Added a lot of fixes to the dates stored as strings without timezone information to made them use the user timezone

This commit is contained in:
Alejandro Gallardo Escobar 2018-06-11 16:40:10 +02:00
parent dcdce9c8fc
commit fac3e21829
26 changed files with 258 additions and 146 deletions

View File

@ -25,7 +25,7 @@ function createXMLData($agent, $agentModule, $time, $data) {
$xmlTemplate = "<?xml version='1.0' encoding='UTF-8'?>
<agent_data description='' group='' os_name='%s' " .
" os_version='%s' interval='%d' version='%s' timestamp='%s' agent_name='%s' timezone_offset='%d'>
" os_version='%s' interval='%d' version='%s' timestamp='%s' agent_name='%s' timezone_offset='0'>
<module>
<name><![CDATA[%s]]></name>
<description><![CDATA[%s]]></description>
@ -34,20 +34,22 @@ function createXMLData($agent, $agentModule, $time, $data) {
</module>
</agent_data>";
$xml = sprintf($xmlTemplate, io_safe_output(get_os_name($agent['id_os'])),
io_safe_output($agent['os_version']), $agent['intervalo'],
io_safe_output($agent['agent_version']), $time,
$xml = sprintf(
$xmlTemplate,
io_safe_output(get_os_name($agent['id_os'])),
io_safe_output($agent['os_version']),
$agent['intervalo'],
io_safe_output($agent['agent_version']),
$time,
io_safe_output($agent['nombre']),
$agent['timezone_offset'],
io_safe_output($agentModule['nombre']), io_safe_output($agentModule['descripcion']), modules_get_type_name($agentModule['id_tipo_modulo']), $data);
if (false === @file_put_contents($config['remote_config'] . '/' . io_safe_output($agent['alias']) . '.' . strtotime($time) . '.data', $xml)) {
return false;
}
else {
return true;
}
io_safe_output($agentModule['nombre']),
io_safe_output($agentModule['descripcion']),
modules_get_type_name($agentModule['id_tipo_modulo']),
$data
);
$file_name = $config["remote_config"] . "/" . io_safe_output($agent["alias"]) . "." . str_replace($time, " ", "_") . ".data";
return (bool) @file_put_contents($file_name, $xml);
}
function mainInsertData() {
@ -61,18 +63,12 @@ function mainInsertData() {
return;
}
$save = (bool)get_parameter('save', false);
$id_agent = (string)get_parameter('id_agent', '');
$save = (bool) get_parameter("save");
$agent_id = (int) get_parameter("agent_id");
$agent_name = (string) get_parameter("agent_name");
foreach ($_POST as $key => $value) {
if(strpos($key,"agent_autocomplete_idagent")!== false){
$id_agente = $value;
}
}
$id_agent_module = (int)get_parameter('id_agent_module', '');
$data = (string)get_parameter('data');
$id_agent_module = (int) get_parameter("id_agent_module");
$data = (string) get_parameter('data');
$date = (string) get_parameter('date', date(DATE_FORMAT));
$time = (string) get_parameter('time', date(TIME_FORMAT));
if (isset($_FILES['csv'])) {
@ -89,12 +85,11 @@ function mainInsertData() {
if ($save) {
if (!check_acl($config['id_user'], agents_get_agent_group(agents_get_agent_id($id_agent)), "AW")) {
if (!check_acl($config['id_user'], agents_get_agent_group($agent_id), "AW")) {
ui_print_error_message(__('You haven\'t privileges for insert data in the agent.'));
}
else {
$agent = db_get_row_filter('tagente', array('id_agente' => $id_agente));
$agent = db_get_row_filter('tagente', array('id_agente' => $agent_id));
$agentModule = db_get_row_filter('tagente_modulo', array('id_agente_modulo' => $id_agent_module));
$done = 0;
@ -104,7 +99,9 @@ function mainInsertData() {
foreach ($file as $line) {
$tokens = explode(';', $line);
$result = createXMLData($agent, $agentModule, trim($tokens[0]), trim($tokens[1]));
$utimestamp = strtotime(trim($tokens[0])) - get_fixed_offset();
$timestamp = date(DATE_FORMAT . " " . TIME_FORMAT, $utimestamp);
$result = createXMLData($agent, $agentModule, $timestamp, trim($tokens[1]));
if ($result) {
$done++;
@ -115,7 +112,9 @@ function mainInsertData() {
}
}
else {
$result = createXMLData($agent, $agentModule, $date . ' ' . $time, $data);
$utimestamp = strtotime($date . " " . $time) - get_fixed_offset();
$timestamp = date(DATE_FORMAT . " " . TIME_FORMAT, $utimestamp);
$result = createXMLData($agent, $agentModule, $timestamp, $data);
if ($result) {
$done++;
@ -159,14 +158,16 @@ function mainInsertData() {
$params = array();
$params['return'] = true;
$params['show_helptip'] = true;
$params['input_name'] = 'id_agent';
$params['value'] = $id_agent;
$params['input_name'] = 'agent_name';
$params['value'] = $agent_name;
$params['javascript_is_function_select'] = true;
$params['javascript_name_function_select'] = 'custom_select_function';
$params['javascript_code_function_select'] = '';
$params['use_hidden_input_idagent'] = true;
$params['print_hidden_input_idagent'] = true;
$params['hidden_input_idagent_id'] = 'hidden-autocomplete_id_agent';
$params['hidden_input_idagent_name'] = 'agent_id';
$params['hidden_input_idagent_value'] = $agent_id;
$table->data[0][1] = ui_print_agent_autocomplete_input($params);

View File

@ -232,7 +232,8 @@ foreach ($result as $row) {
$data = array();
$data[0] = $row["id_usuario"];
$data[1] = ui_print_session_action_icon($row["accion"], true) . $row["accion"];
$data[2] = ui_print_help_tip($row["fecha"], true) . ui_print_timestamp($row["utimestamp"], true);
$data[2] = ui_print_help_tip(date($config["date_format"], $row["utimestamp"]), true)
. ui_print_timestamp($row["utimestamp"], true);
$data[3] = $row["ip_origen"];
$data[4] = $row["descripcion"];

View File

@ -60,15 +60,19 @@ $type_downtime = (string) get_parameter('type_downtime', 'quiet');
$type_execution = (string) get_parameter('type_execution', 'once');
$type_periodicity = (string) get_parameter('type_periodicity', 'weekly');
$once_date_from = (string) get_parameter ('once_date_from', date(DATE_FORMAT));
$once_time_from = (string) get_parameter ('once_time_from', date(TIME_FORMAT));
$once_date_to = (string) get_parameter ('once_date_to', date(DATE_FORMAT));
$once_time_to = (string) get_parameter ('once_time_to', date(TIME_FORMAT, time() + SECONDS_1HOUR));
$utimestamp = get_system_time();
// Fake utimestamp to retrieve the string date of the system
$system_time = $utimestamp - get_fixed_offset();
$once_date_from = (string) get_parameter ('once_date_from', date(DATE_FORMAT, $utimestamp));
$once_time_from = (string) get_parameter ('once_time_from', date(TIME_FORMAT, $utimestamp));
$once_date_to = (string) get_parameter ('once_date_to', date(DATE_FORMAT, $utimestamp));
$once_time_to = (string) get_parameter ('once_time_to', date(TIME_FORMAT, $utimestamp + SECONDS_1HOUR));
$periodically_day_from = (int) get_parameter ('periodically_day_from', 1);
$periodically_day_to = (int) get_parameter ('periodically_day_to', 31);
$periodically_time_from = (string) get_parameter ('periodically_time_from', date(TIME_FORMAT));
$periodically_time_to = (string) get_parameter ('periodically_time_to', date(TIME_FORMAT, time() + SECONDS_1HOUR));
$periodically_time_from = (string) get_parameter ('periodically_time_from', date(TIME_FORMAT, $system_time));
$periodically_time_to = (string) get_parameter ('periodically_time_to', date(TIME_FORMAT, $system_time + SECONDS_1HOUR));
$monday = (bool) get_parameter ('monday');
$tuesday = (bool) get_parameter ('tuesday');
@ -542,6 +546,7 @@ $table->data[5][1] = "
</div>
<div id='periodically_time' style='display: none;'>
<table>
<tr><td>" . ui_get_using_system_timezone_warning() . "</td></tr>
<tr>
<td>" . __('Type Periodicity:') . "&nbsp;".
html_print_select(array(
@ -1226,7 +1231,7 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
// Warning message about the problems caused updating a past planned downtime
var type_execution = "<?php echo $type_execution; ?>";
var datetime_from = <?php echo json_encode(strtotime($once_date_from . ' ' . $once_time_from)); ?>;
var datetime_now = <?php echo json_encode(strtotime(date(DATE_FORMAT). ' ' . date(TIME_FORMAT))); ?>;
var datetime_now = <?php echo json_encode($utimestamp); ?>;
var create = <?php echo json_encode($create); ?>;
if (!create && (type_execution == 'periodically' || (type_execution == 'once' && datetime_from < datetime_now))) {
$("input#submit-updbutton, input#submit-add_item, table#list a").click(function (e) {

View File

@ -782,6 +782,10 @@ else {
}
}
if ($step == 2) {
echo ui_get_using_system_timezone_warning();
}
/* If it's the last step it will redirect to template lists */
if ($step >= LAST_STEP) {
echo '<form method="post" action="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_templates&pure='.$pure.'">';

View File

@ -202,7 +202,7 @@ switch ($action) {
$dyn_height = $style['dyn_height'];
$type = $item['type'];
$name = $item['name'];
switch ($type) {
case 'event_report_log':
$period = $item['period'];
@ -839,6 +839,7 @@ You can of course remove the warnings, that's why we include the source and do n
<?php echo __('Working time');?>
</td>
<td>
<?php echo ui_get_using_system_timezone_warning(); ?>
<table border="0">
<tr>
<td>

View File

@ -87,7 +87,7 @@ foreach ($servers as $server) {
//Status
$data[1] = ui_print_status_image (STATUS_SERVER_OK, '', true);
if (($server['status'] == 0) || (($date - strtotime($server['keepalive'])) > ($server['server_keepalive'])*2)) {
if (($server['status'] == 0) || (($date - time_w_fixed_tz($server['keepalive'])) > ($server['server_keepalive'])*2)) {
$data[1] = ui_print_status_image (STATUS_SERVER_DOWN, '', true);
}

View File

@ -36,10 +36,11 @@ if (isset ($_POST["create"])) { // If create
$id_group = get_parameter ("id_group");
$modal = get_parameter ("modal");
$expire = get_parameter ("expire");
$expire_date = get_parameter ("expire_date");
$expire_date = date('Y-m-d', strtotime($expire_date));
$expire_time = get_parameter ("expire_time");
$expire_timestamp = "$expire_date $expire_time";
$expire_date = get_parameter("expire_date");
$expire_time = get_parameter("expire_time");
// Change the user's timezone to the system's timezone
$expire_timestamp = strtotime("$expire_date $expire_time") - get_fixed_offset();
$expire_timestamp = date("Y-m-d H:i:s", $expire_timestamp);
$values = array('subject' => $subject,
'text' => $text,
@ -64,10 +65,11 @@ if (isset ($_POST["update"])) { // if update
$id_group = get_parameter ("id_group");
$modal = get_parameter ("modal");
$expire = get_parameter ("expire");
$expire_date = get_parameter ("expire_date");
$expire_date = date('Y-m-d', strtotime($expire_date));
$expire_time = get_parameter ("expire_time");
$expire_timestamp = "$expire_date $expire_time";
$expire_date = get_parameter("expire_date");
$expire_time = get_parameter("expire_time");
// Change the user's timezone to the system's timezone
$expire_timestamp = strtotime("$expire_date $expire_time") - get_fixed_offset();
$expire_timestamp = date("Y-m-d H:i:s", $expire_timestamp);
//NOW() column exists in any table and always displays the current date and time, so let's get the value from a row in a table which can't be deleted.
//This way we prevent getting no value for this variable
@ -117,10 +119,10 @@ if ((isset ($_GET["form_add"])) || (isset ($_GET["form_edit"]))) {
if ($expire) {
$expire_timestamp = $result["expire_timestamp"];
$expire_utimestamp = strtotime($expire_timestamp);
$expire_utimestamp = time_w_fixed_tz($expire_timestamp);
}
else {
$expire_utimestamp = time() + SECONDS_1WEEK;
$expire_utimestamp = get_system_time() + SECONDS_1WEEK;
}
$expire_date = date('Y/m/d', $expire_utimestamp);
@ -138,8 +140,8 @@ if ((isset ($_GET["form_add"])) || (isset ($_GET["form_edit"]))) {
$id_group = 0;
$modal = 0;
$expire = 0;
$expire_date = date('Y/m/d', time() + SECONDS_1WEEK);
$expire_time = date('H:i:s', time());
$expire_date = date('Y/m/d', get_system_time() + SECONDS_1WEEK);
$expire_time = date('H:i:s', get_system_time());
}
// Create news
@ -246,10 +248,10 @@ else {
}
echo "<td class='$tdcolor'>".$row["author"]."</b></td>";
$utimestamp = strtotime($row["timestamp"]);
echo "<td class='$tdcolor'>" . date($config['date_format'], strtotime($row["timestamp"])) . "</b></td>";
$utimestamp = time_w_fixed_tz($row["timestamp"]);
echo "<td class='$tdcolor'>" . date($config['date_format'], $utimestamp) . "</b></td>";
if ($row["expire"]) {
$expire_utimestamp = strtotime($row["expire_timestamp"]);
$expire_utimestamp = time_w_fixed_tz($row["expire_timestamp"]);
$expire_in_secs = $expire_utimestamp - $utimestamp;
if( $expire_in_secs <= 0) {

View File

@ -126,6 +126,7 @@ if ($new_user && $config['admin_can_add_user']) {
$user_info['comments'] = '';
$user_info['is_admin'] = 0;
$user_info['language'] = 'default';
$user_info['timezone'] = '';
$user_info["not_login"] = false;
$user_info["strict_acl"] = false;
$user_info["session_time"] = 0;
@ -164,6 +165,7 @@ if ($create_user) {
$values['comments'] = (string) get_parameter ('comments');
$values['is_admin'] = (int) get_parameter ('is_admin', 0);
$values['language'] = get_parameter ('language', 'default');
$values['timezone'] = (string) get_parameter('timezone');
$values['default_event_filter'] = (int) get_parameter('default_event_filter');
$dashboard = get_parameter('dashboard', '');
$visual_console = get_parameter('visual_console', '');
@ -222,7 +224,7 @@ if ($create_user) {
}
else {
$info =
'{"Id_user":"' . $values['id_user'] . '","FullName":"' . $values['fullname'] . '","Firstname":"'. $values['firstname'] .'","Lastname":"'. $values['lastname'] . '","Email":"' . $values['email'] . '","Phone":"' . $values['phone'] . '","Comments":"' . $values['comments'] .'","Is_admin":"' . $values['is_admin'] .'","Language":"' . $values['language'] . '","Block size":"' . $values['block_size'] . '","Interactive Charts":"' . $values['flash_chart'].'"';
'{"Id_user":"' . $values['id_user'] . '","FullName":"' . $values['fullname'] . '","Firstname":"'. $values['firstname'] .'","Lastname":"'. $values['lastname'] . '","Email":"' . $values['email'] . '","Phone":"' . $values['phone'] . '","Comments":"' . $values['comments'] .'","Is_admin":"' . $values['is_admin'] .'","Language":"' . $values['language'] .'","Timezone":"' . $values['timezone'] . '","Block size":"' . $values['block_size'] . '","Interactive Charts":"' . $values['flash_chart'].'"';
if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) {
$info .= ',"Skin":"' . $values['id_skin'].'"}';
@ -287,6 +289,7 @@ if ($update_user) {
$values['comments'] = (string) get_parameter ('comments');
$values['is_admin'] = get_parameter ('is_admin', 0 );
$values['language'] = (string) get_parameter ('language');
$values['timezone'] = (string) get_parameter('timezone');
$values['default_event_filter'] = (int) get_parameter('default_event_filter');
$dashboard = get_parameter('dashboard', '');
$visual_console = get_parameter('visual_console', '');
@ -376,6 +379,7 @@ if ($update_user) {
"Comments":"' . $values['comments'] . '",
"Is_admin":"' . $values['is_admin'] . '",
"Language":"' . $values['language'] . '",
"Timezone":"' . $values['timezone'] . '",
"Block size":"' . $values['block_size'] . '",
"Flash Chats":"' . $values['flash_chart'] . '",
"Section":"' . $values['section'].'"';
@ -522,6 +526,9 @@ $table->data[2][0] = __('Language');
$table->data[2][1] = html_print_select_from_sql ('SELECT id_language, name FROM tlanguage',
'language', $user_info['language'], '', __('Default'), 'default', true);
$table->data[3][0] = __('Timezone');
$table->data[3][1] = html_print_timezone_select("timezone", $user_info["timezone"]);
if ($config['user_can_update_password']) {
$table->data[4][0] = __('Password');
$table->data[4][1] = html_print_input_text_extended ('password_new', '', '', '',

View File

@ -118,13 +118,14 @@ if ($get_module_detail) {
$conexion = false;
}
$selection_mode = get_parameter('selection_mode', 'fromnow');
$date_from = (string) get_parameter ('date_from', date ('Y-m-j'));
$time_from = (string) get_parameter ('time_from', date ('h:iA'));
$date_to = (string) get_parameter ('date_to', date ('Y-m-j'));
$time_to = (string) get_parameter ('time_to', date ('h:iA'));
$freesearch = (string) get_parameter ('freesearch', '');
$free_checkbox = (bool) get_parameter ('free_checkbox', false);
$selection_mode = get_parameter('selection_mode', 'fromnow');
$utimestamp = get_system_time();
$date_from = (string) get_parameter ('date_from', date(DATE_FORMAT, $utimestamp - SECONDS_1DAY));
$time_from = (string) get_parameter ('time_from', date(TIME_FORMAT, $utimestamp - SECONDS_1DAY));
$date_to = (string) get_parameter ('date_to', date(DATE_FORMAT, $utimestamp));
$time_to = (string) get_parameter ('time_to', date(TIME_FORMAT, $utimestamp));
$formtable->width = '98%';
$formtable->class = "databox";

View File

@ -313,7 +313,7 @@ function human_time_comparation ($timestamp, $units = 'large') {
global $config;
if (!is_numeric ($timestamp)) {
$timestamp = strtotime ($timestamp);
$timestamp = time_w_fixed_tz($timestamp);
}
$seconds = get_system_time () - $timestamp;
@ -2827,4 +2827,61 @@ function validate_address($address){
}
return true;
}
/**
* Used to get the offset in seconds to the UTC date.
*
* @param string Timezone identifier.
*/
function get_utc_offset ($timezone) {
if (empty($timezone)) return 0;
$dtz = new DateTimeZone($timezone);
$dt = new DateTime("now", $dtz);
return $dtz->getOffset($dt);
}
function get_system_utc_offset () {
global $config;
return get_utc_offset($config["timezone"]);
}
function get_current_utc_offset () {
return get_utc_offset(date_default_timezone_get());
}
function get_fixed_offset () {
return get_current_utc_offset() - get_system_utc_offset();
}
/**
* Used to transform the dates without timezone information (like '2018/05/23 10:10:10')
* to a unix timestamp compatible with the user custom timezone.
*
* @param string Date without timezone information.
* @param number Offset between the date timezone and the user's default timezone.
*/
function time_w_fixed_tz ($date, $timezone_offset = null) {
if ($timezone_offset === null) $timezone_offset = get_fixed_offset();
return strtotime($date) + $timezone_offset;
}
/**
* Used to transform the dates without timezone information (like '2018/05/23 10:10:10')
* to a date compatible with the user custom timezone.
*
* @param string Date without timezone information.
* @param string Date format.
* @param number Offset between the date timezone and the user's default timezone.
*/
function date_w_fixed_tz ($date, $format = null, $timezone_offset = null) {
global $config;
if ($format === null) $format = $config["date_format"];
return date($format, time_w_fixed_tz($date, $timezone_offset));
}
?>

View File

@ -696,20 +696,13 @@ function agents_process_manage_config ($source_id_agent, $destiny_id_agents, $co
}
function agents_get_next_contact($idAgent, $maxModules = false) {
$agent = db_get_row_sql("SELECT *
FROM tagente
WHERE id_agente = " . $idAgent);
$agent = db_get_row("tagente", "id_agente", $idAgent);
$last_contact = time_w_fixed_tz($agent["ultimo_contacto"]);
$difference = time() - $last_contact;
$difference = get_system_time () - strtotime ($agent["ultimo_contacto"]);
if ($agent["intervalo"] > 0 && strtotime($agent["ultimo_contacto"]) > 0) {
return round ($difference / ($agent["intervalo"] / 100));
}
else {
return 0;
}
return ($agent["intervalo"] > 0 && $last_contact > 0)
? round ($difference / ($agent["intervalo"] / 100))
: 0;
}
/**
@ -1453,7 +1446,7 @@ function agents_get_interval ($id_agent) {
function agents_get_interval_status ($agent) {
$return = '';
$last_time = strtotime ($agent["ultimo_contacto"]);
$last_time = time_w_fixed_tz($agent["ultimo_contacto"]);
$now = time ();
$diferencia = $now - $last_time;
$time = ui_print_timestamp ($last_time, true, array('style' => 'font-size:6.5pt'));

View File

@ -1603,10 +1603,10 @@ function get_alert_type ($id_type) {
*/
function get_agent_alert_fired ($id_agent, $id_alert, $period, $date = 0) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
$date = time_w_fixed_tz($date);
}
if (empty ($date)) {
$date = get_system_time ();
$date = get_system_time();
}
$datelimit = $date - $period;
@ -1635,10 +1635,10 @@ function get_agent_alert_fired ($id_agent, $id_alert, $period, $date = 0) {
function get_module_alert_fired ($id_agent_module, $id_alert, $period, $date = 0) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
$date = time_w_fixed_tz($date);
}
if (empty ($date)) {
$date = get_system_time ();
$date = get_system_time();
}
$datelimit = $date - $period;

View File

@ -4838,9 +4838,7 @@ function api_set_stop_downtime($id, $thrash1, $other, $thrash3) {
return;
}
$date_stop = date ("Y-m-j",get_system_time ());
$time_stop = date ("h:iA",get_system_time ());
$date_time_stop = strtotime ($date_stop.' '.$time_stop);
$date_time_stop = get_system_time();
$values = array();
$values['date_to'] = $date_time_stop;

View File

@ -1273,7 +1273,7 @@ function events_get_agent ($id_agent, $period, $date = 0,
global $config;
if (!is_numeric ($date)) {
$date = strtotime ($date);
$date = time_w_fixed_tz($date);
}
if (empty ($date)) {
$date = get_system_time ();
@ -1920,7 +1920,7 @@ function events_get_response_target($event_id, $response_id, $server_id, $histor
if (strpos($target, '_event_date_') !== false) {
$target = str_replace(
'_event_date_',
date ($config["date_format"], strtotime($event["timestamp"])),
date ($config["date_format"], $event["utimestamp"]),
$target
);
}
@ -2153,12 +2153,12 @@ function events_page_details ($event, $server = "") {
$data = array();
$data[0] = '<div style="font-weight:normal; margin-left: 20px;">'.__('Last contact').'</div>';
$data[1] = $agent["ultimo_contacto"] == "1970-01-01 00:00:00" ? '<i>'.__('N/A').'</i>' : $agent["ultimo_contacto"];
$data[1] = $agent["ultimo_contacto"] == "1970-01-01 00:00:00" ? '<i>'.__('N/A').'</i>' : date_w_fixed_tz($agent["ultimo_contacto"]);
$table_details->data[] = $data;
$data = array();
$data[0] = '<div style="font-weight:normal; margin-left: 20px;">'.__('Last remote contact').'</div>';
$data[1] = $agent["ultimo_contacto_remoto"] == "1970-01-01 00:00:00" ? '<i>'.__('N/A').'</i>' : $agent["ultimo_contacto_remoto"];
$data[1] = $agent["ultimo_contacto_remoto"] == "1970-01-01 00:00:00" ? '<i>'.__('N/A').'</i>' : date_w_fixed_tz($agent["ultimo_contacto_remoto"]);
$table_details->data[] = $data;
$data = array();
@ -2716,7 +2716,7 @@ function events_get_count_events_by_agent ($id_group, $period, $date,
//date
if (!is_numeric ($date)) {
$date = strtotime ($date);
$date = time_w_fixed_tz($date);
}
if (empty ($date)) {
$date = get_system_time ();
@ -2871,7 +2871,7 @@ function events_get_count_events_validated_by_user ($filter, $period, $date,
//date
if (!is_numeric ($date)) {
$date = strtotime ($date);
$date = time_w_fixed_tz($date);
}
if (empty ($date)) {
$date = get_system_time ();
@ -3016,7 +3016,7 @@ function events_get_count_events_by_criticity ($filter, $period, $date,
}
if (!is_numeric ($date)) {
$date = strtotime ($date);
$date = time_w_fixed_tz($date);
}
if (empty ($date)) {
$date = get_system_time ();
@ -3158,7 +3158,7 @@ function events_get_count_events_validated ($filter, $period = null, $date = nul
//date
if (!is_numeric ($date)) {
$date = strtotime ($date);
$date = time_w_fixed_tz($date);
}
if (empty ($date)) {
$date = get_system_time ();

View File

@ -446,7 +446,7 @@ function ui_print_timestamp ($unixtime, $return = false, $option = array ()) {
}
if (!is_numeric ($unixtime)) {
$unixtime = strtotime ($unixtime);
$unixtime = time_w_fixed_tz($unixtime);
}
//prominent_time is either timestamp or comparation
@ -3968,4 +3968,20 @@ function ui_get_snapshot_link($params, $only_params = false) {
// Return the function call to inline js execution
return "winopeng_var('" . implode("', '", $link_parts) . "')";
}
function ui_get_using_system_timezone_warning ($tag = "h3", $return = true) {
global $config;
$user_offset = (-get_fixed_offset() / 60) / 60;
$message = sprintf(
__("This controls are using the timezone of the system (%s) instead of yours (%s). The difference in hours to your timezone is %s."),
$config["timezone"],
date_default_timezone_get(),
$user_offset > 0 ? "+" . $user_offset : $user_offset
);
return ui_print_info_message($message, '', $return, $tag);
}
?>

View File

@ -52,6 +52,8 @@ class User {
$system->setSessionBase('id_usuario', $this->user);
$system->setSession('user', $this);
config_user_set_custom_config();
}
}

View File

@ -232,7 +232,7 @@ class Agents {
private function getListAgents($page = 0, $ajax = false) {
$system = System::getInstance();
$total = 0;
$agents = array();
@ -351,8 +351,10 @@ class Agents {
'<span class="show_collapside" style="vertical-align: 0%; display: none; font-weight: bolder;">' . __('Modules') . ' </span>' .
'<span class="agents_tiny_stats">' . reporting_tiny_stats($agent, true, 'agent', '&nbsp;') . ' </span>';
$last_time = strtotime ($agent["ultimo_contacto"]);
$now = time ();
$last_time = time_w_fixed_tz($agent["ultimo_contacto"]);
html_debug(date('r', $last_time), true);
html_debug(get_current_utc_offset(), true);
$now = get_system_time();
$diferencia = $now - $last_time;
$time = ui_print_timestamp ($last_time, true, array('style' => 'font-size: 12px; margin-left: 20px;', 'units' => 'tiny'));
$style = '';

View File

@ -162,7 +162,7 @@ class Events {
$event['evento'] = io_safe_output($event['evento']);
$event['clean_tags'] = events_clean_tags($event['tags']);
$event["timestamp"] = date($system->getConfig("date_format"), strtotime($event["timestamp"]));
$event["timestamp"] = date($system->getConfig("date_format"), $event["utimestamp"]);
if (empty($event["owner_user"])) {
$event["owner_user"] = '<i>' . __('N/A') . '</i>';
}

View File

@ -239,7 +239,7 @@ if ($agent["ultimo_contacto_remoto"] == "01-01-1970 00:00:00") {
$data[1] .= __('Never');
}
else {
$data[1] .= $agent["ultimo_contacto_remoto"];
$data[1] .= date_w_fixed_tz($agent["ultimo_contacto_remoto"]);
}
$table_contact->data[] = $data;

View File

@ -71,13 +71,16 @@ if (!empty ($export_btn) && !empty ($module)) {
$sql_cache = array ('saved' => array());
//Convert start time and end time to unix timestamps
$start = strtotime ($start_date . " " . $start_time);
$end = strtotime ($end_date . " " . $end_time);
// Convert start time and end time to unix timestamps.
// The date/time will have the user's timezone,
// so we need to change it to the system's timezone.
$fixed_offset = get_fixed_offset();
$start = strtotime ($start_date . " " . $start_time) - $fixed_offset;
$end = strtotime ($end_date . " " . $end_time) - $fixed_offset;
$period = $end - $start;
$data = array ();
//If time is negative or zero, don't process - it's invalid
// If time is negative or zero, don't process - it's invalid
if ($start < 1 || $end < 1) {
ui_print_error_message (__('Invalid time specified'));
return;
@ -168,12 +171,16 @@ if (!empty ($export_btn) && !empty ($module)) {
$output .= $module['data'];
$output .= $divider;
switch($export_type) {
case "data":
$output .= date("Y-m-d G:i:s", $module['utimestamp']);
break;
case "avg":
$output .= date ("Y-m-d G:i:s", $work_start) . ' - ' . date ("Y-m-d G:i:s", $work_end);
break;
case "data":
// Change from the system's timezone to the user's timezone
$output .= date("Y-m-d G:i:s", $module['utimestamp'] + $fixed_offset);
break;
case "avg":
// Change from the system's timezone to the user's timezone
$output .= date ("Y-m-d G:i:s", $work_start + $fixed_offset)
. ' - '
. date ("Y-m-d G:i:s", $work_end + $fixed_offset);
break;
}
$output .= $rowend;
}

View File

@ -33,7 +33,9 @@ ui_require_javascript_file('openlayers.pandora');
/* Get the parameters */
$period = (int)get_parameter ("period", SECONDS_1DAY);
$agentId = (int)get_parameter('id_agente');
$id_agente = $agentId;
$agent_name = agents_get_name($id_agente);
$agent_alias = agents_get_alias($id_agente);
$agentData = gis_get_data_last_position_agent($id_agente);
//Avoid the agents with characters that fails the div.
@ -206,7 +208,7 @@ if ($result !== false) {
__("Manual placement"));
$table->class = 'position_data_table';
$table->id = $agent_name.'_position_data_table';
$table->title = $agent_name_original . " " . __("positional data");
$table->title = $agent_alias . " " . __("positional data");
$table->titlestyle = "background-color:#799E48;";
html_print_table($table); unset($table);

View File

@ -209,27 +209,24 @@ if (($date_from == '') && ($date_to == '')) {
}
}
else {
if ($date_from != '') {
if($time_from != '') {
$filter_resume['time_from'] = $date_from . " " . $time_from;
$udate_from = strtotime($date_from . " " . $time_from);
$sql_post .= " AND (utimestamp >= " . $udate_from . ")";
} else {
$filter_resume['time_from'] = $date_from;
$udate_from = strtotime($date_from . " 00:00:00");
$sql_post .= " AND (utimestamp >= " . $udate_from . ")";
}
// Some of this values will have the user's timezone,
// so we need to reverse it to the system's timezone
// before using it into the db
$fixed_offset = get_fixed_offset();
if (!empty($date_from)) {
if (empty($time_from)) $time_from = "00:00:00";
$utimestamp_from = strtotime($date_from . " " . $time_from) - $fixed_offset;
$filter_resume['time_from'] = date(DATE_FORMAT . " " . TIME_FORMAT, $utimestamp_from);
$sql_post .= " AND (utimestamp >= " . $utimestamp_from . ")";
}
if ($date_to != '') {
if($time_to != '') {
$filter_resume['time_to'] = $date_to . " " . $time_to;
$udate_to = strtotime($date_to . " " . $time_to);
$sql_post .= " AND (utimestamp <= " . $udate_to . ")";
} else {
$filter_resume['time_to'] = $date_to;
$udate_to = strtotime($date_to . " 23:59:59");
$sql_post .= " AND (utimestamp <= " . $udate_to . ")";
}
if (!empty($date_to)) {
if (empty($time_to)) $time_to = "23:59:59";
$utimestamp_to = strtotime($date_to . " " . $time_to) - $fixed_offset;
$filter_resume['time_to'] = date(DATE_FORMAT . " " . TIME_FORMAT, $utimestamp_to);
$sql_post .= " AND (utimestamp <= " . $utimestamp_to . ")";
}
}

View File

@ -101,7 +101,23 @@ $now = date ("Y-m-d");
Header ("Content-type: text/txt");
header ('Content-Disposition: attachment; filename="pandora_export_event'.$now.'.csv"');
echo "timestamp, agent, group, event, status, user, event_type, severity, id";
echo "timestamp";
echo $config["csv_divider"];
echo "agent";
echo $config["csv_divider"];
echo "group";
echo $config["csv_divider"];
echo "event";
echo $config["csv_divider"];
echo "status";
echo $config["csv_divider"];
echo "user";
echo $config["csv_divider"];
echo "event_type";
echo $config["csv_divider"];
echo "severity";
echo $config["csv_divider"];
echo "id";
echo chr (13);
$new = true;
@ -113,22 +129,22 @@ while ($event = db_get_all_row_by_steps_sql($new, $result, $sql)) {
(!check_acl($config["id_user"], 0, "PM") && $event["event_type"] == 'system'))
continue;
echo $event["timestamp"];
echo ",";
echo date($config["date_format"], $event["utimestamp"]);
echo $config["csv_divider"];
echo io_safe_output($alias);
echo ",";
echo $config["csv_divider"];
echo io_safe_output(groups_get_name($event["id_grupo"]));
echo ",";
echo $config["csv_divider"];
echo io_safe_output($event["evento"]);
echo ",";
echo $config["csv_divider"];
echo io_safe_output($event["estado"]);
echo ",";
echo $config["csv_divider"];
echo io_safe_output($event["id_usuario"]);
echo ",";
echo $config["csv_divider"];
echo io_safe_output($event["event_type"]);
echo ",";
echo $config["csv_divider"];
echo $event["criticity"];
echo ",";
echo $config["csv_divider"];
echo $event["id_evento"];
echo chr (13);
}

View File

@ -325,7 +325,7 @@ switch ($opt) {
$row[] = __('Never');
}
else {
$row[] = $agent["ultimo_contacto"];
$row[] = date_w_fixed_tz($agent["ultimo_contacto"]);
}
$table->data[] = $row;
@ -336,7 +336,7 @@ switch ($opt) {
$row[] = __('Never');
}
else {
$row[] = $agent["ultimo_contacto_remoto"];
$row[] = date_w_fixed_tz($agent["ultimo_contacto_remoto"]);
}
$table->data[] = $row;

View File

@ -41,8 +41,8 @@ if (isset ($_GET["id"])) {
// Get values
$titulo = $row["titulo"];
$texto = $row["descripcion"];
$inicio = strtotime ($row["inicio"]);
$actualizacion = strtotime ($row["actualizacion"]);
$inicio = time_w_fixed_tz($row["inicio"]);
$actualizacion = time_w_fixed_tz($row["actualizacion"]);
$estado = $row["estado"];
$prioridad = $row["prioridad"];
$origen = $row["origen"];

View File

@ -111,8 +111,8 @@ else {
$cellName .= "</em>";
}
$last_time = strtotime ($agent["ultimo_contacto"]);
$now = time ();
$last_time = time_w_fixed_tz($agent["ultimo_contacto"]);
$now = get_system_time();
$diferencia = $now - $last_time;
$time = ui_print_timestamp ($last_time, true);
$time_style = $time;