From 281389eff50d9ba3d142b79e2a2187276fec0d85 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 7 Apr 2010 12:34:14 +0000 Subject: [PATCH] 2010-04-05 Miguel de Dios * godmode/alerts/alert_list.php: cleaned source code, added the tabs for to use page alone (not in agent). * godmode/alerts/alert_list.builder.php: tab for the make a alert. * godmode/alerts/alert_list.list.php: tab for the list of alerts. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2546 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 9 + .../godmode/alerts/alert_list.builder.php | 366 +++++++++++ .../godmode/alerts/alert_list.list.php | 575 ++++++++++++++++++ pandora_console/godmode/alerts/alert_list.php | 107 +++- 4 files changed, 1025 insertions(+), 32 deletions(-) create mode 100644 pandora_console/godmode/alerts/alert_list.builder.php create mode 100644 pandora_console/godmode/alerts/alert_list.list.php diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index dd9f911fa9..65d3ca927e 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,12 @@ +2010-04-05 Miguel de Dios + + * godmode/alerts/alert_list.php: cleaned source code, added the tabs for to + use page alone (not in agent). + + * godmode/alerts/alert_list.builder.php: tab for the make a alert. + + * godmode/alerts/alert_list.list.php: tab for the list of alerts. + 2010-04-05 Miguel de Dios * include/functions_agents.php: changed the functions diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php new file mode 100644 index 0000000000..66160edf9c --- /dev/null +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -0,0 +1,366 @@ +'.__('Add alert').''; + +$table->id = 'add_alert_table'; +$table->class = 'databox'; +$table->head = array (); +$table->data = array (); +$table->size = array (); +$table->size = array (); +$table->size[0] = '10%'; +$table->size[1] = '90%'; +$table->style[0] = 'font-weight: bold; vertical-align: top;'; + +/* Add an agent selector */ +if (! $id_agente) { + $table->data['group'][0] = __('Group'); + $table->data['group'][1] = print_select ($groups, 'id_group', $id_group, + false, '', '', true); + + $table->data['agent'][0] = __('Agent'); + + $table->data['agent'][1] = print_input_text_extended ('id_agent', __('Select'), 'text_id_agent', '', 30, 100, false, '', + array('style' => 'background: url(images/lightning.png) no-repeat right;'), true) + . ' ' . __("Type at least two characters to search") . ''; +} + +$table->data[0][0] = __('Module'); +$modules = array (); +if ($id_agente) + $modules = get_agent_modules ($id_agente, false, array("delete_pending" => 0)); + +$table->data[0][1] = print_select ($modules, 'id_agent_module', 0, true, + __('Select'), 0, true, false, true, '', ($id_agente == 0)); +$table->data[0][1] .= ' '; +$table->data[0][1] .= ' '; + +$table->data[1][0] = __('Template'); +$templates = get_alert_templates (false, array ('id', 'name')); +$table->data[1][1] = print_select (index_array ($templates, 'id', 'name'), + 'template', '', '', __('Select'), 0, true); +$table->data[1][1] .= ' '; + +$table->data[2][0] = __('Actions'); + +$actions = array ('0' => __('None')); + +$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 '
'; + +print_table ($table); + +echo '
'; +print_submit_button (__('Add'), 'add', false, 'class="sub next"'); +print_input_hidden ('create_alert', 1); +echo '
'; + +require_css_file ('cluetip'); +require_jquery_file ('cluetip'); +require_jquery_file ('pandora.controls'); +require_jquery_file ('bgiframe'); +require_jquery_file ('autocomplete'); +?> + \ No newline at end of file diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php new file mode 100644 index 0000000000..e5bab201cd --- /dev/null +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -0,0 +1,575 @@ +'.__('Alert control filter').' '.print_image ("images/down.png", true, array ("title" => __('Toggle filter(s)'))).'

