diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php
index 125c5a6f28d02eccaa68f60cb4183d88143fb836..c5273bddd2aa0b9e9c8de677a1eeeb2becf246da 100644
--- a/htdocs/comm/propal/contact.php
+++ b/htdocs/comm/propal/contact.php
@@ -18,11 +18,11 @@
  */
 
 /**
-        \file       htdocs/comm/propal/contact.php
-        \ingroup    propal
-        \brief      Onglet de gestion des contacts de propal
-        \version    $Id$
-*/
+ *       \file       htdocs/comm/propal/contact.php
+ *       \ingroup    propal
+ *       \brief      Onglet de gestion des contacts de propal
+ *       \version    $Id$
+ */
 
 require ("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
@@ -162,11 +162,12 @@ $contactstatic=new Contact($db);
 /* *************************************************************************** */
 if (isset($mesg)) print $mesg;
 
-$id = $_GET["propalid"];
-if ($id > 0)
+$id = $_GET['propalid'];
+$ref= $_GET['ref'];
+if ($id > 0 || ! empty($ref))
 {
 	$propal = New Propal($db);
-	if ( $propal->fetch($_GET['propalid']) > 0)
+	if ( $propal->fetch($id,$ref) > 0)
 	{
 		$soc = new Societe($db, $propal->socid);
 		$soc->fetch($propal->socid);
@@ -181,10 +182,12 @@ if ($id > 0)
 		*/
 		print '<table class="border" width="100%">';
 
+		$linkback="<a href=\"".$_SERVER["PHP_SELF"]."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder\">".$langs->trans("BackToList")."</a>";
+
 		// Ref
-		print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
-		print $propal->ref;
-		print "</td></tr>";
+		print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
+		print $html->showrefnav($propal,'ref',$linkback,1,'ref','ref','');
+		print '</td></tr>';
 
 		// Ref client
 		print '<tr><td>';
diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php
index 1744b1fc524b4bcfafd4423a15d30f4fc952bee3..e6fb8936c63ded2596595d543d5bc396f46b7e0e 100644
--- a/htdocs/comm/propal/document.php
+++ b/htdocs/comm/propal/document.php
@@ -20,11 +20,11 @@
  */
 
 /**
-        \file       htdocs/comm/propal/document.php
-        \ingroup    propale
-        \brief      Page de gestion des documents attach�es � une proposition commerciale
-        \version    $Id$
-*/
+ *       \file       htdocs/comm/propal/document.php
+ *       \ingroup    propale
+ *       \brief      Page de gestion des documents attach�es � une proposition commerciale
+ *       \version    $Id$
+ */
 
 require('./pre.inc.php');
 require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
@@ -109,15 +109,19 @@ if ($action=='delete')
 
 
 /*
- * Affichage
+ * View
  */
 
 llxHeader();
 
-if ($propalid > 0)
+$html = new Form($db);
+
+$id = $_GET['propalid'];
+$ref= $_GET['ref'];
+if ($id > 0 || ! empty($ref))
 {
 	$propal = new Propal($db);
-	if ($propal->fetch($propalid))
+	if ($propal->fetch($id,$ref))
     {
 		$upload_dir = $conf->propale->dir_output.'/'.dol_sanitizeFileName($propal->ref);
 
@@ -139,11 +143,29 @@ if ($propalid > 0)
 
         print '<table class="border"width="100%">';
 
-		// Ref
-        print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">'.$propal->ref.'</td></tr>';
+		$linkback="<a href=\"".$_SERVER["PHP_SELF"]."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder\">".$langs->trans("BackToList")."</a>";
 
-        // Soci�t�
-        print '<tr><td>'.$langs->trans('Company').'</td><td colspan="5">'.$societe->getNomUrl(1).'</td></tr>';
+		// Ref
+		print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
+		print $html->showrefnav($propal,'ref',$linkback,1,'ref','ref','');
+		print '</td></tr>';
+
+		// Ref client
+		print '<tr><td>';
+		print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
+		print $langs->trans('RefCustomer').'</td><td align="left">';
+		print '</td>';
+		print '</tr></table>';
+		print '</td><td colspan="3">';
+		print $propal->ref_client;
+		print '</td>';
+		print '</tr>';
+
+		// Customer
+		if ( is_null($propal->client) )
+			$propal->fetch_client();
+		print "<tr><td>".$langs->trans("Company")."</td>";
+		print '<td colspan="3">'.$propal->client->getNomUrl(1).'</td></tr>';
 
         print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.sizeof($filearray).'</td></tr>';
         print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
diff --git a/htdocs/comm/propal/note.php b/htdocs/comm/propal/note.php
index 70781a9fa51ecad2634b29ddf6196bbeadd34dc8..cdf9c01d14bd9ead92c5e03c1d84cf5be5126c14 100644
--- a/htdocs/comm/propal/note.php
+++ b/htdocs/comm/propal/note.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2004      Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2004      Eric Seigne          <eric.seigne@ryxeo.com>
  * Copyright (C) 2005-2009 Regis Houssin        <regis@dolibarr.fr>
  *
@@ -20,10 +20,10 @@
  */
 
 /**
- \file       htdocs/comm/propal/note.php
- \ingroup    propale
- \brief      Fiche d'information sur une proposition commerciale
- \version    $Id$
+ *	\file       htdocs/comm/propal/note.php
+ *	\ingroup    propale
+ *	\brief      Fiche d'information sur une proposition commerciale
+ *	\version    $Id$
  */
 
 require('./pre.inc.php');
@@ -94,14 +94,16 @@ llxHeader();
 
 $html = new Form($db);
 
-if ($_GET['propalid'])
+$id = $_GET['propalid'];
+$ref= $_GET['ref'];
+if ($id > 0 || ! empty($ref))
 {
 	if ($mesg) print $mesg;
 
 	$now=gmmktime();
 
 	$propal = new Propal($db);
-	if ( $propal->fetch($_GET['propalid']) )
+	if ($propal->fetch($id, $ref))
 	{
 		$societe = new Societe($db);
 		if ( $societe->fetch($propal->socid) )
@@ -111,10 +113,29 @@ if ($_GET['propalid'])
 
 			print '<table class="border" width="100%">';
 
-			print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">'.$propal->ref.'</td></tr>';
+			$linkback="<a href=\"".$_SERVER["PHP_SELF"]."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder\">".$langs->trans("BackToList")."</a>";
 
-			// Societe
-			print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">'.$societe->getNomUrl(1).'</td></tr>';
+			// Ref
+			print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
+			print $html->showrefnav($propal,'ref',$linkback,1,'ref','ref','');
+			print '</td></tr>';
+
+			// Ref client
+			print '<tr><td>';
+			print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
+			print $langs->trans('RefCustomer').'</td><td align="left">';
+			print '</td>';
+			print '</tr></table>';
+			print '</td><td colspan="3">';
+			print $propal->ref_client;
+			print '</td>';
+			print '</tr>';
+
+			// Customer
+			if ( is_null($propal->client) )
+				$propal->fetch_client();
+			print "<tr><td>".$langs->trans("Company")."</td>";
+			print '<td colspan="3">'.$propal->client->getNomUrl(1).'</td></tr>';
 
 			// Ligne info remises tiers
 			print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="3">';
@@ -122,7 +143,7 @@ if ($_GET['propalid'])
 			else print $langs->trans("CompanyHasNoRelativeDiscount");
 			$absolute_discount=$societe->getAvailableDiscounts();
 			print '. ';
-			if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
+			if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie));
 			else print $langs->trans("CompanyHasNoAbsoluteDiscount");
 			print '.';
 			print '</td></tr>';
diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index a0876250a77f54799b14760a66deecd7e9d88c3c..7bc39f37caae2b66793e65c8f89ac0f04e6ca9a3 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -42,6 +42,7 @@ class Commande extends CommonObject
 	var $table_element='commande';
 	var $table_element_line = 'commandedet';
 	var $fk_element = 'fk_commande';
+	var $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
 	var $id ;
 
diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php
index 7469857f555d7e3506707497ecfa9ca521e6978b..aa9d5739ed6f566d1b7f3755005d9ccd6d7d62d8 100644
--- a/htdocs/commonobject.class.php
+++ b/htdocs/commonobject.class.php
@@ -406,22 +406,29 @@ class CommonObject
 	/**
 	 *      \brief      Load properties id_previous and id_next
 	 *      \param      filter		Optional filter
-	 *	   \param      fieldid   	Nom du champ a utiliser pour select next et previous
-	 *      \return     int         	<0 if KO, >0 if OK
+	 *	 	\param      fieldid   	Name of field to use for the select MAX and MIN
+	 *      \return     int         <0 if KO, >0 if OK
 	 */
 	function load_previous_next_ref($filter='',$fieldid)
 	{
+		global $conf;
+
 		if (! $this->table_element)
 		{
 			dol_syslog("CommonObject::load_previous_next was called on objet with property table_element not defined", LOG_ERR);
 			return -1;
 		}
 
+ 		// this->ismultientitymanaged contains
+		// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+
 		$sql = "SELECT MAX(".$fieldid.")";
-		$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
-		if ($this->table_optional) $sql.= ", ".MAIN_DB_PREFIX.$this->table_optional;
-		$sql.= " WHERE ".$fieldid." < '".addslashes($this->ref)."'";
+		$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te";
+		if ($this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s";	// If we need to link to societe to limit select to entity
+		$sql.= " WHERE te.".$fieldid." < '".addslashes($this->ref)."'";
 		if (isset($filter)) $sql.=" AND ".$filter;
+		if ($this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid';			// If we need to link to societe to limit select to entity
+		if ($this->ismultientitymanaged > 0) $sql.= ' AND entity IN (0,'.$conf->entity.')';
 
 		//print $sql."<br>";
 		$result = $this->db->query($sql) ;
@@ -435,11 +442,13 @@ class CommonObject
 
 
 		$sql = "SELECT MIN(".$fieldid.")";
-		$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
-		if ($this->table_optional) $sql.= ", ".MAIN_DB_PREFIX.$this->table_optional;
-		$sql.= " WHERE ".$fieldid." > '".addslashes($this->ref)."'";
+		$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te";
+		if ($this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s";	// If we need to link to societe to limit select to entity
+		$sql.= " WHERE te.".$fieldid." > '".addslashes($this->ref)."'";
 		if (isset($filter)) $sql.=" AND ".$filter;
-		// Rem: Bug in some mysql version: SELECT rowid FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null
+		if ($this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid';			// If we need to link to societe to limit select to entity
+		if ($this->ismultientitymanaged > 0) $sql.= ' AND entity IN (0,'.$conf->entity.')';
+		// Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null
 
 		//print $sql."<br>";
 		$result = $this->db->query($sql) ;
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index d727ba5dab07256ae3561e4baa1c5cff8c18c274..c708d0ab8cc7f76d4c4096401954be05958684e0 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1977,7 +1977,7 @@ else
 		$facstatic = new Facture($db);
 
 		$fac = new Facture($db);
-		$result=$fac->fetch($_GET['facid'],$_GET['ref']);
+		$result=$fac->fetch($id,$ref);
 		if ($result > 0)
 		{
 			if ($user->societe_id>0 && $user->societe_id!=$fac->socid)  accessforbidden('',0);
diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php
index cd50321aa010a51adb93c46e6067620d57253563..7114ac3a1d3068b231816d0c268590550113170a 100644
--- a/htdocs/compta/facture/contact.php
+++ b/htdocs/compta/facture/contact.php
@@ -27,6 +27,7 @@
 require ("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
 require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
+require_once(DOL_DOCUMENT_ROOT.'/discount.class.php');
 require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php');
 require_once(DOL_DOCUMENT_ROOT.'/html.formcompany.class.php');
 
@@ -159,11 +160,13 @@ $contactstatic=new Contact($db);
 /*                                                                             */
 /* *************************************************************************** */
 if (isset($mesg)) print $mesg;
-$id = $_GET["facid"];
-if ($id > 0)
+
+$id = $_GET['facid'];
+$ref= $_GET['ref'];
+if ($id > 0 || ! empty($ref))
 {
-	$facture = New Facture($db);
-	if ( $facture->fetch($_GET['facid'], $user->societe_id) > 0)
+	$facture = new Facture($db);
+	if ($facture->fetch($id, $ref) > 0)
 	{
 		$facture->fetch_client();
 
@@ -176,10 +179,22 @@ if ($id > 0)
 		 */
 		print '<table class="border" width="100%">';
 
-		// Reference du facture
-		print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
-		print $facture->ref;
-		print "</td></tr>";
+		// Ref
+		print '<tr><td width="20%">'.$langs->trans('Ref').'</td>';
+		print '<td colspan="3">';
+		$morehtmlref='';
+		$discount=new DiscountAbsolute($db);
+		$result=$discount->fetch(0,$facture->id);
+		if ($result > 0)
+		{
+			$morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
+		}
+		if ($result < 0)
+		{
+			dol_print_error('',$discount->error);
+		}
+		print $html->showrefnav($facture,'ref','',1,'facnumber','ref',$morehtmlref);
+		print '</td></tr>';
 
 		// Customer
 		print "<tr><td>".$langs->trans("Company")."</td>";
diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php
index bff24e396e1825e11b51fef06b26b1834e9419e1..f00c9e1e1cd33190e1b33fd9f9db5a753662de4c 100644
--- a/htdocs/compta/facture/document.php
+++ b/htdocs/compta/facture/document.php
@@ -20,14 +20,15 @@
  */
 
 /**
- \file       htdocs/compta/facture/document.php
- \ingroup    facture
- \brief      Page de gestion des documents attach�es � une facture
- \version    $Id$
+ *	\file       htdocs/compta/facture/document.php
+ *	\ingroup    facture
+ *	\brief      Page for attached files on invoices
+ *	\version    $Id$
  */
 
 require('./pre.inc.php');
 require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
+require_once(DOL_DOCUMENT_ROOT.'/discount.class.php');
 require_once(DOL_DOCUMENT_ROOT."/lib/invoice.lib.php");
 require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
 require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php");
@@ -109,15 +110,19 @@ if ($action=='delete')
 }
 
 /*
- * Affichage
+ * View
  */
 
 llxHeader();
 
-if ($facid > 0)
+$html = new Form($db);
+
+$id = $_GET['facid'];
+$ref= $_GET['ref'];
+if ($id > 0 || ! empty($ref))
 {
 	$facture = new Facture($db);
-	if ($facture->fetch($facid))
+	if ($facture->fetch($id,$ref) > 0)
 	{
 		$upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($facture->ref);
 
@@ -141,9 +146,23 @@ if ($facid > 0)
 		print '<table class="border"width="100%">';
 
 		// Ref
-		print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">'.$facture->ref.'</td></tr>';
+		print '<tr><td width="30%">'.$langs->trans('Ref').'</td>';
+		print '<td colspan="3">';
+		$morehtmlref='';
+		$discount=new DiscountAbsolute($db);
+		$result=$discount->fetch(0,$facture->id);
+		if ($result > 0)
+		{
+			$morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
+		}
+		if ($result < 0)
+		{
+			dol_print_error('',$discount->error);
+		}
+		print $html->showrefnav($facture,'ref','',1,'facnumber','ref',$morehtmlref);
+		print '</td></tr>';
 
-		// Soci�t�
+		// Company
 		print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">'.$societe->getNomUrl(1).'</td></tr>';
 
 		print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.sizeof($filearray).'</td></tr>';
diff --git a/htdocs/compta/facture/info.php b/htdocs/compta/facture/info.php
index f181ea609610622393567c9cd72734af22cba8bb..a685940406f60c96a924bec45357804f458dcc5b 100644
--- a/htdocs/compta/facture/info.php
+++ b/htdocs/compta/facture/info.php
@@ -18,13 +18,15 @@
  */
 
 /**
-        \file       htdocs/compta/facture/info.php
-        \ingroup    facture
-		\brief      Page des informations d'une facture
-		\version    $Id$
+ *      \file       htdocs/compta/facture/info.php
+ *      \ingroup    facture
+ *		\brief      Page des informations d'une facture
+ *		\version    $Id$
 */
 
 require("./pre.inc.php");
+require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
+require_once(DOL_DOCUMENT_ROOT.'/discount.class.php');
 require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
 require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php');
 
diff --git a/htdocs/compta/facture/note.php b/htdocs/compta/facture/note.php
index 6f3a6ca831a1fb448380831fa36d1223f9cbdaec..2217601b2a6850d546028e6b69be8f364dbd29bc 100644
--- a/htdocs/compta/facture/note.php
+++ b/htdocs/compta/facture/note.php
@@ -18,13 +18,15 @@
  */
 
 /**
-        \file       htdocs/compta/facture/note.php
-        \ingroup    facture
-        \brief      Fiche de notes sur une facture
-		\version    $Id$
+ *      \file       htdocs/compta/facture/note.php
+ *      \ingroup    facture
+ *      \brief      Fiche de notes sur une facture
+ *		\version    $Id$
 */
 
 require("./pre.inc.php");
+require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
+require_once(DOL_DOCUMENT_ROOT.'/discount.class.php');
 require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php');
 
 $socid=isset($_GET["socid"])?$_GET["socid"]:isset($_POST["socid"])?$_POST["socid"]:"";
@@ -93,9 +95,14 @@ llxHeader();
 
 $html = new Form($db);
 
-if ($_GET["facid"])
+$id = $_GET['facid'];
+$ref= $_GET['ref'];
+if ($id > 0 || ! empty($ref))
 {
-    $soc = new Societe($db, $fac->socid);
+	$fac = new Facture($db);
+	$fac->fetch($id,$ref);
+
+	$soc = new Societe($db, $fac->socid);
     $soc->fetch($fac->socid);
 
     $head = facture_prepare_head($fac);
@@ -104,10 +111,24 @@ if ($_GET["facid"])
 
     print '<table class="border" width="100%">';
 
-    // Reference
-	print '<tr><td width="20%">'.$langs->trans('Ref').'</td><td colspan="3">'.$fac->ref.'</td></tr>';
+	// Ref
+	print '<tr><td width="20%">'.$langs->trans('Ref').'</td>';
+	print '<td colspan="3">';
+	$morehtmlref='';
+	$discount=new DiscountAbsolute($db);
+	$result=$discount->fetch(0,$fac->id);
+	if ($result > 0)
+	{
+		$morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
+	}
+	if ($result < 0)
+	{
+		dol_print_error('',$discount->error);
+	}
+	print $html->showrefnav($fac,'ref','',1,'facnumber','ref',$morehtmlref);
+	print '</td></tr>';
 
-    // Soci�t�
+    // Company
     print '<tr><td>'.$langs->trans("Company").'</td>';
     print '<td colspan="3">'.$soc->getNomUrl(1,'compta').'</td>';
 
diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php
index f48f53e328679faecff5b24d580e23a75281d688..06d5bdc09b1ea7c0ab542601ad4773344e9e525f 100644
--- a/htdocs/compta/propal.php
+++ b/htdocs/compta/propal.php
@@ -151,15 +151,14 @@ if ($id > 0 || ! empty($ref))
 
 
 	/*
-	 * Fiche propal
-	 *
+	 * Proposal card
 	 */
 	print '<table class="border" width="100%">';
 
-	$linkback="<a href=\"propal.php?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder\">".$langs->trans("BackToList")."</a>";
+	$linkback="<a href=\"".$_SERVER["PHP_SELF"]."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder\">".$langs->trans("BackToList")."</a>";
 
 	// Ref
-	print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="5">';
+	print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="5">';
 	print $html->showrefnav($propal,'ref',$linkback,1,'ref','ref','');
 	print '</td></tr>';
 
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 06789e717058af4f57538872d82f50fe026d1060..8881212ee14d905f6263911c9810bcc7f641521b 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -47,6 +47,7 @@ class Facture extends CommonObject
 	var $table_element='facture';
 	var $table_element_line = 'facturedet';
 	var $fk_element = 'fk_facture';
+	var $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
 	var $table;
 	var $tabledetail;
diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php
index 5ad227ce788a52a5f34c35ce7d884db556ca7587..9762e5ffaac88705a94c61523ac72829eee856f6 100644
--- a/htdocs/fourn/commande/fiche.php
+++ b/htdocs/fourn/commande/fiche.php
@@ -478,7 +478,6 @@ if ($_GET["action"]	== 'create')
 
 llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur");
 
-
 $html =	new	Form($db);
 $formfile = new FormFile($db);
 $formorder = new FormOrder($db);
@@ -501,7 +500,7 @@ if ($id > 0 || ! empty($ref))
 
 	$commande =	new	CommandeFournisseur($db);
 
-	$result=$commande->fetch($_REQUEST['id'],$_REQUEST['ref']);
+	$result=$commande->fetch($id,$ref);
 	if ($result >= 0)
 	{
 		$soc = new Societe($db);
diff --git a/htdocs/fourn/fiche.php b/htdocs/fourn/fiche.php
index 94de948446b461fb59c5476dd7197c0bb9df2b39..c7583b086c78e14b83f97c30dcd8223ea57466cc 100644
--- a/htdocs/fourn/fiche.php
+++ b/htdocs/fourn/fiche.php
@@ -94,10 +94,10 @@ if ( $societe->fetch($socid) )
 
 	// Phone
 	print '<tr><td>'.$langs->trans("Phone").'</td><td>'.dol_print_phone($societe->tel,$societe->pays_code,0,$societe->id,'AC_TEL').'</td>';
-	
+
 	// Fax
 	print '<td>'.$langs->trans("Fax").'</td><td>'.dol_print_phone($societe->fax,$societe->pays_code,0,$societe->id,'AC_FAX').'</td></tr>';
-	
+
     // EMail
 	print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($societe->email,0,$societe->id,'AC_EMAIL').'</td></tr>';
 
@@ -140,115 +140,108 @@ if ( $societe->fetch($socid) )
 		print '</a></td></tr></table>';
 	}
 
-	
+
 	print '<br>';
 
 	/*
-	 * Liste des commandes associees
+	 * Last orders
 	 */
 	$orderstatic = new CommandeFournisseur($db);
 
-	$sql  = "SELECT p.rowid,p.ref,".$db->pdate("p.date_commande")." as dc, p.fk_statut";
-	$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p ";
-	$sql.= " WHERE p.fk_soc =".$societe->id;
-	$sql.= " ORDER BY p.date_commande DESC";
-	$sql.= " ".$db->plimit($MAXLIST);
-	$resql=$db->query($sql);
-	if ($resql)
+	if ($user->rights->fournisseur->commande->lire)
 	{
-		$i = 0 ;
-		$num = $db->num_rows($resql);
-		if ($num > 0)
+		$sql  = "SELECT p.rowid,p.ref,".$db->pdate("p.date_commande")." as dc, p.fk_statut";
+		$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p ";
+		$sql.= " WHERE p.fk_soc =".$societe->id;
+		$sql.= " ORDER BY p.date_commande DESC";
+		$sql.= " ".$db->plimit($MAXLIST);
+		$resql=$db->query($sql);
+		if ($resql)
 		{
+			$i = 0 ;
+			$num = $db->num_rows($resql);
 			print '<table class="noborder" width="100%">';
 			print '<tr class="liste_titre">';
 			print '<td colspan="3">';
 			print '<table class="noborder" width="100%"><tr><td>'.$langs->trans("LastOrders",($num<$MAXLIST?$num:$MAXLIST)).'</td>';
 			print '<td align="right"><a href="commande/liste.php?socid='.$societe->id.'">'.$langs->trans("AllOrders").' ('.$num.')</td></tr></table>';
 			print '</td></tr>';
-		}
-		while ($i < $num && $i <= $MAXLIST)
-		{
-			$obj = $db->fetch_object($resql);
-			$var=!$var;
-
-			print "<tr $bc[$var]>";
-			print '<td><a href="commande/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref.'</a></td>';
-			print '<td align="center" width="80">';
-			if ($obj->dc)
+			while ($i < $num && $i <= $MAXLIST)
 			{
-				print dol_print_date($obj->dc,'day');
+				$obj = $db->fetch_object($resql);
+				$var=!$var;
+
+				print "<tr $bc[$var]>";
+				print '<td><a href="commande/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref.'</a></td>';
+				print '<td align="center" width="80">';
+				if ($obj->dc)
+				{
+					print dol_print_date($obj->dc,'day');
+				}
+				else
+				{
+					print "-";
+				}
+				print '</td>';
+				print '<td align="right" nowrap="nowrap">'.$orderstatic->LibStatut($obj->fk_statut,5).'</td>';
+				print '</tr>';
+				$i++;
 			}
-			else
-			{
-				print "-";
-			}
-			print '</td>';
-			print '<td align="right" nowrap="nowrap">'.$orderstatic->LibStatut($obj->fk_statut,5).'</td>';
-			print '</tr>';
-			$i++;
+			$db->free($resql);
+			print "</table>";
 		}
-		$db->free($resql);
-		if ($num > 0)
+		else
 		{
-			print "</table>";
+			dol_print_error($db);
 		}
 	}
-	else
-	{
-		dol_print_error($db);
-	}
-
 
 	/*
-	 * Liste des factures associees
+	 * Last invoices
 	 */
 	$MAXLIST=5;
 
 	$langs->load('bills');
 	$facturestatic = new FactureFournisseur($db);
 
-	$sql = 'SELECT p.rowid,p.libelle,p.facnumber,p.fk_statut,'.$db->pdate('p.datef').' as df, total_ttc as amount, paye';
-	$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as p';
-	$sql.= ' WHERE p.fk_soc = '.$societe->id;
-	$sql.= ' ORDER BY p.datef DESC';
-	$resql=$db->query($sql);
-	if ($resql)
+	if ($user->rights->fournisseur->facture->lire)
 	{
-		$i = 0 ;
-		$num = $db->num_rows($resql);
-		if ($num > 0)
+		$sql = 'SELECT p.rowid,p.libelle,p.facnumber,p.fk_statut,'.$db->pdate('p.datef').' as df, total_ttc as amount, paye';
+		$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as p';
+		$sql.= ' WHERE p.fk_soc = '.$societe->id;
+		$sql.= ' ORDER BY p.datef DESC';
+		$resql=$db->query($sql);
+		if ($resql)
 		{
+			$i = 0 ;
+			$num = $db->num_rows($resql);
 			print '<table class="noborder" width="100%">';
 			print '<tr class="liste_titre">';
 			print '<td colspan="4">';
 			print '<table class="noborder" width="100%"><tr><td>'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="facture/index.php?socid='.$societe->id.'">'.$langs->trans('AllBills').' ('.$num.')</td></tr></table>';
 			print '</td></tr>';
+			while ($i < min($num,$MAXLIST))
+			{
+				$obj = $db->fetch_object($resql);
+				$var=!$var;
+				print '<tr '.$bc[$var].'>';
+				print '<td>';
+				print '<a href="facture/fiche.php?facid='.$obj->rowid.'">';
+				print img_object($langs->trans('ShowBill'),'bill').' '.$obj->facnumber.'</a> '.dol_trunc($obj->libelle,14).'</td>';
+				print '<td align="center" nowrap="nowrap">'.dol_print_date($obj->df,'day').'</td>';
+				print '<td align="right" nowrap="nowrap">'.price($obj->amount).'</td>';
+				print '<td align="right" nowrap="nowrap">'.$facturestatic->LibStatut($obj->paye,$obj->fk_statut,5).'</td>';
+				print '</tr>';
+				$i++;
+			}
+			$db->free($resql);
+			print '</table>';
 		}
-		while ($i < min($num,$MAXLIST))
-		{
-			$obj = $db->fetch_object($resql);
-			$var=!$var;
-			print '<tr '.$bc[$var].'>';
-			print '<td>';
-			print '<a href="facture/fiche.php?facid='.$obj->rowid.'">';
-			print img_object($langs->trans('ShowBill'),'bill').' '.$obj->facnumber.'</a> '.dol_trunc($obj->libelle,14).'</td>';
-			print '<td align="center" nowrap="nowrap">'.dol_print_date($obj->df,'day').'</td>';
-			print '<td align="right" nowrap="nowrap">'.price($obj->amount).'</td>';
-			print '<td align="right" nowrap="nowrap">'.$facturestatic->LibStatut($obj->paye,$obj->fk_statut,5).'</td>';
-			print '</tr>';
-			$i++;
-		}
-		$db->free($resql);
-		if ($num > 0)
+		else
 		{
-			print '</table>';
+			dol_print_error($db);
 		}
 	}
-	else
-	{
-		dol_print_error($db);
-	}
 
 	print '</td></tr>';
 	print '</table>' . "\n";
diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php
index 9b32984f4dc132ab76acdcbc1fa9fe56984c3676..6a13a9f1f450a76c111f30f73c705de4bb745f8a 100644
--- a/htdocs/fourn/fournisseur.commande.class.php
+++ b/htdocs/fourn/fournisseur.commande.class.php
@@ -36,15 +36,17 @@ require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
  */
 class CommandeFournisseur extends Commande
 {
+	var $id ;
 	var $db ;
 	var $error;
+
 	var $element='order_supplier';
 	var $table_element='commande_fournisseur';
 	var $table_element_line = 'commande_fournisseurdet';
 	var $fk_element = 'fk_commande';
-	var $table_optional = 'societe as s';
+	var $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
-	var $id ;
+	var $ref;
 	var $brouillon;
 
 
@@ -120,8 +122,6 @@ class CommandeFournisseur extends Commande
 			$this->note_public         = $obj->note_public;
 			$this->modelpdf            = $obj->model_pdf;
 
-			$this->next_prev_filter = 'fk_soc = s.rowid AND s.entity = '.$conf->entity;
-
 			$this->db->free();
 
 			if ($this->statut == 0) $this->brouillon = 1;
diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php
index dbf3c7dd01bdb5144744e935a3ac93e3302e7b53..88a2cd0b4685408f401012d02e0ed8a414bb2de2 100644
--- a/htdocs/fourn/fournisseur.facture.class.php
+++ b/htdocs/fourn/fournisseur.facture.class.php
@@ -38,11 +38,13 @@ class FactureFournisseur extends Facture
 {
 	var $id;
 	var $db;
+	var $error;
 
 	var $element='facture_fourn';
 	var $table_element='facture_fourn';
 	var $table_element_line='facture_fourn_det';
 	var $fk_element='fk_facture_fourn';
+	var $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
 	var $ref;
 	var $ref_supplier;
@@ -212,6 +214,8 @@ class FactureFournisseur extends Facture
 	 */
 	function fetch($rowid)
 	{
+		global $conf;
+
 		$sql = 'SELECT libelle, facnumber, amount, remise, '.$this->db->pdate(datef).'as df,';
 		$sql.= ' total_ht, total_tva, total_ttc, fk_user_author,';
 		$sql.= ' fk_statut, fk_projet as fk_project, paye, f.note, f.note_public,';
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index a2048703a62c048aa11ec2e046e203f995fde084..2ad74cb1b6169d829f062a7657798c1d4e41c75e 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -2720,7 +2720,7 @@ class Form
 						4=>$langs->trans("Day4"),
 						5=>$langs->trans("Day5"),
 						6=>$langs->trans("Day6"));
-						
+
 		$select_week = '<select class="flat" name="'.$htmlname.'">';
 		if ($useempty)
 		{
@@ -2741,7 +2741,7 @@ class Form
 		$select_week .= '</select>';
 		return $select_week;
 	}
-	
+
 	/**
 	 *    	\brief      Return HTML combo list of month
 	 *    	\param      selected          Preselected value
@@ -2773,7 +2773,7 @@ class Form
 		$select_month .= '</select>';
 		return $select_month;
 	}
-	
+
 	/**
 	 *    	\brief      Return HTML combo list of years
 	 *    	\param      selected          Preselected value
@@ -2826,6 +2826,7 @@ class Form
 	{
 		$ret='';
 
+		//print "$paramid,$morehtml,$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
 		$object->load_previous_next_ref($object->next_prev_filter,$fieldid);
 		$previous_ref = $object->ref_previous?'<a href="'.$_SERVER["PHP_SELF"].'?'.$paramid.'='.urlencode($object->ref_previous).$moreparam.'">'.img_previous().'</a>':'';
 		$next_ref     = $object->ref_next?'<a href="'.$_SERVER["PHP_SELF"].'?'.$paramid.'='.urlencode($object->ref_next).$moreparam.'">'.img_next().'</a>':'';
diff --git a/htdocs/html.formfile.class.php b/htdocs/html.formfile.class.php
index 61cd3154f95ee5ff2064a88a9a074e432ff9b9a1..44bfb2c308a5157344f3042e2bdca9dc7641c56f 100644
--- a/htdocs/html.formfile.class.php
+++ b/htdocs/html.formfile.class.php
@@ -121,7 +121,7 @@ class FormFile
 
 
 	/**
-	 *      \brief      Affiche la cartouche de la liste des documents d'une propale, facture...
+	 *      \brief      Show the box with list of available documents for object
 	 *      \param      modulepart          propal=propal, facture=facture, ...
 	 *      \param      filename            Sub dir to scan (use '' if filedir already complete)
 	 *      \param      filedir             Dir to scan
@@ -130,8 +130,8 @@ class FormFile
 	 *      \param      delallowed          Remove is allowed (1/0)
 	 *      \param      modelselected       Model to preselect by default
 	 *      \param      modelliste			Tableau des modeles possibles. Use '' to hide combo select list.
-	 *      \param      forcenomultilang	N'affiche pas option langue meme si MAIN_MULTILANGS defini
-	 *      \param      iconPDF             N'affiche que l'icone PDF avec le lien (1/0)
+	 *      \param      forcenomultilang	Do not show language option (even if MAIN_MULTILANGS defined)
+	 *      \param      iconPDF             Show only PDF icon with link (1/0)
 	 * 		\param		maxfilenamelength	Max length for filename shown
 	 * 		\param		noform				Do not output html form start and end
 	 * 		\param		param				More param on http links
@@ -295,7 +295,7 @@ class FormFile
 			print '<input type="hidden" name="action" value="builddoc">';
 			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 
-			print_titre($langs->trans("BuildDocuments"));
+			print_titre($langs->trans("Documents"));
 			print '<table class="border" summary="listofdocumentstable" width="100%">';
 
 			print '<tr '.$bc[$var].'>';
diff --git a/htdocs/includes/menus/init_menu_auguria.sql b/htdocs/includes/menus/init_menu_auguria.sql
index 09bc82b7d5896c03164fce4aa1b90606a108b119..d7b4eee6c6bb68440b80d824f4d00d6856356f96 100644
--- a/htdocs/includes/menus/init_menu_auguria.sql
+++ b/htdocs/includes/menus/init_menu_auguria.sql
@@ -112,10 +112,10 @@ insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`,
 insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3302__+MAX_llx_menu__, 'suppliers', '', 3300__+MAX_llx_menu__, '/fourn/liste.php', 'List', 1, 'suppliers', '$user->rights->societe->lire && $user->rights->fournisseur->lire', '', 2, 1, __ENTITY__);
 insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3303__+MAX_llx_menu__, 'suppliers', '', 3300__+MAX_llx_menu__, '/contact/index.php?leftmenu=supplier&type=f', 'Contacts', 1, 'suppliers', '$user->rights->societe->lire && $user->rights->fournisseur->lire', '', 2, 2, __ENTITY__);
 insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3304__+MAX_llx_menu__, 'suppliers', '', 3300__+MAX_llx_menu__, '/fourn/stats.php', 'Statistics', 1, 'suppliers', '$user->rights->societe->lire && $user->rights->fournisseur->lire', '', 2, 3, __ENTITY__);
-insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3400__+MAX_llx_menu__, 'suppliers', '', 4__+MAX_llx_menu__, '/fourn/facture/index.php', 'Bills', 0, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 1, __ENTITY__);
+insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3400__+MAX_llx_menu__, 'suppliers', '', 3300__+MAX_llx_menu__, '/fourn/facture/index.php', 'Bills', 0, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 4, __ENTITY__);
 insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3401__+MAX_llx_menu__, 'suppliers', '', 3400__+MAX_llx_menu__, '/fourn/facture/fiche.php?action=create', 'NewBill', 1, 'bills', '$user->rights->fournisseur->facture->creer', '', 2, 0, __ENTITY__);
 insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3402__+MAX_llx_menu__, 'suppliers', '', 3400__+MAX_llx_menu__, '/fourn/facture/paiement.php', 'Payments', 1, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 1, __ENTITY__);
-insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3500__+MAX_llx_menu__, 'suppliers', '', 4__+MAX_llx_menu__, '/fourn/commande/index.php?leftmenu=suppliers', 'Orders', 0, 'orders', '$user->rights->fournisseur->commande->lire', '', 2, 2, __ENTITY__);
+insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3500__+MAX_llx_menu__, 'suppliers', '', 3300__+MAX_llx_menu__, '/fourn/commande/index.php?leftmenu=suppliers', 'Orders', 0, 'orders', '$user->rights->fournisseur->commande->lire', '', 2, 5, __ENTITY__);
 insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3501__+MAX_llx_menu__, 'suppliers', '', 3500__+MAX_llx_menu__, '/societe.php?leftmenu=supplier', 'NewOrder', 1, 'orders', '$user->rights->fournisseur->commande->creer', '', 2, 0, __ENTITY__);
 insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled', 'auguria', 'left', 3502__+MAX_llx_menu__, 'suppliers', '', 3500__+MAX_llx_menu__, '/fourn/commande/liste.php?leftmenu=suppliers', 'List', 1, 'orders', '$user->rights->fournisseur->commande->lire', '', 2, 1, __ENTITY__);
 insert into `llx_menu` (`enabled`, `menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position, entity) values ('$conf->fournisseur->enabled && $conf->categorie->enabled', 'auguria', 'left', 4900__+MAX_llx_menu__, 'suppliers', '', 4__+MAX_llx_menu__, '/categories/index.php?leftmenu=cat&type=1', 'Categories', 0, 'categories', '$user->rights->categorie>lire', '', 2, 3, __ENTITY__);
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index ea663d2fb15da146f92194d1a0b67048103cb727..aefd418c652385fb96faab4bd398ef9175ec50ad 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -497,6 +497,7 @@ Canceled=Canceled
 YouCanChangeValuesForThisListFromDictionnarySetup=You can change values for this list from menu setup - dictionnary
 Color=Color
 Documents=Linked files
+DocumentsNb=Linked files (%s)
 Documents2=Documents
 BuildDocuments=Generated documents
 UploadDisabled=Upload disabled
diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang
index b1725235634d272be56e55b3dd356ba4c1277c49..cbcd05638b5a6fa10d1bcff530bfbbd1ac6b1785 100644
--- a/htdocs/langs/fr_FR/main.lang
+++ b/htdocs/langs/fr_FR/main.lang
@@ -496,6 +496,7 @@ Canceled=Annulé
 YouCanChangeValuesForThisListFromDictionnarySetup=Vous pouvez changer ces valeurs depuis le menu configuration - dictionnaires
 Color=Couleur
 Documents=Fichiers joints
+DocumentsNb=Fichiers joints (%s)
 Documents2=Documents
 BuildDocuments=Documents générés
 UploadDisabled=Transfert désactivé
diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php
index 9329b17e31110f5b24cf0a3ac40d003ac6400472..a2baf32a1b6d5952a470a51ad2ff6caf45bac062 100644
--- a/htdocs/lib/files.lib.php
+++ b/htdocs/lib/files.lib.php
@@ -32,7 +32,7 @@
  *  \param		$exludefilter  	Regex for exclude filter (example: '\.meta$')
  *  \param		$sortcriteria	Sort criteria ("name","date","size")
  *  \param		$sortorder		Sort order (SORT_ASC, SORT_DESC)
- *	\param		$mode			0=Return array with only keys needed, 1=Force all keys to be loaded
+ *	\param		$mode			0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower)
  *  \return		array			Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file')
  */
 function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC, $mode=0)
@@ -189,7 +189,7 @@ function dol_mimetype($file)
 /**
  * 	\brief		Test if a folder is empty
  * 	\param		folder		Name of folder
- * 	\return 	boolean		True if dir is empty or non-existing, false if it contains files
+ * 	\return 	boolean		True if dir is empty or non-existing, False if it contains files
  */
 function dol_dir_is_emtpy($folder)
 {
@@ -210,7 +210,7 @@ function dol_dir_is_emtpy($folder)
 		closedir($handle);
 	}
 	else
-	return true; // Le repertoire n'existe pas
+	return true; // Dir does not exists
 }
 
 /**
diff --git a/htdocs/lib/fourn.lib.php b/htdocs/lib/fourn.lib.php
index eeb28facd231b2bdad266ad63ba9ad7a1bd97e23..2043ae7f36bcbd819883903d2922b38bf9978e9c 100644
--- a/htdocs/lib/fourn.lib.php
+++ b/htdocs/lib/fourn.lib.php
@@ -1,6 +1,6 @@
 <?php
-/* Copyright (C) 2005 Laurent Destailleur   <eldy@users.sourceforge.net>
- * Copyright (C) 2006 Marc Barilley / Ocebo <marc@ocebo.com>
+/* Copyright (C) 2005-2009 Laurent Destailleur   <eldy@users.sourceforge.net>
+ * Copyright (C) 2006      Marc Barilley / Ocebo <marc@ocebo.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
@@ -19,10 +19,10 @@
  */
 
 /**
-	    \file       htdocs/lib/fourn.lib.php
-		\brief      Ensemble de fonctions de base pour le module fournisseur
-		\version    $Id$
-*/
+ *	    \file       htdocs/lib/fourn.lib.php
+ *		\brief      Ensemble de fonctions de base pour le module fournisseur
+ *		\version    $Id$
+ */
 
 function facturefourn_prepare_head($fac)
 {
@@ -46,6 +46,10 @@ function facturefourn_prepare_head($fac)
 	$h++;
 
 	$head[$h][0] = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$fac->id;
+	/*$filesdir = $conf->fournisseur->dir_output.'/facture/'.get_exdir($fac->id,2).$fac->id;
+	include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
+	$listoffiles=dol_dir_list($filesdir,'files',1);
+	$head[$h][1] = (sizeof($listoffiles)?$langs->trans('DocumentsNb',sizeof($listoffiles)):$langs->trans('Documents'));*/
 	$head[$h][1] = $langs->trans('Documents');
 	$head[$h][2] = 'documents';
 	$h++;
@@ -107,7 +111,11 @@ function ordersupplier_prepare_head($commande)
 	$h++;
 
 	$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/document.php?id='.$commande->id;
-	$head[$h][1] = $langs->trans("Documents");
+	/*$filesdir = $conf->fournisseur->dir_output . "/commande/" . dol_sanitizeFileName($commande->ref);
+	include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
+	$listoffiles=dol_dir_list($filesdir,'files',1);
+	$head[$h][1] = (sizeof($listoffiles)?$langs->trans('DocumentsNb',sizeof($listoffiles)):$langs->trans('Documents'));*/
+	$head[$h][1] = $langs->trans('Documents');
 	$head[$h][2] = 'documents';
 	$h++;
 
diff --git a/htdocs/lib/invoice.lib.php b/htdocs/lib/invoice.lib.php
index 8deb714aa40fd074549070dd97aed70dd25ac54f..80bb2d58d1aab5da28dde90ea35aa0b63ec201db 100644
--- a/htdocs/lib/invoice.lib.php
+++ b/htdocs/lib/invoice.lib.php
@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2005-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2005-2009 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
@@ -64,6 +64,10 @@ function facture_prepare_head($fac)
 	$h++;
 
 	$head[$h][0] = DOL_URL_ROOT.'/compta/facture/document.php?facid='.$fac->id;
+	/*$filesdir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($fac->ref);
+	include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
+	$listoffiles=dol_dir_list($filesdir,'files',1);
+	$head[$h][1] = (sizeof($listoffiles)?$langs->trans('DocumentsNb',sizeof($listoffiles)):$langs->trans('Documents'));*/
 	$head[$h][1] = $langs->trans('Documents');
 	$head[$h][2] = 'documents';
 	$h++;
diff --git a/htdocs/lib/order.lib.php b/htdocs/lib/order.lib.php
index 3f9e55290056a12c3061f51f5c8e07eb7939d360..5e0a8baa6aeaf2e13c3277048d47015de5276995 100644
--- a/htdocs/lib/order.lib.php
+++ b/htdocs/lib/order.lib.php
@@ -1,6 +1,6 @@
 <?php
-/* Copyright (C) 2006 Laurent Destailleur  <eldy@users.sourceforge.net>
- * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
+/* Copyright (C) 2006-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2007      Rodolphe Quiedeville <rodolphe@quiedeville.org>
  *
  * 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
@@ -53,7 +53,7 @@ function commande_prepare_head($commande)
 		$h++;
 	}
 
-	// Commande � facturer
+	// Commande a facturer
 	if ($conf->facture->enabled)
 	{
 		$head[$h][0] = DOL_URL_ROOT.'/compta/commande/fiche.php?id='.$commande->id;
@@ -76,6 +76,10 @@ function commande_prepare_head($commande)
 	$h++;
 
 	$head[$h][0] = DOL_URL_ROOT.'/commande/document.php?id='.$commande->id;
+	/*$filesdir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($commande->ref);
+	include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
+	$listoffiles=dol_dir_list($filesdir,'files',1);
+	$head[$h][1] = (sizeof($listoffiles)?$langs->trans('DocumentsNb',sizeof($listoffiles)):$langs->trans('Documents'));*/
 	$head[$h][1] = $langs->trans('Documents');
 	$head[$h][2] = 'documents';
 	$h++;
diff --git a/htdocs/lib/propal.lib.php b/htdocs/lib/propal.lib.php
index 925b276250f9f934bd8fa7bedb0c175d269ab905..33e16d010ac4404a0d1439d4ddc6a86460c053ab 100644
--- a/htdocs/lib/propal.lib.php
+++ b/htdocs/lib/propal.lib.php
@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2006-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2006-2009 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
@@ -77,6 +77,10 @@ function propal_prepare_head($propal)
 	$h++;
 
 	$head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?propalid='.$propal->id;
+	/*$filesdir = $conf->propale->dir_output . "/" . dol_sanitizeFileName($propal->ref);
+	include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
+	$listoffiles=dol_dir_list($filesdir,'files',1);
+	$head[$h][1] = (sizeof($listoffiles)?$langs->trans('DocumentsNb',sizeof($listoffiles)):$langs->trans('Documents'));*/
 	$head[$h][1] = $langs->trans('Documents');
 	$head[$h][2] = 'document';
 	$h++;
diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index f55bcb2d593b767349317dfa7e0c33b8ff4f5f3d..3155600d843bdd799042bed9cbbca8b9a997edb4 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -42,6 +42,7 @@ class Product extends CommonObject
 	var $errno = 0;
 	var $element='product';
 	var $table_element='product';
+	var $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
 	//! Identifiant unique
 	var $id ;
@@ -971,8 +972,6 @@ class Product extends CommonObject
 
 			$this->import_key         = $result["import_key"];
 
-			$this->next_prev_filter = 'entity = '.$conf->entity;
-
 			$this->db->free();
 
 			// multilangs
diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php
index ea6b53a5441382f34e185ba179c898d4e400b024..764a9a5cc88d22dfdf64a24bf905d686055c4295 100644
--- a/htdocs/propal.class.php
+++ b/htdocs/propal.class.php
@@ -48,6 +48,7 @@ class Propal extends CommonObject
 	var $table_element='propal';
 	var $table_element_line='propaldet';
 	var $fk_element='fk_propal';
+	var $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
 	var $id;
 
diff --git a/htdocs/user.class.php b/htdocs/user.class.php
index eb55390c94211c469bc1b097abf93f1f6b234f1a..45d3663f74935fcfaa803effb215c9439289a45c 100644
--- a/htdocs/user.class.php
+++ b/htdocs/user.class.php
@@ -49,6 +49,7 @@ class User extends CommonObject
 	var $errors=array();
 	var $element='user';
 	var $table_element='user';
+	var $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
 	var $id=0;
 	var $ldap_sid;
@@ -211,8 +212,6 @@ class User extends CommonObject
 				$this->contact_id           = $obj->fk_socpeople;
 				$this->fk_member            = $obj->fk_member;
 
-				$this->next_prev_filter     = 'entity IN (0,'.$conf->entity.')';
-
 				if (! $this->lang) $this->lang='fr_FR';
 
 				$this->db->free($result);
diff --git a/htdocs/usergroup.class.php b/htdocs/usergroup.class.php
index 75c3ec949d88fb1d3ac951c4fb4f804dbc3b9eb3..ca9ce0b3bb462804862c1d1329aa6fe8c173c28c 100644
--- a/htdocs/usergroup.class.php
+++ b/htdocs/usergroup.class.php
@@ -28,16 +28,16 @@ if ($conf->ldap->enabled) require_once (DOL_DOCUMENT_ROOT."/lib/ldap.class.php")
 
 
 /**
- \class      UserGroup
- \brief      Classe permettant la gestion des groupes d'utilisateur
+ *	\class      UserGroup
+ *	\brief      Classe permettant la gestion des groupes d'utilisateur
  */
-
 class UserGroup extends CommonObject
 {
 	var $db;			// Database handler
 	var $error;
 	var $errors=array();
 	var $table_element='usergroup';
+	var $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
 	var $id;			// Group id
 	var $entity;  // Entity of group
@@ -94,8 +94,6 @@ class UserGroup extends CommonObject
 				$this->datec = $obj->datec;
 				$this->datem = $obj->datem;
 
-				$this->next_prev_filter = 'entity IN (0,'.$conf->entity.')';
-
 				// Sav current LDAP Current DN
 				//$this->ldap_dn = $this->_load_ldap_dn($this->_load_ldap_info(),0);
 			}