Should avoid addresses with (0.0000,0.0000) coordinates
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 7 Oct 2007 08:32:38 +0000 (10:32 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 7 Oct 2007 08:32:38 +0000 (10:32 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
include/geoloc.inc.php
modules/geoloc.php
modules/profile/addresses.inc.php
modules/profile/jobs.inc.php
modules/profile/page.inc.php
templates/geoloc/form.address.tpl
upgrade/0.9.15/02_entreprises.sql

index df3214a..3069c8c 100644 (file)
@@ -94,11 +94,25 @@ function get_address_infos($txt)
         }
     }
     if (isset($infos['sql']) && $infos['sql'])
-       XDB::execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']);
+       XDB::execute("REPLACE INTO  geoloc_city
+                           VALUES  ".$infos['sql']);
     if (isset($infos['display']) && $infos['display'])
-        XDB::execute("UPDATE geoloc_pays SET display = {?} WHERE a2 = {?}", $infos['display'], $infos['country']);
-    if (isset($infos['cityid']))
+        XDB::execute("UPDATE  geoloc_pays
+                         SET  display = {?}
+                       WHERE  a2 = {?}", $infos['display'], $infos['country']);
+    if (isset($infos['cityid'])) {
         fix_cities_not_on_map(1, $infos['cityid']);
+        if (floatval($infos['precise_lat']) && floatval($infos['precise_lon'])) {
+            $res = XDB::query("SELECT  c.lat / 100000, c.lon / 100000
+                                 FROM  geoloc_city AS c
+                                WHERE  c.id = {?}", $infos['cityid']);
+            if ($res->numRows()) {
+                list($glat, $glng) = $res->fetchOneRow();
+                $infos['precise_lat'] = $glat;
+                $infos['precise_lon'] = $glng;
+            }
+        }
+    }
     return $infos;
 }
 // }}}
@@ -225,7 +239,9 @@ function empty_address() {
         "region" => "",
         "regiontxt" => "",
         "country" => "00",
-        "countrytxt" => "");
+        "countrytxt" => "",
+        "precise_lat" => "",
+        "precise_lon" => "");
 }
 
 // create a simple address from a text without geoloc
index d9d7358..b085d4f 100644 (file)
@@ -79,7 +79,9 @@ class GeolocModule extends PLModule
         }
 
         if ($action == 'precise_coordinates') {
-            XDB::execute("UPDATE adresses AS a INNER JOIN geoloc_city AS c ON(a.cityid = c.id) SET a.glat = c.lat / 100000, a.glng = c.lon / 100000");
+            XDB::execute("UPDATE  adresses AS a
+                      INNER JOIN  geoloc_city AS c ON(a.cityid = c.id)
+                             SET  a.glat = c.lat / 100000, a.glng = c.lon / 100000");
         }
 
         if ($action == 'newmaps') {
index 9c4aec9..0717bb6 100644 (file)
@@ -134,17 +134,17 @@ class ProfileAddress extends ProfileGeoloc
                                               postcode, city, cityid,
                                               country, region, regiontxt,
                                               pub, datemaj, statut,
-                                              uid, adrid)
+                                              uid, adrid, glat, glng)
                            VALUES  ({?}, {?}, {?},
                                     {?}, {?}, {?},
                                     {?}, {?}, {?},
                                     {?}, FROM_UNIXTIME({?}), {?},
-                                    {?}, {?})",
+                                    {?}, {?}, {?}, {?})",
                      $address['adr1'], $address['adr2'], $address['adr3'],
                      $address['postcode'], $address['city'], $address['cityid'],
                      $address['country'], $address['region'], $address['regiontxt'],
                      $address['pub'], $address['datemaj'], $flags,
-                     S::i('uid'), $adrid);
+                     S::i('uid'), $adrid, $address['precise_lat'], $address['precise_lon']);
         foreach ($address['tel'] as $telid=>&$tel) {
             $this->saveTel($adrid, $telid, $tel);
         }
@@ -185,7 +185,8 @@ class ProfileAddresses extends ProfilePage
                                    FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
                                    FIND_IN_SET('courrier', a.statut) AS mail,
                                    FIND_IN_SET('temporaire', a.statut) AS temporary,
-                                   FIND_IN_SET('active', a.statut) AS current
+                                   FIND_IN_SET('active', a.statut) AS current,
+                                   a.glat AS precise_lat, a.glng AS precise_lon
                              FROM  adresses AS a
                        INNER JOIN  geoloc_pays AS gp ON(gp.a2 = a.country)
                             WHERE  uid = {?} AND NOT FIND_IN_SET('pro', statut)
