Fix geoloc on advance search
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 15 Apr 2007 17:58:44 +0000 (17:58 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 15 Apr 2007 17:58:44 +0000 (17:58 +0000)
 include/geoloc.inc.php         |   13 ++++++++-----
 include/userset.inc.php        |   18 +++++++++---------
 modules/search.php             |    2 +-
 modules/search/search.inc.php  |    3 +--
 templates/search/adv.form.tpl  |   13 +------------
 templates/search/adv.links.tpl |    4 ++--
 6 files changed, 22 insertions(+), 31 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1699 839d8a87-29fc-0310-9880-83ba4fa771e5

include/geoloc.inc.php
include/userset.inc.php
modules/search.php
modules/search/search.inc.php
templates/search/adv.form.tpl
templates/search/adv.links.tpl

index 6a460bc..bb341fd 100644 (file)
@@ -406,6 +406,7 @@ function geoloc_getData_subcities($mapid, $SFields, &$cities, $direct=true)
                                           $mapid);
     $fields = new SFieldGroup(true, $SFields);
     $where = $fields->get_where_statement();
+    $joins = $fields->get_select_statement();
     if ($where) {
         $where .= ' AND ';
     }
@@ -414,7 +415,7 @@ function geoloc_getData_subcities($mapid, $SFields, &$cities, $direct=true)
                           gc.name,
                           COUNT(u.user_id) AS pop,
                           SUM(u.promo % 2) AS yellow',
-                          "{$fields->get_select_statement()}
+                          "$joins
                           LEFT JOIN  geoloc_city  AS gc ON(gcim.city_id = gc.id)",
                           $where . ($direct ? "gcim.infos = 'smallest'" : '1'),
                           'gc.id, gc.alias',
@@ -483,14 +484,16 @@ function geoloc_getData_subcountries($mapid, $sin, $minentities)
                                           'am.cityid = gcim.city_id', 
                                           'map.map_id = gcim.map_id'));
     $fields = new SFieldGroup(true, $SFields);
+    $where  = $fields->get_where_statement();
+    $joins  = $fields->get_select_statement();
     $countryres = $set->get('map.map_id AS id,
                              COUNT(u.user_id) AS nbPop,
                              SUM(u.promo % 2) AS yellow,
                              COUNT(DISTINCT gcim.city_id) AS nbCities,
                              SUM(IF(u.user_id IS NULL,0,am.glng)) AS lonPop,
                              SUM(IF(u.user_id IS NULL, 0,am.glat)) AS latPop',
-                            $fields->get_select_statement(),
-                            $fields->get_where_statement(),
+                            $joins,
+                            $where,
                             'map.map_id',
                             'NULL');
     
@@ -503,7 +506,7 @@ function geoloc_getData_subcountries($mapid, $sin, $minentities)
         if ($maxpop < $c['nbPop']) $maxpop = $c['nbPop'];
         $c['xPop'] = geoloc_to_x($c['lonPop'], $c['latPop']);
         $c['yPop'] = geoloc_to_y($c['lonPop'], $c['latPop']);
-        $countries[$c['id']] = array_merge($countries[$c['id']], $c);
+        @$countries[$c['id']] = array_merge($countries[$c['id']], $c);
     
         $nbcities += $c['nbCities'];
     } 
