Merge pull request #15 from LDAPAccountManager/type_api_tmp

Type api tmp
This commit is contained in:
gruberroland 2016-12-28 20:01:14 +01:00 committed by GitHub
commit c8b1dfe35b
6 changed files with 214 additions and 132 deletions

View File

@ -34,7 +34,7 @@ $Id$
* @package types * @package types
*/ */
class baseType { class baseType {
/** label to create another account */ /** label to create another account */
public $LABEL_CREATE_ANOTHER_ACCOUNT; public $LABEL_CREATE_ANOTHER_ACCOUNT;
/** label to return to account list */ /** label to return to account list */
@ -47,7 +47,7 @@ class baseType {
$this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another account'); $this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another account');
$this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to account list'); $this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to account list');
} }
/** /**
* Returns the alias name of this account type. * Returns the alias name of this account type.
* This function must be overwritten by the child classes. * This function must be overwritten by the child classes.
@ -57,7 +57,7 @@ class baseType {
public function getAlias() { public function getAlias() {
return "baseType"; return "baseType";
} }
/** /**
* Returns the description of this account type. * Returns the description of this account type.
* This function must be overwritten by the child classes. * This function must be overwritten by the child classes.
@ -67,7 +67,7 @@ class baseType {
public function getDescription() { public function getDescription() {
return "base type"; return "base type";
} }
/** /**
* Returns the class name for the list object. * Returns the class name for the list object.
* *
@ -76,7 +76,7 @@ class baseType {
public function getListClassName() { public function getListClassName() {
return "lamList"; return "lamList";
} }
/** /**
* Returns the default attribute list for this account type. * Returns the default attribute list for this account type.
* This function must be overwritten by the child classes. * This function must be overwritten by the child classes.
@ -96,7 +96,7 @@ class baseType {
public function getListAttributeDescriptions() { public function getListAttributeDescriptions() {
return array(); return array();
} }
/** /**
* Returns if entries of this type may be created via file upload. * Returns if entries of this type may be created via file upload.
* *
@ -105,7 +105,7 @@ class baseType {
public function supportsFileUpload() { public function supportsFileUpload() {
return true; return true;
} }
/** /**
* Returns the the title text for the title bar on the new/edit page. * Returns the the title text for the title bar on the new/edit page.
* *
@ -128,10 +128,10 @@ class baseType {
public function getTitleBarSubtitle($container) { public function getTitleBarSubtitle($container) {
return null; return null;
} }
/** /**
* Returns a list of LDAP suffixes for this type. * Returns a list of LDAP suffixes for this type.
* *
* @return array sorted list of possible suffixes for this type. * @return array sorted list of possible suffixes for this type.
*/ */
public function getSuffixList() { public function getSuffixList() {
@ -175,25 +175,25 @@ class baseType {
usort($ret, 'compareDN'); usort($ret, 'compareDN');
return $ret; return $ret;
} }
/** /**
* This function is called after the edit page is processed and before the page content is generated. * This function is called after the edit page is processed and before the page content is generated.
* This can be used to run custom handlers after each page processing. * This can be used to run custom handlers after each page processing.
* *
* @param accountContainer $container account container * @param accountContainer $container account container
*/ */
public function runEditPagePostAction(&$container) { public function runEditPagePostAction(&$container) {
} }
/** /**
* Returns a list of configuration options. * Returns a list of configuration options.
* *
* The field names are used as keywords to load and save settings. * The field names are used as keywords to load and save settings.
* We recommend to use the type name as prefix for them (e.g. user_someSetting) to avoid naming conflicts. * We recommend to use the type name as prefix for them (e.g. user_someSetting) to avoid naming conflicts.
* *
* @return mixed htmlElement or array of htmlElement * @return mixed htmlElement or array of htmlElement
* *
* @see htmlElement * @see htmlElement
*/ */
public function get_configOptions() { public function get_configOptions() {
@ -212,7 +212,11 @@ class baseType {
public function check_configOptions(&$options) { public function check_configOptions(&$options) {
return array(); return array();
} }
public function supportsMultipleConfigs() {
return false;
}
} }
?> ?>

View File

@ -660,17 +660,17 @@ class LAMConfig {
$allTypes = LAM\TYPES\getTypes(); $allTypes = LAM\TYPES\getTypes();
$activeTypes = $this->get_ActiveTypes(); $activeTypes = $this->get_ActiveTypes();
for ($i = 0; $i < sizeof($activeTypes); $i++) { for ($i = 0; $i < sizeof($activeTypes); $i++) {
if (!in_array($activeTypes[$i], $allTypes)) { if (!in_array(\LAM\TYPES\getScopeFromTypeId($activeTypes[$i]), $allTypes)) {
unset($activeTypes[$i]); unset($activeTypes[$i]);
} }
} }
$activeTypes = array_values($activeTypes); $activeTypes = array_values($activeTypes);
$this->set_ActiveTypes($activeTypes); $this->set_ActiveTypes($activeTypes);
// check modules // check modules
$scopes = $this->get_ActiveTypes(); $types = $this->get_ActiveTypes();
for ($s = 0; $s < sizeof($scopes); $s++) { foreach ($types as $type) {
$scope = $scopes[$s]; $scope = \LAM\TYPES\getScopeFromTypeId($type);
$moduleVar = "modules_" . $scope; $moduleVar = "modules_" . $type;
if (isset($this->typeSettings[$moduleVar])){ if (isset($this->typeSettings[$moduleVar])){
$modules = explode(",", $this->typeSettings[$moduleVar]); $modules = explode(",", $this->typeSettings[$moduleVar]);
$available = getAvailableModules($scope); $available = getAvailableModules($scope);

View File

@ -73,16 +73,21 @@ function getTypes() {
* Returns the alias name of an account type. * Returns the alias name of an account type.
* *
* @param string $type type name * @param string $type type name
* @param \LAMConfig $config config (optional, uses $_SESSION['config'] by default)
* @return string type alias * @return string type alias
*/ */
function getTypeAlias($type) { function getTypeAlias($type, $config = null) {
if (!empty($_SESSION['config'])) { if (($config == null) && !empty($_SESSION['config'])) {
$typeSettings = $_SESSION['config']->get_typeSettings(); $config = $_SESSION['config'];
}
if ($config != null) {
$typeSettings = $config->get_typeSettings();
if (!empty($typeSettings['customLabel_' . $type])) { if (!empty($typeSettings['customLabel_' . $type])) {
return $typeSettings['customLabel_' . $type]; return $typeSettings['customLabel_' . $type];
} }
} }
$obj = new $type(); $scope = getScopeFromTypeId($type);
$obj = new $scope();
return $obj->getAlias(); return $obj->getAlias();
} }
@ -132,6 +137,17 @@ function getListAttributeDescriptions($type) {
return $obj->getListAttributeDescriptions(); return $obj->getListAttributeDescriptions();
} }
/**
* Returns the account type for a given type id.
*
* @param string $typeId type id (e.g. user_1)
* @return string scope (e.g. user)
*/
function getScopeFromTypeId($typeId) {
$parts = explode('_', $typeId);
return $parts[0];
}
/** /**
* Represents a configured account type variant. * Represents a configured account type variant.
* *
@ -244,7 +260,7 @@ class ConfiguredType {
/** /**
* Returns the base type of this configured type. * Returns the base type of this configured type.
* *
* @return baseType base type * @return \baseType base type
*/ */
public function getBaseType() { public function getBaseType() {
if ($this->baseType != null) { if ($this->baseType != null) {
@ -330,6 +346,20 @@ class ListAttribute {
*/ */
class TypeManager { class TypeManager {
private $config;
/**
* Constructor
*
* @param \LAMConfig $config configuration (uses $_SESSION['config'] by default)
*/
public function __construct(&$config = null) {
if ($config == null) {
$config = &$_SESSION['config'];
}
$this->config = &$config;
}
/** /**
* Returns the configured type with the given id or null. * Returns the configured type with the given id or null.
* *
@ -338,7 +368,7 @@ class TypeManager {
*/ */
public function getConfiguredType($typeId) { public function getConfiguredType($typeId) {
$configuredTypes = array(); $configuredTypes = array();
$activeTypes = $_SESSION['config']->get_ActiveTypes(); $activeTypes = $this->config->get_ActiveTypes();
if (in_array($typeId, $activeTypes)) { if (in_array($typeId, $activeTypes)) {
return $this->buildConfiguredType($typeId); return $this->buildConfiguredType($typeId);
} }
@ -352,7 +382,7 @@ class TypeManager {
*/ */
public function getConfiguredTypes() { public function getConfiguredTypes() {
$configuredTypes = array(); $configuredTypes = array();
$activeTypes = $_SESSION['config']->get_ActiveTypes(); $activeTypes = $this->config->get_ActiveTypes();
foreach ($activeTypes as $typeId) { foreach ($activeTypes as $typeId) {
$configuredTypes[] = $this->buildConfiguredType($typeId); $configuredTypes[] = $this->buildConfiguredType($typeId);
} }
@ -365,12 +395,11 @@ class TypeManager {
* @param string $typeId type id * @param string $typeId type id
*/ */
private function buildConfiguredType($typeId) { private function buildConfiguredType($typeId) {
$parts = explode('_', $typeId); $scope = getScopeFromTypeId($typeId);
$scope = $parts[0]; $suffix = $this->config->get_Suffix($typeId);
$suffix = $_SESSION['config']->get_Suffix($typeId);
$attributes = $this->getAttributes($typeId, $scope); $attributes = $this->getAttributes($typeId, $scope);
$alias = getTypeAlias($typeId); $alias = getTypeAlias($typeId, $this->config);
$ldapFilter = $_SESSION['config']->get_Suffix($typeId); $ldapFilter = $this->config->get_Suffix($typeId);
$hidden = isAccountTypeHidden($typeId); $hidden = isAccountTypeHidden($typeId);
return new ConfiguredType($scope, $typeId, $suffix, $attributes, $alias, $ldapFilter, $hidden); return new ConfiguredType($scope, $typeId, $suffix, $attributes, $alias, $ldapFilter, $hidden);
} }
@ -383,7 +412,7 @@ class TypeManager {
* @return \LAM\TYPES\ListAttribute[] list attributes * @return \LAM\TYPES\ListAttribute[] list attributes
*/ */
private function getAttributes($typeId, $scope) { private function getAttributes($typeId, $scope) {
$attributeString = $_SESSION['config']->get_listAttributes($typeId); $attributeString = $this->config->get_listAttributes($typeId);
$attributeSpecs = explode(';', $attributeString); $attributeSpecs = explode(';', $attributeString);
$attributes = array(); $attributes = array();
foreach ($attributeSpecs as $attributeSpec) { foreach ($attributeSpecs as $attributeSpec) {
@ -392,6 +421,23 @@ class TypeManager {
return $attributes; return $attributes;
} }
/**
* Generates a new unique type id for the given scope.
*
* @param string $scope account type (e.g. user)
*/
public function generateNewTypeId($scope) {
$activeTypes = $this->config->get_ActiveTypes();
if (!in_array($scope, $activeTypes)) {
return $scope;
}
$counter = 1;
while (in_array($scope . '_' . $counter, $activeTypes)) {
$counter++;
}
return $scope . '_' . $counter;
}
} }
?> ?>

View File

@ -1,4 +1,16 @@
<?php <?php
namespace LAM\CONFIG;
use \htmlTable;
use \htmlOutputText;
use \htmlHelpLink;
use \htmlHiddenInput;
use \htmlButton;
use \htmlSpacer;
use \htmlElement;
use \htmlImage;
use \htmlSortableList;
use \htmlSubTitle;
use \htmlDiv;
/* /*
$Id$ $Id$
@ -95,8 +107,6 @@ if (isset($_POST['saveSettings']) || isset($_POST['editmodules'])
} }
} }
$types = $conf->get_ActiveTypes();
echo $_SESSION['header']; echo $_SESSION['header'];
echo "<title>" . _("LDAP Account Manager Configuration") . "</title>\n"; echo "<title>" . _("LDAP Account Manager Configuration") . "</title>\n";
@ -209,15 +219,12 @@ jQuery(document).ready(function() {
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom user-bright"> <div class="ui-tabs-panel ui-widget-content ui-corner-bottom user-bright">
<?php <?php
$typeManager = new \LAM\TYPES\TypeManager($conf);
$account_list = array(); $types = $typeManager->getConfiguredTypes();
for ($i = 0; $i < sizeof($types); $i++) {
$account_list[] = array($types[$i], LAM\TYPES\getTypeAlias($types[$i]));
}
$container = new htmlTable(); $container = new htmlTable();
for ($i = 0; $i < sizeof($account_list); $i++) { foreach ($types as $type) {
config_showAccountModules($account_list[$i][0], $account_list[$i][1], $container); config_showAccountModules($type, $container);
} }
$legendContainer = new htmlTable(); $legendContainer = new htmlTable();
@ -260,20 +267,19 @@ echo "</html>\n";
/** /**
* Displays the module selection boxes and checks if dependencies are fulfilled. * Displays the module selection boxes and checks if dependencies are fulfilled.
* *
* @param string $scope account type * @param \LAM\TYPES\ConfiguredType $type account type
* @param string $title title for module selection (e.g. "User modules")
* @param htmlTable $container meta HTML container * @param htmlTable $container meta HTML container
*/ */
function config_showAccountModules($scope, $title, &$container) { function config_showAccountModules($type, &$container) {
$conf = &$_SESSION['conf_config']; $conf = &$_SESSION['conf_config'];
$typeSettings = $conf->get_typeSettings(); $typeSettings = $conf->get_typeSettings();
// account modules // account modules
$available = getAvailableModules($scope, true); $available = getAvailableModules($type->getScope(), true);
$selected = !empty($typeSettings['modules_' . $scope]) ? $typeSettings['modules_' . $scope] : ''; $selected = !empty($typeSettings['modules_' . $type->getId()]) ? $typeSettings['modules_' . $type->getId()] : '';
$selected = explode(',', $selected); $selected = explode(',', $selected);
$sortedAvailable = array(); $sortedAvailable = array();
for ($i = 0; $i < sizeof($available); $i++) { for ($i = 0; $i < sizeof($available); $i++) {
$sortedAvailable[$available[$i]] = getModuleAlias($available[$i], $scope); $sortedAvailable[$available[$i]] = getModuleAlias($available[$i], $type->getScope());
} }
natcasesort($sortedAvailable); natcasesort($sortedAvailable);
@ -281,18 +287,18 @@ function config_showAccountModules($scope, $title, &$container) {
$selOptions = array(); $selOptions = array();
for ($i = 0; $i < sizeof($selected); $i++) { for ($i = 0; $i < sizeof($selected); $i++) {
if (in_array($selected[$i], $available)) { // selected modules must be available if (in_array($selected[$i], $available)) { // selected modules must be available
if (is_base_module($selected[$i], $scope)) { // mark base modules if (is_base_module($selected[$i], $type->getScope())) { // mark base modules
$selOptions[getModuleAlias($selected[$i], $scope) . " (" . $selected[$i] . ")(*)"] = $selected[$i]; $selOptions[getModuleAlias($selected[$i], $type->getScope()) . " (" . $selected[$i] . ")(*)"] = $selected[$i];
} }
else { else {
$selOptions[getModuleAlias($selected[$i], $scope) . " (" . $selected[$i] . ")"] = $selected[$i]; $selOptions[getModuleAlias($selected[$i], $type->getScope()) . " (" . $selected[$i] . ")"] = $selected[$i];
} }
} }
} }
$availOptions = array(); $availOptions = array();
foreach ($sortedAvailable as $key => $value) { foreach ($sortedAvailable as $key => $value) {
if (! in_array($key, $selected)) { // display non-selected modules if (! in_array($key, $selected)) { // display non-selected modules
if (is_base_module($key, $scope)) { // mark base modules if (is_base_module($key, $type->getScope())) { // mark base modules
$availOptions[$value . " (" . $key . ")(*)"] = $key; $availOptions[$value . " (" . $key . ")(*)"] = $key;
} }
else { else {
@ -302,7 +308,7 @@ function config_showAccountModules($scope, $title, &$container) {
} }
// add account module selection // add account module selection
$container->addElement(new htmlSubTitle($title, '../../graphics/' . $scope . '.png'), true); $container->addElement(new htmlSubTitle($type->getAlias(), '../../graphics/' . $type->getScope() . '.png'), true);
$container->addElement(new htmlOutputText(_("Selected modules"))); $container->addElement(new htmlOutputText(_("Selected modules")));
$container->addElement(new htmlOutputText('')); $container->addElement(new htmlOutputText(''));
$container->addElement(new htmlOutputText(_("Available modules")), true); $container->addElement(new htmlOutputText(_("Available modules")), true);
@ -313,17 +319,17 @@ function config_showAccountModules($scope, $title, &$container) {
$listElements = array(); $listElements = array();
foreach ($selOptions as $key => $value) { foreach ($selOptions as $key => $value) {
$el = new htmlTable('100%'); $el = new htmlTable('100%');
$mod = new $value($scope); $mod = new $value($type->getScope());
$el->addElement(new htmlImage('../../graphics/' . $mod->getIcon(), '16px', '16px')); $el->addElement(new htmlImage('../../graphics/' . $mod->getIcon(), '16px', '16px'));
$el->addElement(new htmlOutputText($key)); $el->addElement(new htmlOutputText($key));
$delButton = new htmlButton('del_' . $scope . '_' . $value, 'del.png', true); $delButton = new htmlButton('del_' . $type->getId() . '_' . $value, 'del.png', true);
$delButton->alignment = htmlElement::ALIGN_RIGHT; $delButton->alignment = htmlElement::ALIGN_RIGHT;
$el->addElement($delButton); $el->addElement($delButton);
$listElements[] = $el; $listElements[] = $el;
} }
$selSortable = new htmlSortableList($listElements, $scope . '_selected', '350px'); $selSortable = new htmlSortableList($listElements, $type->getId() . '_selected', '350px');
$selSortable->alignment = htmlElement::ALIGN_TOP; $selSortable->alignment = htmlElement::ALIGN_TOP;
$selSortable->setOnUpdate('updateModulePositions(\'positions_' . $scope . '\', ui.item.data(\'posOrig\'), ui.item.index());'); $selSortable->setOnUpdate('updateModulePositions(\'positions_' . $type->getId() . '\', ui.item.data(\'posOrig\'), ui.item.index());');
$container->addElement($selSortable); $container->addElement($selSortable);
} }
else { else {
@ -335,10 +341,10 @@ function config_showAccountModules($scope, $title, &$container) {
if (sizeof($availOptions) > 0) { if (sizeof($availOptions) > 0) {
$availTable = new htmlTable(); $availTable = new htmlTable();
foreach ($availOptions as $text => $key) { foreach ($availOptions as $text => $key) {
$mod = new $key($scope); $mod = new $key($type->getScope());
$availTable->addElement(new htmlImage('../../graphics/' . $mod->getIcon(), '16px', '16px')); $availTable->addElement(new htmlImage('../../graphics/' . $mod->getIcon(), '16px', '16px'));
$availTable->addElement(new htmlOutputText($text)); $availTable->addElement(new htmlOutputText($text));
$addButton = new htmlButton('add_' . $scope . '_' . $key, 'add.png', true); $addButton = new htmlButton('add_' . $type->getId() . '_' . $key, 'add.png', true);
$addButton->alignment = htmlElement::ALIGN_RIGHT; $addButton->alignment = htmlElement::ALIGN_RIGHT;
$availTable->addElement($addButton, true); $availTable->addElement($addButton, true);
} }
@ -351,7 +357,7 @@ function config_showAccountModules($scope, $title, &$container) {
for ($i = 0; $i < sizeof($selOptions); $i++) { for ($i = 0; $i < sizeof($selOptions); $i++) {
$positions[] = $i; $positions[] = $i;
} }
$container->addElement(new htmlHiddenInput('positions_' . $scope, implode(',', $positions)), true); $container->addElement(new htmlHiddenInput('positions_' . $type->getId(), implode(',', $positions)), true);
// spacer to next account type // spacer to next account type
$container->addElement(new htmlSpacer(null, '30px'), true); $container->addElement(new htmlSpacer(null, '30px'), true);
} }
@ -368,11 +374,13 @@ function checkInput() {
$errors = array(); $errors = array();
$conf = &$_SESSION['conf_config']; $conf = &$_SESSION['conf_config'];
$typeSettings = $conf->get_typeSettings(); $typeSettings = $conf->get_typeSettings();
$accountTypes = $conf->get_ActiveTypes(); $typeManager = new \LAM\TYPES\TypeManager($conf);
for ($t = 0; $t < sizeof($accountTypes); $t++) { $accountTypes = $typeManager->getConfiguredTypes();
$scope = $accountTypes[$t]; foreach ($accountTypes as $type) {
$scope = $type->getScope();
$typeId = $type->getId();
$available = getAvailableModules($scope, true); $available = getAvailableModules($scope, true);
$selected_temp = (isset($typeSettings['modules_' . $scope])) ? $typeSettings['modules_' . $scope] : ''; $selected_temp = (isset($typeSettings['modules_' . $typeId])) ? $typeSettings['modules_' . $typeId] : '';
$selected_temp = explode(',', $selected_temp); $selected_temp = explode(',', $selected_temp);
$selected = array(); $selected = array();
// only use available modules as selected // only use available modules as selected
@ -382,7 +390,7 @@ function checkInput() {
} }
} }
// reorder based on sortable list // reorder based on sortable list
$sorting = $_POST['positions_' . $scope]; $sorting = $_POST['positions_' . $typeId];
if (!empty($sorting)) { if (!empty($sorting)) {
$sorting = explode(',', $sorting); $sorting = explode(',', $sorting);
$sortTmp = array(); $sortTmp = array();
@ -394,17 +402,17 @@ function checkInput() {
// remove modules from selection // remove modules from selection
$new_selected = array(); $new_selected = array();
for ($i = 0; $i < sizeof($selected); $i++) { for ($i = 0; $i < sizeof($selected); $i++) {
if (!isset($_POST['del_' . $scope . '_' . $selected[$i]])) { if (!isset($_POST['del_' . $typeId . '_' . $selected[$i]])) {
$new_selected[] = $selected[$i]; $new_selected[] = $selected[$i];
} }
} }
$selected = $new_selected; $selected = $new_selected;
$typeSettings['modules_' . $scope] = implode(',', $selected); $typeSettings['modules_' . $typeId] = implode(',', $selected);
// add modules to selection // add modules to selection
foreach ($available as $modName) { foreach ($available as $modName) {
if (isset($_POST['add_' . $scope . '_' . $modName])) { if (isset($_POST['add_' . $typeId . '_' . $modName])) {
$selected[] = $modName; $selected[] = $modName;
$typeSettings['modules_' . $scope] = implode(',', $selected); $typeSettings['modules_' . $typeId] = implode(',', $selected);
break; break;
} }
} }
@ -412,7 +420,7 @@ function checkInput() {
$depends = check_module_depends($selected, getModulesDependencies($scope)); $depends = check_module_depends($selected, getModulesDependencies($scope));
if ($depends != false) { if ($depends != false) {
for ($i = 0; $i < sizeof($depends); $i++) { for ($i = 0; $i < sizeof($depends); $i++) {
$errors[] = array('ERROR', LAM\TYPES\getTypeAlias($scope), _("Unsolved dependency:") . ' ' . $errors[] = array('ERROR', $type->getAlias(), _("Unsolved dependency:") . ' ' .
$depends[$i][0] . " (" . $depends[$i][1] . ")"); $depends[$i][0] . " (" . $depends[$i][1] . ")");
} }
} }
@ -420,7 +428,7 @@ function checkInput() {
$conflicts = check_module_conflicts($selected, getModulesDependencies($scope)); $conflicts = check_module_conflicts($selected, getModulesDependencies($scope));
if ($conflicts != false) { if ($conflicts != false) {
for ($i = 0; $i < sizeof($conflicts); $i++) { for ($i = 0; $i < sizeof($conflicts); $i++) {
$errors[] = array('ERROR', LAM\TYPES\getTypeAlias($scope), _("Conflicting module:") . ' ' . $errors[] = array('ERROR', $type->getAlias(), _("Conflicting module:") . ' ' .
$conflicts[$i][0] . " (" . $conflicts[$i][1] . ")"); $conflicts[$i][0] . " (" . $conflicts[$i][1] . ")");
} }
} }
@ -432,7 +440,7 @@ function checkInput() {
} }
} }
if ($baseCount != 1) { if ($baseCount != 1) {
$errors[] = array('ERROR', LAM\TYPES\getTypeAlias($scope), _("No or more than one base module selected!")); $errors[] = array('ERROR', $type->getAlias(), _("No or more than one base module selected!"));
} }
} }
$conf->set_typeSettings($typeSettings); $conf->set_typeSettings($typeSettings);

View File

@ -1,4 +1,16 @@
<?php <?php
namespace LAM\CONFIG;
use \htmlTable;
use \htmlSubTitle;
use \htmlImage;
use \htmlOutputText;
use \htmlSpacer;
use \htmlButton;
use \htmlElement;
use \htmlGroup;
use \htmlTableExtendedInputField;
use \LAMConfig;
use \htmlTableExtendedInputCheckbox;
/* /*
$Id$ $Id$
@ -105,15 +117,22 @@ if (isset($_POST['saveSettings']) || isset($_POST['editmodules'])
} }
$typeSettings = $conf->get_typeSettings(); $typeSettings = $conf->get_typeSettings();
$allTypes = LAM\TYPES\getTypes(); $allScopes = \LAM\TYPES\getTypes();
$activeTypes = $conf->get_ActiveTypes(); $typeManager = new \LAM\TYPES\TypeManager($conf);
$availableTypes = array(); $activeTypes = $typeManager->getConfiguredTypes();
for ($i = 0; $i < sizeof($allTypes); $i++) { $activeScopes = array();
if (!in_array($allTypes[$i], $activeTypes)) { foreach ($activeTypes as $activeType) {
$availableTypes[$allTypes[$i]] = LAM\TYPES\getTypeAlias($allTypes[$i]); $activeScopes[] = $activeType->getScope();
}
$activeScopes = array_unique($activeScopes);
$availableScopes = array();
foreach ($allScopes as $scope) {
$scopeObj = new $scope();
if (!in_array($scope, $activeScopes) || $scopeObj->supportsMultipleConfigs()) {
$availableScopes[$scope] = $scopeObj->getAlias();
} }
} }
natcasesort($availableTypes); natcasesort($availableScopes);
echo $_SESSION['header']; echo $_SESSION['header'];
@ -223,14 +242,14 @@ jQuery(document).ready(function() {
$container = new htmlTable(); $container = new htmlTable();
// show available types // show available types
if (sizeof($availableTypes) > 0) { if (sizeof($availableScopes) > 0) {
$container->addElement(new htmlSubTitle(_("Available account types")), true); $container->addElement(new htmlSubTitle(_("Available account types")), true);
$availableContainer = new htmlTable(); $availableContainer = new htmlTable();
foreach ($availableTypes as $key => $value) { foreach ($availableScopes as $key => $value) {
$availableContainer->addElement(new htmlImage('../../graphics/' . $key . '.png')); $availableContainer->addElement(new htmlImage('../../graphics/' . $key . '.png'));
$availableContainer->addElement(new htmlOutputText($value)); $availableContainer->addElement(new htmlOutputText($value));
$availableContainer->addElement(new htmlSpacer('10px', null)); $availableContainer->addElement(new htmlSpacer('10px', null));
$availableContainer->addElement(new htmlOutputText(LAM\TYPES\getTypeDescription($key))); $availableContainer->addElement(new htmlOutputText(\LAM\TYPES\getTypeDescription($key)));
$button = new htmlButton('add_' . $key, 'add.png', true); $button = new htmlButton('add_' . $key, 'add.png', true);
$button->setTitle(_("Add")); $button->setTitle(_("Add"));
$availableContainer->addElement($button, true); $availableContainer->addElement($button, true);
@ -244,59 +263,58 @@ $_SESSION['conftypes_optionTypes'] = array();
if (sizeof($activeTypes) > 0) { if (sizeof($activeTypes) > 0) {
$container->addElement(new htmlSubTitle(_("Active account types")), true); $container->addElement(new htmlSubTitle(_("Active account types")), true);
$activeContainer = new htmlTable(); $activeContainer = new htmlTable();
for ($i = 0; $i < sizeof($activeTypes); $i++) { foreach ($activeTypes as $activeType) {
// title // title
$titleGroup = new htmlGroup(); $titleGroup = new htmlGroup();
$titleGroup->colspan = 6; $titleGroup->colspan = 6;
$titleGroup->addElement(new htmlImage('../../graphics/' . $activeTypes[$i] . '.png')); $titleGroup->addElement(new htmlImage('../../graphics/' . $activeType->getScope() . '.png'));
$titleText = new htmlOutputText(LAM\TYPES\getTypeAlias($activeTypes[$i])); $titleText = new htmlOutputText($activeType->getAlias());
$titleText->setIsBold(true); $titleText->setIsBold(true);
$titleGroup->addElement($titleText); $titleGroup->addElement($titleText);
$titleGroup->addElement(new htmlSpacer('10px', null)); $titleGroup->addElement(new htmlSpacer('10px', null));
$titleGroup->addElement(new htmlOutputText(LAM\TYPES\getTypeDescription($activeTypes[$i]))); $titleGroup->addElement(new htmlOutputText($activeType->getBaseType()->getDescription()));
$activeContainer->addElement($titleGroup); $activeContainer->addElement($titleGroup);
// delete button // delete button
$delButton = new htmlButton('rem_'. $activeTypes[$i], 'del.png', true); $delButton = new htmlButton('rem_'. $activeType->getId(), 'del.png', true);
$delButton->alignment = htmlElement::ALIGN_RIGHT; $delButton->alignment = htmlElement::ALIGN_RIGHT;
$delButton->setTitle(_("Remove this account type")); $delButton->setTitle(_("Remove this account type"));
$activeContainer->addElement($delButton, true); //del.png $activeContainer->addElement($delButton, true); //del.png
$activeContainer->addElement(new htmlSpacer(null, '5px'), true); $activeContainer->addElement(new htmlSpacer(null, '5px'), true);
// LDAP suffix // LDAP suffix
$suffixInput = new htmlTableExtendedInputField(_("LDAP suffix"), 'suffix_' . $activeTypes[$i], $typeSettings['suffix_' . $activeTypes[$i]], '202'); $suffixInput = new htmlTableExtendedInputField(_("LDAP suffix"), 'suffix_' . $activeType->getId(), $typeSettings['suffix_' . $activeType->getId()], '202');
$suffixInput->setFieldSize(40); $suffixInput->setFieldSize(40);
$activeContainer->addElement($suffixInput); $activeContainer->addElement($suffixInput);
$activeContainer->addElement(new htmlSpacer('20px', null)); $activeContainer->addElement(new htmlSpacer('20px', null));
// list attributes // list attributes
if (isset($typeSettings['attr_' . $activeTypes[$i]])) { if (isset($typeSettings['attr_' . $activeType->getId()])) {
$attributes = $typeSettings['attr_' . $activeTypes[$i]]; $attributes = $typeSettings['attr_' . $activeType->getId()];
} }
else { else {
$attributes = LAM\TYPES\getDefaultListAttributes($activeTypes[$i]); $attributes = \LAM\TYPES\getDefaultListAttributes($activeType->getScope());
} }
$attrsInput = new htmlTableExtendedInputField(_("List attributes"), 'attr_' . $activeTypes[$i], $attributes, '206'); $attrsInput = new htmlTableExtendedInputField(_("List attributes"), 'attr_' . $activeType->getId(), $attributes, '206');
$attrsInput->setFieldSize(40); $attrsInput->setFieldSize(40);
$attrsInput->setFieldMaxLength(1000); $attrsInput->setFieldMaxLength(1000);
$activeContainer->addElement($attrsInput, true); $activeContainer->addElement($attrsInput, true);
// custom label // custom label
$customLabel = ''; $customLabel = '';
if (isset($typeSettings['customLabel_' . $activeTypes[$i]])) { if (isset($typeSettings['customLabel_' . $activeType->getId()])) {
$customLabel = $typeSettings['customLabel_' . $activeTypes[$i]]; $customLabel = $typeSettings['customLabel_' . $activeType->getId()];
} }
$customLabelInput = new htmlTableExtendedInputField(_('Custom label'), 'customLabel_' . $activeTypes[$i], $customLabel, '264'); $customLabelInput = new htmlTableExtendedInputField(_('Custom label'), 'customLabel_' . $activeType->getId(), $customLabel, '264');
$customLabelInput->setFieldSize(40); $customLabelInput->setFieldSize(40);
$activeContainer->addElement($customLabelInput); $activeContainer->addElement($customLabelInput);
$activeContainer->addElement(new htmlSpacer('20px', null)); $activeContainer->addElement(new htmlSpacer('20px', null));
// LDAP filter // LDAP filter
$filter = ''; $filter = '';
if (isset($typeSettings['filter_' . $activeTypes[$i]])) { if (isset($typeSettings['filter_' . $activeType->getId()])) {
$filter = $typeSettings['filter_' . $activeTypes[$i]]; $filter = $typeSettings['filter_' . $activeType->getId()];
} }
$filterInput = new htmlTableExtendedInputField(_("Additional LDAP filter"), 'filter_' . $activeTypes[$i], $filter, '260'); $filterInput = new htmlTableExtendedInputField(_("Additional LDAP filter"), 'filter_' . $activeType->getId(), $filter, '260');
$filterInput->setFieldSize(40); $filterInput->setFieldSize(40);
$activeContainer->addElement($filterInput, true); $activeContainer->addElement($filterInput, true);
// type options // type options
$typeObj = new $activeTypes[$i]; $typeConfigOptions = $activeType->getBaseType()->get_configOptions();
$typeConfigOptions = $typeObj->get_configOptions();
if (!empty($typeConfigOptions)) { if (!empty($typeConfigOptions)) {
foreach ($typeConfigOptions as $typeConfigOption) { foreach ($typeConfigOptions as $typeConfigOption) {
$activeContainer->addElement($typeConfigOption, true); $activeContainer->addElement($typeConfigOption, true);
@ -314,35 +332,35 @@ if (sizeof($activeTypes) > 0) {
// read-only // read-only
if (isLAMProVersion() && ($conf->getAccessLevel() == LAMConfig::ACCESS_ALL)) { if (isLAMProVersion() && ($conf->getAccessLevel() == LAMConfig::ACCESS_ALL)) {
$isReadOnly = false; $isReadOnly = false;
if (isset($typeSettings['readOnly_' . $activeTypes[$i]])) { if (isset($typeSettings['readOnly_' . $activeType->getId()])) {
$isReadOnly = $typeSettings['readOnly_' . $activeTypes[$i]]; $isReadOnly = $typeSettings['readOnly_' . $activeType->getId()];
} }
$readOnly = new htmlTableExtendedInputCheckbox('readOnly_' . $activeTypes[$i], $isReadOnly, _('Read-only'), '265'); $readOnly = new htmlTableExtendedInputCheckbox('readOnly_' . $activeType->getId(), $isReadOnly, _('Read-only'), '265');
$readOnly->setElementsToDisable(array('hideNewButton_' . $activeTypes[$i], 'hideDeleteButton_' . $activeTypes[$i])); $readOnly->setElementsToDisable(array('hideNewButton_' . $activeType->getId(), 'hideDeleteButton_' . $activeType->getId()));
$advancedOptions->addElement($readOnly); $advancedOptions->addElement($readOnly);
$advancedOptions->addElement(new htmlSpacer('20px', null)); $advancedOptions->addElement(new htmlSpacer('20px', null));
} }
// hidden type // hidden type
$hidden = false; $hidden = false;
if (isset($typeSettings['hidden_' . $activeTypes[$i]])) { if (isset($typeSettings['hidden_' . $activeType->getId()])) {
$hidden = $typeSettings['hidden_' . $activeTypes[$i]]; $hidden = $typeSettings['hidden_' . $activeType->getId()];
} }
$advancedOptions->addElement(new htmlTableExtendedInputCheckbox('hidden_' . $activeTypes[$i], $hidden, _('Hidden'), '261')); $advancedOptions->addElement(new htmlTableExtendedInputCheckbox('hidden_' . $activeType->getId(), $hidden, _('Hidden'), '261'));
if (isLAMProVersion() && ($conf->getAccessLevel() == LAMConfig::ACCESS_ALL)) { if (isLAMProVersion() && ($conf->getAccessLevel() == LAMConfig::ACCESS_ALL)) {
$advancedOptions->addElement(new htmlSpacer('20px', null)); $advancedOptions->addElement(new htmlSpacer('20px', null));
// hide button to create new accounts // hide button to create new accounts
$hideNewButton = false; $hideNewButton = false;
if (isset($typeSettings['hideNewButton_' . $activeTypes[$i]])) { if (isset($typeSettings['hideNewButton_' . $activeType->getId()])) {
$hideNewButton = $typeSettings['hideNewButton_' . $activeTypes[$i]]; $hideNewButton = $typeSettings['hideNewButton_' . $activeType->getId()];
} }
$advancedOptions->addElement(new htmlTableExtendedInputCheckbox('hideNewButton_' . $activeTypes[$i], $hideNewButton, _('No new entries'), '262')); $advancedOptions->addElement(new htmlTableExtendedInputCheckbox('hideNewButton_' . $activeType->getId(), $hideNewButton, _('No new entries'), '262'));
$advancedOptions->addElement(new htmlSpacer('20px', null)); $advancedOptions->addElement(new htmlSpacer('20px', null));
// hide button to delete accounts // hide button to delete accounts
$hideDeleteButton = false; $hideDeleteButton = false;
if (isset($typeSettings['hideDeleteButton_' . $activeTypes[$i]])) { if (isset($typeSettings['hideDeleteButton_' . $activeType->getId()])) {
$hideDeleteButton = $typeSettings['hideDeleteButton_' . $activeTypes[$i]]; $hideDeleteButton = $typeSettings['hideDeleteButton_' . $activeType->getId()];
} }
$advancedOptions->addElement(new htmlTableExtendedInputCheckbox('hideDeleteButton_' . $activeTypes[$i], $hideDeleteButton, _('Disallow delete'), '263'), true); $advancedOptions->addElement(new htmlTableExtendedInputCheckbox('hideDeleteButton_' . $activeType->getId(), $hideDeleteButton, _('Disallow delete'), '263'), true);
} }
$activeContainer->addElement($advancedOptions, true); $activeContainer->addElement($advancedOptions, true);
@ -391,6 +409,7 @@ function checkInput() {
} }
$errors = array(); $errors = array();
$conf = &$_SESSION['conf_config']; $conf = &$_SESSION['conf_config'];
$typeManager = new \LAM\TYPES\TypeManager($conf);
$typeSettings = $conf->get_typeSettings(); $typeSettings = $conf->get_typeSettings();
$accountTypes = $conf->get_ActiveTypes(); $accountTypes = $conf->get_ActiveTypes();
$postKeys = array_keys($_POST); $postKeys = array_keys($_POST);
@ -404,17 +423,12 @@ function checkInput() {
$accountTypes = array_flip($accountTypes); $accountTypes = array_flip($accountTypes);
$accountTypes = array_values($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 // set suffixes
elseif (substr($key, 0, 7) == "suffix_") { elseif (substr($key, 0, 7) == "suffix_") {
$typeSettings[$key] = trim($_POST[$key]); $typeSettings[$key] = trim($_POST[$key]);
$type = substr($postKeys[$i], 7); $type = substr($postKeys[$i], 7);
if (strlen($_POST[$key]) < 1) { if (strlen($_POST[$key]) < 1) {
$errors[] = array("ERROR", _("LDAP Suffix is invalid!"), LAM\TYPES\getTypeAlias($type)); $errors[] = array("ERROR", _("LDAP Suffix is invalid!"), \LAM\TYPES\getTypeAlias($type));
} }
} }
// set attributes // set attributes
@ -422,7 +436,7 @@ function checkInput() {
$typeSettings[$key] = $_POST[$key]; $typeSettings[$key] = $_POST[$key];
$type = substr($postKeys[$i], 5); $type = substr($postKeys[$i], 5);
if (!is_string($_POST[$key]) || !preg_match("/^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$/", $_POST[$key])) { if (!is_string($_POST[$key]) || !preg_match("/^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$/", $_POST[$key])) {
$errors[] = array("ERROR", _("List attributes are invalid!"), LAM\TYPES\getTypeAlias($type)); $errors[] = array("ERROR", _("List attributes are invalid!"), \LAM\TYPES\getTypeAlias($type));
} }
} }
// set filter // set filter
@ -435,28 +449,36 @@ function checkInput() {
} }
} }
$typeConfigOptions = extractConfigOptionsFromPOST($_SESSION['conftypes_optionTypes']); $typeConfigOptions = extractConfigOptionsFromPOST($_SESSION['conftypes_optionTypes']);
for ($i = 0; $i < sizeof($accountTypes); $i++) { foreach ($accountTypes as $accountType) {
// set hidden // set hidden
$key = "hidden_" . $accountTypes[$i]; $key = "hidden_" . $accountType;
$typeSettings[$key] = (isset($_POST[$key]) && ($_POST[$key] == 'on')); $typeSettings[$key] = (isset($_POST[$key]) && ($_POST[$key] == 'on'));
if (isLAMProVersion() && ($conf->getAccessLevel() == LAMConfig::ACCESS_ALL)) { if (isLAMProVersion() && ($conf->getAccessLevel() == LAMConfig::ACCESS_ALL)) {
// set if new entries are allowed // set if new entries are allowed
$key = "hideNewButton_" . $accountTypes[$i]; $key = "hideNewButton_" . $accountType;
$typeSettings[$key] = (isset($_POST[$key]) && ($_POST[$key] == 'on')); $typeSettings[$key] = (isset($_POST[$key]) && ($_POST[$key] == 'on'));
// set if deletion of entries is allowed // set if deletion of entries is allowed
$key = "hideDeleteButton_" . $accountTypes[$i]; $key = "hideDeleteButton_" . $accountType;
$typeSettings[$key] = (isset($_POST[$key]) && ($_POST[$key] == 'on')); $typeSettings[$key] = (isset($_POST[$key]) && ($_POST[$key] == 'on'));
// set if account type is read-only // set if account type is read-only
$key = "readOnly_" . $accountTypes[$i]; $key = "readOnly_" . $accountType;
$typeSettings[$key] = (isset($_POST[$key]) && ($_POST[$key] == 'on')); $typeSettings[$key] = (isset($_POST[$key]) && ($_POST[$key] == 'on'));
} }
// check dynamic type settings // check dynamic type settings
$typeObj = new $accountTypes[$i]; $typeObj = $typeManager->getConfiguredType($accountType)->getBaseType();
$typeMessages = $typeObj->check_configOptions($typeConfigOptions); $typeMessages = $typeObj->check_configOptions($typeConfigOptions);
if (!empty($typeMessages)) { if (!empty($typeMessages)) {
$errors = array_merge($errors, $typeMessages); $errors = array_merge($errors, $typeMessages);
} }
} }
// new type
foreach ($_POST as $key => $value) {
// check if add button was pressed
if (substr($key, 0, 4) == "add_") {
$scope = substr($key, 4);
$accountTypes[] = $typeManager->generateNewTypeId($scope);
}
}
// add dynamic type settings // add dynamic type settings
foreach ($typeConfigOptions as $key => $value) { foreach ($typeConfigOptions as $key => $value) {
$typeSettings[$key] = implode(LAMConfig::LINE_SEPARATOR, $value); $typeSettings[$key] = implode(LAMConfig::LINE_SEPARATOR, $value);

View File

@ -62,11 +62,13 @@ if (!is_array($classes)) {
} }
else { else {
// loop for active account types // loop for active account types
for ($t = 0; $t < sizeof($types); $t++) { $typeManager = new \LAM\TYPES\TypeManager();
$modules = $_SESSION['config']->get_AccountModules($types[$t]); $types = $typeManager->getConfiguredTypes();
$container->addElement(new htmlSubTitle(LAM\TYPES\getTypeAlias($types[$t])), true); foreach ($types as $type) {
$modules = $_SESSION['config']->get_AccountModules($type->getId());
$container->addElement(new htmlSubTitle($type->getAlias()), true);
for ($m = 0; $m < sizeof($modules); $m++) { for ($m = 0; $m < sizeof($modules); $m++) {
$error = checkSchemaForModule($modules[$m], $types[$t]); $error = checkSchemaForModule($modules[$m], $type->getScope());
$message = _("No problems found."); $message = _("No problems found.");
$icon = '../../graphics/pass.png'; $icon = '../../graphics/pass.png';
if ($error != null) { if ($error != null) {
@ -74,7 +76,7 @@ else {
$message = $error; $message = $error;
} }
// module name // module name
$container->addElement(new htmlOutputText(getModuleAlias($modules[$m], $types[$t]))); $container->addElement(new htmlOutputText(getModuleAlias($modules[$m], $type->getScope())));
$container->addElement(new htmlSpacer('10px', null)); $container->addElement(new htmlSpacer('10px', null));
// icon // icon
$container->addElement(new htmlImage($icon)); $container->addElement(new htmlImage($icon));