'; + +//INI DIV OF FORM FILTER +echo "\n"; +//END DIV OF FORM FILTER + +$simple_alerts = array(); + +$total = 0; +$where = ''; + +$total = get_agent_alerts_simple (array_keys ($agents), array('priority' => $priority), + false, $where, false, false, false, true); + +pagination ($total, 'index.php?sec=gagente&sec2=godmode/alerts/alert_list'); +$simple_alerts = get_agent_alerts_simple (array_keys ($agents), array('priority' => $priority), + array ('offset' => (int) get_parameter ('offset'), + 'limit' => $config['block_size']), $where); + +$table->class = 'alert_list'; +$table->width = '90%'; +$table->size = array (); +$table->head = array (); +$table->head[0] = "" . __('E/D') . ""; + +$table->style = array (); +$table->style[1] = 'font-weight: bold'; +$table->head[1] = __('Agent'); +$table->size[0] = '20px'; +$table->size[1] = '15%'; +$table->size[2] = '20%'; +$table->size[3] = '15%'; +if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { + $table->size[4] = '20px'; +} +$table->size[5] = '50%'; + +$table->head[2] = __('Module'); +$table->head[3] = __('Template'); +if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { + $table->head[4] = "" . __('P.') . ""; +} +$table->head[5] = __('Actions'); +$table->head[6] = __('Status'); +$table->head[7] = ''; + +$table->data = array (); + +$rowPair = true; +$iterator = 0; + +foreach ($simple_alerts as $alert) { + if ($alert['disabled']) { + $table->rowstyle[$iterator] = 'font-style: italic; color: #aaaaaa;'; + $table->style[$iterator][1] = 'font-style: italic; color: #aaaaaa;'; + } + + if ($rowPair) + $table->rowclass[$iterator] = 'rowPair'; + else + $table->rowclass[$iterator] = 'rowOdd'; + $rowPair = !$rowPair; + $iterator++; + + $data = array (); + + $data[0] = '
'; + if ($alert['disabled']) { + $data[0] .= print_input_image ('enable', 'images/lightbulb_off.png', 1, '', true); + $data[0] .= print_input_hidden ('enable_alert', 1, true); + } + else { + $data[0] .= print_input_image ('disable', 'images/lightbulb.png', 1, '', true); + $data[0] .= print_input_hidden ('disable_alert', 1, true); + } + $data[0] .= print_input_hidden ('id_alert', $alert['id'], true); + $data[0] .= '
'; + + $id_agent = get_agentmodule_agent ($alert['id_agent_module']); + $data[1] = ''; + if ($alert['disabled']) + $data[1] .= ''; + $data[1] .= get_agent_name ($id_agent); + if ($alert['disabled']) + $data[1] .= ''; + $data[1] .= ''; + + $data[2] = get_agentmodule_name ($alert['id_agent_module']); + $data[3] = ' + '; + + $data[3] .= ""; + $data[3] .= get_alert_template_name ($alert['id_alert_template']); + $data[3] .= ""; + + if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { + $policyInfo = isAlertInPolicy($alert['id_agent_module'], $alert['id_alert_template'], false); + if ($policyInfo === false) + $data[4] = ''; + else { + $img = 'images/policies.png'; + + $data[4] = '' . + print_image($img,true, array('title' => $policyInfo['name_policy'])) . + ''; + } + } + + $actions = get_alert_agent_module_actions ($alert['id']); + + + if (empty($actions)){ + // Get and show default actions for this alert + $default_action = get_db_sql ("SELECT id_alert_action FROM talert_templates WHERE id = ".$alert["id_alert_template"]); + if ($default_action != ""){ + $data[5] = __("Default"). " : ".get_db_sql ("SELECT name FROM talert_actions WHERE id = $default_action"); + } + + } else { + $data[5] = '
    '; + foreach ($actions as $action_id => $action) { + $data[5] .= '
  • '; + if ($alert['disabled']) + $data[5] .= ''; + else + $data[5] .= ''; + $data[5] .= $action['name']; + $data[5] .= ' ('; + if ($action['fires_min'] == $action['fires_max']) { + if ($action['fires_min'] == 0) + $data[5] .= __('Always'); + else + $data[5] .= __('On').' '.$action['fires_min']; + } else { + if ($action['fires_min'] == 0) + $data[5] .= __('Until').' '.$action['fires_max']; + else + $data[5] .= __('From').' '.$action['fires_min']. + ' '.__('to').' '.$action['fires_max']; + } + + $data[5] .= ')'; + $data[5] .= ''; + $data[5] .= ' '; + $data[5] .= ''; + $data[5] .= ''; + $data[5] .= '
  • '; + } + $data[5] .= '
