From e9061d74b64bdcb3c8dc557b3010f1ec5f0afc17 Mon Sep 17 00:00:00 2001 From: Fermin Date: Fri, 8 Mar 2019 11:46:47 +0100 Subject: [PATCH] Added ordering header element Former-commit-id: 11ffbe8c00a8ea9d881321be7c7541eaf0babe92 --- pandora_console/include/functions_html.php | 17 +++++-- pandora_console/include/functions_network.php | 30 ++++++++++++ .../operation/network/network_report.php | 49 ++++++++++++++----- 3 files changed, 80 insertions(+), 16 deletions(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 4b7eebcf87..e38e7160ec 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3132,20 +3132,31 @@ function html_print_switch($attributes=[]) * @param string $text Text to show. * @param array $params Params to be written like inputs hidden. * @param string $text Text of image. + * @param string $style Additional style for the element. * * @return string With HTML code. */ -function html_print_link_with_params($text, $params=[], $type='text') +function html_print_link_with_params($text, $params=[], $type='text', $style='') { $html = '
'; switch ($type) { case 'image': - $html .= html_print_input_image($text, $text, $text, '', true); + $html .= html_print_input_image($text, $text, $text, $style, true); break; case 'text': default: - $html .= html_print_submit_button($text, $text, false, 'class="button-as-link"', true); + if (!empty($style)) { + $style = ' style="'.$style.'"'; + } + + $html .= html_print_submit_button( + $text, + $text, + false, + 'class="button-as-link"'.$style, + true + ); break; } diff --git a/pandora_console/include/functions_network.php b/pandora_console/include/functions_network.php index 2c096f173c..60375b6174 100644 --- a/pandora_console/include/functions_network.php +++ b/pandora_console/include/functions_network.php @@ -89,3 +89,33 @@ function network_get_report_actions($network) ] ); } + + +/** + * Print the header of the network + * + * @param string $title Title of header. + * @param string $order Current ordering. + * @param string $selected Selected order. + * @param array $hidden_data All the data to hide into the button. + * + * @return string With HTML data. + */ +function network_print_explorer_header( + $title, + $order, + $selected, + $hidden_data +) { + $cell = '
'; + $cell .= $title; + $cell .= html_print_link_with_params( + 'images/arrow-down-white.png', + array_merge($hidden_data, ['order_by' => $order]), + 'image', + ($selected === $order) ? 'opacity: 0.5' : '' + ); + $cell .= '
'; + + return $cell; +} diff --git a/pandora_console/operation/network/network_report.php b/pandora_console/operation/network/network_report.php index 1fcfa37a42..e4dd539c8e 100644 --- a/pandora_console/operation/network/network_report.php +++ b/pandora_console/operation/network/network_report.php @@ -48,6 +48,11 @@ if (!$is_period) { $top = (int) get_parameter('top', 10); $main_value = ((bool) get_parameter('remove_filter', 0)) ? '' : get_parameter('main_value', ''); +$order_by = get_parameter('order_by', 'bytes'); +if (!in_array($order_by, ['bytes', 'pkts', 'flows'])) { + $order_by = 'bytes'; +} + $style_end = ($is_period) ? 'display: none;' : ''; $style_period = ($is_period) ? '' : 'display: none;'; @@ -157,19 +162,6 @@ if ($is_network) { ); } -unset($table); -$table = new stdClass(); -$table->styleTable = 'width: 100%'; -// Print the header. -$table->head = []; -$table->head['main'] = __('IP'); -if (!$is_network) { - $table->head['flows'] = __('Flows'); -} - -$table->head['pkts'] = __('Packets'); -$table->head['bytes'] = __('Bytes'); - // Get the params to return the builder. $hidden_main_link = [ 'time_greater' => $time_greater, @@ -182,6 +174,37 @@ $hidden_main_link = [ 'action' => $action, ]; +unset($table); +$table = new stdClass(); +$table->styleTable = 'width: 100%'; +// Print the header. +$table->head = []; +$table->head['main'] = __('IP'); +if (!$is_network) { + $table->head['flows'] = network_print_explorer_header( + __('Flows'), + 'flows', + $order_by, + $hidden_main_link + ); +} + +$table->head['pkts'] = network_print_explorer_header( + __('Packets'), + 'pkts', + $order_by, + $hidden_main_link +); +$table->head['bytes'] = network_print_explorer_header( + __('Bytes'), + 'bytes', + $order_by, + $hidden_main_link +); + +// Add the order. +$hidden_main_link['order_by'] = $order_by; + if (get_parameter('export_csv')) { // Clean the buffer. while (ob_get_level()) {