diff --git a/htdocs/adherents/liste.php b/htdocs/adherents/liste.php
index ad7d6597146ecca7a549a40335cd8c694c5f58a3..ad6fc2284eda2ccd60563c24e05b106371c8f39a 100644
--- a/htdocs/adherents/liste.php
+++ b/htdocs/adherents/liste.php
@@ -41,7 +41,8 @@ $search_prenom=GETPOST("search_prenom");
 $search_login=GETPOST("search_login");
 $type=GETPOST("type");
 $search_email=GETPOST("search_email");
-$search_categ=GETPOST("search_categ");
+$search_categ = GETPOST("search_categ",'int');
+$catid        = GETPOST("catid",'int');
 $sall=GETPOST("sall");
 
 $sortfield = GETPOST("sortfield",'alpha');
@@ -64,6 +65,7 @@ if (GETPOST("button_removefilter"))
 	$type="";
 	$search_email="";
 	$search_categ="";
+	$catid="";
 	$sall="";
 }
 
@@ -86,10 +88,14 @@ $sql = "SELECT d.rowid, d.login, d.nom as lastname, d.prenom as firstname, d.soc
 $sql.= " d.datefin,";
 $sql.= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
 $sql.= " t.libelle as type, t.cotisation";
-$sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
-if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_member as cf";
+$sql.= " FROM ".MAIN_DB_PREFIX."adherent as d";
+if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_member as cm ON d.rowid = cm.fk_member"; // We need this table joined to the select in order to filter by categ
+$sql.= ", ".MAIN_DB_PREFIX."adherent_type as t";
 $sql.= " WHERE d.fk_adherent_type = t.rowid ";
