Code cleaning: fix tabs

This commit is contained in:
Benjamin Renard 2021-06-10 18:45:00 +02:00
parent febb83e39d
commit 40fdc92451
47 changed files with 1814 additions and 1795 deletions

View file

@ -69,7 +69,7 @@ $GLOBALS['LS_SUPANN_EPUI_FORMAT'] = "%{uniqueId}@univ.fr";
* '[key2]' => '[label2],
* [...]
* )
* ),
* ),
* );
*
* [ETIQUETTE] : l'étiquette de la valeur (correspondant le plus souvent ou mainteneur de la nomenclature)
@ -92,57 +92,57 @@ $GLOBALS['LS_SUPANN_EPUI_FORMAT'] = "%{uniqueId}@univ.fr";
*
*/
$GLOBALS['supannNomenclatures'] = array (
'SUPANN' => array (
'civilite' => array(
'Mme' => ___('Mrs.'),
'M.' => ___('Mr.'),
),
'affiliation' => array (
'researcher' => 'Chercheur (researcher)',
'retired' => 'Retraité (retired)',
'emeritus' => 'Professeur émérite (emeritus)',
'teacher' => 'Professeur (teacher)',
'registered-reader' => 'Lecteur enregistré dans une bibliothèque (registered-reader)',
),
'mailPriveLabel' => array (
'SECOURS' => ___('Backup'),
'PERSO' => ___('Personal'),
'PARENTS' => ___('Parents'),
'PRO' => ___('Professional'),
),
'adressePostalePriveeLabel' => array (
'TEMP' => ___('Temporary'),
'PERSO' => ___('Personal'),
'PARENTS' => ___('Parents'),
'PRO' => ___('Professional'),
),
'telephonePriveLabel' => array (
'MOBPERSO' => ___('Personal mobile'),
'FIXEPERSO' => ___('Personal landline'),
'FIXEPARENTS' => ___('Parents landline'),
'MOBPARENTS' => ___('Parents mobile'),
'MOBPRO' => ___('Professional mobile'),
'FIXEPRO' => ___('Professional landline'),
'SECOURS' => ___('Backup'),
),
),
'eduPerson' => array(
'affiliation' => array (
'student' => "Étudiant (student)",
'faculty' => "Membre du corps professoral (faculty)",
'staff' => "Personne exerçant une activité administrative, technique ou de support, autre que l'enseignement et la recherche (staff)",
'employee' => "Personne employée par l'établissement (employee)",
'member' => "Membre de l'établissement (member)",
'affiliate' => "Partenaire en relation avec l'établissement, sans en être membre (affiliate)",
'alum' => "Ancien étudiant (alum)",
'library-walk-in' => "Personne physiquement présente dans une bibliothèque (library-walk-in)",
),
),
'oidc' => array(
'oidc_genre' => array(
'female' => ___('Female'),
'male' => ___('Male'),
'other' => ___('Other'),
),
),
'SUPANN' => array (
'civilite' => array(
'Mme' => ___('Mrs.'),
'M.' => ___('Mr.'),
),
'affiliation' => array (
'researcher' => 'Chercheur (researcher)',
'retired' => 'Retraité (retired)',
'emeritus' => 'Professeur émérite (emeritus)',
'teacher' => 'Professeur (teacher)',
'registered-reader' => 'Lecteur enregistré dans une bibliothèque (registered-reader)',
),
'mailPriveLabel' => array (
'SECOURS' => ___('Backup'),
'PERSO' => ___('Personal'),
'PARENTS' => ___('Parents'),
'PRO' => ___('Professional'),
),
'adressePostalePriveeLabel' => array (
'TEMP' => ___('Temporary'),
'PERSO' => ___('Personal'),
'PARENTS' => ___('Parents'),
'PRO' => ___('Professional'),
),
'telephonePriveLabel' => array (
'MOBPERSO' => ___('Personal mobile'),
'FIXEPERSO' => ___('Personal landline'),
'FIXEPARENTS' => ___('Parents landline'),
'MOBPARENTS' => ___('Parents mobile'),
'MOBPRO' => ___('Professional mobile'),
'FIXEPRO' => ___('Professional landline'),
'SECOURS' => ___('Backup'),
),
),
'eduPerson' => array(
'affiliation' => array (
'student' => "Étudiant (student)",
'faculty' => "Membre du corps professoral (faculty)",
'staff' => "Personne exerçant une activité administrative, technique ou de support, autre que l'enseignement et la recherche (staff)",
'employee' => "Personne employée par l'établissement (employee)",
'member' => "Membre de l'établissement (member)",
'affiliate' => "Partenaire en relation avec l'établissement, sans en être membre (affiliate)",
'alum' => "Ancien étudiant (alum)",
'library-walk-in' => "Personne physiquement présente dans une bibliothèque (library-walk-in)",
),
),
'oidc' => array(
'oidc_genre' => array(
'female' => ___('Female'),
'male' => ___('Male'),
'other' => ___('Other'),
),
),
);

View file

@ -34,33 +34,33 @@ LSerror :: defineError('LSACCESSRIGHTSMATRIXVIEW_SUPPORT_01',
* @retval boolean true if LSaccessRightsMatrixView addon is totally supported, false in other case
*/
function LSaddon_LSaccessRightsMatrixView_support() {
$retval = True;
$MUST_DEFINE_ARRAY= array(
'LSaccessRightsMatrixView_allowed_LSprofiles',
);
foreach($MUST_DEFINE_ARRAY as $array) {
if ( !isset($GLOBALS[$array]) || !is_array($GLOBALS[$array])) {
LSerror :: addErrorCode('LSACCESSRIGHTSMATRIXVIEW_SUPPORT_01',$array);
$retval=false;
}
}
$retval = True;
$MUST_DEFINE_ARRAY= array(
'LSaccessRightsMatrixView_allowed_LSprofiles',
);
foreach($MUST_DEFINE_ARRAY as $array) {
if ( !isset($GLOBALS[$array]) || !is_array($GLOBALS[$array])) {
LSerror :: addErrorCode('LSACCESSRIGHTSMATRIXVIEW_SUPPORT_01',$array);
$retval=false;
}
}
if ($retval)
$retval = LSsession :: registerLSaddonView(
'LSaccessRightsMatrixView',
'accessRightsMatrix',
_('Access rights matrix'),
'LSaccessRightsMatrixView',
$GLOBALS['LSaccessRightsMatrixView_allowed_LSprofiles']
);
if ($retval)
$retval = LSsession :: registerLSaddonView(
'LSaccessRightsMatrixView',
'accessRightsMatrix',
_('Access rights matrix'),
'LSaccessRightsMatrixView',
$GLOBALS['LSaccessRightsMatrixView_allowed_LSprofiles']
);
return $retval;
return $retval;
}
function LSaccessRightsMatrixView() {
$LSprofiles = array(
'user' => _('All connected users'),
);
$LSprofiles = array(
'user' => _('All connected users'),
);
// Authenticable user objects types
$authObjTypes = LSauth :: getAuthObjectTypes();
foreach ($authObjTypes as $objType => $objParams)
@ -68,9 +68,9 @@ function LSaccessRightsMatrixView() {
$LSprofiles[$objType] = LSldapObject :: getLabel($objType);
// Custom configured LSprofiles
if (isset(LSsession :: $ldapServer["LSprofiles"]) && is_array(LSsession :: $ldapServer["LSprofiles"]))
foreach(LSsession :: $ldapServer["LSprofiles"] as $LSprofile => $LSprofile_conf)
$LSprofiles[$LSprofile] = (isset($LSprofile_conf['label'])?__($LSprofile_conf['label']):$LSprofile);
if (isset(LSsession :: $ldapServer["LSprofiles"]) && is_array(LSsession :: $ldapServer["LSprofiles"]))
foreach(LSsession :: $ldapServer["LSprofiles"] as $LSprofile => $LSprofile_conf)
$LSprofiles[$LSprofile] = (isset($LSprofile_conf['label'])?__($LSprofile_conf['label']):$LSprofile);
// List object types
$objectTypes = array();
@ -99,72 +99,72 @@ function LSaccessRightsMatrixView() {
}
}
$LSobjects = array();
foreach ($objectTypes as $LSobject) {
if (!LSsession :: loadLSobject($LSobject))
continue;
$LSobjects = array();
foreach ($objectTypes as $LSobject) {
if (!LSsession :: loadLSobject($LSobject))
continue;
// List attributes and rigths on their
$attrs = array();
foreach(LSconfig :: get("LSobjects.$LSobject.attrs", array()) as $attr_name => $attr_config) {
$raw_attr_rights = LSconfig :: get('rights', array(), 'array', $attr_config);
$attr_rights = array();
if (array_key_exists($LSobject, $authObjTypes))
$attr_rights['self'] = LSconfig :: get('self', False, null, $raw_attr_rights);
foreach(array_keys($LSprofiles) as $LSprofile) {
$attr_rights[$LSprofile] = LSconfig :: get($LSprofile, False, null, $raw_attr_rights);
}
$attrs[$attr_name] = array (
'label' => __(LSconfig :: get('label', $attr_name, 'string', $attr_config)),
'rights' => $attr_rights,
);
}
// List attributes and rigths on their
$attrs = array();
foreach(LSconfig :: get("LSobjects.$LSobject.attrs", array()) as $attr_name => $attr_config) {
$raw_attr_rights = LSconfig :: get('rights', array(), 'array', $attr_config);
$attr_rights = array();
if (array_key_exists($LSobject, $authObjTypes))
$attr_rights['self'] = LSconfig :: get('self', False, null, $raw_attr_rights);
foreach(array_keys($LSprofiles) as $LSprofile) {
$attr_rights[$LSprofile] = LSconfig :: get($LSprofile, False, null, $raw_attr_rights);
}
$attrs[$attr_name] = array (
'label' => __(LSconfig :: get('label', $attr_name, 'string', $attr_config)),
'rights' => $attr_rights,
);
}
// List relations and rigths on their
$relations = array();
foreach(LSconfig :: get("LSobjects.$LSobject.LSrelation", array()) as $relation_name => $relation_config) {
$raw_relation_rights = LSconfig :: get('rights', array(), 'array', $relation_config);
$relation_rights = array();
if (array_key_exists($LSobject, $authObjTypes))
$relation_rights['self'] = LSconfig :: get('self', False, null, $raw_relation_rights);
foreach(array_keys($LSprofiles) as $LSprofile) {
$relation_rights[$LSprofile] = LSconfig :: get($LSprofile, False, null, $raw_relation_rights);
}
$relations[$relation_name] = array (
'label' => __(LSconfig :: get('label', $relation_name, 'string', $relation_config)),
'rights' => $relation_rights,
);
}
// List relations and rigths on their
$relations = array();
foreach(LSconfig :: get("LSobjects.$LSobject.LSrelation", array()) as $relation_name => $relation_config) {
$raw_relation_rights = LSconfig :: get('rights', array(), 'array', $relation_config);
$relation_rights = array();
if (array_key_exists($LSobject, $authObjTypes))
$relation_rights['self'] = LSconfig :: get('self', False, null, $raw_relation_rights);
foreach(array_keys($LSprofiles) as $LSprofile) {
$relation_rights[$LSprofile] = LSconfig :: get($LSprofile, False, null, $raw_relation_rights);
}
$relations[$relation_name] = array (
'label' => __(LSconfig :: get('label', $relation_name, 'string', $relation_config)),
'rights' => $relation_rights,
);
}
// List customActions and rigths on their
$customActions = array();
foreach(LSconfig :: get("LSobjects.$LSobject.customActions", array()) as $action_name => $action_config) {
$raw_action_rights = LSconfig :: get('rights', array(), 'array', $action_config);
$action_rights = array();
if (array_key_exists($LSobject, $authObjTypes))
$action_rights['self'] = in_array('self', $raw_action_rights);
foreach(array_keys($LSprofiles) as $LSprofile)
$action_rights[$LSprofile] = in_array($LSprofile, $raw_action_rights);
$customActions[$action_name] = array (
'label' => __(LSconfig :: get('label', $action_name, 'string', $action_config)),
'rights' => $action_rights,
);
}
$raw_action_rights = LSconfig :: get('rights', array(), 'array', $action_config);
$action_rights = array();
if (array_key_exists($LSobject, $authObjTypes))
$action_rights['self'] = in_array('self', $raw_action_rights);
foreach(array_keys($LSprofiles) as $LSprofile)
$action_rights[$LSprofile] = in_array($LSprofile, $raw_action_rights);
$customActions[$action_name] = array (
'label' => __(LSconfig :: get('label', $action_name, 'string', $action_config)),
'rights' => $action_rights,
);
}
// List customSearchActions and rigths on their
$customSearchActions = array();
foreach(LSconfig :: get("LSobjects.$LSobject.LSsearch.customActions", array()) as $action_name => $action_config) {
$raw_action_rights = LSconfig :: get('rights', array(), 'array', $action_config);
$action_rights = array();
if (array_key_exists($LSobject, $authObjTypes))
$action_rights['self'] = in_array('self', $raw_action_rights);
foreach(array_keys($LSprofiles) as $LSprofile)
$action_rights[$LSprofile] = in_array($LSprofile, $raw_action_rights);
$customSearchActions[$action_name] = array (
'label' => __(LSconfig :: get('label', $action_name, 'string', $action_config)),
'rights' => $action_rights,
);
}
$raw_action_rights = LSconfig :: get('rights', array(), 'array', $action_config);
$action_rights = array();
if (array_key_exists($LSobject, $authObjTypes))
$action_rights['self'] = in_array('self', $raw_action_rights);
foreach(array_keys($LSprofiles) as $LSprofile)
$action_rights[$LSprofile] = in_array($LSprofile, $raw_action_rights);
$customSearchActions[$action_name] = array (
'label' => __(LSconfig :: get('label', $action_name, 'string', $action_config)),
'rights' => $action_rights,
);
}
// Handle LSform layout
$layout = false;
@ -187,30 +187,30 @@ function LSaccessRightsMatrixView() {
}
}
$LSobjects[$LSobject] = array (
'label' => __(LSconfig :: get("LSobjects.$LSobject.label", $LSobject, 'string')),
'attrs' => $attrs,
'relations' => $relations,
'customActions' => $customActions,
'customSearchActions' => $customSearchActions,
'layout' => $layout,
);
}
$LSobjects[$LSobject] = array (
'label' => __(LSconfig :: get("LSobjects.$LSobject.label", $LSobject, 'string')),
'attrs' => $attrs,
'relations' => $relations,
'customActions' => $customActions,
'customSearchActions' => $customSearchActions,
'layout' => $layout,
);
}
// Determine current LSobject
reset($LSobjects);
$LSobject = (isset($_REQUEST['LSobject']) && array_key_exists($_REQUEST['LSobject'], $LSobjects)?$_REQUEST['LSobject']:key($LSobjects));
// Determine current LSobject
reset($LSobjects);
$LSobject = (isset($_REQUEST['LSobject']) && array_key_exists($_REQUEST['LSobject'], $LSobjects)?$_REQUEST['LSobject']:key($LSobjects));
if (array_key_exists($LSobject, $authObjTypes))
$LSprofiles = array_merge(array('self' => _('The user him-self')), $LSprofiles);
if (array_key_exists($LSobject, $authObjTypes))
$LSprofiles = array_merge(array('self' => _('The user him-self')), $LSprofiles);
LSlog :: get_logger('LSaddon_LSaccessRightsMatrixView') -> debug($LSobjects);
LSlog :: get_logger('LSaddon_LSaccessRightsMatrixView') -> debug($LSobjects);
LStemplate :: assign('pagetitle', _('Access rights matrix'));
LStemplate :: assign('LSprofiles', $LSprofiles);
LStemplate :: assign('LSobjects', $LSobjects);
LStemplate :: assign('LSobject', $LSobject);
LStemplate :: assign('pagetitle', _('Access rights matrix'));
LStemplate :: assign('LSprofiles', $LSprofiles);
LStemplate :: assign('LSobjects', $LSobjects);
LStemplate :: assign('LSobject', $LSobject);
LStemplate :: addCssFile('LSaccessRightsMatrixView.css');
LSsession :: setTemplate('LSaccessRightsMatrixView.tpl');
LStemplate :: addCssFile('LSaccessRightsMatrixView.css');
LSsession :: setTemplate('LSaccessRightsMatrixView.tpl');
}

