From 87dc3a0b22768e6f80f45b6a7d1c2a9236f088cb Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 22 Feb 2013 15:24:29 +0100 Subject: [PATCH 1/4] LDAP sync : trigger was launched even if LDAP_SYNCHRO_ACTIVE is 'ldap2dolibarr' --- .../interface_50_modLdap_Ldapsynchro.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php b/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php index 77b54f58d7c..d0a1bd45168 100755 --- a/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php +++ b/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php @@ -110,7 +110,7 @@ class InterfaceLdapsynchro if ($action == 'USER_CREATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap=new Ldap(); $ldap->connect_bind(); @@ -129,7 +129,7 @@ class InterfaceLdapsynchro elseif ($action == 'USER_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap=new Ldap(); $ldap->connect_bind(); @@ -166,7 +166,7 @@ class InterfaceLdapsynchro elseif ($action == 'USER_NEW_PASSWORD') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap=new Ldap(); $ldap->connect_bind(); @@ -207,7 +207,7 @@ class InterfaceLdapsynchro elseif ($action == 'USER_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap=new Ldap(); $ldap->connect_bind(); @@ -226,7 +226,7 @@ class InterfaceLdapsynchro elseif ($action == 'USER_SETINGROUP') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap=new Ldap(); $ldap->connect_bind(); @@ -264,7 +264,7 @@ class InterfaceLdapsynchro elseif ($action == 'USER_REMOVEFROMGROUP') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap=new Ldap(); $ldap->connect_bind(); @@ -304,7 +304,7 @@ class InterfaceLdapsynchro elseif ($action == 'GROUP_CREATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap=new Ldap(); $ldap->connect_bind(); @@ -327,7 +327,7 @@ class InterfaceLdapsynchro elseif ($action == 'GROUP_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap=new Ldap(); $ldap->connect_bind(); @@ -364,7 +364,7 @@ class InterfaceLdapsynchro elseif ($action == 'GROUP_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap=new Ldap(); $ldap->connect_bind(); From 0358ef49187b041d198ff0e5e21b2bde50b1f923 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Mon, 25 Feb 2013 11:53:56 +0100 Subject: [PATCH 2/4] LDAP : sync script now updates or create user --- scripts/user/sync_users_ldap2dolibarr.php | 54 ++++++++++++++++------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/scripts/user/sync_users_ldap2dolibarr.php b/scripts/user/sync_users_ldap2dolibarr.php index 036d45f79a6..1f9360f013a 100755 --- a/scripts/user/sync_users_ldap2dolibarr.php +++ b/scripts/user/sync_users_ldap2dolibarr.php @@ -178,6 +178,8 @@ if ($result >= 0) foreach ($ldaprecords as $key => $ldapuser) { $fuser = new User($db); + + $fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné // Propriete membre $fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; @@ -210,6 +212,7 @@ if ($result >= 0) $fuser->fk_member=0; $fuser->statut=1; + // TODO : revoir la gestion du status /*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS])) { $fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]); @@ -219,25 +222,44 @@ if ($result >= 0) //if ($fuser->statut > 1) $fuser->statut=1; //print_r($ldapuser); - - // Group of user - // We should use here $groupid - - // Creation member - print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); - $fuser_id=$fuser->create($user); - if ($fuser_id > 0) - { - print ' --> Created member id='.$fuser_id.' login='.$fuser->login; - } - else - { - $error++; - print ' --> '.$fuser_id.' '.$fuser->error; + + if($fuser->id > 0) { // User update + print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); + $res=$fuser->update($user); + + if ($res < 0) + { + $error++; + print ' --> '.$res.' '.$fuser->error; + } + else + { + print ' --> Updated user id='.$fuser->id.' login='.$fuser->login; + } + } else { // User creation + print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); + $res=$fuser->create($user); + + if ($res > 0) + { + print ' --> Created user id='.$fuser->id.' login='.$fuser->login; + } + else + { + $error++; + print ' --> '.$res.' '.$fuser->error; + } } print "\n"; - //print_r($fuser); + + // Gestion des groupes + // TODO : revoir la gestion des groupes (ou script de sync groupes) + /*if(!$error) { + foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) { + $groupdn; + } + }*/ } if (! $error || $forcecommit) From 428f844b4d157a45537c349f6449e976dc7c862c Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Mon, 25 Feb 2013 11:57:52 +0100 Subject: [PATCH 3/4] LDAP : add option to get data as an array --- htdocs/core/class/ldap.class.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php index 08838321288..9f18a477bed 100644 --- a/htdocs/core/class/ldap.class.php +++ b/htdocs/core/class/ldap.class.php @@ -874,9 +874,10 @@ class Ldap * @param string $useridentifier Name of key field (Ex: uid) * @param array $attributeArray Array of fields required. Note this array must also contains field $useridentifier (Ex: sn,userPassword) * @param int $activefilter 1=use field this->filter as filter instead of parameter $search + * @param array $attributeAsArray Array of fields wanted as an array not a string * @return array Array of [id_record][ldap_field]=value */ - function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter=0) + function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter=0, $attributeAsArray=array()) { $fulllist=array(); @@ -955,7 +956,15 @@ class Ldap } else { - $fulllist[$recordid][$attributeArray[$j]] = $this->convToOutputCharset($info[$i][$keyattributelower][0],$this->ldapcharset); + if(in_array($attributeArray[$j], $attributeAsArray) && is_array($info[$i][$keyattributelower])) { + $valueTab = array(); + foreach($info[$i][$keyattributelower] as $key => $value) { + $valueTab[$key] = $this->convToOutputCharset($value,$this->ldapcharset); + } + $fulllist[$recordid][$attributeArray[$j]] = $valueTab; + } else { + $fulllist[$recordid][$attributeArray[$j]] = $this->convToOutputCharset($info[$i][$keyattributelower][0],$this->ldapcharset); + } } } } From 2dc4b9152100fa44f38d5db2b4c840491354dc50 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 25 Feb 2013 12:51:38 +0100 Subject: [PATCH 4/4] New: Function plimit of databases drivers accept -1 as value (it means default value set into conf->liste_limit). --- ChangeLog | 3 ++- htdocs/core/db/mssql.class.php | 12 ++++++------ htdocs/core/db/mysql.class.php | 12 ++++++------ htdocs/core/db/mysqli.class.php | 10 +++++----- htdocs/core/db/pgsql.class.php | 12 ++++++------ htdocs/core/db/sqlite.class.php | 12 ++++++------ 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 28c424736d0..8a7c97adf97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,7 +28,8 @@ For developers: - Renamed some database fields, code variables and parameters from french to english. - First change to manage margins on contracts. - Add hook getFormMail. - +- Function plimit of databases drivers accept -1 as value (it means default value set + into conf->liste_limit). For translators: - Update language files. diff --git a/htdocs/core/db/mssql.class.php b/htdocs/core/db/mssql.class.php index cfa8e858f70..f8eb9914cf7 100644 --- a/htdocs/core/db/mssql.class.php +++ b/htdocs/core/db/mssql.class.php @@ -499,16 +499,16 @@ class DoliDBMssql /** - * Define limits of request - * - * @param int $limit nombre maximum de lignes retournees - * @param int $offset numero de la ligne a partir de laquelle recuperer les ligne - * @return string chaine exprimant la syntax sql de la limite + * Define limits and offset of request + * + * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) + * @param int $offset Numero of line from where starting fetch + * @return string String with SQL syntax to add a limit and offset */ function plimit($limit=0,$offset=0) { global $conf; - if (! $limit) $limit=$conf->liste_limit; + if ($limit < 0) $limit=$conf->liste_limit; if ($offset > 0) return " LIMIT $offset,$limit "; else return " LIMIT $limit "; } diff --git a/htdocs/core/db/mysql.class.php b/htdocs/core/db/mysql.class.php index 81d5d7de4ff..7b22c8165c3 100644 --- a/htdocs/core/db/mysql.class.php +++ b/htdocs/core/db/mysql.class.php @@ -479,16 +479,16 @@ class DoliDBMysql /** - * Define limits of request - * - * @param int $limit nombre maximum de lignes retournees - * @param int $offset numero de la ligne a partir de laquelle recuperer les ligne - * @return string chaine exprimant la syntax sql de la limite + * Define limits and offset of request + * + * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) + * @param int $offset Numero of line from where starting fetch + * @return string String with SQL syntax to add a limit and offset */ function plimit($limit=0,$offset=0) { global $conf; - if (! $limit) $limit=$conf->liste_limit; + if ($limit < 0) $limit=$conf->liste_limit; if ($offset > 0) return " LIMIT $offset,$limit "; else return " LIMIT $limit "; } diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 5ccdb661ec2..6ea19ba8c11 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -481,16 +481,16 @@ class DoliDBMysqli /** - * Defini les limites de la requete + * Define limits and offset of request * - * @param int $limit nombre maximum de lignes retournees - * @param int $offset numero de la ligne a partir de laquelle recuperer les ligne - * @return string chaine exprimant la syntax sql de la limite + * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) + * @param int $offset Numero of line from where starting fetch + * @return string String with SQL syntax to add a limit and offset */ function plimit($limit=0,$offset=0) { global $conf; - if (! $limit) $limit=$conf->liste_limit; + if ($limit < 0) $limit=$conf->liste_limit; if ($offset > 0) return " LIMIT $offset,$limit "; else return " LIMIT $limit "; } diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 2c05625e383..df73e562e70 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -691,16 +691,16 @@ class DoliDBPgsql /** - * Defini les limites de la requete - * - * @param int $limit nombre maximum de lignes retournees - * @param int $offset numero de la ligne a partir de laquelle recuperer les lignes - * @return string chaine exprimant la syntax sql de la limite + * Define limits and offset of request + * + * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) + * @param int $offset Numero of line from where starting fetch + * @return string String with SQL syntax to add a limit and offset */ function plimit($limit=0,$offset=0) { global $conf; - if (! $limit) $limit=$conf->liste_limit; + if ($limit < 0) $limit=$conf->liste_limit; if ($offset > 0) return " LIMIT ".$limit." OFFSET ".$offset." "; else return " LIMIT $limit "; } diff --git a/htdocs/core/db/sqlite.class.php b/htdocs/core/db/sqlite.class.php index 4cc217d24ad..8725e9a3efe 100644 --- a/htdocs/core/db/sqlite.class.php +++ b/htdocs/core/db/sqlite.class.php @@ -620,16 +620,16 @@ class DoliDBSqlite /** - * Define limits of request - * - * @param int $limit nombre maximum de lignes retournees - * @param int $offset numero de la ligne a partir de laquelle recuperer les ligne - * @return string chaine exprimant la syntax sql de la limite + * Define limits and offset of request + * + * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) + * @param int $offset Numero of line from where starting fetch + * @return string String with SQL syntax to add a limit and offset */ function plimit($limit=0,$offset=0) { global $conf; - if (! $limit) $limit=$conf->liste_limit; + if ($limit < 0) $limit=$conf->liste_limit; if ($offset > 0) return " LIMIT $offset,$limit "; else return " LIMIT $limit "; }