Commit | Line | Data |
---|---|---|
8c4a0c30 | 1 | <?php |
2 | /*************************************************************************** | |
ba6ae046 | 3 | * Copyright (C) 2003-2013 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 | class UserSet extends PlSet |
23 | { | |
26ba053e | 24 | public function __construct(PlFilterCondition $cond, $orders = null) |
8c4a0c30 | 25 | { |
8e720253 | 26 | parent::__construct($cond, $orders); |
76cbe885 FB |
27 | } |
28 | ||
26ba053e | 29 | protected function buildFilter(PlFilterCondition $cond, $orders) |
76cbe885 | 30 | { |
8e720253 | 31 | return new UserFilter($cond, $orders); |
8c4a0c30 | 32 | } |
33 | } | |
34 | ||
a7d9ab89 RB |
35 | class ProfileSet extends PlSet |
36 | { | |
26ba053e | 37 | public function __construct(PlFilterCondition $cond, $orders = null) |
a7d9ab89 RB |
38 | { |
39 | parent::__construct($cond, $orders); | |
40 | } | |
41 | ||
26ba053e | 42 | protected function buildFilter(PlFilterCondition $cond, $orders) |
a7d9ab89 RB |
43 | { |
44 | return new ProfileFilter($cond, $orders); | |
45 | } | |
46 | } | |
47 | ||
78a47eb4 RB |
48 | require_once "ufbuilder.inc.php"; |
49 | ||
a7d9ab89 | 50 | class SearchSet extends ProfileSet |
8c4a0c30 | 51 | { |
78a47eb4 RB |
52 | protected $score = null; |
53 | protected $valid = true; | |
8c4a0c30 | 54 | |
26ba053e | 55 | public function __construct(UserFilterBuilder $ufb, PlFilterCondition $cond = null) |
8c4a0c30 | 56 | { |
8e720253 | 57 | if (is_null($cond)) { |
8eb6931f | 58 | $conds = new PFC_And(); |
8e720253 | 59 | } else if ($cond instanceof PFC_And) { |
8eb6931f | 60 | $conds = $cond; |
8e720253 | 61 | } else { |
8eb6931f | 62 | $conds = new PFC_And($cond); |
8e720253 RB |
63 | } |
64 | ||
8e720253 | 65 | if (!$ufb->isValid()) { |
51fcda84 | 66 | $this->valid = false; |
8e720253 | 67 | return; |
3b2f9d11 | 68 | } |
8e720253 | 69 | |
3314838e | 70 | $ufc = $ufb->getUFC(); |
8eb6931f | 71 | $conds->addChild($ufc); |
8e720253 RB |
72 | |
73 | $orders = $ufb->getOrders(); | |
8e720253 | 74 | |
8eb6931f | 75 | parent::__construct($conds, $orders); |
8c4a0c30 | 76 | } |
77 | ||
78a47eb4 | 78 | public function isValid() |
8c4a0c30 | 79 | { |
78a47eb4 | 80 | return $this->valid; |
8c4a0c30 | 81 | } |
35fa92e8 | 82 | |
5c4b28bb RB |
83 | /** Add a "rechercher=Chercher" field to the query to simulate the POST |
84 | * behaviour. | |
85 | */ | |
86 | public function args() | |
87 | { | |
88 | $args = parent::args(); | |
89 | if (!isset($args['rechercher'])) { | |
90 | $args['rechercher'] = 'Chercher'; | |
91 | } | |
92 | return $args; | |
93 | } | |
94 | ||
26ba053e | 95 | protected function &getFilterResults(PlFilter $pf, PlLimit $limit) |
35fa92e8 | 96 | { |
d667c548 SJ |
97 | $profiles = $pf->getProfiles($limit, Profile::FETCH_MINIFICHES); |
98 | return $profiles; | |
35fa92e8 | 99 | } |
8c4a0c30 | 100 | } |
101 | ||
78a47eb4 RB |
102 | // Specialized SearchSet for quick search. |
103 | class QuickSearchSet extends SearchSet | |
104 | { | |
105 | public function __construct(PlFilterCondition $cond = null) | |
106 | { | |
107 | if (!S::logged()) { | |
108 | Env::kill('with_soundex'); | |
109 | } | |
110 | ||
111 | parent::__construct(new UFB_QuickSearch(), $cond); | |
112 | } | |
113 | } | |
114 | ||
115 | // Specialized SearchSet for advanced search. | |
116 | class AdvancedSearchSet extends SearchSet | |
117 | { | |
0f567f55 RB |
118 | public function __construct($xorg_admin_fields, $ax_admin_fields, |
119 | PlFilterCondition $cond = null) | |
78a47eb4 | 120 | { |
0f567f55 RB |
121 | parent::__construct(new UFB_AdvancedSearch($xorg_admin_fields, $ax_admin_fields), |
122 | $cond); | |
78a47eb4 RB |
123 | } |
124 | } | |
125 | ||
83d6305f | 126 | /** Simple set based on an array of User emails |
8eb6931f | 127 | */ |
83d6305f | 128 | class UserArraySet extends UserSet |
1cc0afe7 | 129 | { |
83d6305f | 130 | public function __construct(array $emails) |
1cc0afe7 | 131 | { |
83d6305f | 132 | parent::__construct(new UFC_Email($emails)); |
1cc0afe7 | 133 | } |
134 | } | |
135 | ||
83d6305f RB |
136 | /** Simple set based on an array of Profile emails |
137 | */ | |
138 | class ProfileArraySet extends ProfileSet | |
139 | { | |
140 | public function __construct(array $emails) | |
141 | { | |
142 | parent::__construct(new UFC_Email($emails)); | |
143 | } | |
144 | } | |
145 | ||
146 | ||
db1c9df5 | 147 | /** A multipage view for profiles or users |
8eb6931f RB |
148 | * Allows the display of bounds when sorting by name or promo. |
149 | */ | |
db1c9df5 | 150 | abstract class MixedView extends MultipageView |
169edfac RB |
151 | { |
152 | protected function getBoundValue($obj) | |
153 | { | |
154 | if ($obj instanceof Profile) { | |
155 | switch ($this->bound_field) { | |
156 | case 'name': | |
157 | $name = $obj->name('%l'); | |
158 | return strtoupper($name); | |
159 | case 'promo': | |
160 | return $obj->promo(); | |
161 | default: | |
162 | return null; | |
163 | } | |
db1c9df5 RB |
164 | } elseif ($obj instanceof User) { |
165 | switch ($this->bound_field) { | |
166 | case 'name': | |
167 | $name = $obj->lastName(); | |
168 | return strtoupper($name); | |
169 | case 'promo': | |
170 | if ($obj->hasProfile()) { | |
171 | return $obj->profile()->promo(); | |
172 | } else { | |
173 | return 'ext'; | |
174 | } | |
175 | default: | |
176 | return null; | |
177 | } | |
169edfac RB |
178 | } |
179 | return null; | |
180 | } | |
316120eb FB |
181 | |
182 | public function bounds() | |
183 | { | |
184 | $order = Env::v('order', $this->defaultkey); | |
185 | $show_bounds = 0; | |
186 | if (($order == "name") || ($order == "-name")) { | |
187 | $this->bound_field = "name"; | |
188 | $show_bounds = 1; | |
189 | } elseif (($order == "promo") || ($order == "-promo")) { | |
190 | $this->bound_field = "promo"; | |
191 | $show_bounds = -1; | |
192 | } | |
193 | if ($order{0} == '-') { | |
194 | $show_bounds = -$show_bounds; | |
195 | } | |
196 | return $show_bounds; | |
197 | } | |
169edfac RB |
198 | } |
199 | ||
8eb6931f RB |
200 | /** An extended multipage view for profiles, as minifiches. |
201 | * Allows to sort by: | |
202 | * - score (for a search query) | |
203 | * - name | |
204 | * - promo | |
205 | * - latest modification | |
206 | * | |
207 | * Paramaters for this view are: | |
208 | * - with_score: whether to allow ordering by score (set only for a quick search) | |
209 | * - starts_with: show only names beginning with the given letter | |
210 | */ | |
db1c9df5 | 211 | class MinificheView extends MixedView |
8c4a0c30 | 212 | { |
26ba053e | 213 | public function __construct(PlSet $set, array $params) |
8c4a0c30 | 214 | { |
8c4a0c30 | 215 | global $globals; |
216 | $this->entriesPerPage = $globals->search->per_page; | |
35fa92e8 | 217 | if (@$params['with_score']) { |
8e720253 RB |
218 | $this->addSort(new PlViewOrder('score', array( |
219 | new UFO_Score(true), | |
220 | new UFO_ProfileUpdate(true), | |
221 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 222 | new UFO_Name(), |
8e720253 | 223 | ), 'pertinence')); |
35fa92e8 | 224 | } |
8e720253 RB |
225 | $this->addSort(new PlViewOrder( |
226 | 'name', | |
1a074f45 | 227 | array(new UFO_Name()), |
8e720253 RB |
228 | 'nom')); |
229 | $this->addSort(new PlViewOrder('promo', array( | |
230 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 231 | new UFO_Name(), |
8e720253 RB |
232 | ), 'promotion')); |
233 | $this->addSort(new PlViewOrder('date_mod', array( | |
234 | new UFO_ProfileUpdate(true), | |
235 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 236 | new UFO_Name(), |
8e720253 | 237 | ), 'dernière modification')); |
8eb6931f RB |
238 | parent::__construct($set, $params); |
239 | } | |
240 | ||
26ba053e | 241 | public function apply(PlPage $page) |
8eb6931f RB |
242 | { |
243 | if (array_key_exists('starts_with', $this->params) | |
244 | && $this->params['starts_with'] != "" | |
245 | && $this->params['starts_with'] != null) { | |
246 | ||
247 | $this->set->addCond( | |
3e6ab778 | 248 | new UFC_NameInitial($this->params['starts_with']) |
8eb6931f RB |
249 | ); |
250 | } | |
251 | return parent::apply($page); | |
8c4a0c30 | 252 | } |
253 | ||
8c4a0c30 | 254 | public function templateName() |
255 | { | |
256 | return 'include/plview.minifiche.tpl'; | |
257 | } | |
258 | } | |
259 | ||
db1c9df5 | 260 | class MentorView extends MixedView |
ff3eb9b7 | 261 | { |
26ba053e | 262 | public function __construct(PlSet $set, array $params) |
ff3eb9b7 | 263 | { |
eaf30d86 | 264 | $this->entriesPerPage = 10; |
8e720253 | 265 | $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement')); |
1a074f45 | 266 | $this->addSort(new PlViewOrder('name', array(new UFO_Name()), 'nom')); |
8e720253 RB |
267 | $this->addSort(new PlViewOrder('promo', array( |
268 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 269 | new UFO_Name(), |
8e720253 RB |
270 | ), 'promotion')); |
271 | $this->addSort(new PlViewOrder('date_mod', array( | |
272 | new UFO_ProfileUpdate(true), | |
273 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 274 | new UFO_Name(), |
8e720253 | 275 | ), 'dernière modification')); |
8eb6931f | 276 | parent::__construct($set, $params); |
ff3eb9b7 | 277 | } |
278 | ||
ff3eb9b7 | 279 | public function templateName() |
280 | { | |
281 | return 'include/plview.referent.tpl'; | |
282 | } | |
283 | } | |
284 | ||
db1c9df5 | 285 | class GroupMemberView extends MixedView |
4b866888 RB |
286 | { |
287 | public function __construct(PlSet $set, array $params) | |
288 | { | |
289 | $this->entriesPerPage = 20; | |
1a074f45 | 290 | $this->addSort(new PlViewOrder('name', array(new UFO_Name()), 'nom')); |
4b866888 RB |
291 | $this->addSort(new PlViewOrder('promo', array( |
292 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 293 | new UFO_Name(), |
4b866888 | 294 | ), 'promotion')); |
a15c3cc3 SJ |
295 | $this->addSort(new PlViewOrder('date_mod', array( |
296 | new UFO_ProfileUpdate(true), | |
297 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 298 | new UFO_Name(), |
a15c3cc3 | 299 | ), 'dernière modification')); |
4b866888 RB |
300 | parent::__construct($set, $params); |
301 | } | |
302 | ||
303 | public function templateName() | |
304 | { | |
83d6305f RB |
305 | return 'include/plview.groupmember.tpl'; |
306 | } | |
307 | } | |
308 | ||
db1c9df5 | 309 | class ListMemberView extends MixedView |
83d6305f RB |
310 | { |
311 | public function __construct(PlSet $set, array $params) | |
312 | { | |
313 | $this->entriesPerPage = 100; | |
1a074f45 | 314 | $this->addSort(new PlViewOrder('name', array(new UFO_Name()), 'nom')); |
83d6305f RB |
315 | $this->addSort(new PlViewOrder('promo', array( |
316 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 317 | new UFO_Name(), |
83d6305f RB |
318 | ), 'promotion')); |
319 | parent::__construct($set, $params); | |
320 | } | |
321 | ||
322 | public function templateName() | |
323 | { | |
324 | return 'include/plview.listmember.tpl'; | |
4b866888 RB |
325 | } |
326 | } | |
327 | ||
db1c9df5 | 328 | class TrombiView extends MixedView |
027b16e3 | 329 | { |
43a42485 SJ |
330 | private $full_count; |
331 | ||
027b16e3 RB |
332 | public function __construct(PlSet $set, array $params) |
333 | { | |
43a42485 SJ |
334 | $set->getIds(); |
335 | $this->full_count = $set->count(); | |
336 | ||
027b16e3 RB |
337 | $this->entriesPerPage = 24; |
338 | $this->defaultkey = 'name'; | |
339 | if (@$params['with_score']) { | |
340 | $this->addSort(new PlViewOrder('score', array( | |
341 | new UFO_Score(true), | |
342 | new UFO_ProfileUpdate(true), | |
343 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 344 | new UFO_Name(), |
027b16e3 RB |
345 | ), 'pertinence')); |
346 | } | |
347 | $set->addCond(new UFC_Photo()); | |
1a074f45 | 348 | $this->addSort(new PlViewOrder('name', array(new UFO_Name()), 'nom')); |
027b16e3 RB |
349 | $this->addSort(new PlViewOrder('promo', array( |
350 | new UFO_Promo(UserFilter::DISPLAY, true), | |
1a074f45 | 351 | new UFO_Name(), |
027b16e3 RB |
352 | ), 'promotion')); |
353 | parent::__construct($set, $params); | |
354 | } | |
355 | ||
356 | public function templateName() | |
357 | { | |
358 | return 'include/plview.trombi.tpl'; | |
359 | } | |
360 | ||
361 | public function apply(PlPage $page) | |
362 | { | |
363 | if (!empty($GLOBALS['IS_XNET_SITE'])) { | |
364 | global $globals; | |
365 | $page->assign('mainsiteurl', 'https://' . $globals->core->secure_domain . '/'); | |
366 | } | |
43a42485 | 367 | $page->assign('full_count', $this->full_count); |
027b16e3 RB |
368 | return parent::apply($page); |
369 | } | |
370 | } | |
371 | ||
0a928a2f SJ |
372 | class MapView implements PlView |
373 | { | |
374 | private $set; | |
375 | ||
376 | public function __construct(PlSet $set, array $params) | |
377 | { | |
378 | $this->set = $set; | |
379 | } | |
380 | ||
381 | public function apply(PlPage $page) | |
382 | { | |
383 | Platal::load('geoloc'); | |
384 | ||
385 | if (Get::b('ajax')) { | |
386 | $pids = $this->set->getIds(new PlLimit()); | |
387 | GeolocModule::assign_json_to_map($page, $pids); | |
388 | $page->runJSON(); | |
389 | exit; | |
390 | } else { | |
391 | $this->set->getIds(new PlLimit()); | |
392 | GeolocModule::prepare_map($page); | |
393 | return 'geoloc/index.tpl'; | |
394 | } | |
395 | } | |
396 | ||
397 | public function args() | |
398 | { | |
399 | return $this->set->args(); | |
400 | } | |
401 | } | |
402 | ||
92e80560 VZ |
403 | class GadgetView implements PlView |
404 | { | |
26ba053e | 405 | public function __construct(PlSet $set, array $params) |
92e80560 VZ |
406 | { |
407 | $this->set =& $set; | |
408 | } | |
409 | ||
26ba053e | 410 | public function apply(PlPage $page) |
92e80560 | 411 | { |
8e720253 | 412 | $page->assign_by_ref('set', $this->set->get(new PlLimit(5, 0))); |
92e80560 VZ |
413 | } |
414 | ||
415 | public function args() | |
416 | { | |
417 | return null; | |
418 | } | |
419 | } | |
420 | ||
39394cbf SJ |
421 | class AddressesView implements PlView |
422 | { | |
423 | private $set; | |
424 | ||
26ba053e | 425 | public function __construct(PlSet $set, array $params) |
39394cbf SJ |
426 | { |
427 | $this->set =& $set; | |
428 | } | |
429 | ||
67369757 RB |
430 | /* Convert a single address field into 3 lines. |
431 | */ | |
432 | public static function split_address($address) | |
433 | { | |
434 | $lines = preg_split("/(\r|\n)+/", $address, -1, PREG_SPLIT_NO_EMPTY); | |
435 | $nb_lines = count($lines); | |
436 | switch ($nb_lines) { | |
437 | case 0: | |
438 | // No data => nothing | |
439 | return array("", "", ""); | |
440 | case 1: | |
441 | // Single line => Assume it's city+zipcode | |
442 | $line = $lines[0]; | |
443 | return array("", "", $line); | |
444 | case 2: | |
445 | // Two lines => Assume it's street \n city | |
446 | $line1 = $lines[0]; | |
447 | $line3 = $lines[1]; | |
448 | return array($line1, "", $line3); | |
449 | case 3: | |
450 | return $lines; | |
451 | default: | |
452 | // More than 3 lines => Keep 2 last intact, merge other lines. | |
453 | $line3 = array_pop($lines); | |
454 | $line2 = array_pop($lines); | |
455 | $line1 = implode(" ", $lines); | |
456 | return array($line1, $line2, $line3); | |
457 | } | |
458 | } | |
459 | ||
26ba053e | 460 | public function apply(PlPage $page) |
39394cbf | 461 | { |
1319b09e | 462 | $pids = $this->set->getIds(new PlLimit()); |
22771578 | 463 | $visibility = Visibility::defaultForRead(Visibility::VIEW_AX); |
47712f77 | 464 | pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1, 'adresses.csv'); |
39394cbf SJ |
465 | |
466 | $csv = fopen('php://output', 'w'); | |
67369757 RB |
467 | fputcsv($csv, |
468 | array('PROMOTION', 'CIVILITE', 'NOM', 'PRENOM', 'SOCIETE', 'ADRESSE', 'ADRESSE1', 'ADRESSE2', 'ADRESSE3', 'CP', 'EMAIL'), | |
469 | ';'); | |
470 | ||
235e0e23 | 471 | if (!empty($pids)) { |
76231b0e SJ |
472 | $res = XDB::query("SELECT pd.promo, p.title, |
473 | IF (pn.firstname_ordinary = '', UPPER(pn.firstname_main), UPPER(pn.firstname_ordinary)) AS firstname, | |
474 | IF (pn.lastname_ordinary = '', UPPER(pn.lastname_main), UPPER(pn.lastname_ordinary)) AS lastname, | |
e44d8688 | 475 | UPPER(pje.name), pa.postalText, pa.postal_code_fr AS postal_code, p.email_directory |
0782ce75 SJ |
476 | FROM profile_addresses AS pa |
477 | INNER JOIN profiles AS p ON (pa.pid = p.pid) | |
478 | INNER JOIN profile_display AS pd ON (pd.pid = pa.pid) | |
479 | INNER JOIN profile_public_names AS pn ON (pn.pid = pa.pid) | |
480 | LEFT JOIN profile_job AS pj ON (pj.pid = pa.pid | |
481 | AND pj.id = IF(pa.type = 'job', pa.id, NULL)) | |
482 | LEFT JOIN profile_job_enum AS pje ON (pj.jobid = pje.id) | |
483 | WHERE pa.pid IN {?} AND FIND_IN_SET('ax_mail', pa.flags)", $pids); | |
67369757 RB |
484 | foreach ($res->fetchAllRow() as $item) { |
485 | list($promo, $title, $lastname, $firstname, $company, $full_address, $zipcode, $email) = array_map('utf8_decode', $item); | |
486 | $lines = self::split_address($full_address); | |
487 | fputcsv($csv, | |
488 | array($promo, $title, $lastname, $firstname, $company, $full_address, $lines[0], $lines[1], $lines[2], $zipcode, $email), | |
489 | ';'); | |
235e0e23 | 490 | } |
39394cbf SJ |
491 | } |
492 | fclose($csv); | |
493 | exit(); | |
494 | } | |
495 | ||
496 | public function args() | |
497 | { | |
498 | return $this->set->args(); | |
499 | } | |
500 | } | |
501 | ||
e6a2c4d5 FB |
502 | class JSonView implements PlView |
503 | { | |
504 | private $set; | |
b1ae686e | 505 | private $params; |
e6a2c4d5 FB |
506 | |
507 | public function __construct(PlSet $set, array $params) | |
508 | { | |
b1ae686e FB |
509 | $this->set = $set; |
510 | $this->params = $params; | |
e6a2c4d5 FB |
511 | } |
512 | ||
513 | public function apply(PlPage $page) | |
514 | { | |
515 | $export = array(); | |
b1ae686e FB |
516 | $start = isset($this->params['offset']) ? $this->params['offset'] : 0; |
517 | $count = isset($this->params['count']) ? $this->params['count'] : 10; | |
518 | $profiles = $this->set->get(new PlLimit($start, $count)); | |
aaffb7b2 | 519 | foreach ($profiles as $profile) { |
e6a2c4d5 FB |
520 | $export[] = $profile->export(); |
521 | } | |
aaffb7b2 | 522 | $page->jsonAssign('profile_count', $this->set->count()); |
e6a2c4d5 FB |
523 | $page->jsonAssign('profiles', $export); |
524 | } | |
525 | ||
526 | public function args() | |
527 | { | |
528 | return $this->set->args(); | |
529 | } | |
530 | } | |
531 | ||
8c4a0c30 | 532 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
533 | ?> |