Keeps numbering of jobs, addresses and phones between 1 and their current total ...
[platal.git] / modules / profile / general.inc.php
CommitLineData
fd38b30e
FB
1<?php
2/***************************************************************************
9f5bd98e 3 * Copyright (C) 2003-2010 Polytechnique.org *
fd38b30e
FB
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
ac40839f
PC
22require_once 'name.func.inc.php';
23
12bcf04b 24class ProfileSettingSearchNames implements ProfileSetting
fd38b30e 25{
dced83b4
SJ
26 private $private_name_end;
27 private $search_names;
b270577e
SJ
28 private $name_types;
29
30 public function __construct() {
31 $this->name_types = DirEnum::getOptions(DirEnum::NAMES);
32 }
c4b45374 33
e5bcd851
FB
34 private function matchWord($old, $new, $newLen)
35 {
93553cea 36 return ($i = strpos($old, $new)) !== false
fd38b30e
FB
37 && ($i == 0 || $old{$i-1} == ' ')
38 && ($i + $newLen == strlen($old) || $old{$i + $newLen} == ' ');
39 }
40
41 private function prepareField($value)
42 {
ac40839f 43 return name_to_basename($value);
fd38b30e
FB
44 }
45
c4b45374 46 private function prepare(ProfilePage &$page, $field, $value, $init, &$success)
fd38b30e
FB
47 {
48 $success = true;
dced83b4
SJ
49 $ini = $this->prepareField($init);
50 $new = $this->prepareField($value);
c4b45374
SJ
51 $newLen = strlen($new);
52 $success = $this->matchWord($ini, $new, $newLen)
6cb58d39 53 || ($field == 'lastname' && $new == 'DE ' . $ini);
fd38b30e 54 if (!$success) {
c4b45374 55 $field = strtolower($field);
b270577e
SJ
56 Platal::page()->trigError("Le " . $this->name_types[$field] . " que tu as choisi (" . $value .
57 ") est trop loin de ton " . $this->name_types[$field] . " initial (" . $init . ").");
fd38b30e 58 }
c4b45374 59 return $success ? $value : $init;
fd38b30e
FB
60 }
61
b270577e
SJ
62 /* Removes duplicated entries for the fields that do not allow them. */
63 private function clean($value)
64 {
65 $single_types = XDB::fetchAllAssoc('id',
66 'SELECT id, 0
67 FROM profile_name_enum
68 WHERE NOT FIND_IN_SET(\'allow_duplicates\', flags)');
69
70 foreach ($value as $key => $item) {
71 if (isset($single_types[$item['typeid']])) {
72 if ($single_types[$item['typeid']] === true) {
73 unset($value[$key]);
74 } else {
75 $single_types[$item['typeid']] = true;
76 }
77 }
78 }
79
80 return $value;
81 }
82
c4b45374 83 public function value(ProfilePage &$page, $field, $value, &$success)
fd38b30e 84 {
dced83b4 85 $success = true;
c4b45374 86 $success_tmp = true;
09f9ebea 87
c4b45374
SJ
88 if (is_null($value)) {
89 $sn_all = XDB::iterator("SELECT CONCAT(sn.particle, sn.name) AS name,
6cb58d39 90 sn.particle, sn.typeid, e.type, e.name AS type_name,
c4b45374
SJ
91 FIND_IN_SET('has_particle', e.flags) AS has_particle,
92 FIND_IN_SET('always_displayed', e.flags) AS always_displayed,
93 FIND_IN_SET('public', e.flags) AS pub
97a98687
SJ
94 FROM profile_name AS sn
95 INNER JOIN profile_name_enum AS e ON (e.id = sn.typeid)
c4b45374
SJ
96 WHERE sn.pid = {?} AND NOT FIND_IN_SET('not_displayed', e.flags)
97 ORDER BY NOT FIND_IN_SET('always_displayed', e.flags), e.id, sn.name",
111b2736 98 $page->pid());
c4b45374 99
6cb58d39
SJ
100 $sn_types = XDB::iterator("SELECT id, type, name,
101 FIND_IN_SET('has_particle', flags) AS has_particle
97a98687 102 FROM profile_name_enum
c4b45374
SJ
103 WHERE NOT FIND_IN_SET('not_displayed', flags)
104 AND FIND_IN_SET('always_displayed', flags)
105 ORDER BY id");
106
107 $value = array();
108 $sn = $sn_all->next();
109 while ($sn_type = $sn_types->next()) {
110 if ($sn_type['id'] == $sn['typeid']) {
111 $value[] = $sn;
111b2736
FB
112 if ($sn) {
113 $sn = $sn_all->next();
114 }
c4b45374 115 } else {
09f9ebea
SJ
116 $value[] = array('name' => '',
117 'particle' => '',
118 'typeid' => $sn_type['id'],
119 'type' => $sn_type['type'],
120 'type_name' => $sn_type['name'],
c4b45374 121 'has_particle' => $sn_type['has_particle'],
09f9ebea
SJ
122 'always_displayed' => 1,
123 'pub' => 1);
c4b45374
SJ
124 }
125 }
6cb58d39
SJ
126 if ($sn) {
127 do {
128 $value[] = $sn;
129 } while ($sn = $sn_all->next());
111b2736 130 }
b270577e 131 $value = $this->clean($value);
c4b45374 132 } else {
6cb58d39
SJ
133 require_once 'name.func.inc.php';
134
b270577e 135 $value = $this->clean($value);
c4b45374 136 $res = XDB::query("SELECT s.particle, s.name
97a98687
SJ
137 FROM profile_name AS s
138 INNER JOIN profile_name_enum AS e ON (e.id = s.typeid)
2fa91df0
SJ
139 WHERE s.pid = {?} AND (e.type = 'lastname' OR e.type = 'firstname')
140 ORDER BY e.type = 'firstname'",
111b2736 141 $page->pid());
c4b45374
SJ
142 $res = $res->fetchAllAssoc();
143 $initial = array();
6cb58d39
SJ
144 $initial['lastname'] = $res[0]['particle'] . $res[0]['name'];
145 $initial['firstname'] = $res[1]['name'];
146 $sn_types = build_types();
dced83b4
SJ
147 $this->search_names = array();
148 foreach ($value as &$sn) {
c4b45374 149 $sn['name'] = trim($sn['name']);
6cb58d39 150 if ($sn['type'] == 'firstname' || $sn['type'] == 'lastname') {
c4b45374
SJ
151 $sn['name'] = $this->prepare($page, $sn['type'], $sn['name'],
152 $initial[$sn['type']], $success_tmp);
153 $success = $success && $success_tmp;
154 }
dced83b4
SJ
155 if ($sn['pub']) {
156 if (isset($sn['particle']) && ($sn['particle'] != '')) {
faf5f834 157 // particle is before first blank
dced83b4
SJ
158 list($particle, $name) = explode(' ', $sn['name'], 2);
159 $particle = trim($particle) . ' ';
160 if (!$name) {
faf5f834 161 // particle is before first quote
dced83b4
SJ
162 list($particle, $name) = explode('\'', $sn['name'], 2);
163 $particle = trim($particle);
faf5f834
PC
164 if (!$name) {
165 // actually there is no particle
166 $particle = '';
167 $name = $sn['name'];
168 }
dced83b4
SJ
169 }
170 } else {
171 $particle = '';
172 $name = $sn['name'];
173 }
174 }
c4b45374 175 if ($sn['name'] != '') {
dced83b4
SJ
176 if ($sn['pub']) {
177 $this->search_names[$sn['typeid']] = array('fullname' => $sn['name'],
178 'name' => $name,
179 'particle' => $particle,
180 'pub' => $sn['pub']);
c4b45374 181 } else {
dced83b4
SJ
182 if (isset($this->search_names[$sn['typeid']])) {
183 $this->search_names[$sn['typeid']][] = $sn['name'];
184 } else {
185 $this->search_names[$sn['typeid']] = array('fullname' => $sn['name']);
186 }
6cb58d39 187 $sn['type_name'] = $sn_types[$sn['typeid']];
c4b45374
SJ
188 }
189 }
190 }
dced83b4
SJ
191 $res = XDB::query("SELECT public_name, private_name
192 FROM profile_display
193 WHERE pid = {?}",
194 S::v('uid'));
195 list($public_name, $private_name) = $res->fetchOneRow();
196 if ($success) {
dced83b4
SJ
197 $sn_types_private = build_types('private');
198 $this->private_name_end = build_private_name($this->search_names, $sn_types_private);
199 $private_name = $public_name . $this->private_name_end;
200 }
201 Platal::page()->assign('public_name', $public_name);
202 Platal::page()->assign('private_name', $private_name);
fd38b30e 203 }
09f9ebea 204
c4b45374 205 return $value;
fd38b30e
FB
206 }
207
c4b45374 208 public function save(ProfilePage &$page, $field, $value)
fd38b30e 209 {
dced83b4 210 require_once 'name.func.inc.php';
e8a7cf31 211 $sn_old = build_sn_pub($page->pid());
c4b45374 212 XDB::execute("DELETE FROM s
97a98687
SJ
213 USING profile_name AS s
214 INNER JOIN profile_name_enum AS e ON (s.typeid = e.id)
c4b45374 215 WHERE s.pid = {?} AND NOT FIND_IN_SET('not_displayed', e.flags)",
111b2736 216 $page->pid());
e8a7cf31 217 $has_new = set_alias_names($this->search_names, $sn_old, $page->pid(), $page->owner->id());
dced83b4
SJ
218
219 // Only requires validation if modification in public names
220 if ($has_new) {
221 $new_names = new NamesReq(S::user(), $this->search_names, $this->private_name_end);
222 $new_names->submit();
b270577e
SJ
223 Platal::page()->trigWarning('La demande de modification de tes noms a bien été prise en compte.' .
224 ' Tu recevras un email dès que ces changements auront été effectués.');
dced83b4
SJ
225 } else {
226 $display_names = array();
e8a7cf31
SJ
227 build_display_names($display_names, $this->search_names,
228 $page->profile->isFemale(), $this->private_name_end);
229 set_profile_display($display_names, $page->pid());
c4b45374 230 }
fd38b30e
FB
231 }
232}
233
12bcf04b 234class ProfileSettingEdu implements ProfileSetting
576777d7 235{
e5bcd851
FB
236 public function __construct() {
237 }
043bbacf 238
5ba8842e 239 static function sortByGradYear($line1, $line2) {
22f0a0a8
SJ
240 $a = (int) $line1['grad_year'];
241 $b = (int) $line2['grad_year'];
242 if ($a == $b) {
5ba8842e
SJ
243 return 0;
244 }
22f0a0a8 245 return ($a < $b) ? -1 : 1;
5ba8842e
SJ
246 }
247
576777d7
FB
248 public function value(ProfilePage &$page, $field, $value, &$success)
249 {
250 $success = true;
043bbacf
SJ
251 if (is_null($value) || !is_array($value)) {
252 $value = array();
111b2736
FB
253 $value = XDB::fetchAllAssoc("SELECT eduid, degreeid, fieldid, grad_year, program
254 FROM profile_education
ce0b2c6f 255 WHERE pid = {?} AND !FIND_IN_SET('primary', flags)
111b2736
FB
256 ORDER BY id",
257 $page->pid());
043bbacf
SJ
258 } else {
259 $i = 0;
260 foreach ($value as $key=>&$edu) {
261 if (($edu['grad_year'] < 1921) || ($edu['grad_year'] > (date('Y') + 4))) {
262 Platal::page()->trigError('L\'année d\'obtention du diplôme est mal renseignée, elle doit être du type : 2004.');
263 $edu['error'] = true;
264 $success = false;
265 }
266 if ($key != $i) {
267 $value[$i] = $edu;
268 unset($value[$key]);
269 }
270 $i++;
271 }
12bcf04b 272 usort($value, array("ProfileSettingEdu", "sortByGradYear"));
576777d7
FB
273 }
274 return $value;
275 }
276
043bbacf 277 public function save(ProfilePage &$page, $field, $value)
576777d7 278 {
043bbacf 279 XDB::execute("DELETE FROM profile_education
ce0b2c6f 280 WHERE pid = {?} AND !FIND_IN_SET('primary', flags)",
e5bcd851 281 $page->pid());
043bbacf
SJ
282 foreach ($value as $eduid=>&$edu) {
283 if ($edu['eduid'] != '') {
284 XDB::execute("INSERT INTO profile_education
ce0b2c6f 285 SET id = {?}, pid = {?}, eduid = {?}, degreeid = {?},
1504ac45 286 fieldid = {?}, grad_year = {?}, program = {?}",
e5bcd851 287 $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'],
1504ac45 288 $edu['fieldid'], $edu['grad_year'], $edu['program']);
043bbacf 289 }
576777d7
FB
290 }
291 }
292}
293
12bcf04b 294class ProfileSettingEmailDirectory implements ProfileSetting
b715c1e1 295{
b814a8b8
SJ
296 public function __construct(){}
297 public function save(ProfilePage &$page, $field, $value){}
b715c1e1
SJ
298
299 public function value(ProfilePage &$page, $field, $value, &$success)
300 {
ad3fee9d 301 $p = Platal::page();
b715c1e1
SJ
302
303 $success = true;
304 if (!is_null($value)) {
305 $email_stripped = strtolower(trim($value));
ad3fee9d
SJ
306 if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values['email_directory'] == "new@example.org")) {
307 $p->assign('email_error', '1');
308 $p->assign('email_directory_error', $email_stripped);
309 $p->trigError('Adresse Email invalide');
b715c1e1
SJ
310 $success = false;
311 } else {
ad3fee9d 312 $p->assign('email_error', '0');
b715c1e1
SJ
313 }
314 }
315 return $value;
316 }
b715c1e1
SJ
317}
318
12bcf04b 319class ProfileSettingNetworking implements ProfileSetting
d1a2252a
GB
320{
321 private $email;
322 private $pub;
323 private $web;
92446a53 324 private $number;
d1a2252a
GB
325
326 public function __construct()
327 {
12bcf04b
RB
328 $this->email = new ProfileSettingEmail();
329 $this->pub = new ProfileSettingPub();
330 $this->web = new ProfileSettingWeb();
331 $this->number = new ProfileSettingNumber();
d1a2252a
GB
332 }
333
334 public function value(ProfilePage &$page, $field, $value, &$success)
335 {
336 if (is_null($value)) {
1f5cd004 337 $value = XDB::fetchAllAssoc("SELECT n.address, n.pub, n.nwid AS type
111b2736 338 FROM profile_networking AS n
ce0b2c6f 339 WHERE n.pid = {?}",
111b2736 340 $page->pid());
d1a2252a
GB
341 }
342 if (!is_array($value)) {
343 $value = array();
344 }
1f5cd004 345 $filters = XDB::fetchAllAssoc('type', 'SELECT filter, nwid AS type, name
111b2736 346 FROM profile_networking_enum;');
d1a2252a
GB
347 $success = true;
348 foreach($value as $i=>&$network) {
92c3f9e5
GB
349 if (!trim($network['address'])) {
350 unset($value[$i]);
351 } else {
352 if (!isset($network['pub'])) {
353 $network['pub'] = 'private';
354 }
355 $network['error'] = false;
356 $network['pub'] = $this->pub->value($page, 'pub', $network['pub'], $s);
357 $s = true;
1f5cd004
PC
358 $network['name'] = $filters[$network['type']]['name'];
359 if ($filters[$network['type']]['filter'] == 'web') {
92c3f9e5 360 $network['address'] = $this->web->value($page, 'address', $network['address'], $s);
1f5cd004 361 } elseif ($filters[$network['type']]['filter'] == 'email') {
92c3f9e5 362 $network['address'] = $this->email->value($page, 'address', $network['address'], $s);
1f5cd004 363 } elseif ($filters[$network['type']]['filter'] == 'number') {
92c3f9e5
GB
364 $network['address'] = $this->number->value($page, 'address', $network['address'], $s);
365 }
366 if (!$s) {
367 $success = false;
368 $network['error'] = true;
369 }
d1a2252a
GB
370 }
371 }
372 return $value;
373 }
374
375 public function save(ProfilePage &$page, $field, $value)
376 {
377 XDB::execute("DELETE FROM profile_networking
ce0b2c6f 378 WHERE pid = {?}",
e5bcd851 379 $page->pid());
d1a2252a
GB
380 if (!count($value)) {
381 return;
382 }
383 $insert = array();
384 foreach ($value as $id=>$network) {
1f5cd004 385 XDB::execute("INSERT INTO profile_networking (pid, id, nwid, address, pub)
d1a2252a 386 VALUES ({?}, {?}, {?}, {?}, {?})",
e5bcd851 387 $page->pid(), $id, $network['type'], $network['address'], $network['pub']);
d1a2252a
GB
388 }
389 }
390}
391
7e233317
SJ
392class ProfileSettingPromo implements ProfileSetting
393{
394 public function __construct(){}
395
396 public function save(ProfilePage &$page, $field, $value)
397 {
398 $gradYearNew = $value;
399 if ($page->profile->mainEducation() == 'X') {
400 $gradYearNew += $page->profile->mainEducationDuration();
401 }
86ced4d4
SJ
402 if (($page->profile->mainEducation() != 'X'
403 && $value == $page->profile->entry_year + $page->profile->mainEducationDuration())
404 || ($page->profile->mainEducation() == 'X' && $value == $page->profile->entry_year)) {
7e233317
SJ
405 XDB::execute('UPDATE profile_display
406 SET promo = {?}
407 WHERE pid = {?}',
408 $page->profile->mainEducation() . strval($value), $page->profile->id());
409 XDB::execute('UPDATE profile_education
410 SET grad_year = {?}
411 WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)',
412 $gradYearNew, $page->profile->id());
86ced4d4 413 Platal::page()->trigSuccess('Ton statut « orange » a été supprimé.');
7e233317
SJ
414 } else {
415 require_once 'validations.inc.php';
416
417 $myorange = new OrangeReq(S::user(), $gradYearNew);
418 $myorange->submit();
419 Platal::page()->trigSuccess('Tu pourras changer l\'affichage de ta promotion dès que ta nouvelle promotion aura été validée.');
420 }
421 }
422
423 public function value(ProfilePage &$page, $field, $value, &$success)
424 {
425 $entryYear = $page->profile->entry_year;
426 $gradYear = $page->profile->grad_year;
86ced4d4
SJ
427 $yearpromo = $page->profile->grad_year;
428 if ($page->profile->mainEducation() == 'X') {
429 $yearpromo -= $page->profile->mainEducationDuration();
430 }
7e233317 431 $success = true;
86ced4d4 432 if (is_null($value) || $value == $yearpromo) {
7e233317
SJ
433 if ($gradYear != $entryYear + $page->profile->mainEducationDuration()) {
434 $promoChoice = array();
86ced4d4
SJ
435 for ($i = $entryYear; $i <= $gradYear - $page->profile->mainEducationDuration(); ++$i) {
436 if ($page->profile->mainEducation() == 'X') {
437 $promoChoice[] = $page->profile->mainEducation() . strval($i);
438 } else {
439 $promoChoice[] = $page->profile->mainEducation() . strval($i + $page->profile->mainEducationDuration());
440 }
7e233317
SJ
441 }
442 Platal::page()->assign('promo_choice', $promoChoice);
443 }
86ced4d4 444 return $yearpromo;
7e233317
SJ
445 }
446
447 // If this profile belongs to an X, $promoNew needs to be changed to
448 // the graduation year.
449 $gradYearNew = $value;
450 if ($page->profile->mainEducation() == 'X') {
451 $gradYearNew += $page->profile->mainEducationDuration();
452 }
453
454 if ($value < 1000 || $value > 9999) {
455 Platal::page()->trigError('L\'année de sortie doit être un nombre de quatre chiffres.');
456 $success = false;
457 } elseif ($gradYearNew < $entryYear + $page->profile->mainEducationDuration()) {
458 Platal::page()->trigError('Trop tôt&nbsp;!');
459 $success = false;
460 }
461 return intval($value);
462 }
463}
464
465
12bcf04b 466class ProfileSettingGeneral extends ProfilePage
fd38b30e
FB
467{
468 protected $pg_template = 'profile/general.tpl';
469
470 public function __construct(PlWizard &$wiz)
471 {
472 parent::__construct($wiz);
c4b45374 473 $this->settings['search_names']
12bcf04b
RB
474 = new ProfileSettingSearchNames();
475 $this->settings['birthdate'] = new ProfileSettingDate();
bde2be3b 476 $this->settings['freetext_pub']
576777d7 477 = $this->settings['photo_pub']
12bcf04b 478 = new ProfileSettingPub();
93553cea 479 $this->settings['freetext']
e5bcd851
FB
480 = $this->settings['nationality1']
481 = $this->settings['nationality2']
482 = $this->settings['nationality3']
b04882ff 483 = $this->settings['yourself']
7e233317 484 = $this->settings['promo_display']
93553cea 485 = null;
b715c1e1 486 $this->settings['email_directory']
12bcf04b 487 = new ProfileSettingEmail();
b715c1e1 488 $this->settings['email_directory_new']
12bcf04b
RB
489 = new ProfileSettingEmailDirectory();
490 $this->settings['networking'] = new ProfileSettingNetworking();
491 $this->settings['tels'] = new ProfileSettingPhones('user', 0);
492 $this->settings['edus'] = new ProfileSettingEdu();
7e233317 493 $this->settings['promo'] = new ProfileSettingPromo();
6e32823c 494 $this->watched= array('freetext' => true, 'tels' => true,
043bbacf 495 'networking' => true, 'edus' => true,
e5bcd851 496 'nationality1' => true, 'nationality2' => true,
4ca15c31 497 'nationality3' => true, 'search_names' => true);
93553cea
FB
498 }
499
7c2e0f0d 500 protected function _fetchData()
93553cea 501 {
576777d7 502 // Checkout all data...
7e233317
SJ
503 $res = XDB::query("SELECT p.nationality1, p.nationality2, p.nationality3, p.birthdate,
504 pp.display_tel as mobile, pp.pub as mobile_pub,
505 p.email_directory as email_directory, pd.promo AS promo_display,
506 p.freetext, p.freetext_pub, p.ax_id AS matricule_ax, pd.yourself
507 FROM profiles AS p
508 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
509 LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND link_type = 'user')
510 WHERE p.pid = {?}", $this->pid());
93553cea 511 $this->values = $res->fetchOneAssoc();
4ca15c31
FB
512 if ($this->owner) {
513 $this->values['yourself'] = $this->owner->displayName();
514 }
576777d7 515
576777d7
FB
516 // Retreive photo informations
517 $res = XDB::query("SELECT pub
5c4ea53f
FB
518 FROM profile_photos
519 WHERE pid = {?}", $this->pid());
576777d7
FB
520 $this->values['photo_pub'] = $res->fetchOneCell();
521
e5bcd851
FB
522 if ($this->owner) {
523 $res = XDB::query("SELECT COUNT(*)
524 FROM requests
257ae408 525 WHERE type = 'photo' AND uid = {?}",
e5bcd851
FB
526 $this->owner->id());
527 $this->values['nouvellephoto'] = $res->fetchOneCell();
528 } else {
529 $this->values['nouvellephoto'] = 0;
530 }
93553cea
FB
531 }
532
7c2e0f0d 533 protected function _saveData()
93553cea 534 {
e5bcd851 535 if ($this->changed['nationality1'] || $this->changed['nationality2'] || $this->changed['nationality3']
ce0b2c6f
FB
536 || $this->changed['birthdate'] || $this->changed['freetext'] || $this->changed['freetext_pub']
537 || $this->changed['email_directory']) {
e5bcd851
FB
538 if ($this->values['nationality3'] == "") {
539 $this->values['nationality3'] = NULL;
8450c2aa 540 }
e5bcd851
FB
541 if ($this->values['nationality2'] == "") {
542 $this->values['nationality2'] = $this->values['nationality3'];
543 $this->values['nationality3'] = NULL;
8450c2aa 544 }
e5bcd851
FB
545 if ($this->values['nationality1'] == "") {
546 $this->values['nationality1'] = $this->values['nationality2'];
547 $this->values['nationality2'] = $this->values['nationality3'];
548 $this->values['nationality3'] = NULL;
8450c2aa 549 }
ce0b2c6f
FB
550 $new_email = ($this->values['email_directory'] == "new@example.org") ?
551 $this->values['email_directory_new'] : $this->values['email_directory'];
552 if ($new_email == "") {
553 $new_email = NULL;
554 }
8450c2aa 555
e5bcd851
FB
556 XDB::execute("UPDATE profiles
557 SET nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?},
ce0b2c6f 558 freetext = {?}, freetext_pub = {?}, email_directory = {?}
d1e61677 559 WHERE pid = {?}",
e5bcd851
FB
560 $this->values['nationality1'], $this->values['nationality2'], $this->values['nationality3'],
561 preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values['birthdate']),
ce0b2c6f 562 $this->values['freetext'], $this->values['freetext_pub'], $new_email, $this->pid());
b715c1e1 563 }
a7c28fff 564 if ($this->changed['photo_pub']) {
5c4ea53f 565 XDB::execute("UPDATE profile_photos
a7c28fff 566 SET pub = {?}
5c4ea53f 567 WHERE pid = {?}",
e5bcd851 568 $this->values['photo_pub'], $this->pid());
a7c28fff 569 }
c4b45374 570 if ($this->changed['yourself']) {
cb0af6e5
FB
571 if ($this->owner) {
572 XDB::execute('UPDATE accounts
573 SET display_name = {?}
574 WHERE uid = {?}',
575 $this->values['yourself'], $this->owner->id());
576 }
577 XDB::execute('UPDATE profile_display
578 SET yourself = {?}
579 WHERE pid = {?}', $this->values['yourself'],
580 $this->pid());
fb2c09c9 581 }
7e233317 582 if ($this->changed['promo_display']) {
86ced4d4
SJ
583 if ($this->values['promo_display']{0} == $this->profile->mainEducation()) {
584 if (($this->profile->mainEducation() == 'X'
585 && intval(substr($this->values['promo_display'], 1, 4)) >= $this->profile->entry_year)
586 || ($this->profile->mainEducation() != 'X'
587 && intval(substr($this->values['promo_display'], 1, 4)) >= $this->profile->entry_year + $this->profile->mainEducationDuration())) {
588 XDB::execute('UPDATE profile_display
589 SET promo = {?}
590 WHERE pid = {?}',
591 $this->values['promo_display'], $this->pid());
592 }
7e233317 593 }
b04882ff 594 }
fd38b30e
FB
595 }
596
04334c61 597 public function _prepare(PlPage &$page, $id)
fd38b30e 598 {
f711b03f 599 require_once "education.func.inc.php";
d1a2252a 600
111b2736
FB
601 $res = XDB::query("SELECT id, field
602 FROM profile_education_field_enum
603 ORDER BY field");
043bbacf
SJ
604 $page->assign('edu_fields', $res->fetchAllAssoc());
605
b715c1e1 606 require_once "emails.combobox.inc.php";
e5bcd851 607 fill_email_combobox($page, $this->owner, $this->profile);
b715c1e1 608
1f5cd004 609 $res = XDB::query("SELECT nw.nwid AS type, nw.name
111b2736
FB
610 FROM profile_networking_enum AS nw
611 ORDER BY name");
d1a2252a 612 $page->assign('network_list', $res->fetchAllAssoc());
c4b45374
SJ
613
614 $res = XDB::query("SELECT public_name, private_name
615 FROM profile_display
616 WHERE pid = {?}",
111b2736 617 $this->pid());
c4b45374
SJ
618 $res = $res->fetchOneRow();
619 $page->assign('public_name', $res[0]);
620 $page->assign('private_name', $res[1]);
e8a7cf31 621 $page->assign('isFemale', $this->profile->isFemale() ? 1 : 0);
fd38b30e
FB
622 }
623}
624
625// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
626?>