From de0485fd001e8ed3f8649016d22332a9f01ad269 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 7 Oct 2007 10:32:38 +0200 Subject: [PATCH] Should avoid addresses with (0.0000,0.0000) coordinates Signed-off-by: Florent Bruneau --- include/geoloc.inc.php | 24 ++++++++++++++++++++---- modules/geoloc.php | 4 +++- modules/profile/addresses.inc.php | 9 +++++---- modules/profile/jobs.inc.php | 18 ++++++++++++------ modules/profile/page.inc.php | 2 ++ templates/geoloc/form.address.tpl | 2 ++ upgrade/0.9.15/02_entreprises.sql | 2 ++ 7 files changed, 46 insertions(+), 15 deletions(-) diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index df3214a..3069c8c 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -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 diff --git a/modules/geoloc.php b/modules/geoloc.php index d9d7358..b085d4f 100644 --- a/modules/geoloc.php +++ b/modules/geoloc.php @@ -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') { diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index 9c4aec9..0717bb6 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -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) diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index 64b96b6..1777498 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -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, diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 74b3560..96344b8 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -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); } } diff --git a/templates/geoloc/form.address.tpl b/templates/geoloc/form.address.tpl index 8ad46c7..666f779 100644 --- a/templates/geoloc/form.address.tpl +++ b/templates/geoloc/form.address.tpl @@ -61,4 +61,6 @@ + + {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/upgrade/0.9.15/02_entreprises.sql b/upgrade/0.9.15/02_entreprises.sql index 79cd796..d4abbb4 100644 --- a/upgrade/0.9.15/02_entreprises.sql +++ b/upgrade/0.9.15/02_entreprises.sql @@ -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); -- 2.1.4