'; + } + + + $data[5] .= ''; + $data[5] .= print_image ('images/add.png', true); + if ($alert['disabled']) + $data[5] .= ' '. '' .__('Add action') . ''; + else + $data[5] .= ' ' . __('Add action'); + $data[5] .= ''; + + $status = STATUS_ALERT_NOT_FIRED; + $title = ""; + + if ($alert["times_fired"] > 0) { + $status = STATUS_ALERT_FIRED; + $title = __('Alert fired').' '.$alert["times_fired"].' '.__('times'); + } elseif ($alert["disabled"] > 0) { + $status = STATUS_ALERT_DISABLED; + $title = __('Alert disabled'); + } else { + $status = STATUS_ALERT_NOT_FIRED; + $title = __('Alert not fired'); + } + + $data[6] = "
" . print_status_image($status, $title, true) . "
"; + + $data[7] = '
'; + + $data[7] .= print_input_image ('delete', 'images/cross.png', 1, '', true); + $data[7] .= print_input_hidden ('delete_alert', 1, true); + $data[7] .= print_input_hidden ('id_alert', $alert['id'], true); + $data[7] .= '
'; + array_push ($table->data, $data); +} + +if (isset($data)){ + print_table ($table); +} else { + echo "
".__('No alerts defined')."
"; +} + +echo ''; + +require_css_file ('cluetip'); +require_jquery_file ('cluetip'); +require_jquery_file ('pandora.controls'); +require_jquery_file ('bgiframe'); +require_jquery_file ('autocomplete'); +?> + \ No newline at end of file diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index 3fe805a7f6..6ccc79be33 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -13,8 +13,22 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +global $config; + +// Login check check_login (); +if (! give_acl ($config['id_user'], 0, "LW")) { + audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation", + "Trying to access Alert Management"); + require ("general/noaccess.php"); + exit; +} + +require_once ('include/functions_agents.php'); +require_once ('include/functions_alerts.php'); +$isFunctionPolicies = enterprise_include ('include/functions_policies.php'); + if (is_ajax ()) { $get_agent_alerts_simple = (bool) get_parameter ('get_agent_alerts_simple'); $disable_alert = (bool) get_parameter ('disable_alert'); @@ -84,36 +98,27 @@ $id_group = 0; /* Check if this page is included from a agent edition */ if (isset ($id_agente)) { $id_group = get_agent_group ($id_agente); -} else { +} +else { $id_agente = 0; } -if (! give_acl ($config['id_user'], 0, "LW")) { - audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation", - "Trying to access Alert Management"); - require ("general/noaccess.php"); - exit; -} - -require_once ('include/functions_agents.php'); -require_once ('include/functions_alerts.php'); -$isFunctionPolicies = enterprise_include ('include/functions_policies.php'); - $create_alert = (bool) get_parameter ('create_alert'); $add_action = (bool) get_parameter ('add_action'); $delete_action = (bool) get_parameter ('delete_action'); $delete_alert = (bool) get_parameter ('delete_alert'); $disable_alert = (bool) get_parameter ('disable_alert'); $enable_alert = (bool) get_parameter ('enable_alert'); - -// Header -if ($id_agente) { - $agents = array ($id_agente => get_agent_name ($id_agente)); -} else { - print_page_header (__('Alerts').' » '.__('Manage alerts'), "images/god2.png", false, "", true); - $groups = get_user_groups (); - $agents = get_group_agents (array_keys ($groups), false, "none"); -} +$tab = get_parameter('tab', 'list'); +$group = get_parameter('group', 1); //1 is All group +$templateName = get_parameter('template_name',''); +$moduleName = get_parameter('module_name',''); +$agentID = get_parameter('agent_id',''); +$agentName = get_parameter('agent_name',''); +$actionID = get_parameter('action_id',''); +$fieldContent = get_parameter('field_content',''); +$searchType = get_parameter('search_type',''); +$priority = get_parameter('priority',''); if ($create_alert) { $id_alert_template = (int) get_parameter ('template'); @@ -127,8 +132,6 @@ if ($create_alert) { } else { $id = create_alert_agent_module ($id_agent_module, $id_alert_template); -//get_db_value ('name', 'tperfil', 'id_perfil', (int) $id_profile); - $alert_template_name = get_db_value ("name", "talert_templates","id", $id_alert_template); $module_name = get_db_value ("nombre", "tagente_modulo","id_agente_modulo", $id_agent_module); @@ -218,16 +221,56 @@ if ($disable_alert) { __('Could not be disabled')); } -echo ''.__('Alert control filter').' '.print_image ("images/down.png", true, array ("title" => __('Toggle filter(s)'))).'

'; +// Header +if ($id_agente) { + $agents = array ($id_agente => get_agent_name ($id_agente)); +} +else { + $buttons = array( + 'list' => array( + 'active' => false, + 'text' => '' . + print_image ("images/god6.png", true, array ("title" => __('List alerts'))) .''), + 'builder' => array( + 'active' => false, + 'text' => '' . + print_image ("images/config.png", true, array ("title" => __('Builder alert'))) .'')); + + $buttons[$tab]['active'] = true; + + print_page_header(__('Alerts') . ' » ' . __('Manage alerts') . ' » ' . __('List'), "images/god2.png", false, "manage_alert_list", true, $buttons); + + switch ($tab) { + case 'list': + if ($group == 1) { + $groups = get_user_groups (); + } + else { + $groups = array(1 => __('All')); + } + $agents = get_group_agents (array_keys ($groups), false, "none"); + + require_once('godmode/alerts/alert_list.list.php'); + return; + break; + case 'builder': + if ($group == 1) { + $groups = get_user_groups (); + } + else { + $groups = array(1 => __('All')); + } + + require_once('godmode/alerts/alert_list.builder.php'); + return; + break; + } +// print_page_header (__('Alerts').' » '.__('Manage alerts'), "images/god2.png", false, "", true); +// $groups = get_user_groups (); +// $agents = get_group_agents (array_keys ($groups), false, "none"); +} -$templateName = get_parameter('template_name',''); -$moduleName = get_parameter('module_name',''); -$agentID = get_parameter('agent_id',''); -$agentName = get_parameter('agent_name',''); -$actionID = get_parameter('action_id',''); -$fieldContent = get_parameter('field_content',''); -$searchType = get_parameter('search_type',''); -$priority = get_parameter('priority',''); +echo ''.__('Alert control filter').' '.print_image ("images/down.png", true, array ("title" => __('Toggle filter(s)'))).'

'; //INI DIV OF FORM FILTER echo "