2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class GeolocModule
extends PLModule
27 'geoloc' => $this->make_hook('default', AUTH_COOKIE
),
28 'geoloc/icon.php' => $this->make_hook('icon', AUTH_COOKIE
),
29 'geoloc/dynamap.php' => $this->make_hook('dynamap', AUTH_COOKIE
),
30 'geoloc/geolocInit.php' => $this->make_hook('init', AUTH_COOKIE
),
31 'geoloc/getCityInfos.php' => $this->make_hook('city', AUTH_COOKIE
),
32 'geoloc/getData.php' => $this->make_hook('data', AUTH_COOKIE
),
40 foreach ($_GET as $v => $a) {
41 if ($v != 'initfile') {
42 $querystring .= '&'.urlencode($v).'='.urlencode($a);
49 function handler_default(&$page)
53 require_once 'search.inc.php';
55 $page->changeTpl('geoloc/index.tpl');
57 $res = XDB
::query('SELECT COUNT(DISTINCT uid)
58 FROM adresses WHERE cityid IS NOT NULL');
59 $page->assign('localises', $res->fetchOneCell());
61 $fields = new SFieldGroup(true
, advancedSearchFromInput());
62 $search = $fields->get_url();
63 if (Env
::has('only_current') && Env
::v('only_current') != 'on') {
64 $search .= '&only_current=';
66 $search = preg_replace('/(^|&)mapid=([0-9]+)(&|$)/','\1\3', $search);
68 $page->assign('dynamap_vars', $search);
71 $page->assign('use_map', $globals->geoloc
->use_map());
74 function handler_icon(&$page)
78 header("Content-type: application/x-shockwave-flash");
80 if ($globals->geoloc
->use_map()) {
81 readfile($globals->geoloc
->icon_path
);
88 function handler_dynamap(&$page)
92 $querystring = $this->_make_qs();
93 $initfile = urlencode('geolocInit.php?'.$querystring);
95 if (urlencode(Env
::v('initfile')) != $initfile) {
96 header("Location: dynamap.php?initfile=$initfile{$querystring}");
100 header("Content-type: application/x-shockwave-flash");
102 if ($globals->geoloc
->use_map()) {
103 readfile($globals->geoloc
->dynamap_path
);
110 function handler_init(&$page)
114 $page->changeTpl('geoloc/geolocInit.tpl', NO_SKIN
);
116 header('Content-type: text/xml');
117 $page->assign('querystring', $this->_make_qs());
120 function handler_city(&$page)
124 header("Content-type: text/xml");
126 $page->changeTpl('geoloc/getCityInfos.tpl', NO_SKIN
);
128 require_once('geoloc.inc.php');
129 require_once('search.inc.php');
131 $usual_fields = advancedSearchFromInput();
132 $fields = new SFieldGroup(true
, $usual_fields);
133 $where = $fields->get_where_statement();
134 if ($where) $where = "WHERE ".$where;
136 $users = XDB
::iterator("
137 SELECT u.user_id AS id, u.prenom, u.nom, u.promo
139 INNER JOIN auth_user_md5 AS u ON(u.user_id = a.uid)
140 INNER JOIN auth_user_quick AS q ON(q.user_id = a.uid)
141 ".$fields->get_select_statement()."
143 GROUP BY u.user_id LIMIT 11", $id);
145 $page->assign('users', $users);
148 function handler_data(&$page)
152 // to debug sql use the next line
153 if (Env
::has('debug')) {
154 $page->changeTpl('geoloc/getData.tpl', SIMPLE
);
156 header("Content-type: text/xml");
157 $page->changeTpl('geoloc/getData.tpl', NO_SKIN
);
160 require_once 'geoloc.inc.php';
161 require_once 'search.inc.php';
163 $querystring = $this->_make_qs();
164 $page->assign('searchvars', $querystring);
166 $mapid = Env
::has('mapid') ? Env
::i('mapid', -2) : false
;
168 list($countries, $cities) = geoloc_getData_subcountries($mapid, advancedSearchFromInput(), 10);
170 $page->assign('countries', $countries);
171 $page->assign('cities', $cities);