diff --git a/ChangeLog b/ChangeLog
index aaf50f6452b..aec1231f66b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,7 @@ Fix: Enable extrafields for customer order, proposal and invoice lines. This fea
was developed for 3.5 but was disabled (hidden) because of a bug not possible to
fix enough quickly for 3.5.0 release.
Fix: user right on Holiday for month report nor working.
+Fix: [ bug #1250 ] "Supplier Ref. product" sidebar search box does not work
***** ChangeLog for 3.5 compared to 3.4.* *****
For users:
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index c53c0997fcc..b6df6ff335c 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -4496,26 +4496,23 @@ if (! function_exists('getmypid'))
* Natural search
*
* @param mixed $fields String or array of strings filled with the fields names in the SQL query
- * @param string $value The value to look for
+ * @param string $value The value to look for (example: "keyword1 keyword2")
* @return string $res The statement to append to the SQL query
*/
function natural_search($fields, $value)
{
global $db;
$crits = explode(' ', $value);
- $res = "";
- if (! is_array($fields)) {
- $fields = array($fields);
- }
+ $res = '';
+ if (! is_array($fields)) $fields = array($fields);
+
$end = count($fields);
$end2 = count($crits);
$j = 0;
foreach ($crits as $crit) {
$i = 0;
foreach ($fields as $field) {
- if ( $i > 0 && $i < $end){
- $res .= " OR ";
- }
+ if ( $i > 0 && $i < $end) $res .= " OR ";
$res .= $field . " LIKE '%" . $db->escape(trim($crit)) . "%'";
$i++;
}
diff --git a/htdocs/fourn/product/liste.php b/htdocs/fourn/product/liste.php
index 76c34be7034..e380f9dd7df 100644
--- a/htdocs/fourn/product/liste.php
+++ b/htdocs/fourn/product/liste.php
@@ -94,37 +94,26 @@ if ($catid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.f
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid";
$sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
-if (GETPOST('mode', 'alpha') == 'search')
-{
- $sql .= natural_search(array('p.ref', 'p.label'), GETPOST('mode', 'alpha'));
-}
-else
-{
- if (GETPOST('type'))
- {
- $sql .= " AND p.fk_product_type = " . GETPOST('type','int');
- }
- if ($sref)
- {
- $sql .= natural_search('p.ref', $sref);
- }
- if ($sRefSupplier)
- {
- $sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
- }
- if ($snom)
- {
- $sql .= natural_search('p.label', $snom);
- }
- if($catid)
- {
- $sql .= " AND cp.fk_categorie = ".$catid;
- }
-}
if ($sRefSupplier)
{
$sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
}
+if (GETPOST('type'))
+{
+ $sql .= " AND p.fk_product_type = " . GETPOST('type','int');
+}
+if ($sref)
+{
+ $sql .= natural_search('p.ref', $sref);
+}
+if ($snom)
+{
+ $sql .= natural_search('p.label', $snom);
+}
+if($catid)
+{
+ $sql .= " AND cp.fk_categorie = ".$catid;
+}
if ($fourn_id > 0)
{
$sql .= " AND ppf.fk_soc = ".$fourn_id;
@@ -132,9 +121,7 @@ if ($fourn_id > 0)
$sql .= " ORDER BY ".$sortfield." ".$sortorder;
$sql .= $db->plimit($limit + 1, $offset);
-
-dol_syslog("fourn/product/liste: sql=".$sql);
-
+dol_syslog("fourn/product/liste.php: sql=".$sql);
$resql = $db->query($sql);
if ($resql)
{
@@ -142,10 +129,10 @@ if ($resql)
$i = 0;
- if ($num == 1 && ( isset($_POST["sall"]) || $snom || $sref ) )
+ if ($num == 1 && (GETPOST("mode") == 'search'))
{
$objp = $db->fetch_object($resql);
- header("Location: fiche.php?id=".$objp->rowid);
+ header("Location: ".DOL_URL_ROOT."/product/fiche.php?id=".$objp->rowid);
exit;
}
@@ -155,8 +142,8 @@ if ($resql)
llxHeader("","",$texte);
- $param="&tobuy=$tobuy&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":"");
- print_barre_liste($texte, $page, "liste.php", $param, $sortfield, $sortorder,'',$num);
+ $param="&tobuy=".$tobuy."&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type)?"&type=".$type:"").(empty($sRefSupplier)?"":"&srefsupplier=".$sRefSupplier);
+ print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num);
if (isset($catid))
@@ -168,27 +155,27 @@ if ($resql)
print "
";
}
-
- print '