X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fgeoloc.php;h=86bfbc929175fe227077619dbfdc4d6fa5452fcd;hb=afada5eb6cf23005f775fbab0d421c27393172f1;hp=bd9ea59a5494aefd6cf6f278f39766eba17a05bc;hpb=fd8f77de8bc10d40395990e3f8e96e0b4a186b46;p=platal.git diff --git a/modules/geoloc.php b/modules/geoloc.php index bd9ea59..86bfbc9 100644 --- a/modules/geoloc.php +++ b/modules/geoloc.php @@ -1,6 +1,6 @@ $this->make_hook('default', AUTH_COOKIE), - 'geoloc/icon.php' => $this->make_hook('icon', AUTH_COOKIE), - 'geoloc/dynamap.php' => $this->make_hook('dynamap', AUTH_COOKIE), - 'geoloc/geolocInit.php' => $this->make_hook('init', AUTH_COOKIE), - 'geoloc/getCityInfos.php' => $this->make_hook('city', AUTH_COOKIE), - 'geoloc/getData.php' => $this->make_hook('data', AUTH_COOKIE), + 'geoloc' => $this->make_hook('default', AUTH_COOKIE), + 'admin/geoloc' => $this->make_hook('admin', AUTH_MDP, 'admin'), + 'admin/geoloc/dynamap' => $this->make_hook('admin_dynamap', AUTH_MDP, 'admin'), ); } - function _make_qs() - { - $querystring = ""; - - foreach ($_GET as $v => $a) { - if ($v != 'initfile') { - $querystring .= '&'.urlencode($v).'='.urlencode($a); - } - } - - return $querystring; - } - - function handler_default(&$page) + function handler_default(&$page, $action = null, $subaction = null) { global $globals; - require_once 'search.inc.php'; - - $page->changeTpl('geoloc/index.tpl'); - - $res = $globals->xdb->query('SELECT COUNT(DISTINCT uid) - FROM adresses WHERE cityid IS NOT NULL'); - $page->assign('localises', $res->fetchOneCell()); - - $fields = new SFieldGroup(true, advancedSearchFromInput()); - $search = $fields->get_url(); - if (Env::has('only_current') && Env::get('only_current') != 'on') { - $search .= '&only_current='; - } - $search = preg_replace('/(^|&)mapid=([0-9]+)(&|$)/','\1\3', $search); - if ($search) { - $page->assign('dynamap_vars', $search); - } - - $page->assign('use_map', $globals->geoloc->use_map()); + $set = new UserSet(); + $set->addMod('geoloc', 'Geolocalisation', true); + $set->apply('geoloc', $page, $action, $subaction); } - function handler_icon(&$page) - { - global $globals; + function handler_admin(&$page, $action = false) { + $page->changeTpl('geoloc/admin.tpl'); + require_once("geoloc.inc.php"); + $page->assign('xorg_title','Polytechnique.org - Administration - Geolocalisation'); - header("Content-type: application/x-shockwave-flash"); + $nb_synchro = 0; - if ($globals->geoloc->use_map()) { - readfile($globals->geoloc->icon_path); - exit; + if (Env::has('id') && is_numeric(Env::v('id'))) { + if (synchro_city(Env::v('id'))) $nb_synchro ++; } - return PL_NOT_FOUND; - } - - function handler_dynamap(&$page) - { - global $globals; - - $querystring = $this->_make_qs(); - $initfile = urlencode('geolocInit.php?'.$querystring); - - if (urlencode(Env::get('initfile')) != $initfile) { - header("Location: dynamap.php?initfile=$initfile{$querystring}"); - die(); + 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++; } - header("Content-type: application/x-shockwave-flash"); - - if ($globals->geoloc->use_map()) { - readfile($globals->geoloc->dynamap_path); - exit; - } + if ($nb_synchro) + $page->trig(($nb_synchro > 1)?($nb_synchro." villes ont été synchronisées"):"Une ville a été synchronisée"); - return PL_NOT_FOUND; + $res = XDB::query("SELECT COUNT(*) FROM geoloc_city WHERE lat = 0 AND lon = 0"); + $page->assign("nb_missinglat", $res->fetchOneCell()); } - function handler_init(&$page) - { - global $globals; - - new_nonhtml_page('geoloc/geolocInit.tpl', AUTH_COOKIE); - - header('Content-type: text/xml'); - $page->assign('querystring', $this->_make_qs()); - } - - function handler_city(&$page) - { - global $globals; - - header("Content-type: text/xml"); - - new_nonhtml_page('geoloc/getCityInfos.tpl', AUTH_COOKIE); - // to debug sql use the next line - //new_skinned_page('', AUTH_COOKIE); - - require_once('geoloc.inc.php'); - require_once('search.inc.php'); + function handler_admin_dynamap(&$page, $action = false) { + $page->changeTpl('geoloc/admin_dynamap.tpl'); - $usual_fields = advancedSearchFromInput(); - $fields = new SFieldGroup(true, $usual_fields); - $where = $fields->get_where_statement(); - if ($where) $where = "WHERE ".$where; - - $users = $globals->xdb->iterator(" - SELECT u.user_id AS id, u.prenom, u.nom, u.promo - FROM adresses AS a - INNER JOIN auth_user_md5 AS u ON(u.user_id = a.uid) - INNER JOIN auth_user_quick AS q ON(q.user_id = a.uid) - ".$fields->get_select_statement()." - ".$where." - GROUP BY u.user_id LIMIT 11", $id); - - $page->assign('users', $users); - } + 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; + } - function handler_data(&$page) - { - global $globals; + if ($action == 'smallest_maps') { + require_once('geoloc.inc.php'); + set_smallest_levels(); + } - // to debug sql use the next line - if (Env::has('debug')) { - $page->changeTpl('geoloc/getData.tpl'); - $page->assign('simple', true); - } else { - header("Content-type: text/xml"); - new_nonhtml_page('geoloc/getData.tpl', AUTH_COOKIE); + 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"); } - require_once 'geoloc.inc.php'; - require_once 'search.inc.php'; + if ($action == 'newmaps') { + require_once('geoloc.inc.php'); + if (!get_new_maps(Env::v('url'))) + $page->trig("Impossible d'accéder aux nouvelles cartes"); + } - $querystring = $this->_make_qs(); - $page->assign('searchvars', $querystring); + $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(); - $mapid = Env::has('mapid') ? Env::getInt('mapid', -2) : false; + $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; - list($countries, $cities) = geoloc_getData_subcountries($mapid, advancedSearchFromInput(), 10); + $countNoCoordinates = XDB::query("SELECT COUNT(*) FROM adresses WHERE cityid IS NOT NULL AND glat = 0 AND glng = 0"); + $noCoordinates = $countNoCoordinates->fetchOneCell(); - $page->assign('countries', $countries); - $page->assign('cities', $cities); + 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); } + } +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>