redirect to list after successful deletion

This commit is contained in:
Roland Gruber 2010-11-26 20:16:14 +00:00
parent 6e5f7757b6
commit 4f12264fb6
6 changed files with 75 additions and 20 deletions

View File

@ -10,6 +10,7 @@
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"><title>Upgrade notes</title>
@ -27,7 +28,11 @@ This is a list of API changes for all LAM releases.
<br>
<h2>3.1.0 -&gt; 3.2.0</h2><span style="font-weight: bold;">Account types: </span>The CSS classes have changed.
<h2>3.2.0 -&gt; 3.3.0</h2>The cache was removed. Please use local caching and the functions searchLDAP... instead of get_cache().<br>
The return values for baseModule::pre/postDeleteActions() was changed to an array of status message parameters.<br>
<br>
<h2>3.1.0 -&gt; 3.2.0</h2>
<span style="font-weight: bold;">Account types: </span>The CSS classes have changed.
<ul>
<li>tr.TYPElist-over: removed without replacement</li>

View File

@ -1058,22 +1058,22 @@ abstract class baseModule {
* Allows the module to run commands before the LDAP entry is deleted.
*
* Calling this method requires the existence of an enclosing {@link accountContainer}.<br>
* <br>
* An error message should be printed if the function returns false.
*
* @return boolean true, if no problems occured
* @return array Array which contains status messages. Each entry is an array containing the status message parameters.
*/
public function preDeleteActions() {
return true;
return array();
}
/**
* Allows the module to run commands after the LDAP entry is deleted.
*
* Calling this method requires the existence of an enclosing {@link accountContainer}.
*
* @return array Array which contains status messages. Each entry is an array containing the status message parameters.
*/
public function postDeleteActions() {
return;
return array();
}
/**

View File

@ -151,6 +151,8 @@ class lamList {
$this->listGetParams();
// print HTML head
$this->listPrintHeader();
// print messages when redirected from other pages
$this->listPrintRedirectMessages();
// refresh data if needed
if ($this->refresh) {
$this->listBuildFilter();
@ -924,6 +926,15 @@ class lamList {
return;
}
/**
* Prints messages when another page (e.g. delete/upload) redirects to the list view.
*/
protected function listPrintRedirectMessages() {
if (isset($_GET['deleteAllOk'])) {
StatusMessage('INFO', _('Deletion was successful.'));
}
}
}
/**
@ -1169,7 +1180,7 @@ class lamSelectListOption extends lamListOption {
$return->addElement(new htmlTableExtendedSelect($this->getID(), $this->options, array($this->getValue()), $this->name, $this->helpID));
return $return;
}
}
?>

View File

@ -591,12 +591,11 @@ class posixAccount extends baseModule implements passwordService {
/**
* Allows the module to run commands before the LDAP entry is deleted.
* An error message should be printed if the function returns false.
*
* @return true, if no problems occured
* @return array Array which contains status messages. Each entry is an array containing the status message parameters.
*/
function preDeleteActions() {
$return = true;
$return = array();
if (isset($_POST['deletehomedir'])) {
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
@ -624,7 +623,7 @@ class posixAccount extends baseModule implements passwordService {
$singleresult = explode(",", $singleresult);
if (is_array($singleresult)) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
call_user_func_array('StatusMessage', $singleresult);
$return[] = $singleresult;
}
}
}

View File

