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;
|
2008-07-29 15:45:02 +02:00
|
|
|
var $_relationsCache=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 {
|
|
|
|
$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-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
|
|
|
*/
|
|
|
|
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-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
|
|
|
*/
|
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-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) {
|
|
|
|
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-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 {
|
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-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)) {
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|
2008-10-14 13:58:00 +02:00
|
|
|
// $this -> attrs[*] => before_modify
|
|
|
|
foreach($new_data as $attr_name => $attr_val) {
|
2008-10-31 13:12:31 +01:00
|
|
|
$this -> attrs[$attr_name] -> fireEvent('before_modify');
|
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)) {
|
|
|
|
$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-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) {
|
|
|
|
$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-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) {
|
|
|
|
$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);
|
|
|
|
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-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])){
|
|
|
|
$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-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()) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(36);
|
|
|
|
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)) {
|
|
|
|
$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-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()) {
|
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-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;
|
|
|
|
foreach ($this -> config['objectclass'] as $class)
|
|
|
|
$filter.='(objectClass='.$class.')';
|
|
|
|
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
|
|
|
*/
|
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-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']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$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']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-10-14 13:58:00 +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-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
|
|
|
|
$sparams['attributes'] = array($this -> config['rdn']);
|
|
|
|
|
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-06-18 14:27:35 +02:00
|
|
|
if (is_array($ret)) {
|
|
|
|
$ret_final=array();
|
2008-11-09 01:57:50 +01:00
|
|
|
foreach($ret as $obj) {
|
2008-06-18 14:27:35 +02:00
|
|
|
$ret_final[]=$obj['dn'];
|
2008-11-09 01:57:50 +01:00
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
$ret=$ret_final;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ret=array();
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-14 13:58:00 +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-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) {
|
|
|
|
$displayFormat = $this -> getDisplayAttributes();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filtre sur l'objet souhaité
|
|
|
|
$sfilter='(&';
|
|
|
|
$sfilter.=$this -> getObjectFilter();
|
|
|
|
$sfilter_end=')';
|
|
|
|
|
|
|
|
if(($filter)&&(!empty($filter))) {
|
|
|
|
if(substr($filter,0,1)=='(') {
|
|
|
|
$sfilter.=$filter;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sfilter.='('.$filter.')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fermeture du filtre
|
|
|
|
$sfilter.=$sfilter_end;
|
|
|
|
|
|
|
|
// Attributes
|
|
|
|
$sparams['attributes'] = getFieldInFormat($displayFormat);
|
|
|
|
if(empty($sparams['attributes'])) {
|
|
|
|
$sparams['attributes'] = array($this -> config['rdn']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lancement de la recherche
|
|
|
|
$ret=$GLOBALS['LSldap'] -> search ($sfilter,$sbasedn,$sparams);
|
|
|
|
|
|
|
|
if (is_array($ret)) {
|
|
|
|
foreach($ret as $obj) {
|
|
|
|
$retInfos[$obj['dn']] = getFData($displayFormat,$obj['attrs']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retInfos;
|
|
|
|
}
|
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 {
|
|
|
|
$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-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;
|
|
|
|
}
|
|
|
|
$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
|
|
|
|
*
|
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
|
2008-08-06 19:04:03 +02:00
|
|
|
* la met en cache ($this -> _relationsCache)
|
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
|
|
|
*/
|
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'])) {
|
2008-10-09 12:19:07 +02:00
|
|
|
$type = $this -> getType();
|
|
|
|
$me = new $type();
|
|
|
|
$me -> loadData($this -> getDn());
|
2008-07-29 15:45:02 +02:00
|
|
|
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']();
|
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
|
|
|
|
|
|
|
$this -> _relationsCache[$relation_name] = array(
|
|
|
|
'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 {
|
2008-10-10 18:43:36 +02:00
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1004,$relation_conf['LSobject']);
|
2008-07-29 15:45:02 +02:00
|
|
|
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() {
|
|
|
|
return $this -> updateRelationsCache();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-10-09 11:50:38 +02:00
|
|
|
foreach($this -> _relationsCache as $relation_name => $objInfos) {
|
|
|
|
if ((isset($this->config['relations'][$relation_name]['rename_function']))&&(is_array($objInfos['list']))) {
|
|
|
|
foreach($objInfos['list'] as $obj) {
|
2008-08-06 19:04:03 +02:00
|
|
|
$meth = $this->config['relations'][$relation_name]['rename_function'];
|
|
|
|
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() {
|
|
|
|
return $this -> updateRelationsCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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;
|
2008-10-09 11:50:38 +02:00
|
|
|
foreach($this -> _relationsCache as $relation_name => $objInfos) {
|
|
|
|
if ((isset($this->config['relations'][$relation_name]['remove_function']))&&(is_array($objInfos['list']))) {
|
|
|
|
foreach($objInfos['list'] as $obj) {
|
2008-08-06 19:04:03 +02:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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 {
|
|
|
|
$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
|
|
|
|
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)) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1021,'getObjectKeyValueInRelation');
|
|
|
|
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)) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1021,'listObjectsInRelation');
|
|
|
|
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)) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1021,'addOneObjectInRelation');
|
|
|
|
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)) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1021,'deleteOneObjectInRelation');
|
|
|
|
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)) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1021,'renameOneObjectInRelation');
|
|
|
|
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)) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1021,'updateObjectsInRelation');
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
?>
|