Logs last use of Auth-Groupe-X keys (Closes #1476).
[platal.git] / include / ufbuilder.inc.php
CommitLineData
d9b3d712
RB
1<?php
2/***************************************************************************
12262f13 3 * Copyright (C) 2003-2011 Polytechnique.org *
d9b3d712
RB
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
e21504a3
RB
22// {{{ class StoredUserFilterBuilder
23class StoredUserFilterBuilder
24{
25 // Possible stored types (currently only 'ufb' exists)
26 const TYPE_UFB = 'ufb';
27
28 protected $ufb;
29 protected $env;
30 protected $ufc;
31
26ba053e 32 public function __construct(UserFilterBuilder $ufb, PlFilterCondition $ufc = null, array $env = array())
e21504a3
RB
33 {
34 $this->ufb = $ufb;
35 $this->ufc = $ufc;
36 $this->env = $env;
37 }
38
39 public function export()
40 {
41 $export = new PlDict();
42 $export->set('type', self::TYPE_UFB);
43 $export->set('condition', $this->ufc->export());
44 $export->set('env', $this->env);
45 return $export;
46 }
47
48 public function getEnv()
49 {
50 return $this->env;
51 }
52
53 public function fillFromExport($export)
54 {
55 $export = new PlDict($export);
56 if (!$export->has('type')) {
57 throw new Exception("Missing 'type' field in export.");
58 }
59 if ($export->s('type') != self::TYPE_UFB) {
60 throw new Exception("Unknown type '$type' in export.");
61 }
62 $this->ufc = UserFilterCondition::fromExport($export->v('condition'));
63 $this->env = $export->v('env', array());
64 }
65
66 public function updateFromEnv($env)
67 {
68 $this->ufb->setFakeEnv($env);
69 if ($this->ufb->isValid()) {
70 $this->env = $env;
71 $this->ufc = $this->ufb->getUFC();
72 return true;
73 } else {
74 $this->ufb->clearFakeEnv();
75 return false;
76 }
77 }
78
79 public function refresh()
80 {
81 if ($this->isValid()) {
82 $this->ufc = $this->ufb->getUFC();
83 }
84 }
85
86 public function getUFC()
87 {
88 return $this->ufc;
89 }
90
91 public function isValid()
92 {
93 $this->ufb->setFakeEnv($this->env);
94 return $this->ufb->isValid();
95 }
96
97 public function isEmpty()
98 {
99 $this->ufb->setFakeEnv($this->env);
100 return $this->ufb->isEmpty();
101 }
102}
103// }}}
104
21b67462 105// {{{ class UserFilterBuilder
d9b3d712
RB
106class UserFilterBuilder
107{
108 private $envprefix;
109 private $fields;
110 private $valid = true;
111 private $ufc = null;
59c6cb70 112 private $orders = array();
e21504a3 113 private $fake_env = null;
d9b3d712
RB
114
115 /** Constructor
116 * @param $fields An array of UFB_Field objects
117 * @param $envprefix Prefix to use for parts of the query
118 */
119 public function __construct($fields, $envprefix = '')
120 {
121 $this->fields = $fields;
122 $this->envprefix = $envprefix;
123 }
124
e21504a3
RB
125 public function setFakeEnv($env)
126 {
127 $this->fake_env = new PlDict($env);
128 }
129
130 public function clearFakeEnv()
131 {
132 $this->fake_env = null;
133 }
134
d9b3d712
RB
135 /** Builds the UFC; returns as soon as a field says it is invalid
136 */
137 private function buildUFC()
138 {
139 if ($this->ufc != null) {
140 return;
141 }
142 $this->ufc = new PFC_And();
143
144 foreach ($this->fields as $field) {
26ba053e 145 $this->valid = $field->apply($this);
d9b3d712
RB
146 if (!$this->valid) {
147 return;
148 }
149 }
150 }
151
26ba053e 152 public function addCond(PlFilterCondition $cond)
d9b3d712
RB
153 {
154 $this->ufc->addChild($cond);
155 }
156
26ba053e 157 public function addOrder(PlFilterOrder $order)
59c6cb70
RB
158 {
159 $this->order[] = $order;
160 }
161
d9b3d712
RB
162 public function isValid()
163 {
164 $this->buildUFC();
165 return $this->valid;
166 }
167
6faa0186
RB
168 public function isEmpty()
169 {
170 $this->buildUFC();
171 foreach ($this->fields as $field) {
172 if (! $field->isEmpty()) {
173 return false;
174 }
175 }
176 return true;
177 }
178
d9b3d712
RB
179 /** Returns the built UFC
180 * @return The UFC, or PFC_False() if an error happened
181 */
3314838e 182 public function getUFC()
d9b3d712
RB
183 {
184 $this->buildUFC();
185 if ($this->valid) {
0476a1e7
RB
186 if ($this->isEmpty()) {
187 return new PFC_True();
188 } else {
189 return $this->ufc;
190 }
d9b3d712
RB
191 } else {
192 return new PFC_False();
193 }
194 }
195
59c6cb70
RB
196 /** Returns adequate orders
197 */
198 public function getOrders()
199 {
200 $this->buildUFC();
201 return $this->orders;
202 }
203
e21504a3
RB
204 public function getEnvFieldNames()
205 {
206 $fields = array();
207 foreach ($this->fields as $ufbf) {
208 $fields = array_merge($fields, $ufbf->getEnvFieldNames());
209 }
210 return array_unique($fields);
211 }
212
213 public function getEnv()
214 {
215 $values = array();
216 foreach ($this->getEnvFieldNames() as $field) {
217 if ($this->has($field)) {
218 $values[$field] = $this->v($field);
219 }
220 }
221 return $values;
222 }
223
224 public function setEnv($values)
225 {
226 foreach ($this->getEnvFieldNames() as $field) {
227 if (array_key_exists($field, $values)) {
228 Env::set($this->envprefix . $field, $values[$field]);
229 }
230 }
231 }
232
d9b3d712
RB
233 /** Wrappers around Env::i/s/..., to add envprefix
234 */
0f17825b
FB
235 public function s($key, $def = '')
236 {
e21504a3
RB
237 if ($this->fake_env) {
238 return $this->fake_env->s($key, $def);
239 } else {
240 return Env::s($this->envprefix . $key, $def);
241 }
0f17825b
FB
242 }
243
244 public function t($key, $def = '')
245 {
e21504a3
RB
246 if ($this->fake_env) {
247 return $this->fake_env->t($key, $def);
248 } else {
249 return Env::t($this->envprefix . $key, $def);
250 }
d9b3d712
RB
251 }
252
0f17825b
FB
253 public function i($key, $def = 0)
254 {
e21504a3
RB
255 if ($this->fake_env) {
256 return $this->fake_env->i($key, $def);
257 } else {
258 return Env::i($this->envprefix . $key, $def);
259 }
d9b3d712
RB
260 }
261
0f17825b
FB
262 public function v($key, $def = null)
263 {
e21504a3
RB
264 if ($this->fake_env) {
265 return $this->fake_env->v($key, $def);
266 } else {
267 return Env::v($this->envprefix . $key, $def);
268 }
d9b3d712
RB
269 }
270
0f17825b
FB
271 public function b($key, $def = false)
272 {
e21504a3
RB
273 if ($this->fake_env) {
274 return $this->fake_env->b($key, $def);
275 } else {
276 return Env::b($this->envprefix . $key, $def);
277 }
0f17825b
FB
278 }
279
280 public function has($key)
281 {
e21504a3
RB
282 if ($this->fake_env) {
283 return $this->fake_env->has($key);
284 } else {
285 return Env::has($this->envprefix . $key);
286 }
0f17825b
FB
287 }
288
289 public function blank($key, $strict = false)
290 {
e21504a3
RB
291 if ($this->fake_env) {
292 return $this->fake_env->blank($key, $strict);
293 } else {
294 return Env::blank($key, $strict);
295 }
d9b3d712 296 }
d9696b0a 297
78be0329
FB
298 public function hasAlnum($key)
299 {
300 $str = $this->s($key);
301 return preg_match('/[a-z0-9]/i', $str);
302 }
303
304 public function hasAlpha($key)
305 {
306 $str = $this->s($key);
307 return preg_match('/[a-z]/i', $str);
308 }
309
0f17825b
FB
310 public function isOn($key)
311 {
312 return $this->has($key) && $this->t($key) == 'on';
d9696b0a 313 }
d9b3d712 314}
21b67462 315// }}}
d9b3d712 316
59c6cb70
RB
317// {{{ class UFB_QuickSearch
318class UFB_QuickSearch extends UserFilterBuilder
319{
320 public function __construct($envprefix = '')
321 {
322 $fields = array(
323 new UFBF_Quick('quick', 'Recherche rapide'),
78a47eb4 324 new UFBF_NotRegistered('nonins', 'Non inscrits'),
59c6cb70
RB
325 );
326 parent::__construct($fields, $envprefix);
327 }
328}
329// }}}
330
21b67462
RB
331// {{{ class UFB_AdvancedSearch
332class UFB_AdvancedSearch extends UserFilterBuilder
333{
0f567f55
RB
334 /** Create a UFB_AdvancedSearch.
335 * @param $include_admin Whether to include 'admin-only' fields
336 * @param $include_ax Whether to include 'ax-only' fields
337 * @param $envprefix Optional prefix for form field names.
338 */
339 public function __construct($include_admin = false, $include_ax = false, $envprefix = '')
21b67462
RB
340 {
341 $fields = array(
342 new UFBF_Name('name', 'Nom'),
e4937ecc
SJ
343 new UFBF_Promo('promo1', 'Promotion', 'egal1', 'edu_type'),
344 new UFBF_Promo('promo2', 'Promotion', 'egal2', 'edu_type'),
21b67462
RB
345 new UFBF_Sex('woman', 'Sexe'),
346 new UFBF_Registered('subscriber', 'Inscrit'),
c10e9a24 347 new UFBF_HasEmailRedirect('has_email_redirect', 'A une redirection active'),
21b67462
RB
348 new UFBF_Dead('alive', 'En vie'),
349
350 new UFBF_Town('city', 'Ville / Code Postal'),
351 new UFBF_Country('countryTxt', 'country', 'Pays'),
86ab1c8f
SJ
352 new UFBF_AdminArea('administrativearea', 'Région'),
353 new UFBF_SubAdminArea('subadministrativearea', 'Département'),
21b67462
RB
354
355 new UFBF_JobCompany('entreprise', 'Entreprise'),
21b67462
RB
356 new UFBF_JobDescription('jobdescription', 'Fonction'),
357 new UFBF_JobCv('cv', 'CV'),
3ac45f10 358 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
21b67462 359
00f25ab1
SJ
360 new UFBF_OriginCorps('origin_corps', 'Corps d\'origine'),
361 new UFBF_CurrentCorps('current_corps', 'Corps actuel'),
362 new UFBF_CorpsRank('corps_rank', 'Grade'),
363
21b67462
RB
364 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
365 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
366 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
367 new UFBF_Section('sectionTxt', 'section', 'Section'),
368
fb3b6547
RB
369 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
370 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
371 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
21b67462
RB
372
373 new UFBF_Comment('free', 'Commentaire'),
3ed7556a
RB
374 new UFBF_Phone('phone_number', 'Téléphone'),
375 new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'),
96f01fba
RB
376
377 new UFBF_Mentor('only_referent', 'Référent'),
21b67462 378 );
0f567f55
RB
379
380 if ($include_admin || $include_ax) {
381 $fields[] = new UFBF_SchoolIds('schoolid_ax', 'Matricule AX', UFC_SchoolId::AX);
382 }
383
21b67462
RB
384 parent::__construct($fields, $envprefix);
385 }
386}
387// }}}
388
6faa0186
RB
389// {{{ class UFB_MentorSearch
390class UFB_MentorSearch extends UserFilterBuilder
391{
392 public function __construct($envprefix = '')
393 {
394 $fields = array(
459e6f81
PC
395 new UFBF_MentorCountry('country'),
396 new UFBF_MentorTerm('jobterm', 'jobtermText'),
6faa0186
RB
397 new UFBF_MentorExpertise('expertise'),
398 );
399 parent::__construct($fields, $envprefix);
400 }
401}
402// }}}
403
e21504a3
RB
404// {{{ class UFB_NewsLetter
405class UFB_NewsLetter extends UserFilterBuilder
406{
407 const FIELDS_PROMO = 'promo';
408 const FIELDS_AXID = 'axid';
409 const FIELDS_GEO = 'geo';
410
411 public function __construct($flags, $envprefix = '')
412 {
413 $fields = array();
414 if ($flags->hasFlag(self::FIELDS_PROMO)) {
415 $fields[] = new UFBF_Promo('promo1', 'Promotion', 'egal1');
416 $fields[] = new UFBF_Promo('promo2', 'Promotion', 'egal2');
417 }
418 if ($flags->hasFlag(self::FIELDS_AXID)) {
419 $fields[] = new UFBF_SchoolIds('axid', 'Matricule AX', UFC_SchoolId::AX);
420 }
421 parent::__construct($fields, $envprefix);
422 }
423}
424// }}}
425
21b67462 426// {{{ class UFB_Field
d9b3d712
RB
427abstract class UFB_Field
428{
429 protected $envfield;
430 protected $formtext;
431
432 protected $empty = false;
433 protected $val = null;
434
435 /** Constructor
436 * @param $envfield Name of the field in the environment
437 * @param $formtext User-friendly name of that field
438 */
439 public function __construct($envfield, $formtext = '')
440 {
441 $this->envfield = $envfield;
442 if ($formtext != '') {
443 $this->formtext = $formtext;
444 } else {
445 $formtext = ucfirst($envfield);
446 }
447 }
448
449 /** Prints the given error message to the user, and returns false
450 * in order to be used as return $this->raise('ERROR');
451 *
452 * All %s in the $msg will be replaced with the formtext.
453 */
454 protected function raise($msg)
455 {
456 Platal::page()->trigError(str_replace('%s', $this->formtext, $msg));
457 return false;
458 }
459
26ba053e 460 public function apply(UserFilterBuilder $ufb) {
d9b3d712
RB
461 if (!$this->check($ufb)) {
462 return false;
463 }
464
1d364832 465 if (!$this->isEmpty()) {
d9b3d712
RB
466 $ufc = $this->buildUFC($ufb);
467 if ($ufc != null) {
468 $ufb->addCond($ufc);
469 }
470 }
471 return true;
472 }
473
6faa0186
RB
474 public function isEmpty()
475 {
476 return $this->empty;
477 }
478
d9b3d712
RB
479 /** Create the UFC associated to the field; won't be called
480 * if the field is "empty"
26ba053e 481 * @param $ufb UFB to which fields must be added
d9b3d712
RB
482 * @return UFC
483 */
26ba053e 484 abstract protected function buildUFC(UserFilterBuilder $ufb);
d9b3d712
RB
485
486 /** This function is intended to run consistency checks on the value
487 * @return boolean Whether the input is valid
488 */
26ba053e 489 abstract protected function check(UserFilterBuilder $ufb);
e21504a3
RB
490
491 // Simple form interface
492
493 /** Retrieve a list of env field names used by that field
494 * their values will be recorded when saving the 'search' and used to prefill the form
495 * when needed.
496 */
497 public function getEnvFieldNames()
498 {
499 return array($this->envfield);
500 }
d9b3d712 501}
21b67462 502// }}}
d9b3d712 503
21b67462 504// {{{ class UFBF_Text
d9b3d712
RB
505abstract class UFBF_Text extends UFB_Field
506{
d9b3d712
RB
507 private $minlength;
508 private $maxlength;
509
f3f800d8 510 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
d9b3d712
RB
511 {
512 parent::__construct($envfield, $formtext);
d9b3d712
RB
513 $this->minlength = $minlength;
514 $this->maxlength = $maxlength;
515 }
516
26ba053e 517 protected function check(UserFilterBuilder $ufb)
d9b3d712 518 {
0f17825b 519 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
520 $this->empty = true;
521 return true;
522 }
523
0f17825b 524 $this->val = $ufb->t($this->envfield);
d9b3d712
RB
525 if (strlen($this->val) < $this->minlength) {
526 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
527 } else if (strlen($this->val) > $this->maxlength) {
528 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
5a0b9531 529 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val)) {
f3f800d8 530 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
d9b3d712 531 }
f3f800d8 532
d9b3d712
RB
533 return true;
534 }
535}
21b67462 536// }}}
d9b3d712 537
21b67462 538// {{{ class UFBF_Range
d9b3d712
RB
539/** Subclass to use for fields which only allow integers within a range
540 */
541abstract class UFBF_Range extends UFB_Field
542{
543
544 private $min;
545 private $max;
546
547 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
548 {
549 parent::__construct($envfield, $formtext);
550 $this->min = $min;
551 $this->max = $max;
552 }
553
26ba053e 554 protected function check(UserFilterBuilder $ufb)
d9b3d712 555 {
0f17825b 556 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
557 $this->empty = true;
558 return true;
559 }
560
561 $this->val = $ufb->i($this->envfield);
562 if ($this->val < $this->min) {
563 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
564 } else if ($this->val > $this->max) {
565 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
566 }
567 return true;
568 }
569}
21b67462 570// }}}
d9b3d712 571
21b67462 572// {{{ class UFBF_Index
d9b3d712
RB
573/** Subclass to use for indexed fields
574 */
575abstract class UFBF_Index extends UFB_Field
576{
26ba053e 577 protected function check(UserFilterBuilder $ufb)
d9b3d712 578 {
0f17825b 579 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
580 $this->empty = true;
581 }
6faa0186 582 $this->val = $ufb->i($this->envfield);
d9b3d712
RB
583 return true;
584 }
585}
21b67462 586// }}}
d9b3d712 587
21b67462 588// {{{ class UFBF_Enum
d9b3d712
RB
589/** Subclass to use for fields whose value must belong to a specific set of values
590 */
591abstract class UFBF_Enum extends UFB_Field
592{
21b67462
RB
593 protected $allowedvalues;
594
595 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false)
d9b3d712
RB
596 {
597 parent::__construct($envfield, $formtext);
598 $this->allowedvalues = $allowedvalues;
21b67462 599 $this->strict = $strict;
d9b3d712
RB
600 }
601
26ba053e 602 protected function check(UserFilterBuilder $ufb)
d9b3d712 603 {
0f17825b 604 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
605 $this->empty = true;
606 return true;
607 }
608
609 $this->val = $ufb->v($this->envfield);
610 if (! in_array($this->val, $this->allowedvalues)) {
21b67462
RB
611 if ($this->strict) {
612 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
613 } else {
614 $this->empty = true;
615 }
d9b3d712
RB
616 }
617 return true;
618 }
619}
21b67462 620// }}}
d9b3d712 621
21b67462
RB
622// {{{ class UFBF_Bool
623abstract class UFBF_Bool extends UFB_Field
d9b3d712 624{
26ba053e 625 protected function check(UserFilterBuilder $ufb)
21b67462 626 {
0f17825b 627 if ($ufb->blank($this->envfield)) {
21b67462
RB
628 $this->empty = true;
629 return true;
630 }
631
0f17825b 632 $this->val = $ufb->b($this->envfield);
21b67462
RB
633 return true;
634 }
635}
636// }}}
d9b3d712 637
21b67462
RB
638// {{{ class UFBF_Mixed
639/** A class for building UFBFs when the user can input either a text or an ID
640 */
641abstract class UFBF_Mixed extends UFB_Field
642{
643 /** Name of the DirEnum on which class is based
644 */
645 protected $direnum;
646
647 protected $envfieldindex;
648
649 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
d9b3d712 650 {
21b67462
RB
651 parent::__construct($envfieldtext, $formtext);
652 $this->envfieldindex = $envfieldindex;
d9b3d712
RB
653 }
654
26ba053e 655 protected function check(UserFilterBuilder $ufb)
d9b3d712 656 {
78be0329 657 if ($ufb->blank($this->envfieldindex) && !$ufb->hasAlnum($this->envfield)) {
21b67462
RB
658 $this->empty = true;
659 return true;
660 }
661
0f17825b 662 if (!$ufb->blank($this->envfieldindex)) {
21b67462
RB
663 $index = $ufb->v($this->envfieldindex);
664 if (is_int($index)) {
665 $index = intval($index);
666 } else {
667 $index = strtoupper($index);
668 }
669 $this->val = array($index);
d9b3d712 670 } else {
aab2ffdd 671 $indexes = DirEnum::getIDs($this->direnum, $ufb->t($this->envfield),
0f17825b 672 $ufb->b('exact') ? XDB::WILDCARD_EXACT : XDB::WILDCARD_CONTAINS);
21b67462
RB
673 if (count($indexes) == 0) {
674 return false;
675 }
676 $this->val = $indexes;
d9b3d712 677 }
21b67462 678 return true;
d9b3d712 679 }
e21504a3
RB
680
681 public function getEnvFieldNames()
682 {
683 return array($this->envfieldindex, $this->envfield);
684 }
d9b3d712 685}
21b67462 686// }}}
d9b3d712 687
f3f800d8 688// {{{ class UFBF_Quick
59c6cb70
RB
689class UFBF_Quick extends UFB_Field
690{
26ba053e 691 protected function check(UserFilterBuilder $ufb)
59c6cb70 692 {
0f17825b 693 if ($ufb->blank($this->envfield)) {
59c6cb70
RB
694 $this->empty = true;
695 return true;
696 }
697
0f17825b 698 $this->val = str_replace('*', '%', replace_accent($ufb->t($this->envfield)));
4b2e2074
RB
699
700 return true;
59c6cb70
RB
701 }
702
26ba053e 703 protected function buildUFC(UserFilterBuilder $ufb)
59c6cb70 704 {
59c6cb70 705
4b2e2074 706 $r = $s = $this->val;
59c6cb70
RB
707
708 /** Admin: Email, IP
709 */
710 if (S::admin() && strpos($s, '@') !== false) {
4b2e2074 711 return new UFC_Email($s);
59c6cb70 712 } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
0c457792 713 return new UFC_Ip($s);
59c6cb70
RB
714 }
715
4b2e2074
RB
716 $conds = new PFC_And();
717
59c6cb70
RB
718 /** Name
719 */
720 $s = preg_replace('!\d+!', ' ', $s);
67c3a227 721 $strings = preg_split("![^a-z%]+!i", $s, -1, PREG_SPLIT_NO_EMPTY);
99e44215
SJ
722 foreach ($strings as $key => $string) {
723 if (strlen($string) < 2) {
724 unset($strings[$key]);
725 }
726 }
59c6cb70
RB
727 if (count($strings) > 5) {
728 Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
729 $strings = array_slice($strings, 0, 5);
730 }
731
732 if (count($strings)) {
d91f8a50 733 if (S::user() != null && S::user()->checkPerms('directory_private')) {
59c6cb70
RB
734 $flags = array();
735 } else {
736 $flags = array('public');
737 }
0f17825b 738 $exact =$ufb->b('exact');
9d590571 739 $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
59c6cb70 740
4b2e2074 741 $ufb->addOrder(new UFO_Score());
59c6cb70
RB
742 }
743
744 /** Promo ranges
745 */
746 $s = preg_replace('! *- *!', '-', $r);
747 $s = preg_replace('!([<>]) *!', ' \1', $s);
67c3a227 748 $s = preg_replace('![^0-9xmd\-><]!i', ' ', $s);
59c6cb70 749 $s = preg_replace('![<>\-] !', '', $s);
936feeaf
SJ
750 $ranges = preg_split('! +!', strtolower($s), -1, PREG_SPLIT_NO_EMPTY);
751 $grades = array('' => UserFilter::GRADE_ING, 'x' => UserFilter::GRADE_ING, 'm' => UserFilter::GRADE_MST, 'd' => UserFilter::GRADE_PHD);
59c6cb70 752 foreach ($ranges as $r) {
67c3a227 753 if (preg_match('!^([xmd]?)(\d{4})$!', $r, $matches)) {
936feeaf 754 $conds->addChild(new UFC_Promo('=', $grades[$matches[1]], $matches[2]));
67c3a227
SJ
755 } elseif (preg_match('!^([xmd]?)(\d{4})-\1(\d{4})$!', $r, $matches)) {
756 $p1 = min(intval($matches[2]), intval($matches[3]));
757 $p2 = max(intval($matches[2]), intval($matches[3]));
758 $conds->addChild(new PFC_And(
759 new UFC_Promo('>=', $grades[$matches[1]], $p1),
760 new UFC_Promo('<=', $grades[$matches[1]], $p2)
761 ));
762 } elseif (preg_match('!^<([xmd]?)(\d{4})!', $r, $matches)) {
936feeaf 763 $conds->addChild(new UFC_Promo('<=', $grades[$matches[1]], $matches[2]));
67c3a227 764 } elseif (preg_match('!^>([xmd]?)(\d{4})!', $r, $matches)) {
936feeaf 765 $conds->addChild(new UFC_Promo('>=', $grades[$matches[1]], $matches[2]));
59c6cb70
RB
766 }
767 }
768
769 /** Phone number
770 */
67c3a227 771 $t = preg_replace('!([xmd]?\d{4}-|>|<|)[xmd]?\d{4}!i', '', $s);
59c6cb70 772 $t = preg_replace('![<>\- ]!', '', $t);
67c3a227 773 if (strlen($t) > 4) {
59c6cb70
RB
774 $conds->addChild(new UFC_Phone($t));
775 }
776
777 return $conds;
778 }
779}
780// }}}
781
0f567f55
RB
782// {{{ class UFBF_SchoolIds
783class UFBF_SchoolIds extends UFB_Field
784{
785 // One of UFC_SchoolId types
786 protected $type;
e21504a3
RB
787 protected $reversed_envfield;
788 protected $reversed = false;
0f567f55 789
e21504a3 790 public function __construct($envfield, $formtext, $type = UFC_SchoolId::AX, $reversed_envfield = '')
0f567f55
RB
791 {
792 parent::__construct($envfield, $formtext);
793 $this->type = $type;
e21504a3
RB
794 if ($reversed_envfield == '') {
795 $reversed_envfield = $envfield . '_reversed';
796 }
797 $this->reversed_envfield = $reversed_envfield;
0f567f55
RB
798 }
799
26ba053e 800 protected function check(UserFilterBuilder $ufb)
0f567f55
RB
801 {
802 if ($ufb->blank($this->envfield)) {
803 $this->empty = true;
804 return true;
805 }
806
807 $value = $ufb->t($this->envfield);
91b9255b 808 $values = explode("\r\n", $value);
0f567f55
RB
809 $ids = array();
810 foreach ($values as $val) {
811 if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) {
812 $ids[] = $val;
813 }
814 }
815 if (count($ids) == 0) {
816 return $this->raise("Le champ %s ne contient aucune valeur valide.");
817 }
818
e21504a3 819 $this->reversed = $ufb->b($this->reversed_envfield);
0f567f55
RB
820 $this->val = $ids;
821 return true;
822 }
823
26ba053e 824 protected function buildUFC(UserFilterBuilder $ufb)
0f567f55 825 {
e21504a3
RB
826 $ufc = new UFC_SchoolId($this->type, $this->val);
827 if ($this->reversed) {
828 return new PFC_Not($ufc);
829 } else {
830 return $ufc;
831 }
0f567f55
RB
832 }
833}
834// }}}
835
21b67462
RB
836// {{{ class UFBF_Name
837class UFBF_Name extends UFBF_Text
838{
26ba053e 839 protected function check(UserFilterBuilder $ufb)
21b67462
RB
840 {
841 if (!parent::check($ufb)) {
842 return false;
843 }
844
5ed1cce8
RB
845 require_once 'name.func.inc.php';
846
847 $this->val = split_name_for_search($this->val);
21b67462
RB
848 if (count($this->val) == 0) {
849 $this->empty = true;
850 }
851 return true;
852 }
853
26ba053e 854 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 855 {
0f17825b 856 return new UFC_NameTokens($this->val, array(), $ufb->b('with_soundex'), $ufb->b('exact'));
21b67462
RB
857 }
858}
859// }}}
860
861// {{{ class UFBF_Promo
d9b3d712
RB
862class UFBF_Promo extends UFB_Field
863{
864 private static $validcomps = array('<', '<=', '=', '>=', '>');
e4937ecc 865 private static $validtypes = array(UserFilter::GRADE_ING, UserFilter::GRADE_PHD, UserFilter::GRADE_MST);
d9b3d712 866 private $comp;
e4937ecc 867 private $type;
d9b3d712 868 private $envfieldcomp;
e4937ecc 869 private $envfieldtype;
d9b3d712 870
e4937ecc 871 public function __construct($envfield, $formtext = '', $envfieldcomp, $envfieldtype)
d9b3d712 872 {
e21504a3 873 parent::__construct($envfield, $formtext);
d9b3d712 874 $this->envfieldcomp = $envfieldcomp;
e4937ecc 875 $this->envfieldtype = $envfieldtype;
d9b3d712
RB
876 }
877
26ba053e 878 protected function check(UserFilterBuilder $ufb)
d9b3d712 879 {
e4937ecc 880 if ($ufb->blank($this->envfield) || $ufb->blank($this->envfieldcomp) || $ufb->blank($this->envfieldtype)) {
d9b3d712
RB
881 $this->empty = true;
882 return true;
883 }
884
9e6b7376
RB
885 $this->val = $ufb->i($this->envfield);
886 $this->comp = $ufb->v($this->envfieldcomp);
e4937ecc
SJ
887 $this->type = $ufb->v($this->envfieldtype);
888
889 if (!in_array($this->type, self::$validtypes)) {
890 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
891 }
d9b3d712
RB
892
893 if (!in_array($this->comp, self::$validcomps)) {
894 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
895 }
896
897 if (preg_match('/^[0-9]{2}$/', $this->val)) {
898 $this->val += 1900;
899 }
900 if ($this->val < 1900 || $this->val > 9999) {
901 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
902 }
903 return true;
904 }
905
26ba053e 906 protected function buildUFC(UserFilterBuilder $ufb) {
e4937ecc 907 return new UFC_Promo($this->comp, $this->type, $this->val);
d9b3d712 908 }
e21504a3
RB
909
910 public function getEnvFieldNames()
911 {
e4937ecc 912 return array($this->envfield, $this->envfieldcomp, $this->envfieldtype);
e21504a3 913 }
d9b3d712 914}
21b67462
RB
915// }}}
916
917// {{{ class UFBF_Sex
918class UFBF_Sex extends UFBF_Enum
919{
920 public function __construct($envfield, $formtext = '')
921 {
922 parent::__construct($envfield, $formtext, array(1, 2));
923 }
924
925 private static function getVal($id)
926 {
927 switch($id) {
928 case 1:
929 return User::GENDER_MALE;
930 break;
931 case 2:
932 return User::GENDER_FEMALE;
933 break;
934 }
935 }
936
26ba053e 937 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
938 {
939 return new UFC_Sex(self::getVal($this->val));
940 }
941}
942// }}}
943
78a47eb4
RB
944// {{{ class UFBF_NotRegistered
945// Simple field for selecting only alive, not registered users (for quick search)
946class UFBF_NotRegistered extends UFBF_Bool
947{
26ba053e 948 protected function buildUFC(UserFilterBuilder $ufb)
78a47eb4
RB
949 {
950 if ($this->val) {
951 return new PFC_And(
952 new PFC_Not(new UFC_Dead()),
953 new PFC_Not(new UFC_Registered())
954 );
955 }
956 }
957}
958// }}}
959
21b67462
RB
960// {{{ class UFBF_Registered
961class UFBF_Registered extends UFBF_Enum
962{
963 public function __construct($envfield, $formtext = '')
964 {
965 parent::__construct($envfield, $formtext, array(1, 2));
966 }
967
26ba053e 968 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
969 {
970 if ($this->val == 1) {
971 return new UFC_Registered();
972 } else if ($this->val == 2) {
e637cb69 973 return new PFC_Not(new UFC_Registered());
21b67462
RB
974 }
975 }
976}
977// }}}
d9b3d712 978
c10e9a24
SJ
979// {{{ class UFBF_HasEmailRedirect
980class UFBF_HasEmailRedirect extends UFBF_Enum
981{
982 public function __construct($envfield, $formtext = '')
983 {
984 parent::__construct($envfield, $formtext, array(1, 2));
985 }
986
987 protected function buildUFC(UserFilterBuilder $ufb)
988 {
989 if ($this->val == 1) {
990 return new UFC_HasEmailRedirect();
991 } else if ($this->val == 2) {
992 return new PFC_Not(new UFC_HasEmailRedirect());
993 }
994 }
995}
996// }}}
997
21b67462
RB
998// {{{ class UFBF_Dead
999class UFBF_Dead extends UFBF_Enum
1000{
1001 public function __construct($envfield, $formtext = '')
1002 {
1003 parent::__construct($envfield, $formtext, array(1, 2));
1004 }
1005
26ba053e 1006 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1007 {
1008 if ($this->val == 1) {
2d9951d8 1009 return new PFC_Not(new UFC_Dead());
21b67462
RB
1010 } else if ($this->val == 2) {
1011 return new UFC_Dead();
1012 }
1013 }
1014}
1015// }}}
1016
1017// {{{ class UFBF_Town
1018/** Retrieves a town, either from a postal code or a town name
1019 */
1020class UFBF_Town extends UFBF_Text
1021{
1022 const TYPE_TEXT = 1;
1023 const TYPE_ZIP = 2;
1024 const TYPE_ANY = 3;
1025
1026 private $type;
d9696b0a
RB
1027 private $onlycurrentfield;
1028
1029 public function __construct($envfield, $formtext = '', $type = self::TYPE_ANY, $onlycurrentfield = 'only_current')
21b67462
RB
1030 {
1031 $this->type = $type;
d9696b0a 1032 $this->onlycurrentfield = $onlycurrentfield;
f3f800d8 1033 parent::__construct($envfield, $formtext, 2, 30);
21b67462
RB
1034 }
1035
26ba053e 1036 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1037 {
d9696b0a
RB
1038 if ($ufb->isOn($this->onlycurrentfield)) {
1039 $flags = UFC_Address::FLAG_CURRENT;
1040 } else {
1041 $flags = UFC_Address::FLAG_ANY;
1042 }
1043
21b67462
RB
1044 if (preg_match('/[0-9]/', $this->val)) {
1045 if ($this->type & self::TYPE_ZIP) {
d9696b0a 1046 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
1047 } else {
1048 return new PFC_False();
1049 }
1050 } else {
1f8dfc60 1051 $byname = new UFC_AddressText(null, XDB::WILDCARD_CONTAINS, UFC_Address::TYPE_ANY, $flags, null, $this->val);
d9696b0a 1052 $byzip = new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
1053 if ($this->type & self::TYPE_ANY) {
1054 return new PFC_Or($byname, $byzip);
1055 } else if ($this->type & self::TYPE_TEXT) {
1056 return $byname;
1057 } else {
1058 return $byzip;
1059 }
1060 }
1061 }
e21504a3
RB
1062
1063 public function getEnvFieldNames()
1064 {
1065 return array($this->envfield, $this->onlycurrentfield);
1066 }
21b67462
RB
1067}
1068// }}}
1069
1070// {{{ class UFBF_Country
1071class UFBF_Country extends UFBF_Mixed
1072{
1073 protected $direnum = DirEnum::COUNTRIES;
d9696b0a
RB
1074 protected $onlycurrentfield;
1075
1076 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
1077 {
1078 parent::__construct($envfieldtext, $envfieldindex, $formtext);
1079 $this->onlycurrentfield = $onlycurrentfield;
1080 }
21b67462 1081
26ba053e 1082 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1083 {
d9696b0a
RB
1084 if ($ufb->isOn($this->onlycurrentfield)) {
1085 $flags = UFC_Address::FLAG_CURRENT;
1086 } else {
1087 $flags = UFC_Address::FLAG_ANY;
1088 }
1089
1090 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_COUNTRY, UFC_Address::TYPE_ANY, $flags);
21b67462 1091 }
e21504a3
RB
1092
1093 public function getEnvFieldNames()
1094 {
1095 return array($this->envfield, $this->envfieldindex, $this->onlycurrentfield);
1096 }
21b67462
RB
1097}
1098// }}}
1099
1100// {{{ class UFBF_AdminArea
32283a1a 1101class UFBF_AdminArea extends UFBF_Index
21b67462
RB
1102{
1103 protected $direnum = DirEnum::ADMINAREAS;
d9696b0a
RB
1104 protected $onlycurrentfield;
1105
32283a1a 1106 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
d9696b0a 1107 {
32283a1a 1108 parent::__construct($envfield, $formtext);
d9696b0a
RB
1109 $this->onlycurrentfield = $onlycurrentfield;
1110 }
1111
21b67462 1112
26ba053e 1113 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1114 {
d9696b0a
RB
1115 if ($ufb->isOn($this->onlycurrentfield)) {
1116 $flags = UFC_Address::FLAG_CURRENT;
1117 } else {
1118 $flags = UFC_Address::FLAG_ANY;
1119 }
1120
1121 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ADMAREA, UFC_Address::TYPE_ANY, $flags);
86ab1c8f 1122 }
e21504a3
RB
1123
1124 public function getEnvFieldNames()
1125 {
1126 return array($this->envfield, $this->onlycurrentfield);
1127 }
86ab1c8f
SJ
1128}
1129// }}}
1130
1131// {{{ class UFBF_SubAdminArea
1132class UFBF_SubAdminArea extends UFBF_Index
1133{
1134 protected $direnum = DirEnum::SUBADMINAREAS;
1135 protected $onlycurrentfield;
1136
1137 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1138 {
1139 parent::__construct($envfield, $formtext);
1140 $this->onlycurrentfield = $onlycurrentfield;
1141 }
1142
1143
26ba053e 1144 protected function buildUFC(UserFilterBuilder $ufb)
86ab1c8f
SJ
1145 {
1146 if ($ufb->isOn($this->onlycurrentfield)) {
1147 $flags = UFC_Address::FLAG_CURRENT;
1148 } else {
1149 $flags = UFC_Address::FLAG_ANY;
1150 }
1151
1152 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_SUBADMAREA, UFC_Address::TYPE_ANY, $flags);
21b67462 1153 }
e21504a3
RB
1154
1155 public function getEnvFieldNames()
1156 {
1157 return array($this->envfield, $this->onlycurrentfield);
1158 }
21b67462
RB
1159}
1160// }}}
1161
1162// {{{ class UFBF_JobCompany
1163class UFBF_JobCompany extends UFBF_Text
1164{
d9696b0a
RB
1165 private $onlymentorfield;
1166
1167 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1168 {
1169 parent::__construct($envfield, $formtext);
1170 $this->onlymentorfield = $onlymentorfield;
1171 }
1172
26ba053e 1173 public function check(UserFilterBuilder $ufb) {
d9696b0a
RB
1174 if (parent::check($ufb)) {
1175 # No company check for mentors
1176 if ($ufb->isOn($this->onlymentorfield)) {
1177 $this->empty = true;
1178 }
1179 return true;
1180 } else {
1181 return false;
1182 }
1183 }
1184
26ba053e 1185 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1186 {
1187 return new UFC_Job_Company(UFC_Job_Company::JOBNAME, $this->val);
1188 }
e21504a3
RB
1189
1190 public function getEnvFieldNames()
1191 {
1192 return array($this->envfield, $this->onlymentorfield);
1193 }
21b67462
RB
1194}
1195// }}}
1196
3ac45f10
PC
1197// {{{ class UFBF_JobTerms
1198class UFBF_JobTerms extends UFBF_Index
1199{
26ba053e 1200 protected function buildUFC(UserFilterBuilder $ufb)
3ac45f10
PC
1201 {
1202 return new UFC_Job_Terms($this->val);
1203 }
1204}
1205// }}}
1206
21b67462
RB
1207// {{{ class UFBF_JobDescription
1208class UFBF_JobDescription extends UFBF_Text
1209{
d9696b0a
RB
1210 private $onlymentorfield;
1211
1212 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1213 {
1214 parent::__construct($envfield, $formtext);
1215 $this->onlymentorfield = $onlymentorfield;
1216 }
1217
26ba053e 1218 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1219 {
d9696b0a
RB
1220 if ($ufb->isOn($this->onlymentorfield)) {
1221 return new UFC_Mentor_Expertise($this->val);
1222 } else {
1223 return new UFC_Job_Description($this->val, UserFilter::JOB_USERDEFINED);
1224 }
21b67462 1225 }
e21504a3
RB
1226
1227 public function getEnvFieldNames()
1228 {
1229 return array($this->envfield, $this->onlymentorfield);
1230 }
21b67462
RB
1231}
1232// }}}
1233
1234// {{{ class UFBF_JobCv
1235class UFBF_JobCv extends UFBF_Text
1236{
d9696b0a
RB
1237 private $onlymentorfield;
1238
1239 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1240 {
1241 parent::__construct($envfield, $formtext);
1242 $this->onlymentorfield = $onlymentorfield;
1243 }
1244
26ba053e 1245 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1246 {
d9696b0a
RB
1247 if ($ufb->isOn($this->onlymentorfield)) {
1248 return new UFC_Mentor_Expertise($this->val);
1249 } else {
1250 return new UFC_Job_Description($this->val, UserFilter::JOB_CV);
1251 }
21b67462 1252 }
e21504a3
RB
1253
1254 public function getEnvFieldNames()
1255 {
1256 return array($this->envfield, $this->onlymentorfield);
1257 }
21b67462
RB
1258}
1259// }}}
1260
1261// {{{ class UFBF_Nationality
1262class UFBF_Nationality extends UFBF_Mixed
1263{
1264 protected $direnum = DirEnum::NATIONALITIES;
1265
26ba053e 1266 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1267 {
1268 return new UFC_Nationality($this->val);
1269 }
1270}
1271// }}}
1272
1273// {{{ class UFBF_Binet
1274class UFBF_Binet extends UFBF_Mixed
1275{
1276 protected $direnum = DirEnum::BINETS;
1277
26ba053e 1278 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1279 {
1280 return new UFC_Binet($this->val);
1281 }
1282}
1283// }}}
1284
1285// {{{ class UFBF_Group
1286class UFBF_Group extends UFBF_Mixed
1287{
1288 protected $direnum = DirEnum::GROUPESX;
1289
26ba053e 1290 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1291 {
1292 if (count($this->val) == 1) {
1293 return new UFC_Group($this->val[0]);
1294 }
1295
1296 $or = new PFC_Or();
1297 foreach ($this->val as $grp) {
1298 $or->addChild(new UFC_Group($grp));
1299 }
1300 return $or;
1301 }
1302}
1303// }}}
1304
1305// {{{ class UFBF_Section
442f967f 1306class UFBF_Section extends UFBF_Mixed
21b67462
RB
1307{
1308 protected $direnum = DirEnum::SECTIONS;
1309
26ba053e 1310 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1311 {
1312 return new UFC_Section($this->val);
1313 }
1314}
1315// }}}
1316
fb3b6547
RB
1317// {{{ class UFBF_EducationSchool
1318class UFBF_EducationSchool extends UFBF_Mixed
21b67462 1319{
fb3b6547 1320 protected $direnum = DirEnum::EDUSCHOOLS;
21b67462 1321
26ba053e 1322 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1323 {
fb3b6547 1324 return new UFC_EducationSchool($this->val);
21b67462
RB
1325 }
1326}
1327// }}}
1328
fb3b6547
RB
1329// {{{ class UFBF_EducationDegree
1330class UFBF_EducationDegree extends UFBF_Mixed
21b67462 1331{
fb3b6547 1332 protected $direnum = DirEnum::EDUDEGREES;
21b67462 1333
26ba053e 1334 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1335 {
fb3b6547 1336 return new UFC_EducationDegree($this->val);
21b67462
RB
1337 }
1338}
1339// }}}
1340
fb3b6547
RB
1341// {{{ class UFBF_EducationField
1342class UFBF_EducationField extends UFBF_Mixed
21b67462 1343{
fb3b6547 1344 protected $direnum = DirEnum::EDUFIELDS;
21b67462 1345
26ba053e 1346 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1347 {
fb3b6547 1348 return new UFC_EducationField($this->val);
21b67462
RB
1349 }
1350}
1351// }}}
1352
00f25ab1
SJ
1353// {{{ class UFBF_OriginCorps
1354class UFBF_OriginCorps extends UFBF_Index
1355{
1356 protected $direnum = DirEnum::ORIGINCORPS;
1357
1358 protected function buildUFC(UserFilterBuilder $ufb)
1359 {
1360 return new UFC_Corps(null, $this->val, UFC_Corps::ORIGIN);
1361 }
1362}
1363// }}}
1364
1365// {{{ class UFBF_CurrentCorps
1366class UFBF_CurrentCorps extends UFBF_Index
1367{
1368 protected $direnum = DirEnum::CURRENTCORPS;
1369
1370 protected function buildUFC(UserFilterBuilder $ufb)
1371 {
1372 return new UFC_Corps(null, $this->val, UFC_Corps::CURRENT);
1373 }
1374}
1375// }}}
1376
1377// {{{ class UFBF_CorpsRank
1378class UFBF_CorpsRank extends UFBF_Index
1379{
1380 protected $direnum = DirEnum::CORPSRANKS;
1381
1382 protected function buildUFC(UserFilterBuilder $ufb)
1383 {
1384 return new UFC_Corps_Rank(null, $this->val);
1385 }
1386}
1387// }}}
1388
21b67462
RB
1389// {{{ class UFBF_Comment
1390class UFBF_Comment extends UFBF_Text
1391{
26ba053e 1392 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1393 {
1394 return new UFC_Comment($this->val);
1395 }
1396}
1397// }}}
3ed7556a
RB
1398
1399// {{{ class UFBF_Phone
1400class UFBF_Phone extends UFBF_Text
1401{
26ba053e 1402 protected function buildUFC(UserFilterBuilder $ufb)
3ed7556a
RB
1403 {
1404 return new UFC_Phone($this->val);
1405 }
1406}
1407// }}}
1408
1409// {{{ class UFBF_Networking
1410class UFBF_Networking extends UFBF_Text
1411{
1412 private $networktypefield;
1413 private $nwtype;
1414
1415 public function __construct($envfield, $networktypefield, $formtext = '')
1416 {
1417 parent::__construct($envfield, $formtext);
1418 $this->networktypefield = $networktypefield;
1419 }
1420
26ba053e 1421 public function check(UserFilterBuilder $ufb)
3ed7556a
RB
1422 {
1423 if (parent::check($ufb)) {
1424 $this->nwtype = $ufb->i($this->networktypefield);
1425 return true;
1426 } else {
1427 return false;
1428 }
1429 }
1430
1d364832
RB
1431 public function isEmpty()
1432 {
1433 return parent::isEmpty() || $this->nwtype == 0;
1434 }
1435
26ba053e 1436 public function buildUFC(UserFilterBuilder $ufb)
3ed7556a
RB
1437 {
1438 return new UFC_Networking($this->nwtype, $this->val);
1439 }
e21504a3
RB
1440
1441 public function getEnvFieldNames()
1442 {
1443 return array($this->envfield, $this->networktypefield);
1444 }
3ed7556a
RB
1445}
1446// }}}
6faa0186 1447
96f01fba
RB
1448// {{{ class UFBF_Mentor
1449class UFBF_Mentor extends UFBF_Bool
1450{
26ba053e 1451 protected function buildUFC(UserFilterBuilder $ufb)
96f01fba
RB
1452 {
1453 return new UFC_Mentor();
1454 }
1455}
1456// }}}
1457
6faa0186 1458// {{{ class UFBF_MentorCountry
459e6f81 1459class UFBF_MentorCountry extends UFBF_Text
6faa0186 1460{
26ba053e 1461 protected function buildUFC(UserFilterBuilder $ufb)
6faa0186
RB
1462 {
1463 return new UFC_Mentor_Country($this->val);
1464 }
1465}
1466// }}}
1467
459e6f81
PC
1468// {{{ class UFBF_Mentorterm
1469class UFBF_MentorTerm extends UFBF_Index
1470{
26ba053e 1471 protected function buildUFC(UserFilterBuilder $ufb)
459e6f81
PC
1472 {
1473 return new UFC_Mentor_Terms($this->val);
1474 }
1475}
1476// }}}
1477
6faa0186
RB
1478// {{{ class UFBF_MentorExpertise
1479class UFBF_MentorExpertise extends UFBF_Text
1480{
26ba053e 1481 protected function buildUFC(UserFilterBuilder $ufb)
6faa0186
RB
1482 {
1483 return new UFC_Mentor_Expertise($this->val);
1484 }
1485}
1486// }}}
05fa89a5
FB
1487
1488// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
d9b3d712 1489?>