From 151830af0016d0b18435a13236aff0abf542ac10 Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Sat, 11 Jun 2005 10:31:59 +0000 Subject: [PATCH] using address parser on geoloc.org git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-697 --- include/geoloc.inc.php | 13 +++++ include/profil/get_adresses.inc.php | 7 +-- include/profil/update_adresses.inc.php | 1 - include/profil/verif_adresses.inc.php | 6 +++ templates/geoloc/form.address.tpl | 87 ++++++++++++++++++++++++++++++++++ templates/profil/adresses.tpl | 63 +++--------------------- 6 files changed, 117 insertions(+), 60 deletions(-) create mode 100644 templates/geoloc/form.address.tpl diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index 8b77bd5..ca9f369 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -20,6 +20,7 @@ ***************************************************************************/ +// {{{ liste les pays ou les régions d'un pays /** donne la liste déroulante des pays * @param $current pays actuellement selectionné */ @@ -64,5 +65,17 @@ function _geoloc_region_smarty($params){ return geoloc_region($params['pays'], $params['region']); } $page->register_function('geoloc_region', '_geoloc_region_smarty'); +// }}} +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; + fgets($f); + $keys = explode('|',fgets($f)); + $vals = explode('|',fgets($f)); + $infos = array(); + foreach ($keys as $i=>$key) if($vals[$i]) $infos[$key] = $vals[$i]; + return $infos; +} +// 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 0e903e1..11ea2b2 100644 --- a/include/profil/get_adresses.inc.php +++ b/include/profil/get_adresses.inc.php @@ -67,8 +67,9 @@ $res = $globals->xdb->iterRow( 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, - country, region, tel, fax, pub, tel_pub - FROM adresses + 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) WHERE uid = {?} AND NOT FIND_IN_SET('pro',statut) ".$sql_order , Session::getInt('uid', -1) ); @@ -84,7 +85,7 @@ for ($i = 0; $i < $nb_adr; $i++) { $adresses[$adrid]['adr1'], $adresses[$adrid]['adr2'], $adresses[$adrid]['adr3'], $adresses[$adrid]['postcode'], $adresses[$adrid]['city'], $adresses[$adrid]['country'], $adresses[$adrid]['region'], $adresses[$adrid]['tel'], $adresses[$adrid]['fax'], $adresses[$adrid]['pub'], - $adresses[$adrid]['tel_pub'],) = $res->next(); + $adresses[$adrid]['tel_pub'],$adresses[$adrid]['pays']) = $res->next(); $adresses[$adrid]['nouvelle'] = 'modif'; $adresses[$adrid]['numero_formulaire'] = -1; } diff --git a/include/profil/update_adresses.inc.php b/include/profil/update_adresses.inc.php index 9ca73b5..7fff069 100644 --- a/include/profil/update_adresses.inc.php +++ b/include/profil/update_adresses.inc.php @@ -34,7 +34,6 @@ foreach($adresses as $adrid => $adr){ if ($adr["temporaire"]) $statut .= 'temporaire,'; if (! empty($statut)) $statut = substr($statut, 0, -1); - if ($adr["nouvelle"] == 'ajout') { //nouvelle adresse $globals->xdb->execute("INSERT INTO adresses SET diff --git a/include/profil/verif_adresses.inc.php b/include/profil/verif_adresses.inc.php index 17b2f7a..d1db690 100644 --- a/include/profil/verif_adresses.inc.php +++ b/include/profil/verif_adresses.inc.php @@ -83,6 +83,12 @@ function replace_address($i){ replace_ifset_adr('fax', $i); replace_ifset_adr('pub', $i); replace_ifset_adr('tel_pub', $i); + replace_ifset_adr('txt', $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] = array_merge($GLOBALS['adresses'][$i], $new); + } $tab = Env::getMixed('numero_formulaire', Array()); if($tab[$i]) $GLOBALS['adresses'][$i]['numero_formulaire'] = $tab[$i]; diff --git a/templates/geoloc/form.address.tpl b/templates/geoloc/form.address.tpl new file mode 100644 index 0000000..4d245bc --- /dev/null +++ b/templates/geoloc/form.address.tpl @@ -0,0 +1,87 @@ + + + + {$titre} +
+ {if $adr.nouvelle != 'new' && !$smarty.request.detail[$adrid]} + [
corriger] + {/if} + + + {if $smarty.request.detail[$adrid] neq 1} + + + + + + + + + + {else} + + + + + +   + + + + + + + +   + + + + + + + + Code postal / Ville
+ + + +   + + + + + + Pays + + + + + + + + Région ou département
+ (selon pays) + + + + {/if} + + diff --git a/templates/profil/adresses.tpl b/templates/profil/adresses.tpl index abe777b..01d5fa3 100644 --- a/templates/profil/adresses.tpl +++ b/templates/profil/adresses.tpl @@ -50,7 +50,7 @@ {if $adr.nouvelle != 'new'} - + {/if}   @@ -88,61 +88,12 @@ - - - {if $adr.nouvelle != 'new'}Adresse n°{$smarty.section.i.index}{else}Nouvelle adresse{/if}
- - - - - - - -   - - - - - - - -   - - - - - - - - Code postal / Ville
- - - -   - - - - - - Pays - - - - - - - - Région ou département
- (selon pays) - - - - - + {if $adr.nouvelle != 'new'} + {assign var="titre" value="Adresse n°`$smarty.section.i.index` :"} + {else} + {assign var="titre" value="Nouvelle adresse :"} + {/if} + {include file="geoloc/form.address.tpl" adr=$adr titre=$titre url="`$smarty.server.PHP_SELF`?old_tab=`$smarty.request.old_tab`"} Cette adresse est : -- 2.1.4