ajout des cityid et de la table geoloc_city
authorPascal Corpet <pascal.corpet@m4x.org>
Sat, 11 Jun 2005 14:02:51 +0000 (14:02 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:29:12 +0000 (23:29 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-699

include/geoloc.inc.php
include/profil/get_adresses.inc.php
include/profil/update_adresses.inc.php
include/profil/verif_adresses.inc.php
templates/geoloc/form.address.tpl
templates/profil/adresses.tpl
upgrade/0.9.7/01_geoloc.sql

index ca9f369..69b5dbe 100644 (file)
@@ -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:
 ?>
index 11ea2b2..bef7e07 100644 (file)
@@ -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]);
 }
 
 ?>
index 7fff069..cf4a150 100644 (file)
@@ -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'],
index d1db690..39d9121 100644 (file)
@@ -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])
index dfc6377..30aa57f 100644 (file)
@@ -1,11 +1,15 @@
     <tr>
       <td class="colg">
-        <a name="jump_adr{$adrid}" />
+        <a name="jump_adr{$adrid}"></a>
         <span class="titre">{$titre}</span>
-       <br />
         {if $adr.nouvelle != 'new' && !$smarty.request.detail[$adrid]}
-          [<a href="{$url}&detail%5B{$adrid}%5D=1#jump_adr{$adrid}">corriger</a>]
+       <br />
+          [<a href="{$url}&amp;detail[{$adrid}]=1#jump_adr{$adrid}">corriger</a>]
         {/if}
+       {if $adr.nouvelle != 'new' && !$adr.cityid}
+       <br />
+       <span class="erreur">non géolocalisée</span>
+       {/if}
       </td>
       <td class="cold">
         {if $smarty.request.detail[$adrid] neq 1}
         <input type="hidden" name="adr3[{$adrid}]" value="{$adr.adr3}" />
         <input type="hidden" name="postcode[{$adrid}]" value="{$adr.postcode}"/>
         <input type="hidden" name="city[{$adrid}]" value="{$adr.city}" />
+        <input type="hidden" name="cityid[{$adrid}]" value="{$adr.cityid}" />
         <input type="hidden" name="region[{$adrid}]" value="{$adr.region}" />
         <input type="hidden" name="country[{$adrid}]" value="{$adr.country}" />
-        <textarea name="txt[{$adrid}]" cols="43" rows="3" onclick="form.nochange{$adrid}.value=0;select()">
-{if $adr.adr1}{$adr.adr1}
-{/if}
-{if $adr.adr2}{$adr.adr2}
-{/if}
-{if $adr.adr3}{$adr.adr3}
-{/if}
-{if $adr.postcode || $adr.city}
-{if $adr.country eq 'US' || $adr.country eq 'CA'}
-{assign var='tmp' value="%v,\r\n%r %p"}
-{else}
-{assign var='tmp' value="%p %v"}
-{/if}
-{$tmp|replace:"%p":$adr.postcode|replace:"%v":$adr.city|replace:"%r":$adr.region}
-{/if}
-{if $adr.pays}{$adr.pays}{/if}</textarea>
+        <textarea name="txt[{$adrid}]" cols="43" rows="3" onclick="form.nochange{$adrid}.value=0;select()">{$adr.txt}</textarea>
       {else}
+        <input type="hidden" name="cityid[{$adrid}]" value="{$adr.cityid}" />
         <input type="text" name="adr1[{$adrid}]" size="43" maxlength="88" value="{$adr.adr1}" />
       </td>
     </tr>
index b6c220d..a51aa25 100644 (file)
@@ -50,7 +50,7 @@
     <tr>
       <td class="left">
         {if $adr.nouvelle != 'new'}
-        <a href="{$smarty.server.PHP_SELF}?old_tab={$smarty.request.old_tab}&adrid_del%5B{$adrid}%5D=1"><input type="button" value="La supprimer !" /></a>
+        <a href="{$smarty.server.PHP_SELF}?old_tab={$smarty.request.old_tab}&amp;adrid_del[{$adrid}]=1"><input type="button" value="La supprimer !" /></a>
         {/if}
         &nbsp;
       </td>
@@ -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`"}
     <tr>
       <td class="colg">
-        <span class="titre">Cette adresse est :</span>
+        <span class="titre">Cette adresse est&nbsp;:</span>
       </td>
       <td class="cold">
         <input type="radio" name="temporaire[{$adrid}]" value="0" {if !$adr.temporaire}checked="checked"{/if} />
index 039e545..c1bae49 100644 (file)
@@ -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`)
+);