diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index b8ce45fbcf..6e0fab2d1b 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2010-10-08 Junichi Satoh + + * godmode/massive/massive_add_action_alerts.php, + godmode/massive/massive_delete_action_alerts.php: Added simple and + compound alerts selections. + + * include/functions_alerts.php: Added new function, get_alert_compounds(). + 2010-10-07 Sancho Lerena * godmode/alerts/alert_list.list.php: Another ugly warning fixed due diff --git a/pandora_console/godmode/massive/massive_add_action_alerts.php b/pandora_console/godmode/massive/massive_add_action_alerts.php index 42ed6e4d1a..dfe33c09b1 100644 --- a/pandora_console/godmode/massive/massive_add_action_alerts.php +++ b/pandora_console/godmode/massive/massive_add_action_alerts.php @@ -26,8 +26,40 @@ if (! give_acl ($config['id_user'], 0, "AW")) { require_once ('include/functions_agents.php'); require_once ('include/functions_alerts.php'); +if (is_ajax ()) { + $get_alerts = (bool) get_parameter ('get_alerts'); + + if ($get_alerts) { + $id_agents = get_parameter ('id_agents'); + if (empty($id_agents)) { + echo json_encode (''); + return; + } + $get_compounds = get_parameter ('get_compounds'); + if (!$get_compounds) { + $alert_templates = get_agent_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 = get_alert_compounds ($filter, array('id', 'name')); + echo json_encode (index_array ($alert_compounds, 'id', 'name')); + return; + } + } + return; +} + $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'); $add = (bool) get_parameter_post ('add'); @@ -44,15 +76,19 @@ if ($add) { $cont = 0; $agent_alerts_id = array(); foreach($agent_alerts['simple'] as $agent_alert){ - $agent_alerts_id[$cont] = $agent_alert['id']; - $cont = $cont + 1; + if (in_array($agent_alert['id_alert_template'], $id_alert_templates)) { + $agent_alerts_id[$cont] = $agent_alert['id']; + $cont = $cont + 1; + } } $cont = 0; $agent_alerts_id_compound = array(); foreach($agent_alerts['compounds'] as $agent_alert){ - $agent_alerts_id_compound[$cont] = $agent_alert['id']; - $cont = $cont + 1; + if (in_array($agent_alert['id'], $id_alert_compounds)) { + $agent_alerts_id_compound[$cont] = $agent_alert['id']; + $cont = $cont + 1; + } } $options = array(); @@ -62,20 +98,24 @@ if ($add) { if($fires_max > 0) $options['fires_max'] = $fires_max; - $results = true; - foreach($agent_alerts_id as $agent_alert_id){ - $result = add_alert_agent_module_action($agent_alert_id, $action, $options); - if($result === false) - $results = false; - } + if (empty($agent_alerts_id) && empty($agent_alerts_id_compound)) { + print_result_message (false, '', __('Could not be added').". ".__('No alerts selected')); + } else { + $results = true; + foreach($agent_alerts_id as $agent_alert_id){ + $result = add_alert_agent_module_action($agent_alert_id, $action, $options); + if($result === false) + $results = false; + } - foreach($agent_alerts_id_compound as $agent_alert_id_compound) { - $result = add_alert_compound_action ($agent_alert_id_compound, $action, $options); - if($result === false) - $results = false; - } + foreach($agent_alerts_id_compound as $agent_alert_id_compound) { + $result = add_alert_compound_action ($agent_alert_id_compound, $action, $options); + if($result === false) + $results = false; + } - print_result_message ($results, __('Successfully added'), __('Could not be added')); + print_result_message ($results, __('Successfully added'), __('Could not be added')); + } } else { print_result_message (false, '', __('Could not be added').". ".__('No action selected')); @@ -107,18 +147,47 @@ $table->data[1][0] .= ''; $table->data[1][0] .= ''; $table->data[1][1] = print_select (get_group_agents ($id_group, false, "none"), 'id_agents[]', 0, false, '', '', true, true); + +if (empty($id_agents)) { + $alert_templates = ''; +} else { + $alert_templates = get_agent_alerts_simple ($id_agents); +} +$table->data[2][0] = __('Alert templates'); +$table->data[2][0] .= ''; +$table->data[2][1] = 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 = get_alert_compounds ($filter, array('id', 'name')); +} +$table->data[3][0] = __('Alert compounds'); +$table->data[3][0] .= ''; +$table->data[3][1] = print_select (index_array ($alert_compounds, 'id', 'name'), 'id_alert_compounds[]', '', false, '', '', true, true, true, '', $alert_compounds == 0); $actions = get_alert_actions (); -$table->data[2][0] = __('Action'); -$table->data[2][1] = print_select ($actions, 'action', '', '', __('None'), 0, true); -$table->data[2][1] .= ''.__('Advanced options').' » '; -$table->data[2][1] .= ''; +$table->data[4][0] = __('Action'); +$table->data[4][1] = print_select ($actions, 'action', '', '', __('None'), 0, true); +$table->data[4][1] .= ''.__('Advanced options').' » '; +$table->data[4][1] .= ''; echo '
'; print_table ($table); @@ -137,10 +206,72 @@ require_jquery_file ('pandora.controls'); diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index f803f72d0c..0fe8b32037 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -764,6 +764,10 @@ function add_alert_compound_element ($id_alert_compound, $id_alert_template_modu return @process_sql_insert ('talert_compound_elements', $values); } +function get_alert_compounds ($filter = false, $fields = false) { + return @get_db_all_rows_filter ('talert_compound', $filter, $fields); +} + function get_alert_compound ($id_alert_compound) { return get_db_row ('talert_compound', 'id', $id_alert_compound); }