From ee411330056d9a96c2028435eaca0ace5f30a3cc Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 10 Oct 2014 14:42:50 +0200 Subject: [PATCH] Rewrote some parts of code of function ui_pagination. Ticket #1407 --- pandora_console/include/constants.php | 3 + pandora_console/include/functions_ui.php | 164 ++++++++++------------- 2 files changed, 76 insertions(+), 91 deletions(-) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 5722ad0a75..d00a5e4c64 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -380,4 +380,7 @@ define("CUSTOM_GRAPH_STACKED_LINE", 3); define("COLLECTION_PENDING_APPLY", 0); define("COLLECTION_CORRECT", 1); define("COLLECTION_ERROR_LOST_DIRECTORY", 2); + +/* PAGINATION */ +define("PAGINATION_BLOCKS_LIMIT", 15); ?> diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index bea2ef2502..d710f6ba39 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -1527,7 +1527,10 @@ function ui_process_page_body ($string, $bitfield) { * * @return string The pagination div or nothing if no pagination needs to be done */ -function ui_pagination ($count, $url = false, $offset = 0, $pagination = 0, $return = false, $offset_name = 'offset', $print_total_items = true, $other_class = '') { +function ui_pagination ($count, $url = false, $offset = 0, + $pagination = 0, $return = false, $offset_name = 'offset', + $print_total_items = true, $other_class = '') { + global $config; if (empty ($pagination)) { @@ -1547,13 +1550,14 @@ function ui_pagination ($count, $url = false, $offset = 0, $pagination = 0, $ret $url = ui_get_url_refresh (array ($offset_name => false)); } - /* URL passed render links with some parameter + /* + URL passed render links with some parameter &offset - Offset records passed to next page &counter - Number of items to be blocked Pagination needs $url to build the base URL to render links, its a base url, like " http://pandora/index.php?sec=godmode&sec2=godmode/admin_access_logs " */ - $block_limit = 15; // Visualize only $block_limit blocks + $block_limit = PAGINATION_BLOCKS_LIMIT; // Visualize only $block_limit blocks if ($count <= $pagination) { if ($print_total_items) { @@ -1572,32 +1576,22 @@ function ui_pagination ($count, $url = false, $offset = 0, $pagination = 0, $ret return false; } - // If exists more registers than I can put in a page, calculate index markers - $index_counter = ceil ($count /$pagination); // Number of blocks of block_size with data - $index_page = ceil ($offset / $pagination) - (ceil ($block_limit / 2)); // block to begin to show data; - if ($index_page < 0) - $index_page = 0; + $number_of_pages = ceil($count / $pagination); + //~ html_debug_print('number_of_pages'); + //~ html_debug_print($number_of_pages); + $actual_page = floor($offset / $pagination); + //~ html_debug_print('actual_page'); + //~ html_debug_print($actual_page); + $ini_page = floor($actual_page / $block_limit) * $block_limit; + //~ html_debug_print('ini_page'); + //~ html_debug_print($ini_page); + $end_page = $ini_page + $block_limit - 1; + if ($end_page > $number_of_pages) { + $end_page = $number_of_pages - 1; + } + //~ html_debug_print('end_page'); + //~ html_debug_print($end_page); - // This calculate index_limit, block limit for this search. - if (($index_page + $block_limit) > $index_counter) - $index_limit = $index_counter; - else - $index_limit = $index_page + $block_limit; - - // This calculate if there are more blocks than visible (more than $block_limit blocks) - if ($index_counter > $block_limit ) - $paginacion_maxima = 1; // If maximum blocks ($block_limit), show only 10 and "...." - else - $paginacion_maxima = 0; - - // This setup first block of query - if ( $paginacion_maxima == 1) - if ($index_page == 0) - $inicio_pag = 0; - else - $inicio_pag = $index_page; - else - $inicio_pag = 0; $output = "