fixed HTML errors, implemented OU support in user list, always sort user list

This commit is contained in:
Roland Gruber 2003-06-30 20:04:59 +00:00
parent a24b3913fb
commit c48945f39b
3 changed files with 66 additions and 35 deletions

View File

@ -162,10 +162,10 @@ echo "<tr class=\"grouplist-head\"><th width=22 height=34></th><th></th>";
for ($k = 0; $k < sizeof($desc_array); $k++) {
if (strtolower($attr_array[$k]) == $sort) {
echo "<th class=\"grouplist-sort\"><a href=\"listgroups.php?".
"sort=" . strtolower($attr_array[$k]) . $searchfilter . "&norefresh=y" . "\">" . $desc_array[$k] . "</a></th>";
"sort=" . strtolower($attr_array[$k]) . $searchfilter . "&amp;norefresh=y" . "\">" . $desc_array[$k] . "</a></th>";
}
else echo "<th><a href=\"listgroups.php?".
"sort=" . strtolower($attr_array[$k]) . $searchfilter . "&norefresh=y" . "\">" . $desc_array[$k] . "</a></th>";
"sort=" . strtolower($attr_array[$k]) . $searchfilter . "&amp;norefresh=y" . "\">" . $desc_array[$k] . "</a></th>";
}
echo "</tr>\n";
@ -207,7 +207,7 @@ for ($i = $table_begin; $i < $table_end; $i++) {
for ($d = 0; $d < sizeof($grp_info[$i][strtolower($attr_array[$k])]); $d++) {
$user = $grp_info[$i][strtolower($attr_array[$k])][$d]; // user name
// if user was found in LDAP make link, otherwise just print name
$linklist[$d] = "<a href=userlink.php?user='" . $user . "' >" . $user . "</a>";
$linklist[$d] = "<a href=\"userlink.php?user='" . $user . "' \">" . $user . "</a>";
}
echo implode("; ", $linklist);
}

View File

@ -168,10 +168,10 @@ echo "<tr class=\"hostlist-head\"><th width=22 height=34></th><th></th>";
for ($k = 0; $k < sizeof($desc_array); $k++) {
if (strtolower($attr_array[$k]) == $sort) {
echo "<th class=\"hostlist-sort\"><a href=\"listhosts.php?".
"sort=" . strtolower($attr_array[$k]) . $searchfilter . "&norefresh=y" . "\">" . $desc_array[$k] . "</a></th>";
"sort=" . strtolower($attr_array[$k]) . $searchfilter . "&amp;norefresh=y" . "\">" . $desc_array[$k] . "</a></th>";
}
else echo "<th><a href=\"listhosts.php?".
"sort=" . strtolower($attr_array[$k]) . $searchfilter . "&norefresh=y" . "\">" . $desc_array[$k] . "</a></th>";
"sort=" . strtolower($attr_array[$k]) . $searchfilter . "&amp;norefresh=y" . "\">" . $desc_array[$k] . "</a></th>";
}
echo "</tr>\n";

View File

