diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc new file mode 100644 index 00000000..38761a15 --- /dev/null +++ b/lam/lib/lists.inc @@ -0,0 +1,78 @@ + \ No newline at end of file diff --git a/lam/templates/lists/listdomains.php b/lam/templates/lists/listdomains.php index cee3c073..ed010d0b 100644 --- a/lam/templates/lists/listdomains.php +++ b/lam/templates/lists/listdomains.php @@ -22,9 +22,10 @@ $Id$ This code displays a list of all Samba domains. */ -include_once ("../../lib/config.inc"); -include_once ("../../lib/ldap.inc"); -include_once ("../../lib/status.inc"); +include_once("../../lib/config.inc"); +include_once("../../lib/ldap.inc"); +include_once("../../lib/status.inc"); +include_once("../../lib/lists.inc"); // start session session_save_path("../../sess"); @@ -107,7 +108,7 @@ if (! $_GET['norefresh']) { // delete first array entry which is "count" array_shift($dom_info); // sort rows by sort column ($sort) - usort($dom_info, "cmp_array"); + $dom_info = listSort($sort, $attr_array, $dom_info); } else StatusMessage("ERROR", _("LDAP Search failed! Please check your preferences."), _("No Samba Domains found!")); } @@ -115,7 +116,7 @@ if (! $_GET['norefresh']) { else { if (sizeof($dom_info) == 0) StatusMessage("WARN", "", _("No Samba Domains found!")); // sort rows by sort column ($sort) - if ($dom_info) usort($dom_info, "cmp_array"); + if ($dom_info) $dom_info = listSort($sort, $attr_array, $dom_info); } echo ("
\n"); @@ -244,27 +245,6 @@ function draw_navigation_bar ($count) { echo ("\n"); } -// compare function used for usort-method -// rows are sorted with the first attribute entry of the sort column -// if objects have attributes with multiple values the others are ignored -function cmp_array($a, $b) { - // sort specifies the sort column - global $sort; - global $attr_array; - // sort by first column if no attribute is given - if (!$sort) $sort = strtolower($attr_array[0]); - if ($sort != "dn") { - // sort by first attribute with name $sort - if ($a[$sort][0] == $b[$sort][0]) return 0; - else if ($a[$sort][0] == max($a[$sort][0], $b[$sort][0])) return 1; - else return -1; - } - else { - if ($a[$sort] == $b[$sort]) return 0; - else if ($a[$sort] == max($a[$sort], $b[$sort])) return 1; - else return -1; - } -} // save variables to session diff --git a/lam/templates/lists/listgroups.php b/lam/templates/lists/listgroups.php index c6df081f..38d50c2b 100644 --- a/lam/templates/lists/listgroups.php +++ b/lam/templates/lists/listgroups.php @@ -28,6 +28,7 @@ include_once ("../../lib/status.inc"); include_once("../../lib/account.inc"); include_once("../../lib/pdf.inc"); include_once("../../lib/modules.inc"); +include_once("../../lib/lists.inc"); // start session session_save_path("../../sess"); @@ -170,7 +171,7 @@ if (! $_GET['norefresh']) { // delete first array entry which is "count" array_shift($grp_info); // sort rows by sort column ($sort) - usort($grp_info, "cmp_array"); + $grp_info = listSort($sort, $attr_array, $grp_info); } else { $grp_info = array(); @@ -181,7 +182,7 @@ if (! $_GET['norefresh']) { else { if (sizeof($grp_info) == 0) StatusMessage("WARN", "", _("No Groups found!")); // sort rows by sort column ($sort) - if ($grp_info) usort($grp_info, "cmp_array"); + if ($grp_info) $grp_info =listSort($sort, $attr_array, $grp_info); } echo ("\n"); @@ -367,28 +368,6 @@ function draw_navigation_bar ($count) { echo ("\n"); } -// compare function used for usort-method -// rows are sorted with the first attribute entry of the sort column -// if objects have attributes with multiple values the others are ignored -function cmp_array($a, $b) { - // sort specifies the sort column - global $sort; - global $attr_array; - // sort by first column if no attribute is given - if (!$sort) $sort = strtolower($attr_array[0]); - if ($sort != "dn") { - // sort by first attribute with name $sort - if ($a[$sort][0] == $b[$sort][0]) return 0; - else if ($a[$sort][0] == max($a[$sort][0], $b[$sort][0])) return 1; - else return -1; - } - else { - if ($a[$sort] == $b[$sort]) return 0; - else if ($a[$sort] == max($a[$sort], $b[$sort])) return 1; - else return -1; - } -} - // save variables to session $_SESSION['grp_info'] = $grp_info; $_SESSION['grp_units'] = $grp_units; diff --git a/lam/templates/lists/listhosts.php b/lam/templates/lists/listhosts.php index c53b08d3..7131bd15 100644 --- a/lam/templates/lists/listhosts.php +++ b/lam/templates/lists/listhosts.php @@ -28,6 +28,7 @@ include_once ("../../lib/status.inc"); include_once("../../lib/account.inc"); include_once("../../lib/pdf.inc"); include_once("../../lib/modules.inc"); +include_once("../../lib/lists.inc"); // start session session_save_path("../../sess"); @@ -166,7 +167,7 @@ if (! $_GET['norefresh']) { // delete first array entry which is "count" array_shift($hst_info); // sort rows by sort column ($sort) - usort($hst_info, "cmp_array"); + $hst_info = listSort($sort, $attr_array, $hst_info); } else { $hst_info = array(); @@ -177,7 +178,7 @@ if (! $_GET['norefresh']) { else { if (sizeof($hst_info) == 0) StatusMessage("WARN", "", _("No Samba Hosts found!")); // sort rows by sort column ($sort) - if ($hst_info) usort($hst_info, "cmp_array"); + if ($hst_info) $hst_info = listSort($sort, $attr_array, $hst_info); } echo ("\n"); @@ -348,28 +349,6 @@ function draw_navigation_bar ($count) { echo ("\n"); } -// compare function used for usort-method -// rows are sorted with the first attribute entry of the sort column -// if objects have attributes with multiple values the others are ignored -function cmp_array($a, $b) { - // sort specifies the sort column - global $sort; - global $attr_array; - // sort by first column if no attribute is given - if (!$sort) $sort = strtolower($attr_array[0]); - if ($sort != "dn") { - // sort by first attribute with name $sort - if ($a[$sort][0] == $b[$sort][0]) return 0; - else if ($a[$sort][0] == max($a[$sort][0], $b[$sort][0])) return 1; - else return -1; - } - else { - if ($a[$sort] == $b[$sort]) return 0; - else if ($a[$sort] == max($a[$sort], $b[$sort])) return 1; - else return -1; - } -} - // save variables to session $_SESSION['hst_info'] = $hst_info; $_SESSION['hst_units'] = $hst_units; diff --git a/lam/templates/lists/listusers.php b/lam/templates/lists/listusers.php index 726244fe..75b6792f 100644 --- a/lam/templates/lists/listusers.php +++ b/lam/templates/lists/listusers.php @@ -27,6 +27,7 @@ include_once("../../lib/ldap.inc"); include_once("../../lib/pdf.inc"); include_once("../../lib/account.inc"); include_once("../../lib/modules.inc"); +include_once("../../lib/lists.inc"); // used to display status messages include_once ("../../lib/status.inc"); @@ -157,9 +158,9 @@ for ($i = 0; $i < sizeof($temp_array); $i++) { } } -$sortattrib = $_GET["sortattrib"]; -if (!$sortattrib) - $sortattrib = strtolower($attr_array[0]); +$sort = $_GET["sortattrib"]; +if (!$sort) + $sort = strtolower($attr_array[0]); // check search suffix if ($_POST['usr_suffix']) $usr_suffix = $_POST['usr_suffix']; // new suffix selected via combobox @@ -192,7 +193,7 @@ $filter = $filter . ")"; // read entries only from ldap server if not yet stored in session or if refresh // button is pressed or if filter is applied if ($_SESSION["userlist"] && $_GET["norefresh"]) { - usort ($_SESSION["userlist"], "cmp_array"); + $_SESSION["userlist"] = listSort($sort, $attr_array, $_SESSION["userlist"]); $userinfo = $_SESSION["userlist"]; } else { @@ -207,7 +208,7 @@ else { if ($userinfo["count"] == 0) StatusMessage("WARN", "", _("No Users found!")); // delete first array entry which is "count" array_shift($userinfo); - usort ($userinfo, "cmp_array"); + $userinfo = listSort($sort, $attr_array, $userinfo); $_SESSION["userlist"] = $userinfo; } else { @@ -239,7 +240,7 @@ if ($user_count != 0) { echo "\n"; // table header for ($k = 0; $k < sizeof ($desc_array); $k++) { - if ($sortattrib == strtolower($attr_array[$k])) + if ($sort == strtolower($attr_array[$k])) echo "\n"; else echo "\n"; @@ -272,8 +273,8 @@ if ($user_count != 0) { } } // resort if needed - if ($sortattrib == "gidnumber") { - usort ($userinfo, "cmp_array"); + if ($sort == "gidnumber") { + $userinfo = listSort($sort, $attr_array, $userinfo); } } // print user list @@ -316,7 +317,7 @@ if ($user_count != 0) { $colspan = sizeof($attr_array) + 1; echo "\n"; echo "\"select\n"; - echo "  " . "" . _("Select all") . "\n"; echo "\n"; @@ -388,7 +389,7 @@ echo "\n"; function draw_navigation_bar ($user_count) { global $max_pageentrys; global $page; - global $sortattrib; + global $sort; global $searchfilter; global $trans_primary; @@ -397,13 +398,13 @@ function draw_navigation_bar ($user_count) { echo ("\n\n  "); if ($page != 1) echo ("<=\n"); + ($page - 1) . "&sortattrib=" . $sort . $searchfilter . "&trans_primary=" . $trans_primary . "\"><=\n"); else echo ("<="); echo (" "); if ($page < ($user_count / $max_pageentrys)) echo ("=>\n"); + ($page + 1) . "&sortattrib=" . $sort . $searchfilter . "&trans_primary=" . $trans_primary . "\">=>\n"); else echo ("=>"); echo ("\n"); echo ("\n"); @@ -415,35 +416,13 @@ function draw_navigation_bar ($user_count) { for ($i = 0; $i < ($user_count / $max_pageentrys); $i++) { if ($i == $page - 1) echo (" " . ($i + 1)); else echo (" " . ($i + 1) . "\n"); } echo ("\n\n"); } -// compare function used for usort-method -// rows are sorted with the first attribute entry of the sort column -// if objects have attributes with multiple values the others are ignored -function cmp_array($a, $b) { - // sortattrib specifies the sort column - global $sortattrib; - global $attr_array; - // sort by first attribute with name $sortattrib - if (!$sortattrib) $sortattrib = strtolower($attr_array[0]); - if ($sortattrib != "dn") { - // sort by first column if no attribute is given - if ($a[$sortattrib][0] == $b[$sortattrib][0]) return 0; - else if ($a[$sortattrib][0] == max($a[$sortattrib][0], $b[$sortattrib][0])) return 1; - else return -1; - } - else { - if ($a[$sortattrib] == $b[$sortattrib]) return 0; - else if ($a[$sortattrib] == max($a[$sortattrib], $b[$sortattrib])) return 1; - else return -1; - } -} - // save variables to session $_SESSION['usr_units'] = $usr_units; $_SESSION['usr_suffix'] = $usr_suffix;