';
+ print '';
}
else
{
@@ -736,16 +732,22 @@ class Form
function select_produits_do($selected='',$htmlname='productid',$filtretype='',$limit=20,$price_level=0,$ajaxkeyref='',$ajaxkeylabel='')
{
global $langs,$conf,$user;
-
- $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration";
- $sql.= " FROM ".MAIN_DB_PREFIX."product as p ";
- if ($conf->categorie->enabled && !$user->rights->categorie->voir)
+ $user->getrights("categorie");
+
+ $sql = "SELECT ";
+ if ($conf->categorie->enabled && ! $user->rights->categorie->voir)
{
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid";
+ $sql.="DISTINCT";
+ }
+ $sql.= " p.rowid, p.label, p.ref, p.price, p.duration";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product as p ";
+ if ($conf->categorie->enabled && ! $user->rights->categorie->voir)
+ {
+ $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 ($conf->categorie->enabled && !$user->rights->categorie->voir)
+ if ($conf->categorie->enabled && ! $user->rights->categorie->voir)
{
$sql.= ' AND IFNULL(c.visible,1)=1';
}
@@ -755,48 +757,61 @@ class Form
$sql.= " ORDER BY p.nbvente DESC";
if ($limit) $sql.= " LIMIT $limit";
- $result=$this->db->query($sql);
- if (! $result) dolibarr_print_error($this->db);
-
- // Multilang : on construit une liste des traductions des produits listés
- $sqld = "SELECT d.fk_product, d.label";
- $sqld.= " FROM ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."product_det as d ";
- $sqld.= " WHERE d.fk_product=p.rowid AND p.envente=1 AND d.lang='". $langs->getDefaultLang() ."'";
- $sqld.= " ORDER BY p.nbvente DESC";
-
- // inutile de faire la requete si l'option n'est pas active
- if ($conf->global->MAIN_MULTILANGS)
- {
- $resultd = $this->db->query($sqld);
- if ( $resultd ) $objtp = $this->db->fetch_object($resultd);
- }
+ $result=$this->db->query($sql);
+ if (! $result) dolibarr_print_error($this->db);
+
+ // Multilang : on construit une liste des traductions des produits listés
+ if ($conf->global->MAIN_MULTILANGS)
+ {
+ $sqld = "SELECT d.fk_product, d.label";
+ $sqld.= " FROM ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."product_det as d ";
+ $sqld.= " WHERE d.fk_product=p.rowid AND p.envente=1 AND d.lang='". $langs->getDefaultLang() ."'";
+ $sqld.= " ORDER BY p.nbvente DESC";
+ $resultd = $this->db->query($sqld);
+ if ( $resultd ) $objtp = $this->db->fetch_object($resultd);
+ }
if ($result)
{
- if($conf->use_ajax)
- print '