- Refresh user index at registration
[platal.git] / include / userset.inc.php
CommitLineData
8c4a0c30 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
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',
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
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()) {
91 new ThrowError('Recherche trop générale.');
92 }
35fa92e8 93 $this->score = $qSearch->get_score_statement();
a2aa8436 94 parent::__construct($join . ' ' . $fields->get_select_statement(),
95 $where . ' ' . $fields->get_where_statement() .
8c4a0c30 96 (S::logged() && Env::has('nonins') ? ' AND u.perms="pending" AND u.deces=0' : ''));
97
98 $this->order = implode(',',array_filter(array($fields->get_order_statement(),
99 'u.promo DESC, NomSortKey, prenom')));
100 }
101
102 private function getAdvanced()
103 {
104 global $globals;
86b5c8f0 105 $this->advanced = true;
8c4a0c30 106 $fields = new SFieldGroup(true, advancedSearchFromInput());
107 if ($fields->too_large()) {
108 new ThrowError('Recherche trop générale.');
109 }
a2aa8436 110 parent::__construct($join . ' ' . $fields->get_select_statement(),
111 $where . ' ' . $fields->get_where_statement());
8c4a0c30 112 $this->order = implode(',',array_filter(array($fields->get_order_statement(),
113 'promo DESC, NomSortKey, prenom')));
114 }
35fa92e8 115
116 public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null, $limitfrom = null)
117 {
118 if ($this->score) {
119 $fields .= ', ' . $this->score;
120 }
121 return parent::get($fields, $joins, $where, $groupby, $order, $limitcount, $limitfrom);
122 }
8c4a0c30 123}
124
1cc0afe7 125class ArraySet extends UserSet
126{
127 public function __construct(array $users)
128 {
129 $where = $this->getUids($users);
130 if ($where) {
131 $where = "a.alias IN ($where)";
132 } else {
133 $where = " 0 ";
134 }
135 parent::__construct('', $where);
136 }
137
138 private function getUids(array $users)
139 {
140 $users = get_users_forlife_list($users, true, '_silent_user_callback');
141 if (is_null($users)) {
142 return '';
143 }
144 return '\'' . implode('\', \'', $users) . '\'';
145 }
146}
147
8c4a0c30 148class MinificheView extends MultipageView
149{
150 public function __construct(PlSet &$set, $data, array $params)
151 {
152 require_once 'applis.func.inc.php';
153 global $globals;
154 $this->entriesPerPage = $globals->search->per_page;
35fa92e8 155 if (@$params['with_score']) {
acbd9804 156 $this->addSortKey('score', array('-score', '-date', '-promo', 'nom', 'prenom'), 'pertinence');
35fa92e8 157 }
158 $this->addSortKey('name', array('nom', 'prenom'), 'nom');
159 $this->addSortKey('promo', array('-promo', 'nom', 'prenom'), 'promotion');
acbd9804 160 $this->addSortKey('date_mod', array('-date', '-promo', 'nom', 'prenom'), 'dernière modification');
8c4a0c30 161 parent::__construct($set, $data, $params);
162 }
163
164 public function fields()
165 {
166 return "u.user_id AS id,
167 u.*, a.alias AS forlife,
168 u.perms != 'pending' AS inscrit,
169 u.perms != 'pending' AS wasinscrit,
170 u.deces != 0 AS dcd, u.deces, u.matricule_ax,
171 FIND_IN_SET('femme', u.flags) AS sexe,
172 e.entreprise, es.label AS secteur, ef.fonction_fr AS fonction,
173 IF(n.nat='',n.pays,n.nat) AS nat, n.a2 AS iso3166,
174 ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type,
175 ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type,
176 adr.city, gp.a2, gp.pays AS countrytxt, gr.name AS region,
177 IF(u.nom_usage<>'',u.nom_usage,u.nom) AS sortkey,
178 COUNT(em.email) > 0 AS actif" . (S::logged() ? ", c.contact AS contact" : '');
179 }
180
181 public function joins()
182 {
f3af95c0 183 return "LEFT JOIN entreprises AS e ON (e.entrid = 0 AND e.uid = u.user_id".(S::logged() ? "" : " AND e.pub = 'public'").")
8c4a0c30 184 LEFT JOIN emploi_secteur AS es ON (e.secteur = es.id)
185 LEFT JOIN fonctions_def AS ef ON (e.fonction = ef.id)
186 LEFT JOIN geoloc_pays AS n ON (u.nationalite = n.a2)
187 LEFT JOIN applis_ins AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0)
188 LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid)
189 LEFT JOIN applis_ins AS ai1 ON (u.user_id = ai1.uid AND ai1.ordre = 1)
190 LEFT JOIN applis_def AS ad1 ON (ad1.id = ai1.aid)
191 LEFT JOIN adresses AS adr ON (u.user_id = adr.uid
f3af95c0 192 AND FIND_IN_SET('active', adr.statut)".(S::logged() ? "" : " AND adr.pub = 'public'").")
8c4a0c30 193 LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2)
194 LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region)
86b5c8f0 195 LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = 'active')" .
196 (S::logged() ?
197 "LEFT JOIN contacts AS c On (c.contact = u.user_id AND c.uid = " . S::v('uid') . ")"
198 : "");
8c4a0c30 199 }
200
201 public function templateName()
202 {
203 return 'include/plview.minifiche.tpl';
204 }
205}
206
ff3eb9b7 207class MentorView extends MultipageView
208{
209 public function __construct(PlSet &$set, $data, array $params)
210 {
211 $this->entriesPerPage = 10;
212 $this->addSortKey('rand', array('RAND(' . S::i('uid') . ')'), 'aléatoirement');
213 $this->addSortKey('name', array('nom', 'prenom'), 'nom');
214 $this->addSortKey('promo', array('-promo', 'nom', 'prenom'), 'promotion');
acbd9804 215 $this->addSortKey('date_mod', array('-date', '-promo', 'nom', 'prenom'), 'dernière modification');
ff3eb9b7 216 parent::__construct($set, $data, $params);
217 }
218
219 public function fields()
220 {
221 return "m.uid, u.prenom, u.nom, u.promo,
222 a.alias AS bestalias, m.expertise, mp.pid,
223 ms.secteur, ms.ss_secteur";
224 }
225
226 public function templateName()
227 {
228 return 'include/plview.referent.tpl';
229 }
230}
231
8c4a0c30 232class TrombiView extends MultipageView
233{
234 public function __construct(PlSet &$set, $data, array $params)
235 {
236 $this->entriesPerPage = 24;
237 $this->order = explode(',', Env::v('order', 'nom,prenom,promo'));
35fa92e8 238 if (@$params['with_score']) {
239 $this->addSortKey('score', array('-score', '-watch_last', '-promo', 'nom', 'prenom'), 'pertinence');
240 }
241 $this->addSortKey('name', array('nom', 'prenom'), 'nom');
242 $this->addSortKey('promo', array('-promo', 'nom', 'prenom'), 'promotion');
8c4a0c30 243 parent::__construct($set, $data, $params);
244 }
245
246 public function fields()
247 {
248 return "u.user_id, IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo, a.alias AS forlife ";
249 }
250
251 public function joins()
252 {
253 return "INNER JOIN photo AS p ON (p.uid = u.user_id) ";
254 }
255
256 public function templateName()
257 {
258 return 'include/plview.trombi.tpl';
259 }
260
261 public function apply(PlatalPage &$page)
262 {
263 if (!empty($GLOBALS['IS_XNET_SITE'])) {
264 global $globals;
265 $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/');
266 }
267 return parent::apply($page);
268 }
269}
270
271class GeolocView implements PlView
272{
273 private $set;
274 private $type;
275 private $params;
276
277 public function __construct(PlSet &$set, $data, array $params)
278 {
279 $this->params = $params;
280 $this->set =& $set;
281 $this->type = $data;
282 }
283
284 private function use_map()
285 {
286 return is_file(dirname(__FILE__) . '/../modules/geoloc/dynamap.swf') &&
287 is_file(dirname(__FILE__) . '/../modules/geoloc/icon.swf');
288 }
289
35fa92e8 290 public function args()
8c4a0c30 291 {
35fa92e8 292 $args = $this->set->args();
293 unset($args['initfile']);
294 unset($args['mapid']);
295 return $args;
8c4a0c30 296 }
297
298 public function apply(PlatalPage &$page)
299 {
300 require_once 'geoloc.inc.php';
301 require_once '../modules/search/search.inc.php';
302
303 switch ($this->type) {
304 case 'icon.swf':
305 header("Content-type: application/x-shockwave-flash");
306 header("Pragma:");
307 readfile(dirname(__FILE__).'/../modules/geoloc/icon.swf');
308 exit;
309
310 case 'dynamap.swf':
311 header("Content-type: application/x-shockwave-flash");
312 header("Pragma:");
313 readfile(dirname(__FILE__).'/../modules/geoloc/dynamap.swf');
314 exit;
315
316 case 'init':
317 $page->changeTpl('geoloc/init.tpl', NO_SKIN);
318 header('Content-Type: text/xml');
319 header('Pragma:');
320 if (!empty($GLOBALS['IS_XNET_SITE'])) {
321 $page->assign('background', 0xF2E9D0);
322 }
8c4a0c30 323 break;
324
325 case 'city':
326 $page->changeTpl('geoloc/city.tpl', NO_SKIN);
327 header('Content-Type: text/xml');
328 header('Pragma:');
a2aa8436 329 $only_current = Env::v('only_current', false)? ' AND FIND_IN_SET(\'active\', adrf.statut)' : '';
8c4a0c30 330 $it =& $this->set->get('u.user_id AS id, u.prenom, u.nom, u.promo, al.alias',
a2aa8436 331 "INNER JOIN adresses AS adrf ON (adrf.uid = u.user_id $only_current)
8c4a0c30 332 LEFT JOIN aliases AS al ON (u.user_id = al.id
010268b2 333 AND FIND_IN_SET('bestalias', al.flags))
97eff0ff 334 INNER JOIN adresses AS avg ON (" . getadr_join('avg') . ")",
8c4a0c30 335 'adrf.cityid = ' . Env::i('cityid'), null, null, 11);
336 $page->assign('users', $it);
337 break;
338
339 case 'country':
340 if (Env::has('debug')) {
341 $page->changeTpl('geoloc/country.tpl', SIMPLE);
342 } else {
343 $page->changeTpl('geoloc/country.tpl', NO_SKIN);
344 header('Content-Type: text/xml');
345 header('Pragma:');
346 }
8c4a0c30 347 $mapid = Env::has('mapid') ? Env::i('mapid', -2) : false;
348 list($countries, $cities) = geoloc_getData_subcountries($mapid, $this->set, 10);
349 $page->assign('countries', $countries);
350 $page->assign('cities', $cities);
351 break;
352
353 default:
354 global $globals;
355 if (!$this->use_map()) {
356 $page->assign('request_geodesix', true);
357 }
a2aa8436 358 $page->assign('annu', @$this->params['with_annu']);
8c4a0c30 359 $page->assign('protocole', @$_SERVER['HTTPS'] ? 'https' : 'http');
360 $this->set->get('u.user_id', null, "u.perms != 'pending' AND u.deces = 0", "u.user_id", null);
8c4a0c30 361 return 'include/plview.geoloc.tpl';
362 }
363 }
364}
365
366// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
367?>