View file

@ -164,10 +164,10 @@ function mailquota_show_usage(&$LSldapObject) {
function mailquota_formatValue($value) {
$sizeFacts = array(
1073741824 => 'Go',
1048576 => 'Mo',
1024 => 'Ko',
1 => 'o',
1073741824 => 'Go',
1048576 => 'Mo',
1024 => 'Ko',
1 => 'o',
);
krsort($sizeFacts);
foreach($sizeFacts as $sill => $label) {

View file

@ -32,7 +32,7 @@ function LSaddon_showTechInfo_support() {
}
function showTechInfo($object) {
$dn = $object -> getDn();
$dn = $object -> getDn();
// Retreive internal attributes
$internal_attrs = LSldap :: getAttrs(
@ -111,7 +111,7 @@ function showTechInfo($object) {
// Sort other internal attributes by name
ksort($internal_attrs);
LStemplate :: assign('pagetitle', getFData(_('%{name}: Technical information'), $object -> getDisplayName()));
LStemplate :: assign('pagetitle', getFData(_('%{name}: Technical information'), $object -> getDisplayName()));
$LSview_actions=array();
$LSview_actions['return'] = array (
@ -125,14 +125,14 @@ function showTechInfo($object) {
LSform :: loadDependenciesDisplayView();
}
LStemplate :: assign('object', $object);
LStemplate :: assign('object_classes', $object_classes);
LStemplate :: assign('structural_object_class', $structural_object_class);
LStemplate :: assign('special_internal_attributes', $special_internal_attributes);
LStemplate :: assign('object', $object);
LStemplate :: assign('object_classes', $object_classes);
LStemplate :: assign('structural_object_class', $structural_object_class);
LStemplate :: assign('special_internal_attributes', $special_internal_attributes);
LStemplate :: assign('other_internal_attrs', $internal_attrs);
LStemplate :: addCssFile('showTechInfo.css');
LSsession :: setTemplate('showTechInfo.tpl');
LStemplate :: addCssFile('showTechInfo.css');
LSsession :: setTemplate('showTechInfo.tpl');
// Display template
LSsession :: displayTemplate();
exit();

View file

@ -47,147 +47,162 @@ LSerror :: defineError('SUPANN_04',
___("SUPANN: Fail to load nomenclature %{nomenclature}.")
);
/**
* Verification du support SUPANN par ldapSaisie
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si SUPANN est pleinement supporté, false sinon
*/
function LSaddon_supann_support() {
$retval = true;
/**
* Verification du support SUPANN par ldapSaisie
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si SUPANN est pleinement supporté, false sinon
*/
function LSaddon_supann_support() {
$retval = true;
$MUST_DEFINE_STRING= array(
'LS_SUPANN_LASTNAME_ATTR',
'LS_SUPANN_FIRSTNAME_ATTR',
'LS_SUPANN_LSOBJECT_ENTITE_TYPE',
'LS_SUPANN_LSOBJECT_ENTITE_FORMAT_SHORTNAME',
'LS_SUPANN_ETABLISSEMENT_UAI',
'LS_SUPANN_ETABLISSEMENT_DN',
'LS_SUPANN_EPPN_FORMAT',
'LS_SUPANN_EPUI_FORMAT',
);
$MUST_DEFINE_STRING = array(
'LS_SUPANN_LASTNAME_ATTR',
'LS_SUPANN_FIRSTNAME_ATTR',
'LS_SUPANN_LSOBJECT_ENTITE_TYPE',
'LS_SUPANN_LSOBJECT_ENTITE_FORMAT_SHORTNAME',
'LS_SUPANN_ETABLISSEMENT_UAI',
'LS_SUPANN_ETABLISSEMENT_DN',
'LS_SUPANN_EPPN_FORMAT',
'LS_SUPANN_EPUI_FORMAT',
);
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;
}
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;
}
}
$MUST_DEFINE_ARRAY= array(
'LS_SUPANN_LSOBJECT_PARRAIN_TYPES',
'supannNomenclatures',
);
foreach($MUST_DEFINE_ARRAY as $array) {
if ( !isset($GLOBALS[$array]) || !is_array($GLOBALS[$array])) {
LSerror :: addErrorCode('SUPANN_SUPPORT_03',$array);
$retval=false;
}
}
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']);
}
}
return $retval;
}
$MUST_DEFINE_ARRAY = array(
'LS_SUPANN_LSOBJECT_PARRAIN_TYPES',
'supannNomenclatures',
);
foreach($MUST_DEFINE_ARRAY as $array) {
if ( !isset($GLOBALS[$array]) || !is_array($GLOBALS[$array])) {
LSerror :: addErrorCode('SUPANN_SUPPORT_03',$array);
$retval=false;
}
}
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']);
}
}
return $retval;
}
/***********************************************************************
* Fonctions de génération de valeurs d'attributs
**********************************************************************/
* Fonctions de génération de valeurs d'attributs
**********************************************************************/
/**
* Generation du displayName
*
* @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) {
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ]) != 'LSattribute' ) {
LSerror :: addErrorCode('SUPANN_01',array('dependency' => $GLOBALS['LS_SUPANN_LASTNAME_ATTR'], 'attr' => 'cn'));
return;
}
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ]) != 'LSattribute' ) {
LSerror :: addErrorCode('SUPANN_01',array('dependency' => $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'], 'attr' => 'cn'));
return;
}
$noms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ] -> getValue();
$prenoms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ] -> getValue();
return ($prenoms[0].' '.$noms[0]);
/**
* Generation du displayName
*
* @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) {
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ]) != 'LSattribute' ) {
LSerror :: addErrorCode(
'SUPANN_01',
array('dependency' => $GLOBALS['LS_SUPANN_LASTNAME_ATTR'], 'attr' => 'cn')
);
return;
}
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ]) != 'LSattribute' ) {
LSerror :: addErrorCode(
'SUPANN_01',
array('dependency' => $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'], 'attr' => 'cn')
);
return;
}
/**
* Generation du CN
*
* @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) {
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ]) != 'LSattribute' ) {
LSerror :: addErrorCode('SUPANN_01',array('dependency' => $GLOBALS['LS_SUPANN_LASTNAME_ATTR'], 'attr' => 'cn'));
return;
}
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ]) != 'LSattribute' ) {
LSerror :: addErrorCode('SUPANN_01',array('dependency' => $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'], 'attr' => 'cn'));
return;
}
$noms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ] -> getValue();
$prenoms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ] -> getValue();
$noms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ] -> getValue();
$prenoms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ] -> getValue();
return ($prenoms[0].' '.$noms[0]);
}
return (withoutAccents($noms[0]).' '.withoutAccents($prenoms[0]));
/**
* Generation du CN
*
* @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) {
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ]) != 'LSattribute' ) {
LSerror :: addErrorCode(
'SUPANN_01',
array('dependency' => $GLOBALS['LS_SUPANN_LASTNAME_ATTR'], 'attr' => 'cn')
);
return;
}
if ( get_class($ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ]) != 'LSattribute' ) {
LSerror :: addErrorCode(
'SUPANN_01',
array('dependency' => $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'], 'attr' => 'cn')
);
return;
}
/**
* Generation des valeurs de l'attribut eduPersonOrgUnitDN à partir des
* valeurs de l'attribut supannEntiteAffectation.
*
* @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
*/
function generate_eduPersonOrgUnitDN($ldapObject) {
if ( get_class($ldapObject -> attrs[ 'supannEntiteAffectation' ]) != 'LSattribute' ) {
LSerror :: addErrorCode('SUPANN_01',array('dependency' => 'supannEntiteAffectation', 'attr' => 'eduPersonOrgUnitDN'));
return;
}
$noms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ] -> getValue();
$prenoms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_FIRSTNAME_ATTR'] ] -> getValue();
$affectations = $ldapObject -> attrs[ 'supannEntiteAffectation' ] -> getUpdateData();
return (withoutAccents($noms[0]).' '.withoutAccents($prenoms[0]));
}
$basedn=LSconfig :: get('LSobjects.'.$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'].'.container_dn').','.LSsession::getTopDn();
if ($basedn=="") {
LSerror :: addErrorCode('SUPANN_02','eduPersonOrgUnitDN');
return;
}
$retval=array();
foreach ($affectations as $aff) {
$retval[]="supannCodeEntite=".$aff.",$basedn";
}
return $retval;
/**
* Generation des valeurs de l'attribut eduPersonOrgUnitDN à partir des
* valeurs de l'attribut supannEntiteAffectation.
*
* @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
*/
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();
$basedn = LSconfig :: get('LSobjects.'.$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'].'.container_dn').','.LSsession::getTopDn();
if ($basedn == "") {
LSerror :: addErrorCode('SUPANN_02','eduPersonOrgUnitDN');
return;
}
$retval = array();
foreach ($affectations as $aff) {
$retval[] = "supannCodeEntite=".$aff.",$basedn";
}
return $retval;
}
/**
* Generation de la valeur de l'attribut eduPersonPrimaryOrgUnitDN
* à partir de la valeur de l'attribut supannEntiteAffectationPrincipale.
@ -199,28 +214,28 @@ LSerror :: defineError('SUPANN_04',
* @retval array La valeur de l'attribut eduPersonPrimaryOrgUnitDN
* ou false si il y a un problème durant la génération
*/
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();
$basedn=LSconfig :: get('LSobjects.'.$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'].'.container_dn').','.LSsession::getTopDn();
if ($basedn=="") {
LSerror :: addErrorCode('SUPANN_02','eduPersonPrimaryOrgUnitDN');
return;
}
$retval=array();
foreach ($affectations as $aff) {
$retval[]="supannCodeEntite=".$aff.",$basedn";
}
return $retval;
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();
$basedn = LSconfig :: get('LSobjects.'.$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'].'.container_dn').','.LSsession::getTopDn();
if ($basedn == "") {
LSerror :: addErrorCode('SUPANN_02','eduPersonPrimaryOrgUnitDN');
return;
}
$retval = array();
foreach ($affectations as $aff) {
$retval[]="supannCodeEntite=".$aff.",$basedn";
}
return $retval;
}
/**
* Generation de la valeur de l'attribut eduPersonOrgDN
* à partir de la valeur de l'attribut supannEtablissement.
@ -235,22 +250,22 @@ LSerror :: defineError('SUPANN_04',
* @retval array La valeur de l'attribut eduPersonOrgDN ou false
* si il y a un problème durant la génération
*/
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();
if ($eta[0] == '{UAI}'.$GLOBALS['LS_SUPANN_ETABLISSEMENT_UAI']) {
$retval[] = $GLOBALS['LS_SUPANN_ETABLISSEMENT_DN'];
}
return $retval;
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();
if ($eta[0] == '{UAI}'.$GLOBALS['LS_SUPANN_ETABLISSEMENT_UAI']) {
$retval[] = $GLOBALS['LS_SUPANN_ETABLISSEMENT_DN'];
}
return $retval;
}
/***********************************************************************
* Fonction de parsing des valeurs spécifiques SUPANN
**********************************************************************/
@ -266,15 +281,15 @@ LSerror :: defineError('SUPANN_04',
*
* @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;
function supannParseLabeledValue($value) {
if (preg_match('/^\{([^\}]*)\}(.*)$/', $value, $m)) {
return array(
'label' => $m[1],
'value' => $m[2]
);
}
return;
}
/**
* Parse une valeur composite SUPANN
@ -289,16 +304,16 @@ LSerror :: defineError('SUPANN_04',
*
* @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;
function supannParseCompositeValue($val) {
if (preg_match_all('/\[([^=]*)=([^\]]*)\]/',$val,$matches)) {
$parseValue = array();
for($i=0; $i<count($matches[0]); $i++) {
$parseValue[$matches[1][$i]] = array$matches[2][$i];
}
return;
return $parseValue;
}
return;
}
/***********************************************************************
* Fonctions relatives aux entités
@ -311,16 +326,16 @@ LSerror :: defineError('SUPANN_04',
*
* @retval string Le nom de l'entite
**/
function supanGetEntiteNameById($id) {
if (LSsession::loadLSobject($GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'])) {
$e = new $GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE']();
$list=$e -> listObjectsName("(supannCodeEntite=$id)",NULL,array('onlyAccessible' => false),$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_FORMAT_SHORTNAME']);
if (count($list)==1) {
return array_pop($list);
}
function supanGetEntiteNameById($id) {
if (LSsession::loadLSobject($GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'])) {
$e = new $GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE']();
$list=$e -> listObjectsName("(supannCodeEntite=$id)",NULL,array('onlyAccessible' => false),$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_FORMAT_SHORTNAME']);
if (count($list)==1) {
return array_pop($list);
}
return getFData(__("Entity %{id} (unrecognized)"),$id);
}
return getFData(__("Entity %{id} (unrecognized)"), $id);
}
/**
* Valide l'ID d'une entite
@ -329,16 +344,16 @@ LSerror :: defineError('SUPANN_04',
*
* @retval boolean True si une entité avec cet ID existe, False sinon
**/
function supannValidateEntityId($id) {
if (LSsession::loadLSobject($GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'])) {
$e = new $GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE']();
$list=$e -> listObjectsName("(supannCodeEntite=$id)",NULL,array('onlyAccessible' => False));
if (count($list)==1) {
return true;
}
function supannValidateEntityId($id) {
if (LSsession::loadLSobject($GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'])) {
$e = new $GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE']();
$list=$e -> listObjectsName("(supannCodeEntite=$id)",NULL,array('onlyAccessible' => False));
if (count($list)==1) {
return true;
}
return false;
}
return false;
}
/**
* Cherche des entités répond au pattern de recherche passé en paramètres
@ -351,29 +366,30 @@ LSerror :: defineError('SUPANN_04',
* @retval array Tableau du résultat de la recherche mettant en relation
* l'identifiant des entités trouvés avec leur nom d'affichage.
**/
function supannSearchEntityByPattern($pattern, $max_matches=10) {
$retval=array();
if (LSsession::loadLSclass('LSsearch')) {
$search=new LSsearch(
$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'],
'SUPANN:supannSearchEntityByPattern',
array(
'pattern' => $pattern,
'attributes' => array('supannCodeEntite'),
'sizelimit' => $max_matches,
'onlyAccessible' => false
)
);
$search -> run();
function supannSearchEntityByPattern($pattern, $max_matches=10) {
$retval = array();
if (LSsession::loadLSclass('LSsearch')) {
$search=new LSsearch(
$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'],
'SUPANN:supannSearchEntityByPattern',
array(
'pattern' => $pattern,
'attributes' => array('supannCodeEntite'),
'sizelimit' => $max_matches,
'onlyAccessible' => false
)
);
$search -> run();
foreach($search -> getSearchEntries() as $e) {
$code=$e->get('supannCodeEntite');
if (is_array($code)) $code=$code[0];
$retval[$code]=$e->displayName;
}
}
return $retval;
foreach($search -> getSearchEntries() as $e) {
$code = $e->get('supannCodeEntite');
if (is_array($code))
$code = $code[0];
$retval[$code] = $e->displayName;
}
}
return $retval;
}
/***********************************************************************
* Fonctions relatives aux parrains
@ -386,27 +402,27 @@ LSerror :: defineError('SUPANN_04',
*
* @retval array Le nom, le type et le DN du parrain (Format: array('dn' => [DN], 'type' => [type], 'name' => [name]))
**/
function supanGetParrainInfoByDN($dn) {
$matched = array(
'dn' => $dn,
'type' => null,
'name' => getFData(__("Godfather %{dn} (unrecognized)"), $dn),
function supanGetParrainInfoByDN($dn) {
$matched = array(
'dn' => $dn,
'type' => null,
'name' => getFData(__("Godfather %{dn} (unrecognized)"), $dn),
);
foreach($GLOBALS['LS_SUPANN_LSOBJECT_PARRAIN_TYPES'] as $type) {
if (!LSsession::loadLSobject($type)) continue;
$obj = new $type();
$list = $obj -> listObjectsName(
NULL, $dn,
array('onlyAccessible' => false, 'scope' => 'base'),
);
foreach($GLOBALS['LS_SUPANN_LSOBJECT_PARRAIN_TYPES'] as $type) {
if (!LSsession::loadLSobject($type)) continue;
$obj = new $type();
$list = $obj -> listObjectsName(
NULL, $dn,
array('onlyAccessible' => false, 'scope' => 'base'),
);
if (count($list)==1) {
$matched['type'] = $type;
$matched['name'] = array_pop($list);
break;
}
if (count($list)==1) {
$matched['type'] = $type;
$matched['name'] = array_pop($list);
break;
}
return $matched;
}
return $matched;
}
/**
* Valide le DN d'un parrain
@ -415,10 +431,10 @@ LSerror :: defineError('SUPANN_04',
*
* @retval boolean True si un parrain avec ce DN existe, False sinon
**/
function supannValidateParrainDN($dn) {
$info = supanGetParrainInfoByDN($dn);
return !is_null($info['type']);
}
function supannValidateParrainDN($dn) {
$info = supanGetParrainInfoByDN($dn);
return !is_null($info['type']);
}
/**
* Cherche des parrains répondant au pattern de recherche passé en paramètres
@ -430,30 +446,30 @@ LSerror :: defineError('SUPANN_04',
* @retval array Tableau du résultat de la recherche mettant en relation
* le DN des parrains trouvés avec leur nom d'affichage.
**/
function supannSearchParrainByPattern($pattern, $max_matches=10) {
$retval=array();
if (LSsession::loadLSclass('LSsearch')) {
foreach($GLOBALS['LS_SUPANN_LSOBJECT_PARRAIN_TYPES'] as $type) {
if (!LSsession::loadLSobject($type)) continue;
function supannSearchParrainByPattern($pattern, $max_matches=10) {
$retval = array();
if (LSsession::loadLSclass('LSsearch')) {
foreach($GLOBALS['LS_SUPANN_LSOBJECT_PARRAIN_TYPES'] as $type) {
if (!LSsession::loadLSobject($type)) continue;
$search=new LSsearch(
$type,
'SUPANN:supannSearchParrainByPattern',
array(
'pattern' => $pattern,
'sizelimit' => $max_matches,
'onlyAccessible' => false
)
);
$search -> run();
$search=new LSsearch(
$type,
'SUPANN:supannSearchParrainByPattern',
array(
'pattern' => $pattern,
'sizelimit' => $max_matches,
'onlyAccessible' => false
)
);
$search -> run();
foreach($search -> getSearchEntries() as $obj) {
$retval[$obj->dn] = $obj->displayName;
}
foreach($search -> getSearchEntries() as $obj) {
$retval[$obj->dn] = $obj->displayName;
}
}
return $retval;
}
}
return $retval;
}
/***********************************************************************
@ -469,38 +485,38 @@ LSerror :: defineError('SUPANN_04',
*
* @retval booleab True si valide, False sinon
**/
function supannValidateNomenclatureValue($table, $label, $value) {
if (!supannLoadNomenclature($table))
return false;
if ($label) {
$label = strtoupper($label);
if (
isset($GLOBALS['supannNomenclatures'][$label]) &&
isset($GLOBALS['supannNomenclatures'][$label][$table]) &&
isset($GLOBALS['supannNomenclatures'][$label][$table][$value])
) {
return array(
'table' => $table,
'label' => $label,
'value' => $value,
'translated' => $GLOBALS['supannNomenclatures'][$label][$table][$value],
);
}
function supannValidateNomenclatureValue($table, $label, $value) {
if (!supannLoadNomenclature($table))
return false;
if ($label) {
$label = strtoupper($label);
if (
isset($GLOBALS['supannNomenclatures'][$label]) &&
isset($GLOBALS['supannNomenclatures'][$label][$table]) &&
isset($GLOBALS['supannNomenclatures'][$label][$table][$value])
) {
return array(
'table' => $table,
'label' => $label,
'value' => $value,
'translated' => $GLOBALS['supannNomenclatures'][$label][$table][$value],
);
}
else {
foreach($GLOBALS['supannNomenclatures'] as $label => $tables) {
if (!array_key_exists($table, $tables) || !array_key_exists($value, $tables[$table]))
continue;
return array(
'table' => $table,
'label' => $label,
'value' => $value,
'translated' => $tables[$table][$value],
);
}
}
return false;
}
else {
foreach($GLOBALS['supannNomenclatures'] as $label => $tables) {
if (!array_key_exists($table, $tables) || !array_key_exists($value, $tables[$table]))
continue;
return array(
'table' => $table,
'label' => $label,
'value' => $value,
'translated' => $tables[$table][$value],
);
}
}
return false;
}
/**
* Retourne le label d'une valeur en fonction de la table de nomenclature
@ -513,12 +529,12 @@ LSerror :: defineError('SUPANN_04',
* @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.
**/
function supannGetNomenclatureLabel($table, $label, $value) {
$translated = supannValidateNomenclatureValue($table, $label, $value);
if ($translated)
return $translated['translated'];
return getFData(__("%{value} (unrecognized value)"), $value);
}
function supannGetNomenclatureLabel($table, $label, $value) {
$translated = supannValidateNomenclatureValue($table, $label, $value);
if ($translated)
return $translated['translated'];
return getFData(__("%{value} (unrecognized value)"), $value);
}
/**
* Retourne les valeurs possibles d'une table de nomenclature pour chaque fournisseur
@ -528,17 +544,17 @@ LSerror :: defineError('SUPANN_04',
* @retval array Tableau contenant pour chaque fournisseur, les valeurs possibles de
* la table de nomenclature
**/
function supannGetNomenclatureTable($table) {
$retval = array();
if (!supannLoadNomenclature($table))
return $retval;
foreach(array_keys($GLOBALS['supannNomenclatures']) as $provider) {
if (isset($GLOBALS['supannNomenclatures'][$provider][$table])) {
$retval[$provider] = $GLOBALS['supannNomenclatures'][$provider][$table];
}
}
return $retval;
function supannGetNomenclatureTable($table) {
$retval = array();
if (!supannLoadNomenclature($table))
return $retval;
foreach(array_keys($GLOBALS['supannNomenclatures']) as $provider) {
if (isset($GLOBALS['supannNomenclatures'][$provider][$table])) {
$retval[$provider] = $GLOBALS['supannNomenclatures'][$provider][$table];
}
}
return $retval;
}
/**
* Retourne les valeurs possibles d'une table de nomenclature
@ -551,21 +567,21 @@ LSerror :: defineError('SUPANN_04',
* @retval array Tableau contenant les valeurs possibles de la table
* de nomenclature
**/
function supannGetNomenclaturePossibleValues($table, $add_provider_label=True) {
$retval = array();
if (!supannLoadNomenclature($table))
return $retval;
foreach(array_keys($GLOBALS['supannNomenclatures']) as $provider) {
if (isset($GLOBALS['supannNomenclatures'][$provider][$table])) {
foreach($GLOBALS['supannNomenclatures'][$provider][$table] as $value => $label) {
if ($add_provider_label)
$value = "{$provider}$value";
$retval[$value] = __($label);
}
}
}
return $retval;
function supannGetNomenclaturePossibleValues($table, $add_provider_label=True) {
$retval = array();
if (!supannLoadNomenclature($table))
return $retval;
foreach(array_keys($GLOBALS['supannNomenclatures']) as $provider) {
if (isset($GLOBALS['supannNomenclatures'][$provider][$table])) {
foreach($GLOBALS['supannNomenclatures'][$provider][$table] as $value => $label) {
if ($add_provider_label)
$value = "{$provider}$value";
$retval[$value] = __($label);
}
}
}
return $retval;
}
/**
* Cherche des valeurs d'une nomenclature répondant au pattern de recherche passé en paramètres
@ -576,26 +592,26 @@ LSerror :: defineError('SUPANN_04',
*
* @retval array Tableau du résultat de la recherche
**/
function supannSearchNomenclatureValueByPattern($table, $pattern, $max_matches=10) {
$retval=array();
$pattern = withoutAccents(strtolower($pattern));
foreach(supannGetNomenclatureTable($table) as $label => $values) {
foreach($values as $value => $txt) {
if (strpos(withoutAccents(strtolower($txt)), $pattern) === false)
continue;
$retval[] = array(
'label' => $label,
'value' => '{'.$label.'}'.$value,
'translated' => $txt
);
if (count($retval) >= $max_matches)
break;
}
function supannSearchNomenclatureValueByPattern($table, $pattern, $max_matches=10) {
$retval = array();
$pattern = withoutAccents(strtolower($pattern));
foreach(supannGetNomenclatureTable($table) as $label => $values) {
foreach($values as $value => $txt) {
if (strpos(withoutAccents(strtolower($txt)), $pattern) === false)
continue;
$retval[] = array(
'label' => $label,
'value' => '{'.$label.'}'.$value,
'translated' => $txt
);
if (count($retval) >= $max_matches)
break;
}
return $retval;
if (count($retval) >= $max_matches)
break;
}
return $retval;
}
/**
* Retourne les valeurs possibles de l'attribut supannCivilite.
@ -653,14 +669,14 @@ function supannGetAffiliationPossibleValues($options=null, $name=null, $ldapObje
global $_supannCheckEduPersonAffiliation_checked;
$_supannCheckEduPersonAffiliation_checked = false;
function supannCheckEduPersonAffiliation(&$ldapObject) {
global $_supannCheckEduPersonAffiliation_checked;
$values = $ldapObject->getValue('eduPersonAffiliation');
global $_supannCheckEduPersonAffiliation_checked;
$values = $ldapObject->getValue('eduPersonAffiliation');
if (!$_supannCheckEduPersonAffiliation_checked && in_array('affiliate', $values) && in_array('member', $values)) {
$_supannCheckEduPersonAffiliation_checked = true;
return false;
}
return true;
if (!$_supannCheckEduPersonAffiliation_checked && in_array('affiliate', $values) && in_array('member', $values)) {
$_supannCheckEduPersonAffiliation_checked = true;
return false;
}
return true;
}
/**
@ -680,11 +696,11 @@ function supannCheckEduPersonAffiliation(&$ldapObject) {
* @retval boolean True si la valeur est valide, False sinon
**/
function supannCheckEduPersonPrimaryAffiliation(&$ldapObject) {
$primary = $ldapObject->getValue('eduPersonPrimaryAffiliation');
$affiliations = $ldapObject->getValue('eduPersonAffiliation');
if (!array_intersect($primary, $affiliations))
return false;
return true;
$primary = $ldapObject->getValue('eduPersonPrimaryAffiliation');
$affiliations = $ldapObject->getValue('eduPersonAffiliation');
if (!array_intersect($primary, $affiliations))
return false;
return true;
}
/**
@ -896,7 +912,7 @@ function supannLoadNomenclature($table) {
* si il y a un problème durant la génération
*/
function generate_eduPersonPrincipalName($ldapObject) {
return $ldapObject -> getFData($GLOBALS['LS_SUPANN_EPPN_FORMAT']);
return $ldapObject -> getFData($GLOBALS['LS_SUPANN_EPPN_FORMAT']);
}
/**

View file

@ -124,9 +124,9 @@ class LSattr_html extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -111,28 +111,28 @@ class LSattr_html_select_list extends LSattr_html{
$attrInfos=static :: getLSattributePossibleValues($val_label, $options, $name, $ldapObject);
$retInfos=static :: _array_merge($retInfos,$attrInfos);
}
elseif (is_array($val_label)) {
if (!isset($val_label['possible_values']) || !is_array($val_label['possible_values']) || !isset($val_label['label']))
continue;
$subRetInfos=array();
foreach($val_label['possible_values'] as $vk => $vl) {
if ($vk==='OTHER_OBJECT') {
$objInfos=static :: getLSobjectPossibleValues($vl,$options,$name);
$subRetInfos=static :: _array_merge($subRetInfos,$objInfos);
}
else {
$vk = $ldapObject->getFData($vk);
$vl = $ldapObject->getFData(($translate_labels?__($vl):$vl));
$subRetInfos[$vk] = $vl;
}
}
static :: _sort($subRetInfos,$options);
$subRetLabel = $ldapObject->getFData(($translate_labels?__($val_label['label']):$val_label['label']));
$retInfos[] = array (
'label' => $subRetLabel,
'possible_values' => $subRetInfos
);
}
elseif (is_array($val_label)) {
if (!isset($val_label['possible_values']) || !is_array($val_label['possible_values']) || !isset($val_label['label']))
continue;
$subRetInfos=array();
foreach($val_label['possible_values'] as $vk => $vl) {
if ($vk==='OTHER_OBJECT') {
$objInfos=static :: getLSobjectPossibleValues($vl,$options,$name);
$subRetInfos=static :: _array_merge($subRetInfos,$objInfos);
}
else {
$vk = $ldapObject->getFData($vk);
$vl = $ldapObject->getFData(($translate_labels?__($vl):$vl));
$subRetInfos[$vk] = $vl;
}
}
static :: _sort($subRetInfos,$options);
$subRetLabel = $ldapObject->getFData(($translate_labels?__($val_label['label']):$val_label['label']));
$retInfos[] = array (
'label' => $subRetLabel,
'possible_values' => $subRetInfos
);
}
else {
$val_key = $ldapObject->getFData($val_key);
$val_label = $ldapObject->getFData(($translate_labels?__($val_label):$val_label));

View file

@ -103,9 +103,9 @@ class LSattr_ldap extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -735,9 +735,9 @@ class LSattribute extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -98,9 +98,9 @@ class LSauth extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -31,64 +31,64 @@ class LSauthMethod_CAS extends LSauthMethod {
private $configured = false;
public function __construct() {
LSauth :: disableLoginForm();
LSauth :: disableLoginForm();
if (!parent :: __construct())
return;
if (!parent :: __construct())
return;
if (LSsession :: includeFile(PHP_CAS_PATH, true)) {
if (defined('PHP_CAS_DEBUG_FILE')) {
self :: log_debug('LSauthMethod_CAS : enable debug file '.PHP_CAS_DEBUG_FILE);
phpCAS::setDebug(PHP_CAS_DEBUG_FILE);
}
self :: log_debug('LSauthMethod_CAS : initialise phpCAS :: client with CAS server URL https://'.LSAUTH_CAS_SERVER_HOSTNAME.':'.LSAUTH_CAS_SERVER_PORT.(defined('LSAUTH_CAS_SERVER_URI')?LSAUTH_CAS_SERVER_URI: ''));
phpCAS::client (
constant(LSAUTH_CAS_VERSION),
LSAUTH_CAS_SERVER_HOSTNAME,
LSAUTH_CAS_SERVER_PORT,
(defined('LSAUTH_CAS_SERVER_URI')?LSAUTH_CAS_SERVER_URI: ''),
false
);
if (LSsession :: includeFile(PHP_CAS_PATH, true)) {
if (defined('PHP_CAS_DEBUG_FILE')) {
self :: log_debug('LSauthMethod_CAS : enable debug file '.PHP_CAS_DEBUG_FILE);
phpCAS::setDebug(PHP_CAS_DEBUG_FILE);
}
self :: log_debug('LSauthMethod_CAS : initialise phpCAS :: client with CAS server URL https://'.LSAUTH_CAS_SERVER_HOSTNAME.':'.LSAUTH_CAS_SERVER_PORT.(defined('LSAUTH_CAS_SERVER_URI')?LSAUTH_CAS_SERVER_URI: ''));
phpCAS::client (
constant(LSAUTH_CAS_VERSION),
LSAUTH_CAS_SERVER_HOSTNAME,
LSAUTH_CAS_SERVER_PORT,
(defined('LSAUTH_CAS_SERVER_URI')?LSAUTH_CAS_SERVER_URI: ''),
false
);
// Configure CAS server SSL validation
$cas_server_ssl_validation_configured = false;
if (defined('LSAUTH_CAS_SERVER_NO_SSL_VALIDATION') && LSAUTH_CAS_SERVER_NO_SSL_VALIDATION) {
self :: log_debug('LSauthMethod_CAS : disable CAS server SSL validation => /!\ NOT RECOMMENDED IN PRODUCTION ENVIRONMENT /!\\');
phpCAS::setNoCasServerValidation();
$cas_server_ssl_validation_configured = true;
}
// Configure CAS server SSL validation
$cas_server_ssl_validation_configured = false;
if (defined('LSAUTH_CAS_SERVER_NO_SSL_VALIDATION') && LSAUTH_CAS_SERVER_NO_SSL_VALIDATION) {
self :: log_debug('LSauthMethod_CAS : disable CAS server SSL validation => /!\ NOT RECOMMENDED IN PRODUCTION ENVIRONMENT /!\\');
phpCAS::setNoCasServerValidation();
$cas_server_ssl_validation_configured = true;
}
if (defined('LSAUTH_CAS_SERVER_SSL_CACERT')) {
self :: log_debug('LSauthMethod_CAS : validate CAS server SSL certificate using '.LSAUTH_CAS_SERVER_SSL_CACERT.' CA certificate file.');
phpCAS::setCasServerCACert(LSAUTH_CAS_SERVER_SSL_CACERT);
$cas_server_ssl_validation_configured = true;
}
if (defined('LSAUTH_CAS_SERVER_SSL_CACERT')) {
self :: log_debug('LSauthMethod_CAS : validate CAS server SSL certificate using '.LSAUTH_CAS_SERVER_SSL_CACERT.' CA certificate file.');
phpCAS::setCasServerCACert(LSAUTH_CAS_SERVER_SSL_CACERT);
$cas_server_ssl_validation_configured = true;
}
// Check CAS server SSL validation is now configured
if (!$cas_server_ssl_validation_configured) {
LSerror :: addErrorCode('LSauthMethod_CAS_02');
return false;
}
// Check CAS server SSL validation is now configured
if (!$cas_server_ssl_validation_configured) {
LSerror :: addErrorCode('LSauthMethod_CAS_02');
return false;
}
if (defined('LSAUTH_CAS_CURL_SSLVERION')) {
self :: log_debug('LSauthMethod_CAS : use specific SSL version '.LSAUTH_CAS_CURL_SSLVERION);
phpCAS::setExtraCurlOption(CURLOPT_SSLVERSION,LSAUTH_CAS_CURL_SSLVERION);
}
if (defined('LSAUTH_CAS_CURL_SSLVERION')) {
self :: log_debug('LSauthMethod_CAS : use specific SSL version '.LSAUTH_CAS_CURL_SSLVERION);
phpCAS::setExtraCurlOption(CURLOPT_SSLVERSION,LSAUTH_CAS_CURL_SSLVERION);
}
if (LSAUTH_CAS_DISABLE_LOGOUT) {
self :: log_debug('LSauthMethod_CAS : disable logout');
LSauth :: disableLogoutBtn();
}
if (LSAUTH_CAS_DISABLE_LOGOUT) {
self :: log_debug('LSauthMethod_CAS : disable logout');
LSauth :: disableLogoutBtn();
}
// Set configured flag
$this -> configured = true;
return true;
}
else {
LSerror :: addErrorCode('LSauthMethod_CAS_01');
}
return false;
}
// Set configured flag
$this -> configured = true;
return true;
}
else {
LSerror :: addErrorCode('LSauthMethod_CAS_01');
}
return false;
}
/**
* Check Auth Data
@ -98,38 +98,38 @@ class LSauthMethod_CAS extends LSauthMethod {
* @retval Array|false Array of authentication data or False
**/
public function getAuthData() {
if ($this -> configured) {
// Launch Auth
self :: log_debug('LSauthMethod_CAS : force authentication');
phpCAS::forceAuthentication();
if ($this -> configured) {
// Launch Auth
self :: log_debug('LSauthMethod_CAS : force authentication');
phpCAS::forceAuthentication();
$this -> authData = array(
'username' => phpCAS::getUser()
);
self :: log_debug('LSauthMethod_CAS : auth data : '.varDump($this -> authData));
return $this -> authData;
}
return;
}
$this -> authData = array(
'username' => phpCAS::getUser()
);
self :: log_debug('LSauthMethod_CAS : auth data : '.varDump($this -> authData));
return $this -> authData;
}
return;
}
/**
* Logout
*
* @retval boolean True on success or False
**/
public function logout() {
if($this -> configured) {
if (LSauth :: displayLogoutBtn()) {
phpCAS :: forceAuthentication();
self :: log_debug("LSauthMethod_CAS :: logout() : trigger CAS logout");
phpCAS :: logout();
return true;
}
else
self :: log_warning("LSauthMethod_CAS :: logout() : logout is disabled");
}
return;
}
public function logout() {
if($this -> configured) {
if (LSauth :: displayLogoutBtn()) {
phpCAS :: forceAuthentication();
self :: log_debug("LSauthMethod_CAS :: logout() : trigger CAS logout");
phpCAS :: logout();
return true;
}
else
self :: log_warning("LSauthMethod_CAS :: logout() : logout is disabled");
}
return;
}
}

View file

@ -31,23 +31,23 @@ class LSauthMethod_anonymous extends LSauthMethod {
protected static $api_mode_supported = true;
public function __construct() {
LSauth :: disableLoginForm();
LSauth :: disableSelfAccess();
LSauth :: disableLoginForm();
LSauth :: disableSelfAccess();
if (!parent :: __construct())
return;
if (!parent :: __construct())
return;
if ( (!defined('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT')) || (constant('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT') === True)) {
self :: log_debug('logout : '.constant('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT'));
LSauth :: disableLogoutBtn();
}
if ( (!defined('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT')) || (constant('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT') === True)) {
self :: log_debug('logout : '.constant('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT'));
LSauth :: disableLogoutBtn();
}
if ( (!defined('LSAUTHMETHOD_ANONYMOUS_USER')) || (constant('LSAUTHMETHOD_ANONYMOUS_USER') == "")) {
LSerror :: addErrorCode('LSauthMethod_anonymous_01');
return;
}
return true;
}
if ( (!defined('LSAUTHMETHOD_ANONYMOUS_USER')) || (constant('LSAUTHMETHOD_ANONYMOUS_USER') == "")) {
LSerror :: addErrorCode('LSauthMethod_anonymous_01');
return;
}
return true;
}
/**
* Check Auth Data
@ -57,9 +57,9 @@ class LSauthMethod_anonymous extends LSauthMethod {
* @retval Array|false Array of authentication data or False
**/
public function getAuthData() {
$this -> authData = array(
'username' => LSAUTHMETHOD_ANONYMOUS_USER
);
$this -> authData = array(
'username' => LSAUTHMETHOD_ANONYMOUS_USER
);
return $this -> authData;
}
@ -69,5 +69,5 @@ class LSauthMethod_anonymous extends LSauthMethod {
* Error Codes
*/
LSerror :: defineError('LSauthMethod_anonymous_01',
___("LSauthMethod_anonymous : You must define the LSAUTHMETHOD_ANONYMOUS_USER contant in the configuration file.")
___("LSauthMethod_anonymous : You must define the LSAUTHMETHOD_ANONYMOUS_USER contant in the configuration file.")
);

View file

@ -51,7 +51,7 @@ class LSauthMethod_basic extends LSauthMethod {
* @retval LSldapObject|false The LSldapObject of the user authificated or false
*/
public function authenticate() {
$authobjects = LSauth :: username2LSobjects($this -> authData['username']);
$authobjects = LSauth :: username2LSobjects($this -> authData['username']);
if (!$authobjects) {
LSerror :: addErrorCode('LSauth_01');
self :: log_debug('No user found with username="'.$this -> authData['username'].'" => Invalid username');
@ -64,7 +64,7 @@ class LSauthMethod_basic extends LSauthMethod {
$matched[] = $dn;
else
self :: log_trace("Invalid password provided for '$dn'");
if (!$matched) {
if (!$matched) {
LSerror :: addErrorCode('LSauth_01');
self :: log_debug('Invalid password provided');
return false;
@ -74,9 +74,9 @@ class LSauthMethod_basic extends LSauthMethod {
LSerror :: addErrorCode('LSauth_02');
return false;
}
// Authentication succeeded
self :: log_debug('Authentication succeeded for username "'.$this -> authData['username'].'" ("'.$matched[0].'")');
return $authobjects[$matched[0]];
// Authentication succeeded
self :: log_debug('Authentication succeeded for username "'.$this -> authData['username'].'" ("'.$matched[0].'")');
return $authobjects[$matched[0]];
}
}

View file

@ -85,9 +85,9 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -326,9 +326,9 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* Return a parameter (or default value)
*
* @param[] $param The parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The parameter value or default value if not set
**/

View file

@ -357,8 +357,8 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
/**
* Check one component's values
*
* @param[] $c The component name
* @param[] $value The values of the component
* @param[] $c The component name
* @param[] $value The values of the component
*
* @retval void
**/
@ -375,8 +375,8 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
/**
* Check one component's value
*
* @param[] $c The component name
* @param[] $value The value to check
* @param[] $c The component name
* @param[] $value The value to check
*
* @retval void
**/
@ -431,10 +431,10 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
/**
* Return a configuration parameter for a specific component (or default value)
*
* @param[] $component The component name
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $component The component name
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -53,13 +53,13 @@ class LSformElement_postaladdress extends LSformElement_textarea {
else {
LSerror::addErrorCode('LSformElement_postaladdress_01', $map_url_pattern_generate_function);
}
}
elseif ($map_url_pattern_format) {
}
elseif ($map_url_pattern_format) {
$pattern = $this -> attr_html -> attribute -> ldapObject -> getFData($map_url_pattern_format);
$pattern = str_replace("\n"," ",$pattern);
$pattern = urlencode($pattern);
$this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern', $pattern);
}
}
else {
$this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern', LSformElement_postaladdress__generate_pattern($this));
}

View file

@ -34,7 +34,7 @@ LSsession :: loadLSaddon('supann');
class LSformElement_supannAdressePostalePrivee extends LSformElement_supannLabeledValue {
var $supannLabelNomenclatureTable = 'adressePostalePriveeLabel';
var $supannLabelNomenclatureTable = 'adressePostalePriveeLabel';
var $valueFieldType = 'textarea';
@ -45,12 +45,12 @@ class LSformElement_supannAdressePostalePrivee extends LSformElement_supannLabel
*
* @retval array Un tableau cle->valeur contenant value, translated et label
**/
public function parseValue($value) {
$retval = parent :: parseValue($value);
$retval['value'] = str_replace('$', "\n", $retval['value']);
$retval['translated'] = str_replace('$', "\n", $retval['translated']);
return $retval;
}
public function parseValue($value) {
$retval = parent :: parseValue($value);
$retval['value'] = str_replace('$', "\n", $retval['value']);
$retval['translated'] = str_replace('$', "\n", $retval['translated']);
return $retval;
}
/**
@ -62,15 +62,15 @@ class LSformElement_supannAdressePostalePrivee extends LSformElement_supannLabel
* @see LSformElement::getPostData()
* @retval boolean true si la valeur est présente en POST, false sinon
*/
public function getPostData(&$return, $onlyIfPresent=false) {
$retval = parent :: getPostData($return, $onlyIfPresent);
if (isset($return[$this -> name])) {
$fixed_values = array();
foreach($return[$this -> name] as $value)
$fixed_values[] = str_replace("\n", "$", $value);
$return[$this -> name] = $fixed_values;
}
return $retval;
}
public function getPostData(&$return, $onlyIfPresent=false) {
$retval = parent :: getPostData($return, $onlyIfPresent);
if (isset($return[$this -> name])) {
$fixed_values = array();
foreach($return[$this -> name] as $value)
$fixed_values[] = str_replace("\n", "$", $value);
$return[$this -> name] = $fixed_values;
}
return $retval;
}
}

View file

@ -34,6 +34,6 @@ LSsession :: loadLSaddon('supann');
class LSformElement_supannCodePopulation extends LSformElement_supannLabeledValue {
var $supannNomenclatureTable = 'codePopulation';
var $supannNomenclatureTable = 'codePopulation';
}

View file

@ -34,6 +34,6 @@ LSsession :: loadLSaddon('supann');
class LSformElement_supannEmpCorps extends LSformElement_supannLabeledValue {
var $supannNomenclatureTable = 'empCorps';
var $supannNomenclatureTable = 'empCorps';
}

View file

@ -35,56 +35,56 @@ LSsession :: loadLSaddon('supann');
class LSformElement_supannEmpProfil extends LSformElement_supannCompositeAttribute {
public function __construct(&$form, $name, $label, $params, &$attr_html){
$this -> components = array (
'etab' => array (
'label' => _('Establishment'),
'type' => 'table',
'table' => 'codeEtablissement',
'required' => true,
),
'affil' => array (
'label' => _('eduPerson profil'),
'type' => 'select',
$this -> components = array (
'etab' => array (
'label' => _('Establishment'),
'type' => 'table',
'table' => 'codeEtablissement',
'required' => true,
),
'affil' => array (
'label' => _('eduPerson profil'),
'type' => 'select',
'possible_values' => array('' => '-'),
'get_possible_values' => 'supannGetAffiliationPossibleValues',
'required' => false,
),
'corps' => array (
'label' => _('Body of membership'),
'type' => 'table',
'table' => 'empCorps',
'required' => false,
),
'typeaffect' => array (
'label' => _('Entity type'),
'type' => 'table',
'table' => 'typeEntite',
'required' => false,
),
'affect' => array (
'label' => _('Assignment entity'),
'type' => 'codeEntite',
'required' => false,
),
'activite' => array (
'label' => _('Activity'),
'type' => 'table',
'table' => 'supannActivite',
'required' => false,
),
'population' => array (
'label' => _('Population'),
'type' => 'table',
'table' => 'codePopulation',
'required' => false,
),
'datefin' => array (
'label' => _('End date'),
'type' => 'date',
'required' => false,
),
);
return parent :: __construct($form, $name, $label, $params, $attr_html);
'get_possible_values' => 'supannGetAffiliationPossibleValues',
'required' => false,
),
'corps' => array (
'label' => _('Body of membership'),
'type' => 'table',
'table' => 'empCorps',
'required' => false,
),
'typeaffect' => array (
'label' => _('Entity type'),
'type' => 'table',
'table' => 'typeEntite',
'required' => false,
),
'affect' => array (
'label' => _('Assignment entity'),
'type' => 'codeEntite',
'required' => false,
),
'activite' => array (
'label' => _('Activity'),
'type' => 'table',
'table' => 'supannActivite',
'required' => false,
),
'population' => array (
'label' => _('Population'),
'type' => 'table',
'table' => 'codePopulation',
'required' => false,
),
'datefin' => array (
'label' => _('End date'),
'type' => 'date',
'required' => false,
),
);
return parent :: __construct($form, $name, $label, $params, $attr_html);
}
}

View file

@ -34,6 +34,6 @@ LSsession :: loadLSaddon('supann');
class LSformElement_supannMailPrive extends LSformElement_supannLabeledValue {
var $supannLabelNomenclatureTable = 'mailPriveLabel';
var $supannLabelNomenclatureTable = 'mailPriveLabel';
}

View file

@ -35,26 +35,26 @@ LSsession :: loadLSaddon('supann');
class LSformElement_supannRoleEntite extends LSformElement_supannCompositeAttribute {
public function __construct(&$form, $name, $label, $params, &$attr_html){
$this -> components = array (
'role' => array (
'label' => _('Role'),
'type' => 'table',
'table' => 'roleGenerique',
'required' => true,
),
'type' => array (
'label' => _('Entity type'),
'type' => 'table',
'table' => 'typeEntite',
'required' => true,
),
'code' => array (
'label' => _('Entity'),
'type' => 'codeEntite',
'required' => false
)
);
return parent :: __construct($form, $name, $label, $params, $attr_html);
$this -> components = array (
'role' => array (
'label' => _('Role'),
'type' => 'table',
'table' => 'roleGenerique',
'required' => true,
),
'type' => array (
'label' => _('Entity type'),
'type' => 'table',
'table' => 'typeEntite',
'required' => true,
),
'code' => array (
'label' => _('Entity'),
'type' => 'codeEntite',
'required' => false
)
);
return parent :: __construct($form, $name, $label, $params, $attr_html);
}
}

View file

@ -34,6 +34,6 @@ LSsession :: loadLSaddon('supann');
class LSformElement_supannTelephonePrive extends LSformElement_supannLabeledValue {
var $supannLabelNomenclatureTable = 'telephonePriveLabel';
var $supannLabelNomenclatureTable = 'telephonePriveLabel';
}

View file

@ -34,6 +34,6 @@ LSsession :: loadLSaddon('supann');
class LSformElement_supannTypeEntite extends LSformElement_supannLabeledValue {
var $supannNomenclatureTable = 'typeEntite';
var $supannNomenclatureTable = 'typeEntite';
}

View file

@ -60,11 +60,11 @@ class LSformRule_differentPassword extends LSformRule {
return false;
}
// Check attribute use LSldap_attr :: password type
// Check attribute use LSldap_attr :: password type
if (!$formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr] -> ldap instanceof LSattr_ldap_password) {
LSerror :: addErrorCode('LSformRule_differentPassword_05', $attr);
return false;
}
}
if ($formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr] -> ldap -> verify($value, $formElement -> form -> getValue($attr))) {
LSdebug($formElement -> name . " : Password matched with attribute $attr");

View file

@ -70,11 +70,11 @@ class LSformRule_password extends LSformRule {
continue;
}
if (preg_match($r, $value)) {
self :: log_debug("password match with regex '$r'");
self :: log_debug("password match with regex '$r'");
$valid++;
}
else
self :: log_debug("password does not match with regex '$r'");
}
else
self :: log_debug("password does not match with regex '$r'");
}
if ($valid < $minValidRegex) {
self :: log_warning("password match with only $valid regex on ".count($regex).". $minValidRegex valid regex is required");

View file

@ -68,9 +68,9 @@ class LSioFormat extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -160,9 +160,9 @@ class LSioFormatDriver extends LSlog_staticLoggerClass {
/**
* Return a option parameter (or default value)
*
* @param[] $param The option parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The option parameter value or default value if not set
**/

View file

@ -564,9 +564,9 @@ class LSldap extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -1965,9 +1965,9 @@ class LSldapObject extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -27,448 +27,450 @@
*/
class LSlog {
// Enable state
private static $enabled = false;
// Enable state
private static $enabled = false;
// Configured handlers
private static $handlers = array();
// Configured handlers
private static $handlers = array();
// Default handlers (if not configured)
private static $default_handlers = array(
array (
'handler' => 'file',
),
);
// Default handlers (if not configured)
private static $default_handlers = array(
array (
'handler' => 'file',
),
);
// Current level
private static $level;
private static $default_level = 'WARNING';
// Current level
private static $level;
private static $default_level = 'WARNING';
// Levels
private static $levels=array(
'TRACE' => 0,
'DEBUG' => 1,
'INFO' => 2,
'WARNING' => 3,
'ERROR' => 4,
'FATAL' => 5,
);
// Levels
private static $levels=array(
'TRACE' => 0,
'DEBUG' => 1,
'INFO' => 2,
'WARNING' => 3,
'ERROR' => 4,
'FATAL' => 5,
);
// Current existing loggers
private static $loggers = array();
// Current existing loggers
private static $loggers = array();
/**
* Start/initialize logging
*
* @retval bool True on success, False otherwise
**/
public static function start() {
// Load configuration
self :: $enabled = self :: getConfig('enable', false, 'bool');
self :: setLevel();
/**
* Start/initialize logging
*
* @retval bool True on success, False otherwise
**/
public static function start() {
// Load configuration
self :: $enabled = self :: getConfig('enable', false, 'bool');
self :: setLevel();
// Load default handlers class
if (!LSsession :: loadLSclass('LSlog_handler', null, true)) {
LSdebug('LSlog disabled');
return False;
}
// Load default handlers class
if (!LSsession :: loadLSclass('LSlog_handler', null, true)) {
LSdebug('LSlog disabled');
return False;
}
// Load handlers
$handlers = self :: getConfig('handlers');
if (!is_array($handlers)) $handlers = self :: $default_handlers;
LSdebug($handlers, true);
$debug_handlers = array();
foreach($handlers as $handler => $handler_config) {
if (!is_array($handler_config))
$handler_config = array('handler' => $handler);
else
$handler = (isset($handler_config['handler'])?$handler_config['handler']:'system');
// Load handlers
$handlers = self :: getConfig('handlers');
if (!is_array($handlers)) $handlers = self :: $default_handlers;
LSdebug($handlers, true);
$debug_handlers = array();
foreach($handlers as $handler => $handler_config) {
if (!is_array($handler_config))
$handler_config = array('handler' => $handler);
else
$handler = (isset($handler_config['handler'])?$handler_config['handler']:'system');
if (!self :: add_handler($handler, $handler_config))
continue;
if (!self :: add_handler($handler, $handler_config))
continue;
$debug_handlers[] = $handler;
}
LSdebug('LSlog enabled with level='.self :: $level.' and following handlers : '.implode(', ', $debug_handlers));
$debug_handlers[] = $handler;
}
LSdebug('LSlog enabled with level='.self :: $level.' and following handlers : '.implode(', ', $debug_handlers));
set_exception_handler(array('LSlog', 'exception'));
return True;
}
set_exception_handler(array('LSlog', 'exception'));
return True;
}
/**
* Add handler
*
* @param[in] $handler string The handler name
* @param[in] $handler_config array The handler configuration (optional)
*
* @retval boolean True if handler added, false otherwise
**/
public static function add_handler($handler, $handler_config = array()) {
if (!LSconfig :: get('enabled', true, 'bool', $handler_config))
return true;
$handler_class = "LSlog_$handler";
/**
* Add handler
*
* @param[in] $handler string The handler name
* @param[in] $handler_config array The handler configuration (optional)
*
* @retval boolean True if handler added, false otherwise
**/
public static function add_handler($handler, $handler_config = array()) {
if (!LSconfig :: get('enabled', true, 'bool', $handler_config))
return true;
$handler_class = "LSlog_$handler";
// Load handler class
if (!LSsession :: loadLSclass($handler_class) || !class_exists($handler_class)) {
LSerror :: addErrorCode('LSlog_01', $handler);
return false;
}
// Load handler class
if (!LSsession :: loadLSclass($handler_class) || !class_exists($handler_class)) {
LSerror :: addErrorCode('LSlog_01', $handler);
return false;
}
$handler_obj = new $handler_class($handler_config);
if ($handler_obj -> checkCompatibility()) {
self :: $handlers[] = $handler_obj;
return True;
}
LSdebug("LSlog handler $handler not supported.");
return false;
}
$handler_obj = new $handler_class($handler_config);
if ($handler_obj -> checkCompatibility()) {
self :: $handlers[] = $handler_obj;
return True;
}
LSdebug("LSlog handler $handler not supported.");
return false;
}
/**
* Enable console handler (if not already enabled)
*
* @param[in] $level string|null The log level of the console handler
*
* @retval boolean True if log on console enabled, false otherwise
**/
public static function logOnConsole($level=null) {
for ($i=0; $i < count(self :: $handlers); $i++) {
if (is_a(self :: $handlers[$i], 'LSlog_console')) {
if (!is_null($level))
self :: $handlers[$i] -> setLevel($level);
return true;
}
}
return self :: add_handler('console', array('level' => $level));
}
/**
* Enable console handler (if not already enabled)
*
* @param[in] $level string|null The log level of the console handler
*
* @retval boolean True if log on console enabled, false otherwise
**/
public static function logOnConsole($level=null) {
for ($i=0; $i < count(self :: $handlers); $i++) {
if (is_a(self :: $handlers[$i], 'LSlog_console')) {
if (!is_null($level))
self :: $handlers[$i] -> setLevel($level);
return true;
}
}
return self :: add_handler('console', array('level' => $level));
}
/**
* Disable console handler (if already enabled)
*
* @retval void
**/
public static function disableLogOnConsole() {
for ($i=0; $i < count(self :: $handlers); $i++) {
if (is_a(self :: $handlers[$i], 'LSlog_console')) {
LSlog :: debug('Remove console handler');
unset(self :: $handlers[$i]);
}
}
}
/**
* Set log level
*
* @param[in] $level string|null The log level (optional, default: from configuration or 'WARNING')
*
* @retval boolean True if log level set, false otherwise
**/
public static function setLevel($level=null) {
if (!$level) {
$level = self :: getConfig('level', self :: $default_level, 'string');
if (!array_key_exists($level, self :: $levels)) {
self :: $level = 'WARNING';
if ($level)
self :: warning("Invalid log level '$level' configured. Set log level to WARNING.");
$level = 'WARNING';
}
}
else if (!array_key_exists($level, self :: $levels))
return false;
self :: $level = $level;
// Set PHP error/exception handlers
if (in_array(self :: $level, array('DEBUG', 'TRACE')))
set_error_handler(array('LSlog', 'php_error'), E_ALL & ~E_STRICT);
else
set_error_handler(array('LSlog', 'php_error'), E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
return True;
}
/**
* Get a configuration variable value
*
* @param[in] $var string The configuration variable name
* @param[in] $default mixed The default value to return if configuration variable
* is not set (Default : null)
* @param[in] $cast string The type of expected value. The configuration variable
* value will be cast as this type. Could be : bool, int,
* float or string. (Optional, default : raw value)
*
* @retval mixed The configuration variable value
**/
public static function getConfig($var, $default=null, $cast=null) {
return LSconfig :: get($var, $default, $cast, ((isset($GLOBALS['LSlog']) && is_array($GLOBALS['LSlog']))?$GLOBALS['LSlog']:array()));
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public static function logging($level, $message, $logger=null) {
// Check LSlog is enabled
if (!self :: $enabled)
return;
// Check/fix level
if (!array_key_exists($level, self :: $levels))
$level = self :: $default_level;
// Handle non-string message
if (!is_string($message)) {
if (is_object($message) && method_exists($message, '__toString'))
$message = strval($message);
else
$message = varDump($message);
}
foreach (self :: $handlers as $handler) {
// Check handler level
if (!$handler -> checkLevel($level))
continue;
// Check handler logger filters
if (!$handler -> checkLogger($logger))
continue;
// Logging on this handler
call_user_func(array($handler, 'logging'), $level, $message, $logger);
}
if ($level == 'FATAL') {
if (php_sapi_name() == "cli")
die($message);
elseif (class_exists('LStemplate'))
LStemplate :: fatal_error($message);
else
die($message);
}
}
/**
* Check level against configured level
*
* @param[in] $level string The level
* @param[in] $configured_level string|null The configured level (optional, default : self :: $level)
*
* @retval bool True if a message with this level have to be logged, False otherwise
**/
public static function checkLevel($level, $configured_level=null) {
if (is_null($configured_level) || !array_key_exists($configured_level, self :: $levels))
$configured_level = self :: $level;
// On unknown level, use default level
if (!array_key_exists($level, self :: $levels))
$level = self :: $default_level;
return (self :: $levels[$level] >= self :: $levels[$configured_level]);
}
/**
* Check if a log level exists
*
* @param[in] $level string The level
*
* @retval bool True if the specified log level exists, False otherwise
**/
public static function checkLevelExists($level) {
return array_key_exists($level, self :: $levels);
}
/*
* PHP error logging helpers
*/
/**
* Generate current context backtrace
*
* @retval string Current context backtrace
**/
public static function get_debug_backtrace_context() {
$traces = debug_backtrace();
if (!is_array($traces) || count($traces) < 2)
return "unknown context";
$msg = array();
$j=0;
for ($i=count($traces)-1; $i >= 1; $i--) {
$j += 1;
$trace = array("#$j");
if (isset($traces[$i]['file']))
$trace[] = $traces[$i]['file'].(isset($traces[$i]['line'])?":".$traces[$i]['line']:"");
if (isset($traces[$i]['class']) && isset($traces[$i]['function']))
$trace[] = $traces[$i]['class'] . " " . $traces[$i]['type'] . " " . $traces[$i]['function']. "()";
elseif (isset($traces[$i]['function']))
$trace[] = $traces[$i]['function']. "()";
$msg[] = implode(" - ", $trace);
}
return implode("\n", $msg);
}
/**
* Log an exception
*
* Could be used as PHP set_exception_handler callable
* @see https://www.php.net/set_exception_handler
*
* @param[in] $exception Exception The exception to log
* @param[in] $prefix string|null Custom message prefix (optional, default: "An exception occured :\n")
* @param[in] $fatal boolean Log exception as a fatal error (optional, default: true)
* @param[in] $logger string|null The logger name (optional, default: null)
*
/**
* Disable console handler (if already enabled)
*
* @retval void
**/
public static function exception($exception, $prefix=null, $fatal=true, $logger=null) {
$message = ($prefix?"$prefix :\n":"An exception occured :\n"). self :: get_debug_backtrace_context(). "\n" .
"## ".$exception->getFile().":".$exception->getLine(). " : ". $exception->getMessage();
if (is_null($logger))
self :: logging(($fatal?'FATAL':'ERROR'), $message);
else
self :: logging(($fatal?'FATAL':'ERROR'), $message, $logger);
}
**/
public static function disableLogOnConsole() {
for ($i=0; $i < count(self :: $handlers); $i++) {
if (is_a(self :: $handlers[$i], 'LSlog_console')) {
LSlog :: debug('Remove console handler');
unset(self :: $handlers[$i]);
}
}
}
/**
* PHP set_error_handler helper
*
* @see https://www.php.net/set_error_handler
**/
public static function php_error($errno, $errstr, $errfile, $errline) {
$errnos2error = array (
1 => "ERROR",
2 => "WARNING",
4 => "PARSE",
8 => "NOTICE",
16 => "CORE_ERROR",
32 => "CORE_WARNING",
64 => "COMPILE_ERROR",
128 => "COMPILE_WARNING",
256 => "USER_ERROR",
512 => "USER_WARNING",
1024 => "USER_NOTICE",
2048 => "STRICT",
4096 => "RECOVERABLE_ERROR",
8192 => "DEPRECATED",
16384 => "USER_DEPRECATED",
32767 => "ALL",
);
/**
* Set log level
*
* @param[in] $level string|null The log level (optional, default: from configuration or 'WARNING')
*
* @retval boolean True if log level set, false otherwise
**/
public static function setLevel($level=null) {
if (!$level) {
$level = self :: getConfig('level', self :: $default_level, 'string');
if (!array_key_exists($level, self :: $levels)) {
self :: $level = 'WARNING';
if ($level)
self :: warning("Invalid log level '$level' configured. Set log level to WARNING.");
$level = 'WARNING';
}
}
else if (!array_key_exists($level, self :: $levels))
return false;
self :: $level = $level;
$errors2level = array (
"ERROR" => "ERROR",
"WARNING" => "WARNING",
"PARSE" => "FATAL",
"NOTICE" => "INFO",
"CORE_ERROR" => "ERROR",
"CORE_WARNING" => "WARNING",
"COMPILE_ERROR" => "ERROR",
"COMPILE_WARNING" => "WARNING",
"USER_ERROR" => "ERROR",
"USER_WARNING" => "WARNING",
"USER_NOTICE" => "INFO",
"STRICT" => "WARNING",
"RECOVERABLE_ERROR" => "WARNING",
"DEPRECATED" => "DEBUG",
"USER_DEPRECATED" => "DEBUG",
"ALL" => "ERROR",
"UNKNOWN" => "ERROR",
);
$error = (isset($errnos2error[$errno])?$errnos2error[$errno]:'UNKNOWN');
$level = (isset($errors2level[$error])?$errors2level[$error]:'ERROR');
self :: logging($level, "A PHP $error occured (#$errno) : $errstr [$errfile:$errline]");
return False;
}
// Set PHP error/exception handlers
if (in_array(self :: $level, array('DEBUG', 'TRACE')))
set_error_handler(array('LSlog', 'php_error'), E_ALL & ~E_STRICT);
else
set_error_handler(array('LSlog', 'php_error'), E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
return True;
}
/**
* Get logger for a specific name
*
* @param[in] $name The logger name
*
* @retval LSlog_logger The logger
**/
public static function &get_logger($name) {
if (!LSsession :: loadLSclass('LSlog_logger'))
self :: fatal('Fail to load LSlog_logger class.');
if (isset(self :: $loggers[$name]))
return self :: $loggers[$name];
self :: $loggers[$name] = new LSlog_logger(
$name,
self :: getConfig("loggers.$name", array())
);
return self :: $loggers[$name];
}
/**
* Get a configuration variable value
*
* @param[in] $var string The configuration variable name
* @param[in] $default mixed The default value to return if configuration variable
* is not set (Default : null)
* @param[in] $cast string The type of expected value. The configuration variable
* value will be cast as this type. Could be : bool, int,
* float or string. (Optional, default : raw value)
*
* @retval mixed The configuration variable value
**/
public static function getConfig($var, $default=null, $cast=null) {
return LSconfig :: get($var, $default, $cast, ((isset($GLOBALS['LSlog']) && is_array($GLOBALS['LSlog']))?$GLOBALS['LSlog']:array()));
}
/*
* Public logging methods
*/
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public static function logging($level, $message, $logger=null) {
// Check LSlog is enabled
if (!self :: $enabled)
return;
/**
* Log a message with level TRACE
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function trace($message) {
self :: logging('TRACE', $message);
}
// Check/fix level
if (!array_key_exists($level, self :: $levels))
$level = self :: $default_level;
/**
* Log a message with level DEBUG
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function debug($message) {
self :: logging('DEBUG', $message);
}
// Handle non-string message
if (!is_string($message)) {
if (is_object($message) && method_exists($message, '__toString'))
$message = strval($message);
else
$message = varDump($message);
}
/**
* Log a message with level INFO
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function info($message) {
self :: logging('INFO', $message);
}
foreach (self :: $handlers as $handler) {
// Check handler level
if (!$handler -> checkLevel($level))
continue;
// Check handler logger filters
if (!$handler -> checkLogger($logger))
continue;
/**
* Log a message with level WARNING
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function warning($message) {
self :: logging('WARNING', $message);
}
// Logging on this handler
call_user_func(array($handler, 'logging'), $level, $message, $logger);
}
/**
* Log a message with level ERROR
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function error($message) {
self :: logging('ERROR', $message);
}
if ($level == 'FATAL') {
if (php_sapi_name() == "cli")
die($message);
elseif (class_exists('LStemplate'))
LStemplate :: fatal_error($message);
else
die($message);
}
}
/**
* Log a message with level FATAL
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function fatal($message) {
self :: logging('FATAL', $message);
}
/**
* Check level against configured level
*
* @param[in] $level string The level
* @param[in] $configured_level string|null The configured level (optional, default : self :: $level)
*
* @retval bool True if a message with this level have to be logged, False otherwise
**/
public static function checkLevel($level, $configured_level=null) {
if (is_null($configured_level) || !array_key_exists($configured_level, self :: $levels))
$configured_level = self :: $level;
// On unknown level, use default level
if (!array_key_exists($level, self :: $levels))
$level = self :: $default_level;
return (self :: $levels[$level] >= self :: $levels[$configured_level]);
}
/**
* Check if a log level exists
*
* @param[in] $level string The level
*
* @retval bool True if the specified log level exists, False otherwise
**/
public static function checkLevelExists($level) {
return array_key_exists($level, self :: $levels);
}
/*
* PHP error logging helpers
*/
/**
* Generate current context backtrace
*
* @retval string Current context backtrace
**/
public static function get_debug_backtrace_context() {
$traces = debug_backtrace();
if (!is_array($traces) || count($traces) < 2)
return "unknown context";
$msg = array();
$j=0;
for ($i=count($traces)-1; $i >= 1; $i--) {
$j += 1;
$trace = array("#$j");
if (isset($traces[$i]['file']))
$trace[] = $traces[$i]['file'].(isset($traces[$i]['line'])?":".$traces[$i]['line']:"");
if (isset($traces[$i]['class']) && isset($traces[$i]['function']))
$trace[] = $traces[$i]['class'] . " " . $traces[$i]['type'] . " " . $traces[$i]['function']. "()";
elseif (isset($traces[$i]['function']))
$trace[] = $traces[$i]['function']. "()";
$msg[] = implode(" - ", $trace);
}
return implode("\n", $msg);
}
/**
* Log an exception
*
* Could be used as PHP set_exception_handler callable
* @see https://www.php.net/set_exception_handler
*
* @param[in] $exception Exception The exception to log
* @param[in] $prefix string|null Custom message prefix (optional, default: "An exception occured :\n")
* @param[in] $fatal boolean Log exception as a fatal error (optional, default: true)
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public static function exception($exception, $prefix=null, $fatal=true, $logger=null) {
$message =
($prefix?"$prefix :\n":"An exception occured :\n").
self :: get_debug_backtrace_context(). "\n" .
"## ".$exception->getFile().":".$exception->getLine(). " : ". $exception->getMessage();
if (is_null($logger))
self :: logging(($fatal?'FATAL':'ERROR'), $message);
else
self :: logging(($fatal?'FATAL':'ERROR'), $message, $logger);
}
/**
* PHP set_error_handler helper
*
* @see https://www.php.net/set_error_handler
**/
public static function php_error($errno, $errstr, $errfile, $errline) {
$errnos2error = array (
1 => "ERROR",
2 => "WARNING",
4 => "PARSE",
8 => "NOTICE",
16 => "CORE_ERROR",
32 => "CORE_WARNING",
64 => "COMPILE_ERROR",
128 => "COMPILE_WARNING",
256 => "USER_ERROR",
512 => "USER_WARNING",
1024 => "USER_NOTICE",
2048 => "STRICT",
4096 => "RECOVERABLE_ERROR",
8192 => "DEPRECATED",
16384 => "USER_DEPRECATED",
32767 => "ALL",
);
$errors2level = array (
"ERROR" => "ERROR",
"WARNING" => "WARNING",
"PARSE" => "FATAL",
"NOTICE" => "INFO",
"CORE_ERROR" => "ERROR",
"CORE_WARNING" => "WARNING",
"COMPILE_ERROR" => "ERROR",
"COMPILE_WARNING" => "WARNING",
"USER_ERROR" => "ERROR",
"USER_WARNING" => "WARNING",
"USER_NOTICE" => "INFO",
"STRICT" => "WARNING",
"RECOVERABLE_ERROR" => "WARNING",
"DEPRECATED" => "DEBUG",
"USER_DEPRECATED" => "DEBUG",
"ALL" => "ERROR",
"UNKNOWN" => "ERROR",
);
$error = (isset($errnos2error[$errno])?$errnos2error[$errno]:'UNKNOWN');
$level = (isset($errors2level[$error])?$errors2level[$error]:'ERROR');
self :: logging($level, "A PHP $error occured (#$errno) : $errstr [$errfile:$errline]");
return False;
}
/**
* Get logger for a specific name
*
* @param[in] $name The logger name
*
* @retval LSlog_logger The logger
**/
public static function &get_logger($name) {
if (!LSsession :: loadLSclass('LSlog_logger'))
self :: fatal('Fail to load LSlog_logger class.');
if (isset(self :: $loggers[$name]))
return self :: $loggers[$name];
self :: $loggers[$name] = new LSlog_logger(
$name,
self :: getConfig("loggers.$name", array())
);
return self :: $loggers[$name];
}
/*
* Public logging methods
*/
/**
* Log a message with level TRACE
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function trace($message) {
self :: logging('TRACE', $message);
}
/**
* Log a message with level DEBUG
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function debug($message) {
self :: logging('DEBUG', $message);
}
/**
* Log a message with level INFO
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function info($message) {
self :: logging('INFO', $message);
}
/**
* Log a message with level WARNING
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function warning($message) {
self :: logging('WARNING', $message);
}
/**
* Log a message with level ERROR
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function error($message) {
self :: logging('ERROR', $message);
}
/**
* Log a message with level FATAL
*
* @param[in] $message The message to log
*
* @retval void
**/
public static function fatal($message) {
self :: logging('FATAL', $message);
}
}
/**

View file

@ -27,38 +27,38 @@
*/
class LSlog_console extends LSlog_handler {
// File-descriptors for stdout/stderr
private $stdout;
private $stderr;
// File-descriptors for stdout/stderr
private $stdout;
private $stderr;
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
$this -> stdout = fopen('php://stdout', 'w');
$this -> stderr = fopen('php://stderr', 'w');
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
$this -> stdout = fopen('php://stdout', 'w');
$this -> stderr = fopen('php://stderr', 'w');
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
return fwrite(
(in_array($level, array('INFO', 'DEBUG', 'TRACE'))?$this -> stdout:$this -> stderr),
$this -> format($level, $message, $logger)."\n"
);
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
return fwrite(
(in_array($level, array('INFO', 'DEBUG', 'TRACE'))?$this -> stdout:$this -> stderr),
$this -> format($level, $message, $logger)."\n"
);
}
}

View file

@ -27,54 +27,54 @@
*/
class LSlog_email extends LSlog_handler {
// The configured email recipient
private $recipient = null;
// The configured email recipient
private $recipient = null;
// Default datetime prefix (enabled/disabled)
protected $default_datetime_prefix = false;
// Default datetime prefix (enabled/disabled)
protected $default_datetime_prefix = false;
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
$this -> recipient = self :: getConfig('recipient');
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
$this -> recipient = self :: getConfig('recipient');
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Return list of details for the string representation of the LSlog_email
*
* @retval array List of details for the string representation of the LSlog_email
*/
public function __toStringDetails() {
return array_merge(
array("recipient=".$this -> recipient),
parent :: __toStringDetails()
);
}
public function __toStringDetails() {
return array_merge(
array("recipient=".$this -> recipient),
parent :: __toStringDetails()
);
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
if ($this -> recipient)
return error_log(
$this -> format($level, $message, $logger),
1,
$this -> recipient
);
return false;
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
if ($this -> recipient)
return error_log(
$this -> format($level, $message, $logger),
1,
$this -> recipient
);
return false;
}
}

View file

@ -27,52 +27,52 @@
*/
class LSlog_file extends LSlog_handler {
// The configured logfile path
private $path;
// The configured logfile path
private $path;
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
// For reto-compatibilty, use LSlog.filename as default log path value
$this -> path = self :: getConfig('path', LSlog :: getConfig('filename', 'tmp/LS.log'));
if (substr($this -> path, 0, 1) != '/')
$this -> path = LS_ROOT_DIR."/".$this -> path;
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
// For reto-compatibilty, use LSlog.filename as default log path value
$this -> path = self :: getConfig('path', LSlog :: getConfig('filename', 'tmp/LS.log'));
if (substr($this -> path, 0, 1) != '/')
$this -> path = LS_ROOT_DIR."/".$this -> path;
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Return list of details for the string representation of the LSlog_file
*
* @retval array List of details for the string representation of the LSlog_file
*/
public function __toStringDetails() {
return array_merge(
array("path=".$this -> path),
parent :: __toStringDetails()
);
}
public function __toStringDetails() {
return array_merge(
array("path=".$this -> path),
parent :: __toStringDetails()
);
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
return error_log(
$this -> format($level, $message, $logger)."\n",
3,
$this -> path
);
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
return error_log(
$this -> format($level, $message, $logger)."\n",
3,
$this -> path
);
}
}

View file

@ -29,43 +29,43 @@ LSsession :: loadLSclass('LSlog_staticLoggerClass');
*/
class LSlog_handler extends LSlog_staticLoggerClass {
// The handler configuration
protected $config;
// The handler configuration
protected $config;
// Log level
protected $level;
// Log level
protected $level;
// Default log formats
protected $default_format = '%{requesturi} - %{remoteaddr} - %{ldapservername} - %{authuser} - %{logger} - %{level} - %{message}';
protected $default_cli_format = '%{clibinpath} - %{logger} - %{level} - %{message}';
// Default log formats
protected $default_format = '%{requesturi} - %{remoteaddr} - %{ldapservername} - %{authuser} - %{logger} - %{level} - %{message}';
protected $default_cli_format = '%{clibinpath} - %{logger} - %{level} - %{message}';
// Default datetime prefix (enabled/disabled)
protected $default_datetime_prefix = true;
// Default datetime prefix (enabled/disabled)
protected $default_datetime_prefix = true;
// Default datetime format
protected $default_datetime_format = 'Y/m/d H:i:s';
// Default datetime format
protected $default_datetime_format = 'Y/m/d H:i:s';
// Loggers filters
protected $loggers = array();
protected $excluded_loggers = array();
// Loggers filters
protected $loggers = array();
protected $excluded_loggers = array();
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
$this -> config = $config;
$this -> level = $this -> getConfig('level', null, 'string');
$this -> loggers = $this -> getConfig('loggers', array());
if (!is_array($this -> loggers))
$this -> loggers = array($this -> loggers);
$this -> excluded_loggers = $this -> getConfig('excluded_loggers', array());
if (!is_array($this -> excluded_loggers))
$this -> excluded_loggers = array($this -> excluded_loggers);
}
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
$this -> config = $config;
$this -> level = $this -> getConfig('level', null, 'string');
$this -> loggers = $this -> getConfig('loggers', array());
if (!is_array($this -> loggers))
$this -> loggers = array($this -> loggers);
$this -> excluded_loggers = $this -> getConfig('excluded_loggers', array());
if (!is_array($this -> excluded_loggers))
$this -> excluded_loggers = array($this -> excluded_loggers);
}
/**
* Allow conversion of LSlog_handler to string
@ -81,176 +81,176 @@ class LSlog_handler extends LSlog_staticLoggerClass {
*
* @retval array List of details for the string representation of the LSlog_handler
*/
public function __toStringDetails() {
return array(
"level=".($this -> level?$this -> level:'default'),
"loggers=".($this -> loggers?implode(',', $this -> loggers):'all'),
"excluded loggers=".($this -> excluded_loggers?implode(',', $this -> excluded_loggers):'no'),
);
}
public function __toStringDetails() {
return array(
"level=".($this -> level?$this -> level:'default'),
"loggers=".($this -> loggers?implode(',', $this -> loggers):'all'),
"excluded loggers=".($this -> excluded_loggers?implode(',', $this -> excluded_loggers):'no'),
);
}
/**
* Get handler info
*
* @param[in] $key string The info name
*
* @retval mixed The info value
**/
public function __get($key) {
switch ($key) {
case 'enabled':
return $this -> getConfig('enabled', true, 'bool');
case 'format':
if (php_sapi_name() == "cli")
$format = $this -> getConfig('cli_format', $this -> default_cli_format, 'string');
else
$format = $this -> getConfig('format', $this -> default_format, 'string');
// Add datetime prefix (if enabled)
if ($this -> getConfig('datetime_prefix', $this -> default_datetime_prefix, 'boolean')) {
$format = date($this -> getConfig('datetime_format', $this -> default_datetime_format, 'string'))." - $format";
}
return $format;
}
// Unknown key, log warning
self :: log_warning("__get($key): invalid property requested\n".LSlog :: get_debug_backtrace_context());
}
/**
* Get handler info
*
* @param[in] $key string The info name
*
* @retval mixed The info value
**/
public function __get($key) {
switch ($key) {
case 'enabled':
return $this -> getConfig('enabled', true, 'bool');
case 'format':
if (php_sapi_name() == "cli")
$format = $this -> getConfig('cli_format', $this -> default_cli_format, 'string');
else
$format = $this -> getConfig('format', $this -> default_format, 'string');
// Add datetime prefix (if enabled)
if ($this -> getConfig('datetime_prefix', $this -> default_datetime_prefix, 'boolean')) {
$format = date($this -> getConfig('datetime_format', $this -> default_datetime_format, 'string'))." - $format";
}
return $format;
}
// Unknown key, log warning
self :: log_warning("__get($key): invalid property requested\n".LSlog :: get_debug_backtrace_context());
}
/**
* Check system compatibility with this handler
*
* Note : LSlog do not generate no error about imcompatibly, it's
* just omit this handler if system is incompatible. You have to
* trigger it with this method if you want.
*
* @retval bool True if system is compatible, False otherwise
**/
public function checkCompatibility() {
return True;
}
/**
* Check system compatibility with this handler
*
* Note : LSlog do not generate no error about imcompatibly, it's
* just omit this handler if system is incompatible. You have to
* trigger it with this method if you want.
*
* @retval bool True if system is compatible, False otherwise
**/
public function checkCompatibility() {
return True;
}
/**
* Get a configuration variable value
*
* @param[in] $var string The configuration variable name
* @param[in] $default mixed The default value to return if configuration variable
* is not set (Default : null)
* @param[in] $cast string The type of expected value. The configuration variable
* value will be cast as this type. Could be : bool, int,
* float or string. (Optional, default : raw value)
*
* @retval mixed The configuration variable value
**/
public function getConfig($var, $default=null, $cast=null) {
return LSconfig :: get($var, $default, $cast, $this -> config);
}
/**
* Get a configuration variable value
*
* @param[in] $var string The configuration variable name
* @param[in] $default mixed The default value to return if configuration variable
* is not set (Default : null)
* @param[in] $cast string The type of expected value. The configuration variable
* value will be cast as this type. Could be : bool, int,
* float or string. (Optional, default : raw value)
*
* @retval mixed The configuration variable value
**/
public function getConfig($var, $default=null, $cast=null) {
return LSconfig :: get($var, $default, $cast, $this -> config);
}
/**
* Set log level
*
* @param[in] $level string The level
*
* @retval bool True if log level set, False otherwise
**/
public function setLevel($level) {
if (!is_null($level) && !LSlog :: checkLevelExists($level)) {
self :: log_error("Invalid log level '$level'");
return false;
}
self :: log_debug("Log handler ".get_called_class()." level set to ".(is_null($level)?'default':$level));
$this -> level = $level;
}
/**
* Set log level
*
* @param[in] $level string The level
*
* @retval bool True if log level set, False otherwise
**/
public function setLevel($level) {
if (!is_null($level) && !LSlog :: checkLevelExists($level)) {
self :: log_error("Invalid log level '$level'");
return false;
}
self :: log_debug("Log handler ".get_called_class()." level set to ".(is_null($level)?'default':$level));
$this -> level = $level;
}
/**
* Check level against configured level
*
* @param[in] $level string The level
*
* @retval bool True if a message with this level have to be logged, False otherwise
**/
public function checkLevel($level) {
return LSlog :: checkLevel($level, $this -> level);
}
/**
* Check level against configured level
*
* @param[in] $level string The level
*
* @retval bool True if a message with this level have to be logged, False otherwise
**/
public function checkLevel($level) {
return LSlog :: checkLevel($level, $this -> level);
}
/**
* Check logger against configured loggers filters
*
* @param[in] $logger string The logger
*
* @retval bool True if message of this logger have to be logged, False otherwise
**/
public function checkLogger($logger) {
if (!$this -> loggers && !$this -> excluded_loggers)
return true;
if ($this -> loggers && in_array($logger, $this -> loggers))
return true;
if ($this -> excluded_loggers && !in_array($logger, $this -> excluded_loggers))
return true;
return false;
}
/**
* Check logger against configured loggers filters
*
* @param[in] $logger string The logger
*
* @retval bool True if message of this logger have to be logged, False otherwise
**/
public function checkLogger($logger) {
if (!$this -> loggers && !$this -> excluded_loggers)
return true;
if ($this -> loggers && in_array($logger, $this -> loggers))
return true;
if ($this -> excluded_loggers && !in_array($logger, $this -> excluded_loggers))
return true;
return false;
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
return;
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
return;
}
/**
* Format a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval string The formated message to log
**/
protected function format($level, $message, $logger=null) {
global $argv;
return getFData(
$this -> format,
array(
'level' => $level,
'message' => $message,
'logger' => ($logger?$logger:'default'),
'clibinpath' => (isset($argv)?basename($argv[0]):'unknown bin path'),
'requesturi' => (isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:'unknown request URI'),
'remoteaddr' => (isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'unknown remote address'),
'ldapservername' => self :: getLdapServerName(),
'authuser' => self :: getAuthenticatedUserDN(),
)
);
}
/**
* Format a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval string The formated message to log
**/
protected function format($level, $message, $logger=null) {
global $argv;
return getFData(
$this -> format,
array(
'level' => $level,
'message' => $message,
'logger' => ($logger?$logger:'default'),
'clibinpath' => (isset($argv)?basename($argv[0]):'unknown bin path'),
'requesturi' => (isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:'unknown request URI'),
'remoteaddr' => (isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'unknown remote address'),
'ldapservername' => self :: getLdapServerName(),
'authuser' => self :: getAuthenticatedUserDN(),
)
);
}
/**
* Helper to retreive current LDAP server name
*
* @retval string Current LDAP server name
**/
private static function getLdapServerName() {
if (LSsession :: $ldapServer) {
if (isset(LSsession :: $ldapServer['name']))
return LSsession :: $ldapServer['name'];
else
return "#".LSsession :: $ldapServerId;
}
return "Not connected";
}
/**
* Helper to retreive current LDAP server name
*
* @retval string Current LDAP server name
**/
private static function getLdapServerName() {
if (LSsession :: $ldapServer) {
if (isset(LSsession :: $ldapServer['name']))
return LSsession :: $ldapServer['name'];
else
return "#".LSsession :: $ldapServerId;
}
return "Not connected";
}
/**
* Helper to retreive current authenticated user DN
*
* @retval string Current authenticated user DN
**/
private static function getAuthenticatedUserDN() {
$auth_dn = LSsession :: getLSuserObjectDn();
if ($auth_dn)
return LSsession :: getLSuserObjectDn();
return "Anonymous";
}
/**
* Helper to retreive current authenticated user DN
*
* @retval string Current authenticated user DN
**/
private static function getAuthenticatedUserDN() {
$auth_dn = LSsession :: getLSuserObjectDn();
if ($auth_dn)
return LSsession :: getLSuserObjectDn();
return "Anonymous";
}
}

View file

@ -29,32 +29,32 @@ LSsession :: loadLSclass('LSlog_staticLoggerClass');
*/
class LSlog_logger extends LSlog_staticLoggerClass {
// Name
private $name;
// Name
private $name;
// The handler configuration
private $config;
// The handler configuration
private $config;
// Enabled/disabled
private $enabled;
// Enabled/disabled
private $enabled;
// Level
private $level;
// Level
private $level;
/**
* Constructor
*
* @param[in] $name string The logger name
* @param[in] $config array The handler configuration (optional, default: array())
*
* @retval void
**/
public function __construct($name, $config=array()) {
$this -> name = $name;
$this -> config = $config;
$this -> enabled = $this -> getConfig('enabled', true, 'boolean');
$this -> level = $this -> getConfig('level');
}
/**
* Constructor
*
* @param[in] $name string The logger name
* @param[in] $config array The handler configuration (optional, default: array())
*
* @retval void
**/
public function __construct($name, $config=array()) {
$this -> name = $name;
$this -> config = $config;
$this -> enabled = $this -> getConfig('enabled', true, 'boolean');
$this -> level = $this -> getConfig('level');
}
/**
* Allow conversion of LSlog_logger to string
@ -65,153 +65,153 @@ class LSlog_logger extends LSlog_staticLoggerClass {
return "<".get_class($this)." ".$this -> name.">";
}
/**
* Get a configuration variable value
*
* @param[in] $var string The configuration variable name
* @param[in] $default mixed The default value to return if configuration variable
* is not set (Default : null)
* @param[in] $cast string The type of expected value. The configuration variable
* value will be cast as this type. Could be : bool, int,
* float or string. (Optional, default : raw value)
*
* @retval mixed The configuration variable value
**/
public function getConfig($var, $default=null, $cast=null) {
return LSconfig :: get($var, $default, $cast, $this -> config);
}
/**
* Get a configuration variable value
*
* @param[in] $var string The configuration variable name
* @param[in] $default mixed The default value to return if configuration variable
* is not set (Default : null)
* @param[in] $cast string The type of expected value. The configuration variable
* value will be cast as this type. Could be : bool, int,
* float or string. (Optional, default : raw value)
*
* @retval mixed The configuration variable value
**/
public function getConfig($var, $default=null, $cast=null) {
return LSconfig :: get($var, $default, $cast, $this -> config);
}
/**
* Get logger info
*
* @param[in] $key string The info name
*
* @retval mixed The info value
**/
public function __get($key) {
switch ($key) {
case 'name':
return $this -> name;
case 'enabled':
return $this -> enabled;
case 'level':
return $this -> level;
}
// Unknown key, log warning
self :: log_warning("$this -> __get($key): invalid property requested\n".LSlog :: get_debug_backtrace_context());
return;
}
/**
* Get logger info
*
* @param[in] $key string The info name
*
* @retval mixed The info value
**/
public function __get($key) {
switch ($key) {
case 'name':
return $this -> name;
case 'enabled':
return $this -> enabled;
case 'level':
return $this -> level;
}
// Unknown key, log warning
self :: log_warning("$this -> __get($key): invalid property requested\n".LSlog :: get_debug_backtrace_context());
return;
}
/**
* Check level against configured level
*
* @param[in] $level string The level
*
* @retval bool True if a message with this level have to be logged, False otherwise
**/
public function checkLevel($level) {
// If no level configured, always log
if (!$this -> enabled || !$this -> level)
return True;
return LSlog :: checkLevel($level, $this -> level);
}
/**
* Check level against configured level
*
* @param[in] $level string The level
*
* @retval bool True if a message with this level have to be logged, False otherwise
**/
public function checkLevel($level) {
// If no level configured, always log
if (!$this -> enabled || !$this -> level)
return True;
return LSlog :: checkLevel($level, $this -> level);
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
*
* @retval void
**/
public function logging($level, $message) {
if (!$this -> enabled || !$this -> checkLevel($level))
return;
LSlog :: logging($level, $message, $this -> name);
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
*
* @retval void
**/
public function logging($level, $message) {
if (!$this -> enabled || !$this -> checkLevel($level))
return;
LSlog :: logging($level, $message, $this -> name);
}
/*
* Public logging methods
*/
/*
* Public logging methods
*/
/**
* Log a message with level DEBUG
*
* @param[in] $message The message to log
*
* @retval void
**/
public function trace($message) {
$this -> logging('TRACE', $message);
}
/**
* Log a message with level DEBUG
*
* @param[in] $message The message to log
*
* @retval void
**/
public function trace($message) {
$this -> logging('TRACE', $message);
}
/**
* Log a message with level DEBUG
*
* @param[in] $message The message to log
*
* @retval void
**/
public function debug($message) {
$this -> logging('DEBUG', $message);
}
/**
* Log a message with level DEBUG
*
* @param[in] $message The message to log
*
* @retval void
**/
public function debug($message) {
$this -> logging('DEBUG', $message);
}
/**
* Log a message with level INFO
*
* @param[in] $message The message to log
*
* @retval void
**/
public function info($message) {
$this -> logging('INFO', $message);
}
/**
* Log a message with level INFO
*
* @param[in] $message The message to log
*
* @retval void
**/
public function info($message) {
$this -> logging('INFO', $message);
}
/**
* Log a message with level WARNING
*
* @param[in] $message The message to log
*
* @retval void
**/
public function warning($message) {
$this -> logging('WARNING', $message);
}
/**
* Log a message with level WARNING
*
* @param[in] $message The message to log
*
* @retval void
**/
public function warning($message) {
$this -> logging('WARNING', $message);
}
/**
* Log a message with level ERROR
*
* @param[in] $message The message to log
*
* @retval void
**/
public function error($message) {
$this -> logging('ERROR', $message);
}
/**
* Log a message with level ERROR
*
* @param[in] $message The message to log
*
* @retval void
**/
public function error($message) {
$this -> logging('ERROR', $message);
}
/**
* Log a message with level FATAL
*
* @param[in] $message The message to log
*
* @retval void
**/
public function fatal($message) {
$this -> logging('FATAL', $message);
}
/**
* Log a message with level FATAL
*
* @param[in] $message The message to log
*
* @retval void
**/
public function fatal($message) {
$this -> logging('FATAL', $message);
}
/**
* Log an exception
*
* @param[in] $exception Exception The exception to log
* @param[in] $prefix string|null Custom message prefix (optional, see LSlog :: exception())
* @param[in] $fatal boolean Log exception as a fatal error (optional, default: true)
*
* @retval void
**/
public function exception($exception, $prefix=null, $fatal=true) {
if (!$this -> enabled)
return;
LSlog :: exception($exception, $prefix, $fatal, $this -> name);
}
/**
* Log an exception
*
* @param[in] $exception Exception The exception to log
* @param[in] $prefix string|null Custom message prefix (optional, see LSlog :: exception())
* @param[in] $fatal boolean Log exception as a fatal error (optional, default: true)
*
* @retval void
**/
public function exception($exception, $prefix=null, $fatal=true) {
if (!$this -> enabled)
return;
LSlog :: exception($exception, $prefix, $fatal, $this -> name);
}
}

View file

@ -40,15 +40,15 @@ class LSlog_staticLoggerClass {
}
/**
* Log an exception via class logger
*
* @param[in] $exception Exception The exception to log
* @param[in] $prefix string|null Custom message prefix (optional, see self :: log_exception())
* @param[in] $fatal boolean Log exception as a fatal error (optional, default: true)
*
* @retval void
**/
protected static function log_exception($exception, $prefix=null, $fatal=true) {
* Log an exception via class logger
*
* @param[in] $exception Exception The exception to log
* @param[in] $prefix string|null Custom message prefix (optional, see self :: log_exception())
* @param[in] $fatal boolean Log exception as a fatal error (optional, default: true)
*
* @retval void
**/
protected static function log_exception($exception, $prefix=null, $fatal=true) {
LSlog :: get_logger(get_called_class()) -> exception($exception, $prefix, $fatal);
}

View file

@ -27,91 +27,91 @@
*/
class LSlog_syslog extends LSlog_handler {
// Force syslog priority
private $priority = null;
// Force syslog priority
private $priority = null;
// Levels to syslog priority mapping
private static $levels2priority = array (
'EMERG' => LOG_EMERG, // system is unusable
'ALERT' => LOG_ALERT, // action must be taken immediately
'CRITICAL' => LOG_CRIT, // critical conditions
'ERROR' => LOG_ERR, // error conditions
'WARNING' => LOG_WARNING, // warning conditions
'NOTICE' => LOG_NOTICE, // normal, but significant, condition
'INFO' => LOG_INFO, // informational message
'DEBUG' => LOG_DEBUG, // debug-level message
'TRACE' => LOG_DEBUG, // also debug-level message
);
// Levels to syslog priority mapping
private static $levels2priority = array (
'EMERG' => LOG_EMERG, // system is unusable
'ALERT' => LOG_ALERT, // action must be taken immediately
'CRITICAL' => LOG_CRIT, // critical conditions
'ERROR' => LOG_ERR, // error conditions
'WARNING' => LOG_WARNING, // warning conditions
'NOTICE' => LOG_NOTICE, // normal, but significant, condition
'INFO' => LOG_INFO, // informational message
'DEBUG' => LOG_DEBUG, // debug-level message
'TRACE' => LOG_DEBUG, // also debug-level message
);
// Default syslog priority (used if level is not provided or invalid)
private static $default_priority = LOG_WARNING;
// Default syslog priority (used if level is not provided or invalid)
private static $default_priority = LOG_WARNING;
// Default datetime prefix (enabled/disabled)
protected $default_datetime_prefix = false;
// Default datetime prefix (enabled/disabled)
protected $default_datetime_prefix = false;
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
$this -> priority = static :: getConfig('priority');
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
$this -> priority = static :: getConfig('priority');
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Return list of details for the string representation of the LSlog_email
*
* @retval array List of details for the string representation of the LSlog_email
*/
public function __toStringDetails() {
return array_merge(
array("priority=".$this -> priority),
parent :: __toStringDetails()
);
}
/**
* Return list of details for the string representation of the LSlog_email
*
* @retval array List of details for the string representation of the LSlog_email
*/
public function __toStringDetails() {
return array_merge(
array("priority=".$this -> priority),
parent :: __toStringDetails()
);
}
/**
* Check system compatibility with this handler
*
* @retval bool True if system is compatible, False otherwise
**/
public function checkCompatibility() {
return function_exists('syslog');
}
/**
* Check system compatibility with this handler
*
* @retval bool True if system is compatible, False otherwise
**/
public function checkCompatibility() {
return function_exists('syslog');
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
return syslog(
$this -> level2priority($level),
$this -> format($level, $message, $logger)
);
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
return syslog(
$this -> level2priority($level),
$this -> format($level, $message, $logger)
);
}
/**
* Get syslog corresponding priority to a specific log level
*
* @param[in] $level string The log level
*
* @retval int Syslog corresponding priority
**/
private function level2priority($level) {
if ($this -> priority && $level != $this -> priority)
return $this -> level2priority($this -> priority);
if (array_key_exists($level, static :: $levels2priority))
return static :: $levels2priority[$level];
return static :: $default_priority;
}
/**
* Get syslog corresponding priority to a specific log level
*
* @param[in] $level string The log level
*
* @retval int Syslog corresponding priority
**/
private function level2priority($level) {
if ($this -> priority && $level != $this -> priority)
return $this -> level2priority($this -> priority);
if (array_key_exists($level, static :: $levels2priority))
return static :: $levels2priority[$level];
return static :: $default_priority;
}
}

View file

@ -27,34 +27,34 @@
*/
class LSlog_system extends LSlog_handler {
// Default datetime prefix (enabled/disabled)
protected $default_datetime_prefix = false;
// Default datetime prefix (enabled/disabled)
protected $default_datetime_prefix = false;
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
if ($this -> enabled)
self :: log_trace("$this Enabled", get_class($this));
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
error_log(
$this -> format($level, $message, $logger)
);
}
/**
* Log a message
*
* @param[in] $level string The message level
* @param[in] $message string The message
* @param[in] $logger string|null The logger name (optional, default: null)
*
* @retval void
**/
public function logging($level, $message, $logger=null) {
error_log(
$this -> format($level, $message, $logger)
);
}
}

View file

@ -73,9 +73,9 @@ class LSrelation extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/
@ -123,7 +123,7 @@ class LSrelation extends LSlog_staticLoggerClass {
);
}
// Unknown key, log warning
self :: log_warning("__get($key): invalid property requested\n".LSlog :: get_debug_backtrace_context());
self :: log_warning("__get($key): invalid property requested\n".LSlog :: get_debug_backtrace_context());
}
/**

View file

@ -1236,12 +1236,12 @@ class LSsearch extends LSlog_staticLoggerClass {
return $this -> _canCopy;
}
elseif ($key=='predefinedFilters') {
$retval=array();
if (is_array($this -> config['predefinedFilters'])) {
foreach($this -> config['predefinedFilters'] as $filter => $label) {
$retval[$filter]=__($label);
}
}
$retval=array();
if (is_array($this -> config['predefinedFilters'])) {
foreach($this -> config['predefinedFilters'] as $filter => $label) {
$retval[$filter]=__($label);
}
}
return $retval;
}
elseif ($key=='extraDisplayedColumns') {

View file

@ -264,9 +264,9 @@ class LSsearchEntry extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -83,10 +83,11 @@ class LSselect extends LSlog_staticLoggerClass {
/**
* Return a configuration parameter (or default value)
*
* @param[] $id string The LSselect ID
* @param[] $param string The configuration parameter
* @param[] $default mixed The default value (optional, default : null)
* @param[] $cast Cast string|null resulting value in specific type (optional, default : null=disabled)
* @param[] $id string The LSselect ID
* @param[] $param string The configuration parameter
* @param[] $default mixed The default value (optional, default : null)
* @param[] $cast Cast string|null resulting value in specific type
* (optional, default : null=disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/

View file

@ -246,15 +246,15 @@ class LSsession {
}
/**
* Log an exception via class logger
*
* @param[in] $exception Exception The exception to log
* @param[in] $prefix string|null Custom message prefix (optional, see self :: log_exception())
* @param[in] $fatal boolean Log exception as a fatal error (optional, default: true)
*
* @retval void
**/
protected static function log_exception($exception, $prefix=null, $fatal=true) {
* Log an exception via class logger
*
* @param[in] $exception Exception The exception to log
* @param[in] $prefix string|null Custom message prefix (optional, see self :: log_exception())
* @param[in] $fatal boolean Log exception as a fatal error (optional, default: true)
*
* @retval void
**/
protected static function log_exception($exception, $prefix=null, $fatal=true) {
if (class_exists('LSlog')) {
LSlog :: get_logger(get_called_class()) -> exception($exception, $prefix, $fatal);
return;

View file

@ -73,7 +73,7 @@ class LSurlRequest extends LSlog_staticLoggerClass {
return urldecode($this->url_params[$key]);
}
// Unknown key, log warning
self :: log_warning("__get($key): invalid property requested\n".LSlog :: get_debug_backtrace_context());
self :: log_warning("__get($key): invalid property requested\n".LSlog :: get_debug_backtrace_context());
}
/**

View file

@ -69,7 +69,7 @@ function getFData($format,$data,$meth=NULL) {
else {
$val = $data[$ch[1]];
}
$val=_getFData_extractAndModify($val,$ch);
$val=_getFData_extractAndModify($val,$ch);
$format[$i]=str_replace($ch[0],$val,$format[$i]);
}
}
@ -80,7 +80,7 @@ function getFData($format,$data,$meth=NULL) {
if (is_array($value)) {
$value = $value[0];
}
$value=_getFData_extractAndModify($value,$ch);
$value=_getFData_extractAndModify($value,$ch);
$format[$i]=str_replace($ch[0],$value,$format[$i]);
}
else {
@ -108,7 +108,7 @@ function getFData($format,$data,$meth=NULL) {
if (is_array($value)) {
$value = $value[0];
}
$value=_getFData_extractAndModify($value,$ch);
$value=_getFData_extractAndModify($value,$ch);
$format[$i]=str_replace($ch[0],$value,$format[$i]);
}
else {
@ -120,7 +120,7 @@ function getFData($format,$data,$meth=NULL) {
}
else {
while (preg_match($expr,$format[$i],$ch)) {
$val=_getFData_extractAndModify($data,$ch);
$val=_getFData_extractAndModify($data,$ch);
$format[$i]=str_replace($ch[0],$val,$format[$i]);
}
}