From 639c033afbcb2765653a760ec076e40573438850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 15 Mar 2013 15:37:59 +0100 Subject: [PATCH] Added natural search to third parties --- htdocs/societe/societe.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/htdocs/societe/societe.php b/htdocs/societe/societe.php index 763274d2a79..26583442b2c 100644 --- a/htdocs/societe/societe.php +++ b/htdocs/societe/societe.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Marcos García + * Copyright (C) 2013 Raphaël Doursenaud * * 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 @@ -80,19 +81,25 @@ if ($mode == 'search') // 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"; $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; - $sql.= " AND ("; - $sql.= " s.nom LIKE '%".$db->escape($socname)."%'"; - $sql.= " OR s.code_client LIKE '%".$db->escape($socname)."%'"; - $sql.= " OR s.email LIKE '%".$db->escape($socname)."%'"; - $sql.= " OR s.url LIKE '%".$db->escape($socname)."%'"; - $sql.= " OR s.siren LIKE '%".$db->escape($socname)."%'"; - if (!empty($conf->barcode->enabled)) - { - $sql.= "OR s.barcode LIKE '".$db->escape($socname)."'"; - } + // For natural search + $scrit = explode(' ', $socname); + foreach ($scrit as $crit) { + $sql.= " AND ("; + $sql.= " s.nom LIKE '%".$db->escape($crit)."%'"; + $sql.= " OR s.code_client LIKE '%".$db->escape($crit)."%'"; + $sql.= " OR s.email LIKE '%".$db->escape($crit)."%'"; + $sql.= " OR s.url LIKE '%".$db->escape($crit)."%'"; + $sql.= " OR s.siren LIKE '%".$db->escape($crit)."%'"; + + if (!empty($conf->barcode->enabled)) + { + $sql.= "OR s.barcode LIKE '".$db->escape($crit)."'"; + } + + $sql.= ")"; + } - $sql.= ")"; 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 ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale