From f31277401b275887c7fc4c8ebf8322b1655226e3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 27 Jul 2012 23:40:28 +0200 Subject: [PATCH] New: [ task #454 ] Add "No category" into filters on category --- htdocs/adherents/liste.php | 21 +++++++++++---------- htdocs/categories/categorie.php | 7 ++++--- htdocs/comm/prospect/list.php | 26 ++++++++++---------------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/htdocs/adherents/liste.php b/htdocs/adherents/liste.php index ad7d6597146..ad6fc2284ed 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.='       '; } if ($moreforfilter) diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index 75082eaf140..ba99f60eaf9 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -268,7 +268,7 @@ if ($socid) print ''; - print ''; + dol_fiche_end(); dol_htmloutput_mesg($mesg); @@ -328,7 +328,7 @@ else if ($id || $ref) print ''; - print ''; + dol_fiche_end(); dol_htmloutput_mesg($mesg); @@ -409,7 +409,7 @@ else if ($id || $ref) print ''; - print ''; + 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/prospect/list.php b/htdocs/comm/prospect/list.php index 5d93a069b0a..ca9ee950b13 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.='       '; } // If the user can view prospects other than his'