Displays the possible multiple nationalities.
[platal.git] / include / userset.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 n1 ON (u.nationalite = n1.a2)
36 LEFT JOIN geoloc_pays AS n2 ON (u.nationalite2 = n2.a2)
37 LEFT JOIN geoloc_pays AS n3 ON (u.nationalite2 = n3.a2)
38 LEFT JOIN adresses AS adr ON (u.user_id = adr.uid AND FIND_IN_SET(\'active\',adr.statut))
39 LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2)
40 LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region)
41 LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = \'active\')';
42
43 class UserSet extends PlSet
44 {
45 public function __construct($joins = '', $where = '')
46 {
47 global $globals;
48 parent::__construct('auth_user_md5 AS u',
49 (!empty($GLOBALS['IS_XNET_SITE']) ?
50 'INNER JOIN groupex.membres AS gxm ON (u.user_id = gxm.uid
51 AND gxm.asso_id = ' . $globals->asso('id') . ') ' : '')
52 . 'LEFT JOIN auth_user_quick AS q USING (user_id)
53 LEFT JOIN aliases AS a ON (a.id = u.user_id AND a.type = \'a_vie\')
54 ' . $joins,
55 $where,
56 'u.user_id');
57 }
58 }
59
60 class SearchSet extends UserSet
61 {
62 public $advanced = false;
63 private $score = null;
64 private $order = null;
65 private $quick = false;
66
67 public function __construct($quick = false, $no_search = false, $join = '', $where = '')
68 {
69 require_once dirname(__FILE__).'/../modules/search/search.inc.php';
70
71 if ($no_search) {
72 return;
73 }
74
75 $this->quick = $quick;
76 if ($quick) {
77 $this->getQuick($join, $where);
78 } else {
79 $this->getAdvanced($join, $where);
80 }
81 }
82
83 private function getQuick($join, $where)
84 {
85 require_once dirname(__FILE__).'/../modules/search/search.inc.php';
86 global $globals;
87 if (!S::logged()) {
88 Env::kill('with_soundex');
89 }
90 $qSearch = new QuickSearch('quick');
91 $fields = new SFieldGroup(true, array($qSearch));
92 if ($qSearch->isEmpty()) {
93 new ThrowError('Aucun critère de recherche n\'est spécifié.');
94 }
95 $this->score = $qSearch->get_score_statement();
96 $pwhere = $fields->get_where_statement();
97 if (trim($pwhere)) {
98 if (trim($where)) {
99 $where .= ' AND ';
100 }
101 $where .= $pwhere;
102 }
103 if (S::logged() && Env::has('nonins')) {
104 if (trim($where)) {
105 $where .= ' AND ';
106 }
107 $where .= 'u.perms="pending" AND u.deces=0';
108 }
109 parent::__construct($join . ' ' . $fields->get_select_statement(), $where);
110
111 $this->order = implode(',',array_filter(array($fields->get_order_statement(),
112 'u.promo DESC, NomSortKey, prenom')));
113 }
114
115 private function getAdvanced($join, $where)
116 {
117 global $globals;
118 $this->advanced = true;
119 $fields = new SFieldGroup(true, advancedSearchFromInput());
120 if ($fields->too_large()) {
121 new ThrowError('Recherche trop générale.');
122 }
123 parent::__construct(@$join . ' ' . $fields->get_select_statement(),
124 @$where . ' ' . $fields->get_where_statement());
125 $this->order = implode(',',array_filter(array($fields->get_order_statement(),
126 'promo DESC, NomSortKey, prenom')));
127 }
128
129 public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null, $limitfrom = null)
130 {
131 if ($this->score) {
132 $fields .= ', ' . $this->score;
133 }
134 return parent::get($fields, $joins, $where, $groupby, $order, $limitcount, $limitfrom);
135 }
136 }
137
138 class ArraySet extends UserSet
139 {
140 public function __construct(array $users)
141 {
142 $where = $this->getUids($users);
143 if ($where) {
144 $where = "a.alias IN ($where)";
145 } else {
146 $where = " 0 ";
147 }
148 parent::__construct('', $where);
149 }
150
151 private function getUids(array $users)
152 {
153 $users = get_users_forlife_list($users, true, '_silent_user_callback');
154 if (is_null($users)) {
155 return '';
156 }
157 return '\'' . implode('\', \'', $users) . '\'';
158 }
159 }
160
161 class MinificheView extends MultipageView
162 {
163 public function __construct(PlSet &$set, $data, array $params)
164 {
165 require_once 'applis.func.inc.php';
166 global $globals;
167 $this->entriesPerPage = $globals->search->per_page;
168 if (@$params['with_score']) {
169 $this->addSortKey('score', array('-score', '-date', '-promo', 'name_sort'), 'pertinence');
170 }
171 $this->addSortKey('name', array('name_sort'), 'nom');
172 $this->addSortKey('promo', array('-promo', 'name_sort'), 'promotion');
173 $this->addSortKey('date_mod', array('-date', '-promo', 'name_sort'), 'dernière modification');
174 parent::__construct($set, $data, $params);
175 }
176
177 public function fields()
178 {
179 return "u.user_id AS id,
180 u.*, a.alias AS forlife,
181 u.perms != 'pending' AS inscrit,
182 u.perms != 'pending' AS wasinscrit,
183 u.deces != 0 AS dcd, u.deces, u.matricule_ax,
184 FIND_IN_SET('femme', u.flags) AS sexe,
185 e.entreprise, es.label AS secteur, ef.fonction_fr AS fonction,
186 IF(n1.nat='',n1.pays,n1.nat) AS nat1, n1.a2 AS iso3166_1,
187 IF(n2.nat='',n2.pays,n2.nat) AS nat2, n2.a2 AS iso3166_2,
188 IF(n3.nat='',n3.pays,n3.nat) AS nat3, n3.a2 AS iso3166_3,
189 ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type,
190 ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type,
191 adr.city, gp.a2, gp.pays AS countrytxt, gr.name AS region,
192 (COUNT(em.email) > 0 OR FIND_IN_SET('googleapps', u.mail_storage) > 0) AS actif,
193 nd.display AS name_display, nd.tooltip AS name_tooltip, nd.sort AS name_sort" .
194 (S::logged() ? ", c.contact AS contact" : '');
195 }
196
197 public function joins()
198 {
199 return "LEFT JOIN entreprises AS e ON (e.entrid = 0 AND e.uid = u.user_id".(S::logged() ? "" : " AND e.pub = 'public'").")
200 LEFT JOIN emploi_secteur AS es ON (e.secteur = es.id)
201 LEFT JOIN fonctions_def AS ef ON (e.fonction = ef.id)
202 LEFT JOIN geoloc_pays AS n1 ON (u.nationalite = n1.a2)
203 LEFT JOIN geoloc_pays AS n2 ON (u.nationalite2 = n2.a2)
204 LEFT JOIN geoloc_pays AS n3 ON (u.nationalite3 = n3.a2)
205 LEFT JOIN applis_ins AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0)
206 LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid)
207 LEFT JOIN applis_ins AS ai1 ON (u.user_id = ai1.uid AND ai1.ordre = 1)
208 LEFT JOIN applis_def AS ad1 ON (ad1.id = ai1.aid)
209 LEFT JOIN adresses AS adr ON (u.user_id = adr.uid
210 AND FIND_IN_SET('active', adr.statut)".(S::logged() ? "" : " AND adr.pub = 'public'").")
211 LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2)
212 LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region)
213 LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = 'active')
214 INNER JOIN profile_names_display AS nd ON (nd.user_id = u.user_id)" .
215 (S::logged() ?
216 "LEFT JOIN contacts AS c On (c.contact = u.user_id AND c.uid = " . S::v('uid') . ")"
217 : "");
218 }
219
220 public function templateName()
221 {
222 return 'include/plview.minifiche.tpl';
223 }
224 }
225
226 class MentorView extends MultipageView
227 {
228 public function __construct(PlSet &$set, $data, array $params)
229 {
230 $this->entriesPerPage = 10;
231 $this->addSortKey('rand', array('RAND(' . S::i('uid') . ')'), 'aléatoirement');
232 $this->addSortKey('name', array('name_sort'), 'nom');
233 $this->addSortKey('promo', array('-promo', 'name_sort'), 'promotion');
234 $this->addSortKey('date_mod', array('-date', '-promo', 'name_sort'), 'dernière modification');
235 parent::__construct($set, $data, $params);
236 }
237
238 public function fields()
239 {
240 return "m.uid, u.promo,
241 a.alias AS bestalias, m.expertise, mp.pid,
242 ms.secteur, ms.ss_secteur,
243 nd.display AS name_display, nd.tooltip AS name_tooltip, nd.sort AS name_sort";
244 }
245
246 public function joins()
247 {
248 return "INNER JOIN profile_names_display AS nd ON (nd.user_id = u.user_id)";
249 }
250
251 public function templateName()
252 {
253 return 'include/plview.referent.tpl';
254 }
255 }
256
257 class TrombiView extends MultipageView
258 {
259 public function __construct(PlSet &$set, $data, array $params)
260 {
261 $this->entriesPerPage = 24;
262 $this->order = explode(',', Env::v('order', 'name_sort'));
263 if (@$params['with_score']) {
264 $this->addSortKey('score', array('-score', '-watch_last', '-promo', 'name_sort'), 'pertinence');
265 }
266 $this->addSortKey('name', array('name_sort'), 'nom');
267 $this->addSortKey('promo', array('-promo', 'name_sort'), 'promotion');
268 parent::__construct($set, $data, $params);
269 }
270
271 public function fields()
272 {
273 return "u.user_id, nd.display AS name_display, nd.tooltip AS name_tooltip, nd.sort AS name_sort, u.promo, a.alias AS forlife ";
274 }
275
276 public function joins()
277 {
278 return "INNER JOIN photo AS p ON (p.uid = u.user_id)
279 INNER JOIN profile_names_display AS nd ON (nd.user_id = u.user_id)";
280 }
281
282 public function templateName()
283 {
284 return 'include/plview.trombi.tpl';
285 }
286
287 public function apply(PlatalPage &$page)
288 {
289 if (!empty($GLOBALS['IS_XNET_SITE'])) {
290 global $globals;
291 $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/');
292 }
293 return parent::apply($page);
294 }
295 }
296
297 class GeolocView implements PlView
298 {
299 private $set;
300 private $type;
301 private $params;
302
303 public function __construct(PlSet &$set, $data, array $params)
304 {
305 $this->params = $params;
306 $this->set =& $set;
307 $this->type = $data;
308 }
309
310 private function use_map()
311 {
312 return is_file(dirname(__FILE__) . '/../modules/geoloc/dynamap.swf') &&
313 is_file(dirname(__FILE__) . '/../modules/geoloc/icon.swf');
314 }
315
316 public function args()
317 {
318 $args = $this->set->args();
319 unset($args['initfile']);
320 unset($args['mapid']);
321 return $args;
322 }
323
324 public function apply(PlatalPage &$page)
325 {
326 require_once 'geoloc.inc.php';
327 require_once '../modules/search/search.inc.php';
328
329 switch ($this->type) {
330 case 'icon.swf':
331 header("Content-type: application/x-shockwave-flash");
332 header("Pragma:");
333 readfile(dirname(__FILE__).'/../modules/geoloc/icon.swf');
334 exit;
335
336 case 'dynamap.swf':
337 header("Content-type: application/x-shockwave-flash");
338 header("Pragma:");
339 readfile(dirname(__FILE__).'/../modules/geoloc/dynamap.swf');
340 exit;
341
342 case 'init':
343 $page->changeTpl('geoloc/init.tpl', NO_SKIN);
344 header('Content-Type: text/xml');
345 header('Pragma:');
346 if (!empty($GLOBALS['IS_XNET_SITE'])) {
347 $page->assign('background', 0xF2E9D0);
348 }
349 break;
350
351 case 'city':
352 $page->changeTpl('geoloc/city.tpl', NO_SKIN);
353 header('Content-Type: text/xml');
354 header('Pragma:');
355 $only_current = Env::v('only_current', false)? ' AND FIND_IN_SET(\'active\', adrf.statut)' : '';
356 $it =& $this->set->get('u.user_id AS id, u.prenom, u.nom, u.promo, al.alias',
357 "INNER JOIN adresses AS adrf ON (adrf.uid = u.user_id $only_current)
358 LEFT JOIN aliases AS al ON (u.user_id = al.id
359 AND FIND_IN_SET('bestalias', al.flags))
360 INNER JOIN adresses AS avg ON (" . getadr_join('avg') . ")",
361 'adrf.cityid = ' . Env::i('cityid'), null, null, 11);
362 $page->assign('users', $it);
363 break;
364
365 case 'country':
366 if (Env::has('debug')) {
367 $page->changeTpl('geoloc/country.tpl', SIMPLE);
368 } else {
369 $page->changeTpl('geoloc/country.tpl', NO_SKIN);
370 header('Content-Type: text/xml');
371 header('Pragma:');
372 }
373 $mapid = Env::has('mapid') ? Env::i('mapid', -2) : false;
374 list($countries, $cities) = geoloc_getData_subcountries($mapid, $this->set, 10);
375 $page->assign('countries', $countries);
376 $page->assign('cities', $cities);
377 break;
378
379 default:
380 global $globals;
381 if (!$this->use_map()) {
382 $page->assign('request_geodesix', true);
383 }
384 $page->assign('annu', @$this->params['with_annu']);
385 $page->assign('protocole', @$_SERVER['HTTPS'] ? 'https' : 'http');
386 $this->set->get('u.user_id', null, "u.perms != 'pending' AND u.deces = 0", "u.user_id", null);
387 return 'include/plview.geoloc.tpl';
388 }
389 }
390 }
391
392 class GadgetView implements PlView
393 {
394 public function __construct(PlSet &$set, $data, array $params)
395 {
396 $this->set =& $set;
397 }
398
399 public function fields()
400 {
401 return "u.user_id AS id,
402 u.*, a.alias AS forlife," .
403 "u.perms != 'pending' AS inscrit,
404 u.perms != 'pending' AS wasinscrit,
405 u.deces != 0 AS dcd, u.deces,
406 FIND_IN_SET('femme', u.flags) AS sexe,
407 adr.city, gp.a2, gp.pays AS countrytxt, gr.name AS region" .
408 (S::logged() ? ", c.contact AS contact" : '');
409 }
410
411 public function joins()
412 {
413 return "LEFT JOIN adresses AS adr ON (u.user_id = adr.uid AND FIND_IN_SET('active', adr.statut)".(S::logged() ? "" : " AND adr.pub = 'public'").")
414 LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2)
415 LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region)" .
416 (S::logged() ?
417 "LEFT JOIN contacts AS c On (c.contact = u.user_id AND c.uid = " . S::v('uid') . ")"
418 : "");
419 }
420
421 public function apply(PlatalPage &$page)
422 {
423 $page->assign_by_ref('set',
424 $this->set->get($this->fields(), $this->joins(), null, null, null, 5, 0));
425 }
426
427 public function args()
428 {
429 return null;
430 }
431 }
432
433 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
434 ?>