diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 408f4bfb..8c031b17 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -835,70 +835,86 @@ class accountContainer { */ function continue_main() { $result = array(); + $stopProcessing = false; // when set to true, no module options are displayed + $errorsOccured = false; + $this->loadProfileIfRequested(); if ($this->subpage=='') $this->subpage='attributes'; - if (isset($_POST['form_main_reset'])) { + if (isset($_POST['accountContainerReset'])) { $result = $this->load_account($this->dn_orig); } else { // change dn suffix + if (isset($_REQUEST['suffix']) && ($_REQUEST['suffix'] != '')) { + $this->dn = $_REQUEST['suffix']; + } if (isset($_REQUEST['accountContainerSuffix']) && ($_REQUEST['accountContainerSuffix'] != '')) { $this->dn = $_REQUEST['accountContainerSuffix']; } // change RDN - if (isset($_POST['accountContainerRDN'])) $this->rdn = $_POST['accountContainerRDN']; - if ($this->current_page==0) { - if ($this->subpage=='attributes') { - - // save account - if (isset($_POST['create'])) { - $errors = $this->save_account(); - if (sizeof($errors) > 0) { - $result = $errors; - $stopProcessing = true; + if (isset($_POST['accountContainerRDN'])) { + $this->rdn = $_POST['accountContainerRDN']; + } + // create another account + if (isset($_POST['accountContainerCreateAgain'])) { + // open fresh account page + unset($_SESSION[$this->base]); + metaRefresh("edit.php?type=" . $this->type); + exit(); + } + // back to account list + if (isset($_POST['accountContainerBackToList'])) { + // Return to account list + unset($_SESSION[$this->base]); + metaRefresh("../lists/list.php?type=" . $this->type); + exit; + } + // create PDF file + if (isset($_POST['accountContainerCreatePDF'])) { + // display PDf-file + createModulePDF(array($_SESSION[$this->base]), $_POST['pdfStructure']); + exit; + } + // module actions + if (sizeof($_POST) > 0) { + $result = call_user_func(array(&$this->module[$this->order[$this->current_page]], 'process_'.$this->subpage)); + if (is_array($result)) { // messages were returned, check for errors + for ($i = 0; $i < sizeof($result); $i++) { + if ($result[$i][0] == 'ERROR') { + $errorsOccured = true; + break; } - else $this->subpage = 'finish'; - } - } - if ($this->subpage=='finish') { - if (isset($_POST['createagain'])) { - // open fresh account page - unset($_SESSION[$this->base]); - metaRefresh("edit.php?type=" . $this->type); - exit(); - } - if (isset($_POST['backmain'])) { - // Return to account list - unset($_SESSION[$this->base]); - metaRefresh("../lists/list.php?type=" . $this->type); - exit; - } - if (isset($_POST['outputpdf'])) { - // Create / display PDf-file - createModulePDF(array($_SESSION[$this->base]), $_POST['pdfStructure']); - exit; } } } - else $result = call_user_func(array(&$this->module[$this->order[$this->current_page]], 'process_'.$this->subpage)); - // load profile - if (isset($_POST['accountContainerLoadProfile']) && isset($_POST['accountContainerSelectLoadProfile'])) { - $profile = loadAccountProfile($_POST['accountContainerSelectLoadProfile'], $this->type); - $this->lastLoadedProfile = $_POST['accountContainerSelectLoadProfile']; - // pass profile to each module + // save account + if (!$errorsOccured && isset($_POST['accountContainerSaveAccount'])) { + // check if all modules are complete $modules = array_keys($this->module); - foreach ($modules as $module) $this->module[$module]->load_profile($profile); - if (isset($profile['ldap_rdn'][0])) { - if (in_array($profile['ldap_rdn'][0], getRDNAttributes($this->type))) { - $this->rdn = $profile['ldap_rdn'][0]; + $incompleteModules = array(); + foreach ($modules as $module) { + if (!$this->module[$module]->module_complete()) { + $incompleteModules[] = $this->module[$module]->get_alias(); } } - if (isset($profile['ldap_suffix'][0])) { - $this->dn = $profile['ldap_suffix'][0]; + if (sizeof($incompleteModules) > 0) { + StatusMessage('INFO', _('Some required information is missing'), + sprintf(_('Please set up all required attributes on page: %s'), implode(", ", $incompleteModules))); + } + else { + // save account + $errors = $this->save_account(); + if (sizeof($errors) > 0) { + $result = $errors; + $stopProcessing = true; + } + else { + $this->printSuccessPage(); + return; + } } } } // change to next page - $errorsOccured = false; if (is_array($result)) { // messages were returned, check for errors for ($i = 0; $i < sizeof($result); $i++) { if ($result[$i][0] == 'ERROR') { @@ -919,69 +935,39 @@ class accountContainer { } } } - // change module page if requested - if (isset($_POST['form_main_main'])) { - $this->current_page = 0; - $this->subpage='attributes'; - } - else { - for ($i=1; $iorder); $i++ ) { - if (isset($_POST['form_main_'.$this->order[$i]])) { - if ($this->module[$this->order[$i]]->module_ready()) { - $this->current_page = $i; - $this->subpage='attributes'; - } - else { - StatusMessage('ERROR', _('The module %s is not yet ready.'), - _('Please enter the account information on the other pages first.'), - array($this->module[$this->order[$i]]->get_alias())); - } + for ($i=0; $iorder); $i++ ) { + if (isset($_POST['form_main_'.$this->order[$i]])) { + if ($this->module[$this->order[$i]]->module_ready()) { + $this->current_page = $i; + $this->subpage='attributes'; + } + else { + StatusMessage('ERROR', _('The module %s is not yet ready.'), + _('Please enter the account information on the other pages first.'), + array($this->module[$this->order[$i]]->get_alias())); } } } } - // Write HTML-Code - echo $_SESSION['header']; - echo "LDAP Account Manager\n"; - echo "\n"; - echo "type . ".css\">\n"; - echo "\n"; - echo "
\n"; + $this->printPageHeader(); // Display error-messages if (is_array($result)) { for ($i=0; $i\n"; echo "\n"; - return 0; - } - } - if ($this->current_page==0) { - if ($this->subpage=='attributes') { - $modules = array_keys($this->module); - $disabled = false; - $incompleteModules = array(); - foreach ($modules as $module) { - if (!$this->module[$module]->module_complete()) { - $disabled = true; - $incompleteModules[] = $this->module[$module]->get_alias(); - } - } - if (sizeof($incompleteModules) > 0) { - StatusMessage('INFO', _('Some required information is missing'), - sprintf(_('Please set up all required attributes on page: %s'), implode(", ", $incompleteModules))); - } + return; } } echo "type."list\" style=\"border-width:0px;\" width=\"100%\">"; echo ""; echo "'; $x++; } - echo "
"; + // save button + echo " \n"; // reset button if ($this->dn_orig!='') { - echo "subpage == 'finish') echo " disabled"; - echo ">\n"; + echo "\n"; } echo ""; @@ -1009,32 +995,121 @@ class accountContainer { // create module menu echo "type."list\" border=0 width=\"100%\" style=\"border-collapse: collapse;\">\n"; echo "type."list\" valign=\"top\">\n"; + // content header + echo "type . "list\">\n"; + echo "\n"; + echo "\n"; + echo "type . "list\">\n"; + // content area + echo "
"; - + // tab menu + $this->printModuleTabs(); + echo "
\n"; + $this->printContentHeader(); + echo "
"; + // display html-code from modules + $return = array(); + + $return = call_user_func(array($this->module[$this->order[$this->current_page]], 'display_html_'.$this->subpage)); + + $y = 5000; + $z = 10000; + parseHtml($this->order[$this->current_page], $return, array(), false, $y, $z, $this->type); + // Display rest of html-page + echo "
*" . _('required'); + echo "
\n"; + $this->printPageFooter(); + } + + /** + * Prints the header of the account pages. + */ + private function printPageHeader() { + echo $_SESSION['header']; + echo "LDAP Account Manager\n"; + echo "\n"; + echo "type . ".css\">\n"; + echo "\n"; + echo "\n"; + } + + /** + * Prints the footer of the account pages. + */ + private function printPageFooter() { + echo "\n"; + echo "\n"; + echo "\n"; + } + + /** + * Prints the HTML code to notify the user about the successful saving. + * + */ + private function printSuccessPage() { + $pdfStructures = getPDFStructureDefinitions($this->type); + $this->printPageHeader(); + // Show success message + if ($this->dn_orig == '') { + $text = _("Account was created successfully."); + } + else { + $text = _("Account was modified successfully."); + } + StatusMessage('INFO', _('LDAP operation successful.'), $text); + + echo "
\n"; + + echo " \n"; + echo " \n"; + echo "    "; + echo "\n"; + echo "\n"; + echo "\""\n"; + $this->printPageFooter(); + } + + /** + * Checks if the user requested to load a profile. + */ + private function loadProfileIfRequested() { + if (isset($_POST['accountContainerLoadProfile']) && isset($_POST['accountContainerSelectLoadProfile'])) { + $profile = loadAccountProfile($_POST['accountContainerSelectLoadProfile'], $this->type); + $this->lastLoadedProfile = $_POST['accountContainerSelectLoadProfile']; + // pass profile to each module + $modules = array_keys($this->module); + foreach ($modules as $module) $this->module[$module]->load_profile($profile); + if (isset($profile['ldap_rdn'][0])) { + if (in_array($profile['ldap_rdn'][0], getRDNAttributes($this->type))) { + $this->rdn = $profile['ldap_rdn'][0]; + } + } + if (isset($profile['ldap_suffix'][0])) { + $this->dn = $profile['ldap_suffix'][0]; + } + } + } + + /** + * Prints the HTML code of the module tabs. + */ + private function printModuleTabs() { // calculate button width - $buttonWidth = round(0.8 * strlen(utf8_decode(_("Main")))) + 2; - for ($b = 1; $b < sizeof($this->order); $b++) { + $buttonWidth = 0; + for ($b = 0; $b < sizeof($this->order); $b++) { $tempWidth = round(0.8 * strlen(utf8_decode($this->module[$this->order[$b]]->get_alias()))) + 2; if ($buttonWidth < $tempWidth) $buttonWidth = $tempWidth; } + // $x is used to count up tabindex $x=0; echo ""; - // print "main" button - $class = $this->type . "list-head"; - if ($this->order[$this->current_page] == "main") $class = $this->type . "list-edit"; - echo "\n"; - $x++; + echo "\n"; // Loop for module - // $x is used to count up tabindex - for ($i=1; $iorder); $i++ ) { + for ($i=0; $iorder); $i++ ) { $buttonStatus = $this->module[$this->order[$i]]->getButtonStatus(); // skip hidden buttons if ($buttonStatus == 'hidden') continue; @@ -1056,71 +1131,13 @@ class accountContainer { echo "order[$i]."\" type=\"submit\" value=\""; echo $buttonSpace . $this->module[$this->order[$i]]->get_alias(); echo "\" tabindex=$x"; - if (($buttonStatus == 'disabled') || $this->subpage == 'finish') echo " disabled"; + if ($buttonStatus == 'disabled') echo " disabled"; echo ">\n"; echo "
"; - echo "\n"; - echo "
\n"; - echo "subpage == 'finish') echo " disabled"; - echo ">\n"; - echo "
\n"; - echo "
\n"; echo '
 
