From 3c345ed1f901ad0ec10b7c70545638b6e8762f76 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 13 Jul 2023 13:12:43 +0200 Subject: [PATCH] #8285 Add CSV export on agents modules view --- pandora_console/extensions/agents_modules.php | 26 +++- .../extensions/agents_modules_csv.php | 117 ++++++++++++++++++ pandora_console/include/functions_modules.php | 72 +++++++++++ 3 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 pandora_console/extensions/agents_modules_csv.php diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 215e478319..d33341f25f 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -267,6 +267,23 @@ function agents_modules_load_js() // } // }); } + /* e.value).get(); + let module_id = $('#module option:selected').map((_, e) => e.value).get(); + + let filters_array = {group_id: group_id, module_group_id:module_group_id, agent_id:agent_id, module_id:module_id} + let jsonFilters = JSON.stringify(filters_array) + let filters = window.btoa(jsonFilters) + var f = document.forms.filter_form; + + blockResubmit($(this)); + f.action = "extensions/agents_modules_csv.php?get_agents_module_csv=1&filters="+filters; + $("#filter_form").submit(); + } + /* ]]> */ '; + $show_filters = '
'; $show_filters .= ''; $show_filters .= ''; $show_filters .= ''; @@ -679,6 +696,13 @@ function mainAgentsModules() 'onclick' => 'select_selected()', ], true + ).html_print_button( + __('Export to CSV'), + 'srcbutton', + false, + 'export_csv()', + ['class' => 'secondary mini'], + true, ), ], true diff --git a/pandora_console/extensions/agents_modules_csv.php b/pandora_console/extensions/agents_modules_csv.php new file mode 100644 index 0000000000..53225f8e4d --- /dev/null +++ b/pandora_console/extensions/agents_modules_csv.php @@ -0,0 +1,117 @@ + $value) { + $out_csv .= $value.$divider; + } + + $out_csv .= "\n"; + + foreach ($results as $result) { + foreach ($result as $key => $value) { + $out_csv .= io_safe_output($value).$divider; + } + + $out_csv .= "\n"; + } + + echo io_safe_output($out_csv); + + exit; +} diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index b670088f85..940880c3e7 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -4682,3 +4682,75 @@ function get_agent_module_childs( } } } + + +/** + * Function for export a csv file from Agents/Module view + * + * @param array $filters Data from agents/module filter. + * + * @return array Returns the data that will be saved in the csv file + */ +function export_agents_module_csv($filters) +{ + $query_filter = ''; + foreach ($filters as $key => $filter) { + switch ($key) { + case 'group_id': + if ($filter != 0) { + $query_filter .= ' AND ta.id_grupo = '.$filter.' '; + } + break; + + case 'module_group_id': + if ($filter != 0) { + $query_filter .= ' AND tam.id_module_group = '.$filter.' '; + ; + } + break; + + case 'agent_id': + if (count($filter) > 0) { + $agent_filter = '('.implode(', ', $filter).')'; + $query_filter .= ' AND ta.id_agente IN '.$agent_filter.' '; + } + break; + + case 'module_id': + if (count($filter) > 0) { + if (is_numeric($filter[0]) === false) { + foreach ($filter as $key => $module) { + $filter[$key] = io_safe_input($module); + } + + $module_filter = '(\''.implode("', '", $filter).'\')'; + $query_filter .= ' AND tam.nombre IN '.$module_filter.' '; + } else { + $module_filter = '('.implode(', ', $filter).')'; + $query_filter .= ' AND tam.id_tipo_modulo IN '.$module_filter.' '; + } + } + break; + + default: + // Nothing to do + break; + } + } + + // Query fields result. + $query = sprintf( + 'SELECT ta.alias as agent, tam.nombre as module, tae.datos as data + FROM tagente_modulo as tam + INNER JOIN tagente as ta ON tam.id_agente = ta.id_agente + INNER JOIN tagente_estado as tae ON tam.id_agente_modulo = tae.id_agente_modulo + WHERE ta.disabled = 0 + %s + ', + $query_filter + ); + + $result = db_get_all_rows_sql($query); + + return $result; +}
'.$filter_type.'