From 9c69712a7daaf1ef7b82d229c1a6e1c6ccbeb0e5 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 12 Jul 2009 13:40:32 +0000 Subject: [PATCH] tabs --- lam/templates/config/confmain.php | 82 ++++------ lam/templates/config/conftypes.php | 250 +++++++++++++++++------------ 2 files changed, 185 insertions(+), 147 deletions(-) diff --git a/lam/templates/config/confmain.php b/lam/templates/config/confmain.php index 2e64a370..e1c188f3 100644 --- a/lam/templates/config/confmain.php +++ b/lam/templates/config/confmain.php @@ -76,44 +76,37 @@ if ((!isset($_SESSION['conf_isAuthenticated']) || !($_SESSION['conf_isAuthentica } $_SESSION['conf_isAuthenticated'] = $conf->getName(); -// check if button was pressed and if we have to save the setting or go back to login -if (isset($_POST['cancelSettings']) || isset($_POST['saveSettings']) || isset($_POST['editmodules']) || isset($_POST['edittypes'])){ - // go to final page - if (isset($_POST['saveSettings'])){ - saveSettings(); - } - // go to modules page - elseif (isset($_POST['editmodules'])){ - metaRefresh("confmodules.php"); - exit; - } - // go to types page - elseif (isset($_POST['edittypes'])){ - metaRefresh("conftypes.php"); - exit; - } - // back to login - else if (isset($_POST['cancelSettings'])){ - metaRefresh("../login.php"); - exit; +// check if user canceled editing +if (isset($_POST['cancelSettings'])) { + metaRefresh("../login.php"); + exit; +} + +$errorsToDisplay = array(); + +// check if button was pressed and if we have to save the settings or go to another tab +if (isset($_POST['saveSettings']) || isset($_POST['editmodules']) || isset($_POST['edittypes']) || isset($_POST['generalSettingsButton'])) { + $errorsToDisplay = checkInput(); + if (sizeof($errorsToDisplay) == 0) { + // go to final page + if (isset($_POST['saveSettings'])) { + metaRefresh("confsave.php"); + exit; + } + // go to modules page + elseif (isset($_POST['editmodules'])) { + metaRefresh("confmodules.php"); + exit; + } + // go to types page + elseif (isset($_POST['edittypes'])) { + metaRefresh("conftypes.php"); + exit; + } } } -// check if user comes from types page -if (isset($_GET["typesback"])) { - // check if a new account type was added - if (isset($_GET["typeschanged"])) { - metaRefresh("confmodules.php"); - exit; - } -} - -// type information -if (!isset($_SESSION['conf_accountTypes'])) $_SESSION['conf_accountTypes'] = $conf->get_ActiveTypes(); -if (!isset($_SESSION['conf_accountTypesOld'])) $_SESSION['conf_accountTypesOld'] = $conf->get_ActiveTypes(); -if (!isset($_SESSION['conf_typeSettings'])) $_SESSION['conf_typeSettings'] = $conf->get_typeSettings(); - // index for tab order $tabindex = 1; @@ -135,9 +128,9 @@ if (!$conf->isWritable()) { } // display error messages -if (isset($_SESSION['conf_errors'])) { - for ($i = 0; $i < sizeof($_SESSION['conf_errors']); $i++) { - call_user_func_array('StatusMessage', $_SESSION['conf_errors'][$i]); +if (sizeof($errorsToDisplay) > 0) { + for ($i = 0; $i < sizeof($errorsToDisplay); $i++) { + call_user_func_array('StatusMessage', $errorsToDisplay[$i]); } echo "
"; } @@ -542,10 +535,11 @@ echo ("\n"); /** - * Saves the entered settings. + * Checks user input and saves the entered settings. * + * @return array list of errors */ -function saveSettings() { +function checkInput() { $conf = &$_SESSION['conf_config']; $types = $conf->get_ActiveTypes(); @@ -658,15 +652,7 @@ function saveSettings() { // check options $errors = array_merge($errors, checkConfigOptions($scopes, $options)); $conf->set_moduleSettings($options); - // print error messages if any - if (sizeof($errors) > 0) { - $_SESSION['conf_errors'] = $errors; - } - // save settings if no errors occured - else { - metaRefresh("confsave.php"); - exit; - } + return $errors; } ?> diff --git a/lam/templates/config/conftypes.php b/lam/templates/config/conftypes.php index cd3659ca..7001cc04 100644 --- a/lam/templates/config/conftypes.php +++ b/lam/templates/config/conftypes.php @@ -51,101 +51,41 @@ if (!isset($_SESSION['conf_config'])) { exit; } -$conf = &$_SESSION['conf_config']; - -// update type settings -if (isset($_POST['postAvailable'])) { - $postKeys = array_keys($_POST); - for ($i = 0; $i < sizeof($postKeys); $i++) { - $key = $postKeys[$i]; - if (substr($key, 0, 7) == "suffix_") { - $_SESSION['conf_typeSettings'][$key] = $_POST[$key]; - } - elseif (substr($key, 0, 5) == "attr_") { - $_SESSION['conf_typeSettings'][$key] = $_POST[$key]; - } - } -} - -$errors = array(); -// user pressed submit/abort button -if (isset($_POST['submit'])) { - // check settings - $allOK = true; - $postKeys = array_keys($_POST); - for ($i = 0; $i < sizeof($postKeys); $i++) { - $key = $postKeys[$i]; - if (substr($key, 0, 7) == "suffix_") { - $type = substr($postKeys[$i], 7); - if (strlen($_POST[$key]) < 1) { - $errors[] = array("ERROR", _("LDAP Suffix is invalid!"), getTypeAlias($type)); - $allOK = false; - } - } - elseif (substr($key, 0, 5) == "attr_") { - $type = substr($postKeys[$i], 5); - if (!is_string($_POST[$key]) || !eregi("^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$", $_POST[$key])) { - $errors[] = array("ERROR", _("List attributes are invalid!"), getTypeAlias($type)); - $allOK = false; - } - } - } - //selection ok, back to other settings - if ($allOK) { - // check if there is a new type - $addedType = false; - for ($i = 0; $i < sizeof($_SESSION['conf_accountTypes']); $i++) { - if (!in_array($_SESSION['conf_accountTypes'][$i], $_SESSION['conf_accountTypesOld'])) { - $addedType = true; - break; - } - } - $_SESSION['conf_accountTypesOld'] = $_SESSION['conf_accountTypes']; - $conf->set_ActiveTypes($_SESSION['conf_accountTypes']); - $conf->set_typeSettings($_SESSION['conf_typeSettings']); - if ($addedType) { - metarefresh('confmain.php?typesback=true&typeschanged=true'); - } - else { - metarefresh('confmain.php?typesback=true'); - } - exit; - } -} -// no changes -elseif (isset($_POST['abort'])) { - $_SESSION['conf_accountTypes'] = $_SESSION['conf_accountTypesOld']; - metarefresh('confmain.php?typesback=true'); +// check if user canceled editing +if (isset($_POST['cancelSettings'])) { + metaRefresh("../login.php"); exit; } -// check if remove button was pressed -$postKeys = array_keys($_POST); -for ($i = 0; $i < sizeof($postKeys); $i++) { - $key = $postKeys[$i]; - if (substr($key, 0, 4) == "rem_") { - $type = substr($key, 4); - $_SESSION['conf_accountTypes'] = array_flip($_SESSION['conf_accountTypes']); - unset($_SESSION['conf_accountTypes'][$type]); - $_SESSION['conf_accountTypes'] = array_flip($_SESSION['conf_accountTypes']); - $_SESSION['conf_accountTypes'] = array_values($_SESSION['conf_accountTypes']); +$conf = &$_SESSION['conf_config']; + +$errorsToDisplay = checkInput(); + +// check if button was pressed and if we have to save the settings or go to another tab +if (isset($_POST['saveSettings']) || isset($_POST['editmodules']) || isset($_POST['edittypes']) || isset($_POST['generalSettingsButton'])) { + if (sizeof($errorsToDisplay) == 0) { + // go to final page + if (isset($_POST['saveSettings'])) { + metaRefresh("confsave.php"); + exit; + } + // go to modules page + elseif (isset($_POST['editmodules'])) { + metaRefresh("confmodules.php"); + exit; + } + // go to types page + elseif (isset($_POST['generalSettingsButton'])) { + metaRefresh("confmain.php"); + exit; + } } } -// check if add button was pressed -$postKeys = array_keys($_POST); -for ($i = 0; $i < sizeof($postKeys); $i++) { - $key = $postKeys[$i]; - if (substr($key, 0, 4) == "add_") { - $type = substr($key, 4); - $_SESSION['conf_accountTypes'][] = $type; - } -} - - +$typeSettings = $conf->get_typeSettings(); // get active and available types $allTypes = getTypes(); -$activeTypes = $_SESSION['conf_accountTypes']; +$activeTypes = $conf->get_ActiveTypes(); $availableTypes = array(); for ($i = 0; $i < sizeof($allTypes); $i++) { if (!in_array($allTypes[$i], $activeTypes)) $availableTypes[] = $allTypes[$i]; @@ -163,13 +103,80 @@ echo "\n"; echo "\n"; echo ("

". - "\"LDAP



\n"); + "\"LDAP


\n

 

\n"); // print error messages -for ($i = 0; $i < sizeof($errors); $i++) call_user_func_array('StatusMessage', $errors[$i]); +for ($i = 0; $i < sizeof($errorsToDisplay); $i++) call_user_func_array('StatusMessage', $errorsToDisplay[$i]); echo ("
\n"); -echo "

" . _("Account type selection") . "

"; +echo "\n"; +echo "\n"; + +echo "\n"; echo "\n"; - echo "\n"; + echo "\n"; echo "\n"; echo "\n"; // list attributes - if (isset($_SESSION['conf_typeSettings']['attr_' . $activeTypes[$i]])) { - $attributes = $_SESSION['conf_typeSettings']['attr_' . $activeTypes[$i]]; + if (isset($typeSettings['attr_' . $activeTypes[$i]])) { + $attributes = $typeSettings['attr_' . $activeTypes[$i]]; } else { $attributes = getDefaultListAttributes($activeTypes[$i]); @@ -232,20 +239,65 @@ if (sizeof($activeTypes) > 0) { echo "



\n"; } -// submit and abort button -echo "

"; -echo "\n"; -echo "\n"; echo "\n"; -echo "

"; echo "



\n"; +echo '
"; +// show tabs +echo ""; +echo "\n"; + $buttonWidth = 0; + $buttonTexts = array(_('General settings'), _('Account types'), _('Modules'), _('Save'), _('Cancel')); + for ($b = 0; $b < sizeof($buttonTexts); $b++) { + $tempWidth = round(0.8 * strlen(utf8_decode($buttonTexts[$b]))) + 2; + if ($buttonWidth < $tempWidth) $buttonWidth = $tempWidth; + } + $buttonSpace = '       '; + // general settings + echo "'; + // account types + echo "'; + // module selection + echo "'; + echo ""; + // save button + echo "'; + // cancel button + echo "'; + echo "
\n"; + echo "\n"; + echo "
\n"; + $buttonStyle = 'background-image: url(../../graphics/bigTools.png);width:' . $buttonWidth . 'em;'; + echo "\n"; + echo "
\n"; + echo '
\n"; + echo "\n"; + echo "
\n"; + $buttonStyle = 'background-image: url(../../graphics/gear.png);width:' . $buttonWidth . 'em;'; + echo "\n"; + echo "
\n"; + echo '
\n"; + echo "\n"; + echo "
\n"; + $buttonStyle = 'background-image: url(../../graphics/modules.png);width:' . $buttonWidth . 'em;'; + echo "\n"; + echo "
\n"; + echo '
 \n"; + echo "\n"; + echo "
\n"; + $buttonStyle = 'background-image: url(../../graphics/pass.png);width:' . $buttonWidth . 'em;'; + echo "\n"; + echo "
\n"; + echo '
\n"; + echo "\n"; + echo "
\n"; + $buttonStyle = 'background-image: url(../../graphics/fail.png);width:' . $buttonWidth . 'em;'; + echo "\n"; + echo "
\n"; + echo '
\n"; +// end tabs +echo "


\n"; // show available types if (sizeof($availableTypes) > 0) { @@ -201,14 +208,14 @@ if (sizeof($activeTypes) > 0) { // LDAP suffix echo "
" . _("LDAP suffix") . ""; printHelpLink(getHelp('', '202'), '202'); echo "
'; echo "
\n"; echo "\n"; echo "\n"; - +/** + * Checks user input and saves the entered settings. + * + * @return array list of errors + */ +function checkInput() { + if (!isset($_POST['postAvailable'])) { + return array(); + } + $errors = array(); + $conf = &$_SESSION['conf_config']; + $typeSettings = $conf->get_typeSettings(); + $accountTypes = $conf->get_ActiveTypes(); + $postKeys = array_keys($_POST); + for ($i = 0; $i < sizeof($postKeys); $i++) { + $key = $postKeys[$i]; + // check if remove button was pressed + if (substr($key, 0, 4) == "rem_") { + $type = substr($key, 4); + $accountTypes = array_flip($accountTypes); + unset($accountTypes[$type]); + $accountTypes = array_flip($accountTypes); + $accountTypes = array_values($accountTypes); + } + // check if add button was pressed + else if (substr($key, 0, 4) == "add_") { + $type = substr($key, 4); + $accountTypes[] = $type; + } + // set suffixes + elseif (substr($key, 0, 7) == "suffix_") { + $typeSettings[$key] = $_POST[$key]; + $type = substr($postKeys[$i], 7); + if (strlen($_POST[$key]) < 1) { + $errors[] = array("ERROR", _("LDAP Suffix is invalid!"), getTypeAlias($type)); + } + } + elseif (substr($key, 0, 5) == "attr_") { + $typeSettings[$key] = $_POST[$key]; + $type = substr($postKeys[$i], 5); + if (!is_string($_POST[$key]) || !eregi("^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$", $_POST[$key])) { + $errors[] = array("ERROR", _("List attributes are invalid!"), getTypeAlias($type)); + } + } + } + // save input + $conf->set_typeSettings($typeSettings); + $conf->set_ActiveTypes($accountTypes); + return $errors; +} ?>