6 * The following functions are utility functions for templates. Do not
7 * echo output in these functions.
9 * @copyright © 2005-2009 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 $paginator_string .= _("<<") . '][' . _("<") . '][';
147 if ($page_number < $total_pages)
148 $paginator_string .= make_abook_paginator_link($page_number +
1,
152 . make_abook_paginator_link($total_pages,
157 $paginator_string .= _(">") . '][' . _(">>") . ']';
161 // build next/previous links for regular paginator
165 if ($page_number > 1)
166 $paginator_string .= make_abook_paginator_link($page_number - 1,
170 $paginator_string .= _("Previous");
171 $paginator_string .= $nbsp . $sep . $nbsp;
172 if ($page_number < $total_pages)
173 $paginator_string .= make_abook_paginator_link($page_number +
1,
177 $paginator_string .= _("Next");
178 $paginator_string .= ']';
182 // paginator is turned off - just show previous/next links
184 if (!$abook_page_selector)
186 return $paginator_string . $spacing . $show_all_string;
190 $paginator_string .= $spacing;
193 if ($total_pages <= $abook_page_selector_max)
196 $end_page = $total_pages;
200 $pages_to_show = ($abook_page_selector_max %
2 ?
$abook_page_selector_max : $abook_page_selector_max - 1);
201 $end_page = $page_number +
floor($pages_to_show / 2);
202 $start_page = $page_number - floor($pages_to_show / 2);
203 if (!($abook_page_selector_max %
2)) $start_page--;
207 $end_page +
= 1 - $start_page;
210 else if ($end_page > $total_pages)
212 $start_page -= $end_page - $total_pages;
213 $end_page = $total_pages;
217 // do we need to insert elipses?
222 $show_elipses_before = TRUE;
224 if ($total_pages > $end_page)
227 $show_elipses_after = TRUE;
232 // now build the actual (compact) paginator
237 for ($i = 1; $i <= $total_pages; $i++
)
238 $aValues[$i] = $i . '/' . $total_pages;
239 $page_uri = sqm_baseuri() . 'src/addressbook.php';
240 $temp_page_number = $current_page_args['page_number'];
241 unset($current_page_args['page_number']);
242 $page_uri = set_uri_vars($page_uri, array_diff($current_page_args, array('page_number' => 0)), FALSE);
243 $current_page_args['page_number'] = $temp_page_number;
244 $paginator_string .= addSelect('page_number', $aValues,
246 (checkForJavascript()
247 ?
array('onchange' => 'SubmitOnSelect(this, \''
253 // need a submit button when select widget cannot submit itself
255 if (!checkForJavascript())
257 $paginator_string .= addSubmit(_("Go"), 'paginator_submit');
262 // now build the actual (regular) paginator
266 $paginator_string .= '[' . $nbsp;
267 if ($show_elipses_before)
268 $paginator_string .= make_abook_paginator_link(1, 1, $current_page_args)
269 . $nbsp . '...' . $nbsp;
270 for ($x = $start_page; $x <= $end_page; $x++
)
272 if ($x == $page_number)
273 $paginator_string .= $x . $nbsp;
275 $paginator_string .= make_abook_paginator_link($x, $x, $current_page_args) . $nbsp;
277 if ($show_elipses_after)
278 $paginator_string .= '...' . $nbsp
279 . make_abook_paginator_link($total_pages, $total_pages, $current_page_args)
281 $paginator_string .= ']';
283 $paginator_string .= $spacing . $show_all_string;
286 return $paginator_string;
292 * Build a page (pagination) link for use with the address book list page
294 * @param int $page_number The page number for the link
295 * @param string $text The link text
296 * @param array $current_page_args All known query string arguments
297 * for the current page request; structured
298 * as an associative array of key/value pairs
301 function make_abook_paginator_link($page_number, $text, $current_page_args) {
303 $uri = sqm_baseuri() . 'src/addressbook.php';
305 $current_page_args['page_number'] = $page_number;
306 $uri = set_uri_vars($uri, $current_page_args, FALSE);
308 return create_hyperlink($uri, $text);