better error handling

This commit is contained in:
Roland Gruber 2005-05-10 16:51:32 +00:00
parent 200e7e6c1a
commit eb71557f54
1 changed files with 87 additions and 67 deletions

View File

@ -782,9 +782,11 @@ class accountContainer {
// save account // save account
if ($post['create']) { if ($post['create']) {
$errors = $this->save_account(); $errors = $this->save_account();
if (is_array($errors)) $result = array($errors); if (is_array($errors)) {
// return name of subpage $result = array($errors);
$result = 'finish'; $stopProcessing = true;
}
else $result = 'finish';
} }
} }
if ($this->subpage=='finish') { if ($this->subpage=='finish') {
@ -853,10 +855,18 @@ class accountContainer {
echo "</head><body>\n"; echo "</head><body>\n";
echo "<form action=\"edit.php\" method=\"post\">\n"; echo "<form action=\"edit.php\" method=\"post\">\n";
// Display error-messages // Display error-messages
if (is_array($result)) if (is_array($result)) {
foreach ($result as $result2) foreach ($result as $result2) {
if (is_array($result2)) if (is_array($result2)) {
for ($i=0; $i<sizeof($result2); $i++) StatusMessage($result2[$i][0], $result2[$i][1], $result2[$i][2]); for ($i=0; $i<sizeof($result2); $i++) StatusMessage($result2[$i][0], $result2[$i][1], $result2[$i][2]);
}
}
if (isset($stopProcessing) && ($stopProcessing == true)) {
echo "</body>\n";
echo "</html>\n";
return 0;
}
}
if ($this->current_page==0) { if ($this->current_page==0) {
if ($this->subpage=='attributes') { if ($this->subpage=='attributes') {
$modules = array_keys($this->module); $modules = array_keys($this->module);
@ -886,7 +896,9 @@ class accountContainer {
// print normal button // print normal button
echo "<input name=\"form_main_main\" type=\"submit\" value=\""; echo "<input name=\"form_main_main\" type=\"submit\" value=\"";
echo _('Main'); echo _('Main');
echo "\" tabindex=$x>\n<br>"; echo "\" tabindex=$x";
if ($this->subpage == 'finish') echo " disabled";
echo ">\n<br>";
$x++; $x++;
// Loop for module // Loop for module
// $x is used to count up tabindex // $x is used to count up tabindex
@ -894,10 +906,16 @@ class accountContainer {
// print normal button // print normal button
echo "<input name=\"form_main_".$this->order[$i]."\" type=\"submit\" value=\""; echo "<input name=\"form_main_".$this->order[$i]."\" type=\"submit\" value=\"";
echo $this->module[$this->order[$i]]->get_alias(); echo $this->module[$this->order[$i]]->get_alias();
echo "\" tabindex=$x>\n<br>"; echo "\" tabindex=$x";
if ($this->subpage == 'finish') echo " disabled";
echo ">\n<br>";
$x++; $x++;
} }
if ($this->dn_orig!='') echo "<input name=\"form_main_reset\" type=\"submit\" value=\"" . _('Reset changes') . "\"><br>\n"; if ($this->dn_orig!='') {
echo "<input name=\"form_main_reset\" type=\"submit\" value=\"" . _('Reset changes') . "\"";
if ($this->subpage == 'finish') echo " disabled";
echo "><br>\n";
}
echo "</fieldset></td></tr>\n"; echo "</fieldset></td></tr>\n";
echo "</table></td>\n<td>"; echo "</table></td>\n<td>";
if ($this->current_page==0) { if ($this->current_page==0) {
@ -913,6 +931,25 @@ class accountContainer {
// display html-code from mdule // display html-code from mdule
$return = array(); $return = array();
if ($this->current_page == 0) { if ($this->current_page == 0) {
if ($this->subpage == 'finish') {
// Show success message
if ($this->dn_orig == '') {
$text = _("Account was created successfully.");
}
else {
$text = _("Account was modified successfully.");
}
$return[] = array(
0 => array('kind' => 'message', 'type' => 'INFO', 'headline' => _('LDAP operation successful.'), 'text' => $text,
'td' => array('colspan' => 3)));
$return[] = array(
0 => array('kind' => 'text', 'text' => '', 'td' => array('colspan' => 3)));
$return[] = array(
0 => array('kind' => 'input', 'type' => 'submit', 'name' => 'createagain', 'value' => _('Create another account')),
1 => array('kind' => 'input', 'type' => 'submit', 'name' => 'outputpdf', 'value' => _('Create PDF file') ),
2 => array('kind' => 'input', 'type' => 'submit', 'name' => 'backmain', 'value' => _('Back to account list')));
}
else {
// loop through all suffixes // loop through all suffixes
$rootsuffix = $_SESSION['config']->get_Suffix($this->type); $rootsuffix = $_SESSION['config']->get_Suffix($this->type);
foreach ($_SESSION['ldap']->search_units($rootsuffix) as $suffix) { foreach ($_SESSION['ldap']->search_units($rootsuffix) as $suffix) {
@ -954,23 +991,6 @@ class accountContainer {
$return[] = array ( 0 => array ( 'kind' => 'text', 'text' => $text ), $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => $text ),
1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'create', 'value' => $text, 'disabled' => $disabled), 1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'create', 'value' => $text, 'disabled' => $disabled),
2 => array ('kind' => 'help', 'value' => 'create')); 2 => array ('kind' => 'help', 'value' => 'create'));
if ($this->subpage=='finish') {
// Show success message
if ($this->dn_orig == '') {
$text = _("Account was created successfully.");
}
else {
$text = _("Account was modified successfully.");
}
$return[] = array ( 0 => array ( 'kind' => 'message', 'type' => 'INFO', 'headline' => _('LDAP operation successful.'),
'text' => $text ));
$return[] = array ( 0 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'createagain',
'value' => _('Create another account')),
1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'outputpdf',
'value' => _('Create PDF file') ),
2 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'backmain',
'value' => _('Back to account list')));
} }
} }
else $return = call_user_func(array($this->module[$this->order[$this->current_page]], 'display_html_'.$this->subpage), $post); else $return = call_user_func(array($this->module[$this->order[$this->current_page]], 'display_html_'.$this->subpage), $post);
@ -1480,14 +1500,14 @@ class accountContainer {
$_SESSION['cache']->update_cache($this->$dn, 'add', $attr); $_SESSION['cache']->update_cache($this->$dn, 'add', $attr);
$success = ldap_delete($_SESSION['ldap']->server(), $this->dn_orig); $success = ldap_delete($_SESSION['ldap']->server(), $this->dn_orig);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to delete DN: %s.'), $this->dn_orig)); $errors[] = array('ERROR', sprintf(_('Was unable to delete DN: %s.'), $this->dn_orig), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true; $stopprocessing = true;
} }
if ($success) if ($success)
$_SESSION['cache']->update_cache($this->$dn, 'delete_dn'); $_SESSION['cache']->update_cache($this->$dn, 'delete_dn');
} }
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to create DN: %s.'), $this->dn)); $errors[] = array('ERROR', sprintf(_('Was unable to create DN: %s.'), $this->dn), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true; $stopprocessing = true;
} }
} }
@ -1496,7 +1516,7 @@ class accountContainer {
$attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']); $attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']);
$success = ldap_add($_SESSION['ldap']->server(), $this->dn, $attr); $success = ldap_add($_SESSION['ldap']->server(), $this->dn, $attr);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to create DN: %s.'), $this->dn)); $errors[] = array('ERROR', sprintf(_('Was unable to create DN: %s.'), $this->dn), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true; $stopprocessing = true;
} }
else else
@ -1512,7 +1532,7 @@ class accountContainer {
if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) {
$success = @ldap_mod_replace($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']); $success = @ldap_mod_replace($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i])); $errors[] = array('ERROR', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true; $stopprocessing = true;
} }
else else
@ -1522,7 +1542,7 @@ class accountContainer {
if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
$success = @ldap_mod_add($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['add']); $success = @ldap_mod_add($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['add']);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i])); $errors[] = array('ERROR', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true; $stopprocessing = true;
} }
else else
@ -1532,7 +1552,7 @@ class accountContainer {
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
$success = @ldap_mod_del($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']); $success = @ldap_mod_del($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i])); $errors[] = array('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
$stopprocessing = true; $stopprocessing = true;
} }
else else