X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fgeoloc.php;h=1e2920e660433e80726d2316a09a5fddfcfe8049;hb=e336465e05bbca91fd0eb3f5b4c27f1391529f98;hp=133e24a65ebacf14bb84164aeda69b9433dcab4c;hpb=80244bbe5852490f79360c1e3efc3fe61fcda648;p=platal.git diff --git a/modules/geoloc.php b/modules/geoloc.php index 133e24a..1e2920e 100644 --- a/modules/geoloc.php +++ b/modules/geoloc.php @@ -36,6 +36,8 @@ class GeolocModule extends PLModule '%grp/geoloc/init' => $this->make_hook('init', AUTH_COOKIE), '%grp/geoloc/city' => $this->make_hook('city', AUTH_COOKIE), '%grp/geoloc/country' => $this->make_hook('country',AUTH_COOKIE), + 'admin/geoloc' => $this->make_hook('admin', AUTH_MDP, 'admin'), + 'admin/geoloc/dynamap' => $this->make_hook('admin_dynamap', AUTH_MDP, 'admin'), ); } @@ -44,7 +46,7 @@ class GeolocModule extends PLModule $querystring = ""; foreach ($_GET as $v => $a) { - if ($v != 'initfile' && $v != 'p' && $v != 'mapid') { + if ($v != 'initfile' && $v != 'n' && $v != 'mapid') { $querystring .= urlencode($v).'='.urlencode($a).'&'; } } @@ -52,12 +54,17 @@ class GeolocModule extends PLModule return $querystring; } + function use_map() + { + return is_file(dirname(__FILE__).'/geoloc/dynamap.swf') && + is_file(dirname(__FILE__).'/geoloc/icon.swf'); + } + function handler_default(&$page) { global $globals; - if (!is_file(dirname(__FILE__).'/geoloc/dynamap.swf') || - !is_file(dirname(__FILE__).'/geoloc/icon.swf')) + if (!$this->use_map()) $page->assign('request_geodesix', 1); if (!empty($GLOBALS['IS_XNET_SITE'])) { @@ -69,16 +76,16 @@ class GeolocModule extends PLModule require_once 'search.inc.php'; $page->changeTpl('geoloc/index.tpl'); $fields = new SFieldGroup(true, advancedSearchFromInput()); - $search = $fields->get_url(); + $search = str_replace('&','&',$fields->get_url()); if (!Env::has('only_current')) $search .= '&only_current=on'; - elseif (Env::get('only_current') != 'on') + elseif (Env::i('only_current') != 'on') $search .= '&only_current='; - $search = preg_replace('/(^|&)mapid=([0-9]+)(&|$)/','\1\3', $search); + $search = preg_replace('/(^|&)mapid=([0-9]+)(&)/','\1\3', $search); if ($search) $search = '?'.$search; - $page->assign('search',$search); + $page->assign('search',urlencode($search)); $page->assign('protocole', substr($globals->baseurl,0,strpos($globals->baseurl,':'))); @@ -119,7 +126,7 @@ class GeolocModule extends PLModule { global $globals; - $page->changeTpl('geoloc/geolocInit.tpl', NO_SKIN); + $page->changeTpl('geoloc/init.tpl', NO_SKIN); header('Content-type: text/xml'); header('Pragma:'); @@ -135,7 +142,7 @@ class GeolocModule extends PLModule header("Content-type: text/xml"); header("Pragma:"); - $page->changeTpl('geoloc/getCityInfos.tpl', NO_SKIN); + $page->changeTpl('geoloc/city.tpl', NO_SKIN); require_once('geoloc.inc.php'); require_once('search.inc.php'); @@ -171,11 +178,11 @@ class GeolocModule extends PLModule // to debug sql use the next line if (Env::has('debug')) { - $page->changeTpl('geoloc/getData.tpl', SIMPLE); + $page->changeTpl('geoloc/country.tpl', SIMPLE); } else { header("Content-type: text/xml"); header("Pragma:"); - $page->changeTpl('geoloc/getData.tpl', NO_SKIN); + $page->changeTpl('geoloc/country.tpl', NO_SKIN); } require_once 'geoloc.inc.php'; @@ -198,6 +205,73 @@ class GeolocModule extends PLModule $page->assign('countries', $countries); $page->assign('cities', $cities); } + + function handler_admin(&$page, $action = false) { + $page->changeTpl('geoloc/admin.tpl'); + require_once("geoloc.inc.php"); + $page->assign('xorg_title','Polytechnique.org - Administration - Geolocalisation'); + + $nb_synchro = 0; + + if (Env::has('id') && is_numeric(Env::v('id'))) { + if (synchro_city(Env::v('id'))) $nb_synchro ++; + } + + if ($action == 'missinglat') { + $res = XDB::iterRow("SELECT id FROM geoloc_city WHERE lat = 0 AND lon = 0"); + while ($a = $res->next()) if (synchro_city($a[0])) $nb_synchro++; + } + + if ($nb_synchro) + $page->trig(($nb_synchro > 1)?($nb_synchro." villes ont été synchronisées"):"Une ville a été synchronisée"); + + $res = XDB::query("SELECT COUNT(*) FROM geoloc_city WHERE lat = 0 AND lon = 0"); + $page->assign("nb_missinglat", $res->fetchOneCell()); + } + + function handler_admin_dynamap(&$page, $action = false) { + $page->changeTpl('geoloc/admin_dynamap.tpl'); + + if ($action == 'cities_not_on_map') { + require_once('geoloc.inc.php'); + if (!fix_cities_not_on_map(20)) + $page->trig("Impossible d'accéder au webservice"); + else + $refresh = true; + } + + if ($action == 'smallest_maps') { + require_once('geoloc.inc.php'); + set_smallest_levels(); + } + + if ($action == 'precise_coordinates') { + XDB::execute("UPDATE adresses AS a INNER JOIN geoloc_city AS c ON(a.cityid = c.id) SET a.glat = c.lat / 100000, a.glng = c.lon / 100000"); + } + + if ($action == 'newmaps') { + require_once('geoloc.inc.php'); + if (!get_new_maps(Env::v('url'))) + $page->trig("Impossible d'accéder aux nouvelles cartes"); + } + + $countMissing = XDB::query("SELECT COUNT(*) 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"); + $missing = $countMissing->fetchOneCell(); + + $countNoSmallest = XDB::query("SELECT SUM(IF(infos = 'smallest',1,0)) AS n FROM geoloc_city_in_maps GROUP BY city_id ORDER BY n"); + $noSmallest = $countNoSmallest->fetchOneCell() == 0; + + $countNoCoordinates = XDB::query("SELECT COUNT(*) FROM adresses WHERE cityid IS NOT NULL AND glat = 0 AND glng = 0"); + $noCoordinates = $countNoCoordinates->fetchOneCell(); + + if (isset($refresh) && $missing) { + $page->assign("xorg_extra_header", ""); + } + $page->assign("nb_cities_not_on_map", $missing); + $page->assign("no_smallest", $noSmallest); + $page->assign("no_coordinates", $noCoordinates); + } + } ?>