diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 6373a672e6..0da6e6ae51 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,10 @@ +2014-01-16 Ramon Novoa + + * godmode/alerts/alert_list.list.php, + include/functions.php, + include/functions_alerts.php: Changes to the alert view to make it more + compact. + 2014-01-14 Sergio Martin * include/functions_config.php: Fixed a warning message on diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index bf8361f8e6..50fc4fcb80 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -319,24 +319,22 @@ $table->width = '98%'; $table->size = array (); $table->align[2] = 'left'; -$table->align[3] = 'left'; +$table->align[3] = 'center'; $table->align[4] = 'center'; -$table->align[5] = 'center'; $table->head = array (); if (! $id_agente) { $table->style = array (); $table->style[0] = 'font-weight: bold'; - $table->head[0] = __('Agent') . '
' . + $table->head[0] = __('Agent') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectAgentUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectAgentDown)) . ''; - $table->size[0] = '20%'; - $table->size[1] = '15%'; - $table->size[2] = '15%'; - $table->size[3] = '15%'; - $table->size[4] = '2%'; - $table->size[5] = '9%'; + $table->size[0] = '10%'; + $table->size[1] = '25%'; + $table->size[2] = '25%'; + $table->size[3] = '1%'; + $table->size[4] = '10%'; /* if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { $table->size[4] = '8%'; @@ -345,38 +343,30 @@ if (! $id_agente) { else { /* Different sizes or the layout screws up */ $table->size[0] = '0%'; - $table->size[1] = '25%'; - $table->size[3] = '25%'; + $table->size[1] = '30%'; + $table->size[2] = '30%'; /* if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { $table->size[4] = '25%'; } */ - $table->size[4] = '3%'; - $table->size[5] = '13%'; + $table->size[3] = '1%'; + $table->size[4] = '10%'; } -$table->head[1] = __('Module') . '
' . +$table->head[1] = __('Module') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectModuleUp)) . '' . - '' . html_print_image("images/sort_down.png", true, array("style" => $selectModuleDown)) . ''; -$table->head[2] = __('Template') . '
' . + '' . html_print_image("images/sort_down.png", true, array("style" => $selectModuleDown)) . '' . +'
' . __('Template') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectTemplateUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectTemplateDown)) . ''; -/*if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { - $table->head[5] = "" . __('P.') . ""; -}*/ -$table->head[3] = __('Actions'); -$table->head[4] = __('Status'); -$table->head[5] = "" . __('Op.') . ""; +$table->head[2] = __('Actions'); +$table->head[3] = __('Status'); +$table->head[4] = "" . __('Op.') . ""; $table->valign[0] = 'middle'; $table->valign[1] = 'middle'; $table->valign[2] = 'middle'; $table->valign[3] = 'middle'; $table->valign[4] = 'middle'; -$table->valign[5] = 'middle'; - -/*if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { - $table->align[5] = 'center'; -}*/ $table->data = array (); @@ -416,7 +406,8 @@ foreach ($simple_alerts as $alert) { if ($alert['disabled']) $data[0] .= ''; - $data[0] .= '' . agents_get_name ($id_agent) . ''; + $agent_name = agents_get_name ($id_agent); + $data[0] .= ui_print_truncate_text($agent_name, 'agent_small', false, true, true, '[…]', 'display:block;font-size: 7.2pt'); if ($alert['disabled']) $data[0] .= ''; @@ -426,91 +417,93 @@ foreach ($simple_alerts as $alert) { $agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agente); } - $data[1] = ui_print_truncate_text( - modules_get_agentmodule_name ($alert['id_agent_module']), 'module_small', false, true, true, '[…]', 'font-size: 7.2pt'); - - $data[2] = ' ' . - html_print_image("images/zoom.png", true, array("id" => 'template-details-'.$alert['id_alert_template'], "class" => "img_help")) . ' '; + $module_name = modules_get_agentmodule_name ($alert['id_agent_module']); + $data[1] = ui_print_truncate_text($module_name, 'module_medium', false, true, true, '[…]', 'display:block;font-size: 7.2pt') . '
'; $template_group = db_get_value('id_group', 'talert_templates', 'id', $alert['id_alert_template']); // The access to the template manage page is necessary have LW permissions on template group if(check_acl ($config['id_user'], $template_group, "LW")) { - $data[2] .= ""; + $data[1] .= ""; } - $data[2] .= ui_print_truncate_text( - alerts_get_alert_template_name ($alert['id_alert_template']), GENERIC_SIZE_TEXT, false, true, true, '[…]', 'font-size: 7.1pt'); + $data[1] .= ui_print_truncate_text( + alerts_get_alert_template_name ($alert['id_alert_template']), 'module_medium', false, true, true, '[…]', 'font-size: 7.1pt'); + $data[1] .= ' '; + $data[1] .= html_print_image("images/zoom.png", true, array("id" => 'template-details-'.$alert['id_alert_template'], "class" => "img_help")); + $data[1] .= ' '; if(check_acl ($config['id_user'], $template_group, "LW")) { - $data[2] .= ""; + $data[1] .= ""; } $actions = alerts_get_alert_agent_module_actions ($alert['id']); - $data[3] = ""; - if (empty($actions)) { - // Get and show default actions for this alert - $default_action = db_get_sql ("SELECT id_alert_action - FROM talert_templates - WHERE id = ".$alert["id_alert_template"]); - if ($default_action != "") { - $data[3] .= ""; - $data[3] .= ""; - $data[3] .= ""; - } + $data[2] = "
"; - $data[3] .= __("Default"). " : ".db_get_sql ("SELECT name FROM talert_actions WHERE id = $default_action") . ' (' . __('Always') . ')'; - $data[3] .= "
"; + // Get and show default actions for this alert + $default_action = db_get_sql ("SELECT id_alert_action + FROM talert_templates + WHERE id = ".$alert["id_alert_template"]); + if ($default_action != "") { + $data[2] .= ""; + $data[2] .= ""; + $data[2] .= ""; } + foreach ($actions as $action_id => $action) { - $data[3] .= ""; - $data[3] .= ""; + $data[2] .= ""; + $data[2] .= ')'; + $data[2] .= ''; + $data[2] .= ''; + $data[2] .= ''; + $data[2] .= ""; // Is possible manage actions if have LW permissions in the agent group of the alert module if (check_acl ($config['id_user'], $agent_group, "LW")) { - $data[3] .= ""; + $data[2] .= html_print_input_hidden ('delete_action', 1, true); + $data[2] .= html_print_input_hidden ('id_alert', $alert['id'], true); + $data[2] .= html_print_input_hidden ('id_action', $action_id, true); + $data[2] .= ''; + $data[2] .= ""; } - $data[3] .= ""; + $data[2] .= ""; } - + $data[2] .= '
  • "; + $data[2] .= db_get_sql ("SELECT name FROM talert_actions WHERE id = $default_action") . ' (' . __('Default') . ')'; + $data[2] .= "
"; - $data[3] .= '
    '; - $data[3] .= '
  • '; + $data[2] .= "
"; + $data[2] .= '
    '; + $data[2] .= '
  • '; if ($alert['disabled']) - $data[3] .= ''; + $data[2] .= ''; else - $data[3] .= ''; - $data[3] .= ui_print_truncate_text($action['name'], GENERIC_SIZE_TEXT, false); - $data[3] .= ' ('; + $data[2] .= ''; + $data[2] .= ui_print_truncate_text($action['name'], GENERIC_SIZE_TEXT, false); + $data[2] .= ' ('; if ($action['fires_min'] == $action['fires_max']) { if ($action['fires_min'] == 0) - $data[3] .= __('Always'); + $data[2] .= __('Always'); else - $data[3] .= __('On').' '.$action['fires_min']; + $data[2] .= __('On').' '.$action['fires_min']; } - else { + else if ($action['fires_min'] < $action['fires_max']){ if ($action['fires_min'] == 0) - $data[3] .= __('Until').' '.$action['fires_max']; + $data[2] .= __('Until').' '.$action['fires_max']; else - $data[3] .= __('From').' '.$action['fires_min']. + $data[2] .= __('From').' '.$action['fires_min']. ' '.__('to').' '.$action['fires_max']; } + else { + $data[2] .= __('From').' '.$action['fires_min']; + } if ($action['module_action_threshold'] != 0) - $data[3] .= ' '.__('Threshold').' '.$action['module_action_threshold']; + $data[2] .= ' '.__('Threshold').' '.human_time_description_alerts ($action['module_action_threshold'], true, 'tiny'); - $data[3] .= ')'; - $data[3] .= ''; - $data[3] .= '
  • '; - $data[3] .= '
'; - $data[3] .= "
"; - $data[3] .= '"; + $data[2] .= ''; + $data[2] .= html_print_input_image ('delete', + 'images/cross.png', 1, 'padding:0px;', true, array('title' => __('Delete'))); - $data[3] .= html_print_input_hidden ('delete_action', 1, true); - $data[3] .= html_print_input_hidden ('id_alert', $alert['id'], true); - $data[3] .= html_print_input_hidden ('id_action', $action_id, true); - $data[3] .= ''; - $data[3] .= "
'; // Is possible manage actions if have LW permissions in the agent group of the alert module if (check_acl ($config['id_user'], $agent_group, "LW")) { @@ -520,56 +513,62 @@ foreach ($simple_alerts as $alert) { $filter_groups = implode(',', array_keys($own_groups)); $actions = alerts_get_alert_actions_filter(true, 'id_group IN (' . $filter_groups . ')'); + $data[2] .= ''; } - - - $data[3] .= ''; - + $status = STATUS_ALERT_NOT_FIRED; $title = ""; @@ -586,33 +585,33 @@ foreach ($simple_alerts as $alert) { $title = __('Alert not fired'); } - $data[4] = ui_print_status_image($status, $title, true); + $data[3] = ui_print_status_image($status, $title, true); - $data[5] = '
'; + $data[4] = ''; if ($alert['disabled']) { - $data[5] .= html_print_input_image ('enable', 'images/lightbulb_off.png', 1, '', true); - $data[5] .= html_print_input_hidden ('enable_alert', 1, true); + $data[4] .= html_print_input_image ('enable', 'images/lightbulb_off.png', 1, 'padding:0px', true); + $data[4] .= html_print_input_hidden ('enable_alert', 1, true); } else { - $data[5] .= html_print_input_image ('disable', 'images/lightbulb.png', 1, '', true); - $data[5] .= html_print_input_hidden ('disable_alert', 1, true); + $data[4] .= html_print_input_image ('disable', 'images/lightbulb.png', 1, 'padding:0px;', true); + $data[4] .= html_print_input_hidden ('disable_alert', 1, true); } - $data[5] .= html_print_input_hidden ('id_alert', $alert['id'], true); - $data[5] .= '
'; + $data[4] .= html_print_input_hidden ('id_alert', $alert['id'], true); + $data[4] .= ''; // To manage alert is necessary LW permissions in the agent group if(check_acl ($config['id_user'], $agent_group, "LW")) { - $data[5] .= '  
'; + $data[4] .= '  '; if (!$alert['standby']) { - $data[5] .= html_print_input_image ('standby_off', 'images/bell.png', 1, '', true); - $data[5] .= html_print_input_hidden ('standbyon_alert', 1, true); + $data[4] .= html_print_input_image ('standby_off', 'images/bell.png', 1, 'padding:0px;', true); + $data[4] .= html_print_input_hidden ('standbyon_alert', 1, true); } else { - $data[5] .= html_print_input_image ('standby_on', 'images/bell_pause.png', 1, '', true); - $data[5] .= html_print_input_hidden ('standbyoff_alert', 1, true); + $data[4] .= html_print_input_image ('standby_on', 'images/bell_pause.png', 1, 'padding:0px;', true); + $data[4] .= html_print_input_hidden ('standbyoff_alert', 1, true); } - $data[5] .= html_print_input_hidden ('id_alert', $alert['id'], true); - $data[5] .= '
'; + $data[4] .= html_print_input_hidden ('id_alert', $alert['id'], true); + $data[4] .= ''; } // To access to policy page is necessary have AW permissions in the agent @@ -620,11 +619,11 @@ foreach ($simple_alerts as $alert) { if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) { $policyInfo = policies_is_alert_in_policy2($alert['id'], false); if ($policyInfo === false) - $data[5] .= ''; + $data[4] .= ''; else { $img = 'images/policies.png'; - $data[5] .= '  ' . + $data[4] .= '  ' . html_print_image($img, true, array('title' => $policyInfo['name'])) . ''; } @@ -633,11 +632,20 @@ foreach ($simple_alerts as $alert) { // To manage alert is necessary LW permissions in the agent group if(check_acl ($config['id_user'], $agent_group, "LW")) { - $data[5] .= '  
'; - $data[5] .= html_print_input_image ('delete', 'images/cross.png', 1, '', true, array('title' => __('Delete'))); - $data[5] .= html_print_input_hidden ('delete_alert', 1, true); - $data[5] .= html_print_input_hidden ('id_alert', $alert['id'], true); - $data[5] .= '
'; + $data[4] .= '  
'; + if ($alert['disabled']) { + $data[4] .= html_print_image('images/add.disabled.png', + true, array('title' => __("Add action"))); + } + else { + $data[4] .= ''; + $data[4] .= html_print_image('images/add.png', true, array('title' => __("Add action"))); + $data[4] .= ''; + } + $data[4] .= html_print_input_image ('delete', 'images/cross.png', 1, '', true, array('title' => __('Delete'))); + $data[4] .= html_print_input_hidden ('delete_alert', 1, true); + $data[4] .= html_print_input_hidden ('id_alert', $alert['id'], true); + $data[4] .= '
'; } array_push ($table->data, $data); } @@ -753,8 +761,22 @@ function show_advance_options_action(id_alert) { $(".advance_options_" + id_alert).show(); } -function add_action_submit(id_alert) { - $("#add_action_form-" + id_alert).submit(); +function show_add_action(id_alert) { + $("#add_action-div-" + id_alert).hide () + .dialog ({ + resizable: true, + draggable: true, + title: '', + modal: true, + overlay: { + opacity: 0.5, + background: "black" + }, + width: 500, + height: 300 + }) + .show (); } + /* ]]> */ diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 173347e685..b12cf59207 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -536,6 +536,150 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large return "+6 " . $monthsString; } +/** + * INTERNAL (use ui_print_timestamp for output): Transform an amount of time in seconds into a human readable + * strings of minutes, hours or days. Used in alert views. + * + * @param int $seconds Seconds elapsed time + * @param int $exactly If it's true, return the exactly human time + * @param string $units The type of unit, by default 'large'. + * + * @return string A human readable translation of minutes. + */ +function human_time_description_alerts ($seconds, $exactly = false, $units = 'tiny') { + switch ($units) { + case 'large': + $secondsString = __('seconds'); + $daysString = __('days'); + $monthsString = __('months'); + $yearsString = __('years'); + $minutesString = __('minutes'); + $hoursString = __('hours'); + $nowString = __('Now'); + break; + case 'tiny': + $secondsString = __('s'); + $daysString = __('d'); + $monthsString = __('M'); + $yearsString = __('Y'); + $minutesString = __('m'); + $hoursString = __('h'); + $nowString = __('N'); + break; + } + + if (empty ($seconds)) { + return $nowString; + // slerena 25/03/09 + // Most times $seconds is empty is because last contact is current date + // Put here "uknown" or N/A or something similar is not a good idea + } + + if ($exactly) { + $returnDate = ''; + + $years = floor($seconds / 31104000); + + if ($years != 0) { + $seconds = $seconds - ($years * 31104000); + + $returnDate .= "$years $yearsString "; + } + + $months = floor($seconds / 2592000); + + if ($months != 0) { + $seconds = $seconds - ($months * 2592000); + + $returnDate .= "$months $monthsString "; + } + + $days = floor($seconds / 86400); + + if ($days != 0) { + $seconds = $seconds - ($days * 86400); + + $returnDate .= "$days $daysString "; + } + + $returnTime = ''; + + $hours = floor($seconds / 3600); + + if ($hours != 0) { + $seconds = $seconds - ($hours * 3600); + + $returnTime .= "$hours $hoursString "; + } + + $mins = floor($seconds / 60); + + if ($mins != 0) { + $seconds = $seconds - ($mins * 60); + + if ($hours == 0) { + $returnTime .= "$mins $minutesString "; + } + else { + $returnTime = sprintf("%02d",$hours) . "$hoursString" . + sprintf("%02d",$mins) . "$minutesString"; + } + } + + if ($seconds != 0) { + if ($hours == 0) { + $returnTime .= "$seconds $secondsString "; + } + else { + $returnTime = sprintf("%02d",$hours) . "$hoursString" . + sprintf("%02d",$mins) . "$minutesString" . + sprintf("%02d",$seconds) . "$secondsString"; + } + } + + $return = ' '; + + if ($returnDate != '') { + $return = $returnDate; + } + + if ($returnTime != '') { + $return .= $returnTime; + } + + if ($return == ' ') { + return $nowString; + } + else { + return $return; + } + + } + + if ($seconds < 60) + return format_numeric ($seconds, 0)." " . $secondsString; + + if ($seconds < 3600) { + $minutes = floor($seconds / 60); + $seconds = $seconds % 60; + if ($seconds == 0) + return $minutes.' ' . $minutesString; + $seconds = sprintf ("%02d", $seconds); + return $minutes.' '. $minutesString . ' ' .$seconds.' ' . $secondsString; + } + + if ($seconds < 86400) + return format_numeric ($seconds / 3600, 0)." " . $hoursString; + + if ($seconds < 2592000) + return format_numeric ($seconds / 86400, 0) . " " . $daysString; + + if ($seconds < 15552000) + return format_numeric ($seconds / 2592000, 0)." ". $monthsString; + + return "+6 " . $monthsString; +} + /** * @deprecated Get current time minus some seconds. (Do your calculations yourself on unix timestamps) * diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index be33697686..ff775bd922 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1156,15 +1156,11 @@ function alerts_add_alert_agent_module_action ($id_alert_template_module, $id_al $max = 0; $min = 0; if (isset ($options['fires_max'])) - $max = (int) $options['fires_max']; + $values['fires_max'] = $options['fires_max']; if (isset ($options['fires_min'])) - $min = (int) $options['fires_min']; + $values['fires_min'] = $options['fires_min']; if (isset ($options['module_action_threshold'])) - $values['module_action_threshold'] = - (int) $options['module_action_threshold']; - - $values['fires_max'] = max ($max, $min); - $values['fires_min'] = min ($max, $min); + $values['module_action_threshold'] = (int) $options['module_action_threshold']; } switch ($config["dbtype"]) { @@ -1821,4 +1817,4 @@ function alerts_get_alert_special_day ($id_special_day) { return db_get_row ('talert_special_days', 'id', $id_special_day); } -?> \ No newline at end of file +?>