@@ -511,7 +514,7 @@ function geoloc_getData_subcountries($mapid, $sin, $minentities)
     if ($nocity && $nbcities < $minentities){
         foreach($countries as $i => $c) {
             $countries[$i]['nbPop'] = 0;
-            if ($c['nbCities'] > 0) {
+            if (@$c['nbCities'] > 0) {
                 geoloc_getData_subcities($c['id'], $sin, $cities, false);
             }   
         }
index 48d5878..a76b7c1 100644 (file)
@@ -57,6 +57,7 @@ class UserSet extends PlSet
 
 class SearchSet extends UserSet
 {
+    public  $advanced = false;
     private $score = null;
     private $order = null;
     private $quick = false;
@@ -90,8 +91,7 @@ class SearchSet extends UserSet
             new ThrowError('Recherche trop générale.');
         }
         $this->score = $qSearch->get_score_statement();
-        parent::__construct("{$fields->get_select_statement()}
-                             {$globals->search->result_where_statement}",
+        parent::__construct("{$fields->get_select_statement()}",
                             $fields->get_where_statement() .
                             (S::logged() && Env::has('nonins') ? ' AND u.perms="pending" AND u.deces=0' : ''));
 
@@ -102,11 +102,12 @@ class SearchSet extends UserSet
     private function getAdvanced()
     {
         global $globals;
+        $this->advanced = true;
         $fields = new SFieldGroup(true, advancedSearchFromInput());
         if ($fields->too_large()) {
             new ThrowError('Recherche trop générale.');
         }
-        parent::__construct($fields->get_select_statement() . ' ' . $globals->search->result_where_statement,
+        parent::__construct($fields->get_select_statement(),
                             $fields->get_where_statement());
         $this->order = implode(',',array_filter(array($fields->get_order_statement(),
                                                       'promo DESC, NomSortKey, prenom')));
@@ -179,8 +180,7 @@ class MinificheView extends MultipageView
 
     public function joins()
     {
-        return  ($this->set instanceof SearchSet ? "" :
-                "LEFT JOIN  entreprises    AS e   ON (e.entrid = 0 AND e.uid = u.user_id)
+        return  "LEFT JOIN  entreprises    AS e   ON (e.entrid = 0 AND e.uid = u.user_id)
                  LEFT JOIN  emploi_secteur AS es  ON (e.secteur = es.id)
                  LEFT JOIN  fonctions_def  AS ef  ON (e.fonction = ef.id)
                  LEFT JOIN  geoloc_pays    AS n   ON (u.nationalite = n.a2)
@@ -192,10 +192,10 @@ class MinificheView extends MultipageView
                                                       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  emails         AS em  ON (em.uid = u.user_id AND em.flags = 'active')
-                ") . (S::logged() ? 
-                        "LEFT JOIN  contacts       AS c   On (c.contact = u.user_id AND c.uid = " . S::v('uid') . ")"
-                        : ""); 
+                 LEFT JOIN  emails         AS em  ON (em.uid = u.user_id AND em.flags = 'active')" .
+                (S::logged() ? 
+                 "LEFT JOIN  contacts       AS c   On (c.contact = u.user_id AND c.uid = " . S::v('uid') . ")"
+                 : "");
     }
 
     public function templateName()
index ea8491a..5a64865 100644 (file)
@@ -135,7 +135,7 @@ class SearchModule extends PLModule
             $view->addMod('minifiche', 'Minifiches', true);
             $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true));
             $view->addMod('geoloc', 'Planishpère');
-            $view->apply('search', $page, $action, $subaction);
+            $view->apply('search/adv', $page, $action, $subaction);
             
             if ($subaction) {
                 return;
index eae0a04..d3edb4d 100644 (file)
@@ -46,7 +46,6 @@ function advancedSearchFromInput()
     $cityIdField    = new RefSField('cityid',array('av.cityid'),'adresses','av',getadr_join('av'));
     $countryField   = new RefSField('country',array('ap.country'),'adresses','ap',getadr_join('ap'));
     $regionField    = new RefSField('region',array('ar.region'),'adresses','ar',getadr_join('ar'));
-    $mapField       = new MapSField('mapid', array('gcim.map_id'), array('adresses','geoloc_city_in_maps'), array('am','gcim'), array(getadr_join('am'), 'am.cityid = gcim.city_id'));
    
     $entrepriseField = new RefSField('entreprise',array('ee.entreprise'),'entreprises','ee','u.user_id=ee.uid',false);
     $posteField      = new RefSField('poste',array('ep.poste'),'entreprises','ep','u.user_id=ep.uid', false);
@@ -69,7 +68,7 @@ function advancedSearchFromInput()
                 $townField, $countryField, $regionField, $entrepriseField,
                 $posteField, $secteurField, $cvField, $natField, $binetField,
                 $groupexField, $sectionField, $schoolField, $diplomaField,
-                $freeField, $fonctionField, $cityIdField, $mapField);
+                $freeField, $fonctionField, $cityIdField);
 }
 
 // }}}
index b47a3dc..f412da6 100644 (file)
 <script type="text/javascript">// <!-- 
         var baseurl = "{#globals.baseurl#}/search/";
         {literal}
-        
-        // use same form to send to search or map
-        function launch_form(url) {
-          var f = document.getElementById('recherche');
-          f.action = url;
-          f.submit();
-        }
-        
         // display an autocomplete row : blabla (nb of found matches)
         function format_autocomplete(row) {
           if (row[1] == 1) {
@@ -364,7 +356,7 @@ checked="checked"{/if}/>chercher uniquement les adresses où les camarades sont
     <tr>
       <td colspan="2" style="padding-top: 1.5em">
         <div style="float: right">
-          <input type="button" value="Chercher" onclick="launch_form('search/adv')"/>
+          <input type="button" value="Chercher" />
         </div>
         {if $smarty.session.auth ge AUTH_COOKIE}
           <input type='checkbox' name='order' value='date_mod' {if $smarty.request.order eq "date_mod"}checked='checked'{/if} id="order"/>
@@ -374,9 +366,6 @@ checked="checked"{/if}/>chercher uniquement les adresses où les camarades sont
     </tr>
   </table>
 </form>
-<p class="center">
-  <input type="button" value="Voir les résultats sur une carte" onclick="launch_form('geoloc/')"/>
-</p>
 <p>
   <strong>N.B.</strong> Le caractère joker * peut remplacer une ou plusieurs lettres dans les recherches.
 </p>
index 6a086bd..3b238c5 100644 (file)
 <ul class="noprint">
   {if $with_soundex && ($smarty.request.firstname || $smarty.request.name)}
   <li>Étendre ta recherche par <strong>
-    <a  href="{$with_soundex}">proximité sonore</a>
+    <a  href="search/adv{$plset_search}with_soundex=1">proximité sonore</a>
   </strong>
   </li>
   {/if}
 
-  <li><strong><a href="{$url_search_form}">Modifier</a>
+  <li><strong><a href="search/adv{$plset_search|regex_replace:"/rechercher=[^&]*/":""}">Modifier</a>
   </strong> ta recherche
   </li>