+function get_abook_sort() {
+ global $data_dir, $username;
+
+ /* get sorting order */
+ if(sqgetGlobalVar('abook_sort_order', $temp, SQ_GET)) {
+ $abook_sort_order = (int) $temp;
+
+ if ($abook_sort_order < 0 or $abook_sort_order > 8)
+ $abook_sort_order=8;
+
+ setPref($data_dir, $username, 'abook_sort_order', $abook_sort_order);
+ } else {
+ /* get previous sorting options. default to unsorted */
+ $abook_sort_order = getPref($data_dir, $username, 'abook_sort_order', 8);
+ }
+
+ return $abook_sort_order;
+}
+
+/**
+ * This function shows the address book sort button.
+ *
+ * @param integer $abook_sort_order current sort value
+ * @param string $alt_tag alt tag value (string visible to text only browsers)
+ * @param integer $Down sort value when list is sorted ascending
+ * @param integer $Up sort value when list is sorted descending
+ * @return string html code with sorting images and urls
+ */
+function show_abook_sort_button($abook_sort_order, $alt_tag, $Down, $Up ) {
+ global $form_url, $icon_theme_path;
+
+ /* Figure out which image we want to use. */
+ if ($abook_sort_order != $Up && $abook_sort_order != $Down) {
+ $img = 'sort_none.png';
+ $text_icon = '◻'; // U+25FB WHITE MEDIUM SQUARE
+ $which = $Up;
+ } elseif ($abook_sort_order == $Up) {
+ $img = 'up_pointer.png';
+ $text_icon = '⇧'; // U+21E7 UPWARDS WHITE ARROW
+ $which = $Down;
+ } else {
+ $img = 'down_pointer.png';
+ $text_icon = '⇩'; // U+21E9 DOWNWARDS WHITE ARROW
+ $which = 8;
+ }
+
+ /* Now that we have everything figured out, show the actual button. */
+ return ' <a href="' . $form_url .'?abook_sort_order=' . $which .
+ '" style="text-decoration:none" title="'.$alt_tag.'">' .
+ getIcon($icon_theme_path, $img, $text_icon, $alt_tag) .
+ '</a>';
+}