-if ($search_categ) $sql.= " AND d.rowid = cf.fk_member";	// Join for the needed table to filter by categ
+if ($catid > 0)    $sql.= " AND cm.fk_categorie = ".$catid;
+if ($catid == -2)  $sql.= " AND cm.fk_categorie IS NULL";
+if ($search_categ > 0)   $sql.= " AND cm.fk_categorie = ".$search_categ;
+if ($search_categ == -2) $sql.= " AND cm.fk_categorie IS NULL";
 $sql.= " AND d.entity = ".$conf->entity;
 if ($sall)
 {
@@ -132,11 +138,6 @@ if ($filter == 'outofdate')
 {
 	$sql.=" AND datefin < '".$db->idate($now)."'";
 }
-// Insert categ filter
-if ($search_categ)
-{
-	$sql.= " AND cf.fk_categorie = ".$db->escape($search_categ);
-}
 
 // Count total nb of records with no order and no limits
 $nbtotalofrecords = 0;
@@ -200,7 +201,7 @@ if ($resql)
 	if ($conf->categorie->enabled)
 	{
 		$moreforfilter.=$langs->trans('Categories'). ': ';
-		$moreforfilter.=$formother->select_categories(3,$search_categ,'search_categ');
+		$moreforfilter.=$formother->select_categories(3,$search_categ,'search_categ',1);
 		$moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
 	}
 	if ($moreforfilter)
diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php
index 75082eaf1404fc04b6c58f72098fde9d78a85300..ba99f60eaf99b2652e3b7178bbb18b1c55b5eae0 100644
--- a/htdocs/categories/categorie.php
+++ b/htdocs/categories/categorie.php
@@ -268,7 +268,7 @@ if ($socid)
 
 	print '</table>';
 
-	print '</div>';
+	dol_fiche_end();
 
 	dol_htmloutput_mesg($mesg);
 
@@ -328,7 +328,7 @@ else if ($id || $ref)
 
 		print '</table>';
 
-		print '</div>';
+		dol_fiche_end();
 
 		dol_htmloutput_mesg($mesg);
 
@@ -409,7 +409,7 @@ else if ($id || $ref)
 
 		print '</table>';
 
-		print '</div>';
+		dol_fiche_end();
 
 		dol_htmloutput_mesg($mesg);
 
@@ -482,6 +482,7 @@ function formCategory($db,$object,$typeid,$socid=0)
 		foreach ($cats as $cat)
 		{
 			$ways = $cat->print_all_ways();
+
 			foreach ($ways as $way)
 			{
 				$var = ! $var;
diff --git a/htdocs/comm/list.php b/htdocs/comm/list.php
index f95173df5d3ef13af5febdfc41bb70ff166295a5..18c95d655f5e3f25acd796b7cc1826f23e66ea45 100755
--- a/htdocs/comm/list.php
+++ b/htdocs/comm/list.php
@@ -52,8 +52,9 @@ $search_code=GETPOST("search_code");
 $search_compta=GETPOST("search_compta");
 
 // Load sale and categ filters
-$search_sale = GETPOST("search_sale");
-$search_categ = GETPOST("search_categ");
+$search_sale  = GETPOST("search_sale");
+$search_categ = GETPOST("search_categ",'int');
+$catid        = GETPOST("catid",'int');
 
 /*
  * Actions
@@ -63,6 +64,7 @@ $search_categ = GETPOST("search_categ");
 if (GETPOST("button_removefilter_x"))
 {
     $search_categ='';
+    $catid='';
     $search_sale='';
     $socname="";
     $search_nom="";
@@ -89,35 +91,30 @@ $sql = "SELECT s.rowid, s.nom as name, s.client, s.ville, st.libelle as stcomm,
 $sql.= " s.datec, s.datea, s.canvas";
 // We'll need these fields in order to filter by sale (including the case where the user can only see his prospects)
 if ($search_sale) $sql .= ", sc.fk_soc, sc.fk_user";
-// We'll need these fields in order to filter by categ
-if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_societe";
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
-$sql.= " ".MAIN_DB_PREFIX."c_stcomm as st";
+$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
+if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_societe"; // We need this table joined to the select in order to filter by categ
+$sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
 // We'll need this table joined to the select in order to filter by sale
 if ($search_sale || !$user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-// We'll need this table joined to the select in order to filter by categ
-if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
 $sql.= " WHERE s.fk_stcomm = st.id";
 $sql.= " AND s.client IN (1, 3)";
 $sql.= ' AND s.entity IN ('.getEntity('societe', 1).')';
 if (!$user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($socid) $sql.= " AND s.rowid = ".$socid;
 if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
-if ($search_categ) $sql.= " AND s.rowid = cs.fk_societe";	// Join for the needed table to filter by categ
+if ($catid > 0)          $sql.= " AND cs.fk_categorie = ".$catid;
+if ($catid == -2)        $sql.= " AND cs.fk_categorie IS NULL";
+if ($search_categ > 0)   $sql.= " AND cs.fk_categorie = ".$search_categ;
+if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL";
 if ($search_nom)   $sql.= " AND s.nom LIKE '%".$db->escape(strtolower($search_nom))."%'";
 if ($search_ville) $sql.= " AND s.ville LIKE '%".$db->escape(strtolower($search_ville))."%'";
 if ($search_code)  $sql.= " AND s.code_client LIKE '%".$db->escape(strtolower($search_code))."%'";
-if ($search_compta) $sql .= " AND s.code_compta LIKE '%".$db->escape($search_compta)."%'";
+if ($search_compta) $sql.= " AND s.code_compta LIKE '%".$db->escape($search_compta)."%'";
 // Insert sale filter
 if ($search_sale)
 {
 	$sql .= " AND sc.fk_user = ".$search_sale;
 }
-// Insert categ filter
-if ($search_categ)
-{
-	$sql .= " AND cs.fk_categorie = ".$search_categ;
-}
 if ($socname)
 {
 	$sql.= " AND s.nom LIKE '%".$db->escape(strtolower($socname))."%'";
@@ -157,7 +154,7 @@ if ($result)
 	if ($conf->categorie->enabled)
 	{
 	 	$moreforfilter.=$langs->trans('Categories'). ': ';
-		$moreforfilter.=$formother->select_categories(2,$search_categ,'search_categ');
+		$moreforfilter.=$formother->select_categories(2,$search_categ,'search_categ',1);
 	 	$moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
 	}
  	// If the user can view prospects other than his'
diff --git a/htdocs/comm/prospect/list.php b/htdocs/comm/prospect/list.php
index 5d93a069b0adc3bdbf3b38669f00bfec16621315..ca9ee950b13e2585992233dc85d926e8d8bb750d 100755
--- a/htdocs/comm/prospect/list.php
+++ b/htdocs/comm/prospect/list.php
@@ -42,6 +42,8 @@ $search_nom         = GETPOST("search_nom");
 $search_ville       = GETPOST("search_ville");
 $search_departement = GETPOST("search_departement");
 $search_datec       = GETPOST("search_datec");
+$search_categ       = GETPOST("search_categ",'int');
+$catid              = GETPOST("catid",'int');
 
 $sortfield = GETPOST("sortfield",'alpha');
 $sortorder = GETPOST("sortorder",'alpha');
@@ -165,25 +167,22 @@ $sql = "SELECT s.rowid, s.nom, s.ville, s.datec, s.datea, s.status as status,";
 $sql.= " st.libelle as stcomm, s.prefix_comm, s.fk_stcomm, s.fk_prospectlevel,";
 $sql.= " d.nom as departement";
 // Updated by Matelli
-// We'll need these fields in order to filter by sale (including the case where the user can only see his prospects)
-if ($search_sale) $sql .= ", sc.fk_soc, sc.fk_user";
-// We'll need these fields in order to filter by categ
-if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_societe";
+if ($search_sale) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
 $sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm as st";
-// We'll need this table joined to the select in order to filter by sale
-if ($search_sale || !$user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-// We'll need this table joined to the select in order to filter by categ
-if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
+if ($search_sale || !$user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d on (d.rowid = s.fk_departement)";
+if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_societe"; // We need this table joined to the select in order to filter by categ
 $sql.= " WHERE s.fk_stcomm = st.id";
 $sql.= " AND s.client IN (2, 3)";
 $sql.= ' AND s.entity IN ('.getEntity('societe', 1).')';
 if ($user->societe_id) $sql.= " AND s.rowid = " .$user->societe_id;
 if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
-if ($search_categ) $sql.= " AND s.rowid = cs.fk_societe";	// Join for the needed table to filter by categ
 if (isset($stcomm) && $stcomm != '') $sql.= " AND s.fk_stcomm=".$stcomm;
-
+if ($catid > 0)          $sql.= " AND cs.fk_categorie = ".$catid;
+if ($catid == -2)        $sql.= " AND cs.fk_categorie IS NULL";
+if ($search_categ > 0)   $sql.= " AND cs.fk_categorie = ".$search_categ;
+if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL";
 if ($search_nom)   $sql .= " AND s.nom LIKE '%".$db->escape(strtolower($search_nom))."%'";
 if ($search_ville) $sql .= " AND s.ville LIKE '%".$db->escape(strtolower($search_ville))."%'";
 if ($search_departement) $sql .= " AND d.nom LIKE '%".$db->escape(strtolower($search_departement))."%'";
@@ -198,11 +197,6 @@ if ($search_sale)
 {
 	$sql .= " AND sc.fk_user = ".$db->escape($search_sale);
 }
-// Insert categ filter
-if ($search_categ)
-{
-	$sql .= " AND cs.fk_categorie = ".$db->escape($search_categ);
-}
 if ($socname)
 {
 	$sql .= " AND s.nom LIKE '%".$db->escape($socname)."%'";
@@ -271,7 +265,7 @@ if ($resql)
 	if ($conf->categorie->enabled)
 	{
 	 	$moreforfilter.=$langs->trans('Categories'). ': ';
-		$moreforfilter.=$formother->select_categories(2,$search_categ,'search_categ');
+		$moreforfilter.=$formother->select_categories(2,$search_categ,'search_categ',1);
 	 	$moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
 	}
  	// If the user can view prospects other than his'
diff --git a/htdocs/fourn/liste.php b/htdocs/fourn/liste.php
index c8fdfb40d834ca127b7219ecb43bd9b9b5657d43..765683d3b643dcfc33a8a036e41e0cedd3a68d1b 100644
--- a/htdocs/fourn/liste.php
+++ b/htdocs/fourn/liste.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2004-2012 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2011 Regis Houssin        <regis@dolibarr.fr>
  * Copyright (C) 2011      Philippe Grand       <philippe.grand@atoo-net.com>
  *
@@ -37,6 +37,8 @@ $search_ville              = GETPOST("search_ville");
 $search_code_fournisseur   = GETPOST("search_code_fournisseur");
 $search_compta_fournisseur = GETPOST("search_compta_fournisseur");
 $search_datec              = GETPOST("search_datec");
+$search_categ              = GETPOST('search_categ','int');
+$catid                     = GETPOST("catid",'int');
 
 // Security check
 $socid = GETPOST('socid','int');
@@ -53,8 +55,6 @@ $pagenext = $page + 1;
 if (! $sortorder) $sortorder="ASC";
 if (! $sortfield) $sortfield="nom";
 
-// Load categ filters
-$search_categ = GETPOST('search_categ');
 
 
 /*
@@ -70,12 +70,12 @@ llxHeader('',$langs->trans("ThirdParty"),$help_url);
 $sql = "SELECT s.rowid as socid, s.nom, s.ville, s.datec, s.datea,  st.libelle as stcomm, s.prefix_comm, s.status as status, ";
 $sql.= "code_fournisseur, code_compta_fournisseur";
 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
-$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
-if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cf";
+$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
+if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cf ON s.rowid = cf.fk_societe"; // We need this table joined to the select in order to filter by categ
+$sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql.= " WHERE s.fk_stcomm = st.id AND s.fournisseur = 1";
 $sql.= " AND s.entity IN (".getEntity('societe', 1).")";
-if ($search_categ) $sql.= " AND s.rowid = cf.fk_societe";	// Join for the needed table to filter by categ
 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($socid) $sql .= " AND s.rowid = ".$socid;
 if ($socname)
@@ -89,12 +89,10 @@ if ($search_ville) $sql .= " AND s.ville LIKE '%".$db->escape($search_ville)."%'
 if ($search_code_fournisseur)   $sql .= " AND s.code_fournisseur LIKE '%".$db->escape($search_code_fournisseur)."%'";
 if ($search_compta_fournisseur) $sql .= " AND s.code_compta_fournisseur LIKE '%".$db->escape($search_compta_fournisseur)."%'";
 if ($search_datec)   $sql .= " AND s.datec LIKE '%".$db->escape($search_datec)."%'";
-
-// Insert categ filter
-if ($search_categ)
-{
-	$sql .= " AND cf.fk_categorie = ".$db->escape($search_categ);
-}
+if ($catid > 0)          $sql.= " AND cf.fk_categorie = ".$catid;
+if ($catid == -2)        $sql.= " AND cf.fk_categorie IS NULL";
+if ($search_categ > 0)   $sql.= " AND cf.fk_categorie = ".$search_categ;
+if ($search_categ == -2) $sql.= " AND cf.fk_categorie IS NULL";
 // Count total nb of records
 $nbtotalofrecords = 0;
 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@@ -114,7 +112,7 @@ if ($resql)
 	$param = "&amp;search_nom=".$search_nom."&amp;search_code=".$search_code."&amp;search_ville=".$search_ville;
  	if ($search_categ != '') $param.='&amp;search_categ='.$search_categ;
 
-	print_barre_liste($langs->trans("ListOfSuppliers"), $page, "liste.php", $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
+	print_barre_liste($langs->trans("ListOfSuppliers"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
 
 	print '<form action="liste.php" method="GET">';
 	print '<table class="liste" width="100%">';
@@ -124,7 +122,7 @@ if ($resql)
 	if ($conf->categorie->enabled)
 	{
 		$moreforfilter.=$langs->trans('Categories'). ': ';
-		$moreforfilter.=$htmlother->select_categories(1,$search_categ,'search_categ');
+		$moreforfilter.=$htmlother->select_categories(1,$search_categ,'search_categ',1);
 		$moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
 	}
 	if ($moreforfilter)