From 66956ca4a04d451504f2f0d9e70630727c072b9d Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 10 Sep 2009 17:55:44 +0000 Subject: [PATCH] 2009-09-09 Miguel de Dios * 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 --- pandora_console/ChangeLog | 8 ++ pandora_console/godmode/alerts/alert_list.php | 123 +++++++++++++----- .../operation/agentes/estado_agente.php | 19 +++ 3 files changed, 118 insertions(+), 32 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 5763c8aaa5..bd56c2ee70 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2009-09-09 Miguel de Dios + + * 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 * include/javascript/pandora_modules.js: clean code. diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index 98a14fef0f..77e7a8c756 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -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] .= ' '; $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] .= ' '; +// $table->data[2][1] .= '
'; +//} + +$actions = array ('0' => __('None')); + $table->data[2][1] = '
'; -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] .= ' '; - $table->data[2][1] .= '
'; -} +$table->data[2][1] = print_select($actions,'action_select','','','','',true); +$table->data[2][1] .= ' '; +$table->data[2][1] .= ' '; $table->data[2][1] .= '
'; echo '
'; @@ -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 = $("") + .attr ("value", val["id"]) + .append (val["name"]); + $("#action_select").append (option); + }); + } + option = $("") + .attr ("value", '0') + .append (''); + $("#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 (); diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index e178c96f50..9b4e640e3e 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -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');