moved cmp_array to lists.inc
This commit is contained in:
		
							parent
							
								
									11ac8d26e0
								
							
						
					
					
						commit
						4bbeabf249
					
				|  | @ -0,0 +1,78 @@ | |||
| <?php | ||||
| /* | ||||
| $Id$ | ||||
| 
 | ||||
|   This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) | ||||
|   Copyright (C) 2003 - 2004  Roland Gruber | ||||
| 
 | ||||
|   This program is free software; you can redistribute it and/or modify | ||||
|   it under the terms of the GNU General Public License as published by | ||||
|   the Free Software Foundation; either version 2 of the License, or | ||||
|   (at your option) any later version. | ||||
| 
 | ||||
|   This program is distributed in the hope that it will be useful, | ||||
|   but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|   GNU General Public License for more details. | ||||
| 
 | ||||
|   You should have received a copy of the GNU General Public License | ||||
|   along with this program; if not, write to the Free Software | ||||
|   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||
| 
 | ||||
| 
 | ||||
| */ | ||||
| 
 | ||||
| /** | ||||
| * This file includes functions to manage the list views. | ||||
| * | ||||
| * @package lists | ||||
| * @author Roland Gruber | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
| * Sorts an account list by a given attribute | ||||
| * | ||||
| * @param string $sort the attribute by which to sort | ||||
| * @param array $attr_array array of displayed attributes | ||||
| * @param array $info the account list | ||||
| * @return array sorted account list | ||||
| */ | ||||
| function listSort($sort, $attr_array, $info) { | ||||
| 
 | ||||
| 	/** | ||||
| 	* 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 only the first is used for sorting. | ||||
| 	* | ||||
| 	* @param array $a first row which is compared | ||||
| 	* @param array $b second row which is compared | ||||
| 	* @return integer 0 if both are equal, 1 if $a is greater, -1 if $b is greater | ||||
| 	*/ | ||||
| 	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; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// sort and return account list
 | ||||
| 	usort($info, "cmp_array"); | ||||
| 	return $info; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| ?>
 | ||||
|  | @ -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 ("<form action=\"listdomains.php\" method=\"post\">\n"); | ||||
|  | @ -244,27 +245,6 @@ function draw_navigation_bar ($count) { | |||
|   echo ("</td></tr></table>\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
 | ||||
|  |  | |||
|  | @ -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 ("<form action=\"listgroups.php\" method=\"post\">\n"); | ||||
|  | @ -367,28 +368,6 @@ function draw_navigation_bar ($count) { | |||
|   echo ("</td></tr></table>\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; | ||||
|  |  | |||
|  | @ -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 ("<form action=\"listhosts.php\" method=\"post\">\n"); | ||||
|  | @ -348,28 +349,6 @@ function draw_navigation_bar ($count) { | |||
|   echo ("</td></tr></table>\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; | ||||
|  |  | |||
|  | @ -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 "<tr class=\"userlist-head\"><th width=22 height=34></th><th></th>\n"; | ||||
|   // table header
 | ||||
|   for ($k = 0; $k < sizeof ($desc_array); $k++) { | ||||
|     if ($sortattrib == strtolower($attr_array[$k])) | ||||
|     if ($sort == strtolower($attr_array[$k])) | ||||
|       echo "<th class=\"userlist-activecolumn\">\n"; | ||||
|     else | ||||
|       echo "<th>\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 "<tr class=\"userlist\">\n"; | ||||
| 	echo "<td align=\"center\"><img src=\"../../graphics/select.png\" alt=\"select all\"></td>\n"; | ||||
| 	echo "<td colspan=$colspan> <a href=\"listusers.php?norefresh=1&page=" . $page . "&sortattrib=" . $sortattrib . | ||||
| 	echo "<td colspan=$colspan> <a href=\"listusers.php?norefresh=1&page=" . $page . "&sortattrib=" . $sort . | ||||
| 		$searchfilter . "&trans_primary=" . $trans_primary . "&selectall=yes\">" . | ||||
| 		"<font color=\"black\"><b>" . _("Select all") . "</b></font></a></td>\n"; | ||||
| 	echo "</tr>\n"; | ||||
|  | @ -388,7 +389,7 @@ echo "</body></html>\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 ("<td class=\"userlist-navbar\">\n<input type=\"submit\" name=\"refresh\" value=\"" . _("Refresh") . "\">\n  "); | ||||
| 	if ($page != 1) | ||||
| 		echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&page=" . | ||||
| 			($page - 1) . "&sortattrib=" . $sortattrib . $searchfilter . "&trans_primary=" . $trans_primary . "\"><=</a>\n"); | ||||
| 			($page - 1) . "&sortattrib=" . $sort . $searchfilter . "&trans_primary=" . $trans_primary . "\"><=</a>\n"); | ||||
| 	else echo ("<="); | ||||
| 	echo (" "); | ||||
| 
 | ||||
| 	if ($page < ($user_count / $max_pageentrys)) | ||||
| 		echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&page=" . | ||||
| 			($page + 1) . "&sortattrib=" . $sortattrib . $searchfilter . "&trans_primary=" . $trans_primary . "\">=></a>\n"); | ||||
| 			($page + 1) . "&sortattrib=" . $sort . $searchfilter . "&trans_primary=" . $trans_primary . "\">=></a>\n"); | ||||
| 	else echo ("=>"); | ||||
| 	echo ("</td>\n"); | ||||
| 	echo ("<td class=\"userlist-navbartext\">\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 (" <a class=\"userlist\" href=\"listusers.php?norefresh=1&page=" . | ||||
| 				($i + 1) . "&sortattrib=" . $sortattrib . $searchfilter . "&trans_primary=" . $trans_primary . | ||||
| 				($i + 1) . "&sortattrib=" . $sort . $searchfilter . "&trans_primary=" . $trans_primary . | ||||
| 				"\">" . ($i + 1) . "</a>\n"); | ||||
| 	} | ||||
| 	echo ("</td></tr>\n</table>\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; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue