Merge branch 'platal-0.9.16'
[platal.git] / include / geoloc.inc.php
index 89ecd45..51fc43c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -94,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;
 }
 // }}}
@@ -225,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
@@ -501,7 +517,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;
         }