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