From: Pascal Corpet
Date: Sun, 12 Jun 2005 22:11:12 +0000 (+0000)
Subject: geoloc interface
X-Git-Tag: xorg/old~57
X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=91f1b2de4031fc6aaca26d653f2fabf674302776;p=platal.git
geoloc interface
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-707
---
diff --git a/htdocs/images/globe.png b/htdocs/images/globe.png
new file mode 100644
index 0000000..d762d93
Binary files /dev/null and b/htdocs/images/globe.png differ
diff --git a/htdocs/login.php b/htdocs/login.php
index 2d0986e..3dd277e 100644
--- a/htdocs/login.php
+++ b/htdocs/login.php
@@ -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') ;
diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php
index 717436d..defe993 100644
--- a/include/geoloc.inc.php
+++ b/include/geoloc.inc.php
@@ -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:
?>
diff --git a/include/profil/get_adresses.inc.php b/include/profil/get_adresses.inc.php
index c2201a2..417bf9e 100644
--- a/include/profil/get_adresses.inc.php
+++ b/include/profil/get_adresses.inc.php
@@ -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]);
}
?>
diff --git a/include/profil/verif_adresses.inc.php b/include/profil/verif_adresses.inc.php
index b13a1bb..b6e56cc 100644
--- a/include/profil/verif_adresses.inc.php
+++ b/include/profil/verif_adresses.inc.php
@@ -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;
}
diff --git a/templates/geoloc/form.address.tpl b/templates/geoloc/form.address.tpl
index 0d6fc50..5ae02ee 100644
--- a/templates/geoloc/form.address.tpl
+++ b/templates/geoloc/form.address.tpl
@@ -1,43 +1,57 @@
+ {if $adr.old_txt}
-
- {$titre}
- {if !$smarty.request.detail[$adrid]}
-
- [{if $adr.nouvelle != 'new'}corriger{else}préciser{/if} ]
- {/if}
- {if $adr.nouvelle != 'new' && !$adr.cityid && !$smarty.request.detail[$adrid]}
-
- non géolocalisée
-
-
- localiser
- {else}
+
- {/if}
+ La geolocalisation n'a pas marché pour ta nouvelle adresse.
+
+
+ conserver
+
+
+
+ réessayer
+
-
- {if $smarty.request.detail[$adrid] neq 1}
-
-
-
-
-
-
-
-
-
- {else}
+
+ {elseif $adr.geoloc && $adr.geoloc neq $adr.txt}
+
+
+
+ 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.
+
+
+ conserver
+
+
+
+ valider
+
+
+
+ {else}
+
+
+
+
+
+
+ {/if}
+
+
+
+
+
-
+
@@ -45,7 +59,7 @@
-
+
@@ -53,7 +67,7 @@
-
+
Code postal / Ville
@@ -63,17 +77,17 @@
-
+
Pays
-
+
{geoloc_country country=$adr.country}
-
+
Région ou département
(selon pays)
@@ -82,6 +96,5 @@
{geoloc_region country=$adr.country region=$adr.region}
- {/if}
diff --git a/templates/login.tpl b/templates/login.tpl
index 3f74181..e319c4a 100644
--- a/templates/login.tpl
+++ b/templates/login.tpl
@@ -58,6 +58,11 @@ Bienvenue {$smarty.session.prenom}
{/if}
+{if $geoloc_incitation > 0}
+
+ Parmi tes adresses, il y en a {$geoloc_incitation} que nous n'avons pas pu localiser. Clique ici pour rectifier.
+
+{/if}