From c4e6c52fe20b341de74bbfe0b98cae2981f5480f Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Fri, 27 Aug 2021 11:24:23 +0200 Subject: [PATCH] #7915 fixed custom field filter --- .../reporting_builder.item_editor.php | 39 +++++++++++++++++++ .../godmode/reporting/reporting_builder.php | 2 + .../include/functions_reporting.php | 17 +++++++- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 2a4f1de300..e5b47dd219 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -748,6 +748,7 @@ switch ($action) { $selected_agent_group_filter = $es['agent_group_filter']; $selected_agents_inventory_display_options = $es['agents_inventory_display_options']; $selected_agent_os_filter = $es['agent_os_filter']; + $selected_agent_custom_fields = $es['agent_custom_fields']; $selected_agent_custom_field_filter = $es['agent_custom_field_filter']; $selected_agent_status_filter = $es['agent_status_filter']; $selected_agent_module_search_filter = $es['agent_module_search_filter']; @@ -3158,6 +3159,28 @@ $class = 'databox filters'; + + + + + + + + + 0) { + $('#text-agent_custom_field_filter').removeAttr('disabled'); + } else { + $('#text-agent_custom_field_filter').prop('disabled', true); + } + + $("#agent_custom_fields").change(function(e) { + if ($('#agent_custom_fields :selected').length > 0) { + $('#text-agent_custom_field_filter').removeAttr('disabled'); + } else { + $('#text-agent_custom_field_filter').prop('disabled', true); + } + }); + break; case 'inventory': diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 203cfef4b1..c169bf2c7c 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -2219,6 +2219,7 @@ switch ($action) { $es['agents_inventory_display_options'] = get_parameter('agents_inventory_display_options'); $es['agent_custom_field_filter'] = get_parameter('agent_custom_field_filter'); $es['agent_os_filter'] = get_parameter('agent_os_filter'); + $es['agent_custom_fields'] = get_parameter('agent_custom_fields'); $es['agent_status_filter'] = get_parameter('agent_status_filter'); $es['agent_version_filter'] = get_parameter('agent_version_filter'); $es['agent_module_search_filter'] = get_parameter('agent_module_search_filter'); @@ -2858,6 +2859,7 @@ switch ($action) { $es['agents_inventory_display_options'] = get_parameter('agents_inventory_display_options'); $es['agent_custom_field_filter'] = get_parameter('agent_custom_field_filter'); $es['agent_os_filter'] = get_parameter('agent_os_filter'); + $es['agent_custom_fields'] = get_parameter('agent_custom_fields'); $es['agent_status_filter'] = get_parameter('agent_status_filter'); $es['agent_version_filter'] = get_parameter('agent_version_filter'); $es['agent_module_search_filter'] = get_parameter('agent_module_search_filter'); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6b10b7c439..5773908386 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2285,6 +2285,7 @@ function reporting_agents_inventory($report, $content) $external_source = io_safe_input(json_decode($content['external_source'], true)); $es_agents_inventory_display_options = $external_source['agents_inventory_display_options']; + $es_agent_custom_fields = $external_source['agent_custom_fields']; $es_custom_fields = $external_source['agent_custom_field_filter']; $es_os_filter = $external_source['agent_os_filter']; $es_agent_status_filter = $external_source['agent_status_filter']; @@ -2299,10 +2300,20 @@ function reporting_agents_inventory($report, $content) $es_agents_inventory_display_options = []; } + $custom_field_sql = ''; $search_sql = ''; - if ($es_custom_fields != '') { - $search_sql .= ' AND id_os = '.$es_custom_fields; + if (!empty($es_agent_custom_fields)) { + $custom_field_sql = 'INNER JOIN tagent_custom_data tacd ON tacd.id_agent = tagente.id_agente'; + if ($es_agent_custom_fields[0] != 0) { + $custom_field_sql .= ' AND tacd.id_field IN ('.implode(',', $es_agent_custom_fields).')'; + } + + if (!empty($es_custom_fields)) { + $custom_field_sql .= ' AND tacd.description like "%'.$es_custom_fields.'%"'; + } else { + $custom_field_sql .= ' AND tacd.description <> ""'; + } } if (in_array('0', $es_os_filter) === false) { @@ -2341,8 +2352,10 @@ function reporting_agents_inventory($report, $content) ON tagente.id_agente = tasg.id_agent LEFT JOIN tagente_modulo tam ON tam.id_agente = tagente.id_agente + %s WHERE (tagente.id_grupo IN (%s) OR tasg.id_group IN (%s)) %s', + $custom_field_sql, $user_groups_to_sql, $user_groups_to_sql, $search_sql