git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-711
// 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;
+function compare_addresses_text($a, $b) {
+ $ta = strtoupper(preg_replace(array("/[,\"'#~:;_\-]/", "/\r\n/"), array(" ", "\n"), $a));
+ $tb = strtoupper(preg_replace(array("/[,\"'#~:;_\-]/", "/\r\n/"), array(" ", "\n"), $b));
+
+ $la = explode("\n", $ta);
+ $lb = explode("\n", $tb);
+
+ if (count($lb) > count($la) + 1) return false;
+ foreach ($la as $i=>$l) if (levenshtein($l, $lb[$i]) > 3) return false;
return true;
}
"adr1" => "",
"adr2" => "",
"adr3" => "",
- "city_id" => NULL,
+ "cityid" => NULL,
"city" => "",
"postcode" => "",
"region" => "",
- "country" => "00");
+ "country" => "00",
+ "countrytxt" => "");
+}
+
+// create a simple address from a text without geoloc
+function cut_address($txt) {
+ $txt = str_replace("\r\n", "\n", $txt);
+ ereg("^([^\n]*)(\n([^\n]*)(\n(.*))?)?$", trim($txt), $a);
+ return array("adr1" => trim($a[1]), "adr2" => trim($a[3]), "adr3" => trim(str_replace("\n", " ", $a[5])));
}
// localize all the address of a user and modify the database
$erreur = Array();
while ($a = $res->next()) {
- $new = get_address_infos(get_address_text($a));
- if ($new['cityid'] && compare_addresses($a, $new)) {
+ $new = get_address_infos($ta = get_address_text($a));
+ if (compare_addresses_text($ta, get_address_text($new))) {
$globals->xdb->execute("UPDATE adresses SET
adr1 = {?}, adr2 = {?}, adr3 = {?},
cityid = {?}, city = {?}, postcode = {?},
$new['cityid'], $new['city'], $new['postcode'],
$new['region'], $new['country'],
$uid, $a['adrid']);
- } else $erreur[$a['adrid']] = $new;
+ $new['store'] = true;
+ if (!$new['cityid']) return $erreur[$a['adrid']] = $new;
+ } else {
+ $new['store'] = false;
+ $erreur[$a['adrid']] = $new;
+ }
}
return $erreur;
$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
$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]);
}
?>
function replace_address($i){
- global $page, $adresses;
+ global $adresses;
if(!isset($adresses[$i])){
$adresses[$i]['nouvelle'] = 'ajout';
$adresses[$i]['adrid'] = $i;
replace_ifset_adr('pub', $i);
replace_ifset_adr('tel_pub', $i);
if (!get_adr_arg('parsevalid', $i)) replace_ifset_adr('txt', $i);
+ $tab = Env::getMixed('numero_formulaire', Array());
+ if($tab[$i])
+ $adresses[$i]['numero_formulaire'] = $tab[$i];
+ else
+ $adresses[$i]['numero_formulaire'] = -1;
+}
+
+function geoloc_adresse($i) {
+ global $adresses;
$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)) {
+ if (get_adr_arg('parsevalid', $i) || ($adresses[$i]['txt'] && $change) || (!$adresses[$i]['cityid'])) {
require_once('geoloc.inc.php');
+ // erases the previous address (but not the phone or pub)
+ $adresses[$i] = array_merge($adresses[$i], empty_address());
+ // localize new address
$new = get_address_infos($adresses[$i]['txt']);
- // if we found a localisation, erase old address
- 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'] = '';
+ if (compare_addresses_text($adresses[$i]['txt'], $geotxt = get_address_text($new)) || get_adr_arg('parsevalid', $i))
$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'];
+ else {
+ $adresses[$i] = array_merge($adresses[$i], cut_address($adresses[$i]['txt']));
+ $adresses[$i]['geoloc'] = $geotxt;
+ $adresses[$i]['geoloc_cityid'] = $new['cityid'];
}
}
$adresses[$i]['txt'] = get_address_text($adresses[$i]);
- $tab = Env::getMixed('numero_formulaire', Array());
- if($tab[$i])
- $adresses[$i]['numero_formulaire'] = $tab[$i];
- else
- $adresses[$i]['numero_formulaire'] = -1;
}
-
//remplace par les eventuelles nouvelles valeurs :
for ($adrid = 1; $adrid <= $nb_adr_max; $adrid++) {
$tab = Env::getMixed('adrid', Array());
if(isset($tab[$adrid])){ //cet adrid etait donc present dans le formulaire
replace_address($adrid);
}
+ if (isset($adresses[$adrid]['txt']))
+ geoloc_adresse($adrid);
}
if(Env::get('old_tab', '') == 'adresses' && Env::has('modifier')){ // on ne valide que qd on vient du formulaire
- {if $adr.old_txt}
- <tr>
- <td class="cold" colspan="2">
- <input type="hidden" name="change{$adrid}" value="0" />
- <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" onchange="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" onchange="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>
- </tr>
- {elseif $adr.geoloc && $adr.geoloc neq $adr.txt}
+ {if $adr.geoloc}
<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 />
+ <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>
<div class="adresse">
<textarea name="txt[{$adrid}]" cols="23" rows="3" onchange="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>
+ {if !$adr.cityid}style="background:#FAA"{/if}
+ >{$adr.txt}</textarea>
</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 class="adresse">
+ <pre
+ style="border:2px inset threedface{if !$adr.geoloc_cityid};background:#FAA{/if}"
+ >{$adr.geoloc}</pre>
+ [<a href="{$smarty.server.PHP_SELF}?old_tab={$smarty.request.old_tab}&parsevalid[{$adrid}]=1">Valider</a>]
</div>
</td>
</tr>
<input type="hidden" name="change{$adrid}" />
<textarea name="txt[{$adrid}]" cols="43" rows="3" onchange="form.change{$adrid}.value=1"
{if $adr.nouvelle != 'new' && !$adr.cityid}style="background:#FAA"{/if}
- >{$adr.txt}</textarea><br />
+ >{$adr.txt}</textarea>
</td>
</tr>
{/if}