2 /***************************************************************************
3 * Copyright (C) 2003-2014 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ProfileSettingSearchNames
implements ProfileSetting
24 private function diff($pid, array $old, array $new)
27 foreach ($old as $field => $name) {
28 $diff = $diff ||
($name != $new[$field]);
34 private function matchWord($old, $new, $newLen)
36 return ($i = strpos($old, $new)) !== false
37 && ($i == 0 ||
$old{$i-1} == ' ')
38 && ($i +
$newLen == strlen($old) ||
$old{$i +
$newLen} == ' ');
41 private function prepare(ProfilePage
$page, array &$new_value)
43 $initial_value = XDB
::fetchOneAssoc('SELECT lastname_main, firstname_main
44 FROM profile_public_names
49 foreach ($initial_value as $field => $name) {
50 $initial = name_to_basename($name);
51 $new = name_to_basename($new_value[$field]);
53 if (!($this->matchWord($initial, $new, strlen($new))
54 ||
($field == 'lastname_main' && $new == 'DE ' . $initial))) {
55 $new_value[$field . '_error'] = true
;
57 Platal
::page()->trigError('Le nom choisi (' . $new . ') est trop loin de sa valeur initiale (' . $initial . ').');
64 public function value(ProfilePage
$page, $field, $value, &$success)
66 require_once 'name.func.inc.php';
69 if (is_null($value)) {
70 $request = NamesReq
::getPublicNames($page->pid());
73 $value['public_names'] = XDB
::fetchOneAssoc('SELECT lastname_main, lastname_marital, lastname_ordinary,
74 firstname_main, firstname_ordinary, pseudonym
75 FROM profile_public_names
79 $value['public_names'] = $request;
80 Platal
::page()->assign('validation', true
);
83 $value['private_names'] = XDB
::fetchAllAssoc('SELECT type, name
84 FROM profile_private_names
89 foreach ($value['public_names'] as $key => $name) {
90 $value['public_names'][$key] = capitalize_name(trim($name));
92 if (isset($value['private_names'])) {
93 foreach ($value['private_names'] as $key => $name) {
94 $value['private_names'][$key]['name'] = trim($name['name']);
95 if ($value['private_names'][$key]['name'] == '') {
96 unset($value['private_names'][$key]);
101 if (S
::user()->isMe($page->owner
)) {
102 $success = $this->prepare($page, $value['public_names']);
106 $public_name = build_first_name($value['public_names']) . ' ' . build_full_last_name($value['public_names'], $page->profile
->isFemale());
107 if (isset($value['private_names'])) {
108 $private_name_end = build_private_name($value['private_names']);
109 $private_name = $public_name . $private_name_end;
111 $value['private_names'] = array();
112 $private_name = $public_name;
115 Platal
::page()->assign('public_name', $public_name);
116 Platal
::page()->assign('private_name', $private_name);
121 public function save(ProfilePage
$page, $field, $value)
123 require_once 'name.func.inc.php';
125 $old = XDB
::fetchOneAssoc('SELECT lastname_main, lastname_marital, lastname_ordinary,
126 firstname_main, firstname_ordinary, pseudonym
127 FROM profile_public_names
131 if ($has_diff = $this->diff($page->pid(), $old, $value['public_names'])) {
132 $new_names = new NamesReq(S
::user(), $page->profile
, $value['public_names'], $old);
133 $new_names->submit();
134 Platal
::page()->assign('validation', true
);
135 Platal
::page()->trigWarning('La demande de modification des noms a bien été prise en compte.' .
136 ' Un email sera envoyé dès que ces changements auront été effectués.');
139 XDB
::execute('DELETE FROM profile_private_names
143 $nickname = $lastname = $firstname = 0;
144 if (isset($value['private_names'])) {
145 foreach ($value['private_names'] as $name) {
146 $values[] = XDB
::format('({?}, {?}, {?}, {?})', $page->pid(), $name['type'], $
$name['type']++
, $name['name']);
149 if (count($values)) {
150 XDB
::rawExecute('INSERT INTO profile_private_names (pid, type, id, name)
151 VALUES ' . implode(',', $values));
155 update_display_names($page->profile
, $old, $value['private_names']);
157 update_display_names($page->profile
,
158 $value['public_names'], (isset($value['private_names']) ?
$value['private_names'] : null
));
162 public function getText($value) {
163 $public_names = array();
164 foreach ($value['public_names'] as $name) {
166 $public_names[] = $name;
170 if (isset($value['private_names']) && count($value['private_names'])) {
171 $private_names = array();
172 foreach ($value['private_names'] as $name) {
173 $private_names[] = $name['name'];
175 return 'noms publics : ' . implode(', ' , $public_names) . ', noms privés : ' . implode(', ' , $private_names);;
178 return 'noms publics : ' . implode(', ' , $public_names);
182 class ProfileSettingEdu
implements ProfileSetting
184 public function __construct() {
187 static function sortByGradYear($line1, $line2) {
188 $a = (isset($line1['grad_year'])) ?
(int) $line1['grad_year'] : 0;
189 $b = (isset($line2['grad_year'])) ?
(int) $line2['grad_year'] : 0;
193 return ($a < $b) ?
-1 : 1;
196 public function value(ProfilePage
$page, $field, $value, &$success)
199 if (is_null($value)) {
201 $value = XDB
::fetchAllAssoc("SELECT eduid, degreeid, fieldid, grad_year, program
202 FROM profile_education
203 WHERE pid = {?} AND !(FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags))
206 } else if (!is_array($value)) {
210 foreach ($value as $key=>&$edu) {
211 if ($edu['eduid'] < 1 ||
!isset($edu['degreeid']) ||
$edu['degreeid'] < 1) {
212 Platal
::page()->trigError('L\'université ou le diplôme d\'une formation manque.');
215 if (($edu['grad_year'] < 1921) ||
($edu['grad_year'] > (date('Y') +
4))) {
216 Platal
::page()->trigWarning('L\'année d\'obtention du diplôme est mal ou non renseignée, elle doit être du type : 2004.');
217 $edu['grad_year'] = null
;
218 $edu['warning'] = true
;
226 usort($value, array("ProfileSettingEdu", "sortByGradYear"));
231 public function save(ProfilePage
$page, $field, $value)
233 XDB
::execute("DELETE FROM profile_education
234 WHERE pid = {?} AND !(FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags))",
236 $schoolsList = DirEnum
::getOptions(DirEnum
::EDUSCHOOLS
);
237 foreach ($value as $eduid=>&$edu) {
238 if ($edu['eduid'] != '' && $schoolsList[$edu['eduid']] != Profile
::EDU_X
) {
239 $fieldId = ($edu['fieldid'] == 0) ? null
: $edu['fieldid'];
240 XDB
::execute("INSERT INTO profile_education
241 SET id = {?}, pid = {?}, eduid = {?}, degreeid = {?},
242 fieldid = {?}, grad_year = {?}, program = {?}",
243 $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'],
244 $fieldId, $edu['grad_year'], $edu['program']);
249 public function getText($value) {
250 $schoolsList = DirEnum
::getOptions(DirEnum
::EDUSCHOOLS
);
251 $degreesList = DirEnum
::getOptions(DirEnum
::EDUDEGREES
);
252 $fieldsList = DirEnum
::getOptions(DirEnum
::EDUFIELDS
);
253 $educations = array();
254 foreach ($value as $id => $education) {
255 // XXX: the following condition should be removed once there are no more incomplete educations.
256 if (is_null($education['eduid']) ||
is_null($education['degreeid'])) {
257 if (is_null($education['eduid']) && is_null($education['degreeid'])) {
258 $educations[$id] = 'formation manquante';
260 $educations[$id] = (is_null($education['eduid']) ?
'université manquante' : $schoolsList[$education['eduid']]) . ', '
261 . (is_null($education['degreeid']) ?
'diplôme manquant' : $degreesList[$education['degreeid']]);
264 $educations[$id] = $schoolsList[$education['eduid']] . ', ' . $degreesList[$education['degreeid']];
268 if ($education['grad_year']) {
269 $details[] = $education['grad_year'];
271 if ($education['program']) {
272 $details[] = '« ' . $education['program'] . ' »';
274 if ($education['fieldid']) {
275 $details[] = $fieldsList[$education['fieldid']];
277 if (count($details)) {
278 $educations[$id] .= ' (' . implode(', ', $details) . ')';
281 return implode(', ', $educations);
285 class ProfileSettingMainEdu
implements ProfileSetting
289 public function __construct()
291 $eduDegrees = DirEnum
::getOptions(DirEnum
::EDUDEGREES
);
292 $eduDegrees = array_flip($eduDegrees);
293 $this->cycles
= array(
294 $eduDegrees[Profile
::DEGREE_X
] => 'Cycle polytechnicien',
295 $eduDegrees[Profile
::DEGREE_M
] => 'Cycle master',
296 $eduDegrees[Profile
::DEGREE_D
] => 'Cycle doctoral'
300 public function value(ProfilePage
$page, $field, $value, &$success)
303 if (is_null($value)) {
305 $value = XDB
::fetchAllAssoc("SELECT degreeid, fieldid, promo_year, program
306 FROM profile_education
307 WHERE pid = {?} AND (FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags))
308 ORDER BY NOT FIND_IN_SET('primary', flags), degreeid",
311 foreach ($value as &$item) {
312 $item['cycle'] = $this->cycles
[$item['degreeid']];
314 } elseif (!is_array($value)) {
317 foreach ($value as $key => $item) {
318 if (!isset($item['degreeid'])) {
327 public function save(ProfilePage
$page, $field, $value)
329 foreach ($value as $item) {
330 $fieldId = ($item['fieldid'] == 0) ? null
: $item['fieldid'];
331 XDB
::execute("UPDATE profile_education
332 SET fieldid = {?}, program = {?}
333 WHERE pid = {?} AND (FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags)) AND degreeid = {?}",
334 $fieldId, $item['program'], $page->pid(), $item['degreeid']);
338 public function getText($value) {
339 $fieldsList = DirEnum
::getOptions(DirEnum
::EDUFIELDS
);
340 $educations = array();
341 foreach ($value as $item) {
342 $details = array($this->cycles
[$item['degreeid']]);
343 if ($item['program']) {
344 $details[] = '« ' . $item['program'] . ' »';
346 if ($item['fieldid']) {
347 $details[] = $fieldsList[$item['fieldid']];
350 return implode(', ', $educations);
354 class ProfileSettingEmailDirectory
implements ProfileSetting
356 public function __construct(){}
357 public function save(ProfilePage
$page, $field, $value){}
359 public function value(ProfilePage
$page, $field, $value, &$success)
364 if (!is_null($value)) {
365 $email_stripped = strtolower(trim($value));
366 if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values
['email_directory'] == "new@example.org")) {
367 $p->assign('email_error', '1');
368 $p->assign('email_directory_error', $email_stripped);
369 $p->trigError('Adresse Email invalide');
372 $p->assign('email_error', '0');
378 public function getText($value) {
383 class ProfileSettingNetworking
implements ProfileSetting
390 public function __construct()
392 $this->email
= new ProfileSettingEmail();
393 $this->pub
= new ProfileSettingPub();
394 $this->web
= new ProfileSettingWeb();
395 $this->number
= new ProfileSettingNumber();
398 public function value(ProfilePage
$page, $field, $value, &$success)
400 if (is_null($value)) {
401 $value = XDB
::fetchAllAssoc("SELECT n.address, n.pub, n.nwid AS type
402 FROM profile_networking AS n
406 if (!is_array($value)) {
409 $filters = XDB
::fetchAllAssoc('type', 'SELECT filter, nwid AS type, name
410 FROM profile_networking_enum;');
412 foreach($value as $i=>&$network) {
413 if (!trim($network['address'])) {
416 if (!isset($network['pub'])) {
417 $network['pub'] = 'private';
419 $network['error'] = false
;
420 $network['pub'] = $this->pub
->value($page, 'pub', $network['pub'], $s);
422 $network['name'] = $filters[$network['type']]['name'];
423 if ($filters[$network['type']]['filter'] == 'web') {
424 $network['address'] = $this->web
->value($page, 'address', $network['address'], $s);
425 } elseif ($filters[$network['type']]['filter'] == 'email') {
426 $network['address'] = $this->email
->value($page, 'address', $network['address'], $s);
427 } elseif ($filters[$network['type']]['filter'] == 'number') {
428 $network['address'] = $this->number
->value($page, 'address', $network['address'], $s);
432 $network['error'] = true
;
439 public function save(ProfilePage
$page, $field, $value)
441 XDB
::execute("DELETE FROM profile_networking
444 if (!count($value)) {
448 foreach ($value as $id=>$network) {
449 XDB
::execute("INSERT INTO profile_networking (pid, id, nwid, address, pub)
450 VALUES ({?}, {?}, {?}, {?}, {?})",
451 $page->pid(), $id, $network['type'], $network['address'], $network['pub']);
455 public function getText($value) {
456 static $pubs = array('public' => 'publique', 'ax' => 'annuaire papier', 'private' => 'privé', 'hidden' => 'administrateurs');
457 $networkings = array();
458 foreach ($value as $network) {
459 $networkings[] = $network['name'] . ' : ' . $network['address'] . ' (affichage ' . $pubs[$network['pub']] . ')';
461 return implode(', ' , $networkings);
465 class ProfileSettingHobby
implements ProfileSetting
468 static private $type = array('Sport', 'Loisir', 'Hobby');
470 public function __construct()
472 $this->pub
= new ProfileSettingPub();
475 public function value(ProfilePage
$page, $field, $value, &$success)
478 if (is_null($value)) {
479 $value = XDB
::fetchAllAssoc('SELECT type, text, pub
484 if (!is_array($value)) {
487 foreach($value as $i => &$hobby) {
488 $hobby['text'] = trim($hobby['text']);
489 if (!$hobby['text'] ||
!in_array($hobby['type'], self
::$type)) {
492 if (!isset($hobby['pub'])) {
493 $hobby['pub'] = 'private';
496 $hobby['pub'] = $this->pub
->value($page, 'pub', $hobby['pub'], $s);
497 $success = $success && $s;
503 public function save(ProfilePage
$page, $field, $value)
505 XDB
::execute('DELETE FROM profile_hobby
508 if (!count($value)) {
511 foreach ($value as $id => $hobby) {
512 XDB
::execute("INSERT INTO profile_hobby (pid, id, type, text, pub)
513 VALUES ({?}, {?}, {?}, {?}, {?})",
514 $page->pid(), $id, $hobby['type'], $hobby['text'], $hobby['pub']);
518 public function getText($value) {
519 static $pubs = array('public' => 'publique', 'ax' => 'annuaire papier', 'private' => 'privé', 'hidden' => 'administrateurs');
521 foreach (self
::$type as $type) {
522 $hobbies[$type] = array();
524 foreach ($value as $hobby) {
525 $hobbies[$hobby['type']][] = $hobby['text'] . ' (affichage ' . $pubs[$hobby['pub']] . ')';
528 foreach (self
::$type as $type) {
529 if (!empty($hobbies[$type])) {
530 $text[] = $hobbies[$type] . ' : ' . implode(', ' , $hobbies[$type]);
533 return implode(', ' , $text);
538 class ProfileSettingPromo
implements ProfileSetting
540 public function __construct(){}
542 public function save(ProfilePage
$page, $field, $value)
544 $gradYearNew = $value;
545 if ($page->profile
->mainEducation() == 'X') {
546 $gradYearNew +
= $page->profile
->mainEducationDuration();
548 if (($page->profile
->mainEducation() != 'X'
549 && $value == $page->profile
->entry_year +
$page->profile
->mainEducationDuration())
550 ||
($page->profile
->mainEducation() == 'X' && $value == $page->profile
->entry_year
)) {
551 XDB
::execute('UPDATE profile_display
554 $page->profile
->mainEducation() . strval($value), $page->profile
->id());
555 XDB
::execute('UPDATE profile_education
557 WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)',
558 $gradYearNew, $page->profile
->id());
559 Platal
::page()->trigSuccess('Ton statut « orange » a été supprimé.');
561 $myorange = new OrangeReq(S
::user(), $page->profile
, $gradYearNew);
563 Platal
::page()->trigSuccess('Tu pourras changer l\'affichage de ta promotion dès que ta nouvelle promotion aura été validée.');
567 public function value(ProfilePage
$page, $field, $value, &$success)
569 $entryYear = $page->profile
->entry_year
;
570 $gradYear = $page->profile
->grad_year
;
571 $yearpromo = $page->profile
->yearpromo();
573 if (is_null($value) ||
$value == $yearpromo) {
574 if ($gradYear != $entryYear +
$page->profile
->mainEducationDuration()) {
575 $promoChoice = array();
576 for ($i = $entryYear; $i <= $gradYear - $page->profile
->mainEducationDuration(); ++
$i) {
577 if ($page->profile
->mainEducation() == 'X') {
578 $promoChoice[] = $page->profile
->mainEducation() . strval($i);
580 $promoChoice[] = $page->profile
->mainEducation() . strval($i +
$page->profile
->mainEducationDuration());
583 Platal
::page()->assign('promo_choice', $promoChoice);
586 // If this profile belongs to an X, return grad year minus education duration.
587 if ($page->profile
->mainEducation() == 'X') {
588 return $gradYear - $page->profile
->mainEducationDuration();
594 // If this profile belongs to an X, $promoNew needs to be changed to
595 // the graduation year.
596 $gradYearNew = $value;
597 if ($page->profile
->mainEducation() == 'X') {
598 $gradYearNew +
= $page->profile
->mainEducationDuration();
601 if ($value < 1000 ||
$value > 9999) {
602 Platal
::page()->trigError('L\'année de sortie doit être un nombre de quatre chiffres.');
604 } elseif ($gradYearNew < $entryYear +
$page->profile
->mainEducationDuration()) {
605 Platal
::page()->trigError('Trop tôt !');
608 return intval($value);
611 public function getText($value) {
617 class ProfilePageGeneral
extends ProfilePage
619 protected $pg_template = 'profile/general.tpl';
621 public function __construct(PlWizard
$wiz)
623 parent
::__construct($wiz);
624 $this->settings
['search_names'] = new ProfileSettingSearchNames();
625 $this->settings
['nationality1'] = $this->settings
['nationality2']
626 = $this->settings
['nationality3']
627 = $this->settings
['promo_display']
628 = $this->settings
['profile_title']
630 $this->settings
['email_directory'] = new ProfileSettingEmail();
631 $this->settings
['email_directory_new'] = new ProfileSettingEmailDirectory();
632 $this->settings
['tels'] = new ProfileSettingPhones();
633 $this->settings
['edus'] = new ProfileSettingEdu();
634 $this->settings
['main_edus'] = new ProfileSettingMainEdu();
635 $this->settings
['promo'] = new ProfileSettingPromo();
636 $this->settings
['networking'] = new ProfileSettingNetworking();
637 $this->settings
['hobbies'] = new ProfileSettingHobby();
638 $this->watched
= array('tels' => true
,
639 'networking' => true
, 'edus' => true
,
640 'nationality1' => true
, 'nationality2' => true
,
641 'nationality3' => true
, 'search_names' => true
);
643 /* Some fields editable under condition */
644 if (!S
::user()->isMe($this->owner
)) {
645 $this->settings
['deathdate'] = new ProfileSettingDate(true
);
646 $this->settings
['birthdate'] = new ProfileSettingDate(true
);
647 $this->settings
['birthdate_ref'] = new ProfileSettingDate(true
);
648 $this->settings
['axfreetext'] = null
;
650 $this->settings
['yourself'] = null
;
651 $this->settings
['birthdate'] = new ProfileSettingDate();
653 if (S
::user()->checkPerms('directory_private')
654 || S
::user()->isMyProfile($this->owner
)) {
655 $this->settings
['freetext'] = null
;
656 $this->settings
['freetext_pub'] = $this->settings
['photo_pub']
657 = new ProfileSettingPub();
658 $this->watched
['freetext'] = true
;
661 Platal
::page()->assign('is_registered', ($this->owner
->perms ? true
: false
));
664 protected function _fetchData()
666 // Checkout all data...
667 $res = XDB
::query("SELECT p.nationality1, p.nationality2, p.nationality3, IF(p.birthdate = 0, '', p.birthdate) AS birthdate,
668 p.email_directory as email_directory, pd.promo AS promo_display,
669 p.freetext, p.freetext_pub, p.axfreetext, p.ax_id AS matricule_ax, pd.yourself,
670 p.deathdate, IF(p.birthdate_ref = 0, '', p.birthdate_ref) AS birthdate_ref,
671 p.title AS profile_title
673 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
674 WHERE p.pid = {?}", $this->pid());
675 $this->values
= $res->fetchOneAssoc();
677 // Retreive photo informations
678 $res = XDB
::query("SELECT pub
680 WHERE pid = {?}", $this->pid());
681 if ($res->numRows() == 0) {
682 $this->values
['photo_pub'] = 'private';
684 $this->values
['photo_pub'] = $res->fetchOneCell();
688 $res = XDB
::query("SELECT COUNT(*)
690 WHERE type = 'photo' AND pid = {?}",
692 $this->values
['nouvellephoto'] = $res->fetchOneCell();
694 $this->values
['nouvellephoto'] = 0;
698 protected function _saveData()
700 if ($this->changed
['nationality1'] ||
$this->changed
['nationality2'] ||
$this->changed
['nationality3']
701 ||
$this->changed
['birthdate'] ||
$this->changed
['freetext'] ||
$this->changed
['freetext_pub']
702 ||
$this->changed
['axfreetext'] ||
$this->changed
['email_directory'] ||
$this->changed
['profile_title']) {
703 if ($this->values
['nationality3'] == "") {
704 $this->values
['nationality3'] = NULL
;
706 if ($this->values
['nationality2'] == "") {
707 $this->values
['nationality2'] = $this->values
['nationality3'];
708 $this->values
['nationality3'] = NULL
;
710 if ($this->values
['nationality1'] == "") {
711 $this->values
['nationality1'] = $this->values
['nationality2'];
712 $this->values
['nationality2'] = $this->values
['nationality3'];
713 $this->values
['nationality3'] = NULL
;
715 if ($this->values
['nationality1'] == $this->values
['nationality2']
716 && $this->values
['nationality2'] == $this->values
['nationality3']) {
717 $this->values
['nationality2'] = NULL
;
718 $this->values
['nationality3'] = NULL
;
719 } else if ($this->values
['nationality1'] == $this->values
['nationality2']) {
720 $this->values
['nationality2'] = $this->values
['nationality3'];
721 $this->values
['nationality3'] = NULL
;
722 } else if ($this->values
['nationality2'] == $this->values
['nationality3']
723 ||
$this->values
['nationality1'] == $this->values
['nationality3']) {
724 $this->values
['nationality3'] = NULL
;
727 $new_email = ($this->values
['email_directory'] == "new@example.org") ?
728 $this->values
['email_directory_new'] : $this->values
['email_directory'];
729 if ($new_email == "") {
733 XDB
::execute("UPDATE profiles
734 SET nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?},
735 freetext = {?}, freetext_pub = {?}, axfreetext = {?}, email_directory = {?}, title = {?}
737 $this->values
['nationality1'], $this->values
['nationality2'], $this->values
['nationality3'],
738 ProfileSettingDate
::toSQLDate($this->values
['birthdate']),
739 $this->values
['freetext'], $this->values
['freetext_pub'], $this->values
['axfreetext'], $new_email,
740 $this->values
['profile_title'], $this->pid());
742 if ($this->changed
['photo_pub']) {
743 XDB
::execute("UPDATE profile_photos
746 $this->values
['photo_pub'], $this->pid());
748 if (S
::user()->isMe($this->owner
) && $this->changed
['yourself']) {
750 XDB
::execute('UPDATE accounts
751 SET display_name = {?}
753 $this->values
['yourself'], $this->owner
->id());
755 XDB
::execute('UPDATE profile_display
757 WHERE pid = {?}', $this->values
['yourself'],
760 if ($this->changed
['promo_display']) {
761 if ($this->values
['promo_display']{0} == $this->profile
->mainEducation()) {
762 $yearpromo = intval(substr($this->values
['promo_display'], 1, 4));
763 if (($this->profile
->mainEducation() == 'X' && $yearpromo >= $this->profile
->entry_year
)
764 ||
($this->profile
->mainEducation() != 'X'
765 && $yearpromo >= $this->profile
->entry_year +
$this->profile
->mainEducationDuration())) {
766 XDB
::execute('UPDATE profile_display
769 $this->values
['promo_display'], $this->pid());
770 XDB
::execute('UPDATE profile_education
772 WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)',
773 $yearpromo, $this->pid());
777 if ($this->changed
['birthdate_ref'] && S
::admin() && !$this->owner
->perms
) {
778 XDB
::execute('UPDATE profiles
779 SET birthdate_ref = {?}
781 ProfileSettingDate
::toSQLDate($this->values
['birthdate_ref']), $this->pid());
783 if (!S
::user()->isMe($this->owner
) && $this->changed
['deathdate']) {
784 XDB
::execute('UPDATE profiles
785 SET deathdate = {?}, deathdate_rec = NOW()
786 WHERE pid = {?} AND deathdate_rec IS NULL',
787 ProfileSettingDate
::toSQLDate($this->values
['deathdate']), $this->pid());
788 if (XDB
::affectedRows() > 0) {
789 $this->profile
->clear();
791 $this->owner
->clear(true
);
794 /* deathdate_rec was not NULL, this is just an update of the death date
796 XDB
::execute('UPDATE profiles
799 ProfileSettingDate
::toSQLDate($this->values
['deathdate']), $this->pid());
804 public function _prepare(PlPage
$page, $id)
806 require_once "education.func.inc.php";
808 $res = XDB
::query("SELECT id, field
809 FROM profile_education_field_enum
811 $page->assign('edu_fields', $res->fetchAllAssoc());
813 require_once "emails.combobox.inc.php";
814 fill_email_combobox($page, array('source', 'redirect', 'job', 'directory'), $this->owner
);
816 $res = XDB
::query("SELECT nw.nwid AS type, nw.name
817 FROM profile_networking_enum AS nw
819 $page->assign('network_list', $res->fetchAllAssoc());
821 $page->assign('lastnames', array('main' => 'Nom patronymique', 'marital' => 'Nom marital', 'ordinary' => 'Nom usuel'));
822 $page->assign('firstnames', array('firstname_main' => 'Prénom', 'firstname_ordinary' => 'Prénom usuel', 'pseudonym' => 'Pseudonyme (nom de plume)'));
823 $page->assign('other_names', array('nickname' => 'Surnom', 'firstname' => 'Autre prénom', 'lastname' => 'Autre nom'));
824 $page->assign('isFemale', $this->profile
->isFemale() ?
1 : 0);
828 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: