redesigned ou editor
This commit is contained in:
parent
e95403e0c3
commit
08694d9a87
|
@ -3,7 +3,7 @@
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
|
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
|
||||||
Copyright (C) 2003 - 2006 Roland Gruber
|
Copyright (C) 2003 - 2008 Roland Gruber
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -47,21 +47,25 @@ setlanguage();
|
||||||
|
|
||||||
$types = $_SESSION['config']->get_ActiveTypes();
|
$types = $_SESSION['config']->get_ActiveTypes();
|
||||||
|
|
||||||
|
// check if deletion was canceled
|
||||||
|
if (isset($_POST['abort'])) {
|
||||||
|
display_main();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// check if submit button was pressed
|
// check if submit button was pressed
|
||||||
if (isset($_POST['submit'])) {
|
if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) {
|
||||||
// check user input
|
|
||||||
for ($i = 0; $i < sizeof($types); $i++) {
|
|
||||||
// new ou
|
// new ou
|
||||||
if ($_POST['type'] == "new_" . $types[$i]) {
|
if (isset($_POST['createOU'])) {
|
||||||
// create ou if valid
|
// create ou if valid
|
||||||
if (eregi("^[a-z0-9 _\\-]+$", $_POST['newname_' . $types[$i]])) {
|
if (eregi("^[a-z0-9 _\\-]+$", $_POST['newOU'])) {
|
||||||
// check if ou already exists
|
// check if ou already exists
|
||||||
$new_dn = "ou=" . $_POST['newname_' . $types[$i]] . "," . $_POST['parentsuff_' . $types[$i]];
|
$new_dn = "ou=" . $_POST['newOU'] . "," . $_POST['parentOU'];
|
||||||
if (!in_array($new_dn, $_SESSION['ldap']->search_units($_POST['parentsuff_' . $types[$i]]))) {
|
if (!in_array($new_dn, $_SESSION['ldap']->search_units($_POST['parentOU']))) {
|
||||||
// add new ou
|
// add new ou
|
||||||
$ou = array();
|
$ou = array();
|
||||||
$ou['objectClass'] = "organizationalunit";
|
$ou['objectClass'] = "organizationalunit";
|
||||||
$ou['ou'] = $_POST['newname_' . $types[$i]];
|
$ou['ou'] = $_POST['newOU'];
|
||||||
$ret = @ldap_add($_SESSION['ldap']->server(), $new_dn, $ou);
|
$ret = @ldap_add($_SESSION['ldap']->server(), $new_dn, $ou);
|
||||||
if ($ret) {
|
if ($ret) {
|
||||||
$message = _("New OU created successfully.");
|
$message = _("New OU created successfully.");
|
||||||
|
@ -74,12 +78,12 @@ if (isset($_POST['submit'])) {
|
||||||
}
|
}
|
||||||
// show errormessage if ou is invalid
|
// show errormessage if ou is invalid
|
||||||
else {
|
else {
|
||||||
$error = _("OU is invalid!") . " " . $_POST['newname_' . $types[$i]];
|
$error = _("OU is invalid!") . "<br>" . $_POST['newOU'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// delete ou, user was sure
|
// delete ou, user was sure
|
||||||
elseif (($_POST['type'] == "del_" . $types[$i]) && ($_POST['sure'])) {
|
elseif (isset($_POST['deleteOU']) && isset($_POST['sure'])) {
|
||||||
$ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['deletename_' . $types[$i]]);
|
$ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['deletename']);
|
||||||
if ($ret) {
|
if ($ret) {
|
||||||
$message = _("OU deleted successfully.");
|
$message = _("OU deleted successfully.");
|
||||||
}
|
}
|
||||||
|
@ -87,25 +91,19 @@ if (isset($_POST['submit'])) {
|
||||||
$error = _("Unable to delete OU!");
|
$error = _("Unable to delete OU!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// do not delete ou
|
|
||||||
elseif (($_POST['type'] == "del_" . $types[$i]) && ($_POST['abort'])) {
|
|
||||||
display_main();
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
// ask if user is sure to delete
|
// ask if user is sure to delete
|
||||||
elseif ($_POST['type'] == "del_" . $types[$i]) {
|
elseif (isset($_POST['deleteOU'])) {
|
||||||
// check for sub entries
|
// check for sub entries
|
||||||
$sr = @ldap_list($_SESSION['ldap']->server(), $_POST['deletename_' . $types[$i]], "ObjectClass=*", array(""));
|
$sr = @ldap_list($_SESSION['ldap']->server(), $_POST['deleteableOU'], "ObjectClass=*", array(""));
|
||||||
$info = @ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
$info = @ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||||
if ($sr && $info['count'] == 0) {
|
if ($sr && $info['count'] == 0) {
|
||||||
$text = "<br>\n" .
|
$text = "<br>\n" .
|
||||||
"<p><big><b>" . _("Do you really want to delete this OU?") . " </b></big>" . "\n" .
|
"<p><big><b>" . _("Do you really want to delete this OU?") . " </b></big>" . "\n" .
|
||||||
"<br>\n<p>" . $_POST['deletename_' . $types[$i]] . "</p>\n" .
|
"<br>\n<p>" . $_POST['deleteableOU'] . "</p>\n" .
|
||||||
"<br>\n" .
|
"<br>\n" .
|
||||||
"<form action=\"ou_edit.php\" method=\"post\">\n" .
|
"<form action=\"ou_edit.php\" method=\"post\">\n" .
|
||||||
"<input type=\"hidden\" name=\"type\" value=\"del_" . $types[$i] . "\">\n" .
|
"<input type=\"hidden\" name=\"deleteOU\" value=\"submit\">\n" .
|
||||||
"<input type=\"hidden\" name=\"submit\" value=\"submit\">\n" .
|
"<input type=\"hidden\" name=\"deletename\" value=\"" . $_POST['deleteableOU'] . "\">\n" .
|
||||||
"<input type=\"hidden\" name=\"deletename_" . $types[$i] . "\" value=\"" . $_POST['deletename_' . $types[$i]] . "\">\n" .
|
|
||||||
"<input type=\"submit\" name=\"sure\" value=\"" . _("Delete") . "\">\n" .
|
"<input type=\"submit\" name=\"sure\" value=\"" . _("Delete") . "\">\n" .
|
||||||
"<input type=\"submit\" name=\"abort\" value=\"" . _("Cancel") . "\">\n" .
|
"<input type=\"submit\" name=\"abort\" value=\"" . _("Cancel") . "\">\n" .
|
||||||
"</form>";
|
"</form>";
|
||||||
|
@ -114,8 +112,6 @@ if (isset($_POST['submit'])) {
|
||||||
$error = _("OU is not empty or invalid!");
|
$error = _("OU is not empty or invalid!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// print header
|
// print header
|
||||||
echo $_SESSION['header'];
|
echo $_SESSION['header'];
|
||||||
|
@ -139,8 +135,12 @@ if (isset($_POST['submit'])) {
|
||||||
echo ("</body></html>\n");
|
echo ("</body></html>\n");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else display_main();
|
|
||||||
|
|
||||||
|
display_main();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the main page of the OU editor
|
||||||
|
*/
|
||||||
function display_main() {
|
function display_main() {
|
||||||
$types = $_SESSION['config']->get_ActiveTypes();
|
$types = $_SESSION['config']->get_ActiveTypes();
|
||||||
// display main page
|
// display main page
|
||||||
|
@ -156,38 +156,45 @@ function display_main() {
|
||||||
echo ("<br>\n");
|
echo ("<br>\n");
|
||||||
echo ("<form action=\"ou_edit.php\" method=\"post\">\n");
|
echo ("<form action=\"ou_edit.php\" method=\"post\">\n");
|
||||||
|
|
||||||
// display fieldsets
|
$options = "";
|
||||||
for ($i = 0; $i < sizeof($types); $i++) {
|
for ($i = 0; $i < sizeof($types); $i++) {
|
||||||
// generate lists of possible suffixes
|
$options .= "<optgroup label=\"" . getTypeAlias($types[$i]) . "\">\n";
|
||||||
$units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($types[$i]));
|
$units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($types[$i]));
|
||||||
echo ("<fieldset class=\"" . $types[$i] . "edit\"><legend><b>" . getTypeAlias($types[$i]) . "</b></legend><br>\n");
|
for ($u = 0; $u < sizeof($units); $u++) {
|
||||||
|
$options .= "<option>" . $units[$u] . "</option>\n";
|
||||||
|
}
|
||||||
|
$options .= "</optgroup>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo ("<fieldset class=\"useredit\"><br>\n");
|
||||||
echo ("<table border=0>\n");
|
echo ("<table border=0>\n");
|
||||||
// new OU
|
// new OU
|
||||||
echo ("<tr>\n");
|
echo ("<tr>\n");
|
||||||
echo ("<td><input type=radio name=\"type\" value=\"new_" . $types[$i] . "\"></td>\n");
|
echo ("<td><b>" . _("New organizational unit") . "</b></td>\n");
|
||||||
echo ("<td><b>" . _("New organizational unit") . ":</b></td>\n");
|
|
||||||
echo ("<td> </td>\n");
|
echo ("<td> </td>\n");
|
||||||
echo ("<td><select class=\"" . $types[$i] . "\" size=1 name=parentsuff_" . $types[$i] . ">");
|
echo ("<td><select size=1 name=\"parentOU\">");
|
||||||
for ($u = 0; $u < sizeof($units); $u++) {
|
echo $options;
|
||||||
echo ("<option>" . $units[$u] . "</option>\n");
|
|
||||||
}
|
|
||||||
echo ("</select><td>\n");
|
echo ("</select><td>\n");
|
||||||
echo ("<td><input type=text name=newname_" . $types[$i] . "></td>\n");
|
echo ("<td><input type=text name=\"newOU\"></td>\n");
|
||||||
|
echo "<td>";
|
||||||
|
echo "<input type=\"submit\" name=\"createOU\" value=\"" . _("Ok") . "\"> ";
|
||||||
|
echo "</td>";
|
||||||
echo "<td><a href=\"help.php?HelpNumber=601\" target=\"lamhelp\">";
|
echo "<td><a href=\"help.php?HelpNumber=601\" target=\"lamhelp\">";
|
||||||
echo "<img src=\"../graphics/help.png\" alt=\"". _("Help") ."\" title=\"" . _("Help") . "\">";
|
echo "<img src=\"../graphics/help.png\" alt=\"". _("Help") ."\" title=\"" . _("Help") . "\">";
|
||||||
echo "</a></td>\n";
|
echo "</a></td>\n";
|
||||||
echo ("</tr>\n");
|
echo ("</tr>\n");
|
||||||
|
echo "<tr><td colspan=5> </td></tr>\n";
|
||||||
// delete OU
|
// delete OU
|
||||||
echo ("<tr>\n");
|
echo ("<tr>\n");
|
||||||
echo ("<td><input type=radio name=\"type\" value=\"del_" . $types[$i] . "\"></td>\n");
|
echo ("<td><b>" . _("Delete organizational unit") . "</b></td>\n");
|
||||||
echo ("<td><b>" . _("Delete organizational unit") . ":</b></td>\n");
|
|
||||||
echo ("<td> </td>\n");
|
echo ("<td> </td>\n");
|
||||||
echo ("<td><select class=\"" . $types[$i] . "\" size=1 name=deletename_" . $types[$i] . ">");
|
echo ("<td><select size=1 name=\"deleteableOU\">");
|
||||||
for ($u = 0; $u < sizeof($units); $u++) {
|
echo $options;
|
||||||
echo ("<option>" . $units[$u] . "</option>\n");
|
|
||||||
}
|
|
||||||
echo ("</select><td>\n");
|
echo ("</select><td>\n");
|
||||||
echo ("<td> </td>\n");
|
echo ("<td> </td>\n");
|
||||||
|
echo "<td>";
|
||||||
|
echo "<input type=\"submit\" name=\"deleteOU\" value=\"" . _("Ok") . "\"> ";
|
||||||
|
echo "</td>";
|
||||||
echo "<td><a href=\"help.php?HelpNumber=602\" target=\"lamhelp\">";
|
echo "<td><a href=\"help.php?HelpNumber=602\" target=\"lamhelp\">";
|
||||||
echo "<img src=\"../graphics/help.png\" alt=\"". _("Help") ."\" title=\"" . _("Help") . "\">";
|
echo "<img src=\"../graphics/help.png\" alt=\"". _("Help") ."\" title=\"" . _("Help") . "\">";
|
||||||
echo "</a></td>\n";
|
echo "</a></td>\n";
|
||||||
|
@ -195,9 +202,7 @@ function display_main() {
|
||||||
echo ("</table>\n");
|
echo ("</table>\n");
|
||||||
echo ("</fieldset>\n");
|
echo ("</fieldset>\n");
|
||||||
echo ("<br>\n");
|
echo ("<br>\n");
|
||||||
}
|
|
||||||
|
|
||||||
echo ("<input type=\"submit\" name=\"submit\" value=\"" . _("Ok") . "\">");
|
|
||||||
echo ("</form>\n");
|
echo ("</form>\n");
|
||||||
echo ("</body></html>\n");
|
echo ("</body></html>\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue