refactoring

This commit is contained in:
Roland Gruber 2018-01-07 17:44:50 +01:00
parent c370ab7e09
commit 12cf9e61da
1 changed files with 41 additions and 37 deletions

View File

@ -22,7 +22,7 @@ use \moduleCache;
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2004 - 2017 Roland Gruber Copyright (C) 2004 - 2018 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -119,18 +119,18 @@ if (isset($_POST['type'])) {
// get selected modules // get selected modules
$selectedModules = array(); $selectedModules = array();
$checkedBoxes = array_keys($_POST, 'on'); $checkedBoxes = array_keys($_POST, 'on');
for ($i = 0; $i < sizeof($checkedBoxes); $i++) { foreach ($checkedBoxes as $checkedBox) {
if (strpos($checkedBoxes[$i], $typeId . '___') === 0) { if (strpos($checkedBox, $typeId . '___') === 0) {
$selectedModules[] = substr($checkedBoxes[$i], strlen($typeId) + strlen('___')); $selectedModules[] = substr($checkedBox, strlen($typeId) + strlen('___'));
} }
} }
$deps = getModulesDependencies($type->getScope()); $deps = getModulesDependencies($type->getScope());
$depErrors = check_module_depends($selectedModules, $deps); $depErrors = check_module_depends($selectedModules, $deps);
if (is_array($depErrors) && (sizeof($depErrors) > 0)) { if (is_array($depErrors) && (sizeof($depErrors) > 0)) {
for ($i = 0; $i < sizeof($depErrors); $i++) { foreach ($depErrors as $depError) {
StatusMessage('ERROR', _("Unsolved dependency:") . ' ' . StatusMessage('ERROR', _("Unsolved dependency:") . ' ' .
getModuleAlias($depErrors[$i][0], $type->getScope()) . " (" . getModuleAlias($depError[0], $type->getScope()) . " (" .
getModuleAlias($depErrors[$i][1], $type->getScope()) . ")"); getModuleAlias($depError[1], $type->getScope()) . ")");
} }
} }
else { else {
@ -191,25 +191,25 @@ foreach ($types as $type) {
} }
$innerTable = new htmlTable(); $innerTable = new htmlTable();
$modules = $_SESSION['config']->get_AccountModules($type->getId()); $modules = $_SESSION['config']->get_AccountModules($type->getId());
for ($m = 0; $m < sizeof($modules); $m++) { foreach ($modules as $m => $moduleName) {
if (($m != 0) && ($m%3 == 0)) { if (($m != 0) && ($m%3 == 0)) {
echo $innerTable->addNewLine(); echo $innerTable->addNewLine();
} }
$module = moduleCache::getModule($modules[$m], $type->getScope()); $module = moduleCache::getModule($moduleName, $type->getScope());
$iconImage = $module->getIcon(); $iconImage = $module->getIcon();
if (!is_null($iconImage) && !(strpos($iconImage, 'http') === 0) && !(strpos($iconImage, '/') === 0)) { if (!is_null($iconImage) && !(strpos($iconImage, 'http') === 0) && !(strpos($iconImage, '/') === 0)) {
$iconImage = '../../graphics/' . $iconImage; $iconImage = '../../graphics/' . $iconImage;
} }
$innerTable->addElement(new htmlImage($iconImage)); $innerTable->addElement(new htmlImage($iconImage));
$enabled = true; $enabled = true;
if (is_base_module($modules[$m], $type->getScope())) { if (is_base_module($moduleName, $type->getScope())) {
$enabled = false; $enabled = false;
} }
$checked = true; $checked = true;
if (isset($_POST['submit']) && !isset($_POST[$type->getId() . '___' . $modules[$m]])) { if (isset($_POST['submit']) && !isset($_POST[$type->getId() . '___' . $moduleName])) {
$checked = false; $checked = false;
} }
$checkbox = new htmlTableExtendedInputCheckbox($type->getId() . '___' . $modules[$m], $checked, getModuleAlias($modules[$m], $type->getScope()), null, false); $checkbox = new htmlTableExtendedInputCheckbox($type->getId() . '___' . $moduleName, $checked, getModuleAlias($moduleName, $type->getScope()), null, false);
$checkbox->setIsEnabled($enabled); $checkbox->setIsEnabled($enabled);
if ($enabled) { if ($enabled) {
$innerTable->addElement($checkbox); $innerTable->addElement($checkbox);
@ -218,7 +218,7 @@ foreach ($types as $type) {
$boxGroup = new htmlGroup(); $boxGroup = new htmlGroup();
$boxGroup->addElement($checkbox); $boxGroup->addElement($checkbox);
// add hidden field to fake disabled checkbox value // add hidden field to fake disabled checkbox value
$boxGroup->addElement(new htmlHiddenInput($type->getId() . '___' . $modules[$m], 'on')); $boxGroup->addElement(new htmlHiddenInput($type->getId() . '___' . $moduleName, 'on'));
$innerTable->addElement($boxGroup); $innerTable->addElement($boxGroup);
} }
$innerTable->addElement(new htmlSpacer('10px', null)); $innerTable->addElement(new htmlSpacer('10px', null));
@ -380,18 +380,18 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
$dnRDNRow->setCSSClasses(array($scope . '-bright')); $dnRDNRow->setCSSClasses(array($scope . '-bright'));
$columnContainer->addElement($dnRDNRow); $columnContainer->addElement($dnRDNRow);
// module options // module options
for ($m = 0; $m < sizeof($modules); $m++) { foreach ($modules as $moduleName) {
// skip modules without upload columns // skip modules without upload columns
if (sizeof($columns[$modules[$m]]) < 1) { if (sizeof($columns[$moduleName]) < 1) {
continue; continue;
} }
$columnContainer->addElement(new htmlSpacer(null, '10px'), true); $columnContainer->addElement(new htmlSpacer(null, '10px'), true);
$module = moduleCache::getModule($modules[$m], $scope); $module = moduleCache::getModule($moduleName, $scope);
$icon = $module->getIcon(); $icon = $module->getIcon();
if (!empty($icon) && !(strpos($icon, 'http') === 0) && !(strpos($icon, '/') === 0)) { if (!empty($icon) && !(strpos($icon, 'http') === 0) && !(strpos($icon, '/') === 0)) {
$icon = '../../graphics/' . $icon; $icon = '../../graphics/' . $icon;
} }
$moduleTitle = new htmlSubTitle(getModuleAlias($modules[$m], $scope), $icon); $moduleTitle = new htmlSubTitle(getModuleAlias($moduleName, $scope), $icon);
$moduleTitle->colspan = 20; $moduleTitle->colspan = 20;
$columnContainer->addElement($moduleTitle, true); $columnContainer->addElement($moduleTitle, true);
$columnContainer->addElement(new htmlOutputText('')); $columnContainer->addElement(new htmlOutputText(''));
@ -417,37 +417,37 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
$possibleOut->alignment = htmlElement::ALIGN_LEFT; $possibleOut->alignment = htmlElement::ALIGN_LEFT;
$columnContainer->addElement($possibleOut, false, true); $columnContainer->addElement($possibleOut, false, true);
$odd = true; $odd = true;
for ($i = 0; $i < sizeof($columns[$modules[$m]]); $i++) { foreach ($columns[$moduleName] as $column) {
$required = false; $required = false;
if (isset($columns[$modules[$m]][$i]['required']) && ($columns[$modules[$m]][$i]['required'] === true)) { if (isset($column['required']) && ($column['required'] === true)) {
$required = true; $required = true;
} }
$rowCells = array(); $rowCells = array();
$rowCells[] = $columnSpacer; $rowCells[] = $columnSpacer;
$rowCells[] = new htmlHelpLink($columns[$modules[$m]][$i]['help'], $modules[$m], $scope); $rowCells[] = new htmlHelpLink($column['help'], $moduleName, $scope);
$rowCells[] = $columnSpacer; $rowCells[] = $columnSpacer;
$descriptionText = new htmlOutputText($columns[$modules[$m]][$i]['description']); $descriptionText = new htmlOutputText($column['description']);
$descriptionText->setMarkAsRequired($required); $descriptionText->setMarkAsRequired($required);
$descriptionText->setNoWrap(true); $descriptionText->setNoWrap(true);
$rowCells[] = $descriptionText; $rowCells[] = $descriptionText;
$rowCells[] = $columnSpacer; $rowCells[] = $columnSpacer;
$rowCells[] = new htmlOutputText($columns[$modules[$m]][$i]['name']); $rowCells[] = new htmlOutputText($column['name']);
$rowCells[] = $columnSpacer; $rowCells[] = $columnSpacer;
$example = ''; $example = '';
if (isset($columns[$modules[$m]][$i]['example'])) { if (isset($column['example'])) {
$example = $columns[$modules[$m]][$i]['example']; $example = $column['example'];
} }
$rowCells[] = new htmlOutputText($example); $rowCells[] = new htmlOutputText($example);
$rowCells[] = $columnSpacer; $rowCells[] = $columnSpacer;
if (isset($columns[$modules[$m]][$i]['default'])) { if (isset($column['default'])) {
$rowCells[] = new htmlOutputText($columns[$modules[$m]][$i]['default']); $rowCells[] = new htmlOutputText($column['default']);
} }
else { else {
$rowCells[] = new htmlOutputText(''); $rowCells[] = new htmlOutputText('');
} }
$rowCells[] = $columnSpacer; $rowCells[] = $columnSpacer;
if (isset($columns[$modules[$m]][$i]['values'])) { if (isset($column['values'])) {
$rowCells[] = new htmlOutputText($columns[$modules[$m]][$i]['values']); $rowCells[] = new htmlOutputText($column['values']);
} }
else { else {
$rowCells[] = new htmlOutputText(''); $rowCells[] = new htmlOutputText('');
@ -479,10 +479,12 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
$sampleCSV_head[] = "\"dn_suffix\""; $sampleCSV_head[] = "\"dn_suffix\"";
$sampleCSV_head[] = "\"dn_rdn\""; $sampleCSV_head[] = "\"dn_rdn\"";
// module attributes // module attributes
for ($m = 0; $m < sizeof($modules); $m++) { foreach ($modules as $moduleName) {
if (sizeof($columns[$modules[$m]]) < 1) continue; if (sizeof($columns[$moduleName]) < 1) {
for ($i = 0; $i < sizeof($columns[$modules[$m]]); $i++) { continue;
$sampleCSV_head[] = "\"" . $columns[$modules[$m]][$i]['name'] . "\""; }
for ($i = 0; $i < sizeof($columns[$moduleName]); $i++) {
$sampleCSV_head[] = "\"" . $columns[$moduleName][$i]['name'] . "\"";
} }
} }
$RDNs = getRDNAttributes($type->getId(), $selectedModules); $RDNs = getRDNAttributes($type->getId(), $selectedModules);
@ -490,11 +492,13 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
$sampleCSV_row[] = "\"" . $type->getSuffix() . "\""; $sampleCSV_row[] = "\"" . $type->getSuffix() . "\"";
$sampleCSV_row[] = "\"" . $RDNs[0] . "\""; $sampleCSV_row[] = "\"" . $RDNs[0] . "\"";
// module attributes // module attributes
for ($m = 0; $m < sizeof($modules); $m++) { foreach ($modules as $moduleName) {
if (sizeof($columns[$modules[$m]]) < 1) continue; if (sizeof($columns[$moduleName]) < 1) {
for ($i = 0; $i < sizeof($columns[$modules[$m]]); $i++) { continue;
if (isset($columns[$modules[$m]][$i]['example'])) { }
$sampleCSV_row[] = '"' . $columns[$modules[$m]][$i]['example'] . '"'; foreach ($columns[$moduleName] as $column) {
if (isset($column['example'])) {
$sampleCSV_row[] = '"' . $column['example'] . '"';
} }
else { else {
$sampleCSV_row[] = '""'; $sampleCSV_row[] = '""';