new type API

This commit is contained in:
Roland Gruber 2016-12-29 20:12:15 +01:00
parent 23c1251009
commit a6330b41e2
2 changed files with 35 additions and 24 deletions

View File

@ -90,18 +90,24 @@ function is_base_module($name, $scope) {
/**
* Returns the LDAP filter used by the account lists
*
* @param string $scope the account type ("user", "group", "host")
* @param string $typeId the account type ("user", "group", "host")
* @return string LDAP filter
*/
function get_ldap_filter($scope) {
$mods = $_SESSION['config']->get_AccountModules($scope);
$filters = array();
function get_ldap_filter($typeId) {
$typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($typeId);
$mods = $_SESSION['config']->get_AccountModules($typeId);
$filters = array('or' => array(), 'and' => array());
$orFilter = '';
for ($i = 0; $i < sizeof($mods); $i++) {
$module = moduleCache::getModule($mods[$i], $scope);
$module = moduleCache::getModule($mods[$i], $type->getScope());
$modinfo = $module->get_ldap_filter();
if (isset($modinfo['or'])) $filters['or'][] = $modinfo['or'];
if (isset($modinfo['and'])) $filters['and'][] = $modinfo['and'];
if (isset($modinfo['or'])) {
$filters['or'][] = $modinfo['or'];
}
if (isset($modinfo['and'])) {
$filters['and'][] = $modinfo['and'];
}
}
// build OR filter
if (sizeof($filters['or']) == 1) {
@ -111,15 +117,17 @@ function get_ldap_filter($scope) {
$orFilter = "(|" . implode("", $filters['or']) . ")";
}
// add built OR filter to AND filters
if ($orFilter != '') $filters['and'][] = $orFilter;
if (!empty($orFilter)) {
$filters['and'][] = $orFilter;
}
// add type filter
$typeSettings = $_SESSION['config']->get_typeSettings();
if (isset($typeSettings['filter_' . $scope]) && ($typeSettings['filter_' . $scope] != '')) {
if (strpos($typeSettings['filter_' . $scope], '(') === 0) {
$filters['and'][] = $typeSettings['filter_' . $scope];
if (isset($typeSettings['filter_' . $typeId]) && ($typeSettings['filter_' . $typeId] != '')) {
if (strpos($typeSettings['filter_' . $typeId], '(') === 0) {
$filters['and'][] = $typeSettings['filter_' . $typeId];
}
else {
$filters['and'][] = '(' . $typeSettings['filter_' . $scope] . ')';
$filters['and'][] = '(' . $typeSettings['filter_' . $typeId] . ')';
}
}
// collapse AND filters
@ -140,12 +148,12 @@ function get_ldap_filter($scope) {
*
* The list is already sorted by the priority given by the nodules.
*
* @param string $scope account type (user, group, host)
* @param string $typeId account type (user, group, host)
* @param array $selectedModules return only RDN attributes of these modules
* @return array list of LDAP attributes
*/
function getRDNAttributes($scope, $selectedModules=null) {
$mods = $_SESSION['config']->get_AccountModules($scope);
function getRDNAttributes($typeId, $selectedModules=null) {
$mods = $_SESSION['config']->get_AccountModules($typeId);
if ($selectedModules != null) {
$mods = $selectedModules;
}
@ -155,7 +163,7 @@ function getRDNAttributes($scope, $selectedModules=null) {
$attrs_high = array();
for ($i = 0; $i < sizeof($mods); $i++) {
// get list of attributes
$module = moduleCache::getModule($mods[$i], $scope);
$module = moduleCache::getModule($mods[$i], \LAM\TYPES\getScopeFromTypeId($typeId));
$attrs = $module->get_RDNAttributes();
$keys = array_keys($attrs);
// sort attributes
@ -595,14 +603,17 @@ function doUploadPostActions($scope, &$data, $ids, $failed, $selectedModules, &$
*/
function getRequiredExtensions() {
$extList = array();
$scopes = $_SESSION['config']->get_ActiveTypes();
for ($i = 0; $i < sizeof($scopes); $i++) {
$mods = $_SESSION['config']->get_AccountModules($scopes[$i]);
$typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
foreach ($types as $type) {
$mods = $_SESSION['config']->get_AccountModules($type->getId());
for ($m = 0; $m < sizeof($mods); $m++) {
$module = moduleCache::getModule($mods[$m], $scopes[$i]);
$module = moduleCache::getModule($mods[$m], $type->getScope());
$ext = $module->getRequiredExtensions();
for ($e = 0; $e < sizeof($ext); $e++) {
if (!in_array($ext[$e], $extList)) $extList[] = $ext[$e];
if (!in_array($ext[$e], $extList)) {
$extList[] = $ext[$e];
}
}
}
}

View File

@ -206,7 +206,7 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
$existingContainer->addElement(new htmlSpacer(null, '10px'), true);
}
$existingContainer->addElement(new htmlImage('../../graphics/' . $profileClasses[$i]['typeId'] . '.png'));
$existingContainer->addElement(new htmlImage('../../graphics/' . \LAM\TYPES\getScopeFromTypeId($profileClasses[$i]['typeId']) . '.png'));
$existingContainer->addElement(new htmlSpacer('3px', null));
$existingContainer->addElement(new htmlOutputText($profileClasses[$i]['title']));
$existingContainer->addElement(new htmlSpacer('3px', null));