Commit | Line | Data |
---|---|---|
fd38b30e FB |
1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 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 | ||
12bcf04b | 22 | class ProfileSettingSearchNames implements ProfileSetting |
fd38b30e | 23 | { |
0e1dfbad SJ |
24 | private function diff($pid, array $old, array $new) |
25 | { | |
26 | $diff = false; | |
27 | foreach ($old as $field => $name) { | |
28 | $diff = $diff || ($name != $new[$field]); | |
29 | } | |
b270577e | 30 | |
0e1dfbad | 31 | return $diff; |
b270577e | 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 | ||
0e1dfbad | 41 | private function prepare(ProfilePage $page, array &$new_value) |
fd38b30e | 42 | { |
0e1dfbad SJ |
43 | $initial_value = XDB::fetchOneAssoc('SELECT lastname_main, firstname_main |
44 | FROM profile_public_names | |
45 | WHERE pid = {?}', | |
46 | $page->pid()); | |
fd38b30e | 47 | |
fd38b30e | 48 | $success = true; |
0e1dfbad SJ |
49 | foreach ($initial_value as $field => $name) { |
50 | $initial = name_to_basename($name); | |
51 | $new = name_to_basename($new_value[$field]); | |
fd38b30e | 52 | |
0e1dfbad SJ |
53 | if (!($this->matchWord($initial, $new, strlen($new)) |
54 | || ($field == 'lastname_main' && $new == 'DE ' . $initial))) { | |
55 | $new_value[$field . '_error'] = true; | |
56 | $success = false; | |
57 | Platal::page()->trigError('Le nom choisi (' . $new . ') est trop loin de sa valeur initiale (' . $initial . ').'); | |
b270577e SJ |
58 | } |
59 | } | |
60 | ||
0e1dfbad | 61 | return $success; |
b270577e SJ |
62 | } |
63 | ||
26ba053e | 64 | public function value(ProfilePage $page, $field, $value, &$success) |
fd38b30e | 65 | { |
0e1dfbad | 66 | $success = true; |
09f9ebea | 67 | |
c4b45374 | 68 | if (is_null($value)) { |
0e1dfbad | 69 | $request = NamesReq::getPublicNames($page->pid()); |
c4b45374 | 70 | |
0e1dfbad SJ |
71 | if (!$request) { |
72 | $value['public_names'] = XDB::fetchOneAssoc('SELECT particles, lastname_main, lastname_marital, lastname_ordinary, | |
73 | firstname_main, firstname_ordinary, pseudonym | |
74 | FROM profile_public_names | |
75 | WHERE pid = {?}', | |
76 | $page->pid()); | |
77 | ||
78 | $flags = new PlFlagSet($value['public_names']['particles']); | |
79 | unset($value['public_names']['particles']); | |
80 | static $suffixes = array('main', 'marital', 'ordinary'); | |
81 | ||
82 | foreach ($suffixes as $suffix) { | |
83 | $value['public_names']['particle_' . $suffix] = $flags->hasFlag($suffix); | |
c4b45374 | 84 | } |
0e1dfbad SJ |
85 | } else { |
86 | $value['public_names'] = $request; | |
bd3e755e SJ |
87 | Platal::page()->assign('validation', true); |
88 | } | |
0e1dfbad SJ |
89 | |
90 | $value['private_names'] = XDB::fetchAllAssoc('SELECT type, name | |
91 | FROM profile_private_names | |
92 | WHERE pid = {?} | |
93 | ORDER BY type, id', | |
94 | $page->pid()); | |
c4b45374 | 95 | } else { |
0e1dfbad SJ |
96 | foreach ($value['public_names'] as $key => $name) { |
97 | $value['public_names'][$key] = trim($name); | |
98 | } | |
99 | foreach ($value['private_names'] as $key => $name) { | |
100 | $value['private_names'][$key]['name'] = trim($name['name']); | |
101 | if ($value['private_names'][$key]['name'] == '') { | |
102 | unset($value['private_names'][$key]); | |
c4b45374 SJ |
103 | } |
104 | } | |
0e1dfbad SJ |
105 | |
106 | if (S::user()->isMe($page->owner)) { | |
107 | $success = $this->prepare($page, $value['public_names']); | |
dced83b4 | 108 | } |
fd38b30e | 109 | } |
09f9ebea | 110 | |
0e1dfbad SJ |
111 | require_once 'name.func.inc.php'; |
112 | $public_name = build_first_name($value['public_names']) . ' ' . build_full_last_name($value['public_names'], $page->profile->isFemale()); | |
113 | $private_name_end = build_private_name($value['private_names']); | |
114 | $private_name = $public_name . $private_name_end; | |
115 | ||
116 | Platal::page()->assign('public_name', $public_name); | |
117 | Platal::page()->assign('private_name', $private_name); | |
118 | ||
c4b45374 | 119 | return $value; |
fd38b30e FB |
120 | } |
121 | ||
26ba053e | 122 | public function save(ProfilePage $page, $field, $value) |
fd38b30e | 123 | { |
dced83b4 | 124 | require_once 'name.func.inc.php'; |
024ec1e5 | 125 | |
0e1dfbad SJ |
126 | $old = XDB::fetchOneAssoc('SELECT lastname_main, lastname_marital, lastname_ordinary, |
127 | firstname_main, firstname_ordinary, pseudonym | |
128 | FROM profile_public_names | |
129 | WHERE pid = {?}', | |
130 | $page->pid()); | |
dced83b4 | 131 | |
0e1dfbad SJ |
132 | if ($has_diff = $this->diff($page->pid(), $old, $value['public_names'])) { |
133 | $new_names = new NamesReq(S::user(), $page->profile, $value['public_names'], $old); | |
dced83b4 | 134 | $new_names->submit(); |
0e1dfbad SJ |
135 | Platal::page()->assign('validation', true); |
136 | Platal::page()->trigWarning('La demande de modification des noms a bien été prise en compte.' . | |
137 | ' Un email sera envoyé dès que ces changements auront été effectués.'); | |
138 | } | |
139 | ||
140 | XDB::execute('DELETE FROM profile_private_names | |
141 | WHERE pid = {?}', | |
142 | $page->pid()); | |
143 | $values = array(); | |
144 | $nickname = $lastname = $firstname = 0; | |
145 | foreach ($value['private_names'] as $name) { | |
146 | $values[] = XDB::format('({?}, {?}, {?}, {?})', $page->pid(), $name['type'], $$name['type']++, $name['name']); | |
147 | } | |
148 | if (count($values)) { | |
149 | XDB::rawExecute('INSERT INTO profile_private_names (pid, type, id, name) | |
150 | VALUES ' . implode(',', $values)); | |
151 | } | |
152 | ||
153 | if ($has_diff) { | |
154 | update_display_names($page->profile, $old, $value['private_names']); | |
dced83b4 | 155 | } else { |
0e1dfbad | 156 | update_display_names($page->profile, $value['public_names'], $value['private_names']); |
c4b45374 | 157 | } |
fd38b30e | 158 | } |
a0fce0c6 SJ |
159 | |
160 | public function getText($value) { | |
0e1dfbad SJ |
161 | $public_names = array(); |
162 | foreach ($value['public_names'] as $name) { | |
163 | if ($name != '') { | |
164 | $public_names[] = $name; | |
a0fce0c6 SJ |
165 | } |
166 | } | |
0e1dfbad SJ |
167 | |
168 | if (count($value['private_names'])) { | |
169 | $private_names = array(); | |
170 | foreach ($value['private_names'] as $name) { | |
171 | $private_names[] = $name['name']; | |
172 | } | |
173 | return 'noms publics : ' . implode(', ' , $public_names) . ', noms privés : ' . implode(', ' , $private_names);; | |
174 | } | |
175 | ||
176 | return 'noms publics : ' . implode(', ' , $public_names); | |
a0fce0c6 | 177 | } |
fd38b30e FB |
178 | } |
179 | ||
12bcf04b | 180 | class ProfileSettingEdu implements ProfileSetting |
576777d7 | 181 | { |
e5bcd851 FB |
182 | public function __construct() { |
183 | } | |
043bbacf | 184 | |
5ba8842e | 185 | static function sortByGradYear($line1, $line2) { |
be6806fa SJ |
186 | $a = (isset($line1['grad_year'])) ? (int) $line1['grad_year'] : 0; |
187 | $b = (isset($line2['grad_year'])) ? (int) $line2['grad_year'] : 0; | |
22f0a0a8 | 188 | if ($a == $b) { |
5ba8842e SJ |
189 | return 0; |
190 | } | |
22f0a0a8 | 191 | return ($a < $b) ? -1 : 1; |
5ba8842e SJ |
192 | } |
193 | ||
26ba053e | 194 | public function value(ProfilePage $page, $field, $value, &$success) |
576777d7 FB |
195 | { |
196 | $success = true; | |
885fa398 | 197 | if (is_null($value)) { |
043bbacf | 198 | $value = array(); |
111b2736 FB |
199 | $value = XDB::fetchAllAssoc("SELECT eduid, degreeid, fieldid, grad_year, program |
200 | FROM profile_education | |
fb052bde | 201 | WHERE pid = {?} AND !(FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags)) |
111b2736 FB |
202 | ORDER BY id", |
203 | $page->pid()); | |
885fa398 SJ |
204 | } else if (!is_array($value)) { |
205 | $value = null; | |
043bbacf SJ |
206 | } else { |
207 | $i = 0; | |
208 | foreach ($value as $key=>&$edu) { | |
3ede4850 SJ |
209 | if ($edu['eduid'] < 1 || !isset($edu['degreeid']) || $edu['degreeid'] < 1) { |
210 | Platal::page()->trigError('L\'université ou le diplôme d\'une formation manque.'); | |
211 | $success = false; | |
212 | } | |
043bbacf | 213 | if (($edu['grad_year'] < 1921) || ($edu['grad_year'] > (date('Y') + 4))) { |
be6806fa | 214 | Platal::page()->trigWarning('L\'année d\'obtention du diplôme est mal ou non renseignée, elle doit être du type : 2004.'); |
83065276 | 215 | $edu['grad_year'] = null; |
be6806fa | 216 | $edu['warning'] = true; |
043bbacf SJ |
217 | } |
218 | if ($key != $i) { | |
219 | $value[$i] = $edu; | |
220 | unset($value[$key]); | |
221 | } | |
222 | $i++; | |
223 | } | |
12bcf04b | 224 | usort($value, array("ProfileSettingEdu", "sortByGradYear")); |
576777d7 FB |
225 | } |
226 | return $value; | |
227 | } | |
228 | ||
26ba053e | 229 | public function save(ProfilePage $page, $field, $value) |
576777d7 | 230 | { |
043bbacf | 231 | XDB::execute("DELETE FROM profile_education |
fb052bde | 232 | WHERE pid = {?} AND !(FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags))", |
e5bcd851 | 233 | $page->pid()); |
fb052bde | 234 | $schoolsList = DirEnum::getOptions(DirEnum::EDUSCHOOLS); |
043bbacf | 235 | foreach ($value as $eduid=>&$edu) { |
fb052bde | 236 | if ($edu['eduid'] != '' && $schoolsList[$edu['eduid']] != Profile::EDU_X) { |
8768e5af | 237 | $fieldId = ($edu['fieldid'] == 0) ? null : $edu['fieldid']; |
043bbacf | 238 | XDB::execute("INSERT INTO profile_education |
ce0b2c6f | 239 | SET id = {?}, pid = {?}, eduid = {?}, degreeid = {?}, |
1504ac45 | 240 | fieldid = {?}, grad_year = {?}, program = {?}", |
e5bcd851 | 241 | $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'], |
8768e5af | 242 | $fieldId, $edu['grad_year'], $edu['program']); |
043bbacf | 243 | } |
576777d7 FB |
244 | } |
245 | } | |
a0fce0c6 SJ |
246 | |
247 | public function getText($value) { | |
248 | $schoolsList = DirEnum::getOptions(DirEnum::EDUSCHOOLS); | |
249 | $degreesList = DirEnum::getOptions(DirEnum::EDUDEGREES); | |
250 | $fieldsList = DirEnum::getOptions(DirEnum::EDUFIELDS); | |
251 | $educations = array(); | |
14aba233 SJ |
252 | foreach ($value as $id => $education) { |
253 | // XXX: the following condition should be removed once there are no more incomplete educations. | |
254 | if (is_null($education['eduid']) || is_null($education['degreeid'])) { | |
255 | if (is_null($education['eduid']) && is_null($education['degreeid'])) { | |
256 | $educations[$id] = 'formation manquante'; | |
257 | } else { | |
258 | $educations[$id] = (is_null($education['eduid']) ? 'université manquante' : $schoolsList[$education['eduid']]) . ', ' | |
259 | . (is_null($education['degreeid']) ? 'diplôme manquant' : $degreesList[$education['degreeid']]); | |
260 | } | |
261 | } else { | |
262 | $educations[$id] = $schoolsList[$education['eduid']] . ', ' . $degreesList[$education['degreeid']]; | |
263 | } | |
264 | ||
265 | $details = array(); | |
266 | if ($education['grad_year']) { | |
267 | $details[] = $education['grad_year']; | |
268 | } | |
269 | if ($education['program']) { | |
270 | $details[] = '« ' . $education['program'] . ' »'; | |
271 | } | |
272 | if ($education['fieldid']) { | |
273 | $details[] = $fieldsList[$education['fieldid']]; | |
274 | } | |
275 | if (count($details)) { | |
276 | $educations[$id] .= ' (' . implode(', ', $details) . ')'; | |
277 | } | |
a0fce0c6 SJ |
278 | } |
279 | return implode(', ', $educations); | |
280 | } | |
576777d7 FB |
281 | } |
282 | ||
d7de04af SJ |
283 | class ProfileSettingMainEdu implements ProfileSetting |
284 | { | |
285 | private $cycles; | |
286 | ||
287 | public function __construct() | |
288 | { | |
289 | $eduDegrees = DirEnum::getOptions(DirEnum::EDUDEGREES); | |
290 | $eduDegrees = array_flip($eduDegrees); | |
291 | $this->cycles = array( | |
292 | $eduDegrees[Profile::DEGREE_X] => 'Cycle polytechnicien', | |
293 | $eduDegrees[Profile::DEGREE_M] => 'Cycle master', | |
294 | $eduDegrees[Profile::DEGREE_D] => 'Cycle doctoral' | |
295 | ); | |
296 | } | |
297 | ||
298 | public function value(ProfilePage $page, $field, $value, &$success) | |
299 | { | |
300 | $success = true; | |
301 | if (is_null($value)) { | |
302 | $value = array(); | |
303 | $value = XDB::fetchAllAssoc("SELECT degreeid, fieldid, promo_year, program | |
304 | FROM profile_education | |
fb052bde SJ |
305 | WHERE pid = {?} AND (FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags)) |
306 | ORDER BY NOT FIND_IN_SET('primary', flags), degreeid", | |
d7de04af SJ |
307 | $page->pid()); |
308 | ||
309 | foreach ($value as &$item) { | |
310 | $item['cycle'] = $this->cycles[$item['degreeid']]; | |
311 | } | |
312 | } elseif (!is_array($value)) { | |
313 | $value = array(); | |
314 | } else { | |
315 | foreach ($value as $key => $item) { | |
316 | if (!isset($item['degreeid'])) { | |
317 | unset($value[$key]); | |
318 | } | |
319 | } | |
320 | } | |
321 | ||
322 | return $value; | |
323 | } | |
324 | ||
325 | public function save(ProfilePage $page, $field, $value) | |
326 | { | |
327 | foreach ($value as $item) { | |
328 | $fieldId = ($item['fieldid'] == 0) ? null : $item['fieldid']; | |
329 | XDB::execute("UPDATE profile_education | |
330 | SET fieldid = {?}, program = {?} | |
fb052bde | 331 | WHERE pid = {?} AND (FIND_IN_SET('primary', flags) OR FIND_IN_SET('secondary', flags)) AND degreeid = {?}", |
d7de04af SJ |
332 | $fieldId, $item['program'], $page->pid(), $item['degreeid']); |
333 | } | |
334 | } | |
335 | ||
336 | public function getText($value) { | |
337 | $fieldsList = DirEnum::getOptions(DirEnum::EDUFIELDS); | |
338 | $educations = array(); | |
339 | foreach ($value as $item) { | |
340 | $details = array($this->cycles[$item['degreeid']]); | |
341 | if ($education['program']) { | |
342 | $details[] = '« ' . $education['program'] . ' »'; | |
343 | } | |
344 | if ($education['fieldid']) { | |
345 | $details[] = $fieldsList[$education['fieldid']]; | |
346 | } | |
347 | } | |
348 | return implode(', ', $educations); | |
349 | } | |
350 | } | |
351 | ||
12bcf04b | 352 | class ProfileSettingEmailDirectory implements ProfileSetting |
b715c1e1 | 353 | { |
b814a8b8 | 354 | public function __construct(){} |
26ba053e | 355 | public function save(ProfilePage $page, $field, $value){} |
b715c1e1 | 356 | |
26ba053e | 357 | public function value(ProfilePage $page, $field, $value, &$success) |
b715c1e1 | 358 | { |
ad3fee9d | 359 | $p = Platal::page(); |
b715c1e1 SJ |
360 | |
361 | $success = true; | |
362 | if (!is_null($value)) { | |
363 | $email_stripped = strtolower(trim($value)); | |
ad3fee9d SJ |
364 | if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values['email_directory'] == "new@example.org")) { |
365 | $p->assign('email_error', '1'); | |
366 | $p->assign('email_directory_error', $email_stripped); | |
367 | $p->trigError('Adresse Email invalide'); | |
b715c1e1 SJ |
368 | $success = false; |
369 | } else { | |
ad3fee9d | 370 | $p->assign('email_error', '0'); |
b715c1e1 SJ |
371 | } |
372 | } | |
373 | return $value; | |
374 | } | |
a0fce0c6 SJ |
375 | |
376 | public function getText($value) { | |
377 | return $value; | |
378 | } | |
b715c1e1 SJ |
379 | } |
380 | ||
12bcf04b | 381 | class ProfileSettingNetworking implements ProfileSetting |
d1a2252a GB |
382 | { |
383 | private $email; | |
384 | private $pub; | |
385 | private $web; | |
92446a53 | 386 | private $number; |
d1a2252a GB |
387 | |
388 | public function __construct() | |
389 | { | |
12bcf04b RB |
390 | $this->email = new ProfileSettingEmail(); |
391 | $this->pub = new ProfileSettingPub(); | |
392 | $this->web = new ProfileSettingWeb(); | |
393 | $this->number = new ProfileSettingNumber(); | |
d1a2252a GB |
394 | } |
395 | ||
26ba053e | 396 | public function value(ProfilePage $page, $field, $value, &$success) |
d1a2252a GB |
397 | { |
398 | if (is_null($value)) { | |
1f5cd004 | 399 | $value = XDB::fetchAllAssoc("SELECT n.address, n.pub, n.nwid AS type |
111b2736 | 400 | FROM profile_networking AS n |
ce0b2c6f | 401 | WHERE n.pid = {?}", |
111b2736 | 402 | $page->pid()); |
d1a2252a GB |
403 | } |
404 | if (!is_array($value)) { | |
405 | $value = array(); | |
406 | } | |
1f5cd004 | 407 | $filters = XDB::fetchAllAssoc('type', 'SELECT filter, nwid AS type, name |
111b2736 | 408 | FROM profile_networking_enum;'); |
d1a2252a GB |
409 | $success = true; |
410 | foreach($value as $i=>&$network) { | |
92c3f9e5 GB |
411 | if (!trim($network['address'])) { |
412 | unset($value[$i]); | |
413 | } else { | |
414 | if (!isset($network['pub'])) { | |
415 | $network['pub'] = 'private'; | |
416 | } | |
417 | $network['error'] = false; | |
418 | $network['pub'] = $this->pub->value($page, 'pub', $network['pub'], $s); | |
419 | $s = true; | |
1f5cd004 PC |
420 | $network['name'] = $filters[$network['type']]['name']; |
421 | if ($filters[$network['type']]['filter'] == 'web') { | |
92c3f9e5 | 422 | $network['address'] = $this->web->value($page, 'address', $network['address'], $s); |
1f5cd004 | 423 | } elseif ($filters[$network['type']]['filter'] == 'email') { |
92c3f9e5 | 424 | $network['address'] = $this->email->value($page, 'address', $network['address'], $s); |
1f5cd004 | 425 | } elseif ($filters[$network['type']]['filter'] == 'number') { |
92c3f9e5 GB |
426 | $network['address'] = $this->number->value($page, 'address', $network['address'], $s); |
427 | } | |
428 | if (!$s) { | |
429 | $success = false; | |
430 | $network['error'] = true; | |
431 | } | |
d1a2252a GB |
432 | } |
433 | } | |
434 | return $value; | |
435 | } | |
436 | ||
26ba053e | 437 | public function save(ProfilePage $page, $field, $value) |
d1a2252a GB |
438 | { |
439 | XDB::execute("DELETE FROM profile_networking | |
ce0b2c6f | 440 | WHERE pid = {?}", |
e5bcd851 | 441 | $page->pid()); |
d1a2252a GB |
442 | if (!count($value)) { |
443 | return; | |
444 | } | |
445 | $insert = array(); | |
446 | foreach ($value as $id=>$network) { | |
1f5cd004 | 447 | XDB::execute("INSERT INTO profile_networking (pid, id, nwid, address, pub) |
d1a2252a | 448 | VALUES ({?}, {?}, {?}, {?}, {?})", |
e5bcd851 | 449 | $page->pid(), $id, $network['type'], $network['address'], $network['pub']); |
d1a2252a GB |
450 | } |
451 | } | |
a0fce0c6 SJ |
452 | |
453 | public function getText($value) { | |
14aba233 | 454 | static $pubs = array('public' => 'publique', 'ax' => 'annuaire AX', 'private' => 'privé'); |
a0fce0c6 SJ |
455 | $networkings = array(); |
456 | foreach ($value as $network) { | |
14aba233 | 457 | $networkings[] = $network['name'] . ' : ' . $network['address'] . ' (affichage ' . $pubs[$network['pub']] . ')'; |
a0fce0c6 | 458 | } |
14aba233 | 459 | return implode(', ' , $networkings); |
a0fce0c6 | 460 | } |
d1a2252a GB |
461 | } |
462 | ||
7e233317 SJ |
463 | class ProfileSettingPromo implements ProfileSetting |
464 | { | |
465 | public function __construct(){} | |
466 | ||
26ba053e | 467 | public function save(ProfilePage $page, $field, $value) |
7e233317 SJ |
468 | { |
469 | $gradYearNew = $value; | |
470 | if ($page->profile->mainEducation() == 'X') { | |
471 | $gradYearNew += $page->profile->mainEducationDuration(); | |
472 | } | |
86ced4d4 SJ |
473 | if (($page->profile->mainEducation() != 'X' |
474 | && $value == $page->profile->entry_year + $page->profile->mainEducationDuration()) | |
475 | || ($page->profile->mainEducation() == 'X' && $value == $page->profile->entry_year)) { | |
7e233317 SJ |
476 | XDB::execute('UPDATE profile_display |
477 | SET promo = {?} | |
478 | WHERE pid = {?}', | |
479 | $page->profile->mainEducation() . strval($value), $page->profile->id()); | |
480 | XDB::execute('UPDATE profile_education | |
481 | SET grad_year = {?} | |
482 | WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)', | |
483 | $gradYearNew, $page->profile->id()); | |
86ced4d4 | 484 | Platal::page()->trigSuccess('Ton statut « orange » a été supprimé.'); |
7e233317 | 485 | } else { |
0b981fbe | 486 | $myorange = new OrangeReq(S::user(), $page->profile, $gradYearNew); |
7e233317 SJ |
487 | $myorange->submit(); |
488 | Platal::page()->trigSuccess('Tu pourras changer l\'affichage de ta promotion dès que ta nouvelle promotion aura été validée.'); | |
489 | } | |
490 | } | |
491 | ||
26ba053e | 492 | public function value(ProfilePage $page, $field, $value, &$success) |
7e233317 SJ |
493 | { |
494 | $entryYear = $page->profile->entry_year; | |
495 | $gradYear = $page->profile->grad_year; | |
7733ade1 | 496 | $yearpromo = $page->profile->yearpromo(); |
7e233317 | 497 | $success = true; |
86ced4d4 | 498 | if (is_null($value) || $value == $yearpromo) { |
7e233317 SJ |
499 | if ($gradYear != $entryYear + $page->profile->mainEducationDuration()) { |
500 | $promoChoice = array(); | |
86ced4d4 SJ |
501 | for ($i = $entryYear; $i <= $gradYear - $page->profile->mainEducationDuration(); ++$i) { |
502 | if ($page->profile->mainEducation() == 'X') { | |
503 | $promoChoice[] = $page->profile->mainEducation() . strval($i); | |
504 | } else { | |
505 | $promoChoice[] = $page->profile->mainEducation() . strval($i + $page->profile->mainEducationDuration()); | |
506 | } | |
7e233317 SJ |
507 | } |
508 | Platal::page()->assign('promo_choice', $promoChoice); | |
509 | } | |
67b4d856 SJ |
510 | |
511 | // If this profile belongs to an X, return grad year minus education duration. | |
512 | if ($page->profile->mainEducation() == 'X') { | |
513 | return $gradYear - $page->profile->mainEducationDuration(); | |
514 | } | |
515 | ||
516 | return $gradYear; | |
7e233317 SJ |
517 | } |
518 | ||
519 | // If this profile belongs to an X, $promoNew needs to be changed to | |
520 | // the graduation year. | |
521 | $gradYearNew = $value; | |
522 | if ($page->profile->mainEducation() == 'X') { | |
523 | $gradYearNew += $page->profile->mainEducationDuration(); | |
524 | } | |
525 | ||
526 | if ($value < 1000 || $value > 9999) { | |
527 | Platal::page()->trigError('L\'année de sortie doit être un nombre de quatre chiffres.'); | |
528 | $success = false; | |
529 | } elseif ($gradYearNew < $entryYear + $page->profile->mainEducationDuration()) { | |
530 | Platal::page()->trigError('Trop tôt !'); | |
531 | $success = false; | |
532 | } | |
533 | return intval($value); | |
534 | } | |
a0fce0c6 SJ |
535 | |
536 | public function getText($value) { | |
537 | return $value; | |
538 | } | |
7e233317 SJ |
539 | } |
540 | ||
541 | ||
66c4bdaf | 542 | class ProfilePageGeneral extends ProfilePage |
fd38b30e FB |
543 | { |
544 | protected $pg_template = 'profile/general.tpl'; | |
545 | ||
26ba053e | 546 | public function __construct(PlWizard $wiz) |
fd38b30e FB |
547 | { |
548 | parent::__construct($wiz); | |
c4b45374 | 549 | $this->settings['search_names'] |
12bcf04b | 550 | = new ProfileSettingSearchNames(); |
42ec0fe2 | 551 | $this->settings['nationality1'] |
e5bcd851 FB |
552 | = $this->settings['nationality2'] |
553 | = $this->settings['nationality3'] | |
7e233317 | 554 | = $this->settings['promo_display'] |
93553cea | 555 | = null; |
b715c1e1 | 556 | $this->settings['email_directory'] |
12bcf04b | 557 | = new ProfileSettingEmail(); |
b715c1e1 | 558 | $this->settings['email_directory_new'] |
12bcf04b RB |
559 | = new ProfileSettingEmailDirectory(); |
560 | $this->settings['networking'] = new ProfileSettingNetworking(); | |
0b6c8b36 | 561 | $this->settings['tels'] = new ProfileSettingPhones(); |
12bcf04b | 562 | $this->settings['edus'] = new ProfileSettingEdu(); |
d7de04af | 563 | $this->settings['main_edus'] = new ProfileSettingMainEdu(); |
7e233317 | 564 | $this->settings['promo'] = new ProfileSettingPromo(); |
42ec0fe2 | 565 | $this->watched= array('tels' => true, |
043bbacf | 566 | 'networking' => true, 'edus' => true, |
e5bcd851 | 567 | 'nationality1' => true, 'nationality2' => true, |
4ca15c31 | 568 | 'nationality3' => true, 'search_names' => true); |
42ec0fe2 FB |
569 | |
570 | /* Some fields editable under condition */ | |
571 | if (!S::user()->isMe($this->owner)) { | |
572 | $this->settings['deathdate'] = new ProfileSettingDate(true); | |
c56a253e | 573 | $this->settings['birthdate'] = new ProfileSettingDate(true); |
e1805873 | 574 | $this->settings['birthdate_ref'] = new ProfileSettingDate(true); |
c56a253e | 575 | } else { |
1447ed1a | 576 | $this->settings['yourself'] = null; |
c56a253e | 577 | $this->settings['birthdate'] = new ProfileSettingDate(); |
1447ed1a | 578 | } |
42ec0fe2 FB |
579 | if (S::user()->checkPerms('directory_private') |
580 | || S::user()->isMyProfile($this->owner)) { | |
1447ed1a | 581 | $this->settings['freetext'] = null; |
42ec0fe2 FB |
582 | $this->settings['freetext_pub'] |
583 | = $this->settings['photo_pub'] | |
584 | = new ProfileSettingPub(); | |
585 | $this->watched['freetext'] = true; | |
586 | } | |
587 | ||
93553cea FB |
588 | } |
589 | ||
7c2e0f0d | 590 | protected function _fetchData() |
93553cea | 591 | { |
576777d7 | 592 | // Checkout all data... |
c56a253e | 593 | $res = XDB::query("SELECT p.nationality1, p.nationality2, p.nationality3, IF(p.birthdate = 0, '', p.birthdate) AS birthdate, |
7e233317 | 594 | p.email_directory as email_directory, pd.promo AS promo_display, |
87db81e7 | 595 | p.freetext, p.freetext_pub, p.ax_id AS matricule_ax, pd.yourself, |
e1805873 | 596 | p.deathdate, IF(p.birthdate_ref = 0, '', p.birthdate_ref) AS birthdate_ref |
7e233317 SJ |
597 | FROM profiles AS p |
598 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
7e233317 | 599 | WHERE p.pid = {?}", $this->pid()); |
93553cea | 600 | $this->values = $res->fetchOneAssoc(); |
576777d7 | 601 | |
576777d7 FB |
602 | // Retreive photo informations |
603 | $res = XDB::query("SELECT pub | |
5c4ea53f FB |
604 | FROM profile_photos |
605 | WHERE pid = {?}", $this->pid()); | |
bf9202ed SJ |
606 | if ($res->numRows() == 0) { |
607 | $this->values['photo_pub'] = 'private'; | |
608 | } else { | |
609 | $this->values['photo_pub'] = $res->fetchOneCell(); | |
610 | } | |
576777d7 | 611 | |
e5bcd851 FB |
612 | if ($this->owner) { |
613 | $res = XDB::query("SELECT COUNT(*) | |
614 | FROM requests | |
58bb2d9c | 615 | WHERE type = 'photo' AND pid = {?}", |
e5bcd851 FB |
616 | $this->owner->id()); |
617 | $this->values['nouvellephoto'] = $res->fetchOneCell(); | |
618 | } else { | |
619 | $this->values['nouvellephoto'] = 0; | |
620 | } | |
93553cea FB |
621 | } |
622 | ||
7c2e0f0d | 623 | protected function _saveData() |
93553cea | 624 | { |
e5bcd851 | 625 | if ($this->changed['nationality1'] || $this->changed['nationality2'] || $this->changed['nationality3'] |
ce0b2c6f FB |
626 | || $this->changed['birthdate'] || $this->changed['freetext'] || $this->changed['freetext_pub'] |
627 | || $this->changed['email_directory']) { | |
e5bcd851 FB |
628 | if ($this->values['nationality3'] == "") { |
629 | $this->values['nationality3'] = NULL; | |
8450c2aa | 630 | } |
e5bcd851 FB |
631 | if ($this->values['nationality2'] == "") { |
632 | $this->values['nationality2'] = $this->values['nationality3']; | |
633 | $this->values['nationality3'] = NULL; | |
8450c2aa | 634 | } |
e5bcd851 | 635 | if ($this->values['nationality1'] == "") { |
48a4525c | 636 | $this->values['nationality1'] = $this->values['nationality2']; |
e5bcd851 FB |
637 | $this->values['nationality2'] = $this->values['nationality3']; |
638 | $this->values['nationality3'] = NULL; | |
8450c2aa | 639 | } |
48a4525c SJ |
640 | if ($this->values['nationality1'] == $this->values['nationality2'] |
641 | && $this->values['nationality2'] == $this->values['nationality3']) { | |
642 | $this->values['nationality2'] = NULL; | |
643 | $this->values['nationality3'] = NULL; | |
644 | } else if ($this->values['nationality1'] == $this->values['nationality2']) { | |
645 | $this->values['nationality2'] = $this->values['nationality3']; | |
646 | $this->values['nationality3'] = NULL; | |
647 | } else if ($this->values['nationality2'] == $this->values['nationality3'] | |
648 | || $this->values['nationality1'] == $this->values['nationality3']) { | |
649 | $this->values['nationality3'] = NULL; | |
650 | } | |
651 | ||
ce0b2c6f FB |
652 | $new_email = ($this->values['email_directory'] == "new@example.org") ? |
653 | $this->values['email_directory_new'] : $this->values['email_directory']; | |
654 | if ($new_email == "") { | |
655 | $new_email = NULL; | |
656 | } | |
8450c2aa | 657 | |
e5bcd851 FB |
658 | XDB::execute("UPDATE profiles |
659 | SET nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?}, | |
ce0b2c6f | 660 | freetext = {?}, freetext_pub = {?}, email_directory = {?} |
d1e61677 | 661 | WHERE pid = {?}", |
e5bcd851 | 662 | $this->values['nationality1'], $this->values['nationality2'], $this->values['nationality3'], |
87db81e7 | 663 | ProfileSettingDate::toSQLDate($this->values['birthdate']), |
ce0b2c6f | 664 | $this->values['freetext'], $this->values['freetext_pub'], $new_email, $this->pid()); |
b715c1e1 | 665 | } |
a7c28fff | 666 | if ($this->changed['photo_pub']) { |
5c4ea53f | 667 | XDB::execute("UPDATE profile_photos |
a7c28fff | 668 | SET pub = {?} |
5c4ea53f | 669 | WHERE pid = {?}", |
e5bcd851 | 670 | $this->values['photo_pub'], $this->pid()); |
a7c28fff | 671 | } |
9241c897 | 672 | if (S::user()->isMe($this->owner) && $this->changed['yourself']) { |
cb0af6e5 FB |
673 | if ($this->owner) { |
674 | XDB::execute('UPDATE accounts | |
675 | SET display_name = {?} | |
676 | WHERE uid = {?}', | |
677 | $this->values['yourself'], $this->owner->id()); | |
678 | } | |
679 | XDB::execute('UPDATE profile_display | |
680 | SET yourself = {?} | |
681 | WHERE pid = {?}', $this->values['yourself'], | |
682 | $this->pid()); | |
fb2c09c9 | 683 | } |
7e233317 | 684 | if ($this->changed['promo_display']) { |
86ced4d4 | 685 | if ($this->values['promo_display']{0} == $this->profile->mainEducation()) { |
7733ade1 SJ |
686 | $yearpromo = intval(substr($this->values['promo_display'], 1, 4)); |
687 | if (($this->profile->mainEducation() == 'X' && $yearpromo >= $this->profile->entry_year) | |
86ced4d4 | 688 | || ($this->profile->mainEducation() != 'X' |
7733ade1 | 689 | && $yearpromo >= $this->profile->entry_year + $this->profile->mainEducationDuration())) { |
86ced4d4 SJ |
690 | XDB::execute('UPDATE profile_display |
691 | SET promo = {?} | |
692 | WHERE pid = {?}', | |
693 | $this->values['promo_display'], $this->pid()); | |
7733ade1 SJ |
694 | XDB::execute('UPDATE profile_education |
695 | SET promo_year = {?} | |
696 | WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)', | |
697 | $yearpromo, $this->pid()); | |
86ced4d4 | 698 | } |
7e233317 | 699 | } |
b04882ff | 700 | } |
e1805873 SJ |
701 | if ($this->orig['birthdate_ref'] == 0 && !S::user()->isMe($this->owner) && $this->changed['birthdate_ref']) { |
702 | XDB::execute('UPDATE profiles | |
703 | SET birthdate_ref = {?} | |
704 | WHERE pid = {?}', | |
705 | ProfileSettingDate::toSQLDate($this->values['birthdate_ref']), $this->pid()); | |
706 | } | |
f7190088 | 707 | if (!S::user()->isMe($this->owner) && $this->changed['deathdate']) { |
87db81e7 FB |
708 | XDB::execute('UPDATE profiles |
709 | SET deathdate = {?}, deathdate_rec = NOW() | |
710 | WHERE pid = {?} AND deathdate_rec IS NULL', | |
711 | ProfileSettingDate::toSQLDate($this->values['deathdate']), $this->pid()); | |
712 | if (XDB::affectedRows() > 0) { | |
713 | $this->profile->clear(); | |
714 | if ($this->owner) { | |
715 | $this->owner->clear(true); | |
716 | } | |
717 | } else { | |
718 | /* deathdate_rec was not NULL, this is just an update of the death date | |
719 | */ | |
720 | XDB::execute('UPDATE profiles | |
721 | SET deathdate = {?} | |
722 | WHERE pid = {?}', | |
723 | ProfileSettingDate::toSQLDate($this->values['deathdate']), $this->pid()); | |
724 | } | |
725 | } | |
fd38b30e FB |
726 | } |
727 | ||
26ba053e | 728 | public function _prepare(PlPage $page, $id) |
fd38b30e | 729 | { |
f711b03f | 730 | require_once "education.func.inc.php"; |
d1a2252a | 731 | |
111b2736 FB |
732 | $res = XDB::query("SELECT id, field |
733 | FROM profile_education_field_enum | |
734 | ORDER BY field"); | |
043bbacf SJ |
735 | $page->assign('edu_fields', $res->fetchAllAssoc()); |
736 | ||
b715c1e1 | 737 | require_once "emails.combobox.inc.php"; |
17c6e7bb | 738 | fill_email_combobox($page, array('source', 'redirect', 'job', 'directory'), $this->owner); |
b715c1e1 | 739 | |
1f5cd004 | 740 | $res = XDB::query("SELECT nw.nwid AS type, nw.name |
111b2736 FB |
741 | FROM profile_networking_enum AS nw |
742 | ORDER BY name"); | |
d1a2252a | 743 | $page->assign('network_list', $res->fetchAllAssoc()); |
c4b45374 | 744 | |
0e1dfbad SJ |
745 | $page->assign('lastnames', array('main' => 'Nom patronymique', 'marital' => 'Nom marital', 'ordinary' => 'Nom usuel')); |
746 | $page->assign('firstnames', array('firstname_main' => 'Prénom', 'firstname_ordinary' => 'Prénom usuel', 'pseudonym' => 'Pseudonyme (nom de plume)')); | |
747 | $page->assign('other_names', array('nickname' => 'Surnom', 'firstname' => 'Autre prénom', 'lastname' => 'Autre nom')); | |
e8a7cf31 | 748 | $page->assign('isFemale', $this->profile->isFemale() ? 1 : 0); |
fd38b30e FB |
749 | } |
750 | } | |
751 | ||
752 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
753 | ?> |