X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fgeoloc.inc.php;h=28ffe51ff732675da6d40c5c646b58bac07bb71f;hb=54e73532f787629c1b9b98b0700aa37b75e01d33;hp=a1939b8ae76328e017d6ed4fa66682ddbb7ab0a4;hpb=37d44b3b542764eda8d4f9c3febc814ae37f8157;p=platal.git diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index a1939b8..28ffe51 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -1,6 +1,6 @@ register_function('geoloc_country', '_geoloc_country_smarty'); - /** donne la liste deroulante des regions pour un pays * @param $pays le pays dont on veut afficher les regions * @param $current la region actuellement selectionnee @@ -79,15 +68,6 @@ function geoloc_region($country, $current, $avail_only = false) } return $html; } - -function _geoloc_region_smarty($params, &$smarty) -{ - if(!isset($params['country']) || !isset($params['region'])) { - return; - } - return geoloc_region($params['country'], $params['region'], @$params['available']); -} -$GLOBALS['page']->register_function('geoloc_region', '_geoloc_region_smarty'); // }}} // {{{ get_address_infos($txt) @@ -114,11 +94,25 @@ function get_address_infos($txt) } } if (isset($infos['sql']) && $infos['sql']) - XDB::execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']); + XDB::execute("REPLACE INTO geoloc_city + VALUES ".$infos['sql']); if (isset($infos['display']) && $infos['display']) - XDB::execute("UPDATE geoloc_pays SET display = {?} WHERE a2 = {?}", $infos['display'], $infos['country']); - if (isset($infos['cityid'])) + XDB::execute("UPDATE geoloc_pays + SET display = {?} + WHERE a2 = {?}", $infos['display'], $infos['country']); + if (isset($infos['cityid'])) { fix_cities_not_on_map(1, $infos['cityid']); + if (floatval($infos['precise_lat']) && floatval($infos['precise_lon'])) { + $res = XDB::query("SELECT c.lat / 100000, c.lon / 100000 + FROM geoloc_city AS c + WHERE c.id = {?}", $infos['cityid']); + if ($res->numRows()) { + list($glat, $glng) = $res->fetchOneRow(); + $infos['precise_lat'] = $glat; + $infos['precise_lon'] = $glng; + } + } + } return $infos; } // }}} @@ -245,7 +239,9 @@ function empty_address() { "region" => "", "regiontxt" => "", "country" => "00", - "countrytxt" => ""); + "countrytxt" => "", + "precise_lat" => "", + "precise_lon" => ""); } // create a simple address from a text without geoloc @@ -330,8 +326,10 @@ function fix_cities_not_on_map($limit=false, $cityid=false) $values .= ",($cityid, $map_id, '')"; } } - XDB::execute("REPLACE INTO geoloc_city_in_maps - VALUES ".substr($values, 1)); + if (strlen($values) > 1) { + XDB::execute("REPLACE INTO geoloc_city_in_maps + VALUES ".substr($values, 1)); + } } else { return false; } @@ -420,7 +418,7 @@ function geoloc_getData_subcities($mapid, $SFields, &$cities, $direct=true) $where . ($direct ? "gcim.infos = 'smallest'" : '1'), 'gc.id, gc.alias', 'pop DESC'); - while ($c = $cityres->next()) { + foreach($cityres as $c) { if ($c['pop'] > 0) { $city = $c; $city['x'] = geoloc_to_x($c['x'], $c['y']); @@ -498,8 +496,8 @@ function geoloc_getData_subcountries($mapid, $sin, $minentities) 'NULL'); $maxpop = 0; - $nbentities = $nbcities + $countryres->total(); - while ($c = $countryres->next()) { + $nbentities = $nbcities + count($countryres); + foreach ($countryres as $c) { $c['latPop'] /= $c['nbPop']; $c['lonPop'] /= $c['nbPop']; $c['rad'] = size_of_territory($c['nbPop']); @@ -521,7 +519,7 @@ function geoloc_getData_subcountries($mapid, $sin, $minentities) } foreach ($countries as $i => $c) { - if ($c['nbPop'] > 0) { + if (@$c['nbPop'] > 0) { $lambda = pow($c['nbPop'] / $maxpop,0.3); $countries[$i]['color'] = 0x0000FF + round((1-$lambda) * 0xFF)*0x010100; }