2008-02-26 18:40:05 +01: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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type d'attribut HTML select_object
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
class LSattr_html_select_object extends LSattr_html{
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Ajoute l'attribut au formualaire passer en paramètre
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @param[in] &$form LSform Le formulaire
|
|
|
|
* @param[in] $idForm L'identifiant du formulaire
|
|
|
|
* @param[in] $data Valeur du champs du formulaire
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval LSformElement L'element du formulaire ajouté
|
2008-02-26 18:40:05 +01:00
|
|
|
*/
|
|
|
|
function addToForm (&$form,$idForm,$data=NULL) {
|
|
|
|
$this -> config['attrObject'] = $this;
|
|
|
|
$element=$form -> addElement('select_object', $this -> name, $this -> config['label'],$this -> config,$this);
|
|
|
|
if(!$element) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(206,$this -> name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($data) {
|
|
|
|
$values=$this -> getValues($data);
|
|
|
|
if ($values) {
|
|
|
|
$element -> setValue($values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$element -> setSelectableObject($this -> config['selectable_object']['object_type']);
|
|
|
|
return $element;
|
|
|
|
}
|
|
|
|
|
2008-05-14 16:43:23 +02:00
|
|
|
/**
|
|
|
|
* Effectue les tâches nécéssaires au moment du rafraichissement du formulaire
|
|
|
|
*
|
|
|
|
* Récupère un array du type array('DNs' => 'displayValue') à partir d'une
|
|
|
|
* liste de DNs.
|
|
|
|
*
|
|
|
|
* @param[in] $data mixed La valeur de l'attribut (liste de DNs)
|
|
|
|
*
|
|
|
|
* @retval mixed La valeur formatée de l'attribut (array('DNs' => 'displayValue'))
|
|
|
|
**/
|
2008-02-26 18:40:05 +01:00
|
|
|
function refreshForm($data) {
|
|
|
|
return $this -> getValues($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne un tableau des valeurs possibles de la liste
|
|
|
|
*
|
|
|
|
* @param[in] mixed Tableau des valeurs de l'attribut
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval array Tableau associatif des valeurs possible de la liste avec en clé
|
|
|
|
* la valeur des balises option et en valeur ce qui sera affiché.
|
2008-02-26 18:40:05 +01:00
|
|
|
*/
|
|
|
|
function getValues($values=NULL) {
|
|
|
|
$retInfos = array();
|
|
|
|
if (isset($this -> config['selectable_object'])) {
|
|
|
|
$conf=$this -> config['selectable_object'];
|
|
|
|
if (!isset($conf['object_type'])) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(102,$this -> name);
|
2008-10-06 15:11:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$GLOBALS['LSsession'] -> loadLSobject($conf['object_type'])) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1004,$conf['object_type']);
|
|
|
|
return;
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($values)) {
|
|
|
|
if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')) {
|
|
|
|
$list=array();
|
|
|
|
foreach($values as $dn) {
|
|
|
|
$obj=new $conf['object_type']();
|
|
|
|
if ($obj -> loadData($dn)) {
|
|
|
|
$list[]=$obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$filter='(|';
|
|
|
|
foreach($values as $val) {
|
|
|
|
$filter.='('.$conf['value_attribute'].'='.$val.')';
|
|
|
|
}
|
|
|
|
$filter.=')';
|
|
|
|
$obj = new $conf['object_type']();
|
|
|
|
$list = $obj -> listObjects($filter);
|
|
|
|
}
|
|
|
|
if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')) {
|
|
|
|
for($i=0;$i<count($list);$i++) {
|
|
|
|
$retInfos[$list[$i] -> dn]=$list[$i] -> getDisplayValue($conf['display_attribute']);
|
|
|
|
$DNs[]=$list[$i] -> dn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for($i=0;$i<count($list);$i++) {
|
2008-07-31 11:16:25 +02:00
|
|
|
$key = $val['value_attribute'] -> getValue();
|
|
|
|
$key = $key[0];
|
|
|
|
$retInfos[$list[$i] -> attrs[$key]]=$list[$i] -> getDisplayValue($conf['display_attribute']);
|
2008-02-26 18:40:05 +01:00
|
|
|
$DNs[]=$list[$i] -> dn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$_SESSION['LSselect'][$conf['object_type']]=$DNs;
|
|
|
|
return $retInfos;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne un tableau des valeurs de l'attribut à partir de la variable session
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval array Tableau associatif des valeurs possible de la liste avec en clé
|
|
|
|
* la valeur des balises option et en valeur ce qui sera affiché.
|
2008-02-26 18:40:05 +01:00
|
|
|
*/
|
|
|
|
function getValuesFromSession() {
|
|
|
|
$retInfos = array();
|
|
|
|
if (isset($this -> config['selectable_object'])) {
|
|
|
|
$conf=$this -> config['selectable_object'];
|
|
|
|
if (!isset($conf['object_type'])) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(102,$this -> name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_array($_SESSION['LSselect'][$conf['object_type']])) {
|
|
|
|
foreach($_SESSION['LSselect'][$conf['object_type']] as $dn) {
|
|
|
|
$obj = new $conf['object_type']();
|
|
|
|
if ($obj->loadData($dn)) {
|
|
|
|
if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')) {
|
|
|
|
$retInfos[$obj -> dn]=$obj -> getDisplayValue($conf['display_attribute']);
|
|
|
|
}
|
|
|
|
else {
|
2008-07-31 11:16:25 +02:00
|
|
|
$key = $val['value_attribute'] -> getValue();
|
|
|
|
$key = $key[0];
|
|
|
|
$retInfos[$obj -> attrs[$key]]=$obj -> getDisplayValue($conf['display_attribute']);
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
$DNs[]=$dn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$_SESSION['LSselect'][$conf['object_type']]=$DNs;
|
|
|
|
return $retInfos;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|