X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fgeoloc.inc.php;h=133d6ea9cb4aa2c6741143315ca1b91b9db7df4c;hb=fb7e68a264092430fc364a11979ff5adb614873a;hp=a8d2c08860c6c3f2fe8886a05514c13f8225c6a5;hpb=c41e72df3fb80a3e89f388e276778c74b5c772b8;p=platal.git diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index a8d2c08..133d6ea 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -19,14 +19,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ - // {{{ liste les pays ou les régions d'un pays /** donne la liste déroulante des pays * @param $current pays actuellement selectionné */ function geoloc_country($current) { - global $globals; - $res = $globals->xdb->iterRow('SELECT a2,pays FROM geoloc_pays ORDER BY pays'); + $res = XDB::iterRow('SELECT a2,pays FROM geoloc_pays ORDER BY pays'); $html = ""; while (list($my_id, $my_pays) = $res->next()) { $html .= sprintf("\n", @@ -47,8 +45,7 @@ $GLOBALS['page']->register_function('geoloc_country', '_geoloc_country_smarty'); * @param $current la region actuellement selectionnee */ function geoloc_region($country,$current) { - global $globals; - $res = $globals->xdb->iterRow('SELECT region,name FROM geoloc_region where a2={?} ORDER BY name', $country); + $res = XDB::iterRow('SELECT region,name FROM geoloc_region where a2={?} ORDER BY name', $country); $html = ""; while (list($regid, $regname) = $res->next()) { $html .= sprintf("\n", @@ -81,9 +78,9 @@ function get_address_infos($txt) { $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) => "œ"))); if ($infos['sql']) - $globals->xdb->execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']); + XDB::execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']); if ($infos['display']) - $globals->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']); return $infos; } // }}} @@ -113,18 +110,24 @@ function get_cities_maps($array) /** set new maps from url **/ function get_new_maps($url) { - if (!($f = @fopen($url, 'r'))) return false; - global $globals; - $globals->xdb->query('TRUNCATE TABLE geoloc_maps'); - $s = ''; - while (!feof($f)) { - $l = fgetcsv($f, 1024, ';', '"'); - foreach ($l as $i => $val) if ($val != 'NULL') $l[$i] = '\''.addslashes($val).'\''; - $s .= ',('.implode(',',$l).')'; - } - $globals->xdb->execute('INSERT INTO geoloc_maps VALUES '.substr($s, 1)); - return true; + if (!($f = @fopen($url, 'r'))) { + return false; + } + XDB::query('TRUNCATE TABLE geoloc_maps'); + $s = ''; + while (!feof($f)) { + $l = fgetcsv($f, 1024, ';', '"'); + foreach ($l as $i => $val) { + if ($val != 'NULL') { + $l[$i] = '\''.addslashes($val).'\''; + } + } + $s .= ',('.implode(',',$l).')'; + } + XDB::execute('INSERT INTO geoloc_maps VALUES '.substr($s, 1)); + return true; } +// }}} // {{{ get_address_text($adr) /** make the text of an address that can be read by a mailman @@ -159,8 +162,7 @@ function get_address_text($adr) { } if ($l) $t .= "\n".trim($l); if ($adr['country'] != '00' && (!$adr['countrytxt'] || $adr['countrytxt'] == strtoupper($adr['countrytxt']))) { - global $globals; - $res = $globals->xdb->query("SELECT pays FROM geoloc_pays WHERE a2 = {?}", $adr['country']); + $res = XDB::query("SELECT pays FROM geoloc_pays WHERE a2 = {?}", $adr['country']); $adr['countrytxt'] = $res->fetchOneCell(); } if ($adr['countrytxt']) $t .= "\n".$adr['countrytxt']; @@ -214,14 +216,13 @@ function cut_address($txt) { * @param $uid the id of the user */ function localize_addresses($uid) { - global $globals; - $res = $globals->xdb->iterator("SELECT * FROM adresses WHERE uid = {?} and (cityid IS NULL OR cityid = 0)", $uid); + $res = XDB::iterator("SELECT * FROM adresses WHERE uid = {?} and (cityid IS NULL OR cityid = 0)", $uid); $erreur = Array(); while ($a = $res->next()) { $new = get_address_infos($ta = get_address_text($a)); if (compare_addresses_text($ta, get_address_text($new))) { - $globals->xdb->execute("UPDATE adresses SET + XDB::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?}, adr3 = {?}, cityid = {?}, city = {?}, postcode = {?}, region = {?}, regiontxt = {?}, country = {?}, @@ -253,15 +254,14 @@ function localize_addresses($uid) { if (!($f = @fopen($url, 'r'))) return false; $s = fgets($f); if ($s) - return $globals->xdb->execute("REPLACE INTO geoloc_city VALUES ".$s) > 0; + return XDB::execute("REPLACE INTO geoloc_city VALUES ".$s) > 0; } // }}} // {{{ function fix_cities_not_on_map($limit) function fix_cities_not_on_map($limit=false) { - global $globals; - $missing = $globals->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".($limit?" LIMIT $limit":"")); $maps = get_cities_maps($missing->fetchColumn()); if ($maps) { @@ -269,7 +269,7 @@ function fix_cities_not_on_map($limit=false) foreach ($maps as $cityid => $maps_c) foreach ($maps_c as $map_id) $values .= ",($cityid, $map_id, '')"; - $globals->xdb->execute("REPLACE INTO geoloc_city_in_maps VALUES ".substr($values, 1)); + XDB::execute("REPLACE INTO geoloc_city_in_maps VALUES ".substr($values, 1)); } else return false; @@ -277,15 +277,14 @@ function fix_cities_not_on_map($limit=false) } function set_smallest_levels() { - global $globals; - $maxlengths = $globals->xdb->iterRow("SELECT MAX(LENGTH(gm.path)), gcim.city_id + $maxlengths = XDB::iterRow("SELECT MAX(LENGTH(gm.path)), gcim.city_id FROM geoloc_city_in_maps AS gcim INNER JOIN geoloc_maps AS gm USING ( map_id ) GROUP BY gcim.city_id "); while (list($length, $id) = $maxlengths->next()) { - $globals->xdb->execute("UPDATE geoloc_city_in_maps AS gcim + XDB::execute("UPDATE geoloc_city_in_maps AS gcim INNER JOIN geoloc_maps AS gm USING(map_id) SET gcim.infos = IF(LENGTH(gm.path) = {?}, 'smallest', '') WHERE gcim.city_id = {?}", $length, $id); @@ -307,7 +306,6 @@ function size_of_city($nb) { $s = round(log($nb + 1)*2,2); if ($s < 1) return 1; function size_of_territory($nb) { return size_of_city($nb); } function geoloc_getData_subcities($mapid, $SFields, &$cities, $direct=true) { - global $globals; for ($i_mapfield=0; $i_mapfield < count($SFields) ; $i_mapfield++) if ($SFields[$i_mapfield]->fieldFormName == 'mapid') break; $SFields[$i_mapfield] = new MapSField('mapid', array('gcim.map_id'), array('adresses','geoloc_city_in_maps'), array('am','gcim'), array(getadr_join('am'), 'am.cityid = gcim.city_id'), $mapid); @@ -315,7 +313,7 @@ function geoloc_getData_subcities($mapid, $SFields, &$cities, $direct=true) { $where = $fields->get_where_statement(); if ($where) $where = " AND ".$where; - $cityres = $globals->xdb->iterator(" + $cityres = XDB::iterator(" SELECT gc.id, gc.lon / 100000 AS x, gc.lat/100000 AS y, gc.name, @@ -340,7 +338,6 @@ function geoloc_getData_subcities($mapid, $SFields, &$cities, $direct=true) { } function geoloc_getData_subcountries($mapid, $SFields, $minentities) { - global $globals; $countries = array(); $cities = array(); @@ -348,11 +345,13 @@ function geoloc_getData_subcountries($mapid, $SFields, $minentities) { $wheremapid = "WHERE gm.parent IS NULL"; else $wheremapid = "WHERE gm.parent = {?}"; - $submapres = $globals->xdb->iterator( + $submapres = XDB::iterator( "SELECT gm.map_id AS id, gm.name, gm.x, gm.y, gm.xclip, gm.yclip, gm.width, gm.height, gm.scale, 1 AS rat FROM geoloc_maps AS gm - ".$wheremapid, Env::get('mapid','')); + ".$wheremapid, Env::v('mapid','')); + + global $globals; while ($c = $submapres->next()) { @@ -365,7 +364,7 @@ function geoloc_getData_subcountries($mapid, $SFields, $minentities) { if ($mapid === false) return array($countries, $cities); - geoloc_getData_subcities(Env::getInt('mapid'), $SFields, $cities); + geoloc_getData_subcities(Env::i('mapid'), $SFields, $cities); $nbcities = count($cities); $nocity = $nbcities == 0; @@ -376,7 +375,7 @@ function geoloc_getData_subcountries($mapid, $SFields, $minentities) { $where = $fields->get_where_statement(); if ($where) $where = " WHERE ".$where; - $countryres = $globals->xdb->iterator(" + $countryres = XDB::iterator(" SELECT map.map_id AS id, COUNT(u.user_id) AS nbPop, SUM(u.promo % 2) AS yellow, @@ -422,5 +421,7 @@ function geoloc_getData_subcountries($mapid, $SFields, $minentities) { return array($countries, $cities); } +// }}} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?>