Compare commits

...

7 commits

Author SHA1 Message Date
Benjamin Renard
56e17a40f6 phpstan: Be sure Mail & Mail_mime classes are loaded during analyse 2023-01-02 01:56:57 +01:00
Benjamin Renard
f53d868640 Update .gitlab-ci.yml file 2023-01-02 00:45:20 +00:00
Benjamin Renard
8e1aa74e12 Update .gitlab-ci.yml file 2023-01-02 00:38:47 +00:00
Benjamin Renard
ecaf2aeb13 Docker: add missing vimrc.local file 2023-01-02 01:20:19 +01:00
Benjamin Renard
20432adb14 Clean errors detected by PHPstan (level 3) 2023-01-02 01:17:46 +01:00
Benjamin Renard
bbde10bbf0 Add some class properties type & coments and clean errors detected by PHPstan (level 2) 2023-01-01 19:38:03 +01:00
Benjamin Renard
8a02680114 Clean/normalize comments format about parameters & returned value of functions/methods 2022-12-31 05:52:31 +01:00
190 changed files with 4552 additions and 3318 deletions

View file

@ -2,14 +2,18 @@ stages:
- tests
tests:
image: composer
image:
name: brenard/ldapsaisie:dev
entrypoint: [""]
stage: tests
rules:
- changes:
- src/*
script:
- composer install
- ./vendor/bin/phpstan analyse --no-interaction --configuration=phpstan.neon --error-format=junit > tests-report.xml
- service slapd start
- ./vendor/bin/phpstan analyse --no-interaction --configuration=.phpstan/config.neon --error-format=junit > tests-report.xml
artifacts:
when: always
paths:

15
.phpstan/config.neon Normal file
View file

@ -0,0 +1,15 @@
parameters:
level: 3
paths:
- ../src
excludePaths:
- ../src/local
- ../src/tmp
bootstrapFiles:
- ../src/includes/core.php
- init.php
typeAliases:
LSformat: 'string'
universalObjectCratesClasses:
- LSsearchEntry
- LSurlRequest

12
.phpstan/init.php Normal file
View file

@ -0,0 +1,12 @@
<?php
require 'Net/LDAP2.php';
require 'Console/Table.php';
require 'Zxcvbn/autoload.php';
require '/usr/share/php/phpseclib/autoload.php';
require 'CAS.php';
require 'Mail.php';
require 'Mail/mime.php';
spl_autoload_register(array('LSsession', 'loadLSclass'));
LSsession :: initialize();

78
composer.lock generated Normal file
View file

@ -0,0 +1,78 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "37f736b754e8e0455f279bf0da013262",
"packages": [],
"packages-dev": [
{
"name": "phpstan/phpstan",
"version": "1.9.4",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "d03bccee595e2146b7c9d174486b84f4dc61b0f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/d03bccee595e2146b7c9d174486b84f4dc61b0f2",
"reference": "d03bccee595e2146b7c9d174486b84f4dc61b0f2",
"shasum": ""
},
"require": {
"php": "^7.2|^8.0"
},
"conflict": {
"phpstan/phpstan-shim": "*"
},
"bin": [
"phpstan",
"phpstan.phar"
],
"type": "library",
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"keywords": [
"dev",
"static analysis"
],
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/1.9.4"
},
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://github.com/phpstan",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
"type": "tidelift"
}
],
"time": "2022-12-17T13:33:52+00:00"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View file

@ -82,7 +82,7 @@ les possibilités de contribution.</para>
*
* @author My Name <my.email@example.com>
*
* @retval boolean true if my addon is totaly supported, false in other cases
* @return boolean true if my addon is totaly supported, false in other cases
**/
function LSaddon_myaddon_support() {
@ -128,7 +128,7 @@ les possibilités de contribution.</para>
*
* @author My Name <my.email@example.com>
*
* @retval [type(s) of returned values (pipe separator)] Description of the return of this function
* @return [type(s) of returned values (pipe separator)] Description of the return of this function
**/
function myaddon_first_function($arg1, $arg2) {
// Do some stuff
@ -257,7 +257,7 @@ les possibilités de contribution.</para>
*
* @author My Name <my.email@example.com>
*
* @retval void
* @return void
**/
function myaddon_view() {
// Do some stuff and set some template variables
@ -431,7 +431,7 @@ les possibilités de contribution.</para>
*
* Description of this CLI command.
*
* @param[in] $command_args array Command arguments
* @param array $command_args Command arguments
* - Positional arguments :
* - LSobject
* - dn
@ -440,7 +440,7 @@ les possibilités de contribution.</para>
*
* @author My Name <my.email@example.com>
*
* @retval boolean True on success, false otherwise
* @return boolean True on success, false otherwise
**/
function cli_my_custom_cli_cmd($command_args) {
$objType = null;
@ -480,12 +480,12 @@ les possibilités de contribution.</para>
/**
* Args autocompleter for CLI my_custom_cli_cmd command
*
* @param[in] $command_args array List of already typed words of the command
* @param[in] $comp_word_num int The command word number to autocomplete
* @param[in] $comp_word string The command word to autocomplete
* @param[in] $opts array List of global available options
* @param array<string> $command_args List of already typed words of the command
* @param int $comp_word_num The command word number to autocomplete
* @param string $comp_word The command word to autocomplete
* @param array<string> $opts List of global available options
*
* @retval array List of available options for the word to autocomplete
* @return array<string> List of available options for the word to autocomplete
**/
public static function cli_my_custom_cli_cmd_autocompleter($command_args, $comp_word_num, $comp_word, $opts) {
$opts = array_merge($opts, array ('-f', '--force'));

View file

@ -8,7 +8,7 @@ RUN wget -O - http://ldapsaisie.org/debian/ldapsaisie.gpg.key | apt-key add -
COPY apt.list /etc/apt/sources.list.d/ldapsaisie.list
RUN apt-get update
# Install dependencies
RUN DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get install -y git slapd apache2 php-ldap libapache2-mod-php php-cli smarty3 php-net-ldap2 php-net-ftp php-mail php-mail-mime php-console-table ldapvi locales sed bash-completion liquidprompt vim curl jq iproute2 net-tools
RUN DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get install -y git slapd apache2 php-ldap libapache2-mod-php php-cli smarty3 php-net-ldap2 php-net-ftp php-mail php-mail-mime php-console-table ldapvi locales sed bash-completion liquidprompt vim curl jq iproute2 net-tools composer php-cas php-zxcvbn php-phpseclib
# Add fr_FR* locales
RUN sed -i 's/^# fr_FR/fr_FR/' /etc/locale.gen
RUN locale-gen

10
docker/vimrc.local Normal file
View file

@ -0,0 +1,10 @@
set backup " Keep a backup file
set backupdir=/var/backups/vim,. "keep backup file in another dir if possible, otherwise .
syntax on " Highlight syntax
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
set incsearch " Incremental search
set modeline
set bg=dark
autocmd BufEnter * set mouse-=a

View file

@ -1,32 +0,0 @@
parameters:
level: 1
paths:
- src
excludePaths:
- src/local
- src/tmp
# Error message "Class Smarty_Resource_LdapSaisie extends unknown class Smarty_Resource_Custom." cannot be ignored, use excludePaths instead.
- src/includes/class/class.LStemplate_smarty3_support.php
bootstrapFiles:
- src/includes/core.php
universalObjectCratesClasses:
- LSsearch
- LSsearchEntry
- LSrelation
- LSlog_handler
- LSlog_logger
- LSldapObject
- LSurlRequest
ignoreErrors:
- "#Instantiated class (Smarty|Console_Table|ZxcvbnPhp\\\\Zxcvbn|phpseclib\\\\Crypt\\\\RSA|phpseclib\\\\Net\\\\SFTP|phpseclib\\\\Net\\\\SSH2|Net_FTP) not found\\.#"
- "#Call to static method (connect|isError)\\(\\) on an unknown class Net_LDAP2\\.#"
- "#(Class|Constant) (Net_LDAP2_Filter|Net_LDAP2_Entry|PEAR_Error) not found\\.#"
- "#Call to static method (create|parse|combine|escape)\\(\\) on an unknown class Net_LDAP2_Filter\\.#"
- "#Call to static method (createFresh)\\(\\) on an unknown class Net_LDAP2_Entry\\.#"
- "#Call to static method (forceAuthentication|getUser|logout|setDebug|client|setNoCasServerValidation|setCasServerCACert|setExtraCurlOption)\\(\\) on an unknown class phpCAS\\.#"
-
message: "#Call to static method factory\\(\\) on an unknown class Mail\\.#"
path: src/includes/addons/LSaddons.mail.php
-
message: "#Instantiated class Mail_mime not found\\.#"
path: src/includes/addons/LSaddons.mail.php

View file

@ -31,7 +31,7 @@ LSerror :: defineError('LSACCESSRIGHTSMATRIXVIEW_SUPPORT_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if LSaccessRightsMatrixView addon is totally supported, false in other case
* @return boolean true if LSaccessRightsMatrixView addon is totally supported, false in other case
*/
function LSaddon_LSaccessRightsMatrixView_support() {
$retval = True;

View file

@ -24,16 +24,19 @@
// Support
LSerror :: defineError('ASTERISK_SUPPORT_01',
___("Asterisk Support : The constant %{const} is not defined.")
___("Asterisk Support: The constant %{const} is not defined.")
);
LSerror :: defineError('ASTERISK_01',
___("Asterisk : The function %{function} only work with %{objectName}.")
___("Asterisk: The function %{function} only work with %{objectName}.")
);
LSerror :: defineError('ASTERISK_02',
___("Asterisk : The attribute %{dependency} is missing. Unable to generate MD5 hashed password.")
___("Asterisk: The attribute %{dependency} is missing. Unable to generate MD5 hashed password.")
);
LSerror :: defineError('ASTERISK_03',
___("Asterisk : Clear password not availlable. Unable to generate MD5 hashed password.")
___("Asterisk: Clear password not availlable. Unable to generate MD5 hashed password.")
);
LSerror :: defineError('ASTERISK_04',
___("Asterisk: The LDAP attribute type of the attribute %{attr} is incorrect: its must be password.")
);
/**
@ -41,7 +44,7 @@ LSerror :: defineError('ASTERISK_03',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if Asterisk is totally supported, false in other case
* @return boolean true if Asterisk is totally supported, false in other case
*/
function LSaddon_asterisk_support() {
$retval=true;
@ -72,18 +75,18 @@ LSerror :: defineError('ASTERISK_03',
*
* This function can be used as encode_function of LSattr_ldap :: password.
*
* @param[in] $ldapObject LSldapObject The LSldapObject use to build the hashed password
* @param[in] $clearPassword string The password in clear text
* @param LSldapObject $ldapObject The LSldapObject use to build the hashed password
* @param string $clearPassword The password in clear text
*
* @retval string The hashed password
* @return string|false The hashed password, or false
*/
function hashAsteriskPassword($ldapObject,$clearPassword) {
if (!is_a($ldapObject,'LSldapObject')) {
LSerror :: addErrorCode('ASTERISK_01',array('function' => 'hashAsteriskPassword', 'objectName' => 'LSldapObject'));
return;
return false;
}
if (!is_string($clearPassword)) {
return;
return false;
}
$ldapObject -> registerOtherValue('clearPassword',$clearPassword);
return md5($ldapObject->getFData(LS_ASTERISK_HASH_PWD_FORMAT));
@ -94,20 +97,30 @@ LSerror :: defineError('ASTERISK_03',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject The LSldapObject
* @param LSldapObject $ldapObject The LSldapObject
*
* @retval string asterisk MD5 hashed password or False
* @return string|false asterisk MD5 hashed password or False
*/
function generate_asteriskMD5HashedPassword($ldapObject) {
if ( get_class($ldapObject -> attrs[ LS_ASTERISK_USERPASSWORD_ATTR ]) != 'LSattribute' ) {
LSerror :: addErrorCode('ASTERISK_02',array(LS_ASTERISK_USERPASSWORD_ATTR));
return;
return false;
}
if (
!is_a(
$ldapObject -> attrs[ LS_ASTERISK_USERPASSWORD_ATTR ] -> ldap,
'LSattr_ldap_password'
)
) {
LSerror :: addErrorCode('ASTERISK_04', LS_ASTERISK_USERPASSWORD_ATTR);
return false;
}
$password = $ldapObject -> attrs[ LS_ASTERISK_USERPASSWORD_ATTR ] -> ldap -> getClearPassword();
if (!$password) {
LSerror :: addErrorCode('ASTERISK_03');
return;
return false;
}
return hashAsteriskPassword($ldapObject,(string)$password);
}

View file

@ -44,7 +44,7 @@ LSerror :: defineError('DYNGROUP_02',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if dyngroup are fully supported, false otherwise
* @return boolean true if dyngroup are fully supported, false otherwise
*/
function LSaddon_dyngroup_support() {
$retval = true;
@ -79,12 +79,12 @@ function LSaddon_dyngroup_support() {
return $retval;
}
/*
/**
* Parse LDAP search URI
*
* @param[in] $uri string The LDAP search URI to parse
* @param string $uri The LDAP search URI to parse
*
* @retval array|false Array of parsed LDAP search URI info, or false
* @return array|false Array of parsed LDAP search URI info, or false
*/
function parseLdapSearchURI($uri) {
$uri_parts = explode('?', $uri);
@ -103,9 +103,9 @@ function parseLdapSearchURI($uri) {
/*
* Extract attributes cited in an LDAP filter string
*
* @param[in] $filter string The LDAP filter string
* @param string $uri The LDAP filter string
*
* @retval array|false Array of the attributes cited in the LDAP filter string, or false
* @return array|false Array of the attributes cited in the LDAP filter string, or false
*/
function extractAttributesFromLdapFilterString($filter) {
if ($filter[0] != '(')
@ -122,9 +122,9 @@ function extractAttributesFromLdapFilterString($filter) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject The LSldapObject
* @param LSldapObject $ldapObject The LSldapObject
*
* @retval array|null array of memberUid URI attribute values or null in case of error
* @return array|false array of memberUid URI attribute values or false in case of error
*/
function generateDyngroupMemberUidURI($ldapObject) {
if (!isset($ldapObject -> attrs[ DYNGROUP_MEMBER_DN_URI_ATTRIBUTE ])) {
@ -132,17 +132,17 @@ function generateDyngroupMemberUidURI($ldapObject) {
'DYNGROUP_01',
array('dependency' => DYNGROUP_MEMBER_DN_URI_ATTRIBUTE, 'attr' => DYNGROUP_MEMBER_UID_URI_ATTRIBUTE)
);
return;
return false;
}
$dn_uri = $ldapObject -> attrs[ DYNGROUP_MEMBER_DN_URI_ATTRIBUTE ] -> getValue();
if (empty($dn_uri))
return;
return false;
$uri_parts = explode('?', $dn_uri[0]);
if (count($uri_parts) < 2) {
LSerror :: addErrorCode('DYNGROUP_02', DYNGROUP_MEMBER_DN_URI_ATTRIBUTE);
return;
return false;
}
$uri_parts[1] = 'uid';
return array(
@ -155,9 +155,9 @@ function generateDyngroupMemberUidURI($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $dyngroup The LSldapObject
* @param LSldapObject $dyngroup The LSldapObject
*
* @retval boolean True on success, False otherwise
* @return boolean True on success, False otherwise
*/
function updateDynGroupMembersCache($dyngroup, $reload=true) {
if ($reload && !$dyngroup -> reloadData()) {
@ -354,6 +354,11 @@ function triggerUpdateDynGroupsMembersCacheOnUserChanges(&$user, &$changed_attrs
if (php_sapi_name() != 'cli')
return true;
/**
* CLI command to update dynamic groups members cache
* @param array<string> $command_args Command arguments
* @return bool
*/
function cli_updateDynGroupsMembersCache($command_args) {
return updateDynGroupsMembersCache();
}

View file

@ -50,7 +50,7 @@ LSerror :: defineError('LS_EXPORTSEARCHRESULTASCSV_03',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if exportSearchResultAsCSV is fully supported, false in other case
* @return boolean true if exportSearchResultAsCSV is fully supported, false in other case
*/
function LSaddon_exportSearchResultAsCSV_support() {
$retval=true;
@ -79,11 +79,11 @@ LSerror :: defineError('LS_EXPORTSEARCHRESULTASCSV_03',
/**
* Write LSsearch result as CSV and force download of it.
*
* @param[in] $LSsearch The LSsearch object
* @param LSsearch $LSsearch The LSsearch object
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean Void if CSV file is successfully generated and upload, false in other case
* @return boolean Void if CSV file is successfully generated and upload, false in other case
*/
function exportSearchResultAsCSV($LSsearch) {
$csv = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+');
@ -139,12 +139,12 @@ LSerror :: defineError('LS_EXPORTSEARCHRESULTASCSV_03',
/**
* Write CSV row in file
*
* @param[in] $csv The CSV file description reference
* @param[in] $row An array of a CSV row fields to write
* @param resource &$csv The CSV file description reference
* @param array<string> $row An array of a CSV row fields to write
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean True if CSV row is successfully writed, false in other case
* @return boolean True if CSV row is successfully writed, false in other case
*/
function writeRowInCSV(&$csv, &$row) {
if (!defined('PHP_VERSION_ID') or PHP_VERSION_ID < 50504) {

View file

@ -58,7 +58,7 @@ LSerror :: defineError('FTP_05',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si FTP est pleinement supporté, false sinon
* @return boolean true si FTP est pleinement supporté, false sinon
*/
function LSaddon_ftp_support() {
$retval=true;
@ -84,12 +84,12 @@ LSerror :: defineError('FTP_05',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $host string Le nom ou l'IP du serveur FTP
* @param[in] $port string Le port de connexion au serveur ftp
* @param[in] $user string Le nom d'utilidateur de connexion
* @param[in] $pwd string Le mot de passe de connexion
* @param string $host Le nom ou l'IP du serveur FTP
* @param string $port Le port de connexion au serveur ftp
* @param string $user Le nom d'utilidateur de connexion
* @param string $pwd Le mot de passe de connexion
*
* @retval mixed Net_FTP object en cas de succès, false sinon
* @return Net_FTP|false Net_FTP object en cas de succès, false sinon
*/
function connectToFTP($host,$port,$user,$pwd) {
$cnx = new Net_FTP();
@ -102,13 +102,13 @@ LSerror :: defineError('FTP_05',
else {
LSerror :: addErrorCode('FTP_01',"2");
LSerror :: addErrorCode('FTP_00',$do -> getMessage());
return;
return false;
}
}
else {
LSerror :: addErrorCode('FTP_01',"1");
LSerror :: addErrorCode('FTP_00',$do -> getMessage());
return;
return false;
}
}
@ -117,19 +117,17 @@ LSerror :: defineError('FTP_05',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $host string Le nom ou l'IP du serveur FTP
* @param[in] $port string Le port de connexion au serveur ftp
* @param[in] $user string Le nom d'utilidateur de connexion
* @param[in] $pwd string Le mot de passe de connexion
* @param[in] $dirs array ou string Le(s) dossier(s) à ajouter
* @param string $host Le nom ou l'IP du serveur FTP
* @param string $port Le port de connexion au serveur ftp
* @param string $user Le nom d'utilidateur de connexion
* @param string $pwd Le mot de passe de connexion
* @param array $dirs ou string Le(s) dossier(s) à ajouter
*
* @retval string True ou false si il y a un problème durant la création du/des dossier(s)
* @return bool True ou false si il y a un problème durant la création du/des dossier(s)
*/
function createDirsByFTP($host,$port,$user,$pwd,$dirs,$chmod=NULL) {
$cnx = connectToFTP($host,$port,$user,$pwd);
if (! $cnx){
return;
}
if (!$cnx) return false;
if (!is_array($dirs)) {
$dirs = array($dirs);
}
@ -138,7 +136,7 @@ LSerror :: defineError('FTP_05',
if ($do instanceof PEAR_Error) {
LSerror :: addErrorCode('FTP_02',$dir);
LSerror :: addErrorCode('FTP_00',$do -> getMessage());
return;
return false;
}
if ($chmod) {
$do = $cnx -> chmod($dir,$chmod);
@ -164,19 +162,17 @@ LSerror :: defineError('FTP_05',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $host string Le nom ou l'IP du serveur FTP
* @param[in] $port string Le port de connexion au serveur ftp
* @param[in] $user string Le nom d'utilidateur de connexion
* @param[in] $pwd string Le mot de passe de connexion
* @param[in] $dirs array ou string Le(s) dossier(s) à supprimer
* @param string $host Le nom ou l'IP du serveur FTP
* @param string $port Le port de connexion au serveur ftp
* @param string $user Le nom d'utilidateur de connexion
* @param string $pwd Le mot de passe de connexion
* @param array $dirs ou string Le(s) dossier(s) à supprimer
*
* @retval string True ou false si il y a un problème durant la suppression du/des dossier(s)
* @return bool True ou false si il y a un problème durant la suppression du/des dossier(s)
*/
function removeDirsByFTP($host,$port,$user,$pwd,$dirs) {
$cnx = connectToFTP($host,$port,$user,$pwd);
if (! $cnx){
return;
}
if (!$cnx) return false;
if (!is_array($dirs)) {
$dirs = array($dirs);
}
@ -188,7 +184,7 @@ LSerror :: defineError('FTP_05',
if ($do instanceof PEAR_Error) {
LSerror :: addErrorCode('FTP_03',$dir);
LSerror :: addErrorCode('FTP_00',$do -> getMessage());
return;
return false;
}
}
return true;
@ -199,25 +195,23 @@ LSerror :: defineError('FTP_05',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $host string Le nom ou l'IP du serveur FTP
* @param[in] $port string Le port de connexion au serveur ftp
* @param[in] $user string Le nom d'utilidateur de connexion
* @param[in] $pwd string Le mot de passe de connexion
* @param[in] $old string Le dossier à renomer
* @param[in] $new string Le nouveau nom du dossier à renomer
* @param string $host Le nom ou l'IP du serveur FTP
* @param string $port Le port de connexion au serveur ftp
* @param string $user Le nom d'utilidateur de connexion
* @param string $pwd Le mot de passe de connexion
* @param string $old Le dossier à renomer
* @param string $new Le nouveau nom du dossier à renomer
*
* @retval string True ou false si il y a un problème durant le renomage du/des dossier(s)
* @return bool True ou false si il y a un problème durant le renomage du/des dossier(s)
*/
function renameDirByFTP($host,$port,$user,$pwd,$old,$new) {
$cnx = connectToFTP($host,$port,$user,$pwd);
if (! $cnx){
return;
}
if (!$cnx) return false;
$do = $cnx -> rename($old,$new);
if ($do instanceof PEAR_Error) {
LSerror :: addErrorCode('FTP_05',array('old' => $old,'new' => $new));
LSerror :: addErrorCode('FTP_00',$do -> getMessage());
return;
return false;
}
return true;
}

View file

@ -44,7 +44,7 @@ LSerror :: defineError('MAIL_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si MAIL est pleinement supporté, false sinon
* @return boolean true si MAIL est pleinement supporté, false sinon
*/
function LSaddon_mail_support() {
$retval=true;
@ -87,7 +87,7 @@ LSerror :: defineError('MAIL_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si MAIL est pleinement supporté, false sinon
* @return boolean true si MAIL est pleinement supporté, false sinon
*/
function sendMail($to, $subject, $msg, $headers=array(), $attachments=array(), $eol="\n", $encoding="utf8", $html=false) {
global $MAIL_SEND_PARAMS, $MAIL_HEARDERS;
@ -154,7 +154,7 @@ LSerror :: defineError('MAIL_01',
if ($ret instanceof PEAR_Error) {
LSerror :: addErrorCode('MAIL_01');
LSerror :: addErrorCode('MAIL_00', $ret -> getMessage());
return;
return false;
}
return true;
}
@ -163,6 +163,11 @@ LSerror :: defineError('MAIL_01',
if (php_sapi_name() != 'cli')
return true;
/**
* CLI command to send a test email
* @param array $command_args Command arguments
* @return bool
*/
function cli_test_send_mail($command_args) {
$recipient = null;
$subject = "Test email";
@ -209,6 +214,16 @@ function cli_test_send_mail($command_args) {
return true;
}
/**
* Args autocompleter for CLI test_send_mail command
*
* @param array<string> $comp_words List of already typed words of the command
* @param int $comp_word_num The command word number to autocomplete
* @param string $comp_word The command word to autocomplete
* @param array<string> $opts List of global available options
*
* @return array<string> List of available options for the word to autocomplete
**/
function cli_test_send_mail_autocompleter($comp_words, $comp_word_num, $comp_word, $opts) {
switch ($comp_words[$comp_word_num-1]) {
case '-s':

View file

@ -49,10 +49,10 @@ LSerror :: defineError('MAILDIR_04',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si Maildir est pleinement supporté, false sinon
* @return boolean true si Maildir est pleinement supporté, false sinon
*/
function LSaddon_maildir_support() {
$retval=true;
$retval=true;
// Dependance de librairie
if (!function_exists('createDirsByFTP')) {
@ -83,17 +83,17 @@ $retval=true;
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param[in] $dir Le chemin de la maildir. Si défini, la valeur ne sera pas
* @param LSldapObject $ldapObject L'objet ldap
* @param string $dir Le chemin de la maildir. Si défini, la valeur ne sera pas
* récupérée dans le ldapObject
*
* @retval string True ou false si il y a un problème durant la création de la Maildir
* @return bool True ou false si il y a un problème durant la création de la Maildir
*/
function createMaildirByFTP($ldapObject,$dir=null) {
if (!$dir) {
$dir = getMaildirPath($ldapObject);
if (!$dir) {
return;
return false;
}
}
$dirs = array(
@ -103,7 +103,7 @@ $retval=true;
);
if (!createDirsByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$dirs,LS_MAILDIR_FTP_MAILDIR_CHMOD)) {
LSerror :: addErrorCode('MAILDIR_01');
return;
return false;
}
return true;
}
@ -113,22 +113,22 @@ $retval=true;
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param[in] $dir Le chemin de la maildir. Si défini, la valeur ne sera pas
* @param LSldapObject $ldapObject L'objet ldap
* @param string $dir Le chemin de la maildir. Si défini, la valeur ne sera pas
* récupérée dans le ldapObject
*
* @retval string True ou false si il y a un problème durant la suppression de la Maildir
* @return bool True ou false si il y a un problème durant la suppression de la Maildir
*/
function removeMaildirByFTP($ldapObject,$dir=null) {
if (!$dir) {
$dir = getMaildirPath($ldapObject);
if (!$dir) {
return;
return false;
}
}
if (!removeDirsByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$dir)) {
LSerror :: addErrorCode('MAILDIR_02');
return;
return false;
}
return true;
}
@ -138,9 +138,9 @@ $retval=true;
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval string Le chemin distant de la maildir ou false si il y a un problème
* @return string|false Le chemin distant de la maildir ou false si il y a un problème
*/
function getMaildirPath($ldapObject) {
$dir = getFData(LS_MAILDIR_FTP_MAILDIR_PATH,$ldapObject,'getValue');
@ -156,7 +156,7 @@ $retval=true;
if ($dir=="") {
LSerror :: addErrorCode('MAILDIR_04');
return;
return false;
}
return $dir;
@ -167,15 +167,15 @@ $retval=true;
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $old L'ancien chemin de la maildir
* @param[in] $new Le nouveau chemin de la maildir
* @param string $old L'ancien chemin de la maildir
* @param string $new Le nouveau chemin de la maildir
*
* @retval string True ou false si il y a un problème durant le renomage de la Maildir
* @return bool True ou false si il y a un problème durant le renomage de la Maildir
*/
function renameMaildirByFTP($old,$new) {
if (!renameDirByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$old,$new)) {
LSerror :: addErrorCode('MAILDIR_03');
return;
return false;
}
return true;
}

View file

@ -49,7 +49,7 @@ LSerror :: defineError('MAILQUOTA_04',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean True if this addons is fully supported, false otherwise
* @return boolean True if this addons is fully supported, false otherwise
*/
function LSaddon_mailquota_support() {
$retval=True;
@ -81,9 +81,9 @@ function LSaddon_mailquota_support() {
/**
* Get IMAP mailbox usage
*
* @param[in] $ldapobject LSldapObject The LDAP object
* @param LSldapObject &$LSldapObject The LDAP object
*
* @retval array|false Array with mailbox usage and quota, or false
* @return array|false Array with mailbox usage and quota, or false
**/
function mailquota_get_usage(&$LSldapObject) {
$logger = LSlog :: get_logger("LSaddon_mailquota");
@ -144,9 +144,9 @@ function mailquota_get_usage(&$LSldapObject) {
* [...]
* );
*
* @param[in] $ldapobject LSldapObject The LDAP object
* @param LSldapObject &$LSldapObject The LDAP object
*
* @retval true in any case
* @return bool true in any case
**/
function mailquota_show_usage(&$LSldapObject) {
$quota = mailquota_get_usage($LSldapObject);

View file

@ -35,7 +35,7 @@ LSerror :: defineError('LSORGCHART_SUPPORT_02',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if orgchart addon is totally supported, false in other case
* @return boolean true if orgchart addon is totally supported, false in other case
*/
function LSaddon_orgchart_support() {
$retval = True;

View file

@ -33,7 +33,7 @@ LSerror :: defineError('PHPLDAPADMIN_SUPPORT_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if is supported, false also
* @return boolean true if is supported, false also
*/
function LSaddon_phpldapadmin_support() {
$retval=true;
@ -57,7 +57,7 @@ function LSaddon_phpldapadmin_support() {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true in all cases
* @return boolean true in all cases
*/
function redirectToPhpLdapAdmin(&$ldapObject) {
$url = $ldapObject->getFData(LS_PHPLDAPADMIN_VIEW_OBJECT_URL_FORMAT);

View file

@ -41,7 +41,7 @@ LSerror :: defineError('POSIX_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si POSIX est pleinement supporté, false sinon
* @return boolean true si POSIX est pleinement supporté, false sinon
*/
function LSaddon_posix_support() {
@ -85,9 +85,9 @@ LSerror :: defineError('POSIX_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval integer uidNumber ou false si il y a un problème durant la génération
* @return integer|false uidNumber ou false si il y a un problème durant la génération
*/
function generate_uidNumber($ldapObject) {
@ -103,7 +103,7 @@ LSerror :: defineError('POSIX_01',
$uidNumber = LS_POSIX_UIDNUMBER_MIN_VAL;
if (!is_array($objects))
return;
return false;
foreach($objects as $object) {
if($object['attrs'][LS_POSIX_UIDNUMBER_ATTR] > $uidNumber)
@ -120,9 +120,9 @@ LSerror :: defineError('POSIX_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval integer gidNumber ou false si il y a un problème durant la génération
* @return integer|false gidNumber ou false si il y a un problème durant la génération
*/
function generate_gidNumber($ldapObject) {
@ -138,7 +138,7 @@ LSerror :: defineError('POSIX_01',
$gidNumber = LS_POSIX_GIDNUMBER_MIN_VAL;
if (!is_array($objects))
return;
return false;
foreach($objects as $object) {
if($object['attrs'][LS_POSIX_GIDNUMBER_ATTR] > $gidNumber)
@ -155,14 +155,14 @@ LSerror :: defineError('POSIX_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval string homeDirectory ou false si il y a un problème durant la génération
* @return string|false homeDirectory ou false si il y a un problème durant la génération
*/
function generate_homeDirectory($ldapObject) {
if ( get_class($ldapObject -> attrs[ LS_POSIX_UID_ATTR ]) != 'LSattribute' ) {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'uid', 'attr' => 'homeDirectory'));
return;
return false;
}
$uid = $ldapObject -> attrs[ LS_POSIX_UID_ATTR ] -> getValue();
@ -172,19 +172,19 @@ LSerror :: defineError('POSIX_01',
}
/**
* Generation de homeDirectory
* Create home directory by FTP
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval string homeDirectory ou false si il y a un problème durant la génération
* @return bool True on success, false otherwise
*/
function createHomeDirectoryByFTP($ldapObject) {
$dir = getFData(LS_POSIX_HOMEDIRECTORY_FTP_PATH,$ldapObject,'getValue');
if (!createDirsByFTP(LS_POSIX_HOMEDIRECTORY_FTP_HOST,LS_POSIX_HOMEDIRECTORY_FTP_PORT,LS_POSIX_HOMEDIRECTORY_FTP_USER,LS_POSIX_HOMEDIRECTORY_FTP_PWD,$dir)) {
LSerror :: addErrorCode('POSIX_02');
return;
return false;
}
return true;
}
@ -197,24 +197,24 @@ LSerror :: defineError('POSIX_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject The LSldapObject
* @param LSldapObject $ldapObject The LSldapObject
*
* @retval array|null array of member attribute values or null in case of error
* @return array|false array of member attribute values or false in case of error
*/
function generateMemberFromMemberUid($ldapObject) {
if ( get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute' ) {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'memberUid', 'attr' => 'member'));
return;
return false;
}
if ( get_class($ldapObject -> attrs[ 'member' ]) != 'LSattribute' ) {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'member', 'attr' => 'member'));
return;
return false;
}
$obj_type=LSconfig::get('LSobjects.'.get_class($ldapObject).'.attrs.memberUid.html_options.selectable_object.object_type');
if (empty($obj_type))
return;
return false;
$uids = $ldapObject -> attrs[ 'memberUid' ] -> getValue();
$member = array();
@ -235,19 +235,19 @@ LSerror :: defineError('POSIX_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject The LSldapObject
* @param LSldapObject $ldapObject The LSldapObject
*
* @retval array|null array of memberUid values or null in case of error
* @return array|false array of memberUid values or false in case of error
*/
function generate_memberUidFromUniqueMember($ldapObject) {
if ( get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute' ) {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'memberUid', 'attr' => 'memberUid'));
return;
return false;
}
if ( get_class($ldapObject -> attrs[ 'uniqueMember' ]) != 'LSattribute' ) {
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'uniqueMember', 'attr' => 'memberUid'));
return;
return false;
}
$dns = $ldapObject -> attrs[ 'uniqueMember' ] -> getValue();
@ -275,9 +275,9 @@ LSerror :: defineError('POSIX_01',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $anything anything
* @param mixed $anything anything
*
* @retval integer The shadowLastChange attribute value (=current date)
* @return integer The shadowLastChange attribute value (=current date)
*/
function generate_shadowLastChange($anything) {
return time();

View file

@ -96,7 +96,7 @@ function LSaddon_ppolicy_support() {
/**
* Retrieve ppolicy object (from cache if already loaded)
*
* @param[in] $dn string The DN of the ppolicy object
* @param string $dn The DN of the ppolicy object
*
* @return array|false Array of ppolicy object's attributes on success, false otherwise
*
@ -112,7 +112,7 @@ function get_ppolicy_object($dn) {
/**
* Retrieve ppolicy password max age
*
* @param[in] $ppolicy_dn string Optional DN of the ppolicy object to use
* @param string|null $ppolicy_dn Optional DN of the ppolicy object to use
*
* @return int|null|false The ppolicy password max age (in second) if defined, null if no password max age is defined or false in case of error
*
@ -134,9 +134,9 @@ function get_ppolicy_password_max_age($ppolicy_dn=null) {
/**
* Format and return HTML code of a badge
*
* @param[in] $text string The text of the badge
* @param[in] $bg_color string The background color of the badge (optional, default: green)
* @param[in] $color string The text color of the badge (optional, default: white)
* @param string $text The text of the badge
* @param string $bg_color The background color of the badge (optional, default: green)
* @param string $color The text color of the badge (optional, default: white)
*
* @return string The HTML code of the badge
*
@ -157,7 +157,7 @@ function _ppolicy_badge($text, $bg_color='green', $color='white') {
/**
* Retrieve Ppolicy extraDisplayedColumn password expiration
*
* @param[in] $entry An LSsearchEntry object
* @param LSsearchEntry $entry An LSsearchEntry object
*
* @return string Ppolicy extraDisplayedColumn password expiration
*
@ -194,11 +194,14 @@ function ppolicy_extraDisplayColumn_password_expiration($entry) {
/**
* Write LSsearch result as CSV and force download of it.
*
* @param[in] $LSsearch The LSsearch object
* @param LSsearch $LSsearch The LSsearch object
* @param boolean $as_csv True for CSV export, False for JSON export
* @param boolean $return Set to true to return data instead of trigger the download of it
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @return boolean Void if CSV file is successfully generated and upload, false in other case
* @return boolean|array Data to export as array if $return is enabled, otherwise, true on
* success and false on error.
*/
function ppolicy_export_search_info($LSsearch, $as_csv=true, $return=false) {
$csv = null;
@ -301,12 +304,12 @@ function ppolicy_export_search_info($LSsearch, $as_csv=true, $return=false) {
/**
* Write CSV row in file
*
* @param[in] $csv The CSV file description reference
* @param[in] $row An array of a CSV row fields to write
* @param resource $csv The CSV file description reference
* @param array<string> $row An array of a CSV row fields to write
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean True if CSV row is successfully writed, false in other case
* @return boolean True if CSV row is successfully writed, false in other case
*/
function _ppolicy_write_row_in_csv(&$csv, &$row) {
if (!defined('PHP_VERSION_ID') or PHP_VERSION_ID < 50504) {
@ -324,7 +327,7 @@ function _ppolicy_write_row_in_csv(&$csv, &$row) {
/**
* Handle exportPpolicyInfo API request
*
* @param[in] $request LSurlRequest The request
* @param LSurlRequest $request The request
*
* @return void
**/
@ -343,13 +346,13 @@ function handle_api_LSobject_exportPpolicyInfo($request) {
if (!array_intersect($GLOBALS['LS_PPOLICY_API_GRANTED_PROFILES'], $whoami)) {
LSerror :: addErrorCode('LSsession_11');
LSsession :: displayAjaxReturn();
return false;
return;
}
if (!LSsession :: loadLSclass('LSsearch')) {
LSerror :: addErrorCode('LSsession_05', 'LSsearch');
LSsession :: displayAjaxReturn();
return false;
return;
}
$search = new LSsearch(
@ -365,6 +368,12 @@ function handle_api_LSobject_exportPpolicyInfo($request) {
if (php_sapi_name() != 'cli')
return true;
/**
* CLI command to export password policy info of a all objects of a specified object type
* @param array<string> $command_args Command arguments
* @return bool
*/
function cli_export_ppolicy_info($command_args) {
$objType = null;
$output = false;
@ -425,19 +434,20 @@ function cli_export_ppolicy_info($command_args) {
exit();
}
$fd = fopen($output, 'w') or LStemplate::fatal_error("Fail to open output file '$output'");
fwrite($fd, $data) or LStemplate::fatal_error("Fail to write result in output file '$output'");
$result = fwrite($fd, $data) or LStemplate::fatal_error("Fail to write result in output file '$output'");
@fclose($fd);
return $result;
}
/**
* Args autocompleter for CLI export_ppolicy_info command
*
* @param[in] $command_args array List of already typed words of the command
* @param[in] $comp_word_num int The command word number to autocomplete
* @param[in] $comp_word string The command word to autocomplete
* @param[in] $opts array List of global available options
* @param array<string> $command_args List of already typed words of the command
* @param int $comp_word_num The command word number to autocomplete
* @param string $comp_word The command word to autocomplete
* @param array<string> $opts List of global available options
*
* @retval array List of available options for the word to autocomplete
* @return array<string> List of available options for the word to autocomplete
**/
function cli_export_ppolicy_info_args_autocompleter($command_args, $comp_word_num, $comp_word, $opts) {
$opts = array_merge($opts, array ('-o', '--output', '-j', '--json', '-p', '--pretty'));

View file

@ -36,16 +36,19 @@ LSerror :: defineError('SAMBA_SUPPORT_03',
// Autres erreurs
LSerror :: defineError('SAMBA_01',
___("SAMBA Support: The attribute %{dependency} is missing. Unable to forge the attribute %{attr}.")
___("SAMBA: The attribute %{dependency} is missing. Unable to forge the attribute %{attr}.")
);
LSerror :: defineError('SAMBA_02',
___("SAMBA Support: Can't get the sambaUnixIdPool object.")
___("SAMBA: Can't get the sambaUnixIdPool object.")
);
LSerror :: defineError('SAMBA_03',
___("SAMBA Support: Error modifying the sambaUnixIdPool object.")
___("SAMBA: Error modifying the sambaUnixIdPool object.")
);
LSerror :: defineError('SAMBA_04',
___("SAMBA Support: The %{attr} of the sambaUnixIdPool object is incorrect.")
___("SAMBA: The %{attr} of the sambaUnixIdPool object is incorrect.")
);
LSerror :: defineError('SAMBA_05',
___("SAMBA: The LDAP attribute type of the attribute %{attr} is incorrect: its must be password.")
);
// CONSTANTES
@ -58,7 +61,7 @@ define('LS_SAMBA_INFINITY_TIME',2147483647);
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean True if Samba is fully supported, false otherwise
* @return boolean True if Samba is fully supported, false otherwise
*/
function LSaddon_samba_support() {
@ -110,11 +113,11 @@ function LSaddon_samba_support() {
* sambaSID = LS_SAMBA_DOMAIN_SID-Number
*
* @author Benjamin Renard <brenard@easter-eggs.com>
* @param[in] $ldapObject LSldapObjet The LSldapObjet object
* @param[in] $unix_attr string The UNIX attribute name
* @param[in] $base_number integer The base number value
* @param LSldapObject $ldapObject The LSldapObject object
* @param string $unix_attr The UNIX attribute name
* @param integer $base_number The base number value
*
* @retval string SambaSID ou false si il y a un problème durant la génération
* @return string|false SambaSID ou false si il y a un problème durant la génération
*/
function generate_sambaSID($ldapObject, $unix_attr, $base_number) {
if ( get_class($ldapObject -> attrs[ $unix_attr ]) != 'LSattribute' ) {
@ -125,7 +128,7 @@ function generate_sambaSID($ldapObject, $unix_attr, $base_number) {
'attr' => 'sambaSID'
)
);
return;
return false;
}
$unix_id_attr_val = $ldapObject -> getValue($unix_attr, true, null);
@ -139,10 +142,10 @@ function generate_sambaSID($ldapObject, $unix_attr, $base_number) {
* Number = LS_SAMBA_UIDNUMBER_ATTR * 2 + LS_SAMBA_SID_BASE_USER
* sambaSID = LS_SAMBA_DOMAIN_SID-Number
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval string User SambaSID value on success, false otherwise
* @return string|false User SambaSID value on success, false otherwise
*/
function generate_user_sambaSID($ldapObject) {
return generate_sambaSID($ldapObject, LS_SAMBA_UIDNUMBER_ATTR, LS_SAMBA_SID_BASE_USER);
@ -156,10 +159,10 @@ function generate_user_sambaSID($ldapObject) {
* Number = LS_SAMBA_UIDNUMBER_ATTR * 2 + LS_SAMBA_SID_BASE_USER
* sambaSID = LS_SAMBA_DOMAIN_SID-Number
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval string User SambaSID value on success, false otherwise
* @return string|false User SambaSID value on success, false otherwise
*/
function generate_sambaUserSID($ldapObject) {
LSerror :: addErrorCode(
@ -179,10 +182,10 @@ function generate_sambaUserSID($ldapObject) {
* Number = LS_SAMBA_GIDNUMBER_ATTR * 2 + LS_SAMBA_SID_BASE_GROUP
* sambaSID = LS_SAMBA_DOMAIN_SID-Number
*
* @param[in] $ldapObject LSldapObjet The group LSldapObjet object
* @param LSldapObject $ldapObject The group LSldapObject object
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval string Group SambaSID value on success, false otherwise
* @return string|false Group SambaSID value on success, false otherwise
*/
function generate_group_sambaSID($ldapObject) {
return generate_sambaSID($ldapObject, LS_SAMBA_GIDNUMBER_ATTR, LS_SAMBA_SID_BASE_GROUP);
@ -194,10 +197,10 @@ function generate_group_sambaSID($ldapObject) {
* Note: old-name of the function keep for retro-compatibility. An error
* message is raised when this function is used.
*
* @param[in] $ldapObject LSldapObjet The group LSldapObjet object
* @param LSldapObject $ldapObject The group LSldapObject object
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval string Group SambaSID value on success, false otherwise
* @return string|false Group SambaSID value on success, false otherwise
*/
function generate_sambaGroupSID($ldapObject) {
LSerror :: addErrorCode(
@ -217,10 +220,10 @@ function generate_sambaGroupSID($ldapObject) {
* Number = LS_SAMBA_GIDNUMBER_ATTR * 2 + LS_SAMBA_SID_BASE_GROUP
* sambaSID = LS_SAMBA_DOMAIN_SID-Number
*
* @param[in] $ldapObject LSldapObjet The LSldapObjet object
* @param LSldapObject $ldapObject The LSldapObject object
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval string The sambaPrimaryGroupSID value on success, false otherwise
* @return string|false The sambaPrimaryGroupSID value on success, false otherwise
*/
function generate_sambaPrimaryGroupSID($ldapObject) {
return generate_sambaSID($ldapObject, LS_SAMBA_GIDNUMBER_ATTR, LS_SAMBA_SID_BASE_GROUP);
@ -232,22 +235,31 @@ function generate_sambaPrimaryGroupSID($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval string|false sambaNTPassword value on success, false otherwise
* @return string|false sambaNTPassword value on success, false otherwise
*/
function generate_sambaNTPassword($ldapObject) {
if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) {
LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaNTPassword'));
return;
return false;
}
if (
!is_a(
$ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ] -> ldap,
'LSattr_ldap_password'
)
) {
LSerror :: addErrorCode('SAMBA_05', LS_SAMBA_USERPASSWORD_ATTR);
return false;
}
$password = $ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ] -> ldap -> getClearPassword();
$sambapassword = new smbHash;
$sambaNTPassword = $sambapassword -> nthash($password);
if($sambaNTPassword == '') {
return;
return false;
}
return $sambaNTPassword;
}
@ -257,14 +269,27 @@ function generate_sambaPrimaryGroupSID($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval string|false sambaLMPassword value on success, false otherwise
* @return string|false sambaLMPassword value on success, false otherwise
*/
function generate_sambaLMPassword($ldapObject) {
if ( get_class($ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ]) != 'LSattribute' ) {
LSerror :: addErrorCode('SAMBA_01',array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaLMPassword'));
return;
LSerror :: addErrorCode(
'SAMBA_01',
array('dependency' => LS_SAMBA_USERPASSWORD_ATTR, 'attr' => 'sambaLMPassword')
);
return false;
}
if (
!is_a(
$ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ] -> ldap,
'LSattr_ldap_password'
)
) {
LSerror :: addErrorCode('SAMBA_05', LS_SAMBA_USERPASSWORD_ATTR);
return false;
}
$password = $ldapObject -> attrs[ LS_SAMBA_USERPASSWORD_ATTR ] -> ldap -> getClearPassword();
@ -272,7 +297,7 @@ function generate_sambaPrimaryGroupSID($ldapObject) {
$sambaLMPassword = $sambapassword -> lmhash($password);
if($sambaLMPassword == '') {
return;
return false;
}
return $sambaLMPassword;
}
@ -282,33 +307,31 @@ function generate_sambaPrimaryGroupSID($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $attr string The sambaUnixIdPool attribute name that contain next ID value
* @param string $attr The sambaUnixIdPool attribute name that contain next ID value
*
* @retval integer UNIX ID value on success, false otherwise
* @return string|false UNIX ID value on success, false otherwise
*/
function get_samba_unix_pool_next_id($attr) {
$unix_id_pool_dn = (defined('LS_SAMBA_UNIX_ID_POOL_DN')?constant('LS_SAMBA_UNIX_ID_POOL_DN'):LS_SAMBA_DOMAIN_OBJECT_DN);
$unix_id_pool = LSldap :: getLdapEntry ($unix_id_pool_dn);
if ($unix_id_pool === false) {
LSerror :: addErrorCode('SAMBA_02');
return;
return false;
}
$next_id = $unix_id_pool->getValue($attr, 'single');
if (Net_LDAP2::isError($next_id) || $next_id == 0) {
if (Net_LDAP2::isError($next_id) || !is_string($next_id) || $next_id == '0') {
LSerror :: addErrorCode('SAMBA_04', $attr);
return;
return false;
}
$unix_id_pool->replace(array($attr => ($next_id+1)));
$unix_id_pool->replace(array($attr => (intval($next_id) + 1)));
$res = $unix_id_pool->update();
if(!Net_LDAP2::isError($res)) {
return $next_id;
}
else {
LSerror :: addErrorCode('SAMBA_03');
return;
}
LSerror :: addErrorCode('SAMBA_03');
return false;
}
/**
@ -316,9 +339,9 @@ function get_samba_unix_pool_next_id($attr) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval integer|false uidNumber value on success, false otherwise
* @return integer|false uidNumber value on success, false otherwise
*/
function generate_samba_uidNumber($ldapObject) {
return get_samba_unix_pool_next_id('uidNumber');
@ -332,9 +355,9 @@ function generate_samba_uidNumber($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval integer|false uidNumber value on success, false otherwise
* @return integer|false uidNumber value on success, false otherwise
*/
function generate_uidNumber_withSambaDomainObject($ldapObject) {
LSerror :: addErrorCode(
@ -353,9 +376,9 @@ function generate_uidNumber_withSambaDomainObject($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval integer|false gidNumber value on success, false otherwise
* @return integer|false gidNumber value on success, false otherwise
*/
function generate_samba_gidNumber($ldapObject) {
return get_samba_unix_pool_next_id('gidNumber');
@ -369,9 +392,9 @@ function generate_samba_gidNumber($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval integer|false gidNumber value on success, false otherwise
* @return integer|false gidNumber value on success, false otherwise
*/
function generate_gidNumber_withSambaDomainObject($ldapObject) {
LSerror :: addErrorCode(
@ -390,9 +413,9 @@ function generate_gidNumber_withSambaDomainObject($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $anything anything
* @param mixed $anything anything
*
* @retval integer NT infinity time
* @return integer NT infinity time
*/
function get_samba_infinity_time($anything=null) {
return LS_SAMBA_INFINITY_TIME;
@ -406,9 +429,9 @@ function get_samba_infinity_time($anything=null) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $anything anything
* @param mixed $anything anything
*
* @retval integer NT infinity time
* @return integer NT infinity time
*/
function return_sambaInfinityTime($anything=null) {
LSerror :: addErrorCode(
@ -429,9 +452,9 @@ function return_sambaInfinityTime($anything=null) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $anything anything
* @param mixed $anything anything
*
* @retval integer The sambaPwdLastSet attribute value (=current timestamp)
* @return integer The sambaPwdLastSet attribute value (=current timestamp)
*/
function generate_sambaPwdLastSet($anything) {
return time();
@ -444,9 +467,9 @@ function generate_sambaPwdLastSet($anything) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $anything anything
* @param mixed $anything anything
*
* @retval string The sambaDomainName attribute value
* @return string The sambaDomainName attribute value
*/
function generate_sambaDomainName($anything) {
return LS_SAMBA_DOMAIN_NAME;
@ -457,9 +480,9 @@ function generate_sambaDomainName($anything) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval string The sambaHomePath attribute value
* @return string The sambaHomePath attribute value
*/
function generate_sambaHomePath($ldapObject) {
return $ldapObject -> getFData(LS_SAMBA_HOME_PATH_FORMAT);
@ -470,9 +493,9 @@ function generate_sambaHomePath($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval string The sambaProfilePath attribute value
* @return string The sambaProfilePath attribute value
*/
function generate_sambaProfilePath($ldapObject) {
return $ldapObject -> getFData(LS_SAMBA_PROFILE_PATH_FORMAT);
@ -484,9 +507,9 @@ function generate_sambaProfilePath($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval string The shadowExpire attribute value
* @return string The shadowExpire attribute value
*/
function generate_shadowExpire_from_sambaPwdMustChange($ldapObject) {
$time = $ldapObject -> getValue('sambaPwdMustChange', true, null);
@ -500,9 +523,9 @@ function generate_shadowExpire_from_sambaPwdMustChange($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval string Timestamp corresponding to shadowExpire
* @return string Timestamp corresponding to shadowExpire
*/
function generate_timestamp_from_shadowExpire($ldapObject) {
$days = $ldapObject -> getValue('shadowExpire', true, null);
@ -517,9 +540,9 @@ function generate_timestamp_from_shadowExpire($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval string The sambaPwdMustChange attribute value
* @return string The sambaPwdMustChange attribute value
*/
function generate_sambaPwdMustChange_from_shadowExpire($ldapObject) {
return generate_timestamp_from_shadowExpire($ldapObject);
@ -531,9 +554,9 @@ function generate_sambaPwdMustChange_from_shadowExpire($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject LSldapObjet The user LSldapObjet object
* @param LSldapObject $ldapObject The user LSldapObject object
*
* @retval string The sambaKickoffTime attribute value
* @return string The sambaKickoffTime attribute value
*/
function generate_sambaKickoffTime_from_shadowExpire($ldapObject) {
return generate_timestamp_from_shadowExpire($ldapObject);

View file

@ -25,7 +25,7 @@
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if LSaccessRightsMatrixView addon is totally supported, false in other case
* @return boolean true if LSaccessRightsMatrixView addon is totally supported, false in other case
*/
function LSaddon_showTechInfo_support() {
return True;

View file

@ -64,7 +64,7 @@ LSerror :: defineError('SSH_07',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if SSH is fully supported, false otherwise
* @return boolean true if SSH is fully supported, false otherwise
*/
function LSaddon_ssh_support() {
$retval=true;
@ -88,7 +88,7 @@ LSerror :: defineError('SSH_07',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $params array The SSH connexion parameters :
* @param array $params The SSH connexion parameters :
* array (
* 'host' => '[SSH server hostname/IP]', // required
* 'port' => [SSH port], // optional, default : 22
@ -109,9 +109,9 @@ LSerror :: defineError('SSH_07',
* 'password' => '[SSH private key file password]' // Only if need
* )
* )
* @param[in] $sftp boolean Enable SFTP mode (default : false)
* @param boolean $sftp Enable SFTP mode (default : false)
*
* @retval mixed SSH2/SFTP object or false
* @return SSH2|SFTP|false SSH2/SFTP object or false
*/
function connectToSSH($params, $sftp=false) {
$logger = LSlog :: get_logger('LSaddon_ssh');
@ -150,7 +150,7 @@ LSerror :: defineError('SSH_07',
$key_content = file_get_contents($key_file_path);
if (!$password -> loadKey($key_content)) {
LSerror :: addErrorCode('SSH_03', $key_file_path);
return;
return false;
}
$logger -> debug("Connect on $user@$host:$port (timeout: $timeout sec) with key authentication using file '$key_file_path'.");
}
@ -163,7 +163,7 @@ LSerror :: defineError('SSH_07',
return false;
}
if (isset($sftp))
if ($sftp)
$cnx = new SFTP($host, $port, $timeout);
else
$cnx = new SSH2($host, $port, $timeout);
@ -182,20 +182,18 @@ LSerror :: defineError('SSH_07',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $connection_params array Connection parameters
* @param[in] $dirs array|string The directory/ies to add
* @param[in] $mode integer The directory/ies mode as an octal number (do not forget leading zero,
* @param array $connection_params Connection parameters
* @param array|string $dirs The directory/ies to add
* @param int $chmod The directory/ies mode as an octal number (do not forget leading zero,
* example: 0755 or 02755, default : default umask on the SSH server)
* @param[in] $recursive boolean Enable recursive mode (default : false)
* @param[in] $continue boolean Enable continue mode : do not on error (default : false)
* @param boolean $recursive Enable recursive mode (default : false)
* @param boolean $continue Enable continue mode : do not on error (default : false)
*
* @retval boolean
* @return boolean
*/
function createDirsBySFTP($connection_params, $dirs, $chmod=-1, $recursive=false, $continue=false) {
$cnx = connectToSSH($connection_params, true);
if (! $cnx){
return;
}
if (!$cnx instanceof SFTP) return false;
if (!is_array($dirs)) {
$dirs = array($dirs);
}
@ -216,18 +214,16 @@ LSerror :: defineError('SSH_07',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $connection_params array Connection parameters
* @param[in] $dirs array|string The directory/ies to remove
* @param[in] $recursive boolean Enable recursive mode (default : false)
* @param[in] $continue boolean Enable continue mode : do not on error (default : false)
* @param array $connection_params Connection parameters
* @param array|string $dirs The directory/ies to remove
* @param boolean $recursive Enable recursive mode (default : false)
* @param boolean $continue Enable continue mode : do not on error (default : false)
*
* @retval boolean
* @return boolean
*/
function removeDirsBySFTP($connection_params, $dirs, $recursive=false, $continue=false) {
$cnx = connectToSSH($connection_params, true);
if (! $cnx){
return;
}
if (!$cnx instanceof SFTP) return false;
if (!is_array($dirs)) {
$dirs = array($dirs);
}
@ -248,21 +244,19 @@ LSerror :: defineError('SSH_07',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $connection_params array Connection parameters
* @param[in] $old string The actual directory path to rename
* @param[in] $new string The new directory path
* @param array $connection_params Connection parameters
* @param string $old The actual directory path to rename
* @param string $new The new directory path
*
* @retval boolean
* @return boolean
*/
function renameDirBySFTP($connection_params, $old, $new) {
$cnx = connectToSSH($connection_params, true);
if (! $cnx){
return;
}
if (!$cnx instanceof SFTP) return false;
LSlog :: get_logger('LSaddon_ssh') -> debug("rename($old, $new)");
if (!$cnx -> rename($old, $new)) {
LSerror :: addErrorCode('SSH_07',array('old' => $old,'new' => $new));
return;
return false;
}
return true;
}
@ -272,18 +266,16 @@ LSerror :: defineError('SSH_07',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $connection_params array Connection parameters
* @param[in] $cmd string The command to run on remote server
* @param array $connection_params Connection parameters
* @param string $cmd The command to run on remote server
*
* @retval mixed False if connection fail and an array otherwise, with
* @return array|false False if connection fail and an array otherwise, with
* exit code as first value and the command outup as second
* one (stdout + stderr).
*/
function execBySSH($connection_params, $cmd) {
$cnx = connectToSSH($connection_params);
if (! $cnx){
return;
}
if (!$cnx instanceof SSH2) return false;
LSlog :: get_logger('LSaddon_ssh') -> debug("exec($cmd)");
$result = $cnx -> exec($cmd);
$exit_status = $cnx->getExitStatus();

View file

@ -52,7 +52,7 @@ LSerror :: defineError('SUPANN_04',
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si SUPANN est pleinement supporté, false sinon
* @return boolean true si SUPANN est pleinement supporté, false sinon
*/
function LSaddon_supann_support() {
$retval = true;
@ -110,9 +110,9 @@ function LSaddon_supann_support() {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval string Le displayName ou false si il y a un problème durant la génération
* @return string|false 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' ) {
@ -120,14 +120,14 @@ function generate_displayName($ldapObject) {
'SUPANN_01',
array('dependency' => $GLOBALS['LS_SUPANN_LASTNAME_ATTR'], 'attr' => 'cn')
);
return;
return false;
}
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;
return false;
}
$noms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ] -> getValue();
@ -141,9 +141,9 @@ function generate_displayName($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval string Le CN ou false si il y a un problème durant la génération
* @return string|false 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' ) {
@ -151,14 +151,14 @@ function generate_cn($ldapObject) {
'SUPANN_01',
array('dependency' => $GLOBALS['LS_SUPANN_LASTNAME_ATTR'], 'attr' => 'cn')
);
return;
return false;
}
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;
return false;
}
$noms = $ldapObject -> attrs[ $GLOBALS['LS_SUPANN_LASTNAME_ATTR'] ] -> getValue();
@ -173,9 +173,9 @@ function generate_cn($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut eduPersonOrgUnitDN ou false
* @return array|false Les valeurs de l'attribut eduPersonOrgUnitDN ou false
* si il y a un problème durant la génération
*/
function generate_eduPersonOrgUnitDN($ldapObject) {
@ -184,7 +184,7 @@ function generate_eduPersonOrgUnitDN($ldapObject) {
'SUPANN_01',
array('dependency' => 'supannEntiteAffectation', 'attr' => 'eduPersonOrgUnitDN')
);
return;
return false;
}
$affectations = $ldapObject -> attrs[ 'supannEntiteAffectation' ] -> getUpdateData();
@ -192,7 +192,7 @@ function generate_eduPersonOrgUnitDN($ldapObject) {
$basedn = LSconfig :: get('LSobjects.'.$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'].'.container_dn').','.LSsession::getTopDn();
if ($basedn == "") {
LSerror :: addErrorCode('SUPANN_02','eduPersonOrgUnitDN');
return;
return false;
}
$retval = array();
@ -209,15 +209,15 @@ function generate_eduPersonOrgUnitDN($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array La valeur de l'attribut eduPersonPrimaryOrgUnitDN
* @return array|false 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;
return false;
}
$affectations = $ldapObject -> attrs[ 'supannEntiteAffectationPrincipale' ] -> getUpdateData();
@ -225,7 +225,7 @@ function generate_eduPersonPrimaryOrgUnitDN($ldapObject) {
$basedn = LSconfig :: get('LSobjects.'.$GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'].'.container_dn').','.LSsession::getTopDn();
if ($basedn == "") {
LSerror :: addErrorCode('SUPANN_02','eduPersonPrimaryOrgUnitDN');
return;
return false;
}
$retval = array();
@ -245,15 +245,15 @@ function generate_eduPersonPrimaryOrgUnitDN($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array La valeur de l'attribut eduPersonOrgDN ou false
* @return array|false 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;
return false;
}
$eta = $ldapObject -> attrs[ 'supannEtablissement' ] -> getUpdateData();
@ -277,9 +277,9 @@ function generate_eduPersonOrgDN($ldapObject) {
*
* {SUPANN}S410
*
* @param[in] $val La valeur
* @param string $value La valeur
*
* @retval array Un tableau cle->valeur contenant label et value ou False
* @return array|false Un tableau cle->valeur contenant label et value ou False
**/
function supannParseLabeledValue($value) {
if (preg_match('/^\{([^\}]*)\}(.*)$/', $value, $m)) {
@ -288,7 +288,7 @@ function supannParseLabeledValue($value) {
'value' => $m[2]
);
}
return;
return false;
}
/**
@ -300,15 +300,15 @@ function supannParseLabeledValue($value) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $val La valeur composite
* @param string $val La valeur composite
*
* @retval array Un tableau contenant key->value ou false en cas d'erreur
* @return array|false Un tableau contenant key->value ou false en cas d'erreur
**/
function supannParseCompositeValue($val) {
// Check value is valid
if (!preg_match('/^(\[[^=]+=[^\]\]]*\])+$/', $val)) {
LSlog :: get_logger('LSaddon_supann') -> warning("supannParseCompositeValue($val): invalid value");
return;
return false;
}
// Search for components value
@ -319,7 +319,7 @@ function supannParseCompositeValue($val) {
}
return $parseValue;
}
return;
return false;
}
/**
@ -342,9 +342,9 @@ function supannParseCompositeValue($val) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $val Tableau associatif des valeurs
* @param array $val Tableau associatif des valeurs
*
* @retval array Un tableau contenant key->value ou false en cas d'erreur
* @return string La valeur composite formatée
**/
function supannFormatCompositeValue($val) {
$retval = "";
@ -361,9 +361,9 @@ function supannFormatCompositeValue($val) {
/**
* Retourne le nom court d'une entite en fonction de son identifiant
*
* @param[in] $id L'identifiant de l'entite (supannCodeEntite)
* @param string $id L'identifiant de l'entite (supannCodeEntite)
*
* @retval string Le nom de l'entite
* @return string Le nom de l'entite
**/
function supanGetEntiteNameById($id) {
if (LSsession::loadLSobject($GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'])) {
@ -379,9 +379,9 @@ function supanGetEntiteNameById($id) {
/**
* Valide l'ID d'une entite
*
* @param[in] $id L'identifiant de l'entite (supannCodeEntite)
* @param string $id L'identifiant de l'entite (supannCodeEntite)
*
* @retval boolean True si une entité avec cet ID existe, False sinon
* @return boolean True si une entité avec cet ID existe, False sinon
**/
function supannValidateEntityId($id) {
if (LSsession::loadLSobject($GLOBALS['LS_SUPANN_LSOBJECT_ENTITE_TYPE'])) {
@ -399,10 +399,10 @@ function supannValidateEntityId($id) {
* et retourne un tableau mettant en relation leur identifiant et leur nom
* d'affichage.
*
* @param[in] $pattern string Le pattern de recherche
* @param[in] $max_matches int Nombre maximum de résultat retournés (optionnel, par défaut : 10)
* @param string $pattern Le pattern de recherche
* @param string $pattern Nombre maximum de résultat retournés (optionnel, par défaut : 10)
*
* @retval array Tableau du résultat de la recherche mettant en relation
* @return 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) {
@ -437,9 +437,9 @@ function supannSearchEntityByPattern($pattern, $max_matches=10) {
/**
* Retourne les infos d'un parrain en fonction de son DN
*
* @param[in] $dn Le DN du parrain
* @param string $dn Le DN du parrain
*
* @retval array Le nom, le type et le DN du parrain (Format: array('dn' => [DN], 'type' => [type], 'name' => [name]))
* @return array Le nom, le type et le DN du parrain (Format: array('dn' => [DN], 'type' => [type], 'name' => [name]))
**/
function supanGetParrainInfoByDN($dn) {
$matched = array(
@ -466,9 +466,9 @@ function supanGetParrainInfoByDN($dn) {
/**
* Valide le DN d'un parrain
*
* @param[in] $dn Le DN d'un parrain
* @param string $dn Le DN d'un parrain
*
* @retval boolean True si un parrain avec ce DN existe, False sinon
* @return boolean True si un parrain avec ce DN existe, False sinon
**/
function supannValidateParrainDN($dn) {
$info = supanGetParrainInfoByDN($dn);
@ -479,10 +479,10 @@ function supannValidateParrainDN($dn) {
* Cherche des parrains répondant au pattern de recherche passé en paramètres
* et retourne un tableau mettant en relation leur DN et leur nom d'affichage.
*
* @param[in] $pattern string Le pattern de recherche
* @param[in] $max_matches int Nombre maximum de résultat retournés (optionnel, par défaut : 10)
* @param string $pattern Le pattern de recherche
* @param string $pattern Nombre maximum de résultat retournés (optionnel, par défaut : 10)
*
* @retval array Tableau du résultat de la recherche mettant en relation
* @return 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) {
@ -518,11 +518,11 @@ function supannSearchParrainByPattern($pattern, $max_matches=10) {
/**
* Vérifie si une valeur et son étiquette sont valide pour une table donnée
*
* @param[in] $table La table de nomenclature
* @param[in] $label L'étiquette de la valeur (optionnel)
* @param[in] $value La valeur
* @param string $table La table de nomenclature
* @param string $label L'étiquette de la valeur (optionnel)
* @param string $value La valeur
*
* @retval booleab True si valide, False sinon
* @return array|false Tableau des informations de la valeur si elle est valide, false sinon
**/
function supannValidateNomenclatureValue($table, $label, $value) {
if (!supannLoadNomenclature($table))
@ -561,11 +561,11 @@ function supannValidateNomenclatureValue($table, $label, $value) {
* Retourne le label d'une valeur en fonction de la table de nomenclature
* et de l'étiquette de la valeur.
*
* @param[in] $table La table de nomenclature
* @param[in] $label L'étiquette de la valeur (optionnel)
* @param[in] $value La valeur
* @param string $table La table de nomenclature
* @param string $label L'étiquette de la valeur (optionnel)
* @param string $value La valeur
*
* @retval array Le label de la valeur. En cas de valeur nor-reconnue, retourne
* @return string 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) {
@ -578,9 +578,9 @@ function supannGetNomenclatureLabel($table, $label, $value) {
/**
* Retourne les valeurs possibles d'une table de nomenclature pour chaque fournisseur
*
* @param[in] $table La table de nomenclature
* @param string $table La table de nomenclature
*
* @retval array Tableau contenant pour chaque fournisseur, les valeurs possibles de
* @return array Tableau contenant pour chaque fournisseur, les valeurs possibles de
* la table de nomenclature
**/
function supannGetNomenclatureTable($table) {
@ -598,12 +598,12 @@ function supannGetNomenclatureTable($table) {
/**
* Retourne les valeurs possibles d'une table de nomenclature
*
* @param[in] $table La table de nomenclature
* @param[in] $add_provider_label Booléen définissant si le fournisseur de la valeur
* @param string $table La table de nomenclature
* @param bool $add_provider_label Booléen définissant si le fournisseur de la valeur
* doit être ajouté en tant qu'étiquette de la valeur
* (optinel, par défaut: vrai)
*
* @retval array Tableau contenant les valeurs possibles de la table
* @return array Tableau contenant les valeurs possibles de la table
* de nomenclature
**/
function supannGetNomenclaturePossibleValues($table, $add_provider_label=True) {
@ -626,10 +626,10 @@ function supannGetNomenclaturePossibleValues($table, $add_provider_label=True) {
* Cherche des valeurs d'une nomenclature répondant au pattern de recherche passé en paramètres
* et retourne un tableau de celles-ci.
*
* @param[in] $pattern string Le pattern de recherche
* @param[in] $max_matches int Nombre maximum de résultat retournés (optionnel, par défaut : 10)
* @param string $pattern Le pattern de recherche
* @param string $pattern Nombre maximum de résultat retournés (optionnel, par défaut : 10)
*
* @retval array Tableau du résultat de la recherche
* @return array Tableau du résultat de la recherche
**/
function supannSearchNomenclatureValueByPattern($table, $pattern, $max_matches=10) {
$retval = array();
@ -659,11 +659,11 @@ function supannSearchNomenclatureValueByPattern($table, $pattern, $max_matches=1
* get_possible_values de la configuration HTML de l'attribut
* supannCivilite avec un type d'attribut HTML select_list (ou select_box).
*
* @param[in] $options La configuration HTML de l'attribut
* @param[in] $name Le nom de l'attribut
* @param[in] &$ldapObject Une référence à l'object LSldapObject
* @param array $options La configuration HTML de l'attribut
* @param string $name Le nom de l'attribut
* @param LSldapObject &$ldapObject Une référence à l'object LSldapObject
*
* @retval array Tableau contenant les valeurs possibles de l'attribut
* @return array Tableau contenant les valeurs possibles de l'attribut
* (avec les labels traduits).
**/
function supannGetCivilitePossibleValues($options, $name, $ldapObject) {
@ -677,11 +677,11 @@ function supannGetCivilitePossibleValues($options, $name, $ldapObject) {
* get_possible_values de la configuration HTML de l'attribut
* eduPersonAffiliation (par exemple) avec un type d'attribut HTML select_list.
*
* @param[in] $options La configuration HTML de l'attribut
* @param[in] $name Le nom de l'attribut
* @param[in] &$ldapObject Une référence à l'object LSldapObject
* @param array $options La configuration HTML de l'attribut
* @param string $name Le nom de l'attribut
* @param LSldapObject &$ldapObject Une référence à l'object LSldapObject
*
* @retval array Tableau contenant les valeurs possibles de l'attribut
* @return array Tableau contenant les valeurs possibles de l'attribut
* (avec les labels traduits).
**/
function supannGetAffiliationPossibleValues($options=null, $name=null, $ldapObject=null) {
@ -695,11 +695,11 @@ function supannGetAffiliationPossibleValues($options=null, $name=null, $ldapObje
* get_possible_values de la configuration du composant ressource de l'attribut
* supannRessourceEtat (entre autre) avec un type de composant select.
*
* @param[in] $options La configuration HTML de l'attribut
* @param[in] $name Le nom de l'attribut
* @param[in] &$ldapObject Une référence à l'object LSldapObject
* @param array $options La configuration HTML de l'attribut
* @param string $name Le nom de l'attribut
* @param LSldapObject &$ldapObject Une référence à l'object LSldapObject
*
* @retval array Tableau contenant les valeurs possibles de l'attribut
* @return array Tableau contenant les valeurs possibles de l'attribut
* (avec les labels traduits).
**/
function supannGetRessourcePossibleValues($options=null, $name=null, $ldapObject=null) {
@ -713,11 +713,11 @@ function supannGetRessourcePossibleValues($options=null, $name=null, $ldapObject
* get_possible_values de la configuration du composant etat de l'attribut
* supannRessourceEtat (entre autre) avec un type de composant select.
*
* @param[in] $options La configuration HTML de l'attribut
* @param[in] $name Le nom de l'attribut
* @param[in] &$ldapObject Une référence à l'object LSldapObject
* @param array $options La configuration HTML de l'attribut
* @param string $name Le nom de l'attribut
* @param LSldapObject &$ldapObject Une référence à l'object LSldapObject
*
* @retval array Tableau contenant les valeurs possibles de l'attribut
* @return array Tableau contenant les valeurs possibles de l'attribut
* (avec les labels traduits).
**/
function supannGetRessourceEtatPossibleValues($options=null, $name=null, $ldapObject=null) {
@ -731,11 +731,11 @@ function supannGetRessourceEtatPossibleValues($options=null, $name=null, $ldapOb
* get_possible_values de la configuration du composant sous_etat de l'attribut
* supannRessourceEtat (entre autre) avec un type de composant select.
*
* @param[in] $options La configuration HTML de l'attribut
* @param[in] $name Le nom de l'attribut
* @param[in] &$ldapObject Une référence à l'object LSldapObject
* @param array $options La configuration HTML de l'attribut
* @param string $name Le nom de l'attribut
* @param LSldapObject &$ldapObject Une référence à l'object LSldapObject
*
* @retval array Tableau contenant les valeurs possibles de l'attribut
* @return array Tableau contenant les valeurs possibles de l'attribut
* (avec les labels traduits).
**/
function supannGetRessourceSousEtatPossibleValues($options=null, $name=null, $ldapObject=null) {
@ -754,10 +754,10 @@ function supannGetRessourceSousEtatPossibleValues($options=null, $name=null, $ld
*
* @author Benjamin Dauvergne <bdauvergne@entrouvert.com>
*
* @param[in] &$ldapObject Une référence à l'object LSldapObject
* @param LSldapObject &$ldapObject Une référence à l'object LSldapObject
* @author Benjamin Dauvergne <bdauvergne@entrouvert.com>
*
* @retval boolean True si les valeurs sont valides, False sinon
* @return boolean True si les valeurs sont valides, False sinon
**/
global $_supannCheckEduPersonAffiliation_checked;
$_supannCheckEduPersonAffiliation_checked = false;
@ -784,9 +784,9 @@ function supannCheckEduPersonAffiliation(&$ldapObject) {
*
* @author Benjamin Dauvergne <bdauvergne@entrouvert.com>
*
* @param[in] &$ldapObject Une référence à l'object LSldapObject
* @param LSldapObject &$ldapObject Une référence à l'object LSldapObject
*
* @retval boolean True si la valeur est valide, False sinon
* @return boolean True si la valeur est valide, False sinon
**/
function supannCheckEduPersonPrimaryAffiliation(&$ldapObject) {
$primary = $ldapObject->getValue('eduPersonPrimaryAffiliation');
@ -803,11 +803,11 @@ function supannCheckEduPersonPrimaryAffiliation(&$ldapObject) {
* get_possible_values de la configuration HTML de l'attribut
* supannOIDCGenre avec un type d'attribut HTML select_list ou select_box.
*
* @param[in] $options La configuration HTML de l'attribut
* @param[in] $name Le nom de l'attribut
* @param[in] &$ldapObject Une référence à l'object LSldapObject
* @param array $options La configuration HTML de l'attribut
* @param string $name Le nom de l'attribut
* @param LSldapObject &$ldapObject Une référence à l'object LSldapObject
*
* @retval array Tableau contenant les valeurs possibles de l'attribut
* @return array Tableau contenant les valeurs possibles de l'attribut
* (avec les labels traduits).
**/
function supannGetOIDCGenrePossibleValues($options, $name, $ldapObject) {
@ -834,12 +834,12 @@ function supannDetectCodesPopulations($populations, $prefix="") {
}
}
/*
/**
* Charge une nomenclature SUPANN
*
* @param[in] $table string La nomenclature à charger
* @param string $pattern La nomenclature à charger
*
* @retval boolean True si la nomenclature est chargée, False en cas de problème
* @return boolean True si la nomenclature est chargée, False en cas de problème
*/
$GLOBALS['_supann_loaded_nomenclatures'] = array();
function supannLoadNomenclature($table) {
@ -1007,9 +1007,9 @@ function supannLoadNomenclature($table) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array La valeur de l'attribut eduPersonOrgDN ou false
* @return string|false La valeur de l'attribut eduPersonOrgDN ou false
* si il y a un problème durant la génération
*/
function generate_eduPersonPrincipalName($ldapObject) {
@ -1022,9 +1022,9 @@ function generate_eduPersonPrincipalName($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array La valeur de l'attribut eduPersonOrgDN ou false
* @return string|false La valeur de l'attribut eduPersonOrgDN ou false
* si il y a un problème durant la génération
*/
function generate_eduPersonUniqueId($ldapObject) {
@ -1044,9 +1044,9 @@ function generate_eduPersonUniqueId($ldapObject) {
* Note: Cette fonction peut également être utilisé pour le type d'objet
* correspond aux établissements.
*
* @param[in] &$ldapObject Une référence à l'object LSldapObject
* @param LSldapObject &$ldapObject Une référence à l'object LSldapObject
*
* @retval boolean True si la valeur est valide, False sinon
* @return boolean True si la valeur est valide, False sinon
**/
function supannCheckEntityCouldBeDeleted($ldapObject) {
$children = $ldapObject -> listObjectsInRelation(
@ -1067,11 +1067,11 @@ function supannCheckEntityCouldBeDeleted($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param[in] $component Le composant associés à l'attribut à généré
* @param[in] $ignore_value Valeur possible du composant qui doit être ignoré (optionnel)
* @param LSldapObject $ldapObject L'objet ldap
* @param string $component Le composant associés à l'attribut à généré
* @param string $ignore_value Valeur possible du composant qui doit être ignoré (optionnel)
*
* @retval array Les valeurs (uniques) du composant passé en paramètres trouvées dans les
* @return array Les valeurs (uniques) du composant passé en paramètres trouvées dans les
* valeurs de l'attribut supannEtuInscription
*/
function generate_from_supannEtuInscription($ldapObject, $component, $ignore_value=null) {
@ -1108,9 +1108,9 @@ function generate_from_supannEtuInscription($ldapObject, $component, $ignore_val
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut supannEtuDiplome
* @return array Les valeurs de l'attribut supannEtuDiplome
*/
function generate_supannEtuDiplome($ldapObject) {
return generate_from_supannEtuInscription($ldapObject, 'diplome');
@ -1122,9 +1122,9 @@ function generate_supannEtuDiplome($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut supannEtuTypeDiplome
* @return array Les valeurs de l'attribut supannEtuTypeDiplome
*/
function generate_supannEtuTypeDiplome($ldapObject) {
return generate_from_supannEtuInscription($ldapObject, 'typedip');
@ -1136,9 +1136,9 @@ function generate_supannEtuTypeDiplome($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut supannEtuRegimeInscription
* @return array Les valeurs de l'attribut supannEtuRegimeInscription
*/
function generate_supannEtuRegimeInscription($ldapObject) {
return generate_from_supannEtuInscription($ldapObject, 'regimeinsc', '$');
@ -1150,9 +1150,9 @@ function generate_supannEtuRegimeInscription($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut supannEtuSecteurDisciplinaire
* @return array Les valeurs de l'attribut supannEtuSecteurDisciplinaire
*/
function generate_supannEtuSecteurDisciplinaire($ldapObject) {
return generate_from_supannEtuInscription($ldapObject, 'sectdisc', '-');
@ -1164,9 +1164,9 @@ function generate_supannEtuSecteurDisciplinaire($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut supannEtuAnneeInscription
* @return array Les valeurs de l'attribut supannEtuAnneeInscription
*/
function generate_supannEtuAnneeInscription($ldapObject) {
return generate_from_supannEtuInscription($ldapObject, 'anneeinsc');
@ -1178,9 +1178,9 @@ function generate_supannEtuAnneeInscription($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut supannEtuCursusAnnee
* @return array Les valeurs de l'attribut supannEtuCursusAnnee
*/
function generate_supannEtuCursusAnnee($ldapObject) {
return generate_from_supannEtuInscription($ldapObject, 'cursusann');
@ -1192,9 +1192,9 @@ function generate_supannEtuCursusAnnee($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut supannEtuElementPedagogique
* @return array Les valeurs de l'attribut supannEtuElementPedagogique
*/
function generate_supannEtuElementPedagogique($ldapObject) {
return generate_from_supannEtuInscription($ldapObject, 'eltpedago');
@ -1206,9 +1206,9 @@ function generate_supannEtuElementPedagogique($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut supannEtuEtape
* @return array Les valeurs de l'attribut supannEtuEtape
*/
function generate_supannEtuEtape($ldapObject) {
return generate_from_supannEtuInscription($ldapObject, 'etape');
@ -1220,9 +1220,9 @@ function generate_supannEtuEtape($ldapObject) {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $ldapObject L'objet ldap
* @param LSldapObject $ldapObject L'objet ldap
*
* @retval array Les valeurs de l'attribut supannEtuDateFin
* @return string|null Les valeurs de l'attribut supannEtuDateFin
*/
function generate_supannEtuDateFin($ldapObject) {
$values = generate_from_supannEtuInscription($ldapObject, 'datefin');
@ -1242,17 +1242,25 @@ function generate_supannEtuDateFin($ldapObject) {
LSlog :: get_logger('LSaddon_supann') -> debug(
"generate_supannEtuDateFin($ldapObject): result = ".varDump($max_time)
);
return $max_time;
return $max_time?strval($max_time):null;
}
if (php_sapi_name() != 'cli')
return true;
/**
* CLI command to generate Supann codeEtablissement UAI nomenclature
* @param array<string> $command_args Command arguments
* @return bool
*/
function cli_generate_supann_codeEtablissement_uai_nomenclature($command_args) {
$data = file_get_contents('https://data.enseignementsup-recherche.gouv.fr/explore/dataset/fr-esr-principaux-etablissements-enseignement-superieur/download?format=json');
$items = json_decode($data, true);
if (!is_array($items))
LSlog :: get_logger('LSaddon_supann') -> fatal('Fail to retrieve UAI dataset from data.enseignementsup-recherche.gouv.fr');
if (!is_array($items)) {
LSlog :: get_logger('LSaddon_supann') -> fatal(
'Fail to retrieve UAI dataset from data.enseignementsup-recherche.gouv.fr');
return false;
}
$codes = array();
foreach($items as $item) {
if (!isset($item['fields']) || !isset($item['fields']['uai']) || !$item['fields']['uai'])
@ -1260,6 +1268,7 @@ function cli_generate_supann_codeEtablissement_uai_nomenclature($command_args) {
$codes[$item['fields']['uai']] = $item['fields']['uo_lib'];
}
var_export($codes);
return true;
}
LScli :: add_command(

View file

@ -29,23 +29,39 @@ LSsession :: loadLSclass('LSlog_staticLoggerClass');
*/
class LSattr_html extends LSlog_staticLoggerClass {
// The attribute name
var $name;
/**
* The attribute name
* @var string
*/
var string $name;
// The attribute configuration
var $config;
/**
* Attribute configuration (LSobjects.<type>.attrs.<attr_name>)
* @var array<string,mixed>
*/
var array $config;
// The reference of the parent LSattribute object
var $attribute;
/**
* The reference of the parent LSattribute object
* @var LSattribute
*/
var LSattribute $attribute;
// The corresponding LSformElement object type
var $LSformElement_type = false;
/**
* The corresponding LSformElement object type
* Note: Must be set in implemented classes
* @var string
*/
var string $LSformElement_type = '';
// If true, this LSattr_html type is considered as able to only support
// the first and unique value of the attribute. If more than one value
// is passed to this LSattr_html type, an LSattr_html_03 error will be
// triggered.
protected $singleValue = false;
/**
* If true, this LSattr_html type is considered as able to only support
* the first and unique value of the attribute. If more than one value
* is passed to this LSattr_html type, an LSattr_html_03 error will be
* triggered.
* @var bool
*/
protected bool $singleValue = false;
/**
* Constructeur
@ -54,23 +70,22 @@ class LSattr_html extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $name string Nom de l'attribut ldap
* @param[in] $config array Configuration de l'objet
* @param[in] &$attribute LSattribute L'objet LSattribut parent
* @param string $name Nom de l'attribut ldap
* @param array $config Configuration de l'objet
* @param LSattribute &$attribute L'objet LSattribut parent
*
* @retval boolean Retourne true.
* @return boolean Retourne true.
*/
public function __construct($name, $config, &$attribute) {
$this -> name = $name;
$this -> config = $config;
$this -> attribute =& $attribute;
return true;
}
/**
* Allow conversion of LSattr_html to string
*
* @retval string The string representation of the LSattr_html
* @return string The string representation of the LSattr_html
*/
public function __toString() {
return "<".get_class($this)." ".$this -> name.">";
@ -82,7 +97,7 @@ class LSattr_html extends LSlog_staticLoggerClass {
* Retourne le label de l'attribut ou son nom si aucun label n'est défini
* dans la configuration.
*
* @retval string Le label de l'attribut.
* @return string Le label de l'attribut.
*/
public function getLabel() {
return __($this -> getConfig('label', $this -> name));
@ -91,21 +106,21 @@ class LSattr_html extends LSlog_staticLoggerClass {
/**
* Ajoute l'attribut au formualaire passer en paramètre
*
* @param[in] &$form LSform Le formulaire
* @param[in] $idForm L'identifiant du formulaire
* @param[in] $data Valeur du champs du formulaire
* @param LSform &$form Le formulaire
* @param string $idForm L'identifiant du formulaire
* @param array|string|null $data Valeur du champs du formulaire
*
* @retval LSformElement L'element du formulaire ajouté
* @return LSformElement|false L'element du formulaire ajouté, ou false
*/
public function addToForm (&$form,$idForm,$data=NULL) {
if (!$this -> LSformElement_type) {
LSerror :: addErrorCode('LSattr_html_01',$this -> name);
return;
return false;
}
$element=$form -> addElement($this -> LSformElement_type, $this -> name, $this -> getLabel(), $this -> config, $this);
if(!$element) {
LSerror :: addErrorCode('LSform_06',$this -> name);
return;
return false;
}
if (!is_null($data)) {
$data = ensureIsArray($data);
@ -123,9 +138,9 @@ class LSattr_html extends LSlog_staticLoggerClass {
/**
* Effectue les tâches nécéssaires au moment du rafraichissement du formulaire
*
* @param[in] $data mixed La valeur de l'attribut
* @param mixed $data The attribute value
*
* @retval mixed La valeur formatée de l'attribut
* @return mixed La valeur formatée de l'attribut
**/
public function refreshForm($data) {
return $data;
@ -134,9 +149,9 @@ class LSattr_html extends LSlog_staticLoggerClass {
/**
* Return the values to be displayed in the LSform
*
* @param[in] $data The values of attribute
* @param array $data The values of attribute
*
* @retval array The values to be displayed in the LSform
* @return array The values to be displayed in the LSform
**/
public function getFormVal($data) {
return $this -> attribute -> getDisplayValue($data);
@ -145,11 +160,11 @@ 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 string $param The configuration parameter
* @param mixed $default The default value (default : null)
* @param string $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
* @return mixed The configuration parameter value or default value if not set
**/
public function getConfig($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> config);

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_boolean extends LSattr_html {
var $LSformElement_type = 'boolean';
var string $LSformElement_type = 'boolean';
}

View file

@ -27,16 +27,16 @@
*/
class LSattr_html_date extends LSattr_html {
var $LSformElement_type = 'date';
var string $LSformElement_type = 'date';
/**
* Ajoute l'attribut au formualaire passer en paramètre
*
* @param[in] &$form LSform Le formulaire
* @param[in] $idForm L'identifiant du formulaire
* @param[in] $data Valeur du champs du formulaire
* @param LSform &$form Le formulaire
* @param string $idForm L'identifiant du formulaire
* @param array|string|null $data Valeur du champs du formulaire
*
* @retval LSformElement L'element du formulaire ajouté
* @return LSformElement_date|false L'element du formulaire ajouté
*/
function addToForm (&$form,$idForm,$data=NULL) {
$element = parent::addToForm($form,$idForm,$data);
@ -46,12 +46,12 @@ class LSattr_html_date extends LSattr_html {
array(
'msg' => _('Invalid value'),
'params' => array(
'format' => $element -> getFormat(),
'special_values' => array_keys($element -> getSpecialValues()),
'format' => $element -> getFormat(), // @phpstan-ignore-line
'special_values' => array_keys($element -> getSpecialValues()), // @phpstan-ignore-line
)
)
);
return $element;
return (is_a($element, 'LSformElement_date')?$element:false);
}
}

View file

@ -27,7 +27,7 @@
*/
class LSattr_html_image extends LSattr_html {
var $LSformElement_type = 'image';
protected $singleValue = true;
var string $LSformElement_type = 'image';
protected bool $singleValue = true;
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_jsonCompositeAttribute extends LSattr_html {
var $LSformElement_type = 'jsonCompositeAttribute';
var string $LSformElement_type = 'jsonCompositeAttribute';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_labeledValue extends LSattr_html {
var $LSformElement_type = 'labeledValue';
var string $LSformElement_type = 'labeledValue';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_mail extends LSattr_html {
var $LSformElement_type = 'mail';
var string $LSformElement_type = 'mail';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_mailQuota extends LSattr_html {
var $LSformElement_type = 'mailQuota';
var string $LSformElement_type = 'mailQuota';
}

View file

@ -29,7 +29,12 @@ LSsession :: loadLSaddon('maildir');
*/
class LSattr_html_maildir extends LSattr_html {
var $LSformElement_type = 'maildir';
var string $LSformElement_type = 'maildir';
/**
* Registered actions to do on object events
* @var array
*/
var $_toDo = array();
public function __construct($name, $config, &$attribute) {

View file

@ -27,7 +27,7 @@
*/
class LSattr_html_password extends LSattr_html {
var $LSformElement_type = 'password';
protected $singleValue = true;
var string $LSformElement_type = 'password';
protected bool $singleValue = true;
}

View file

@ -29,6 +29,6 @@ LSsession :: loadLSclass('LSattr_html_textarea');
*/
class LSattr_html_postaladdress extends LSattr_html_textarea {
var $LSformElement_type = 'postaladdress';
var string $LSformElement_type = 'postaladdress';
}

View file

@ -29,6 +29,6 @@ LSsession :: loadLSclass('LSattr_html_textarea');
*/
class LSattr_html_pre extends LSattr_html_textarea {
var $LSformElement_type = 'pre';
var string $LSformElement_type = 'pre';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_quota extends LSattr_html {
var $LSformElement_type = 'quota';
var string $LSformElement_type = 'quota';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_rss extends LSattr_html {
var $LSformElement_type = 'rss';
var string $LSformElement_type = 'rss';
}

View file

@ -27,18 +27,18 @@ LSsession :: loadLSclass('LSattr_html_select_box');
*/
class LSattr_html_sambaAcctFlags extends LSattr_html_select_box {
var $LSformElement_type = 'sambaAcctFlags';
var string $LSformElement_type = 'sambaAcctFlags';
/**
* Retourne un tableau des valeurs possibles de la liste
*
* @param[in] $options Attribute options (optional)
* @param[in] $name Attribute name (optional)
* @param[in] &$ldapObject Related LSldapObject (optional)
* @param array|false $options Attribute options (optional)
* @param string|false $name Attribute name (optional)
* @param LSldapObject|false &$ldapObject Related LSldapObject (optional)
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array Tableau associatif des valeurs possible de la liste avec en clé
* @return array Tableau associatif des valeurs possible de la liste avec en clé
* la valeur des balises option et en valeur ce qui sera affiché.
*/
public static function _getPossibleValues($options=false, $name=false, &$ldapObject=false) {

View file

@ -33,6 +33,6 @@ LSsession :: loadLSclass('LSattr_html_select_list');
*/
class LSattr_html_select_box extends LSattr_html_select_list {
var $LSformElement_type = 'select_box';
var string $LSformElement_type = 'select_box';
}

View file

@ -42,16 +42,16 @@
*/
class LSattr_html_select_list extends LSattr_html{
var $LSformElement_type = 'select';
var string $LSformElement_type = 'select';
/**
* Ajoute l'attribut au formualaire passer en paramètre
*
* @param[in] &$form LSform Le formulaire
* @param[in] $idForm L'identifiant du formulaire
* @param[in] $data Valeur du champs du formulaire
* @param LSform &$form Le formulaire
* @param string $idForm L'identifiant du formulaire
* @param array|string|null $data Valeur du champs du formulaire
*
* @retval LSformElement L'element du formulaire ajouté
* @return LSformElement L'element du formulaire ajouté
*/
public function addToForm (&$form,$idForm,$data=NULL) {
$possible_values=$this -> getPossibleValues();
@ -70,7 +70,7 @@ class LSattr_html_select_list extends LSattr_html{
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array Associative array with possible values as key and corresponding
* @return array Associative array with possible values as key and corresponding
* translated label as value.
*/
protected function getPossibleValues() {
@ -84,13 +84,13 @@ class LSattr_html_select_list extends LSattr_html{
/**
* Return array of possible values with translated labels (if enabled)
*
* @param[in] $options Attribute HTML options (optional)
* @param[in] $name Attribute name (optional)
* @param[in] &$ldapObject Related LSldapObject (optional)
* @param array|false $options Attribute HTML options (optional)
* @param string|false $name Attribute name (optional)
* @param LSldapObject|false &$ldapObject Related LSldapObject (optional)
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array Associative array with possible values as key and corresponding
* @return array Associative array with possible values as key and corresponding
* translated label as value.
*/
public static function _getPossibleValues($options=false, $name=false, &$ldapObject=false) {
@ -152,7 +152,7 @@ class LSattr_html_select_list extends LSattr_html{
* As array_merge PHP function, this function merge arrays but
* this method permit to preverve key even if it's numeric key.
*
* @retval array Merged array
* @return array Merged array
**/
protected static function _array_merge() {
$ret=array();
@ -167,10 +167,10 @@ class LSattr_html_select_list extends LSattr_html{
/**
* Apply sort feature on possible values if this feature is enabled
*
* @param[in] &$retInfos array Possible values array reference to sort
* @param[in] $options array|false Attribute HTML options
* @param array &$retInfos Possible values array reference to sort
* @param array|false $options Attribute HTML options
*
* @retval void
* @return void
**/
public static function _sort(&$retInfos, $options) {
if (!isset($options['sort']) || $options['sort']) {
@ -186,10 +186,10 @@ class LSattr_html_select_list extends LSattr_html{
/**
* Function use with uasort to sort two values in ASC order
*
* @param[in] $va string One value
* @param[in] $vb string One value
* @param string $va One value
* @param string $va One value
*
* @retval int Value for uasort
* @return int Value for uasort
**/
protected static function _sortTwoValuesAsc(&$va,&$vb) {
if (is_array($va)) {
@ -216,10 +216,10 @@ class LSattr_html_select_list extends LSattr_html{
/**
* Function use with uasort to sort two values in DESC order
*
* @param[in] $va string One value
* @param[in] $vb string One value
* @param string $va One value
* @param string $va One value
*
* @retval int Value for uasort
* @return int Value for uasort
**/
protected static function _sortTwoValuesDesc(&$va,&$vb) {
return (-1 * static :: _sortTwoValuesAsc($va,$vb));
@ -229,24 +229,25 @@ class LSattr_html_select_list extends LSattr_html{
/**
* Retourne un tableau des valeurs possibles d'un type d'objet
*
* @param[in] $conf OTHER_OBJECT configuration array
* @param[in] $options array|false Attribute HTML options
* @param[in] $name Attribute name
* @param array $conf OTHER_OBJECT configuration array
* @param array|false $options Attribute HTML options
* @param string $name Attribute name
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array Tableau associatif des valeurs possible de la liste avec en clé
* la valeur des balises option et en valeur ce qui sera affiché.
* @return array|false Tableau associatif des valeurs possible de la liste avec en clé
* la valeur des balises option et en valeur ce qui sera affiché.
* False en cas d'erreur.
*/
protected static function getLSobjectPossibleValues($conf, $options, $name) {
$retInfos = array();
if ((!isset($conf['object_type'])) || ((!isset($conf['value_attribute'])) && (!isset($conf['values_attribute'])))) {
LSerror :: addErrorCode('LSattr_html_select_list_01',$name);
return;
return false;
}
if (!LSsession :: loadLSclass('LSsearch')) {
return;
return false;
}
$param=array(
@ -299,14 +300,14 @@ class LSattr_html_select_list extends LSattr_html{
/**
* Retourne un tableau des valeurs possibles d'un autre attribut
*
* @param[in] $attr OTHER_ATTRIBUTE configuration value
* @param[in] $options array|false Attribute HTML options
* @param[in] $name Attribute name
* @param[in] $LSldapObject LSldapObject reference
* @param string|array $attr OTHER_ATTRIBUTE configuration value
* @param array|false $options Attribute HTML options
* @param string $name Attribute name
* @param LSldapObject &$ldapObject The related LSldapObject reference
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array Tableau associatif des valeurs possible de la liste avec en clé
* @return array Tableau associatif des valeurs possible de la liste avec en clé
* la valeur des balises option et en valeur ce qui sera affiché.
*/
protected static function getLSattributePossibleValues($attr, $options ,$name ,&$ldapObject) {
@ -381,13 +382,13 @@ class LSattr_html_select_list extends LSattr_html{
* Return array of possible values with translated labels (if enabled)
* by using specify callable
*
* @param[in] $options Attribute HTML options
* @param[in] $name Attribute name
* @param[in] &$ldapObject Related LSldapObject
* @param array $options Attribute HTML options
* @param string $name Attribute name
* @param LSldapObject &$ldapObject Related LSldapObject
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array|false Associative array with possible values as key and corresponding
* @return array|false Associative array with possible values as key and corresponding
* translated label as value, or false in case of error.
*/
public static function getCallablePossibleValues($options, $name, &$ldapObject) {

View file

@ -27,24 +27,30 @@
*/
class LSattr_html_select_object extends LSattr_html{
var $LSformElement_type = 'select_object';
var $unrecognizedValues=false;
var string $LSformElement_type = 'select_object';
/**
* Array of unrecognized values
* @see LSattr_html_select_object::getFormValues()
* @var array<int,string>
*/
var array $unrecognizedValues = array();
/**
* Ajoute l'attribut au formualaire passer en paramètre
*
* @param[in] &$form LSform Le formulaire
* @param[in] $idForm L'identifiant du formulaire
* @param[in] $data Valeur du champs du formulaire
* @param LSform &$form Le formulaire
* @param string $idForm L'identifiant du formulaire
* @param array|string|null $data Valeur du champs du formulaire
*
* @retval LSformElement L'element du formulaire ajouté
* @return LSformElement|false L'element du formulaire ajouté, ou false
*/
public function addToForm (&$form,$idForm,$data=NULL) {
$this -> config['attrObject'] = $this;
$element=$form -> addElement($this -> LSformElement_type, $this -> name, $this -> getLabel(), $this -> config, $this);
if(!$element) {
LSerror :: addErrorCode('LSform_06',$this -> name);
return;
return false;
}
if ($data) {
$values = $this -> getFormValues(ensureIsArray($data));
@ -61,9 +67,9 @@ class LSattr_html_select_object extends LSattr_html{
* Récupère un array du type array('DNs' => 'displayName') à partir d'une
* liste de DNs.
*
* @param[in] $data mixed La valeur de l'attribut (liste de DNs)
* @param mixed $data The attribute value (liste de DNs)
*
* @retval mixed La valeur formatée de l'attribut (array('DNs' => 'displayName'))
* @return array La valeur formatée de l'attribut (array('DNs' => 'displayName'))
**/
public function refreshForm($data,$fromDNs=false) {
return $this -> getFormValues($data,$fromDNs);
@ -73,13 +79,13 @@ class LSattr_html_select_object extends LSattr_html{
* Check and return selectable objects configuration and eventually instanciate
* it if &instanciate
*
* @param[in] boolean &$instanciated_objects reference If this reference point to an array, each valid
* @param boolean &$instanciated_objects reference If this reference point to an array, each valid
* selectable object type will be instanciated in this
* array with object type name as key.
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array|false Selectable objects configuration or False on error.
* @return array|false Selectable objects configuration or False on error.
*/
public function getSelectableObjectsConfig(&$instanciated_objects) {
$confs = $this -> getConfig('html_options.selectable_object');
@ -166,14 +172,14 @@ class LSattr_html_select_object extends LSattr_html{
* Return an array of selected objects with DN as key and as value, an array with object name (key name)
* and type (key object_type).
*
* @param[in] mixed $values array|null Array of the input values ()
* @param[in] boolean $fromDNs boolean If true, considered provided values as DNs (default: false)
* @param[in] boolean $retrieveAttrValues boolean If true, attribute values will be returned instead
* @param mixed $values array|null Array of the input values ()
* @param boolean $fromDNs boolean If true, considered provided values as DNs (default: false)
* @param boolean $retrieveAttrValues boolean If true, attribute values will be returned instead
* of selected objects info (default: false)
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array|false Array of selected objects with DN as key and object info as value or array
* @return array|false Array of selected objects with DN as key and object info as value or array
* of attribute values if $retrieveAttrValues==true or False on error.
*/
public function getFormValues($values=NULL, $fromDNs=false, $retrieveAttrValues=false) {
@ -343,11 +349,11 @@ class LSattr_html_select_object extends LSattr_html{
/**
* Return array of atttribute values form array of form values
*
* @param[in] mixed Array of form values
* @param mixed $values Array of form values
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array|false Array of attribute values or False on error.
* @return array|false Array of attribute values or False on error.
*/
public function getValuesFromFormValues($values=NULL) {
if (is_array($values)) {
@ -362,8 +368,8 @@ class LSattr_html_select_object extends LSattr_html{
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array Tableau associatif des objects selectionnés avec en clé
* le DN et en valeur ce qui sera affiché.
* @return array|false Tableau associatif des objects selectionnés avec en clé
* le DN et en valeur ce qui sera affiché. False en cas d'erreur.
*/
public function getValuesFromLSselect() {
$LSselect_id = $this -> getLSselectId();
@ -383,9 +389,9 @@ class LSattr_html_select_object extends LSattr_html{
/**
* Return the values to be displayed in the LSform
*
* @param[in] $data The values of attribute
* @param array $data The values of attribute
*
* @retval array The values to be displayed in the LSform
* @return array The values to be displayed in the LSform
**/
public function getFormVal($data) {
return $data;

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_ssh_key extends LSattr_html {
var $LSformElement_type = 'ssh_key';
var string $LSformElement_type = 'ssh_key';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannActivite extends LSattr_html {
var $LSformElement_type = 'supannActivite';
var string $LSformElement_type = 'supannActivite';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannAdressePostalePrivee extends LSattr_html {
var $LSformElement_type = 'supannAdressePostalePrivee';
var string $LSformElement_type = 'supannAdressePostalePrivee';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannCodePopulation extends LSattr_html {
var $LSformElement_type = 'supannCodePopulation';
var string $LSformElement_type = 'supannCodePopulation';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEmpCorps extends LSattr_html {
var $LSformElement_type = 'supannEmpCorps';
var string $LSformElement_type = 'supannEmpCorps';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEmpProfil extends LSattr_html {
var $LSformElement_type = 'supannEmpProfil';
var string $LSformElement_type = 'supannEmpProfil';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEtablissement extends LSattr_html {
var $LSformElement_type = 'supannEtablissement';
var string $LSformElement_type = 'supannEtablissement';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEtuDiplome extends LSattr_html {
var $LSformElement_type = 'supannEtuDiplome';
var string $LSformElement_type = 'supannEtuDiplome';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEtuElementPedagogique extends LSattr_html {
var $LSformElement_type = 'supannEtuElementPedagogique';
var string $LSformElement_type = 'supannEtuElementPedagogique';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEtuEtape extends LSattr_html {
var $LSformElement_type = 'supannEtuEtape';
var string $LSformElement_type = 'supannEtuEtape';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEtuInscription extends LSattr_html {
var $LSformElement_type = 'supannEtuInscription';
var string $LSformElement_type = 'supannEtuInscription';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEtuRegimeInscription extends LSattr_html {
var $LSformElement_type = 'supannEtuRegimeInscription';
var string $LSformElement_type = 'supannEtuRegimeInscription';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEtuSecteurDisciplinaire extends LSattr_html {
var $LSformElement_type = 'supannEtuSecteurDisciplinaire';
var string $LSformElement_type = 'supannEtuSecteurDisciplinaire';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannEtuTypeDiplome extends LSattr_html {
var $LSformElement_type = 'supannEtuTypeDiplome';
var string $LSformElement_type = 'supannEtuTypeDiplome';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannExtProfil extends LSattr_html {
var $LSformElement_type = 'supannExtProfil';
var string $LSformElement_type = 'supannExtProfil';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannLabeledValue extends LSattr_html {
var $LSformElement_type = 'supannLabeledValue';
var string $LSformElement_type = 'supannLabeledValue';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannMailPrive extends LSattr_html {
var $LSformElement_type = 'supannMailPrive';
var string $LSformElement_type = 'supannMailPrive';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannRessourceEtat extends LSattr_html {
var $LSformElement_type = 'supannRessourceEtat';
var string $LSformElement_type = 'supannRessourceEtat';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannRessourceEtatDate extends LSattr_html {
var $LSformElement_type = 'supannRessourceEtatDate';
var string $LSformElement_type = 'supannRessourceEtatDate';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannRoleEntite extends LSattr_html {
var $LSformElement_type = 'supannRoleEntite';
var string $LSformElement_type = 'supannRoleEntite';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannRoleGenerique extends LSattr_html {
var $LSformElement_type = 'supannRoleGenerique';
var string $LSformElement_type = 'supannRoleGenerique';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannTelephonePrive extends LSattr_html {
var $LSformElement_type = 'supannTelephonePrive';
var string $LSformElement_type = 'supannTelephonePrive';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_supannTypeEntite extends LSattr_html {
var $LSformElement_type = 'supannTypeEntite';
var string $LSformElement_type = 'supannTypeEntite';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_tel extends LSattr_html {
var $LSformElement_type = 'tel';
var string $LSformElement_type = 'tel';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_text extends LSattr_html {
var $LSformElement_type = 'text';
var string $LSformElement_type = 'text';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_textarea extends LSattr_html {
var $LSformElement_type = 'textarea';
var string $LSformElement_type = 'textarea';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_url extends LSattr_html {
var $LSformElement_type = 'url';
var string $LSformElement_type = 'url';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_valueWithUnit extends LSattr_html {
var $LSformElement_type = 'valueWithUnit';
var string $LSformElement_type = 'valueWithUnit';
}

View file

@ -29,6 +29,6 @@ LSsession :: loadLSclass('LSattr_html_textarea');
*/
class LSattr_html_wysiwyg extends LSattr_html_textarea {
var $LSformElement_type = 'wysiwyg';
var string $LSformElement_type = 'wysiwyg';
}

View file

@ -27,6 +27,6 @@
*/
class LSattr_html_xmpp extends LSattr_html {
var $LSformElement_type = 'xmpp';
var string $LSformElement_type = 'xmpp';
}

View file

@ -23,15 +23,29 @@
LSsession :: loadLSclass('LSlog_staticLoggerClass');
/**
* Base d'un type d'attribut Ldap
* Basic implementatin of a LDAP attribute type
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSattr_ldap extends LSlog_staticLoggerClass {
var $name;
var $config;
var $attribute;
/**
* LDAP attribute name
* @var string
*/
var string $name;
/**
* Attribute configuration (LSobjects.<type>.attrs.<attr_name>)
* @var array<string,mixed>
*/
var array $config;
/**
* The reference of the parent LSattribute object
* @var LSattribute
*/
var LSattribute $attribute;
/**
* Constructeur
@ -40,45 +54,42 @@ class LSattr_ldap extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $name string Nom de l'attribut ldap
* @param[in] $config array Configuration de l'objet
* @param[in] &$attribute LSattribute L'objet LSattribut parent
*
* @retval boolean Retourne true.
* @param string $name Nom de l'attribut ldap
* @param array $config Configuration de l'objet
* @param LSattribute &$attribute L'objet LSattribut parent
*/
public function __construct($name, $config, &$attribute) {
$this -> name = $name;
$this -> config = $config;
$this -> attribute =& $attribute;
return true;
}
/**
* Allow conversion of LSattr_ldap to string
*
* @retval string The string representation of the LSattr_ldap
* @return string The string representation of the LSattr_ldap
*/
public function __toString() {
return "<".get_class($this)." ".$this -> name.">";
}
/**
* Retourne la valeur de l'attribut après traitement lié à son type ldap
* Return the update value of the attribute after handling it acording to its LDAP type
*
* @param[in] $data mixed La valeur de l'attribut
* @param mixed $data The attribute value
*
* @retval mixed La valeur traitée de l'attribut
* @return mixed The processed attribute value
*/
public function getUpdateData($data) {
return ensureIsArray($data);
}
/**
* Retourne la valeur d'affichage de l'attribut après traitement lié à son type ldap
* Return the display value of the attribute after handling it acording to its LDAP type
*
* @param[in] $data mixed La valeur de l'attribut
* @param mixed $data The attribute value
*
* @retval mixed La valeur d'affichage de l'attribut
* @return mixed The display value of the attribute
*/
public function getDisplayValue($data) {
return ensureIsArray($data);
@ -88,26 +99,26 @@ class LSattr_ldap extends LSlog_staticLoggerClass {
* Retourne vrai si la valeur passé en paramètre n'était pas la même que la
* valeur passer au formulaire
*
* @param[in] $data mixed La valeur a tester
* @param mixed $data La valeur a tester
*
* @retval boolean True uniquement si la valeur passer en paramètre différe de l'actuelle
* @return boolean True uniquement si la valeur passer en paramètre différe de l'actuelle
*/
public function isUpdated($data) {
$data = $this -> getUpdateData($data);
if ($this -> attribute -> data != $data) {
return true;
}
return;
return false;
}
/**
* 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 string $param The configuration parameter
* @param mixed $default The default value (default : null)
* @param string $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
* @return mixed The configuration parameter value or default value if not set
**/
public function getConfig($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> config);

View file

@ -28,24 +28,24 @@ class LSattr_ldap_boolean extends LSattr_ldap {
/**
* Return display value of attribute after treatment related to LDAP type
*
* @param[in] $data mixed Attribute data
* @param mixed $data Attribute data
*
* @retval mixed Attribute display value
* @return string|null Attribute display value
**/
public function getDisplayValue($data) {
if ($this -> isTrue($data))
return 'yes';
if ($this -> isFalse($data))
return 'no';
return;
return null;
}
/**
* Return attribute value after treatment related to LDAP type
*
* @param[in] $data mixed Attribute data
* @param mixed $data Attribute data
*
* @retval mixed Attribute data
* @return array Attribute data
**/
public function getUpdateData($data) {
$data = ensureIsArray($data);
@ -63,9 +63,9 @@ class LSattr_ldap_boolean extends LSattr_ldap {
/**
* Check if a value corresponding to True
*
* @param[in] $data Attribute data
* @param array|string|null $data Attribute data
*
* @retval boolean True or False
* @return boolean True or False
**/
public function isTrue($data) {
$data = ensureIsArray($data);
@ -78,9 +78,9 @@ class LSattr_ldap_boolean extends LSattr_ldap {
/**
* Check if a value corresponding to False
*
* @param[in] $data Attribute data
* @param array|string|null $data Attribute data
*
* @retval boolean True or False
* @return boolean True or False
**/
public function isFalse($data) {
$data = ensureIsArray($data);
@ -93,7 +93,7 @@ class LSattr_ldap_boolean extends LSattr_ldap {
/**
* Return True value
*
* @retval string The True value
* @return string The True value
**/
public function getTrue() {
return $this -> getConfig('ldap_options.true_value', 'TRUE', 'string');
@ -102,7 +102,7 @@ class LSattr_ldap_boolean extends LSattr_ldap {
/**
* Return False value
*
* @retval string The False value
* @return string The False value
**/
public function getFalse() {
return $this -> getConfig('ldap_options.false_value', 'FALSE', 'string');

View file

@ -21,20 +21,20 @@
******************************************************************************/
/**
* Type d'attribut Ldap compositeValueToJSON
* Convertit les attributes composite du format suivant :
* LDAP attribute type compositeValueToJSON
* Convert the composite attributes in the following format:
* [key1=value1][key2=value2]..
* Au format JSON (utilisable par le LSformElement_jsonCompositeAttribute ) :
* To JSON format (usable with LSattr_jsonCompositeAttribute):
* {"key1":"value1","key2":"value2"}
*/
class LSattr_ldap_compositeValueToJSON extends LSattr_ldap {
/**
* Retourne la valeur d'affichage de l'attribut après traitement lié à son type ldap
* Return the display value of the attribute after handling it acording to its LDAP type
*
* @param[in] $data mixed La valeur de l'attribut
* @param mixed $data The attribute value
*
* @retval mixed La valeur d'affichage de l'attribut
* @return array The display value of the attribute
*/
public function getDisplayValue($data) {
$ret = array();
@ -44,11 +44,11 @@ class LSattr_ldap_compositeValueToJSON extends LSattr_ldap {
}
/**
* Retourne la valeur de l'attribut après traitement lié à son type ldap
* Return the update value of the attribute after handling it acording to its LDAP type
*
* @param[in] $data mixed La valeur de l'attribut
* @param mixed $data The attribute value
*
* @retval mixed La valeur traitée de l'attribut
* @return array The processed attribute value
*/
public function getUpdateData($data) {
$ret = array();
@ -57,6 +57,11 @@ class LSattr_ldap_compositeValueToJSON extends LSattr_ldap {
return $ret;
}
/**
* Parse a value
* @param string $value The value to parse
* @return array|null The parse value as array, or null in case of error
*/
public static function parseValue($value) {
if (preg_match_all('/\[([^=]*)=([^\]]*)\]/', $value, $matches)) {
$parseValue = array();
@ -65,9 +70,14 @@ class LSattr_ldap_compositeValueToJSON extends LSattr_ldap {
}
return $parseValue;
}
return;
return null;
}
/**
* Compute a composite value
* @param array $value The value to encode
* @return string|false The computed composite value as string, or False in case of error
*/
public static function encodeValue($value) {
if (is_array($value)) {
$ret = "";

View file

@ -21,17 +21,17 @@
******************************************************************************/
/**
* Type d'attribut Ldap date
* LDAP attribute type date
*
*/
class LSattr_ldap_date extends LSattr_ldap {
/**
* Retourne la valeur d'affichage de l'attribut après traitement lié à son type ldap
* Return the display value of the attribute after handling it acording to its LDAP type
*
* @param[in] $data mixed La valeur de l'attribut
* @param mixed $data The attribute value
*
* @retval mixed La valeur d'affichage de l'attribut
* @return array The display value of the attribute
*/
public function getDisplayValue($data) {
$data = ensureIsArray($data);
@ -49,11 +49,11 @@ class LSattr_ldap_date extends LSattr_ldap {
}
/**
* Retourne la valeur de l'attribut après traitement lié à son type ldap
* Return the update value of the attribute after handling it acording to its LDAP type
*
* @param[in] $data mixed La valeur de l'attribut
* @param mixed $data The attribute value
*
* @retval mixed La valeur traitée de l'attribut
* @return array The processed attribute value
*/
public function getUpdateData($data) {
$data = ensureIsArray($data);
@ -76,9 +76,9 @@ class LSattr_ldap_date extends LSattr_ldap {
}
/**
* Retourne le format de stockage de la date
* Return the storage date format
*
* @retval string Le format de la date
* @return string The storage date format
**/
public function getFormat() {
return $this -> getConfig('ldap_options.format', 'YmdHisO');

View file

@ -21,7 +21,7 @@
******************************************************************************/
/**
* Type d'attribut Ldap image
* LDAP attribute type image
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/

View file

@ -31,9 +31,9 @@ class LSattr_ldap_naiveDate extends LSattr_ldap {
/**
* Return the display value of the attribute after handling is LDAP type
*
* @param[in] $data mixed The LDAP attribute value
* @param mixed $data The LDAP attribute value
*
* @retval mixed The display value ot the attribute
* @return array The display value ot the attribute
*/
public function getDisplayValue($data) {
$retval = array();
@ -56,9 +56,9 @@ class LSattr_ldap_naiveDate extends LSattr_ldap {
/**
* Return the value of the LDAP attribute after handling is LDAP type
*
* @param[in] $data mixed The value of the attribute
* @param mixed $data The value of the attribute
*
* @retval mixed The LDAP value of the attribute
* @return array The LDAP value of the attribute
*/
public function getUpdateData($data) {
$retval = array();
@ -72,10 +72,10 @@ class LSattr_ldap_naiveDate extends LSattr_ldap {
/**
* Return the storage format of the date (as accept by strptime()/strftime())
*
* @retval string the storage format of the date
* @return string the storage format of the date
**/
public function getFormat() {
return $this -> getConfig('ldap_options.format', "%Y%m%d%H%M%SZ");
return $this -> getConfig('ldap_options.format', "%Y%m%d%H%M%SZ", 'string');
}
}

View file

@ -21,7 +21,7 @@
******************************************************************************/
/**
* Type d'attribut Ldap numeric
* LDAP attribute type numeric
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/

View file

@ -26,14 +26,20 @@
*/
class LSattr_ldap_password extends LSattr_ldap {
var $clearPassword = NULL;
/**
* Cache of the new password in raw format (=clear, not hashed)
* @see LSattr_ldap_password::getUpdateData()
* @see LSattr_ldap_password::getClearPassword()
* @var string
*/
private string $clearPassword = '';
/**
* Return the display value of this attribute
*
* @param[in] $data mixed The value of this attribute
* @param mixed $data The value of this attribute
*
* @retval mixed The display value of this attribute
* @return mixed The display value of this attribute
*/
public function getDisplayValue($data) {
if ($this -> getConfig('ldap_options.displayClearValue', false, 'bool')) {
@ -56,9 +62,9 @@ class LSattr_ldap_password extends LSattr_ldap {
* Note : Password encoding was strongly inspired of the project phpLdapAdmin.
* URL : http://phpldapadmin.sourceforge.net/
*
* @param[in] $data mixed The attribute value
* @param mixed $data The attribute value
*
* @retval mixed The value of this attribute to be stocked
* @return mixed The value of this attribute to be stocked
*/
public function getUpdateData($data) {
$ret = array();
@ -84,9 +90,11 @@ class LSattr_ldap_password extends LSattr_ldap {
* Note : Password encoding was strongly inspired of the project phpLdapAdmin.
* URL : http://phpldapadmin.sourceforge.net/
*
* @param[in] $clearPassword string The clear password
* @param string $clearPassword The clear password
* @param string|null $encode The encoding type
* @param callable $encode_function The encoding callable
*
* @retval strinf The encode password
* @return string The encode password
*/
public function encodePassword($clearPassword, $encode=null, $encode_function=null, $salt=null) {
if (is_null($encode))
@ -238,6 +246,12 @@ class LSattr_ldap_password extends LSattr_ldap {
return $clearPassword;
}
/**
* Verify if the clear specified password match with specified hashed password(s)
* @param string $clearPassword The clear password to check
* @param string|array|null $hashedPassword The hashed password(s) (optional, default: check againt attibute values)
* @return bool True if clear password matched, False otherwise
*/
function verify($clearPassword, $hashedPassword=null) {
// If $hashedPassword is not provided, use attribute values
if (is_null($hashedPassword))
@ -343,9 +357,9 @@ class LSattr_ldap_password extends LSattr_ldap {
/**
* Return salt (random string)
*
* @param[in] integer Number of caracters in this salt
* @param integer $length Number of caracters in this salt
*
* @retval string A salt
* @return string A salt
*/
public static function getSalt($length=8) {
$pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
@ -360,7 +374,7 @@ class LSattr_ldap_password extends LSattr_ldap {
/**
* Return the password in clear text
*
* @retval string The password in clear text
* @return string The password in clear text
*/
public function getClearPassword() {
return $this -> clearPassword;

View file

@ -21,17 +21,17 @@
******************************************************************************/
/**
* Type d'attribut Ldap postaladdress
* RFC4519 : les retours a la ligne sont remplace par des '$'
* LDAP attribute type postaladdress
* See RFC4519: Line returns are replaced with '$'.
*/
class LSattr_ldap_postaladdress extends LSattr_ldap {
/**
* Retourne la valeur d'affichage de l'attribut après traitement lié à son type ldap
* Return the display value of the attribute after handling it acording to its LDAP type
*
* @param[in] $data mixed La valeur de l'attribut
* @param mixed $data The attribute value
*
* @retval mixed La valeur d'affichage de l'attribut
* @return mixed The display value of the attribute
*/
public function getDisplayValue($data) {
$ret = array();
@ -41,11 +41,11 @@ class LSattr_ldap_postaladdress extends LSattr_ldap {
}
/**
* Retourne la valeur de l'attribut après traitement lié à son type ldap
* Return the update value of the attribute after handling it acording to its LDAP type
*
* @param[in] $data mixed La valeur de l'attribut
* @param mixed $data The attribute value
*
* @retval mixed La valeur traitée de l'attribut
* @return mixed The processed attribute value
*/
public function getUpdateData($data) {
$ret = array();

View file

@ -36,9 +36,9 @@ class LSattr_ldap_pwdHistory extends LSattr_ldap {
/**
* Return the values as JSON encoded string
*
* @param[in] $data mixed LDAP attribute value
* @param mixed $data LDAP attribute value
*
* @retval mixed Array of JSON encoded string
* @return mixed Array of JSON encoded string
*/
public function getDisplayValue($data) {
$ret = array();
@ -50,9 +50,9 @@ class LSattr_ldap_pwdHistory extends LSattr_ldap {
/**
* Return the values for saving
*
* @param[in] $data mixed Array of timestamp
* @param mixed $data Array of timestamp
*
* @retval mixed LDAP attribute values
* @return mixed LDAP attribute values
*/
public function getUpdateData($data) {
$ret = array();
@ -61,11 +61,18 @@ class LSattr_ldap_pwdHistory extends LSattr_ldap {
return $ret;
}
/**
* Parse value
*
* @param array|string|null $value The value to parse
*
* @return array|false Array of parsed value info as array, or false
**/
public function parseValue($value) {
$parts = explode('#', $value);
if (!is_array($parts) || count($parts) != 4) {
self :: log_warning($this."->parseValue($value): Invalid value (parts count != 4).");
return;
return false;
}
$datetime = date_create_from_format('YmdHisO', $parts[0]);
if ($datetime instanceof DateTime) {
@ -84,15 +91,20 @@ class LSattr_ldap_pwdHistory extends LSattr_ldap {
);
}
/**
* Encode a value
* @param array $value The value to encode
* @return string|false The encoded value, or false
*/
public function encodeValue($value) {
if (!is_array($value)) {
self :: log_warning($this."->encodeValue($value): Provided value is not an array.");
return;
return false;
}
$datetime = date_create_from_format('YmdHisO', $value['time']);
if (!is_a($datetime, 'DateTime')) {
self :: log_warning($this."->encodeValue($value): Fail to create DateTime object from timestamp '".varDump($value['time'])."'.");
return;
self :: log_warning($this."->encodeValue(".varDump($value)."): Fail to create DateTime object from timestamp '".varDump($value['time'])."'.");
return false;
}
$datetime -> setTimezone('UTC');
$datetime_string = $datetime -> format('YmdHisO');
@ -111,7 +123,7 @@ class LSattr_ldap_pwdHistory extends LSattr_ldap {
/**
* Return date format
*
* @retval string The date format (as accept by Datetime :: format() and date_create_from_format())
* @return string The date format (as accept by Datetime :: format() and date_create_from_format())
**/
public function getFormat() {
return $this -> getConfig('ldap_options.date_format', 'Y/m/d H:i:s');

View file

@ -28,9 +28,9 @@ class LSattr_ldap_sambaAcctFlags extends LSattr_ldap {
/**
* Return display value of attribute after treatment related to LDAP type
*
* @param[in] $data mixed Attribute data
* @param mixed $data Attribute data
*
* @retval mixed Attribute display value
* @return mixed Attribute display value
**/
public function getDisplayValue($data) {
$values = self :: parse_flags($data);
@ -42,9 +42,9 @@ class LSattr_ldap_sambaAcctFlags extends LSattr_ldap {
/**
* Return attribute value after treatment related to LDAP type
*
* @param[in] $data mixed Attribute data
* @param mixed $data Attribute data
*
* @retval mixed Attribute data
* @return mixed Attribute data
**/
public function getUpdateData($data) {
$values = self :: format_flags($data);
@ -56,9 +56,9 @@ class LSattr_ldap_sambaAcctFlags extends LSattr_ldap {
/**
* Parse flags
*
* @param[in] $data Attribute data
* @param array|string|null $data Attribute data
*
* @retval array Array of enabled flags
* @return array|false Array of enabled flags, or false
**/
public static function parse_flags($data) {
if (!$data)
@ -66,7 +66,7 @@ class LSattr_ldap_sambaAcctFlags extends LSattr_ldap {
$data = ensureIsArray($data);
if (count($data) > 1) {
LSerror :: addErrorCode('LSattr_ldap_sambaAcctFlags_01');
return;
return false;
}
$value = $data[0];
$preg_pattern = "/^\[([ ";
@ -78,7 +78,7 @@ class LSattr_ldap_sambaAcctFlags extends LSattr_ldap {
if (!preg_match($preg_pattern, $value, $m)) {
self :: log_error("parse($value): fail to parse value.");
LSerror :: addErrorCode('LSattr_ldap_sambaAcctFlags_02');
return;
return false;
}
$flags = array();
foreach(str_split($m[1]) as $flag) {
@ -94,16 +94,16 @@ class LSattr_ldap_sambaAcctFlags extends LSattr_ldap {
/**
* Format flags as one LDAP attribute value
*
* @param[in] $flags array of string Flags
* @param array $flags of string Flags
*
* @retval array Array of LDAP attribute value
* @return array|false Array of LDAP attribute value, or false
**/
public static function format_flags($flags) {
$flags = ensureIsArray($flags);
foreach($flags as $flag) {
if (!self :: check_flag($flag)) {
LSerror :: addErrorCode('LSattr_ldap_sambaAcctFlags_03', $flag);
return;
return false;
}
}
// Add some space if need
@ -117,9 +117,9 @@ class LSattr_ldap_sambaAcctFlags extends LSattr_ldap {
/**
* Check if a flag is valid
*
* @param[in] $flag string The flag
* @param string $flag The flag
*
* @retval boolean True if flag is valid, False otherwise
* @return boolean True if flag is valid, False otherwise
**/
public static function check_flag($flag) {
foreach(self :: get_available_flags() as $group_label => $flags)

View file

@ -21,7 +21,7 @@
******************************************************************************/
/**
* LDAP Attribute shadowExpire
* LDAP attribute type shadowExpire
*
* This class permit to manage shadowExpire attribute as a timestamp, and consequently
* permit to use LSattr_html_date to manage it value in the interface.
@ -31,9 +31,9 @@ class LSattr_ldap_shadowExpire extends LSattr_ldap {
/**
* Return the values as timestamps
*
* @param[in] $data mixed LDAP attribute value
* @param mixed $data LDAP attribute value
*
* @retval mixed Array of timestamp
* @return mixed Array of timestamp
*/
public function getDisplayValue($data) {
$ret = array();
@ -45,9 +45,9 @@ class LSattr_ldap_shadowExpire extends LSattr_ldap {
/**
* Return the values for saving
*
* @param[in] $data mixed Array of timestamp
* @param mixed $data Array of timestamp
*
* @retval mixed LDAP attribute values
* @return mixed LDAP attribute values
*/
public function getUpdateData($data) {
$ret=array();

View file

@ -33,18 +33,93 @@ LSsession :: loadLSclass('LSattr_html');
*/
class LSattribute extends LSlog_staticLoggerClass {
var $name;
var $config;
var $ldapObject;
var $ldap;
var $html;
var $data;
/**
* Attribute name
* @var string
*/
var string $name;
/**
* Attribute configuration (LSobjects.<type>.attrs.<attr_name>)
* @var array<string,mixed>
*/
var array $config;
/**
* The reference of the parent LSldapObject object
* @var LSldapObject
*/
var LSldapObject $ldapObject;
/**
* The implemented LSattr_ldap object
* @see LSattribute::__construct()
* @var LSattr_ldap
*/
var LSattr_ldap $ldap;
/**
* The implemented LSattr_ldap object
* @see LSattribute::__construct()
* @var LSattr_html
*/
var LSattr_html $html;
/**
* Attribute data
* @var array
*/
var array $data = array();
/**
* Attribute updated data
* @see LSattribute::setUpdateData()
* @see LSattribute::getUpdateData()
* @see LSattribute::isUpdate()
* @see LSattribute::reloadData()
* @see LSattribute::generateValue()
* @var array|false
*/
var $updateData=false;
var $is_validate=false;
var $_finalUpdateData=false;
var $_myRights=NULL;
var $_events=array();
var $_objectEvents=array();
/**
* Telltale of the validation state of the new attibute data
* @see LSattribute::validate()
* @see LSattribute::isValidate()
* @see LSattribute::reloadData()
* @var bool
*/
var bool $is_validate=false;
/**
* Cache of the validated new attribute data
* @see LSattribute::getUpdateData()
* @var array<string>
*/
var array $_finalUpdateData=array();
/**
* Cache of the current connected user right on this attribute
* @see LSattribute::myRights()
* @var null|string
*/
var $_myRights=null;
/**
* Object registered hooks on event
* @see LSattribute::addEvent()
* @see LSattribute::fireEvent()
* @var array<string,array>
*/
var array $_events=array();
/**
* Object registered hooks on event trigger object methods
* @see LSattribute::addObjectEvent()
* @see LSattribute::fireEvent()
* @var array<string,array>
*/
var array $_objectEvents=array();
/**
* Constructeur
@ -55,11 +130,11 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $name string Nom de l'attribut ldap
* @param[in] $config array Configuration de l'objet
* @param[in] &$ldapObject LSldapObject L'objet ldap parent
* @param string $name Nom de l'attribut ldap
* @param array $config Configuration de l'objet
* @param LSldapObject &$ldapObject L'objet ldap parent
*
* @retval boolean Retourne true si la création a réussi, false sinon.
* @return boolean Retourne true si la création a réussi, false sinon.
*/
public function __construct($name, $config, &$ldapObject) {
$this -> name = $name;
@ -82,13 +157,12 @@ class LSattribute extends LSlog_staticLoggerClass {
);
return;
}
return true;
}
/**
* Allow conversion of LSattribute to string
*
* @retval string The string representation of the LSattribute
* @return string The string representation of the LSattribute
*/
public function __toString() {
return strval($this -> ldapObject)." -> <LSattribute ".$this -> name.">";
@ -99,7 +173,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval string Le label de l'attribut
* @return string|false Le label de l'attribut, ou false
*
* @see LSattr_html::getLabel()
*/
@ -107,7 +181,7 @@ class LSattribute extends LSlog_staticLoggerClass {
public function getLabel() {
if (!$this -> html) {
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
return;
return false;
}
return $this -> html -> getLabel();
}
@ -117,7 +191,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true
* @return boolean true
*/
public function loadData($attr_data) {
$this -> data = ensureIsArray($attr_data);
@ -129,7 +203,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true
* @return boolean true
*/
public function reloadData($attr_data) {
$this -> data = ensureIsArray($attr_data);
@ -145,7 +219,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval mixed La valeur de l'attribut
* @return mixed La valeur de l'attribut
*/
public function getValue() {
if ($this -> isUpdate()) {
@ -161,7 +235,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval mixed La valeur originale de l'attribut
* @return mixed La valeur originale de l'attribut
*/
public function getOldValue() {
return $this -> data;
@ -170,16 +244,16 @@ class LSattribute extends LSlog_staticLoggerClass {
/**
* Return attribute's display value
*
* @param[in] $data mixed Custom attribute data (optional, default: current attribute data)
* @param string|false $data Custom attribute data (optional, default: current attribute data)
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval mixed The display value of the attribute
* @return mixed The display value of the attribute
*/
public function getDisplayValue($data=false) {
if (!$this -> ldap) {
LSerror :: addErrorCode('LSattribute_09',array('type' => 'ldap','name' => $this -> name));
return;
return false;
}
if ($data !== false) {
@ -201,7 +275,7 @@ class LSattribute extends LSlog_staticLoggerClass {
}
else {
LSerror :: addErrorCode('LSattribute_02', array('attr' => $this->name, 'func' => $func));
return;
return false;
}
}
return $result;
@ -217,12 +291,12 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] object $form Le formulaire dans lequel doit être ajouté l'attribut
* @param[in] string $idForm L'identifiant du formulaire
* @param[in] objet &$obj Objet utilisable pour la génération de la valeur de l'attribut
* @param[in] array $value valeur de l'élement
* @param object $form Le formulaire dans lequel doit être ajouté l'attribut
* @param string $idForm L'identifiant du formulaire
* @param object &$obj Objet utilisable pour la génération de la valeur de l'attribut
* @param string $idForm valeur de l'élement
*
* @retval boolean true si l'ajout a fonctionner ou qu'il n'est pas nécessaire, false sinon
* @return boolean true si l'ajout a fonctionner ou qu'il n'est pas nécessaire, false sinon
*/
public function addToForm(&$form,$idForm,&$obj=NULL,$value=NULL) {
$form_mode = $this -> getConfig("form.$idForm", false);
@ -261,7 +335,7 @@ class LSattribute extends LSlog_staticLoggerClass {
// Check rule
if(!is_empty($rule) && !$form -> isRuleRegistered($rule)) {
LSerror :: addErrorCode('LSattribute_03', array('attr' => $this->name, 'rule' => $rule));
return;
return false;
}
// Add rule to form
$form -> addRule($this -> name, $rule, (is_array($rule_options)?$rule_options:array()));
@ -277,7 +351,7 @@ class LSattribute extends LSlog_staticLoggerClass {
/**
* Récupération des droits de l'utilisateur sur l'attribut
*
* @retval string 'r'/'w'/'n' pour 'read'/'write'/'none'
* @return string 'r'/'w'/'n' pour 'read'/'write'/'none'
**/
private function myRights() {
// cache
@ -313,11 +387,11 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $form LSform The LSform object
* @param[in] $api_mode boolean True if it's a view in API mode (=all accessible attributes present,
* @param LSform &$form The LSform object
* @param boolean $api_mode True if it's a view in API mode (=all accessible attributes present,
* optional, default: false)
*
* @retval boolean True on success, False otherwise
* @return boolean True on success, False otherwise
*/
public function addToView(&$form, $api_mode=false) {
if ((!$api_mode && !$this -> getConfig('view', false, 'bool')) || ($this -> myRights() == 'n') )
@ -335,9 +409,9 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $form LSform The LSform object
* @param LSform &$form The LSform object
*
* @retval boolean True on success, False otherwise
* @return boolean True on success, False otherwise
*/
public function addToExport(&$form) {
if ($this -> myRights() == 'n')
@ -355,14 +429,14 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] object $form The LSform object
* @param LSform $form The LSform object
*
* @retval LSformElement|False LSformElement object on success, False otherwise
* @return LSformElement|False LSformElement object on success, False otherwise
*/
private function _addToForm(&$form, $idForm, &$obj=NULL, $data=NULL) {
if (!$this -> html) {
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
return;
return false;
}
if (is_null($data)) {
@ -377,7 +451,7 @@ class LSattribute extends LSlog_staticLoggerClass {
$element = $this -> html -> addToForm($form, $idForm, $data);
if(!$element instanceof LSformElement) {
LSerror :: addErrorCode('LSform_06',$this -> name);
return;
return false;
}
return $element;
}
@ -387,16 +461,16 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] object &$form LSform Le formulaire dans lequel doit être ajouté l'attribut
* @param[in] string $idForm L'identifiant du formulaire
* @param LSform $form LSform Le formulaire dans lequel doit être ajouté l'attribut
* @param string $idForm L'identifiant du formulaire
*
* @retval boolean true si la valeur a été rafraichie ou que ce n'est pas nécessaire, false sinon
* @return boolean true si la valeur a été rafraichie ou que ce n'est pas nécessaire, false sinon
*/
public function refreshForm(&$form,$idForm) {
if ($this -> getConfig("form.$idForm") && ($this -> myRights() != 'n')) {
if (!$this -> html) {
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
return;
return false;
}
$form_element = $form -> getElement($this -> name);
if ($form_element) {
@ -413,11 +487,11 @@ class LSattribute extends LSlog_staticLoggerClass {
/**
* Return the form display value
*
* @param[in] $data mixed Custom attribute data (optional, default: current attribute data)
* @param mixed $data Custom attribute data (optional, default: current attribute data)
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval string The form display value
* @return string The form display value
*/
public function getFormVal($data=null) {
if (is_null($data)) {
@ -431,9 +505,9 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] string $data Les données de mise à jour.
* @param mixed $data Les données de mise à jour.
*
* @retval void
* @return void
*/
public function setUpdateData($data) {
if($this -> ldap -> isUpdated($data)) {
@ -446,7 +520,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si l'attribut a été validé, false sinon
* @return boolean true si l'attribut a été validé, false sinon
*/
public function isValidate() {
return $this -> is_validate;
@ -457,7 +531,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval void
* @return void
*/
public function validate() {
$this -> is_validate=true;
@ -468,7 +542,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si l'attribut a été mis à jour, false sinon
* @return boolean true si l'attribut a été mis à jour, false sinon
*/
public function isUpdate() {
return ($this -> updateData===false)?false:true;
@ -479,7 +553,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si l'attribut est obligatoire, false sinon
* @return boolean true si l'attribut est obligatoire, false sinon
*/
public function isRequired() {
return $this -> getConfig('required', false, 'bool');
@ -490,7 +564,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si la valeur de l'attribut peut être générée, false sinon
* @return boolean true si la valeur de l'attribut peut être générée, false sinon
*/
public function canBeGenerated() {
$format = $this -> getConfig('generate_value_format', $this -> getConfig('default_value'));
@ -507,7 +581,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si la valeur à put être générée, false sinon
* @return boolean true si la valeur à put être générée, false sinon
*/
public function generateValue() {
$value = $this -> getConfig('default_value', false);
@ -524,7 +598,7 @@ class LSattribute extends LSlog_staticLoggerClass {
self :: log_debug($this."generateValue(): generated values = ".varDump($this -> updateData));
return true;
}
return;
return false;
}
/**
@ -533,14 +607,14 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval mixed La valeur de l'attribut pour son enregistrement dans l'annuaire
* @return mixed La valeur de l'attribut pour son enregistrement dans l'annuaire
*/
public function getUpdateData() {
if (!$this -> isUpdate()) {
return;
return null;
}
if ( $this -> _finalUpdateData ) {
return $this -> _finalUpdateData;
return $this -> _finalUpdateData;
}
$data=$this -> updateData;
if (isset($this -> config['onSave'])) {
@ -552,7 +626,7 @@ class LSattribute extends LSlog_staticLoggerClass {
}
else {
LSerror :: addErrorCode('LSattribute_05',array('attr' => $this->name,'func' => $func));
return;
return false;
}
}
}
@ -562,14 +636,14 @@ class LSattribute extends LSlog_staticLoggerClass {
}
else {
LSerror :: addErrorCode('LSattribute_05',array('attr' => $this->name,'func' => $this -> config['onSave']));
return;
return false;
}
}
}
else {
if (!$this -> ldap) {
LSerror :: addErrorCode('LSattribute_09',array('type' => 'ldap','name' => $this -> name));
return;
return false;
}
else {
$result = $this -> ldap -> getUpdateData($data);
@ -584,13 +658,13 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval mixed La configuration de validation de l'attribut
* @return array|null La configuration de validation de l'attribut
*/
public function getValidateConfig() {
if (isset($this -> config['validation'])) {
return $this -> config['validation'];
}
return;
return null;
}
/**
@ -598,7 +672,7 @@ class LSattribute extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval array les noms des attributs dépendants
* @return array les noms des attributs dépendants
*/
public function getDependsAttrs() {
return (isset($this -> config['dependAttrs'])?$this -> config['dependAttrs']:null);
@ -607,12 +681,12 @@ class LSattribute extends LSlog_staticLoggerClass {
/**
* Ajouter une action lors d'un événement
*
* @param[in] $event string Le nom de l'événement
* @param[in] $fct string Le nom de la fonction à exectuer
* @param[in] $params mixed Paramètres pour le lancement de la fonction
* @param[in] $class Nom de la classe possèdant la méthode $fct à executer
* @param string $event Le nom de l'événement
* @param callable $fct Le nom de la fonction à exectuer
* @param array $params Paramètres pour le lancement de la fonction
* @param string $class Nom de la classe possèdant la méthode $fct à executer
*
* @retval void
* @return void
*/
public function addEvent($event,$fct,$params,$class=NULL) {
$this -> _events[$event][] = array(
@ -625,12 +699,12 @@ class LSattribute extends LSlog_staticLoggerClass {
/**
* Ajouter une action sur un objet lors d'un événement
*
* @param[in] $event string Le nom de l'événement
* @param[in] $obj object L'objet dont la méthode doit être executé
* @param[in] $meth string Le nom de la méthode
* @param[in] $params mixed Paramètres d'execution de la méthode
* @param string $event Le nom de l'événement
* @param object &$obj L'objet dont la méthode doit être executé
* @param string $meth Le nom de la méthode
* @param array $params Paramètres d'execution de la méthode
*
* @retval void
* @return void
*/
public function addObjectEvent($event,&$obj,$meth,$params=NULL) {
$this -> _objectEvents[$event][] = array(
@ -643,9 +717,9 @@ class LSattribute extends LSlog_staticLoggerClass {
/**
* Lance les actions à executer lors d'un événement
*
* @param[in] $event string Le nom de l'événement
* @param string $event Le nom de l'événement
*
* @retval boolean True si tout c'est bien passé, false sinon
* @return boolean True si tout c'est bien passé, false sinon
*/
public function fireEvent($event) {
self :: log_debug(strval($this)." -> fireEvent($event)");
@ -736,11 +810,11 @@ 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 string $param The configuration parameter
* @param mixed $default The default value (default : null)
* @param string $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
* @return mixed The configuration parameter value or default value if not set
**/
public function getConfig($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> config);

View file

@ -43,6 +43,10 @@ class LSauth extends LSlog_staticLoggerClass {
'displaySelfAccess' => true
);
/**
* Start authentication
* @return bool
*/
public static function start() {
self :: log_debug('start()');
// Load Config
@ -51,7 +55,7 @@ class LSauth extends LSlog_staticLoggerClass {
}
if (!LSsession :: loadLSclass('LSauthMethod')) {
self :: log_debug('Failed to load LSauthMethod class');
return;
return false;
}
$api_mode = LSsession :: get('api_mode');
if ($api_mode)
@ -63,22 +67,26 @@ class LSauth extends LSlog_staticLoggerClass {
if (LSsession :: loadLSclass($class)) {
if ($api_mode && !$class :: apiModeSupported()) {
LSerror :: addErrorCode('LSauth_08', self :: $method);
return;
return false;
}
self :: $provider = new $class();
if (!self :: $provider) {
LSerror :: addErrorCode('LSauth_05', self :: $method);
return;
return false;
}
self :: log_debug('Provider Started !');
return true;
}
else {
LSerror :: addErrorCode('LSauth_04', self :: $method);
return;
return false;
}
}
/**
* Force user authentication
* @return LSldapObject|false
*/
public static function forceAuthentication() {
self :: log_debug('LSauth :: forceAuthentication()');
if (!is_null(self :: $provider)) {
@ -89,20 +97,20 @@ class LSauth extends LSlog_staticLoggerClass {
}
// No data : user has not filled the login form
self :: log_debug('No data -> user has not filled the login form');
return;
return false;
}
LSerror :: addErrorCode('LSauth_06');
return;
return false;
}
/**
* 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 string $param The configuration parameter
* @param mixed $default The default value (default : null)
* @param string $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
* @return mixed The configuration parameter value or default value if not set
**/
private static function getConfig($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, self :: $config);
@ -142,7 +150,7 @@ class LSauth extends LSlog_staticLoggerClass {
/**
* Check if the specified auth object type have acces to LdapSaisie (on the current mode)
*
* @param[in] $objType string The LSobject type
* @param string $objType The LSobject type
*
* @return boolean True if specified auth object type have acces to LdapSaisie, False otherwise
*/
@ -157,7 +165,7 @@ class LSauth extends LSlog_staticLoggerClass {
/**
* Retrieved LSobjects corresponding to a username
*
* @retval array|false Array of corresponding LSldapObject with object DN as key, or false in case of error
* @return array|false Array of corresponding LSldapObject with object DN as key, or false in case of error
*/
public static function username2LSobjects($username) {
$user_objects = array();
@ -198,9 +206,9 @@ class LSauth extends LSlog_staticLoggerClass {
/**
* Get user password attribute name
*
* @param[in] &object LSldapObject The user object
* @param LSldapObject &$object The user object
*
* @retval string|false The user password attribute name or false if not configured
* @return string|false The user password attribute name or false if not configured
*/
public static function getUserPasswordAttribute(&$object) {
$authObjectTypes = self :: getAuthObjectTypes();
@ -215,9 +223,9 @@ class LSauth extends LSlog_staticLoggerClass {
*
* Return LDAP credentials or false
*
* @params[in] $user The LSldapObject of the user authificated
* @param LSldapObject $user The LSldapObject of the user authificated
*
* @retval Array|false Array of LDAP credentials array('dn','pwd') or False
* @return array|false Array of LDAP credentials array('dn','pwd') or False
**/
public static function getLDAPcredentials($user) {
return self :: $provider -> getLDAPcredentials($user);
@ -226,14 +234,14 @@ class LSauth extends LSlog_staticLoggerClass {
/**
* Logout
*
* @retval void
* @return bool
**/
public static function logout() {
if (!is_null(self :: $provider)) {
return self :: $provider -> logout();
}
LSerror :: addErrorCode('LSauth_06');
return;
return false;
}
/**
@ -242,20 +250,19 @@ class LSauth extends LSlog_staticLoggerClass {
* This method is run by LSsession after the local session was
* was successfully destroyed.
*
* @retval void
* @return void
**/
public static function afterLogout() {
if (!is_null(self :: $provider)) {
return self :: $provider -> afterLogout();
}
LSerror :: addErrorCode('LSauth_06');
return;
if (!is_null(self :: $provider))
self :: $provider -> afterLogout();
else
LSerror :: addErrorCode('LSauth_06');
}
/**
* Disable logout button in LSauth parameters
*
* @retval void
* @return void
**/
public static function disableLogoutBtn() {
self :: $params['displayLogoutBtn'] = false;
@ -264,7 +271,7 @@ class LSauth extends LSlog_staticLoggerClass {
/**
* Can display or not logout button in LSauth parameters
*
* @retval boolean
* @return boolean
**/
public static function displayLogoutBtn() {
return self :: $params['displayLogoutBtn'];
@ -273,7 +280,7 @@ class LSauth extends LSlog_staticLoggerClass {
/**
* Disable self access
*
* @retval void
* @return void
**/
public static function disableSelfAccess() {
self :: $params['displaySelfAccess'] = false;
@ -282,7 +289,7 @@ class LSauth extends LSlog_staticLoggerClass {
/**
* Can display or not self access
*
* @retval boolean
* @return boolean
**/
public static function displaySelfAccess() {
return self :: $params['displaySelfAccess'];

View file

@ -48,7 +48,7 @@ class LSauthMethod extends LSlog_staticLoggerClass {
*
* Return authentication data or false
*
* @retval Array|false Array of authentication data or False
* @return array|false Array of authentication data or False
**/
public function getAuthData() {
// Do nothing in the standard LSauthMethod class
@ -59,7 +59,7 @@ class LSauthMethod extends LSlog_staticLoggerClass {
/**
* Check authentication
*
* @retval LSldapObject|false The LSldapObject of the user authificated or false
* @return LSldapObject|false The LSldapObject of the user authificated or false
*/
public function authenticate() {
$authobjects = LSauth :: username2LSobjects($this -> authData['username']);
@ -82,7 +82,7 @@ class LSauthMethod extends LSlog_staticLoggerClass {
/**
* Logout
*
* @retval boolean True on success or False
* @return boolean True on success or False
**/
public function logout() {
// Do nothing in the standard LSauthMethod class
@ -95,10 +95,10 @@ class LSauthMethod extends LSlog_staticLoggerClass {
* This method is run by LSsession after the local session was
* was successfully destroyed.
*
* @retval void
* @return void
**/
public static function afterLogout() {
return true;
return;
}
/**
@ -106,9 +106,9 @@ class LSauthMethod extends LSlog_staticLoggerClass {
*
* Return LDAP credentials or false
*
* @params[in] $user The LSldapObject of the user authificated
* @param LSldapObject $user The LSldapObject of the authenticated user
*
* @retval Array|false Array of LDAP credentials array('dn','pwd') or False
* @return array|false Array of LDAP credentials array('dn','pwd') or False
**/
public function getLDAPcredentials($user) {
if (isset($this -> authData['password'])) {
@ -123,7 +123,7 @@ class LSauthMethod extends LSlog_staticLoggerClass {
/**
* Check API mode support of this method
*
* @retval boolean True if API mode is support, false otherwise
* @return boolean True if API mode is support, false otherwise
*/
static public function apiModeSupported() {
return static :: $api_mode_supported;

View file

@ -92,7 +92,7 @@ class LSauthMethod_CAS extends LSauthMethod {
*
* Return authentication data or false
*
* @retval Array|false Array of authentication data or False
* @return array|false Array of authentication data or False
**/
public function getAuthData() {
if ($this -> configured) {
@ -106,13 +106,13 @@ class LSauthMethod_CAS extends LSauthMethod {
self :: log_debug('LSauthMethod_CAS : auth data : '.varDump($this -> authData));
return $this -> authData;
}
return;
return false;
}
/**
* Logout
*
* @retval boolean True on success or False
* @return boolean True on success or False
**/
public function logout() {
if($this -> configured) {
@ -125,7 +125,7 @@ class LSauthMethod_CAS extends LSauthMethod {
else
self :: log_warning("LSauthMethod_CAS :: logout() : logout is disabled");
}
return;
return false;
}
}

View file

@ -44,7 +44,7 @@ class LSauthMethod_HTTP extends LSauthMethod_basic {
*
* Return authentication data or false
*
* @retval Array|false Array of authentication data or False
* @return array|false Array of authentication data or False
**/
public function getAuthData() {
if (!defined('LSAUTHMETHOD_HTTP_METHOD')) {
@ -110,7 +110,7 @@ class LSauthMethod_HTTP extends LSauthMethod_basic {
/**
* Check authentication
*
* @retval LSldapObject|false The LSldapObject of the user authificated or false
* @return LSldapObject|false The LSldapObject of the user authificated or false
*/
public function authenticate() {
if ( (defined('LSAUTHMETHOD_HTTP_TRUST_WITHOUT_PASSWORD_CHALLENGE')) && (constant('LSAUTHMETHOD_HTTP_TRUST_WITHOUT_PASSWORD_CHALLENGE') === True)) {
@ -129,7 +129,7 @@ class LSauthMethod_HTTP extends LSauthMethod_basic {
* This method is run by LSsession after the local session was
* was successfully destroyed.
*
* @retval void
* @return void
**/
public static function afterLogout() {
if (defined('LSAUTHMETHOD_HTTP_LOGOUT_REMOTE_URL')) {
@ -137,7 +137,6 @@ class LSauthMethod_HTTP extends LSauthMethod_basic {
LSurl :: redirect(LSAUTHMETHOD_HTTP_LOGOUT_REMOTE_URL);
}
self :: log_debug('No logout remote URL configured');
return true;
}
}

View file

@ -52,7 +52,7 @@ class LSauthMethod_anonymous extends LSauthMethod {
*
* Return authentication data or false
*
* @retval Array|false Array of authentication data or False
* @return array|false Array of authentication data or False
**/
public function getAuthData() {
$this -> authData = array(

View file

@ -32,7 +32,7 @@ class LSauthMethod_basic extends LSauthMethod {
*
* Return authentication data or false
*
* @retval Array|false Array of authentication data or False
* @return array|false Array of authentication data or False
**/
public function getAuthData() {
if (isset($_POST['LSauth_user']) && !empty($_POST['LSauth_user'])) {
@ -42,13 +42,13 @@ class LSauthMethod_basic extends LSauthMethod {
);
return $this -> authData;
}
return;
return false;
}
/**
* Check authentication
*
* @retval LSldapObject|false The LSldapObject of the user authificated or false
* @return LSldapObject|false The LSldapObject of the user authificated or false
*/
public function authenticate() {
$authobjects = LSauth :: username2LSobjects($this -> authData['username']);

View file

@ -29,29 +29,37 @@ LSsession :: loadLSclass('LSlog_staticLoggerClass');
*/
class LScli extends LSlog_staticLoggerClass {
// Configured commands
private static $commands = array();
/**
* Configured commands
* @see LScli::add_command()
* @var array
*/
private static array $commands = array();
// Store current executed command
/**
* Store current executed command
* @see LScli::handle_args()
* @var null|string
*/
private static $current_command = null;
/**
* Add a CLI command
*
* @param[in] $command string The CLI command name (required)
* @param[in] $handler callable The CLI command handler (must be callable, required)
* @param[in] $short_desc string|false A short description of what this command does (required)
* @param[in] $usage_args string|false A short list of commands available arguments show in usage message
* @param string $command The CLI command name (required)
* @param callable $handler The CLI command handler (must be callable, required)
* @param string|false $short_desc A short description of what this command does (required)
* @param string|false $usage_args A short list of commands available arguments show in usage message
* (optional, default: false)
* @param[in] $long_desc string|false A long description of what this command does (optional, default: false)
* @param[in] $need_ldap_con boolean Permit to define if this command need connection to LDAP server (optional,
* @param string|false $long_desc A long description of what this command does (optional, default: false)
* @param boolean $need_ldap_con Permit to define if this command need connection to LDAP server (optional,
* default: true)
* @param[in] $args_autocompleter callable|null Callable of the CLI command arguments autocompleter (optional, default:
* @param callable|null $args_autocompleter Callable of the CLI command arguments autocompleter (optional, default:
* null)
* @param[in] $override boolean Allow override if a command already exists with the same name (optional,
* @param boolean $override Allow override if a command already exists with the same name (optional,
* default: false)
*
* @retval void
* @return bool
**/
public static function add_command($command, $handler, $short_desc, $usage_args=false, $long_desc=false,
$need_ldap_con=true, $args_autocompleter=null, $override=false) {
@ -79,8 +87,8 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Show usage message
*
* @param[in] $error string|false Error message to display before usage message (optional, default: false)
* @retval void
* @param string|false $error Error message to display before usage message (optional, default: false)
* @return void
**/
public static function usage($error=false) {
global $argv;
@ -125,7 +133,7 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Handle CLI arguments and run command (if provided)
*
* @retval void
* @return void
**/
public static function handle_args() {
if (php_sapi_name() != "cli") {
@ -260,16 +268,16 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Run command
*
* @param[in] $command string The command name
* @param[in] $command string The command arguments (optional, default: array())
* @param[in] $exit boolean If true, function will exit after command execution (optional, default: true)
* @param string $command The command name
* @param string $command The command arguments (optional, default: array())
* @param boolean $exit If true, function will exit after command execution (optional, default: true)
*
* @retval void|boolean If $exit is False, return boolean casted command return
* @return boolean If $exit is False, return boolean casted command return, otherwise exit with 1 on error and 0 otherwise
**/
public static function run_command($command, $command_args=array(), $exit=true) {
if (php_sapi_name() != "cli") {
self :: log_fatal('Try to use LScli :: run_command() in non-CLI context.');
return;
return false;
}
if (!array_key_exists($command, self :: $commands)) {
self :: log_warning("LScli :: run_command() : invalid command '$command'.");
@ -301,7 +309,7 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Start LDAP connection (if not already connected)
*
* @retval void
* @return void
**/
public static function need_ldap_con() {
// Connect to LDAP server (if not already the case)
@ -314,14 +322,14 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Run external command
*
* @param[in] $command string|array The command. It's could be an array of the command with its arguments.
* @param[in] $data_stdin string|null The command arguments (optional, default: null)
* @param[in] $escape_command_args boolean If true, the command will be escaped (optional, default: true)
* @param[in] $cwd string|null The initial working dir for the command
* @param string|array $command The command. It's could be an array of the command with its arguments.
* @param string|null $data_stdin The command arguments (optional, default: null)
* @param boolean $escape_command_args If true, the command will be escaped (optional, default: true)
* @param string|null $cwd The initial working dir for the command
* (optional, default: null = use current PHP
* process working directory)
*
* @retval false|array An array of return code, stdout and stderr result or False in case of fatal error
* @return array|false An array of return code, stdout and stderr result or False in case of fatal error
**/
public static function run_external_command($command, $data_stdin=null, $escape_command_args=true, $cwd=null) {
if (array($command))
@ -365,9 +373,9 @@ class LScli extends LSlog_staticLoggerClass {
/**
* CLI helper to ask for user confirmation
*
* @param[in] $question string The confirmation question (optional, default: "Are you sure?")
* @param string $question The confirmation question (optional, default: "Are you sure?")
*
* @retval boolean True if user confirmed, false otherwise
* @return boolean True if user confirmed, false otherwise
**/
public static function confirm($question=null) {
if (is_null($question))
@ -386,16 +394,16 @@ class LScli extends LSlog_staticLoggerClass {
/**
* CLI command to handle BASH command autocompleter
*
* @param[in] $command_args array Command arguments
* @param array $command_args Command arguments
*
* @retval boolean True on success, false otherwise
* @return boolean True on success, false otherwise
**/
public static function bash_autocomplete($command_args) {
if (count($command_args) < 3)
return;
return false;
$comp_word_num = intval($command_args[0]);
if ($comp_word_num <= 0) return;
if ($command_args[1] != '--') return;
if ($comp_word_num <= 0) return false;
if ($command_args[1] != '--') return false;
$comp_words = array_slice($command_args, 2);
$comp_word = (isset($comp_words[$comp_word_num])?$comp_words[$comp_word_num]:'');
@ -548,9 +556,9 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Print list of available autocomplete options as required by BASH
*
* @param[in] $list mixed List of available autocomplete options if it's an array
* @param mixed $list List of available autocomplete options if it's an array
*
* @retval boolean True if $list is an array, false otherwise
* @return boolean True if $list is an array, false otherwise
**/
public static function return_bash_autocomplete_list($list) {
if (is_array($list)) {
@ -563,9 +571,9 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Autocomplete class name
*
* @param[in] $prefix string Class name prefix (optional, default=empty string)
* @param string $prefix Class name prefix (optional, default=empty string)
*
* @retval array List of matched class names
* @return array List of matched class names
**/
public static function autocomplete_class_name($prefix='', $quote_char=null) {
$classes = array();
@ -585,9 +593,9 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Autocomplete addon name
*
* @param[in] $prefix string Addon name prefix (optional, default=empty string)
* @param string $prefix Addon name prefix (optional, default=empty string)
*
* @retval array List of matched addon names
* @return array List of matched addon names
**/
public static function autocomplete_addon_name($prefix='') {
$addons = array();
@ -606,13 +614,13 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Autocomplete options
*
* @param[in] $opts array Available options
* @param[in] $prefix string Option name prefix (optional, default=empty string)
* @param[in] $case_sensitive boolean Set to false if options are case insensitive (optional, default=true)
* @param[in] $quote_char boolean Quote character (optional, if not set, $prefix will be unquoted and its
* @param array $opts Available options
* @param string $prefix Option name prefix (optional, default=empty string)
* @param boolean $case_sensitive Set to false if options are case insensitive (optional, default=true)
* @param string $quote_char Quote character (optional, if not set, $prefix will be unquoted and its
* quote char (if detected) will be used to quote options)
*
* @retval array List of matched options
* @return array List of matched options
**/
public static function autocomplete_opts($opts, $prefix='', $case_sensitive=true, $quote_char='') {
if (!is_string($prefix) || strlen($prefix)==0)
@ -637,9 +645,9 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Autocomplete integer option
*
* @param[in] $prefix string Option prefix (optional, default=empty string)
* @param string $prefix Option prefix (optional, default=empty string)
*
* @retval array List of available options
* @return array List of available options
**/
public static function autocomplete_int($prefix='', $quote_char='') {
$opts = array();
@ -652,9 +660,9 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Autocomplete boolean option
*
* @param[in] $prefix string Option prefix (optional, default=empty string)
* @param string $prefix Option prefix (optional, default=empty string)
*
* @retval array List of available options
* @return array List of available options
**/
public static function autocomplete_bool($prefix='', $quote_char='') {
return self :: autocomplete_opts(array('0', '1'), $prefix, false, $quote_char);
@ -663,12 +671,12 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Autocomplete LSobject type option
*
* @param[in] $prefix string Option prefix (optional, default=empty string)
* @param[in] $case_sensitive boolean Set to false if options are case insensitive (optional, default=true)
* @param[in] $quote_char boolean Quote character (optional, if not set, $prefix will be unquoted and its
* @param string $prefix Option prefix (optional, default=empty string)
* @param boolean $case_sensitive Set to false if options are case insensitive (optional, default=true)
* @param string $quote_char Quote character (optional, if not set, $prefix will be unquoted and its
* quote char (if detected) will be used to quote options)
*
* @retval array List of available options
* @return array List of available options
**/
public static function autocomplete_LSobject_types($prefix='', $case_sensitive=true, $quote_char='') {
$subdn_config = LSconfig :: get('subDn', null, null, LSsession :: $ldapServer);
@ -717,13 +725,13 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Autocomplete LSobject DN option
*
* @param[in] $objType string LSobject type
* @param[in] $prefix string Option prefix (optional, default=empty string)
* @param[in] $case_sensitive boolean Set to false if options are case insensitive (optional, default=true)
* @param[in] $quote_char boolean Quote character (optional, if not set, $prefix will be unquoted and its
* @param string $objType LSobject type
* @param string $prefix Option prefix (optional, default=empty string)
* @param boolean $case_sensitive Set to false if options are case insensitive (optional, default=true)
* @param string $quote_char Quote character (optional, if not set, $prefix will be unquoted and its
* quote char (if detected) will be used to quote options)
*
* @retval array List of available options
* @return array List of available options
**/
public static function autocomplete_LSobject_dn($objType, $prefix='', $case_sensitive=true, $quote_char='') {
if (!LSsession ::loadLSobject($objType, false))
@ -756,13 +764,13 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Autocomplete LSobject ioFormat option
*
* @param[in] $objType string LSobject type
* @param[in] $prefix string Option prefix (optional, default=empty string)
* @param[in] $case_sensitive boolean Set to false if options are case insensitive (optional, default=true)
* @param[in] $quote_char boolean Quote character (optional, if not set, $prefix will be unquoted and its
* @param string $objType LSobject type
* @param string $prefix Option prefix (optional, default=empty string)
* @param boolean $case_sensitive Set to false if options are case insensitive (optional, default=true)
* @param string $quote_char Quote character (optional, if not set, $prefix will be unquoted and its
* quote char (if detected) will be used to quote options)
*
* @retval array List of available options
* @return array List of available options
**/
public static function autocomplete_LSobject_ioFormat($objType, $prefix='', $case_sensitive=true, $quote_char='') {
if (!LSsession ::loadLSobject($objType, false))
@ -781,9 +789,9 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Autocomplete LSformRule name
*
* @param[in] $prefix string LSformRule name prefix (optional, default=empty string)
* @param string $prefix LSformRule name prefix (optional, default=empty string)
*
* @retval array List of matched LSformRule names
* @return array List of matched LSformRule names
**/
public static function autocomplete_LSformRule_name($prefix='', $quote_char=null) {
$rules = array();
@ -797,9 +805,9 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Unquote a word
*
* @param[in] &$word string Reference of the word to unquote
* @param string &$word Reference of the word to unquote
*
* @retval string The quote character or an empty string if word if not quoted
* @return string The quote character or an empty string if word if not quoted
*/
public static function unquote_word(&$word) {
if (in_array($word[0], array('"', "'"))) {
@ -815,11 +823,11 @@ class LScli extends LSlog_staticLoggerClass {
/**
* Quote a word
*
* @param[in] $word string The word to quote
* @param[in] $quote_char string The quote character. If not defined or empty, the input word
* @param string $word The word to quote
* @param string $quote_char The quote character. If not defined or empty, the input word
* will be returned unmodified.
*
* @retval string The quoted word
* @return string The quoted word
*/
public static function quote_word($word, $quote_char) {
if (!$quote_char) return $word;

View file

@ -27,7 +27,13 @@
*/
class LSconfig {
// Configuration Data
/**
* Configuration Data
* @see LSconfig::start()
* @see $GLOBALS['LSconfig']
* @see $GLOBALS['LSaddons']
* @var array<string,mixed>
*/
private static $data=array();
/**
@ -36,13 +42,13 @@ class LSconfig {
* Chargement initiale des données de configuration à partir des fichiers en
* config.*.php du dossier LS_CONF_DIR
*
* @retval boolean True si tout s'est bien passé, False sinon
* @return boolean True si tout s'est bien passé, False sinon
**/
public static function start() {
$files=array('config.inc.php','config.LSaddons.php');
foreach($files as $file) {
if (!LSsession::includeFile(LS_CONF_DIR.'/'.$file)) {
return;
return false;
}
}
if (is_array($GLOBALS['LSconfig'])) {
@ -50,21 +56,21 @@ class LSconfig {
self :: $data['LSaddons'] = $GLOBALS['LSaddons'];
return true;
}
return;
return false;
}
/**
* Get a specific configuration variable value
*
* @param[in] $var string The configuration variable name
* @param[in] $default mixed The default value to return if configuration variable
* @param string $var The configuration variable name
* @param mixed $default 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
* @param string $cast 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)
* @param[in] $data array The configuration data (optional)
* @param array $data The configuration data (optional)
*
* @retval mixed The configuration variable value
* @return mixed The configuration variable value
**/
public static function get($var, $default=null, $cast=null, $data=null) {
$vars = explode('.', $var);
@ -98,10 +104,10 @@ class LSconfig {
/**
* Get list of keys of a specific configuration variable
*
* @param[in] $var string The configuration variable name
* @param[in] $data array The configuration data (optional)
* @param string $var The configuration variable name
* @param array $data The configuration data (optional)
*
* @retval array An array of the keys of a specific configuration variable
* @return array An array of the keys of a specific configuration variable
**/
public static function keys($var, $data=null) {
$value = self :: get($var, null, null, $data);
@ -115,13 +121,13 @@ class LSconfig {
* variable name. In this case, the keys of the parent value will be iterated to compose
* the result.
*
* @param[in] $pattern string The configuration variable pattern
* @param[in] $default mixed The default value to return if configuration variable
* @param string $pattern The configuration variable pattern
* @param mixed $default The default value to return if configuration variable
* is not set (optional, see self :: get())
* @param[in] $cast string The type of expected value (optional, see self :: get())
* @param[in] $data array The configuration data (optional, see self :: get())
* @param string $cast The type of expected value (optional, see self :: get())
* @param array $data The configuration data (optional, see self :: get())
*
* @retval array The list of matching configuration variables with their value
* @return array The list of matching configuration variables with their value
**/
public static function getMatchingKeys($pattern, $default=null, $cast=null, $data=null, $prefix=null) {
$return = array();
@ -151,10 +157,10 @@ class LSconfig {
/**
* Définition d'une valeur
*
* @param[in] $var string Le nom de valeur à définir
* @param[in] $val mixed La valeur de la variable
* @param string $var Le nom de valeur à définir
* @param mixed $val La valeur de la variable
*
* @retval boolean True si tout s'est bien passé, False sinon
* @return boolean True si tout s'est bien passé, False sinon
**/
public static function set($var,$val) {
$vars=explode('.',$var);

View file

@ -25,7 +25,7 @@ class LSconfirmBox {
/*
* Méthode chargeant les dépendances d'affichage
*
* @retval void
* @return void
*/
public static function loadDependenciesDisplay() {
LStemplate :: addJSscript('LSconfirmBox.js');

View file

@ -29,6 +29,10 @@
*/
class LSerror {
/**
* Registered error codes
* @var array<string|int,array>
*/
private static $_errorCodes = array(
'0' => array('msg' => "%{msg}")
);
@ -38,14 +42,14 @@ class LSerror {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $code string The error code
* @param[in] $msg LSformat The LSformat of the error message
* @param[in] $escape boolean Set to false if you don't want the message
* @param string $code The error code
* @param LSformat $msg The LSformat of the error message
* @param boolean $escape Set to false if you don't want the message
* to be escaped on display (Default: true)
*
* @retval void
* @return void
*/
public static function defineError($code=-1, $msg='', $escape=True) {
public static function defineError($code='-1', $msg='', $escape=True) {
self :: $_errorCodes[$code] = array(
'msg' => $msg,
'escape' => boolval($escape),
@ -57,16 +61,16 @@ class LSerror {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $code string The error code
* @param[in] $msg mixed If error code is not specified (or not defined), it could content the
* @param string $code The error code
* @param mixed $msg If error code is not specified (or not defined), it could content the
* the error message. If error code is provided (and defined), this parameter
* will be used to format registred error message (as LSformat). In this case,
* it could be any of data support by getFData function as $data parameter.
*
* @param[in] $escape boolean Set to false if you don't want the message
* @param boolean $escape Set to false if you don't want the message
* to be escaped on display (Default: true)
*
* @retval void
* @return void
*/
public static function addErrorCode($code=null, $msg=null, $escape=true) {
$_SESSION['LSerror'][] = self :: formatError($code, $msg, $escape);
@ -79,38 +83,18 @@ class LSerror {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $return boolean True if you want to retrieved errors message. If false,
* @param boolean $return True if you want to retrieved errors message. If false,
* (default), LSerrors template variable will be assigned
* with errors message.
*
* @retval string|null
* @return array|null
*/
public static function display($return=False) {
$errors = self :: getErrors();
if ($errors && $return)
return $errors;
LStemplate :: assign('LSerrors', base64_encode(json_encode($errors)));
return;
}
/**
* Print errors and stop LdapSaisie
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $code Error code (see addErrorCode())
* @param[in] $msg Error msg (see addErrorCode())
* @param[in] $escape boolean (see addErrorCode())
*
* @retval void
*/
public static function stop($code=-1, $msg='', $escape=true) {
if(!empty($_SESSION['LSerror'])) {
print "<h1>"._('Errors')."</h1>\n";
print self :: display(true);
}
print "<h1>"._('Stop')."</h1>\n";
exit (self :: formatError($code, $msg, $escape));
return null;
}
/**
@ -118,7 +102,7 @@ class LSerror {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retvat string Le texte des erreurs
* @return array Array of formated error messages
*/
public static function getErrors() {
$return = (
@ -133,9 +117,13 @@ class LSerror {
/**
* Format error message
*
* @param string|null $code The error code
* @param mixed $message Error message data for registred errors or the error message as string, or null
* @param bool $escape Set to false to disable escaping error message
* @param callable $escape_method The escape method (default: htmlentities)
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retvat string Le texte des erreurs
* @return string Le texte des erreurs
*/
private static function formatError($code=null, $message=null, $escape=True, $escape_method=null) {
if ($code && array_key_exists($code, self :: $_errorCodes)) {
@ -165,7 +153,7 @@ class LSerror {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retvat boolean
* @return boolean
*/
public static function errorsDefined() {
return (
@ -180,7 +168,7 @@ class LSerror {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retvat void
* @return void
*/
private static function resetError() {
if (isset($_SESSION['LSerror']))
@ -190,9 +178,9 @@ class LSerror {
/**
* Check if is Net_LDAP2 error and display possible error message
*
* @param[in] $data mixed Data
* @param mixed $data Data
*
* @retval boolean True if it's an error or False
* @return boolean True if it's an error or False
**/
public static function isLdapError($data) {
if (Net_LDAP2::isError($data)) {

View file

@ -31,30 +31,129 @@ LSsession :: loadLSclass('LSlog_staticLoggerClass');
*/
class LSform extends LSlog_staticLoggerClass {
/**
* Reference of the related LSldapObject
* @var LSldapObject
*/
var $ldapObject;
/**
* Identifier of the form (create/update/...)
* @var string
*/
var $idForm;
var $config;
var $can_validate = true;
var $elements = array();
var $_rules = array();
var $_postData = array();
/**
* Configuration (LSobjects.<type>.LSform)
* @see LSform::__construct()
* @var array
*/
var array $config;
var $_elementsErrors = array();
/**
* Validation ability telltale
* @see LSform::validate()
* @see LSform::setElementError()
* @var boolean
*/
var bool $can_validate = true;
/**
* Form elements with attribute name as key and an implemented LSformElement as value
* @see LSform::addElement()
* @see LSattr_html::addToForm()
* @var array<string,LSformElement>
*/
var array $elements = array();
/**
* Registred elements's rules
* @var array<string,array>
*/
var array $_rules = array();
/**
* Post data of the form
* @see LSform::getPostData()
* @var array<string,array>
*/
var array $_postData = array();
/**
* Registered elements's errors
* @see LSform::setElementError()
* @see LSform::definedError()
* @see LSform::getErrors()
* @var array<string,array>
*/
var array $_elementsErrors = array();
/**
* Validation telltale
* @see LSform::validate()
* @var boolean
*/
var $_isValidate = false;
/**
* List of attributes explicitly declared as not updated
* @see LSformElement_password::getPostData()
* @var array<string,bool>
*/
var $_notUpdate = array();
/**
* MAX_FILE_SIZE value of the form
* @see LSform::setMaxFileSize()
* @var int|null
*/
var $maxFileSize = NULL;
/**
* Name of the applied data entry form
* @see LSform::applyDataEntryForm()
* @var string|null
*/
var $dataEntryForm = NULL;
/**
* Configuration of the applied data entry form
* (LSobjects.<type>.LSform.dataEntryForm.<dataEntryForm_name>)
* @see LSform::applyDataEntryForm()
* @var array|null
*/
var $dataEntryFormConfig = NULL;
var $warnings = array();
/**
* Registred warnings
* @see LSform::addWarning()
* @var array<int,string>
*/
var array $warnings = array();
var $api_mode = false;
/**
* Telltale of the API mode
* @see LSform::__construct()
* @var bool
*/
var bool $api_mode = false;
private $submited = false;
/**
* Submited telltale
* @see LSform::setSubmited()
* @see LSform::isSubmit()
* @var bool
*/
private bool $submited = false;
/**
* The submit button value
* Note: used to detect the submited state of the form from the current request data
* @see LSform::__construct()
* @see LSform::isSubmit()
* @var string|null
*/
private $submit = null;
/**
@ -64,33 +163,30 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $idForm [<b>required</b>] string L'identifiant du formulaire
* @param[in] $submit string La valeur du bouton submit
* @param LSldapObject &$ldapObject The related LSldapObject
* @param string $idForm The form identifier
* @param string|null $submit The submit button value
* @param bool $api_mode Set to True to enable API mode
*
* @retval void
* @return void
*/
public function __construct(&$ldapObject, $idForm, $submit=NULL, $api_mode=false){
$this -> idForm = $idForm;
if (!$submit) {
$this -> submit = _("Validate");
}
else {
$this -> submit = $submit;
}
$this -> submit = ($submit?$submit:_("Validate"));
$this -> api_mode = $api_mode;
$this -> ldapObject =& $ldapObject;
$this -> config = $ldapObject -> getConfig('LSform');
$this -> config = $ldapObject -> getConfig('LSform', array(), 'array');
LSsession :: loadLSclass('LSformElement');
}
/**
* 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 string $param The configuration parameter
* @param mixed $default The default value (default : null)
* @param string $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
* @return mixed The configuration parameter value or default value if not set
**/
public function getConfig($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> config);
@ -99,7 +195,7 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Allow conversion of LSform to string
*
* @retval string The string representation of the LSform
* @return string The string representation of the LSform
*/
public function __toString() {
return "<LSform ".$this -> idForm." on ".$this -> ldapObject -> toString(false).">";
@ -108,10 +204,10 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Display the form
*
* @param[in] $LSform_action string|null The form action attribute value (optional, default: $_SERVER['PHP_SELF'])
* @param string|null $LSform_action The form action attribute value (optional, default: $_SERVER['PHP_SELF'])
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval void
* @return void
*/
public function display($LSform_action=null){
// Load view dependencies
@ -209,10 +305,10 @@ class LSform extends LSlog_staticLoggerClass {
LStemplate :: assign('LSform_submittxt',$this -> submit);
}
/*
/**
* Méthode chargeant les dépendances d'affichage d'une LSview
*
* @retval void
* @return void
*/
public static function loadDependenciesDisplayView($ldapObject=false, $search_view=false) {
LStemplate :: addCssFile('LSform.css');
@ -260,7 +356,7 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval void
* @return void
*/
public function displayView(){
self :: loadDependenciesDisplayView($this -> ldapObject);
@ -288,21 +384,22 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $attr [<b>required</b>] string Le nom du champ
* @param[in] $msg Le format du message d'erreur à afficher (pouvant comporter
* des valeurs %{[n'importe quoi]} qui seront remplacé par le label
* du champs concerné.
* @param LSformElement $element Le nom du champ
* @param string|null $msg Le format du message d'erreur à afficher (pouvant comporter
* des valeurs %{[n'importe quoi]} qui seront remplacé par le label
* du champs concerné.
* @param array|null $extra_values Extra values to compute the LSformat of the message
* (optional, by default, only the field label is provided to getFData)
*
* @retval void
* @return void
*/
public function setElementError($attr,$msg=NULL) {
if($msg!='') {
$msg_error=getFData($msg,$attr->getLabel());
}
else {
$msg_error=getFData(_("%{label} attribute data is not valid."),$attr->getLabel());
}
$this -> _elementsErrors[$attr->name][]=$msg_error;
public function setElementError($element, $msg=null, $extra_values=null) {
$this -> _elementsErrors[$element->name][] = getFData(
$msg?$msg:_("%{label} attribute data is not valid."),
is_array($extra_values)?
array_merge(array('label' => $element->getLabel()), $extra_values):
$element->getLabel()
);
$this -> can_validate=false;
}
@ -311,9 +408,9 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $element [<b>required</b>] string Le nom de l'élement
* @param string|null $element Le nom de l'élement
*
* @retval boolean
* @return boolean
*/
public function definedError($element=NULL) {
if ($element) {
@ -327,7 +424,7 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Retourne le tableau des erreurs
*
* @retval Array array(element => array(errors))
* @return array array(element => array(errors))
*/
public function getErrors() {
return $this -> _elementsErrors;
@ -336,27 +433,27 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Check form is submited and its data are validat
*
* @param[in] $onlyIfPresent boolean If true and data of this element is not present in POST data,
* @param boolean $onlyIfPresent If true and data of this element is not present in POST data,
* just ignore it.
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if form is submited and its data are valid, false otherwise
* @return boolean true if form is submited and its data are valid, false otherwise
*/
public function validate($onlyIfPresent=false){
if(!$this -> can_validate)
return;
return false;
if ($this -> isSubmit()) {
if (!$this -> getPostData($onlyIfPresent)) {
LSerror :: addErrorCode('LSform_01');
return;
return false;
}
// Check getPostData do not trigger fields errors
if(!$this -> can_validate)
return;
return false;
$this -> setValuesFromPostData();
//Validation des données ici !!! ///
if (!$this -> checkData()) {
return;
return false;
}
LSdebug("Data are checked up");
$this -> _isValidate = true;
@ -370,7 +467,7 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si toutes la saisie est OK, false sinon
* @return boolean true si toutes la saisie est OK, false sinon
*/
public function checkData() {
$retval=true;
@ -411,20 +508,20 @@ class LSform extends LSlog_staticLoggerClass {
}
/**
* Vérifie si au moins une valeur est présente dans le tableau
* Check if at least one non-empty value is present in the specifed array
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $data array tableau de valeurs
* @param array $data Array of values
*
* @retval boolean true si au moins une valeur est présente, false sinon
* @return boolean True if at least one non-empty value is present, false otherwise
*/
public function checkRequired($data) {
foreach($data as $val) {
if (!is_empty($val))
return true;
}
return;
return false;
}
/**
@ -432,20 +529,20 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true si la saisie du formulaire est présente en POST, false sinon
* @return boolean true si la saisie du formulaire est présente en POST, false sinon
*/
public function isSubmit() {
if ($this -> submited)
return true;
if( (isset($_POST['validate']) && ($_POST['validate']=='LSform')) && (isset($_POST['idForm']) && ($_POST['idForm'] == $this -> idForm)) )
return true;
return;
return false;
}
/**
* Set form as submited
*
* @retval void
* @return void
*/
public function setSubmited() {
$this -> submited = true;
@ -456,10 +553,10 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $data array('attr' => array(values)) Tableau des données du formulaire
* @param[in] $consideredAsSubmit Définie si on force le formualaire comme envoyer
* @param array $data Tableau des données du formulaire : array('attr' => array(values))
* @param bool $consideredAsSubmit Définie si on force le formualaire comme envoyer
*
* @retval boolean true si les données ont été définies, false sinon
* @return boolean true si les données ont été définies, false sinon
*/
public function setPostData($data,$consideredAsSubmit=false) {
if (is_array($data)) {
@ -477,24 +574,24 @@ class LSform extends LSlog_staticLoggerClass {
return true;
}
return;
return false;
}
/**
* Retrieve POST data of the form
*
* @param[in] $onlyIfPresent boolean If true and data of this element is not present in POST data,
* @param boolean $onlyIfPresent If true and data of this element is not present in POST data,
* just ignore it.
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval boolean true if POST data are retrieved, false otherwise
* @return boolean true if POST data are retrieved, false otherwise
*/
public function getPostData($onlyIfPresent=false) {
if (is_null($this -> dataEntryForm)) {
foreach($this -> elements as $element_name => $element) {
if( !($element -> getPostData($this -> _postData, $onlyIfPresent)) ) {
LSerror :: addErrorCode('LSform_02',$element_name);
return;
return false;
}
}
}
@ -530,7 +627,7 @@ class LSform extends LSlog_staticLoggerClass {
// Retrieve POST data of the element
if( !($element -> getPostData($this -> _postData, $onlyIfPresent)) ) {
LSerror :: addErrorCode('LSform_02',$elementName);
return;
return false;
}
}
}
@ -542,19 +639,20 @@ class LSform extends LSlog_staticLoggerClass {
*
* Ajoute un élément au formulaire et définis les informations le concernant.
*
* @param[in] $type string Le type de l'élément
* @param[in] $name string Le nom de l'élément
* @param[in] $label string Le label de l'élément
* @param[in] $param mixed Paramètres supplémentaires
* @param string $type Le type de l'élément
* @param string $name Le nom de l'élément
* @param string $label Le label de l'élément
* @param array $params Paramètres supplémentaires
* @param LSattr_html &$attr_html The related LSattr_html
*
* @retval LSformElement
* @return LSformElement|false The LSformElement on success, false otherwise
*/
public function addElement($type,$name,$label,$params,&$attr_html) {
$elementType='LSformElement_'.$type;
LSsession :: loadLSclass($elementType);
if (!class_exists($elementType)) {
LSerror :: addErrorCode('LSform_05',array('type' => $type));
return;
return false;
}
$element=$this -> elements[$name] = new $elementType($this,$name,$label,$params,$attr_html);
if ($element) {
@ -563,16 +661,16 @@ class LSform extends LSlog_staticLoggerClass {
else {
unset ($this -> elements[$name]);
LSerror :: addErrorCode('LSform_06',array('element' => $name));
return;
return false;
}
}
/**
* Check if form has a specified element (by attr name)
*
* @param[in] $attr string The element/attribute name
* @param string $name The element/attribute name
*
* @retval boolean
* @return boolean
**/
public function hasElement($name) {
return isset($this -> elements[$name]);
@ -581,12 +679,12 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Check if a specified element (by attr name) is freezed
*
* @param[in] $attr string The element/attribute name
* @param string $name The element/attribute name
*
* @retval boolean
* @return boolean
**/
public function isFreeze($name) {
return isset($this -> elements[$name]) && $this -> elements[$name] -> isFreeze($name);
return isset($this -> elements[$name]) && $this -> elements[$name] -> isFreeze();
}
/**
@ -594,11 +692,11 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $element string Le nom de l'élément conserné
* @param[in] $rule string Le nom de la règle à ajouter
* @param[in] $options array Options (facultative)
* @param string $element Le nom de l'élément conserné
* @param string $rule Le nom de la règle à ajouter
* @param array $options Options (facultative)
*
* @retval boolean
* @return boolean
*/
public function addRule($element, $rule, $options=null) {
if ( isset($this ->elements[$element]) ) {
@ -611,12 +709,12 @@ class LSform extends LSlog_staticLoggerClass {
}
else {
LSerror :: addErrorCode('LSattribute_03', array('attr' => $element, 'rule' => $rule));
return;
return false;
}
}
else {
LSerror :: addErrorCode('LSform_04', array('element' => $element));
return;
return false;
}
}
@ -628,15 +726,16 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $element string Le nom de l'élément conserné
* @param string $element Le nom de l'élément conserné
*
* @retval boolean
* @return boolean
*/
public function setRequired($element) {
if (isset( $this -> elements[$element] ) )
return $this -> elements[$element] -> setRequired();
else
return;
if (isset( $this -> elements[$element] ) ) {
$this -> elements[$element] -> setRequired();
return true;
}
return false;
}
/**
@ -646,7 +745,8 @@ class LSform extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $element string Le nom de l'élément conserné
* @param string $rule The rule name
* @return bool
*/
public function isRuleRegistered($rule) {
LSsession :: loadLSclass('LSformRule');
@ -657,7 +757,7 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Retourne les valeurs validés du formulaire
*
* @retval mixed Les valeurs validés du formulaire, ou false si elles ne le sont pas
* @return mixed Les valeurs validés du formulaire, ou false si elles ne le sont pas
*/
public function exportValues() {
if ($this -> _isValidate) {
@ -668,16 +768,16 @@ class LSform extends LSlog_staticLoggerClass {
return $retval;
}
else {
return;
return false;
}
}
/**
* Retourn un élement du formulaire
*
* @param[in] string $element Nom de l'élement voulu
* @param string $element Nom de l'élement voulu
*
* @retval LSformElement L'élement du formulaire voulu
* @return LSformElement L'élement du formulaire voulu
*/
public function getElement($element) {
return $this -> elements[$element];
@ -689,25 +789,25 @@ class LSform extends LSlog_staticLoggerClass {
* If form is posted, retrieve values from postData, otherwise
* retrieve value from the element.
*
* @param[in] string $element The element name
* @param string $element The element name
*
* @retval mixed The element values
* @return mixed The element values
**/
public function getValue($element) {
if ($this -> isSubmit() && $this -> _postData) {
return $this -> _postData[$element];
}
return $this -> elements[$element] -> getValue();
return $this -> elements[$element] -> values;
}
/**
* Défini les valeurs des élements à partir des valeurs postées
*
* @retval boolean True si les valeurs ont été définies, false sinon.
* @return boolean True si les valeurs ont été définies, false sinon.
*/
public function setValuesFromPostData() {
if (empty($this -> _postData)) {
return;
return false;
}
foreach($this -> _postData as $element => $values) {
$this -> elements[$element] -> setValueFromPostData($values);
@ -718,10 +818,10 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Return the HTML code of an empty form field
*
* @param[in] $element string The form element name
* @param[in] $value_idx integer|null The value index (optional, default: null == 0)
* @param string $element The form element name
* @param int|null $value_idx The value index (optional, default: null == 0)
*
* @retval string|null The HTML code of the specified field if exist, null otherwise
* @return string|null The HTML code of the specified field if exist, null otherwise
*/
public function getEmptyField($element, $value_idx=null) {
$element = $this -> getElement($element);
@ -729,16 +829,16 @@ class LSform extends LSlog_staticLoggerClass {
return $element -> getEmptyField($value_idx);
}
else {
return;
return null;
}
}
/**
* Défini la taille maximal pour les fichiers envoyés par le formualaire
*
* @param[in] $size La taille maximal en octets
* @param int $size La taille maximal en octets
*
* @retval void
* @return void
**/
public function setMaxFileSize($size) {
$this -> maxFileSize = $size;
@ -747,9 +847,9 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Applique un masque de saisie au formulaire
*
* @param[in] $dataEntryForm string Le nom du masque de saisie
* @param string $dataEntryForm Le nom du masque de saisie
*
* @retval boolean True si le masque de saisie a été appliqué, False sinon
* @return boolean True si le masque de saisie a été appliqué, False sinon
**/
public function applyDataEntryForm($dataEntryForm) {
$dataEntryForm=(string)$dataEntryForm;
@ -775,15 +875,15 @@ class LSform extends LSlog_staticLoggerClass {
return true;
}
LSerror :: addErrorCode('LSform_07',$dataEntryForm);
return;
return false;
}
/**
* Liste les dataEntryForm disponible pour un type d'LSldapObject
*
* @param[in] $type string Le type d'LSldapObject
* @param string $type Le type d'LSldapObject
*
* @retval array Tableau contenant la liste de dataEntryForm disponible pour ce type d'LSldapObject (nom => label)
* @return array Tableau contenant la liste de dataEntryForm disponible pour ce type d'LSldapObject (nom => label)
**/
public static function listAvailableDataEntryForm($type) {
$retval=array();
@ -807,9 +907,9 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Ajoute un avertissement au sujet du formulaire
*
* @param[in] $txt string Le texte de l'avertissement
* @param string $txt Le texte de l'avertissement
*
* @retval void
* @return void
**/
public function addWarning($txt) {
$this -> warnings[]=$txt;
@ -818,9 +918,9 @@ class LSform extends LSlog_staticLoggerClass {
/**
* Méthode Ajax permetant de retourner le code HTML d'un élément du formulaire vide
*
* @param[in] &$data Variable de retour
* @param array &$data Variable de retour
*
* @retval void
* @return void
**/
public static function ajax_onAddFieldBtnClick(&$data) {
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['fieldId'])) ) {
@ -845,11 +945,12 @@ class LSform extends LSlog_staticLoggerClass {
/**
* CLI autocompleter for form attributes values
*
* @param[in] &$opts array Reference of array of avalaible autocomplete options
* @param[in] $comp_word string The command word to autocomplete
* @param[in] $multiple_value_delimiter string The multiple value delimiter (optional, default: "|")
* @param array &$opts Array of avalaible autocomplete options
* @param string $comp_word The command word to autocomplete
* @param string $multiple_value_delimiter The multiple value delimiter
* (optional, default: "|")
*
* @retval void
* @return void
*/
public function autocomplete_attrs_values(&$opts, $comp_word, $multiple_value_delimiter='|') {
if ($comp_word && strpos($comp_word, '=') !== false) {

View file

@ -32,30 +32,94 @@ LSsession :: loadLSclass('LSlog_staticLoggerClass');
class LSformElement extends LSlog_staticLoggerClass {
var $name;
var $label;
var $params;
var $values = array();
/**
* The attribute name
* @var string
*/
var string $name;
/**
* The attribute label
* @see LSformElement::__construct()
* @see LSformElement::getLabel()
* @var string
*/
var string $label;
/**
* Attribute configuration (LSobjects.<type>.attrs.<attr_name>)
* @see LSformElement::getParam()
* @var array<string,mixed>
*/
var array $params;
/**
* Values of the element
* @var array<mixed>
*/
var array $values = array();
/**
* Reference of the related LSform object
* @var LSform
*/
var $form = null;
var $_required = false;
var $_freeze = false;
/**
* Require telltale
* @see LSformElement::setRequired()
* @see LSformElement::isRequired()
* @var bool
*/
var bool $_required = false;
/**
* Freeze telltale (=read-only element)
* @see LSformElement::freeze()
* @see LSformElement::isFreeze()
* @var bool
*/
var bool $_freeze = false;
/**
* Reference to the related LSattr_html object
* @var LSattr_html
*/
var $attr_html;
var $fieldTemplate = 'LSformElement_field.tpl';
var $template = 'LSformElement.tpl';
var $fetchVariables = array();
/**
* The one-value template filename (=for one vaue of the form element)
* Note: commonly overwrite in implementated classes
* @var string
*/
var string $fieldTemplate = 'LSformElement_field.tpl';
/**
* The template filename (of the form complement element)
* Note: may be overwrite in implementated classes
* @var string
*/
var string $template = 'LSformElement.tpl';
/**
* Template variables passed to Smarty computing the form element template
* Note: this variables are commonly added in implementated classes
* @var array<string,mixed>
*/
var array $fetchVariables = array();
/**
* Constructor
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] &$form LSform The LSform parent object
* @param[in] $name string The name of the element
* @param[in] $label string The label of the element
* @param[in] $params array The parameters of the element
* @param[in] &$attr_html LSattr_html The LSattr_html object of the corresponding attribute
* @param LSform &$form The LSform parent object
* @param string $name The name of the element
* @param string $label The label of the element
* @param array $params The parameters of the element
* @param LSattr_html &$attr_html The LSattr_html object of the corresponding attribute
*
* @retval void
* @return void
*/
public function __construct(&$form, $name, $label, $params, &$attr_html){
$this -> name = $name;
@ -68,7 +132,7 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* Allow conversion of LSformElement to string
*
* @retval string The string representation of the LSformElement
* @return string The string representation of the LSformElement
*/
public function __toString() {
return strval($this -> form)." -> <".get_class($this)." ".$this -> name.">";
@ -81,9 +145,9 @@ class LSformElement extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] [<b>required</b>] string or array La futur valeur de l'élément
* @param string|array $data La futur valeur de l'élément
*
* @retval boolean Retourne True
* @return boolean Retourne True
*/
public function setValue($data) {
$this -> values = ensureIsArray($data);
@ -99,9 +163,9 @@ class LSformElement extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] [<b>required</b>] string or array La futur valeur de l'élément
* @param string|array $data La futur valeur de l'élément
*
* @retval boolean Retourne True
* @return boolean Retourne True
*/
public function setValueFromPostData($data) {
$this -> values = ensureIsArray($data);
@ -112,7 +176,7 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* Exporte les valeurs de l'élément
*
* @retval Array Les valeurs de l'élement
* @return array Les valeurs de l'élement
*/
public function exportValues(){
return $this -> values;
@ -125,9 +189,9 @@ class LSformElement extends LSlog_staticLoggerClass {
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] [<b>required</b>] string or array La futur valeur de l'élément
* @param string|array $data La futur valeur de l'élément
*
* @retval void
* @return void
*/
public function addValue($data) {
$this -> values = array_merge($this -> values, ensureIsArray($data));
@ -138,7 +202,7 @@ class LSformElement extends LSlog_staticLoggerClass {
*
* Cette méthode test si l'élément est éditable
*
* @retval boolean
* @return boolean
*/
public function isFreeze(){
return $this -> _freeze;
@ -149,7 +213,7 @@ class LSformElement extends LSlog_staticLoggerClass {
*
* Rend l'élément non-editable
*
* @retval void
* @return void
*/
public function freeze() {
$this -> _freeze = true;
@ -158,9 +222,9 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* Défini la propriété required de l'élément.
*
* param[in] $isRequired boolean true si l'élément est requis, false sinon
* param boolean $isRequired true si l'élément est requis, false sinon
*
* @retval void
* @return void
*/
public function setRequired($isRequired=true) {
$this -> _required = $isRequired;
@ -171,16 +235,22 @@ class LSformElement extends LSlog_staticLoggerClass {
*
* Cette méthode test si l'élément est requis
*
* @retval boolean
* @return boolean
*/
public function isRequired(){
return $this -> _required;
}
/**
* Retourne le label de l'élement
* Return label info of the element:
* array(
* 'label' => 'The label',
* 'required' => true|false,
* 'help_info' => 'The help info of the element',
* 'help_info_in_view' => true|false,
* )
*
* @retval void
* @return array The label info
*/
public function getLabelInfos() {
if ($this -> isRequired()) {
@ -207,11 +277,11 @@ class LSformElement extends LSlog_staticLoggerClass {
* Cette méthode vérifie la présence en POST de la valeur de l'élément et la récupère
* pour la mettre dans le tableau passer en paramètre avec en clef le nom de l'élément
*
* @param[in] &$return array Reference of the array for retrieved values
* @param[in] $onlyIfPresent boolean If true and data of this element is not present in POST data,
* @param array &$return Reference of the array for retrieved values
* @param boolean $onlyIfPresent If true and data of this element is not present in POST data,
* just ignore it.
*
* @retval boolean true si la valeur est présente en POST, false sinon
* @return boolean true si la valeur est présente en POST, false sinon
*/
public function getPostData(&$return, $onlyIfPresent=false) {
if($this -> isFreeze()) {
@ -234,10 +304,10 @@ class LSformElement extends LSlog_staticLoggerClass {
* Retrieve the value of the element specified by its name ($name)
* from POST data (provided as $post).
*
* @param[in] &$post array Reference of the array for input POST data
* @param[in] $name string POST data element name
* @param array &$post Reference of the array for input POST data
* @param string $name POST data element name
*
* @retval mixed Array of POST data value if present, false otherwise
* @return mixed Array of POST data value if present, false otherwise
*/
protected static function getData(&$post, $name) {
if (isset($post[$name])) {
@ -258,7 +328,7 @@ class LSformElement extends LSlog_staticLoggerClass {
*
* Retourne $this -> label, ou $this -> params['label'], ou $this -> name
*
* @retval string Le label de l'élément
* @return string Le label de l'élément
*/
public function getLabel() {
if ($this -> label != "") {
@ -270,7 +340,7 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* Le champ est-il a valeur multiple
*
* @retval boolean True si le champ est à valeur multiple, False sinon
* @return boolean True si le champ est à valeur multiple, False sinon
*/
public function isMultiple() {
return $this -> getParam('multiple', false, 'bool');
@ -279,10 +349,10 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* Return HTML code of the LSformElement based on its (smarty) template file
*
* @param[in] $template string The template filename (optional, default: $this -> template)
* @param[in] $variables array Array of template variables to assign before template compilation (optional)
* @param string $template The template filename (optional, default: $this -> template)
* @param array $variables Array of template variables to assign before template compilation (optional)
*
* @retval string HTML code of the LSformElement
* @return string HTML code of the LSformElement
*/
public function fetchTemplate($template=NULL,$variables=array()) {
if (!$template) {
@ -310,9 +380,9 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* Return HTML code of an empty form field
*
* @param[in] $value_idx integer|null The value index (optional, default: null == 0)
* @param integer|null $value_idx The value index (optional, default: null == 0)
*
* @retval string The HTML code of an empty field
* @return string The HTML code of an empty field
*/
public function getEmptyField($value_idx=null) {
return $this -> fetchTemplate(
@ -326,11 +396,11 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* Return a 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 string $param The configuration parameter
* @param mixed $default The default value (default : null)
* @param string $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The parameter value or default value if not set
* @return mixed The parameter value or default value if not set
**/
public function getParam($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> params);
@ -339,14 +409,16 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* CLI autocompleter for form element attribute values
*
* @param[in] &$opts array Reference of array of avalaible autocomplete options
* @param[in] $comp_word string The (unquoted) command word to autocomplete
* @param[in] $attr_value string The current attribute value in command word to autocomplete
* (optional, default: empty string)
* @param[in] $multiple_value_delimiter string The multiple value delimiter (optional, default: "|")
* @param[in] $quote_char string The quote character detected (optional, default: empty string)
* @param array &$opts Array of avalaible autocomplete options
* @param string $comp_word The (unquoted) command word to autocomplete
* @param string $attr_value The current attribute value in command word to
* autocomplete (optional, default: empty string)
* @param string $multiple_value_delimiter The multiple value delimiter
* (optional, default: "|")
* @param string $quote_char The quote character detected
* (optional, default: empty string)
*
* @retval void
* @return void
*/
public function autocomplete_attr_values(&$opts, $comp_word, $attr_value="", $multiple_value_delimiter="|", $quote_char='') {
return;
@ -355,21 +427,23 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* CLI autocompleter helper to split form element attribute values
*
* @param[in] $attr_value string The current attribute value in command word to autocomplete
* (optional, default: empty string)
* @param[in] $multiple_value_delimiter string The multiple value delimiter (optional, default: "|")
* @param[in] &$attr_values Reference of array Reference of array that will contain splited attribute
* values without last-one
* @param[in] &$last_attr_value Reference of string Reference of array that will contain the last splited attribute
* value
* @param string $attr_value The current attribute value in command word
* to autocomplete
* (optional, default: empty string)
* @param string $multiple_value_delimiter The multiple value delimiter
* (optional, default: "|")
* @param array &$attr_values Array that will contain splited attribute
* values without last-one
* @param string &$last_attr_value Array that will contain the last splited
* attribute value
*
* @retval boolean True on success, False otherwise
* @return boolean True on success, False otherwise
*/
protected function split_autocomplete_attr_values($attr_value, $multiple_value_delimiter, &$attr_values, &$last_attr_value) {
$attr_values = explode($multiple_value_delimiter, $attr_value);
if (count($attr_values) > 1 && !$this -> getParam('multiple', false, 'bool')) {
self :: log_error("The attribute ".$this -> name." is not multivalued.");
return;
return false;
}
self :: log_debug("split_autocomplete_attr_values('$attr_value', '$multiple_value_delimiter'): values = '".implode("', '", $attr_values)."'");
$last_attr_value = array_pop($attr_values);
@ -380,13 +454,13 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* CLI autocompleter helper to format and add form element attribute value option
*
* @param[in] &$opts array Reference of array of avalaible autocomplete options
* @param[in] &$attr_values Reference of array Reference of array of splited attribute values without last-one
* @param[in] $value string The attribute value to add as option
* @param[in] $multiple_value_delimiter string The multiple value delimiter (optional, default: "|")
* @param[in] $quote_char string The quote character (optional, default: empty string)
* @param array &$opts Array of avalaible autocomplete options
* @param array &$attr_values Array of splited attribute values without last-one
* @param string $value The attribute value to add as option
* @param string $multiple_value_delimiter The multiple value delimiter (optional, default: "|")
* @param string $quote_char The quote character (optional, default: empty string)
*
* @retval boolean True on success, False otherwise
* @return void
*/
protected function add_autocomplete_attr_value_opts(&$opts, &$attr_values, $value, $multiple_value_delimiter='|', $quote_char='') {
if (in_array($value, $attr_values)) {
@ -404,10 +478,10 @@ class LSformElement extends LSlog_staticLoggerClass {
/**
* Retrieve value as return in API response
*
* @param[in] $details boolean If true, returned values will contain details if this field type
* support it (optional, default: false)
* @param boolean $details If true, returned values will contain details if this field
* type support it (optional, default: false)
*
* @retval mixed API value(s) or null/empty array if no value
* @return mixed API value(s) or null/empty array if no value
*/
public function getApiValue($details=false) {
if (method_exists($this, 'parseValue')) {
@ -428,4 +502,14 @@ class LSformElement extends LSlog_staticLoggerClass {
return $values[0];
}
/**
* Get display info of the form element
*
* @return array
*/
public function getDisplay(){
$return = $this -> getLabelInfos();
$return['html'] = $this -> fetchTemplate();
return $return;
}
}

View file

@ -32,15 +32,15 @@
class LSformElement_boolean extends LSformElement {
var $fieldTemplate = 'LSformElement_boolean_field.tpl';
var $template = 'LSformElement_boolean.tpl';
var string $fieldTemplate = 'LSformElement_boolean_field.tpl';
var string $template = 'LSformElement_boolean.tpl';
/**
* Retourne les infos d'affichage de l'élément
*
* Cette méthode retourne les informations d'affichage de l'élement
*
* @retval array
* @return array
*/
public function getDisplay(){
$return = $this -> getLabelInfos();
@ -67,13 +67,16 @@ class LSformElement_boolean extends LSformElement {
/**
* CLI autocompleter for form element attribute values
*
* @param[in] &$opts array Reference of array of avalaible autocomplete options
* @param[in] $comp_word string The (unquoted) command word to autocomplete
* @param[in] $attr_value string The current attribute value in command word to autocomplete (optional, default: empty string)
* @param[in] $multiple_value_delimiter string The multiple value delimiter (optional, default: "|")
* @param[in] $quote_char string The quote character detected (optional, default: empty string)
* @param array &$opts Array of avalaible autocomplete options
* @param string $comp_word The (unquoted) command word to autocomplete
* @param string $attr_value The current attribute value in command word to
* autocomplete (optional, default: empty string)
* @param string $multiple_value_delimiter The multiple value delimiter
* (optional, default: "|")
* @param string $quote_char The quote character detected
* (optional, default: empty string)
*
* @retval void
* @return void
*/
public function autocomplete_attr_values(&$opts, $comp_word, $attr_value="", $multiple_value_delimiter="|", $quote_char='') {
// Split attribute values and retrieved splited value in $attr_values and $last_attr_value

View file

@ -32,9 +32,9 @@
class LSformElement_date extends LSformElement {
var $fieldTemplate = 'LSformElement_date_field.tpl';
var string $fieldTemplate = 'LSformElement_date_field.tpl';
var $_php2js_format = array(
var array $_php2js_format = array(
"a" => "a",
"A" => "A",
"b" => "b",
@ -60,18 +60,18 @@ class LSformElement_date extends LSformElement {
"%" => "%",
);
var $_cache_php2js_format=array();
var array $_cache_php2js_format=array();
var $default_style="vista";
var string $default_style="vista";
/**
* Définis la valeur de l'élément date
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] [<b>required</b>] string or array La futur valeur de l'élément
* @param string|array $data La futur valeur de l'élément
*
* @retval boolean Retourne True
* @return boolean Retourne True
*/
public function setValue($data) {
$special_values = $this -> getSpecialValues();
@ -97,7 +97,7 @@ class LSformElement_date extends LSformElement {
/**
* Exporte les valeurs de l'élément
*
* @retval Array Les valeurs de l'élement
* @return array Les valeurs de l'élement
*/
public function exportValues(){
$retval=array();
@ -124,7 +124,7 @@ class LSformElement_date extends LSformElement {
/**
* Retourne le format d'affichage de la date
*
* @retval string Le format de la date
* @return string Le format de la date
**/
public function getFormat() {
return $this -> getParam('html_options.format', ($this -> getParam('html_options.time', true)?'%d/%m/%Y, %T':'%d/%m/%Y'));
@ -133,7 +133,7 @@ class LSformElement_date extends LSformElement {
/**
* Return date picker style value
*
* @retval string The date picker style
* @return string The date picker style
**/
public function getStyle() {
$style = $this -> getParam('html_options.style', $this -> default_style, 'string');
@ -151,7 +151,7 @@ class LSformElement_date extends LSformElement {
*
* Cette méthode retourne les informations d'affichage de l'élement
*
* @retval array
* @return array
*/
public function getDisplay(){
$return = $this -> getLabelInfos();
@ -196,10 +196,10 @@ class LSformElement_date extends LSformElement {
/**
* Retournne un template Smarty compilé dans le contexte d'un LSformElement
*
* @param[in] string $template Le template à retourner
* @param[in] array $variables Variables Smarty à assigner avant l'affichage
* @param string $template Le template à retourner
* @param array $variables Variables Smarty à assigner avant l'affichage
*
* @retval string Le HTML compilé du template
* @return string Le HTML compilé du template
*/
public function fetchTemplate($template=NULL, $variables=array()) {
$variables['special_values'] = $this -> getSpecialValues();
@ -212,11 +212,11 @@ class LSformElement_date extends LSformElement {
* Cette méthode vérifie la présence en POST de la valeur de l'élément et la récupère
* pour la mettre dans le tableau passer en paramètre avec en clef le nom de l'élément
*
* @param[in] &$return array Reference of the array for retrieved values
* @param[in] $onlyIfPresent boolean If true and data of this element is not present in POST data,
* @param array &$return Reference of the array for retrieved values
* @param boolean $onlyIfPresent If true and data of this element is not present in POST data,
* just ignore it.
*
* @retval boolean true si la valeur est présente en POST, false sinon
* @return boolean true si la valeur est présente en POST, false sinon
*/
public function getPostData(&$return, $onlyIfPresent=false) {
if($this -> isFreeze()) {
@ -267,7 +267,7 @@ class LSformElement_date extends LSformElement {
/**
* Convertis un format de date Php (strftime) en JS (jscalendar)
*
* @retval mixed Format de date jscalendar (string) ou False si la convertion
* @return string|false Format de date jscalendar (string) ou False si la convertion
* n'a pas réussi.
*/
public function php2js_format($format) {
@ -283,7 +283,7 @@ class LSformElement_date extends LSformElement {
}
else {
$this -> _cache_php2js_format[$format]=false;
return;
return false;
}
}
else {

View file

@ -31,16 +31,14 @@
class LSformElement_image extends LSformElement {
var $postImage = NULL;
var $tmp_file = array();
var $fieldTemplate = 'LSformElement_image_field.tpl';
var string $fieldTemplate = 'LSformElement_image_field.tpl';
/**
* Retourne les infos d'affichage de l'élément
*
* Cette méthode retourne les informations d'affichage de l'élement
*
* @retval array
* @return array
*/
public function getDisplay(){
LStemplate :: addCssFile('LSformElement_image.css');
@ -86,11 +84,11 @@ class LSformElement_image extends LSformElement {
* Cette méthode vérifie la présence en POST de la valeur de l'élément et la récupère
* pour la mettre dans le tableau passer en paramètre avec en clef le nom de l'élément
*
* @param[in] &$return array Reference of the array for retrieved values
* @param[in] $onlyIfPresent boolean If true and data of this element is not present in POST data,
* @param array &$return Reference of the array for retrieved values
* @param boolean $onlyIfPresent If true and data of this element is not present in POST data,
* just ignore it.
*
* @retval boolean true si la valeur est présente en POST, false sinon
* @return boolean true si la valeur est présente en POST, false sinon
*/
public function getPostData(&$return, $onlyIfPresent=false) {
if($this -> isFreeze()) {
@ -140,7 +138,7 @@ class LSformElement_image extends LSformElement {
/**
* Get file upload error message
*
* @retval string The translated file upload error message
* @return string The translated file upload error message
*/
private function getFileUploadErrorMessage() {
if (isset($_FILES[$this -> name]) && isset($_FILES[$this -> name]['error'])) {
@ -167,10 +165,10 @@ class LSformElement_image extends LSformElement {
/**
* Retrieve value as return in API response
*
* @param[in] $details boolean If true, returned values will contain details if this field type
* @param boolean $details If true, returned values will contain details if this field type
* support it (optional, default: false)
*
* @retval mixed API value(s) or null/empty array if no value
* @return string|array|null API value(s) or null/empty array if no value
*/
public function getApiValue($details=false) {
if ($this -> isMultiple()) {

Some files were not shown because too many files have changed in this diff Show more