implemented sort filter to event view custom fields

This commit is contained in:
alejandro-campos 2018-08-03 10:38:53 +02:00
parent 01656f2e76
commit 097661d82b
2 changed files with 116 additions and 22 deletions

View File

@ -161,7 +161,8 @@ function events_get_events_grouped($sql_post, $offset = 0,
(SELECT id_usuario FROM $table WHERE id_evento = MAX(te.id_evento)) id_usuario,
(SELECT id_agente FROM $table WHERE id_evento = MAX(te.id_evento)) id_agente,
(SELECT criticity FROM $table WHERE id_evento = MAX(te.id_evento)) AS criticity,
(SELECT ack_utimestamp FROM $table WHERE id_evento = MAX(te.id_evento)) AS ack_utimestamp
(SELECT ack_utimestamp FROM $table WHERE id_evento = MAX(te.id_evento)) AS ack_utimestamp,
(SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = te.id_agentmodule) AS module_name
FROM $table te LEFT JOIN tagent_secondary_group tasg ON te.id_grupo = tasg.id_group
WHERE 1=1 " . $sql_post . "
GROUP BY estado, evento, id_agente, id_agentmodule" . $groupby_extra . "
@ -181,6 +182,12 @@ function events_get_events_grouped($sql_post, $offset = 0,
if ($order=='down')
$sql .= "evento" . " DESC";
break;
case 'event_id':
if ($order=='up')
$sql .= "id_evento" . " ASC";
if ($order=='down')
$sql .= "id_evento" . " DESC";
break;
case 'status':
if ($order=='up')
$sql .= "estado" . " ASC";
@ -199,6 +206,90 @@ function events_get_events_grouped($sql_post, $offset = 0,
if ($order=='down')
$sql .= "timestamp_rep" . " DESC";
break;
case 'user_id':
if ($order=='up')
$sql .= "id_usuario" . " ASC";
if ($order=='down')
$sql .= "id_usuario" . " DESC";
break;
case 'owner':
if ($order=='up')
$sql .= "owner_user" . " ASC";
if ($order=='down')
$sql .= "owner_user" . " DESC";
break;
case 'group_id':
if ($order=='up')
$sql .= "id_grupo" . " ASC";
if ($order=='down')
$sql .= "id_grupo" . " DESC";
break;
case 'module_name':
if ($order=='up')
$sql .= "module_name" . " ASC";
if ($order=='down')
$sql .= "module_name" . " DESC";
break;
case 'event_type':
if ($order=='up')
$sql .= "event_type" . " ASC";
if ($order=='down')
$sql .= "event_type" . " DESC";
break;
case 'alert_id':
if ($order=='up')
$sql .= "id_alert_am" . " ASC";
if ($order=='down')
$sql .= "id_alert_am" . " DESC";
break;
case 'criticity':
if ($order=='up')
$sql .= "criticity" . " ASC";
if ($order=='down')
$sql .= "criticity" . " DESC";
break;
case 'comment':
if ($order=='up')
$sql .= "user_comment" . " ASC";
if ($order=='down')
$sql .= "user_comment" . " DESC";
break;
case 'tags':
if ($order=='up')
$sql .= "tags" . " ASC";
if ($order=='down')
$sql .= "tags" . " DESC";
break;
case 'source':
if ($order=='up')
$sql .= "source" . " ASC";
if ($order=='down')
$sql .= "source" . " DESC";
break;
case 'extra_id':
if ($order=='up')
$sql .= "id_extra" . " ASC";
if ($order=='down')
$sql .= "id_extra" . " DESC";
break;
case 'ack_timestamp':
if ($order=='up')
$sql .= "ack_utimestamp" . " ASC";
if ($order=='down')
$sql .= "ack_utimestamp" . " DESC";
break;
case 'data':
if ($order=='up')
$sql .= "data" . " ASC";
if ($order=='down')
$sql .= "data" . " DESC";
break;
case 'module_status':
if ($order=='up')
$sql .= "module_status" . " ASC";
if ($order=='down')
$sql .= "module_status" . " DESC";
break;
default:
$sql .= "timestamp_rep" . " DESC";
}

View File

@ -17,6 +17,9 @@ global $config;
require_once ($config["homedir"] . "/include/functions_ui.php");
$sort_field = get_parameter("sort_field", "timestamp");
$sort = get_parameter("sort", "down");
$table = new stdClass();
if(!isset($table->width)) {
@ -130,7 +133,7 @@ else {
//headers
$i = 0;
$table->head[$i] = __('ID') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_id&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&sort_field=event_id&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->head[$i] = __('ID') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_id&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_id&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
@ -141,104 +144,104 @@ else {
$i++;
}
if (in_array('estado', $show_fields)) {
$table->head[$i] = __('Status') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=status&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&sort_field=status&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->head[$i] = __('Status') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=status&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=status&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('id_evento', $show_fields)) {
$table->head[$i] = __('Event ID');
$table->head[$i] = __('Event ID') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_id&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_id&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('evento', $show_fields)) {
$table->head[$i] = __('Event Name') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_name&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&sort_field=event_name&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->head[$i] = __('Event Name') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_name&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_name&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$table->style[$i] = 'min-width: 200px; max-width: 350px; word-break: break-all;';
$i++;
}
if (in_array('id_agente', $show_fields)) {
$table->head[$i] = __('Agent name') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=agent_id&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&sort_field=agent_id&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->head[$i] = __('Agent name') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=agent_id&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=agent_id&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$table->style[$i] = 'max-width: 350px; word-break: break-all;';
$i++;
}
if (in_array('timestamp', $show_fields)) {
$table->head[$i] = __('Timestamp') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=timestamp&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&sort_field=timestamp&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->head[$i] = __('Timestamp') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=timestamp&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=timestamp&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('id_usuario', $show_fields)) {
$table->head[$i] = __('User');
$table->head[$i] = __('User') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=user_id&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=user_id&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('owner_user', $show_fields)) {
$table->head[$i] = __('Owner');
$table->head[$i] = __('Owner') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=owner&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=owner&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('id_grupo', $show_fields)) {
$table->head[$i] = __('Group');
$table->head[$i] = __('Group') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=group_id&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=group_id&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('event_type', $show_fields)) {
$table->head[$i] = __('Event Type');
$table->head[$i] = __('Event Type') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_type&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=event_type&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$table->style[$i] = 'min-width: 85px;';
$i++;
}
if (in_array('id_agentmodule', $show_fields)) {
$table->head[$i] = __('Module Name');
$table->head[$i] = __('Module Name') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=module_name&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=module_name&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('id_alert_am', $show_fields)) {
$table->head[$i] = __('Alert');
$table->head[$i] = __('Alert') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=alert_id&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=alert_id&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('criticity', $show_fields)) {
$table->head[$i] = __('Severity');
$table->head[$i] = __('Severity') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=criticity&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=criticity&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('user_comment', $show_fields)) {
$table->head[$i] = __('Comment');
$table->head[$i] = __('Comment') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=comment&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=comment&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('tags', $show_fields)) {
$table->head[$i] = __('Tags');
$table->head[$i] = __('Tags') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=tags&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=tags&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('source', $show_fields)) {
$table->head[$i] = __('Source');
$table->head[$i] = __('Source') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=source&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=source&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('id_extra', $show_fields)) {
$table->head[$i] = __('Extra ID');
$table->head[$i] = __('Extra ID') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=extra_id&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=extra_id&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('ack_utimestamp', $show_fields)) {
$table->head[$i] = __('ACK Timestamp');
$table->head[$i] = __('ACK Timestamp') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=ack_timestamp&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=ack_utimestamp&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
@ -250,13 +253,13 @@ else {
$i++;
}
if (in_array('data', $show_fields)) {
$table->head[$i] = __('Data');
$table->head[$i] = __('Data') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=data&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=data&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';
$table->align[$i] = 'left';
$i++;
}
if (in_array('module_status', $show_fields)) {
$table->head[$i] = __('Module Status');
$table->head[$i] = __('Module Status') . ' ' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=module_status&sort=up&disabled='.$disabled.'">' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '</a>' . '<a href="index.php?sec=eventos&sec2=operation/events/events&offset='.$offset.'&sort_field=module_status&sort=down&disabled=$disabled">' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '</a>';;
$table->align[$i] = 'left';
$i++;
@ -769,7 +772,7 @@ else {
if (!empty ($table->data)) {
if ($allow_pagination) {
ui_pagination ($total_events, $url, $offset, $pagination);
ui_pagination ($total_events, "index.php?sec=eventos&sec2=operation/events/events&sort_field=$sort_field&sort=$sort&disabled=$disabled", $offset, $pagination);
}
if ($allow_action) {