From 377b25f823ee063a106bba4313613d8a3ece60ee Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 15 Jun 2023 10:22:05 +0200 Subject: [PATCH 1/2] #11579 Fix inventory table --- .../include/functions_inventory.php | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 3e1aa3b9d0..ba09ddd62f 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -707,17 +707,6 @@ 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 = []; @@ -803,12 +792,29 @@ function inventory_get_datatable( $agent_data = []; $rows_tmp = []; foreach ($rows as $row) { - $agent_data[$row['id_agente']][] = $row; + $replace_agent_data = false; + if (isset($agent_data[$row['id_agente']]) === true) { + foreach ($agent_data[$row['id_agente']] as $key => $compare_data) { + if ($compare_data['id_module_inventory'] === $row['id_module_inventory'] + && $row['last_update'] > $compare_data['last_update'] + ) { + $agent_data[$row['id_agente']][$key] = $row; + $replace_agent_data = true; + } + } + } + + if ($replace_agent_data === false) { + $agent_data[$row['id_agente']][] = $row; + } } foreach ($agent_data as $id_agent => $data_agent) { - $rows_tmp['agent'] = $data_agent['name_agent']; foreach ($data_agent as $key => $agent_row) { + if (isset($rows_tmp['agent']) === false) { + $rows_tmp['agent'] = $agent_row['name_agent']; + } + $data_agent[$key]['timestamp'] = $agent_row['last_update_timestamp']; $data_agent[$key]['utimestamp'] = $agent_row['last_update']; From 76346daf11f7f612ee71740a9cbc5f5729dadc6c Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 20 Jun 2023 11:00:09 +0200 Subject: [PATCH 2/2] #11579 Fix inventory --- .../include/functions_inventory.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index ba09ddd62f..34ddd65277 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -742,7 +742,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( @@ -761,13 +761,22 @@ function inventory_get_datatable( ON tagente.id_agente = tagent_module_inventory.id_agente WHERE %s - ORDER BY tmodule_inventory.id_module_inventory - LIMIT %d, %d', - implode(' AND ', $where), - $offset, - $config['block_size'] + ORDER BY tmodule_inventory.id_module_inventory + ', + implode(' AND ', $where) ); + if ($inventory_module_name[0] !== '0' + && $inventory_module_name !== '' + && $inventory_module_name !== 'all' + ) { + $sql .= sprintf( + 'LIMIT %d, %d', + $offset, + $config['block_size'] + ); + } + $rows = db_get_all_rows_sql($sql); if ($order_by_agent === false) {