diff --git a/htdocs/adherents/ldap.php b/htdocs/adherents/ldap.php
index 87fec8feebf..c2779eae1f7 100644
--- a/htdocs/adherents/ldap.php
+++ b/htdocs/adherents/ldap.php
@@ -177,8 +177,10 @@ if ($result > 0)
$search = "(".$adh->_load_ldap_dn($info,2).")";
$records=$ldap->search($dn,$search);
+ //print_r($records);
+
// Affichage arbre
- if (sizeof($records))
+ if (sizeof($records) && (! isset($records['count']) || $records['count'] > 0))
{
if (! is_array($records))
{
diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php
index 3385a665718..49f1a8f7651 100644
--- a/htdocs/contact/ldap.php
+++ b/htdocs/contact/ldap.php
@@ -159,17 +159,26 @@ if ($result > 0)
$info=$contact->_load_ldap_info();
$dn=$contact->_load_ldap_dn($info,1);
$search = "(".$contact->_load_ldap_dn($info,2).")";
- $result=$ldap->search($dn,$search);
+ $records=$ldap->search($dn,$search);
+
+ //print_r($records);
// Affichage arbre
- if (sizeof($result))
+ if (sizeof($records) && (! isset($records['count']) || $records['count'] > 0))
{
- $html=new Form($db);
- $html->show_ldap_content($result,0,0,true);
+ if (! is_array($records))
+ {
+ print '
| '.$langs->trans("ErrorFailedToReadLDAP").' |
';
+ }
+ else
+ {
+ $html=new Form($db);
+ $result=$html->show_ldap_content($records,0,0,true);
+ }
}
else
{
- print '| '.$langs->trans("LDAPRecordNotFound").' |
';
+ print '| '.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.') |
';
}
$ldap->unbind();
diff --git a/htdocs/lib/ldap.class.php b/htdocs/lib/ldap.class.php
index 355572498d0..e5c2e5a47d1 100644
--- a/htdocs/lib/ldap.class.php
+++ b/htdocs/lib/ldap.class.php
@@ -762,17 +762,17 @@ class Ldap
/**
* \brief Returns an array containing a details of elements
- * \param $search
- * \param $userDn
- * \param $useridentifier
- * \param $attributeArray Variables required
+ * \param $search Valeur champ clé recherché, sinon '*' pour tous.
+ * \param $userDn DN (Ex: ou=adherents,ou=people,dc=parinux,dc=org)
+ * \param $useridentifier Nom du champ clé (Ex: uid)
+ * \param $attributeArray Array of fields required (Ex: sn,userPassword)
* \param $activefilter 1=utilise le champ this->filter comme filtre
- *
+ * \return array Array of [id_record][ldap_field]=value
* \remarks ldapsearch -LLLx -hlocalhost -Dcn=admin,dc=parinux,dc=org -w password -b "ou=adherents,ou=people,dc=parinux,dc=org" userPassword
*/
function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter=0)
{
- $userslist=array();
+ $fulllist=array();
dolibarr_syslog("Ldap::getRecords search=".$search." userDn=".$userDn." useridentifier=".$useridentifier." attributeArray=array(".join(',',$attributeArray).")");
@@ -822,7 +822,7 @@ class Ldap
if ($recordid)
{
//print "Found record with key $useridentifier=".$recordid."
\n";
- $userslist[$recordid][$useridentifier]=$recordid;
+ $fulllist[$recordid][$useridentifier]=$recordid;
// Add to the array for each attribute in my list
for ($j = 0; $j < count($attributeArray); $j++)
@@ -834,18 +834,18 @@ class Ldap
if ($this->serverType == "activedirectory" && $keyattributelower == "objectsid")
{
$objectsid = $this->getObjectSid($recordid);
- $userslist[$recordid][$attributeArray[$j]] = $objectsid;
+ $fulllist[$recordid][$attributeArray[$j]] = $objectsid;
}
else
{
- $userslist[$recordid][$attributeArray[$j]] = $this->ldap_utf8_decode($info[$i][$keyattributelower][0]);
+ $fulllist[$recordid][$attributeArray[$j]] = $this->ldap_utf8_decode($info[$i][$keyattributelower][0]);
}
}
}
}
- asort($userslist);
- return $userslist;
+ asort($fulllist);
+ return $fulllist;
}
/**
@@ -922,7 +922,10 @@ class Ldap
* \remarks this->connection doit etre défini donc la methode bind ou bindauth doit avoir deja été appelée
* \param checkDn DN de recherche (Ex: ou=users,cn=my-domain,cn=com)
* \param filter Filtre de recherche (ex: (sn=nom_personne) )
- * \return array Tableau des reponses
+ * \return array Tableau des reponses (clé en minuscule-valeur)
+ * \remarks Ne pas utiliser pour recherche d'une liste donnée de propriétés
+ * car conflit majuscule-minuscule. A n'utiliser que pour les pages
+ * 'Fiche LDAP' qui affiche champ lisibles par defaut.
*/
function search($checkDn, $filter)
{
diff --git a/htdocs/user/group/ldap.php b/htdocs/user/group/ldap.php
index cca10525f9c..b9fb790642b 100644
--- a/htdocs/user/group/ldap.php
+++ b/htdocs/user/group/ldap.php
@@ -123,19 +123,27 @@ if ($result > 0)
$info=$fgroup->_load_ldap_info();
$dn=$fgroup->_load_ldap_dn($info,1);
$search = "(".$fgroup->_load_ldap_dn($info,2).")";
- $result=$ldap->search($dn,$search);
+ $records=$ldap->search($dn,$search);
+
+ //print_r($records);
// Affichage arbre
- if (sizeof($result))
+ if (sizeof($records) && (! isset($records['count']) || $records['count'] > 0))
{
- $html=new Form($db);
- $html->show_ldap_content($result,0,0,true);
+ if (! is_array($records))
+ {
+ print '| '.$langs->trans("ErrorFailedToReadLDAP").' |
';
+ }
+ else
+ {
+ $html=new Form($db);
+ $result=$html->show_ldap_content($records,0,0,true);
+ }
}
else
{
- print '| '.$langs->trans("LDAPRecordNotFound").' |
';
+ print '| '.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.') |
';
}
-
$ldap->unbind();
$ldap->close();
}