2008-10-06 15:11: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-12 11:57:27 +01:00
|
|
|
// Messages d'erreur
|
2008-10-06 15:11:14 +02:00
|
|
|
|
2009-01-12 11:57:27 +01:00
|
|
|
// Support
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('SUPANN_SUPPORT_01',
|
2009-02-14 00:06:58 +01:00
|
|
|
_("SUPANN Support : The constant %{const} is not defined.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2010-03-09 19:16:50 +01:00
|
|
|
LSerror :: defineError('SUPANN_SUPPORT_02',
|
|
|
|
_("SUPANN Support : The LSobject type %{type} does not exist. Can't work with entities..")
|
|
|
|
);
|
2012-08-10 12:31:06 +02:00
|
|
|
LSerror :: defineError('SUPANN_SUPPORT_03',
|
|
|
|
_("SUPANN Support : The global array %{array} is not defined.")
|
|
|
|
);
|
2008-10-06 15:11:14 +02:00
|
|
|
|
2009-01-12 11:57:27 +01:00
|
|
|
// Autres erreurs
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('SUPANN_01',
|
2009-02-14 00:06:58 +01:00
|
|
|
_("SUPANN Support : The attribute %{dependency} is missing. Unable to forge the attribute %{attr}.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2010-03-09 19:16:50 +01:00
|
|
|
LSerror :: defineError('SUPANN_02',
|
|
|
|
_("SUPANN Support : Can't get the basedn of entities. Unable to forge the attribute %{attr}.")
|
|
|
|
);
|
2014-11-20 00:44:41 +01:00
|
|
|
|
2008-10-06 15:11:14 +02:00
|
|
|
/**
|
|
|
|
* Verification du support SUPANN par ldapSaisie
|
2014-11-20 00:44:41 +01:00
|
|
|
*
|
2008-10-06 15:11:14 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval boolean true si SUPANN est pleinement supporté, false sinon
|
|
|
|
*/
|
|
|
|
function LSaddon_supann_support() {
|
|
|
|
$retval = true;
|
2014-11-20 00:44:41 +01:00
|
|
|
|
2014-12-13 00:04:10 +01:00
|
|
|
$MUST_DEFINE_STRING= array(
|
2008-10-06 15:11:14 +02:00
|
|
|
'LS_SUPANN_LASTNAME_ATTR',
|
2010-03-09 19:16:50 +01:00
|
|
|
'LS_SUPANN_FIRSTNAME_ATTR',
|
|
|
|
'LS_SUPANN_LSOBJECT_ENTITE_TYPE',
|
2012-08-10 12:31:06 +02:00
|
|
|
'LS_SUPANN_LSOBJECT_ENTITE_FORMAT_SHORTNAME',
|
2010-03-09 19:16:50 +01:00
|
|
|
'LS_SUPANN_ETABLISSEMENT_UAI',
|
|
|
|
'LS_SUPANN_ETABLISSEMENT_DN'
|
2008-10-06 15:11:14 +02:00
|
|
|
);
|
|
|
|
|
2014-12-13 00:04:10 +01:00
|
|
|
foreach($MUST_DEFINE_STRING as $string) {
|
|
|
|
if ( isset($GLOBALS[$string]) && is_string($GLOBALS[$string])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach(LSconfig :: get('ldap_servers') as $id => $infos) {
|
|
|
|
if ( !isset($infos['globals'][$string]) || !is_string($infos['globals'][$string])) {
|
|
|
|
LSerror :: addErrorCode('SUPANN_SUPPORT_01',$string);
|
|
|
|
$retval=false;
|
|
|
|
continue 2;
|
|
|
|
}
|
2008-10-06 15:11:14 +02:00
|
|
|
}
|
|
|
|
}
|
2010-03-09 19:16:50 +01:00
|
|
|
|
2012-08-10 12:31:06 +02:00
|
|
|
$MUST_DEFINE_ARRAY= array(
|
2014-11-20 00:44:41 +01:00
|
|
|
'supannNomenclatures',
|
2012-08-10 12:31:06 +02:00
|
|
|
);
|
|
|
|
foreach($MUST_DEFINE_ARRAY as $array) {
|
|
|
|
if ( !isset($GLOBALS[$array]) || !is_array($GLOBALS[$array])) {
|
2014-11-20 00:44:41 +01:00
|
|
|
LSerror :: addErrorCode('SUPANN_SUPPORT_03',$array);
|
2012-08-10 12:31:06 +02:00
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-13 00:04:10 +01:00
|
|
|
if (isset($GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'])) {
|
|
|
|
if ( ! LSsession :: loadLSobject( $GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'] ) ) {
|
|
|
|
LSerror :: addErrorCode('SUPANN_SUPPORT_02', $GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE']);
|
2010-03-09 19:16:50 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-20 00:44:41 +01:00
|
|
|
|
2008-10-06 15:11:14 +02:00
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
2014-11-20 00:44:41 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* Fonctions de génération de valeurs d'attributs
|
|
|
|
**********************************************************************/
|
|
|
|
|
2008-10-06 15:11:14 +02:00
|
|
|
/**
|
|
|
|
* Generation du displayName
|
2014-11-20 00:44:41 +01:00
|
|
|
*
|
2008-10-06 15:11:14 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval string Le displayName ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function generate_displayName($ldapObject) {
|
2014-12-13 00:04:10 +01:00
|
|
|
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('SUPANN_01',array('dependency' => $GLOBALS['LS_SUPANN_LASTNAME_ATTR'], 'attr' => 'cn'));
|
2008-10-06 15:11:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-12-13 00:04:10 +01:00
|
|
|
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('SUPANN_01',array('dependency' => $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'], 'attr' => 'cn'));
|
2008-10-06 15:11:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-13 00:04:10 +01:00
|
|
|
$noms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ] -> getValue();
|
|
|
|
$prenoms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ] -> getValue();
|
2008-10-06 15:11:14 +02:00
|
|
|
|
2008-10-06 15:36:41 +02:00
|
|
|
return ($prenoms[0].' '.$noms[0]);
|
2008-10-06 15:11:14 +02:00
|
|
|
}
|
2014-11-20 00:44:41 +01:00
|
|
|
|
2008-10-06 15:11:14 +02:00
|
|
|
/**
|
|
|
|
* Generation du CN
|
2014-11-20 00:44:41 +01:00
|
|
|
*
|
2008-10-06 15:11:14 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval string Le CN ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function generate_cn($ldapObject) {
|
2014-12-13 00:04:10 +01:00
|
|
|
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('SUPANN_01',array('dependency' => $GLOBALS['LS_SUPANN_LASTNAME_ATTR'], 'attr' => 'cn'));
|
2008-10-06 15:11:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-12-13 00:04:10 +01:00
|
|
|
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('SUPANN_01',array('dependency' => $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'], 'attr' => 'cn'));
|
2008-10-06 15:11:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-13 00:04:10 +01:00
|
|
|
$noms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ] -> getValue();
|
|
|
|
$prenoms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ] -> getValue();
|
2008-10-06 15:11:14 +02:00
|
|
|
|
2010-03-09 19:25:10 +01:00
|
|
|
return (withoutAccents($noms[0]).' '.withoutAccents($prenoms[0]));
|
2008-10-06 15:11:14 +02:00
|
|
|
}
|
2010-03-09 19:25:10 +01:00
|
|
|
|
2008-10-06 15:11:14 +02:00
|
|
|
/**
|
2010-03-09 19:25:10 +01:00
|
|
|
* Generation des valeurs de l'attribut eduPersonOrgUnitDN à partir des
|
|
|
|
* valeurs de l'attribut supannEntiteAffectation.
|
2014-11-20 00:44:41 +01:00
|
|
|
*
|
2010-03-09 19:25:10 +01:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval array Les valeurs de l'attribut eduPersonOrgUnitDN ou false
|
|
|
|
* si il y a un problème durant la génération
|
2014-11-20 00:44:41 +01:00
|
|
|
*/
|
2010-03-09 19:16:50 +01:00
|
|
|
function generate_eduPersonOrgUnitDN($ldapObject) {
|
|
|
|
if ( get_class($ldapObject -> attrs[ 'supannEntiteAffectation' ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('SUPANN_01',array('dependency' => 'supannEntiteAffectation', 'attr' => 'eduPersonOrgUnitDN'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$affectations = $ldapObject -> attrs[ 'supannEntiteAffectation' ] -> getUpdateData();
|
|
|
|
|
2014-12-13 00:04:10 +01:00
|
|
|
$basedn=LSconfig :: get('LSobjects.'.$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'].'.container_dn').','.LSsession::getTopDn();
|
2010-03-09 19:16:50 +01:00
|
|
|
if ($basedn=="") {
|
|
|
|
LSerror :: addErrorCode('SUPANN_02','eduPersonOrgUnitDN');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$retval=array();
|
|
|
|
foreach ($affectations as $aff) {
|
|
|
|
$retval[]="supannCodeEntite=".$aff.",$basedn";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
2010-03-09 19:25:10 +01:00
|
|
|
/**
|
2014-11-20 00:44:41 +01:00
|
|
|
* Generation de la valeur de l'attribut eduPersonPrimaryOrgUnitDN
|
2010-03-09 19:25:10 +01:00
|
|
|
* à partir de la valeur de l'attribut supannEntiteAffectationPrincipale.
|
2014-11-20 00:44:41 +01:00
|
|
|
*
|
2010-03-09 19:25:10 +01:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval array La valeur de l'attribut eduPersonPrimaryOrgUnitDN
|
|
|
|
* ou false si il y a un problème durant la génération
|
2014-11-20 00:44:41 +01:00
|
|
|
*/
|
2010-03-09 19:16:50 +01:00
|
|
|
function generate_eduPersonPrimaryOrgUnitDN($ldapObject) {
|
|
|
|
if ( get_class($ldapObject -> attrs[ 'supannEntiteAffectationPrincipale' ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('SUPANN_01',array('dependency' => 'supannEntiteAffectationPrincipale', 'attr' => 'eduPersonPrimaryOrgUnitDN'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$affectations = $ldapObject -> attrs[ 'supannEntiteAffectationPrincipale' ] -> getUpdateData();
|
|
|
|
|
2014-12-13 00:04:10 +01:00
|
|
|
$basedn=LSconfig :: get('LSobjects.'.$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'].'.container_dn').','.LSsession::getTopDn();
|
2010-03-09 19:16:50 +01:00
|
|
|
if ($basedn=="") {
|
|
|
|
LSerror :: addErrorCode('SUPANN_02','eduPersonPrimaryOrgUnitDN');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$retval=array();
|
|
|
|
foreach ($affectations as $aff) {
|
|
|
|
$retval[]="supannCodeEntite=".$aff.",$basedn";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
2010-03-09 19:25:10 +01:00
|
|
|
/**
|
2014-11-20 00:44:41 +01:00
|
|
|
* Generation de la valeur de l'attribut eduPersonOrgDN
|
2010-03-09 19:25:10 +01:00
|
|
|
* à partir de la valeur de l'attribut supannEtablissement.
|
|
|
|
*
|
2014-12-13 00:04:10 +01:00
|
|
|
* La valeur sera $GLOBALS['LS_SUPANN_ETABLISSEMENT_DN'] si l'attribut supannEtablissement
|
|
|
|
* vaut {UAI}$GLOBALS['LS_SUPANN_ETABLISSEMENT_UAI'].
|
2014-11-20 00:44:41 +01:00
|
|
|
*
|
2010-03-09 19:25:10 +01:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval array La valeur de l'attribut eduPersonOrgDN ou false
|
|
|
|
* si il y a un problème durant la génération
|
2014-11-20 00:44:41 +01:00
|
|
|
*/
|
2010-03-09 19:16:50 +01:00
|
|
|
function generate_eduPersonOrgDN($ldapObject) {
|
|
|
|
if ( get_class($ldapObject -> attrs[ 'supannEtablissement' ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('SUPANN_01',array('dependency' => 'supannEtablissement', 'attr' => 'eduPersonOrgDN'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$eta = $ldapObject -> attrs[ 'supannEtablissement' ] -> getUpdateData();
|
|
|
|
|
|
|
|
$retval=array();
|
2014-12-13 00:04:10 +01:00
|
|
|
if ($eta[0] == '{UAI}'.$GLOBALS['LS_SUPANN_ETABLISSEMENT_UAI']) {
|
|
|
|
$retval[] = $GLOBALS['LS_SUPANN_ETABLISSEMENT_DN'];
|
2010-03-09 19:16:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
2014-11-20 00:44:41 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* Fonction de parsing des valeurs spécifiques SUPANN
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse une valeur a etiquette SUPANN
|
|
|
|
*
|
|
|
|
* Exemple de valeur :
|
|
|
|
*
|
|
|
|
* {SUPANN}S410
|
|
|
|
*
|
|
|
|
* @param[in] $val La valeur
|
|
|
|
*
|
|
|
|
* @retval array Un tableau cle->valeur contenant label et value ou False
|
|
|
|
**/
|
|
|
|
function supannParseLabeledValue($value) {
|
|
|
|
if (preg_match('/^\{([^\}]*)\}(.*)$/',$value,$m)) {
|
|
|
|
return array(
|
|
|
|
'label'=>$m[1],
|
|
|
|
'value'=>$m[2]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-10 12:31:06 +02:00
|
|
|
/**
|
|
|
|
* Parse une valeur composite SUPANN
|
|
|
|
*
|
|
|
|
* Exemple de valeur :
|
|
|
|
*
|
|
|
|
* [key1=value][key2=value][key3=value]
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $val La valeur composite
|
|
|
|
*
|
|
|
|
* @retval array Un tableau contenant key->value ou false en cas d'erreur
|
|
|
|
**/
|
|
|
|
function supannParseCompositeValue($val) {
|
|
|
|
if (preg_match_all('/\[([^=]*)=([^\]]*)\]/',$val,$matches)) {
|
|
|
|
$parseValue=array();
|
|
|
|
for($i=0;$i<count($matches[0]);$i++) {
|
|
|
|
$parseValue[$matches[1][$i]]=$matches[2][$i];
|
|
|
|
}
|
|
|
|
return $parseValue;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-20 00:44:41 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* Fonctions relatives aux entités
|
|
|
|
**********************************************************************/
|
|
|
|
|
2012-08-10 12:31:06 +02:00
|
|
|
/**
|
2014-11-20 00:44:41 +01:00
|
|
|
* Retourne le nom court d'une entite en fonction de son identifiant
|
2012-08-10 12:31:06 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @param[in] $id L'identifiant de l'entite (supannCodeEntite)
|
2012-08-10 12:31:06 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @retval string Le nom de l'entite
|
2012-08-10 12:31:06 +02:00
|
|
|
**/
|
2014-11-20 00:44:41 +01:00
|
|
|
function supanGetEntiteNameById($id) {
|
2014-12-13 00:04:10 +01:00
|
|
|
if (LSsession::loadLSobject($GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'])) {
|
|
|
|
$e = new $GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE']();
|
|
|
|
$list=$e -> listObjectsName("(supannCodeEntite=$id)",NULL,array(),$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_FORMAT_SHORTNAME']);
|
2014-11-20 00:44:41 +01:00
|
|
|
if (count($list)==1) {
|
|
|
|
return array_pop($list);
|
|
|
|
}
|
2012-08-10 12:31:06 +02:00
|
|
|
}
|
2014-11-20 00:44:41 +01:00
|
|
|
return getFData(__("Entity %{id} (unrecognized)"),$id);
|
2012-08-10 12:31:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-20 00:44:41 +01:00
|
|
|
* Valide l'ID d'une entite
|
2012-08-10 12:31:06 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @param[in] $id L'identifiant de l'entite (supannCodeEntite)
|
2012-08-10 12:31:06 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @retval boolean True si une entité avec cet ID existe, False sinon
|
2012-08-10 12:31:06 +02:00
|
|
|
**/
|
2014-11-20 00:44:41 +01:00
|
|
|
function supannValidateEntityId($id) {
|
2014-12-13 00:04:10 +01:00
|
|
|
if (LSsession::loadLSobject($GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'])) {
|
|
|
|
$e = new $GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE']();
|
2014-11-20 00:44:41 +01:00
|
|
|
$list=$e -> listObjectsName("(supannCodeEntite=$id)");
|
2012-08-10 12:31:06 +02:00
|
|
|
if (count($list)==1) {
|
2014-11-20 00:44:41 +01:00
|
|
|
return true;
|
2012-08-10 12:31:06 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-20 00:44:41 +01:00
|
|
|
return false;
|
2012-08-10 12:31:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-20 00:44:41 +01:00
|
|
|
* Cherche des entités répond au pattern de recherche passé en paramètres
|
|
|
|
* et retourne un tableau mettant en relation leur identifiant et leur nom
|
|
|
|
* d'affichage.
|
2012-08-10 12:31:06 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @param[in] $pattern string Le pattern de recherche
|
2012-08-10 12:31:06 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @retval array Tableau du résultat de la recherche mettant en relation
|
|
|
|
* l'identifiant des entités trouvés avec leur nom d'affichage.
|
2012-08-10 12:31:06 +02:00
|
|
|
**/
|
2014-11-20 00:44:41 +01:00
|
|
|
function supannSearchEntityByPattern($pattern) {
|
|
|
|
$retval=array();
|
|
|
|
if (LSsession::loadLSclass('LSsearch')) {
|
|
|
|
$search=new LSsearch(
|
2014-12-13 00:04:10 +01:00
|
|
|
$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'],
|
2014-11-20 00:44:41 +01:00
|
|
|
'SUPANN:supannSearchEntityByPattern',
|
|
|
|
array(
|
|
|
|
'pattern' => $pattern,
|
|
|
|
'attributes' => array('supannCodeEntite'),
|
|
|
|
'sizelimit' => 10,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$search -> run();
|
|
|
|
|
|
|
|
foreach($search -> getSearchEntries() as $e) {
|
|
|
|
$code=$e->get('supannCodeEntite');
|
|
|
|
if (is_array($code)) $code=$code[0];
|
|
|
|
$retval[$code]=$e->displayName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $retval;
|
2012-08-10 12:31:06 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 00:44:41 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Fonctions relatives aux nomenclatures
|
|
|
|
**********************************************************************/
|
|
|
|
|
2012-10-03 15:04:10 +02:00
|
|
|
/**
|
2014-11-20 00:44:41 +01:00
|
|
|
* Vérifie si une valeur et son étiquette sont valide pour une table donnée
|
2012-10-03 15:04:10 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @param[in] $table La table de nomenclature
|
|
|
|
* @param[in] $label L'étiquette de la valeur
|
2012-10-03 15:04:10 +02:00
|
|
|
* @param[in] $value La valeur
|
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @retval booleab True si valide, False sinon
|
2012-10-03 15:04:10 +02:00
|
|
|
**/
|
2014-11-20 00:44:41 +01:00
|
|
|
function supannValidateNomenclatureValue($table,$label,$value) {
|
|
|
|
$label=strtoupper($label);
|
|
|
|
if (isset($GLOBALS['supannNomenclatures'][$label]) &&
|
|
|
|
isset($GLOBALS['supannNomenclatures'][$label][$table]) &&
|
|
|
|
isset($GLOBALS['supannNomenclatures'][$label][$table][$value])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-10-03 15:04:10 +02:00
|
|
|
}
|
|
|
|
|
2012-08-10 12:31:06 +02:00
|
|
|
/**
|
2014-11-20 00:44:41 +01:00
|
|
|
* Retourne le label d'une valeur en fonction de la table de nomenclature
|
|
|
|
* et de l'étiquette de la valeur.
|
2012-08-10 12:31:06 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @param[in] $table La table de nomenclature
|
|
|
|
* @param[in] $label L'étiquette de la valeur
|
2012-08-10 12:31:06 +02:00
|
|
|
* @param[in] $value La valeur
|
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @retval array Le label de la valeur. En cas de valeur nor-reconnue, retourne
|
|
|
|
* la valeur en spécifiant qu'elle n'est pas reconnue.
|
2012-08-10 12:31:06 +02:00
|
|
|
**/
|
2014-11-20 00:44:41 +01:00
|
|
|
function supannGetNomenclatureLabel($table,$label,$value) {
|
|
|
|
if (supannValidateNomenclatureValue($table,$label,$value)) {
|
|
|
|
$label=strtoupper($label);
|
|
|
|
return $GLOBALS['supannNomenclatures'][$label][$table][$value];
|
|
|
|
}
|
|
|
|
return getFData(__("%{value} (unrecognized value)"),$value);
|
2012-08-10 12:31:06 +02:00
|
|
|
}
|
|
|
|
|
2012-08-10 12:35:55 +02:00
|
|
|
/**
|
2014-11-20 00:44:41 +01:00
|
|
|
* Retourne les valeurs possibles d'une table de nomenclature
|
2012-08-10 12:35:55 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @param[in] $table La table de nomenclature
|
2012-08-10 12:35:55 +02:00
|
|
|
*
|
2014-11-20 00:44:41 +01:00
|
|
|
* @retval array Tableau contenant les valeurs possibles de la table
|
|
|
|
* de nomenclature
|
2012-08-10 12:35:55 +02:00
|
|
|
**/
|
2014-11-20 00:44:41 +01:00
|
|
|
function supannGetNomenclatureTable($table) {
|
|
|
|
$retval=array();
|
|
|
|
foreach($GLOBALS['supannNomenclatures'] as $label => $tables) {
|
|
|
|
if (isset($GLOBALS['supannNomenclatures'][$label][$table])) {
|
|
|
|
$retval[$label]=$GLOBALS['supannNomenclatures'][$label][$table];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $retval;
|
2012-08-10 12:35:55 +02:00
|
|
|
}
|
|
|
|
|