2007-03-29 18:10:14 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
2021-04-13 18:04:19 +02:00
|
|
|
* https://ldapsaisie.org
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2020-05-08 15:49:05 +02:00
|
|
|
LSsession :: loadLSclass('LSlog_staticLoggerClass');
|
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>
|
|
|
|
*/
|
2020-05-08 15:49:05 +02:00
|
|
|
class LSattribute extends LSlog_staticLoggerClass {
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2022-12-31 21:15:19 +01:00
|
|
|
/**
|
|
|
|
* Attribute name
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $name;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attribute configuration (LSobjects.<type>.attrs.<attr_name>)
|
|
|
|
* @var array<string,mixed>
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $config;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The reference of the parent LSldapObject object
|
|
|
|
* @var LSldapObject
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $ldapObject;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The implemented LSattr_ldap object
|
|
|
|
* @see LSattribute::__construct()
|
|
|
|
* @var LSattr_ldap
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $ldap;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The implemented LSattr_ldap object
|
|
|
|
* @see LSattribute::__construct()
|
|
|
|
* @var LSattr_html
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $html;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attribute data
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $data = array();
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attribute updated data
|
|
|
|
* @see LSattribute::setUpdateData()
|
|
|
|
* @see LSattribute::getUpdateData()
|
|
|
|
* @see LSattribute::isUpdate()
|
|
|
|
* @see LSattribute::reloadData()
|
|
|
|
* @see LSattribute::generateValue()
|
|
|
|
* @var array|false
|
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
var $updateData=false;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Telltale of the validation state of the new attibute data
|
|
|
|
* @see LSattribute::validate()
|
|
|
|
* @see LSattribute::isValidate()
|
|
|
|
* @see LSattribute::reloadData()
|
|
|
|
* @var bool
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $is_validate=false;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache of the validated new attribute data
|
|
|
|
* @see LSattribute::getUpdateData()
|
|
|
|
* @var array<string>
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $_finalUpdateData=array();
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache of the current connected user right on this attribute
|
|
|
|
* @see LSattribute::myRights()
|
|
|
|
* @var null|string
|
|
|
|
*/
|
|
|
|
var $_myRights=null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Object registered hooks on event
|
|
|
|
* @see LSattribute::addEvent()
|
|
|
|
* @see LSattribute::fireEvent()
|
|
|
|
* @var array<string,array>
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $_events=array();
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Object registered hooks on event trigger object methods
|
|
|
|
* @see LSattribute::addObjectEvent()
|
|
|
|
* @see LSattribute::fireEvent()
|
|
|
|
* @var array<string,array>
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $_objectEvents=array();
|
2020-04-29 15:54:21 +02:00
|
|
|
|
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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string $name Nom de l'attribut ldap
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param array $config Configuration de l'objet
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param LSldapObject &$ldapObject L'objet ldap parent
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean Retourne true si la création a réussi, false sinon.
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function __construct($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;
|
2021-01-29 15:59:13 +01:00
|
|
|
$html_type = $this -> getConfig('html_type', 'text', 'string');
|
|
|
|
$html_class = "LSattr_html_".$html_type;
|
|
|
|
$ldap_type = $this -> getConfig('ldap_type', 'ascii', 'string');
|
|
|
|
$ldap_class = "LSattr_ldap_".$ldap_type;
|
|
|
|
LSsession :: loadLSclass($html_class);
|
|
|
|
LSsession :: loadLSclass($ldap_class);
|
|
|
|
if (class_exists($html_class) && class_exists($ldap_class)) {
|
|
|
|
$this -> html = new $html_class($name, $config, $this);
|
|
|
|
$this -> ldap = new $ldap_class($name, $config, $this);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-01-29 15:59:13 +01:00
|
|
|
LSerror :: addErrorCode(
|
|
|
|
'LSattribute_01',
|
|
|
|
array('attr' => $name, 'html'=> $html_type, 'ldap' => $ldap_type)
|
|
|
|
);
|
2007-03-29 18:10:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2020-08-26 18:08:14 +02:00
|
|
|
/**
|
|
|
|
* Allow conversion of LSattribute to string
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return string The string representation of the LSattribute
|
2020-08-26 18:08:14 +02:00
|
|
|
*/
|
|
|
|
public function __toString() {
|
|
|
|
return strval($this -> ldapObject)." -> <LSattribute ".$this -> name.">";
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Retourne la valeur du label de l'attribut
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2023-01-02 01:17:46 +01:00
|
|
|
* @return string|false Le label de l'attribut, ou false
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @see LSattr_html::getLabel()
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2007-03-29 18:10:14 +02:00
|
|
|
|
2019-03-12 11:42:53 +01:00
|
|
|
public 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));
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2009-01-02 17:00:25 +01:00
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
return $this -> html -> getLabel();
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean true
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function loadData($attr_data) {
|
2020-11-30 19:37:44 +01:00
|
|
|
$this -> data = ensureIsArray($attr_data);
|
2007-03-29 18:10:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean true
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function reloadData($attr_data) {
|
2020-11-30 19:37:44 +01:00
|
|
|
$this -> data = ensureIsArray($attr_data);
|
|
|
|
$this -> updateData = false;
|
|
|
|
$this -> is_validate = false;
|
2007-11-15 19:07:24 +01:00
|
|
|
return true;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed La valeur de l'attribut
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public 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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed La valeur originale de l'attribut
|
2010-03-16 11:11:29 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getOldValue() {
|
2010-03-16 11:11:29 +01:00
|
|
|
return $this -> data;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2021-03-23 12:37:45 +01:00
|
|
|
* Return attribute's display value
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string|false $data Custom attribute data (optional, default: current attribute data)
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed The display value of the attribute
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2021-03-23 12:37:45 +01:00
|
|
|
public function getDisplayValue($data=false) {
|
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));
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2009-01-02 17:00:25 +01:00
|
|
|
}
|
2012-11-13 11:20:16 +01:00
|
|
|
|
2023-09-18 16:58:46 +02:00
|
|
|
$data = $this -> ldap -> getDisplayValue(
|
|
|
|
$data !== false ? $data : $this -> getValue()
|
|
|
|
);
|
2012-11-13 11:20:16 +01:00
|
|
|
|
2019-03-11 22:21:25 +01:00
|
|
|
$onDisplay = $this -> getConfig('onDisplay');
|
|
|
|
if ($onDisplay) {
|
|
|
|
$result = $data;
|
2020-11-30 19:43:52 +01:00
|
|
|
foreach(ensureIsArray($onDisplay) as $func) {
|
2019-03-11 22:21:25 +01:00
|
|
|
if (function_exists($func)) {
|
|
|
|
$result = call_user_func($func, $result);
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-03-11 22:21:25 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_02', array('attr' => $this->name, 'func' => $func));
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
return $result;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param object $form Le formulaire dans lequel doit être ajouté l'attribut
|
|
|
|
* @param string $idForm L'identifiant du formulaire
|
|
|
|
* @param object &$obj Objet utilisable pour la génération de la valeur de l'attribut
|
|
|
|
* @param string $idForm valeur de l'élement
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return 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
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function addToForm(&$form,$idForm,&$obj=NULL,$value=NULL) {
|
2021-02-05 11:42:55 +01:00
|
|
|
$form_mode = $this -> getConfig("form.$idForm", false);
|
|
|
|
self :: log_debug("$this -> addToForm($idForm): mode = ".varDump($form_mode));
|
|
|
|
if($form_mode === false) {
|
|
|
|
self :: log_debug("Attribute ".$this -> name." not in form $idForm.");
|
|
|
|
return True;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2021-02-22 15:50:43 +01:00
|
|
|
$myRights = $this -> myRights();
|
|
|
|
if($myRights == 'n') {
|
|
|
|
self :: log_debug("User can't read or write the attribute ".$this -> name.", don't add it to $idForm form.");
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2021-02-05 11:42:55 +01:00
|
|
|
$element = $this -> _addToForm($form, $idForm, $obj, $value);
|
|
|
|
if(!$element)
|
|
|
|
return false;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2021-02-05 11:42:55 +01:00
|
|
|
if($this -> getConfig('required', false, 'bool'))
|
|
|
|
$form -> setRequired($this -> name);
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2021-11-29 12:46:58 +01:00
|
|
|
if ( !$form_mode || ($myRights != 'w') ) {
|
2021-02-05 11:42:55 +01:00
|
|
|
self :: log_debug("Attribute ".$this -> name." is freeze in form $idForm.");
|
|
|
|
$element -> freeze();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$check_data = $this -> getConfig('check_data', array());
|
|
|
|
if(is_array($check_data)) {
|
2021-07-19 16:46:44 +02:00
|
|
|
foreach ($check_data as $rule => $rule_options) {
|
2021-07-19 16:47:20 +02:00
|
|
|
// Handle rule without options or message
|
|
|
|
if (is_int($rule) && is_string($rule_options)) {
|
|
|
|
$rule = $rule_options;
|
|
|
|
$rule_options = array();
|
|
|
|
}
|
2021-07-19 16:46:44 +02:00
|
|
|
// Check rule
|
|
|
|
if(!is_empty($rule) && !$form -> isRuleRegistered($rule)) {
|
|
|
|
LSerror :: addErrorCode('LSattribute_03', array('attr' => $this->name, 'rule' => $rule));
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2021-07-19 16:46:44 +02:00
|
|
|
// Add rule to form
|
|
|
|
$form -> addRule($this -> name, $rule, (is_array($rule_options)?$rule_options:array()));
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
}
|
2021-02-05 11:42:55 +01:00
|
|
|
else {
|
|
|
|
LSerror :: addErrorCode('LSattribute_04', $this->name);
|
|
|
|
}
|
2020-05-08 21:02:28 +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
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return string 'r'/'w'/'n' pour 'read'/'write'/'none'
|
2008-02-12 18:59:44 +01:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
private function myRights() {
|
2008-02-08 18:39:24 +01:00
|
|
|
// cache
|
|
|
|
if ($this -> _myRights != NULL) {
|
|
|
|
return $this -> _myRights;
|
|
|
|
}
|
|
|
|
$return='n';
|
2020-05-08 21:02:28 +02:00
|
|
|
if (php_sapi_name() == 'cli') {
|
|
|
|
// In CLI mode, take maximum rights affected to LSprofiles
|
|
|
|
foreach ($this -> getConfig("rights", array()) as $who => $right) {
|
|
|
|
if (in_array($right, array('r', 'w'))) {
|
|
|
|
$return = $right;
|
|
|
|
if ($return == 'w') break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$whoami = $this -> ldapObject -> whoami();
|
|
|
|
foreach($whoami as $who) {
|
2020-12-01 16:40:21 +01:00
|
|
|
$right = $this -> getConfig("rights.$who", null);
|
2020-05-08 21:02:28 +02:00
|
|
|
if (in_array($right, array('r', 'w'))) {
|
|
|
|
$return = $right;
|
|
|
|
if ($return == 'w') break;
|
|
|
|
}
|
2008-11-12 17:57:40 +01:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
$this -> _myRights = $return;
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-05 11:42:55 +01:00
|
|
|
* Add attribute to LSview
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param LSform &$form The LSform object
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param boolean $api_mode True if it's a view in API mode (=all accessible attributes present,
|
2021-06-30 18:11:26 +02:00
|
|
|
* optional, default: false)
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean True on success, False otherwise
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2021-06-30 18:11:26 +02:00
|
|
|
public function addToView(&$form, $api_mode=false) {
|
|
|
|
if ((!$api_mode && !$this -> getConfig('view', false, 'bool')) || ($this -> myRights() == 'n') )
|
2021-02-05 11:42:55 +01:00
|
|
|
return true;
|
|
|
|
$element = $this -> _addToForm($form, 'view');
|
|
|
|
if ($element) {
|
|
|
|
$element -> freeze();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add attribute to export
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param LSform &$form The LSform object
|
2021-02-05 11:42:55 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean True on success, False otherwise
|
2021-02-05 11:42:55 +01:00
|
|
|
*/
|
|
|
|
public function addToExport(&$form) {
|
|
|
|
if ($this -> myRights() == 'n')
|
|
|
|
return False;
|
|
|
|
$element = $this -> _addToForm($form, 'export');
|
|
|
|
if ($element) {
|
|
|
|
$element -> freeze();
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add attribute to a LSform for export
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param LSform $form The LSform object
|
2021-02-05 11:42:55 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return LSformElement|False LSformElement object on success, False otherwise
|
2021-02-05 11:42:55 +01:00
|
|
|
*/
|
|
|
|
private function _addToForm(&$form, $idForm, &$obj=NULL, $data=NULL) {
|
|
|
|
if (!$this -> html) {
|
|
|
|
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2021-02-05 11:42:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($data)) {
|
2020-09-11 13:34:42 +02:00
|
|
|
if(!is_empty($this -> data)) {
|
|
|
|
$data = $this -> getFormVal();
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2021-02-05 11:42:55 +01:00
|
|
|
else if ($obj && !is_empty($this -> getConfig('default_value'))) {
|
|
|
|
$data = $obj -> getFData($this -> getConfig('default_value'));
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2021-02-05 11:42:55 +01:00
|
|
|
|
|
|
|
$element = $this -> html -> addToForm($form, $idForm, $data);
|
|
|
|
if(!$element instanceof LSformElement) {
|
|
|
|
LSerror :: addErrorCode('LSform_06',$this -> name);
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2021-02-05 11:42:55 +01:00
|
|
|
}
|
|
|
|
return $element;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
|
|
|
* Rafraichis la valeur de l'attribut dans un formualaire
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param LSform $form LSform Le formulaire dans lequel doit être ajouté l'attribut
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string $idForm L'identifiant du formulaire
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return 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
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function refreshForm(&$form,$idForm) {
|
2019-03-11 22:21:25 +01:00
|
|
|
if ($this -> getConfig("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));
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2009-01-02 17:00:25 +01:00
|
|
|
}
|
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;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2021-03-23 14:27:27 +01:00
|
|
|
* Return the form display value
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param mixed $data Custom attribute data (optional, default: current attribute data)
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return string The form display value
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2021-03-23 14:27:27 +01:00
|
|
|
public function getFormVal($data=null) {
|
|
|
|
if (is_null($data)) {
|
|
|
|
$data = ($this -> isUpdate()?$this -> updateData:$this -> data);
|
|
|
|
}
|
|
|
|
return ensureIsArray($this -> html -> getFormVal($data));
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +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>
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param mixed $data Les données de mise à jour.
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function setUpdateData($data) {
|
2010-02-14 20:06:19 +01:00
|
|
|
if($this -> ldap -> isUpdated($data)) {
|
2020-11-30 19:37:44 +01:00
|
|
|
$this -> updateData = ensureIsArray($data);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02: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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean true si l'attribut a été validé, false sinon
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function isValidate() {
|
2007-11-15 19:07:24 +01:00
|
|
|
return $this -> is_validate;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Valide le champs
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function validate() {
|
2007-03-29 18:10:14 +02:00
|
|
|
$this -> is_validate=true;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean true si l'attribut a été mis à jour, false sinon
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function isUpdate() {
|
2008-10-15 11:12:20 +02:00
|
|
|
return ($this -> updateData===false)?false:true;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
2024-03-04 11:34:41 +01:00
|
|
|
* Check if the attribute is required
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2024-03-04 11:34:41 +01:00
|
|
|
* @return boolean True if the attribute is required, false otherwise.
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function isRequired() {
|
2019-03-11 22:21:25 +01:00
|
|
|
return $this -> getConfig('required', false, 'bool');
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
2024-03-04 11:34:41 +01:00
|
|
|
* Check if the attribute value could be generated
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2024-03-04 11:34:41 +01:00
|
|
|
* @return boolean True if the attribute value could be generated, false otherwise.
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function canBeGenerated() {
|
2019-03-11 22:21:25 +01:00
|
|
|
$format = $this -> getConfig('generate_value_format', $this -> getConfig('default_value'));
|
2021-02-04 10:33:13 +01:00
|
|
|
self :: log_debug($this."->canBeGenerated(): format=".varDump($format));
|
2010-01-06 15:21:37 +01:00
|
|
|
return (
|
2019-03-11 22:21:25 +01:00
|
|
|
(function_exists($this -> getConfig('generate_function')))
|
2010-01-06 15:21:37 +01:00
|
|
|
||
|
2020-12-02 19:53:29 +01:00
|
|
|
!is_empty($format)
|
2010-01-06 15:21:37 +01:00
|
|
|
);
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2024-03-04 11:34:41 +01:00
|
|
|
* Generate attribute value using its generation function, its generation format or its default
|
|
|
|
* value.
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2024-03-04 11:34:41 +01:00
|
|
|
* @return boolean True if value has been generated, false otherwise.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function generateValue() {
|
2020-12-02 20:17:18 +01:00
|
|
|
$value = $this -> getConfig('default_value', false);
|
2019-03-11 22:21:25 +01:00
|
|
|
$generate_function = $this -> getConfig('generate_function');
|
2020-12-02 20:17:18 +01:00
|
|
|
$format = $this -> getConfig('generate_value_format');
|
2019-03-11 22:21:25 +01:00
|
|
|
if ($generate_function && function_exists($generate_function)) {
|
|
|
|
$value = call_user_func_array($generate_function, array(&$this -> ldapObject));
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
else if ($format) {
|
|
|
|
$value = $this -> ldapObject -> getFData($format);
|
2010-01-06 15:21:37 +01:00
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
if ($value !== false) {
|
2020-11-30 19:37:44 +01:00
|
|
|
$this -> updateData = ensureIsArray($value);
|
2020-12-01 16:48:07 +01:00
|
|
|
self :: log_debug($this."generateValue(): generated values = ".varDump($this -> updateData));
|
2008-02-08 18:39:24 +01:00
|
|
|
return true;
|
|
|
|
}
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2024-03-04 11:34:41 +01:00
|
|
|
/**
|
|
|
|
* Set attribute value as default
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @return boolean True if value has been set as default, false otherwise
|
|
|
|
*/
|
|
|
|
public function setValueAsDefault() {
|
|
|
|
$value = $this -> getConfig('default_value', false);
|
|
|
|
if ($value !== false) {
|
|
|
|
$this -> updateData = ensureIsArray($value);
|
|
|
|
self :: log_debug($this."setValueAsDefault(): default values = ".varDump($this -> updateData));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed La valeur de l'attribut pour son enregistrement dans l'annuaire
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getUpdateData() {
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$this -> isUpdate()) {
|
2023-01-02 01:17:46 +01:00
|
|
|
return null;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
if ( $this -> _finalUpdateData ) {
|
2023-01-02 01:17:46 +01:00
|
|
|
return $this -> _finalUpdateData;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
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));
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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']));
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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));
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2009-01-02 17:00:25 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2020-04-29 15:54:21 +02: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>
|
|
|
|
*
|
2023-01-02 01:17:46 +01:00
|
|
|
* @return array|null La configuration de validation de l'attribut
|
2007-03-29 18:10:14 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getValidateConfig() {
|
2012-09-03 10:22:18 +02:00
|
|
|
if (isset($this -> config['validation'])) {
|
|
|
|
return $this -> config['validation'];
|
|
|
|
}
|
2023-01-02 01:17:46 +01:00
|
|
|
return null;
|
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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return array les noms des attributs dépendants
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public 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
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $event Le nom de l'événement
|
|
|
|
* @param callable $fct Le nom de la fonction à exectuer
|
|
|
|
* @param array $params Paramètres pour le lancement de la fonction
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string $class Nom de la classe possèdant la méthode $fct à executer
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2008-10-31 13:12:31 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function addEvent($event,$fct,$params,$class=NULL) {
|
2008-10-31 13:12:31 +01:00
|
|
|
$this -> _events[$event][] = array(
|
|
|
|
'function' => $fct,
|
|
|
|
'params' => $params,
|
|
|
|
'class' => $class
|
|
|
|
);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-31 13:12:31 +01:00
|
|
|
/**
|
|
|
|
* Ajouter une action sur un objet lors d'un événement
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $event Le nom de l'événement
|
|
|
|
* @param object &$obj L'objet dont la méthode doit être executé
|
|
|
|
* @param string $meth Le nom de la méthode
|
|
|
|
* @param array $params Paramètres d'execution de la méthode
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2008-10-31 13:12:31 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function addObjectEvent($event,&$obj,$meth,$params=NULL) {
|
2008-10-31 13:12:31 +01:00
|
|
|
$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
|
|
|
|
);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-31 13:12:31 +01:00
|
|
|
/**
|
|
|
|
* Lance les actions à executer lors d'un événement
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $event Le nom de l'événement
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean True si tout c'est bien passé, false sinon
|
2008-10-31 13:12:31 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function fireEvent($event) {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_debug(strval($this)." -> fireEvent($event)");
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = true;
|
|
|
|
if(isset($this -> config[$event])) {
|
2020-11-30 19:43:52 +01:00
|
|
|
foreach(ensureIsArray($this -> config[$event]) as $func) {
|
2008-10-31 13:12:31 +01:00
|
|
|
if(function_exists($func)) {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_debug(strval($this)." -> fireEvent($event): run ".format_callable($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 {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_warning(strval($this)." -> fireEvent($event): function '".format_callable($func)."' doesn't exists.");
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-26 18:08:14 +02:00
|
|
|
else
|
|
|
|
self :: log_trace(strval($this)." -> fireEvent($event): no configured trigger for this event.");
|
2020-04-29 15:54:21 +02:00
|
|
|
|
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 {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_debug(strval($this)." -> fireEvent($event): run ".format_callable(array($obj, $e['fct'])));
|
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) {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_exception($er, strval($this)." -> fireEvent($event): exception occured running ".format_callable(array($obj, $e['fct'])));
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_warning(strval($this)." -> fireEvent($event): method '".$e['fct']."' of the class '".$e['class']."' doesn't exists.");
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_warning(strval($this)." -> fireEvent($event): the class '".$e['class']."' doesn't exists.");
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (function_exists($e['fct'])) {
|
|
|
|
try {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_debug(strval($this)." -> fireEvent($event): run ".format_callable($e['fct']));
|
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) {
|
2022-12-31 04:09:56 +01:00
|
|
|
self :: log_exception($er, strval($this)." -> fireEvent($event): exception occured running ".format_callable($e['fct']));
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_warning(strval($this)." -> fireEvent($event): the function '".$e['fct']."' doesn't exists.");
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
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) {
|
2020-08-26 18:08:14 +02:00
|
|
|
if (method_exists($e['obj'], $e['meth'])) {
|
2008-10-31 13:12:31 +01:00
|
|
|
try {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_debug(strval($this)." -> fireEvent($event): run ".format_callable(array($e['obj'], $e['meth'])));
|
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) {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_exception($er, strval($this)." -> fireEvent($event): exception occured running ".format_callable(array($e['obj'], $e['meth'])));
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-08-26 18:08:14 +02:00
|
|
|
self :: log_warning(strval($this)." -> fireEvent($event): the method '".$e['meth']."' of the object doesn't exists.");
|
2008-10-31 13:12:31 +01:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-31 13:12:31 +01:00
|
|
|
return $return;
|
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a configuration parameter (or default value)
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $param The configuration parameter
|
|
|
|
* @param mixed $default The default value (default : null)
|
|
|
|
* @param string $cast Cast resulting value in specific type (default : disabled)
|
2019-03-11 22:21:25 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed The configuration parameter value or default value if not set
|
2019-03-11 22:21:25 +01:00
|
|
|
**/
|
|
|
|
public function getConfig($param, $default=null, $cast=null) {
|
|
|
|
return LSconfig :: get($param, $default, $cast, $this -> config);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
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',
|
2024-03-04 11:34:41 +01:00
|
|
|
___("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',
|
2024-03-04 11:34:41 +01:00
|
|
|
___("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',
|
2024-03-04 11:34:41 +01:00
|
|
|
___("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',
|
2024-03-04 11:34:41 +01:00
|
|
|
___("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',
|
2024-03-04 11:34:41 +01:00
|
|
|
___("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',
|
2024-03-04 11:34:41 +01:00
|
|
|
___("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',
|
2024-03-04 11:34:41 +01:00
|
|
|
___("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',
|
2024-03-04 11:34:41 +01:00
|
|
|
___("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',
|
2024-03-04 11:34:41 +01:00
|
|
|
___("LSattribute: The attr_%{type} of the attribute %{name} is not yet defined.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSattribute_10',
|
|
|
|
___("LSattribute: The default value of the attribute %{attr} is invalid.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSattribute_11',
|
|
|
|
___("LSattribute: Fail to set attribute %{attr} value as default.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|