diff --git a/htdocs/comm/list.php b/htdocs/comm/list.php index e03b7473c55..2c256ec2fda 100644 --- a/htdocs/comm/list.php +++ b/htdocs/comm/list.php @@ -117,11 +117,11 @@ 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 .= natural_search(array('s.nom'), $search_nom); + $sql .= natural_search('s.nom', $search_nom); } if ($search_zipcode) $sql.= " AND s.zip LIKE '".$db->escape($search_zipcode)."%'"; if ($search_town) { - $sql .= natural_search(array('s.town'), $search_town); + $sql .= natural_search('s.town', $search_town); } if ($search_code) $sql.= " AND s.code_client LIKE '%".$db->escape($search_code)."%'"; if ($search_compta) $sql.= " AND s.code_compta LIKE '%".$db->escape($search_compta)."%'"; diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index d0a7228e21e..ae489ce83c0 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -162,16 +162,16 @@ if (! $user->rights->societe->client->voir && ! $socid) //restriction $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; } if ($search_town) {//restriction - $sql .= natural_search(array('s.town'), $search_town); + $sql .= natural_search('s.town', $search_town); } if ($search_ref) { - $sql .= natural_search(array('p.ref'), $search_ref); + $sql .= natural_search('p.ref', $search_ref); } if ($search_refcustomer) { - $sql .= natural_search(array('p.ref_client'), $search_refcustomer); + $sql .= natural_search('p.ref_client', $search_refcustomer); } if ($search_societe) { - $sql .= natural_search(array('s.nom'), $search_societe); + $sql .= natural_search('s.nom', $search_societe); } if ($search_author) { diff --git a/htdocs/comm/prospect/list.php b/htdocs/comm/prospect/list.php index eabd74fa64b..959c271b85e 100644 --- a/htdocs/comm/prospect/list.php +++ b/htdocs/comm/prospect/list.php @@ -195,14 +195,14 @@ 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 .= natural_search(array('s.nom'), $search_nom); + $sql .= natural_search('s.nom', $search_nom); } if ($search_zipcode) $sql .= " AND s.zip LIKE '".$db->escape(strtolower($search_zipcode))."%'"; if ($search_town) { - $sql .= natural_search(array('s.town'), $search_town); + $sql .= natural_search('s.town', $search_town); } if ($search_state) { - $sql .= natural_search(array('d.nom'), $search_state); + $sql .= natural_search('d.nom', $search_state); } if ($search_datec) $sql .= " AND s.datec LIKE '%".$db->escape($search_datec)."%'"; // Insert levels filters @@ -216,7 +216,7 @@ if ($search_sale) $sql .= " AND sc.fk_user = ".$db->escape($search_sale); } if ($socname) { - $sql .= natural_search(array('s.nom'), $search_nom); + $sql .= natural_search('s.nom', $search_nom); $sortfield = "s.nom"; $sortorder = "ASC"; } diff --git a/htdocs/commande/liste.php b/htdocs/commande/liste.php index 13bbac17e50..9bf7caf379a 100644 --- a/htdocs/commande/liste.php +++ b/htdocs/commande/liste.php @@ -127,7 +127,7 @@ $sql.= ' AND c.entity = '.$conf->entity; if ($socid) $sql.= ' AND s.rowid = '.$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($sref) { - $sql .= natural_search(array('c.ref'), $sref); + $sql .= natural_search('c.ref', $sref); } if ($sall) { @@ -187,7 +187,7 @@ else if ($deliveryyear > 0) } if (!empty($snom)) { - $sql .= natural_search(array('s.nom'), $snom); + $sql .= natural_search('s.nom', $snom); } if (!empty($sref_client)) { diff --git a/htdocs/compta/dons/liste.php b/htdocs/compta/dons/liste.php index 73fc2b0ba48..56c66d4fdce 100644 --- a/htdocs/compta/dons/liste.php +++ b/htdocs/compta/dons/liste.php @@ -76,7 +76,7 @@ if (trim($search_ref) != '') } if (trim($search_company) != '') { - $sql .= natural_search(array('d.societe'), $search_company); + $sql .= natural_search('d.societe', $search_company); } if (trim($search_name) != '') { diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index f1835fd41f1..7a5749006a6 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -175,11 +175,11 @@ if ($filtre) } if ($search_ref) { - $sql .= natural_search(array('f.facnumber'), $search_ref); + $sql .= natural_search('f.facnumber', $search_ref); } if ($search_societe) { - $sql .= natural_search(array('s.nom'), $search_societe); + $sql .= natural_search('s.nom', $search_societe); } if ($search_montant_ht) { diff --git a/htdocs/compta/paiement/liste.php b/htdocs/compta/paiement/liste.php index a4952b66f41..5e1653b3ec3 100644 --- a/htdocs/compta/paiement/liste.php +++ b/htdocs/compta/paiement/liste.php @@ -113,7 +113,7 @@ else if (GETPOST("search_account") > 0) $sql .=" AND b.fk_account=".GETPOST("search_account",'int'); if (GETPOST("search_paymenttype") != "") $sql .=" AND c.code='".GETPOST("search_paymenttype")."'"; if (GETPOST("search_amount")) $sql .=" AND p.amount=".price2num(GETPOST("search_amount")); - if (GETPOST("search_company")) $sql .= natural_search(array('s.nom'), GETPOST('search_company')); + if (GETPOST("search_company")) $sql .= natural_search('s.nom', GETPOST('search_company')); } $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit+1, $offset); diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 11ddd4ae72f..686e8766b44 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -150,16 +150,16 @@ if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$search_categ; if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL"; if ($search_lastname) { // filter on lastname - $sql .= natural_search(array('p.lastname'), $search_lastname); + $sql .= natural_search('p.lastname', $search_lastname); } if ($search_firstname) { // filter on firstname - $sql .= natural_search(array('p.firstname'), $search_firstname); + $sql .= natural_search('p.firstname', $search_firstname); } if ($search_societe) { // filtre sur la societe - $sql .= natural_search(array('s.nom'), $search_societe); + $sql .= natural_search('s.nom', $search_societe); } if (strlen($search_poste)) { // filtre sur la societe - $sql .= natural_search(array('p.poste'), $search_poste); + $sql .= natural_search('p.poste', $search_poste); } if (strlen($search_phone)) { diff --git a/htdocs/contrat/liste.php b/htdocs/contrat/liste.php index 2a90ce37d1d..40a6811e41b 100644 --- a/htdocs/contrat/liste.php +++ b/htdocs/contrat/liste.php @@ -81,7 +81,7 @@ $sql.= " AND c.entity = ".$conf->entity; if ($socid) $sql.= " AND s.rowid = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($search_nom) { - $sql .= natural_search(array('s.nom'), $search_nom); + $sql .= natural_search('s.nom', $search_nom); } if ($search_contract) { $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2604073fb63..ca2a68c3454 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4439,7 +4439,7 @@ if (! function_exists('getmypid')) /** * Natural search - * @param array[string] $fields array filled with the fields names in the SQL query + * @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 * @return string $res the statement to append to the SQL query * */ @@ -4448,6 +4448,9 @@ function natural_search($fields, $value) global $db; $crits = explode(' ', $value); $res = ""; + if (! is_array($fields)) { + $fields = array($fields); + } $end = count($fields); $end2 = count($crits); $j = 0; diff --git a/htdocs/fichinter/list.php b/htdocs/fichinter/list.php index eed071cb42f..93142ed2dc3 100644 --- a/htdocs/fichinter/list.php +++ b/htdocs/fichinter/list.php @@ -75,10 +75,10 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as fd ON fd.fk_fichinter = f.r $sql.= " WHERE f.fk_soc = s.rowid "; $sql.= " AND f.entity = ".$conf->entity; if ($search_ref) { - $sql .= natural_search(array('f.ref'), $search_ref); + $sql .= natural_search('f.ref', $search_ref); } if ($search_company) { - $sql .= natural_search(array('s.nom'), $search_company); + $sql .= natural_search('s.nom', $search_company); } if ($search_desc) { $sql .= natural_search(array('f.description', 'fd.description'), $search_desc); diff --git a/htdocs/fourn/commande/liste.php b/htdocs/fourn/commande/liste.php index bf4f274dc43..e56c60a68dd 100644 --- a/htdocs/fourn/commande/liste.php +++ b/htdocs/fourn/commande/liste.php @@ -93,11 +93,11 @@ $sql.= " AND cf.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($sref) { - $sql .= natural_search(array('cf.ref'), $sref); + $sql .= natural_search('cf.ref', $sref); } if ($snom) { - $sql .= natural_search(array('s.nom'), $snom); + $sql .= natural_search('s.nom', $snom); } if ($suser) { diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index 6f93fd3c61e..bc7632350c1 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -132,11 +132,11 @@ if (GETPOST('filtre')) if (GETPOST("search_ref")) { if (is_numeric(GETPOST("search_ref"))) $sql .= natural_search(array('fac.rowid', 'fac.ref'), GETPOST('search_ref'));// For backward compatibility - else $sql .= natural_search(array('fac.ref'), GETPOST("search_ref")); + else $sql .= natural_search('fac.ref', GETPOST("search_ref")); } if (GETPOST("search_ref_supplier")) { - $sql .= natural_search(array('fac.ref_supplier'), GETPOST('search_ref_supplier')); + $sql .= natural_search('fac.ref_supplier', GETPOST('search_ref_supplier')); } if ($month > 0) { @@ -151,12 +151,12 @@ else if ($year > 0) } if (GETPOST("search_libelle")) { - $sql .= natural_search(array('fac.libelle'), GETPOST('search_libelle')); + $sql .= natural_search('fac.libelle', GETPOST('search_libelle')); } if (GETPOST("search_societe")) { - $sql .= natural_search(array('s.nom'), GETPOST('search_societe')); + $sql .= natural_search('s.nom', GETPOST('search_societe')); } if (GETPOST("search_montant_ht")) diff --git a/htdocs/fourn/liste.php b/htdocs/fourn/liste.php index c4256625a3a..78668103606 100644 --- a/htdocs/fourn/liste.php +++ b/htdocs/fourn/liste.php @@ -90,16 +90,16 @@ $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 ($socname) { - $sql .= natural_search(array('s.nom'), $socname); + $sql .= natural_search('s.nom', $socname); $sortfield = "s.nom"; $sortorder = "ASC"; } if ($search_nom) { - $sql .= natural_search(array('s.nom'), $search_nom); + $sql .= natural_search('s.nom', $search_nom); } if ($search_zipcode) $sql .= " AND s.zip LIKE '".$db->escape($search_zipcode)."%'"; if ($search_town) { - $sql .= natural_search(array('s.town'), $search_town); + $sql .= natural_search('s.town', $search_town); } 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)."%'"; diff --git a/htdocs/fourn/product/liste.php b/htdocs/fourn/product/liste.php index bc82a48c907..33439ed05fd 100644 --- a/htdocs/fourn/product/liste.php +++ b/htdocs/fourn/product/liste.php @@ -106,11 +106,11 @@ else } if ($sref) { - $sql .= natural_search(array('p.ref'), $sref); + $sql .= natural_search('p.ref', $sref); } if ($snom) { - $sql .= natural_search(array('p.label'), $snom); + $sql .= natural_search('p.label', $snom); } if($catid) { @@ -119,7 +119,7 @@ else } if ($sRefSupplier) { - $sql .= natural_search(array('ppf.ref_fourn'), $sRefSupplier); + $sql .= natural_search('ppf.ref_fourn', $sRefSupplier); } if ($fourn_id > 0) { diff --git a/htdocs/product/liste.php b/htdocs/product/liste.php index 2ad7147ac63..af1dfea171b 100644 --- a/htdocs/product/liste.php +++ b/htdocs/product/liste.php @@ -162,7 +162,7 @@ else else $sql.= " AND p.fk_product_type <> '1'"; } if ($sref) { - $sql .= natural_search(array('p.ref'), $sref); + $sql .= natural_search('p.ref', $sref); } if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'"; if ($snom) diff --git a/htdocs/projet/liste.php b/htdocs/projet/liste.php index bb07738e09f..23ad699b512 100644 --- a/htdocs/projet/liste.php +++ b/htdocs/projet/liste.php @@ -87,15 +87,15 @@ if ($mine || ! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$pro if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; if ($search_ref) { - $sql .= natural_search(array('p.ref'), $search_ref); + $sql .= natural_search('p.ref', $search_ref); } if ($search_label) { - $sql .= natural_search(array('p.title'), $search_label); + $sql .= natural_search('p.title', $search_label); } if ($search_societe) { - $sql .= natural_search(array('s.nom'), $search_societe); + $sql .= natural_search('s.nom', $search_societe); } $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($conf->liste_limit+1, $offset);