From 9da8e8363337e98cdff93b379a87bc4c4d9323d6 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 18 Apr 2023 09:52:59 +0200 Subject: [PATCH 1/6] Modified the timestamp according to input data. Added query with the timestamp of the filter. --- .../include/functions_inventory.php | 20 +++++++++++++++---- .../operation/agentes/agent_inventory.php | 9 ++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 5b3efedc93..9bda1f17a1 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -741,15 +741,23 @@ function inventory_get_datatable( array_push($where, "tagent_module_inventory.data LIKE '%".$inventory_search_string."%'"); } + if ($utimestamp > 0) { + array_push($where, 'tagente_datos_inventory.utimestamp <= '.$utimestamp.' '); + } + $sql = sprintf( 'SELECT tmodule_inventory.*, tagent_module_inventory.*, - tagente.alias as name_agent + tagente.alias as name_agent, + tagente_datos_inventory.utimestamp as last_update, + tagente_datos_inventory.timestamp as last_update_timestamp FROM tmodule_inventory INNER JOIN tagent_module_inventory ON tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory LEFT JOIN tagente ON tagente.id_agente = tagent_module_inventory.id_agente + LEFT JOIN tagente_datos_inventory + ON tagent_module_inventory.id_agent_module_inventory = tagente_datos_inventory.id_agent_module_inventory WHERE %s ORDER BY tmodule_inventory.id_module_inventory LIMIT %d, %d', @@ -763,6 +771,10 @@ function inventory_get_datatable( if ($order_by_agent === false) { $modules = []; foreach ($rows as $row) { + if ($row['utimestamp'] !== $row['last_update']) { + $row['timestamp'] = $row['last_update_timestamp']; + } + $data_rows = explode(PHP_EOL, $row['data']); foreach ($data_rows as $data_key => $data_value) { if (empty($data_value) === false) { @@ -894,16 +906,16 @@ function inventory_get_dates($module_inventory_name, $inventory_agent, $inventor AND tagente_datos_inventory.id_agent_module_inventory = tagent_module_inventory.id_agent_module_inventory AND tagente.id_agente = tagent_module_inventory.id_agente'; - if ($inventory_agent != 0) { + if ($inventory_agent !== 'All') { $sql .= ' AND tagent_module_inventory.id_agente IN ('."'".implode(',', (array) $inventory_agent)."'".')'; } - if ($inventory_id_group != 0) { + if ($inventory_id_group !== 0) { $sql .= " AND tagente.id_grupo = $inventory_id_group"; } if (is_string($module_inventory_name) === true - && $module_inventory_name != 'all' + && $module_inventory_name !== '0' ) { $sql .= " AND tmodule_inventory.name IN ('".str_replace(',', "','", $module_inventory_name)."')"; } diff --git a/pandora_console/operation/agentes/agent_inventory.php b/pandora_console/operation/agentes/agent_inventory.php index 1d692bfd41..9ae081186b 100644 --- a/pandora_console/operation/agentes/agent_inventory.php +++ b/pandora_console/operation/agentes/agent_inventory.php @@ -232,7 +232,14 @@ foreach ($rows as $row) { $table->cellspacing = 4; $table->class = 'info_table'; $table->head = []; - $table->head[0] = $row['name'].' - ('.date($config['date_format'], $row['utimestamp']).')'; + + if ($row['utimestamp'] === '0' && $utimestamp === 0) { + $table->head[0] = $row['name']; + } else if ($utimestamp === 0) { + $table->head[0] = $row['name'].' - (Last update '.date($config['date_format'], $row['utimestamp']).')'; + } else { + $table->head[0] = $row['name'].' - ('.date($config['date_format'], $utimestamp).')'; + } if ((bool) $row['block_mode'] === true) { $table->head[0] .= '   '.html_print_image( From cccb03010c5469deeb4cab2f68f27d1c1addc515 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 25 May 2023 10:30:34 +0200 Subject: [PATCH 2/6] #10851 change date order to asc and fix sql query --- pandora_console/include/functions_inventory.php | 12 ++++++++---- .../operation/agentes/agent_inventory.php | 5 ++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 9bda1f17a1..2430b69163 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -750,14 +750,16 @@ function inventory_get_datatable( tagent_module_inventory.*, tagente.alias as name_agent, tagente_datos_inventory.utimestamp as last_update, - tagente_datos_inventory.timestamp as last_update_timestamp + tagente_datos_inventory.timestamp as last_update_timestamp, + tagente_datos_inventory.data as data_inventory FROM tmodule_inventory INNER JOIN tagent_module_inventory ON tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory + INNER JOIN tagente_datos_inventory + ON tagent_module_inventory.id_agent_module_inventory = tagente_datos_inventory.id_agent_module_inventory LEFT JOIN tagente ON tagente.id_agente = tagent_module_inventory.id_agente - LEFT JOIN tagente_datos_inventory - ON tagent_module_inventory.id_agent_module_inventory = tagente_datos_inventory.id_agent_module_inventory + WHERE %s ORDER BY tmodule_inventory.id_module_inventory LIMIT %d, %d', @@ -766,6 +768,8 @@ function inventory_get_datatable( $config['block_size'] ); + hd($sql, true); + $rows = db_get_all_rows_sql($sql); if ($order_by_agent === false) { @@ -775,7 +779,7 @@ function inventory_get_datatable( $row['timestamp'] = $row['last_update_timestamp']; } - $data_rows = explode(PHP_EOL, $row['data']); + $data_rows = explode(PHP_EOL, $row['data_inventory']); foreach ($data_rows as $data_key => $data_value) { if (empty($data_value) === false) { $row['data'] = $data_value; diff --git a/pandora_console/operation/agentes/agent_inventory.php b/pandora_console/operation/agentes/agent_inventory.php index 9ae081186b..b378f0f810 100644 --- a/pandora_console/operation/agentes/agent_inventory.php +++ b/pandora_console/operation/agentes/agent_inventory.php @@ -90,13 +90,12 @@ $utimestamps = db_get_all_rows_sql( FROM tmodule_inventory, tagent_module_inventory, tagente_datos_inventory WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory AND tagente_datos_inventory.id_agent_module_inventory = tagent_module_inventory.id_agent_module_inventory - AND tagent_module_inventory.%s', + AND tagent_module_inventory.%s ORDER BY tagente_datos_inventory.utimestamp DESC', ($module !== 0) ? 'id_module_inventory = '.$module : 'id_agente = '.$id_agente ) ); $utimestamps = (empty($utimestamps) === true) ? [] : extract_column($utimestamps, 'utimestamp'); - $utimestampSelectValues = array_reduce( $utimestamps, function ($acc, $utimestamp) use ($config) { @@ -143,7 +142,7 @@ $table->data[0][1] = html_print_label_input_block( 0, true, false, - true, + false, '', false, 'width:100%;' From bd453ea1deec1f10e6e0a370b0dc6919fb2553e7 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Fri, 26 May 2023 08:36:56 +0200 Subject: [PATCH 3/6] #10851 Fix inventory date filter and last update query --- .../include/functions_inventory.php | 26 ++++++++++++++----- .../operation/inventory/inventory.php | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 2430b69163..c91a375225 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -707,6 +707,17 @@ function inventory_get_datatable( ) { global $config; + if ($utimestamp === 0) { + $data_last = db_get_row_sql( + sprintf( + 'SELECT `utimestamp`, `timestamp` + FROM tagente_datos_inventory + ORDER BY utimestamp DESC' + ) + ); + $utimestamp = $data_last['utimestamp']; + } + $offset = (int) get_parameter('offset'); $where = []; @@ -742,7 +753,7 @@ function inventory_get_datatable( } if ($utimestamp > 0) { - array_push($where, 'tagente_datos_inventory.utimestamp <= '.$utimestamp.' '); + array_push($where, 'tagente_datos_inventory.utimestamp = '.$utimestamp.' '); } $sql = sprintf( @@ -768,8 +779,6 @@ function inventory_get_datatable( $config['block_size'] ); - hd($sql, true); - $rows = db_get_all_rows_sql($sql); if ($order_by_agent === false) { @@ -797,16 +806,17 @@ function inventory_get_datatable( $agent_data[$row['id_agente']][] = $row; } - foreach ($agent_data as $id_agent => $rows) { + foreach ($agent_data as $id_agent => $data_rows) { $rows_tmp['agent'] = $row['name_agent']; - foreach ($rows as $row) { + foreach ($data_rows as $row) { if ($utimestamp > 0) { $data_row = db_get_row_sql( sprintf( 'SELECT `data`, - `timestamp` + `timestamp`, + `utimestamp` FROM tagente_datos_inventory - WHERE utimestamp <= "%s" + WHERE utimestamp = "%s" AND id_agent_module_inventory = %d ORDER BY utimestamp DESC', $utimestamp, @@ -817,12 +827,14 @@ function inventory_get_datatable( if ($data_row !== false) { $row['data'] = $data_row['data']; $row['timestamp'] = $data_row['timestamp']; + $row['utimestamp'] = $data_row['utimestamp']; } else { continue; } } } + $rows[0]['timestamp'] = $row['timestamp']; $rows_tmp['row'] = $rows; array_push($agents_rows, $rows_tmp); } diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index ba45efe85a..fd30943e8d 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -690,7 +690,7 @@ if (is_metaconsole() === false) { 0, true, false, - true, + false, '', false, 'width:100%;' From cf843eba7a41f9bf3e991042131e52a436115143 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 30 May 2023 11:47:34 +0200 Subject: [PATCH 4/6] #10851 Fix order by agent foreach --- .../include/functions_inventory.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index c91a375225..ab58844052 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -806,9 +806,12 @@ function inventory_get_datatable( $agent_data[$row['id_agente']][] = $row; } - foreach ($agent_data as $id_agent => $data_rows) { - $rows_tmp['agent'] = $row['name_agent']; - foreach ($data_rows as $row) { + foreach ($agent_data as $id_agent => $data_agent) { + $rows_tmp['agent'] = $data_agent['name_agent']; + foreach ($data_agent as $key => $agent_row) { + $data_agent[$key]['timestamp'] = $agent_row['last_update_timestamp']; + $data_agent[$key]['utimestamp'] = $agent_row['last_update']; + if ($utimestamp > 0) { $data_row = db_get_row_sql( sprintf( @@ -820,22 +823,19 @@ function inventory_get_datatable( AND id_agent_module_inventory = %d ORDER BY utimestamp DESC', $utimestamp, - $row['id_agent_module_inventory'] + $agent_row['id_agent_module_inventory'] ) ); if ($data_row !== false) { - $row['data'] = $data_row['data']; - $row['timestamp'] = $data_row['timestamp']; - $row['utimestamp'] = $data_row['utimestamp']; + $data_agent[$key]['data'] = $data_row['data']; } else { continue; } } } - $rows[0]['timestamp'] = $row['timestamp']; - $rows_tmp['row'] = $rows; + $rows_tmp['row'] = $data_agent; array_push($agents_rows, $rows_tmp); } From cdb01f11058c21263720b0e807f62b16e0936c36 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 30 May 2023 14:03:39 +0200 Subject: [PATCH 5/6] #10851 Fix variable name --- pandora_console/operation/inventory/inventory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index fd30943e8d..9ee25710a4 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -675,10 +675,10 @@ $table->data[1][1] = html_print_label_input_block( if (is_metaconsole() === false) { $dates = inventory_get_dates( $inventory_module, - $inventory_agent, + $inventory_id_agent, $inventory_id_group ); - + hd($dates, true); $table->data[1][2] = html_print_label_input_block( __('Date'), html_print_select( From 6d843537782ca6e69cbd4d69e63a2da86853a5fb Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 30 May 2023 14:09:32 +0200 Subject: [PATCH 6/6] #10851 Fix id agent and delete hd --- pandora_console/include/functions_inventory.php | 2 +- pandora_console/operation/inventory/inventory.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index ab58844052..0337b28ed0 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -922,7 +922,7 @@ function inventory_get_dates($module_inventory_name, $inventory_agent, $inventor AND tagente_datos_inventory.id_agent_module_inventory = tagent_module_inventory.id_agent_module_inventory AND tagente.id_agente = tagent_module_inventory.id_agente'; - if ($inventory_agent !== 'All') { + if ($inventory_agent !== 0) { $sql .= ' AND tagent_module_inventory.id_agente IN ('."'".implode(',', (array) $inventory_agent)."'".')'; } diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index 9ee25710a4..1e25980c52 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -678,7 +678,6 @@ if (is_metaconsole() === false) { $inventory_id_agent, $inventory_id_group ); - hd($dates, true); $table->data[1][2] = html_print_label_input_block( __('Date'), html_print_select(