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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass('LSattr_ldap');
|
|
|
|
LSsession :: loadLSclass('LSattr_html');
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Attribut Ldap
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette classe modélise un attribut Ldap
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
class LSattribute {
|
|
|
|
|
|
|
|
var $name;
|
|
|
|
var $config;
|
2007-11-15 19:07:24 +01:00
|
|
|
var $ldapObject;
|
2007-03-29 18:10:14 +02:00
|
|
|
var $ldap;
|
|
|
|
var $html;
|
|
|
|
var $data;
|
|
|
|
var $updateData=false;
|
|
|
|
var $is_validate=false;
|
2008-02-08 18:39:24 +01:00
|
|
|
var $_finalUpdateData=false;
|
|
|
|
var $_myRights=NULL;
|
2008-10-31 13:12:31 +01:00
|
|
|
var $_events=array();
|
|
|
|
var $_objectEvents=array();
|
2007-03-29 18:10:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructeur
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette methode construit l'objet et définis la configuration.
|
2007-03-29 18:10:14 +02:00
|
|
|
* Elle lance la construction des objets LSattr_html et LSattr_ldap correspondant
|
2008-04-25 16:09:27 +02:00
|
|
|
* à ses types définis définis dans sa configuration
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $name string Nom de l'attribut ldap
|
|
|
|
* @param[in] $config array Configuration de l'objet
|
2007-11-15 19:07:24 +01:00
|
|
|
* @param[in] &$ldapObject LSldapObject L'objet ldap parent
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean Retourne true si la création a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
function LSattribute ($name,$config,&$ldapObject) {
|
2007-03-29 18:10:14 +02:00
|
|
|
$this -> name = $name;
|
|
|
|
$this -> config = $config;
|
2015-04-14 15:10:40 +02:00
|
|
|
$this -> ldapObject =& $ldapObject;
|
2007-03-29 18:10:14 +02:00
|
|
|
$html_type = "LSattr_html_".$config['html_type'];
|
|
|
|
$ldap_type = "LSattr_ldap_".$config['ldap_type'];
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass($html_type);
|
|
|
|
LSsession :: loadLSclass($ldap_type);
|
2007-03-29 18:10:14 +02:00
|
|
|
if((class_exists($html_type))&&(class_exists($ldap_type))) {
|
2007-11-15 19:07:24 +01:00
|
|
|
$this -> html = new $html_type($name,$config,$this);
|
|
|
|
$this -> ldap = new $ldap_type($name,$config,$this);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_01',array('attr' => $name,'html'=>$config['html_type'],'ldap'=>$config['ldap_type']));
|
2007-03-29 18:10:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne la valeur du label de l'attribut
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval string Le label de l'attribut
|
|
|
|
*
|
|
|
|
* @see LSattr_html::getLabel()
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
|
|
|
function getLabel() {
|
2009-01-02 17:00:25 +01:00
|
|
|
if (!$this -> html) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
|
2009-01-02 17:00:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
return $this -> html -> getLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Défini la valeur de l'attribut
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval boolean true
|
|
|
|
*/
|
|
|
|
function loadData($attr_data) {
|
2008-07-31 11:16:25 +02:00
|
|
|
if ((!is_array($attr_data))&&(!empty($attr_data))) {
|
|
|
|
$attr_data = array($attr_data);
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
$this -> data = $attr_data;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Redéfini la valeur de l'attribut
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2007-11-15 19:07:24 +01:00
|
|
|
* @retval boolean true
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
function reloadData($attr_data) {
|
2008-07-31 11:16:25 +02:00
|
|
|
if ((!is_array($attr_data))&&(!empty($attr_data))) {
|
|
|
|
$attr_data = array($attr_data);
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
$this -> data = $attr_data;
|
|
|
|
$this -> updateData=false;
|
|
|
|
$this -> is_validate=false;
|
|
|
|
return true;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne la valeur de l'attribut
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne la valeur nouvelle si elle existe, sinon la valeur passé.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval mixed La valeur de l'attribut
|
|
|
|
*/
|
|
|
|
function getValue() {
|
2010-03-16 17:28:32 +01:00
|
|
|
if ($this -> isUpdate()) {
|
|
|
|
return $this -> getUpdateData();
|
2010-03-16 17:33:55 +01:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
else {
|
2010-03-16 17:28:32 +01:00
|
|
|
return $this -> getOldValue();
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2010-03-16 11:11:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne la valeur originale de l'attribut
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval mixed La valeur originale de l'attribut
|
|
|
|
*/
|
|
|
|
function getOldValue() {
|
|
|
|
return $this -> data;
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne la valeur d'affichage de l'attribut
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval string La valeur d'affichage de l'attribut
|
|
|
|
*/
|
|
|
|
function getDisplayValue() {
|
2009-01-02 17:00:25 +01:00
|
|
|
if (!$this -> ldap) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_09',array('type' => 'ldap','name' => $this -> name));
|
2009-01-02 17:00:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-11-13 11:20:16 +01:00
|
|
|
|
|
|
|
if ($this -> isUpdate()) {
|
|
|
|
$data = $this -> ldap -> getDisplayValue($this -> updateData);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$data = $this -> ldap -> getDisplayValue($this -> data);
|
|
|
|
}
|
|
|
|
|
2010-11-16 19:44:38 +01:00
|
|
|
if (isset($this -> config['onDisplay'])) {
|
2007-03-29 18:10:14 +02:00
|
|
|
if (is_array($this -> config['onDisplay'])) {
|
|
|
|
$result=$data;
|
|
|
|
foreach($this -> config['onDisplay'] as $func) {
|
|
|
|
if (function_exists($func)) {
|
2017-04-26 10:40:37 +02:00
|
|
|
$result=call_user_func($func, $result);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_02',array('attr' => $this->name,'func' => $func));
|
2007-03-29 18:10:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (function_exists($this -> config['onDisplay'])) {
|
|
|
|
return $this -> config['onDisplay']($data);
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_02',array('attr' => $this->name,'func' => $this -> config['onDisplay']));
|
2007-03-29 18:10:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-02 17:00:25 +01:00
|
|
|
* Ajoute l'attribut au formulaire
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette méthode ajoute l'attribut au formulaire $form si l'identifiant de celui-ci
|
2007-03-29 18:10:14 +02:00
|
|
|
* ($idForm) est connu dans la configuration de l'objet.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] object $form Le formulaire dans lequel doit être ajouté l'attribut
|
2007-11-15 19:07:24 +01:00
|
|
|
* @param[in] string $idForm L'identifiant du formulaire
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] objet &$obj Objet utilisable pour la génération de la valeur de l'attribut
|
|
|
|
* @param[in] array $value valeur de l'élement
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si l'ajout a fonctionner ou qu'il n'est pas nécessaire, false sinon
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2008-02-12 18:59:44 +01:00
|
|
|
function addToForm(&$form,$idForm,&$obj=NULL,$value=NULL) {
|
2007-03-29 18:10:14 +02:00
|
|
|
if(isset($this -> config['form'][$idForm])) {
|
2009-01-02 17:00:25 +01:00
|
|
|
if (!$this -> html) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
|
2009-01-02 17:00:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
if($this -> myRights() == 'n') {
|
|
|
|
return true;
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
if ($value) {
|
|
|
|
$data = $value;
|
|
|
|
}
|
|
|
|
else if($this -> data !='') {
|
2007-11-15 19:07:24 +01:00
|
|
|
$data=$this -> getFormVal();
|
|
|
|
}
|
|
|
|
else if (isset($this -> config['default_value'])) {
|
|
|
|
$data=$obj -> getFData($this -> config['default_value']);
|
|
|
|
}
|
2012-09-03 10:22:18 +02:00
|
|
|
else {
|
|
|
|
$data=NULL;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
$element = $this -> html -> addToForm($form,$idForm,$data);
|
2008-02-08 18:39:24 +01:00
|
|
|
if(!$element) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSform_06',$this -> name);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2012-09-03 10:22:18 +02:00
|
|
|
if(isset($this -> config['required']) && $this -> config['required']==1) {
|
2007-11-15 19:07:24 +01:00
|
|
|
$form -> setRequired($this -> name);
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
if (($this -> config['form'][$idForm]==0) || ($this -> myRights() == 'r')) {
|
2007-03-29 18:10:14 +02:00
|
|
|
$element -> freeze();
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
else {
|
|
|
|
if(isset($this -> config['check_data'])) {
|
|
|
|
if(is_array($this -> config['check_data'])) {
|
|
|
|
foreach ($this -> config['check_data'] as $rule => $rule_infos) {
|
|
|
|
if((!$form -> isRuleRegistered($rule))&&($rule!='')) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_03',array('attr' => $this->name,'rule' => $rule));
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2009-03-19 18:42:51 +01:00
|
|
|
if(!isset($rule_infos['msg'])) {
|
|
|
|
$rule_infos['msg']=getFData(_('The value of field %{label} is invalid.'),$this -> getLabel());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rule_infos['msg']=__($rule_infos['msg']);
|
|
|
|
}
|
2008-10-07 17:23:06 +02:00
|
|
|
if(!isset($rule_infos['params']))
|
|
|
|
$rule_infos['params']=NULL;
|
|
|
|
$form -> addRule($this -> name,$rule,array('msg' => $rule_infos['msg'], 'params' => $rule_infos['params']));
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_04',$this->name);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Récupération des droits de l'utilisateur sur l'attribut
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @retval string 'r'/'w'/'n' pour 'read'/'write'/'none'
|
|
|
|
**/
|
2008-02-08 18:39:24 +01:00
|
|
|
function myRights() {
|
|
|
|
// cache
|
|
|
|
if ($this -> _myRights != NULL) {
|
|
|
|
return $this -> _myRights;
|
|
|
|
}
|
|
|
|
$return='n';
|
2008-11-12 17:57:40 +01:00
|
|
|
$whoami = $this -> ldapObject -> whoami();
|
|
|
|
foreach($whoami as $who) {
|
|
|
|
switch ($who) {
|
|
|
|
case 'admin':
|
|
|
|
if($this -> config['rights']['admin']=='w') {
|
|
|
|
$return='w';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$return='r';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2010-11-16 19:45:11 +01:00
|
|
|
if (!isset($this -> config['rights'][$who])) break;
|
2008-11-12 17:57:40 +01:00
|
|
|
if ($this -> config['rights'][$who] == 'w') {
|
|
|
|
$return='w';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if($this -> config['rights'][$who] == 'r') {
|
|
|
|
$return='r';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($return=='w') {
|
2008-02-08 18:39:24 +01:00
|
|
|
break;
|
2008-11-12 17:57:40 +01:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
$this -> _myRights = $return;
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajoute l'attribut au formualaire de vue
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette méthode ajoute l'attribut au formulaire $form de vue si il doit l'être
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] object $form Le formulaire dans lequel doit être ajouté l'attribut
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si l'ajout a fonctionner ou qu'il n'est pas nécessaire, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function addToView(&$form) {
|
2009-02-12 10:08:40 +01:00
|
|
|
if((isset($this -> config['view'])) && ($this -> config['view']) && ($this -> myRights() != 'n') ) {
|
2009-01-02 17:00:25 +01:00
|
|
|
if (!$this -> html) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
|
2009-01-02 17:00:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
if($this -> data !='') {
|
|
|
|
$data=$this -> getFormVal();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$data='';
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
$element = $this -> html -> addToForm($form,'view',$data);
|
2008-07-18 16:43:19 +02:00
|
|
|
if(!$element instanceof LSformElement) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSform_06',$this -> name);
|
2008-07-18 16:43:19 +02:00
|
|
|
return;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
$element -> freeze();
|
|
|
|
return true;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
|
|
|
* Rafraichis la valeur de l'attribut dans un formualaire
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] object &$form LSform Le formulaire dans lequel doit être ajouté l'attribut
|
2007-11-15 19:07:24 +01:00
|
|
|
* @param[in] string $idForm L'identifiant du formulaire
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si la valeur a été rafraichie ou que ce n'est pas nécessaire, false sinon
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
|
|
|
function refreshForm(&$form,$idForm) {
|
2008-10-27 17:10:10 +01:00
|
|
|
if(isset($this -> config['form'][$idForm])&&($this -> myRights()!='n')) {
|
2009-01-02 17:00:25 +01:00
|
|
|
if (!$this -> html) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
|
2009-01-02 17:00:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
$form_element = $form -> getElement($this -> name);
|
2008-10-27 17:05:26 +01:00
|
|
|
if ($form_element) {
|
|
|
|
$values = $this -> html -> refreshForm($this -> getFormVal());
|
|
|
|
return $form_element -> setValue($values);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSdebug('LSformElement "'.$this -> name.'" n\'existe pas');
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Retourne la valeur a afficher dans le formulaire
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval string La valeur a afficher dans le formulaire.
|
|
|
|
*/
|
|
|
|
function getFormVal() {
|
2011-01-20 12:15:51 +01:00
|
|
|
$data=$this -> html -> getFormVal($this -> data);
|
2008-10-15 11:59:52 +02:00
|
|
|
if ($data==NULL) {
|
|
|
|
$data=array();
|
|
|
|
}
|
2008-10-06 17:53:52 +02:00
|
|
|
if(!is_array($data)) {
|
2008-02-08 18:39:24 +01:00
|
|
|
$data=array($data);
|
2008-10-06 16:53:32 +02:00
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
return $data;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Définis les données de mises à jour si un changement a eut lieu
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] string $data Les données de mise à jour.
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
function setUpdateData($data) {
|
2010-02-14 20:06:19 +01:00
|
|
|
if($this -> ldap -> isUpdated($data)) {
|
2007-03-29 18:10:14 +02:00
|
|
|
$this -> updateData=$data;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Vérifie si l'attribut a été validé
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si l'attribut a été validé, false sinon
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
|
|
|
function isValidate() {
|
2007-11-15 19:07:24 +01:00
|
|
|
return $this -> is_validate;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Valide le champs
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function validate() {
|
|
|
|
$this -> is_validate=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Vérifie si l'attribut a été mise à jour
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si l'attribut a été mis à jour, false sinon
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
|
|
|
function isUpdate() {
|
2008-10-15 11:12:20 +02:00
|
|
|
return ($this -> updateData===false)?false:true;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Vérifie si l'attribut est obligatoire
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval boolean true si l'attribut est obligatoire, false sinon
|
|
|
|
*/
|
|
|
|
function isRequired() {
|
2010-11-16 19:45:41 +01:00
|
|
|
return (isset($this -> config['required'])?(bool)$this -> config['required']:false);
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Vérifie si la valeur de l'attribut peut être générée
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si la valeur de l'attribut peut être générée, false sinon
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
|
|
|
function canBeGenerated() {
|
2010-01-06 15:21:37 +01:00
|
|
|
return (
|
|
|
|
(function_exists($this -> config['generate_function']))
|
|
|
|
||
|
|
|
|
(isset($this -> config['generate_value_format']))
|
|
|
|
||
|
|
|
|
(
|
|
|
|
(is_string($this -> config['default_value']))
|
|
|
|
&&
|
|
|
|
(strlen($this -> config['default_value'])>0)
|
|
|
|
)
|
|
|
|
);
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Génere la valeur de l'attribut à partir de la fonction de génération
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si la valeur à put être générée, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function generateValue() {
|
2010-03-09 17:40:22 +01:00
|
|
|
$value=false;
|
2008-07-29 15:45:02 +02:00
|
|
|
if (function_exists($this -> config['generate_function'])) {
|
2017-04-28 10:22:01 +02:00
|
|
|
$value=call_user_func_array($this -> config['generate_function'],array(&$this -> ldapObject));
|
2008-07-29 15:45:02 +02:00
|
|
|
}
|
|
|
|
else if (isset($this -> config['generate_value_format'])) {
|
|
|
|
$value = $this -> ldapObject -> getFData($this -> config['generate_value_format']);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2010-01-06 15:21:37 +01:00
|
|
|
else if (is_string($this -> config['default_value']) && strlen($this -> config['default_value'])>0) {
|
2010-03-16 17:48:12 +01:00
|
|
|
$value = $this -> ldapObject -> getFData($this -> config['default_value']);
|
2010-01-06 15:21:37 +01:00
|
|
|
}
|
2010-03-09 17:40:22 +01:00
|
|
|
if ($value!==false) {
|
|
|
|
if (!empty($value)) {
|
|
|
|
if (!is_array($value)) {
|
|
|
|
$value=array($value);
|
|
|
|
}
|
|
|
|
$this -> updateData=$value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this -> updateData=array();
|
2010-03-09 17:04:36 +01:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Retourne la valeur de l'attribut pour son enregistrement dans l'annuaire
|
2008-04-25 16:09:27 +02:00
|
|
|
* si l'attribut à été modifié.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval mixed La valeur de l'attribut pour son enregistrement dans l'annuaire
|
|
|
|
*/
|
|
|
|
function getUpdateData() {
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$this -> isUpdate()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( $this -> _finalUpdateData ) {
|
|
|
|
return $this -> _finalUpdateData;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
$data=$this -> updateData;
|
2010-11-16 19:46:52 +01:00
|
|
|
if (isset($this -> config['onSave'])) {
|
2007-03-29 18:10:14 +02:00
|
|
|
if (is_array($this -> config['onSave'])) {
|
|
|
|
$result=$data;
|
|
|
|
foreach($this -> config['onSave'] as $func) {
|
|
|
|
if (function_exists($func)) {
|
2017-04-26 10:40:37 +02:00
|
|
|
$result=call_user_func($func, $result);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_05',array('attr' => $this->name,'func' => $func));
|
2007-03-29 18:10:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (function_exists($this -> config['onSave'])) {
|
2007-11-15 19:07:24 +01:00
|
|
|
$result = $this -> config['onSave']($data);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_05',array('attr' => $this->name,'func' => $this -> config['onSave']));
|
2007-03-29 18:10:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
else {
|
2009-01-02 17:00:25 +01:00
|
|
|
if (!$this -> ldap) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_09',array('type' => 'ldap','name' => $this -> name));
|
2009-01-02 17:00:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$result = $this -> ldap -> getUpdateData($data);
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> _finalUpdateData = $result;
|
2007-11-15 19:07:24 +01:00
|
|
|
return $result;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2007-11-15 19:07:24 +01:00
|
|
|
* Retourne la configuration de validation de l'attribut
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval mixed La configuration de validation de l'attribut
|
|
|
|
*/
|
|
|
|
function getValidateConfig() {
|
2012-09-03 10:22:18 +02:00
|
|
|
if (isset($this -> config['validation'])) {
|
|
|
|
return $this -> config['validation'];
|
|
|
|
}
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne les attributs dépendants de celui-ci
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval array les noms des attributs dépendants
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
|
|
|
function getDependsAttrs() {
|
2010-11-16 19:47:23 +01:00
|
|
|
return (isset($this -> config['dependAttrs'])?$this -> config['dependAttrs']:null);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
2008-10-31 13:12:31 +01:00
|
|
|
/**
|
|
|
|
* Ajouter une action lors d'un événement
|
|
|
|
*
|
|
|
|
* @param[in] $event string Le nom de l'événement
|
|
|
|
* @param[in] $fct string Le nom de la fonction à exectuer
|
|
|
|
* @param[in] $params mixed Paramètres pour le lancement de la fonction
|
|
|
|
* @param[in] $class Nom de la classe possèdant la méthode $fct à executer
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function addEvent($event,$fct,$params,$class=NULL) {
|
|
|
|
$this -> _events[$event][] = array(
|
|
|
|
'function' => $fct,
|
|
|
|
'params' => $params,
|
|
|
|
'class' => $class
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajouter une action sur un objet lors d'un événement
|
|
|
|
*
|
|
|
|
* @param[in] $event string Le nom de l'événement
|
|
|
|
* @param[in] $obj object L'objet dont la méthode doit être executé
|
|
|
|
* @param[in] $meth string Le nom de la méthode
|
|
|
|
* @param[in] $params mixed Paramètres d'execution de la méthode
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function addObjectEvent($event,&$obj,$meth,$params=NULL) {
|
|
|
|
$this -> _objectEvents[$event][] = array(
|
2015-04-14 15:10:40 +02:00
|
|
|
'obj' => &$obj,
|
2008-10-31 13:12:31 +01:00
|
|
|
'meth' => $meth,
|
|
|
|
'params' => $params
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lance les actions à executer lors d'un événement
|
|
|
|
*
|
|
|
|
* @param[in] $event string Le nom de l'événement
|
|
|
|
*
|
|
|
|
* @retval boolean True si tout c'est bien passé, false sinon
|
|
|
|
*/
|
|
|
|
function fireEvent($event) {
|
|
|
|
$return = true;
|
|
|
|
if(isset($this -> config[$event])) {
|
|
|
|
if (!is_array($this -> config[$event])) {
|
|
|
|
$funcs = array($this -> config[$event]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$funcs = $this -> config[$event];
|
|
|
|
}
|
|
|
|
foreach($funcs as $func) {
|
|
|
|
if(function_exists($func)) {
|
2017-04-28 10:22:01 +02:00
|
|
|
if(!call_user_func_array($func, array(&$this -> ldapObject))) {
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 19:48:11 +01:00
|
|
|
if (isset($this -> _events[$event]) && is_array($this -> _events[$event])) {
|
2008-10-31 13:12:31 +01:00
|
|
|
foreach ($this -> _events[$event] as $e) {
|
|
|
|
if ($e['class']) {
|
|
|
|
if (class_exists($e['class'])) {
|
|
|
|
$obj = new $e['class']();
|
|
|
|
if (method_exists($obj,$e['fct'])) {
|
|
|
|
try {
|
2017-04-28 10:22:01 +02:00
|
|
|
call_user_func_array(array($obj, $e['fct']), array(&$e['params']));
|
2008-10-31 13:12:31 +01:00
|
|
|
}
|
|
|
|
catch(Exception $er) {
|
|
|
|
$return = false;
|
|
|
|
LSdebug("Event ".$event." : Erreur durant l'execution de la méthode ".$e['fct']." de la classe ".$e['class']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSdebug("Event ".$event." : La méthode ".$e['fct']." de la classe ".$e['class']." n'existe pas.");
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$return = false;
|
|
|
|
LSdebug("Event ".$event." : La classe ".$e['class']." n'existe pas");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (function_exists($e['fct'])) {
|
|
|
|
try {
|
2017-04-28 10:22:01 +02:00
|
|
|
call_user_func_array($e['fct'], array(&$e['params']));
|
2008-10-31 13:12:31 +01:00
|
|
|
}
|
|
|
|
catch(Exception $er) {
|
|
|
|
LSdebug("Event ".$event." : Erreur durant l'execution de la function ".$e['fct']);
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSdebug("Event ".$event." : la function ".$e['fct']." n'existe pas");
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 19:48:11 +01:00
|
|
|
if (isset($this -> _objectEvents[$event]) && is_array($this -> _objectEvents[$event])) {
|
2008-10-31 13:12:31 +01:00
|
|
|
foreach ($this -> _objectEvents[$event] as $e) {
|
|
|
|
if (method_exists($e['obj'],$e['meth'])) {
|
|
|
|
try {
|
2017-04-28 10:22:01 +02:00
|
|
|
call_user_func_array(array($e['obj'], $e['meth']),array(&$e['params']));
|
2008-10-31 13:12:31 +01:00
|
|
|
}
|
|
|
|
catch(Exception $er) {
|
|
|
|
$return = false;
|
|
|
|
LSdebug("Event ".$event." : Erreur durant l'execution de la méthode ".$e['meth']." sur l'objet.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSdebug("Event ".$event." : La méthode ".$e['meth']." de l'objet n'existe pas.");
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:00:25 +01:00
|
|
|
/**
|
|
|
|
* Error Codes
|
|
|
|
**/
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattribute_01',
|
|
|
|
_("LSattribute : Attribute %{attr} : LDAP or HTML types unknow (LDAP = %{ldap} & HTML = %{html}).")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattribute_02',
|
|
|
|
_("LSattribute : The function %{func} to display the attribute %{attr} is unknow.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattribute_03',
|
|
|
|
_("LSattribute : The rule %{rule} to validate the attribute %{attr} is unknow.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattribute_04',
|
|
|
|
_("LSattribute : Configuration data to verify the attribute %{attr} are incorrect.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattribute_05',
|
|
|
|
_("LSattribute : The function %{func} to save the attribute %{attr} is unknow.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattribute_06',
|
|
|
|
_("LSattribute : The value of the attribute %{attr} can't be generated.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattribute_07',
|
|
|
|
_("LSattribute : Generation of the attribute %{attr} failed.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattribute_08',
|
|
|
|
_("LSattribute : Generation of the attribute %{attr} did not return a correct value.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSattribute_09',
|
|
|
|
_("LSattribute : The attr_%{type} of the attribute %{name} is not yet defined.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
?>
|