seconde version code ldap , contact dans branche people

This commit is contained in:
opensides 2004-06-16 16:29:38 +00:00
parent aec05045b7
commit 46bd2c167f

View File

@ -50,7 +50,7 @@ class Contact
{ {
if (!$this->socid) if (!$this->socid)
{ {
$this->socid = 0; $this->socid = 0;
} }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (datec, fk_soc, name, fk_user) "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (datec, fk_soc, name, fk_user) ";
@ -58,15 +58,15 @@ class Contact
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
$id = $this->db->last_insert_id(); $id = $this->db->last_insert_id();
$this->update($id, $user); $this->update($id, $user);
return $id; return $id;
} }
else else
{ {
print $this->db->error() . '<br>' . $sql; print $this->db->error() . '<br>' . $sql;
} }
} }
/* /*
@ -74,44 +74,44 @@ class Contact
* *
*/ */
Function update($id, $user=0) Function update($id, $user=0)
{
$this->id = $id;
$this->error = array();
$this->email = trim($this->email);
$this->phone_pro = ereg_replace(" ","",$this->phone_pro);
$this->phone_perso = ereg_replace(" ","",$this->phone_perso);
if (strlen($this->phone_pro) == 0 && $this->socid > 0)
{ {
$soc = new Societe($this->db); $this->id = $id;
$soc->fetch($this->socid); $this->error = array();
$this->phone_pro = $soc->tel;
}
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET name='$this->name', firstname='$this->firstname'"; $this->email = trim($this->email);
$sql .= ", poste='$this->poste'";
$sql .= ", fax='$this->fax'";
$sql .= ", email='$this->email'";
$sql .= ", note='$this->note'";
$sql .= ", phone = '$this->phone_pro'";
$sql .= ", phone_perso = '$this->phone_perso'";
$sql .= ", phone_mobile = '$this->phone_mobile'";
$sql .= ", jabberid = '$this->jabberid'";
$sql .= " WHERE idp=$id";
$result = $this->db->query($sql); $this->phone_pro = ereg_replace(" ","",$this->phone_pro);
$this->phone_perso = ereg_replace(" ","",$this->phone_perso);
if (!$result) if (strlen($this->phone_pro) == 0 && $this->socid > 0)
{ {
print $this->db->error() . '<br>' . $sql; $soc = new Societe($this->db);
} $soc->fetch($this->socid);
$this->phone_pro = $soc->tel;
}
if (defined('MAIN_MODULE_LDAP') && MAIN_MODULE_LDAP) $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET name='$this->name', firstname='$this->firstname'";
{ $sql .= ", poste='$this->poste'";
$this->update_ldap($user); $sql .= ", fax='$this->fax'";
} $sql .= ", email='$this->email'";
$sql .= ", note='$this->note'";
$sql .= ", phone = '$this->phone_pro'";
$sql .= ", phone_perso = '$this->phone_perso'";
$sql .= ", phone_mobile = '$this->phone_mobile'";
$sql .= ", jabberid = '$this->jabberid'";
$sql .= " WHERE idp=$id";
$result = $this->db->query($sql);
if (!$result)
{
print $this->db->error() . '<br>' . $sql;
}
if (defined('MAIN_MODULE_LDAP') && MAIN_MODULE_LDAP)
{
$this->update_ldap($user);
}
return $result; return $result;
} }
/* /*
@ -123,47 +123,48 @@ class Contact
$this->fetch($this->id); $this->fetch($this->id);
$ds = dolibarr_ldap_connect(); $ds = dolibarr_ldap_connect();
if ($ds) if ($ds)
{ {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); dolibarr_ldap_setversion($ds,$version);
$ldapbind = dolibarr_ldap_bind($ds);
if ($ldapbind) $ldapbind = dolibarr_ldap_bind($ds);
{
$info["cn"] = utf8_encode($this->firstname." ".$this->name);
$info["sn"] = utf8_encode($this->name);
$info["ou"] = "People";
if ($this->email) if ($ldapbind)
$info["rfc822Mailbox"] = $this->email; {
$info["cn"] = utf8_encode($this->firstname." ".$this->name);
if ($this->phone_pro) $info["sn"] = utf8_encode($this->name);
$info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro); $info["ou"] = People;
if ($this->phone_mobile)
$info["mobile"] = dolibarr_print_phone($this->phone_mobile);
if ($this->phone_perso)
$info["homePhone"] = dolibarr_print_phone($this->phone_perso);
if ($this->poste)
$info["title"] = utf8_encode($this->poste);
if ($this->socid > 0) if ($this->email)
{ $info["rfc822Mailbox"] = $this->email;
$soc = new Societe($this->db);
$soc->fetch($this->socid);
$info["o"] = utf8_encode($soc->nom);
if ($soc->ville)
{
$info["l"] = utf8_encode($soc->ville);
}
}
$info["objectclass"][0] = "organizationalPerson"; if ($this->phone_pro)
$info["objectclass"][1] = "inetOrgPerson"; $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro);
if ($this->phone_mobile)
$info["mobile"] = dolibarr_print_phone($this->phone_mobile);
if ($this->phone_perso)
$info["homePhone"] = dolibarr_print_phone($this->phone_perso);
if ($this->poste)
$info["title"] = utf8_encode($this->poste);
if ($this->socid > 0)
{
$soc = new Societe($this->db);
$soc->fetch($this->socid);
$info["o"] = utf8_encode($soc->nom);
if ($soc->ville)
{
$info["l"] = utf8_encode($soc->ville);
}
}
$info["objectclass"][0] = "organizationalPerson";
$info["objectclass"][1] = "inetOrgPerson";
// $info["objectclass"][2] = "phpgwContact"; // compatibilite egroupware // $info["objectclass"][2] = "phpgwContact"; // compatibilite egroupware
// $info['uidnumber'] = $this->id; // $info['uidnumber'] = $this->id;
@ -172,36 +173,39 @@ class Contact
// $info['phpgwMailType'] = 'INTERNET'; // $info['phpgwMailType'] = 'INTERNET';
// $info['phpgwMailHomeType'] = 'INTERNET'; // $info['phpgwMailHomeType'] = 'INTERNET';
$info["uid"] = $this->id. ":".$info["sn"]; $info["uid"] = $this->id. ":".$info["sn"];
// $info["phpgwContactTypeId"] = 'n'; // $info["phpgwContactTypeId"] = 'n';
// $info["phpgwContactCatId"] = 0; // $info["phpgwContactCatId"] = 0;
// $info["phpgwContactAccess"] = "public"; // $info["phpgwContactAccess"] = "public";
// $info["phpgwContactOwner"] = $user->egroupware_id; // $info["phpgwContactOwner"] = $user->egroupware_id;
$info["givenName"] = utf8_encode($this->firstname); $info["givenName"] = utf8_encode($this->firstname);
// if ($this->phone_mobile) // if ($this->phone_mobile)
// $info["phpgwCellTelephoneNumber"] = dolibarr_print_phone($this->phone_mobile); // $info["phpgwCellTelephoneNumber"] = dolibarr_print_phone($this->phone_mobile);
//$dn = "uid=".$info["uid"].","."cn=".$info["cn"].", ".LDAP_SERVER_DN ; //$dn = "uid=".$info["uid"].","."cn=".$info["cn"].", ".LDAP_SERVER_DN ;
//$dn = "cn=".$info["cn"].", ".LDAP_SERVER_DN ;
$r = @ldap_delete($ds, LDAP_SERVER_DN); $dn = "cn=".$info["cn"].","."ou=".$info["ou"].", ".LDAP_SERVER_DN_SHORT ;
if (! ldap_add($ds, $dn, $info)) $r = @ldap_delete($ds, $dn);
{
$this->error[0] = ldap_err2str(ldap_errno($ds)); if (! ldap_add($ds, $dn, $info))
var_dump($info); {
} $this->error[0] = ldap_err2str(ldap_errno($ds));
} var_dump($info);
else }
{ }
echo "LDAP bind failed..."; else
} {
ldap_close($ds); echo "Connection au dn $dn échoué !";
} }
dolibarr_ldap_unbind($ds);
}
else else
{ {
echo "Unable to connect to LDAP server"; echo "Impossible de se connecter au serveur LDAP !";
} }
} }