From: x2000habouzit Date: Sat, 13 Nov 2004 12:28:56 +0000 (+0000) Subject: support star for quick search X-Git-Tag: xorg/old~966 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=8f07effd1e0ea936ae040efd0bf3fe6ff565b16c;p=platal.git support star for quick search --- diff --git a/include/search.classes.inc.php b/include/search.classes.inc.php index 0bfa209..b280b70 100644 --- a/include/search.classes.inc.php +++ b/include/search.classes.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: search.classes.inc.php,v 1.32 2004-11-13 11:54:28 x2000habouzit Exp $ + $Id: search.classes.inc.php,v 1.33 2004-11-13 12:28:56 x2000habouzit Exp $ ***************************************************************************/ require_once("xorg.misc.inc.php"); @@ -101,6 +101,8 @@ class SField { function get_request() { $this->value = (isset($_REQUEST[$this->fieldFormName]))?trim($_REQUEST[$this->fieldFormName]):''; + if (preg_match(":[][<>{}~/§_`|%$^=+]|\*\*:", $this->value)) + new ThrowError('Un champ contient un caractère interdit rendant la recherche impossible.'); } /** récupérer la clause correspondant au champ dans la clause WHERE de la requête @@ -152,7 +154,8 @@ class QuickSearch extends SField { $s = replace_accent(trim($this->value)); $s = preg_replace('!\d+!', ' ', $s); $s = preg_replace('! - !', '', $s); - $this->strings = preg_split("![^a-zA-Z\-]+!",$s, -1, PREG_SPLIT_NO_EMPTY); + $s = str_replace('*','%',$s); + $this->strings = preg_split("![^a-zA-Z\-%]+!",$s, -1, PREG_SPLIT_NO_EMPTY); $s = trim($this->value); $s = preg_replace('! *- *!', '-', $s); @@ -169,10 +172,13 @@ class QuickSearch extends SField { function get_where_statement() { $where = Array(); if(count($this->strings) == 1) { - $s = $this->strings[0]; - $where[] = "(r.nom LIKE '%$s%' OR r.epouse LIKE '%$s%')"; + $t = '%'.str_replace('*', '%', $this->strings[0]).'%'; + $t = str_replace('%%', '%', $t); + $where[] = "(r.nom LIKE '$t' OR r.epouse LIKE '$t')"; } else foreach($this->strings as $s) { - $where[] = "(r.nom LIKE '%$s%' OR r.epouse LIKE '%$s%' OR r.prenom LIKE '%$s%')"; + $t = '%'.str_replace('*', '%', $s).'%'; + $t = str_replace('%%', '%', $t); + $where[] = "(r.nom LIKE '$t' OR r.epouse LIKE '$t' OR r.prenom LIKE '$t')"; } $wherep = Array();