7b14a2a0 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
4 | * http://opensource.polytechnique.org/ * |
5 | * * |
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. * |
10 | * * |
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. * |
15 | * * |
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 * |
18 | * Foundation, Inc., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
22 | class GeolocModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
0bf274a8 |
27 | 'geoloc' => $this->make_hook('default', AUTH_COOKIE), |
28 | 'geoloc/icon.swf' => $this->make_hook('icon', AUTH_COOKIE), |
29 | 'geoloc/dynamap.swf' => $this->make_hook('dynamap', AUTH_COOKIE), |
30 | 'geoloc/init' => $this->make_hook('init', AUTH_COOKIE), |
31 | 'geoloc/city' => $this->make_hook('city', AUTH_COOKIE), |
32 | 'geoloc/country' => $this->make_hook('country', AUTH_COOKIE), |
7b14a2a0 |
33 | ); |
34 | } |
35 | |
36 | function _make_qs() |
37 | { |
38 | $querystring = ""; |
39 | |
40 | foreach ($_GET as $v => $a) { |
0bf274a8 |
41 | if ($v != 'initfile' && $v != 'p' && $v != 'mapid') { |
42 | $querystring .= urlencode($v).'='.urlencode($a).'&'; |
7b14a2a0 |
43 | } |
44 | } |
45 | |
46 | return $querystring; |
47 | } |
48 | |
49 | function handler_default(&$page) |
50 | { |
51 | global $globals; |
52 | |
53 | require_once 'search.inc.php'; |
54 | |
55 | $page->changeTpl('geoloc/index.tpl'); |
56 | |
7b14a2a0 |
57 | $fields = new SFieldGroup(true, advancedSearchFromInput()); |
58 | $search = $fields->get_url(); |
0bf274a8 |
59 | if (!Env::has('only_current')) |
60 | $search .= '&only_current=on'; |
61 | elseif (Env::get('only_current') != 'on') |
7b14a2a0 |
62 | $search .= '&only_current='; |
0bf274a8 |
63 | |
7b14a2a0 |
64 | $search = preg_replace('/(^|&)mapid=([0-9]+)(&|$)/','\1\3', $search); |
0bf274a8 |
65 | if ($search) |
66 | $search = '?'.$search; |
67 | $initfile = urlencode('geoloc/init'.$search); |
68 | $page->assign('flashvars','initfile='.$initfile); |
69 | |
70 | $page->assign('protocole', substr($globals->baseurl,0,strpos($globals->baseurl,':'))); |
71 | |
72 | if (!$search) { |
73 | $res = XDB::query('SELECT COUNT(DISTINCT uid) |
74 | FROM adresses WHERE cityid IS NOT NULL'); |
75 | $page->assign('localises', $res->fetchOneCell()); |
7b14a2a0 |
76 | } |
7b14a2a0 |
77 | } |
78 | |
79 | function handler_icon(&$page) |
80 | { |
81 | global $globals; |
82 | |
83 | header("Content-type: application/x-shockwave-flash"); |
00d0011e |
84 | header("Pragma:"); |
7b14a2a0 |
85 | |
138b3c8e |
86 | if ($globals->geoloc->use_map) { |
7b14a2a0 |
87 | readfile($globals->geoloc->icon_path); |
88 | exit; |
89 | } |
90 | |
91 | return PL_NOT_FOUND; |
92 | } |
93 | |
94 | function handler_dynamap(&$page) |
95 | { |
96 | global $globals; |
97 | |
7b14a2a0 |
98 | header("Content-type: application/x-shockwave-flash"); |
99 | |
138b3c8e |
100 | if ($globals->geoloc->use_map) { |
00d0011e |
101 | header("Pragma:"); |
7b14a2a0 |
102 | readfile($globals->geoloc->dynamap_path); |
103 | exit; |
104 | } |
105 | |
106 | return PL_NOT_FOUND; |
107 | } |
108 | |
109 | function handler_init(&$page) |
110 | { |
111 | global $globals; |
112 | |
801fcad8 |
113 | $page->changeTpl('geoloc/geolocInit.tpl', NO_SKIN); |
7b14a2a0 |
114 | |
115 | header('Content-type: text/xml'); |
00d0011e |
116 | header('Pragma:'); |
7b14a2a0 |
117 | $page->assign('querystring', $this->_make_qs()); |
7b14a2a0 |
118 | } |
119 | |
120 | function handler_city(&$page) |
121 | { |
122 | global $globals; |
123 | |
124 | header("Content-type: text/xml"); |
00d0011e |
125 | header("Pragma:"); |
7b14a2a0 |
126 | |
801fcad8 |
127 | $page->changeTpl('geoloc/getCityInfos.tpl', NO_SKIN); |
7b14a2a0 |
128 | |
129 | require_once('geoloc.inc.php'); |
130 | require_once('search.inc.php'); |
131 | |
132 | $usual_fields = advancedSearchFromInput(); |
133 | $fields = new SFieldGroup(true, $usual_fields); |
134 | $where = $fields->get_where_statement(); |
135 | if ($where) $where = "WHERE ".$where; |
136 | |
08cce2ff |
137 | $users = XDB::iterator(" |
7b14a2a0 |
138 | SELECT u.user_id AS id, u.prenom, u.nom, u.promo |
139 | FROM adresses AS a |
140 | INNER JOIN auth_user_md5 AS u ON(u.user_id = a.uid) |
141 | INNER JOIN auth_user_quick AS q ON(q.user_id = a.uid) |
142 | ".$fields->get_select_statement()." |
143 | ".$where." |
144 | GROUP BY u.user_id LIMIT 11", $id); |
145 | |
146 | $page->assign('users', $users); |
7b14a2a0 |
147 | } |
148 | |
0bf274a8 |
149 | function handler_country(&$page) |
7b14a2a0 |
150 | { |
151 | global $globals; |
152 | |
153 | // to debug sql use the next line |
154 | if (Env::has('debug')) { |
62a66dfc |
155 | $page->changeTpl('geoloc/getData.tpl', SIMPLE); |
7b14a2a0 |
156 | } else { |
157 | header("Content-type: text/xml"); |
00d0011e |
158 | header("Pragma:"); |
801fcad8 |
159 | $page->changeTpl('geoloc/getData.tpl', NO_SKIN); |
7b14a2a0 |
160 | } |
161 | |
162 | require_once 'geoloc.inc.php'; |
163 | require_once 'search.inc.php'; |
164 | |
165 | $querystring = $this->_make_qs(); |
166 | $page->assign('searchvars', $querystring); |
167 | |
5e2307dc |
168 | $mapid = Env::has('mapid') ? Env::i('mapid', -2) : false; |
7b14a2a0 |
169 | |
170 | list($countries, $cities) = geoloc_getData_subcountries($mapid, advancedSearchFromInput(), 10); |
171 | |
172 | $page->assign('countries', $countries); |
173 | $page->assign('cities', $cities); |
7b14a2a0 |
174 | } |
175 | } |
176 | |
177 | ?> |