diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 3cc78b737c..c1714df9ed 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1786,46 +1786,10 @@ $class = 'databox filters'; $value) { - $agents2[$value['id_agente']] = $value['alias']; - } - } - - if ((empty($agents2)) || $agents2 == -1) { - $agents = []; - } - - $agents_select = []; - if (is_array($id_agents) || is_object($id_agents)) { - foreach ($id_agents as $id) { - foreach ($agents2 as $key => $a) { - if ($key == (int) $id) { - $agents_select[$key] = $key; - } - } - } - } - html_print_select( - $agents2, + [], 'id_agents3[]', - $agents_select, + '', $script = '', '', 0, @@ -6110,6 +6074,58 @@ function addGeneralRow() { } } +function loadLogAgents() { + var params = []; + + params.push("get_log_agents=1"); + params.push("source="); + params.push('id_agents='); + params.push("page=include/ajax/reporting.ajax"); + + $('#id_agents3') + .find('option') + .remove(); + + $('#id_agents3') + .append(''); + + jQuery.ajax ({ + data: params.join ("&"), + type: 'POST', + url: action= + + + "/ajax.php", + timeout: 300000, + dataType: 'json', + success: function (data) { + if (data['correct']) { + $('#id_agents3') + .find('option') + .remove(); + + var selectElements = []; + var selectedStr = 'selected="selected"' + data['select_agents'].forEach(function(agentAlias, agentID) { + var optionAttr = ''; + if (typeof data['agents_selected'][agentID] !== 'undefined') { + optionAttr = ' selected="selected"'; + } + + $('#id_agents3') + .append(''); + }); + } + } + }); +} + function chooseType() { var meta = ''; type = $("#type").val(); @@ -6278,6 +6294,9 @@ function chooseType() { $("#agents_row").show(); $("#row_source").show(); $("#row_historical_db_check").hide(); + + loadLogAgents(); + break; case 'increment': diff --git a/pandora_console/include/ajax/reporting.ajax.php b/pandora_console/include/ajax/reporting.ajax.php index bafe01307d..977af7f372 100755 --- a/pandora_console/include/ajax/reporting.ajax.php +++ b/pandora_console/include/ajax/reporting.ajax.php @@ -25,6 +25,9 @@ if (! check_acl($config['id_user'], 0, 'RW')) { exit; } +$get_log_agents = (bool) get_parameter('get_log_agents', 0); +$agents_id = get_parameter('id_agents', []); +$agents_id = get_parameter('source', 0); $delete_sla_item = get_parameter('delete_sla_item', 0); $delete_general_item = get_parameter('delete_general_item', 0); $get_custom_sql = get_parameter('get_custom_sql', 0); @@ -244,3 +247,60 @@ if ($change_custom_fields_macros_report === true) { echo $custom_field_draw; return; } + +if ($get_log_agents === true) { + try { + $agents_id = json_decode($agents_id, true); + } catch (Exception $e) { + $data['correct'] = 0; + echo json_encode($data); + return; + } + + if ($source) { + $sql_log_report = 'SELECT id_agente, alias + FROM tagente, tagent_module_log + WHERE tagente.id_agente = tagent_module_log.id_agent + AND tagente.disabled = 0 + AND tagent_module_log.source like "'.$source.'"'; + } else { + $sql_log_report = 'SELECT id_agente, alias + FROM tagente, tagent_module_log + WHERE tagente.id_agente = tagent_module_log.id_agent + AND tagente.disabled = 0'; + } + + $all_agent_log = db_get_all_rows_sql($sql_log_report); + + if (isset($all_agent_log) && is_array($all_agent_log)) { + foreach ($all_agent_log as $key => $value) { + $select_agents[$value['id_agente']] = $value['alias']; + } + } + + if ((empty($select_agents)) || $select_agents == -1) { + $agents = []; + } + + $agents_selected = []; + if (is_array($agents_id) === true || is_object($agents_id) === true) { + foreach ($select_agents as $key => $a) { + if (in_array((string) $key, $agents_id)) { + $agents_selected[$key] = $key; + } + } + } + + $data['select_agents'] = $select_agents; + $data['agents_selected'] = $agents_selected; + + $data['correct'] = 1; + + if ($result === false) { + $data['correct'] = 0; + } + + echo json_encode($data); + + return; +}