AX enabled version of the first page of the profile edition.
[platal.git] / modules / profile / general.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
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
22 class ProfileSettingSearchNames implements ProfileSetting
23 {
24 private $private_name_end;
25 private $search_names;
26 private $name_types;
27
28 public function __construct() {
29 $this->name_types = DirEnum::getOptions(DirEnum::NAMES);
30 }
31
32 private function matchWord($old, $new, $newLen)
33 {
34 return ($i = strpos($old, $new)) !== false
35 && ($i == 0 || $old{$i-1} == ' ')
36 && ($i + $newLen == strlen($old) || $old{$i + $newLen} == ' ');
37 }
38
39 private function prepareField($value)
40 {
41 return name_to_basename($value);
42 }
43
44 private function prepare(ProfilePage &$page, $field, $value, $init, &$success)
45 {
46 $success = true;
47 $ini = $this->prepareField($init);
48 $new = $this->prepareField($value);
49 $newLen = strlen($new);
50 $success = $this->matchWord($ini, $new, $newLen)
51 || ($field == 'lastname' && $new == 'DE ' . $ini);
52 if (!$success) {
53 $field = strtolower($field);
54 Platal::page()->trigError("Le " . $this->name_types[$field] . " que tu as choisi (" . $value .
55 ") est trop loin de ton " . $this->name_types[$field] . " initial (" . $init . ").");
56 }
57 return $success ? $value : $init;
58 }
59
60 /* Removes duplicated entries for the fields that do not allow them. */
61 private function clean($value)
62 {
63 $single_types = XDB::fetchAllAssoc('id',
64 'SELECT id, 0
65 FROM profile_name_enum
66 WHERE NOT FIND_IN_SET(\'allow_duplicates\', flags)');
67
68 foreach ($value as $key => $item) {
69 if (isset($single_types[$item['typeid']])) {
70 if ($single_types[$item['typeid']] === true) {
71 unset($value[$key]);
72 } else {
73 $single_types[$item['typeid']] = true;
74 }
75 }
76 }
77
78 return $value;
79 }
80
81 public function value(ProfilePage &$page, $field, $value, &$success)
82 {
83 $success = true;
84 $success_tmp = true;
85
86 if (is_null($value)) {
87 $sn_all = XDB::iterator("SELECT CONCAT(sn.particle, sn.name) AS name,
88 sn.particle, sn.typeid, e.type, e.name AS type_name,
89 FIND_IN_SET('has_particle', e.flags) AS has_particle,
90 FIND_IN_SET('always_displayed', e.flags) AS always_displayed,
91 FIND_IN_SET('public', e.flags) AS pub
92 FROM profile_name AS sn
93 INNER JOIN profile_name_enum AS e ON (e.id = sn.typeid)
94 WHERE sn.pid = {?} AND NOT FIND_IN_SET('not_displayed', e.flags)
95 ORDER BY NOT FIND_IN_SET('always_displayed', e.flags), e.id, sn.name",
96 $page->pid());
97
98 $sn_types = XDB::iterator("SELECT id, type, name,
99 FIND_IN_SET('has_particle', flags) AS has_particle
100 FROM profile_name_enum
101 WHERE NOT FIND_IN_SET('not_displayed', flags)
102 AND FIND_IN_SET('always_displayed', flags)
103 ORDER BY id");
104
105 $value = array();
106 $sn = $sn_all->next();
107 while ($sn_type = $sn_types->next()) {
108 if ($sn_type['id'] == $sn['typeid']) {
109 $value[] = $sn;
110 if ($sn) {
111 $sn = $sn_all->next();
112 }
113 } else {
114 $value[] = array('name' => '',
115 'particle' => '',
116 'typeid' => $sn_type['id'],
117 'type' => $sn_type['type'],
118 'type_name' => $sn_type['name'],
119 'has_particle' => $sn_type['has_particle'],
120 'always_displayed' => 1,
121 'pub' => 1);
122 }
123 }
124 if ($sn) {
125 do {
126 $value[] = $sn;
127 } while ($sn = $sn_all->next());
128 }
129 $namesRequest = ProfileValidate::get_typed_requests($page->pid(), 'usage');
130 if (count($namesRequest) > 0) {
131 Platal::page()->assign('validation', true);
132 }
133 $value = $this->clean($value);
134 } else {
135 require_once 'name.func.inc.php';
136
137 $value = $this->clean($value);
138 $res = XDB::query("SELECT s.particle, s.name
139 FROM profile_name AS s
140 INNER JOIN profile_name_enum AS e ON (e.id = s.typeid)
141 WHERE s.pid = {?} AND (e.type = 'lastname' OR e.type = 'firstname')
142 ORDER BY e.type = 'firstname'",
143 $page->pid());
144 $res = $res->fetchAllAssoc();
145 $initial = array();
146 $initial['lastname'] = $res[0]['particle'] . $res[0]['name'];
147 $initial['firstname'] = $res[1]['name'];
148 $sn_types = build_types();
149 $this->search_names = array();
150 foreach ($value as &$sn) {
151 $sn['name'] = trim($sn['name']);
152 if ($sn['type'] == 'firstname' || $sn['type'] == 'lastname') {
153 $sn['name'] = $this->prepare($page, $sn['type'], $sn['name'],
154 $initial[$sn['type']], $success_tmp);
155 $success = $success && $success_tmp;
156 }
157 if ($sn['pub']) {
158 if (isset($sn['particle']) && ($sn['particle'] != '')) {
159 // particle is before first blank
160 list($particle, $name) = explode(' ', $sn['name'], 2);
161 $particle = trim($particle) . ' ';
162 if (!$name) {
163 // particle is before first quote
164 list($particle, $name) = explode('\'', $sn['name'], 2);
165 $particle = trim($particle);
166 if (!$name) {
167 // actually there is no particle
168 $particle = '';
169 $name = $sn['name'];
170 }
171 }
172 } else {
173 $particle = '';
174 $name = $sn['name'];
175 }
176 }
177 if ($sn['name'] != '') {
178 if ($sn['pub']) {
179 $this->search_names[$sn['typeid']] = array('fullname' => $sn['name'],
180 'name' => $name,
181 'particle' => $particle,
182 'pub' => $sn['pub']);
183 } else {
184 if (isset($this->search_names[$sn['typeid']])) {
185 $this->search_names[$sn['typeid']][] = $sn['name'];
186 } else {
187 $this->search_names[$sn['typeid']] = array('fullname' => $sn['name']);
188 }
189 $sn['type_name'] = $sn_types[$sn['typeid']];
190 }
191 }
192 }
193 $res = XDB::query("SELECT public_name, private_name
194 FROM profile_display
195 WHERE pid = {?}",
196 $page->pid());
197 list($public_name, $private_name) = $res->fetchOneRow();
198 if ($success) {
199 $sn_types_private = build_types('private');
200 $this->private_name_end = build_private_name($this->search_names, $sn_types_private);
201 $private_name = $public_name . $this->private_name_end;
202 }
203 Platal::page()->assign('public_name', $public_name);
204 Platal::page()->assign('private_name', $private_name);
205 }
206
207 return $value;
208 }
209
210 public function save(ProfilePage &$page, $field, $value)
211 {
212 require_once 'name.func.inc.php';
213
214 $sn_old = build_sn_pub($page->pid());
215 XDB::execute("DELETE FROM s
216 USING profile_name AS s
217 INNER JOIN profile_name_enum AS e ON (s.typeid = e.id)
218 WHERE s.pid = {?} AND NOT FIND_IN_SET('not_displayed', e.flags)",
219 $page->pid());
220 $has_new = set_alias_names($this->search_names, $sn_old, $page->pid(), $page->owner->id());
221
222 // Only requires validation if modification in public names
223 if ($has_new) {
224 $new_names = new NamesReq(S::user(), $page->profile, $this->search_names, $this->private_name_end);
225 $new_names->submit();
226 Platal::page()->trigWarning('La demande de modification de tes noms a bien été prise en compte.' .
227 ' Tu recevras un email dès que ces changements auront été effectués.');
228 } else {
229 $display_names = array();
230 build_display_names($display_names, $this->search_names,
231 $page->profile->isFemale(), $this->private_name_end);
232 set_profile_display($display_names, $page->profile);
233 }
234 }
235
236 public function getText($value) {
237 $names = array();
238 foreach ($value as $name) {
239 if ($name['name'] != '') {
240 $names[] = $name['type_name'] . ' : ' . $name['name'];
241 }
242 }
243 return implode(', ' , $names);
244 }
245 }
246
247 class ProfileSettingEdu implements ProfileSetting
248 {
249 public function __construct() {
250 }
251
252 static function sortByGradYear($line1, $line2) {
253 $a = (isset($line1['grad_year'])) ? (int) $line1['grad_year'] : 0;
254 $b = (isset($line2['grad_year'])) ? (int) $line2['grad_year'] : 0;
255 if ($a == $b) {
256 return 0;
257 }
258 return ($a < $b) ? -1 : 1;
259 }
260
261 public function value(ProfilePage &$page, $field, $value, &$success)
262 {
263 $success = true;
264 if (is_null($value)) {
265 $value = array();
266 $value = XDB::fetchAllAssoc("SELECT eduid, degreeid, fieldid, grad_year, program
267 FROM profile_education
268 WHERE pid = {?} AND !FIND_IN_SET('primary', flags)
269 ORDER BY id",
270 $page->pid());
271 } else if (!is_array($value)) {
272 $value = null;
273 } else {
274 $i = 0;
275 foreach ($value as $key=>&$edu) {
276 if ($edu['eduid'] < 1 || !isset($edu['degreeid']) || $edu['degreeid'] < 1) {
277 Platal::page()->trigError('L\'université ou le diplôme d\'une formation manque.');
278 $success = false;
279 }
280 if (($edu['grad_year'] < 1921) || ($edu['grad_year'] > (date('Y') + 4))) {
281 Platal::page()->trigWarning('L\'année d\'obtention du diplôme est mal ou non renseignée, elle doit être du type : 2004.');
282 $edu['grad_year'] = null;
283 $edu['warning'] = true;
284 }
285 if ($key != $i) {
286 $value[$i] = $edu;
287 unset($value[$key]);
288 }
289 $i++;
290 }
291 usort($value, array("ProfileSettingEdu", "sortByGradYear"));
292 }
293 return $value;
294 }
295
296 public function save(ProfilePage &$page, $field, $value)
297 {
298 XDB::execute("DELETE FROM profile_education
299 WHERE pid = {?} AND !FIND_IN_SET('primary', flags)",
300 $page->pid());
301 foreach ($value as $eduid=>&$edu) {
302 if ($edu['eduid'] != '') {
303 $fieldId = ($edu['fieldid'] == 0) ? null : $edu['fieldid'];
304 XDB::execute("INSERT INTO profile_education
305 SET id = {?}, pid = {?}, eduid = {?}, degreeid = {?},
306 fieldid = {?}, grad_year = {?}, program = {?}",
307 $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'],
308 $fieldId, $edu['grad_year'], $edu['program']);
309 }
310 }
311 }
312
313 public function getText($value) {
314 $schoolsList = DirEnum::getOptions(DirEnum::EDUSCHOOLS);
315 $degreesList = DirEnum::getOptions(DirEnum::EDUDEGREES);
316 $fieldsList = DirEnum::getOptions(DirEnum::EDUFIELDS);
317 $educations = array();
318 foreach ($value as $education) {
319 $educations[] = 'Université : ' . $schoolsList[$education['eduid']]
320 . ', diplôme : ' . $degreesList[$education['degreeid']]
321 . ', domaine : ' . $fieldsList[$education['fieldid']]
322 . ', année d\'obtention : ' . $education['grad_year']
323 . ', intitulé : ' . $education['program'];
324 }
325 return implode(', ', $educations);
326 }
327 }
328
329 class ProfileSettingEmailDirectory implements ProfileSetting
330 {
331 public function __construct(){}
332 public function save(ProfilePage &$page, $field, $value){}
333
334 public function value(ProfilePage &$page, $field, $value, &$success)
335 {
336 $p = Platal::page();
337
338 $success = true;
339 if (!is_null($value)) {
340 $email_stripped = strtolower(trim($value));
341 if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values['email_directory'] == "new@example.org")) {
342 $p->assign('email_error', '1');
343 $p->assign('email_directory_error', $email_stripped);
344 $p->trigError('Adresse Email invalide');
345 $success = false;
346 } else {
347 $p->assign('email_error', '0');
348 }
349 }
350 return $value;
351 }
352
353 public function getText($value) {
354 return $value;
355 }
356 }
357
358 class ProfileSettingNetworking implements ProfileSetting
359 {
360 private $email;
361 private $pub;
362 private $web;
363 private $number;
364
365 public function __construct()
366 {
367 $this->email = new ProfileSettingEmail();
368 $this->pub = new ProfileSettingPub();
369 $this->web = new ProfileSettingWeb();
370 $this->number = new ProfileSettingNumber();
371 }
372
373 public function value(ProfilePage &$page, $field, $value, &$success)
374 {
375 if (is_null($value)) {
376 $value = XDB::fetchAllAssoc("SELECT n.address, n.pub, n.nwid AS type
377 FROM profile_networking AS n
378 WHERE n.pid = {?}",
379 $page->pid());
380 }
381 if (!is_array($value)) {
382 $value = array();
383 }
384 $filters = XDB::fetchAllAssoc('type', 'SELECT filter, nwid AS type, name
385 FROM profile_networking_enum;');
386 $success = true;
387 foreach($value as $i=>&$network) {
388 if (!trim($network['address'])) {
389 unset($value[$i]);
390 } else {
391 if (!isset($network['pub'])) {
392 $network['pub'] = 'private';
393 }
394 $network['error'] = false;
395 $network['pub'] = $this->pub->value($page, 'pub', $network['pub'], $s);
396 $s = true;
397 $network['name'] = $filters[$network['type']]['name'];
398 if ($filters[$network['type']]['filter'] == 'web') {
399 $network['address'] = $this->web->value($page, 'address', $network['address'], $s);
400 } elseif ($filters[$network['type']]['filter'] == 'email') {
401 $network['address'] = $this->email->value($page, 'address', $network['address'], $s);
402 } elseif ($filters[$network['type']]['filter'] == 'number') {
403 $network['address'] = $this->number->value($page, 'address', $network['address'], $s);
404 }
405 if (!$s) {
406 $success = false;
407 $network['error'] = true;
408 }
409 }
410 }
411 return $value;
412 }
413
414 public function save(ProfilePage &$page, $field, $value)
415 {
416 XDB::execute("DELETE FROM profile_networking
417 WHERE pid = {?}",
418 $page->pid());
419 if (!count($value)) {
420 return;
421 }
422 $insert = array();
423 foreach ($value as $id=>$network) {
424 XDB::execute("INSERT INTO profile_networking (pid, id, nwid, address, pub)
425 VALUES ({?}, {?}, {?}, {?}, {?})",
426 $page->pid(), $id, $network['type'], $network['address'], $network['pub']);
427 }
428 }
429
430 public function getText($value) {
431 $networkings = array();
432 foreach ($value as $network) {
433 $networkings[] = 'nom : ' . $network['name'] . ', adresse : ' . $network['address']
434 . ', affichage : ' . $network['pub'];
435 }
436 return implode(' ; ' , $networkings);
437 }
438 }
439
440 class ProfileSettingPromo implements ProfileSetting
441 {
442 public function __construct(){}
443
444 public function save(ProfilePage &$page, $field, $value)
445 {
446 $gradYearNew = $value;
447 if ($page->profile->mainEducation() == 'X') {
448 $gradYearNew += $page->profile->mainEducationDuration();
449 }
450 if (($page->profile->mainEducation() != 'X'
451 && $value == $page->profile->entry_year + $page->profile->mainEducationDuration())
452 || ($page->profile->mainEducation() == 'X' && $value == $page->profile->entry_year)) {
453 XDB::execute('UPDATE profile_display
454 SET promo = {?}
455 WHERE pid = {?}',
456 $page->profile->mainEducation() . strval($value), $page->profile->id());
457 XDB::execute('UPDATE profile_education
458 SET grad_year = {?}
459 WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)',
460 $gradYearNew, $page->profile->id());
461 Platal::page()->trigSuccess('Ton statut « orange » a été supprimé.');
462 } else {
463 $myorange = new OrangeReq(S::user(), $page->profile, $gradYearNew);
464 $myorange->submit();
465 Platal::page()->trigSuccess('Tu pourras changer l\'affichage de ta promotion dès que ta nouvelle promotion aura été validée.');
466 }
467 }
468
469 public function value(ProfilePage &$page, $field, $value, &$success)
470 {
471 $entryYear = $page->profile->entry_year;
472 $gradYear = $page->profile->grad_year;
473 $yearpromo = $page->profile->grad_year;
474 if ($page->profile->mainEducation() == 'X') {
475 $yearpromo -= $page->profile->mainEducationDuration();
476 }
477 $success = true;
478 if (is_null($value) || $value == $yearpromo) {
479 if ($gradYear != $entryYear + $page->profile->mainEducationDuration()) {
480 $promoChoice = array();
481 for ($i = $entryYear; $i <= $gradYear - $page->profile->mainEducationDuration(); ++$i) {
482 if ($page->profile->mainEducation() == 'X') {
483 $promoChoice[] = $page->profile->mainEducation() . strval($i);
484 } else {
485 $promoChoice[] = $page->profile->mainEducation() . strval($i + $page->profile->mainEducationDuration());
486 }
487 }
488 Platal::page()->assign('promo_choice', $promoChoice);
489 }
490 return $yearpromo;
491 }
492
493 // If this profile belongs to an X, $promoNew needs to be changed to
494 // the graduation year.
495 $gradYearNew = $value;
496 if ($page->profile->mainEducation() == 'X') {
497 $gradYearNew += $page->profile->mainEducationDuration();
498 }
499
500 if ($value < 1000 || $value > 9999) {
501 Platal::page()->trigError('L\'année de sortie doit être un nombre de quatre chiffres.');
502 $success = false;
503 } elseif ($gradYearNew < $entryYear + $page->profile->mainEducationDuration()) {
504 Platal::page()->trigError('Trop tôt&nbsp;!');
505 $success = false;
506 }
507 return intval($value);
508 }
509
510 public function getText($value) {
511 return $value;
512 }
513 }
514
515
516 class ProfilePageGeneral extends ProfilePage
517 {
518 protected $pg_template = 'profile/general.tpl';
519
520 public function __construct(PlWizard &$wiz)
521 {
522 parent::__construct($wiz);
523 $this->settings['search_names']
524 = new ProfileSettingSearchNames();
525 $this->settings['birthdate'] = new ProfileSettingDate();
526 $this->settings['nationality1']
527 = $this->settings['nationality2']
528 = $this->settings['nationality3']
529 = $this->settings['promo_display']
530 = null;
531 $this->settings['email_directory']
532 = new ProfileSettingEmail();
533 $this->settings['email_directory_new']
534 = new ProfileSettingEmailDirectory();
535 $this->settings['networking'] = new ProfileSettingNetworking();
536 $this->settings['tels'] = new ProfileSettingPhones();
537 $this->settings['edus'] = new ProfileSettingEdu();
538 $this->settings['promo'] = new ProfileSettingPromo();
539 $this->watched= array('tels' => true,
540 'networking' => true, 'edus' => true,
541 'nationality1' => true, 'nationality2' => true,
542 'nationality3' => true, 'search_names' => true);
543
544 /* Some fields editable under condition */
545 if (!S::user()->isMe($this->owner)) {
546 $this->settings['deathdate'] = new ProfileSettingDate(true);
547 }
548 if (S::user()->checkPerms('directory_private')
549 || S::user()->isMyProfile($this->owner)) {
550 $this->settings['yourself']
551 = $this->settings['freetext']
552 = null;
553 $this->settings['freetext_pub']
554 = $this->settings['photo_pub']
555 = new ProfileSettingPub();
556 $this->watched['freetext'] = true;
557 }
558
559 }
560
561 protected function _fetchData()
562 {
563 // Checkout all data...
564 $res = XDB::query("SELECT p.nationality1, p.nationality2, p.nationality3, p.birthdate,
565 p.email_directory as email_directory, pd.promo AS promo_display,
566 p.freetext, p.freetext_pub, p.ax_id AS matricule_ax, pd.yourself,
567 p.deathdate
568 FROM profiles AS p
569 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
570 WHERE p.pid = {?}", $this->pid());
571 $this->values = $res->fetchOneAssoc();
572
573 // Retreive photo informations
574 $res = XDB::query("SELECT pub
575 FROM profile_photos
576 WHERE pid = {?}", $this->pid());
577 $this->values['photo_pub'] = $res->fetchOneCell();
578
579 if ($this->owner) {
580 $res = XDB::query("SELECT COUNT(*)
581 FROM requests
582 WHERE type = 'photo' AND pid = {?}",
583 $this->owner->id());
584 $this->values['nouvellephoto'] = $res->fetchOneCell();
585 } else {
586 $this->values['nouvellephoto'] = 0;
587 }
588 }
589
590 protected function _saveData()
591 {
592 if ($this->changed['nationality1'] || $this->changed['nationality2'] || $this->changed['nationality3']
593 || $this->changed['birthdate'] || $this->changed['freetext'] || $this->changed['freetext_pub']
594 || $this->changed['email_directory']) {
595 if ($this->values['nationality3'] == "") {
596 $this->values['nationality3'] = NULL;
597 }
598 if ($this->values['nationality2'] == "") {
599 $this->values['nationality2'] = $this->values['nationality3'];
600 $this->values['nationality3'] = NULL;
601 }
602 if ($this->values['nationality1'] == "") {
603 $this->values['nationality1'] = $this->values['nationality2'];
604 $this->values['nationality2'] = $this->values['nationality3'];
605 $this->values['nationality3'] = NULL;
606 }
607 if ($this->values['nationality1'] == $this->values['nationality2']
608 && $this->values['nationality2'] == $this->values['nationality3']) {
609 $this->values['nationality2'] = NULL;
610 $this->values['nationality3'] = NULL;
611 } else if ($this->values['nationality1'] == $this->values['nationality2']) {
612 $this->values['nationality2'] = $this->values['nationality3'];
613 $this->values['nationality3'] = NULL;
614 } else if ($this->values['nationality2'] == $this->values['nationality3']
615 || $this->values['nationality1'] == $this->values['nationality3']) {
616 $this->values['nationality3'] = NULL;
617 }
618
619 $new_email = ($this->values['email_directory'] == "new@example.org") ?
620 $this->values['email_directory_new'] : $this->values['email_directory'];
621 if ($new_email == "") {
622 $new_email = NULL;
623 }
624
625 XDB::execute("UPDATE profiles
626 SET nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?},
627 freetext = {?}, freetext_pub = {?}, email_directory = {?}
628 WHERE pid = {?}",
629 $this->values['nationality1'], $this->values['nationality2'], $this->values['nationality3'],
630 ProfileSettingDate::toSQLDate($this->values['birthdate']),
631 $this->values['freetext'], $this->values['freetext_pub'], $new_email, $this->pid());
632 }
633 if ($this->changed['photo_pub']) {
634 XDB::execute("UPDATE profile_photos
635 SET pub = {?}
636 WHERE pid = {?}",
637 $this->values['photo_pub'], $this->pid());
638 }
639 if ($this->changed['yourself']) {
640 if ($this->owner) {
641 XDB::execute('UPDATE accounts
642 SET display_name = {?}
643 WHERE uid = {?}',
644 $this->values['yourself'], $this->owner->id());
645 }
646 XDB::execute('UPDATE profile_display
647 SET yourself = {?}
648 WHERE pid = {?}', $this->values['yourself'],
649 $this->pid());
650 }
651 if ($this->changed['promo_display']) {
652 if ($this->values['promo_display']{0} == $this->profile->mainEducation()) {
653 if (($this->profile->mainEducation() == 'X'
654 && intval(substr($this->values['promo_display'], 1, 4)) >= $this->profile->entry_year)
655 || ($this->profile->mainEducation() != 'X'
656 && intval(substr($this->values['promo_display'], 1, 4)) >= $this->profile->entry_year + $this->profile->mainEducationDuration())) {
657 XDB::execute('UPDATE profile_display
658 SET promo = {?}
659 WHERE pid = {?}',
660 $this->values['promo_display'], $this->pid());
661 }
662 }
663 }
664 if ($this->changed['deathdate']) {
665 XDB::execute('UPDATE profiles
666 SET deathdate = {?}, deathdate_rec = NOW()
667 WHERE pid = {?} AND deathdate_rec IS NULL',
668 ProfileSettingDate::toSQLDate($this->values['deathdate']), $this->pid());
669 if (XDB::affectedRows() > 0) {
670 $this->profile->clear();
671 if ($this->owner) {
672 $this->owner->clear(true);
673 }
674 } else {
675 /* deathdate_rec was not NULL, this is just an update of the death date
676 */
677 XDB::execute('UPDATE profiles
678 SET deathdate = {?}
679 WHERE pid = {?}',
680 ProfileSettingDate::toSQLDate($this->values['deathdate']), $this->pid());
681 }
682 }
683 }
684
685 public function _prepare(PlPage &$page, $id)
686 {
687 require_once "education.func.inc.php";
688
689 $res = XDB::query("SELECT id, field
690 FROM profile_education_field_enum
691 ORDER BY field");
692 $page->assign('edu_fields', $res->fetchAllAssoc());
693
694 require_once "emails.combobox.inc.php";
695 fill_email_combobox($page, $this->owner);
696
697 $res = XDB::query("SELECT nw.nwid AS type, nw.name
698 FROM profile_networking_enum AS nw
699 ORDER BY name");
700 $page->assign('network_list', $res->fetchAllAssoc());
701
702 $res = XDB::query("SELECT public_name, private_name
703 FROM profile_display
704 WHERE pid = {?}",
705 $this->pid());
706 $res = $res->fetchOneRow();
707 $page->assign('public_name', $res[0]);
708 $page->assign('private_name', $res[1]);
709 $page->assign('isFemale', $this->profile->isFemale() ? 1 : 0);
710 }
711 }
712
713 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
714 ?>