backport fix lien pour remonter en haut des events
[platal.git] / include / geoloc.inc.php
index 133d6ea..4ba4410 100644 (file)
@@ -76,11 +76,21 @@ function get_address_infos($txt) {
     $keys = explode('|',fgets($f));
     $vals = explode('|',fgets($f));
     $infos = array();
-    foreach ($keys as $i=>$key) if($vals[$i]) $infos[$key] = ($key == 'sql')?$vals[$i]:utf8_decode(strtr($vals[$i], array(chr(197).chr(147) => "œ")));
+    foreach ($keys as $i=>$key) {
+        if($vals[$i]) {
+            if ($key == 'sql') {
+                $infos[$key] = $vals[$i];
+            } else {
+                $val = strtr($vals[$i], array(chr(197).chr(147) => "œ"));
+                $infos[$key] = (iconv('utf-8', 'utf-8', $val) == $val)  ? utf8_decode($val) : $val;
+            }
+        }
+    }
     if ($infos['sql'])
        XDB::execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']);
     if ($infos['display'])
-       XDB::execute("UPDATE geoloc_pays SET display = {?} WHERE a2 = {?}", $infos['display'], $infos['country']);
+        XDB::execute("UPDATE geoloc_pays SET display = {?} WHERE a2 = {?}", $infos['display'], $infos['country']);
+    fix_cities_not_on_map(1, $infos['cityid']);
     return $infos;
 }
 // }}}
@@ -259,9 +269,9 @@ function localize_addresses($uid) {
  // }}}
 
 // {{{ function fix_cities_not_on_map($limit)
-function fix_cities_not_on_map($limit=false)
+function fix_cities_not_on_map($limit=false, $cityid=false)
 {
-    $missing = XDB::query("SELECT c.id FROM geoloc_city AS c LEFT JOIN geoloc_city_in_maps AS m ON(c.id = m.city_id) WHERE m.city_id IS NULL".($limit?" LIMIT $limit":""));
+    $missing = XDB::query("SELECT c.id FROM geoloc_city AS c LEFT JOIN geoloc_city_in_maps AS m ON(c.id = m.city_id) WHERE m.city_id IS NULL".($cityid?(" AND c.id = '".$cityid."'"):"").($limit?" LIMIT $limit":""));
     $maps = get_cities_maps($missing->fetchColumn());
     if ($maps)
     {