6 * The following functions are utility functions for templates. Do not
7 * echo output in these functions.
9 * @copyright 2005-2020 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
17 * Display a column header with sort buttons
19 * @param string $field Which field to display
20 * @param array $current_page_args All known query string arguments
21 * for the current page request; structured
22 * as an associative array of key/value pairs
27 function addAbookSort ($field, $current_page_args) {
28 global $abook_sort_order, $nbsp;
33 $alt = _("Sort by nickname");
40 $alt = _("Sort by name");
47 $alt = _("Sort by email");
54 $alt = _("Sort by info");
60 return 'BAD SORT FIELD GIVEN: "'.$field.'"';
63 // show_abook_sort_button() creates a hyperlink (using hyperlink.tpl) that encompases an image, using a getImage() call
64 return $str . ($has_sort ?
$nbsp . show_abook_sort_button($abook_sort_order, $alt, $down, $up, $current_page_args) : '');
69 * Creates an address book paginator
71 * @param boolean $abook_page_selector Whether or not to show the page selector
72 * @param int $abook_page_selector_max The maximum number of page links to show
74 * @param int $page_number What page is being viewed - 0 if not used
75 * @param int $page_size Maximum number of addresses to be shown
77 * @param int $total_addresses The total count of addresses in the backend
78 * @param boolean $show_all Whether or not all addresses are being shown
79 * @param array $current_page_args All known query string arguments
80 * for the current page request; structured
81 * as an associative array of key/value pairs
82 * @param boolean $compact Whether or not to build a smaller,
85 * @return string The paginator, ready for output
88 function get_abook_paginator($abook_page_selector, $abook_page_selector_max,
89 $page_number, $page_size, $total_addresses,
90 $show_all, $current_page_args, $compact) {
92 // if showing all, just show pagination link
96 unset($current_page_args['show_all']);
97 return '[' . make_abook_paginator_link(1, _("Paginate"), $current_page_args) . ']';
101 // if we don't have enough information to build the paginator, return nothing
103 if (empty($page_number) ||
empty($page_size) ||
empty($total_addresses))
107 // calculate some values we need below
109 $show_elipses_before = FALSE;
110 $show_elipses_after = FALSE;
113 $paginator_string = '[';
114 $total_pages = ceil($total_addresses / $page_size);
115 if ($page_number > $total_pages) $page_number = $total_pages;
116 $spacing = ($compact ?
$nbsp : $nbsp . $nbsp);
119 // only enough addresses for one page anyway? no pagination needed
121 if ($total_pages < 2) return '';
124 // build "Show All" link
126 $show_all_string = '['
127 . make_abook_paginator_link(1, _("All"),
128 array_merge($current_page_args, array('show_all' => 1)))
132 // build next/previous links for compact paginator
136 if ($page_number > 1)
137 $paginator_string .= make_abook_paginator_link(1,
141 . make_abook_paginator_link($page_number - 1,
146 // i18n: "<<" is for the first page in the paginator. "<" is for the previous page.
147 $paginator_string .= _("<<") . '][' . _("<") . '][';
148 if ($page_number < $total_pages)
149 $paginator_string .= make_abook_paginator_link($page_number +
1,
153 . make_abook_paginator_link($total_pages,
158 // i18n: ">>" is for the last page in the paginator. ">" is for the next page.
159 $paginator_string .= _(">") . '][' . _(">>") . ']';
163 // build next/previous links for regular paginator
167 if ($page_number > 1)
168 $paginator_string .= make_abook_paginator_link($page_number - 1,
172 $paginator_string .= _("Previous");
173 $paginator_string .= $nbsp . $sep . $nbsp;
174 if ($page_number < $total_pages)
175 $paginator_string .= make_abook_paginator_link($page_number +
1,
179 $paginator_string .= _("Next");
180 $paginator_string .= ']';
184 // paginator is turned off - just show previous/next links
186 if (!$abook_page_selector)
188 return $paginator_string . $spacing . $show_all_string;
192 $paginator_string .= $spacing;
195 if ($total_pages <= $abook_page_selector_max)
198 $end_page = $total_pages;
202 $pages_to_show = ($abook_page_selector_max %
2 ?
$abook_page_selector_max : $abook_page_selector_max - 1);
203 $end_page = $page_number +
floor($pages_to_show / 2);
204 $start_page = $page_number - floor($pages_to_show / 2);
205 if (!($abook_page_selector_max %
2)) $start_page--;
209 $end_page +
= 1 - $start_page;
212 else if ($end_page > $total_pages)
214 $start_page -= $end_page - $total_pages;
215 $end_page = $total_pages;
219 // do we need to insert elipses?
224 $show_elipses_before = TRUE;
226 if ($total_pages > $end_page)
229 $show_elipses_after = TRUE;
234 // now build the actual (compact) paginator
239 for ($i = 1; $i <= $total_pages; $i++
)
240 $aValues[$i] = $i . '/' . $total_pages;
241 $page_uri = sqm_baseuri() . 'src/addressbook.php';
242 $temp_page_number = $current_page_args['page_number'];
243 unset($current_page_args['page_number']);
244 $page_uri = set_uri_vars($page_uri, array_diff($current_page_args, array('page_number' => 0)), FALSE);
245 $current_page_args['page_number'] = $temp_page_number;
246 $paginator_string .= addSelect('page_number', $aValues,
248 (checkForJavascript()
249 ?
array('onchange' => 'SubmitOnSelect(this, \''
255 // need a submit button when select widget cannot submit itself
257 if (!checkForJavascript())
259 $paginator_string .= addSubmit(_("Go"), 'paginator_submit');
264 // now build the actual (regular) paginator
268 $paginator_string .= '[' . $nbsp;
269 if ($show_elipses_before)
270 $paginator_string .= make_abook_paginator_link(1, 1, $current_page_args)
271 . $nbsp . '...' . $nbsp;
272 for ($x = $start_page; $x <= $end_page; $x++
)
274 if ($x == $page_number)
275 $paginator_string .= $x . $nbsp;
277 $paginator_string .= make_abook_paginator_link($x, $x, $current_page_args) . $nbsp;
279 if ($show_elipses_after)
280 $paginator_string .= '...' . $nbsp
281 . make_abook_paginator_link($total_pages, $total_pages, $current_page_args)
283 $paginator_string .= ']';
285 $paginator_string .= $spacing . $show_all_string;
288 return $paginator_string;
294 * Build a page (pagination) link for use with the address book list page
296 * @param int $page_number The page number for the link
297 * @param string $text The link text
298 * @param array $current_page_args All known query string arguments
299 * for the current page request; structured
300 * as an associative array of key/value pairs
303 function make_abook_paginator_link($page_number, $text, $current_page_args) {
305 $uri = sqm_baseuri() . 'src/addressbook.php';
307 $current_page_args['page_number'] = $page_number;
308 $uri = set_uri_vars($uri, $current_page_args, FALSE);
310 return create_hyperlink($uri, $text);