index 64b96b6..1777498 100644 (file)
@@ -100,12 +100,14 @@ class ProfileJob extends ProfileGeoloc
                                                     fonction, poste, adr1, adr2, adr3, postcode,
                                                     city, cityid, country, region, regiontxt,
                                                     tel, fax, mobile, email, web,
-                                                    pub, adr_pub, tel_pub, email_pub, flags)
+                                                    pub, adr_pub, tel_pub, email_pub, flags,
+                                                    glat, glng)
                                VALUES  ({?}, {?}, {?}, {?}, {?},
                                         {?}, {?}, {?}, {?}, {?}, {?},
                                         {?}, {?}, {?}, {?}, {?},
                                         {?}, {?}, {?}, {?}, {?},
-                                        {?}, {?}, {?}, {?}, {?})",
+                                        {?}, {?}, {?}, {?}, {?},
+                                        {?}, {?})",
                          S::i('uid'), $i++, $job['name'], $job['secteur'], $job['ss_secteur'],
                          $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'],
                          $job['adr']['postcode'],
@@ -113,7 +115,8 @@ class ProfileJob extends ProfileGeoloc
                          $job['adr']['regiontxt'],
                          $job['tel'], $job['fax'], $job['mobile'], $job['email'], $job['web'],
                          $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub'],
-                         $job['adr']['checked'] ? 'geoloc' : '');
+                         $job['adr']['checked'] ? 'geoloc' : '', $job['adr']['precise_lat'],
+                         $job['adr']['precise_lon']);
         }
     }
 }
@@ -145,7 +148,8 @@ class ProfileJobs extends ProfilePage
                                      e.country, gp.pays, gp.display,
                                      FIND_IN_SET('geoloc', flags),
                                      e.tel, e.fax, e.mobile, e.email, e.web, e.pub,
-                                     e.adr_pub, e.tel_pub, e.email_pub
+                                     e.adr_pub, e.tel_pub, e.email_pub,
+                                     e.glat AS precise_lat, e.glng AS precise_lon
                                FROM  entreprises AS e
                          INNER JOIN  geoloc_pays AS gp ON(gp.a2 = e.country)
                               WHERE  uid = {?} AND entreprise != ''
@@ -155,7 +159,7 @@ class ProfileJobs extends ProfilePage
                     $adr1, $adr2, $adr3, $postcode, $city, $cityid,
                     $region, $regiontxt, $country, $countrytxt, $display,
                     $checked, $tel, $fax, $mobile, $email, $web,
-                    $pub, $adr_pub, $tel_pub, $email_pub) = $res->next()) {
+                    $pub, $adr_pub, $tel_pub, $email_pub, $glat, $glng) = $res->next()) {
             $this->values['jobs'][] = array('name'       => $name,
                                             'secteur'    => $secteur,
                                             'ss_secteur' => $ss_secteur,
@@ -173,7 +177,9 @@ class ProfileJobs extends ProfilePage
                                                                   'countrytxt' => $countrytxt,
                                                                   'display'    => $display,
                                                                   'pub'        => $adr_pub,
-                                                                  'checked'    => $checked),
+                                                                  'checked'    => $checked,
+                                                                  'precise_lat'=> $glat,
+                                                                  'precise_lon'=> $glng),
                                             'tel'        => $tel,
                                             'fax'        => $fax,
                                             'mobile'     => $mobile,
index 74b3560..96344b8 100644 (file)
@@ -187,6 +187,8 @@ abstract class ProfileGeoloc implements ProfileSetting
                 $address['checked'] = true;
             }
         }
+        $address['precise_lat'] = rtrim($address['precise_lat'], '.0');
+        $address['precise_lon'] = rtrim($address['precise_lon'], '.0'); 
         $address['text'] = get_address_text($address);
     }
 }
index 8ad46c7..666f779 100644 (file)
@@ -61,4 +61,6 @@
 <input type="hidden" name="{$name}[region]" value="{$adr.region}" />
 <input type="hidden" name="{$name}[regiontxt]" value="{$adr.regiontxt}" />
 <input type="hidden" name="{$name}[checked]" value="{$adr.checked}" />
+<input type="hidden" name="{$name}[precise_lat]" value="{$adr.precise_lat}" />
+<input type="hidden" name="{$name}[precise_lon]" value="{$adr.precise_lon}" />
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 79cd796..d4abbb4 100644 (file)
@@ -1,6 +1,8 @@
 alter table entreprises add column cityid int(11) default null after city;
 alter table entreprises add column regiontxt varchar(80) not null after region;
 alter table entreprises add column flags set('geoloc') not null;
+alter table entreprises add column glat float(9,6) not null default 0;
+alter table entreprises add column glng float(9,6) not null default 0;
 alter table entreprises add key cityid (cityid);
 alter table entreprises add key country (country);
 alter table entreprises add key region (region);