2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
23 LSsession :: loadLSclass('LSattribute');
26 * Base d'un objet ldap
28 * Cette classe définis la base de tout objet ldap géré par LdapSaisie
30 * @author Benjamin Renard <brenard@easter-eggs.com>
34 var $config = array();
41 var $other_values=array();
42 var $submitError=true;
44 var $_LSrelationsCache=array();
47 var $_objectEvents=array();
54 * Cette methode construit l'objet et définis la configuration.
55 * Elle lance la construction du tableau d'attributs représentés par un objet LSattribute.
57 * @author Benjamin Renard <brenard@easter-eggs.com>
59 * @retval boolean true si l'objet a été construit, false sinon.
61 function LSldapObject() {
62 $this -> type_name = get_class($this);
63 $config = LSconfig :: get('LSobjects.'.$this -> type_name);
64 if(is_array($config)) {
65 $this -> config = $config;
68 LSerror :: addErrorCode('LSldapObject_01');
72 foreach($this -> config['attrs'] as $attr_name => $attr_config) {
73 if(!$this -> attrs[$attr_name]=new LSattribute($attr_name,$attr_config,$this)) {
82 * Charge les données de l'objet
84 * Cette methode définis le DN de l'objet et charge les valeurs de attributs de l'objet
85 * Ã partir de l'annuaire.
87 * @author Benjamin Renard <brenard@easter-eggs.com>
89 * @param[in] $dn string Le DN de l'objet.
91 * @retval boolean true si la chargement a réussi, false sinon.
93 function loadData($dn) {
95 $data = LSldap :: getAttrs($dn);
97 foreach($this -> attrs as $attr_name => $attr) {
98 if(!$this -> attrs[$attr_name] -> loadData($data[$attr_name]))
107 * Recharge les données de l'objet
109 * @author Benjamin Renard <brenard@easter-eggs.com>
111 * @retval boolean true si la rechargement a réussi, false sinon.
113 function reloadData() {
114 $data = LSldap :: getAttrs($this -> dn);
115 foreach($this -> attrs as $attr_name => $attr) {
116 if(!$this -> attrs[$attr_name] -> reloadData($data[$attr_name]))
123 * Retourne le format d'affichage de l'objet
125 * @author Benjamin Renard <brenard@easter-eggs.com>
127 * @retval string Format d'affichage de l'objet.
129 function getDisplayNameFormat() {
130 return $this -> config['display_name_format'];
134 * Retourne la valeur descriptive d'affichage de l'objet
136 * Cette fonction retourne la valeur descriptive d'affichage de l'objet en fonction
137 * du format défini dans la configuration de l'objet ou spécifié en paramètre.
139 * @author Benjamin Renard <brenard@easter-eggs.com>
141 * @param[in] $spe [<i>optionnel</i>] string Format d'affichage de l'objet
142 * @param[in] $full [<i>optionnel</i>] boolean True pour afficher en plus le
145 * @retval string Valeur descriptive d'affichage de l'objet
147 function getDisplayName($spe='',$full=false) {
149 $spe = $this -> getDisplayNameFormat();
151 $val = $this -> getFData($spe,&$this -> attrs,'getDisplayValue');
152 if (LSsession :: haveSubDn() && $full) {
153 $val.=' ('.$this -> subDnName.')';
161 * Cette fonction retourne la valeur d'une chaine formatée en prennant les valeurs
164 * @author Benjamin Renard <brenard@easter-eggs.com>
166 * @param[in] $format string Format de la chaine
168 * @retval string Valeur d'une chaine formatée
170 function getFData($format) {
171 $format=getFData($format,$this,'getValue');
176 * Construit un formulaire de l'objet
178 * Cette méthode construit un formulaire LSform à partir de la configuration de l'objet
179 * et de chaque attribut.
181 * @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
182 * @param[in] $load DN d'un objet similaire dont la valeur des attribut doit être chargé dans le formulaire.
184 * @author Benjamin Renard <brenard@easter-eggs.com>
186 * @retval LSform Le formulaire crée
188 function getForm($idForm,$load=NULL) {
189 LSsession :: loadLSclass('LSform');
190 $LSform = new LSform($this,$idForm);
191 $this -> forms[$idForm] = array($LSform,$load);
194 $type = $this -> getType();
195 $loadObject = new $type();
196 if (!$loadObject -> loadData($load)) {
202 foreach($this -> attrs as $attr_name => $attr) {
203 if(!$this -> attrs[$attr_name] -> addToForm($LSform,$idForm,$this,$loadObject -> attrs[$attr_name] -> getFormVal())) {
204 $LSform -> can_validate = false;
209 foreach($this -> attrs as $attr_name => $attr) {
210 if(!$this -> attrs[$attr_name] -> addToForm($LSform,$idForm,$this)) {
211 $LSform -> can_validate = false;
215 LSsession :: addJSconfigParam('LSform_'.$idForm,array(
216 'ajaxSubmit' => ((isset($this -> config['LSform']['ajaxSubmit']))?$this -> config['LSform']['ajaxSubmit']:1)
222 * Construit un formulaire de l'objet
224 * Cette méthode construit un formulaire LSform à partir de la configuration de l'objet
225 * et de chaque attribut.
227 * @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
228 * @param[in] $config Configuration spécifique pour le formulaire
230 * @author Benjamin Renard <brenard@easter-eggs.com>
232 * @retval LSform Le formulaire crée
235 LSsession :: loadLSclass('LSform');
236 $this -> view = new LSform($this,'view');
237 foreach($this -> attrs as $attr_name => $attr) {
238 $this -> attrs[$attr_name] -> addToView($this -> view);
240 $this -> view -> can_validate = false;
241 return $this -> view;
245 * Rafraichis le formulaire de l'objet
247 * Cette méthode recharge les données d'un formulaire LSform.
249 * @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
251 * @author Benjamin Renard <brenard@easter-eggs.com>
253 * @retval boolean true sile formulaire a été rafraichis, false sinon
255 function refreshForm($idForm) {
256 $LSform = $this -> forms[$idForm][0];
257 foreach($this -> attrs as $attr_name => $attr) {
258 if(!$this -> attrs[$attr_name] -> refreshForm($LSform,$idForm)) {
266 * Met à jour les données de l'objet et de l'entré de l'annuaire
268 * Met à jour les données de l'objet à partir d'un retour d'un formulaire.
270 * @param[in] $idForm Identifiant du formulaire d'origine
272 * @author Benjamin Renard <brenard@easter-eggs.com>
274 * @retval boolean true si la mise à jour a réussi, false sinon
276 * @see validateAttrsData()
277 * @see submitChange()
279 function updateData($idForm=NULL) {
281 if(isset($this -> forms[$idForm]))
282 $LSform = $this -> forms[$idForm][0];
284 LSerror :: addErrorCode('LSldapObject_02',$this -> getType());
289 if(count($this -> forms) > 0) {
290 reset($this -> forms);
291 $idForm = key($this -> forms);
292 $LSform = current($this -> forms);
293 $config = $LSform[1];
294 $LSform = $LSform[0];
297 LSerror :: addErrorCode('LSldapObject_03',$this -> getType());
301 $new_data = $LSform -> exportValues();
302 if(!is_array($new_data)) {
305 foreach($new_data as $attr_name => $attr_val) {
306 if(isset($this -> attrs[$attr_name])) {
307 $this -> attrs[$attr_name] -> setUpdateData($attr_val);
310 if($this -> validateAttrsData($idForm)) {
311 LSdebug("les données sont validées");
313 if (!$this -> fireEvent('before_modify')) {
317 // $this -> attrs[ {inNewData} ] -> fireEvent('before_modify')
318 foreach($new_data as $attr_name => $attr_val) {
319 if (!$this -> attrs[$attr_name] -> fireEvent('before_modify')) {
324 if ($this -> submitChange($idForm)) {
325 LSdebug('Les modifications sont submitées');
326 $this -> submitError = false;
327 $this -> reloadData();
328 $this -> refreshForm($idForm);
334 // Event After Modify
335 if(!$this -> submitError) {
336 $this -> fireEvent('after_modify');
339 // $this -> attrs[*] => After Modify
340 foreach($new_data as $attr_name => $attr_val) {
341 $this -> attrs[$attr_name] -> fireEvent('after_modify');
351 * Valide les données retournées par un formulaire
353 * @param[in] $idForm Identifiant du formulaire d'origine
355 * @author Benjamin Renard <brenard@easter-eggs.com>
357 * @retval boolean true si les données sont valides, false sinon
359 function validateAttrsData($idForm) {
361 $LSform=$this -> forms[$idForm][0];
362 foreach($this -> attrs as $attr) {
363 $attr_values = $attr -> getValue();
364 if (!$attr -> isValidate()) {
365 if($attr -> isUpdate()) {
366 if (!$this -> validateAttrData($LSform, $attr)) {
370 else if( (empty($attr_values)) && ($attr -> isRequired()) ) {
371 if ( $attr -> canBeGenerated()) {
372 if ($attr -> generateValue()) {
373 if (!$this -> validateAttrData($LSform, $attr)) {
374 LSerror :: addErrorCode('LSattribute_08',$attr -> getLabel());
379 LSerror :: addErrorCode('LSattribute_07',$attr -> getLabel());
384 LSerror :: addErrorCode('LSattribute_06',$attr -> getLabel());
394 * Valide les données d'un attribut
396 * @param[in] $LSForm Formulaire d'origine
397 * @param[in] &$attr Attribut à valider
399 * @author Benjamin Renard <brenard@easter-eggs.com>
401 * @retval boolean true si les données sont valides, false sinon
403 function validateAttrData(&$LSform,&$attr) {
406 $vconfig=$attr -> getValidateConfig();
408 $data=$attr -> getUpdateData();
409 if(!is_array($data)) {
413 // Validation des valeurs de l'attribut
414 if(is_array($vconfig)) {
415 foreach($vconfig as $test) {
416 // Définition du basedn par défaut
417 if (!isset($test['basedn'])) {
418 $test['basedn']=LSsession :: getTopDn();
421 // Définition du message d'erreur
422 if (!empty($test['msg'])) {
423 $msg_error=getFData($test['msg'],$this,'getValue');
426 $msg_error=getFData(_("The attribute %{attr} is not valid."),$attr -> getLabel());
428 foreach($data as $val) {
429 // validation par check LDAP
430 if((isset($test['filter'])||isset($test['basedn']))&&(isset($test['result']))) {
431 $sparams=(isset($test['scope']))?array('scope' => $test['scope']):array();
432 $this -> other_values['val']=$val;
433 $sfilter_user=(isset($test['basedn']))?getFData($test['filter'],$this,'getValue'):NULL;
434 if(isset($test['object_type'])) {
435 $test_obj = new $test['object_type']();
436 $sfilter=$test_obj->getObjectFilter();
437 $sfilter='(&'.$sfilter;
438 if($sfilter_user[0]=='(') {
439 $sfilter=$sfilter.$sfilter_user.')';
442 $sfilter=$sfilter.'('.$sfilter_user.'))';
446 $sfilter=$sfilter_user;
448 $sbasedn=(isset($test['basedn']))?getFData($test['basedn'],$this,'getValue'):NULL;
449 $ret=LSldap :: getNumberResult ($sfilter,$sbasedn,$sparams);
450 if($test['result']==0) {
452 $LSform -> setElementError($attr,$msg_error);
458 $LSform -> setElementError($attr,$msg_error);
463 // Validation par fonction externe
464 else if(isset($test['function'])) {
465 if (function_exists($test['function'])) {
466 if(!$test['function']($this)) {
467 $LSform -> setElementError($attr,$msg_error);
472 LSerror :: addErrorCode('LSldapObject_04',array('attr' => $attr->name,'obj' => $this->getType(),'func' => $test['function']));
477 LSerror :: addErrorCode('LSldapObject_05',array('attr' => $attr->name,'obj' => $this->getType()));
483 // Génération des valeurs des attributs dépendants
484 $dependsAttrs=$attr->getDependsAttrs();
485 if (!empty($dependsAttrs)) {
486 foreach($dependsAttrs as $dependAttr) {
487 if(!isset($this -> attrs[$dependAttr])){
488 LSerror :: addErrorCode('LSldapObject_14',array('attr_depend' => $dependAttr, 'attr' => $attr -> getLabel()));
491 if($this -> attrs[$dependAttr] -> canBeGenerated()) {
492 if (!$this -> attrs[$dependAttr] -> generateValue()) {
493 LSerror :: addErrorCode('LSattribute_07',$this -> attrs[$dependAttr] -> getLabel());
498 LSerror :: addErrorCode('LSattribute_06',$this -> attrs[$dependAttr] -> getLabel());
505 unset($this -> other_values['val']);
510 * Met à jour les données modifiés dans l'annuaire
512 * @param[in] $idForm Identifiant du formulaire d'origine
514 * @author Benjamin Renard <brenard@easter-eggs.com>
516 * @retval boolean true si la mise à jour a réussi, false sinon
518 function submitChange($idForm) {
520 $new = $this -> isNew();
521 foreach($this -> attrs as $attr) {
522 if(($attr -> isUpdate())&&($attr -> isValidate())) {
523 if(($attr -> name == $this -> config['rdn'])&&(!$new)) {
526 if (!$this -> fireEvent('before_rename')) {
527 LSerror :: addErrorCode('LSldapObject_16');
530 $oldDn = $this -> getDn();
532 $newDn = $this -> getDn();
534 if (!LSldap :: move($oldDn,$newDn)) {
537 $this -> dn = $newDn;
538 $this -> oldDn = $oldDn;
539 if (!$this -> fireEvent('after_rename')) {
540 LSerror :: addErrorCode('LSldapObject_17');
549 $submitData[$attr -> name] = $attr -> getUpdateData();
553 if(!empty($submitData)) {
554 $dn=$this -> getDn();
557 LSdebug($submitData);
559 if (!$this -> fireEvent('before_create')) {
560 LSerror :: addErrorCode('LSldapObject_20');
563 foreach ($submitData as $attr_name => $attr) {
564 if (!$this -> attrs[$attr_name] -> fireEvent('before_create')) {
565 LSerror :: addErrorCode('LSldapObject_20');
570 if (!LSldap :: update($this -> getType(),$dn, $submitData)) {
574 if (!$this -> fireEvent('after_create')) {
575 LSerror :: addErrorCode('LSldapObject_21');
578 foreach ($submitData as $attr_name => $attr) {
579 if (!$this -> attrs[$attr_name] -> fireEvent('after_create')) {
580 LSerror :: addErrorCode('LSldapObject_21');
588 LSerror :: addErrorCode('LSldapObject_13');
598 * Retourne les informations issus d'un DN
600 * @param[in] $dn Un DN.
602 * @author Benjamin Renard <brenard@easter-eggs.com>
604 * @retval array Tableau :
605 * - [0] : le premier paramètre
606 * - [1] : les paramètres suivants
608 function getDnInfos($dn) {
609 $infos=ldap_explode_dn($dn,0);
613 for($i=1;$i<$infos['count'];$i++)
619 $basedn.=','.$infos[$i];
620 return array($infos[0],$basedn);
624 * Retourne le filtre correpondants aux objetcClass de l'objet
626 * @author Benjamin Renard <brenard@easter-eggs.com>
628 * @retval string le filtre ldap correspondant au type de l'objet
630 function getObjectFilter($type=null) {
631 if (is_null($type)) {
632 $type = $this -> type_name;
634 $oc=LSconfig::get("LSobjects.$type.objectclass");
635 if(!is_array($oc)) return;
637 foreach ($oc as $class) {
638 $filters[]=Net_LDAP2_Filter::create('objectClass','equals',$class);
641 $filter=LSconfig::get("LSobjects.$type.filter");
646 $filter = LSldap::combineFilters('and',$filters,true);
649 LSerror :: addErrorCode('LSldapObject_30',$type);
654 * Retourne le filtre correpondants au pattern passé
656 * @author Benjamin Renard <brenard@easter-eggs.com>
658 * @param[in] $pattern string Le mot clé recherché
659 * @param[in] $approx booléen Booléen activant ou non la recherche approximative
661 * @retval string le filtre ldap correspondant
663 function getPatternFilter($pattern=null,$approx=null) {
664 if ($pattern!=NULL) {
665 if (is_array($this -> config['LSsearch']['attrs'])) {
666 $attrs=$this -> config['LSsearch']['attrs'];
669 $attrs=array($this -> config['rdn']);
673 foreach ($attrs as $attr_name) {
674 $pfilter.='('.$attr_name.'~='.$pattern.')';
678 foreach ($attrs as $attr_name) {
679 $pfilter.='('.$attr_name.'=*'.$pattern.'*)';
691 * Retourne une liste d'objet du même type.
693 * Effectue une recherche en fonction des paramètres passé et retourne un
694 * tableau d'objet correspond au resultat de la recherche.
696 * @author Benjamin Renard <brenard@easter-eggs.com>
698 * @param[in] $filter array (ou string) Filtre de recherche Ldap / Tableau de filtres de recherche
699 * @param[in] $basedn string DN de base pour la recherche
700 * @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
702 * @retval array Tableau d'objets correspondant au resultat de la recherche
704 function listObjects($filter=NULL,$basedn=NULL,$params=array()) {
705 if (!LSsession :: loadLSclass('LSsearch')) {
706 LSerror::addErrorCode('LSsession_05','LSsearch');
713 'attributes' => array('dn')
716 if (is_array($params)) {
717 $sparams=array_merge($sparams,$params);
719 $LSsearch = new LSsearch($this -> type_name,'LSldapObjet::listObjects',$sparams,true);
723 return $LSsearch -> listObjects();
726 for($i=0;$i<count($ret);$i++) {
727 $retInfos[$i] = new $this -> type_name($this -> config);
728 $retInfos[$i] -> loadData($ret[$i]['dn']);
736 * Recherche les objets du même type dans l'annuaire
738 * Effectue une recherche en fonction des paramètres passé et retourne un
739 * tableau array(dn => '', attrs => array()) d'objet correspondant au resultat*
742 * @author Benjamin Renard <brenard@easter-eggs.com>
744 * @param[in] $filter array (ou string) Filtre de recherche Ldap / Tableau de filtres de recherche
745 * @param[in] $basedn string DN de base pour la recherche
746 * @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
748 * @retval array Tableau d'objets correspondant au resultat de la recherche
751 function search($filter='',$basedn=NULL,$params=array()) {
754 $check_final_dn=false;
756 if(!is_array($filter))
757 $filter=array(array('filter' => $filter));
759 $nbFilter=count($filter);
761 for($i=0;$i<$nbFilter;$i++) {
763 // Défintion des paramètres de base pour la recherche
767 if (isset($filter[$i]['scope']))
768 $sparams["scope"]=$filter[$i]['scope'];
770 // Definition des critères de recherche correspondant au type d'objet à lister
771 if(($nbFilter==1)||(!isset($filter[$i]['attr']))) {
772 // Filtre sur l'objet souhaité
774 $sfilter.=$this -> getObjectFilter();
776 $check_final_dn=true;
778 // Initialisation des critères d'une recherche intermédiaire
780 if(isset($filter[$i]['object_type'])) {
781 $obj_tmp=new $filter[$i]['object_type']();
782 $obj_filter=$obj_tmp->getObjectFilter();
783 $sfilter='(&'.$obj_filter;
790 if(isset($filter[$i]['scope'])) {
791 $sparams['scope']=$filter[$i]['scope'];
793 if(isset($filter[$i]['basedn'])) {
794 $sbasedn=$filter[$i]['basedn'];
797 // Dans le cas d'une recherche intermédiaire ou finale
799 // Initialisation des variables
803 // Pour tout les attributs retournés
804 for($ii=0;$ii<count($attrs);$ii++) {
806 // Définition du filtre de recherche à partir des paramètres utilisateurs et
807 // des paramètres de recherche de l'objet à listé (dans le cas d'une recherche finale
808 if((isset($filter[$i]['filter']))&&(!empty($filter[$i]['filter']))) {
809 $sfilter_user=getFData($filter[$i]['filter'],$attrs[$ii]);
810 if($sfilter_user[0]=='(')
811 $sfilter_for=$sfilter.$sfilter_user;
813 $sfilter_for=$sfilter.'('.$sfilter_user.')';
816 $sfilter_for=$sfilter;
819 if(isset($filter[$i]['basedn'])) {
820 $sbasedn=getFData($filter[$i]['basedn'],$attrs[$ii]);
821 if ((!$this -> isCompatibleDNs($sbasedn,$basedn))&&($check_final_dn)) continue;
824 // Vérification de la compatibilité du basedn de la recherche et du basedn générale
825 // Finalisation du filtre
826 $sfilter_for.=$sfilter_end;
830 if ($filter[$i]['attr']) {
831 $sparams['attributes'] = array($filter[$i]['attr']);
833 else if (!isset($sparams['attributes'])) {
834 $sparams['attributes'] = array($this -> config['rdn']);
837 // Execution de la recherche
838 $ret=LSldap :: search ($sfilter_for,$sbasedn,$sparams);
842 // si il ya une suite (recherche intermédiaire)
843 if($filter[$i]['attr']){
844 for($iii=0;$iii<count($ret);$iii++) {
845 if(isset($ret[$iii]['attrs'][$filter[$i]['attr']])) {
846 // cas de valeur multiple
847 if(is_array($ret[$iii]['attrs'][$filter[$i]['attr']])) {
848 foreach($ret[$iii]['attrs'][$filter[$i]['attr']] as $val_attr) {
849 $new_attrs[]=$val_attr;
852 // cas de valeur unique
854 $new_attrs[]=$ret[$iii]['attrs'][$filter[$i]['attr']];
861 // cas du dernier filtre
862 if(!empty($ret_gen)) {
865 // dans le cas d'une suite prévu mais d'un retour nul de la précédente recherche
866 else if(empty($new_attrs)) {
867 // retour vide et arrêt de la recherche
875 // Dans le cas de la recherche initiale
877 // Déclaration du filtre de recherche
878 if((isset($filter[$i]['filter']))&&(!empty($filter[$i]['filter']))) {
879 if($filter[$i]['filter'][0]=='(') {
880 $sfilter.=$filter[$i]['filter'];
883 $sfilter.='('.$filter[$i]['filter'].')';
886 // fermeture du filtre
887 $sfilter.=$sfilter_end;
890 if (!isset($sparams['attributes'])) {
891 $sparams['attributes'] = array($this -> config['rdn']);
894 // Lancement de la recherche
895 $ret=LSldap :: search ($sfilter,$sbasedn,$sparams);
897 //Si filtre multiple => on recupère une liste d'attributs
898 if(isset($filter[$i]['attr'])) {
899 for($ii=0;$ii<count($ret);$ii++) {
900 if(isset($ret[$ii]['attrs'][$filter[$i]['attr']])) {
901 // cas de valeur multiple
902 if(is_array($ret[$ii]['attrs'][$filter[$i]['attr']])) {
903 foreach($ret[$ii]['attrs'][$filter[$i]['attr']] as $val_attr) {
907 // cas de valeur unique
909 $attrs[]=$ret[$ii]['attrs'][$filter[$i]['attr']];
914 // Si aucunne valeur n'est retournées
916 // arrêt et retour à zéro
921 // Si recherche unique
923 // préparation du retour finale
924 if (!is_array($ret)) {
936 * Retourne une liste d'objet du même type et retourne leur noms
938 * Effectue une recherche en fonction des paramètres passé et retourne un
939 * tableau (dn => nom) correspondant au resultat de la recherche.
941 * @author Benjamin Renard <brenard@easter-eggs.com>
943 * @param[in] $filter string Filtre de recherche Ldap
944 * @param[in] $basedn string DN de base pour la recherche
945 * @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
946 * @param[in] $displayFormat string Format d'affichage du nom des objets
948 * @retval array Tableau dn => name correspondant au resultat de la recherche
950 function listObjectsName($filter=NULL,$sbasedn=NULL,$sparams=array(),$displayFormat=false,$cache=true) {
951 if (!LSsession :: loadLSclass('LSsearch')) {
952 LSerror::addErrorCode('LSsession_05','LSsearch');
956 if (!$displayFormat) {
957 $displayFormat = $this -> getDisplayNameFormat();
961 'displayFormat' => $displayFormat,
962 'basedn' => $sbasedn,
966 if (is_array($sparams)) {
967 $params=array_merge($sparams,$params);
970 $LSsearch = new LSsearch($this -> type_name,'LSldapObject::listObjectsName',$params,true);
972 $LSsearch -> run($cache);
974 return $LSsearch -> listObjectsName();
979 * Recherche un objet à partir de la valeur exact de son RDN ou d'un filtre de
980 * recherche LDAP sous la forme d'un LSformat qui sera construit avec la valeur
983 * @author Benjamin Renard <brenard@easter-eggs.com>
985 * @param[in] $name string Valeur de son RDN ou de la valeur pour composer le filtre
986 * @param[in] $basedn string Le DN de base de la recherche
987 * @param[in] $filter string Le filtre de recherche de l'objet
988 * @param[in] $params array Tableau de paramètres
990 * @retval array Tableau d'objets correspondant au resultat de la recherche
992 function searchObject($name,$basedn=NULL,$filter=NULL,$params=NULL) {
994 $filter = '('.$this -> config['rdn'].'='.$name.')';
997 $filter = getFData($filter,$name);
999 return $this -> listObjects($filter,$basedn,$params);
1003 * Retourne une valeur de l'objet
1005 * Retourne une valeur en fonction du paramètre. Si la valeur est inconnue, la valeur retourné est ' '.
1006 * tableau d'objet correspond au resultat de la recherche.
1008 * Valeurs possibles :
1009 * - 'dn' ou '%{dn} : DN de l'objet
1010 * - [nom d'un attribut] : valeur de l'attribut
1011 * - [clef de $this -> other_values] : valeur de $this -> other_values
1013 * @author Benjamin Renard <brenard@easter-eggs.com>
1015 * @param[in] $val string Le nom de la valeur demandée
1017 * @retval mixed la valeur demandé ou ' ' si celle-ci est inconnue.
1019 function getValue($val) {
1020 if(($val=='dn')||($val=='%{dn}')) {
1023 else if(($val=='rdn')||($val=='%{rdn}')) {
1024 return $this -> attrs[ $this -> config['rdn'] ] -> getValue();
1026 else if(($val=='subDn')||($val=='%{subDn}')) {
1027 return $this -> subDnValue;
1029 else if(($val=='subDnName')||($val=='%{subDnName}')) {
1030 return $this -> subDnName;
1032 else if(isset($this -> attrs[$val])){
1033 if (method_exists($this -> attrs[$val],'getValue'))
1034 return $this -> attrs[$val] -> getValue();
1038 else if(isset($this -> other_values[$val])){
1039 return $this -> other_values[$val];
1047 * Retourn un tableau pour un select d'un objet du même type
1049 * @author Benjamin Renard <brenard@easter-eggs.com>
1051 * @retval array('dn' => 'display')
1053 function getSelectArray($pattern=NULL,$topDn=NULL,$displayFormat=NULL,$approx=false,$cache=true) {
1054 return $this -> listObjectsName($filter,$topDn,array('pattern' => $pattern),$displayFormat,$cache);
1058 * Retourne le DN de l'objet
1060 * Cette methode retourne le DN de l'objet. Si celui-ci n'existe pas, il le construit à partir de la
1061 * configuration de l'objet et la valeur de son attribut rdn.
1063 * @author Benjamin Renard <brenard@easter-eggs.com>
1065 * @retval string Le DN de l'objet
1072 $rdn_attr=$this -> config['rdn'];
1073 $topDn = LSsession :: getTopDn();
1074 if( (isset($this -> config['rdn'])) && (isset($this -> attrs[$rdn_attr])) && (isset($this -> config['container_dn'])) && ($topDn) ) {
1075 $rdn_val=$this -> attrs[$rdn_attr] -> getUpdateData();
1076 if (!empty($rdn_val)) {
1077 return $rdn_attr.'='.$rdn_val[0].','.$this -> config['container_dn'].','.$topDn;
1080 LSerror :: addErrorCode('LSldapObject_12',$this -> config['rdn']);
1085 LSerror :: addErrorCode('LSldapObject_11',$this -> getType());
1092 * Retourne le type de l'objet
1094 * @author Benjamin Renard <brenard@easter-eggs.com>
1096 * @retval string Le type de l'objet ($this -> type_name)
1098 function getType() {
1099 return $this -> type_name;
1103 * Retourne qui est l'utilisateur par rapport à cet object
1105 * @author Benjamin Renard <brenard@easter-eggs.com>
1107 * @retval string 'admin'/'self'/'user' pour Admin , l'utilisateur lui même ou un simple utilisateur
1110 if (!$this -> _whoami)
1111 $this -> _whoami = LSsession :: whoami($this -> dn);
1112 return $this -> _whoami;
1116 * Retourne le label de l'objet
1118 * @author Benjamin Renard <brenard@easter-eggs.com>
1120 * @retval string Le label de l'objet ($this -> config['label'])
1122 function getLabel($type=null) {
1123 if (is_null($type)) {
1124 $type = $this -> type_name;
1126 return __(LSconfig::get("LSobjects.$type.label"));
1131 * Supprime l'objet dans l'annuaire
1133 * @author Benjamin Renard <brenard@easter-eggs.com>
1135 * @retval boolean True si l'objet à été supprimé, false sinon
1138 if ($this -> fireEvent('before_delete')) {
1139 if (LSldap :: remove($this -> getDn())) {
1140 if ($this -> fireEvent('after_delete')) {
1143 LSerror :: addErrorCode('LSldapObject_19');
1147 LSerror :: addErrorCode('LSldapObject_18');
1153 * L'objet est-il nouveau
1155 * @author Benjamin Renard <brenard@easter-eggs.com>
1157 * @retval boolean True si l'objet est nouveau, false sinon
1160 return (!$this -> dn);
1164 * Retourne la valeur (DN) du subDn de l'objet
1166 * @parram[in] $dn string Un DN
1168 * @return string La valeur du subDn de l'object
1170 public static function getSubDnValue($dn) {
1172 $subDnLdapServer = LSsession :: getSortSubDnLdapServer();
1173 foreach ($subDnLdapServer as $subDn => $subDn_name) {
1174 if (isCompatibleDNs($subDn,$dn)&&($subDn!=$dn)) {
1175 $subDn_value=$subDn;
1179 return $subDn_value;
1183 * Retourne la nom du subDn de l'objet
1185 * @parram[in] $dn string Un DN
1187 * @return string Le nom du subDn de l'object
1189 public static function getSubDnName($dn) {
1190 $subDnLdapServer = LSsession :: getSortSubDnLdapServer();
1191 return $subDnLdapServer[self :: getSubDnValue($dn)];
1195 * Methode créant la liste des objets en relations avec l'objet courant et qui
1196 * la met en cache ($this -> _LSrelationsCache)
1198 * @retval True en cas de cas ce succès, False sinon.
1200 function updateLSrelationsCache() {
1201 $this -> _LSrelationsCache=array();
1202 if (is_array($this->config['LSrelation'])) {
1203 $type = $this -> getType();
1205 $me -> loadData($this -> getDn());
1206 foreach($this->config['LSrelation'] as $relation_name => $relation_conf) {
1207 if ( isset($relation_conf['list_function']) ) {
1208 if (LSsession :: loadLSobject($relation_conf['LSobject'])) {
1209 $obj = new $relation_conf['LSobject']();
1210 if ((method_exists($obj,$relation_conf['list_function']))&&(method_exists($obj,$relation_conf['getkeyvalue_function']))) {
1211 $list = $obj -> $relation_conf['list_function']($me);
1212 if (is_array($list)) {
1214 $key = $obj -> $relation_conf['getkeyvalue_function']($me);
1216 $this -> _LSrelationsCache[$relation_name] = array(
1222 LSdebug('Problème durant la mise en cache de la relation '.$relation_name);
1227 LSdebug('Les méthodes de mise en cache de la relation '.$relation_name. ' ne sont pas toutes disponibles.');
1241 * Methode executant les actions nécéssaires avant le changement du DN de
1244 * Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
1245 * pour les objets plus complexe.
1247 * @retval True en cas de cas ce succès, False sinon.
1249 function beforeRename() {
1251 return $this -> updateLSrelationsCache();
1255 * Methode executant les actions nécéssaires après le changement du DN de
1258 * Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
1259 * pour les objets plus complexe.
1261 * @retval True en cas de cas ce succès, False sinon.
1263 function afterRename() {
1266 // Change LSsession -> userObject Dn
1267 if(LSsession :: getLSuserObjectDn() == $this -> oldDn) {
1268 LSsession :: changeAuthUser($this);
1272 foreach($this -> _LSrelationsCache as $relation_name => $objInfos) {
1273 if ((isset($this->config['LSrelation'][$relation_name]['rename_function']))&&(is_array($objInfos['list']))) {
1274 foreach($objInfos['list'] as $obj) {
1275 $meth = $this->config['LSrelation'][$relation_name]['rename_function'];
1276 if (method_exists($obj,$meth)) {
1277 if (!($obj -> $meth($this,$objInfos['keyvalue']))) {
1291 * Methode executant les actions nécéssaires avant la suppression de
1294 * Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
1295 * pour les objets plus complexe.
1297 * @retval True en cas de cas ce succès, False sinon.
1299 function beforeDelete() {
1300 $return = $this -> updateLSrelationsCache();
1302 foreach(array_keys($this -> attrs) as $attr_name) {
1303 if (!$this -> attrs[$attr_name] -> fireEvent('before_delete')) {
1312 * Methode executant les actions nécéssaires après la suppression de
1315 * Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
1316 * pour les objets plus complexe.
1318 * @retval True en cas de cas ce succès, False sinon.
1320 function afterDelete() {
1324 foreach($this -> _LSrelationsCache as $relation_name => $objInfos) {
1325 if ((isset($this->config['LSrelation'][$relation_name]['remove_function']))&&(is_array($objInfos['list']))) {
1326 foreach($objInfos['list'] as $obj) {
1327 $meth = $this->config['LSrelation'][$relation_name]['remove_function'];
1328 if (method_exists($obj,$meth)) {
1329 if (!($obj -> $meth($this))) {
1340 // Binding LSattributes
1341 foreach(array_keys($this -> attrs) as $attr_name) {
1342 if (!$this -> attrs[$attr_name] -> fireEvent('after_delete')) {
1347 // LSsearch : Purge LSobject cache
1348 if (LSsession :: loadLSclass('LSsearch')) {
1349 LSsearch :: purgeCache($this -> type_name);
1356 * Methode executant les actions nécéssaires après la création de
1359 * Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
1360 * pour les objets plus complexe.
1362 * @retval True en cas de cas ce succès, False sinon.
1364 function afterCreate() {
1368 // container_auto_create
1369 if (LSsession :: isSubDnLSobject($this -> getType())) {
1370 if (is_array(LSsession :: $ldapServer['subDn']['LSobject'][$this -> getType()]['LSobjects'])) {
1371 foreach(LSsession :: $ldapServer['subDn']['LSobject'][$this -> getType()]['LSobjects'] as $type) {
1372 if (LSsession :: loadLSobject($type)) {
1373 $conf_type=LSconfig :: get("LSobjects.$type");
1374 if (isset($conf_type['container_auto_create'])&&isset($conf_type['container_dn'])) {
1375 $dn = $conf_type['container_dn'].','.$this -> getDn();
1376 if(!LSldap :: getNewEntry($dn,$conf_type['container_auto_create']['objectclass'],$conf_type['container_auto_create']['attrs'],true)) {
1377 LSdebug("Impossible de créer l'entrée fille : ".print_r(
1380 'objectClass' => $conf_type['container_auto_create']['objectclass'],
1381 'attrs' => $conf_type['container_auto_create']['attrs']
1395 // LSsearch : Purge LSobject cache
1396 if (LSsession :: loadLSclass('LSsearch')) {
1397 LSsearch :: purgeCache($this -> type_name);
1404 * Methode executant les actions nécéssaires après la modification de
1407 * Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
1408 * pour les objets plus complexe.
1410 * @retval True en cas de cas ce succès, False sinon.
1412 function afterModify() {
1415 // LSsearch : Purge LSobject cache
1416 if (LSsession :: loadLSclass('LSsearch')) {
1417 LSsearch :: purgeCache($this -> type_name);
1424 * Retourne la valeur clef d'un objet en relation
1426 * @param[in] $object Un object de type $objectType
1427 * @param[in] $attr L'attribut dans lequel l'objet doit apparaitre
1428 * @param[in] $objectType Le type d'objet en relation
1429 * @param[in] $value La valeur que doit avoir l'attribut :
1430 * - soit le dn (par defaut)
1431 * - soit la valeur [0] d'un attribut
1433 * @retval Mixed La valeur clef d'un objet en relation
1435 function getObjectKeyValueInRelation($object,$attr,$objectType,$attrValue='dn') {
1436 if ((!$attr)||(!$objectType)) {
1437 LSerror :: addErrorCode('LSrelations_05','getObjectKeyValueInRelation');
1440 if ($attrValue=='dn') {
1441 $val = $object -> getDn();
1444 $val = $object -> getValue($attrValue);
1451 * Retourne la liste des relations pour l'objet en fonction de sa présence
1452 * dans un des attributs
1454 * Retourne un tableau de d'objet (type : $objectType) correspondant à la
1455 * relation entre l'objet $object et les objets de type $objectType. Cette relation
1456 * est établis par la présence de la valeur de référence à l'objet dans
1457 * l'attribut des objets de type $objectType.
1459 * @param[in] $object Un object de type $objectType
1460 * @param[in] $attr L'attribut dans lequel l'objet doit apparaitre
1461 * @param[in] $objectType Le type d'objet en relation
1462 * @param[in] $value La valeur que doit avoir l'attribut :
1463 * - soit le dn (par defaut)
1464 * - soit la valeur [0] d'un attribut
1466 * @retval Array of $objectType Les objets en relations
1468 function listObjectsInRelation($object,$attr,$objectType,$attrValue='dn') {
1469 if ((!$attr)||(!$objectType)) {
1470 LSerror :: addErrorCode('LSrelations_05','listObjectsInRelation');
1473 if ($attrValue=='dn') {
1474 $val = $object -> getDn();
1477 $val = $object -> getValue($attrValue);
1481 $filter = Net_LDAP2_Filter::create($attr,'equals',$val);
1482 return $this -> listObjects($filter,LSsession :: getRootDn(),array('scope' => 'sub','recursive' => true,'withoutCache'=>true));
1488 * Ajoute un objet en relation dans l'attribut $attr de $this
1490 * @param[in] $object Un objet de type $objectType à ajouter
1491 * @param[in] $attr L'attribut dans lequel l'objet doit être ajouté
1492 * @param[in] $objectType Le type d'objet en relation
1493 * @param[in] $attrValue La valeur que doit avoir l'attribut :
1494 * - soit le dn (par defaut)
1495 * - soit la valeur [0] d'un attribut
1496 * @param[in] $canEditFunction Le nom de la fonction pour vérifier que la
1497 * relation avec l'objet est éditable par le user
1499 * @retval boolean true si l'objet à été ajouté, False sinon
1501 function addOneObjectInRelation($object,$attr,$objectType,$attrValue='dn',$canEditFunction=NULL) {
1502 if ((!$attr)||(!$objectType)) {
1503 LSerror :: addErrorCode('LSrelations_05','addOneObjectInRelation');
1506 if ($object instanceof $objectType) {
1507 if ($canEditFunction) {
1508 if (!$this -> $canEditFunction()) {
1509 LSerror :: addErrorCode('LSsession_11');
1513 if ($this -> attrs[$attr] instanceof LSattribute) {
1514 if ($attrValue=='dn') {
1515 $val = $object -> getDn();
1518 $val = $object -> getValue($attrValue);
1521 $values = $this -> attrs[$attr] -> getValue();
1522 if ($this -> attrs[$attr] -> config['multiple']) {
1523 if (!is_array($values)) {
1524 $updateData = array($val);
1526 else if (!in_array($val,$values)) {
1528 $updateData = $values;
1532 if (($values[0]!=$val)&&($values!=$val)) {
1533 $updateData = array($val);
1536 if (isset($updateData)) {
1537 return LSldap :: update($this -> getType(),$this -> getDn(), array($attr => $updateData));
1546 * Supprime un objet en relation dans l'attribut $attr de $this
1548 * @param[in] $object Un objet de type $objectType à supprimer
1549 * @param[in] $attr L'attribut dans lequel l'objet doit être supprimé
1550 * @param[in] $objectType Le type d'objet en relation
1551 * @param[in] $attrValue La valeur que doit avoir l'attribut :
1552 * - soit le dn (par defaut)
1553 * - soit la valeur [0] d'un attribut
1554 * @param[in] $canEditFunction Le nom de la fonction pour vérifier que la
1555 * relation avec l'objet est éditable par le user
1557 * @retval boolean true si l'objet à été supprimé, False sinon
1559 function deleteOneObjectInRelation($object,$attr,$objectType,$attrValue='dn',$canEditFunction=NULL) {
1560 if ((!$attr)||(!$objectType)) {
1561 LSerror :: addErrorCode('LSrelations_05','deleteOneObjectInRelation');
1564 if ($object instanceof $objectType) {
1565 if ($canEditFunction) {
1566 if (!$this -> $canEditFunction()) {
1567 LSerror :: addErrorCode('LSsession_11');
1571 if ($this -> attrs[$attr] instanceof LSattribute) {
1572 if ($attrValue=='dn') {
1573 $val = $object -> getDn();
1576 $val = $object -> getValue($attrValue);
1579 $values = $this -> attrs[$attr] -> getValue();
1580 if ((!is_array($values)) && (!empty($values))) {
1581 $values = array($values);
1583 if (is_array($values)) {
1584 $updateData=array();
1585 foreach($values as $value) {
1587 $updateData[]=$value;
1590 return LSldap :: update($this -> getType(),$this -> getDn(), array($attr => $updateData));
1598 * Renome un objet en relation dans l'attribut $attr de $this
1600 * @param[in] $object Un objet de type $objectType à renomer
1601 * @param[in] $oldValue string L'ancienne valeur faisant référence à l'objet
1602 * @param[in] $attr L'attribut dans lequel l'objet doit être supprimé
1603 * @param[in] $objectType Le type d'objet en relation
1604 * @param[in] $attrValue La valeur que doit avoir l'attribut :
1605 * - soit le dn (par defaut)
1606 * - soit la valeur [0] d'un attribut
1608 * @retval boolean True en cas de succès, False sinon
1610 function renameOneObjectInRelation($object,$oldValue,$attr,$objectType,$attrValue='dn') {
1611 if ((!$attr)||(!$objectType)) {
1612 LSerror :: addErrorCode('LSrelations_05','renameOneObjectInRelation');
1615 if ($object instanceof $objectType) {
1616 if ($this -> attrs[$attr] instanceof LSattribute) {
1617 $values = $this -> attrs[$attr] -> getValue();
1618 if ((!is_array($values)) && (!empty($values))) {
1619 $values = array($values);
1621 if (is_array($values)) {
1622 $updateData=array();
1623 foreach($values as $value) {
1624 if ($value!=$oldValue) {
1625 $updateData[] = $value;
1628 if ($attrValue=='dn') {
1629 $val = $object -> getDn();
1632 $val = $object -> getValue($attrValue);
1635 $updateData[] = $val;
1638 return LSldap :: update($this -> getType(),$this -> getDn(), array($attr => $updateData));
1646 * Met à jour les objets du meme type que $this en relation avec l'objet $object
1647 * de type $objectType en modifiant la valeur de leur attribut $attr des objets
1650 * @param[in] $object Mixed Un object (type : $this -> userObjectType) : l'utilisateur
1651 * @param[in] $listDns Array(string) Un tableau des DNs des objets en relation
1652 * @param[in] $attr L'attribut dans lequel l'utilisateur doit apparaitre
1653 * @param[in] $objectType Le type d'objet en relation
1654 * @param[in] $attrValue La valeur que doit avoir l'attribut :
1655 * - soit le dn (par defaut)
1656 * - soit la valeur [0] d'un attribut
1657 * @param[in] $canEditFunction Le nom de la fonction pour vérifier que la
1658 * relation avec l'objet est éditable par le user
1660 * @retval boolean true si tout c'est bien passé, False sinon
1662 function updateObjectsInRelation($object,$listDns,$attr,$objectType,$attrValue='dn',$canEditFunction=NULL) {
1663 if ((!$attr)||(!$objectType)) {
1664 LSerror :: addErrorCode('LSrelations_05','updateObjectsInRelation');
1667 $currentObjects = $this -> listObjectsInRelation($object,$attr,$objectType,$attrValue);
1668 $type=$this -> getType();
1669 if(is_array($currentObjects)) {
1670 if (is_array($listDns)) {
1672 if ($attrValue!='dn') {
1673 $obj=new $objectType();
1674 foreach ($listDns as $dn) {
1675 $obj -> loadData($dn);
1676 $val = $obj -> getValue($attrValue);
1677 $values[$dn] = $val[0];
1681 foreach($listDns as $dn) {
1685 $dontDelete=array();
1687 for ($i=0;$i<count($currentObjects);$i++) {
1688 if ($attrValue=='dn') {
1689 $val = $currentObjects[$i] -> getDn();
1692 $val = $currentObjects[$i] -> getValue($attrValue);
1695 if (in_array($val, $listDns)) {
1696 $dontDelete[$i]=true;
1701 for($i=0;$i<count($currentObjects);$i++) {
1702 if ($dontDelete[$i]) {
1706 if (!$currentObjects[$i] -> deleteOneObjectInRelation($object,$attr,$objectType,$attrValue,$canEditFunction)) {
1712 foreach($values as $dn => $val) {
1713 if (in_array($val,$dontAdd)) {
1718 if ($obj -> loadData($dn)) {
1719 if (!$obj -> addOneObjectInRelation($object,$attr,$objectType,$attrValue,$canEditFunction)) {
1732 if(!is_array($listDns)) {
1735 foreach($listDns as $dn) {
1737 if ($obj -> loadData($dn)) {
1738 if (!$obj -> addOneObjectInRelation($object,$attr,$objectType,$attrValue,$canEditFunction)) {
1750 * Ajouter une action lors d'un événement
1752 * @param[in] $event string Le nom de l'événement
1753 * @param[in] $fct string Le nom de la fonction à exectuer
1754 * @param[in] $param mixed Paramètre pour le lancement de la fonction
1755 * @param[in] $class Nom de la classe possèdant la méthode $fct à executer
1759 function addEvent($event,$fct,$param=NULL,$class=NULL) {
1760 $this -> _events[$event][] = array(
1768 * Ajouter une action sur un objet lors d'un événement
1770 * @param[in] $event string Le nom de l'événement
1771 * @param[in] $obj object L'objet dont la méthode doit être executé
1772 * @param[in] $meth string Le nom de la méthode
1773 * @param[in] $param mixed Paramètre d'execution de la méthode
1777 function addObjectEvent($event,&$obj,$meth,$param=NULL) {
1778 $this -> _objectEvents[$event][] = array(
1786 * Lance les actions à executer lors d'un événement
1788 * @param[in] $event string Le nom de l'événement
1790 * @retval boolean True si tout c'est bien passé, false sinon
1792 function fireEvent($event) {
1795 $return = $this -> fireObjectEvent($event);
1798 if(isset($this -> config[$event])) {
1799 if (!is_array($this -> config[$event])) {
1800 $funcs = array($this -> config[$event]);
1803 $funcs = $this -> config[$event];
1805 foreach($funcs as $func) {
1806 if(function_exists($func)) {
1809 LSerror :: addErrorCode('LSldapObject_07',array('func' => $func,'event' => $event));
1814 LSerror :: addErrorCode('LSldapObject_06',array('func' => $func,'event' => $event));
1819 // Binding via addEvent
1820 if (is_array($this -> _events[$event])) {
1821 foreach ($this -> _events[$event] as $e) {
1823 if (class_exists($e['class'])) {
1824 $obj = new $e['class']();
1825 if (method_exists($obj,$e['fct'])) {
1827 $obj -> $e['fct']($e['param']);
1829 catch(Exception $er) {
1830 LSerror :: addErrorCode('LSldapObject_10',array('class' => $e['class'],'meth' => $e['fct'],'event' => $event));
1835 LSerror :: addErrorCode('LSldapObject_09',array('class' => $e['class'],'meth' => $e['fct'],'event' => $event));
1840 LSerror :: addErrorCode('LSldapObject_08',array('class' => $e['class'],'meth' => $e['fct'],'event' => $event));
1845 if (function_exists($e['fct'])) {
1847 $e['fct']($e['param']);
1849 catch(Exception $er) {
1850 LSerror :: addErrorCode('LSldapObject_27',array('func' => $e['fct'],'event' => $event));
1855 LSerror :: addErrorCode('LSldapObject_26',array('func' => $e['fct'],'event' => $event));
1862 // Binding via addObjectEvent
1863 if (is_array($this -> _objectEvents[$event])) {
1864 foreach ($this -> _objectEvents[$event] as $e) {
1865 if (method_exists($e['obj'],$e['meth'])) {
1867 $e['obj'] -> $e['meth']($e['param']);
1869 catch(Exception $er) {
1870 LSerror :: addErrorCode('LSldapObject_29',array('meth' => $e['meth'],'event' => $event));
1875 LSerror :: addErrorCode('LSldapObject_28',array('meth' => $e['meth'],'event' => $event));
1885 * Lance les actions à executer lors d'un événement sur l'objet lui-même
1887 * @param[in] $event string Le nom de l'événement
1889 * @retval boolean True si tout c'est bien passé, false sinon
1891 function fireObjectEvent($event) {
1893 case 'after_create':
1894 return $this -> afterCreate();
1895 case 'after_delete':
1896 return $this -> afterDelete();
1897 case 'after_rename':
1898 return $this -> afterRename();
1899 case 'after_modify':
1900 return $this -> afterModify();
1902 case 'before_create':
1903 return $this -> beforeCreate();
1905 case 'before_delete':
1906 return $this -> beforeDelete();
1907 case 'before_rename':
1908 return $this -> beforeRename();
1910 case 'before_modify':
1911 return $this -> beforeModify();
1918 * Access to infos of the object
1920 * @param[in] $key string The name of the value
1922 * @retval mixed The value
1924 function __get($key) {
1925 if ($key=='subDnValue') {
1926 if ($this -> cache['subDnValue']) {
1927 return $this -> cache['subDnValue'];
1929 $this -> cache['subDnValue'] = self :: getSubDnValue($this -> dn);
1930 return $this -> cache['subDnValue'];
1932 if ($key=='subDnName') {
1933 if ($this -> cache['subDnName']) {
1934 return $this -> cache['subDnName'];
1936 $this -> cache['subDnName'] = self :: getSubDnName($this -> dn);
1937 return $this -> cache['subDnName'];
1946 LSerror :: defineError('LSldapObject_01',
1947 _("LSldapObject : Object type unknown.")
1949 LSerror :: defineError('LSldapObject_02',
1950 _("LSldapObject : Update form is not defined for the object %{obj}.")
1952 LSerror :: defineError('LSldapObject_03',
1953 _("LSldapObject : No form exists for the object %{obj}.")
1955 LSerror :: defineError('LSldapObject_04',
1956 _("LSldapObject : The function %{func} to validate the attribute %{attr} the object %{obj} is unknow.")
1958 LSerror :: defineError('LSldapObject_05',
1959 _("LSldapObject : Configuration data are missing to validate the attribute %{attr} of the object %{obj}.")
1962 LSerror :: defineError('LSldapObject_06',
1963 _("LSldapObject : The function %{func} to be executed on the object event %{event} doesn't exist.")
1965 LSerror :: defineError('LSldapObject_07',
1966 _("LSldapObject : The %{func} execution on the object event %{event} failed.")
1969 LSerror :: defineError('LSldapObject_08',
1970 _("LSldapObject : Class %{class}, which method %{meth} to be executed on the object event %{event}, doesn't exist.")
1972 LSerror :: defineError('LSldapObject_09',
1973 _("LSldapObject : Method %{meth} within %{class} class to be executed on object event %{event}, doesn't exist.")
1975 LSerror :: defineError('LSldapObject_10',
1976 _("LSldapObject : Error during execute %{meth} method within %{class} class, to be executed on object event %{event}.")
1979 LSerror :: defineError('LSldapObject_11',
1980 _("LSldapObject : Some configuration data of the object type %{obj} are missing to generate the DN of the new object.")
1982 LSerror :: defineError('LSldapObject_12',
1983 _("LSldapObject : The attibute %{attr} of the object is not yet defined. Can't generate DN.")
1985 LSerror :: defineError('LSldapObject_13',
1986 _("LSldapObject : Without DN, the object could not be changed.")
1988 LSerror :: defineError('LSldapObject_14',
1989 _("LSldapObject : The attribute %{attr_depend} depending on the attribute %{attr} doesn't exist.")
1991 LSerror :: defineError('LSldapObject_15',
1992 _("LSldapObject : Error during deleting the object %{objectname}.")
1995 LSerror :: defineError('LSldapObject_16',
1996 _("LSldapObject : Error during actions to be executed before renaming the objet.")
1998 LSerror :: defineError('LSldapObject_17',
1999 _("LSldapObject : Error during actions to be executed after renaming the objet.")
2002 LSerror :: defineError('LSldapObject_18',
2003 _("LSldapObject : Error during actions to be executed before deleting the objet.")
2005 LSerror :: defineError('LSldapObject_19',
2006 _("LSldapObject : Error during actions to be executed after deleting the objet.")
2009 LSerror :: defineError('LSldapObject_20',
2010 _("LSldapObject : Error during the actions to be executed before creating the object.")
2012 LSerror :: defineError('LSldapObject_21',
2013 _("LSldapObject : Error during the actions to be executed after creating the object. It was created anyway.")
2016 LSerror :: defineError('LSldapObject_22',
2017 _("LSldapObject : The function %{func} to be executed before creating the object doesn't exist.")
2019 LSerror :: defineError('LSldapObject_23',
2020 _("LSldapObject : Error executing the function %{func} to be execute after deleting the object.")
2022 LSerror :: defineError('LSldapObject_24',
2023 _("LSldapObject : The function %{func} to be executed after deleting the object doesn't exist.")
2025 LSerror :: defineError('LSldapObject_25',
2026 _("LSldapObject : Error executing the function %{func} to be execute after creating the object.")
2029 LSerror :: defineError('LSldapObject_26',
2030 _("LSldapObject : %{func} function, to be executed on object event %{event}, doesn't exist.")
2032 LSerror :: defineError('LSldapObject_27',
2033 _("LSldapObject : Error during the execution of %{func} function on object event %{event}.")
2036 LSerror :: defineError('LSldapObject_28',
2037 _("LSldapObject : %{meth} method, to be executed on object event %{event}, doesn't exist.")
2039 LSerror :: defineError('LSldapObject_29',
2040 _("LSldapObject : Error during execution of %{meth} method on object event %{event}.")
2042 LSerror :: defineError('LSldapObject_30',
2043 _("LSldapObject : Error during generate LDAP filter for %{LSobject}.")
2047 LSerror :: defineError('LSrelations_05',
2048 _("LSrelation : Some parameters are missing in the call of methods to handle standard relations (Method : %{meth}).")