From 08694d9a8705e9dcc563bdcabd92d947045ea3e2 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 28 Dec 2008 13:43:44 +0000 Subject: [PATCH] redesigned ou editor --- lam/templates/ou_edit.php | 213 +++++++++++++++++++------------------- 1 file changed, 109 insertions(+), 104 deletions(-) diff --git a/lam/templates/ou_edit.php b/lam/templates/ou_edit.php index 19272e86..3a93895f 100644 --- a/lam/templates/ou_edit.php +++ b/lam/templates/ou_edit.php @@ -3,7 +3,7 @@ $Id$ 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 it under the terms of the GNU General Public License as published by @@ -47,76 +47,72 @@ setlanguage(); $types = $_SESSION['config']->get_ActiveTypes(); +// check if deletion was canceled +if (isset($_POST['abort'])) { + display_main(); + exit; +} + // check if submit button was pressed -if (isset($_POST['submit'])) { - // check user input - for ($i = 0; $i < sizeof($types); $i++) { - // new ou - if ($_POST['type'] == "new_" . $types[$i]) { - // create ou if valid - if (eregi("^[a-z0-9 _\\-]+$", $_POST['newname_' . $types[$i]])) { - // check if ou already exists - $new_dn = "ou=" . $_POST['newname_' . $types[$i]] . "," . $_POST['parentsuff_' . $types[$i]]; - if (!in_array($new_dn, $_SESSION['ldap']->search_units($_POST['parentsuff_' . $types[$i]]))) { - // add new ou - $ou = array(); - $ou['objectClass'] = "organizationalunit"; - $ou['ou'] = $_POST['newname_' . $types[$i]]; - $ret = @ldap_add($_SESSION['ldap']->server(), $new_dn, $ou); - if ($ret) { - $message = _("New OU created successfully."); - } - else { - $error = _("Unable to create new OU!"); - } +if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) { + // new ou + if (isset($_POST['createOU'])) { + // create ou if valid + if (eregi("^[a-z0-9 _\\-]+$", $_POST['newOU'])) { + // check if ou already exists + $new_dn = "ou=" . $_POST['newOU'] . "," . $_POST['parentOU']; + if (!in_array($new_dn, $_SESSION['ldap']->search_units($_POST['parentOU']))) { + // add new ou + $ou = array(); + $ou['objectClass'] = "organizationalunit"; + $ou['ou'] = $_POST['newOU']; + $ret = @ldap_add($_SESSION['ldap']->server(), $new_dn, $ou); + if ($ret) { + $message = _("New OU created successfully."); + } + else { + $error = _("Unable to create new OU!"); } - else $error = _("OU already exists!"); - } - // show errormessage if ou is invalid - else { - $error = _("OU is invalid!") . " " . $_POST['newname_' . $types[$i]]; } + else $error = _("OU already exists!"); } - // delete ou, user was sure - elseif (($_POST['type'] == "del_" . $types[$i]) && ($_POST['sure'])) { - $ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['deletename_' . $types[$i]]); - if ($ret) { - $message = _("OU deleted successfully."); - } - else { - $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 - elseif ($_POST['type'] == "del_" . $types[$i]) { - // check for sub entries - $sr = @ldap_list($_SESSION['ldap']->server(), $_POST['deletename_' . $types[$i]], "ObjectClass=*", array("")); - $info = @ldap_get_entries($_SESSION['ldap']->server(), $sr); - if ($sr && $info['count'] == 0) { - $text = "
\n" . - "

" . _("Do you really want to delete this OU?") . " " . "\n" . - "
\n

" . $_POST['deletename_' . $types[$i]] . "

\n" . - "
\n" . - "
\n" . - "\n" . - "\n" . - "\n" . - "\n" . - "\n" . - "
"; - } - else { - $error = _("OU is not empty or invalid!"); - } + // show errormessage if ou is invalid + else { + $error = _("OU is invalid!") . "
" . $_POST['newOU']; } } - - + // delete ou, user was sure + elseif (isset($_POST['deleteOU']) && isset($_POST['sure'])) { + $ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['deletename']); + if ($ret) { + $message = _("OU deleted successfully."); + } + else { + $error = _("Unable to delete OU!"); + } + } + // ask if user is sure to delete + elseif (isset($_POST['deleteOU'])) { + // check for sub entries + $sr = @ldap_list($_SESSION['ldap']->server(), $_POST['deleteableOU'], "ObjectClass=*", array("")); + $info = @ldap_get_entries($_SESSION['ldap']->server(), $sr); + if ($sr && $info['count'] == 0) { + $text = "
\n" . + "

" . _("Do you really want to delete this OU?") . " " . "\n" . + "
\n

" . $_POST['deleteableOU'] . "

\n" . + "
\n" . + "
\n" . + "\n" . + "\n" . + "\n" . + "\n" . + "
"; + } + else { + $error = _("OU is not empty or invalid!"); + } + } + // print header echo $_SESSION['header']; echo ("OU-Editor\n"); @@ -139,8 +135,12 @@ if (isset($_POST['submit'])) { echo ("\n"); exit; } -else display_main(); +display_main(); + +/** + * Displays the main page of the OU editor + */ function display_main() { $types = $_SESSION['config']->get_ActiveTypes(); // display main page @@ -155,49 +155,54 @@ function display_main() { echo "

" . _("OU editor") . "

"; echo ("
\n"); echo ("
\n"); - - // display fieldsets + + $options = ""; for ($i = 0; $i < sizeof($types); $i++) { - // generate lists of possible suffixes + $options .= "\n"; $units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($types[$i])); - echo ("
" . getTypeAlias($types[$i]) . "
\n"); - echo ("\n"); - // new OU - echo ("\n"); - echo ("\n"); - echo ("\n"); - echo ("\n"); - echo ("\n"); - echo "\n"; - echo ("\n"); - // delete OU - echo ("\n"); - echo ("\n"); - echo ("\n"); - echo ("\n"); - echo ("\n"); - echo "\n"; - echo ("\n"); - echo ("
" . _("New organizational unit") . ": \n"); - echo (""; - echo "\""."; - echo "
" . _("Delete organizational unit") . ": \n"); - echo (" "; - echo "\""."; - echo "
\n"); - echo ("
\n"); - echo ("
\n"); + $options .= "
\n"; } - - echo (""); + + echo ("

\n"); + echo ("\n"); + // new OU + echo ("\n"); + echo ("\n"); + echo ("\n"); + echo ("\n"); + echo ""; + echo "\n"; + echo ("\n"); + echo "\n"; + // delete OU + echo ("\n"); + echo ("\n"); + echo ("\n"); + echo ("\n"); + echo ""; + echo "\n"; + echo ("\n"); + echo ("
" . _("New organizational unit") . " \n"); + echo (""; + echo " "; + echo ""; + echo "\""."; + echo "
 
" . _("Delete organizational unit") . " \n"); + echo (" "; + echo " "; + echo ""; + echo "\""."; + echo "
\n"); + echo ("
\n"); + echo ("
\n"); + echo ("
\n"); echo ("\n"); }