Commit | Line | Data |
---|---|---|
8c4a0c30 | 1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 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 | 22 | require_once('user.func.inc.php'); |
23 | ||
24 | global $globals; | |
25 | ||
e4cd7a1f SJ |
26 | @$globals->search->result_where_statement = " |
27 | LEFT JOIN profile_education AS edu ON (u.user_id = edu.uid) | |
28 | LEFT JOIN profile_education_enum AS ede ON (ede.id = edu.eduid) | |
29 | LEFT JOIN profile_job AS j ON (j.id = 0 AND j.uid = u.user_id) | |
30 | LEFT JOIN profile_job_enum AS je ON (je.id = j.jobid) | |
31 | LEFT JOIN profile_job_sector_enum AS es ON (j.sectorid = es.id) | |
32 | LEFT JOIN fonctions_def AS ef ON (j.functionid = ef.id) | |
33 | LEFT JOIN geoloc_countries AS n1 ON (u.nationalite = n1.iso_3166_1_a2) | |
34 | LEFT JOIN geoloc_countries AS n2 ON (u.nationalite2 = n2.iso_3166_1_a2) | |
35 | LEFT JOIN geoloc_countries AS n3 ON (u.nationalite2 = n3.iso_3166_1_a2) | |
36 | LEFT JOIN profile_addresses AS adr ON (u.user_id = adr.pid | |
37 | AND FIND_IN_SET('current', adr.flags)) | |
38 | LEFT JOIN geoloc_countries AS gc ON (adr.countryId = gc.iso_3166_1_a2) | |
39 | LEFT JOIN geoloc_administrativeareas AS gr ON (adr.countryId = gr.country | |
40 | AND adr.administrativeAreaId = gr.id) | |
41 | LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = 'active')"; | |
8c4a0c30 | 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', | |
eaf30d86 PH |
49 | (!empty($GLOBALS['IS_XNET_SITE']) ? |
50 | 'INNER JOIN groupex.membres AS gxm ON (u.user_id = gxm.uid | |
8c4a0c30 | 51 | AND gxm.asso_id = ' . $globals->asso('id') . ') ' : '') |
7773d125 | 52 | . 'LEFT JOIN auth_user_quick AS q USING (user_id)' . $joins, |
8c4a0c30 | 53 | $where, |
54 | 'u.user_id'); | |
55 | } | |
56 | } | |
57 | ||
58 | class 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 | { |
adb07f6f | 67 | Platal::load('search', 'search.inc.php'); |
8c4a0c30 | 68 | if ($no_search) { |
69 | return; | |
70 | } | |
71 | ||
72 | $this->quick = $quick; | |
73 | if ($quick) { | |
a2aa8436 | 74 | $this->getQuick($join, $where); |
8c4a0c30 | 75 | } else { |
a2aa8436 | 76 | $this->getAdvanced($join, $where); |
8c4a0c30 | 77 | } |
78 | } | |
79 | ||
a2aa8436 | 80 | private function getQuick($join, $where) |
8c4a0c30 | 81 | { |
adb07f6f | 82 | Platal::load('search', 'search.inc.php'); |
8c4a0c30 | 83 | global $globals; |
84 | if (!S::logged()) { | |
85 | Env::kill('with_soundex'); | |
86 | } | |
87 | $qSearch = new QuickSearch('quick'); | |
88 | $fields = new SFieldGroup(true, array($qSearch)); | |
89 | if ($qSearch->isEmpty()) { | |
8d118e58 | 90 | new ThrowError('Aucun critère de recherche n\'est spécifié.'); |
8c4a0c30 | 91 | } |
35fa92e8 | 92 | $this->score = $qSearch->get_score_statement(); |
3b2f9d11 | 93 | $pwhere = $fields->get_where_statement(); |
94 | if (trim($pwhere)) { | |
95 | if (trim($where)) { | |
96 | $where .= ' AND '; | |
97 | } | |
98 | $where .= $pwhere; | |
99 | } | |
100 | if (S::logged() && Env::has('nonins')) { | |
101 | if (trim($where)) { | |
102 | $where .= ' AND '; | |
103 | } | |
104 | $where .= 'u.perms="pending" AND u.deces=0'; | |
105 | } | |
106 | parent::__construct($join . ' ' . $fields->get_select_statement(), $where); | |
8c4a0c30 | 107 | |
108 | $this->order = implode(',',array_filter(array($fields->get_order_statement(), | |
109 | 'u.promo DESC, NomSortKey, prenom'))); | |
110 | } | |
111 | ||
63fac48e | 112 | private function getAdvanced($join, $where) |
8c4a0c30 | 113 | { |
114 | global $globals; | |
86b5c8f0 | 115 | $this->advanced = true; |
8c4a0c30 | 116 | $fields = new SFieldGroup(true, advancedSearchFromInput()); |
117 | if ($fields->too_large()) { | |
118 | new ThrowError('Recherche trop générale.'); | |
119 | } | |
137e819f FB |
120 | parent::__construct(@$join . ' ' . $fields->get_select_statement(), |
121 | @$where . ' ' . $fields->get_where_statement()); | |
8c4a0c30 | 122 | $this->order = implode(',',array_filter(array($fields->get_order_statement(), |
123 | 'promo DESC, NomSortKey, prenom'))); | |
124 | } | |
35fa92e8 | 125 | |
126 | public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null, $limitfrom = null) | |
127 | { | |
128 | if ($this->score) { | |
129 | $fields .= ', ' . $this->score; | |
130 | } | |
131 | return parent::get($fields, $joins, $where, $groupby, $order, $limitcount, $limitfrom); | |
132 | } | |
8c4a0c30 | 133 | } |
134 | ||
1cc0afe7 | 135 | class ArraySet extends UserSet |
136 | { | |
137 | public function __construct(array $users) | |
138 | { | |
139 | $where = $this->getUids($users); | |
140 | if ($where) { | |
7586ae0b | 141 | $where = "u.hruid IN ($where)"; |
1cc0afe7 | 142 | } else { |
143 | $where = " 0 "; | |
144 | } | |
145 | parent::__construct('', $where); | |
146 | } | |
147 | ||
148 | private function getUids(array $users) | |
149 | { | |
4f25bc90 | 150 | $users = User::getBulkHruid($users, array('User', '_silent_user_callback')); |
1cc0afe7 | 151 | if (is_null($users)) { |
152 | return ''; | |
153 | } | |
154 | return '\'' . implode('\', \'', $users) . '\''; | |
155 | } | |
156 | } | |
157 | ||
8c4a0c30 | 158 | class MinificheView extends MultipageView |
159 | { | |
160 | public function __construct(PlSet &$set, $data, array $params) | |
161 | { | |
f711b03f | 162 | require_once 'education.func.inc.php'; |
8c4a0c30 | 163 | global $globals; |
164 | $this->entriesPerPage = $globals->search->per_page; | |
35fa92e8 | 165 | if (@$params['with_score']) { |
013dc429 | 166 | $this->addSortKey('score', array('-score', '-date', '-d.promo', 'sort_name'), 'pertinence'); |
35fa92e8 | 167 | } |
dd6fce1e | 168 | $this->addSortKey('name', array('sort_name'), 'nom'); |
013dc429 SJ |
169 | $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion'); |
170 | $this->addSortKey('date_mod', array('-date', '-d.promo', 'sort_name'), 'dernière modification'); | |
8c4a0c30 | 171 | parent::__construct($set, $data, $params); |
172 | } | |
173 | ||
174 | public function fields() | |
175 | { | |
7773d125 | 176 | global $globals; |
d1319488 | 177 | return "u.user_id AS id, u.*, d.promo, |
abc50010 | 178 | CONCAT(a.alias, '@{$globals->mail->domain}') AS bestemail, |
8c4a0c30 | 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, | |
541e8d03 | 183 | je.name AS entreprise, je.url AS job_web, es.name AS sector, ef.fonction_fr AS fonction, |
e4cd7a1f SJ |
184 | IF(n1.nat = '', n1.countryFR, n1.nat) AS nat1, n1.iso_3166_1_a2 AS iso3166_1, |
185 | IF(n2.nat = '', n2.countryFR, n2.nat) AS nat2, n2.iso_3166_1_a2 AS iso3166_2, | |
186 | IF(n3.nat = '', n3.countryFR, n3.nat) AS nat3, n3.iso_3166_1_a2 AS iso3166_3, | |
c7eac294 SJ |
187 | IF(ede0.abbreviation = '', ede0.name, ede0.abbreviation) AS eduname0, ede0.url AS eduurl0, |
188 | IF(edd0.abbreviation = '', edd0.degree, edd0.abbreviation) AS edudegree0, | |
1504ac45 | 189 | edu0.grad_year AS edugrad_year0, f0.field AS edufield0, edu0.program AS eduprogram0, |
c7eac294 SJ |
190 | IF(ede1.abbreviation = '', ede1.name, ede1.abbreviation) AS eduname1, ede1.url AS eduurl1, |
191 | IF(edd1.abbreviation = '', edd1.degree, edd1.abbreviation) AS edudegree1, | |
1504ac45 | 192 | edu1.grad_year AS edugrad_year1, f1.field AS edufield1, edu1.program AS eduprogram1, |
c7eac294 SJ |
193 | IF(ede2.abbreviation = '', ede2.name, ede2.abbreviation) AS eduname2, ede2.url AS eduurl2, |
194 | IF(edd2.abbreviation = '', edd2.degree, edd2.abbreviation) AS edudegree2, | |
0b37833b | 195 | edu2.grad_year AS edugrad_year2, f2.field AS edufield2, edu2.program AS eduprogram2, |
c7eac294 SJ |
196 | IF(ede3.abbreviation = '', ede3.name, ede3.abbreviation) AS eduname3, ede3.url AS eduurl3, |
197 | IF(edd3.abbreviation = '', edd3.degree, edd3.abbreviation) AS edudegree3, | |
0b37833b | 198 | edu3.grad_year AS edugrad_year3, f3.field AS edufield3, edu3.program AS eduprogram3, |
d6eb0554 SJ |
199 | "// adr.localityId, gr.name AS region |
200 | . "gc.iso_3166_1_a2, gc.countryFR AS countrytxt | |
cd5bd7dc | 201 | (COUNT(em.email) > 0 OR FIND_IN_SET('googleapps', u.mail_storage) > 0) AS actif, |
dd6fce1e | 202 | d.directory_name, d.sort_name" . |
0e5ec860 | 203 | (S::logged() ? ", c.contact AS contact" : ''); |
8c4a0c30 | 204 | } |
205 | ||
206 | public function joins() | |
207 | { | |
abc50010 | 208 | return "LEFT JOIN aliases AS a ON (u.user_id = a.id AND FIND_IN_SET('bestalias', a.flags)) |
6443c93d | 209 | LEFT JOIN search_name AS n ON (u.user_id = n.uid) |
abc50010 | 210 | LEFT JOIN profile_job AS j ON (j.uid = u.user_id".(S::logged() ? "" : " AND j.pub = 'public'").") |
f9cddbef SJ |
211 | LEFT JOIN profile_job_enum AS je ON (je.id = j.jobid) |
212 | LEFT JOIN profile_job_sector_enum AS es ON (j.sectorid = es.id) | |
213 | LEFT JOIN fonctions_def AS ef ON (j.functionid = ef.id) | |
e4cd7a1f SJ |
214 | LEFT JOIN geoloc_countries AS n1 ON (u.nationalite = n1.iso_3166_1_a2) |
215 | LEFT JOIN geoloc_countries AS n2 ON (u.nationalite2 = n2.iso_3166_1_a2) | |
216 | LEFT JOIN geoloc_countries AS n3 ON (u.nationalite3 = n3.iso_3166_1_a2) | |
043bbacf SJ |
217 | LEFT JOIN profile_education AS edu0 ON (u.user_id = edu0.uid AND edu0.id = 0) |
218 | LEFT JOIN profile_education_enum AS ede0 ON (ede0.id = edu0.eduid) | |
219 | LEFT JOIN profile_education_degree_enum AS edd0 ON (edd0.id = edu0.degreeid) | |
220 | LEFT JOIN profile_education_field_enum AS f0 ON (f0.id = edu0.fieldid) | |
221 | LEFT JOIN profile_education AS edu1 ON (u.user_id = edu1.uid AND edu1.id = 1) | |
222 | LEFT JOIN profile_education_enum AS ede1 ON (ede1.id = edu1.eduid) | |
223 | LEFT JOIN profile_education_degree_enum AS edd1 ON (edd1.id = edu1.degreeid) | |
224 | LEFT JOIN profile_education_field_enum AS f1 ON (f1.id = edu1.fieldid) | |
225 | LEFT JOIN profile_education AS edu2 ON (u.user_id = edu2.uid AND edu2.id = 2) | |
226 | LEFT JOIN profile_education_enum AS ede2 ON (ede2.id = edu2.eduid) | |
227 | LEFT JOIN profile_education_degree_enum AS edd2 ON (edd2.id = edu2.degreeid) | |
228 | LEFT JOIN profile_education_field_enum AS f2 ON (f2.id = edu2.fieldid) | |
229 | LEFT JOIN profile_education AS edu3 ON (u.user_id = edu3.uid AND edu3.id = 3) | |
230 | LEFT JOIN profile_education_enum AS ede3 ON (ede3.id = edu3.eduid) | |
231 | LEFT JOIN profile_education_degree_enum AS edd3 ON (edd3.id = edu3.degreeid) | |
232 | LEFT JOIN profile_education_field_enum AS f3 ON (f3.id = edu3.fieldid) | |
d6eb0554 SJ |
233 | LEFT JOIN profile_addresses AS adr ON (u.user_id = adr.pid |
234 | AND FIND_IN_SET('current', adr.flags)" | |
235 | . (S::logged() ? "" : | |
236 | "AND adr.pub = 'public'") . ") | |
237 | LEFT JOIN geoloc_countries AS gc ON (adr.countryId = gc.iso_3166_a2) | |
e4cd7a1f SJ |
238 | LEFT JOIN geoloc_administrativeareas AS gr ON (adr.countryId = gr.country |
239 | AND adr.administrativeAreaId = gr.id) | |
240 | LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = 'active') | |
d1319488 | 241 | INNER JOIN profile_display AS d ON (d.pid = u.user_id)" . (S::logged() ? |
fb2c09c9 | 242 | "LEFT JOIN contacts AS c ON (c.contact = u.user_id AND c.uid = " . S::v('uid') . ")" |
86b5c8f0 | 243 | : ""); |
8c4a0c30 | 244 | } |
245 | ||
b71b2a36 SJ |
246 | public function bounds() |
247 | { | |
248 | $order = Env::v('order', $this->defaultkey); | |
249 | $show_bounds = 0; | |
250 | if (($order == "name") || ($order == "-name")) { | |
251 | $this->bound_field = "nom"; | |
252 | $show_bounds = 1; | |
253 | } elseif (($order == "promo") || ($order == "-promo")) { | |
254 | $this->bound_field = "promo"; | |
255 | $show_bounds = -1; | |
256 | } | |
257 | if ($order{0} == '-') { | |
258 | $show_bounds = -$show_bounds; | |
259 | } | |
260 | return $show_bounds; | |
261 | } | |
262 | ||
8c4a0c30 | 263 | public function templateName() |
264 | { | |
265 | return 'include/plview.minifiche.tpl'; | |
266 | } | |
267 | } | |
268 | ||
ff3eb9b7 | 269 | class MentorView extends MultipageView |
270 | { | |
271 | public function __construct(PlSet &$set, $data, array $params) | |
272 | { | |
eaf30d86 | 273 | $this->entriesPerPage = 10; |
ff3eb9b7 | 274 | $this->addSortKey('rand', array('RAND(' . S::i('uid') . ')'), 'aléatoirement'); |
dd6fce1e | 275 | $this->addSortKey('name', array('sort_name'), 'nom'); |
013dc429 SJ |
276 | $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion'); |
277 | $this->addSortKey('date_mod', array('-date', '-d.promo', 'sort_name'), 'dernière modification'); | |
eaf30d86 | 278 | parent::__construct($set, $data, $params); |
ff3eb9b7 | 279 | } |
280 | ||
281 | public function fields() | |
282 | { | |
d1319488 | 283 | return "m.uid, d.promo, u.hruid, |
5fecdf6d | 284 | m.expertise, mp.country, ms.sectorid, ms.subsectorid, |
dd6fce1e | 285 | d.directory_name, d.sort_name"; |
cd5bd7dc PC |
286 | } |
287 | ||
288 | public function joins() | |
289 | { | |
dd6fce1e | 290 | return "INNER JOIN profile_display AS d ON (d.pid = u.user_id)"; |
ff3eb9b7 | 291 | } |
292 | ||
b71b2a36 SJ |
293 | public function bounds() |
294 | { | |
295 | $order = Env::v('order', $this->defaultkey); | |
296 | $show_bounds = 0; | |
297 | if (($order == "name") || ($order == "-name")) { | |
298 | $this->bound_field = "nom"; | |
299 | $show_bounds = 1; | |
300 | } elseif (($order == "promo") || ($order == "-promo")) { | |
301 | $this->bound_field = "promo"; | |
302 | $show_bounds = -1; | |
303 | } | |
304 | if ($order{0} == '-') { | |
305 | $show_bounds = -$show_bounds; | |
306 | } | |
307 | return $show_bounds; | |
308 | } | |
309 | ||
ff3eb9b7 | 310 | public function templateName() |
311 | { | |
312 | return 'include/plview.referent.tpl'; | |
313 | } | |
314 | } | |
315 | ||
8c4a0c30 | 316 | class TrombiView extends MultipageView |
317 | { | |
318 | public function __construct(PlSet &$set, $data, array $params) | |
319 | { | |
320 | $this->entriesPerPage = 24; | |
dd6fce1e | 321 | $this->order = explode(',', Env::v('order', 'sort_name')); |
35fa92e8 | 322 | if (@$params['with_score']) { |
013dc429 | 323 | $this->addSortKey('score', array('-score', '-watch_last', '-d.promo', 'sort_name'), 'pertinence'); |
35fa92e8 | 324 | } |
dd6fce1e | 325 | $this->addSortKey('name', array('sort_name'), 'nom'); |
013dc429 | 326 | $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion'); |
8c4a0c30 | 327 | parent::__construct($set, $data, $params); |
328 | } | |
329 | ||
330 | public function fields() | |
331 | { | |
dd6fce1e | 332 | return "u.user_id, d.directory_name, d.sort_name, u.promo, d.promo, u.hruid "; |
8c4a0c30 | 333 | } |
334 | ||
335 | public function joins() | |
336 | { | |
dd6fce1e SJ |
337 | return "INNER JOIN photo AS p ON (p.uid = u.user_id) |
338 | INNER JOIN profile_display AS d ON (d.pid = u.user_id)"; | |
8c4a0c30 | 339 | } |
340 | ||
b71b2a36 SJ |
341 | public function bounds() |
342 | { | |
343 | $order = Env::v('order', $this->defaultkey); | |
344 | $show_bounds = 0; | |
345 | if (($order == "name") || ($order == "-name")) { | |
346 | $this->bound_field = "nom"; | |
347 | $show_bounds = 1; | |
348 | } elseif (($order == "promo") || ($order == "-promo")) { | |
349 | $this->bound_field = "promo"; | |
350 | $show_bounds = -1; | |
351 | } | |
352 | if ($order{0} == '-') { | |
353 | $show_bounds = -$show_bounds; | |
354 | } | |
355 | return $show_bounds; | |
356 | } | |
357 | ||
8c4a0c30 | 358 | public function templateName() |
359 | { | |
360 | return 'include/plview.trombi.tpl'; | |
361 | } | |
362 | ||
04334c61 | 363 | public function apply(PlPage &$page) |
8c4a0c30 | 364 | { |
365 | if (!empty($GLOBALS['IS_XNET_SITE'])) { | |
366 | global $globals; | |
367 | $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/'); | |
368 | } | |
369 | return parent::apply($page); | |
370 | } | |
371 | } | |
372 | ||
92e80560 VZ |
373 | class GadgetView implements PlView |
374 | { | |
375 | public function __construct(PlSet &$set, $data, array $params) | |
376 | { | |
377 | $this->set =& $set; | |
378 | } | |
379 | ||
380 | public function fields() | |
381 | { | |
7773d125 | 382 | return "u.user_id AS id, u.*," . |
92e80560 VZ |
383 | "u.perms != 'pending' AS inscrit, |
384 | u.perms != 'pending' AS wasinscrit, | |
385 | u.deces != 0 AS dcd, u.deces, | |
386 | FIND_IN_SET('femme', u.flags) AS sexe, | |
d6eb0554 SJ |
387 | " // adr.city, gr.name AS region |
388 | . "gc.iso_3166_1_a2, gc.countryFR AS countrytxt" . | |
92e80560 VZ |
389 | (S::logged() ? ", c.contact AS contact" : ''); |
390 | } | |
391 | ||
392 | public function joins() | |
393 | { | |
e4cd7a1f SJ |
394 | return "LEFT JOIN profile_addresses AS adr ON (u.user_id = adr.pid AND |
395 | FIND_IN_SET('current', adr.flags)" | |
396 | . (S::logged() ? "" : "AND adr.pub = 'public'") . ") | |
397 | LEFT JOIN geoloc_countries AS gc ON (adr.countryId = gc.iso_3166_1_a2) | |
398 | LEFT JOIN geoloc_administrativeareas AS gr ON (adr.countryId = gr.country | |
399 | AND adr.administrativeAreaId = gr.id) | |
400 | " . (S::logged() ? | |
401 | "LEFT JOIN contacts AS c ON (c.contact = u.user_id | |
402 | AND c.uid = " . S::v('uid') . ")" : ""); | |
92e80560 VZ |
403 | } |
404 | ||
04334c61 | 405 | public function apply(PlPage &$page) |
92e80560 VZ |
406 | { |
407 | $page->assign_by_ref('set', | |
408 | $this->set->get($this->fields(), $this->joins(), null, null, null, 5, 0)); | |
409 | } | |
410 | ||
411 | public function args() | |
412 | { | |
413 | return null; | |
414 | } | |
415 | } | |
416 | ||
8c4a0c30 | 417 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
418 | ?> |