From 2a59cf8433db982c4bafdf04ae11336b5910dfb4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Nov 2006 04:56:10 +0000 Subject: [PATCH] New: On ajout un onglet LDAP sur fiches contacts pour voir a quoi ressemble le contact dans la base LDAP. --- htdocs/admin/ldap_contacts.php | 33 +++++- htdocs/contact.class.php | 189 +++++++++++--------------------- htdocs/contact/exportimport.php | 25 +---- htdocs/contact/fiche.php | 112 +++++++++---------- htdocs/contact/info.php | 23 +--- htdocs/contact/ldap.php | 4 +- htdocs/contact/perso.php | 26 +---- htdocs/html.form.class.php | 40 +++++++ htdocs/langs/en_US/admin.lang | 8 +- htdocs/langs/fr_BE/admin.lang | 6 +- htdocs/langs/fr_FR/admin.lang | 12 +- htdocs/langs/fr_FR/ldap.lang | 5 +- htdocs/lib/authldap.lib.php | 86 +++++++++------ htdocs/lib/contact.lib.php | 69 ++++++++++++ 14 files changed, 354 insertions(+), 284 deletions(-) create mode 100644 htdocs/lib/contact.lib.php diff --git a/htdocs/admin/ldap_contacts.php b/htdocs/admin/ldap_contacts.php index 57947006c89..49dedce1a1c 100644 --- a/htdocs/admin/ldap_contacts.php +++ b/htdocs/admin/ldap_contacts.php @@ -43,7 +43,7 @@ if (!$user->admin) /* * Actions */ - + if ($_GET["action"] == 'setvalue' && $user->admin) { $error=0; @@ -52,8 +52,11 @@ if ($_GET["action"] == 'setvalue' && $user->admin) if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',$_POST["fieldfirstname"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_MAIL',$_POST["fieldmail"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_PHONE',$_POST["fieldphone"])) $error++; - if (! dolibarr_set_const($db, 'LDAP_FIELD_FAX',$_POST["fieldfax"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_MOBILE',$_POST["fieldmobile"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_FAX',$_POST["fieldfax"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_ADDRESS',$_POST["fieldaddress"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_ZIP',$_POST["fieldzip"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_TOWN',$_POST["fieldtown"])) $error++; if ($error) { @@ -158,17 +161,35 @@ print ''.$langs->trans("LDAPFieldPhone").''; print ''; print ''.$langs->trans("LDAPFieldPhoneExample").''; +// Mobile +$var=!$var; +print ''.$langs->trans("LDAPFieldMobile").''; +print ''; +print ''.$langs->trans("LDAPFieldMobileExample").''; + // Fax $var=!$var; print ''.$langs->trans("LDAPFieldFax").''; print ''; print ''.$langs->trans("LDAPFieldFaxExample").''; -// Mobile +// Address $var=!$var; -print ''.$langs->trans("LDAPFieldMobile").''; -print ''; -print ''.$langs->trans("LDAPFieldMobileExample").''; +print ''.$langs->trans("LDAPFieldAddress").''; +print ''; +print ''.$langs->trans("LDAPFieldAddressExample").''; + +// CP +$var=!$var; +print ''.$langs->trans("LDAPFieldZip").''; +print ''; +print ''.$langs->trans("LDAPFieldZipExample").''; + +// Ville +$var=!$var; +print ''.$langs->trans("LDAPFieldTown").''; +print ''; +print ''.$langs->trans("LDAPFieldTownExample").''; $var=!$var; diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index fcbaad2c0f1..94d8016b3b1 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -53,7 +53,7 @@ class Contact var $cp; var $ville; var $fk_pays; - var $fk_soc; + var $socid; // fk_soc var $code; var $email; @@ -86,7 +86,7 @@ class Contact { // Nettoyage parametres $this->name=trim($this->name); - if (! $this->socid)$this->socid = 0; + if (! $this->socid) $this->socid = 0; $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (datec, fk_soc, name, fk_user)"; $sql.= " VALUES (now(),"; @@ -290,148 +290,91 @@ class Contact { if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') { - // Pas de conversion utf8 pour etre compatible Windows $info["objectclass"]=array("top", "person", "organizationalPerson", "user"); - - // Champs obligatoires - $info["cn"] = trim($this->firstname." ".$this->name); - if ($this->name) $info[$conf->global->LDAP_FIELD_NAME] = $this->name; - else - { - $langs->load("other"); - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name")); - return -1; - } - - // Champs optionnels - if ($this->firstname && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = utf8_encode($this->firstname); - if ($this->poste) $info["title"] = $this->poste; - if ($this->socid > 0) - { - $soc = new Societe($this->db); - $soc->fetch($this->socid); - $info["o"] = $soc->nom; - $info["company"] = $soc->nom; - - if ($soc->client == 1) - { - $info["businessCategory"] = "Customers"; - } - elseif ($soc->client == 2) - { - $info["businessCategory"] = "Prospects"; - } - - if ($soc->fournisseur == 1) - { - $info["businessCategory"] = "Suppliers"; - } - - if ($soc->ville) - { - if ($soc->adresse) - { - $info["streetAddress"] = $soc->adresse; - } - if ($soc->cp) - { - $info["postalCode"] = $soc->cp; - } - - $info["l"] = $soc->ville; - } - } - if ($this->phone_pro && $conf->global->LDAP_FIELD_PHONE) $info[$conf->global->LDAP_FIELD_PHONE] = $this->phone_pro; - if ($this->phone_perso) $info["homePhone"] = $this->phone_perso; - if ($this->phone_mobile && $conf->global->LDAP_FIELD_MOBILE) $info[$conf->global->LDAP_FIELD_MOBILE] = $this->phone_mobile; - if ($this->fax && $conf->global->LDAP_FIELD_FAX) $info[$conf->global->LDAP_FIELD_FAX] = $this->fax; - if ($this->note) $info["description"] = $this->note; - if ($this->email && $conf->global->LDAP_FIELD_MAIL) $info[$conf->global->LDAP_FIELD_MAIL] = $this->email; } else { - // OpenLDAP. On encode les param en utf8 $info["objectclass"]=array("top", "person", "organizationalPerson", "inetOrgPerson"); - - // Champs obligatoires - $info["cn"] = utf8_encode(trim($this->firstname." ".$this->name)); - if ($this->name) $info[$conf->global->LDAP_FIELD_NAME] = utf8_encode($this->name); - else - { - $langs->load("other"); - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name")); - return -1; - } - - // Champs optionnels - if ($this->firstname && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = utf8_encode($this->firstname); - 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); + // Champs obligatoires + $info["cn"] = trim($this->firstname." ".$this->name); + if ($this->name) $info[$conf->global->LDAP_FIELD_NAME] = $this->name; + else + { + $langs->load("other"); + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name")); + return -1; + } + + // Champs optionnels + if ($this->firstname && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = $this->firstname; + if ($this->poste) $info["title"] = $this->poste; + if ($this->socid > 0) + { + $soc = new Societe($this->db); + $soc->fetch($this->socid); - if ($soc->client == 1) $info["businessCategory"] = utf8_encode("Customers"); - if ($soc->client == 2) $info["businessCategory"] = utf8_encode("Prospects"); - if ($soc->fournisseur == 1) $info["businessCategory"] = utf8_encode("Suppliers"); - if ($soc->adresse) $info["street"] = utf8_encode($soc->adresse); - if ($soc->cp) $info["postalCode"] = utf8_encode($soc->cp); - if ($soc->ville) $info["l"] = utf8_encode($soc->ville); - } - if ($this->phone_pro && $conf->global->LDAP_FIELD_PHONE) $info[$conf->global->LDAP_FIELD_PHONE] = utf8_encode($this->phone_pro); - if ($this->phone_perso) $info["homePhone"] = utf8_encode($this->phone_perso); - if ($this->phone_mobile && $conf->global->LDAP_FIELD_MOBILE) $info[$conf->global->LDAP_FIELD_MOBILE] = utf8_encode($this->phone_mobile); - if ($this->fax && $conf->global->LDAP_FIELD_FAX) $info[$conf->global->LDAP_FIELD_FAX] = utf8_encode($this->fax); - if ($this->note) $info["description"] = utf8_encode($this->note); - if ($this->email && $conf->global->LDAP_FIELD_MAIL) $info[$conf->global->LDAP_FIELD_MAIL] = utf8_encode($this->email); + $info["o"] = $soc->nom; + if ($soc->client == 1) $info["businessCategory"] = "Customers"; + if ($soc->client == 2) $info["businessCategory"] = "Prospects"; + if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers"; + } + if ($this->address && $conf->global->LDAP_FIELD_ADDRESS) $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address; + if ($this->cp && $conf->global->LDAP_FIELD_ZIP) $info[$conf->global->LDAP_FIELD_ZIP] = $this->cp; + if ($this->ville && $conf->global->LDAP_FIELD_TOWN) $info[$conf->global->LDAP_FIELD_TOWN] = $this->ville; + if ($this->phone_pro && $conf->global->LDAP_FIELD_PHONE) $info[$conf->global->LDAP_FIELD_PHONE] = $this->phone_pro; + if ($this->phone_perso) $info["homePhone"] = $this->phone_perso; + if ($this->phone_mobile && $conf->global->LDAP_FIELD_MOBILE) $info[$conf->global->LDAP_FIELD_MOBILE] = $this->phone_mobile; + if ($this->fax && $conf->global->LDAP_FIELD_FAX) $info[$conf->global->LDAP_FIELD_FAX] = $this->fax; + if ($this->note) $info["description"] = $this->note; + if ($this->email && $conf->global->LDAP_FIELD_MAIL) $info[$conf->global->LDAP_FIELD_MAIL] = $this->email; - if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') + if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') + { + $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware + + $info['uidnumber'] = $this->id; + + $info['phpgwTz'] = 0; + $info['phpgwMailType'] = 'INTERNET'; + $info['phpgwMailHomeType'] = 'INTERNET'; + + $info["phpgwContactTypeId"] = 'n'; + $info["phpgwContactCatId"] = 0; + $info["phpgwContactAccess"] = "public"; + + if (strlen($user->egroupware_id) == 0) { - $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware - - if ($this->email) $info["rfc822Mailbox"] = $this->email; - - $info['uidnumber'] = $this->id; - - $info['phpgwTz'] = 0; - $info['phpgwMailType'] = 'INTERNET'; - $info['phpgwMailHomeType'] = 'INTERNET'; - - $info["phpgwContactTypeId"] = 'n'; - $info["phpgwContactCatId"] = 0; - $info["phpgwContactAccess"] = "public"; - - if (strlen($user->egroupware_id) == 0) - { - $user->egroupware_id = 1; - } - - $info["phpgwContactOwner"] = $user->egroupware_id; - - if ($this->phone_mobile) - $info["phpgwCellTelephoneNumber"] = dolibarr_print_phone($this->phone_mobile); + $user->egroupware_id = 1; } - $info["uid"] = "Dolibarr ".$this->id. ": ".utf8_encode(trim($this->firstname." ".$this->name)); - + $info["phpgwContactOwner"] = $user->egroupware_id; + + if ($this->email) $info["rfc822Mailbox"] = $this->email; + if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile; } + $info["uid"] = "Dolibarr ".$this->id. ": ".trim($this->firstname." ".$this->name); + + $newdn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN; + $olddn = $newdn; + if ($this->old_firstname || $this->old_name) $olddn="cn=".trim($this->old_firstname." ".$this->old_name).",".$conf->global->LDAP_CONTACT_DN; + // On supprime et on insère - $dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN; - dolibarr_syslog("Contact.class::update_ldap dn=".$dn." info=".$info); - $result = $ldap->delete($dn); - $result = $ldap->add($dn, $info); + dolibarr_syslog("Contact.class::update_ldap olddn=".$olddn." newdn=".$newdn); + + $result = $ldap->delete($olddn); + $result = $ldap->add($newdn, $info); if ($result <= 0) { - $this->error = $ldap->error." ".ldap_errno($ldap->connection)." ".ldap_error($ldap->connection); + $this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error; dolibarr_syslog("Contact.class::update_ldap ".$this->error); //print_r($info); return -1; @@ -874,7 +817,7 @@ class Contact $this->fk_pays = 1; $this->email = 'specimen@specimen.com'; $socid = rand(1, $num_socs); - $this->fk_soc = $socids[$socid]; + $this->socid = $socids[$socid]; } } diff --git a/htdocs/contact/exportimport.php b/htdocs/contact/exportimport.php index c1acc782401..01eb9e9e04b 100644 --- a/htdocs/contact/exportimport.php +++ b/htdocs/contact/exportimport.php @@ -29,6 +29,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/contact.lib.php"); $user->getrights('commercial'); @@ -80,26 +81,12 @@ $contact = new Contact($db); $contact->fetch($_GET["id"], $user); -$h=0; +/* + * Affichage onglets + */ +$head = contact_prepare_head($contact); -$head[$h][0] = DOL_URL_ROOT.'/contact/fiche.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("General"); -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("PersonalInformations"); -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/contact/exportimport.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("ExportImport"); -$hselected=$h; -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/contact/info.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("Info"); -$h++; - -dolibarr_fiche_head($head, $hselected, $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); +dolibarr_fiche_head($head, 'exportimport', $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); /* diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 429fa697c57..a767657c695 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -32,7 +32,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/actioncomm.class.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); -require_once(DOL_DOCUMENT_ROOT."/lib/vcard/vcard.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/contact.lib.php"); $langs->load("companies"); $langs->load("users"); @@ -63,7 +63,7 @@ if ($contactid && !$user->rights->commercial->client->voir) $sql .= " AND sc.fk_soc = sp.fk_soc AND sc.fk_user = ".$user->id; } if ($user->societe_id > 0) $sql .= " AND sp.fk_soc = ".$socid; - + if ( $db->query($sql) ) { if ( $db->num_rows() == 0) accessforbidden(); @@ -77,7 +77,7 @@ if ($user->rights->societe->contact->creer) // Recuperation contact actuel $contact = new Contact($db); $result = $contact->fetch($_GET["id"]); - + // Creation user $nuser = new User($db); $nuser->nom = $contact->name; @@ -149,40 +149,45 @@ if ($user->rights->societe->contact->supprimer) if ($user->rights->societe->contact->creer) { - if ($_POST["action"] == 'update') - { - $contact = new Contact($db); - - $contact->old_name = $_POST["old_name"]; - $contact->old_firstname = $_POST["old_firstname"]; - - $contact->socid = $_POST["socid"]; - $contact->name = $_POST["name"]; - $contact->firstname = $_POST["firstname"]; - $contact->civilite_id = $_POST["civilite_id"]; - $contact->poste = $_POST["poste"]; - - $contact->address = $_POST["address"]; - $contact->cp = $_POST["cp"]; - $contact->ville = $_POST["ville"]; - $contact->fk_pays = $_POST["pays_id"]; - - $contact->email = $_POST["email"]; - $contact->phone_pro = $_POST["phone_pro"]; - $contact->phone_perso = $_POST["phone_perso"]; - $contact->phone_mobile = $_POST["phone_mobile"]; - $contact->fax = $_POST["fax"]; - $contact->jabberid = $_POST["jabberid"]; - - $contact->note = $_POST["note"]; - - $result = $contact->update($_POST["contactid"], $user); - - if ($contact->error) - { - $error = $contact->error; - } - } + if ($_POST["action"] == 'update' && ! $_POST["cancel"]) + { + $contact = new Contact($db); + + $contact->old_name = $_POST["old_name"]; + $contact->old_firstname = $_POST["old_firstname"]; + + $contact->socid = $_POST["socid"]; + $contact->name = $_POST["name"]; + $contact->firstname = $_POST["firstname"]; + $contact->civilite_id = $_POST["civilite_id"]; + $contact->poste = $_POST["poste"]; + + $contact->address = $_POST["address"]; + $contact->cp = $_POST["cp"]; + $contact->ville = $_POST["ville"]; + $contact->fk_pays = $_POST["pays_id"]; + + $contact->email = $_POST["email"]; + $contact->phone_pro = $_POST["phone_pro"]; + $contact->phone_perso = $_POST["phone_perso"]; + $contact->phone_mobile = $_POST["phone_mobile"]; + $contact->fax = $_POST["fax"]; + $contact->jabberid = $_POST["jabberid"]; + + $contact->note = $_POST["note"]; + + $result = $contact->update($_POST["contactid"], $user); + + if ($result > 0) + { + $contact->old_name=''; + $contact->old_firstname=''; + } + else + { + $error = $contact->error; + } + } } @@ -215,25 +220,12 @@ if ($_GET["id"] > 0) dolibarr_print_error('',$contact->error); } - $h=0; - $head[$h][0] = DOL_URL_ROOT.'/contact/fiche.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("General"); - $hselected=$h; - $h++; + /* + * Affichage onglets + */ + $head = contact_prepare_head($contact); - $head[$h][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("PersonalInformations"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/contact/exportimport.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("ExportImport"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/contact/info.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("Info"); - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); + dolibarr_fiche_head($head, 'general', $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); } @@ -456,7 +448,11 @@ if ($user->rights->societe->contact->creer) else print $langs->trans("NoDolibarrAccess"); print ''; - print ''; + print ''; + print ''; + print '   '; + print ''; + print ''; print ''; print ""; @@ -686,7 +682,7 @@ if ($_GET["id"] && $_GET["action"] != 'edit') print ''.$langs->trans("Author").''; print ''.$langs->trans("Status").''; print ''; - + foreach ($histo as $key=>$value) { $var=!$var; @@ -732,7 +728,7 @@ if ($_GET["id"] && $_GET["action"] != 'edit') $actionstatic=new ActionComm($db); print $actionstatic->LibStatut($histo[$key]['percent'],5); print ''; - + print "\n"; } print ""; diff --git a/htdocs/contact/info.php b/htdocs/contact/info.php index 38637df57ea..6109d40d0b8 100644 --- a/htdocs/contact/info.php +++ b/htdocs/contact/info.php @@ -30,6 +30,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/contact.lib.php"); $user->getrights('commercial'); @@ -79,25 +80,13 @@ $contact = new Contact($db); $contact->fetch($_GET["id"], $user); -$h=0; -$head[$h][0] = DOL_URL_ROOT.'/contact/fiche.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("General"); -$h++; +/* + * Affichage onglets + */ +$head = contact_prepare_head($contact); -$head[$h][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("PersonalInformations"); -$h++; +dolibarr_fiche_head($head, 'info', $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); -$head[$h][0] = DOL_URL_ROOT.'/contact/exportimport.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("ExportImport"); -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/contact/info.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("Info"); -$hselected=$h; -$h++; - -dolibarr_fiche_head($head, $hselected, $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); /* * Visualisation de la fiche diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php index badcdf766f3..6f4d55366b5 100644 --- a/htdocs/contact/ldap.php +++ b/htdocs/contact/ldap.php @@ -144,12 +144,12 @@ if ($result) $bind=''; if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS) { - dolibarr_syslog("Contact.class::delete_ldap authBind user=".$conf->global->LDAP_ADMIN_DN,LOG_DEBUG); + dolibarr_syslog("ldap.php: authBind user=".$conf->global->LDAP_ADMIN_DN,LOG_DEBUG); $bind=$ldap->authBind($conf->global->LDAP_ADMIN_DN,$conf->global->LDAP_ADMIN_PASS); } else { - dolibarr_syslog("Contact.class::delete_ldap bind",LOG_DEBUG); + dolibarr_syslog("ldap.php: bind",LOG_DEBUG); $bind=$ldap->bind(); } diff --git a/htdocs/contact/perso.php b/htdocs/contact/perso.php index 5bdca60e4ab..dbfc818f64c 100644 --- a/htdocs/contact/perso.php +++ b/htdocs/contact/perso.php @@ -29,7 +29,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); -require_once(DOL_DOCUMENT_ROOT."/lib/vcard/vcard.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/contact.lib.php"); $user->getrights('commercial'); @@ -103,27 +103,13 @@ $form = new Form($db); $contact = new Contact($db); $contact->fetch($_GET["id"], $user); +/* + * Affichage onglets + */ +$head = contact_prepare_head($contact); -$h=0; +dolibarr_fiche_head($head, 'perso', $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); -$head[$h][0] = DOL_URL_ROOT.'/contact/fiche.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("General"); -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("PersonalInformations"); -$hselected=$h; -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/contact/exportimport.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("ExportImport"); -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/contact/info.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("Info"); -$h++; - -dolibarr_fiche_head($head, $hselected, $langs->trans("Contact").": ".$contact->firstname.' '.$contact->name); if ($_GET["action"] == 'edit') diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index ab14dcb0685..3d4555ee897 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -2716,6 +2716,46 @@ class Form return $i; } + + function show_ldap_content($result,$level,$count,$var) + { + global $bc; + + $count++; + if ($count > 1000) return; // To avoid infinite loop + + foreach($result as $key => $val) + { + if ("$key" == "objectclass") continue; + if ("$key" == "count") continue; + if ("$key" == "dn") continue; + + if ("$val" == "objectclass") continue; + if ("$val" == $lastkey[$level]) continue; + + $lastkey[$level]=$key; + + if (is_array($val)) + { + if (! is_numeric($key)) + { + $var=!$var; + print ''; + print $key; + print ''; + } + $this->show_ldap_content($val,$level+1,$count,$var); + } + else + { + print utf8_decode("$val"); + //print "
\n"; + print ''; + } + } + return 1; + } + } ?> diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 636b68808b0..cec098e45a3 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -553,7 +553,7 @@ LDAPFieldName=Name LDAPFieldNameExample=Suggested value : sn LDAPFieldFirstName=Firstname LDAPFieldFirstNameExample=Suggested value : givenname -LDAPFieldMail=E-Mail address +LDAPFieldMail=Email address LDAPFieldMailExample=Suggested value : mail LDAPFieldPhone=Phone number LDAPFieldPhoneExample=Suggested value : telephonenumber @@ -561,6 +561,12 @@ LDAPFieldFax=Fax number LDAPFieldFaxExample=Suggested value : facsimiletelephonenumber LDAPFieldMobile=Cellular phone LDAPFieldMobileExample=Suggested value : mobile +LDAPFieldAddress=Street +LDAPFieldAddressExample=Valeur recommandée : street +LDAPFieldZip=Zip +LDAPFieldZipExample=Valeur recommandée : postalcode +LDAPFieldTown=Town +LDAPFieldTownExample=Valeur recommandée : l LDAPParametersAreStillHardCoded=LDAP parametres are still hardcoded (in contact class) LDAPSetupNotComplete=LDAP setup not complete (go on others tabs) LDAPNoUserOrPasswordProvidedAccessIsReadOnly=No administrator or password provided. LDAP access will be anonymous and in read only mode. diff --git a/htdocs/langs/fr_BE/admin.lang b/htdocs/langs/fr_BE/admin.lang index b120c33dffd..5f9198a6c7a 100644 --- a/htdocs/langs/fr_BE/admin.lang +++ b/htdocs/langs/fr_BE/admin.lang @@ -525,11 +525,11 @@ LDAPFieldName=Non LDAPFieldNameExample=Attribut par défaut : sn LDAPFieldFirstName=Prénom LDAPFieldFirstNameExample=Attribut par défaut: givenname -LDAPFieldMail=Adresse e-mail +LDAPFieldMail=Email LDAPFieldMailExample=Attribut par défaut: mail -LDAPFieldPhone=Numéro de téléphone +LDAPFieldPhone=Téléphone LDAPFieldPhoneExample=Attribut par défaut: telephonenumber -LDAPFieldFax=Numéro de fax +LDAPFieldFax=Fax LDAPFieldFaxExample=Attribut par défaut: facsimiletelephonenumber LDAPFieldMobile=Téléphone cellulaire LDAPFieldMobileExample=Attribut par défault: mobile diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index b3cd803d905..5bccca9ff75 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -553,14 +553,20 @@ LDAPFieldName=Nom LDAPFieldNameExample=Valeur recommandée : sn LDAPFieldFirstName=Prénom LDAPFieldFirstNameExample=Valeur recommandée : givenname -LDAPFieldMail=Adresse E-Mail +LDAPFieldMail=Email LDAPFieldMailExample=Valeur recommandée : mail -LDAPFieldPhone=Numéro de téléphone +LDAPFieldPhone=Téléphone LDAPFieldPhoneExample=Valeur recommandée : telephonenumber -LDAPFieldFax=Numéro de fax +LDAPFieldFax=Fax LDAPFieldFaxExample=Valeur recommandée : facsimiletelephonenumber LDAPFieldMobile=Téléphone portable LDAPFieldMobileExample=Valeur recommandée : mobile +LDAPFieldAddress=Adresse +LDAPFieldAddressExample=Valeur recommandée : street +LDAPFieldZip=Code postal +LDAPFieldZipExample=Valeur recommandée : postalcode +LDAPFieldTown=Ville +LDAPFieldTownExample=Valeur recommandée : l LDAPParametersAreStillHardCoded=Les parametres LDAP sont codés en dur (dans classe contact) LDAPSetupNotComplete=Configuration LDAP incomplète (à compléter sur les autres onglets) LDAPNoUserOrPasswordProvidedAccessIsReadOnly=Administrateur ou mot de passe non renseigné. Les accès LDAP seront donc anonymes et en lecture seule. diff --git a/htdocs/langs/fr_FR/ldap.lang b/htdocs/langs/fr_FR/ldap.lang index e0925ce956d..9e7c8d77146 100644 --- a/htdocs/langs/fr_FR/ldap.lang +++ b/htdocs/langs/fr_FR/ldap.lang @@ -3,4 +3,7 @@ DomainPassword=Mot de passe du domaine UserMustChangePassNextLogon=L'utilisateur doit changer de mot de passe à la prochaine connexion LdapUacf_NORMAL_ACCOUNT=Compte Utilisateur LdapUacf_DONT_EXPIRE_PASSWORD=Le mot de passe n'expire jamais -LdapUacf_ACCOUNTDISABLE=Le compte est désactivé sur le domaine \ No newline at end of file +LdapUacf_ACCOUNTDISABLE=Le compte est désactivé sur le domaine +LDAPInformationsForThisContact=Informations en base LDAP pour ce contact +LDAPInformationsForThisUser=Informations en base LDAP pour cet utilisateur +LDAPAttribute=Attribut diff --git a/htdocs/lib/authldap.lib.php b/htdocs/lib/authldap.lib.php index 254cbd2f5d1..02ca9917d4a 100644 --- a/htdocs/lib/authldap.lib.php +++ b/htdocs/lib/authldap.lib.php @@ -108,7 +108,8 @@ class AuthLdap { * Constructor- creates a new instance of the authentication class * */ - function AuthLdap () { + function AuthLdap () + { global $conf; //Server @@ -431,8 +432,21 @@ class AuthLdap { */ function add($dn, $info) { - dolibarr_syslog("authldap::add Add LDAP entry dn=".$dn); - + global $conf; + + // Encode en UTF8 + if ($conf->global->LDAP_SERVER_TYPE != 'activedirectory') + { + $dn=utf8_encode($dn); + foreach($info as $key => $val) + { + if (! is_array($val)) $info[$key]=utf8_encode($val); + } + } + + dolibarr_syslog("authldap::add dn=".$dn); + dolibarr_syslog("authldap::add info=".join(',',$info)); + //print_r($info); $result=@ldap_add($this->connection, $dn, $info); @@ -447,6 +461,14 @@ class AuthLdap { */ function delete($dn) { + global $conf; + + // Encode en UTF8 + if ($conf->global->LDAP_SERVER_TYPE != 'activedirectory') + { + $dn=utf8_encode($dn); + } + dolibarr_syslog("authldap::delete Delete LDAP entry dn=".$dn); $result=@ldap_delete($this->connection, $dn); @@ -456,6 +478,7 @@ class AuthLdap { } + // 2.4 Attribute methods ----------------------------------------------------- /** * 2.4.1 : Returns an array containing a set of attribute values. @@ -625,36 +648,37 @@ class AuthLdap { return $result; } - /** - * \brief fonction de recherche avec filtre - * \param dn de recherche - * \param filtre de recherche (ex: sn=nom_personne) - */ - function search( $checkDn, $filter) { + /** + * \brief fonction de recherche avec filtre + * \param dn de recherche + * \param filtre de recherche (ex: sn=nom_personne) + */ + function search( $checkDn, $filter) { + + // Perform the search and get the entry handles + + // if the directory is AD, then bind first with the search user first + if ($this->serverType == "activedirectory") { + $this->authBind($this->searchUser, $this->searchPassword); + } + + $this->result = @ldap_search( $this->connection, $checkDn, $filter); + + $result = @ldap_get_entries( $this->connection, $this->result); + + if (!$result) + { + $this->ldapErrorCode = ldap_errno( $this->connection); + $this->ldapErrorText = ldap_error( $this->connection); + } + else + { + ldap_free_result($this->result); + return $result; + } + } - // Perform the search and get the entry handles - - // if the directory is AD, then bind first with the search user first - if ($this->serverType == "activedirectory") { - $this->authBind($this->searchUser, $this->searchPassword); - } - - $this->result = @ldap_search( $this->connection, $checkDn, $filter); - - $result = @ldap_get_entries( $this->connection, $this->result); - if (!$result) - { - $this->ldapErrorCode = ldap_errno( $this->connection); - $this->ldapErrorText = ldap_error( $this->connection); - } - else - { - ldap_free_result($this->result); - return $result; - } - } - /** * \brief récupère les attributs de l'utilisateur * \param $user : utilisateur ldap diff --git a/htdocs/lib/contact.lib.php b/htdocs/lib/contact.lib.php new file mode 100644 index 00000000000..c0328381212 --- /dev/null +++ b/htdocs/lib/contact.lib.php @@ -0,0 +1,69 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/lib/contact.lib.php + \brief Ensemble de fonctions de base pour les contacts + \version $Revision$ + + Ensemble de fonctions de base de dolibarr sous forme d'include +*/ + +function contact_prepare_head($contrat) +{ + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/contact/fiche.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("General"); + $head[$h][2] = 'general'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("PersonalInformations"); + $head[$h][2] = 'perso'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/contact/exportimport.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("ExportImport"); + $head[$h][2] = 'exportimport'; + $h++; + + if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE) + { + $head[$h][0] = DOL_URL_ROOT.'/contact/ldap.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("LDAP"); + $head[$h][2] = 'ldap'; + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/contact/info.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; + + return $head; +} + +?> \ No newline at end of file