2010-10-08 Junichi Satoh <junichi@rworks.jp>

* 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().



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3367 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
jsatoh 2010-10-08 03:26:49 +00:00
parent 7109acb41a
commit 2a5bf6ea34
4 changed files with 327 additions and 54 deletions

View File

@ -1,3 +1,11 @@
2010-10-08 Junichi Satoh <junichi@rworks.jp>
* 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 <slerena@artica.es>
* godmode/alerts/alert_list.list.php: Another ugly warning fixed due

View File

@ -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] .= '<img src="images/spinner.png" />';
$table->data[1][0] .= '</span>';
$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] .= '<span id="template_loading" class="invisible">';
$table->data[2][0] .= '<img src="images/spinner.png" />';
$table->data[2][0] .= '</span>';
$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] .= '<span id="compound_loading" class="invisible">';
$table->data[3][0] .= '<img src="images/spinner.png" />';
$table->data[3][0] .= '</span>';
$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] .= '<span><a href="#" class="show_advanced_actions">'.__('Advanced options').' &raquo; </a></span>';
$table->data[2][1] .= '<span id="advanced_actions" class="advanced_actions invisible">';
$table->data[2][1] .= __('Number of alerts match from').' ';
$table->data[2][1] .= print_input_text ('fires_min', 0, '', 4, 10, true);
$table->data[2][1] .= ' '.__('to').' ';
$table->data[2][1] .= print_input_text ('fires_max', 0, '', 4, 10, true);
$table->data[2][1] .= print_help_icon ("alert-matches", true);
$table->data[2][1] .= '</span>';
$table->data[4][0] = __('Action');
$table->data[4][1] = print_select ($actions, 'action', '', '', __('None'), 0, true);
$table->data[4][1] .= '<span><a href="#" class="show_advanced_actions">'.__('Advanced options').' &raquo; </a></span>';
$table->data[4][1] .= '<span id="advanced_actions" class="advanced_actions invisible">';
$table->data[4][1] .= __('Number of alerts match from').' ';
$table->data[4][1] .= print_input_text ('fires_min', 0, '', 4, 10, true);
$table->data[4][1] .= ' '.__('to').' ';
$table->data[4][1] .= print_input_text ('fires_max', 0, '', 4, 10, true);
$table->data[4][1] .= print_help_icon ("alert-matches", true);
$table->data[4][1] .= '</span>';
echo '<form method="post" action="index.php?sec=gagente&sec2=godmode/massive/massive_operations&option=add_action_alerts" onsubmit="if (! confirm(\''.__('Are you sure?').'\')) return false;">';
print_table ($table);
@ -137,10 +206,72 @@ require_jquery_file ('pandora.controls');
<script type="text/javascript">
$(document).ready (function () {
update_alerts();
$("#id_group").pandoraSelectGroupAgent ({
agentSelect: "select#id_agents"
agentSelect: "select#id_agents",
callbackPost: function () {
var $select_template = $("#id_alert_templates").disable ();
var $select_compound = $("#id_alert_compounds").disable ();
$("option", $select_template).remove ();
$("option", $select_compound).remove ();
}
});
$("#id_agents").change (function () {
update_alerts();
});
function update_alerts() {
var idAgents = Array();
jQuery.each ($("#id_agents option:selected"), function (i, val) {
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
},
function (data, status) {
options = "";
jQuery.each (data, function (id, value) {
options += "<option value=\""+id+"\">"+value+"</option>";
});
$("#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 += "<option value=\""+id+"\">"+value+"</option>";
});
$("#id_alert_compounds").append (options);
$("#compound_loading").hide ();
$select_compound.enable ();
},
"json"
);
}
$("a.show_advanced_actions").click (function () {
/* It can be done in two different sites, so it must use two different selectors */
actions = $(this).parents ("form").children ("span.advanced_actions");

View File

@ -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');
$delete = (bool) get_parameter_post ('delete');
@ -42,45 +74,52 @@ if ($delete) {
$alerts_agent_modules = array();
foreach($agent_alerts['simple'] as $agent_alert){
$alerts_agent_modules = array_merge($alerts_agent_modules, get_alerts_agent_module ($agent_alert['id_agent_module'], true, false, 'id'));
if (in_array($agent_alert['id_alert_template'], $id_alert_templates)) {
$alerts_agent_modules = array_merge($alerts_agent_modules, get_alerts_agent_module ($agent_alert['id_agent_module'], true, false, 'id'));
}
}
$cont = 0;
$alerts_compound = array();
foreach($agent_alerts['compounds'] as $agent_alert){
$alerts_compound[$cont] = $agent_alert['id'];
$cont = $cont + 1;
if (in_array($agent_alert['id'], $id_alert_compounds)) {
$alerts_compound[$cont] = $agent_alert['id'];
$cont = $cont + 1;
}
}
$results = true;
$agent_module_actions = array();
if (empty($alerts_agent_modules) && empty($alerts_compound)) {
print_result_message (false, '', __('Could not be deleted').". ".__('No alerts selected'));
} else {
$results = true;
$agent_module_actions = array();
foreach($alerts_agent_modules as $alert_agent_module){
$agent_module_actions = get_alert_agent_module_actions ($alert_agent_module['id'], array('id','id_alert_action'));
foreach($alerts_agent_modules as $alert_agent_module){
$agent_module_actions = get_alert_agent_module_actions ($alert_agent_module['id'], array('id','id_alert_action'));
foreach ($agent_module_actions as $agent_module_action){
if($agent_module_action['id_alert_action'] == $action) {
$result = delete_alert_agent_module_action ($agent_module_action['id']);
foreach ($agent_module_actions as $agent_module_action){
if($agent_module_action['id_alert_action'] == $action) {
$result = delete_alert_agent_module_action ($agent_module_action['id']);
if($result === false)
$results = false;
if($result === false)
$results = false;
}
}
}
}
foreach($alerts_compound as $alert_compound) {
$compound_actions = 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 = delete_alert_compound_action($compound_action['id']);
if($result === false)
$results = false;
foreach($alerts_compound as $alert_compound) {
$compound_actions = 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 = delete_alert_compound_action($compound_action['id']);
if($result === false)
$results = false;
}
}
}
}
print_result_message ($results, __('Successfully deleted'), __('Could not be deleted')/*.": ". $agent_alerts['simple'][0]['id']*/);
print_result_message ($results, __('Successfully deleted'), __('Could not be deleted')/*.": ". $agent_alerts['simple'][0]['id']*/);
}
}
else {
print_result_message (false, '', __('Could not be deleted').". ".__('No action selected'));
@ -112,10 +151,39 @@ $table->data[1][0] .= '<img src="images/spinner.png" />';
$table->data[1][0] .= '</span>';
$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] .= '<span id="template_loading" class="invisible">';
$table->data[2][0] .= '<img src="images/spinner.png" />';
$table->data[2][0] .= '</span>';
$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] .= '<span id="compound_loading" class="invisible">';
$table->data[3][0] .= '<img src="images/spinner.png" />';
$table->data[3][0] .= '</span>';
$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[4][0] = __('Action');
$table->data[4][1] = print_select ($actions, 'action', '', '', __('None'), 0, true);
echo '<form method="post" action="index.php?sec=gagente&sec2=godmode/massive/massive_operations&option=delete_action_alerts" onsubmit="if (! confirm(\''.__('Are you sure?').'\')) return false;">';
print_table ($table);
@ -134,9 +202,71 @@ require_jquery_file ('pandora.controls');
<script type="text/javascript">
$(document).ready (function () {
update_alerts();
$("#id_group").pandoraSelectGroupAgent ({
agentSelect: "select#id_agents"
agentSelect: "select#id_agents",
callbackPost: function () {
var $select_template = $("#id_alert_templates").disable ();
var $select_compound = $("#id_alert_compounds").disable ();
$("option", $select_template).remove ();
$("option", $select_compound).remove ();
}
});
$("#id_agents").change (function () {
update_alerts();
});
function update_alerts() {
var idAgents = Array();
jQuery.each ($("#id_agents option:selected"), function (i, val) {
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) {
options = "";
jQuery.each (data, function (id, value) {
options += "<option value=\""+id+"\">"+value+"</option>";
});
$("#id_alert_templates").append (options);
$("#template_loading").hide ();
$select_template.enable ();
},
"json"
);
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 += "<option value=\""+id+"\">"+value+"</option>";
});
$("#id_alert_compounds").append (options);
$("#compound_loading").hide ();
$select_compound.enable ();
},
"json"
);
}
});
/* ]]> */
</script>

View File

@ -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);
}