From 21639c67d105c13ef355dc51bd31be89ced5a7b2 Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Sat, 11 Jun 2005 14:02:51 +0000 Subject: [PATCH] ajout des cityid et de la table geoloc_city git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-699 --- include/geoloc.inc.php | 25 +++++++++++++++++++++++++ include/profil/get_adresses.inc.php | 6 ++++-- include/profil/update_adresses.inc.php | 4 ++++ include/profil/verif_adresses.inc.php | 10 ++++++++++ templates/geoloc/form.address.tpl | 29 ++++++++++------------------- templates/profil/adresses.tpl | 4 ++-- upgrade/0.9.7/01_geoloc.sql | 28 ++++++++++++++++++++++++++++ 7 files changed, 83 insertions(+), 23 deletions(-) diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index ca9f369..69b5dbe 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -67,6 +67,8 @@ function _geoloc_region_smarty($params){ $page->register_function('geoloc_region', '_geoloc_region_smarty'); // }}} +// retrieve the infos on a text address +// store on the fly the info of the city concerned function get_address_infos($txt) { $url ="http://www.geoloc.org/adressparser/address.php?txt=".urlencode(utf8_encode($txt)); if (!($f = @fopen($url, 'r'))) return false; @@ -75,7 +77,30 @@ function get_address_infos($txt) { $vals = explode('|',fgets($f)); $infos = array(); foreach ($keys as $i=>$key) if($vals[$i]) $infos[$key] = $vals[$i]; + global $globals; + if ($infos['sql']) + $globals->xdb->execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']); return $infos; } + +// make the text of an address that can be read by a mailman +function get_address_text($adr) { + $t = ""; + if ($adr['adr1']) $t.= $adr['adr1']; + if ($adr['adr2']) $t.= "\n".$adr['adr2']; + if ($adr['adr3']) $t.= "\n".$adr['adr3']; + $l = ""; + if ($adr['country'] == 'US' || $adr['country'] == 'CA') { + if ($adr['city']) $l .= $adr['city'].",\n"; + if ($adr['region']) $l .= $adr['region']." "; + if ($adr['postcode']) $l .= $adr['postcode']; + } else { + if ($adr['postcode']) $l .= $adr['postcode']." "; + if ($adr['city']) $l .= $adr['city']; + } + if ($l) $t .= "\n".trim($l); + if ($adr['pays']) $t .= "\n".$adr['pays']; + return trim($t); +} // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?> diff --git a/include/profil/get_adresses.inc.php b/include/profil/get_adresses.inc.php index 11ea2b2..bef7e07 100644 --- a/include/profil/get_adresses.inc.php +++ b/include/profil/get_adresses.inc.php @@ -66,7 +66,7 @@ $res = $globals->xdb->iterRow( "SELECT FIND_IN_SET('res-secondaire', statut), FIND_IN_SET('courrier', statut), FIND_IN_SET('active', statut), FIND_IN_SET('temporaire', statut), - adr1, adr2, adr3, postcode, city, + adr1, adr2, adr3, postcode, city, cityid, a.country, region, tel, fax, pub, tel_pub, gp.pays FROM adresses AS a INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country) @@ -82,12 +82,14 @@ for ($i = 0; $i < $nb_adr; $i++) { list( $adresses[$adrid]['secondaire'], $adresses[$adrid]['courrier'], $adresses[$adrid]['active'], $adresses[$adrid]['temporaire'], - $adresses[$adrid]['adr1'], $adresses[$adrid]['adr2'], $adresses[$adrid]['adr3'], $adresses[$adrid]['postcode'], $adresses[$adrid]['city'], + $adresses[$adrid]['adr1'], $adresses[$adrid]['adr2'], $adresses[$adrid]['adr3'], $adresses[$adrid]['postcode'], $adresses[$adrid]['city'], $adresses[$adrid]['cityid'], $adresses[$adrid]['country'], $adresses[$adrid]['region'], $adresses[$adrid]['tel'], $adresses[$adrid]['fax'], $adresses[$adrid]['pub'], $adresses[$adrid]['tel_pub'],$adresses[$adrid]['pays']) = $res->next(); $adresses[$adrid]['nouvelle'] = 'modif'; $adresses[$adrid]['numero_formulaire'] = -1; + require_once('geoloc.inc.php'); + $adresses[$adrid]['txt'] = get_address_text($adresses[$adrid]); } ?> diff --git a/include/profil/update_adresses.inc.php b/include/profil/update_adresses.inc.php index 7fff069..cf4a150 100644 --- a/include/profil/update_adresses.inc.php +++ b/include/profil/update_adresses.inc.php @@ -42,6 +42,7 @@ foreach($adresses as $adrid => $adr){ adr3 = {?}, postcode = {?}, city = {?}, + cityid = {?}, country = {?}, region = {?}, tel = {?}, @@ -56,6 +57,7 @@ foreach($adresses as $adrid => $adr){ $adr['adr3'], $adr['postcode'], $adr['city'], + $adr['cityid'], $adr['country'], $adr['region'], $adr['tel'], @@ -75,6 +77,7 @@ foreach($adresses as $adrid => $adr){ adr3 = {?}, postcode = {?}, city = {?}, + cityid = {?}, country = {?}, region = {?}, tel = {?}, @@ -89,6 +92,7 @@ foreach($adresses as $adrid => $adr){ $adr['adr3'], $adr['postcode'], $adr['city'], + $adr['cityid'], $adr['country'], $adr['region'], $adr['tel'], diff --git a/include/profil/verif_adresses.inc.php b/include/profil/verif_adresses.inc.php index d1db690..39d9121 100644 --- a/include/profil/verif_adresses.inc.php +++ b/include/profil/verif_adresses.inc.php @@ -77,6 +77,7 @@ function replace_address($i){ replace_ifset_adr('adr3', $i); replace_ifset_adr('postcode', $i); replace_ifset_adr('city', $i); + replace_ifset_adr('cityid', $i); replace_ifset_adr('country', $i); replace_ifset_adr('region', $i); replace_ifset_adr('tel', $i); @@ -87,7 +88,16 @@ function replace_address($i){ if ($GLOBALS['adresses'][$i]['txt'] && !Env::get('nochange'.$i, true)) { require_once('geoloc.inc.php'); $new = get_address_infos($GLOBALS['adresses'][$i]['txt']); + $GLOBALS['adresses'][$i]['adr1'] = ''; + $GLOBALS['adresses'][$i]['adr2'] = ''; + $GLOBALS['adresses'][$i]['adr3'] = ''; + $GLOBALS['adresses'][$i]['postcode'] = ''; + $GLOBALS['adresses'][$i]['city'] = ''; + unset($GLOBALS['adresses'][$i]['cityid']); + $GLOBALS['adresses'][$i]['country'] = '00'; + $GLOBALS['adresses'][$i]['region'] = ''; $GLOBALS['adresses'][$i] = array_merge($GLOBALS['adresses'][$i], $new); + $GLOBALS['adresses'][$i]['txt'] = get_address_text($GLOBALS['adresses'][$i]); } $tab = Env::getMixed('numero_formulaire', Array()); if($tab[$i]) diff --git a/templates/geoloc/form.address.tpl b/templates/geoloc/form.address.tpl index dfc6377..30aa57f 100644 --- a/templates/geoloc/form.address.tpl +++ b/templates/geoloc/form.address.tpl @@ -1,11 +1,15 @@ - + {$titre} -
{if $adr.nouvelle != 'new' && !$smarty.request.detail[$adrid]} - [corriger] +
+ [corriger] {/if} + {if $adr.nouvelle != 'new' && !$adr.cityid} +
+ non géolocalisée + {/if} {if $smarty.request.detail[$adrid] neq 1} @@ -15,25 +19,12 @@ + - + {else} + diff --git a/templates/profil/adresses.tpl b/templates/profil/adresses.tpl index b6c220d..a51aa25 100644 --- a/templates/profil/adresses.tpl +++ b/templates/profil/adresses.tpl @@ -50,7 +50,7 @@ {if $adr.nouvelle != 'new'} - + {/if}   @@ -68,7 +68,7 @@ {include file="geoloc/form.address.tpl" adr=$adr titre=$titre url="`$smarty.server.PHP_SELF`?old_tab=`$smarty.request.old_tab`"} - Cette adresse est : + Cette adresse est : diff --git a/upgrade/0.9.7/01_geoloc.sql b/upgrade/0.9.7/01_geoloc.sql index 039e545..c1bae49 100644 --- a/upgrade/0.9.7/01_geoloc.sql +++ b/upgrade/0.9.7/01_geoloc.sql @@ -7,3 +7,31 @@ CHANGE ville city VARCHAR(80) DEFAULT '' NOT NULL, CHANGE cp postcode VARCHAR(20) DEFAULT '' NOT NULL, CHANGE pays country VARCHAR(2) DEFAULT '00' NOT NULL; +ALTER TABLE adresses ADD cityid INT DEFAULT NULL AFTER city; + +ALTER TABLE adresses ADD INDEX(cityid); + +CREATE TABLE `geoloc_city` ( + `id` int(11) NOT NULL default '0', + `alias` smallint(6) NOT NULL default '0', + `name` varchar(200) NOT NULL default '', + `search_name` varchar(200) NOT NULL default '', + `prefix` varchar(30) NOT NULL default '', + `lat` int(11) NOT NULL default '0', + `lon` int(11) NOT NULL default '0', + `country` char(2) NOT NULL default '', + `region` char(2) NOT NULL default '', + `subregion` varchar(200) NOT NULL default '', + `postcode` varchar(8) NOT NULL default '', + `level` tinyint(4) NOT NULL default '5', + `population` int(11) NOT NULL default '0', + `x` float NOT NULL default '0', + `y` float NOT NULL default '0', + `z` float NOT NULL default '0', + PRIMARY KEY (`id`,`alias`), + KEY `famous` (`level`,`search_name`), + KEY `name` (`country`,`search_name`), + KEY `postcode` (`country`,`postcode`), + KEY `lat` (`lat`), + KEY `lon` (`lon`) +); -- 2.1.4