diff --git a/htdocs/adherents/ldap.php b/htdocs/adherents/ldap.php
index 6733039e7e1a0a2e891cedd36b76b28db68f59c1..946b28cb0584e7ca7c9e4d84640f2f62a4eb4461 100644
--- a/htdocs/adherents/ldap.php
+++ b/htdocs/adherents/ldap.php
@@ -118,6 +118,8 @@ print '<tr><td>LDAP '.$langs->trans("LDAPMemberDn").'</td><td class="valeur">'.$
 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS."</td></tr>\n";
 
 // LDAP Server
+print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
+print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
@@ -154,7 +156,7 @@ if ($result > 0)
 	{
 		if (! is_array($records))
 		{
-			print '<tr><td colspan="2">'.$langs->trans("ErrorFailedToReadLDAP").'</td></tr>';	
+			print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';	
 		}
 		else
 		{
@@ -164,7 +166,7 @@ if ($result > 0)
 	}
 	else
 	{
-		print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>';
+		print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
 	}
 
 	$ldap->unbind();
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 96cf2a4bcfa93d8b5a56df986e1bd3f26397d208..efc4108df566a9c03bc743eaee5c8a913b42971f 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -2259,8 +2259,8 @@ class Facture extends CommonObject
 
   /**
      \brief     	Renvoi liste des factures remplacables
-     Statut validee + aucun paiement + non paye + pas deja remplac�es
-     \param		socid		Id societe
+					Statut valid�e + aucun paiement + non pay�e + pas deja remplac�e
+     \param			socid		Id societe
      \return    	array		Tableau des factures ('id'=>id, 'ref'=>ref, 'statut'=>status)
    */
   function list_replacable_invoices($socid=0)
@@ -2274,9 +2274,10 @@ class Facture extends CommonObject
     $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
     $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
     $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON f.rowid = ff.fk_facture_source";
-    $sql.= " WHERE f.fk_statut = 1 AND f.paye = 0 AND pf.fk_paiement IS NULL";
-    $sql.= " AND ff.fk_statut IS NULL";			// Renvoie vrai si pas de jointure
-    //$sql.= " AND IFNULL(ff.fk_statut,0) = 0";	// Renvoie vrai si pas de jointure ou si jointure vers statut � 0
+    $sql.= " WHERE f.fk_statut = 1";
+	$sql.= " AND f.paye = 0";					// Pas class�e pay�e compl�tement
+	$sql.= " AND pf.fk_paiement IS NULL";		// Aucun paiement deja fait
+    $sql.= " AND ff.fk_statut IS NULL";			// Renvoi vrai si pas facture de remplacement
     if ($socid > 0) $sql.=" AND f.fk_soc = ".$socid;
     $sql.= " ORDER BY f.facnumber";
 
@@ -2304,7 +2305,7 @@ class Facture extends CommonObject
 
   /**
    *  	\brief     	Renvoi liste des factures qualifiables pour avoir
-   *				Statut >= validee + pas class� pay�e completement + pas class� pay�e partiellement + pas deja remplac�e
+   *				Statut >= valid�e + class�e pay�e completement ou class�e pay�e partiellement + pas deja remplac�e
    *	\param		socid		Id societe
    *   	\return    	array		Tableau des factures ($id => $ref)
    */
@@ -2319,9 +2320,9 @@ class Facture extends CommonObject
     $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
     $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON (f.rowid = ff.fk_facture_source AND ff.type=1)";
     $sql.= " WHERE f.fk_statut >= 1";
-	$sql.= " AND f.paye = 0";			// Pas class� pay� compl�tement
-	$sql.= " AND f.close_code IS NULL";	// Pas class� pay� partiellement
-    $sql.= " AND ff.type IS NULL";		// Renvoi vrai si pas facture de remplacement
+	$sql.= " AND (f.paye = 1";				// Class�e pay�e compl�tement
+	$sql.= " OR f.close_code IS NOT NULL)";	// Class�e pay�e partiellement
+    $sql.= " AND ff.type IS NULL";			// Renvoi vrai si pas facture de remplacement
     if ($socid > 0) $sql.=" AND f.fk_soc = ".$socid;
     $sql.= " ORDER BY f.facnumber";
 
diff --git a/htdocs/includes/modules/modAdherent.class.php b/htdocs/includes/modules/modAdherent.class.php
index fc9720f571325c8d65e315c28bdfc0537c4060e8..cc0c96430259feca89cc32dba4720786d045d030 100644
--- a/htdocs/includes/modules/modAdherent.class.php
+++ b/htdocs/includes/modules/modAdherent.class.php
@@ -84,7 +84,7 @@ class modAdherent extends DolibarrModules
         $this->const[2]= array("ADHERENT_MAIL_EDIT","texte","Voici le rappel des coordonnees que vous avez modifiees (toute information erronee entrainera la non validation de votre inscription) :\r\n\r\n%INFO%\r\n\r\nVous pouvez a tout moment, grace a votre login et mot de passe, modifier vos coordonnees a l'adresse suivante :\r\n%SERVEUR%public/adherents/","Mail d'edition");
         $this->const[3] = array("ADHERENT_MAIL_RESIL","texte","Votre adhesion sur %SERVEUR% vient d'etre resilie.\r\nNous esperons vous revoir tres bientot","Mail de r�siliation");
         $this->const[4] = array("ADHERENT_MAIL_NEW","texte","Merci de votre inscription. Votre adhesion devrait etre rapidement validee.^M\nVoici le rappel des coordonnees que vous avez rentrees (toute information erronee entrainera la non validation de votre inscription) :\r\n\r\n%INFO%\r\n\r\nVous pouvez a tout moment, grace a votre login et mot de passe, modifier vos coordonnees a l'adresse suivante :\r\n%SERVEUR%public/adherents/","Mail de nouvel inscription");
-        $this->const[5] = array("ADHERENT_MAIL_VALID_SUBJECT","chaine"," Votre adh<E9>sion a ete valid<E9>e sur %SERVEUR%","sujet du mail de validation");
+        $this->const[5] = array("ADHERENT_MAIL_VALID_SUBJECT","chaine"," Votre adhesion a ete validee sur %SERVEUR%","sujet du mail de validation");
         $this->const[6] = array("ADHERENT_MAIL_RESIL_SUBJECT","chaine","Resiliation de votre adhesion sur %SERVEUR% ","sujet du mail de resiliation");
         $this->const[7] = array("ADHERENT_MAIL_NEW_SUBJECT","chaine","Bienvenue sur %SERVEUR%","Sujet du mail de nouvelle adhesion");
         $this->const[8] = array("ADHERENT_MAIL_EDIT_SUBJECT","chaine","Votre fiche a ete editee sur %SERVEUR%","Sujet du mail d'edition");
@@ -101,7 +101,7 @@ class modAdherent extends DolibarrModules
         $this->const[19] = array("ADHERENT_SPIP_SERVEUR","chaine","","serveur spip");
         $this->const[20] = array("ADHERENT_SPIP_DB","chaine","","db spip");
         $this->const[21] = array("ADHERENT_MAIL_FROM","chaine","","From des mails");
-        $this->const[22] = array("ADHERENT_MAIL_COTIS","texte","Bonjour %PRENOM%,^M\n^M\nCet email confirme que votre cotisation a ete recue\r\net enregistree","Mail de validation de cotisation");
+        $this->const[22] = array("ADHERENT_MAIL_COTIS","texte","Bonjour %PRENOM%,\r\nCet email confirme que votre cotisation a ete recue\r\net enregistree","Mail de validation de cotisation");
         $this->const[23] = array("ADHERENT_MAIL_COTIS_SUBJECT","chaine"," Recu de votre cotisation","sujet du mail de validation de cotisation");
         $this->const[24] = array("ADHERENT_TEXT_NEW_ADH","texte","","Texte d'entete du formulaire d'adhesion en ligne");
         $this->const[25] = array("ADHERENT_CARD_HEADER_TEXT","chaine","%ANNEE%","Texte imprime sur le haut de la carte adherent");
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 7d4cef8a7210f39216fd1160ea755c1b5cfd3e3f..146549602259ae9c746af1a50be6c7017df41203 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -531,7 +531,7 @@ LDAPServerUseTLSExample=Your LDAP server use TLS
 LDAPServerDn=Server DN
 LDAPAdminDn=Administrator DN
 LDAPAdminDnExample=Complete DN (ex: cn=adminldap,dc=society,dc=com)
-LDAPPassword=administrator password
+LDAPPassword=Administrator password
 LDAPUserDn=Users' DN
 LDAPUserDnExample=Complete DN (ex: ou=users,dc=society,dc=com)
 LDAPGroupDn=Groups' DN
@@ -559,7 +559,7 @@ LDAPTestSynchroGroup=Test group's synchronization
 LDAPTestSynchroMember=Test member's synchronization
 LDAPSynchroOK=Synchronization test successful
 LDAPSynchroKO=Failed synchronization test
-LDAPSynchroKOMayBePermissions=Failed synchronization test. Chack that connexion to server is correctly configured and allows LDAP udpates
+LDAPSynchroKOMayBePermissions=Failed synchronization test. Check that connexion to server is correctly configured and allows LDAP udpates
 LDAPTCPConnectOK=TCP connect to LDAP server successful (Server=%s, Port=%s)
 LDAPTCPConnectKO=TCP connect to LDAP server failed (Server=%s, Port=%s)
 LDAPBindOK=Connect/Authentificate to LDAP server sucessfull (Server=%s, Port=%s, Admin=%s, Password=%s)
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index cdc85f815e2389b1d4bbe4968ca2168fa6d92c30..7bf23a92af65f459d0280fa11824d02d035f6a2d 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -16,7 +16,7 @@ InvoiceReplacementAsk=Replacement invoice for invoice
 InvoiceReplacementDesc=<b>Replacement invoice</b> is used to cancel and replace completely an invoice with no paiement already recevided.<br>Reference of canceled invoice is required.
 InvoiceAvoir=Credit note
 InvoiceAvoirAsk=Credit note to correct invoice
-InvoiceAvoirDesc=The <b>credit note</b> is a negative invoice used to solve fact that an invoice has an higher amount that amount that was or will be payed (all possible reasons).
+InvoiceAvoirDesc=The <b>credit note</b> is a negative invoice used to solve fact that an invoice has an higher amount that should be (all possible reasons) or a product returned after invoice was payed.
 ReplaceInvoice=Replace invoice %s
 ReplacedByInvoice=Replaced by invoice %s
 CorrectInvoice=Correct invoice %s
@@ -85,7 +85,7 @@ BillShortStatusValidated=Validated
 BillShortStatusStarted=Started
 BillShortStatusNotPayed=Not payed
 BillShortStatusClosedUnpayed=Closed
-BillShortStatusClosedPayedPartially=Payed (part)
+BillShortStatusClosedPayedPartially=Payed (partially)
 PaymentStatusToValidShort=To validate
 ErrorVATIntraNotConfigured=Intracommunautary VAT number not yet defined
 ErrorNoPaiementModeConfigured=No paiment mode yet defined
diff --git a/htdocs/langs/en_US/ldap.lang b/htdocs/langs/en_US/ldap.lang
index 2d9a20eac5e0b0c3fa6268becfe6ad311b3f19a9..97c087ad216900bb1870f23e4657312a6537a1ee 100644
--- a/htdocs/langs/en_US/ldap.lang
+++ b/htdocs/langs/en_US/ldap.lang
@@ -17,4 +17,4 @@ LDAPGroups=Groups in LDAP database
 SynchronizeDolibarr2Ldap=Synchronize user (Dolibarr -> LDAP)
 UserSynchronized=User synchronized
 ForceSynchronize=Force synchronizing Dolibarr -> LDAP
-ErrorFailedToReadLDAP=Failed to read LDAP database.Check LDAP module setup and database accessibility.
+ErrorFailedToReadLDAP=Failed to read LDAP database. Check LDAP module setup and database accessibility.
diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang
index fd8dd3a3a20c5ccd9bd096bdb6fd0f15cf39d660..a2be5f555c8cfce65328f468932d3e83e80f094d 100644
--- a/htdocs/langs/fr_FR/bills.lang
+++ b/htdocs/langs/fr_FR/bills.lang
@@ -16,7 +16,7 @@ InvoiceReplacementAsk=Facture de remplacement de la facture
 InvoiceReplacementDesc=La <b>facture de remplacement</b> sert � annuler et remplacer une facture existante sur laquelle aucun paiement n'a encore eu lieu.<br>La r�f�rence de la facture qui doit �tre annul�e est obligatoire.
 InvoiceAvoir=Facture avoir
 InvoiceAvoirAsk=Facture avoir pour correction de la facture
-InvoiceAvoirDesc=La <b>facture d'avoir</b> est une facture n�gative destin�e � compenser une facture comportant un montant sup�rieur � ce qui a �t� ou sera r�ellement pay� (toutes causes possibles).
+InvoiceAvoirDesc=La <b>facture d'avoir</b> est une facture n�gative destin�e � compenser une facture comportant un montant sup�rieur � ce qui aurait du (toutes causes possibles) ou parce qu'un produit a �t� retourn� apr�s que la facture soit pay�e.
 ReplaceInvoice=Remplace la facture %s
 ReplacedByInvoice=Remplac�e par la facture %s
 CorrectInvoice=Corrige facture %s
diff --git a/htdocs/lib/ldap.class.php b/htdocs/lib/ldap.class.php
index 67ce8555bff6b4cd2f7fa29f3f3792ba1b7c7bc7..2c0fe3ded3375d3155b3476812d0e63b1e162824 100644
--- a/htdocs/lib/ldap.class.php
+++ b/htdocs/lib/ldap.class.php
@@ -213,8 +213,18 @@ class Ldap
 
 				if ($this->serverType == "activedirectory")
 				{
-					$this->setReferrals();
-					$connected=2;
+					$result=$this->setReferrals();
+					if ($result)
+					{
+						//$this->bind=????	Comment positionne-t-on bind avec activedirectory ?
+						//si bind non d�fini, les autres fonctions �chouent
+						$connected=2;
+						break;
+					}
+					else
+					{
+						$this->error=ldap_errno($this->connection).' '.ldap_error($this->connection);
+					}
 				}
 				else
 				{
@@ -656,6 +666,9 @@ class Ldap
 		$fp=fopen($file,"w");
 		if ($fp)
 		{
+			fputs($fp,"# ldapadd -c -v -D cn=Manager,dc=my-domain,dc=com -W -f ldapinput.in\n");
+			fputs($fp,"# ldapmodify -c -v -D cn=Manager,dc=my-domain,dc=com -W -f ldapinput.in\n");
+			fputs($fp,"# ldapdelete -c -v -D cn=Manager,dc=my-domain,dc=com -W -f ldapinput.in\n");
 			fputs($fp, "dn: ".$dn."\n");	
 			foreach($info as $key => $value)
 			{
@@ -817,11 +830,19 @@ class Ldap
         	return -1;
         } 	 
   	 
-         $entry = ldap_first_entry($this->connection, $ldapSearchResult); 	 
-         $ldapBinary = ldap_get_values_len ($this->connection, $entry, "objectsid"); 	 
-         $SIDText = $this->binSIDtoText($ldapBinary[0]); 	 
-         return $SIDText; 	 
-         return $ldapBinary; 	 
+        $entry = ldap_first_entry($this->connection, $ldapSearchResult); 	 
+        if ($entry)
+		{
+			$ldapBinary = ldap_get_values_len ($this->connection, $entry, "objectsid"); 	 
+			$SIDText = $this->binSIDtoText($ldapBinary[0]);
+			return $SIDText; 	 
+			//return $ldapBinary; 	 
+		}
+		else
+		{
+			return '?';
+		}
+
      }
      
      /**
diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php
index 8d703c178f1747aecd80111e0e8050faba24426b..943b2a9a860d67e6e3d1205139d15f74990bcf4e 100644
--- a/htdocs/user/fiche.php
+++ b/htdocs/user/fiche.php
@@ -729,7 +729,14 @@ else
 
             // Ref
             print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>';
-            print '<td width="50%">'.$fuser->id.'</td>';
+            print '<td width="50%">';
+
+			if ($previous_ref || $next_ref) print '<table class="nobordernopadding" width="100%"><tr class="nobordernopadding"><td class="nobordernopadding">';
+			print $fuser->id;
+			if ($previous_ref || $next_ref) print '</td><td class="nobordernopadding" align="center" width="20">'.$previous_ref.'</td><td class="nobordernopadding" align="center" width="20">'.$next_ref.'</td></tr></table>';
+			
+			print '</td>';
+			
             print '<td align="center" valign="middle" width="25%" rowspan="'.$rowspan.'">';
             if (file_exists($conf->users->dir_output."/".$fuser->id.".jpg"))
             {
diff --git a/htdocs/user/ldap.php b/htdocs/user/ldap.php
index e6a3f0aaae0b712955e916b2948b40d740cf68dd..1710b66f0c8fe387b17626287578f9c8a1055bdb 100644
--- a/htdocs/user/ldap.php
+++ b/htdocs/user/ldap.php
@@ -61,14 +61,13 @@ if ($_GET["action"] == 'dolibarr2ldap')
 	$db->begin();
 
 	$ldap=new Ldap();
-	$ldap->connect_bind();
+	$result=$ldap->connect_bind();
 
 	$info=$fuser->_load_ldap_info();
 	$dn=$fuser->_load_ldap_dn($info);
-	
-    $ret=$ldap->update($dn,$info,$user);	// Marche en creation LDAP et mise a jour
+    $result=$ldap->update($dn,$info,$user);	// Marche en creation LDAP et mise a jour
 
-	if ($ret >= 0)
+	if ($result >= 0)
 	{
 		$message.='<div class="ok">'.$langs->trans("UserSynchronized").'</div>';
 		$db->commit();
@@ -153,6 +152,8 @@ print '<tr><td>LDAP '.$langs->trans("LDAPUserDn").'</td><td class="valeur">'.$co
 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_USERS."</td></tr>\n";
 
 // LDAP Server
+print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
+print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
@@ -199,21 +200,26 @@ if ($result > 0)
 	$info=$fuser->_load_ldap_info();
 	$dn=$fuser->_load_ldap_dn($info,1);
 	$search = "(".$fuser->_load_ldap_dn($info,2).")";
-	$result=$ldap->search($dn,$search);
-	if ($result < 0)
-	{
-		dolibarr_print_error($db,$ldap->error);
-	}
-	
+	$records=$ldap->search($dn,$search);
+
+	//print_r($records);
+
 	// Affichage arbre
-	if (sizeof($result))
+	if (sizeof($records) && (! isset($records['count']) || $records['count'] > 0))
 	{
-		$html=new Form($db);
-		$html->show_ldap_content($result,0,0,true);
+		if (! is_array($records))
+		{
+			print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';	
+		}
+		else
+		{
+			$html=new Form($db);
+			$result=$html->show_ldap_content($records,0,0,true);
+		}
 	}
 	else
 	{
-		print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>';
+		print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
 	}
 
 	$ldap->unbind();