added preDeleteActions()

This commit is contained in:
Roland Gruber 2007-02-25 13:51:40 +00:00
parent f20325c0e0
commit 896c8f89d4
1 changed files with 59 additions and 47 deletions

View File

@ -140,59 +140,71 @@ if ($_POST['delete']) {
// First load DN. // First load DN.
$_SESSION['account']->load_account($_SESSION['delete_dn'][$m]); $_SESSION['account']->load_account($_SESSION['delete_dn'][$m]);
// get commands and changes of each attribute // get commands and changes of each attribute
$module = array_keys ($_SESSION['account']->module); $module = array_keys($_SESSION['account']->module);
$attributes = array(); $attributes = array();
$errors = array(); $errors = array();
// load attributes // predelete actions
foreach ($module as $singlemodule) { if (!$stopprocessing) {
// load changes foreach ($module as $singlemodule) {
$temp = $_SESSION['account']->module[$singlemodule]->delete_attributes(); $success = $_SESSION['account']->module[$singlemodule]->preDeleteActions();
if (is_array($temp)) { if (!$success) {
// merge changes $stopprocessing = true;
$DNs = array_keys($temp); break;
// *** fixme don't include references
$attributes = array_merge_recursive($temp, $attributes);
for ($i=0; $i<count($DNs); $i++) {
$ops = array_keys($temp[$DNs[$i]]);
for ($j=0; $j<count($ops); $j++) {
$attrs = array_keys($temp[$DNs[$i]][$ops[$j]]);
for ($k=0; $k<count($attrs); $k++)
$attributes[$DNs[$i]][$ops[$j]][$attrs[$k]] = array_unique($attributes[$DNs[$i]][$ops[$j]][$attrs[$k]]);
}
} }
} }
} }
$DNs = array_keys($attributes); if (!$stopprocessing) {
for ($i=0; $i<count($DNs); $i++) { // load attributes
if (isset($attributes[$DNs[$i]]['errors'])) { foreach ($module as $singlemodule) {
foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) { // load changes
$errors[] = $singleerror; $temp = $_SESSION['account']->module[$singlemodule]->delete_attributes();
if ($singleerror[0] == 'ERROR') $stopprocessing = true; if (is_array($temp)) {
// merge changes
$DNs = array_keys($temp);
// *** fixme don't include references
$attributes = array_merge_recursive($temp, $attributes);
for ($i=0; $i<count($DNs); $i++) {
$ops = array_keys($temp[$DNs[$i]]);
for ($j=0; $j<count($ops); $j++) {
$attrs = array_keys($temp[$DNs[$i]][$ops[$j]]);
for ($k=0; $k<count($attrs); $k++)
$attributes[$DNs[$i]][$ops[$j]][$attrs[$k]] = array_unique($attributes[$DNs[$i]][$ops[$j]][$attrs[$k]]);
}
}
} }
} }
if (!$stopprocessing) { $DNs = array_keys($attributes);
// modify attributes for ($i=0; $i<count($DNs); $i++) {
if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['errors'])) {
$success = @ldap_mod_replace($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']); foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) {
if (!$success) { $errors[] = $singleerror;
$errors[] = array ('ERROR', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server())); if ($singleerror[0] == 'ERROR') $stopprocessing = true;
$stopprocessing = true;
} }
} }
// add attributes if (!$stopprocessing) {
if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) { // modify attributes
$success = @ldap_mod_add($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['add']); if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) {
if (!$success) { $success = @ldap_mod_replace($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']);
$errors[] = array ('ERROR', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server())); if (!$success) {
$stopprocessing = true; $errors[] = array ('ERROR', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true;
}
} }
} // add attributes
// removce attributes if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) { $success = @ldap_mod_add($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['add']);
$success = @ldap_mod_del($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']); if (!$success) {
if (!$success) { $errors[] = array ('ERROR', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$errors[] = array ('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server())); $stopprocessing = true;
$stopprocessing = true; }
}
// removce attributes
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
$success = @ldap_mod_del($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']);
if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true;
}
} }
} }
} }
@ -201,10 +213,10 @@ if ($_POST['delete']) {
$errors = deleteDN($_SESSION['delete_dn'][$m]); $errors = deleteDN($_SESSION['delete_dn'][$m]);
if (sizeof($errors) > 0) $stopprocessing = true; if (sizeof($errors) > 0) $stopprocessing = true;
} }
// post delete actions
if (!$stopprocessing) { if (!$stopprocessing) {
// post delete actions
foreach ($module as $singlemodule) { foreach ($module as $singlemodule) {
$_SESSION['account']->module[$singlemodule]->postDeleteActions(); $_SESSION['account']->module[$singlemodule]->postDeleteActions();
} }
} }
if (!$stopprocessing) { if (!$stopprocessing) {