use php5-isms
[platal.git] / include / search / classes.inc.php
index 4b5718a..57f1d7d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  Copyright (C) 2003-2006 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -35,9 +35,10 @@ $globals->search->result_fields = '
                 ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type,
                 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,';
+                IF(n.nat=\'\',n.pays,n.nat) AS nat, n.a2 AS iso3166,
+        COUNT(em.email) > 0 AS actif,';
 // hide private information if not logged
-if (logged()) 
+if (S::logged()) 
        $globals->search->result_fields .='
                q.profile_web AS web,
                q.profile_mobile AS mobile,
@@ -64,7 +65,8 @@ $globals->search->result_where_statement = '
                 LEFT JOIN  geoloc_pays    AS n   ON (u.nationalite = n.a2)
                 LEFT JOIN  adresses       AS adr ON (u.user_id = adr.uid AND FIND_IN_SET(\'active\',adr.statut))
                 LEFT JOIN  geoloc_pays    AS gp  ON (adr.country = gp.a2)
-                LEFT JOIN  geoloc_region  AS gr  ON (adr.country = gr.a2 AND adr.region = gr.region)';
+                LEFT JOIN  geoloc_region  AS gr  ON (adr.country = gr.a2 AND adr.region = gr.region)
+                LEFT JOIN  emails         AS em  ON (em.uid = u.user_id AND em.flags = \'active\')';
 
 // }}}
 // {{{ function display_lines()
@@ -100,7 +102,8 @@ class ThrowError
     function ThrowError($explain)
     {
         global $page;
-        $page->trig_run('Erreur : '.$explain);
+        $page->trig('Erreur : '.$explain);
+        $page->run();
     }
 }
 
@@ -145,7 +148,7 @@ class SField
      * on met une chaîne vide si le champ n'a pas été complété */
     function get_request()
     {
-        $this->value = trim(Env::get($this->fieldFormName));
+        $this->value = trim(Env::v($this->fieldFormName));
     }
 
     // }}}
@@ -439,6 +442,37 @@ class RefSField extends SField
 }
 
 // }}}
+
+// {{{ class RefSFieldMultipleTable
+class MapSField extends RefSField
+{
+       var $mapId;
+       
+    function MapSField($_fieldFormName, $_fieldDbName='', $_refTable, $_refAlias, $_refCondition, $_mapId=false)
+    {
+        if ($_mapId === false)
+            $this->mapId = Env::v($_fieldFormName, '');
+        else
+            $this->mapId = $_mapId;
+        $this->RefSField($_fieldFormName, $_fieldDbName, $_refTable, $_refAlias, $_refCondition, true, false);
+    }
+    function get_select_statement()
+    {
+        if ($this->mapId === '') return false;
+        $res = implode(' OR ', array_filter(array_map(array($this, 'get_single_match_statement'), $this->fieldDbName)));
+        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) ":"").")";
+        return $inner;
+    }
+    function get_request()
+    {
+        $this->value = $this->mapId;
+    }
+}
+
 // {{{ class RefWithSoundexSField                       [ ??? ]
 
 class RefWithSoundexSField extends RefSField
@@ -777,4 +811,5 @@ class SFieldGroup
 
 // }}}
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>