@ -41,6 +41,9 @@ echo "<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n";
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">\n";
$usr_units = $_SESSION['usr_units'];
session_register('usr_units');
// check if button was pressed and if we have to add/delete a user
if ($_POST['new_user'] || $_POST['del_user']){
// add new user
@ -101,6 +104,12 @@ $sortattrib = $_GET["sortattrib"];
if (!$sortattrib)
$sortattrib = strtolower($attr_array[0]);
// check search suffix
if ($_POST['usr_suffix']) $usr_suffix = $_POST['usr_suffix']; // new suffix selected via combobox
elseif ($_SESSION['usr_suffix']) $usr_suffix = $_SESSION['usr_suffix']; // old suffix from session
else $usr_suffix = $_SESSION["config"]->get_GroupSuffix(); // default suffix
session_register('usr_suffix');
// generate search filter for sort links
$searchfilter = "";
@ -114,7 +123,14 @@ for ($k = 0; $k < sizeof($desc_array); $k++) {
// configure search filter
// Users have the attribute "*"
$filter = "(&(&(|(objectClass=posixAccount) (objectClass=sambaAccount)) (!(uid=*$)))";
if ($_SESSION['config']->get_samba3() == "yes") {
// Samba users have the attribute "sambaSamAccount" and end with "$"
$filter = "(&(&(|(objectClass=posixAccount) (objectClass=sambaSamAccount)) (!(uid=*$)))";
}
else {
// Samba users have the attribute "sambaAccount" and end with "$"
$filter = "(&(&(|(objectClass=posixAccount) (objectClass=sambaAccount)) (!(uid=*$)))";
}
for ($k = 0; $k < sizeof($desc_array); $k++) {
if ($_POST["filter" . strtolower($attr_array[$k])])
$filter = $filter . "(" . strtolower($attr_array[$k]) . "=" .
@ -127,13 +143,12 @@ $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"]) {
if ($_GET["sort"] == 1)
usort ($_SESSION["userlist"], "cmp_array");
usort ($_SESSION["userlist"], "cmp_array");
$userinfo = $_SESSION["userlist"];
} else {
$attrs = $attr_array;
$sr = @ldap_search($_SESSION["ldap"]->server(),
$_SESSION["config"]->get_UserSuffix(),
$usr_suffix,
$filter, $attrs);
if ($sr) {
$userinfo = ldap_get_entries ($_SESSION["ldap"]->server, $sr);
@ -145,9 +160,10 @@ if ($_SESSION["userlist"] && $_GET["norefresh"]) {
// delete first array entry which is "count"
array_shift($userinfo);
usort ($userinfo, "cmp_array");
$_SESSION["userlist"] = $userinfo;
}
else
else
StatusMessage("ERROR",
_("LDAP Search failed! Please check your preferences."),
_("No Groups found!"));
@ -177,7 +193,7 @@ if ($user_count != 0) {
echo "<th class=\"userlist_activecolumn\">\n";
else
echo "<th>\n";
echo "<a class=\"userlist\" href=\"listusers.php?norefresh=1&sort=1&sortattrib=" .
echo "<a class=\"userlist\" href=\"listusers.php?norefresh=1&amp;sortattrib=" .
strtolower($attr_array[$k]) . $searchfilter . "\">" .
$desc_array[$k] . "</a></th>\n";
}
@ -204,17 +220,19 @@ if ($user_count != 0) {
echo("<tr class=\"userlist\" onMouseOver=\"user_over(this, '" . $userinfo[$i]["dn"] . "')\"" .
" onMouseOut=\"user_out(this, '" . $userinfo[$i]["dn"] . "')\"" .
" onClick=\"user_click(this, '" . $userinfo[$i]["dn"] . "')\"" .
" onDblClick=parent.frames[1].location.href=\"../account.php?type=user&DN='" . $userinfo[$i]["dn"] . "'\">" .
" onDblClick=\"parent.frames[1].location.href='../account.php?type=user&amp;DN=" . $userinfo[$i]["dn"] . "'\">" .
" <td height=22><input onClick=\"user_click(this, '" . $userinfo[$i]["dn"] . "')\" type=\"checkbox\" name=\"" . $userinfo[$i]["dn"] . "\"></td>" .
" <td align='center'><a href=\"../account.php?type=user&DN='" . $userinfo[$i]["dn"] . "'\">" . _("Edit") . "</a></td>\n");
" <td align='center'><a href=\"../account.php?type=user&amp;DN='" . $userinfo[$i]["dn"] . "'\">" . _("Edit") . "</a></td>\n");
for ($k = 0; $k < sizeof($attr_array); $k++) {
echo ("<td>\n");
// print all attribute entries seperated by "; "
if (sizeof($userinfo[$i][strtolower($attr_array[$k])]) > 0) {
// delete first array entry which is "count"
array_shift($userinfo[$i][strtolower($attr_array[$k])]);
// print all other attributes
echo implode("; ", $userinfo[$i][strtolower($attr_array[$k])]);
if (is_array($userinfo[$i][strtolower($attr_array[$k])])) {
array_shift($userinfo[$i][strtolower($attr_array[$k])]);
echo implode("; ", $userinfo[$i][strtolower($attr_array[$k])]);
}
else echo $userinfo[$i][strtolower($attr_array[$k])];
}
}
echo ("</td>");
@ -229,21 +247,34 @@ if ($user_count != 0) {
echo ("<br />");
}
echo ("<table align=\"left\" border=\"0\">");
echo ("<tr><td align=\"left\"><input type=\"submit\" name=\"new_user\" value=\"" . _("New User") . "\"></td>");
if ($user_count != 0) {
echo ("<td align=\"left\"><input type=\"submit\" name=\"del_user\" value=\"" . _("Delete User(s)") . "\"></td></tr>");
if (! $_GET['norefresh']) {
// generate list of possible suffixes
$usr_units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_UserSuffix());
}
echo ("</table>\n");
echo ("<p align=\"left\">\n");
echo ("<input type=\"submit\" name=\"new_user\" value=\"" . _("New User") . "\">\n");
if ($user_count != 0) echo ("<input type=\"submit\" name=\"del_user\" value=\"" . _("Delete User(s)") . "\">\n");
// print combobox with possible sub-DNs
if (sizeof($usr_units) > 1) {
echo ("&nbsp;&nbsp;&nbsp;&nbsp;<b>" . _("Suffix") . ": </b>");
echo ("<select size=1 name=\"usr_suffix\">\n");
for ($i = 0; $i < sizeof($usr_units); $i++) {
if ($usr_suffix == $usr_units[$i]) echo ("<option selected>" . $usr_units[$i] . "</option>\n");
else echo("<option>" . $usr_units[$i] . "</option>\n");
}
echo ("</select>\n");
echo ("<input type=\"submit\" name=\"refresh\" value=\"" . _("Change Suffix") . "\">");
}
echo ("</p>\n");
echo ("</form>\n");
echo "</body></html>\n";
/**
/**
* @brief draws a navigation bar to switch between pages
*
*
*
* @return void
*/
function draw_navigation_bar ($user_count) {
@ -256,16 +287,16 @@ function draw_navigation_bar ($user_count) {
echo ("<tr>");
echo ("<td class=\"userlist_navbar\"><input type=\"submit\" name=\"refresh\" value=\"" . _("Refresh") . "\">&nbsp;&nbsp;");
if ($page != 1)
echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&page=" .
($page - 1) . "&sortattrib=" . $sortattrib .
echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&amp;page=" .
($page - 1) . "&amp;sortattrib=" . $sortattrib .
$searchfilter . "\">&lt;=</a>");
else
echo ("&lt;=");
echo ("&nbsp;");
if ($page < ($user_count / $max_pageentrys))
echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&page=" .
($page + 1) . "&sortattrib=" . $sortattrib . $searchfilter . "\">=&gt;</a>");
echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&amp;page=" .
($page + 1) . "&amp;sortattrib=" . $sortattrib . $searchfilter . "\">=&gt;</a>");
else
echo ("=&gt;");
echo ("</td>");
@ -279,9 +310,9 @@ function draw_navigation_bar ($user_count) {
if ($i == $page - 1)
echo ("&nbsp;" . ($i + 1));
else
echo ("&nbsp;<a class=\"userlist\" href=\"listusers.php?norefresh=1&page=" .
echo ("&nbsp;<a class=\"userlist\" href=\"listusers.php?norefresh=1&amp;page=" .
($i + 1) .
"&sortattrib=" . $sortattrib . $searchfilter .
"&amp;sortattrib=" . $sortattrib . $searchfilter .
"\">" . ($i + 1) . "</a>");
}
echo ("</td></tr></table>");
@ -296,10 +327,10 @@ function cmp_array($a, $b) {
global $sortattrib;
global $attr_array;
// sort by first attribute with name $sortattrib
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;
if (!$sortattrib) $sortattrib = strtolower($attr_array[0]);
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;
}
?>