* 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 = XDB::iterRow('SELECT a2,pays FROM geoloc_pays ORDER BY pays');
$html = "";
while (list($my_id, $my_pays) = $res->next()) {
* @param $current la region actuellement selectionnee
*/
function geoloc_region($country,$current) {
- global $globals;
$res = XDB::iterRow('SELECT region,name FROM geoloc_region where a2={?} ORDER BY name', $country);
$html = "<option value=\"\"></option>";
while (list($regid, $regname) = $res->next()) {
$GLOBALS['page']->register_function('geoloc_region', '_geoloc_region_smarty');
// }}}
+function geoloc_is_utf8($text)
+{
+ return (iconv('utf-8', 'utf-8', $text) == $text);
+}
+
+function geoloc_utf8_decode($text)
+{
+ return geoloc_is_utf8($text) ? utf8_decode($text) : $text;
+}
+
// {{{ get_address_infos($txt)
/** retrieve the infos on a text address
* store on the fly the info of the city concerned
$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] = geoloc_utf8_decode($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;
}
// }}}
/** set new maps from url **/
function get_new_maps($url)
{
- if (!($f = @fopen($url, 'r'))) return false;
- global $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).')';
- }
- 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
}
if ($l) $t .= "\n".trim($l);
if ($adr['country'] != '00' && (!$adr['countrytxt'] || $adr['countrytxt'] == strtoupper($adr['countrytxt']))) {
- global $globals;
$res = XDB::query("SELECT pays FROM geoloc_pays WHERE a2 = {?}", $adr['country']);
$adr['countrytxt'] = $res->fetchOneCell();
}
* @param $uid the id of the user
*/
function localize_addresses($uid) {
- global $globals;
$res = XDB::iterator("SELECT * FROM adresses WHERE uid = {?} and (cityid IS NULL OR cityid = 0)", $uid);
$erreur = Array();
// }}}
// {{{ 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)
{
- global $globals;
- $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)
{
}
function set_smallest_levels() {
- global $globals;
$maxlengths = XDB::iterRow("SELECT MAX(LENGTH(gm.path)), gcim.city_id
FROM geoloc_city_in_maps AS gcim
INNER JOIN geoloc_maps AS gm
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);
if ($c['pop'] > 0)
{
$city = $c;
+ // $city['name'] = geoloc_utf8_decode($city['name']);
+ if (!geoloc_is_utf8($city['name'])) {
+ $city['name'] = utf8_encode($city['name']);
+ }
$city['x'] = geoloc_to_x($c['x'], $c['y']);
$city['y'] = geoloc_to_y($c['x'], $c['y']);
$city['size'] = size_of_city($c['pop']);
}
function geoloc_getData_subcountries($mapid, $SFields, $minentities) {
- global $globals;
$countries = array();
$cities = array();
"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())
{
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;
return array($countries, $cities);
}
+// }}}
+
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
?>