Serves javascript file from a per-version directory, to prevent cross-version caching...
[platal.git] / modules / search / classes.inc.php
index 42ee056..9def2db 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -239,9 +239,9 @@ class QuickSearch extends SField
         $s = replace_accent(trim($this->value));
         $r = $s = str_replace('*','%',$s);
 
-        if (S::has_perms() && strpos($s, '@') !== false) {
+        if (S::admin() && strpos($s, '@') !== false) {
             $this->email = $s;
-        } else if (S::has_perms() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
+        } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
             $this->ip = $s;
         }
         if ($this->email || $this->ip) {
@@ -277,6 +277,8 @@ class QuickSearch extends SField
             if (Env::i('with_soundex') && strlen($s) > 1) {
                 $t = soundex_fr($s);
                 $where[] = "sn$i.soundex = '$t'";
+            } elseif (Env::i('exact')) {
+                $where[] = "sn$i.token = '$s'";
             } else {
                 $t = str_replace('*', '%', $s).'%';
                 $t = str_replace('%%', '%', $t);
@@ -306,7 +308,14 @@ class QuickSearch extends SField
         }
         if (!empty($this->ip)) {
             $ip = ip_to_uint($this->ip);
-            $where[] = "( ls.ip = $ip OR ls.forward_ip = $ip ) AND ls.suid = 0";
+
+            // If the IP address requested for the search cannot be translated,
+            // the predicate should always be valued to false.
+            if ($ip != null) {
+                $where[] = "( ls.ip = $ip OR ls.forward_ip = $ip ) AND ls.suid = 0";
+            } else {
+                $where[] = "false";
+            }
         }
 
         return join(" AND ", $where);
@@ -443,6 +452,7 @@ class RefSField extends SField
     function compare()
     {
         $val = addslashes($this->value);
+        if (Env::i('exact')) return "='$val'";
         return $this->exact ? "='$val'" : " LIKE '%$val%'";
     }
 
@@ -561,7 +571,7 @@ class StringSField extends SField
      * imposées par l'utilisateur) */
     function length()
     {
-        $cleaned = replace_accent(strtolower($this->value));
+        $cleaned = strtolower(replace_accent($this->value));
         $length  = strlen(ereg_replace('[a-z0-9]', '', $cleaned));
         return strlen($this->value) - $length;
     }
@@ -581,7 +591,9 @@ class StringSField extends SField
      * @param field nom de champ de la bdd concerné par la clause */
     function get_single_where_statement($field)
     {
-        $regexp = strtr(addslashes($this->value), '-*', '_%');
+        $val = addslashes($this->value);
+        if (Env::i('exact')) return "$field = '$val'";
+        $regexp = strtr($val, '-*', '_%');
         return "$field LIKE '$regexp%'";
     }
 
@@ -612,7 +624,9 @@ class NameSField extends StringSField
 
     function get_single_where_statement($field)
     {
-        $regexp = strtr(addslashes($this->value), '-*', '_%');
+        $val = addslashes($this->value);
+        if (Env::i('exact')) return "$field = '$val'";
+        $regexp = strtr($val, '-*', '_%');
         return "$field LIKE '$regexp%' OR $field LIKE '% $regexp%' OR $field LIKE '%-$regexp%'";
     }