diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 87d2e3d8f1..e06ddd3763 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2012-04-09 Sergio Martin + + * include/javascript/jquery.pandora.controls.js + godmode/groups/group_list.php + godmode/massive/massive_delete_action_alerts.php + godmode/massive/massive_add_action_alerts.php: Improved the + template actions sections into massive operations + deleting compound deprecated alerts and showing only the + agents with templates in the combos + 2012-04-09 Sergio Martin * include/functions_reports.php: Fixed "forecating" diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php index 59a801f0c9..2088737532 100644 --- a/pandora_console/godmode/groups/group_list.php +++ b/pandora_console/godmode/groups/group_list.php @@ -66,14 +66,20 @@ if (is_ajax ()) { $disabled = (int) get_parameter ('disabled', 0); $search = (string) get_parameter ('search', ''); $recursion = (int) get_parameter ('recursion', 0); - + // Ids of agents to be include in the SQL clause as id_agent IN () + $filter_agents_json = (string) get_parameter ('filter_agents_json', ''); + if (! check_acl ($config['id_user'], $id_group, "AR")) { db_pandora_audit("ACL Violation", "Trying to access Alert Management"); echo json_encode (false); return; } - + + if($filter_agents_json != '') { + $filter['id_agente'] = json_decode(io_safe_output($filter_agents_json), true); + } + $filter['disabled'] = $disabled; if($search != '') { diff --git a/pandora_console/godmode/massive/massive_add_action_alerts.php b/pandora_console/godmode/massive/massive_add_action_alerts.php index 44fb2151f9..30e1374479 100644 --- a/pandora_console/godmode/massive/massive_add_action_alerts.php +++ b/pandora_console/godmode/massive/massive_add_action_alerts.php @@ -36,24 +36,14 @@ if (is_ajax ()) { echo json_encode (''); return; } - $get_compounds = get_parameter ('get_compounds'); - if (!$get_compounds) { - $alert_templates = agents_get_alerts_simple ($id_agents); - echo json_encode (index_array ($alert_templates, 'id_alert_template', 'template_name')); - return; - } - else { - $filter = ''; - foreach ($id_agents as $id_agent) { - if ($filter != '') { - $filter .= ' OR '; - } - $filter .= 'id_agent=' . $id_agent; - } - $alert_compounds = alerts_get_alert_compounds ($filter, array('id', 'name')); - echo json_encode (index_array ($alert_compounds, 'id', 'name')); - return; + + if(is_array($id_agents) && count($id_agents) == 1 && $id_agents[0] == '') { + $id_agents = false; } + + $alert_templates = agents_get_alerts_simple ($id_agents); + echo json_encode (index_array ($alert_templates, 'id_alert_template', 'template_name')); + return; } return; } @@ -61,7 +51,6 @@ if (is_ajax ()) { $id_group = (int) get_parameter ('id_group'); $id_agents = get_parameter ('id_agents'); $id_alert_templates = (array) get_parameter ('id_alert_templates'); -$id_alert_compounds = (array) get_parameter ('id_alert_compounds'); $recursion = get_parameter ('recursion'); $add = (bool) get_parameter_post ('add'); @@ -84,15 +73,6 @@ if ($add) { $cont = $cont + 1; } } - - $cont = 0; - $agent_alerts_id_compound = array(); - foreach($agent_alerts['compounds'] as $agent_alert){ - if (in_array($agent_alert['id'], $id_alert_compounds)) { - $agent_alerts_id_compound[$cont] = $agent_alert['id']; - $cont = $cont + 1; - } - } $options = array(); @@ -101,7 +81,7 @@ if ($add) { if($fires_max > 0) $options['fires_max'] = $fires_max; - if (empty($agent_alerts_id) && empty($agent_alerts_id_compound)) { + if (empty($agent_alerts_id)) { ui_print_result_message (false, '', __('Could not be added').". ".__('No alerts selected')); } else { @@ -111,12 +91,6 @@ if ($add) { if($result === false) $results = false; } - - foreach ($agent_alerts_id_compound as $agent_alert_id_compound) { - $result = alerts_add_alert_compound_action ($agent_alert_id_compound, $action, $options); - if($result === false) - $results = false; - } db_pandora_audit("Masive management", "Add alert action " . json_encode($id_agents), false, false, 'Agents: ' . json_encode($id_agents) . ' Alerts : ' . json_encode($agent_alerts) . @@ -153,59 +127,43 @@ $table->data[0][1] = html_print_select_groups(false, "AR", true, 'id_group', $id $table->data[0][2] = __('Group recursion'); $table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion, true, false); -$table->data[1][0] = __('Agents'); +$table->data[1][0] = __('Agents with templates'); $table->data[1][0] .= ''; -$table->data[1][1] = html_print_select (agents_get_group_agents ($id_group, false, "none"), - 'id_agents[]', 0, false, __('Any'), '', true, true); +$table->data[1][1] = html_print_select (array(),'id_agents[]', 0, false, __('Any'), '', true, true); -if (empty($id_agents)) { - $alert_templates = ''; -} -else { - $alert_templates = agents_get_alerts_simple ($id_agents); -} $table->data[2][0] = __('Alert templates'); $table->data[2][0] .= ''; -$table->data[2][1] = html_print_select (index_array ($alert_templates, 'id_alert_template', 'template_name'), 'id_alert_templates[]', '', '', '', '', true, true, true, '', $alert_templates == 0); +$table->data[2][1] = html_print_select (array(), 'id_alert_templates[]', '', '', '', '', true, true, true, '', $alert_templates == 0); -if (empty($id_agents)) { - $alert_compounds = ''; -} -else { - $filter = ''; - foreach ($id_agents as $id_agent) { - if ($filter != '') { - $filter .= ' OR '; - } - $filter .= 'id_agent=' . $id_agent; - } - $alert_compounds = alerts_get_alert_compounds ($filter, array('id', 'name')); -} -$table->data[3][0] = __('Alert compounds'); -$table->data[3][0] .= ''; -$table->data[3][1] = html_print_select (index_array ($alert_compounds, 'id', 'name'), 'id_alert_compounds[]', '', false, '', '', true, true, true, '', $alert_compounds == 0); - $actions = alerts_get_alert_actions (); -$table->data[4][0] = __('Action'); -$table->data[4][1] = html_print_select ($actions, 'action', '', '', __('None'), 0, true); -$table->data[4][1] .= ''.__('Advanced options').' » '; -$table->data[4][1] .= ''; +$table->data[3][0] = __('Action'); +$table->data[3][1] = html_print_select ($actions, 'action', '', '', __('None'), 0, true); +$table->data[3][1] .= ''.__('Advanced options').' » '; +$table->data[3][1] .= ''; echo '
'; html_print_table ($table); +$sql = 'SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo IN (SELECT id_agent_module FROM talert_template_modules)'; +$agents_with_templates = db_get_all_rows_sql($sql); +$agents_with_templates_json = array(); +foreach($agents_with_templates as $ag) { + $agents_with_templates_json[] = $ag['id_agente']; +} +$agents_with_templates_json = json_encode($agents_with_templates_json); + +echo ""; + echo '
'; html_print_input_hidden ('add', 1); html_print_submit_button (__('Add'), 'go', false, 'class="sub add"'); @@ -227,15 +185,16 @@ $(document).ready (function () { recursion = this.checked ? 1 : 0; $("#id_group").trigger("change"); }); - + + var filter_agents_json = $("#hidden-agents_with_templates").val(); + $("#id_group").pandoraSelectGroupAgent ({ agentSelect: "select#id_agents", recursion: function() {return recursion}, + filter_agents_json: filter_agents_json, callbackPost: function () { var $select_template = $("#id_alert_templates").disable (); - var $select_compound = $("#id_alert_compounds").disable (); $("option", $select_template).remove (); - $("option", $select_compound).remove (); } }); @@ -249,45 +208,28 @@ $(document).ready (function () { idAgents.push($(val).val()); }); $("#template_loading").show(); - $("#compound_loading").show(); var $select_template = $("#id_alert_templates").disable (); - var $select_compound = $("#id_alert_compounds").disable (); $("option", $select_template).remove (); - $("option", $select_compound).remove (); - + jQuery.post ("ajax.php", {"page" : "godmode/massive/massive_add_action_alerts", "get_alerts" : 1, - "get_compounds" : 0, - "id_agents[]" : idAgents + "id_agents[]" : idAgents }, - function (data, status) { - options = ""; - jQuery.each (data, function (id, value) { - options += ""; - }); - $("#id_alert_templates").append (options); - $("#template_loading").hide (); - $select_template.enable (); - }, - "json" - ); - - jQuery.post ("ajax.php", - {"page" : "godmode/massive/massive_add_action_alerts", - "get_alerts" : 1, - "get_compounds" : 1, - "id_agents[]" : idAgents - }, function (data, status) { options = ""; jQuery.each (data, function (id, value) { - options += ""; + options += ""; }); - $("#id_alert_compounds").append (options); - $("#compound_loading").hide (); - $select_compound.enable (); + + if(options == "") { + options += ""; + } + + $("#id_alert_templates").append (options); + $("#template_loading").hide (); + $select_template.enable (); }, "json" ); @@ -302,6 +244,8 @@ $(document).ready (function () { $(this).remove (); return false; }); + + $('#id_group').trigger('change'); }); /* ]]> */ diff --git a/pandora_console/godmode/massive/massive_delete_action_alerts.php b/pandora_console/godmode/massive/massive_delete_action_alerts.php index babd80940c..461b604637 100644 --- a/pandora_console/godmode/massive/massive_delete_action_alerts.php +++ b/pandora_console/godmode/massive/massive_delete_action_alerts.php @@ -36,23 +36,9 @@ if (is_ajax ()) { echo json_encode (''); return; } - $get_compounds = get_parameter ('get_compounds'); - if (!$get_compounds) { - $alert_templates = agents_get_alerts_simple ($id_agents); - echo json_encode (index_array ($alert_templates, 'id_alert_template', 'template_name')); - return; - } else { - $filter = ''; - foreach ($id_agents as $id_agent) { - if ($filter != '') { - $filter .= ' OR '; - } - $filter .= 'id_agent=' . $id_agent; - } - $alert_compounds = alerts_get_alert_compounds ($filter, array('id', 'name')); - echo json_encode (index_array ($alert_compounds, 'id', 'name')); - return; - } + $alert_templates = agents_get_alerts_simple ($id_agents); + echo json_encode (index_array ($alert_templates, 'id_alert_template', 'template_name')); + return; } return; } @@ -60,7 +46,6 @@ if (is_ajax ()) { $id_group = (int) get_parameter ('id_group'); $id_agents = get_parameter ('id_agents'); $id_alert_templates = (array) get_parameter ('id_alert_templates'); -$id_alert_compounds = (array) get_parameter ('id_alert_compounds'); $recursion = get_parameter ('recursion'); $delete = (bool) get_parameter_post ('delete'); @@ -80,17 +65,8 @@ if ($delete) { $alerts_agent_modules = array_merge($alerts_agent_modules, alerts_get_alerts_agent_module ($agent_alert['id_agent_module'], true, false, 'id')); } } - - $cont = 0; - $alerts_compound = array(); - foreach($agent_alerts['compounds'] as $agent_alert){ - if (in_array($agent_alert['id'], $id_alert_compounds)) { - $alerts_compound[$cont] = $agent_alert['id']; - $cont = $cont + 1; - } - } - if (empty($alerts_agent_modules) && empty($alerts_compound)) { + if (empty($alerts_agent_modules)) { ui_print_result_message (false, '', __('Could not be deleted').". ".__('No alerts selected')); } else { $results = true; @@ -108,27 +84,16 @@ if ($delete) { } } } - - foreach($alerts_compound as $alert_compound) { - $compound_actions = alerts_get_alert_compound_actions ($alert_compound['id'], array('id','id_alert_action')); - foreach ($compound_actions as $compound_action) { - if ($compound_action['id_alert_action'] == $action) { - $result = alerts_delete_alert_compound_action($compound_action['id']); - if($result === false) - $results = false; - } - } - } if ($results) { db_pandora_audit("Masive management", "Delete alert action", false, false, 'Agent: ' . json_encode($id_agents) . ' Alert templates: ' . json_encode($id_alert_templates) . - ' Alert compound: ' . $id_alert_compounds . ' Action: ' . $action); + ' Action: ' . $action); } else { db_pandora_audit("Masive management", "Fail try to delete alert action", false, false, 'Agent: ' . json_encode($id_agents) . ' Alert templates: ' . json_encode($id_alert_templates) . - ' Alert compound: ' . $id_alert_compounds . ' Action: ' . $action); + ' Action: ' . $action); } ui_print_result_message ($results, __('Successfully deleted'), __('Could not be deleted')/*.": ". $agent_alerts['simple'][0]['id']*/); @@ -162,12 +127,11 @@ $table->data[0][1] = html_print_select_groups(false, "AR", true, 'id_group', $id $table->data[0][2] = __('Group recursion'); $table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion, true, false); -$table->data[1][0] = __('Agents'); +$table->data[1][0] = __('Agents with templates'); $table->data[1][0] .= ''; -$table->data[1][1] = html_print_select (agents_get_group_agents ($id_group, false, "none"), - 'id_agents[]', 0, false, '', '', true, true); +$table->data[1][1] = html_print_select (array(),'id_agents[]', 0, false, '', '', true, true); if (empty($id_agents)) { $alert_templates = ''; @@ -180,31 +144,23 @@ $table->data[2][0] .= html_print_image('images/spinner.png', true); $table->data[2][0] .= ''; $table->data[2][1] = html_print_select (index_array ($alert_templates, 'id_alert_template', 'template_name'), 'id_alert_templates[]', '', '', '', '', true, true, true, '', $alert_templates == 0); -if (empty($id_agents)) { - $alert_compounds = ''; -} else { - $filter = ''; - foreach ($id_agents as $id_agent) { - if ($filter != '') { - $filter .= ' OR '; - } - $filter .= 'id_agent=' . $id_agent; - } - $alert_compounds = alerts_get_alert_compounds ($filter, array('id', 'name')); -} -$table->data[3][0] = __('Alert compounds'); -$table->data[3][0] .= ''; -$table->data[3][1] = html_print_select (index_array ($alert_compounds, 'id', 'name'), 'id_alert_compounds[]', '', false, '', '', true, true, true, '', $alert_compounds == 0); - $actions = alerts_get_alert_actions (); -$table->data[4][0] = __('Action'); -$table->data[4][1] = html_print_select ($actions, 'action', '', '', __('None'), 0, true); +$table->data[3][0] = __('Action'); +$table->data[3][1] = html_print_select ($actions, 'action', '', '', __('None'), 0, true); echo ''; html_print_table ($table); +$sql = 'SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo IN (SELECT id_agent_module FROM talert_template_modules)'; +$agents_with_templates = db_get_all_rows_sql($sql); +$agents_with_templates_json = array(); +foreach($agents_with_templates as $ag) { + $agents_with_templates_json[] = $ag['id_agente']; +} +$agents_with_templates_json = json_encode($agents_with_templates_json); + +echo ""; + echo '
'; html_print_input_hidden ('delete', 1); html_print_submit_button (__('Delete'), 'go', false, 'class="sub delete"'); @@ -226,15 +182,16 @@ $(document).ready (function () { recursion = this.checked ? 1 : 0; $("#id_group").trigger("change"); }); - + + var filter_agents_json = $("#hidden-agents_with_templates").val(); + $("#id_group").pandoraSelectGroupAgent ({ agentSelect: "select#id_agents", recursion: function() {return recursion}, + filter_agents_json: filter_agents_json, callbackPost: function () { var $select_template = $("#id_alert_templates").disable (); - var $select_compound = $("#id_alert_compounds").disable (); $("option", $select_template).remove (); - $("option", $select_compound).remove (); } }); @@ -248,17 +205,13 @@ $(document).ready (function () { idAgents.push($(val).val()); }); $("#template_loading").show(); - $("#compound_loading").show(); var $select_template = $("#id_alert_templates").disable (); - var $select_compound = $("#id_alert_compounds").disable (); $("option", $select_template).remove (); - $("option", $select_compound).remove (); jQuery.post ("ajax.php", {"page" : "godmode/massive/massive_delete_action_alerts", "get_alerts" : 1, - "get_compounds" : 0, "id_agents[]" : idAgents }, function (data, status) { @@ -271,26 +224,11 @@ $(document).ready (function () { $select_template.enable (); }, "json" - ); + ); + } + + $('#id_group').trigger('change'); - jQuery.post ("ajax.php", - {"page" : "godmode/massive/massive_delete_action_alerts", - "get_alerts" : 1, - "get_compounds" : 1, - "id_agents[]" : idAgents - }, - function (data, status) { - options = ""; - jQuery.each (data, function (id, value) { - options += ""; - }); - $("#id_alert_compounds").append (options); - $("#compound_loading").hide (); - $select_compound.enable (); - }, - "json" - ); - } }); /* ]]> */ diff --git a/pandora_console/include/javascript/jquery.pandora.controls.js b/pandora_console/include/javascript/jquery.pandora.controls.js index ca3fd200b4..7be143bca0 100644 --- a/pandora_console/include/javascript/jquery.pandora.controls.js +++ b/pandora_console/include/javascript/jquery.pandora.controls.js @@ -9,6 +9,7 @@ this.defaults = { agentSelect: "select#id_agent", recursion: 0, + filter_agents_json: "", loading: "#agent_loading", callbackBefore: dummyFunc, callbackPre: dummyFunc, @@ -38,6 +39,7 @@ "get_group_agents" : 1, "id_group" : this.value, "recursion" : config.recursion, + "filter_agents_json" : config.filter_agents_json, "disabled" : config.disabled ? 1 : 0, };