diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php
index 2aa8c4bceff1122f0ae38f2db87d9716a4316724..05be6c0643f2f36a2967656bd1d57f2e22403919 100644
--- a/htdocs/adherents/adherent.class.php
+++ b/htdocs/adherents/adherent.class.php
@@ -517,8 +517,9 @@ class Adherent
 
 
     /**
-    		\brief fonction qui r�cup�re l'adh�rent en donnant son rowid
-    		\param	rowid
+    		\brief 		Fonction qui r�cup�re l'adh�rent en donnant son rowid
+    		\param		rowid
+    		\return		int			<0 si KO, >0 si OK
     */
     function fetch($rowid)
     {
@@ -531,13 +532,14 @@ class Adherent
         $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
         $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON d.pays = p.rowid";
         $sql.= " WHERE d.rowid = ".$rowid." AND d.fk_adherent_type = t.rowid";
-
-        $result=$this->db->query( $sql);
-        if ($result)
+		dolibarr_syslog("Adherent.class::fetch sql=".$sql);
+		
+        $resql=$this->db->query($sql);
+        if ($resql)
         {
-            if ($this->db->num_rows($result))
+            if ($this->db->num_rows($resql))
             {
-                $obj = $this->db->fetch_object($result);
+                $obj = $this->db->fetch_object($resql);
 
                 $this->id             = $obj->rowid;
                 $this->statut         = $obj->statut;
@@ -568,12 +570,13 @@ class Adherent
                 $this->type           = $obj->type;
                 $this->need_subscription = ($obj->cotisation=='yes'?1:0);
             }
+			return 1;
         }
         else
         {
-            dolibarr_print_error($this->db);
+            $this->error=$this->db->error();
+			return -1;
         }
-
     }
 
 
diff --git a/htdocs/adherents/adherent_type.class.php b/htdocs/adherents/adherent_type.class.php
index 2f7bcf7e6be1f3f0c1f8abe0d7737f9b9819ba59..c44a0b9f4bf40ae10bb42407b47f6827ab80f78c 100644
--- a/htdocs/adherents/adherent_type.class.php
+++ b/htdocs/adherents/adherent_type.class.php
@@ -159,39 +159,43 @@ class AdherentType
   }
 
 	/**
-		\brief fonction qui permet de r�cup�rer le status de l'adh�rent
-		\param rowid
-*/
-
+		\brief 		Fonction qui permet de r�cup�rer le status de l'adh�rent
+		\param 		rowid
+		\return		int			<0 si KO, >0 si OK
+	*/
 	function fetch($rowid)
-  {
-    $sql = "SELECT d.rowid, d.libelle, d.statut, d.cotisation, d.mail_valid, d.note, d.vote";
-    $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
-    $sql .= " WHERE d.rowid = $rowid";
-    
-    if ( $this->db->query( $sql) )
-    {
-        if ($this->db->num_rows())
-        {
-            $obj = $this->db->fetch_object();
-    
-            $this->id             = $obj->rowid;
-            $this->libelle        = $obj->libelle;
-            $this->statut         = $obj->statut;
-            $this->cotisation     = $obj->cotisation;
-            $this->mail_valid     = $obj->mail_valid;
-            $this->commentaire    = $obj->note;
-            $this->vote           = $obj->vote;
-        }
-    }
-    else
-    {
-        print $this->db->error();
-    }
+	{
+		$sql = "SELECT d.rowid, d.libelle, d.statut, d.cotisation, d.mail_valid, d.note, d.vote";
+		$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
+		$sql .= " WHERE d.rowid = ".$rowid;
+		dolibarr_syslog("Adherent_type::fetch sql=".$sql);
+
+		$resql=$this->db->query($sql);
+		if ($resql)
+		{
+			if ($this->db->num_rows($resql))
+			{
+				$obj = $this->db->fetch_object($resql);
+		
+				$this->id             = $obj->rowid;
+				$this->libelle        = $obj->libelle;
+				$this->statut         = $obj->statut;
+				$this->cotisation     = $obj->cotisation;
+				$this->mail_valid     = $obj->mail_valid;
+				$this->commentaire    = $obj->note;
+				$this->vote           = $obj->vote;
+			}
+			return 1;
+		}
+		else
+		{
+			$this->error=$this->db->error();
+			return -1;
+		}
+	}
 
-  }
 
-  function liste_array()
+	function liste_array()
     {
       $projets = array();
 
diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index 4edd6218ff1dc5cb8718f1bf4115f2efa4deea2f..28de40bc746e6053655842cdc6da600946975c55 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -29,6 +29,7 @@
 */
 
 require("./pre.inc.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php");
 require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php");
 require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_type.class.php");
 require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_options.class.php");
@@ -557,13 +558,21 @@ if ($action == 'create')
 
     print '<table class="border" width="100%">';
 
+    // Nom
     print '<tr><td>'.$langs->trans("Lastname").'*</td><td><input type="text" name="nom" value="'.$adh->nom.'" size="40"></td>';
     print '<td width="50%" valign="top">'.$langs->trans("Comments").' :</td></tr>';
 
+	// Prenom
     print '<tr><td>'.$langs->trans("Firstname").'*</td><td><input type="text" name="prenom" size="40" value="'.$adh->prenom.'"></td>';
     $rowspan=12;
     print '<td valign="top" rowspan="'.$rowspan.'"><textarea name="comment" wrap="soft" cols="60" rows="12"></textarea></td></tr>';
 
+	// Login
+    print '<tr><td>'.$langs->trans("Login").'*</td><td><input type="text" name="member_login" size="40" value="'.$adh->login.'"></td></tr>';
+	
+	// Mot de pass
+    print '<tr><td>'.$langs->trans("Password").'*</td><td><input type="password" name="member_pass" size="40" value="'.$adh->password.'"></td></tr>';
+
 	// Type
     print '<tr><td width="15%">'.$langs->trans("MemberType").'*</td><td width="35%">';
     $listetype=$adht->liste_array();
@@ -583,15 +592,21 @@ if ($action == 'create')
     print "</td>\n";
 
     print '<tr><td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.$adh->societe.'"></td></tr>';
+    
+    // Adresse
     print '<tr><td valign="top">'.$langs->trans("Address").'</td><td>';
     print '<textarea name="adresse" wrap="soft" cols="40" rows="2"></textarea></td></tr>';
+    
+    // CP
     print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td><input type="text" name="cp" size="8"> <input type="text" name="ville" size="32" value="'.$adh->ville.'"></td></tr>';
+
+	// Ville
     print '<tr><td>'.$langs->trans("Country").'</td><td>';
     $htmls->select_pays($adh->pays_code?$adh->pays_code:$mysoc->pays_code,'pays_code');
     print '</td></tr>';
+    
+    // EMail
     print '<tr><td>'.$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'*':'').'</td><td><input type="text" name="member_email" size="40" value="'.$adh->email.'"></td></tr>';
-    print '<tr><td>'.$langs->trans("Login").'*</td><td><input type="text" name="member_login" size="40" value="'.$adh->login.'"></td></tr>';
-    print '<tr><td>'.$langs->trans("Password").'*</td><td><input type="password" name="member_pass" size="40" value="'.$adh->password.'"></td></tr>';
 
 	// Date naissance
     print "<tr><td>".$langs->trans("Birthday")."</td><td>\n";
@@ -659,17 +674,13 @@ if ($rowid && $action != 'edit')
     $html = new Form($db);
 
 
-    /*
-     * Affichage onglets
-     */
-    $h = 0;
+	/*
+	 * Affichage onglets
+	 */
+	$head = member_prepare_head($adh);
 
-    $head[$h][0] = DOL_URL_ROOT.'/adherents/fiche.php?rowid='.$rowid;
-    $head[$h][1] = $langs->trans("Card");
-    $hselected=$h;
-    $h++;
+	dolibarr_fiche_head($head, 'general', $langs->trans("Member").": ".$adh->fullname);
 
-    dolibarr_fiche_head($head, $hselected, $langs->trans("MemberCard"));
 
     // Confirmation de la suppression de l'adh�rent
     if ($action == 'delete')
@@ -737,19 +748,26 @@ if ($rowid && $action != 'edit')
     }
 
 
-    print '<table class="border" width="100%">';
     print '<form action="fiche.php" method="post">';
+    print '<table class="border" width="100%">';
 
+    // Ref
     print '<tr><td>'.$langs->trans("Ref").'</td><td class="valeur" colspan="3">'.$adh->id.'&nbsp;</td></tr>';
 
+    // Nom
     print '<tr><td>'.$langs->trans("Lastname").'*</td><td class="valeur">'.$adh->nom.'&nbsp;</td>';
     print '<td valign="top" width="50%">'.$langs->trans("Comments").'</td></tr>';
 
+    // Prenom
     print '<tr><td width="15%">'.$langs->trans("Firstname").'*</td><td class="valeur" width="35%">'.$adh->prenom.'&nbsp;</td>';
     print '<td rowspan="'.(13+count($adh->array_options)).'" valign="top" width="50%">';
     print nl2br($adh->commentaire).'&nbsp;</td></tr>';
 
-    print '<tr><td>'.$langs->trans("Type").'*</td><td class="valeur">'.$adh->type."</td></tr>\n";
+    // Login
+    print '<tr><td>'.$langs->trans("Login").'*</td><td class="valeur">'.$adh->login.'&nbsp;</td></tr>';
+
+	// Type
+	print '<tr><td>'.$langs->trans("Type").'*</td><td class="valeur">'.$adh->type."</td></tr>\n";
     print '<tr><td>'.$langs->trans("Person").'</td><td class="valeur">'.$adh->getmorphylib().'</td></tr>';
 
     print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$adh->societe.'&nbsp;</td></tr>';
@@ -757,7 +775,6 @@ if ($rowid && $action != 'edit')
     print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td class="valeur">'.$adh->cp.' '.$adh->ville.'&nbsp;</td></tr>';
     print '<tr><td>'.$langs->trans("Country").'</td><td class="valeur">'.$adh->pays.'</td></tr>';
     print '<tr><td>'.$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'*':'').'</td><td class="valeur">'.$adh->email.'&nbsp;</td></tr>';
-    print '<tr><td>'.$langs->trans("Login").'*</td><td class="valeur">'.$adh->login.'&nbsp;</td></tr>';
     //  print '<tr><td>Pass</td><td class="valeur">'.$adh->pass.'&nbsp;</td></tr>';
     print '<tr><td>'.$langs->trans("Birthday").'</td><td class="valeur">'.$adh->naiss.'&nbsp;</td></tr>';
     print '<tr><td>URL Photo</td><td class="valeur">'.$adh->photo.'&nbsp;</td></tr>';