@ -271,9 +271,8 @@ class quota extends baseModule {
/**
* Allows the module to run commands before the LDAP entry is deleted.
* An error message should be printed if the function returns false.
*
* @return true, if no problems occured
* @return array Array which contains status messages. Each entry is an array containing the status message parameters.
*/
function preDeleteActions() {
$this->initQuotas();
@ -306,7 +305,7 @@ class quota extends baseModule {
}
lamdaemon(implode(quota::$SPLIT_DELIMITER, array($id, "quota", "set", $this->get_scope(), "$quotastring\n")), $server);
}
return true;
return array();
}
/**

View File

@ -123,6 +123,10 @@ if (isset($_POST['cancel'])) {
if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']);
metaRefresh("lists/list.php?type=" . $_POST['type']);
}
elseif (isset($_POST['cancelAllOk'])) {
if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']);
metaRefresh("lists/list.php?type=" . $_POST['type'] . '&amp;deleteAllOk=1');
}
if (isset($_POST['delete'])) {
// Show HTML Page
@ -133,6 +137,7 @@ if (isset($_POST['delete'])) {
echo "<br>\n";
// Delete dns
$allOk = true;
for ($m=0; $m<count($_SESSION['delete_dn']); $m++) {
// Set to true if an real error has happened
$stopprocessing = false;
@ -146,7 +151,18 @@ if (isset($_POST['delete'])) {
// predelete actions
if (!$stopprocessing) {
foreach ($moduleNames as $singlemodule) {
$success = $modules[$singlemodule]->preDeleteActions();
$success = true;
$messages = $modules[$singlemodule]->preDeleteActions();
for ($i = 0; $i < sizeof($messages); $i++) {
$errors[] = $messages[$i];
if ($messages[$i][0] == 'ERROR') {
$success = false;
$allOk = false;
}
elseif ($messages[$i][0] == 'WARN') {
$allOk = false;
}
}
if (!$success) {
$stopprocessing = true;
break;
@ -177,7 +193,10 @@ if (isset($_POST['delete'])) {
if (isset($attributes[$DNs[$i]]['errors'])) {
foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) {
$errors[] = $singleerror;
if ($singleerror[0] == 'ERROR') $stopprocessing = true;
if ($singleerror[0] == 'ERROR') {
$stopprocessing = true;
$allOk = false;
}
}
}
if (!$stopprocessing) {
@ -187,6 +206,7 @@ if (isset($_POST['delete'])) {
if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true;
$allOk = false;
}
}
// add attributes
@ -195,6 +215,7 @@ if (isset($_POST['delete'])) {
if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true;
$allOk = false;
}
}
// removce attributes
@ -203,6 +224,7 @@ if (isset($_POST['delete'])) {
if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true;
$allOk = false;
}
}
}
@ -210,34 +232,53 @@ if (isset($_POST['delete'])) {
}
if (!$stopprocessing) {
$errors = deleteDN($_SESSION['delete_dn'][$m]);
if (sizeof($errors) > 0) $stopprocessing = true;
if (sizeof($errors) > 0) {
$stopprocessing = true;
$allOk = false;
}
}
// post delete actions
if (!$stopprocessing) {
foreach ($moduleNames as $singlemodule) {
$modules[$singlemodule]->postDeleteActions();
$messages = $modules[$singlemodule]->postDeleteActions();
for ($i = 0; $i < sizeof($messages); $i++) {
$errors[] = $messages[$i];
if (($messages[$i][0] == 'ERROR') || ($messages[$i][0] == 'WARN')) {
$allOk = false;
}
}
}
}
if (!$stopprocessing) {
echo sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "<br>\n";
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
foreach ($errors as $error) {
call_user_func_array('StatusMessage', $error);
}
echo "<br>\n";
flush();
}
else {
echo sprintf(_('Error while deleting DN: %s'), $_SESSION['delete_dn'][$m]) . "<br>\n";
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
foreach ($errors as $error) {
call_user_func_array('StatusMessage', $error);
}
echo "<br>\n";
}
}
echo "<br>\n";
echo "<br><button class=\"smallPadding\" name=\"cancel\" id=\"backButton\">" . _('Back to list') . "</button>\n";
echo "<br><button class=\"hidden\" name=\"cancelAllOk\" id=\"backButtonAllOk\"> </button>\n";
echo "</div>\n";
echo "</form>\n";
?>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
jQuery('#backButton').button();
<?php
if ($allOk) {
echo "jQuery('#backButtonAllOk').click();";
}
?>
});
</script>
<?php