| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2007 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 | require_once('xorg.misc.inc.php'); |
| 23 | require_once('user.func.inc.php'); |
| 24 | |
| 25 | global $globals; |
| 26 | |
| 27 | $globals->search->result_where_statement = ' |
| 28 | LEFT JOIN applis_ins AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0) |
| 29 | LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid) |
| 30 | LEFT JOIN applis_ins AS ai1 ON (u.user_id = ai1.uid AND ai1.ordre = 1) |
| 31 | LEFT JOIN applis_def AS ad1 ON (ad1.id = ai1.aid) |
| 32 | LEFT JOIN entreprises AS e ON (e.entrid = 0 AND e.uid = u.user_id) |
| 33 | LEFT JOIN emploi_secteur AS es ON (e.secteur = es.id) |
| 34 | LEFT JOIN fonctions_def AS ef ON (e.fonction = ef.id) |
| 35 | LEFT JOIN geoloc_pays AS n ON (u.nationalite = n.a2) |
| 36 | LEFT JOIN adresses AS adr ON (u.user_id = adr.uid AND FIND_IN_SET(\'active\',adr.statut)) |
| 37 | LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2) |
| 38 | LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region) |
| 39 | LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = \'active\')'; |
| 40 | |
| 41 | class UserSet extends PlSet |
| 42 | { |
| 43 | public function __construct($joins = '', $where = '') |
| 44 | { |
| 45 | global $globals; |
| 46 | parent::__construct('auth_user_md5 AS u', |
| 47 | (!empty($GLOBALS['IS_XNET_SITE']) ? |
| 48 | 'INNER JOIN groupex.membres AS gxm ON (u.user_id = gxm.uid |
| 49 | AND gxm.asso_id = ' . $globals->asso('id') . ') ' : '') |
| 50 | . 'LEFT JOIN auth_user_quick AS q USING (user_id) |
| 51 | LEFT JOIN aliases AS a ON (a.id = u.user_id AND type = \'a_vie\') |
| 52 | ' . $joins, |
| 53 | $where, |
| 54 | 'u.user_id'); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | class SearchSet extends UserSet |
| 59 | { |
| 60 | private $order = null; |
| 61 | private $quick = false; |
| 62 | |
| 63 | public function __construct($quick = false, $no_search = false) |
| 64 | { |
| 65 | require_once dirname(__FILE__).'/../modules/search/search.inc.php'; |
| 66 | |
| 67 | if ($no_search) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | $this->quick = $quick; |
| 72 | if ($quick) { |
| 73 | $this->getQuick(); |
| 74 | } else { |
| 75 | $this->getAdvanced(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | private function getQuick() |
| 80 | { |
| 81 | require_once dirname(__FILE__).'/../modules/search/search.inc.php'; |
| 82 | global $globals; |
| 83 | if (!S::logged()) { |
| 84 | Env::kill('with_soundex'); |
| 85 | } |
| 86 | $qSearch = new QuickSearch('quick'); |
| 87 | $fields = new SFieldGroup(true, array($qSearch)); |
| 88 | if ($qSearch->isEmpty()) { |
| 89 | new ThrowError('Recherche trop générale.'); |
| 90 | } |
| 91 | parent::__construct($fields->get_select_statement() . ' ' . $globals->search->result_where_statement, |
| 92 | $fields->get_where_statement() . |
| 93 | (S::logged() && Env::has('nonins') ? ' AND u.perms="pending" AND u.deces=0' : '')); |
| 94 | |
| 95 | $this->order = implode(',',array_filter(array($fields->get_order_statement(), |
| 96 | 'u.promo DESC, NomSortKey, prenom'))); |
| 97 | } |
| 98 | |
| 99 | private function getAdvanced() |
| 100 | { |
| 101 | global $globals; |
| 102 | $fields = new SFieldGroup(true, advancedSearchFromInput()); |
| 103 | if ($fields->too_large()) { |
| 104 | new ThrowError('Recherche trop générale.'); |
| 105 | } |
| 106 | parent::__construct($fields->get_select_statement() . ' ' . $globals->search->result_where_statement, |
| 107 | $fields->get_where_statement()); |
| 108 | $this->order = implode(',',array_filter(array($fields->get_order_statement(), |
| 109 | 'promo DESC, NomSortKey, prenom'))); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | class MinificheView extends MultipageView |
| 114 | { |
| 115 | public function __construct(PlSet &$set, $data, array $params) |
| 116 | { |
| 117 | require_once 'applis.func.inc.php'; |
| 118 | global $globals; |
| 119 | $this->entriesPerPage = $globals->search->per_page; |
| 120 | $this->order = explode(',', Env::v('order', 'nom,prenom,promo')); |
| 121 | parent::__construct($set, $data, $params); |
| 122 | } |
| 123 | |
| 124 | public function fields() |
| 125 | { |
| 126 | return "u.user_id AS id, |
| 127 | u.*, a.alias AS forlife, |
| 128 | u.perms != 'pending' AS inscrit, |
| 129 | u.perms != 'pending' AS wasinscrit, |
| 130 | u.deces != 0 AS dcd, u.deces, u.matricule_ax, |
| 131 | FIND_IN_SET('femme', u.flags) AS sexe, |
| 132 | e.entreprise, es.label AS secteur, ef.fonction_fr AS fonction, |
| 133 | IF(n.nat='',n.pays,n.nat) AS nat, n.a2 AS iso3166, |
| 134 | ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type, |
| 135 | ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type, |
| 136 | adr.city, gp.a2, gp.pays AS countrytxt, gr.name AS region, |
| 137 | IF(u.nom_usage<>'',u.nom_usage,u.nom) AS sortkey, |
| 138 | COUNT(em.email) > 0 AS actif" . (S::logged() ? ", c.contact AS contact" : ''); |
| 139 | } |
| 140 | |
| 141 | public function joins() |
| 142 | { |
| 143 | return ($this->set instanceof SearchSet ? "" : |
| 144 | "LEFT JOIN entreprises AS e ON (e.entrid = 0 AND e.uid = u.user_id) |
| 145 | LEFT JOIN emploi_secteur AS es ON (e.secteur = es.id) |
| 146 | LEFT JOIN fonctions_def AS ef ON (e.fonction = ef.id) |
| 147 | LEFT JOIN geoloc_pays AS n ON (u.nationalite = n.a2) |
| 148 | LEFT JOIN applis_ins AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0) |
| 149 | LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid) |
| 150 | LEFT JOIN applis_ins AS ai1 ON (u.user_id = ai1.uid AND ai1.ordre = 1) |
| 151 | LEFT JOIN applis_def AS ad1 ON (ad1.id = ai1.aid) |
| 152 | LEFT JOIN adresses AS adr ON (u.user_id = adr.uid |
| 153 | AND FIND_IN_SET('active', adr.statut)) |
| 154 | LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2) |
| 155 | LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region) |
| 156 | LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = 'active') |
| 157 | ") . (S::logged() ? |
| 158 | "LEFT JOIN contacts AS c On (c.contact = u.user_id AND c.uid = " . S::v('uid') . ")" |
| 159 | : ""); |
| 160 | } |
| 161 | |
| 162 | public function templateName() |
| 163 | { |
| 164 | return 'include/plview.minifiche.tpl'; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | class TrombiView extends MultipageView |
| 169 | { |
| 170 | public function __construct(PlSet &$set, $data, array $params) |
| 171 | { |
| 172 | $this->entriesPerPage = 24; |
| 173 | $this->order = explode(',', Env::v('order', 'nom,prenom,promo')); |
| 174 | parent::__construct($set, $data, $params); |
| 175 | } |
| 176 | |
| 177 | public function fields() |
| 178 | { |
| 179 | return "u.user_id, IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo, a.alias AS forlife "; |
| 180 | } |
| 181 | |
| 182 | public function joins() |
| 183 | { |
| 184 | return "INNER JOIN photo AS p ON (p.uid = u.user_id) "; |
| 185 | } |
| 186 | |
| 187 | public function templateName() |
| 188 | { |
| 189 | return 'include/plview.trombi.tpl'; |
| 190 | } |
| 191 | |
| 192 | public function apply(PlatalPage &$page) |
| 193 | { |
| 194 | if (!empty($GLOBALS['IS_XNET_SITE'])) { |
| 195 | global $globals; |
| 196 | $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/'); |
| 197 | } |
| 198 | return parent::apply($page); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | class GeolocView implements PlView |
| 203 | { |
| 204 | private $set; |
| 205 | private $type; |
| 206 | private $params; |
| 207 | |
| 208 | public function __construct(PlSet &$set, $data, array $params) |
| 209 | { |
| 210 | $this->params = $params; |
| 211 | $this->set =& $set; |
| 212 | $this->type = $data; |
| 213 | } |
| 214 | |
| 215 | private function use_map() |
| 216 | { |
| 217 | return is_file(dirname(__FILE__) . '/../modules/geoloc/dynamap.swf') && |
| 218 | is_file(dirname(__FILE__) . '/../modules/geoloc/icon.swf'); |
| 219 | } |
| 220 | |
| 221 | private function make_qs($urlencode = true) |
| 222 | { |
| 223 | $qs = ""; |
| 224 | foreach ($_GET as $v=>$a) { |
| 225 | if ($v != 'initfile' && $v != 'n' && $v != 'mapid') { |
| 226 | if (!$urlencode) { |
| 227 | $qs .= $v . '=' . $a . '&'; |
| 228 | } else { |
| 229 | $qs .= urlencode($v) . '=' . urlencode($a) . '&'; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | return $qs; |
| 234 | } |
| 235 | |
| 236 | public function apply(PlatalPage &$page) |
| 237 | { |
| 238 | require_once 'geoloc.inc.php'; |
| 239 | require_once '../modules/search/search.inc.php'; |
| 240 | |
| 241 | switch ($this->type) { |
| 242 | case 'icon.swf': |
| 243 | header("Content-type: application/x-shockwave-flash"); |
| 244 | header("Pragma:"); |
| 245 | readfile(dirname(__FILE__).'/../modules/geoloc/icon.swf'); |
| 246 | exit; |
| 247 | |
| 248 | case 'dynamap.swf': |
| 249 | header("Content-type: application/x-shockwave-flash"); |
| 250 | header("Pragma:"); |
| 251 | readfile(dirname(__FILE__).'/../modules/geoloc/dynamap.swf'); |
| 252 | exit; |
| 253 | |
| 254 | case 'init': |
| 255 | $page->changeTpl('geoloc/init.tpl', NO_SKIN); |
| 256 | header('Content-Type: text/xml'); |
| 257 | header('Pragma:'); |
| 258 | if (!empty($GLOBALS['IS_XNET_SITE'])) { |
| 259 | $page->assign('background', 0xF2E9D0); |
| 260 | } |
| 261 | $page->assign('querystring', $this->make_qs()); |
| 262 | break; |
| 263 | |
| 264 | case 'city': |
| 265 | $page->changeTpl('geoloc/city.tpl', NO_SKIN); |
| 266 | header('Content-Type: text/xml'); |
| 267 | header('Pragma:'); |
| 268 | $it =& $this->set->get('u.user_id AS id, u.prenom, u.nom, u.promo, al.alias', |
| 269 | "INNER JOIN adresses AS adrf ON (adrf.uid = u.user_id) |
| 270 | LEFT JOIN aliases AS al ON (u.user_id = al.id |
| 271 | AND FIND_IN_SET(al.flags, 'bestalias')) |
| 272 | INNER JOIN adresses AS av ON (" . getadr_join('av') . ")", |
| 273 | 'adrf.cityid = ' . Env::i('cityid'), null, null, 11); |
| 274 | $page->assign('users', $it); |
| 275 | break; |
| 276 | |
| 277 | case 'country': |
| 278 | if (Env::has('debug')) { |
| 279 | $page->changeTpl('geoloc/country.tpl', SIMPLE); |
| 280 | } else { |
| 281 | $page->changeTpl('geoloc/country.tpl', NO_SKIN); |
| 282 | header('Content-Type: text/xml'); |
| 283 | header('Pragma:'); |
| 284 | } |
| 285 | $querystring = $this->make_qs(); |
| 286 | $page->assign('searchvars', $querystring); |
| 287 | $mapid = Env::has('mapid') ? Env::i('mapid', -2) : false; |
| 288 | list($countries, $cities) = geoloc_getData_subcountries($mapid, $this->set, 10); |
| 289 | $page->assign('countries', $countries); |
| 290 | $page->assign('cities', $cities); |
| 291 | break; |
| 292 | |
| 293 | default: |
| 294 | global $globals; |
| 295 | if (!$this->use_map()) { |
| 296 | $page->assign('request_geodesix', true); |
| 297 | } |
| 298 | if (!empty($GLOBALS['IS_XNET_SITE'])) { |
| 299 | $page->assign('no_annu', true); |
| 300 | } |
| 301 | $page->assign('protocole', @$_SERVER['HTTPS'] ? 'https' : 'http'); |
| 302 | $this->set->get('u.user_id', null, "u.perms != 'pending' AND u.deces = 0", "u.user_id", null); |
| 303 | $url = '?' . $this->make_qs(false); |
| 304 | $page->assign('search_nourlencode', $url); |
| 305 | $page->assign('search', urlencode($url)); |
| 306 | return 'include/plview.geoloc.tpl'; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 312 | ?> |