@@ -771,8 +788,8 @@ if ($rowid && $action != 'edit')
         print "<tr><td>$value</td><td>".$adh->array_options["options_$key"]."&nbsp;</td></tr>\n";
     }
     
-    print '</form>';
     print "</table>\n";
+    print '</form>';
     
     print "</div>\n";
 
@@ -907,13 +924,14 @@ if ($rowid && $action != 'edit')
      */
     if ($user->rights->adherent->cotisation->creer)
     {
+        print "\n\n<!-- Form add subscription -->\n";
+        print '<form name="cotisation" method="post" action="'.$_SERVER["PHP_SELF"].'">';
         print "<table class=\"border\" width=\"100%\">\n";
     
-        print '<form name="cotisation" method="post" action="fiche.php">';
+        print '<tr><td width="15%">'.$langs->trans("SubscriptionEndDate");
         print '<input type="hidden" name="action" value="cotisation">';
         print '<input type="hidden" name="rowid" value="'.$rowid.'">';
-    
-        print '<tr><td width="15%">'.$langs->trans("SubscriptionEndDate").'</td>';
+        print '</td>';
         print '<td width="35%">';
         if ($adh->datefin)
         {
@@ -968,10 +986,11 @@ if ($rowid && $action != 'edit')
             print strftime("%Y",($adh->datefin?$adh->datefin:time())).'" ></td></tr>';
         }
 
-        print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"</td></tr>';
+        print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td></tr>';
     
-        print '</form>';
         print '</table>';
+        print '</form>';
+		print "\n<!-- End form subscription -->\n\n";
     }
     
     print '</td></tr>';
diff --git a/htdocs/adherents/ldap.php b/htdocs/adherents/ldap.php
new file mode 100644
index 0000000000000000000000000000000000000000..8d572ed4b2a1fab855912197003863e4acc511ec
--- /dev/null
+++ b/htdocs/adherents/ldap.php
@@ -0,0 +1,200 @@
+<?php
+/* Copyright (C) 2006 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2006 Regis Houssin        <regis.houssin@cap-networks.com>
+ *
+ * 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.
+ *
+ * $Id$
+ * $Source$
+ */
+
+/**
+        \file       htdocs/adherents/ldap.php
+        \ingroup    ldap
+        \brief      Page fiche LDAP adherent
+        \version    $Revision$
+*/
+
+require("./pre.inc.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php");
+require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_type.class.php");
+
+$user->getrights('commercial');
+
+$langs->load("companies");
+$langs->load("members");
+$langs->load("ldap");
+
+// Protection quand utilisateur externe
+$rowid = isset($_GET["id"])?$_GET["id"]:'';
+
+$socid=0;
+if ($user->societe_id > 0)
+{
+    $socid = $user->societe_id;
+}
+
+
+/*
+ *	Affichage page
+ */
+
+llxHeader();
+
+$form = new Form($db);
+
+
+$adh = new Adherent($db);
+$adh->id = $rowid;
+$result=$adh->fetch($rowid);
+if (! $result)
+{
+	dolibarr_print_error($db,"Failed to get adherent: ".$adh->error);
+	exit;
+}
+$adh->fetch_optionals($rowid);
+
+$adht = new AdherentType($db);
+$result=$adht->fetch($adh->typeid);
+if (! $result)
+{
+	dolibarr_print_error($db,"Failed to get type of adherent: ".$adht->error);
+	exit;
+}
+
+
+
+/*
+ * Affichage onglets
+ */
+$head = member_prepare_head($adh);
+
+dolibarr_fiche_head($head, 'ldap', $langs->trans("Member").": ".$adh->fullname);
+
+
+
+/*
+ * Fiche en mode visu
+ */
+print '<table class="border" width="100%">';
+
+// Ref
+print '<tr><td>'.$langs->trans("Ref").'</td><td class="valeur">'.$adh->id.'&nbsp;</td></tr>';
+
+// Nom
+print '<tr><td>'.$langs->trans("Lastname").'*</td><td class="valeur">'.$adh->nom.'&nbsp;</td>';
+print '</tr>';
+
+// Prenom
+print '<tr><td width="15%">'.$langs->trans("Firstname").'*</td><td class="valeur">'.$adh->prenom.'&nbsp;</td>';
+print '</tr>';
+
+// Login
+print '<tr><td>'.$langs->trans("Login").'*</td><td class="valeur">'.$adh->login.'&nbsp;</td></tr>';
+
+// Type
+print '<tr><td>'.$langs->trans("Type").'*</td><td class="valeur">'.$adh->type."</td></tr>\n";
+
+// LDAP DN
+$langs->load("admin");
+print '<tr><td>'.$langs->trans("LDAPMemberDn").'*</td><td class="valeur">'.$conf->global->LDAP_MEMBER_DN."</td></tr>\n";
+
+// LDAP Server
+print '<tr><td>'.$langs->trans("LDAPPrimaryServer").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
+print '<tr><td>'.$langs->trans("LDAPSecondaryServer").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
+print '<tr><td>'.$langs->trans("LDAPServerPort").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
+
+print '</table>';
+
+print '</div>';
+
+print '<br>';
+
+
+print_titre($langs->trans("LDAPInformationsForThisMember"));
+
+// Affichage attributs LDAP
+print '<table width="100%" class="noborder">';
+
+print '<tr class="liste_titre">';
+print '<td>'.$langs->trans("LDAPAttributes").'</td>';
+print '<td>'.$langs->trans("Value").'</td>';
+print '</tr>';
+
+// Lecture LDAP
+$ldap=new AuthLdap();
+$result=$ldap->connect();
+if ($result)
+{
+	$bind='';
+	if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS)
+	{
+		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);
+	}
+	if (! $bind)	// Si pas de login ou si connexion avec login en echec, on tente en anonyme
+	{
+		dolibarr_syslog("ldap.php: bind",LOG_DEBUG);
+		$bind=$ldap->bind();
+	}
+
+	if ($bind)
+	{
+		$info["cn"] = trim($adh->prenom." ".$adh->nom);
+		$info["uid"] = trim($adh->login);
+
+		$dn = $conf->global->LDAP_MEMBER_DN;
+//		$dn = "cn=".$info["cn"].",".$dn;
+//		$dn = "uid=".$info["uid"].",".$dn
+		$search = "(cn=".$info["cn"].")";
+		//$search = "(uid=".$info["uid"].")";
+		
+		$result=$ldap->search($dn,$search);
+
+		// Affichage arbre
+		if (sizeof($result))
+		{
+			$html=new Form($db);
+			$html->show_ldap_content($result,0,0,true);
+		}
+		else
+		{
+			print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>';
+		}
+
+		$ldap->unbind();
+	}
+	else
+	{
+		dolibarr_print_error('',$ldap->error);
+	}
+	$ldap->close();
+}
+else
+{
+	dolibarr_print_error('',$ldap->error);
+}
+
+print '</table>';
+
+
+
+
+$db->close();
+
+llxFooter('$Date$ - $Revision$');
+?>
diff --git a/htdocs/admin/ldap.php b/htdocs/admin/ldap.php
index fd9dbb74b64a35cad7a3c6e5cebea245e752c10a..6bfacacc9d2a74dd09dd90d6373a5ac6cc5a7fef 100644
--- a/htdocs/admin/ldap.php
+++ b/htdocs/admin/ldap.php
@@ -32,6 +32,7 @@
 
 require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.php");
 
 $langs->load("admin");
 
@@ -74,8 +75,12 @@ if ($_GET["action"] == 'setvalue' && $user->admin)
 
 llxHeader();
 
+
+$head = ldap_prepare_head();
+
 print_fiche_titre($langs->trans("LDAPSetup"),'','setup');
 
