diff --git a/trunk/includes/class/class.LSldapObject.php b/trunk/includes/class/class.LSldapObject.php index d5e8f4f4..b8501da9 100644 --- a/trunk/includes/class/class.LSldapObject.php +++ b/trunk/includes/class/class.LSldapObject.php @@ -712,6 +712,14 @@ class LSldapObject { $sfilter_for.=$sfilter_end; + // Attributes + if ($filter[$i]['attr']) { + $sparams['attributes'] = array($filter[$i]['attr']); + } + else { + $sparams['attributes'] = array($this -> config['rdn']); + } + // Execution de la recherche $ret=$GLOBALS['LSldap'] -> search ($sfilter_for,$sbasedn,$sparams); @@ -774,6 +782,9 @@ class LSldapObject { // fermeture du filtre $sfilter.=$sfilter_end; + // Attributes + $sparams['attributes'] = array($this -> config['rdn']); + // Lancement de la recherche $ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams); @@ -806,8 +817,9 @@ class LSldapObject { // préparation du retour finale if (is_array($ret)) { $ret_final=array(); - foreach($ret as $obj) + foreach($ret as $obj) { $ret_final[]=$obj['dn']; + } $ret=$ret_final; } else { @@ -826,6 +838,62 @@ class LSldapObject { return $retInfos; } + + /** + * Retourne une liste d'objet du même type et retourne leur noms + * + * Effectue une recherche en fonction des paramètres passé et retourne un + * tableau (dn => nom) correspondant au resultat de la recherche. + * + * @author Benjamin Renard + * + * @param[in] $filter string Filtre de recherche Ldap + * @param[in] $basedn string DN de base pour la recherche + * @param[in] $params array Paramètres de recherche au format Net_LDAP2::search() + * @param[in] $displayFormat string Format d'affichage du nom des objets + * + * @retval array Tableau dn => name correspondant au resultat de la recherche + */ + function listObjectsName($filter=NULL,$sbasedn=NULL,$sparams=array(),$displayFormat=false) { + $retInfos=array(); + + if (!$displayFormat) { + $displayFormat = $this -> getDisplayAttributes(); + } + + // Filtre sur l'objet souhaité + $sfilter='(&'; + $sfilter.=$this -> getObjectFilter(); + $sfilter_end=')'; + + if(($filter)&&(!empty($filter))) { + if(substr($filter,0,1)=='(') { + $sfilter.=$filter; + } + else { + $sfilter.='('.$filter.')'; + } + } + // fermeture du filtre + $sfilter.=$sfilter_end; + + // Attributes + $sparams['attributes'] = getFieldInFormat($displayFormat); + if(empty($sparams['attributes'])) { + $sparams['attributes'] = array($this -> config['rdn']); + } + + // Lancement de la recherche + $ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams); + + if (is_array($ret)) { + foreach($ret as $obj) { + $retInfos[$obj['dn']] = getFData($displayFormat,$obj['attrs']); + } + } + + return $retInfos; + } /** @@ -912,12 +980,7 @@ class LSldapObject { else { $filter=NULL; } - $list = $this -> listObjects($filter,$topDn); - $return=array(); - foreach($list as $object) { - $return[$object -> getDn()] = $object -> getDisplayValue($displayFormat); - } - return $return; + return $this -> listObjectsName($filter,$topDn,array(),$displayFormat); } /** @@ -1025,13 +1088,17 @@ class LSldapObject { /** * Retourne la valeur (DN) du subDn de l'objet * + * @parram[in] $dn string Un DN + * * @return string La valeur du subDn de l'object */ - function getSubDnValue() { - if ($this -> _subDn_value) { - return $this -> _subDn_value; + function getSubDnValue($dn=NULL) { + if (!$dn) { + $dn = $this -> getValue('dn'); + } + if ($this -> _subDn_value[$dn]) { + return $this -> _subDn_value[$dn]; } - $dn = $this -> getValue('dn'); $subDn_value=''; $subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer(); foreach ($subDnLdapServer as $subDn => $subDn_name) { @@ -1040,18 +1107,20 @@ class LSldapObject { break; } } - $this -> _subDn_value = $subDn_value; + $this -> _subDn_value[$dn] = $subDn_value; return $subDn_value; } /** * Retourne la nom du subDn de l'objet * + * @parram[in] $dn string Un DN + * * @return string Le nom du subDn de l'object */ - function getSubDnName() { + function getSubDnName($dn=NULL) { $subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer(); - return $subDnLdapServer[$this -> getSubDnValue()]; + return $subDnLdapServer[$this -> getSubDnValue($dn)]; } /** diff --git a/trunk/includes/functions.php b/trunk/includes/functions.php index b505be2c..2c6ec5e9 100644 --- a/trunk/includes/functions.php +++ b/trunk/includes/functions.php @@ -146,6 +146,16 @@ function getFData($format,$data,$meth=NULL) { return $format; } +function getFieldInFormat($format) { + $fields=array(); + $expr="%{([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9])+)?}"; + while (ereg($expr,$format,$ch)) { + $fields[]=$ch[1]; + $format=ereg_replace($ch[0],'',$format); + } + return $fields; +} + function loadDir($dir,$regexpr='^.*\.php$') { if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { diff --git a/trunk/view.php b/trunk/view.php index 96091271..d56db47f 100644 --- a/trunk/view.php +++ b/trunk/view.php @@ -318,22 +318,21 @@ if($LSsession -> startLSsession()) { 'action' => 'refresh' ); - $list=$object -> listObjects($filter,$topDn,$params); - + $list=$object -> listObjectsName($filter,$topDn,$params); $nbObjects=0; - foreach($list as $thisObject) { - if ($GLOBALS['LSsession'] -> canAccess($LSobject,$thisObject->getValue('dn'))) { + foreach($list as $objDn => $objName) { + if ($GLOBALS['LSsession'] -> canAccess($LSobject,$objDn)) { $subDn_name=false; if ($doSubDn) { - $subDn_name = $thisObject -> getSubDnName(); + $subDn_name = $object -> getSubDnName($objDn); } $nbObjects++; $objectList[]=array( - 'dn' => $thisObject->getValue('dn'), - 'displayValue' => $thisObject->getDisplayValue(), + 'dn' => $objDn, + 'displayValue' => $objName, 'subDn' => $subDn_name ); }