$total_pages) $page_number = $total_pages; $spacing = ($compact ? $nbsp : $nbsp . $nbsp); // only enough addresses for one page anyway? no pagination needed // if ($total_pages < 2) return ''; // build "Show All" link // $show_all_string = '[' . make_abook_paginator_link(1, _("All"), array_merge($current_page_args, array('show_all' => 1))) . ']'; // build next/previous links for compact paginator // if ($compact) { if ($page_number > 1) $paginator_string .= make_abook_paginator_link(1, _("<<"), $current_page_args) . '][' . make_abook_paginator_link($page_number - 1, _("<"), $current_page_args) . ']['; else // i18n: "<<" is for the first page in the paginator. "<" is for the previous page. $paginator_string .= _("<<") . '][' . _("<") . ']['; if ($page_number < $total_pages) $paginator_string .= make_abook_paginator_link($page_number + 1, _(">"), $current_page_args) . '][' . make_abook_paginator_link($total_pages, _(">>"), $current_page_args) . ']'; else // i18n: ">>" is for the last page in the paginator. ">" is for the next page. $paginator_string .= _(">") . '][' . _(">>") . ']'; } // build next/previous links for regular paginator // else { if ($page_number > 1) $paginator_string .= make_abook_paginator_link($page_number - 1, _("Previous"), $current_page_args); else $paginator_string .= _("Previous"); $paginator_string .= $nbsp . $sep . $nbsp; if ($page_number < $total_pages) $paginator_string .= make_abook_paginator_link($page_number + 1, _("Next"), $current_page_args); else $paginator_string .= _("Next"); $paginator_string .= ']'; } // paginator is turned off - just show previous/next links // if (!$abook_page_selector) { return $paginator_string . $spacing . $show_all_string; } $paginator_string .= $spacing; if ($total_pages <= $abook_page_selector_max) { $start_page = 1; $end_page = $total_pages; } else { $pages_to_show = ($abook_page_selector_max % 2 ? $abook_page_selector_max : $abook_page_selector_max - 1); $end_page = $page_number + floor($pages_to_show / 2); $start_page = $page_number - floor($pages_to_show / 2); if (!($abook_page_selector_max % 2)) $start_page--; if ($start_page < 1) { $end_page += 1 - $start_page; $start_page = 1; } else if ($end_page > $total_pages) { $start_page -= $end_page - $total_pages; $end_page = $total_pages; } // do we need to insert elipses? // if (1 < $start_page) { $start_page++; $show_elipses_before = TRUE; } if ($total_pages > $end_page) { $end_page--; $show_elipses_after = TRUE; } } // now build the actual (compact) paginator // if ($compact) { $aValues = array(); for ($i = 1; $i <= $total_pages; $i++) $aValues[$i] = $i . '/' . $total_pages; $page_uri = sqm_baseuri() . 'src/addressbook.php'; $temp_page_number = $current_page_args['page_number']; unset($current_page_args['page_number']); $page_uri = set_uri_vars($page_uri, array_diff($current_page_args, array('page_number' => 0)), FALSE); $current_page_args['page_number'] = $temp_page_number; $paginator_string .= addSelect('page_number', $aValues, $page_number, TRUE, (checkForJavascript() ? array('onchange' => 'SubmitOnSelect(this, \'' . $page_uri . '&page_number=' . '\')') : array())); // need a submit button when select widget cannot submit itself // if (!checkForJavascript()) { $paginator_string .= addSubmit(_("Go"), 'paginator_submit'); } } // now build the actual (regular) paginator // else { $paginator_string .= '[' . $nbsp; if ($show_elipses_before) $paginator_string .= make_abook_paginator_link(1, 1, $current_page_args) . $nbsp . '...' . $nbsp; for ($x = $start_page; $x <= $end_page; $x++) { if ($x == $page_number) $paginator_string .= $x . $nbsp; else $paginator_string .= make_abook_paginator_link($x, $x, $current_page_args) . $nbsp; } if ($show_elipses_after) $paginator_string .= '...' . $nbsp . make_abook_paginator_link($total_pages, $total_pages, $current_page_args) . $nbsp; $paginator_string .= ']'; } $paginator_string .= $spacing . $show_all_string; return $paginator_string; } /** * Build a page (pagination) link for use with the address book list page * * @param int $page_number The page number for the link * @param string $text The link text * @param array $current_page_args All known query string arguments * for the current page request; structured * as an associative array of key/value pairs * */ function make_abook_paginator_link($page_number, $text, $current_page_args) { $uri = sqm_baseuri() . 'src/addressbook.php'; $current_page_args['page_number'] = $page_number; $uri = set_uri_vars($uri, $current_page_args, FALSE); return create_hyperlink($uri, $text); }