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