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( |
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), |
33 | ); |
34 | } |
35 | |
36 | function _make_qs() |
37 | { |
38 | $querystring = ""; |
39 | |
40 | foreach ($_GET as $v => $a) { |
41 | if ($v != 'initfile') { |
42 | $querystring .= '&'.urlencode($v).'='.urlencode($a); |
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 | |
57 | $res = $globals->xdb->query('SELECT COUNT(DISTINCT uid) |
58 | FROM adresses WHERE cityid IS NOT NULL'); |
59 | $page->assign('localises', $res->fetchOneCell()); |
60 | |
61 | $fields = new SFieldGroup(true, advancedSearchFromInput()); |
62 | $search = $fields->get_url(); |
63 | if (Env::has('only_current') && Env::get('only_current') != 'on') { |
64 | $search .= '&only_current='; |
65 | } |
66 | $search = preg_replace('/(^|&)mapid=([0-9]+)(&|$)/','\1\3', $search); |
67 | if ($search) { |
68 | $page->assign('dynamap_vars', $search); |
69 | } |
70 | |
71 | $page->assign('use_map', $globals->geoloc->use_map()); |
72 | |
73 | return PL_OK; |
74 | } |
75 | |
76 | function handler_icon(&$page) |
77 | { |
78 | global $globals; |
79 | |
80 | header("Content-type: application/x-shockwave-flash"); |
81 | |
82 | if ($globals->geoloc->use_map()) { |
83 | readfile($globals->geoloc->icon_path); |
84 | exit; |
85 | } |
86 | |
87 | return PL_NOT_FOUND; |
88 | } |
89 | |
90 | function handler_dynamap(&$page) |
91 | { |
92 | global $globals; |
93 | |
94 | $querystring = $this->_make_qs(); |
95 | $initfile = urlencode('geolocInit.php?'.$querystring); |
96 | |
97 | if (urlencode(Env::get('initfile')) != $initfile) { |
98 | header("Location: dynamap.php?initfile=$initfile{$querystring}"); |
99 | die(); |
100 | } |
101 | |
102 | header("Content-type: application/x-shockwave-flash"); |
103 | |
104 | if ($globals->geoloc->use_map()) { |
105 | readfile($globals->geoloc->dynamap_path); |
106 | exit; |
107 | } |
108 | |
109 | return PL_NOT_FOUND; |
110 | } |
111 | |
112 | function handler_init(&$page) |
113 | { |
114 | global $globals; |
115 | |
116 | new_nonhtml_page('geoloc/geolocInit.tpl', AUTH_COOKIE); |
117 | |
118 | header('Content-type: text/xml'); |
119 | $page->assign('querystring', $this->_make_qs()); |
120 | |
121 | return PL_OK; |
122 | } |
123 | |
124 | function handler_city(&$page) |
125 | { |
126 | global $globals; |
127 | |
128 | header("Content-type: text/xml"); |
129 | |
130 | new_nonhtml_page('geoloc/getCityInfos.tpl', AUTH_COOKIE); |
131 | // to debug sql use the next line |
132 | //new_skinned_page('', AUTH_COOKIE); |
133 | |
134 | require_once('geoloc.inc.php'); |
135 | require_once('search.inc.php'); |
136 | |
137 | $usual_fields = advancedSearchFromInput(); |
138 | $fields = new SFieldGroup(true, $usual_fields); |
139 | $where = $fields->get_where_statement(); |
140 | if ($where) $where = "WHERE ".$where; |
141 | |
142 | $users = $globals->xdb->iterator(" |
143 | SELECT u.user_id AS id, u.prenom, u.nom, u.promo |
144 | FROM adresses AS a |
145 | INNER JOIN auth_user_md5 AS u ON(u.user_id = a.uid) |
146 | INNER JOIN auth_user_quick AS q ON(q.user_id = a.uid) |
147 | ".$fields->get_select_statement()." |
148 | ".$where." |
149 | GROUP BY u.user_id LIMIT 11", $id); |
150 | |
151 | $page->assign('users', $users); |
152 | |
153 | return PL_OK; |
154 | } |
155 | |
156 | function handler_data(&$page) |
157 | { |
158 | global $globals; |
159 | |
160 | // to debug sql use the next line |
161 | if (Env::has('debug')) { |
162 | $page->changeTpl('geoloc/getData.tpl'); |
163 | $page->assign('simple', true); |
164 | } else { |
165 | header("Content-type: text/xml"); |
166 | new_nonhtml_page('geoloc/getData.tpl', AUTH_COOKIE); |
167 | } |
168 | |
169 | require_once 'geoloc.inc.php'; |
170 | require_once 'search.inc.php'; |
171 | |
172 | $querystring = $this->_make_qs(); |
173 | $page->assign('searchvars', $querystring); |
174 | |
175 | $mapid = Env::has('mapid') ? Env::getInt('mapid', -2) : false; |
176 | |
177 | list($countries, $cities) = geoloc_getData_subcountries($mapid, advancedSearchFromInput(), 10); |
178 | |
179 | $page->assign('countries', $countries); |
180 | $page->assign('cities', $cities); |
181 | |
182 | return PL_OK; |
183 | } |
184 | } |
185 | |
186 | ?> |