diff --git a/htdocs/lib/ldap.class.php b/htdocs/lib/ldap.class.php index 91c04de6bf6..ca9552be259 100644 --- a/htdocs/lib/ldap.class.php +++ b/htdocs/lib/ldap.class.php @@ -67,7 +67,7 @@ class Ldap */ var $groups; /** - * Code erreur retourn� par le serveur Ldap + * Code erreur retourne par le serveur Ldap */ var $ldapErrorCode; /** @@ -622,7 +622,159 @@ class Ldap if ($result) return 1; return -1; } + + /** + * \brief Add a LDAP attribute in entry + * \param dn DN entry key + * \param info Attributes array + * \param user Objet user that create + * \return int <0 if KO, >0 if OK + * \remarks Ldap object connect and bind must have been done + */ + function add_attribute($dn, $info, $user) + { + global $conf; + dol_syslog("Ldap::add_attribute dn=".$dn." info=".join(',',$info)); + + // Check parameters + if (! $this->connection) + { + $this->error="NotConnected"; + return -2; + } + if (! $this->bind) + { + $this->error="NotConnected"; + return -3; + } + + // Encode to LDAP page code + $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); + foreach($info as $key => $val) + { + if (! is_array($val)) $info[$key]=$this->convFromOutputCharset($val,$this->ldapcharset); + } + + $this->dump($dn,$info); + + //print_r($info); + $result=@ldap_mod_add($this->connection, $dn, $info); + + if ($result) + { + dol_syslog("Ldap::add_attribute successfull", LOG_DEBUG); + return 1; + } + else + { + $this->error=@ldap_error($this->connection); + dol_syslog("Ldap::add_attribute failed: ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * \brief Replace a LDAP attribute in entry + * \param dn DN entry key + * \param info Attributes array + * \param user Objet user that create + * \return int <0 if KO, >0 if OK + * \remarks Ldap object connect and bind must have been done + */ + function replace_attribute($dn, $info, $user) + { + global $conf; + + dol_syslog("Ldap::replace_attribute dn=".$dn." info=".join(',',$info)); + + // Check parameters + if (! $this->connection) + { + $this->error="NotConnected"; + return -2; + } + if (! $this->bind) + { + $this->error="NotConnected"; + return -3; + } + + // Encode to LDAP page code + $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); + foreach($info as $key => $val) + { + if (! is_array($val)) $info[$key]=$this->convFromOutputCharset($val,$this->ldapcharset); + } + + $this->dump($dn,$info); + + //print_r($info); + $result=@ldap_mod_replace($this->connection, $dn, $info); + + if ($result) + { + dol_syslog("Ldap::replace_attribute successfull", LOG_DEBUG); + return 1; + } + else + { + $this->error=@ldap_error($this->connection); + dol_syslog("Ldap::replace_attribute failed: ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * \brief Delete a LDAP attribute in entry + * \param dn DN entry key + * \param info Attributes array + * \param user Objet user that create + * \return int <0 if KO, >0 if OK + * \remarks Ldap object connect and bind must have been done + */ + function delete_attribute($dn, $info, $user) + { + global $conf; + + dol_syslog("Ldap::delete_attribute dn=".$dn." info=".join(',',$info)); + + // Check parameters + if (! $this->connection) + { + $this->error="NotConnected"; + return -2; + } + if (! $this->bind) + { + $this->error="NotConnected"; + return -3; + } + + // Encode to LDAP page code + $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); + foreach($info as $key => $val) + { + if (! is_array($val)) $info[$key]=$this->convFromOutputCharset($val,$this->ldapcharset); + } + + $this->dump($dn,$info); + + //print_r($info); + $result=@ldap_mod_del($this->connection, $dn, $info); + + if ($result) + { + dol_syslog("Ldap::delete_attribute successfull", LOG_DEBUG); + return 1; + } + else + { + $this->error=@ldap_error($this->connection); + dol_syslog("Ldap::delete_attribute failed: ".$this->error, LOG_ERR); + return -1; + } + } /** * \brief Build a LDAP message diff --git a/htdocs/usergroup.class.php b/htdocs/usergroup.class.php index 4fdf49be53a..00f03791f80 100644 --- a/htdocs/usergroup.class.php +++ b/htdocs/usergroup.class.php @@ -45,7 +45,7 @@ class UserGroup extends CommonObject var $note; // Note on group var $datec; // Creation date of group var $datem; // Modification date of group - var $members=array(); // Array of users + var $members=array(1,2); // Array of users var $oldcopy; // To contains a clone of this when we need to save old properties of object