| 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.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), |
| 33 | '%grp/geoloc' => $this->make_hook('default',AUTH_COOKIE), |
| 34 | '%grp/geoloc/icon.swf' => $this->make_hook('icon', AUTH_COOKIE), |
| 35 | '%grp/geoloc/dynamap.swf'=> $this->make_hook('dynamap',AUTH_COOKIE), |
| 36 | '%grp/geoloc/init' => $this->make_hook('init', AUTH_COOKIE), |
| 37 | '%grp/geoloc/city' => $this->make_hook('city', AUTH_COOKIE), |
| 38 | '%grp/geoloc/country' => $this->make_hook('country',AUTH_COOKIE), |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | function _make_qs() |
| 43 | { |
| 44 | $querystring = ""; |
| 45 | |
| 46 | foreach ($_GET as $v => $a) { |
| 47 | if ($v != 'initfile' && $v != 'p' && $v != 'mapid') { |
| 48 | $querystring .= urlencode($v).'='.urlencode($a).'&'; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return $querystring; |
| 53 | } |
| 54 | |
| 55 | function handler_default(&$page) |
| 56 | { |
| 57 | global $globals; |
| 58 | |
| 59 | if (!is_file(dirname(__FILE__).'/geoloc/dynamap.swf') || |
| 60 | !is_file(dirname(__FILE__).'/geoloc/icon.swf')) |
| 61 | $page->assign('request_geodesix', 1); |
| 62 | |
| 63 | if (!empty($GLOBALS['IS_XNET_SITE'])) { |
| 64 | $page->useMenu(); |
| 65 | $page->setType($globals->asso('cat')); |
| 66 | $page->assign('no_annu', 1); |
| 67 | } |
| 68 | |
| 69 | require_once 'search.inc.php'; |
| 70 | $page->changeTpl('geoloc/index.tpl'); |
| 71 | $fields = new SFieldGroup(true, advancedSearchFromInput()); |
| 72 | $search = $fields->get_url(); |
| 73 | if (!Env::has('only_current')) |
| 74 | $search .= '&only_current=on'; |
| 75 | elseif (Env::get('only_current') != 'on') |
| 76 | $search .= '&only_current='; |
| 77 | |
| 78 | $search = preg_replace('/(^|&)mapid=([0-9]+)(&|$)/','\1\3', $search); |
| 79 | if ($search) |
| 80 | $search = '?'.$search; |
| 81 | $page->assign('search',$search); |
| 82 | |
| 83 | $page->assign('protocole', substr($globals->baseurl,0,strpos($globals->baseurl,':'))); |
| 84 | |
| 85 | if (!$search) { |
| 86 | $res = XDB::query('SELECT COUNT(DISTINCT uid) |
| 87 | FROM adresses WHERE cityid IS NOT NULL'); |
| 88 | $page->assign('localises', $res->fetchOneCell()); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | function handler_icon(&$page) |
| 93 | { |
| 94 | global $globals; |
| 95 | |
| 96 | header("Content-type: application/x-shockwave-flash"); |
| 97 | header("Pragma:"); |
| 98 | |
| 99 | readfile(dirname(__FILE__).'/geoloc/icon.swf'); |
| 100 | exit; |
| 101 | |
| 102 | return PL_NOT_FOUND; |
| 103 | } |
| 104 | |
| 105 | function handler_dynamap(&$page) |
| 106 | { |
| 107 | global $globals; |
| 108 | |
| 109 | header("Content-type: application/x-shockwave-flash"); |
| 110 | |
| 111 | header("Pragma:"); |
| 112 | readfile(dirname(__FILE__).'/geoloc/dynamap.swf'); |
| 113 | exit; |
| 114 | |
| 115 | return PL_NOT_FOUND; |
| 116 | } |
| 117 | |
| 118 | function handler_init(&$page) |
| 119 | { |
| 120 | global $globals; |
| 121 | |
| 122 | $page->changeTpl('geoloc/geolocInit.tpl', NO_SKIN); |
| 123 | |
| 124 | header('Content-type: text/xml'); |
| 125 | header('Pragma:'); |
| 126 | if(!empty($GLOBALS['IS_XNET_SITE'])) |
| 127 | $page->assign('background', 0xF2E9D0); |
| 128 | $page->assign('querystring', $this->_make_qs()); |
| 129 | } |
| 130 | |
| 131 | function handler_city(&$page) |
| 132 | { |
| 133 | global $globals; |
| 134 | |
| 135 | header("Content-type: text/xml"); |
| 136 | header("Pragma:"); |
| 137 | |
| 138 | $page->changeTpl('geoloc/getCityInfos.tpl', NO_SKIN); |
| 139 | |
| 140 | require_once('geoloc.inc.php'); |
| 141 | require_once('search.inc.php'); |
| 142 | |
| 143 | if (empty($GLOBALS['IS_XNET_SITE'])) { |
| 144 | $usual_fields = advancedSearchFromInput(); |
| 145 | $fields = new SFieldGroup(true, $usual_fields); |
| 146 | } else { |
| 147 | $_REQUEST['asso_id'] = $globals->asso('id'); |
| 148 | $_REQUEST['only_current'] = 'on'; |
| 149 | $fields = new SFieldGroup(true, array( |
| 150 | new RefSField('asso_id',array('gxm.asso_id'),'groupex.membres','gxm','u.user_id=gxm.uid'), |
| 151 | new RefSField('cityid',array('av.cityid'),'adresses','av',getadr_join('av')))); |
| 152 | } |
| 153 | $where = $fields->get_where_statement(); |
| 154 | if ($where) $where = "WHERE ".$where; |
| 155 | |
| 156 | $users = XDB::iterator(" |
| 157 | SELECT u.user_id AS id, u.prenom, u.nom, u.promo |
| 158 | FROM adresses AS a |
| 159 | INNER JOIN auth_user_md5 AS u ON(u.user_id = a.uid) |
| 160 | INNER JOIN auth_user_quick AS q ON(q.user_id = a.uid) |
| 161 | ".$fields->get_select_statement()." |
| 162 | ".$where." |
| 163 | GROUP BY u.user_id LIMIT 11", $id); |
| 164 | |
| 165 | $page->assign('users', $users); |
| 166 | } |
| 167 | |
| 168 | function handler_country(&$page) |
| 169 | { |
| 170 | global $globals; |
| 171 | |
| 172 | // to debug sql use the next line |
| 173 | if (Env::has('debug')) { |
| 174 | $page->changeTpl('geoloc/getData.tpl', SIMPLE); |
| 175 | } else { |
| 176 | header("Content-type: text/xml"); |
| 177 | header("Pragma:"); |
| 178 | $page->changeTpl('geoloc/getData.tpl', NO_SKIN); |
| 179 | } |
| 180 | |
| 181 | require_once 'geoloc.inc.php'; |
| 182 | require_once 'search.inc.php'; |
| 183 | |
| 184 | $querystring = $this->_make_qs(); |
| 185 | $page->assign('searchvars', $querystring); |
| 186 | |
| 187 | $mapid = Env::has('mapid') ? Env::i('mapid', -2) : false; |
| 188 | if (empty($GLOBALS['IS_XNET_SITE'])) { |
| 189 | $fields = advancedSearchFromInput(); |
| 190 | } else { |
| 191 | $_REQUEST['asso_id'] = $globals->asso('id'); |
| 192 | $_REQUEST['only_current'] = 'on'; |
| 193 | $fields = array(new RefSField('asso_id',array('gxm.asso_id'),'groupex.membres','gxm','u.user_id=gxm.uid')); |
| 194 | } |
| 195 | |
| 196 | list($countries, $cities) = geoloc_getData_subcountries($mapid, $fields, 10); |
| 197 | |
| 198 | $page->assign('countries', $countries); |
| 199 | $page->assign('cities', $cities); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | ?> |