diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php
index 8d424386e31..008641f7e67 100644
--- a/htdocs/adherents/class/adherent.class.php
+++ b/htdocs/adherents/class/adherent.class.php
@@ -1958,6 +1958,7 @@ class Adherent extends CommonObject
$info["objectclass"]=explode(',',$conf->global->LDAP_MEMBER_OBJECT_CLASS);
$this->fullname=$this->getFullName($langs);
+
// For avoid ldap error when firstname and lastname are empty
if ($this->morphy == 'mor' && empty($this->fullname)) {
$this->fullname = $this->societe;
@@ -1983,11 +1984,10 @@ class Adherent extends CommonObject
// Check if it is the LDAP key and if its value has been changed
if (! empty($conf->global->LDAP_KEY_MEMBERS) && $conf->global->LDAP_KEY_MEMBERS == $conf->global->$constname)
{
- if (! empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) $keymodified=true;
+ if (! empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) $keymodified=true; // For check if LDAP key has been modified
}
}
}
-
if ($this->firstname && ! empty($conf->global->LDAP_MEMBER_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_MEMBER_FIELD_FIRSTNAME] = $this->firstname;
if ($this->poste && ! empty($conf->global->LDAP_MEMBER_FIELD_TITLE)) $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste;
if ($this->societe && ! empty($conf->global->LDAP_MEMBER_FIELD_COMPANY)) $info[$conf->global->LDAP_MEMBER_FIELD_COMPANY] = $this->societe;
@@ -2007,13 +2007,13 @@ class Adherent extends CommonObject
if ($this->datefin && ! empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin,'dayhourldap');
// When password is modified
- if ($this->pass)
+ if (! empty($this->pass))
{
if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
- if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // md5 for OpenLdap TODO add type of encryption
+ if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // Create OpenLDAP MD5 password (TODO add type of encryption)
}
- // When LDAP key is modified and password no defined
- else if ($keymodified)
+ // Set LDAP password if possible
+ else
{
if (! empty($conf->global->DATABASE_PWD_ENCRYPTED))
{
@@ -2021,7 +2021,7 @@ class Adherent extends CommonObject
if (empty($conf->global->MAIN_SECURITY_HASH_ALGO))
{
if ($this->pass_indatabase_crypted && ! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
- $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase_crypted, 5); // md5 for OpenLdap TODO add type of encryption
+ $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase_crypted, 5); // Create OpenLDAP MD5 password from Dolibarr MD5 password
}
}
}
diff --git a/htdocs/adherents/ldap.php b/htdocs/adherents/ldap.php
index 65aea951d76..795a5b34b9f 100644
--- a/htdocs/adherents/ldap.php
+++ b/htdocs/adherents/ldap.php
@@ -59,26 +59,23 @@ if (! $result)
if ($action == 'dolibarr2ldap')
{
- $db->begin();
-
$ldap=new Ldap();
$result=$ldap->connect_bind();
- $info=$object->_load_ldap_info();
- $dn=$object->_load_ldap_dn($info);
- $olddn=$dn; // We can say that old dn = dn as we force synchro
-
- $result=$ldap->update($dn,$info,$user,$olddn);
-
- if ($result >= 0)
+ if ($result > 0)
{
- setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
- $db->commit();
+ $info=$object->_load_ldap_info();
+ $dn=$object->_load_ldap_dn($info);
+ $olddn=$dn; // We can say that old dn = dn as we force synchro
+
+ $result=$ldap->update($dn,$info,$user,$olddn);
}
- else
- {
+
+ if ($result >= 0) {
+ setEventMessages($langs->trans("MemberSynchronized"), null, 'mesgs');
+ }
+ else {
setEventMessages($ldap->errors, $ldap->error, 'errors');
- $db->rollback();
}
}
diff --git a/htdocs/admin/ldap_users.php b/htdocs/admin/ldap_users.php
index a0866c1305a..2d2d045cd43 100644
--- a/htdocs/admin/ldap_users.php
+++ b/htdocs/admin/ldap_users.php
@@ -184,7 +184,7 @@ print '';
print '