Source for file abook_util.php

Documentation is available at abook_util.php

  1. <?php
  2. /**
  3. * abook_util.php
  4. *
  5. * The following functions are utility functions for templates. Do not
  6. * echo output in these functions.
  7. *
  8. * @copyright 2005-2020 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id: abook_util.php 14845 2020年01月07日 08:09:34Z pdontthink $
  11. * @package squirrelmail
  12. */
  13. /**
  14. * Display a column header with sort buttons
  15. *
  16. * @param string $field Which field to display
  17. * @param array $current_page_args All known query string arguments
  18. * for the current page request; structured
  19. * as an associative array of key/value pairs
  20. *
  21. * @author Steve Brown
  22. * @since 1.5.2
  23. */
  24. function addAbookSort ($field, $current_page_args) {
  25. global $abook_sort_order, $nbsp;
  26. switch ($field) {
  27. case 'nickname':
  28. $str = _ ("Nickname");
  29. $alt = _ ("Sort by nickname");
  30. $down = 0;
  31. $up = 1;
  32. $has_sort = true;
  33. break;
  34. case 'fullname':
  35. $str = _ ("Name");
  36. $alt = _ ("Sort by name");
  37. $down = 2;
  38. $up = 3;
  39. $has_sort = true;
  40. break;
  41. case 'email':
  42. $str = _ ("E-mail");
  43. $alt = _ ("Sort by email");
  44. $down = 4;
  45. $up = 5;
  46. $has_sort = true;
  47. break;
  48. case 'info':
  49. $str = _ ("Info");
  50. $alt = _ ("Sort by info");
  51. $down = 6;
  52. $up = 7;
  53. $has_sort = true;
  54. break;
  55. default:
  56. return 'BAD SORT FIELD GIVEN: "'.$field.'"';
  57. }
  58. // show_abook_sort_button() creates a hyperlink (using hyperlink.tpl) that encompases an image, using a getImage() call
  59. return $str . ($has_sort ? $nbsp . show_abook_sort_button ($abook_sort_order, $alt, $down, $up, $current_page_args) : '');
  60. }
  61. /**
  62. * Creates an address book paginator
  63. *
  64. * @param boolean $abook_page_selector Whether or not to show the page selector
  65. * @param int $abook_page_selector_max The maximum number of page links to show
  66. * on screen
  67. * @param int $page_number What page is being viewed - 0 if not used
  68. * @param int $page_size Maximum number of addresses to be shown
  69. * per page
  70. * @param int $total_addresses The total count of addresses in the backend
  71. * @param boolean $show_all Whether or not all addresses are being shown
  72. * @param array $current_page_args All known query string arguments
  73. * for the current page request; structured
  74. * as an associative array of key/value pairs
  75. * @param boolean $compact Whether or not to build a smaller,
  76. * "compact" paginator
  77. *
  78. * @return string The paginator, ready for output
  79. *
  80. */
  81. function get_abook_paginator ($abook_page_selector, $abook_page_selector_max,
  82. $page_number, $page_size, $total_addresses,
  83. $show_all, $current_page_args, $compact) {
  84. // if showing all, just show pagination link
  85. //
  86. if ($show_all)
  87. {
  88. unset($current_page_args['show_all']);
  89. return '[' . make_abook_paginator_link (1, _ ("Paginate"), $current_page_args) . ']';
  90. }
  91. // if we don't have enough information to build the paginator, return nothing
  92. //
  93. if (empty($page_number) || empty($page_size) || empty($total_addresses))
  94. return '';
  95. // calculate some values we need below
  96. //
  97. $show_elipses_before = FALSE;
  98. $show_elipses_after = FALSE;
  99. global $nbsp;
  100. $sep = '|';
  101. $paginator_string = '[';
  102. $total_pages = ceil ($total_addresses / $page_size);
  103. if ($page_number > $total_pages) $page_number = $total_pages;
  104. $spacing = ($compact ? $nbsp : $nbsp . $nbsp);
  105. // only enough addresses for one page anyway? no pagination needed
  106. //
  107. if ($total_pages < 2) return '';
  108. // build "Show All" link
  109. //
  110. $show_all_string = '['
  111. . make_abook_paginator_link (1, _ ("All"),
  112. array_merge ($current_page_args, array('show_all' => 1)))
  113. . ']';
  114. // build next/previous links for compact paginator
  115. //
  116. if ($compact)
  117. {
  118. if ($page_number > 1)
  119. $paginator_string .= make_abook_paginator_link (1,
  120. _ ("<<"),
  121. $current_page_args)
  122. . ']['
  123. . make_abook_paginator_link ($page_number - 1,
  124. _ ("<"),
  125. $current_page_args)
  126. . '][';
  127. else
  128. // i18n: "<<" is for the first page in the paginator. "<" is for the previous page.
  129. $paginator_string .= _ ("<<") . '][' . _ ("<") . '][';
  130. if ($page_number < $total_pages)
  131. $paginator_string .= make_abook_paginator_link ($page_number + 1,
  132. _ (">"),
  133. $current_page_args)
  134. . ']['
  135. . make_abook_paginator_link ($total_pages,
  136. _ (">>"),
  137. $current_page_args)
  138. . ']';
  139. else
  140. // i18n: ">>" is for the last page in the paginator. ">" is for the next page.
  141. $paginator_string .= _ (">") . '][' . _ (">>") . ']';
  142. }
  143. // build next/previous links for regular paginator
  144. //
  145. else
  146. {
  147. if ($page_number > 1)
  148. $paginator_string .= make_abook_paginator_link ($page_number - 1,
  149. _ ("Previous"),
  150. $current_page_args);
  151. else
  152. $paginator_string .= _ ("Previous");
  153. $paginator_string .= $nbsp . $sep . $nbsp;
  154. if ($page_number < $total_pages)
  155. $paginator_string .= make_abook_paginator_link ($page_number + 1,
  156. _ ("Next"),
  157. $current_page_args);
  158. else
  159. $paginator_string .= _ ("Next");
  160. $paginator_string .= ']';
  161. }
  162. // paginator is turned off - just show previous/next links
  163. //
  164. if (!$abook_page_selector)
  165. {
  166. return $paginator_string . $spacing . $show_all_string;
  167. }
  168. $paginator_string .= $spacing;
  169. if ($total_pages <= $abook_page_selector_max)
  170. {
  171. $start_page = 1;
  172. $end_page = $total_pages;
  173. }
  174. else
  175. {
  176. $pages_to_show = ($abook_page_selector_max % 2 ? $abook_page_selector_max : $abook_page_selector_max - 1);
  177. $end_page = $page_number + floor ($pages_to_show / 2);
  178. $start_page = $page_number - floor ($pages_to_show / 2);
  179. if (!($abook_page_selector_max % 2)) $start_page--;
  180. if ($start_page < 1)
  181. {
  182. $end_page += 1 - $start_page;
  183. $start_page = 1;
  184. }
  185. else if ($end_page > $total_pages)
  186. {
  187. $start_page -= $end_page - $total_pages;
  188. $end_page = $total_pages;
  189. }
  190. // do we need to insert elipses?
  191. //
  192. if (1 < $start_page)
  193. {
  194. $start_page++;
  195. $show_elipses_before = TRUE;
  196. }
  197. if ($total_pages > $end_page)
  198. {
  199. $end_page--;
  200. $show_elipses_after = TRUE;
  201. }
  202. }
  203. // now build the actual (compact) paginator
  204. //
  205. if ($compact)
  206. {
  207. $aValues = array();
  208. for ($i = 1; $i <= $total_pages; $i++)
  209. $aValues[$i] = $i . '/' . $total_pages;
  210. $page_uri = sqm_baseuri () . 'src/addressbook.php';
  211. $temp_page_number = $current_page_args['page_number'];
  212. unset($current_page_args['page_number']);
  213. $page_uri = set_uri_vars ($page_uri, array_diff ($current_page_args, array('page_number' => 0)), FALSE);
  214. $current_page_args['page_number'] = $temp_page_number;
  215. $paginator_string .= addSelect ('page_number', $aValues,
  216. $page_number, TRUE,
  217. ? array('onchange' => 'SubmitOnSelect(this, \''
  218. . $page_uri
  219. . '&page_number='
  220. . '\')')
  221. : array()));
  222. // need a submit button when select widget cannot submit itself
  223. //
  224. {
  225. $paginator_string .= addSubmit (_ ("Go"), 'paginator_submit');
  226. }
  227. }
  228. // now build the actual (regular) paginator
  229. //
  230. else
  231. {
  232. $paginator_string .= '[' . $nbsp;
  233. if ($show_elipses_before)
  234. $paginator_string .= make_abook_paginator_link (1, 1, $current_page_args)
  235. . $nbsp . '...' . $nbsp;
  236. for ($x = $start_page; $x <= $end_page; $x++)
  237. {
  238. if ($x == $page_number)
  239. $paginator_string .= $x . $nbsp;
  240. else
  241. $paginator_string .= make_abook_paginator_link ($x, $x, $current_page_args) . $nbsp;
  242. }
  243. if ($show_elipses_after)
  244. $paginator_string .= '...' . $nbsp
  245. . make_abook_paginator_link ($total_pages, $total_pages, $current_page_args)
  246. . $nbsp;
  247. $paginator_string .= ']';
  248. }
  249. $paginator_string .= $spacing . $show_all_string;
  250. return $paginator_string;
  251. }
  252. /**
  253. * Build a page (pagination) link for use with the address book list page
  254. *
  255. * @param int $page_number The page number for the link
  256. * @param string $text The link text
  257. * @param array $current_page_args All known query string arguments
  258. * for the current page request; structured
  259. * as an associative array of key/value pairs
  260. *
  261. */
  262. function make_abook_paginator_link ($page_number, $text, $current_page_args) {
  263. $uri = sqm_baseuri () . 'src/addressbook.php';
  264. $current_page_args['page_number'] = $page_number;
  265. $uri = set_uri_vars ($uri, $current_page_args, FALSE);
  266. return create_hyperlink ($uri, $text);
  267. }

Documentation generated on 2020年1月13日 04:21:57 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /