From: tokul Date: Sun, 18 Apr 2004 10:28:38 +0000 (+0000) Subject: adding address book sorting function X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=92948f86768dd49bf544b9f09cd134a07a9cf1eb;p=squirrelmail.git adding address book sorting function git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7143 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/addressbook.php b/functions/addressbook.php index a5013808..705742df 100644 --- a/functions/addressbook.php +++ b/functions/addressbook.php @@ -546,8 +546,12 @@ class addressbook_backend { } -/* Sort array by the key "name" */ +/** + * Sort array by the key "name" + */ function alistcmp($a,$b) { + $abook_sort=get_abook_sort(); + if ($a['backend'] > $b['backend']) { return 1; } else { @@ -555,9 +559,31 @@ function alistcmp($a,$b) { return -1; } } - return (strtolower($a['name']) > strtolower($b['name'])) ? 1 : -1; + return (strtolower($a[$abook_sort]) > strtolower($b[$abook_sort])) ? 1 : -1; } +/** + * Address book sorting order + * + * returns name of field that should be used for sorting. + * @return string name of address book field + */ +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); + } else { + $abook_sort = getPref($data_dir, $username, 'abook_sort', 'name'); + } + + if ($abook_sort != "nickname" && $abook_sort != "email" && $abook_sort != "label") + $abook_sort = "name"; + + return $abook_sort; +} /* PHP 5 requires that the class be made first, which seems rather