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-10-14 13:58:00 +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;
|
2009-01-08 00:06:05 +01:00
|
|
|
var $_LSrelationsCache=array();
|
2007-03-29 18:10:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructeur
|
|
|
|
*
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +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 {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_01');
|
2008-02-08 18:39:24 +01:00
|
|
|
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-10-14 13:58:00 +02:00
|
|
|
* Charge les données de l'objet
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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
|
|
|
*/
|
2009-01-07 20:24:14 +01:00
|
|
|
function getDisplayNameFormat() {
|
|
|
|
return $this -> config['display_name_format'];
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
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-10-14 13:58:00 +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
|
|
|
*/
|
2009-01-07 20:24:14 +01:00
|
|
|
function getDisplayName($spe='',$full=false) {
|
2007-03-29 18:10:14 +02:00
|
|
|
if ($spe=='') {
|
2009-01-07 20:24:14 +01:00
|
|
|
$spe = $this -> getDisplayNameFormat();
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
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-10-14 13:58:00 +02:00
|
|
|
* Chaine formatée
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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) {
|
2008-11-10 00:55:17 +01:00
|
|
|
if(!$this -> attrs[$attr_name] -> addToForm($LSform,$idForm,$this,$loadObject -> attrs[$attr_name] -> getFormVal())) {
|
2008-02-12 18:59:44 +01:00
|
|
|
$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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +02:00
|
|
|
* Cette méthode recharge les données d'un formulaire LSform.
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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 {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_02',$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 {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_03',$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-09-26 20:03:56 +02:00
|
|
|
LSdebug("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)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_08',$this -> config['before_modify']);
|
2008-02-12 18:59:44 +01:00
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_07',$this -> config['before_modify']);
|
2008-02-12 18:59:44 +01:00
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-14 13:58:00 +02:00
|
|
|
// $this -> attrs[*] => before_modify
|
|
|
|
foreach($new_data as $attr_name => $attr_val) {
|
2009-01-21 18:08:09 +01:00
|
|
|
if (!$this -> attrs[$attr_name] -> fireEvent('before_modify')) {
|
|
|
|
return;
|
|
|
|
}
|
2008-10-14 13:58:00 +02:00
|
|
|
}
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
if ($this -> submitChange($idForm)) {
|
2008-10-14 13:58:00 +02:00
|
|
|
LSdebug('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)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_10',$this -> config['after_modify']);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_09',$this -> config['after_modify']);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-14 13:58:00 +02:00
|
|
|
|
|
|
|
// $this -> attrs[*] => After Modify
|
|
|
|
foreach($new_data as $attr_name => $attr_val) {
|
2008-10-31 13:12:31 +01:00
|
|
|
$this -> attrs[$attr_name] -> fireEvent('after_modify');
|
2008-10-14 13:58:00 +02:00
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +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) {
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = true;
|
2007-03-29 18:10:14 +02:00
|
|
|
$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)) {
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
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)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSattribute_08',$attr -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSattribute_07',$attr -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSattribute_06',$attr -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-10 16:32:56 +01:00
|
|
|
return $retval;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Valide les données d'un attribut
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @param[in] $LSForm Formulaire d'origine
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] &$attr Attribut à valider
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +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) {
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = true;
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$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-10-14 13:58:00 +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-10-14 13:58:00 +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);
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Validation par fonction externe
|
|
|
|
else if(isset($test['function'])) {
|
|
|
|
if (function_exists($test['function'])) {
|
|
|
|
if(!$test['function']($this)) {
|
|
|
|
$LSform -> setElementError($attr,$msg_error);
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_04',array('attr' => $attr->name,'obj' => $this->getType(),'func' => $test['function']));
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_05',array('attr' => $attr->name,'obj' => $this->getType()));
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-14 13:58:00 +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])){
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_14',array('attr_depend' => $dependAttr, 'attr' => $attr -> getLabel()));
|
2008-02-08 18:39:24 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if($this -> attrs[$dependAttr] -> canBeGenerated()) {
|
|
|
|
if (!$this -> attrs[$dependAttr] -> generateValue()) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSattribute_07',$this -> attrs[$dependAttr] -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSattribute_06',$this -> attrs[$dependAttr] -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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-11-10 16:32:56 +01:00
|
|
|
return $retval;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +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-09-26 20:03:56 +02:00
|
|
|
LSdebug('Rename');
|
2008-07-29 15:45:02 +02:00
|
|
|
if (!$this -> beforeRename()) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_16');
|
2008-07-29 15:45:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$oldDn = $this -> getDn();
|
|
|
|
$this -> dn = false;
|
|
|
|
$newDn = $this -> getDn();
|
|
|
|
if ($newDn) {
|
|
|
|
if (!$GLOBALS['LSldap'] -> move($oldDn,$newDn)) {
|
|
|
|
return;
|
|
|
|
}
|
2008-10-09 11:50:38 +02:00
|
|
|
$this -> dn = $newDn;
|
2008-07-29 15:45:02 +02:00
|
|
|
if (!$this -> afterRename($oldDn,$newDn)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_17');
|
2008-07-29 15:45:02 +02:00
|
|
|
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-09-26 20:03:56 +02:00
|
|
|
LSdebug($submitData);
|
2008-08-06 19:04:03 +02:00
|
|
|
if (!$GLOBALS['LSldap'] -> update($this -> getType(),$dn, $submitData)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($new) {
|
|
|
|
if (!$this -> afterCreate()) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_21');
|
2008-08-06 19:04:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_13');
|
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-10-14 13:58:00 +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;
|
2008-12-05 17:15:10 +01:00
|
|
|
$filter="(&";
|
|
|
|
foreach ($this -> config['objectclass'] as $class) {
|
2007-03-29 18:10:14 +02:00
|
|
|
$filter.='(objectClass='.$class.')';
|
2008-12-05 17:15:10 +01:00
|
|
|
}
|
|
|
|
$filter.=')';
|
|
|
|
if ($this -> config['filter']) {
|
|
|
|
$filter="(&(".$this -> config['filter'].")$filter)";
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
return $filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Retourne une liste d'objet du même type.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +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
|
|
|
*/
|
2008-11-09 17:47:55 +01:00
|
|
|
function listObjects($filter=NULL,$basedn=NULL,$params=array()) {
|
|
|
|
$retInfos=array();
|
|
|
|
|
|
|
|
$ret = $this -> search($filter,$basedn,$params);
|
|
|
|
|
|
|
|
// Création d'un tableau d'objet correspondant au valeur retourné
|
|
|
|
for($i=0;$i<count($ret);$i++) {
|
|
|
|
$retInfos[$i] = new $this -> type_name($this -> config);
|
|
|
|
$retInfos[$i] -> loadData($ret[$i]['dn']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recherche les objets du même type dans l'annuaire
|
|
|
|
*
|
|
|
|
* Effectue une recherche en fonction des paramètres passé et retourne un
|
|
|
|
* tableau array(dn => '', attrs => array()) d'objet correspondant 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
|
|
|
|
* @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
|
|
|
|
*
|
|
|
|
* @retval array Tableau d'objets correspondant au resultat de la recherche
|
|
|
|
*/
|
|
|
|
function search($filter='',$basedn=NULL,$params=array()) {
|
2007-03-29 18:10:14 +02:00
|
|
|
$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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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;
|
|
|
|
|
|
|
|
|
2008-11-09 01:57:50 +01:00
|
|
|
// Attributes
|
|
|
|
if ($filter[$i]['attr']) {
|
|
|
|
$sparams['attributes'] = array($filter[$i]['attr']);
|
|
|
|
}
|
2008-11-09 17:47:55 +01:00
|
|
|
else if (!isset($sparams['attributes'])) {
|
2008-11-09 01:57:50 +01:00
|
|
|
$sparams['attributes'] = array($this -> config['rdn']);
|
|
|
|
}
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
// Execution de la recherche
|
|
|
|
$ret=$GLOBALS['LSldap'] -> search ($sfilter_for,$sbasedn,$sparams);
|
|
|
|
|
|
|
|
// Si il y un retour
|
|
|
|
if(isset($ret[0])) {
|
2008-10-14 13:58:00 +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']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// cas du dernier filtre
|
|
|
|
if(!empty($ret_gen)) {
|
|
|
|
break;
|
|
|
|
}
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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;
|
|
|
|
|
2008-11-09 01:57:50 +01:00
|
|
|
// Attributes
|
2008-11-09 17:47:55 +01:00
|
|
|
if (!isset($sparams['attributes'])) {
|
|
|
|
$sparams['attributes'] = array($this -> config['rdn']);
|
|
|
|
}
|
2008-11-09 01:57:50 +01:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
// Lancement de la recherche
|
|
|
|
$ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams);
|
|
|
|
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +02:00
|
|
|
// Si aucunne valeur n'est retournées
|
2007-03-29 18:10:14 +02:00
|
|
|
if(empty($attrs)){
|
2008-10-14 13:58:00 +02:00
|
|
|
// arrêt et retour à zéro
|
2007-03-29 18:10:14 +02:00
|
|
|
$ret=array();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Si recherche unique
|
|
|
|
else {
|
2008-10-14 13:58:00 +02:00
|
|
|
// préparation du retour finale
|
2008-11-09 17:47:55 +01:00
|
|
|
if (!is_array($ret)) {
|
2008-06-18 14:27:35 +02:00
|
|
|
$ret=array();
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-09 17:47:55 +01:00
|
|
|
return $ret;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2008-11-09 01:57:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne une liste d'objet du même type et retourne leur noms
|
|
|
|
*
|
|
|
|
* Effectue une recherche en fonction des paramètres passé et retourne un
|
|
|
|
* tableau (dn => nom) correspondant au resultat de la recherche.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $filter string Filtre de recherche Ldap
|
|
|
|
* @param[in] $basedn string DN de base pour la recherche
|
|
|
|
* @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
|
|
|
|
* @param[in] $displayFormat string Format d'affichage du nom des objets
|
|
|
|
*
|
|
|
|
* @retval array Tableau dn => name correspondant au resultat de la recherche
|
|
|
|
*/
|
|
|
|
function listObjectsName($filter=NULL,$sbasedn=NULL,$sparams=array(),$displayFormat=false) {
|
|
|
|
$retInfos=array();
|
|
|
|
|
|
|
|
if (!$displayFormat) {
|
2009-01-07 20:24:14 +01:00
|
|
|
$displayFormat = $this -> getDisplayNameFormat();
|
2008-11-09 01:57:50 +01:00
|
|
|
}
|
|
|
|
// Attributes
|
2008-11-09 17:47:55 +01:00
|
|
|
$attrs = getFieldInFormat($displayFormat);
|
|
|
|
if(!empty($attrs)) {
|
|
|
|
$sparams['attributes'] = $attrs;
|
2008-11-09 01:57:50 +01:00
|
|
|
}
|
2008-11-09 17:47:55 +01:00
|
|
|
|
2008-11-09 01:57:50 +01:00
|
|
|
// Lancement de la recherche
|
2008-11-09 17:47:55 +01:00
|
|
|
$ret=$this -> search ($filter,$sbasedn,$sparams);
|
2008-11-09 01:57:50 +01:00
|
|
|
|
|
|
|
if (is_array($ret)) {
|
|
|
|
foreach($ret as $obj) {
|
|
|
|
$retInfos[$obj['dn']] = getFData($displayFormat,$obj['attrs']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retInfos;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2008-06-19 16:07:57 +02:00
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Recherche un objet à partir de la valeur exact de son RDN
|
2008-06-19 16:07:57 +02:00
|
|
|
*
|
|
|
|
* @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-10-14 13:58:00 +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-10-14 13:58:00 +02:00
|
|
|
* @param[in] $val string Le nom de la valeur demandée
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +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-10-14 13:58:00 +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-11-05 15:57:19 +01:00
|
|
|
function getSelectArray($pattern=NULL,$topDn=NULL,$displayFormat=NULL,$approx=false) {
|
|
|
|
if ($pattern!=NULL) {
|
|
|
|
$filter='(|';
|
|
|
|
if ($approx) {
|
|
|
|
foreach ($this -> attrs as $attr_name => $attr_val) {
|
|
|
|
$filter.='('.$attr_name.'~='.$pattern.')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($this -> attrs as $attr_name => $attr_val) {
|
|
|
|
$filter.='('.$attr_name.'=*'.$pattern.'*)';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$filter.=')';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$filter=NULL;
|
|
|
|
}
|
2008-11-09 01:57:50 +01:00
|
|
|
return $this -> listObjectsName($filter,$topDn,array(),$displayFormat);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
|
|
|
* Retourne le DN de l'objet
|
|
|
|
*
|
2008-10-14 13:58:00 +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 {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_12',$this -> config['rdn']);
|
2007-11-15 19:07:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_11',$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-10-14 13:58:00 +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-10-14 13:58:00 +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-10-14 13:58:00 +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;
|
|
|
|
}
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_19');
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_18');
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
*
|
2008-11-09 01:57:50 +01:00
|
|
|
* @parram[in] $dn string Un DN
|
|
|
|
*
|
2008-06-21 18:16:15 +02:00
|
|
|
* @return string La valeur du subDn de l'object
|
|
|
|
*/
|
2008-11-09 01:57:50 +01:00
|
|
|
function getSubDnValue($dn=NULL) {
|
|
|
|
if (!$dn) {
|
|
|
|
$dn = $this -> getValue('dn');
|
|
|
|
}
|
|
|
|
if ($this -> _subDn_value[$dn]) {
|
|
|
|
return $this -> _subDn_value[$dn];
|
2008-06-21 18:16:15 +02:00
|
|
|
}
|
|
|
|
$subDn_value='';
|
|
|
|
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
|
|
|
|
foreach ($subDnLdapServer as $subDn => $subDn_name) {
|
|
|
|
if (isCompatibleDNs($subDn,$dn)&&($subDn!=$dn)) {
|
|
|
|
$subDn_value=$subDn;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-09 01:57:50 +01:00
|
|
|
$this -> _subDn_value[$dn] = $subDn_value;
|
2008-06-21 18:16:15 +02:00
|
|
|
return $subDn_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne la nom du subDn de l'objet
|
|
|
|
*
|
2008-11-09 01:57:50 +01:00
|
|
|
* @parram[in] $dn string Un DN
|
|
|
|
*
|
2008-06-21 18:16:15 +02:00
|
|
|
* @return string Le nom du subDn de l'object
|
|
|
|
*/
|
2008-11-09 01:57:50 +01:00
|
|
|
function getSubDnName($dn=NULL) {
|
2008-06-21 18:16:15 +02:00
|
|
|
$subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer();
|
2008-11-09 01:57:50 +01:00
|
|
|
return $subDnLdapServer[$this -> getSubDnValue($dn)];
|
2008-06-21 18:16:15 +02:00
|
|
|
}
|
2008-07-29 15:45:02 +02:00
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode créant la liste des objets en relations avec l'objet courant et qui
|
2009-01-08 00:06:05 +01:00
|
|
|
* la met en cache ($this -> _LSrelationsCache)
|
2008-07-29 15:45:02 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-07-29 15:45:02 +02:00
|
|
|
*/
|
2009-01-08 00:06:05 +01:00
|
|
|
function updateLSrelationsCache() {
|
|
|
|
$this -> _LSrelationsCache=array();
|
|
|
|
if (is_array($this->config['LSrelation'])) {
|
2008-10-09 12:19:07 +02:00
|
|
|
$type = $this -> getType();
|
|
|
|
$me = new $type();
|
|
|
|
$me -> loadData($this -> getDn());
|
2009-01-08 00:06:05 +01:00
|
|
|
foreach($this->config['LSrelation'] 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']();
|
2008-10-09 11:50:38 +02:00
|
|
|
if ((method_exists($obj,$relation_conf['list_function']))&&(method_exists($obj,$relation_conf['getkeyvalue_function']))) {
|
2008-10-09 12:19:07 +02:00
|
|
|
$list = $obj -> $relation_conf['list_function']($me);
|
2008-07-29 15:45:02 +02:00
|
|
|
if (is_array($list)) {
|
2008-10-09 11:50:38 +02:00
|
|
|
// Key Value
|
2008-10-09 12:19:07 +02:00
|
|
|
$key = $obj -> $relation_conf['getkeyvalue_function']($me);
|
2008-10-09 11:50:38 +02:00
|
|
|
|
2009-01-08 00:06:05 +01:00
|
|
|
$this -> _LSrelationsCache[$relation_name] = array(
|
2008-10-09 11:50:38 +02:00
|
|
|
'list' => $list,
|
|
|
|
'keyvalue' => $key
|
|
|
|
);
|
2008-07-29 15:45:02 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-10-14 13:58:00 +02:00
|
|
|
LSdebug('Problème durant la mise en cache de la relation '.$relation_name);
|
2008-07-29 15:45:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-10-14 13:58:00 +02:00
|
|
|
LSdebug('Les méthodes de mise en cache de la relation '.$relation_name. ' ne sont pas toutes disponibles.');
|
2008-07-29 15:45:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires avant le changement du DN de
|
2008-08-06 19:04:03 +02:00
|
|
|
* l'objet.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-08-06 19:04:03 +02:00
|
|
|
* pour les objets plus complexe.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-08-06 19:04:03 +02:00
|
|
|
*/
|
|
|
|
function beforeRename() {
|
2009-01-08 00:06:05 +01:00
|
|
|
return $this -> updateLSrelationsCache();
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires après le changement du DN de
|
2008-07-29 15:45:02 +02:00
|
|
|
* l'objet.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-07-29 15:45:02 +02:00
|
|
|
* 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
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-07-29 15:45:02 +02:00
|
|
|
*/
|
|
|
|
function afterRename($oldDn,$newDn) {
|
|
|
|
$error = 0;
|
|
|
|
if($GLOBALS['LSsession'] -> dn == $oldDn) {
|
|
|
|
$GLOBALS['LSsession'] -> changeAuthUser($this);
|
|
|
|
}
|
|
|
|
|
2009-01-08 00:06:05 +01:00
|
|
|
foreach($this -> _LSrelationsCache as $relation_name => $objInfos) {
|
|
|
|
if ((isset($this->config['LSrelation'][$relation_name]['rename_function']))&&(is_array($objInfos['list']))) {
|
2008-10-09 11:50:38 +02:00
|
|
|
foreach($objInfos['list'] as $obj) {
|
2009-01-08 00:06:05 +01:00
|
|
|
$meth = $this->config['LSrelation'][$relation_name]['rename_function'];
|
2008-08-06 19:04:03 +02:00
|
|
|
if (method_exists($obj,$meth)) {
|
2008-10-09 11:50:38 +02:00
|
|
|
if (!($obj -> $meth($this,$objInfos['keyvalue']))) {
|
2008-08-06 19:04:03 +02:00
|
|
|
$error=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-07-29 15:45:02 +02:00
|
|
|
$error=1;
|
|
|
|
}
|
|
|
|
}
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return !$error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires avant la suppression de
|
2008-08-06 19:04:03 +02:00
|
|
|
* l'objet.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-08-06 19:04:03 +02:00
|
|
|
* pour les objets plus complexe.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-08-06 19:04:03 +02:00
|
|
|
*/
|
|
|
|
function beforeDelete() {
|
2009-01-08 00:06:05 +01:00
|
|
|
return $this -> updateLSrelationsCache();
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires après la suppression de
|
2008-08-06 19:04:03 +02:00
|
|
|
* l'objet.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-08-06 19:04:03 +02:00
|
|
|
* pour les objets plus complexe.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-08-06 19:04:03 +02:00
|
|
|
*/
|
|
|
|
function afterDelete() {
|
|
|
|
$error = 0;
|
2009-01-08 00:06:05 +01:00
|
|
|
foreach($this -> _LSrelationsCache as $relation_name => $objInfos) {
|
|
|
|
if ((isset($this->config['LSrelation'][$relation_name]['remove_function']))&&(is_array($objInfos['list']))) {
|
2008-10-09 11:50:38 +02:00
|
|
|
foreach($objInfos['list'] as $obj) {
|
2009-01-08 00:06:05 +01:00
|
|
|
$meth = $this->config['LSrelation'][$relation_name]['remove_function'];
|
2008-08-06 19:04:03 +02:00
|
|
|
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)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_25',$action);
|
2008-09-09 17:48:07 +02:00
|
|
|
$error=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_24',$action);
|
2008-09-09 17:48:07 +02:00
|
|
|
$error=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
return !$error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires après la création de
|
2008-08-06 19:04:03 +02:00
|
|
|
* l'objet.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-08-06 19:04:03 +02:00
|
|
|
* pour les objets plus complexe.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-08-06 19:04:03 +02:00
|
|
|
*/
|
|
|
|
function afterCreate() {
|
2008-09-26 20:03:56 +02:00
|
|
|
LSdebug('after');
|
2008-08-06 19:04:03 +02:00
|
|
|
$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)) {
|
2008-10-14 13:58:00 +02:00
|
|
|
LSdebug("Impossible de créer l'entrée fille : ".print_r(
|
2008-08-06 19:04:03 +02:00
|
|
|
array(
|
|
|
|
'dn' => $dn,
|
|
|
|
'objectClass' => $GLOBALS['LSobjects'][$type]['container_auto_create']['objectclass'],
|
|
|
|
'attrs' => $GLOBALS['LSobjects'][$type]['container_auto_create']['attrs']
|
|
|
|
)
|
|
|
|
,true));
|
|
|
|
$error=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$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)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_23',$action);
|
2008-09-09 17:48:07 +02:00
|
|
|
$error=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSldapObject_22',$action);
|
2008-09-09 17:48:07 +02:00
|
|
|
$error=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
return !$error;
|
|
|
|
}
|
2008-08-06 19:04:03 +02:00
|
|
|
|
2008-10-09 11:50:38 +02:00
|
|
|
/**
|
|
|
|
* Retourne la valeur clef d'un objet en relation
|
|
|
|
*
|
|
|
|
* @param[in] $object Un object de type $objectType
|
|
|
|
* @param[in] $attr L'attribut dans lequel l'objet doit apparaitre
|
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
|
|
|
* @param[in] $value La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
|
|
|
*
|
|
|
|
* @retval Mixed La valeur clef d'un objet en relation
|
|
|
|
**/
|
|
|
|
function getObjectKeyValueInRelation($object,$attr,$objectType,$attrValue='dn') {
|
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSrelations_05','getObjectKeyValueInRelation');
|
2008-10-09 11:50:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($attrValue=='dn') {
|
|
|
|
$val = $object -> getDn();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val = $object -> getValue($attrValue);
|
|
|
|
$val = $val[0];
|
|
|
|
}
|
|
|
|
return $val;
|
|
|
|
}
|
|
|
|
|
2008-10-08 15:24:18 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Retourne la liste des relations pour l'objet en fonction de sa présence
|
2008-10-08 15:24:18 +02:00
|
|
|
* dans un des attributs
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Retourne un tableau de d'objet (type : $objectType) correspondant à la
|
2008-10-08 15:24:18 +02:00
|
|
|
* relation entre l'objet $object et les objets de type $objectType. Cette relation
|
2008-10-14 13:58:00 +02:00
|
|
|
* est établis par la présence de la valeur de référence à l'objet dans
|
2008-10-08 19:06:36 +02:00
|
|
|
* l'attribut des objets de type $objectType.
|
2008-10-08 15:24:18 +02:00
|
|
|
*
|
|
|
|
* @param[in] $object Un object de type $objectType
|
|
|
|
* @param[in] $attr L'attribut dans lequel l'objet doit apparaitre
|
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $value La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
2008-10-08 15:24:18 +02:00
|
|
|
*
|
|
|
|
* @retval Array of $objectType Les objets en relations
|
|
|
|
**/
|
2008-10-08 18:49:18 +02:00
|
|
|
function listObjectsInRelation($object,$attr,$objectType,$attrValue='dn') {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSrelations_05','listObjectsInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($attrValue=='dn') {
|
|
|
|
$val = $object -> getDn();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val = $object -> getValue($attrValue);
|
|
|
|
$val = $val[0];
|
|
|
|
}
|
|
|
|
if ($val) {
|
|
|
|
$filter = $this -> getObjectFilter();
|
|
|
|
$filter = '(&'.$filter.'('.$attr.'='.$val.'))';
|
|
|
|
return $this -> listObjects($filter,$GLOBALS['LSsession'] -> ldapServer['ldap_config']['basedn'],array('scope' => 'sub'));
|
|
|
|
}
|
|
|
|
return;
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajoute un objet en relation dans l'attribut $attr de $this
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $object Un objet de type $objectType à ajouter
|
|
|
|
* @param[in] $attr L'attribut dans lequel l'objet doit être ajouté
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $attrValue La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
2008-10-08 15:24:18 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si l'objet à été ajouté, False sinon
|
2008-10-08 15:24:18 +02:00
|
|
|
**/
|
2008-10-08 18:49:18 +02:00
|
|
|
function addOneObjectInRelation($object,$attr,$objectType,$attrValue='dn') {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSrelations_05','addOneObjectInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($object instanceof $objectType) {
|
|
|
|
if ($this -> attrs[$attr] instanceof LSattribute) {
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($attrValue=='dn') {
|
|
|
|
$val = $object -> getDn();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val = $object -> getValue($attrValue);
|
|
|
|
$val = $val[0];
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
$values = $this -> attrs[$attr] -> getValue();
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($this -> attrs[$attr] -> config['multiple']) {
|
|
|
|
if (!is_array($values)) {
|
|
|
|
$updateData = array($val);
|
|
|
|
}
|
|
|
|
else if (!in_array($val,$values)) {
|
|
|
|
$values[]=$val;
|
|
|
|
$updateData = $values;
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
2008-10-08 18:49:18 +02:00
|
|
|
else {
|
|
|
|
if (($values[0]!=$val)&&($values!=$val)) {
|
|
|
|
$updateData = array($val);
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
if (isset($updateData)) {
|
|
|
|
return $GLOBALS['LSldap'] -> update($this -> getType(),$this -> getDn(), array($attr => $updateData));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Supprime un objet en relation dans l'attribut $attr de $this
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $object Un objet de type $objectType à supprimer
|
|
|
|
* @param[in] $attr L'attribut dans lequel l'objet doit être supprimé
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $attrValue La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
2008-10-08 15:24:18 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si l'objet à été supprimé, False sinon
|
2008-10-08 15:24:18 +02:00
|
|
|
**/
|
2008-10-08 18:49:18 +02:00
|
|
|
function deleteOneObjectInRelation($object,$attr,$objectType,$attrValue='dn') {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSrelations_05','deleteOneObjectInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($object instanceof $objectType) {
|
|
|
|
if ($this -> attrs[$attr] instanceof LSattribute) {
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($attrValue=='dn') {
|
|
|
|
$val = $object -> getDn();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val = $object -> getValue($attrValue);
|
|
|
|
$val = $val[0];
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
$values = $this -> attrs[$attr] -> getValue();
|
|
|
|
if ((!is_array($values)) && (!empty($values))) {
|
|
|
|
$values = array($values);
|
|
|
|
}
|
|
|
|
if (is_array($values)) {
|
|
|
|
$updateData=array();
|
|
|
|
foreach($values as $value) {
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($value!=$val) {
|
2008-10-08 15:24:18 +02:00
|
|
|
$updateData[]=$value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $GLOBALS['LSldap'] -> update($this -> getType(),$this -> getDn(), array($attr => $updateData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renome un objet en relation dans l'attribut $attr de $this
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $object Un objet de type $objectType à renomer
|
|
|
|
* @param[in] $oldValue string L'ancienne valeur faisant référence à l'objet
|
|
|
|
* @param[in] $attr L'attribut dans lequel l'objet doit être supprimé
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $attrValue La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
2008-10-08 15:24:18 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean True en cas de succès, False sinon
|
2008-10-08 15:24:18 +02:00
|
|
|
*/
|
2008-10-08 18:49:18 +02:00
|
|
|
function renameOneObjectInRelation($object,$oldValue,$attr,$objectType,$attrValue='dn') {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSrelations_05','renameOneObjectInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($object instanceof $objectType) {
|
|
|
|
if ($this -> attrs[$attr] instanceof LSattribute) {
|
|
|
|
$values = $this -> attrs[$attr] -> getValue();
|
|
|
|
if ((!is_array($values)) && (!empty($values))) {
|
|
|
|
$values = array($values);
|
|
|
|
}
|
|
|
|
if (is_array($values)) {
|
|
|
|
$updateData=array();
|
|
|
|
foreach($values as $value) {
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($value!=$oldValue) {
|
2008-10-08 15:24:18 +02:00
|
|
|
$updateData[] = $value;
|
|
|
|
}
|
|
|
|
else {
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($attrValue=='dn') {
|
|
|
|
$val = $object -> getDn();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val = $object -> getValue($attrValue);
|
|
|
|
$val = $val[0];
|
|
|
|
}
|
|
|
|
$updateData[] = $val;
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $GLOBALS['LSldap'] -> update($this -> getType(),$this -> getDn(), array($attr => $updateData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Met à jour les objets du meme type que $this en relation avec l'objet $object
|
2008-10-08 15:24:18 +02:00
|
|
|
* de type $objectType en modifiant la valeur de leur attribut $attr des objets
|
|
|
|
* en relation
|
|
|
|
*
|
|
|
|
* @param[in] $object Mixed Un object (type : $this -> userObjectType) : l'utilisateur
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $listDns Array(string) Un tableau des DNs des objets en relation
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $attr L'attribut dans lequel l'utilisateur doit apparaitre
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
|
|
|
* @param[in] $attrValue La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
2008-10-08 15:24:18 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si tout c'est bien passé, False sinon
|
2008-10-08 15:24:18 +02:00
|
|
|
**/
|
2008-10-08 18:49:18 +02:00
|
|
|
function updateObjectsInRelation($object,$listDns,$attr,$objectType,$attrValue='dn') {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-21 18:37:02 +01:00
|
|
|
LSerror::addErrorCode('LSrelations_05','updateObjectsInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-10-08 19:06:36 +02:00
|
|
|
$currentObjects = $this -> listObjectsInRelation($object,$attr,$objectType,$attrValue);
|
2008-10-08 15:24:18 +02:00
|
|
|
$type=$this -> getType();
|
|
|
|
if(is_array($currentObjects)) {
|
|
|
|
if (is_array($listDns)) {
|
2008-10-08 18:49:18 +02:00
|
|
|
$values=array();
|
|
|
|
if ($attrValue!='dn') {
|
|
|
|
$obj=new $objectType();
|
|
|
|
foreach ($listDns as $dn) {
|
|
|
|
$obj -> loadData($dn);
|
|
|
|
$val = $obj -> getValue($attrValue);
|
|
|
|
$values[$dn] = $val[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach($listDns as $dn) {
|
|
|
|
$values[$dn] = $dn;
|
|
|
|
}
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
$dontDelete=array();
|
|
|
|
$dontAdd=array();
|
|
|
|
for ($i=0;$i<count($currentObjects);$i++) {
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($attrValue=='dn') {
|
|
|
|
$val = $currentObjects[$i] -> getDn();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val = $currentObjects[$i] -> getValue($attrValue);
|
|
|
|
$val = $val[0];
|
|
|
|
}
|
|
|
|
if (in_array($val, $listDns)) {
|
2008-10-08 15:24:18 +02:00
|
|
|
$dontDelete[$i]=true;
|
2008-10-08 18:49:18 +02:00
|
|
|
$dontAdd[]=$val;
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for($i=0;$i<count($currentObjects);$i++) {
|
|
|
|
if ($dontDelete[$i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
2008-10-08 19:06:36 +02:00
|
|
|
if (!$currentObjects[$i] -> deleteOneObjectInRelation($object,$attr,$objectType,$attrValue)) {
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-08 18:49:18 +02:00
|
|
|
foreach($values as $dn => $val) {
|
|
|
|
if (in_array($val,$dontAdd)) {
|
2008-10-08 15:24:18 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$obj = new $type();
|
|
|
|
if ($obj -> loadData($dn)) {
|
2008-10-08 19:06:36 +02:00
|
|
|
if (!$obj -> addOneObjectInRelation($object,$attr,$objectType,$attrValue)) {
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(!is_array($listDns)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
foreach($listDns as $dn) {
|
|
|
|
$obj = new $type();
|
|
|
|
if ($obj -> loadData($dn)) {
|
2008-10-08 19:06:36 +02:00
|
|
|
if (!$obj -> addOneObjectInRelation($object,$attr,$objectType,$attrValue)) {
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:00:25 +01:00
|
|
|
/**
|
|
|
|
* Error Codes
|
|
|
|
**/
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_01'] = array (
|
|
|
|
'msg' => _("LSldapObject : Object type unknow.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_02'] = array (
|
|
|
|
'msg' => _("LSldapObject : Update form is not defined for the object %{obj}.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_03'] = array (
|
|
|
|
'msg' => _("LSldapObject : No form exist for the object %{obj}.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_04'] = array (
|
|
|
|
'msg' => _("LSldapObject : The function %{func} to validate the attribute %{attr} the object %{obj} is unknow.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_05'] = array (
|
|
|
|
'msg' => _("LSldapObject : Configuration data are missing to validate the attribute %{attr} of the object %{obj}.")
|
|
|
|
);
|
|
|
|
/* No longer used
|
|
|
|
$GLOBALS['LSerror_code'][26] = array (
|
|
|
|
'msg' => _("LSldapObject : Configuration error : The object %{obj} doesn't had attribute %{attr}.")
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_07'] = array (
|
|
|
|
'msg' => _("LSldapObject : The function %{func} to be executed before changing the object doesn't exist.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_08'] = array (
|
|
|
|
'msg' => _("LSldapObject : The execution of the function %{func} to be executed before changing the object failed.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_09'] = array (
|
|
|
|
'msg' => _("LSldapObject : The function %{func} to be executed after changing the object doesn't exist.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_10'] = array (
|
|
|
|
'msg' => _("LSldapObject : The execution of the function %{func} to be executed after changing the object failed.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_11'] = array (
|
|
|
|
'msg' => _("LSldapObject : Some configuration data of the object type %{obj} are missing to generate the DN of the new object.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_12'] = array (
|
|
|
|
'msg' => _("LSldapObject : The attibute %{attr} of the object is not yet defined. Impossible to generate DN.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_13'] = array (
|
|
|
|
'msg' => _("LSldapObject : Without DN, the object could not be changed.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_14'] = array (
|
|
|
|
'msg' => _("LSldapObject : The attribute %{attr_depend} depending on the attribute %{attr} doesn't exist.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_15'] = array (
|
|
|
|
'msg' => _("LSldapObject : Error during deleting the object %{objectname}.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_16'] = array (
|
|
|
|
'msg' => _("LSldapObject : Error during actions to be executed before renaming the objet.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_17'] = array (
|
|
|
|
'msg' => _("LSldapObject : Error during actions to be executed after renaming the objet.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_18'] = array (
|
|
|
|
'msg' => _("LSldapObject : Error during actions to be executed before deleting the objet.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_19'] = array (
|
|
|
|
'msg' => _("LSldapObject : Error during actions to be executed after deleting the objet.")
|
|
|
|
);
|
|
|
|
// 20 : not used
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_21'] = array (
|
|
|
|
'msg' => _("LSldapObject : Error during the actions to be executed after creating the object. It was created anyway.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_22'] = array (
|
|
|
|
'msg' => _("LSldapObject : The function %{func} to be generated before creating the object doesn't exist.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_23'] = array (
|
|
|
|
'msg' => _("LSldapObject : Error during the execution of the function %{func} to be generated after deleting the object.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_24'] = array (
|
|
|
|
'msg' => _("LSldapObject : The function %{func} to be generated after deleting the object doesn't exist.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code']['LSldapObject_25'] = array (
|
|
|
|
'msg' => _("LSldapObject : Error during the execution of the function %{func} to be generated after creating the object.")
|
|
|
|
);
|
|
|
|
/* Not yet used
|
|
|
|
$GLOBALS['LSerror_code'][306] = array (
|
|
|
|
'msg' => _("LSldapObject : The function %{func} to be executed after changing the attribute %{attr} is unknow.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code'][307] = array (
|
|
|
|
'msg' => _("LSldapObject : The execution of the function %{func} to be executed after changing the attribute %{attr} failed.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code'][308] = array (
|
|
|
|
'msg' => _("LSldapObject : The function %{func} to be executed before changing the attribute %{attr} is unknow.")
|
|
|
|
);
|
|
|
|
$GLOBALS['LSerror_code'][309] = array (
|
|
|
|
'msg' => _("LSldapObject : The execution of the function %{func} to be executed before changing the attribute %{attr} failed.")
|
|
|
|
);
|
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
?>
|