\n"; - // content header - echo "type . "list\">\n"; - echo "\n"; - $this->printContentHeader(); - echo "\n"; - echo "\n"; - echo "type . "list\">\n"; - // content area - echo ""; - // display html-code from modules - $return = array(); - 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' => 'backmain', 'value' => _('Back to account list'))); - $return[] = array(0 => array('kind' => 'text', 'text' => ' ')); // empty line - $return[] = array(0 => array('kind' => 'text', 'text' => ' ')); // empty line - $pdfStructures = getPDFStructureDefinitions($this->type); - $return[] = array( - 0 => array('kind' => 'fieldset', 'legend' => 'PDF', 'td' => array('colspan' => 2), 'value' => array(array( - 0 => array('kind' => 'select', 'name' => 'pdfStructure', 'options' => $pdfStructures), - 1 => array('kind' => 'input', 'type' => 'submit', 'name' => 'outputpdf', 'value' => _('Create PDF file')), - 2 => array('kind' => 'help', 'value' => '403')) - ))); - } - else { - $return[] = array(0 => array('kind' => 'text', 'text' => ' ')); // empty line - if ($this->dn_orig!='') $text = _('Modify account'); - else $text = _('Create account'); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => $text ), - 1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'create', 'value' => $text, 'disabled' => $disabled), - 2 => array ('kind' => 'help', 'value' => '402')); - } - } - else $return = call_user_func(array($this->module[$this->order[$this->current_page]], 'display_html_'.$this->subpage)); - $y = 5000; - $z = 10000; - parseHtml($this->order[$this->current_page], $return, array(), false, $y, $z, $this->type); - // Display rest of html-page - if ($this->current_page != "main") echo "
*" . _('required'); - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - return 0; + echo " \n"; } /** @@ -1629,7 +1646,6 @@ class accountContainer { if (sizeof($depModules) > 0) { for ($i = 0; $i < sizeof($depModules); $i++) $order[] = $depModules[$i]; } - array_unshift($order, 'main'); $this->order = $order; }