Gives details about main education (field and program).
[platal.git] / classes / profile.php
CommitLineData
e7b93962
FB
1<?php
2/***************************************************************************
5e1513f6 3 * Copyright (C) 2003-2011 Polytechnique.org *
e7b93962
FB
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
aaffb7b2 22class Profile implements PlExportable
1a9affb7 23{
f5642983 24
913a4e90
RB
25 /* name tokens */
26 const LASTNAME = 'lastname';
27 const FIRSTNAME = 'firstname';
28 const NICKNAME = 'nickname';
29 const PSEUDONYM = 'pseudonym';
30 const NAME = 'name';
31 /* name variants */
32 const VN_MARITAL = 'marital';
33 const VN_ORDINARY = 'ordinary';
34 const VN_OTHER = 'other';
35 const VN_INI = 'ini';
36 /* display names */
37 const DN_FULL = 'directory_name';
38 const DN_DISPLAY = 'yourself';
39 const DN_YOURSELF = 'yourself';
40 const DN_DIRECTORY = 'directory_name';
41 const DN_PRIVATE = 'private_name';
42 const DN_PUBLIC = 'public_name';
43 const DN_SHORT = 'short_name';
44 const DN_SORT = 'sort_name';
e02d9fbb
SJ
45 /* education related names */
46 const EDU_X = 'École polytechnique';
47 const DEGREE_X = 'Ingénieur';
48 const DEGREE_M = 'Master';
49 const DEGREE_D = 'Doctorat';
913a4e90
RB
50
51 static public $name_variants = array(
52 self::LASTNAME => array(self::VN_MARITAL, self::VN_ORDINARY),
53 self::FIRSTNAME => array(self::VN_ORDINARY, self::VN_INI, self::VN_OTHER)
54 );
55
3c985c08
RB
56 const ADDRESS_MAIN = 0x00000001;
57 const ADDRESS_PERSO = 0x00000002;
58 const ADDRESS_PRO = 0x00000004;
59 const ADDRESS_ALL = 0x00000006;
60 const ADDRESS_POSTAL = 0x00000008;
61
62 const EDUCATION_MAIN = 0x00000010;
63 const EDUCATION_EXTRA = 0x00000020;
64 const EDUCATION_ALL = 0x00000040;
65 const EDUCATION_FINISHED = 0x00000080;
66 const EDUCATION_CURRENT = 0x00000100;
67
68 const JOBS_MAIN = 0x00001000;
69 const JOBS_ALL = 0x00002000;
70 const JOBS_FINISHED = 0x00004000;
71 const JOBS_CURRENT = 0x00008000;
72
34de4b20 73 const NETWORKING_ALL = 0x00070000;
3c985c08
RB
74 const NETWORKING_WEB = 0x00010000;
75 const NETWORKING_IM = 0x00020000;
76 const NETWORKING_SOCIAL = 0x00040000;
77
78 const PHONE_LINK_JOB = 0x00100000;
79 const PHONE_LINK_ADDRESS = 0x00200000;
80 const PHONE_LINK_PROFILE = 0x00400000;
81 const PHONE_LINK_COMPANY = 0x00800000;
82 const PHONE_LINK_ANY = 0x00F00000;
83
84 const PHONE_TYPE_FAX = 0x01000000;
85 const PHONE_TYPE_FIXED = 0x02000000;
86 const PHONE_TYPE_MOBILE = 0x04000000;
87 const PHONE_TYPE_ANY = 0x07000000;
88
89 const PHONE_ANY = 0x07F00000;
04a94b1d 90
4d1f0f6b
RB
91 const FETCH_ADDRESSES = 0x000001;
92 const FETCH_CORPS = 0x000002;
93 const FETCH_EDU = 0x000004;
94 const FETCH_JOBS = 0x000008;
95 const FETCH_MEDALS = 0x000010;
96 const FETCH_NETWORKING = 0x000020;
4d1f0f6b
RB
97 const FETCH_MENTOR_COUNTRY = 0x000080;
98 const FETCH_PHONES = 0x000100;
3ac45f10
PC
99 const FETCH_JOB_TERMS = 0x000200;
100 const FETCH_MENTOR_TERMS = 0x000400;
9f21bd15 101
4d1f0f6b 102 const FETCH_MINIFICHES = 0x00012D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_NETWORKING | FETCH_PHONES
fa9994fa 103
3ac45f10 104 const FETCH_ALL = 0x0007FF; // OR of FETCH_*
6b5008ec 105
7a9680aa
SJ
106 static public $descriptions = array(
107 'search_names' => 'Noms',
108 'nationality1' => 'Nationalité',
109 'nationality2' => '2e nationalité',
110 'nationality3' => '3e nationalité',
111 'promo_display' => 'Promotion affichée',
112 'email_directory' => 'Email annuaire papier',
113 'networking' => 'Messageries…',
114 'tels' => 'Téléphones',
115 'edus' => 'Formations',
d7de04af 116 'main_edus' => 'Formations à l\'X',
7a9680aa
SJ
117 'promo' => 'Promotion de sortie',
118 'birthdate' => 'Date de naissance',
119 'yourself' => 'Nom affiché',
120 'freetext' => 'Commentaire',
121 'freetext_pub' => 'Affichage du commentaire',
122 'photo' => 'Photographie',
123 'photo_pub' => 'Affichage de la photographie',
124 'addresses' => 'Adresses',
125 'corps' => 'Corps',
126 'cv' => 'CV',
127 'jobs' => 'Emplois',
128 'section' => 'Section',
129 'binets' => 'Binets',
130 'medals' => 'Décorations',
131 'medals_pub' => 'Affichage des décorations',
132 'competences' => 'Compétences',
133 'langues' => 'Langues',
134 'expertise' => 'Expertises (mentoring)',
135 'terms' => 'Compétences (mentoring)',
136 'countries' => 'Pays (mentoring)'
137 );
138
1f8250e4
RB
139 private $fetched_fields = 0x000000;
140
e7b93962
FB
141 private $pid;
142 private $hrpid;
564e2b2a
RB
143 private $owner;
144 private $owner_fetched = false;
3e53a496
FB
145 private $data = array();
146
f5642983
FB
147 private $visibility = null;
148
1f8250e4 149
b774ddab 150 private function __construct(array $data)
e7b93962 151 {
b774ddab 152 $this->data = $data;
832e6fcb
FB
153 $this->pid = $this->data['pid'];
154 $this->hrpid = $this->data['hrpid'];
1a9affb7 155 $this->visibility = new ProfileVisibility();
9f21bd15
RB
156 }
157
e7b93962
FB
158 public function id()
159 {
160 return $this->pid;
161 }
162
163 public function hrid()
164 {
165 return $this->hrpid;
166 }
167
564e2b2a
RB
168 public function owner()
169 {
170 if ($this->owner == null && !$this->owner_fetched) {
171 $this->owner_fetched = true;
172 $this->owner = User::getSilent($this);
173 }
174 return $this->owner;
175 }
176
280806d9
SJ
177 public function isActive()
178 {
179 if ($this->owner()) {
180 return $this->owner->isActive();
181 }
182 return false;
183 }
184
d5e60905
FB
185 public function promo()
186 {
187 return $this->promo;
188 }
189
845f0a4d
SJ
190 public function yearpromo()
191 {
7733ade1 192 return $this->promo_year;
845f0a4d
SJ
193 }
194
1168306a
PC
195 /** Check if user is an orange (associated with several promos)
196 */
197 public function isMultiPromo()
198 {
199 return $this->grad_year != $this->entry_year + $this->mainEducationDuration();
200 }
201
202 /** Returns an array with all associated promo years.
203 */
204 public function yearspromo()
205 {
206 $promos = array();
207 $d = -$this->deltaPromoToGradYear();
208 for ($g = $this->entry_year + $this->mainEducationDuration(); $g <= $this->grad_year; ++$g) {
209 $promos[] = $g + $d;
210 }
211 return $promos;
212 }
213
963bc7fc
SJ
214 public function mainEducation()
215 {
39e2c58c
FB
216 if (empty($this->promo)) {
217 return null;
218 } else {
219 return $this->promo{0};
220 }
963bc7fc
SJ
221 }
222
02d9dff0
FB
223 public function mainGrade()
224 {
225 switch ($this->mainEducation()) {
226 case 'X':
227 return UserFilter::GRADE_ING;
228 case 'M':
229 return UserFilter::GRADE_MST;
230 case 'D':
231 return UserFilter::GRADE_PHD;
232 default:
233 return null;
234 }
235 }
236
963bc7fc
SJ
237 public function mainEducationDuration()
238 {
239 switch ($this->mainEducation()) {
240 case 'X':
241 return 3;
242 case 'M':
243 return 2;
244 case 'D':
245 return 3;
246 default:
247 return 0;
248 }
249 }
250
1168306a
PC
251 /** Number of years between the promotion year until the
252 * graduation year. In standard schools it's 0, but for
253 * Polytechnique the promo year is the entry year.
254 */
255 public function deltaPromoToGradYear()
256 {
257 if ($this->mainEducation() == 'X') {
258 return $this->mainEducationDuration();
259 }
260 return 0;
261 }
262
94b72319
FB
263 /** Print a name with the given formatting:
264 * %s = • for women
265 * %f = firstname
266 * %l = lastname
267 * %F = fullname
268 * %S = shortname
269 * %p = promo
270 */
271 public function name($format)
272 {
273 return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'),
274 array($this->isFemale() ? '•' : '',
faf75faf
SJ
275 $this->firstName(), $this->lastName(),
276 $this->fullName(), $this->shortName(),
277 $this->promo()), $format);
94b72319
FB
278 }
279
280 public function fullName($with_promo = false)
281 {
282 if ($with_promo) {
283 return $this->full_name . ' (' . $this->promo . ')';
284 }
285 return $this->full_name;
286 }
287
288 public function shortName($with_promo = false)
289 {
290 if ($with_promo) {
291 return $this->short_name . ' (' . $this->promo . ')';
292 }
293 return $this->short_name;
294 }
295
296 public function firstName()
297 {
08c91036 298 return $this->firstname;
94b72319
FB
299 }
300
5c005b37
RB
301 public function firstNames()
302 {
303 return $this->nameVariants(self::FIRSTNAME);
304 }
305
94b72319
FB
306 public function lastName()
307 {
08c91036 308 return $this->lastname;
94b72319
FB
309 }
310
5c005b37
RB
311 public function lastNames()
312 {
313 return $this->nameVariants(self::LASTNAME);
314 }
315
94b72319
FB
316 public function isFemale()
317 {
318 return $this->sex == PlUser::GENDER_FEMALE;
319 }
320
400ac338
RB
321 public function isDead()
322 {
323 return ($this->deathdate != null);
324 }
325
564e2b2a
RB
326 public function displayEmail()
327 {
328 $o = $this->owner();
329 if ($o != null) {
330 return $o->bestEmail();
331 } else {
332 return $this->email_directory;
333 }
334 }
335
94b72319
FB
336 public function data()
337 {
338 $this->first_name;
339 return $this->data;
340 }
341
5c005b37
RB
342 private function nameVariants($type)
343 {
344 $vals = array($this->$type);
345 foreach (self::$name_variants[$type] as $var) {
346 $vartype = $type . '_' . $var;
347 $varname = $this->$vartype;
348 if ($varname != null && $varname != "") {
349 $vals[] = $varname;
350 }
351 }
352 return array_unique($vals);
353 }
354
b6569a95
FB
355 public function nationalities()
356 {
357 $nats = array();
6420023b 358 $countries = DirEnum::getOptions(DirEnum::COUNTRIES);
b6569a95 359 if ($this->nationality1) {
6420023b 360 $nats[$this->nationality1] = $countries[$this->nationality1];
b6569a95
FB
361 }
362 if ($this->nationality2) {
6420023b 363 $nats[$this->nationality2] = $countries[$this->nationality2];
b6569a95
FB
364 }
365 if ($this->nationality3) {
6420023b 366 $nats[$this->nationality3] = $countries[$this->nationality3];
b6569a95
FB
367 }
368 return $nats;
369 }
370
3e53a496
FB
371 public function __get($name)
372 {
373 if (property_exists($this, $name)) {
374 return $this->$name;
375 }
376
3e53a496
FB
377 if (isset($this->data[$name])) {
378 return $this->data[$name];
379 }
380
381 return null;
382 }
383
384 public function __isset($name)
385 {
386 return property_exists($this, $name) || isset($this->data[$name]);
387 }
388
ddbebe4c
FB
389 public function __unset($name)
390 {
391 if (property_exists($this, $name)) {
392 $this->$name = null;
393 } else {
394 unset($this->data[$name]);
395 }
396 }
397
398
405d70cc
RB
399 /**
400 * Clears a profile.
401 * *always deletes in: profile_addresses, profile_binets, profile_job,
402 * profile_langskills, profile_mentor, profile_networking,
403 * profile_phones, profile_skills, watch_profile
404 * *always keeps in: profile_corps, profile_display, profile_education,
405 * profile_medals, profile_name, profile_photos, search_name
406 * *modifies: profiles
407 */
408 public function clear()
409 {
410 $tables = array(
411 'profile_job', 'profile_langskills', 'profile_mentor',
412 'profile_networking', 'profile_skills', 'watch_profile',
413 'profile_phones', 'profile_addresses', 'profile_binets');
414
415 foreach ($tables as $t) {
416 XDB::execute('DELETE FROM ' . $t . '
417 WHERE pid = {?}',
418 $this->id());
419 }
420
421 XDB::execute("UPDATE profiles
422 SET cv = NULL, freetext = NULL, freetext_pub = 'private',
423 medals_pub = 'private', alias_pub = 'private',
424 email_directory = NULL
425 WHERE pid = {?}",
426 $this->id());
427 }
428
c159e50f
RB
429 /** Sets the level of visibility of the profile
430 * Sets $this->visibility to a list of valid visibilities.
1a9affb7 431 * @param one of the self::VIS_* values
c159e50f 432 */
f5642983
FB
433 public function setVisibilityLevel($visibility)
434 {
1a9affb7 435 $this->visibility->setLevel($visibility);
f5642983
FB
436 }
437
c159e50f
RB
438 /** Determine whether an item with visibility $visibility can be displayed
439 * with the current level of visibility of the profile
440 * @param $visibility The level of visibility to be checked
441 */
442 public function isVisible($visibility)
443 {
1a9affb7 444 return $this->visibility->isVisible($visibility);
9f21bd15
RB
445 }
446
a0f5fa32 447 /** Stores the list of fields which have already been fetched for this Profile
1f8250e4
RB
448 */
449 public function setFetchedFields($fields)
990cb17b 450 {
1f8250e4
RB
451 if (($fields | self::FETCH_ALL) != self::FETCH_ALL) {
452 Platal::page()->kill("Invalid fetched fields: $fields");
453 }
454
455 $this->fetched_fields = $fields;
456 }
457
4ec03752
RB
458 /** Have we already fetched this field ?
459 */
1f8250e4
RB
460 private function fetched($field)
461 {
4ec03752
RB
462 if (!array_key_exists($field, ProfileField::$fields)) {
463 Platal::page()->kill("Invalid field: $field");
1f8250e4
RB
464 }
465
466 return ($this->fetched_fields & $field);
467 }
468
469 /** If not already done, fetches data for the given field
470 * @param $field One of the Profile::FETCH_*
471 * @return A ProfileField, or null
472 */
473 private function getProfileField($field)
474 {
3ac45f10
PC
475 if (!array_key_exists($field, ProfileField::$fields)) {
476 Platal::page()->kill("Invalid field: $field");
477 }
1f8250e4
RB
478 if ($this->fetched($field)) {
479 return null;
480 } else {
481 $this->fetched_fields = $this->fetched_fields | $field;
482 }
483
484 $cls = ProfileField::$fields[$field];
485
990cb17b
RB
486 return ProfileField::getForPID($cls, $this->id(), $this->visibility);
487 }
488
8cf886dc
RB
489 /** Consolidates internal data (addresses, phones, jobs)
490 */
491 private function consolidateFields()
492 {
4ec03752 493 // Link phones to addresses
8cf886dc
RB
494 if ($this->phones != null) {
495 if ($this->addresses != null) {
496 $this->addresses->addPhones($this->phones);
497 }
498
499 if ($this->jobs != null) {
500 $this->jobs->addPhones($this->phones);
501 }
502 }
503
4ec03752 504 // Link addresses to jobs
8cf886dc
RB
505 if ($this->addresses != null && $this->jobs != null) {
506 $this->jobs->addAddresses($this->addresses);
507 }
4ec03752
RB
508
509 // Link jobterms to jobs
3ac45f10
PC
510 if ($this->jobs != null && $this->jobterms != null) {
511 $this->jobs->addJobTerms($this->jobterms);
512 }
8cf886dc
RB
513 }
514
833a6e86
FB
515 /* Photo
516 */
1a9affb7 517 private $photo = null;
7988f7d6 518 public function getPhoto($fallback = true, $data = false)
9f21bd15 519 {
1a9affb7
RB
520 if ($this->has_photo) {
521 if ($data && ($this->photo == null || $this->photo->mimeType == null)) {
8d6bbca3 522 $res = XDB::fetchOneAssoc('SELECT attach, attachmime, x, y, last_update
1f8250e4
RB
523 FROM profile_photos
524 WHERE pid = {?}', $this->pid);
8d6bbca3 525 $this->photo = PlImage::fromData($res['attach'], 'image/' .$res['attachmime'], $res['x'], $res['y'], $res['last_update']);
1a9affb7
RB
526 } else if ($this->photo == null) {
527 $this->photo = PlImage::fromData(null, null, $this->photo_width, $this->photo_height);
528 }
529 return $this->photo;
9f21bd15 530 } else if ($fallback) {
fa671a30
SJ
531 if ($this->mainEducation() == 'X') {
532 return PlImage::fromFile(dirname(__FILE__) . '/../htdocs/images/none_x.png', 'image/png');
533 }
534 return PlImage::fromFile(dirname(__FILE__) . '/../htdocs/images/none_md.png', 'image/png');
9f21bd15
RB
535 }
536 return null;
537 }
7d0ebdf5 538
4bc5b8f0
FB
539 /* Addresses
540 */
7d0ebdf5
RB
541 private $addresses = null;
542 public function setAddresses(ProfileAddresses $addr)
543 {
544 $this->addresses = $addr;
8cf886dc 545 $this->consolidateFields();
7d0ebdf5
RB
546 }
547
dbcc3b3d 548 private function fetchAddresses()
f5642983 549 {
1f8250e4 550 if ($this->addresses == null && !$this->fetched(self::FETCH_ADDRESSES)) {
61ee68c7
FB
551 $addr = $this->getProfileField(self::FETCH_ADDRESSES);
552 if ($addr) {
553 $this->setAddresses($addr);
dbcc3b3d 554 $this->fetchPhones();
61ee68c7 555 }
f5642983 556 }
dbcc3b3d
RB
557 }
558
559 public function getAddresses($flags, $limit = null)
560 {
561 $this->fetchAddresses();
0907501b
RB
562
563 if ($this->addresses == null) {
598c57f6 564 return array();
0907501b 565 }
990cb17b 566 return $this->addresses->get($flags, $limit);
f5642983
FB
567 }
568
598c57f6
RB
569 public function iterAddresses($flags, $limit = null)
570 {
571 return PlIteratorUtils::fromArray($this->getAddresses($flags, $limit), 1, true);
572 }
573
f5642983
FB
574 public function getMainAddress()
575 {
b0ffc881
RB
576 $main = $this->getAddresses(self::ADDRESS_MAIN);
577 $perso = $this->getAddresses(self::ADDRESS_PERSO);
578
579 if (count($main)) {
580 return array_pop($main);
581 } else if (count($perso)) {
582 return array_pop($perso);
f5642983 583 } else {
b0ffc881 584 return null;
f5642983
FB
585 }
586 }
3e53a496 587
bdef0d33
RB
588 /* Phones
589 */
590 private $phones = null;
591 public function setPhones(ProfilePhones $phones)
592 {
593 $this->phones = $phones;
594 $this->consolidateFields();
595 }
596
dbcc3b3d 597 private function fetchPhones()
bdef0d33 598 {
1f8250e4 599 if ($this->phones == null && !$this->fetched(self::FETCH_PHONES)) {
56721636
PC
600 $phones = $this->getProfileField(self::FETCH_PHONES);
601 if (isset($phones)) {
602 $this->setPhones($phones);
603 }
bdef0d33 604 }
dbcc3b3d 605 }
bdef0d33 606
dbcc3b3d
RB
607 public function getPhones($flags, $limit = null)
608 {
609 $this->fetchPhones();
bdef0d33 610 if ($this->phones == null) {
598c57f6 611 return array();
bdef0d33
RB
612 }
613 return $this->phones->get($flags, $limit);
614 }
4bc5b8f0
FB
615
616 /* Educations
617 */
d4d395bb 618 private $educations = null;
a060e1c3
RB
619 public function setEducations(ProfileEducation $edu)
620 {
621 $this->educations = $edu;
622 }
623
4bc5b8f0
FB
624 public function getEducations($flags, $limit = null)
625 {
1f8250e4
RB
626 if ($this->educations == null && !$this->fetched(self::FETCH_EDU)) {
627 $this->setEducations($this->getProfileField(self::FETCH_EDU));
d4d395bb 628 }
0907501b
RB
629
630 if ($this->educations == null) {
598c57f6 631 return array();
0907501b 632 }
a060e1c3 633 return $this->educations->get($flags, $limit);
4bc5b8f0
FB
634 }
635
636 public function getExtraEducations($limit = null)
637 {
638 return $this->getEducations(self::EDUCATION_EXTRA, $limit);
639 }
640
0396c259
RB
641 /* Corps
642 */
643 private $corps = null;
644 public function setCorps(ProfileCorps $corps)
645 {
646 $this->corps = $corps;
647 }
648
649 public function getCorps()
650 {
1f8250e4
RB
651 if ($this->corps == null && !$this->fetched(self::FETCH_CORPS)) {
652 $this->setCorps($this->getProfileField(self::FETCH_CORPS));
0396c259
RB
653 }
654 return $this->corps;
655 }
4bc5b8f0 656
04a94b1d
FB
657 /** Networking
658 */
d4d395bb
RB
659 private $networks = null;
660 public function setNetworking(ProfileNetworking $nw)
661 {
662 $this->networks = $nw;
663 }
04a94b1d
FB
664
665 public function getNetworking($flags, $limit = null)
666 {
1f8250e4 667 if ($this->networks == null && !$this->fetched(self::FETCH_NETWORKING)) {
dad85695
FB
668 $nw = $this->getProfileField(self::FETCH_NETWORKING);
669 if ($nw) {
670 $this->setNetworking($nw);
671 }
04a94b1d 672 }
0907501b 673 if ($this->networks == null) {
598c57f6 674 return array();
0907501b 675 }
d4d395bb 676 return $this->networks->get($flags, $limit);
04a94b1d
FB
677 }
678
679 public function getWebSite()
680 {
681 $site = $this->getNetworking(self::NETWORKING_WEB, 1);
598c57f6 682 if (count($site) != 1) {
04a94b1d
FB
683 return null;
684 }
598c57f6 685 $site = array_pop($site);
dad85695 686 return $site;
04a94b1d
FB
687 }
688
689
e718bd18
FB
690 /** Jobs
691 */
949fc736
RB
692 private $jobs = null;
693 public function setJobs(ProfileJobs $jobs)
694 {
695 $this->jobs = $jobs;
696 $this->consolidateFields();
697 }
e718bd18 698
dbcc3b3d 699 private function fetchJobs()
e718bd18 700 {
1f8250e4 701 if ($this->jobs == null && !$this->fetched(self::FETCH_JOBS)) {
61ee68c7
FB
702 $jobs = $this->getProfileField(self::FETCH_JOBS);
703 if ($jobs) {
704 $this->setJobs($jobs);
dbcc3b3d 705 $this->fetchAddresses();
61ee68c7 706 }
e718bd18 707 }
dbcc3b3d
RB
708 }
709
710 public function getJobs($flags, $limit = null)
711 {
712 $this->fetchJobs();
949fc736 713
0907501b 714 if ($this->jobs == null) {
598c57f6 715 return array();
0907501b 716 }
949fc736 717 return $this->jobs->get($flags, $limit);
e718bd18
FB
718 }
719
44ec5eb5 720 public function getMainJob()
e718bd18
FB
721 {
722 $job = $this->getJobs(self::JOBS_MAIN, 1);
598c57f6 723 if (count($job) != 1) {
e718bd18
FB
724 return null;
725 }
598c57f6 726 return array_pop($job);
e718bd18
FB
727 }
728
3ac45f10
PC
729 /** JobTerms
730 */
731 private $jobterms = null;
732 public function setJobTerms(ProfileJobTerms $jobterms)
733 {
734 $this->jobterms = $jobterms;
735 $this->consolidateFields();
736 }
737
4d1f0f6b
RB
738 private $mentor_countries = null;
739 public function setMentoringCountries(ProfileMentoringCountries $countries)
740 {
741 $this->mentor_countries = $countries;
742 }
743
744 public function getMentoringCountries()
745 {
746 if ($this->mentor_countries == null && !$this->fetched(self::FETCH_MENTOR_COUNTRY)) {
747 $this->setMentoringCountries($this->getProfileField(self::FETCH_MENTOR_COUNTRY));
748 }
749
750 if ($this->mentor_countries == null) {
751 return array();
752 } else {
753 return $this->mentor_countries->countries;
754 }
755 }
756
3ac45f10
PC
757 /** List of job terms to specify mentoring */
758 private $mentor_terms = null;
759 /**
760 * set job terms to specify mentoring
761 * @param $terms a ProfileMentoringTerms object listing terms only for this profile
762 */
763 public function setMentoringTerms(ProfileMentoringTerms $terms)
764 {
765 $this->mentor_terms = $terms;
766 }
767 /**
768 * get all job terms that specify mentoring
769 * @return an array of JobTerms objects
770 */
771 public function getMentoringTerms()
772 {
773 if ($this->mentor_terms == null && !$this->fetched(self::FETCH_MENTOR_TERMS)) {
774 $this->setMentoringTerms($this->getProfileField(self::FETCH_MENTOR_TERMS));
775 }
776
777 if ($this->mentor_terms == null) {
778 return array();
779 } else {
780 return $this->mentor_terms->get();
781 }
782 }
783
784
5c005b37
RB
785 /* Binets
786 */
787 public function getBinets()
788 {
875a88d3
RB
789 if ($this->visibility->isVisible(ProfileVisibility::VIS_PRIVATE)) {
790 return XDB::fetchColumn('SELECT binet_id
791 FROM profile_binets
792 WHERE pid = {?}', $this->id());
793 } else {
794 return array();
795 }
5c005b37 796 }
97b71de5
RB
797 public function getBinetsNames()
798 {
875a88d3
RB
799 if ($this->visibility->isVisible(ProfileVisibility::VIS_PRIVATE)) {
800 return XDB::fetchColumn('SELECT text
801 FROM profile_binets AS pb
802 LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id)
803 WHERE pb.pid = {?}', $this->id());
804 } else {
805 return array();
806 }
97b71de5 807 }
5c005b37 808
26ca919b
RB
809 /* Medals
810 */
811 private $medals = null;
812 public function setMedals(ProfileMedals $medals)
813 {
814 $this->medals = $medals;
815 }
816
817 public function getMedals()
818 {
1f8250e4
RB
819 if ($this->medals == null && !$this->fetched(self::FETCH_MEDALS)) {
820 $this->setMedals($this->getProfileField(self::FETCH_MEDALS));
26ca919b
RB
821 }
822 if ($this->medals == null) {
823 return array();
824 }
825 return $this->medals->medals;
826 }
e718bd18 827
94590511
SJ
828 public function compareNames($firstname, $lastname)
829 {
830 $_lastname = mb_strtoupper($this->lastName());
831 $_firstname = mb_strtoupper($this->firstName());
832 $lastname = mb_strtoupper($lastname);
833 $firstname = mb_strtoupper($firstname);
834
835 $isOk = (mb_strtoupper($_firstname) == mb_strtoupper($firstname));
836 $tokens = preg_split("/[ \-']/", $lastname, -1, PREG_SPLIT_NO_EMPTY);
837 $maxlen = 0;
838
839 foreach ($tokens as $str) {
840 $isOk &= (strpos($_lastname, $str) !== false);
841 $maxlen = max($maxlen, strlen($str));
842 }
843
844 return ($isOk && ($maxlen > 2 || $maxlen == strlen($_lastname)));
845 }
846
aaffb7b2
FB
847 /* Export to JSON
848 */
849 public function export()
850 {
851 return array(
852 'hrpid' => $this->hrid(),
853 'display_name' => $this->shortName(),
854 'full_name' => $this->fullName(),
855 'directory_name' => $this->directory_name,
856 'promo' => $this->promo(),
857 'year_promo' => $this->yearpromo(),
858 'is_active' => $this->isActive(),
859 'first_name' => $this->firstName(),
860 'last_name' => $this->lastName(),
861 'is_female' => $this->isFemale(),
862 );
863 }
864
9f21bd15 865 private static function fetchProfileData(array $pids, $respect_order = true, $fields = 0x0000, $visibility = null)
b774ddab
FB
866 {
867 if (count($pids) == 0) {
7a8da8e8 868 return null;
b774ddab 869 }
0d906109
RB
870
871 if ($respect_order) {
872 $order = 'ORDER BY ' . XDB::formatCustomOrder('p.pid', $pids);
873 } else {
874 $order = '';
875 }
876
1a9affb7 877 $visibility = new ProfileVisibility($visibility);
9f21bd15 878
3e2442cd
RB
879 $it = XDB::Iterator('SELECT p.pid, p.hrpid, p.xorg_id, p.ax_id, p.birthdate, p.birthdate_ref,
880 p.next_birthday, p.deathdate, p.deathdate_rec, p.sex = \'female\' AS sex,
77d2ae52
RB
881 IF ({?}, p.cv, NULL) AS cv, p.medals_pub, p.alias_pub, p.email_directory,
882 p.last_change, p.nationality1, p.nationality2, p.nationality3,
3e2442cd 883 IF (p.freetext_pub IN {?}, p.freetext, NULL) AS freetext,
7733ade1 884 pe.entry_year, pe.grad_year, pe.promo_year,
348b3844
RB
885 IF ({?}, pse.text, NULL) AS section,
886 pn_f.name AS firstname, pn_l.name AS lastname,
887 IF( {?}, pn_n.name, NULL) AS nickname,
9f21bd15
RB
888 IF(pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_ordinary,
889 IF(pn_ul.name IS NULL, pn_l.name, pn_ul.name) AS lastname_ordinary,
09e54905
SJ
890 pd.yourself, pd.promo, pd.short_name, pd.public_name AS full_name,
891 pd.directory_name, pd.public_name, pd.private_name,
892 IF(pp.pub IN {?}, pp.display_tel, NULL) AS mobile,
1a9affb7 893 (ph.pub IN {?} AND ph.attach IS NOT NULL) AS has_photo,
7988f7d6 894 ph.x AS photo_width, ph.y AS photo_height,
9f21bd15 895 p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old,
bdef0d33 896 pm.expertise AS mentor_expertise,
9f21bd15
RB
897 ap.uid AS owner_id
898 FROM profiles AS p
899 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
900 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags))
97b71de5 901 LEFT JOIN profile_section_enum AS pse ON (pse.id = p.section)
9f21bd15
RB
902 INNER JOIN profile_name AS pn_f ON (pn_f.pid = p.pid
903 AND pn_f.typeid = ' . self::getNameTypeId('firstname', true) . ')
904 INNER JOIN profile_name AS pn_l ON (pn_l.pid = p.pid
905 AND pn_l.typeid = ' . self::getNameTypeId('lastname', true) . ')
906 LEFT JOIN profile_name AS pn_uf ON (pn_uf.pid = p.pid
907 AND pn_uf.typeid = ' . self::getNameTypeId('firstname_ordinary', true) . ')
908 LEFT JOIN profile_name AS pn_ul ON (pn_ul.pid = p.pid
909 AND pn_ul.typeid = ' . self::getNameTypeId('lastname_ordinary', true) . ')
910 LEFT JOIN profile_name AS pn_n ON (pn_n.pid = p.pid
911 AND pn_n.typeid = ' . self::getNameTypeId('nickname', true) . ')
912 LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\')
913 LEFT JOIN profile_photos AS ph ON (ph.pid = p.pid)
bdef0d33 914 LEFT JOIN profile_mentor AS pm ON (pm.pid = p.pid)
9f21bd15 915 LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms))
3e2442cd 916 WHERE p.pid IN {?}
9f21bd15 917 GROUP BY p.pid
3e2442cd 918 ' . $order,
77d2ae52
RB
919 $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // CV
920 $visibility->levels(), // freetext
921 $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // section
922 $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // nickname
923 $visibility->levels(), // mobile
924 $visibility->levels(), // photo
3e2442cd
RB
925 $pids
926 );
31ef12ef 927 return new ProfileIterator($it, $pids, $fields, $visibility);
b774ddab
FB
928 }
929
930 public static function getPID($login)
931 {
932 if ($login instanceof PlUser) {
933 return XDB::fetchOneCell('SELECT pid
934 FROM account_profiles
935 WHERE uid = {?} AND FIND_IN_SET(\'owner\', perms)',
936 $login->id());
9f21bd15 937 } else if (ctype_digit($login)) {
b774ddab
FB
938 return XDB::fetchOneCell('SELECT pid
939 FROM profiles
940 WHERE pid = {?}', $login);
941 } else {
942 return XDB::fetchOneCell('SELECT pid
943 FROM profiles
944 WHERE hrpid = {?}', $login);
945 }
946 }
947
0d906109
RB
948 public static function getPIDsFromUIDs($uids, $respect_order = true)
949 {
950 if ($respect_order) {
951 $order = 'ORDER BY ' . XDB::formatCustomOrder('uid', $uids);
952 } else {
953 $order = '';
954 }
955 return XDB::fetchAllAssoc('uid', 'SELECT ap.uid, ap.pid
956 FROM account_profiles AS ap
957 WHERE FIND_IN_SET(\'owner\', ap.perms)
9f21bd15
RB
958 AND ap.uid IN ' . XDB::formatArray($uids) .'
959 ' . $order);
0d906109 960 }
b774ddab 961
e7b93962
FB
962 /** Return the profile associated with the given login.
963 */
9f21bd15 964 public static function get($login, $fields = 0x0000, $visibility = null)
a3118782 965 {
641f2115 966 if (is_array($login)) {
1a9affb7
RB
967 $pf = new Profile($login);
968 $pf->setVisibilityLevel($visibility);
969 return $pf;
641f2115 970 }
b774ddab
FB
971 $pid = self::getPID($login);
972 if (!is_null($pid)) {
9f21bd15 973 $it = self::iterOverPIDs(array($pid), false, $fields, $visibility);
0d906109 974 return $it->next();
b774ddab 975 } else {
efe597c5
FB
976 /* Let say we can identify a profile using the identifiers of its owner.
977 */
455ea0c9
FB
978 if (!($login instanceof PlUser)) {
979 $user = User::getSilent($login);
980 if ($user && $user->hasProfile()) {
981 return $user->profile();
982 }
efe597c5 983 }
3e53a496 984 return null;
e7b93962
FB
985 }
986 }
a3118782 987
9f21bd15 988 public static function iterOverUIDs($uids, $respect_order = true, $fields = 0x0000, $visibility = null)
0d906109 989 {
9f21bd15 990 return self::iterOverPIDs(self::getPIDsFromUIDs($uids), $respect_order, $fields, $visibility);
0d906109
RB
991 }
992
9f21bd15 993 public static function iterOverPIDs($pids, $respect_order = true, $fields = 0x0000, $visibility = null)
0d906109 994 {
9f21bd15 995 return self::fetchProfileData($pids, $respect_order, $fields, $visibility);
0d906109
RB
996 }
997
b774ddab
FB
998 /** Return profiles for the list of pids.
999 */
1a9affb7 1000 public static function getBulkProfilesWithPIDs(array $pids, $fields = 0x0000, $visibility = null)
b774ddab
FB
1001 {
1002 if (count($pids) == 0) {
1003 return array();
1004 }
9f21bd15 1005 $it = self::iterOverPIDs($pids, true, $fields, $visibility);
b774ddab 1006 $profiles = array();
0d906109
RB
1007 while ($p = $it->next()) {
1008 $profiles[$p->id()] = $p;
b774ddab
FB
1009 }
1010 return $profiles;
1011 }
1012
1013 /** Return profiles for uids.
1014 */
9f21bd15 1015 public static function getBulkProfilesWithUIDS(array $uids, $fields = 0x000, $visibility = null)
b774ddab
FB
1016 {
1017 if (count($uids) == 0) {
1018 return array();
1019 }
9f21bd15 1020 return self::getBulkProfilesWithPIDs(self::getPIDsFromUIDs($uids), $fields, $visibility);
b774ddab
FB
1021 }
1022
913a4e90
RB
1023 public static function isDisplayName($name)
1024 {
1025 return $name == self::DN_FULL || $name == self::DN_DISPLAY
1026 || $name == self::DN_YOURSELF || $name == self::DN_DIRECTORY
1027 || $name == self::DN_PRIVATE || $name == self::DN_PUBLIC
1028 || $name == self::DN_SHORT || $name == self::DN_SORT;
1029 }
1030
a9ef52c9
RB
1031 /** Returns the closest "accounts only" name type for $name
1032 */
1033 public static function getAccountEquivalentName($name)
1034 {
1035 switch ($name)
1036 {
1037 case self::DN_DIRECTORY:
1038 case self::DN_SORT:
1039 return 'directory_name';
1040 case self::DN_FULL:
1041 case self::DN_PUBLIC:
1042 return 'full_name';
1043 case self::DN_PRIVATE:
1044 case self::DN_SHORT:
1045 case self::DN_YOURSELF:
1046 default:
1047 return 'display_name';
1048 }
1049 }
1050
9f21bd15
RB
1051 public static function getNameTypeId($type, $for_sql = false)
1052 {
1053 if (!S::has('name_types')) {
1054 $table = XDB::fetchAllAssoc('type', 'SELECT id, type
1055 FROM profile_name_enum');
1056 S::set('name_types', $table);
1057 } else {
1058 $table = S::v('name_types');
1059 }
1060 if ($for_sql) {
1061 return XDB::escape($table[$type]);
1062 } else {
1063 return $table[$type];
1064 }
1065 }
1066
bedc4295 1067 public static function rebuildSearchTokens($pids, $transaction = true)
726eaf7a 1068 {
5acd53a9
FB
1069 if (!is_array($pids)) {
1070 $pids = array($pids);
1071 }
80bc45c2
FB
1072 $keys = XDB::iterator("(SELECT n.pid AS pid, n.name AS name, e.score AS score,
1073 IF(FIND_IN_SET('public', e.flags), 'public', '') AS public
1074 FROM profile_name AS n
1075 INNER JOIN profile_name_enum AS e ON (n.typeid = e.id)
1076 WHERE n.pid IN {?} AND NOT FIND_IN_SET('not_displayed', e.flags))
1077 UNION
1078 (SELECT n.pid AS pid, n.particle AS name, 0 AS score,
1079 IF(FIND_IN_SET('public', e.flags), 'public', '') AS public
1080 FROM profile_name AS n
1081 INNER JOIN profile_name_enum AS e ON (n.typeid = e.id)
1082 WHERE n.pid IN {?} AND NOT FIND_IN_SET('not_displayed', e.flags))
1083 ",
1084 $pids, $pids);
5acd53a9 1085 $names = array();
2f62eba7 1086 while ($key = $keys->next()) {
726eaf7a
SJ
1087 if ($key['name'] == '') {
1088 continue;
1089 }
5acd53a9 1090 $pid = $key['pid'];
5ed1cce8
RB
1091 require_once 'name.func.inc.php';
1092 $toks = split_name_for_search($key['name']);
80bc45c2
FB
1093 $toks = array_reverse($toks);
1094
1095 /* Split the score between the tokens to avoid the user to be over-rated.
1096 * Let says my user name is "Machin-Truc Bidule" and I also have a user named
1097 * 'Machin Truc'. Distributing the score force "Machin Truc" to be displayed
1098 * before "Machin-Truc" for both "Machin Truc" and "Machin" searches.
1099 */
1100 $eltScore = ceil(((float)$key['score'])/((float)count($toks)));
726eaf7a 1101 $token = '';
80bc45c2
FB
1102 foreach ($toks as $tok) {
1103 $token = $tok . $token;
5acd53a9
FB
1104 $names["$pid-$token"] = XDB::format('({?}, {?}, {?}, {?}, {?})',
1105 $token, $pid, soundex_fr($token),
80bc45c2 1106 $eltScore, $key['public']);
726eaf7a
SJ
1107 }
1108 }
bedc4295
FB
1109 if ($transaction) {
1110 XDB::startTransaction();
1111 }
5acd53a9
FB
1112 XDB::execute('DELETE FROM search_name
1113 WHERE pid IN {?}',
1114 $pids);
1115 if (count($names) > 0) {
80bc45c2
FB
1116 XDB::rawExecute('INSERT INTO search_name (token, pid, soundex, score, flags)
1117 VALUES ' . implode(', ', $names));
5acd53a9 1118 }
bedc4295
FB
1119 if ($transaction) {
1120 XDB::commit();
1121 }
69b46857
SJ
1122 }
1123
1124 /** The school identifier consists of 6 digits. The first 3 represent the
1125 * promotion entry year. The last 3 indicate the student's rank.
aab2ffdd 1126 *
69b46857
SJ
1127 * Our identifier consists of 8 digits and both half have the same role.
1128 * This enables us to deal with bigger promotions and with a wider range
1129 * of promotions.
1130 *
1131 * getSchoolId returns a school identifier given one of ours.
1132 * getXorgId returns a X.org identifier given a school identifier.
1133 */
1134 public static function getSchoolId($xorgId)
1135 {
1136 if (!preg_match('/^[0-9]{8}$/', $xorgId)) {
1137 return null;
1138 }
1139
1140 $year = intval(substr($xorgId, 0, 4));
1141 $rank = intval(substr($xorgId, 5, 3));
1142 if ($year < 1996) {
1143 return null;
1144 } elseif ($year < 2000) {
1145 $year = intval(substr(1900 - $year, 1, 3));
1146 return sprintf('%02u0%03u', $year, $rank);
1147 } else {
1148 $year = intval(substr(1900 - $year, 1, 3));
1149 return sprintf('%03u%03u', $year, $rank);
1150 }
1151 }
726eaf7a 1152
69b46857
SJ
1153 public static function getXorgId($schoolId)
1154 {
94590511 1155 if (!preg_match('/^[0-9]{6}$/', $schoolId)) {
a292484d
SJ
1156 return null;
1157 }
1158
69b46857
SJ
1159 $year = intval(substr($schoolId, 0, 3));
1160 $rank = intval(substr($schoolId, 3, 3));
726eaf7a 1161
69b46857
SJ
1162 if ($year > 200) {
1163 $year /= 10;
1164 }
1165 if ($year < 96) {
1166 return null;
1167 } else {
1168 return sprintf('%04u%04u', 1900 + $year, $rank);
1169 }
726eaf7a 1170 }
e7b93962
FB
1171}
1172
31ef12ef
RB
1173
1174/** Iterator over a set of Profiles
1175 */
1176class ProfileIterator implements PlIterator
9f21bd15
RB
1177{
1178 private $iterator = null;
1179 private $fields;
1a9affb7 1180 private $visibility;
9f21bd15 1181
3ac45f10
PC
1182 const FETCH_ALL = 0x000033F; // FETCH_ADDRESSES | FETCH_CORPS | FETCH_EDU | FETCH_JOBS | FETCH_MEDALS | FETCH_NETWORKING | FETCH_PHONES | FETCH_JOB_TERMS
1183
1a9affb7 1184 public function __construct(PlIterator $it, array $pids, $fields = 0x0000, ProfileVisibility $visibility = null)
9f21bd15
RB
1185 {
1186 require_once 'profilefields.inc.php';
1a9affb7
RB
1187
1188 if ($visibility == null) {
1189 $visibility = new ProfileVisibility();
1190 }
1191
9f21bd15 1192 $this->fields = $fields;
1a9affb7 1193 $this->visibility = $visibility;
9f21bd15
RB
1194
1195 $subits = array();
1196 $callbacks = array();
1197
1198 $subits[0] = $it;
1199 $callbacks[0] = PlIteratorUtils::arrayValueCallback('pid');
1200 $cb = PlIteratorUtils::objectPropertyCallback('pid');
1201
3ac45f10
PC
1202 $fields = $fields & self::FETCH_ALL;
1203 for ($field = 1; $field < $fields; $field *= 2) {
1204 if (($fields & $field) ) {
1205 $callbacks[$field] = $cb;
1206 $subits[$field] = new ProfileFieldIterator($field, $pids, $visibility);
1207 }
9f21bd15
RB
1208 }
1209
9f21bd15
RB
1210 $this->iterator = PlIteratorUtils::parallelIterator($subits, $callbacks, 0);
1211 }
1212
1f8250e4 1213 private function hasData($field, $vals)
9f21bd15 1214 {
1f8250e4 1215 return ($this->fields & $field) && ($vals[$field] != null);
9f21bd15
RB
1216 }
1217
1218 private function fillProfile(array $vals)
1219 {
9f21bd15 1220 $pf = Profile::get($vals[0]);
1a9affb7 1221 $pf->setVisibilityLevel($this->visibility->level());
1f8250e4 1222 $pf->setFetchedFields($this->fields);
1a9affb7 1223
8cf886dc
RB
1224 if ($this->hasData(Profile::FETCH_PHONES, $vals)) {
1225 $pf->setPhones($vals[Profile::FETCH_PHONES]);
9f21bd15 1226 }
8cf886dc
RB
1227 if ($this->hasData(Profile::FETCH_ADDRESSES, $vals)) {
1228 $pf->setAddresses($vals[Profile::FETCH_ADDRESSES]);
1229 }
1230 if ($this->hasData(Profile::FETCH_JOBS, $vals)) {
1231 $pf->setJobs($vals[Profile::FETCH_JOBS]);
1232 }
3ac45f10
PC
1233 if ($this->hasData(Profile::FETCH_JOB_TERMS, $vals)) {
1234 $pf->setJobTerms($vals[Profile::FETCH_JOB_TERMS]);
1235 }
8cf886dc
RB
1236
1237 if ($this->hasData(Profile::FETCH_CORPS, $vals)) {
9f21bd15
RB
1238 $pf->setCorps($vals[Profile::FETCH_CORPS]);
1239 }
8cf886dc 1240 if ($this->hasData(Profile::FETCH_EDU, $vals)) {
26ca919b 1241 $pf->setEducations($vals[Profile::FETCH_EDU]);
9f21bd15 1242 }
8cf886dc 1243 if ($this->hasData(Profile::FETCH_MEDALS, $vals)) {
9f21bd15
RB
1244 $pf->setMedals($vals[Profile::FETCH_MEDALS]);
1245 }
8cf886dc 1246 if ($this->hasData(Profile::FETCH_NETWORKING, $vals)) {
9f21bd15
RB
1247 $pf->setNetworking($vals[Profile::FETCH_NETWORKING]);
1248 }
9f21bd15
RB
1249
1250 return $pf;
1251 }
1252
1253 public function next()
1254 {
1255 $vals = $this->iterator->next();
1256 if ($vals == null) {
1257 return null;
1258 }
1259 return $this->fillProfile($vals);
1260 }
1261
1262 public function first()
1263 {
1264 return $this->iterator->first();
1265 }
1266
1267 public function last()
1268 {
1269 return $this->iterator->last();
1270 }
1271
1272 public function total()
1273 {
1274 return $this->iterator->total();
1275 }
1276}
1277
e7b93962
FB
1278// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
1279?>