2007-03-29 18:10:14 +02:00
|
|
|
|
<?php
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
|
*
|
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2008-02-05 17:11:21 +01:00
|
|
|
|
$GLOBALS['LSsession'] -> loadLSclass('LSattribute');
|
2007-03-29 18:10:14 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base d'un objet ldap
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette classe définis la base de tout objet ldap géré par LdapSaisie
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*/
|
|
|
|
|
class LSldapObject {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
|
2008-04-25 15:48:12 +02:00
|
|
|
|
var $config = array();
|
2008-02-08 18:39:24 +01:00
|
|
|
|
var $type_name;
|
2008-04-25 15:48:12 +02:00
|
|
|
|
var $attrs = array();
|
2007-03-29 18:10:14 +02:00
|
|
|
|
var $forms;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
var $view;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
var $dn=false;
|
|
|
|
|
var $other_values=array();
|
2007-11-15 19:07:24 +01:00
|
|
|
|
var $submitError=true;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
var $_whoami=NULL;
|
2008-06-21 18:16:15 +02:00
|
|
|
|
var $_subDn_value=NULL;
|
2008-07-29 15:45:02 +02:00
|
|
|
|
var $_relationsCache=array();
|
2007-03-29 18:10:14 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructeur
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette methode construit l'objet et définis la configuration.
|
|
|
|
|
* Elle lance la construction du tableau d'attributs représentés par un objet LSattribute.
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $type_name [<b>required</b>] string Le nom du type de l'objet
|
|
|
|
|
* @param[in] $config array La configuration de l'objet
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si l'objet a été construit, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
|
|
|
|
function LSldapObject($type_name,$config='auto') {
|
|
|
|
|
$this -> type_name = $type_name;
|
2008-02-05 17:11:21 +01:00
|
|
|
|
$this -> config = $config;
|
|
|
|
|
if($config=='auto') {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
if(isset($GLOBALS['LSobjects'][$type_name])) {
|
|
|
|
|
$this -> config = $GLOBALS['LSobjects'][$type_name];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(21);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
foreach($this -> config['attrs'] as $attr_name => $attr_config) {
|
|
|
|
|
if(!$this -> attrs[$attr_name]=new LSattribute($attr_name,$attr_config,$this)) {
|
2007-03-29 18:10:14 +02:00
|
|
|
|
return;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
return true;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Charge les données de l'objet
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette methode définis le DN de l'objet et charge les valeurs de attributs de l'objet
|
|
|
|
|
* à partir de l'annuaire.
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $dn string Le DN de l'objet.
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si la chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
function loadData($dn) {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
$this -> dn = $dn;
|
|
|
|
|
$data = $GLOBALS['LSldap'] -> getAttrs($dn);
|
|
|
|
|
if(!empty($data)) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
|
|
|
|
if(!$this -> attrs[$attr_name] -> loadData($data[$attr_name]))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2008-02-12 18:59:44 +01:00
|
|
|
|
}
|
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Recharge les données de l'objet
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si la rechargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
|
function reloadData() {
|
|
|
|
|
$data = $GLOBALS['LSldap'] -> getAttrs($this -> dn);
|
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
|
|
|
|
if(!$this -> attrs[$attr_name] -> reloadData($data[$attr_name]))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
|
/**
|
|
|
|
|
* Retourne le format d'affichage de l'objet
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval string Format d'affichage de l'objet.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
|
|
|
|
function getDisplayAttributes() {
|
|
|
|
|
return $this -> config['select_display_attrs'];
|
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne la valeur descriptive d'affichage de l'objet
|
|
|
|
|
*
|
|
|
|
|
* Cette fonction retourne la valeur descriptive d'affichage de l'objet en fonction
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* du format défini dans la configuration de l'objet ou spécifié en paramètre.
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $spe [<i>optionnel</i>] string Format d'affichage de l'objet
|
2008-07-05 22:28:49 +02:00
|
|
|
|
* @param[in] $full [<i>optionnel</i>] boolean True pour afficher en plus le
|
|
|
|
|
* subDnName
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @retval string Valeur descriptive d'affichage de l'objet
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2008-07-05 22:28:49 +02:00
|
|
|
|
function getDisplayValue($spe='',$full=false) {
|
2007-03-29 18:10:14 +02:00
|
|
|
|
if ($spe=='') {
|
|
|
|
|
$spe = $this -> getDisplayAttributes();
|
|
|
|
|
}
|
2008-07-05 22:28:49 +02:00
|
|
|
|
$val = $this -> getFData($spe,&$this -> attrs,'getDisplayValue');
|
|
|
|
|
if ($GLOBALS['LSsession'] -> haveSubDn() && $full) {
|
|
|
|
|
$val.=' ('.$this -> getSubDnName().')';
|
|
|
|
|
}
|
|
|
|
|
return $val;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Chaine formatée
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette fonction retourne la valeur d'une chaine formatée en prennant les valeurs
|
2007-03-29 18:10:14 +02:00
|
|
|
|
* de l'objet.
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $format string Format de la chaine
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval string Valeur d'une chaine formatée
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
function getFData($format) {
|
|
|
|
|
$format=getFData($format,$this,'getValue');
|
|
|
|
|
return $format;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construit un formulaire de l'objet
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette méthode construit un formulaire LSform à partir de la configuration de l'objet
|
2007-03-29 18:10:14 +02:00
|
|
|
|
* et de chaque attribut.
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
|
|
|
|
|
* @param[in] $load DN d'un objet similaire dont la valeur des attribut doit être chargé dans le formulaire.
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval LSform Le formulaire crée
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2008-02-12 18:59:44 +01:00
|
|
|
|
function getForm($idForm,$load=NULL) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
$GLOBALS['LSsession'] -> loadLSclass('LSform');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
$LSform = new LSform($this,$idForm);
|
2008-02-12 18:59:44 +01:00
|
|
|
|
$this -> forms[$idForm] = array($LSform,$load);
|
|
|
|
|
|
|
|
|
|
if ($load) {
|
|
|
|
|
$type = $this -> getType();
|
|
|
|
|
$loadObject = new $type();
|
|
|
|
|
if (!$loadObject -> loadData($load)) {
|
|
|
|
|
$load=false;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
|
|
|
|
|
if ($load) {
|
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
|
|
|
|
if(!$this -> attrs[$attr_name] -> addToForm($LSform,$idForm,$this,$loadObject -> getValue($attr_name))) {
|
|
|
|
|
$LSform -> can_validate = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
|
|
|
|
if(!$this -> attrs[$attr_name] -> addToForm($LSform,$idForm,$this)) {
|
|
|
|
|
$LSform -> can_validate = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
return $LSform;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
|
/**
|
|
|
|
|
* Construit un formulaire de l'objet
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette méthode construit un formulaire LSform à partir de la configuration de l'objet
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* et de chaque attribut.
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
|
|
|
|
|
* @param[in] $config Configuration spécifique pour le formulaire
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval LSform Le formulaire crée
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
|
|
|
|
function getView() {
|
|
|
|
|
$GLOBALS['LSsession'] -> loadLSclass('LSform');
|
|
|
|
|
$this -> view = new LSform($this,'view');
|
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
|
|
|
|
$this -> attrs[$attr_name] -> addToView($this -> view);
|
|
|
|
|
}
|
|
|
|
|
$this -> view -> can_validate = false;
|
|
|
|
|
return $this -> view;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
|
/**
|
|
|
|
|
* Rafraichis le formulaire de l'objet
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette méthode recharge les données d'un formulaire LSform.
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true sile formulaire a été rafraichis, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
|
function refreshForm($idForm) {
|
|
|
|
|
$LSform = $this -> forms[$idForm][0];
|
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
|
|
|
|
if(!$this -> attrs[$attr_name] -> refreshForm($LSform,$idForm)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Met à jour les données de l'objet et de l'entré de l'annuaire
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Met à jour les données de l'objet à partir d'un retour d'un formulaire.
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @param[in] $idForm Identifiant du formulaire d'origine
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si la mise à jour a réussi, false sinon
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @see validateAttrsData()
|
|
|
|
|
* @see submitChange()
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
function updateData($idForm=NULL) {
|
|
|
|
|
if($idForm!=NULL) {
|
|
|
|
|
if(isset($this -> forms[$idForm]))
|
|
|
|
|
$LSform = $this -> forms[$idForm][0];
|
|
|
|
|
else {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(22,$this -> getType());
|
2007-03-29 18:10:14 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if(count($this -> forms) > 0) {
|
|
|
|
|
reset($this -> forms);
|
|
|
|
|
$idForm = key($this -> forms);
|
|
|
|
|
$LSform = current($this -> forms);
|
|
|
|
|
$config = $LSform[1];
|
|
|
|
|
$LSform = $LSform[0];
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(23,$this -> getType());
|
2008-02-12 18:59:44 +01:00
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
$new_data = $LSform -> exportValues();
|
2008-07-18 16:02:46 +02:00
|
|
|
|
if(!is_array($new_data)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
foreach($new_data as $attr_name => $attr_val) {
|
|
|
|
|
if(isset($this -> attrs[$attr_name])) {
|
|
|
|
|
$this -> attrs[$attr_name] -> setUpdateData($attr_val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if($this -> validateAttrsData($idForm)) {
|
2008-04-25 16:09:27 +02:00
|
|
|
|
debug("les données sont validées");
|
2008-09-09 17:48:07 +02:00
|
|
|
|
if(isset($this -> config['before_modify'])) {
|
|
|
|
|
if(function_exists($this -> config['before_modify'])) {
|
|
|
|
|
if(!$this -> config['before_modify']($this)) {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(28,$this -> config['before_modify']);
|
2008-02-12 18:59:44 +01:00
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-09-09 17:48:07 +02:00
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(27,$this -> config['before_modify']);
|
2008-02-12 18:59:44 +01:00
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
if ($this -> submitChange($idForm)) {
|
2008-04-25 16:09:27 +02:00
|
|
|
|
debug('Les modifications sont submitées');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
$this -> submitError = false;
|
|
|
|
|
$this -> reloadData();
|
|
|
|
|
$this -> refreshForm($idForm);
|
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-09-09 17:48:07 +02:00
|
|
|
|
if((isset($this -> config['after_modify']))&&(!$this -> submitError)) {
|
|
|
|
|
if(function_exists($this -> config['after_modify'])) {
|
|
|
|
|
if(!$this -> config['after_modify']($this)) {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(30,$this -> config['after_modify']);
|
2008-02-12 18:59:44 +01:00
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-09-09 17:48:07 +02:00
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(29,$this -> config['after_modify']);
|
2008-02-12 18:59:44 +01:00
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Valide les données retournées par un formulaire
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @param[in] $idForm Identifiant du formulaire d'origine
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si les données sont valides, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
function validateAttrsData($idForm) {
|
|
|
|
|
$LSform=$this -> forms[$idForm][0];
|
|
|
|
|
foreach($this -> attrs as $attr) {
|
2008-07-31 11:16:25 +02:00
|
|
|
|
$attr_values = $attr -> getValue();
|
2008-02-08 18:39:24 +01:00
|
|
|
|
if (!$attr -> isValidate()) {
|
|
|
|
|
if($attr -> isUpdate()) {
|
|
|
|
|
if (!$this -> validateAttrData($LSform, $attr)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-07-31 11:16:25 +02:00
|
|
|
|
else if( (empty($attr_values)) && ($attr -> isRequired()) ) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
if ( $attr -> canBeGenerated()) {
|
|
|
|
|
if ($attr -> generateValue()) {
|
|
|
|
|
if (!$this -> validateAttrData($LSform, $attr)) {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(48,$attr -> getLabel());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(47,$attr -> getLabel());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(46,$attr -> getLabel());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Valide les données d'un attribut
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @param[in] $LSForm Formulaire d'origine
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] &$attr Attribut à valider
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si les données sont valides, false sinon
|
2007-11-15 19:07:24 +01:00
|
|
|
|
*/
|
2008-02-08 18:39:24 +01:00
|
|
|
|
function validateAttrData(&$LSform,&$attr) {
|
|
|
|
|
$vconfig=$attr -> getValidateConfig();
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
|
$data=$attr -> getUpdateData();
|
|
|
|
|
if(!is_array($data)) {
|
|
|
|
|
$data=array($data);
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
|
// Validation des valeurs de l'attribut
|
2007-11-15 19:07:24 +01:00
|
|
|
|
if(is_array($vconfig)) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
foreach($vconfig as $test) {
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Définition du basedn par défaut
|
2008-02-08 18:39:24 +01:00
|
|
|
|
if (!isset($test['basedn'])) {
|
|
|
|
|
$test['basedn']=$GLOBALS['LSsession']->topDn;
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Définition du message d'erreur
|
2008-02-08 18:39:24 +01:00
|
|
|
|
if (!empty($test['msg'])) {
|
|
|
|
|
$msg_error=getFData($test['msg'],$this,'getValue');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$msg_error=getFData(_("L'attribut %{attr} n'est pas valide."),$attr -> getLabel());
|
|
|
|
|
}
|
|
|
|
|
foreach($data as $val) {
|
|
|
|
|
// validation par check LDAP
|
|
|
|
|
if((isset($test['filter'])||isset($test['basedn']))&&(isset($test['result']))) {
|
|
|
|
|
$sparams=(isset($test['scope']))?array('scope' => $test['scope']):array();
|
|
|
|
|
$this -> other_values['val']=$val;
|
|
|
|
|
$sfilter_user=(isset($test['basedn']))?getFData($test['filter'],$this,'getValue'):NULL;
|
|
|
|
|
if(isset($test['object_type'])) {
|
|
|
|
|
$test_obj = new $test['object_type']();
|
|
|
|
|
$sfilter=$test_obj->getObjectFilter();
|
|
|
|
|
$sfilter='(&'.$sfilter;
|
|
|
|
|
if($sfilter_user[0]=='(') {
|
|
|
|
|
$sfilter=$sfilter.$sfilter_user.')';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sfilter=$sfilter.'('.$sfilter_user.'))';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sfilter=$sfilter_user;
|
|
|
|
|
}
|
|
|
|
|
$sbasedn=(isset($test['basedn']))?getFData($test['basedn'],$this,'getValue'):NULL;
|
|
|
|
|
$ret=$GLOBALS['LSldap'] -> getNumberResult ($sfilter,$sbasedn,$sparams);
|
|
|
|
|
if($test['result']==0) {
|
|
|
|
|
if($ret!=0) {
|
|
|
|
|
$LSform -> setElementError($attr,$msg_error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-07-29 15:45:02 +02:00
|
|
|
|
if($ret<0) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
$LSform -> setElementError($attr,$msg_error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Validation par fonction externe
|
|
|
|
|
else if(isset($test['function'])) {
|
|
|
|
|
if (function_exists($test['function'])) {
|
|
|
|
|
if(!$test['function']($this)) {
|
|
|
|
|
$LSform -> setElementError($attr,$msg_error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(24,array('attr' => $attr->name,'obj' => $this->getType(),'func' => $test['function']));
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(25,array('attr' => $attr->name,'obj' => $this->getType()));
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Génération des valeurs des attributs dépendants
|
2008-02-08 18:39:24 +01:00
|
|
|
|
$dependsAttrs=$attr->getDependsAttrs();
|
|
|
|
|
if (!empty($dependsAttrs)) {
|
|
|
|
|
foreach($dependsAttrs as $dependAttr) {
|
|
|
|
|
if(!isset($this -> attrs[$dependAttr])){
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(34,array('attr_depend' => $dependAttr, 'attr' => $attr -> getLabel()));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if($this -> attrs[$dependAttr] -> canBeGenerated()) {
|
|
|
|
|
if (!$this -> attrs[$dependAttr] -> generateValue()) {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(47,$this -> attrs[$dependAttr] -> getLabel());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(46,$this -> attrs[$dependAttr] -> getLabel());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
|
$attr -> validate();
|
2007-11-15 19:07:24 +01:00
|
|
|
|
unset($this -> other_values['val']);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Met à jour les données modifiés dans l'annuaire
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
|
|
|
|
* @param[in] $idForm Identifiant du formulaire d'origine
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean true si la mise à jour a réussi, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
function submitChange($idForm) {
|
2007-11-15 19:07:24 +01:00
|
|
|
|
$submitData=array();
|
2008-08-06 19:04:03 +02:00
|
|
|
|
$new = $this -> isNew();
|
2007-03-29 18:10:14 +02:00
|
|
|
|
foreach($this -> attrs as $attr) {
|
|
|
|
|
if(($attr -> isUpdate())&&($attr -> isValidate())) {
|
2008-08-06 19:04:03 +02:00
|
|
|
|
if(($attr -> name == $this -> config['rdn'])&&(!$new)) {
|
|
|
|
|
$new = true;
|
2008-07-29 15:45:02 +02:00
|
|
|
|
debug('Rename');
|
|
|
|
|
if (!$this -> beforeRename()) {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(36);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$oldDn = $this -> getDn();
|
|
|
|
|
$this -> dn = false;
|
|
|
|
|
$newDn = $this -> getDn();
|
|
|
|
|
if ($newDn) {
|
|
|
|
|
if (!$GLOBALS['LSldap'] -> move($oldDn,$newDn)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!$this -> afterRename($oldDn,$newDn)) {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(37);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$submitData[$attr -> name] = $attr -> getUpdateData();
|
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!empty($submitData)) {
|
|
|
|
|
$dn=$this -> getDn();
|
|
|
|
|
if($dn) {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
$this -> dn=$dn;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
debug($submitData);
|
2008-08-06 19:04:03 +02:00
|
|
|
|
if (!$GLOBALS['LSldap'] -> update($this -> getType(),$dn, $submitData)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ($new) {
|
|
|
|
|
if (!$this -> afterCreate()) {
|
2008-09-09 17:48:07 +02:00
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(301);
|
2008-08-06 19:04:03 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(33);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne les informations issus d'un DN
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $dn Un DN.
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval array Tableau :
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* - [0] : le premier paramètre
|
|
|
|
|
* - [1] : les paramètres suivants
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
function getDnInfos($dn) {
|
|
|
|
|
$infos=ldap_explode_dn($dn,0);
|
|
|
|
|
if(!$infos)
|
|
|
|
|
return;
|
|
|
|
|
$first=true;
|
|
|
|
|
for($i=1;$i<$infos['count'];$i++)
|
|
|
|
|
if($first) {
|
|
|
|
|
$basedn.=$infos[$i];
|
|
|
|
|
$first=false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
$basedn.=','.$infos[$i];
|
|
|
|
|
return array($infos[0],$basedn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne le filtre correpondants aux objetcClass de l'objet
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval string le filtre ldap correspondant au type de l'objet
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
function getObjectFilter() {
|
|
|
|
|
if(!isset($this -> config['objectclass'])) return;
|
|
|
|
|
foreach ($this -> config['objectclass'] as $class)
|
|
|
|
|
$filter.='(objectClass='.$class.')';
|
|
|
|
|
return $filter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Retourne une liste d'objet du même type.
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Effectue une recherche en fonction des paramètres passé et retourne un
|
2007-03-29 18:10:14 +02:00
|
|
|
|
* tableau d'objet correspond au resultat de la recherche.
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $filter array (ou string) Filtre de recherche Ldap / Tableau de filtres de recherche
|
|
|
|
|
* @param[in] $basedn string DN de base pour la recherche
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
|
* @retval array Tableau d'objets correspondant au resultat de la recherche
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
function listObjects($filter='',$basedn=NULL,$params=array()) {
|
|
|
|
|
$retInfos=array();
|
|
|
|
|
$attrs=false;
|
|
|
|
|
$check_final_dn=false;
|
|
|
|
|
|
|
|
|
|
if(!is_array($filter))
|
|
|
|
|
$filter=array(array('filter' => $filter));
|
|
|
|
|
|
|
|
|
|
$nbFilter=count($filter);
|
|
|
|
|
|
|
|
|
|
for($i=0;$i<$nbFilter;$i++) {
|
|
|
|
|
$new_attrs=array();
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Défintion des paramètres de base pour la recherche
|
2007-03-29 18:10:14 +02:00
|
|
|
|
$sbasedn=$basedn;
|
|
|
|
|
$sparams=$params;
|
|
|
|
|
$ret=array();
|
|
|
|
|
if (isset($filter[$i]['scope']))
|
|
|
|
|
$sparams["scope"]=$filter[$i]['scope'];
|
|
|
|
|
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Definition des critères de recherche correspondant au type d'objet à lister
|
2007-03-29 18:10:14 +02:00
|
|
|
|
if(($nbFilter==1)||(!isset($filter[$i]['attr']))) {
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Filtre sur l'objet souhaité
|
2007-03-29 18:10:14 +02:00
|
|
|
|
$sfilter='(&';
|
|
|
|
|
$sfilter.=$this -> getObjectFilter();
|
|
|
|
|
$sfilter_end=')';
|
|
|
|
|
$check_final_dn=true;
|
|
|
|
|
}
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Initialisation des critères d'une recherche intermédiaire
|
2007-03-29 18:10:14 +02:00
|
|
|
|
else {
|
|
|
|
|
if(isset($filter[$i]['object_type'])) {
|
|
|
|
|
$obj_tmp=new $filter[$i]['object_type']();
|
|
|
|
|
$obj_filter=$obj_tmp->getObjectFilter();
|
|
|
|
|
$sfilter='(&'.$obj_filter;
|
|
|
|
|
$sfilter_end=')';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sfilter='';
|
|
|
|
|
$sfilter_end='';
|
|
|
|
|
}
|
|
|
|
|
if(isset($filter[$i]['scope'])) {
|
|
|
|
|
$sparams['scope']=$filter[$i]['scope'];
|
|
|
|
|
}
|
|
|
|
|
if(isset($filter[$i]['basedn'])) {
|
|
|
|
|
$sbasedn=$filter[$i]['basedn'];
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Dans le cas d'une recherche intermédiaire ou finale
|
2007-03-29 18:10:14 +02:00
|
|
|
|
if($attrs!=false) {
|
|
|
|
|
// Initialisation des variables
|
|
|
|
|
$ret_gen=array();
|
|
|
|
|
$new_attrs=array();
|
|
|
|
|
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Pour tout les attributs retournés
|
2007-03-29 18:10:14 +02:00
|
|
|
|
for($ii=0;$ii<count($attrs);$ii++) {
|
|
|
|
|
$sfilter_for='';
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Définition du filtre de recherche à partir des paramètres utilisateurs et
|
|
|
|
|
// des paramètres de recherche de l'objet à listé (dans le cas d'une recherche finale
|
2007-03-29 18:10:14 +02:00
|
|
|
|
if((isset($filter[$i]['filter']))&&(!empty($filter[$i]['filter']))) {
|
|
|
|
|
$sfilter_user=getFData($filter[$i]['filter'],$attrs[$ii]);
|
|
|
|
|
if($sfilter_user[0]=='(')
|
|
|
|
|
$sfilter_for=$sfilter.$sfilter_user;
|
|
|
|
|
else
|
|
|
|
|
$sfilter_for=$sfilter.'('.$sfilter_user.')';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sfilter_for=$sfilter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(isset($filter[$i]['basedn'])) {
|
|
|
|
|
$sbasedn=getFData($filter[$i]['basedn'],$attrs[$ii]);
|
|
|
|
|
if ((!$this -> isCompatibleDNs($sbasedn,$basedn))&&($check_final_dn)) continue;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Vérification de la compatibilité du basedn de la recherche et du basedn générale
|
2007-03-29 18:10:14 +02:00
|
|
|
|
// Finalisation du filtre
|
|
|
|
|
$sfilter_for.=$sfilter_end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Execution de la recherche
|
|
|
|
|
$ret=$GLOBALS['LSldap'] -> search ($sfilter_for,$sbasedn,$sparams);
|
|
|
|
|
|
|
|
|
|
// Si il y un retour
|
|
|
|
|
if(isset($ret[0])) {
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// si il ya une suite (recherche intermédiaire)
|
2007-03-29 18:10:14 +02:00
|
|
|
|
if($filter[$i]['attr']){
|
|
|
|
|
for($iii=0;$iii<count($ret);$iii++) {
|
|
|
|
|
if(isset($ret[$iii]['attrs'][$filter[$i]['attr']])) {
|
|
|
|
|
// cas de valeur multiple
|
|
|
|
|
if(is_array($ret[$iii]['attrs'][$filter[$i]['attr']])) {
|
|
|
|
|
foreach($ret[$iii]['attrs'][$filter[$i]['attr']] as $val_attr) {
|
|
|
|
|
$new_attrs[]=$val_attr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// cas de valeur unique
|
|
|
|
|
else {
|
|
|
|
|
$new_attrs[]=$ret[$iii]['attrs'][$filter[$i]['attr']];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// vérification de la compatibilité de la compatibilité du DN resultant
|
2007-03-29 18:10:14 +02:00
|
|
|
|
// et du basedn de recherche
|
|
|
|
|
if (!$this -> isCompatibleDNs($ret[0]['dn'],$basedn))
|
|
|
|
|
continue;
|
|
|
|
|
// ajout du DN au resultat finale
|
|
|
|
|
$ret_gen[]=$ret[0]['dn'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// cas du dernier filtre
|
|
|
|
|
if(!empty($ret_gen)) {
|
|
|
|
|
// on quitte la boucle des filtres de la conf
|
|
|
|
|
$ret=$ret_gen;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// dans le cas d'une suite prévu mais d'un retour nul de la précédente recherche
|
2007-03-29 18:10:14 +02:00
|
|
|
|
else if(empty($new_attrs)) {
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// retour vide et arrêt de la recherche
|
2007-03-29 18:10:14 +02:00
|
|
|
|
$ret=array();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$attrs=$new_attrs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Dans le cas de la recherche initiale
|
|
|
|
|
else {
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Déclaration du filtre de recherche
|
2007-03-29 18:10:14 +02:00
|
|
|
|
if((isset($filter[$i]['filter']))&&(!empty($filter[$i]['filter']))) {
|
|
|
|
|
if($filter[$i]['filter'][0]=='(') {
|
|
|
|
|
$sfilter.=$filter[$i]['filter'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sfilter.='('.$filter[$i]['filter'].')';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// fermeture du filtre
|
|
|
|
|
$sfilter.=$sfilter_end;
|
|
|
|
|
|
|
|
|
|
// Lancement de la recherche
|
|
|
|
|
$ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams);
|
|
|
|
|
|
2008-04-25 16:09:27 +02:00
|
|
|
|
//Si filtre multiple => on recupère une liste d'attributs
|
2007-03-29 18:10:14 +02:00
|
|
|
|
if(isset($filter[$i]['attr'])) {
|
|
|
|
|
for($ii=0;$ii<count($ret);$ii++) {
|
|
|
|
|
if(isset($ret[$ii]['attrs'][$filter[$i]['attr']])) {
|
|
|
|
|
// cas de valeur multiple
|
|
|
|
|
if(is_array($ret[$ii]['attrs'][$filter[$i]['attr']])) {
|
|
|
|
|
foreach($ret[$ii]['attrs'][$filter[$i]['attr']] as $val_attr) {
|
|
|
|
|
$attrs[]=$val_attr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// cas de valeur unique
|
|
|
|
|
else {
|
|
|
|
|
$attrs[]=$ret[$ii]['attrs'][$filter[$i]['attr']];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Si aucunne valeur n'est retournées
|
2007-03-29 18:10:14 +02:00
|
|
|
|
if(empty($attrs)){
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// arrêt et retour à zéro
|
2007-03-29 18:10:14 +02:00
|
|
|
|
$ret=array();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Si recherche unique
|
|
|
|
|
else {
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// préparation du retour finale
|
2008-06-18 14:27:35 +02:00
|
|
|
|
if (is_array($ret)) {
|
|
|
|
|
$ret_final=array();
|
|
|
|
|
foreach($ret as $obj)
|
|
|
|
|
$ret_final[]=$obj['dn'];
|
|
|
|
|
$ret=$ret_final;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$ret=array();
|
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-25 16:09:27 +02:00
|
|
|
|
// Création d'un tableau d'objet correspondant au valeur retourné
|
2007-03-29 18:10:14 +02:00
|
|
|
|
for($i=0;$i<count($ret);$i++) {
|
|
|
|
|
$retInfos[$i] = new $this -> type_name($this -> config);
|
|
|
|
|
$retInfos[$i] -> loadData($ret[$i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $retInfos;
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-06-19 16:07:57 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Recherche un objet <EFBFBD> partir de la valeur exact de son RDN
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $name string Valeur de son RDN
|
|
|
|
|
* @param[in] $basedn string Le DN de base de la recherche
|
|
|
|
|
*
|
|
|
|
|
* @retval array Tableau d'objets correspondant au resultat de la recherche
|
|
|
|
|
*/
|
2008-02-08 18:39:24 +01:00
|
|
|
|
function searchObject($name,$basedn=NULL) {
|
|
|
|
|
$filter = $this -> config['rdn'].'='.$name;
|
|
|
|
|
return $this -> listObjects($filter,$basedn);
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
|
/**
|
|
|
|
|
* Retourne une valeur de l'objet
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Retourne une valeur en fonction du paramètre. Si la valeur est inconnue, la valeur retourné est ' '.
|
2007-03-29 18:10:14 +02:00
|
|
|
|
* tableau d'objet correspond au resultat de la recherche.
|
|
|
|
|
*
|
|
|
|
|
* Valeurs possibles :
|
|
|
|
|
* - 'dn' ou '%{dn} : DN de l'objet
|
|
|
|
|
* - [nom d'un attribut] : valeur de l'attribut
|
|
|
|
|
* - [clef de $this -> other_values] : valeur de $this -> other_values
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @param[in] $val string Le nom de la valeur demandée
|
2007-03-29 18:10:14 +02:00
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval mixed la valeur demandé ou ' ' si celle-ci est inconnue.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
function getValue($val) {
|
|
|
|
|
if(($val=='dn')||($val=='%{dn}')) {
|
|
|
|
|
return $this -> dn;
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
else if(($val=='rdn')||($val=='%{rdn}')) {
|
|
|
|
|
return $this -> attrs[ $this -> config['rdn'] ] -> getValue();
|
|
|
|
|
}
|
2008-07-18 17:20:52 +02:00
|
|
|
|
else if(($val=='subDn')||($val=='%{subDn}')) {
|
|
|
|
|
return $this -> getSubDnValue();
|
|
|
|
|
}
|
|
|
|
|
else if(($val=='subDnName')||($val=='%{subDnName}')) {
|
|
|
|
|
return $this -> getSubDnName();
|
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
else if(isset($this -> attrs[$val])){
|
|
|
|
|
if (method_exists($this -> attrs[$val],'getValue'))
|
|
|
|
|
return $this -> attrs[$val] -> getValue();
|
|
|
|
|
else
|
|
|
|
|
return ' ';
|
|
|
|
|
}
|
|
|
|
|
else if(isset($this -> other_values[$val])){
|
|
|
|
|
return $this -> other_values[$val];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ' ';
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Retourn un tableau pour un select d'un objet du même type
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 15:48:12 +02:00
|
|
|
|
* @retval array('dn' => 'display')
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2008-04-25 15:48:12 +02:00
|
|
|
|
function getSelectArray($topDn=NULL) {
|
|
|
|
|
$list = $this -> listObjects(NULL,$topDn);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
$return=array();
|
|
|
|
|
foreach($list as $object) {
|
2008-04-25 15:48:12 +02:00
|
|
|
|
$return[$object -> getDn()] = $object -> getDisplayValue();
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
|
/**
|
|
|
|
|
* Retourne le DN de l'objet
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Cette methode retourne le DN de l'objet. Si celui-ci n'existe pas, il le construit à partir de la
|
2007-11-15 19:07:24 +01:00
|
|
|
|
* configuration de l'objet et la valeur de son attribut rdn.
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval string Le DN de l'objet
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
|
function getDn() {
|
|
|
|
|
if($this -> dn) {
|
|
|
|
|
return $this -> dn;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$rdn_attr=$this -> config['rdn'];
|
2008-02-05 17:11:21 +01:00
|
|
|
|
if( (isset($this -> config['rdn'])) && (isset($this -> attrs[$rdn_attr])) && (isset($this -> config['container_dn'])) && (isset($GLOBALS['LSsession']->topDn)) ) {
|
2007-11-15 19:07:24 +01:00
|
|
|
|
$rdn_val=$this -> attrs[$rdn_attr] -> getUpdateData();
|
|
|
|
|
if (!empty($rdn_val)) {
|
2008-02-05 17:11:21 +01:00
|
|
|
|
return $rdn_attr.'='.$rdn_val[0].','.$this -> config['container_dn'].','.$GLOBALS['LSsession']->topDn;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(32,$this -> config['rdn']);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(31,$this -> getType());
|
2007-11-15 19:07:24 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
|
/**
|
|
|
|
|
* Retourne le type de l'objet
|
|
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* @retval string Le type de l'objet ($this -> type_name)
|
|
|
|
|
*/
|
|
|
|
|
function getType() {
|
|
|
|
|
return $this -> type_name;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* Retourne qui est l'utilisateur par rapport à cet object
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval string 'admin'/'self'/'user' pour Admin , l'utilisateur lui même ou un simple utilisateur
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
2008-02-08 18:39:24 +01:00
|
|
|
|
function whoami() {
|
|
|
|
|
if (!$this -> _whoami)
|
|
|
|
|
$this -> _whoami = $GLOBALS['LSsession'] -> whoami($this -> dn);
|
|
|
|
|
return $this -> _whoami;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
|
|
|
|
* Retourne le label de l'objet
|
|
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-02-12 18:59:44 +01:00
|
|
|
|
* @retval string Le label de l'objet ($this -> config['label'])
|
|
|
|
|
*/
|
2008-02-08 18:39:24 +01:00
|
|
|
|
function getLabel() {
|
|
|
|
|
return $this -> config['label'];
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Supprime l'objet dans l'annuaire
|
|
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
|
* @retval boolean True si l'objet à été supprimé, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
|
|
|
|
function remove() {
|
2008-08-06 19:04:03 +02:00
|
|
|
|
if ($this -> beforeDelete()) {
|
|
|
|
|
if ($GLOBALS['LSldap'] -> remove($this -> getDn())) {
|
|
|
|
|
if ($this -> afterDelete()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(39);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(38);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-06-19 16:07:57 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* L'objet est-il nouveau
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si l'objet est nouveau, false sinon
|
|
|
|
|
*/
|
|
|
|
|
function isNew() {
|
|
|
|
|
return (!$this -> dn);
|
|
|
|
|
}
|
2008-06-21 18:16:15 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne la valeur (DN) du subDn de l'objet
|
|
|
|
|
*
|
|
|
|
|
* @return string La valeur du subDn de l'object
|
|
|
|
|
*/
|
|
|
|
|
function getSubDnValue() {
|
|
|
|
|
if ($this -> _subDn_value) {
|
|
|
|
|
return $this -> _subDn_value;
|
|
|
|
|
}
|
|
|
|
|
$dn = $this -> getValue('dn');
|
|
|
|
|
$subDn_value='';
|
|
|
|
|
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
|
|
|
|
|
foreach ($subDnLdapServer as $subDn => $subDn_name) {
|
|
|
|
|
if (isCompatibleDNs($subDn,$dn)&&($subDn!=$dn)) {
|
|
|
|
|
$subDn_value=$subDn;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this -> _subDn_value = $subDn_value;
|
|
|
|
|
return $subDn_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne la nom du subDn de l'objet
|
|
|
|
|
*
|
|
|
|
|
* @return string Le nom du subDn de l'object
|
|
|
|
|
*/
|
|
|
|
|
function getSubDnName() {
|
|
|
|
|
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
|
|
|
|
|
return $subDnLdapServer[$this -> getSubDnValue()];
|
|
|
|
|
}
|
2008-07-29 15:45:02 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2008-08-06 19:04:03 +02:00
|
|
|
|
* Methode cr<EFBFBD>ant la liste des objets en relations avec l'objet courant et qui
|
|
|
|
|
* la met en cache ($this -> _relationsCache)
|
2008-07-29 15:45:02 +02:00
|
|
|
|
*
|
|
|
|
|
* @retval True en cas de cas ce succ<EFBFBD>s, False sinon.
|
|
|
|
|
*/
|
2008-08-06 19:04:03 +02:00
|
|
|
|
function updateRelationsCache() {
|
|
|
|
|
$this -> _relationsCache=array();
|
2008-07-29 15:45:02 +02:00
|
|
|
|
if (is_array($this->config['relations'])) {
|
|
|
|
|
foreach($this->config['relations'] as $relation_name => $relation_conf) {
|
2008-08-06 19:04:03 +02:00
|
|
|
|
if ( isset($relation_conf['list_function']) ) {
|
2008-07-29 15:45:02 +02:00
|
|
|
|
if ($GLOBALS['LSsession'] -> loadLSobject($relation_conf['LSobject'])) {
|
|
|
|
|
$obj = new $relation_conf['LSobject']();
|
|
|
|
|
if (method_exists($obj,$relation_conf['list_function'])) {
|
|
|
|
|
$list = $obj -> $relation_conf['list_function']($this);
|
|
|
|
|
if (is_array($list)) {
|
|
|
|
|
$this -> _relationsCache[$relation_name] = $list;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
|
/**
|
|
|
|
|
* Methode executant les actions n<EFBFBD>c<EFBFBD>ssaires avant le changement du DN de
|
|
|
|
|
* l'objet.
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode n'est qu'un exemple et elle doit <EFBFBD>tre certainement r<EFBFBD><EFBFBD>crite
|
|
|
|
|
* pour les objets plus complexe.
|
|
|
|
|
*
|
|
|
|
|
* @retval True en cas de cas ce succ<EFBFBD>s, False sinon.
|
|
|
|
|
*/
|
|
|
|
|
function beforeRename() {
|
|
|
|
|
return $this -> updateRelationsCache();
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* Methode executant les actions n<EFBFBD>c<EFBFBD>ssaires apr<EFBFBD>s le changement du DN de
|
|
|
|
|
* l'objet.
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode n'est qu'un exemple et elle doit <EFBFBD>tre certainement r<EFBFBD><EFBFBD>crite
|
|
|
|
|
* pour les objets plus complexe.
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $oldDn string L'ancien DN de l'objet
|
|
|
|
|
* @param[in] $newDn string Le nouveau DN de l'objet
|
|
|
|
|
*
|
|
|
|
|
* @retval True en cas de cas ce succ<EFBFBD>s, False sinon.
|
|
|
|
|
*/
|
|
|
|
|
function afterRename($oldDn,$newDn) {
|
|
|
|
|
$error = 0;
|
|
|
|
|
if($GLOBALS['LSsession'] -> dn == $oldDn) {
|
|
|
|
|
$GLOBALS['LSsession'] -> changeAuthUser($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach($this -> _relationsCache as $relation_name => $objList) {
|
2008-08-06 19:04:03 +02:00
|
|
|
|
if (isset($this->config['relations'][$relation_name]['rename_function'])) {
|
|
|
|
|
foreach($objList as $obj) {
|
|
|
|
|
$meth = $this->config['relations'][$relation_name]['rename_function'];
|
|
|
|
|
if (method_exists($obj,$meth)) {
|
|
|
|
|
if (!($obj -> $meth($this,$oldDn))) {
|
|
|
|
|
$error=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-07-29 15:45:02 +02:00
|
|
|
|
$error=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-08-06 19:04:03 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return !$error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Methode executant les actions n<EFBFBD>c<EFBFBD>ssaires avant la suppression de
|
|
|
|
|
* l'objet.
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode n'est qu'un exemple et elle doit <EFBFBD>tre certainement r<EFBFBD><EFBFBD>crite
|
|
|
|
|
* pour les objets plus complexe.
|
|
|
|
|
*
|
|
|
|
|
* @retval True en cas de cas ce succ<EFBFBD>s, False sinon.
|
|
|
|
|
*/
|
|
|
|
|
function beforeDelete() {
|
|
|
|
|
return $this -> updateRelationsCache();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Methode executant les actions n<EFBFBD>c<EFBFBD>ssaires apr<EFBFBD>s la suppression de
|
|
|
|
|
* l'objet.
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode n'est qu'un exemple et elle doit <EFBFBD>tre certainement r<EFBFBD><EFBFBD>crite
|
|
|
|
|
* pour les objets plus complexe.
|
|
|
|
|
*
|
|
|
|
|
* @retval True en cas de cas ce succ<EFBFBD>s, False sinon.
|
|
|
|
|
*/
|
|
|
|
|
function afterDelete() {
|
|
|
|
|
$error = 0;
|
|
|
|
|
foreach($this -> _relationsCache as $relation_name => $objList) {
|
|
|
|
|
if (isset($this->config['relations'][$relation_name]['remove_function'])) {
|
|
|
|
|
foreach($objList as $obj) {
|
|
|
|
|
$meth = $this->config['relations'][$relation_name]['remove_function'];
|
|
|
|
|
if (method_exists($obj,$meth)) {
|
|
|
|
|
if (!($obj -> $meth($this))) {
|
|
|
|
|
$error=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$error=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-09 17:48:07 +02:00
|
|
|
|
|
|
|
|
|
if (isset($this -> config['after_delete'])) {
|
|
|
|
|
if (is_array($this -> config['after_delete'])) {
|
|
|
|
|
$config = $this -> config['after_delete'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$config = array($this -> config['after_delete']);
|
|
|
|
|
}
|
|
|
|
|
foreach($config as $action) {
|
|
|
|
|
if(function_exists($action)) {
|
|
|
|
|
if(!$action($this)) {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(305,$action);
|
|
|
|
|
$error=true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(304,$action);
|
|
|
|
|
$error=true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
|
return !$error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Methode executant les actions n<EFBFBD>c<EFBFBD>ssaires apr<EFBFBD>s la cr<EFBFBD>ation de
|
|
|
|
|
* l'objet.
|
|
|
|
|
*
|
|
|
|
|
* Cette m<EFBFBD>thode n'est qu'un exemple et elle doit <EFBFBD>tre certainement r<EFBFBD><EFBFBD>crite
|
|
|
|
|
* pour les objets plus complexe.
|
|
|
|
|
*
|
|
|
|
|
* @retval True en cas de cas ce succ<EFBFBD>s, False sinon.
|
|
|
|
|
*/
|
|
|
|
|
function afterCreate() {
|
|
|
|
|
debug('after');
|
|
|
|
|
$error = 0;
|
|
|
|
|
if ($GLOBALS['LSsession'] -> isSubDnLSobject($this -> getType())) {
|
|
|
|
|
if (is_array($GLOBALS['LSsession'] -> ldapServer['subDn']['LSobject'][$this -> getType()]['LSobjects'])) {
|
|
|
|
|
foreach($GLOBALS['LSsession'] -> ldapServer['subDn']['LSobject'][$this -> getType()]['LSobjects'] as $type) {
|
|
|
|
|
if ($GLOBALS['LSsession'] -> loadLSobject($type)) {
|
|
|
|
|
if (isset($GLOBALS['LSobjects'][$type]['container_auto_create'])&&isset($GLOBALS['LSobjects'][$type]['container_dn'])) {
|
|
|
|
|
$dn = $GLOBALS['LSobjects'][$type]['container_dn'].','.$this -> getDn();
|
|
|
|
|
if(!$GLOBALS['LSldap'] -> getNewEntry($dn,$GLOBALS['LSobjects'][$type]['container_auto_create']['objectclass'],$GLOBALS['LSobjects'][$type]['container_auto_create']['attrs'],true)) {
|
|
|
|
|
debug("Impossible de cr<63>er l'entr<74>e fille : ".print_r(
|
|
|
|
|
array(
|
|
|
|
|
'dn' => $dn,
|
|
|
|
|
'objectClass' => $GLOBALS['LSobjects'][$type]['container_auto_create']['objectclass'],
|
|
|
|
|
'attrs' => $GLOBALS['LSobjects'][$type]['container_auto_create']['attrs']
|
|
|
|
|
)
|
|
|
|
|
,true));
|
|
|
|
|
$error=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1004,$type);
|
|
|
|
|
$error=1;
|
|
|
|
|
}
|
2008-07-29 15:45:02 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-09 17:48:07 +02:00
|
|
|
|
|
|
|
|
|
if (isset($this -> config['after_create'])) {
|
|
|
|
|
if (is_array($this -> config['after_create'])) {
|
|
|
|
|
$config = $this -> config['after_create'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$config = array($this -> config['after_create']);
|
|
|
|
|
}
|
|
|
|
|
foreach($config as $action) {
|
|
|
|
|
if(function_exists($action)) {
|
|
|
|
|
if(!$action($this)) {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(303,$action);
|
|
|
|
|
$error=true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(302,$action);
|
|
|
|
|
$error=true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
|
return !$error;
|
|
|
|
|
}
|
2008-08-06 19:04:03 +02:00
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
|
?>
|