geoloc interface
authorPascal Corpet <pascal.corpet@m4x.org>
Sun, 12 Jun 2005 22:11:12 +0000 (22:11 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:29:15 +0000 (23:29 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-707

htdocs/images/globe.png [new file with mode: 0644]
htdocs/login.php
include/geoloc.inc.php
include/profil/get_adresses.inc.php
include/profil/verif_adresses.inc.php
templates/geoloc/form.address.tpl
templates/login.tpl
templates/profil/adresses.tpl

diff --git a/htdocs/images/globe.png b/htdocs/images/globe.png
new file mode 100644 (file)
index 0000000..d762d93
Binary files /dev/null and b/htdocs/images/globe.png differ
index 2d0986e..3dd277e 100644 (file)
@@ -44,6 +44,11 @@ if (substr($naissance, 5) == date("m-d")) {
 $res = $globals->xdb->query('SELECT COUNT(*) FROM photo WHERE uid={?}', Session::getInt('uid'));
 $page->assign('photo_incitation', $res->fetchOneCell() == 0);
 
+// Incitation à se géolocaliser
+require_once('geoloc.inc.php');
+$res = localize_addresses(Session::getInt('uid', -1));
+$page->assign('geoloc_incitation', count($res));
+
 // affichage de la boîte avec quelques liens
 
 require_once('login.conf.php') ;
index 717436d..defe993 100644 (file)
@@ -99,7 +99,7 @@ function get_address_text($adr) {
         if ($adr['city']) $l .= $adr['city'];
     }
     if ($l) $t .= "\n".trim($l);
-    if ($adr['country'] != '00' && !$adr['countrytxt']) {
+    if ($adr['country'] != '00' && (!$adr['countrytxt'] || $adr['countrytxt'] == strtoupper($adr['countrytxt']))) {
         global $globals;
         $res = $globals->xdb->query("SELECT pays FROM geoloc_pays WHERE a2 = {?}", $adr['country']);
         $adr['countrytxt'] = $res->fetchOneCell();
@@ -107,5 +107,55 @@ function get_address_text($adr) {
     if ($adr['countrytxt']) $t .= "\n".$adr['countrytxt'];
     return trim($t);
 }
+
+// compares if two address matches
+// $b should be a complete valid address
+function compare_addresses($a, $b) {
+    if ($a['country'] != '00' && $b['country'] != $a['country']) return false;
+    if ($a['postcode'] && $a['postcode'] != $b['postcode']) return false;
+    if ($a['city'] && strtoupper($a['city']) != strtoupper($b['city'])) return false;
+    if (trim($a['adr1']) != trim($b['adr1'])) return false;
+    if (trim($a['adr2']) != trim($b['adr2'])) return false;
+    if (trim($a['adr3']) != trim($b['adr3']))return false;
+    return true;
+}
+
+function empty_address() {
+    return Array(
+        "adr1" => "",
+        "adr2" => "",
+        "adr3" => "",
+        "city_id" => NULL,
+        "city" => "",
+        "postcode" => "",
+        "region" => "",
+        "country" => "00");
+}
+
+// localize all the address of a user and modify the database
+// if the new address match with the old one
+function localize_addresses($uid) {
+    global $globals;
+    $res = $globals->xdb->iterator("SELECT * FROM adresses WHERE uid = {?} and (cityid IS NULL OR cityid = 0)", $uid);
+    $erreur = Array();
+
+    while ($a = $res->next()) {
+        $new = get_address_infos(get_address_text($a));
+        if ($new['cityid'] && compare_addresses($a, $new)) {
+            $globals->xdb->execute("UPDATE adresses SET
+                adr1 = {?}, adr2 = {?}, adr3 = {?},
+                cityid = {?}, city = {?}, postcode = {?},
+                region = {?}, country = {?}
+                WHERE uid = {?} AND adrid = {?}",
+                $new['adr1'], $new['adr2'], $new['adr3'],
+                $new['cityid'], $new['city'], $new['postcode'],
+                $new['region'], $new['country'],
+                $uid, $a['adrid']);
+        } else $erreur[$a['adrid']] = $new;
+    }
+
+    return $erreur;
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index c2201a2..417bf9e 100644 (file)
@@ -61,6 +61,8 @@ $sql_order = '';
 $res = $globals->xdb->query("SELECT adrid FROM adresses WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut) ".$sql_order, Session::getInt('uid', -1));
 $adrids = $res->fetchColumn();
 
+$non_geoloc = localize_addresses(Session::getInt('uid', -1));
+
 //recuperation des donnees de la bd
 $res = $globals->xdb->iterRow(
        "SELECT
@@ -90,6 +92,9 @@ for ($i = 0; $i < $nb_adr; $i++) {
   $adresses[$adrid]['numero_formulaire'] = -1;
   require_once('geoloc.inc.php');
   $adresses[$adrid]['txt'] = get_address_text($adresses[$adrid]);
+
+  if (isset($non_geoloc[$adrid]))
+       $adresses[$adrid]['geoloc'] = get_address_text($non_geoloc[$adrid]);
 }
 
 ?>
index b13a1bb..b6e56cc 100644 (file)
@@ -49,6 +49,11 @@ function replace_ifset_adr($varname, $i){
        $GLOBALS['adresses'][$i][$varname] = $tab[$i];
 }
 
+function get_adr_arg($varname, $i) {
+  $tab = Env::getMixed($varname, Array());
+  return $tab[$i];
+}
+
 function set_flag_adr($varname,$i){
   $tab = Env::getMixed($varname, Array());
   if (isset($tab[$i])){
@@ -60,18 +65,19 @@ function set_flag_adr($varname,$i){
 
 
 function replace_address($i){
-  if(!isset($GLOBALS['adresses'][$i])){
-    $GLOBALS['adresses'][$i]['nouvelle'] = 'ajout';
-    $GLOBALS['adresses'][$i]['adrid'] = $i;
+  global $page, $adresses;
+  if(!isset($adresses[$i])){
+    $adresses[$i]['nouvelle'] = 'ajout';
+    $adresses[$i]['adrid'] = $i;
   }
   
   replace_ifset_adr('secondaire', $i);
   set_flag_adr('courrier', $i);
   replace_ifset_adr('temporaire', $i);
   if(Env::getInt('adrid_active', $i+1) == $i)
-    $GLOBALS['adresses'][$i]['active'] = 1;
+    $adresses[$i]['active'] = 1;
   else
-    $GLOBALS['adresses'][$i]['active'] = 0;
+    $adresses[$i]['active'] = 0;
   replace_ifset_adr('adr1', $i);
   replace_ifset_adr('adr2', $i);
   replace_ifset_adr('adr3', $i);
@@ -84,30 +90,39 @@ 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('change'.$i, false)) {
+  if (!get_adr_arg('parsevalid', $i)) replace_ifset_adr('txt', $i);
+  $change = Env::get('change'.$i);
+  if (Env::get('parseretry'.$i)) {
+       $adresses[$i]['txt'] = get_adr_arg('retrytxt', $i);
+       $change = true;
+  }    
+  if (get_adr_arg('parsevalid', $i) || ($adresses[$i]['txt'] && $change)) {
        require_once('geoloc.inc.php');
-       $new = get_address_infos($GLOBALS['adresses'][$i]['txt']);
+       $new = get_address_infos($adresses[$i]['txt']);
        // if we found a localisation, erase old address
-       if ($new['sql']) {
-               $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]['countrytxt'] = '';
-               $GLOBALS['adresses'][$i]['region'] = '';
-               $GLOBALS['adresses'][$i] = array_merge($GLOBALS['adresses'][$i], $new);
+       if ($new['sql'] || get_adr_arg('parsevalid', $i)) {
+               $adresses[$i]['adr1'] = '';
+               $adresses[$i]['adr2'] = '';
+               $adresses[$i]['adr3'] = '';
+               $adresses[$i]['postcode'] = '';
+               $adresses[$i]['city'] = '';
+               unset($adresses[$i]['cityid']);
+               $adresses[$i]['country'] = '00';
+               $adresses[$i]['countrytxt'] = '';
+               $adresses[$i]['region'] = '';
+               $adresses[$i] = array_merge($adresses[$i], $new);
+               unset($adresses[$i]['geoloc']);
+       }else {
+               $page->trig("L'adresse n'a pas été reconnue par la geoloc");
+               $adresses[$i]['old_txt'] = $adresses[$i]['txt'];
        }
   }
-  $GLOBALS['adresses'][$i]['txt'] = get_address_text($GLOBALS['adresses'][$i]);
+  $adresses[$i]['txt'] = get_address_text($adresses[$i]);
   $tab = Env::getMixed('numero_formulaire', Array());
   if($tab[$i])
-    $GLOBALS['adresses'][$i]['numero_formulaire'] = $tab[$i];
+    $adresses[$i]['numero_formulaire'] = $tab[$i];
   else
-    $GLOBALS['adresses'][$i]['numero_formulaire'] = -1;
+    $adresses[$i]['numero_formulaire'] = -1;
 }
 
 
index 0d6fc50..5ae02ee 100644 (file)
@@ -1,43 +1,57 @@
+    {if $adr.old_txt}
     <tr>
-      <td class="colg">
-        <span class="titre">{$titre}</span>
-        {if !$smarty.request.detail[$adrid]}
-       <br />
-          [<a href="{$url}&amp;detail[{$adrid}]=1">{if $adr.nouvelle != 'new'}corriger{else}préciser{/if}</a>]
-       {/if}
-       {if $adr.nouvelle != 'new' && !$adr.cityid && !$smarty.request.detail[$adrid]}
-       <br />
-       <span class="erreur">non géolocalisée</span>
-       <br />
-       <input type="checkbox" name="change{$adrid}" id="change{$adrid}" />
-       <label for="change{$adrid}">localiser</label>
-       {else}
+      <td class="cold" colspan="2">
         <input type="hidden" name="change{$adrid}" value="0" />
-        {/if}
+       <span class="erreur">La geolocalisation n'a pas marché pour ta nouvelle adresse.</span><br />
+       <div class="adresse">
+        <textarea name="txt[{$adrid}]" cols="23" rows="3" onclick="form.change{$adrid}.value=1;document.getElementById('parsekeep{$adrid}').checked='checked'"
+       {if $adr.nouvelle != 'new' && !$adr.cityid}style="background:#FAA"{/if}
+       >{$adr.txt}</textarea><br />
+       <input type="radio" name="parseretry{$adrid}" value="0" id="parsekeep{$adrid}" checked="checked"/><label for="parsekeep{$adrid}">conserver</label>
+       </div>
+       <div>
+         <textarea cols="23" rows="3" name="retrytxt[{$adrid}]" style="background:#FAA" onclick="document.getElementById('parseretry{$adrid}').checked='checked'">{$adr.old_txt}</textarea><br />
+       <input type="radio" name="parseretry{$adrid}" value="1" id="parseretry{$adrid}" /><label for="parseretry{$adrid}">réessayer</label>
+       </div>
       </td>
-      <td class="cold">
-        {if $smarty.request.detail[$adrid] neq 1}
-        <input type="hidden" name="adr1[{$adrid}]" value="{$adr.adr1}" />
-        <input type="hidden" name="adr2[{$adrid}]" value="{$adr.adr2}" />
-        <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"
-       {if $adr.nouvelle != 'new' && !$adr.cityid && !$smarty.request.detail[$adrid]}
-       onclick="form.change{$adrid}.checked='checked';select()"
-       {else}
-       onclick="form.change{$adrid}.value=1;select()"
-       {/if}
-       >{$adr.txt}</textarea>
-      {else}
+    </tr>
+    {elseif $adr.geoloc && $adr.geoloc neq $adr.txt}
+    <tr>
+      <td class="cold" colspan="2">
+        <input type="hidden" name="change{$adrid}" value="0"/>
+       <span class="erreur">La geolocalisation n'a pas donné un résultat certain, vérifie la nouvelle adresse ou modifie l'ancienne pour que ton adresse puisse être prise en compte.</span><br />
+       <div class="adresse">
+        <textarea name="txt[{$adrid}]" cols="23" rows="3" onclick="form.change{$adrid}.value=1"
+       {if $adr.nouvelle != 'new' && !$adr.cityid}style="background:#FAA"{/if}
+       >{$adr.txt}</textarea><br />
+       <input type="radio" name="parsevalid[{$adrid}]" value="0" id="parsekeep[{$adrid}]" checked="checked"/><label for="parsekeep[{$adrid}]">conserver</label>
+       </div>
+       <div>
+         <textarea cols="23" rows="3" style="background:#AFA">{$adr.geoloc}</textarea><br />
+       <input type="radio" name="parsevalid[{$adrid}]" value="1" id="parsevalid[{$adrid}]" /><label for="parsevalid[{$adrid}]">valider</label>
+       </div>
+      </td>
+    </tr>
+    {else}
+    <tr class="center">
+      <td class="cold" colspan="2">
+        <input type="hidden" name="change{$adrid}" />
+        <textarea name="txt[{$adrid}]" cols="43" rows="3" onclick="form.change{$adrid}.value=1"
+       {if $adr.nouvelle != 'new' && !$adr.cityid}style="background:#FAA"{/if}
+       >{$adr.txt}</textarea><br />
+      </td>
+    </tr>
+    {/if}
+    <tr style="display:none">
+      <td class="colg">
+        &nbsp;
+      </td>
+      <td>
         <input type="hidden" name="cityid[{$adrid}]" value="{$adr.cityid}" />
         <input type="text" name="adr1[{$adrid}]" size="43" maxlength="88" value="{$adr.adr1}" />
       </td>
     </tr>
-    <tr>
+    <tr style="display:none">
       <td class="colg">
         &nbsp;
       </td>
@@ -45,7 +59,7 @@
         <input type="text" name="adr2[{$adrid}]" size="43" maxlength="88" value="{$adr.adr2}" />
       </td>
     </tr>
-    <tr>
+    <tr style="display:none">
       <td class="colg">
         &nbsp;
       </td>
@@ -53,7 +67,7 @@
         <input type="text" name="adr3[{$adrid}]" size="43" maxlength="88" value="{$adr.adr3}" />
       </td>
     </tr>
-    <tr>
+    <tr style="display:none">
       <td class="colg">
         <span class="titre">Code postal / Ville</span><br />
       </td>
         <input type="text" name="city[{$adrid}]" value="{$adr.city}" size="32" maxlength="78" />
       </td>
     </tr>
-    <tr>
+    <tr style="display:none">
       <td class="colg">
         <span class="titre">Pays</span>
       </td>
       <td class="cold">
-        <select name="country[{$adrid}]" onchange="this.form.submit();">
+        <select name="country[{$adrid}]">
           {geoloc_country country=$adr.country}
         </select>
       </td>
     </tr>
-    <tr>
+    <tr style="display:none">
       <td class="colg">
         <span class="titre">Région ou département</span><br />
         <span class="comm">(selon pays)</span>
@@ -82,6 +96,5 @@
         <select name="region[{$adrid}]">
           {geoloc_region country=$adr.country region=$adr.region}
         </select>
-        {/if}
       </td>
     </tr>
index 3f74181..e319c4a 100644 (file)
@@ -58,6 +58,11 @@ Bienvenue {$smarty.session.prenom}
   </p>
 {/if}
 
+{if $geoloc_incitation > 0}
+  <p>
+    Parmi tes adresses, il y en a {$geoloc_incitation} que nous n'avons pas pu localiser. Clique <a href="{rel}/profil.php?old_tab=adresses">ici</a> pour rectifier.
+  </p>
+{/if}
 <br />
 
   <table class="bicol">
index 2ad80b6..a483af4 100644 (file)
         {else}
         <input type="hidden" name="numero_formulaire[{$adrid}]" value="{$smarty.section.i.index}" />
         {/if}
+        {if $adr.nouvelle != 'new'}
+        [<a href="{$smarty.server.PHP_SELF}?old_tab={$smarty.request.old_tab}&amp;adrid_del[{$adrid}]=1" style="color:inherit">La supprimer !</a>]
+        {/if}
       </th>
     </tr>
+    {include file="include/flags.radio.tpl" name="pub[$adrid]" val=$adr.pub}
     <tr>
       <td class="left">
-        {if $adr.nouvelle != 'new'}
-        [<a href="{$smarty.server.PHP_SELF}?old_tab={$smarty.request.old_tab}&amp;adrid_del[{$adrid}]=1">La supprimer !</a>]
-        {/if}
         &nbsp;
       </td>
       <td colspan="4" class="right">
@@ -59,7 +60,6 @@
         <input name="adrid_active" type="radio" value="{$adrid}" {if $adr.active}checked="checked"{/if} />
       </td>
     </tr>
-    {include file="include/flags.radio.tpl" name="pub[$adrid]" val=$adr.pub}
     {if $adr.nouvelle != 'new'}
     {assign var="titre" value="Adresse n°`$smarty.section.i.index`&nbsp;:"}
     {else}