2 /***************************************************************************
3 * Copyright (C) 2003-2011 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 particles, lastname_main, lastname_marital, lastname_ordinary,
74 firstname_main, firstname_ordinary, pseudonym
75 FROM profile_public_names
79 $flags = new PlFlagSet($value['public_names']['particles']);
80 unset($value['public_names']['particles']);
81 static $suffixes = array('main', 'marital', 'ordinary');
83 foreach ($suffixes as $suffix) {
84 $value['public_names']['particle_' . $suffix] = $flags->hasFlag($suffix);
87 $value['public_names'] = $request;
88 Platal
::page()->assign('validation', true
);
91 $value['private_names'] = XDB
::fetchAllAssoc('SELECT type, name
92 FROM profile_private_names
97 foreach ($value['public_names'] as $key => $name) {
98 $value['public_names'][$key] = capitalize_name(trim($name));
100 if (isset($value['private_names'])) {
101 foreach ($value['private_names'] as $key => $name) {
102 $value['private_names'][$key]['name'] = trim($name['name']);
103 if ($value['private_names'][$key]['name'] == '') {
104 unset($value['private_names'][$key]);
109 if (S
::user()->isMe($page->owner
)) {
110 $success = $this->prepare($page, $value['public_names']);
114 $public_name = build_first_name($value['public_names']) . ' ' . build_full_last_name($value['public_names'], $page->profile
->isFemale());
115 if (isset($value['private_names'])) {
116 $private_name_end = build_private_name($value['private_names']);
117 $private_name = $public_name . $private_name_end;
119 $value['private_names'] = array();
120 $private_name = $public_name;
123 Platal
::page()->assign('public_name', $public_name);
124 Platal
::page()->assign('private_name', $private_name);
129 public function save(ProfilePage
$page, $field, $value)
131 require_once 'name.func.inc.php';
133 $old = XDB
::fetchOneAssoc('SELECT lastname_main, lastname_marital, lastname_ordinary,
134 firstname_main, firstname_ordinary, pseudonym
135 FROM profile_public_names
139 if ($has_diff = $this->diff($page->pid(), $old, $value['public_names'])) {
140 $new_names = new NamesReq(S
::user(), $page->profile
, $value['public_names'], $old);
141 $new_names->submit();
142 Platal
::page()->assign('validation', true
);
143 Platal
::page()->trigWarning('La demande de modification des noms a bien été prise en compte.' .
144 ' Un email sera envoyé dès que ces changements auront été effectués.');
147 XDB
::execute('DELETE FROM profile_private_names
151 $nickname = $lastname = $firstname = 0;
152 if (isset($value['private_names'])) {
153 foreach ($value['private_names'] as $name) {
154 $values[] = XDB
::format('({?}, {?}, {?}, {?})', $page->pid(), $name['type'], $
$name['type']++
, $name['name']);
157 if (count($values)) {
158 XDB
::rawExecute('INSERT INTO profile_private_names (pid, type, id, name)
159 VALUES ' . implode(',', $values));
163 update_display_names($page->profile
, $old, $value['private_names']);
165 update_display_names($page->profile
,
166 $value['public_names'], (isset($value['private_names']) ?
$value['private_names'] : null
));
170 public function getText($value) {
171 $public_names = array();
172 foreach ($value['public_names'] as $name) {
174 $public_names[] = $name;
178 if (isset($value['private_names']) && count($value['private_names'])) {
179 $private_names = array();
180 foreach ($value['private_names'] as $name) {
181 $private_names[] = $name['name'];
183 return 'noms publics : ' . implode(', ' , $public_names) . ', noms privés : ' . implode(', ' , $private_names);;
186 return 'noms publics : ' . implode(', ' , $public_names);
190 class ProfileSettingEdu
implements ProfileSetting
192 public function __construct() {
195 static function sortByGradYear($line1, $line2) {
196 $a = (isset($line1['grad_year'])) ?
(int) $line1['grad_year'] : 0;
197 $b = (isset($line2['grad_year'])) ?
(int) $line2['grad_year'] : 0;
201 return ($a < $b) ?
-1 : 1;
204 public function value(ProfilePage
$page, $field, $value, &$success)
207 if (is_null($value)) {
209 $value = XDB
::fetchAllAssoc("SELECT eduid, degreeid, fieldid, grad_year, program
210 FROM profile_education
211 WHERE pid = {?} AND !(FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags))
214 } else if (!is_array($value)) {
218 foreach ($value as $key=>&$edu) {
219 if ($edu['eduid'] < 1 ||
!isset($edu['degreeid']) ||
$edu['degreeid'] < 1) {
220 Platal
::page()->trigError('L\'université ou le diplôme d\'une formation manque.');
223 if (($edu['grad_year'] < 1921) ||
($edu['grad_year'] > (date('Y') +
4))) {
224 Platal
::page()->trigWarning('L\'année d\'obtention du diplôme est mal ou non renseignée, elle doit être du type : 2004.');
225 $edu['grad_year'] = null
;
226 $edu['warning'] = true
;
234 usort($value, array("ProfileSettingEdu", "sortByGradYear"));
239 public function save(ProfilePage
$page, $field, $value)
241 XDB
::execute("DELETE FROM profile_education
242 WHERE pid = {?} AND !(FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags))",
244 $schoolsList = DirEnum
::getOptions(DirEnum
::EDUSCHOOLS
);
245 foreach ($value as $eduid=>&$edu) {
246 if ($edu['eduid'] != '' && $schoolsList[$edu['eduid']] != Profile
::EDU_X
) {
247 $fieldId = ($edu['fieldid'] == 0) ? null
: $edu['fieldid'];
248 XDB
::execute("INSERT INTO profile_education
249 SET id = {?}, pid = {?}, eduid = {?}, degreeid = {?},
250 fieldid = {?}, grad_year = {?}, program = {?}",
251 $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'],
252 $fieldId, $edu['grad_year'], $edu['program']);
257 public function getText($value) {
258 $schoolsList = DirEnum
::getOptions(DirEnum
::EDUSCHOOLS
);
259 $degreesList = DirEnum
::getOptions(DirEnum
::EDUDEGREES
);
260 $fieldsList = DirEnum
::getOptions(DirEnum
::EDUFIELDS
);
261 $educations = array();
262 foreach ($value as $id => $education) {
263 // XXX: the following condition should be removed once there are no more incomplete educations.
264 if (is_null($education['eduid']) ||
is_null($education['degreeid'])) {
265 if (is_null($education['eduid']) && is_null($education['degreeid'])) {
266 $educations[$id] = 'formation manquante';
268 $educations[$id] = (is_null($education['eduid']) ?
'université manquante' : $schoolsList[$education['eduid']]) . ', '
269 . (is_null($education['degreeid']) ?
'diplôme manquant' : $degreesList[$education['degreeid']]);
272 $educations[$id] = $schoolsList[$education['eduid']] . ', ' . $degreesList[$education['degreeid']];
276 if ($education['grad_year']) {
277 $details[] = $education['grad_year'];
279 if ($education['program']) {
280 $details[] = '« ' . $education['program'] . ' »';
282 if ($education['fieldid']) {
283 $details[] = $fieldsList[$education['fieldid']];
285 if (count($details)) {
286 $educations[$id] .= ' (' . implode(', ', $details) . ')';
289 return implode(', ', $educations);
293 class ProfileSettingMainEdu
implements ProfileSetting
297 public function __construct()
299 $eduDegrees = DirEnum
::getOptions(DirEnum
::EDUDEGREES
);
300 $eduDegrees = array_flip($eduDegrees);
301 $this->cycles
= array(
302 $eduDegrees[Profile
::DEGREE_X
] => 'Cycle polytechnicien',
303 $eduDegrees[Profile
::DEGREE_M
] => 'Cycle master',
304 $eduDegrees[Profile
::DEGREE_D
] => 'Cycle doctoral'
308 public function value(ProfilePage
$page, $field, $value, &$success)
311 if (is_null($value)) {
313 $value = XDB
::fetchAllAssoc("SELECT degreeid, fieldid, promo_year, program
314 FROM profile_education
315 WHERE pid = {?} AND (FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags))
316 ORDER BY NOT FIND_IN_SET('primary', flags), degreeid",
319 foreach ($value as &$item) {
320 $item['cycle'] = $this->cycles
[$item['degreeid']];
322 } elseif (!is_array($value)) {
325 foreach ($value as $key => $item) {
326 if (!isset($item['degreeid'])) {
335 public function save(ProfilePage
$page, $field, $value)
337 foreach ($value as $item) {
338 $fieldId = ($item['fieldid'] == 0) ? null
: $item['fieldid'];
339 XDB
::execute("UPDATE profile_education
340 SET fieldid = {?}, program = {?}
341 WHERE pid = {?} AND (FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags)) AND degreeid = {?}",
342 $fieldId, $item['program'], $page->pid(), $item['degreeid']);
346 public function getText($value) {
347 $fieldsList = DirEnum
::getOptions(DirEnum
::EDUFIELDS
);
348 $educations = array();
349 foreach ($value as $item) {
350 $details = array($this->cycles
[$item['degreeid']]);
351 if ($item['program']) {
352 $details[] = '« ' . $item['program'] . ' »';
354 if ($item['fieldid']) {
355 $details[] = $fieldsList[$item['fieldid']];
358 return implode(', ', $educations);
362 class ProfileSettingEmailDirectory
implements ProfileSetting
364 public function __construct(){}
365 public function save(ProfilePage
$page, $field, $value){}
367 public function value(ProfilePage
$page, $field, $value, &$success)
372 if (!is_null($value)) {
373 $email_stripped = strtolower(trim($value));
374 if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values
['email_directory'] == "new@example.org")) {
375 $p->assign('email_error', '1');
376 $p->assign('email_directory_error', $email_stripped);
377 $p->trigError('Adresse Email invalide');
380 $p->assign('email_error', '0');
386 public function getText($value) {
391 class ProfileSettingNetworking
implements ProfileSetting
398 public function __construct()
400 $this->email
= new ProfileSettingEmail();
401 $this->pub
= new ProfileSettingPub();
402 $this->web
= new ProfileSettingWeb();
403 $this->number
= new ProfileSettingNumber();
406 public function value(ProfilePage
$page, $field, $value, &$success)
408 if (is_null($value)) {
409 $value = XDB
::fetchAllAssoc("SELECT n.address, n.pub, n.nwid AS type
410 FROM profile_networking AS n
414 if (!is_array($value)) {
417 $filters = XDB
::fetchAllAssoc('type', 'SELECT filter, nwid AS type, name
418 FROM profile_networking_enum;');
420 foreach($value as $i=>&$network) {
421 if (!trim($network['address'])) {
424 if (!isset($network['pub'])) {
425 $network['pub'] = 'private';
427 $network['error'] = false
;
428 $network['pub'] = $this->pub
->value($page, 'pub', $network['pub'], $s);
430 $network['name'] = $filters[$network['type']]['name'];
431 if ($filters[$network['type']]['filter'] == 'web') {
432 $network['address'] = $this->web
->value($page, 'address', $network['address'], $s);
433 } elseif ($filters[$network['type']]['filter'] == 'email') {
434 $network['address'] = $this->email
->value($page, 'address', $network['address'], $s);
435 } elseif ($filters[$network['type']]['filter'] == 'number') {
436 $network['address'] = $this->number
->value($page, 'address', $network['address'], $s);
440 $network['error'] = true
;
447 public function save(ProfilePage
$page, $field, $value)
449 XDB
::execute("DELETE FROM profile_networking
452 if (!count($value)) {
456 foreach ($value as $id=>$network) {
457 XDB
::execute("INSERT INTO profile_networking (pid, id, nwid, address, pub)
458 VALUES ({?}, {?}, {?}, {?}, {?})",
459 $page->pid(), $id, $network['type'], $network['address'], $network['pub']);
463 public function getText($value) {
464 static $pubs = array('public' => 'publique', 'ax' => 'annuaire AX', 'private' => 'privé');
465 $networkings = array();
466 foreach ($value as $network) {
467 $networkings[] = $network['name'] . ' : ' . $network['address'] . ' (affichage ' . $pubs[$network['pub']] . ')';
469 return implode(', ' , $networkings);
473 class ProfileSettingHobby
implements ProfileSetting
476 static private $type = array('Sport', 'Loisir', 'Hobby');
478 public function __construct()
480 $this->pub
= new ProfileSettingPub();
483 public function value(ProfilePage
$page, $field, $value, &$success)
486 if (is_null($value)) {
487 $value = XDB
::fetchAllAssoc('SELECT type, text, pub
492 if (!is_array($value)) {
495 foreach($value as $i => &$hobby) {
496 $hobby['text'] = trim($hobby['text']);
497 if (!$hobby['text'] ||
!in_array($hobby['type'], self
::$type)) {
500 if (!isset($hobby['pub'])) {
501 $hobby['pub'] = 'private';
504 $hobby['pub'] = $this->pub
->value($page, 'pub', $hobby['pub'], $s);
505 $success = $success && $s;
511 public function save(ProfilePage
$page, $field, $value)
513 XDB
::execute('DELETE FROM profile_hobby
516 if (!count($value)) {
519 foreach ($value as $id => $hobby) {
520 XDB
::execute("INSERT INTO profile_hobby (pid, id, type, text, pub)
521 VALUES ({?}, {?}, {?}, {?}, {?})",
522 $page->pid(), $id, $hobby['type'], $hobby['text'], $hobby['pub']);
526 public function getText($value) {
527 static $pubs = array('public' => 'publique', 'private' => 'privé');
529 foreach (self
::$type as $type) {
530 $hobbies[$type] = array();
532 foreach ($value as $hobby) {
533 $hobbies[$hobby['type']][] = $hobby['text'] . ' (affichage ' . $pubs[$hobby['pub']] . ')';
536 foreach (self
::$type as $type) {
537 if (!empty($hobbies[$type])) {
538 $text[] = $hobbies[$type] . ' : ' . implode(', ' , $hobbies[$type]);
541 return implode(', ' , $text);
546 class ProfileSettingPromo
implements ProfileSetting
548 public function __construct(){}
550 public function save(ProfilePage
$page, $field, $value)
552 $gradYearNew = $value;
553 if ($page->profile
->mainEducation() == 'X') {
554 $gradYearNew +
= $page->profile
->mainEducationDuration();
556 if (($page->profile
->mainEducation() != 'X'
557 && $value == $page->profile
->entry_year +
$page->profile
->mainEducationDuration())
558 ||
($page->profile
->mainEducation() == 'X' && $value == $page->profile
->entry_year
)) {
559 XDB
::execute('UPDATE profile_display
562 $page->profile
->mainEducation() . strval($value), $page->profile
->id());
563 XDB
::execute('UPDATE profile_education
565 WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)',
566 $gradYearNew, $page->profile
->id());
567 Platal
::page()->trigSuccess('Ton statut « orange » a été supprimé.');
569 $myorange = new OrangeReq(S
::user(), $page->profile
, $gradYearNew);
571 Platal
::page()->trigSuccess('Tu pourras changer l\'affichage de ta promotion dès que ta nouvelle promotion aura été validée.');
575 public function value(ProfilePage
$page, $field, $value, &$success)
577 $entryYear = $page->profile
->entry_year
;
578 $gradYear = $page->profile
->grad_year
;
579 $yearpromo = $page->profile
->yearpromo();
581 if (is_null($value) ||
$value == $yearpromo) {
582 if ($gradYear != $entryYear +
$page->profile
->mainEducationDuration()) {
583 $promoChoice = array();
584 for ($i = $entryYear; $i <= $gradYear - $page->profile
->mainEducationDuration(); ++
$i) {
585 if ($page->profile
->mainEducation() == 'X') {
586 $promoChoice[] = $page->profile
->mainEducation() . strval($i);
588 $promoChoice[] = $page->profile
->mainEducation() . strval($i +
$page->profile
->mainEducationDuration());
591 Platal
::page()->assign('promo_choice', $promoChoice);
594 // If this profile belongs to an X, return grad year minus education duration.
595 if ($page->profile
->mainEducation() == 'X') {
596 return $gradYear - $page->profile
->mainEducationDuration();
602 // If this profile belongs to an X, $promoNew needs to be changed to
603 // the graduation year.
604 $gradYearNew = $value;
605 if ($page->profile
->mainEducation() == 'X') {
606 $gradYearNew +
= $page->profile
->mainEducationDuration();
609 if ($value < 1000 ||
$value > 9999) {
610 Platal
::page()->trigError('L\'année de sortie doit être un nombre de quatre chiffres.');
612 } elseif ($gradYearNew < $entryYear +
$page->profile
->mainEducationDuration()) {
613 Platal
::page()->trigError('Trop tôt !');
616 return intval($value);
619 public function getText($value) {
625 class ProfilePageGeneral
extends ProfilePage
627 protected $pg_template = 'profile/general.tpl';
629 public function __construct(PlWizard
$wiz)
631 parent
::__construct($wiz);
632 $this->settings
['search_names'] = new ProfileSettingSearchNames();
633 $this->settings
['nationality1'] = $this->settings
['nationality2']
634 = $this->settings
['nationality3']
635 = $this->settings
['promo_display']
636 = $this->settings
['profile_title']
638 $this->settings
['email_directory'] = new ProfileSettingEmail();
639 $this->settings
['email_directory_new'] = new ProfileSettingEmailDirectory();
640 $this->settings
['tels'] = new ProfileSettingPhones();
641 $this->settings
['edus'] = new ProfileSettingEdu();
642 $this->settings
['main_edus'] = new ProfileSettingMainEdu();
643 $this->settings
['promo'] = new ProfileSettingPromo();
644 $this->settings
['networking'] = new ProfileSettingNetworking();
645 $this->settings
['hobbies'] = new ProfileSettingHobby();
646 $this->watched
= array('tels' => true
,
647 'networking' => true
, 'edus' => true
,
648 'nationality1' => true
, 'nationality2' => true
,
649 'nationality3' => true
, 'search_names' => true
);
651 /* Some fields editable under condition */
652 if (!S
::user()->isMe($this->owner
)) {
653 $this->settings
['deathdate'] = new ProfileSettingDate(true
);
654 $this->settings
['birthdate'] = new ProfileSettingDate(true
);
655 $this->settings
['birthdate_ref'] = new ProfileSettingDate(true
);
657 $this->settings
['yourself'] = null
;
658 $this->settings
['birthdate'] = new ProfileSettingDate();
660 if (S
::user()->checkPerms('directory_private')
661 || S
::user()->isMyProfile($this->owner
)) {
662 $this->settings
['freetext'] = null
;
663 $this->settings
['freetext_pub'] = $this->settings
['photo_pub']
664 = new ProfileSettingPub();
665 $this->watched
['freetext'] = true
;
668 Platal
::page()->assign('is_registered', ($this->owner
->perms ? true
: false
));
671 protected function _fetchData()
673 // Checkout all data...
674 $res = XDB
::query("SELECT p.nationality1, p.nationality2, p.nationality3, IF(p.birthdate = 0, '', p.birthdate) AS birthdate,
675 p.email_directory as email_directory, pd.promo AS promo_display,
676 p.freetext, p.freetext_pub, p.ax_id AS matricule_ax, pd.yourself,
677 p.deathdate, IF(p.birthdate_ref = 0, '', p.birthdate_ref) AS birthdate_ref,
678 p.title AS profile_title
680 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
681 WHERE p.pid = {?}", $this->pid());
682 $this->values
= $res->fetchOneAssoc();
684 // Retreive photo informations
685 $res = XDB
::query("SELECT pub
687 WHERE pid = {?}", $this->pid());
688 if ($res->numRows() == 0) {
689 $this->values
['photo_pub'] = 'private';
691 $this->values
['photo_pub'] = $res->fetchOneCell();
695 $res = XDB
::query("SELECT COUNT(*)
697 WHERE type = 'photo' AND pid = {?}",
699 $this->values
['nouvellephoto'] = $res->fetchOneCell();
701 $this->values
['nouvellephoto'] = 0;
705 protected function _saveData()
707 if ($this->changed
['nationality1'] ||
$this->changed
['nationality2'] ||
$this->changed
['nationality3']
708 ||
$this->changed
['birthdate'] ||
$this->changed
['freetext'] ||
$this->changed
['freetext_pub']
709 ||
$this->changed
['email_directory'] ||
$this->changed
['profile_title']) {
710 if ($this->values
['nationality3'] == "") {
711 $this->values
['nationality3'] = NULL
;
713 if ($this->values
['nationality2'] == "") {
714 $this->values
['nationality2'] = $this->values
['nationality3'];
715 $this->values
['nationality3'] = NULL
;
717 if ($this->values
['nationality1'] == "") {
718 $this->values
['nationality1'] = $this->values
['nationality2'];
719 $this->values
['nationality2'] = $this->values
['nationality3'];
720 $this->values
['nationality3'] = NULL
;
722 if ($this->values
['nationality1'] == $this->values
['nationality2']
723 && $this->values
['nationality2'] == $this->values
['nationality3']) {
724 $this->values
['nationality2'] = NULL
;
725 $this->values
['nationality3'] = NULL
;
726 } else if ($this->values
['nationality1'] == $this->values
['nationality2']) {
727 $this->values
['nationality2'] = $this->values
['nationality3'];
728 $this->values
['nationality3'] = NULL
;
729 } else if ($this->values
['nationality2'] == $this->values
['nationality3']
730 ||
$this->values
['nationality1'] == $this->values
['nationality3']) {
731 $this->values
['nationality3'] = NULL
;
734 $new_email = ($this->values
['email_directory'] == "new@example.org") ?
735 $this->values
['email_directory_new'] : $this->values
['email_directory'];
736 if ($new_email == "") {
740 XDB
::execute("UPDATE profiles
741 SET nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?},
742 freetext = {?}, freetext_pub = {?}, email_directory = {?}, title = {?}
744 $this->values
['nationality1'], $this->values
['nationality2'], $this->values
['nationality3'],
745 ProfileSettingDate
::toSQLDate($this->values
['birthdate']),
746 $this->values
['freetext'], $this->values
['freetext_pub'], $new_email,
747 $this->values
['profile_title'], $this->pid());
749 if ($this->changed
['photo_pub']) {
750 XDB
::execute("UPDATE profile_photos
753 $this->values
['photo_pub'], $this->pid());
755 if (S
::user()->isMe($this->owner
) && $this->changed
['yourself']) {
757 XDB
::execute('UPDATE accounts
758 SET display_name = {?}
760 $this->values
['yourself'], $this->owner
->id());
762 XDB
::execute('UPDATE profile_display
764 WHERE pid = {?}', $this->values
['yourself'],
767 if ($this->changed
['promo_display']) {
768 if ($this->values
['promo_display']{0} == $this->profile
->mainEducation()) {
769 $yearpromo = intval(substr($this->values
['promo_display'], 1, 4));
770 if (($this->profile
->mainEducation() == 'X' && $yearpromo >= $this->profile
->entry_year
)
771 ||
($this->profile
->mainEducation() != 'X'
772 && $yearpromo >= $this->profile
->entry_year +
$this->profile
->mainEducationDuration())) {
773 XDB
::execute('UPDATE profile_display
776 $this->values
['promo_display'], $this->pid());
777 XDB
::execute('UPDATE profile_education
779 WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)',
780 $yearpromo, $this->pid());
784 if ($this->changed
['birthdate_ref'] && S
::admin() && !$this->owner
->perms
) {
785 XDB
::execute('UPDATE profiles
786 SET birthdate_ref = {?}
788 ProfileSettingDate
::toSQLDate($this->values
['birthdate_ref']), $this->pid());
790 if (!S
::user()->isMe($this->owner
) && $this->changed
['deathdate']) {
791 XDB
::execute('UPDATE profiles
792 SET deathdate = {?}, deathdate_rec = NOW()
793 WHERE pid = {?} AND deathdate_rec IS NULL',
794 ProfileSettingDate
::toSQLDate($this->values
['deathdate']), $this->pid());
795 if (XDB
::affectedRows() > 0) {
796 $this->profile
->clear();
798 $this->owner
->clear(true
);
801 /* deathdate_rec was not NULL, this is just an update of the death date
803 XDB
::execute('UPDATE profiles
806 ProfileSettingDate
::toSQLDate($this->values
['deathdate']), $this->pid());
811 public function _prepare(PlPage
$page, $id)
813 require_once "education.func.inc.php";
815 $res = XDB
::query("SELECT id, field
816 FROM profile_education_field_enum
818 $page->assign('edu_fields', $res->fetchAllAssoc());
820 require_once "emails.combobox.inc.php";
821 fill_email_combobox($page, array('source', 'redirect', 'job', 'directory'), $this->owner
);
823 $res = XDB
::query("SELECT nw.nwid AS type, nw.name
824 FROM profile_networking_enum AS nw
826 $page->assign('network_list', $res->fetchAllAssoc());
828 $page->assign('lastnames', array('main' => 'Nom patronymique', 'marital' => 'Nom marital', 'ordinary' => 'Nom usuel'));
829 $page->assign('firstnames', array('firstname_main' => 'Prénom', 'firstname_ordinary' => 'Prénom usuel', 'pseudonym' => 'Pseudonyme (nom de plume)'));
830 $page->assign('other_names', array('nickname' => 'Surnom', 'firstname' => 'Autre prénom', 'lastname' => 'Autre nom'));
831 $page->assign('isFemale', $this->profile
->isFemale() ?
1 : 0);
835 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: