| 1 |
<?php |
| 2 |
|
| 3 |
namespace LAM\CONFIG; |
| 4 |
|
| 5 |
use htmlJavaScript; |
| 6 |
use LAM\TYPES\TypeManager; |
| 7 |
use LAMConfig; |
| 8 |
use moduleCache; |
| 9 |
use htmlSpacer; |
| 10 |
use htmlTable; |
| 11 |
use htmlButton; |
| 12 |
use htmlResponsiveRow; |
| 13 |
use htmlSubTitle; |
| 14 |
|
| 15 |
/* |
| 16 |
|
| 17 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 18 |
Copyright (C) 2009 - 2026 Roland Gruber |
| 19 |
|
| 20 |
This program is free software; you can redistribute it and/or modify |
| 21 |
it under the terms of the GNU General Public License as published by |
| 22 |
the Free Software Foundation; either version 2 of the License, or |
| 23 |
(at your option) any later version. |
| 24 |
|
| 25 |
This program is distributed in the hope that it will be useful, |
| 26 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 |
GNU General Public License for more details. |
| 29 |
|
| 30 |
You should have received a copy of the GNU General Public License |
| 31 |
along with this program; if not, write to the Free Software |
| 32 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 33 |
|
| 34 |
*/ |
| 35 |
|
| 36 |
|
| 37 |
/** |
| 38 |
* Here the user can edit the module settings. |
| 39 |
* |
| 40 |
* @package configuration |
| 41 |
* @author Roland Gruber |
| 42 |
*/ |
| 43 |
|
| 44 |
|
| 45 |
/** Access to config functions */ |
| 46 |
include_once(__DIR__ . '/../../lib/config.inc'); |
| 47 |
/** Access to account types */ |
| 48 |
include_once(__DIR__ . '/../../lib/types.inc'); |
| 49 |
/** common functions */ |
| 50 |
include_once __DIR__ . '/../../lib/configPages.inc'; |
| 51 |
|
| 52 |
// start session |
| 53 |
if (isFileBasedSession()) { |
| 54 |
session_save_path("../../sess"); |
| 55 |
} |
| 56 |
lam_start_session(); |
| 57 |
|
| 58 |
setlanguage(); |
| 59 |
|
| 60 |
// check if config is set |
| 61 |
// if not: load login page |
| 62 |
if (!isset($_SESSION['conf_config'])) { |
| 63 |
/** go back to login if password is invalid */ |
| 64 |
require(__DIR__ . '/conflogin.php'); |
| 65 |
exit; |
| 66 |
} |
| 67 |
|
| 68 |
// check if user canceled editing |
| 69 |
if (isset($_POST['cancelSettings'])) { |
| 70 |
metaRefresh("../login.php"); |
| 71 |
exit; |
| 72 |
} |
| 73 |
|
| 74 |
$conf = &$_SESSION['conf_config']; |
| 75 |
if (!($conf instanceof LAMConfig)) { |
| 76 |
die(); |
| 77 |
} |
| 78 |
|
| 79 |
$errorsToDisplay = checkInput(); |
| 80 |
|
| 81 |
// check if button was pressed and if we have to save the settings or go to another tab |
| 82 |
if ((isset($_POST['saveSettings']) || isset($_POST['editmodules']) |
| 83 |
|| isset($_POST['edittypes']) || isset($_POST['generalSettingsButton']) |
| 84 |
|| isset($_POST['moduleSettings']) || isset($_POST['jobs'])) |
| 85 |
&& (count($errorsToDisplay) === 0)) { |
| 86 |
// go to final page |
| 87 |
if (isset($_POST['saveSettings'])) { |
| 88 |
metaRefresh("confsave.php"); |
| 89 |
exit; |
| 90 |
} |
| 91 |
// go to types page |
| 92 |
elseif (isset($_POST['edittypes'])) { |
| 93 |
metaRefresh("conftypes.php"); |
| 94 |
exit; |
| 95 |
} |
| 96 |
// go to modules page |
| 97 |
elseif (isset($_POST['editmodules'])) { |
| 98 |
metaRefresh("confmodules.php"); |
| 99 |
exit; |
| 100 |
} |
| 101 |
// go to the types page |
| 102 |
elseif (isset($_POST['generalSettingsButton'])) { |
| 103 |
metaRefresh("confmain.php"); |
| 104 |
exit; |
| 105 |
} |
| 106 |
// go to the jobs page |
| 107 |
elseif (isset($_POST['jobs'])) { |
| 108 |
metaRefresh("jobs.php"); |
| 109 |
exit; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
echo $_SESSION['header']; |
| 114 |
printHeaderContents(_("LDAP Account Manager Configuration"), '../..'); |
| 115 |
echo "</head><body>\n"; |
| 116 |
printJsIncludes('../..'); |
| 117 |
printConfigurationPageHeaderBar($conf); |
| 118 |
|
| 119 |
// print error messages |
| 120 |
foreach ($errorsToDisplay as $errorToDisplay) { |
| 121 |
call_user_func_array(StatusMessage(...), $errorToDisplay); |
| 122 |
} |
| 123 |
|
| 124 |
echo "<form id=\"inputForm\" action=\"moduleSettings.php\" method=\"post\" autocomplete=\"off\" onSubmit=\"window.lam.utility.saveScrollPosition('inputForm')\" novalidate=\"novalidate\">\n"; |
| 125 |
|
| 126 |
printConfigurationPageTabs(ConfigurationPageTab::MODULE_SETTINGS); |
| 127 |
|
| 128 |
?> |
| 129 |
<input type="text" name="hiddenPreventAutocomplete" autocomplete="false" class="hidden" value=""> |
| 130 |
<input type="password" name="hiddenPreventAutocompletePwd1" autocomplete="false" class="hidden" value="123"> |
| 131 |
<input type="password" name="hiddenPreventAutocompletePwd2" autocomplete="false" class="hidden" value="321"> |
| 132 |
<?php |
| 133 |
|
| 134 |
|
| 135 |
// module settings |
| 136 |
$typeManager = new TypeManager($conf); |
| 137 |
$types = $typeManager->getConfiguredTypes(); |
| 138 |
|
| 139 |
// get the list of module scopes |
| 140 |
$scopes = []; |
| 141 |
foreach ($types as $type) { |
| 142 |
$moduleNames = $conf->get_AccountModules($type->getId()); |
| 143 |
foreach ($moduleNames as $moduleName) { |
| 144 |
$scopes[$moduleName][] = $type->getId(); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
// get module options |
| 149 |
$options = getConfigOptions($scopes); |
| 150 |
// get current setting |
| 151 |
$old_options = $conf->get_moduleSettings(); |
| 152 |
|
| 153 |
|
| 154 |
// display module boxes |
| 155 |
$moduleNames = array_keys($options); |
| 156 |
$_SESSION['conf_types'] = []; |
| 157 |
foreach ($moduleNames as $moduleName) { |
| 158 |
if (empty($options[$moduleName])) { |
| 159 |
continue; |
| 160 |
} |
| 161 |
$module = moduleCache::getModule($moduleName, null); |
| 162 |
if ($module === null) { |
| 163 |
continue; |
| 164 |
} |
| 165 |
$iconImage = $module->getIcon(); |
| 166 |
if (($iconImage != null) && !(str_starts_with($iconImage, 'http')) && !(str_starts_with($iconImage, '/'))) { |
| 167 |
$iconImage = '../../graphics/' . $iconImage; |
| 168 |
} |
| 169 |
$row = new htmlResponsiveRow(); |
| 170 |
$row->add(new htmlSubTitle($module->get_alias(), $iconImage, null, true)); |
| 171 |
if (is_array($options[$moduleName])) { |
| 172 |
foreach ($options[$moduleName] as $option) { |
| 173 |
$row->add($option); |
| 174 |
} |
| 175 |
} |
| 176 |
else { |
| 177 |
$row->add($options[$moduleName]); |
| 178 |
} |
| 179 |
$configTypes = parseHtml($moduleName, $row, $old_options, false, null); |
| 180 |
$_SESSION['conf_types'] = array_merge($configTypes, $_SESSION['conf_types']); |
| 181 |
echo "<br>"; |
| 182 |
} |
| 183 |
|
| 184 |
echo "<input type=\"hidden\" name=\"postAvailable\" value=\"yes\">\n"; |
| 185 |
|
| 186 |
echo "</div></div>"; |
| 187 |
|
| 188 |
$buttonContainer = new htmlTable(); |
| 189 |
$buttonContainer->addElement(new htmlSpacer(null, '10px'), true); |
| 190 |
$saveButton = new htmlButton('saveSettings', _('Save')); |
| 191 |
$saveButton->setCSSClasses(['lam-primary']); |
| 192 |
$buttonContainer->addElement($saveButton); |
| 193 |
$cancelButton = new htmlButton('cancelSettings', _('Cancel')); |
| 194 |
$buttonContainer->addElement($cancelButton, true); |
| 195 |
$buttonContainer->addElement(new htmlSpacer(null, '10px'), true); |
| 196 |
|
| 197 |
if (empty($errorsToDisplay) && isset($_POST['scrollPositionTop']) && get_preg($_POST['scrollPositionTop'], 'digit') |
| 198 |
&& isset($_POST['scrollPositionLeft']) && get_preg($_POST['scrollPositionLeft'], 'digit')) { |
| 199 |
// scroll to last position |
| 200 |
$buttonContainer->addElement(new htmlJavaScript('window.lam.utility.restoreScrollPosition(' . $_POST['scrollPositionTop'] . ', ' . $_POST['scrollPositionLeft'] . ')')); |
| 201 |
} |
| 202 |
|
| 203 |
parseHtml(null, $buttonContainer, [], false, null); |
| 204 |
|
| 205 |
echo "</form>\n"; |
| 206 |
echo "</body>\n"; |
| 207 |
echo "</html>\n"; |
| 208 |
|
| 209 |
|
| 210 |
/** |
| 211 |
* Checks user input and saves the entered settings. |
| 212 |
* |
| 213 |
* @return array<string[]> list of errors |
| 214 |
*/ |
| 215 |
function checkInput(): array { |
| 216 |
if (!isset($_POST['postAvailable'])) { |
| 217 |
return []; |
| 218 |
} |
| 219 |
$conf = &$_SESSION['conf_config']; |
| 220 |
if (!($conf instanceof LAMConfig)) { |
| 221 |
return []; |
| 222 |
} |
| 223 |
$typeManager = new TypeManager($conf); |
| 224 |
$types = $typeManager->getConfiguredTypes(); |
| 225 |
|
| 226 |
// check module options |
| 227 |
// create the option array to check and save |
| 228 |
$options = extractConfigOptionsFromPOST($_SESSION['conf_types']); |
| 229 |
|
| 230 |
// get the list of the modules' scopes |
| 231 |
$scopes = []; |
| 232 |
foreach ($types as $type) { |
| 233 |
$moduleNames = $conf->get_AccountModules($type->getId()); |
| 234 |
foreach ($moduleNames as $moduleName) { |
| 235 |
$scopes[$moduleName][] = $type->getId(); |
| 236 |
} |
| 237 |
} |
| 238 |
// check options |
| 239 |
$errors = checkConfigOptions($scopes, $options); |
| 240 |
$conf->set_moduleSettings($options); |
| 241 |
return $errors; |
| 242 |
} |