- Fixed date display bug for messages of today. Show short format in case
of long format. (only occures in the timeframe around 0:00 AM till
timezone).
+ - Added address book sorting options. Ascending/descending sorting code
+ written by Bryan Loniewski
Version 1.5.0
--------------------
<?php
-
/**
* addressbook.php
*
* Sort array by the key "name"
*/
function alistcmp($a,$b) {
- $abook_sort=get_abook_sort();
+ $abook_sort_order=get_abook_sort();
+
+ switch ($abook_sort_order) {
+ case 0:
+ case 1:
+ $abook_sort='nickname';
+ break;
+ case 4:
+ case 5:
+ $abook_sort='email';
+ break;
+ case 6:
+ case 7:
+ $abook_sort='label';
+ break;
+ case 2:
+ case 3:
+ case 8:
+ default:
+ $abook_sort='name';
+ }
if ($a['backend'] > $b['backend']) {
return 1;
return -1;
}
}
- return (strtolower($a[$abook_sort]) > strtolower($b[$abook_sort])) ? 1 : -1;
+
+ if( (($abook_sort_order+2) % 2) == 1) {
+ return (strtolower($a[$abook_sort]) < strtolower($b[$abook_sort])) ? 1 : -1;
+ } else {
+ return (strtolower($a[$abook_sort]) > strtolower($b[$abook_sort])) ? 1 : -1;
+ }
}
/**
- * Address book sorting order
+ * Address book sorting options
*
- * returns name of field that should be used for sorting.
- * @return string name of address book field
+ * returns address book sorting order
+ * @return integer book sorting options order
*/
function get_abook_sort() {
global $data_dir, $username;
/* get sorting order */
- if(sqgetGlobalVar('abook_sort', $abook_sort,SQ_GET)) {
- sqgetGlobalVar('abook_sort', $abook_sort,SQ_GET);
- setPref($data_dir, $username, 'abook_sort', $abook_sort);
+ 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 {
- $abook_sort = getPref($data_dir, $username, 'abook_sort', 'name');
+ /* get previous sorting options. default to unsorted */
+ $abook_sort_order = getPref($data_dir, $username, 'abook_sort_order', 8);
}
- if ($abook_sort != "nickname" && $abook_sort != "email" && $abook_sort != "label")
- $abook_sort = "name";
+ 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;
+
+ /* Figure out which image we want to use. */
+ if ($abook_sort_order != $Up && $abook_sort_order != $Down) {
+ $img = 'sort_none.png';
+ $which = $Up;
+ } elseif ($abook_sort_order == $Up) {
+ $img = 'up_pointer.png';
+ $which = $Down;
+ } else {
+ $img = 'down_pointer.png';
+ $which = 8;
+ }
- return $abook_sort;
+ /* Now that we have everything figured out, show the actual button. */
+ return ' <a href="' . $form_url .'?abook_sort_order=' . $which
+ . '"><img src="../images/' . $img
+ . '" border="0" width="12" height="10" alt="' . $alt_tag . '" title="'
+ . _("Click here to change the sorting of the address list") .'"></a>';
}
/*
sqgetGlobalVar('backend', $backend, SQ_POST);
sqgetGlobalVar('doedit', $doedit, SQ_POST);
+/* Get sorting order */
+$abook_sort_order = get_abook_sort();
+
/**
* Make an input field
* @param string $label
html_tag( 'tr', "\n" .
html_tag( 'th', ' ', 'left', '', 'width="1%"' ) . "\n" .
html_tag( 'th', _("Nickname") .
- " <a href=\"$form_url?abook_sort=nickname\">".
- "<img src=\"../images/sort_none.png\" border=\"0\" width=\"12\" height=\"10\" alt=\"sort by nickname\" title=\"" .
- _("Click here to change the sorting of the address list") .
- "\" /></a>", 'left', '', 'width="1%"' ) . "\n" .
+ show_abook_sort_button($abook_sort_order, _("sort by nickname"), 0, 1)
+ , 'left', '', 'width="1%"' ) . "\n" .
html_tag( 'th', _("Name") .
- " <a href=\"$form_url?abook_sort=name\">" .
- "<img src=\"../images/sort_none.png\" border=\"0\" width=\"12\" height=\"10\" " .
- "alt=\"sort by name\" title=\"" .
- _("Click here to change the sorting of the address list") .
- "\" /></a>", 'left', '', 'width="1%"' ) . "\n" .
+ show_abook_sort_button($abook_sort_order, _("sort by name"), 2, 3)
+ , 'left', '', 'width="1%"' ) . "\n" .
html_tag( 'th', _("E-mail") .
- " <a href=\"$form_url?abook_sort=email\">" .
- "<img src=\"../images/sort_none.png\" border=\"0\" width=\"12\" height=\"10\" " .
- "alt=\"sort by email\" title=\"" .
- _("Click here to change the sorting of the address list") .
- "\" /></a>", 'left', '', 'width="1%"' ) . "\n" .
+ show_abook_sort_button($abook_sort_order, _("sort by email"), 4, 5)
+ , 'left', '', 'width="1%"' ) . "\n" .
html_tag( 'th', _("Info") .
- " <a href=\"$form_url?abook_sort=label\">" .
- "<img src=\"../images/sort_none.png\" border=\"0\" width=\"12\" height=\"10\" " .
- "alt=\"sort by info\" title=\"" .
- _("Click here to change the sorting of the address list") .
- "\" /></a>", 'left', '', 'width="1%"' ) . "\n",
+ show_abook_sort_button($abook_sort_order, _("sort by info"), 6, 7)
+ , 'left', '', 'width="1%"' ) . "\n",
'', $color[9] ) . "\n";
}