backport, bug fix pour geoloc avec ie en https
[platal.git] / modules / geoloc.php
CommitLineData
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
22class GeolocModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
27 'geoloc' => $this->make_hook('default', AUTH_COOKIE),
00d0011e 28 'geoloc/icon.swf' => $this->make_hook('icon', AUTH_COOKIE),
29 'geoloc/dynamap.swf' => $this->make_hook('dynamap', AUTH_COOKIE),
7b14a2a0 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
08cce2ff 57 $res = XDB::query('SELECT COUNT(DISTINCT uid)
7b14a2a0 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();
5e2307dc 63 if (Env::has('only_current') && Env::v('only_current') != 'on') {
7b14a2a0 64 $search .= '&only_current=';
65 }
66 $search = preg_replace('/(^|&amp;)mapid=([0-9]+)(&amp;|$)/','\1\3', $search);
67 if ($search) {
68 $page->assign('dynamap_vars', $search);
69 }
7b14a2a0 70 }
71
72 function handler_icon(&$page)
73 {
74 global $globals;
75
76 header("Content-type: application/x-shockwave-flash");
00d0011e 77 header("Pragma:");
7b14a2a0 78
138b3c8e 79 if ($globals->geoloc->use_map) {
7b14a2a0 80 readfile($globals->geoloc->icon_path);
81 exit;
82 }
83
84 return PL_NOT_FOUND;
85 }
86
87 function handler_dynamap(&$page)
88 {
89 global $globals;
90
7b14a2a0 91 header("Content-type: application/x-shockwave-flash");
92
138b3c8e 93 if ($globals->geoloc->use_map) {
00d0011e 94 header("Pragma:");
7b14a2a0 95 readfile($globals->geoloc->dynamap_path);
96 exit;
97 }
98
99 return PL_NOT_FOUND;
100 }
101
102 function handler_init(&$page)
103 {
104 global $globals;
105
801fcad8 106 $page->changeTpl('geoloc/geolocInit.tpl', NO_SKIN);
7b14a2a0 107
108 header('Content-type: text/xml');
00d0011e 109 header('Pragma:');
7b14a2a0 110 $page->assign('querystring', $this->_make_qs());
7b14a2a0 111 }
112
113 function handler_city(&$page)
114 {
115 global $globals;
116
117 header("Content-type: text/xml");
00d0011e 118 header("Pragma:");
7b14a2a0 119
801fcad8 120 $page->changeTpl('geoloc/getCityInfos.tpl', NO_SKIN);
7b14a2a0 121
122 require_once('geoloc.inc.php');
123 require_once('search.inc.php');
124
125 $usual_fields = advancedSearchFromInput();
126 $fields = new SFieldGroup(true, $usual_fields);
127 $where = $fields->get_where_statement();
128 if ($where) $where = "WHERE ".$where;
129
08cce2ff 130 $users = XDB::iterator("
7b14a2a0 131 SELECT u.user_id AS id, u.prenom, u.nom, u.promo
132 FROM adresses AS a
133 INNER JOIN auth_user_md5 AS u ON(u.user_id = a.uid)
134 INNER JOIN auth_user_quick AS q ON(q.user_id = a.uid)
135 ".$fields->get_select_statement()."
136 ".$where."
137 GROUP BY u.user_id LIMIT 11", $id);
138
139 $page->assign('users', $users);
7b14a2a0 140 }
141
142 function handler_data(&$page)
143 {
144 global $globals;
145
146 // to debug sql use the next line
147 if (Env::has('debug')) {
62a66dfc 148 $page->changeTpl('geoloc/getData.tpl', SIMPLE);
7b14a2a0 149 } else {
150 header("Content-type: text/xml");
00d0011e 151 header("Pragma:");
801fcad8 152 $page->changeTpl('geoloc/getData.tpl', NO_SKIN);
7b14a2a0 153 }
154
155 require_once 'geoloc.inc.php';
156 require_once 'search.inc.php';
157
158 $querystring = $this->_make_qs();
159 $page->assign('searchvars', $querystring);
160
5e2307dc 161 $mapid = Env::has('mapid') ? Env::i('mapid', -2) : false;
7b14a2a0 162
163 list($countries, $cities) = geoloc_getData_subcountries($mapid, advancedSearchFromInput(), 10);
164
165 $page->assign('countries', $countries);
166 $page->assign('cities', $cities);
7b14a2a0 167 }
168}
169
170?>