Bye xorg.misc.inc.php
[platal.git] / modules / search / classes.inc.php
index 7664bb0..db5a414 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -19,8 +19,6 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-require_once("xorg.misc.inc.php");
-
 // {{{ Global variables used for the search Queries
 
 @$globals->search->result_fields = '
@@ -36,9 +34,9 @@ require_once("xorg.misc.inc.php");
     ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type,
     es.label AS secteur, ef.fonction_fr AS fonction,
     IF(n.nat=\'\',n.pays,n.nat) AS nat, n.a2 AS iso3166,
-    COUNT(em.email) > 0 AS actif,';
+    (COUNT(em.email) > 0 OR FIND_IN_SET("googleapps", u.mail_storage) > 0) AS actif,';
 // hide private information if not logged
-if (S::logged()) 
+if (S::logged())
     $globals->search->result_fields .='
         q.profile_web AS web,
         q.profile_mobile AS mobile,
@@ -92,11 +90,12 @@ class ThrowError
      */
     private static function defaultHandler($explain)
     {
-        global $page, $globals;
+        global $globals;
+        $page =& Platal::page();
         $page->changeTpl('search/index.tpl');
-        $page->assign('xorg_title','Polytechnique.org - Annuaire');
+        $page->assign('pl_title','Polytechnique.org - Annuaire');
         $page->assign('baseurl', $globals->baseurl);
-        $page->trig('Erreur : '.$explain);
+        $page->trigError($explain);
         $page->run();
     }
 }
@@ -138,7 +137,7 @@ class SField
     // }}}
     // {{{ function get_request()
 
-    /** récupérer la requête de l'utilisateur 
+    /** récupérer la requête de l'utilisateur
      * on met une chaîne vide si le champ n'a pas été complété */
     function get_request()
     {
@@ -149,7 +148,7 @@ class SField
     // {{{ function get_where_statement()
 
     /** récupérer la clause correspondant au champ dans la clause WHERE de la requête
-     * on parcourt l'ensemble des champs de la bdd de $fieldDbName et on associe 
+     * on parcourt l'ensemble des champs de la bdd de $fieldDbName et on associe
      * à chacun d'entre eux une clause spécifique
      * la clause totale et la disjonction de ces clauses spécifiques */
     function get_where_statement()
@@ -252,6 +251,10 @@ class QuickSearch extends SField
 
         $s = preg_replace('!\d+!', ' ', $s);
         $this->strings = preg_split("![^a-zA-Z%]+!",$s, -1, PREG_SPLIT_NO_EMPTY);
+        if (count($this->strings) > 5) {
+            Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
+            $this->strings = array_slice($this->strings, 0, 5);
+        }
 
         $s = preg_replace('! *- *!', '-', $r);
         $s = preg_replace('!([<>]) *!', ' \1', $s);
@@ -302,9 +305,10 @@ class QuickSearch extends SField
             $where[] = 'ems.email = ' . XDB::escape($this->email);
         }
         if (!empty($this->ip)) {
-            $ip = XDB::escape($this->ip);
-            $where[] = "( ls.ip = $ip OR ls.forward_ip = $ip )";
+            $ip = ip_to_uint($this->ip);
+            $where[] = "( ls.ip = $ip OR ls.forward_ip = $ip ) AND ls.suid = 0";
         }
+
         return join(" AND ", $where);
     }
 
@@ -467,7 +471,16 @@ class RefSField extends SField
             return false;
         }
         $res = implode(' OR ', array_filter(array_map(array($this, 'get_single_match_statement'), $this->fieldDbName)));
-        return "INNER JOIN {$this->refTable} AS {$this->refAlias} ON ({$this->refCondition} AND ($res) )";
+        if (is_array($this->refTable)) {
+           foreach ($this->refTable as $i => $refT)
+               $last = $i;
+           $inner = "";
+            foreach ($this->refTable as $i => $refT)
+                $inner .= " INNER JOIN {$refT} AS {$this->refAlias[$i]} ON ({$this->refCondition[$i]} ".(($i == $last)?"AND ($res) ":"").")\n";
+            return $inner;
+        } else {
+            return "INNER JOIN {$this->refTable} AS {$this->refAlias} ON ({$this->refCondition} AND ($res) )";
+        }
     }
 
     // }}}
@@ -489,7 +502,7 @@ class MapSField extends RefSField
         $this->value =  $this->mapId;
         $this->RefSField($_fieldFormName, $_fieldDbName, $_refTable, $_refAlias, $_refCondition, true, false);
     }
-    
+
     function get_select_statement()
     {
         if ($this->mapId === '') return false;
@@ -650,7 +663,7 @@ class PromoSField extends SField
     // }}}
     // {{{ constructor
 
-    /** constructeur 
+    /** constructeur
      * compareField est un champ de formulaire très simple qui ne sert qu'à la construction de la
      * clause WHERE de la promo */
     function PromoSField($_fieldFormName, $_compareFieldFormName, $_fieldDbName, $_fieldResultName)
@@ -740,6 +753,11 @@ class SFieldGroup
     {
         $this->fields = $_fields;
         $this->and    = $_and;
+        foreach ($this->fields as $key=>&$field) {
+            if (is_null($field)) {
+                unset($this->fields[$key]);
+            }
+        }
     }
 
     // }}}
@@ -749,7 +767,9 @@ class SFieldGroup
     {
         $b = true;
         for ($i=0 ; $b && $i<count($this->fields) ; $i++) {
-            $b = $b && $this->fields[$i]->too_large();
+            if (!is_null($this->fields[$i])) {
+                $b = $b && $this->fields[$i]->too_large();
+            }
         }
         return $b;
     }