From f92c05ec388c0fcba563b93bf8b05fa2609b40ec Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 10 Jul 2008 21:50:23 +0000 Subject: [PATCH] Fix: Products on hold are not reported in list with ajax selector --- htdocs/html.form.class.php | 37 ++++++++++++++++++--------------- htdocs/product/ajaxproducts.php | 20 +++++++++--------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 70d7f284d8d..7c57cf34962 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -932,14 +932,15 @@ class Form /** - \brief Retourne la liste des produits en Ajax si ajax activé ou renvoie à select_produits_do - \param selected Produit pré-sélectionné - \param htmlname Nom de la zone select - \param filtretype Pour filtre sur type de produit - \param limit Limite sur le nombre de lignes retournées - \param price_level Niveau de prix en fonction du client + \brief Retourne la liste des produits en Ajax si ajax activé ou renvoie à select_produits_do + \param selected Produit pré-sélectionné + \param htmlname Nom de la zone select + \param filtretype Pour filtre sur type de produit + \param limit Limite sur le nombre de lignes retournées + \param price_level Niveau de prix en fonction du client + \param status -1=Return all products, 0=Products not on sell, 1=Products on sell */ - function select_produits($selected='',$htmlname='productid',$filtretype='',$limit=20,$price_level=0) + function select_produits($selected='',$htmlname='productid',$filtretype='',$limit=20,$price_level=0,$status=1) { global $langs,$conf; @@ -956,13 +957,13 @@ class Form print ''; print ''; print ''; - print ajax_updater($htmlname,'keysearch','/product/ajaxproducts.php','&price_level='.$price_level.'&type=1',''); + print ajax_updater($htmlname,'keysearch','/product/ajaxproducts.php','&price_level='.$price_level.'&type='.$filtretype.'&status='.$status,''); print ''; print ''; } else { - $this->select_produits_do($selected,$htmlname,$filtretype,$limit,$price_level); + $this->select_produits_do($selected,$htmlname,$filtretype,$limit,$price_level,'',$status); } } @@ -974,8 +975,9 @@ class Form \param limit Limite sur le nombre de lignes retournées \param price_level Niveau de prix en fonction du client \param ajaxkeysearch Filtre des produits si ajax est utilisé + \param status -1=Return all products, 0=Products not on sell, 1=Products on sell */ - function select_produits_do($selected='',$htmlname='productid',$filtretype='',$limit=20,$price_level=0,$ajaxkeysearch='') + function select_produits_do($selected='',$htmlname='productid',$filtretype='',$limit=20,$price_level=0,$ajaxkeysearch='',$status=1) { global $langs,$conf,$user; @@ -991,13 +993,14 @@ class Form $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid"; } - $sql.= " WHERE p.envente = 1"; + if ($status >= 0) $sql.= " WHERE p.envente = ".$status; + else $sql.= " WHERE 1 = 1"; if ($conf->categorie->enabled && ! $user->rights->categorie->voir) { $sql.= ' AND IFNULL(c.visible,1)=1'; } if ($filtretype && $filtretype != '') $sql.=" AND p.fk_product_type=".$filtretype; - if ($ajaxkeysearch && $ajaxkeysearch != '') $sql.=" AND p.ref like '%".$ajaxkeysearch."%' OR p.label like '%".$ajaxkeysearch."%'"; + if ($ajaxkeysearch && $ajaxkeysearch != '') $sql.=" AND (p.ref like '%".$ajaxkeysearch."%' OR p.label like '%".$ajaxkeysearch."%')"; $sql.= " ORDER BY p.nbvente DESC"; if ($limit) $sql.= " LIMIT $limit"; @@ -1128,7 +1131,7 @@ class Form \param selected Produit pré-sélectionné \param htmlname Nom de la zone select \param filtretype Pour filtre sur type de produit - \param limit Limite sur le nombre de lignes retournées + \param filtre Pour filtre sql */ function select_produits_fournisseurs($socid,$selected='',$htmlname='productid',$filtretype='',$filtre='') { @@ -1136,7 +1139,7 @@ class Form if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT) { print $langs->trans("RefOrLabel").' : '; - print ajax_updater($htmlname,'keysearch','/product/ajaxproducts.php','&socid='.$socid.'&type=2','working'); + print ajax_updater($htmlname,'keysearch','/product/ajaxproducts.php','&socid='.$socid.'&type='.$filtretype,'working'); } else { @@ -1150,7 +1153,7 @@ class Form \param selected Produit pré-sélectionné \param htmlname Nom de la zone select \param filtretype Pour filtre sur type de produit - \param filtre Pour filtre + \param filtre Pour filtre sql \param ajaxkeysearch Filtre des produits si ajax est utilisé */ function select_produits_fournisseurs_do($socid,$selected='',$htmlname='productid',$filtretype='',$filtre='',$ajaxkeysearch='') @@ -1169,8 +1172,8 @@ class Form $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur"; $sql.= " WHERE p.envente = 1"; if ($socid) $sql.= " AND pf.fk_soc = ".$socid; - if ($filtretype && $filtretype != '') $sql.=" AND p.fk_product_type=".$filtretype; - if ($filtre) $sql.="$filtre"; + if (! empty($filtretype)) $sql.=" AND p.fk_product_type=".$filtretype; + if (! empty($filtre)) $sql.=" ".$filtre; if ($ajaxkeysearch && $ajaxkeysearch != '') $sql.=" AND (pf.ref_fourn like '%".$ajaxkeysearch."%' OR p.label like '%".$ajaxkeysearch."%')"; $sql.= " ORDER BY pf.ref_fourn DESC"; diff --git a/htdocs/product/ajaxproducts.php b/htdocs/product/ajaxproducts.php index 6bb17fcfbc6..afd3d961ba0 100644 --- a/htdocs/product/ajaxproducts.php +++ b/htdocs/product/ajaxproducts.php @@ -1,7 +1,7 @@ * Copyright (C) 2005-2007 Regis Houssin - * Copyright (C) 2007 Laurent Destailleur + * Copyright (C) 2007-2008 Laurent Destailleur * * 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 @@ -16,15 +16,12 @@ * 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/product/ajaxproducts.php \brief Fichier de reponse sur evenement Ajax - \version $Revision$ + \version $Id$ */ require('../main.inc.php'); @@ -37,19 +34,22 @@ top_htmlhead("", "", 1); print ''."\n"; // Generation liste de produits -if(isset($_GET['keysearch']) && !empty($_GET['keysearch'])) +if (! empty($_GET['keysearch'])) { + $status=-1; + if (isset($_GET['status'])) $status=$_GET['status']; + $form = new Form($db); if ($_GET['type'] == 1) { - $form->select_produits_do("",$_GET["htmlname"],"","",$_GET["price_level"],$_GET["keysearch"]); + $form->select_produits_do("",$_GET["htmlname"],"","",$_GET["price_level"],$_GET["keysearch"],$status); } - else if ($_GET['type'] == 2) + if ($_GET['type'] == 2) { $form->select_produits_fournisseurs_do($_GET["socid"],"",$_GET["htmlname"],"","",$_GET["keysearch"]); } } -else if(isset($_GET['markup']) && !empty($_GET['markup'])) +else if (! empty($_GET['markup'])) { print $_GET['markup']; //print $_GET['count']; @@ -57,7 +57,7 @@ else if(isset($_GET['markup']) && !empty($_GET['markup'])) //print ''; //print $field; } -else if(isset($_GET['selling']) && !empty($_GET['selling'])) +else if (! empty($_GET['selling'])) { //print $_GET['markup']; //print $_GET['count'];