2009-09-09 Miguel de Dios <miguel.dedios@artica.es>

* operation/agentes/estado_agente.php: add ajax request for actions.
	* godmode/alerts/alert_list.php: change the checkboxs for a ajax
	select for actions. And fix messages when you try make two times the same
	alert.
	Fixes: 2843852



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1929 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2009-09-10 17:55:44 +00:00
parent 0e9b86cc97
commit 66956ca4a0
3 changed files with 118 additions and 32 deletions

View File

@ -1,3 +1,11 @@
2009-09-09 Miguel de Dios <miguel.dedios@artica.es>
* operation/agentes/estado_agente.php: add ajax request for actions.
* godmode/alerts/alert_list.php: change the checkboxs for a ajax
select for actions. And fix messages when you try make two times the same
alert.
Fixes: 2843852
2009-09-09 Miguel de Dios <miguel.dedios@artica.es>
* include/javascript/pandora_modules.js: clean code.

View File

@ -109,22 +109,27 @@ if ($create_alert) {
$id_alert_template = (int) get_parameter ('template');
$id_agent_module = (int) get_parameter ('id_agent_module');
$id = create_alert_agent_module ($id_agent_module, $id_alert_template);
print_result_message ($id,
__('Successfully created'),
__('Could not be created'));
if ($id !== false) {
$actions = (array) get_parameter ('actions');
$fires_min = (array) get_parameter ('fires_min');
$fires_max = (array) get_parameter ('fires_max');
foreach ($actions as $id_action) {
$values = array ();
if (isset ($fires_min[$id_action]))
$values['fires_min'] = @max ($fires_min[$id_action], 0);
if (($fires_max != -1) && (isset ($fires_min[$id_action])))
$values['fires_max'] = @max ($fires_max[$id_action], 0);
add_alert_agent_module_action ($id, $id_action, $values);
if (get_db_row_sql("SELECT COUNT(id)
FROM talert_template_modules
WHERE id_agent_module = " . $id_agent_module . "
AND id_alert_template = " . $id_alert_template) > 0) {
print_result_message (false, '', __('Yet added'));
}
else {
$id = create_alert_agent_module ($id_agent_module, $id_alert_template);
print_result_message ($id,
__('Successfully created'),
__('Could not be created'));
if ($id !== false) {
$action_select = get_parameter('action_select');
if ($action_select != 0) {
$values = array();
$values['fires_min'] = get_parameter ('fires_min');
$values['fires_max'] = get_parameter ('fires_max');
add_alert_agent_module_action ($id, $action_select, $values);
}
}
}
}
@ -462,23 +467,37 @@ $table->data[1][1] .= ' <a class="template_details invisible" href="#">
<img class="img_help" src="images/zoom.png" /></a>';
$table->data[2][0] = __('Actions');
$actions = get_alert_actions ();
if (empty ($actions))
$actions = array ();
//$actions = get_alert_actions ();
//if (empty ($actions))
// $actions = array ();
//foreach ($actions as $action_id => $action_name) {
// $id = 'actions['.$action_id.']';
// $table->data[2][1] .= print_checkbox ($id, $action_id, false, true);
// $table->data[2][1] .= print_label ($action_name, 'checkbox-'.$id, true);
// $table->data[2][1] .= ' <span id="advanced_'.$action_id.'" class="advanced_actions invisible">';
// $table->data[2][1] .= __('From').' ';
// $table->data[2][1] .= print_input_text ('fires_min['.$action_id.']', -1, '', 4, 10, true);
// $table->data[2][1] .= ' '.__('to').' ';
// $table->data[2][1] .= print_input_text ('fires_max['.$action_id.']', -1, '', 4, 10, true);
// $table->data[2][1] .= ' '.__('matches of the alert');
// $table->data[2][1] .= '</span>';
// $table->data[2][1] .= '<br />';
//}
$actions = array ('0' => __('None'));
$table->data[2][1] = '<div class="actions_container">';
foreach ($actions as $action_id => $action_name) {
$id = 'actions['.$action_id.']';
$table->data[2][1] .= print_checkbox ($id, $action_id, false, true);
$table->data[2][1] .= print_label ($action_name, 'checkbox-'.$id, true);
$table->data[2][1] .= ' <span id="advanced_'.$action_id.'" class="advanced_actions invisible">';
$table->data[2][1] .= __('From').' ';
$table->data[2][1] .= print_input_text ('fires_min['.$action_id.']', -1, '', 4, 10, true);
$table->data[2][1] .= ' '.__('to').' ';
$table->data[2][1] .= print_input_text ('fires_max['.$action_id.']', -1, '', 4, 10, true);
$table->data[2][1] .= ' '.__('matches of the alert');
$table->data[2][1] .= '</span>';
$table->data[2][1] .= '<br />';
}
$table->data[2][1] = print_select($actions,'action_select','','','','',true);
$table->data[2][1] .= ' <span id="action_loading" class="invisible">';
$table->data[2][1] .= '<img src="images/spinner.gif" /></span>';
$table->data[2][1] .= ' <span id="advanced_action" class="advanced_actions invisible">';
$table->data[2][1] .= __('From').' ';
$table->data[2][1] .= print_input_text ('fires_min', '', '', 4, 10, true);
$table->data[2][1] .= ' '.__('to').' ';
$table->data[2][1] .= print_input_text ('fires_max', '', '', 4, 10, true);
$table->data[2][1] .= ' '.__('matches of the alert');
$table->data[2][1] .= '</span>';
$table->data[2][1] .= '</div>';
echo '<form class="add_alert_form" method="post">';
@ -658,7 +677,47 @@ $(document).ready (function () {
}).click (function () {
return false;
});
$("#action_select").hide();
$("#action_select").html('');
$("#action_loading").show ();
jQuery.post ("ajax.php",
{"page" : "operation/agentes/estado_agente",
"get_actions_alert_template" : 1,
"id_template" : this.value
},
function (data, status) {
if (data != '') {
jQuery.each (data, function (i, val) {
option = $("<option></option>")
.attr ("value", val["id"])
.append (val["name"]);
$("#action_select").append (option);
});
}
option = $("<option></option>")
.attr ("value", '0')
.append ('<?php echo __('None'); ?>');
$("#action_select").append (option);
$("#action_loading").hide ();
$("#action_select").show();
$('#advanced_action').show();
},
"json"
);
});
$("#action_select").change(function () {
if ($("#action_select").attr ("value") != '0') {
$('#advanced_action').show();
}
else {
$('#advanced_action').hide();
}
}
);
$("#id_agent_module").change (function () {
var $value = $(this).siblings ("span#latest_value").hide ();

View File

@ -29,6 +29,25 @@ if (! give_acl ($config['id_user'], 0, "AR")) {
if (is_ajax ()) {
$get_agent_module_last_value = (bool) get_parameter ('get_agent_module_last_value');
$get_actions_alert_template = (bool) get_parameter("get_actions_alert_template");
if ($get_actions_alert_template) {
$id_template = get_parameter("id_template");
$rows = get_db_all_rows_sql("SELECT t1.id, t1.name,
(SELECT COUNT(t2.id)
FROM talert_templates AS t2
WHERE t2.id = " . $id_template . "
AND t2.id_alert_action = t1.id) as 'sort_order'
FROM talert_actions AS t1
ORDER BY sort_order DESC");
if ($rows !== false) {
echo json_encode($rows);
}
return;
}
if ($get_agent_module_last_value) {
$id_module = (int) get_parameter ('id_agent_module');