Added functions in LDAP class for manage attributes in entry
This commit is contained in:
parent
419fe6914e
commit
10b183c010
@ -67,7 +67,7 @@ class Ldap
|
|||||||
*/
|
*/
|
||||||
var $groups;
|
var $groups;
|
||||||
/**
|
/**
|
||||||
* Code erreur retourn<EFBFBD> par le serveur Ldap
|
* Code erreur retourne par le serveur Ldap
|
||||||
*/
|
*/
|
||||||
var $ldapErrorCode;
|
var $ldapErrorCode;
|
||||||
/**
|
/**
|
||||||
@ -623,6 +623,158 @@ class Ldap
|
|||||||
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
|
* \brief Build a LDAP message
|
||||||
|
|||||||
@ -45,7 +45,7 @@ class UserGroup extends CommonObject
|
|||||||
var $note; // Note on group
|
var $note; // Note on group
|
||||||
var $datec; // Creation date of group
|
var $datec; // Creation date of group
|
||||||
var $datem; // Modification 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
|
var $oldcopy; // To contains a clone of this when we need to save old properties of object
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user