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++) { for ($k = 0; $k < sizeof($desc_array); $k++) {
if (strtolower($attr_array[$k]) == $sort) { if (strtolower($attr_array[$k]) == $sort) {
echo "<th class=\"grouplist-sort\"><a href=\"listgroups.php?". 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?". 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"; 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++) { for ($d = 0; $d < sizeof($grp_info[$i][strtolower($attr_array[$k])]); $d++) {
$user = $grp_info[$i][strtolower($attr_array[$k])][$d]; // user name $user = $grp_info[$i][strtolower($attr_array[$k])][$d]; // user name
// if user was found in LDAP make link, otherwise just print 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); 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++) { for ($k = 0; $k < sizeof($desc_array); $k++) {
if (strtolower($attr_array[$k]) == $sort) { if (strtolower($attr_array[$k]) == $sort) {
echo "<th class=\"hostlist-sort\"><a href=\"listhosts.php?". 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?". 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"; 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\" echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">\n"; \"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 // check if button was pressed and if we have to add/delete a user
if ($_POST['new_user'] || $_POST['del_user']){ if ($_POST['new_user'] || $_POST['del_user']){
// add new user // add new user
@ -101,6 +104,12 @@ $sortattrib = $_GET["sortattrib"];
if (!$sortattrib) if (!$sortattrib)
$sortattrib = strtolower($attr_array[0]); $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 // generate search filter for sort links
$searchfilter = ""; $searchfilter = "";
@ -114,7 +123,14 @@ for ($k = 0; $k < sizeof($desc_array); $k++) {
// configure search filter // configure search filter
// Users have the attribute "*" // Users have the attribute "*"
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=*$)))"; $filter = "(&(&(|(objectClass=posixAccount) (objectClass=sambaAccount)) (!(uid=*$)))";
}
for ($k = 0; $k < sizeof($desc_array); $k++) { for ($k = 0; $k < sizeof($desc_array); $k++) {
if ($_POST["filter" . strtolower($attr_array[$k])]) if ($_POST["filter" . strtolower($attr_array[$k])])
$filter = $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 // read entries only from ldap server if not yet stored in session or if refresh
// button is pressed or if filter is applied // button is pressed or if filter is applied
if ($_SESSION["userlist"] && $_GET["norefresh"]) { if ($_SESSION["userlist"] && $_GET["norefresh"]) {
if ($_GET["sort"] == 1)
usort ($_SESSION["userlist"], "cmp_array"); usort ($_SESSION["userlist"], "cmp_array");
$userinfo = $_SESSION["userlist"]; $userinfo = $_SESSION["userlist"];
} else { } else {
$attrs = $attr_array; $attrs = $attr_array;
$sr = @ldap_search($_SESSION["ldap"]->server(), $sr = @ldap_search($_SESSION["ldap"]->server(),
$_SESSION["config"]->get_UserSuffix(), $usr_suffix,
$filter, $attrs); $filter, $attrs);
if ($sr) { if ($sr) {
$userinfo = ldap_get_entries ($_SESSION["ldap"]->server, $sr); $userinfo = ldap_get_entries ($_SESSION["ldap"]->server, $sr);
@ -145,6 +160,7 @@ if ($_SESSION["userlist"] && $_GET["norefresh"]) {
// delete first array entry which is "count" // delete first array entry which is "count"
array_shift($userinfo); array_shift($userinfo);
usort ($userinfo, "cmp_array");
$_SESSION["userlist"] = $userinfo; $_SESSION["userlist"] = $userinfo;
} }
else else
@ -177,7 +193,7 @@ if ($user_count != 0) {
echo "<th class=\"userlist_activecolumn\">\n"; echo "<th class=\"userlist_activecolumn\">\n";
else else
echo "<th>\n"; 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 . "\">" . strtolower($attr_array[$k]) . $searchfilter . "\">" .
$desc_array[$k] . "</a></th>\n"; $desc_array[$k] . "</a></th>\n";
} }
@ -204,18 +220,20 @@ if ($user_count != 0) {
echo("<tr class=\"userlist\" onMouseOver=\"user_over(this, '" . $userinfo[$i]["dn"] . "')\"" . echo("<tr class=\"userlist\" onMouseOver=\"user_over(this, '" . $userinfo[$i]["dn"] . "')\"" .
" onMouseOut=\"user_out(this, '" . $userinfo[$i]["dn"] . "')\"" . " onMouseOut=\"user_out(this, '" . $userinfo[$i]["dn"] . "')\"" .
" onClick=\"user_click(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 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++) { for ($k = 0; $k < sizeof($attr_array); $k++) {
echo ("<td>\n"); echo ("<td>\n");
// print all attribute entries seperated by "; " // print all attribute entries seperated by "; "
if (sizeof($userinfo[$i][strtolower($attr_array[$k])]) > 0) { if (sizeof($userinfo[$i][strtolower($attr_array[$k])]) > 0) {
// delete first array entry which is "count" // delete first array entry which is "count"
if (is_array($userinfo[$i][strtolower($attr_array[$k])])) {
array_shift($userinfo[$i][strtolower($attr_array[$k])]); array_shift($userinfo[$i][strtolower($attr_array[$k])]);
// print all other attributes
echo implode("; ", $userinfo[$i][strtolower($attr_array[$k])]); echo implode("; ", $userinfo[$i][strtolower($attr_array[$k])]);
} }
else echo $userinfo[$i][strtolower($attr_array[$k])];
}
} }
echo ("</td>"); echo ("</td>");
} }
@ -229,14 +247,27 @@ if ($user_count != 0) {
echo ("<br />"); echo ("<br />");
} }
if (! $_GET['norefresh']) {
echo ("<table align=\"left\" border=\"0\">"); // generate list of possible suffixes
echo ("<tr><td align=\"left\"><input type=\"submit\" name=\"new_user\" value=\"" . _("New User") . "\"></td>"); $usr_units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_UserSuffix());
if ($user_count != 0) {
echo ("<td align=\"left\"><input type=\"submit\" name=\"del_user\" value=\"" . _("Delete User(s)") . "\"></td></tr>");
} }
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 ("</form>\n");
echo "</body></html>\n"; echo "</body></html>\n";
@ -256,16 +287,16 @@ function draw_navigation_bar ($user_count) {
echo ("<tr>"); echo ("<tr>");
echo ("<td class=\"userlist_navbar\"><input type=\"submit\" name=\"refresh\" value=\"" . _("Refresh") . "\">&nbsp;&nbsp;"); echo ("<td class=\"userlist_navbar\"><input type=\"submit\" name=\"refresh\" value=\"" . _("Refresh") . "\">&nbsp;&nbsp;");
if ($page != 1) if ($page != 1)
echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&page=" . echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&amp;page=" .
($page - 1) . "&sortattrib=" . $sortattrib . ($page - 1) . "&amp;sortattrib=" . $sortattrib .
$searchfilter . "\">&lt;=</a>"); $searchfilter . "\">&lt;=</a>");
else else
echo ("&lt;="); echo ("&lt;=");
echo ("&nbsp;"); echo ("&nbsp;");
if ($page < ($user_count / $max_pageentrys)) if ($page < ($user_count / $max_pageentrys))
echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&page=" . echo ("<a class=\"userlist\" href=\"listusers.php?norefresh=1&amp;page=" .
($page + 1) . "&sortattrib=" . $sortattrib . $searchfilter . "\">=&gt;</a>"); ($page + 1) . "&amp;sortattrib=" . $sortattrib . $searchfilter . "\">=&gt;</a>");
else else
echo ("=&gt;"); echo ("=&gt;");
echo ("</td>"); echo ("</td>");
@ -279,9 +310,9 @@ function draw_navigation_bar ($user_count) {
if ($i == $page - 1) if ($i == $page - 1)
echo ("&nbsp;" . ($i + 1)); echo ("&nbsp;" . ($i + 1));
else 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) . ($i + 1) .
"&sortattrib=" . $sortattrib . $searchfilter . "&amp;sortattrib=" . $sortattrib . $searchfilter .
"\">" . ($i + 1) . "</a>"); "\">" . ($i + 1) . "</a>");
} }
echo ("</td></tr></table>"); echo ("</td></tr></table>");
@ -296,9 +327,9 @@ function cmp_array($a, $b) {
global $sortattrib; global $sortattrib;
global $attr_array; global $attr_array;
// sort by first attribute with name $sortattrib // sort by first attribute with name $sortattrib
if (!$sortattrib) $sortattrib = strtolower($attr_array[0]);
if ($a[$sortattrib][0] == $b[$sortattrib][0]) return 0; if ($a[$sortattrib][0] == $b[$sortattrib][0]) return 0;
else if ($a[$sortattrib][0] == else if ($a[$sortattrib][0] == max($a[$sortattrib][0], $b[$sortattrib][0])) return 1;
max($a[$sortattrib][0], $b[$sortattrib][0])) return 1;
else return -1; else return -1;
} }