X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fgeoloc.inc.php;h=4ba4410b0da8435d03774820ab96e5e22a8f36ce;hb=c46ec4752db88dbde3f792a278f350c922cd211d;hp=133d6ea9cb4aa2c6741143315ca1b91b9db7df4c;hpb=80244bbe5852490f79360c1e3efc3fe61fcda648;p=platal.git diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index 133d6ea..4ba4410 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -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) {