removed double checks, better error handling

This commit is contained in:
Roland Gruber 2003-07-28 18:35:35 +00:00
parent b2448de10a
commit d198a67671
1 changed files with 24 additions and 48 deletions

View File

@ -64,10 +64,6 @@ if ($_POST['submit']) {
} }
// delete ou, user was sure // delete ou, user was sure
elseif (($_POST['type'] == "del_usr") && ($_POST['sure'])) { elseif (($_POST['type'] == "del_usr") && ($_POST['sure'])) {
// check for sub entries
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['usersuff_d'], "ObjectClass=*", array(""));
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($info['count'] == 0) {
$ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['usersuff_d']); $ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['usersuff_d']);
if ($ret) { if ($ret) {
$message = _("OU deleted successfully."); $message = _("OU deleted successfully.");
@ -76,10 +72,6 @@ if ($_POST['submit']) {
$error = _("Unable to delete OU!"); $error = _("Unable to delete OU!");
} }
} }
else {
$error = _("OU is not empty!");
}
}
// do not delete ou // do not delete ou
elseif (($_POST['type'] == "del_usr") && ($_POST['abort'])) { elseif (($_POST['type'] == "del_usr") && ($_POST['abort'])) {
display_main(); display_main();
@ -88,9 +80,9 @@ if ($_POST['submit']) {
// ask if user is sure to delete // ask if user is sure to delete
elseif ($_POST['type'] == "del_usr") { elseif ($_POST['type'] == "del_usr") {
// check for sub entries // check for sub entries
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['usersuff_d'], "ObjectClass=*", array("")); $sr = @ldap_list($_SESSION['ldap']->server(), $_POST['usersuff_d'], "ObjectClass=*", array(""));
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr); $info = @ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($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['usersuff_d'] . "</p>\n" . "<br>\n<p>" . $_POST['usersuff_d'] . "</p>\n" .
@ -104,7 +96,7 @@ if ($_POST['submit']) {
"</form>"; "</form>";
} }
else { else {
$error = _("OU is not empty!"); $error = _("OU is not empty or invalid!");
} }
} }
@ -137,10 +129,6 @@ if ($_POST['submit']) {
} }
// delete ou, user was sure // delete ou, user was sure
elseif (($_POST['type'] == "del_grp") && ($_POST['sure'])) { elseif (($_POST['type'] == "del_grp") && ($_POST['sure'])) {
// check for sub entries
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['groupsuff_d'], "ObjectClass=*", array(""));
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($info['count'] == 0) {
$ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['groupsuff_d']); $ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['groupsuff_d']);
if ($ret) { if ($ret) {
$message = _("OU deleted successfully."); $message = _("OU deleted successfully.");
@ -149,10 +137,6 @@ if ($_POST['submit']) {
$error = _("Unable to delete OU!"); $error = _("Unable to delete OU!");
} }
} }
else {
$error = _("OU is not empty!");
}
}
// do not delete ou // do not delete ou
elseif (($_POST['type'] == "del_grp") && ($_POST['abort'])) { elseif (($_POST['type'] == "del_grp") && ($_POST['abort'])) {
display_main(); display_main();
@ -161,9 +145,9 @@ if ($_POST['submit']) {
// ask if user is sure to delete // ask if user is sure to delete
elseif ($_POST['type'] == "del_grp") { elseif ($_POST['type'] == "del_grp") {
// check for sub entries // check for sub entries
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['groupsuff_d'], "ObjectClass=*", array("")); $sr = @ldap_list($_SESSION['ldap']->server(), $_POST['groupsuff_d'], "ObjectClass=*", array(""));
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr); $info = @ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($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['groupsuff_d'] . "</p>\n" . "<br>\n<p>" . $_POST['groupsuff_d'] . "</p>\n" .
@ -177,7 +161,7 @@ if ($_POST['submit']) {
"</form>"; "</form>";
} }
else { else {
$error = _("OU is not empty!"); $error = _("OU is not empty or invalid!");
} }
} }
@ -210,10 +194,6 @@ if ($_POST['submit']) {
} }
// delete ou, user was sure // delete ou, user was sure
elseif (($_POST['type'] == "del_hst") && ($_POST['sure'])) { elseif (($_POST['type'] == "del_hst") && ($_POST['sure'])) {
// check for sub entries
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['hostsuff_d'], "ObjectClass=*", array(""));
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($info['count'] == 0) {
$ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['hostsuff_d']); $ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['hostsuff_d']);
if ($ret) { if ($ret) {
$message = _("OU deleted successfully."); $message = _("OU deleted successfully.");
@ -222,10 +202,6 @@ if ($_POST['submit']) {
$error = _("Unable to delete OU!"); $error = _("Unable to delete OU!");
} }
} }
else {
$error = _("OU is not empty!");
}
}
// do not delete ou // do not delete ou
elseif (($_POST['type'] == "del_hst") && ($_POST['abort'])) { elseif (($_POST['type'] == "del_hst") && ($_POST['abort'])) {
display_main(); display_main();
@ -234,9 +210,9 @@ if ($_POST['submit']) {
// ask if user is sure to delete // ask if user is sure to delete
elseif ($_POST['type'] == "del_hst") { elseif ($_POST['type'] == "del_hst") {
// check for sub entries // check for sub entries
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['hostsuff_d'], "ObjectClass=*", array("")); $sr = @ldap_list($_SESSION['ldap']->server(), $_POST['hostsuff_d'], "ObjectClass=*", array(""));
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr); $info = @ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($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['hostsuff_d'] . "</p>\n" . "<br>\n<p>" . $_POST['hostsuff_d'] . "</p>\n" .
@ -250,7 +226,7 @@ if ($_POST['submit']) {
"</form>"; "</form>";
} }
else { else {
$error = _("OU is not empty!"); $error = _("OU is not empty or invalid!");
} }
} }