+
 // Test si fonction LDAP actives
 if (! function_exists("ldap_connect"))
 {
@@ -86,36 +91,9 @@ if ($mesg) print '<div class="error">'.$mesg.'</div>';
 else print '<br>';
 
 
-// Onglets
-$h = 0;
-
-$head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
-$head[$h][1] = $langs->trans("LDAPGlobalParameters");
-$hselected=$h;
-$h++;
-
-if ($conf->global->LDAP_SYNCHRO_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
-	$head[$h][1] = $langs->trans("LDAPUsersAndGroupsSynchro");
-	$h++;
-}
-
-if ($conf->global->LDAP_CONTACT_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
-	$head[$h][1] = $langs->trans("LDAPContactsSynchro");
-	$h++;
-}
 
-if ($conf->global->LDAP_MEMBERS_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
-	$head[$h][1] = $langs->trans("LDAPMembersSynchro");
-	$h++;
-}
 
-dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP"));
+dolibarr_fiche_head($head, 'ldap', $langs->trans("LDAP"));
 
 $var=true;
 $html=new Form($db);
diff --git a/htdocs/admin/ldap_contacts.php b/htdocs/admin/ldap_contacts.php
index aae2f5114ed26338351cb475afe7722d0afdf935..49b33ad1f7b05fc3e8ad2f4946825854b00bce74 100644
--- a/htdocs/admin/ldap_contacts.php
+++ b/htdocs/admin/ldap_contacts.php
@@ -32,6 +32,7 @@
 
 require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.php");
 require_once (DOL_DOCUMENT_ROOT."/contact.class.php");
 
 $langs->load("admin");
@@ -47,7 +48,10 @@ if (!$user->admin)
 if ($_GET["action"] == 'setvalue' && $user->admin)
 {
 	$error=0;
+	if (! dolibarr_set_const($db, 'LDAP_KEY_CONTACTS',$_POST["key"])) $error++;
+
 	if (! dolibarr_set_const($db, 'LDAP_CONTACT_DN',$_POST["contactdn"])) $error++;
+	if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"])) $error++;
 	if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++;
 	if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',$_POST["fieldfirstname"])) $error++;
 	if (! dolibarr_set_const($db, 'LDAP_FIELD_MAIL',$_POST["fieldmail"])) $error++;
@@ -72,8 +76,11 @@ if ($_GET["action"] == 'setvalue' && $user->admin)
 
 llxHeader();
 
+$head = ldap_prepare_head();
+
 print_fiche_titre($langs->trans("LDAPSetup"),'','setup');
 
+
 // Test si fonction LDAP actives
 if (! function_exists("ldap_connect"))
 {
@@ -84,36 +91,8 @@ if ($mesg) print '<div class="error">'.$mesg.'</div>';
 else print '<br>';
 
 
-// Onglets
-$h = 0;
-
-$head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
-$head[$h][1] = $langs->trans("LDAPGlobalParameters");
-$h++;
-
-if ($conf->global->LDAP_SYNCHRO_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
-	$head[$h][1] = $langs->trans("LDAPUsersAndGroupsSynchro");
-	$h++;
-}
-
-if ($conf->global->LDAP_CONTACT_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
-	$head[$h][1] = $langs->trans("LDAPContactsSynchro");
-	$hselected=$h;
-	$h++;
-}
-
-if ($conf->global->LDAP_MEMBERS_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
-	$head[$h][1] = $langs->trans("LDAPMembersSynchro");
-	$h++;
-}
+dolibarr_fiche_head($head, 'contacts', $langs->trans("LDAP"));
 
-dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP"));
 
 print $langs->trans("LDAPDescContact").'<br>';
 print '<br>';
@@ -123,7 +102,8 @@ print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">';
 print '<table class="noborder" width="100%">';
 
 print '<tr class="liste_titre">';
-print '<td colspan="3">'.$langs->trans("LDAPSynchronizeContacts").'</td>';
+print '<td colspan="3">'.$langs->trans("LDAPSynchronizeUsers").'</td>';
+print '<td>'.$langs->trans("LDAPNamingAttribute").'</td>';
 print "</tr>\n";
    
 $var=true;
@@ -133,67 +113,94 @@ $html=new Form($db);
 // DN Pour les contacts
 $var=!$var;
 print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPContactDn").picto_required().'</b></td><td>';
-print '<input size="38" type="text" name="contactdn" value="'.$conf->global->LDAP_CONTACT_DN.'">';
-print '</td><td>'.$langs->trans("LDAPContactDnExample").'</td></tr>';
+print '<input size="48" type="text" name="contactdn" value="'.$conf->global->LDAP_CONTACT_DN.'">';
+print '</td><td>'.$langs->trans("LDAPContactDnExample").'</td>';
+print '<td>&nbsp;</td>';
+print '</tr>';
+
+// Common name
+$var=!$var;
+print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFullname").'</td><td>';
+print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_FIELD_FULLNAME.'">';
+print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_FULLNAME.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_FULLNAME?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Name
 $var=!$var;
-print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPFieldName").picto_required().'</b></td><td>';
+print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldName").'</td><td>';
 print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">';
-print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_NAME.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_NAME?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Firstname
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
 print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">';
-print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td></tr>';
-
+print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_FIRSTNAME?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Mail
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
 print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">';
-print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_MAIL.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_MAIL?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Phone
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
 print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">';
-print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_PHONE.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_PHONE?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Mobile
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
 print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
-print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_MOBILE.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_MOBILE?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Fax
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
 print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
-print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_FAX.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_FAX?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Address
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldAddress").'</td><td>';
 print '<input size="25" type="text" name="fieldaddress" value="'.$conf->global->LDAP_FIELD_ADDRESS.'">';
-print '</td><td>'.$langs->trans("LDAPFieldAddressExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldAddressExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_ADDRESS.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_ADDRESS?' checked="true"':'')."></td>";
+print '</tr>';
 
 // CP
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldZip").'</td><td>';
 print '<input size="25" type="text" name="fieldzip" value="'.$conf->global->LDAP_FIELD_ZIP.'">';
-print '</td><td>'.$langs->trans("LDAPFieldZipExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldZipExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_ZIP.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_ZIP?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Ville
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldTown").'</td><td>';
 print '<input size="25" type="text" name="fieldtown" value="'.$conf->global->LDAP_FIELD_TOWN.'">';
-print '</td><td>'.$langs->trans("LDAPFieldTownExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldTownExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_TOWN.'"'.($conf->global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_TOWN?' checked="true"':'')."></td>";
+print '</tr>';
 
 
 $var=!$var;
-print '<tr '.$bc[$var].'><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
+print '<tr '.$bc[$var].'><td colspan="4" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
 print '</table>';
 
 print '</form>';
diff --git a/htdocs/admin/ldap_members.php b/htdocs/admin/ldap_members.php
index 9c01d4ac93af7bf2924a1345fb0387c9cd82d602..e97e82d7c88f08bb843e37507212605307fdf490 100644
--- a/htdocs/admin/ldap_members.php
+++ b/htdocs/admin/ldap_members.php
@@ -34,6 +34,7 @@ require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php");
 require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_type.class.php");
 require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.php");
 
 $langs->load("admin");
 
@@ -48,8 +49,10 @@ if (!$user->admin)
 if ($_GET["action"] == 'setvalue' && $user->admin)
 {
 	$error=0;
+	if (! dolibarr_set_const($db, 'LDAP_KEY_MEMBERS',$_POST["key"])) $error++;
+
 	if (! dolibarr_set_const($db, 'LDAP_MEMBER_DN',$_POST["user"])) $error++;
-	if (! dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_DN',$_POST["group"])) $error++;
+	if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"])) $error++;
 	if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',$_POST["fieldlogin"])) $error++;
 	if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN_SAMBA',$_POST["fieldloginsamba"])) $error++;
 	if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++;
@@ -73,8 +76,11 @@ if ($_GET["action"] == 'setvalue' && $user->admin)
 
 llxHeader();
 
+$head = ldap_prepare_head();
+
 print_fiche_titre($langs->trans("LDAPSetup"),'','setup');
 
+
 // Test si fonction LDAP actives
 if (! function_exists("ldap_connect"))
 {
@@ -85,37 +91,8 @@ if ($mesg) print '<div class="error">'.$mesg.'</div>';
 else print '<br>';
 
 
-// Onglets
-$h = 0;
-
-$head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
-$head[$h][1] = $langs->trans("LDAPGlobalParameters");
-$h++;
+dolibarr_fiche_head($head, 'members', $langs->trans("LDAP"));
 
-if ($conf->global->LDAP_SYNCHRO_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
-	$head[$h][1] = $langs->trans("LDAPUsersAndGroupsSynchro");
-	$h++;
-}
-
-if ($conf->global->LDAP_CONTACT_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
-	$head[$h][1] = $langs->trans("LDAPContactsSynchro");
-	$h++;
-}
-
-if ($conf->global->LDAP_MEMBERS_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
-	$head[$h][1] = $langs->trans("LDAPMembersSynchro");
-	$hselected=$h;
-	$h++;
-}
-
-
-dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP"));
 
 print $langs->trans("LDAPDescMembers").'<br>';
 print '<br>';
@@ -130,81 +107,102 @@ $html=new Form($db);
 
 
 print '<tr class="liste_titre">';
-print '<td colspan="3">'.$langs->trans("LDAPSynchronizeMembers").'</td>';
+print '<td colspan="3">'.$langs->trans("LDAPSynchronizeUsers").'</td>';
+print '<td>'.$langs->trans("LDAPNamingAttribute").'</td>';
 print "</tr>\n";
 
 // DN Pour les adherents
 $var=!$var;
 print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPMemberDn").picto_required().'</b></td><td>';
-print '<input size="38" type="text" name="user" value="'.$conf->global->LDAP_MEMBER_DN.'">';
-print '</td><td>'.$langs->trans("LDAPMemberDnExample").'</td></tr>';
-
-// DN pour les types
-/*
-$var=!$var;
-print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPMemberTypeDn").picto_required().'</b></td><td>';
-print '<input size="38" type="text" name="group" value="'.$conf->global->LDAP_MEMBER_TYPE_DN.'">';
-print '</td><td>'.$langs->trans("LDAPMemberTypeDnExample").'</td></tr>';
-*/
+print '<input size="48" type="text" name="user" value="'.$conf->global->LDAP_MEMBER_DN.'">';
+print '</td><td>'.$langs->trans("LDAPMemberDnExample").'</td>';
+print '<td>&nbsp;</td>';
+print '</tr>';
 
 // Filtre
 /*
 $var=!$var;
 print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPFilterConnection").picto_required().'</b></td><td>';
 print '<input size="38" type="text" name="filterconnection" value="'.$conf->global->LDAP_FILTER_CONNECTION.'">';
-print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td>';
+print '</tr>';
 */
 
+// Common name
+$var=!$var;
+print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFullname").'</td><td>';
+print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_FIELD_FULLNAME.'">';
+print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_FULLNAME.'"'.($conf->global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_FULLNAME?' checked="true"':'')."></td>";
+print '</tr>';
+
 // Name
 $var=!$var;
-print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPFieldName").picto_required().'</b></td><td>';
+print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldName").'</td><td>';
 print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">';
-print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_NAME.'"'.($conf->global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_NAME?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Firstname
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
 print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">';
-print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'"'.($conf->global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_FIRSTNAME?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Login unix
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>';
 print '<input size="25" type="text" name="fieldlogin" value="'.$conf->global->LDAP_FIELD_LOGIN.'">';
-print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_LOGIN.'"'.($conf->global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_LOGIN?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Login samba
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>';
 print '<input size="25" type="text" name="fieldloginsamba" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'">';
-print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'"'.($conf->global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_LOGIN_SAMBA?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Mail
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
 print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">';
-print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_MAIL.'"'.($conf->global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_MAIL?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Phone
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
 print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">';
-print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_PHONE.'"'.($conf->global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_PHONE?' checked="true"':'')."></td>";
+print '</tr>';
+
+// Mobile
+$var=!$var;
+print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
+print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
+print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_MOBILE.'"'.($conf->global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_MOBILE?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Fax
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
 print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
-print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_FAX.'"'.($conf->global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_FAX?' checked="true"':'')."></td>";
+print '</tr>';
 
-// Mobile
-$var=!$var;
-print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
-print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
-print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td></tr>';
 
 $var=!$var;
-print '<tr '.$bc[$var].'><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
+print '<tr '.$bc[$var].'><td colspan="4" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
 print '</table>';
 
 print '</form>';
diff --git a/htdocs/admin/ldap_users.php b/htdocs/admin/ldap_users.php
index b83e3c989145efd6c6ba3a0376d0afbcc64a896b..2c0f6e93140a1ffc0af257b535e0dc89357d23ef 100644
--- a/htdocs/admin/ldap_users.php
+++ b/htdocs/admin/ldap_users.php
@@ -34,6 +34,7 @@ require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/user.class.php");
 require_once(DOL_DOCUMENT_ROOT."/usergroup.class.php");
 require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.php");
 
 $langs->load("admin");
 
@@ -48,8 +49,10 @@ if (!$user->admin)
 if ($_GET["action"] == 'setvalue' && $user->admin)
 {
 	$error=0;
+	if (! dolibarr_set_const($db, 'LDAP_KEY_USERS',$_POST["key"])) $error++;
+
 	if (! dolibarr_set_const($db, 'LDAP_USER_DN',$_POST["user"])) $error++;
-	if (! dolibarr_set_const($db, 'LDAP_GROUP_DN',$_POST["group"])) $error++;
+	if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"])) $error++;
 	if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',$_POST["fieldlogin"])) $error++;
 	if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN_SAMBA',$_POST["fieldloginsamba"])) $error++;
 	if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++;
@@ -73,8 +76,11 @@ if ($_GET["action"] == 'setvalue' && $user->admin)
 
 llxHeader();
 
+$head = ldap_prepare_head();
+
 print_fiche_titre($langs->trans("LDAPSetup"),'','setup');
 
+
 // Test si fonction LDAP actives
 if (! function_exists("ldap_connect"))
 {
@@ -85,36 +91,8 @@ if ($mesg) print '<div class="error">'.$mesg.'</div>';
 else print '<br>';
 
 
-// Onglets
-$h = 0;
-
-$head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
-$head[$h][1] = $langs->trans("LDAPGlobalParameters");
-$h++;
-
-if ($conf->global->LDAP_SYNCHRO_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
-	$head[$h][1] = $langs->trans("LDAPUsersAndGroupsSynchro");
-	$hselected=$h;
-	$h++;
-}
-
-if ($conf->global->LDAP_CONTACT_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
-	$head[$h][1] = $langs->trans("LDAPContactsSynchro");
-	$h++;
-}
+dolibarr_fiche_head($head, 'users', $langs->trans("LDAP"));
 
-if ($conf->global->LDAP_MEMBERS_ACTIVE)
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
-	$head[$h][1] = $langs->trans("LDAPMembersSynchro");
-	$h++;
-}
-
-dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP"));
 
 print $langs->trans("LDAPDescUsers").'<br>';
 print '<br>';
@@ -129,79 +107,101 @@ $html=new Form($db);
 
 
 print '<tr class="liste_titre">';
-print '<td colspan="3">'.$langs->trans("LDAPSynchronizeUsersAndGroup").'</td>';
+print '<td colspan="3">'.$langs->trans("LDAPSynchronizeUsers").'</td>';
+print '<td>'.$langs->trans("LDAPNamingAttribute").'</td>';
 print "</tr>\n";
 
 // DN Pour les utilisateurs
 $var=!$var;
 print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPUserDn").picto_required().'</b></td><td>';
-print '<input size="38" type="text" name="user" value="'.$conf->global->LDAP_USER_DN.'">';
-print '</td><td>'.$langs->trans("LDAPUserDnExample").'</td></tr>';
-
-// DN pour les groupes
-$var=!$var;
-print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPGroupDn").picto_required().'</b></td><td>';
-print '<input size="38" type="text" name="group" value="'.$conf->global->LDAP_GROUP_DN.'">';
-print '</td><td>'.$langs->trans("LDAPGroupDnExample").'</td></tr>';
+print '<input size="48" type="text" name="user" value="'.$conf->global->LDAP_USER_DN.'">';
+print '</td><td>'.$langs->trans("LDAPUserDnExample").'</td>';
+print '<td>&nbsp;</td>';
+print '</tr>';
 
 // Filtre
 /*
 $var=!$var;
 print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPFilterConnection").picto_required().'</b></td><td>';
 print '<input size="38" type="text" name="filterconnection" value="'.$conf->global->LDAP_FILTER_CONNECTION.'">';
-print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td>';
+print '</tr>';
 */
 
+// Common name
+$var=!$var;
+print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFullname").'</td><td>';
+print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_FIELD_FULLNAME.'">';
+print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_FULLNAME.'"'.($conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FULLNAME?' checked="true"':'')."></td>";
+print '</tr>';
+
 // Name
 $var=!$var;
-print '<tr '.$bc[$var].'><td><b>'.$langs->trans("LDAPFieldName").picto_required().'</b></td><td>';
+print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldName").'</td><td>';
 print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">';
-print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_NAME.'"'.($conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_NAME?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Firstname
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
 print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">';
-print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'"'.($conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FIRSTNAME?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Login unix
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>';
 print '<input size="25" type="text" name="fieldlogin" value="'.$conf->global->LDAP_FIELD_LOGIN.'">';
-print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_LOGIN.'"'.($conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Login samba
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>';
 print '<input size="25" type="text" name="fieldloginsamba" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'">';
-print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'"'.($conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN_SAMBA?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Mail
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
 print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">';
-print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_MAIL.'"'.($conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MAIL?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Phone
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
 print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">';
-print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td></tr>';
-
-// Fax
-$var=!$var;
-print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
-print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
-print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_PHONE.'"'.($conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_PHONE?' checked="true"':'')."></td>";
+print '</tr>';
 
 // Mobile
 $var=!$var;
 print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
 print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
-print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td></tr>';
+print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_MOBILE.'"'.($conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MOBILE?' checked="true"':'')."></td>";
+print '</tr>';
+
+// Fax
+$var=!$var;
+print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
+print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
+print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>';
+print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_FIELD_FAX.'"'.($conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FAX?' checked="true"':'')."></td>";
+print '</tr>';
 
 $var=!$var;
-print '<tr '.$bc[$var].'><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
+print '<tr '.$bc[$var].'><td colspan="4" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
 print '</table>';
 
 print '</form>';
@@ -219,7 +219,6 @@ if (function_exists("ldap_connect"))
 	{
 		print '<br>';
 		print '<a class="tabAction" href="'.$_SERVER["PHP_SELF"].'?action=testuser">'.$langs->trans("LDAPTestSynchroUser").'</a>';
-		print '<a class="tabAction" href="'.$_SERVER["PHP_SELF"].'?action=testgroup">'.$langs->trans("LDAPTestSynchroGroup").'</a>';
 		print '<br><br>';
 	}
 
@@ -248,32 +247,6 @@ if (function_exists("ldap_connect"))
 		}
 
 	}
-
-	if ($_GET["action"] == 'testgroup')
-	{
-		// Creation contact
-		$fgroup=new UserGroup($db);
-		$fgroup->initAsSpecimen();
-
-		// Test synchro
-		//$result1=$fgroup->delete_ldap($user);
-		$result2=$fgroup->update_ldap($user);
-		$result3=$fgroup->delete_ldap($user);
-	
-		if ($result2 > 0)
-		{
-			print img_picto('','info').' ';
-			print '<font class="ok">'.$langs->trans("LDAPSynchroOK").'</font><br>';
-		}
-		else
-		{
-			print img_picto('','error').' ';
-			print '<font class="warning">'.$langs->trans("LDAPSynchroKO");
-			print ': '.$fgroup->error;
-			print '</font><br>';
-		}
-
-	}
 }
 
 $db->close();
diff --git a/htdocs/conf/conf.class.php b/htdocs/conf/conf.class.php
index 24c93f626e85648e33c8286b97453d8ef5832375..1df733aaebdbd24a902c111590d534c3b9b19d72 100644
--- a/htdocs/conf/conf.class.php
+++ b/htdocs/conf/conf.class.php
@@ -119,6 +119,13 @@ class Conf
 		if (! $this->global->MAIN_MENU_BARRELEFT) $this->global->MAIN_MENU_BARRELEFT="default.php";
 		if (! $this->global->MAIN_MENUFRONT_BARRELEFT) $this->global->MAIN_MENUFRONT_BARRELEFT="default.php";
 
+		// Variable globales LDAP
+		if (! $this->global->LDAP_KEY_USERS) $this->global->LDAP_KEY_USERS=$this->global->LDAP_FIELD_FULLNAME;
+		if (! $this->global->LDAP_KEY_GROUPS) $this->global->LDAP_KEY_GROUPS=$this->global->LDAP_FIELD_FULLNAME;
+		if (! $this->global->LDAP_KEY_CONTACTS) $this->global->LDAP_KEY_CONTACTS=$this->global->LDAP_FIELD_FULLNAME;
+		if (! $this->global->LDAP_KEY_MEMBERS) $this->global->LDAP_KEY_MEMBERS=$this->global->LDAP_FIELD_FULLNAME;
+
+
 		/*
 		 * Charge l'objet de traduction et positionne langage courant global
 		 */
diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php
index 6f7098f3217096e5f4666a5567ddb429619a2419..43ffe06e38560983d25e613d73505062fb01d8fa 100644
--- a/htdocs/contact.class.php
+++ b/htdocs/contact.class.php
@@ -233,9 +233,9 @@ class Contact
 			
 			if ($bind)
 			{
-				$info["cn"] = trim($this->firstname." ".$this->name);
-				$dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN;
-				
+				$info=$this->_load_ldap_info($info);
+
+				$dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN;
 				$result=$ldap->delete($dn);
 				
 				return $result;
@@ -250,8 +250,81 @@ class Contact
 	}
 	
 	
+	function _load_ldap_info($info)
+	{
+		global $conf,$langs;
+
+		if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') 
+		{
+			$info["objectclass"]=array("top",
+									   "person",
+									   "organizationalPerson",
+									   "user");
+		}
+		else
+		{
+			$info["objectclass"]=array("top",
+									   "person",
+									   "organizationalPerson",
+									   "inetOrgPerson");
+		}	
+
+		// Champs 
+		if ($this->fullname  && $conf->global->LDAP_FIELD_FULLNAME) $info[$conf->global->LDAP_FIELD_FULLNAME] = $this->fullname;
+		if ($this->name && $conf->global->LDAP_FIELD_NAME) $info[$conf->global->LDAP_FIELD_NAME] = $this->name;
+		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);
+
+			$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')
+		{
+			$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($this->egroupware_id) == 0)
+			{
+				$this->egroupware_id = 1;
+			}
+
+			$info["phpgwContactOwner"] = $this->egroupware_id;
+
+			if ($this->email) $info["rfc822Mailbox"] = $this->email;
+			if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
+		}
+						
+		return $info;
+	}
+
+
 	/**
-	*   \brief      Creation d'un contact dans l'arbre LDAP
+	*   \brief      Creation dans l'arbre LDAP
 	*   \param      user        Utilisateur qui effectue la creation
 	*	\return		int			<0 si ko, >0 si ok
 	*/
@@ -294,90 +367,19 @@ class Contact
 			}
 			if ($bind)
 			{
-				if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') 
-				{
-					$info["objectclass"]=array("top",
-											   "person",
-											   "organizationalPerson",
-											   "user");
-				}
-				else
-				{
-					$info["objectclass"]=array("top",
-											   "person",
-											   "organizationalPerson",
-											   "inetOrgPerson");
-				}	
-
-				// 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);
-
-					$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')
-				{
-					$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)
-					{
-						$user->egroupware_id = 1;
-					}
-
-					$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);
+				$info=$this->_load_ldap_info($info);
 
-				$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;
+				// Definitition du DN
+				$dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN;
+				$olddn = $dn;
+				if (($this->old_firstname || $this->old_name) && $conf->global->LDAP_KEY_CONTACTS=="cn")
+					$olddn=$conf->global->LDAP_KEY_CONTACTS."=".trim($this->old_firstname." ".$this->old_name).",".$conf->global->LDAP_CONTACT_DN;
 
 				// On supprime et on ins�re
-				dolibarr_syslog("Contact.class::update_ldap olddn=".$olddn." newdn=".$newdn);	
+				dolibarr_syslog("User.class::update_ldap dn=".$dn." olddn=".$olddn);
 
 				$result = $ldap->delete($olddn);
-				$result = $ldap->add($newdn, $info);
+				$result = $ldap->add($dn, $info);
 				if ($result <= 0)
 				{
 					$this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error;
diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php
index e39d1803ca4273900602b8cc19cb8717c2ec418e..6a1a8049728c9758d045d9546007b8fb21f9d7fc 100644
--- a/htdocs/contact/ldap.php
+++ b/htdocs/contact/ldap.php
@@ -115,9 +115,21 @@ print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
 print $form->civilite_name($contact->civilite_id);
 print '</td></tr>';
 
+// Nom
 print '<tr><td width="20%">'.$langs->trans("Lastname").'</td><td>'.$contact->name.'</td>';
+
+// Prenom
 print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
 
+// LDAP DN
+$langs->load("admin");
+print '<tr><td>'.$langs->trans("LDAPContactDn").'*</td><td class="valeur">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
+
+// LDAP Server
+print '<tr><td>'.$langs->trans("LDAPPrimaryServer").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
+print '<tr><td>'.$langs->trans("LDAPSecondaryServer").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
+print '<tr><td>'.$langs->trans("LDAPServerPort").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
+
 print '</table>';
 
 print '</div>';
@@ -146,7 +158,7 @@ if ($result)
 		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
+	if (! $bind)	// Si pas de login ou si connexion avec login en echec, on tente en anonyme
 	{
 		dolibarr_syslog("ldap.php: bind",LOG_DEBUG);
 		$bind=$ldap->bind();
@@ -155,9 +167,14 @@ if ($result)
 	if ($bind)
 	{
 		$info["cn"] = trim($contact->firstname." ".$contact->name);
-		$dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN;
 
-		$result=$ldap->search($dn,'(objectClass=*)');
+		$dn = $conf->global->LDAP_CONTACT_DN;
+//		$dn = "cn=".$info["cn"].",".$dn;
+//		$dn = "uid=".$info["uid"].",".$dn
+		$search = "(cn=".$info["cn"].")";
+		//$search = "(uid=".$info["uid"].")";
+
+		$result=$ldap->search($dn,$search);
 
 		// Affichage arbre
 		if (sizeof($result))
@@ -169,15 +186,18 @@ if ($result)
 		{
 			print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>';
 		}
+		
+		$ldap->unbind();
 	}
 	else
 	{
-		dolibarr_print_error('',$ldap);
+		dolibarr_print_error('',$ldap->error);
 	}
+	$ldap->close();
 }
 else
 {
-	dolibarr_print_error('',$ldap);
+	dolibarr_print_error('',$ldap->error);
 }
 
 print '</table>';
diff --git a/htdocs/don.class.php b/htdocs/don.class.php
index 4dc0617fec01220a754501d1f9e436fe838ca962..bf9da0e3e8a5a05cd26d39023972dbcd9a819a01 100644
--- a/htdocs/don.class.php
+++ b/htdocs/don.class.php
@@ -55,7 +55,7 @@ class Don
     var $statut;
     
     var $projet;
-    var $errorstr;
+    var $error;
     
     /**
      *    \brief  Constructeur
@@ -186,10 +186,10 @@ class Don
      */
     function print_error_list()
     {
-    $num = sizeof($this->errorstr);
+    $num = sizeof($this->error);
     for ($i = 0 ; $i < $num ; $i++)
       {
-	print "<li>" . $this->errorstr[$i];
+	print "<li>" . $this->error[$i];
       }
     }
 
@@ -267,7 +267,7 @@ class Don
       
       if ($err)
 	{
-	  $this->errorstr = $error_string;
+	  $this->error = $error_string;
 	  return 0;
 	}
       else
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index 3d4555ee897c4e00bdb4d45f9543a3d4c06460c6..b5a5b2e7703490ecf73353195a1fcc75f3fd3cd2 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -41,7 +41,7 @@
 class Form
 {
     var $db;
-    var $errorstr;
+    var $error;
     
     var $cache_types_paiements_code=array();
     var $cache_types_paiements_libelle=array();
@@ -2372,7 +2372,7 @@ class Form
      */
     function error()
     {
-        return $this->errorstr;
+        return $this->error;
     }
 
 
diff --git a/htdocs/html.formmail.class.php b/htdocs/html.formmail.class.php
index 690dbc94c925d4d9b20d497079a486dcd3f6f5e1..f92ecefc5293cf78ac1b9f750fe0f829f145e75b 100644
--- a/htdocs/html.formmail.class.php
+++ b/htdocs/html.formmail.class.php
@@ -64,7 +64,7 @@ class FormMail
 	var $substit=array();
 	var $param=array();
 	
-	var $errorstr;
+	var $error;
 
   
 	/**
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 682f809ac224e00e8923bbb26fcf21b5ad28befc..32756b8bfa5b353b83fc8cd35c0e176a230e9396 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -492,14 +492,19 @@ AdherentMailRequired=EMail required to create a new member
 ##### LDAP setup #####
 LDAPSetup=LDAP Setup
 LDAPGlobalParameters=Global parameters
-LDAPUsersAndGroupsSynchro=Users/groups synchro
-LDAPContactsSynchro=Contacts synchro
+LDAPUsersSynchro=Users
+LDAPGroupsSynchro=Groups
+LDAPContactsSynchro=Contacts
+LDAPMembersSynchro=Members
 LDAPSynchronization=LDAP synchronisation
 LDAPFunctionsNotAvailableOnPHP=LDAP functions are not availbale on your PHP
-LDAPSynchronizeUsersAndGroup=Synchronize Dolibarr users and groups with LDAP
 LDAPToDolibarr=LDAP -> Dolibarr
 DolibarrToLDAP=Dolibarr -> LDAP
+LDAPNamingAttribute=Key
+LDAPSynchronizeUsers=Synchronize Dolibarr users with LDAP
+LDAPSynchronizeGroups=Synchronize Dolibarr groups with LDAP
 LDAPSynchronizeContacts=Synchronize Dolibarr contacts with LDAP
+LDAPSynchronizeMembers=Synchronize members of Dolibarr fundation module with LDAP
 LDAPTypeExample=OpenLdap, Egroupware or Active Directory
 LDAPPrimaryServer=LDAP primary server
 LDAPSecondaryServer=LDAP secondary server
@@ -524,8 +529,14 @@ LDAPDnSynchroActiveExample=LDAP to Dolibarr or Dolibarr to LDAP synchronization
 LDAPDnContactActive=Contacts' synchronization
 LDAPDnContactActiveYes=Activated synchronization
 LDAPDnContactActiveExample=Activated/Unactivated synchronization
+LDAPDnMemberActive=Members' synchronization
+LDAPDnMemberActiveExample=Activated/Unactivated synchronization
 LDAPContactDn=Dolibarr contacts' DN
 LDAPContactDnExample=Complete DN (ex: ou=contacts,dc=society,dc=com)
+LDAPMemberDn=Dolibarr members' DN
+LDAPMemberDnExample=Complete DN (ex: ou=members,dc=society,dc=com)
+LDAPMemberTypeDn=Dolibarr member's type DN
+LDAPMemberTypeDnExample=Complete DN (ex: ou=type_members,dc=society,dc=com)
 LDAPTestConnect=Test LDAP connection
 LDAPTestSynchroContact=Test contact's synchronization
 LDAPTestSynchroUser=Test user's synchronization
@@ -544,35 +555,39 @@ LDAPConnectToDNFailed=Connection au DN (%s) 
 LDAPSetupForVersion3=LDAP server configured for version 3
 LDAPSetupForVersion2=LDAP server configured for version 2
 LDAPFieldLoginUnix=Login (unix)
-LDAPFieldLoginExample=Suggested value : uid
+LDAPFieldLoginExample=Example : uid
 LDAPFilterConnection=Search filter
-LDAPFilterConnectionExample=Suggested value : &(objectClass=user)(objectCategory=person)
+LDAPFilterConnectionExample=Example : &(objectClass=user)(objectCategory=person)
 LDAPFieldLoginSamba=Login (samba, activedirectory)
-LDAPFieldLoginSambaExample=Suggested value : samaccountname (Samba and ActiveDirectory)
+LDAPFieldLoginSambaExample=Example : samaccountname
+LDAPFieldFullname=Firstname Name
+LDAPFieldFullnameExample=Example : cn
 LDAPFieldName=Name
-LDAPFieldNameExample=Suggested value : sn
+LDAPFieldNameExample=Example : sn
 LDAPFieldFirstName=Firstname
-LDAPFieldFirstNameExample=Suggested value : givenname
+LDAPFieldFirstNameExample=Example : givenname
 LDAPFieldMail=Email address
-LDAPFieldMailExample=Suggested value : mail
+LDAPFieldMailExample=Example : mail
 LDAPFieldPhone=Phone number
-LDAPFieldPhoneExample=Suggested value : telephonenumber
+LDAPFieldPhoneExample=Example : telephonenumber
 LDAPFieldFax=Fax number
-LDAPFieldFaxExample=Suggested value : facsimiletelephonenumber
+LDAPFieldFaxExample=Example : facsimiletelephonenumber
 LDAPFieldMobile=Cellular phone
-LDAPFieldMobileExample=Suggested value : mobile
+LDAPFieldMobileExample=Example : mobile
 LDAPFieldAddress=Street
-LDAPFieldAddressExample=Valeur recommand�e : street
+LDAPFieldAddressExample=Example : street
 LDAPFieldZip=Zip
-LDAPFieldZipExample=Valeur recommand�e : postalcode
+LDAPFieldZipExample=Example : postalcode
 LDAPFieldTown=Town
-LDAPFieldTownExample=Valeur recommand�e : l
+LDAPFieldTownExample=Example : 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.
 LDAPDescContact=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr contacts.
 LDAPDescUsers=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr users.
-LDAPDescValues=Suggested values are designed for <b>OpenLDAP</b> with following loaded schemas: <b>core.schema, cosine.schema, inetorgperson.schema</b>). If you use thoose values and OpenLDAP, modify your LDAP config file <b>slapd.conf</b> to have all thoose schemas loaded.
+LDAPDescGroups=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr groups.
+LDAPDescMembers=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr members module.
+LDAPDescValues=Example values are designed for <b>OpenLDAP</b> with following loaded schemas: <b>core.schema, cosine.schema, inetorgperson.schema</b>). If you use thoose values and OpenLDAP, modify your LDAP config file <b>slapd.conf</b> to have all thoose schemas loaded.
 ##### Products #####
 ProductSetup=Products module setup
 NumberOfProductShowInSelect=Max number of products in combos select lists (0=no limit)
diff --git a/htdocs/langs/en_US/ldap.lang b/htdocs/langs/en_US/ldap.lang
index f8ba059e19df0ef9b0794aa0caa4580ddae7267f..a7e3e52425cd9e29c783d93cad2add35be70e3f3 100644
--- a/htdocs/langs/en_US/ldap.lang
+++ b/htdocs/langs/en_US/ldap.lang
@@ -7,6 +7,7 @@ LdapUacf_ACCOUNTDISABLE=Account is disabled on this domain
 LDAPInformationsForThisContact=Informations in LDAP database for this contact
 LDAPInformationsForThisUser=Informations in LDAP database for this user
 LDAPInformationsForThisGroup=Informations in LDAP database for this group
+LDAPInformationsForThisMember=Informations in LDAP database for this member
 LDAPAttribute=LDAP attribute
 LDAPAttributes=LDAP attributes
 LDAPCard=LDAP card
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index a104d8618491ef3d7b70b0602ed505cdfcb70280..6ba481b570ddaa60c1859377f4d294cfff8adea9 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -63,6 +63,7 @@ AddActionDone=Add action done
 Close=Close
 Close2=Close
 Confirm=Confirm
+ConfirmSendCardByMail=Do you really want to send this card by mail ?
 Delete=Delete
 Remove=Remove
 Resiliate=Resiliate
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index d73e84e82cade72e0491c4d6f0019d552bcd1258..9fb3806f9a8110acc056c0c7ff49b50eac45231e 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -492,14 +492,19 @@ AdherentMailRequired=EMail obligatoire pour cr
 ##### LDAP setup #####
 LDAPSetup=Configuration du module LDAP
 LDAPGlobalParameters=Param�tres globals
-LDAPUsersAndGroupsSynchro=Synchro utilisateurs/groupes
-LDAPContactsSynchro=Synchro contacts
+LDAPUsersSynchro=Utilisateurs
+LDAPGroupsSynchro=Groupes
+LDAPContactsSynchro=Contacts
+LDAPMembersSynchro=Adh�rents
 LDAPSynchronization=Synchronisation LDAP
 LDAPFunctionsNotAvailableOnPHP=Les fonctions LDAP ne sont pas disponibles sur votre PHP
-LDAPSynchronizeUsersAndGroup=Synchronisation des utilisateurs et groupes Dolibarr avec LDAP
 LDAPToDolibarr=LDAP -> Dolibarr
 DolibarrToLDAP=Dolibarr -> LDAP
+LDAPNamingAttribute=Cl�
+LDAPSynchronizeUsers=Synchronisation des utilisateurs Dolibarr avec LDAP
+LDAPSynchronizeGroups=Synchronisation des groupes utilisateurs Dolibarr avec LDAP
 LDAPSynchronizeContacts=Synchronisation des contacts Dolibarr avec LDAP
+LDAPSynchronizeMembers=Synchronisation des membres du module adh�rents de Dolibarr avec LDAP
 LDAPTypeExample=OpenLdap, Egroupware ou Active Directory
 LDAPPrimaryServer=Serveur primaire
 LDAPSecondaryServer=Serveur secondaire
@@ -524,8 +529,14 @@ LDAPDnSynchroActiveExample=Synchronisation de LDAP vers Dolibarr ou Dolibarr ver
 LDAPDnContactActive=Synchronisation des contacts
 LDAPDnContactActiveYes=Synchronisation activ�e
 LDAPDnContactActiveExample=Synchronisation activ�e/d�sactiv�e
+LDAPDnMemberActive=Synchronisation des adh�rents
+LDAPDnMemberActiveExample=Synchronisation activ�e/d�sactiv�e
 LDAPContactDn=DN des contacts Dolibarr
 LDAPContactDnExample=DN complet (ex: ou=contacts,dc=my-domain,dc=com)
+LDAPMemberDn=DN des adh�rents
+LDAPMemberDnExample=DN complet (ex: ou=members,dc=society,dc=com)
+LDAPMemberTypeDn=DN des types d'adh�rents
+LDAPMemberTypeDnExample=DN complet (ex: ou=type_members,dc=society,dc=com)
 LDAPTestConnect=Tester la connexion LDAP
 LDAPTestSynchroContact=Tester synchronisation contacts
 LDAPTestSynchroUser=Tester synchronisation utilisateur
@@ -544,35 +555,39 @@ LDAPConnectToDNFailed=Connection au DN (%s) 
 LDAPSetupForVersion3=Serveur LDAP configur� en version 3
 LDAPSetupForVersion2=Serveur LDAP configur� en version 2
 LDAPFieldLoginUnix=Login (unix)
-LDAPFieldLoginExample=Valeur recommand�e : uid
+LDAPFieldLoginExample=Exemple : uid
 LDAPFilterConnection=Filtre de recherche
-LDAPFilterConnectionExample=Valeur recommand�e : &(objectClass=user)(objectCategory=person)
+LDAPFilterConnectionExample=Exemple : &(objectClass=user)(objectCategory=person)
 LDAPFieldLoginSamba=Login (samba, activedirectory)
-LDAPFieldLoginSambaExample=Valeur recommand�e : samaccountname (Samba et ActiveDirectory)
+LDAPFieldLoginSambaExample=Exemple : samaccountname
+LDAPFieldFullname=Pr�nom Nom
+LDAPFieldFullnameExample=Exemple : cn
 LDAPFieldName=Nom
-LDAPFieldNameExample=Valeur recommand�e : sn
+LDAPFieldNameExample=Exemple : sn
 LDAPFieldFirstName=Pr�nom
-LDAPFieldFirstNameExample=Valeur recommand�e : givenname
+LDAPFieldFirstNameExample=Exemple : givenname
 LDAPFieldMail=Email
-LDAPFieldMailExample=Valeur recommand�e : mail
+LDAPFieldMailExample=Exemple : mail
 LDAPFieldPhone=T�l�phone
-LDAPFieldPhoneExample=Valeur recommand�e : telephonenumber
+LDAPFieldPhoneExample=Exemple : telephonenumber
 LDAPFieldFax=Fax
-LDAPFieldFaxExample=Valeur recommand�e : facsimiletelephonenumber
+LDAPFieldFaxExample=Exemple : facsimiletelephonenumber
 LDAPFieldMobile=T�l�phone portable
-LDAPFieldMobileExample=Valeur recommand�e : mobile
+LDAPFieldMobileExample=Exemple : mobile
 LDAPFieldAddress=Adresse
-LDAPFieldAddressExample=Valeur recommand�e : street
+LDAPFieldAddressExample=Exemple : street
 LDAPFieldZip=Code postal
-LDAPFieldZipExample=Valeur recommand�e : postalcode
+LDAPFieldZipExample=Exemple : postalcode
 LDAPFieldTown=Ville
-LDAPFieldTownExample=Valeur recommand�e : l
+LDAPFieldTownExample=Exemple : 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.
 LDAPDescContact=Cette page permet de d�finir le nom des attributs de l'arbre LDAP pour chaque informations des contacts Dolibarr.
 LDAPDescUsers=Cette page permet de d�finir le nom des attributs de l'arbre LDAP pour chaque informations des utilisateurs Dolibarr.
-LDAPDescValues=Les valeurs recommand�es sont adapt�es � <b>OpenLDAP</b> avec les schemas suivant charg�s: <b>core.schema, cosine.schema, inetorgperson.schema</b>). Si vous utiliser les valeurs sugg�r�s et OpenLDAP, modifier votre fichier de configuration LDAP <b>slapd.conf</b> pour avoir tous ces sch�mas actifs.
+LDAPDescGroups=Cette page permet de d�finir le nom des attributs de l'arbre LDAP pour chaque informations des groupes utilisateurs Dolibarr.
+LDAPDescMembers=Cette page permet de d�finir le nom des attributs de l'arbre LDAP pour chaque informations des membres du module adh�rents Dolibarr.
+LDAPDescValues=Les valeurs exemples sont adapt�es � <b>OpenLDAP</b> avec les schemas suivant charg�s: <b>core.schema, cosine.schema, inetorgperson.schema</b>). Si vous utiliser les valeurs sugg�r�s et OpenLDAP, modifier votre fichier de configuration LDAP <b>slapd.conf</b> pour avoir tous ces sch�mas actifs.
 ##### Products #####
 ProductSetup=Configuration du module Produits
 NumberOfProductShowInSelect=Nombre de produits max dans les listes d�roulantes (0=aucune limite)
diff --git a/htdocs/langs/fr_FR/ldap.lang b/htdocs/langs/fr_FR/ldap.lang
index 738c3a1d8fa2e89ef5d54442fbad6970a6be305b..564c6cec495bcc5bfab81efef88751e9b52cc215 100644
--- a/htdocs/langs/fr_FR/ldap.lang
+++ b/htdocs/langs/fr_FR/ldap.lang
@@ -7,6 +7,7 @@ LdapUacf_ACCOUNTDISABLE=Le compte est d
 LDAPInformationsForThisContact=Informations en base LDAP pour ce contact
 LDAPInformationsForThisUser=Informations en base LDAP pour cet utilisateur
 LDAPInformationsForThisGroup=Informations en base LDAP pour ce groupe
+LDAPInformationsForThisMember=Informations en base LDAP pour ce membre
 LDAPAttribute=Attribut LDAP
 LDAPAttributes=Attributs LDAP
 LDAPCard=Fiche LDAP
diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang
index 5e60a74e0be950e8738c0d10a01637d650786b27..67fd36fc424521c56075668a54d001ba0541d406 100644
--- a/htdocs/langs/fr_FR/main.lang
+++ b/htdocs/langs/fr_FR/main.lang
@@ -63,6 +63,7 @@ AddActionDone=Ajouter action faite
 Close=Cl�turer
 Close2=Fermer
 Confirm=Confirmer
+ConfirmSendCardByMail=Voulez vous envoyer cette fiche par mail ?
 Delete=Supprimer
 Remove=Enlever
 Resiliate=R�silier
diff --git a/htdocs/lib/authldap.lib.php b/htdocs/lib/authldap.lib.php
index d7a81b0b4c77e9e72e8459304a38c700230f7cf7..32a7fd1c6acab88ceaaa3e3d8be623f9b63b1205 100644
--- a/htdocs/lib/authldap.lib.php
+++ b/htdocs/lib/authldap.lib.php
@@ -174,10 +174,10 @@ class AuthLdap {
      * 2.1.2 : Simply closes the connection set up earlier.
      * Returns true if OK, false if there was an error.
      */
-    function close() {
-        if ( !@ldap_close($this->connection)) {
-            $this->ldapErrorCode = ldap_errno( $this->connection);
-            $this->ldapErrorText = ldap_error( $this->connection);
+    function close()
+    {
+        if ($this->connection && ! @ldap_close($this->connection))
+        {
             return false;
         } else {
             return true;
@@ -192,6 +192,7 @@ class AuthLdap {
         if ( !$this->result=@ldap_bind( $this->connection)) {
             $this->ldapErrorCode = ldap_errno( $this->connection);
             $this->ldapErrorText = ldap_error( $this->connection);
+            $this->error=$this->ldapErrorCode." ".$this->ldapErrorText;
             return false;
         } else {
             return true;
@@ -224,6 +225,7 @@ class AuthLdap {
         if ( !$this->result = @ldap_bind( $this->connection,$bindDn,$pass)) {
             $this->ldapErrorCode = ldap_errno( $this->connection);
             $this->ldapErrorText = ldap_error( $this->connection);
+            $this->error=$this->ldapErrorCode." ".$this->ldapErrorText;
             return false;
         } else {
             return true;
diff --git a/htdocs/lib/ldap.lib.php b/htdocs/lib/ldap.lib.php
new file mode 100644
index 0000000000000000000000000000000000000000..48f12071397cf88bc222ac122197637d67b5b519
--- /dev/null
+++ b/htdocs/lib/ldap.lib.php
@@ -0,0 +1,81 @@
+<?php
+/* Copyright (C) 2006 Laurent Destailleur  <eldy@users.sourceforge.net>
+ *
+ * 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/ldap.lib.php
+		\brief      Ensemble de fonctions de base pour le module LDAP
+        \ingroup    ldap
+        \version    $Revision$
+
+		Ensemble de fonctions de base de dolibarr sous forme d'include
+*/
+
+function ldap_prepare_head()
+{
+	global $langs, $conf, $user;
+	$langs->load("ldap");
+
+	// Onglets
+	$head=array();
+	$h = 0;
+	
+	$head[$h][0] = DOL_URL_ROOT."/admin/ldap.php";
+	$head[$h][1] = $langs->trans("LDAPGlobalParameters");
+	$head[$h][2] = 'ldap';
+	$h++;
+	
+	if ($conf->global->LDAP_SYNCHRO_ACTIVE)
+	{
+		$head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php";
+		$head[$h][1] = $langs->trans("LDAPUsersSynchro");
+		$head[$h][2] = 'users';
+		$h++;
+	}
+
+	if ($conf->global->LDAP_SYNCHRO_ACTIVE)
+	{
+		$head[$h][0] = DOL_URL_ROOT."/admin/ldap_groups.php";
+		$head[$h][1] = $langs->trans("LDAPGroupsSynchro");
+		$head[$h][2] = 'groups';
+		$h++;
+	}
+	
+	if ($conf->global->LDAP_CONTACT_ACTIVE)
+	{
+		$head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php";
+		$head[$h][1] = $langs->trans("LDAPContactsSynchro");
+		$head[$h][2] = 'contacts';
+		$h++;
+	}
+	
+	if ($conf->global->LDAP_MEMBERS_ACTIVE)
+	{
+		$head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php";
+		$head[$h][1] = $langs->trans("LDAPMembersSynchro");
+		$head[$h][2] = 'members';
+		$h++;
+	}
+
+	return $head;
+}
+
+?>
\ No newline at end of file
diff --git a/htdocs/lib/member.lib.php b/htdocs/lib/member.lib.php
new file mode 100644
index 0000000000000000000000000000000000000000..82596bc4a32cad4ba018999c3028df2835cd65ea
--- /dev/null
+++ b/htdocs/lib/member.lib.php
@@ -0,0 +1,56 @@
+<?php
+/* Copyright (C) 2006 Laurent Destailleur  <eldy@users.sourceforge.net>
+ *
+ * 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/memeber.lib.php
+		\brief      Ensemble de fonctions de base pour les adh�rents
+		\version    $Revision$
+
+		Ensemble de fonctions de base de dolibarr sous forme d'include
+*/
+
+function member_prepare_head($member)
+{
+	global $langs, $conf;
+	
+	$h = 0;
+	$head = array();
+	
+	$head[$h][0] = DOL_URL_ROOT.'/adherents/fiche.php?rowid='.$member->id;
+	$head[$h][1] = $langs->trans("Card");
+	$head[$h][2] = 'general';
+	$h++;
+	
+	if ($conf->ldap->enabled && $conf->global->LDAP_MEMBERS_ACTIVE)
+	{
+		$langs->load("ldap");
+		
+		$head[$h][0] = DOL_URL_ROOT.'/adherents/ldap.php?id='.$member->id;
+		$head[$h][1] = $langs->trans("LDAPCard");
+		$head[$h][2] = 'ldap';
+		$h++;
+	}
+
+	return $head;
+}
+
+?>
\ No newline at end of file
diff --git a/htdocs/user.class.php b/htdocs/user.class.php
index 03cf0560b249f0bfb7fe6e72cb937634f98b4567..b57d2eb467c1dc6bf3b414c402735ae9d4eae7c0 100644
--- a/htdocs/user.class.php
+++ b/htdocs/user.class.php
@@ -1195,6 +1195,18 @@ class User
 	}	
 
 
+	/**
+	*   \brief      Creation dans l'arbre LDAP
+	*   \param      user        Utilisateur qui effectue la creation
+	*	\return		int			<0 si ko, >0 si ok
+	*/
+	function create_ldap($user)
+	{
+		dolibarr_syslog("User.class::create_ldap this->id=".$this->id,LOG_DEBUG);
+		return $this->update_ldap($user);
+	}
+
+	
 	/**
 	*   \brief      Mise � jour dans l'arbre LDAP
 	*   \param      user        Utilisateur qui effectue la mise � jour
@@ -1227,90 +1239,19 @@ class User
 			}
 			if ($bind)
 			{
-				if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') 
-				{
-					$info["objectclass"]=array("top",
-											   "person",
-											   "organizationalPerson",
-											   "user");
-				}
-				else
-				{
-					$info["objectclass"]=array("top",
-											   "person",
-											   "organizationalPerson",
-											   "inetOrgPerson");
-				}	
-
-				// Champs obligatoires
-				$info["cn"] = trim($this->prenom." ".$this->nom);
-				if ($this->nom) $info[$conf->global->LDAP_FIELD_NAME] = $this->nom;
-				else
-				{
-					$langs->load("other");
-					$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name"));
-					return -1;
-				}
-				
-				// Champs optionnels
-				if ($this->prenom && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = $this->prenom;
-				if ($this->poste) $info["title"] = $this->poste;
-				if ($this->societe_id > 0)
-				{
-					$soc = new Societe($this->db);
-					$soc->fetch($this->societe_id);
-
-					$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')
-				{
-					$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)
-					{
-						$user->egroupware_id = 1;
-					}
-
-					$info["phpgwContactOwner"] = $user->egroupware_id;
-
-					if ($this->email) $info["rfc822Mailbox"] = $this->email;
-					if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
-				}
+				$info=$this->_load_ldap_info($info);
 
-				$info["uid"] = "Dolibarr ".$this->ldap_sid;
-
-				$newdn = "cn=".$info["cn"].",".$conf->global->LDAP_USER_DN;
-				$olddn = $newdn;
-				if ($this->old_firstname || $this->old_name) $olddn="cn=".trim($this->old_firstname." ".$this->old_name).",".$conf->global->LDAP_CONTACT_DN;
+				// Definitition du DN
+				$dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN;
+				$olddn = $dn;
+				if (($this->old_firstname || $this->old_name) && $conf->global->LDAP_KEY_USERS=="cn")
+					$olddn=$conf->global->LDAP_KEY_USERS."=".trim($this->old_firstname." ".$this->old_name).",".$conf->global->LDAP_USER_DN;
 
 				// On supprime et on ins�re
-				dolibarr_syslog("User.class::update_ldap olddn=".$olddn." newdn=".$newdn);	
+				dolibarr_syslog("User.class::update_ldap dn=".$dn." olddn=".$olddn);
 
 				$result = $ldap->delete($olddn);
-				$result = $ldap->add($newdn, $info);
+				$result = $ldap->add($dn, $info);
 				if ($result <= 0)
 				{
 					$this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error;
@@ -1374,9 +1315,9 @@ class User
 			
 			if ($bind)
 			{
-				$info["cn"] = trim($this->prenom." ".$this->nom);
-				$dn = "cn=".$info["cn"].",".$conf->global->LDAP_USER_DN;
-				
+				$info=$this->_load_ldap_info($info);
+
+				$dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN;
 				$result=$ldap->delete($dn);
 				
 				return $result;
@@ -1390,6 +1331,80 @@ class User
 		}
 	}
 	
+
+	function _load_ldap_info($info)
+	{
+		global $conf,$langs;
+		
+		if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') 
+		{
+			$info["objectclass"]=array("top",
+									   "person",
+									   "organizationalPerson",
+									   "user");
+		}
+		else
+		{
+			$info["objectclass"]=array("top",
+									   "person",
+									   "organizationalPerson",
+									   "inetOrgPerson");
+		}	
+
+		// Champs 
+		if ($this->fullname  && $conf->global->LDAP_FIELD_FULLNAME) $info[$conf->global->LDAP_FIELD_FULLNAME] = $this->fullname;
+		if ($this->nom && $conf->global->LDAP_FIELD_NAME) $info[$conf->global->LDAP_FIELD_NAME] = $this->nom;
+		if ($this->prenom && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = $this->prenom;
+		if ($this->login && $conf->global->LDAP_FIELD_LOGIN) $info[$conf->global->LDAP_FIELD_LOGIN] = $this->login;
+		if ($this->poste) $info["title"] = $this->poste;
+		if ($this->societe_id > 0)
+		{
+			$soc = new Societe($this->db);
+			$soc->fetch($this->societe_id);
+	
+			$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')
+		{
+			$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($this->egroupware_id) == 0)
+			{
+				$this->egroupware_id = 1;
+			}
+	
+			$info["phpgwContactOwner"] = $this->egroupware_id;
+	
+			if ($this->email) $info["rfc822Mailbox"] = $this->email;
+			if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
+		}
+
+		return $info;
+	}
+	
 	
 	/**
 	 *		\brief		Initialise le user avec valeurs fictives al�atoire
diff --git a/htdocs/user/group/ldap.php b/htdocs/user/group/ldap.php
index 05ac304daa6bced07941228ba871ef9f07a7333e..290c5fb3945373e91abe442fc5934ccdacded18d 100644
--- a/htdocs/user/group/ldap.php
+++ b/htdocs/user/group/ldap.php
@@ -84,6 +84,16 @@ print "</tr>\n";
 print '<tr><td width="25%" valign="top">'.$langs->trans("Note").'</td>';
 print '<td class="valeur">'.nl2br($fgroup->note).'&nbsp;</td>';
 print "</tr>\n";
+
+// LDAP DN
+$langs->load("admin");
+print '<tr><td>'.$langs->trans("LDAPGroupDn").'*</td><td class="valeur">'.$conf->global->LDAP_GROUP_DN."</td></tr>\n";
+
+// LDAP Server
+print '<tr><td>'.$langs->trans("LDAPPrimaryServer").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
+print '<tr><td>'.$langs->trans("LDAPSecondaryServer").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
+print '<tr><td>'.$langs->trans("LDAPServerPort").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
+
 print "</table>\n";
 
 print '</div>';
@@ -112,7 +122,7 @@ if ($result)
 		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
+	if (! $bind)	// Si pas de login ou si connexion avec login en echec, on tente en anonyme
 	{
 		dolibarr_syslog("ldap.php: bind",LOG_DEBUG);
 		$bind=$ldap->bind();
@@ -120,11 +130,15 @@ if ($result)
 
 	if ($bind)
 	{
-//		$info["cn"] = $ldap->getUserIdentifier()."=".$fuser->uname;
 		$info["cn"] = trim($fgroup->nom);
-		$dn = "cn=".$info["cn"].",".$conf->global->LDAP_GROUP_DN;
 
-		$result=$ldap->search($dn,'(objectClass=*)');
+		$dn = $conf->global->LDAP_GROUP_DN;
+//		$dn = "cn=".$info["cn"].",".$dn;
+//		$dn = "uid=".$info["uid"].",".$dn
+		$search = "(cn=".$info["cn"].")";
+		//$search = "(uid=".$info["uid"].")";
+
+		$result=$ldap->search($dn,$search);
 
 		// Affichage arbre
 		if (sizeof($result))
@@ -136,15 +150,18 @@ if ($result)
 		{
 			print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>';
 		}
+
+		$ldap->unbind();
 	}
 	else
 	{
-		dolibarr_print_error('',$ldap);
+		dolibarr_print_error('',$ldap->error);
 	}
+	$ldap->close();
 }
 else
 {
-	dolibarr_print_error('',$ldap);
+	dolibarr_print_error('',$ldap->error);
 }
 
 print '</table>';
diff --git a/htdocs/user/ldap.php b/htdocs/user/ldap.php
index 90f6c86359de8d5dd16ff40010ae930836588f91..82183f651c2f96398559e2937c818c04684e68e5 100644
--- a/htdocs/user/ldap.php
+++ b/htdocs/user/ldap.php
@@ -100,6 +100,15 @@ else
 }
 print '</tr>';
 
+// LDAP DN
+$langs->load("admin");
+print '<tr><td>'.$langs->trans("LDAPUserDn").'*</td><td class="valeur">'.$conf->global->LDAP_USER_DN."</td></tr>\n";
+
+// LDAP Server
+print '<tr><td>'.$langs->trans("LDAPPrimaryServer").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
+print '<tr><td>'.$langs->trans("LDAPSecondaryServer").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
+print '<tr><td>'.$langs->trans("LDAPServerPort").'*</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
+
 print '</table>';
 
 print '</div>';
@@ -128,7 +137,7 @@ if ($result)
 		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
+	if (! $bind)	// Si pas de login ou si connexion avec login en echec, on tente en anonyme
 	{
 		dolibarr_syslog("ldap.php: bind",LOG_DEBUG);
 		$bind=$ldap->bind();
@@ -136,11 +145,15 @@ if ($result)
 
 	if ($bind)
 	{
-//		$info["cn"] = $ldap->getUserIdentifier()."=".$fuser->uname;
 		$info["cn"] = trim($fuser->prenom." ".$fuser->nom);
-		$dn = "cn=".$info["cn"].",".$conf->global->LDAP_USER_DN;
 
-		$result=$ldap->search($dn,'(objectClass=*)');
+		$dn = $conf->global->LDAP_USER_DN;
+//		$dn = "cn=".$info["cn"].",".$dn;
+//		$dn = "uid=".$info["uid"].",".$dn
+		$search = "(cn=".$info["cn"].")";
+		//$search = "(uid=".$info["uid"].")";
+
+		$result=$ldap->search($dn,$search);
 
 		// Affichage arbre
 		if (sizeof($result))
@@ -152,15 +165,18 @@ if ($result)
 		{
 			print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>';
 		}
+
+		$ldap->unbind();
 	}
 	else
 	{
-		dolibarr_print_error('',$ldap);
+		dolibarr_print_error('',$ldap->error);
 	}
+	$ldap->close();
 }
 else
 {
-	dolibarr_print_error('',$ldap);
+	dolibarr_print_error('',$ldap->error);
 }
 
 print '</table>';
diff --git a/htdocs/usergroup.class.php b/htdocs/usergroup.class.php
index 1220e3a877906745b2efa6bdf23ed8bb83e66490..659ac6a5b9ff4567bbd1a21077aa28d40d093ec9 100644
--- a/htdocs/usergroup.class.php
+++ b/htdocs/usergroup.class.php
@@ -425,6 +425,18 @@ class UserGroup
    }
 
 
+	/**
+	*   \brief      Creation dans l'arbre LDAP
+	*   \param      user        Utilisateur qui effectue la creation
+	*	\return		int			<0 si ko, >0 si ok
+	*/
+	function create_ldap($user)
+	{
+		dolibarr_syslog("UserGroup.class::create_ldap this->id=".$this->id,LOG_DEBUG);
+		return $this->update_ldap($user);
+	}
+
+	
 	/**
 	*   \brief      Mise � jour dans l'arbre LDAP
 	*   \param      user        Utilisateur qui effectue la mise � jour
@@ -457,45 +469,17 @@ class UserGroup
 			}
 			if ($bind)
 			{
-				if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory')
-				{
-					$info["objectclass"]=array("top",
-											   "person",
-											   "organizationalPerson",
-											   "user");
-				}
-				else
-				{
-					$info["objectclass"]=array("top",
-											   "person",
-											   "organizationalPerson",
-											   "inetOrgPerson");
-				}
-
-				// Champs obligatoires
-				$info["cn"] = trim($this->nom);
-				if ($this->nom) $info[$conf->global->LDAP_FIELD_NAME] = $this->nom;
-				else
-				{
-					$langs->load("other");
-					$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name"));
-					return -1;
-				}
-
-				// Champs optionnels
-				if ($this->note) $info["description"] = $this->note;
+				$info=$this->_load_ldap_info($info);
 
-				$info["uid"] = "Dolibarr ".$this->id;
-
-				$newdn = "cn=".$info["cn"].",".$conf->global->LDAP_GROUP_DN;
-				$olddn = $newdn;
-				if ($this->old_name) $olddn="cn=".trim($this->old_name).",".$conf->global->LDAP_CONTACT_DN;
+				// Definitition du DN
+				$dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN;
+				$olddn = $dn;
 
 				// On supprime et on ins�re
-				dolibarr_syslog("UserGroup.class::update_ldap olddn=".$olddn." newdn=".$newdn);
+				dolibarr_syslog("User.class::update_ldap dn=".$dn." olddn=".$olddn);
 
 				$result = $ldap->delete($olddn);
-				$result = $ldap->add($newdn, $info);
+				$result = $ldap->add($dn, $info);
 				if ($result <= 0)
 				{
 					$this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error;
@@ -558,9 +542,9 @@ class UserGroup
 
 			if ($bind)
 			{
-				$info["cn"] = trim($this->nom);
-				$dn = "cn=".$info["cn"].",".$conf->global->LDAP_GROUP_DN;
+				$info=$this->_load_ldap_info($info);
 
+				$dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN;
 				$result=$ldap->delete($dn);
 
 				return $result;
@@ -574,6 +558,36 @@ class UserGroup
 		}
 	}
 
+
+	function _load_ldap_info($info)
+	{
+		global $conf,$langs;
+		
+		if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory')
+		{
+			$info["objectclass"]=array("top",
+									   "person",
+									   "organizationalPerson",
+									   "user");
+		}
+		else
+		{
+			$info["objectclass"]=array("top",
+									   "person",
+									   "organizationalPerson",
+									   "inetOrgPerson");
+		}
+
+		// Champs 
+		if ($this->fullname  && $conf->global->LDAP_FIELD_FULLNAME) $info[$conf->global->LDAP_FIELD_FULLNAME] = $this->fullname;
+		if ($this->name && $conf->global->LDAP_FIELD_NAME) $info[$conf->global->LDAP_FIELD_NAME] = $this->name;
+		if ($this->firstname && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = $this->firstname;
+		if ($this->note) $info["description"] = $this->note;
+
+		return $info;
+	}
+
+
 	/**
 	 *		\brief		Initialise le groupe avec valeurs fictives al�atoire
 	 */