Merge pull request #22 from LDAPAccountManager/type_api_tmp

Type api tmp
This commit is contained in:
gruberroland 2017-01-07 19:16:24 +01:00 committed by GitHub
commit 841306c00c
3 changed files with 28 additions and 44 deletions

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2009 - 2016 Roland Gruber
2009 - 2017 Roland Gruber
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
@ -672,13 +672,14 @@ function searchLDAPByAttribute($name, $value, $objectClass, $attributes, $scopes
elseif (sizeof($filterParts) > 1) {
$filter = '(& ' . implode(' ', $filterParts) . ')';
}
$activeTypes = $_SESSION['config']->get_ActiveTypes();
for ($s = 0; $s < sizeof($scopes); $s++) {
if (!in_array($scopes[$s], $activeTypes)) {
$typeManager = new \LAM\TYPES\TypeManager();
$activeTypes = $typeManager->getConfiguredTypes();
foreach ($activeTypes as $type) {
if (!in_array($type->getScope(), $scopes)) {
continue; // skip non-active account types
}
// search LDAP
$entries = searchLDAPPaged($_SESSION['ldap']->server(), escapeDN($_SESSION['config']->get_Suffix($scopes[$s])),
$entries = searchLDAPPaged($_SESSION['ldap']->server(), escapeDN($type->getSuffix()),
$filter, $attributes, 0, $_SESSION['config']->get_searchLimit());
if (ldap_errno($_SESSION['ldap']->server()) == 4) {
logNewMessage(LOG_WARNING, 'LDAP size limit exeeded. Please increase the limit on your server.');
@ -703,9 +704,14 @@ function searchLDAPByFilter($filter, $attributes, $scopes, $attrsOnly = false) {
if ($attrsOnly) {
$readAttributesOnly = 1;
}
for ($s = 0; $s < sizeof($scopes); $s++) {
$typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
foreach ($types as $type) {
if (!in_array($type->getScope(), $scopes)) {
continue;
}
// search LDAP
$entries = searchLDAPPaged($_SESSION['ldap']->server(), escapeDN($_SESSION['config']->get_Suffix($scopes[$s])),
$entries = searchLDAPPaged($_SESSION['ldap']->server(), escapeDN($type->getSuffix()),
$filter, $attributes, $readAttributesOnly, $_SESSION['config']->get_searchLimit());
if (ldap_errno($_SESSION['ldap']->server()) == 4) {
logNewMessage(LOG_WARNING, 'LDAP size limit exeeded. Please increase the limit on your server.');

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2005 - 2016 Roland Gruber
2005 - 2017 Roland Gruber
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
@ -37,8 +37,6 @@ $Id$
*/
class inetOrgPerson extends baseModule implements passwordService {
/** caches the list of possible managers */
private $cachedManagers = null;
/** clear text password */
private $clearTextPassword = null;
/** cache for departments */
@ -3495,28 +3493,6 @@ class inetOrgPerson extends baseModule implements passwordService {
return array();
}
/**
* Returns a list of possible managers.
*
* @return array list of format array(abstract DN => DN)
*/
private function getManagers() {
if ($this->cachedManagers != null) {
return $this->cachedManagers;
}
$dnUsers = searchLDAPByAttribute(null, null, 'inetOrgPerson', array('dn'), array('user'));
for ($i = 0; $i < sizeof($dnUsers); $i++) {
$dnUsers[$i] = $dnUsers[$i]['dn'];
}
usort($dnUsers, 'compareDN');
array_unshift($dnUsers, '-');
$this->cachedManagers = array();
for ($i = 0; $i < sizeof($dnUsers); $i++) {
$this->cachedManagers[getAbstractDN($dnUsers[$i])] = $dnUsers[$i];
}
return $this->cachedManagers;
}
/**
* Loads cached data from LDAP such as departmets etc.
*/

View File

@ -8,7 +8,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Michael Duergner
2011 - 2016 Roland Gruber
2011 - 2017 Roland Gruber
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
@ -40,19 +40,20 @@ include_once("ldap.inc");
/**
* This function will return all available PDF structure definitions for the submitted
* account scope.
* account type.
*
* @param string $scope The account scope the PDF structure definitions should be
* returned.
* @param string $typeId the account type
* @param string $profile server profile name
*
* @return array $scope All available PDF structure definitions for the submitted account
* @return array All available PDF structure definitions for the submitted account
* scope. Each entry is a string being the filename that may be passed to the
* createModulePDF() function as second argument.
*/
function getPDFStructures($scope = "user", $profile = null) {
function getPDFStructures($typeId, $profile = null) {
$return = array();
if (!preg_match('/[a-zA-Z]+/', $typeId)) {
return null;
}
if (!isset($profile)) {
$profile = $_SESSION['config']->getName();
}
@ -61,7 +62,7 @@ function getPDFStructures($scope = "user", $profile = null) {
$dirHandle = opendir($path);
while($file = readdir($dirHandle)) {
$struct_file = explode('.',$file);
if(!is_dir($path.$file) && ($file != '.') && ($file != '..') && (sizeof($struct_file) == 3) && ($struct_file[1] == $scope) && ($struct_file[2] == 'xml')) {
if(!is_dir($path.$file) && ($file != '.') && ($file != '..') && (sizeof($struct_file) == 3) && ($struct_file[1] == $typeId) && ($struct_file[2] == 'xml')) {
array_push($return, $struct_file[0]);
}
}
@ -292,14 +293,15 @@ function deletePDFLogo($name) {
return new htmlStatusMessage('ERROR', _('File does not exist.'), htmlspecialchars($name));
}
// check if still in use
$activeTypes = $_SESSION['config']->get_ActiveTypes();
$typeManager = new \LAM\TYPES\TypeManager();
$activeTypes = $typeManager->getConfiguredTypes();
foreach ($activeTypes as $type) {
$structures = getPDFStructures($type);
$structures = getPDFStructures($type->getId());
foreach ($structures as $structure) {
$data = loadPDFStructure($type, $structure);
$data = loadPDFStructure($type->getId(), $structure);
if ($data['page_definitions']['filename'] == $name) {
return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'),
sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, \LAM\TYPES\getTypeAlias($type)));
sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, $type->getAlias()));
}
}
}