Commit | Line | Data |
---|---|---|
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 | ||
12bcf04b | 22 | class ProfileSettingSearchNames implements ProfileSetting |
fd38b30e | 23 | { |
dced83b4 SJ |
24 | private $private_name_end; |
25 | private $search_names; | |
b270577e SJ |
26 | private $name_types; |
27 | ||
28 | public function __construct() { | |
29 | $this->name_types = DirEnum::getOptions(DirEnum::NAMES); | |
30 | } | |
c4b45374 | 31 | |
e5bcd851 FB |
32 | private function matchWord($old, $new, $newLen) |
33 | { | |
93553cea | 34 | return ($i = strpos($old, $new)) !== false |
fd38b30e FB |
35 | && ($i == 0 || $old{$i-1} == ' ') |
36 | && ($i + $newLen == strlen($old) || $old{$i + $newLen} == ' '); | |
37 | } | |
38 | ||
39 | private function prepareField($value) | |
40 | { | |
ac40839f | 41 | return name_to_basename($value); |
fd38b30e FB |
42 | } |
43 | ||
c4b45374 | 44 | private function prepare(ProfilePage &$page, $field, $value, $init, &$success) |
fd38b30e FB |
45 | { |
46 | $success = true; | |
dced83b4 SJ |
47 | $ini = $this->prepareField($init); |
48 | $new = $this->prepareField($value); | |
c4b45374 SJ |
49 | $newLen = strlen($new); |
50 | $success = $this->matchWord($ini, $new, $newLen) | |
6cb58d39 | 51 | || ($field == 'lastname' && $new == 'DE ' . $ini); |
fd38b30e | 52 | if (!$success) { |
c4b45374 | 53 | $field = strtolower($field); |
b270577e SJ |
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 . ")."); | |
fd38b30e | 56 | } |
c4b45374 | 57 | return $success ? $value : $init; |
fd38b30e FB |
58 | } |
59 | ||
b270577e SJ |
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 | ||
c4b45374 | 81 | public function value(ProfilePage &$page, $field, $value, &$success) |
fd38b30e | 82 | { |
dced83b4 | 83 | $success = true; |
c4b45374 | 84 | $success_tmp = true; |
09f9ebea | 85 | |
c4b45374 SJ |
86 | if (is_null($value)) { |
87 | $sn_all = XDB::iterator("SELECT CONCAT(sn.particle, sn.name) AS name, | |
6cb58d39 | 88 | sn.particle, sn.typeid, e.type, e.name AS type_name, |
c4b45374 SJ |
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 | |
97a98687 SJ |
92 | FROM profile_name AS sn |
93 | INNER JOIN profile_name_enum AS e ON (e.id = sn.typeid) | |
c4b45374 SJ |
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", | |
111b2736 | 96 | $page->pid()); |
c4b45374 | 97 | |
6cb58d39 SJ |
98 | $sn_types = XDB::iterator("SELECT id, type, name, |
99 | FIND_IN_SET('has_particle', flags) AS has_particle | |
97a98687 | 100 | FROM profile_name_enum |
c4b45374 SJ |
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; | |
111b2736 FB |
110 | if ($sn) { |
111 | $sn = $sn_all->next(); | |
112 | } | |
c4b45374 | 113 | } else { |
09f9ebea SJ |
114 | $value[] = array('name' => '', |
115 | 'particle' => '', | |
116 | 'typeid' => $sn_type['id'], | |
117 | 'type' => $sn_type['type'], | |
118 | 'type_name' => $sn_type['name'], | |
c4b45374 | 119 | 'has_particle' => $sn_type['has_particle'], |
09f9ebea SJ |
120 | 'always_displayed' => 1, |
121 | 'pub' => 1); | |
c4b45374 SJ |
122 | } |
123 | } | |
6cb58d39 SJ |
124 | if ($sn) { |
125 | do { | |
126 | $value[] = $sn; | |
127 | } while ($sn = $sn_all->next()); | |
111b2736 | 128 | } |
bd3e755e SJ |
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 | } | |
b270577e | 134 | $value = $this->clean($value); |
c4b45374 | 135 | } else { |
6cb58d39 SJ |
136 | require_once 'name.func.inc.php'; |
137 | ||
b270577e | 138 | $value = $this->clean($value); |
c4b45374 | 139 | $res = XDB::query("SELECT s.particle, s.name |
97a98687 SJ |
140 | FROM profile_name AS s |
141 | INNER JOIN profile_name_enum AS e ON (e.id = s.typeid) | |
2fa91df0 SJ |
142 | WHERE s.pid = {?} AND (e.type = 'lastname' OR e.type = 'firstname') |
143 | ORDER BY e.type = 'firstname'", | |
111b2736 | 144 | $page->pid()); |
c4b45374 SJ |
145 | $res = $res->fetchAllAssoc(); |
146 | $initial = array(); | |
6cb58d39 SJ |
147 | $initial['lastname'] = $res[0]['particle'] . $res[0]['name']; |
148 | $initial['firstname'] = $res[1]['name']; | |
149 | $sn_types = build_types(); | |
dced83b4 SJ |
150 | $this->search_names = array(); |
151 | foreach ($value as &$sn) { | |
c4b45374 | 152 | $sn['name'] = trim($sn['name']); |
6cb58d39 | 153 | if ($sn['type'] == 'firstname' || $sn['type'] == 'lastname') { |
c4b45374 SJ |
154 | $sn['name'] = $this->prepare($page, $sn['type'], $sn['name'], |
155 | $initial[$sn['type']], $success_tmp); | |
156 | $success = $success && $success_tmp; | |
157 | } | |
dced83b4 SJ |
158 | if ($sn['pub']) { |
159 | if (isset($sn['particle']) && ($sn['particle'] != '')) { | |
faf5f834 | 160 | // particle is before first blank |
dced83b4 SJ |
161 | list($particle, $name) = explode(' ', $sn['name'], 2); |
162 | $particle = trim($particle) . ' '; | |
163 | if (!$name) { | |
faf5f834 | 164 | // particle is before first quote |
dced83b4 SJ |
165 | list($particle, $name) = explode('\'', $sn['name'], 2); |
166 | $particle = trim($particle); | |
faf5f834 PC |
167 | if (!$name) { |
168 | // actually there is no particle | |
169 | $particle = ''; | |
170 | $name = $sn['name']; | |
171 | } | |
dced83b4 SJ |
172 | } |
173 | } else { | |
174 | $particle = ''; | |
175 | $name = $sn['name']; | |
176 | } | |
177 | } | |
c4b45374 | 178 | if ($sn['name'] != '') { |
dced83b4 SJ |
179 | if ($sn['pub']) { |
180 | $this->search_names[$sn['typeid']] = array('fullname' => $sn['name'], | |
181 | 'name' => $name, | |
182 | 'particle' => $particle, | |
183 | 'pub' => $sn['pub']); | |
c4b45374 | 184 | } else { |
dced83b4 SJ |
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 | } | |
6cb58d39 | 190 | $sn['type_name'] = $sn_types[$sn['typeid']]; |
c4b45374 SJ |
191 | } |
192 | } | |
193 | } | |
dced83b4 SJ |
194 | $res = XDB::query("SELECT public_name, private_name |
195 | FROM profile_display | |
196 | WHERE pid = {?}", | |
f41cf525 | 197 | $page->pid()); |
dced83b4 SJ |
198 | list($public_name, $private_name) = $res->fetchOneRow(); |
199 | if ($success) { | |
dced83b4 SJ |
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); | |
fd38b30e | 206 | } |
09f9ebea | 207 | |
c4b45374 | 208 | return $value; |
fd38b30e FB |
209 | } |
210 | ||
c4b45374 | 211 | public function save(ProfilePage &$page, $field, $value) |
fd38b30e | 212 | { |
dced83b4 | 213 | require_once 'name.func.inc.php'; |
024ec1e5 SJ |
214 | require_once 'validations.inc.php'; |
215 | ||
e8a7cf31 | 216 | $sn_old = build_sn_pub($page->pid()); |
c4b45374 | 217 | XDB::execute("DELETE FROM s |
97a98687 SJ |
218 | USING profile_name AS s |
219 | INNER JOIN profile_name_enum AS e ON (s.typeid = e.id) | |
c4b45374 | 220 | WHERE s.pid = {?} AND NOT FIND_IN_SET('not_displayed', e.flags)", |
111b2736 | 221 | $page->pid()); |
e8a7cf31 | 222 | $has_new = set_alias_names($this->search_names, $sn_old, $page->pid(), $page->owner->id()); |
dced83b4 SJ |
223 | |
224 | // Only requires validation if modification in public names | |
225 | if ($has_new) { | |
0b981fbe | 226 | $new_names = new NamesReq(S::user(), $page->profile, $this->search_names, $this->private_name_end); |
dced83b4 | 227 | $new_names->submit(); |
b270577e SJ |
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.'); | |
dced83b4 SJ |
230 | } else { |
231 | $display_names = array(); | |
e8a7cf31 SJ |
232 | build_display_names($display_names, $this->search_names, |
233 | $page->profile->isFemale(), $this->private_name_end); | |
234 | set_profile_display($display_names, $page->pid()); | |
c4b45374 | 235 | } |
fd38b30e | 236 | } |
a0fce0c6 SJ |
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 | } | |
fd38b30e FB |
247 | } |
248 | ||
12bcf04b | 249 | class ProfileSettingEdu implements ProfileSetting |
576777d7 | 250 | { |
e5bcd851 FB |
251 | public function __construct() { |
252 | } | |
043bbacf | 253 | |
5ba8842e | 254 | static function sortByGradYear($line1, $line2) { |
be6806fa SJ |
255 | $a = (isset($line1['grad_year'])) ? (int) $line1['grad_year'] : 0; |
256 | $b = (isset($line2['grad_year'])) ? (int) $line2['grad_year'] : 0; | |
22f0a0a8 | 257 | if ($a == $b) { |
5ba8842e SJ |
258 | return 0; |
259 | } | |
22f0a0a8 | 260 | return ($a < $b) ? -1 : 1; |
5ba8842e SJ |
261 | } |
262 | ||
576777d7 FB |
263 | public function value(ProfilePage &$page, $field, $value, &$success) |
264 | { | |
265 | $success = true; | |
885fa398 | 266 | if (is_null($value)) { |
043bbacf | 267 | $value = array(); |
111b2736 FB |
268 | $value = XDB::fetchAllAssoc("SELECT eduid, degreeid, fieldid, grad_year, program |
269 | FROM profile_education | |
ce0b2c6f | 270 | WHERE pid = {?} AND !FIND_IN_SET('primary', flags) |
111b2736 FB |
271 | ORDER BY id", |
272 | $page->pid()); | |
885fa398 SJ |
273 | } else if (!is_array($value)) { |
274 | $value = null; | |
043bbacf SJ |
275 | } else { |
276 | $i = 0; | |
277 | foreach ($value as $key=>&$edu) { | |
278 | if (($edu['grad_year'] < 1921) || ($edu['grad_year'] > (date('Y') + 4))) { | |
be6806fa | 279 | Platal::page()->trigWarning('L\'année d\'obtention du diplôme est mal ou non renseignée, elle doit être du type : 2004.'); |
83065276 | 280 | $edu['grad_year'] = null; |
be6806fa | 281 | $edu['warning'] = true; |
043bbacf SJ |
282 | } |
283 | if ($key != $i) { | |
284 | $value[$i] = $edu; | |
285 | unset($value[$key]); | |
286 | } | |
287 | $i++; | |
288 | } | |
12bcf04b | 289 | usort($value, array("ProfileSettingEdu", "sortByGradYear")); |
576777d7 FB |
290 | } |
291 | return $value; | |
292 | } | |
293 | ||
043bbacf | 294 | public function save(ProfilePage &$page, $field, $value) |
576777d7 | 295 | { |
043bbacf | 296 | XDB::execute("DELETE FROM profile_education |
ce0b2c6f | 297 | WHERE pid = {?} AND !FIND_IN_SET('primary', flags)", |
e5bcd851 | 298 | $page->pid()); |
043bbacf SJ |
299 | foreach ($value as $eduid=>&$edu) { |
300 | if ($edu['eduid'] != '') { | |
301 | XDB::execute("INSERT INTO profile_education | |
ce0b2c6f | 302 | SET id = {?}, pid = {?}, eduid = {?}, degreeid = {?}, |
1504ac45 | 303 | fieldid = {?}, grad_year = {?}, program = {?}", |
e5bcd851 | 304 | $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'], |
1504ac45 | 305 | $edu['fieldid'], $edu['grad_year'], $edu['program']); |
043bbacf | 306 | } |
576777d7 FB |
307 | } |
308 | } | |
a0fce0c6 SJ |
309 | |
310 | public function getText($value) { | |
311 | $schoolsList = DirEnum::getOptions(DirEnum::EDUSCHOOLS); | |
312 | $degreesList = DirEnum::getOptions(DirEnum::EDUDEGREES); | |
313 | $fieldsList = DirEnum::getOptions(DirEnum::EDUFIELDS); | |
314 | $educations = array(); | |
315 | foreach ($value as $education) { | |
316 | $educations[] = 'Université : ' . $schoolsList[$education['eduid']] | |
317 | . ', diplôme : ' . $degreesList[$education['degreeid']] | |
318 | . ', domaine : ' . $fieldsList[$education['fieldid']] | |
319 | . ', année d\'obtention : ' . $education['grad_year'] | |
320 | . ', intitulé : ' . $education['program']; | |
321 | } | |
322 | return implode(', ', $educations); | |
323 | } | |
576777d7 FB |
324 | } |
325 | ||
12bcf04b | 326 | class ProfileSettingEmailDirectory implements ProfileSetting |
b715c1e1 | 327 | { |
b814a8b8 SJ |
328 | public function __construct(){} |
329 | public function save(ProfilePage &$page, $field, $value){} | |
b715c1e1 SJ |
330 | |
331 | public function value(ProfilePage &$page, $field, $value, &$success) | |
332 | { | |
ad3fee9d | 333 | $p = Platal::page(); |
b715c1e1 SJ |
334 | |
335 | $success = true; | |
336 | if (!is_null($value)) { | |
337 | $email_stripped = strtolower(trim($value)); | |
ad3fee9d SJ |
338 | if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values['email_directory'] == "new@example.org")) { |
339 | $p->assign('email_error', '1'); | |
340 | $p->assign('email_directory_error', $email_stripped); | |
341 | $p->trigError('Adresse Email invalide'); | |
b715c1e1 SJ |
342 | $success = false; |
343 | } else { | |
ad3fee9d | 344 | $p->assign('email_error', '0'); |
b715c1e1 SJ |
345 | } |
346 | } | |
347 | return $value; | |
348 | } | |
a0fce0c6 SJ |
349 | |
350 | public function getText($value) { | |
351 | return $value; | |
352 | } | |
b715c1e1 SJ |
353 | } |
354 | ||
12bcf04b | 355 | class ProfileSettingNetworking implements ProfileSetting |
d1a2252a GB |
356 | { |
357 | private $email; | |
358 | private $pub; | |
359 | private $web; | |
92446a53 | 360 | private $number; |
d1a2252a GB |
361 | |
362 | public function __construct() | |
363 | { | |
12bcf04b RB |
364 | $this->email = new ProfileSettingEmail(); |
365 | $this->pub = new ProfileSettingPub(); | |
366 | $this->web = new ProfileSettingWeb(); | |
367 | $this->number = new ProfileSettingNumber(); | |
d1a2252a GB |
368 | } |
369 | ||
370 | public function value(ProfilePage &$page, $field, $value, &$success) | |
371 | { | |
372 | if (is_null($value)) { | |
1f5cd004 | 373 | $value = XDB::fetchAllAssoc("SELECT n.address, n.pub, n.nwid AS type |
111b2736 | 374 | FROM profile_networking AS n |
ce0b2c6f | 375 | WHERE n.pid = {?}", |
111b2736 | 376 | $page->pid()); |
d1a2252a GB |
377 | } |
378 | if (!is_array($value)) { | |
379 | $value = array(); | |
380 | } | |
1f5cd004 | 381 | $filters = XDB::fetchAllAssoc('type', 'SELECT filter, nwid AS type, name |
111b2736 | 382 | FROM profile_networking_enum;'); |
d1a2252a GB |
383 | $success = true; |
384 | foreach($value as $i=>&$network) { | |
92c3f9e5 GB |
385 | if (!trim($network['address'])) { |
386 | unset($value[$i]); | |
387 | } else { | |
388 | if (!isset($network['pub'])) { | |
389 | $network['pub'] = 'private'; | |
390 | } | |
391 | $network['error'] = false; | |
392 | $network['pub'] = $this->pub->value($page, 'pub', $network['pub'], $s); | |
393 | $s = true; | |
1f5cd004 PC |
394 | $network['name'] = $filters[$network['type']]['name']; |
395 | if ($filters[$network['type']]['filter'] == 'web') { | |
92c3f9e5 | 396 | $network['address'] = $this->web->value($page, 'address', $network['address'], $s); |
1f5cd004 | 397 | } elseif ($filters[$network['type']]['filter'] == 'email') { |
92c3f9e5 | 398 | $network['address'] = $this->email->value($page, 'address', $network['address'], $s); |
1f5cd004 | 399 | } elseif ($filters[$network['type']]['filter'] == 'number') { |
92c3f9e5 GB |
400 | $network['address'] = $this->number->value($page, 'address', $network['address'], $s); |
401 | } | |
402 | if (!$s) { | |
403 | $success = false; | |
404 | $network['error'] = true; | |
405 | } | |
d1a2252a GB |
406 | } |
407 | } | |
408 | return $value; | |
409 | } | |
410 | ||
411 | public function save(ProfilePage &$page, $field, $value) | |
412 | { | |
413 | XDB::execute("DELETE FROM profile_networking | |
ce0b2c6f | 414 | WHERE pid = {?}", |
e5bcd851 | 415 | $page->pid()); |
d1a2252a GB |
416 | if (!count($value)) { |
417 | return; | |
418 | } | |
419 | $insert = array(); | |
420 | foreach ($value as $id=>$network) { | |
1f5cd004 | 421 | XDB::execute("INSERT INTO profile_networking (pid, id, nwid, address, pub) |
d1a2252a | 422 | VALUES ({?}, {?}, {?}, {?}, {?})", |
e5bcd851 | 423 | $page->pid(), $id, $network['type'], $network['address'], $network['pub']); |
d1a2252a GB |
424 | } |
425 | } | |
a0fce0c6 SJ |
426 | |
427 | public function getText($value) { | |
428 | $networkings = array(); | |
429 | foreach ($value as $network) { | |
430 | $networkings[] = 'nom : ' . $network['name'] . ', adresse : ' . $network['address'] | |
431 | . ', affichage : ' . $network['pub']; | |
432 | } | |
433 | return implode(' ; ' , $networkings); | |
434 | } | |
d1a2252a GB |
435 | } |
436 | ||
7e233317 SJ |
437 | class ProfileSettingPromo implements ProfileSetting |
438 | { | |
439 | public function __construct(){} | |
440 | ||
441 | public function save(ProfilePage &$page, $field, $value) | |
442 | { | |
443 | $gradYearNew = $value; | |
444 | if ($page->profile->mainEducation() == 'X') { | |
445 | $gradYearNew += $page->profile->mainEducationDuration(); | |
446 | } | |
86ced4d4 SJ |
447 | if (($page->profile->mainEducation() != 'X' |
448 | && $value == $page->profile->entry_year + $page->profile->mainEducationDuration()) | |
449 | || ($page->profile->mainEducation() == 'X' && $value == $page->profile->entry_year)) { | |
7e233317 SJ |
450 | XDB::execute('UPDATE profile_display |
451 | SET promo = {?} | |
452 | WHERE pid = {?}', | |
453 | $page->profile->mainEducation() . strval($value), $page->profile->id()); | |
454 | XDB::execute('UPDATE profile_education | |
455 | SET grad_year = {?} | |
456 | WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)', | |
457 | $gradYearNew, $page->profile->id()); | |
86ced4d4 | 458 | Platal::page()->trigSuccess('Ton statut « orange » a été supprimé.'); |
7e233317 SJ |
459 | } else { |
460 | require_once 'validations.inc.php'; | |
461 | ||
0b981fbe | 462 | $myorange = new OrangeReq(S::user(), $page->profile, $gradYearNew); |
7e233317 SJ |
463 | $myorange->submit(); |
464 | Platal::page()->trigSuccess('Tu pourras changer l\'affichage de ta promotion dès que ta nouvelle promotion aura été validée.'); | |
465 | } | |
466 | } | |
467 | ||
468 | public function value(ProfilePage &$page, $field, $value, &$success) | |
469 | { | |
470 | $entryYear = $page->profile->entry_year; | |
471 | $gradYear = $page->profile->grad_year; | |
86ced4d4 SJ |
472 | $yearpromo = $page->profile->grad_year; |
473 | if ($page->profile->mainEducation() == 'X') { | |
474 | $yearpromo -= $page->profile->mainEducationDuration(); | |
475 | } | |
7e233317 | 476 | $success = true; |
86ced4d4 | 477 | if (is_null($value) || $value == $yearpromo) { |
7e233317 SJ |
478 | if ($gradYear != $entryYear + $page->profile->mainEducationDuration()) { |
479 | $promoChoice = array(); | |
86ced4d4 SJ |
480 | for ($i = $entryYear; $i <= $gradYear - $page->profile->mainEducationDuration(); ++$i) { |
481 | if ($page->profile->mainEducation() == 'X') { | |
482 | $promoChoice[] = $page->profile->mainEducation() . strval($i); | |
483 | } else { | |
484 | $promoChoice[] = $page->profile->mainEducation() . strval($i + $page->profile->mainEducationDuration()); | |
485 | } | |
7e233317 SJ |
486 | } |
487 | Platal::page()->assign('promo_choice', $promoChoice); | |
488 | } | |
86ced4d4 | 489 | return $yearpromo; |
7e233317 SJ |
490 | } |
491 | ||
492 | // If this profile belongs to an X, $promoNew needs to be changed to | |
493 | // the graduation year. | |
494 | $gradYearNew = $value; | |
495 | if ($page->profile->mainEducation() == 'X') { | |
496 | $gradYearNew += $page->profile->mainEducationDuration(); | |
497 | } | |
498 | ||
499 | if ($value < 1000 || $value > 9999) { | |
500 | Platal::page()->trigError('L\'année de sortie doit être un nombre de quatre chiffres.'); | |
501 | $success = false; | |
502 | } elseif ($gradYearNew < $entryYear + $page->profile->mainEducationDuration()) { | |
503 | Platal::page()->trigError('Trop tôt !'); | |
504 | $success = false; | |
505 | } | |
506 | return intval($value); | |
507 | } | |
a0fce0c6 SJ |
508 | |
509 | public function getText($value) { | |
510 | return $value; | |
511 | } | |
7e233317 SJ |
512 | } |
513 | ||
514 | ||
12bcf04b | 515 | class ProfileSettingGeneral extends ProfilePage |
fd38b30e FB |
516 | { |
517 | protected $pg_template = 'profile/general.tpl'; | |
518 | ||
519 | public function __construct(PlWizard &$wiz) | |
520 | { | |
521 | parent::__construct($wiz); | |
c4b45374 | 522 | $this->settings['search_names'] |
12bcf04b RB |
523 | = new ProfileSettingSearchNames(); |
524 | $this->settings['birthdate'] = new ProfileSettingDate(); | |
bde2be3b | 525 | $this->settings['freetext_pub'] |
576777d7 | 526 | = $this->settings['photo_pub'] |
12bcf04b | 527 | = new ProfileSettingPub(); |
93553cea | 528 | $this->settings['freetext'] |
e5bcd851 FB |
529 | = $this->settings['nationality1'] |
530 | = $this->settings['nationality2'] | |
531 | = $this->settings['nationality3'] | |
b04882ff | 532 | = $this->settings['yourself'] |
7e233317 | 533 | = $this->settings['promo_display'] |
93553cea | 534 | = null; |
b715c1e1 | 535 | $this->settings['email_directory'] |
12bcf04b | 536 | = new ProfileSettingEmail(); |
b715c1e1 | 537 | $this->settings['email_directory_new'] |
12bcf04b RB |
538 | = new ProfileSettingEmailDirectory(); |
539 | $this->settings['networking'] = new ProfileSettingNetworking(); | |
540 | $this->settings['tels'] = new ProfileSettingPhones('user', 0); | |
541 | $this->settings['edus'] = new ProfileSettingEdu(); | |
7e233317 | 542 | $this->settings['promo'] = new ProfileSettingPromo(); |
6e32823c | 543 | $this->watched= array('freetext' => true, 'tels' => true, |
043bbacf | 544 | 'networking' => true, 'edus' => true, |
e5bcd851 | 545 | 'nationality1' => true, 'nationality2' => true, |
4ca15c31 | 546 | 'nationality3' => true, 'search_names' => true); |
93553cea FB |
547 | } |
548 | ||
7c2e0f0d | 549 | protected function _fetchData() |
93553cea | 550 | { |
576777d7 | 551 | // Checkout all data... |
7e233317 SJ |
552 | $res = XDB::query("SELECT p.nationality1, p.nationality2, p.nationality3, p.birthdate, |
553 | pp.display_tel as mobile, pp.pub as mobile_pub, | |
554 | p.email_directory as email_directory, pd.promo AS promo_display, | |
555 | p.freetext, p.freetext_pub, p.ax_id AS matricule_ax, pd.yourself | |
556 | FROM profiles AS p | |
557 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
558 | LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND link_type = 'user') | |
559 | WHERE p.pid = {?}", $this->pid()); | |
93553cea | 560 | $this->values = $res->fetchOneAssoc(); |
4ca15c31 FB |
561 | if ($this->owner) { |
562 | $this->values['yourself'] = $this->owner->displayName(); | |
563 | } | |
576777d7 | 564 | |
576777d7 FB |
565 | // Retreive photo informations |
566 | $res = XDB::query("SELECT pub | |
5c4ea53f FB |
567 | FROM profile_photos |
568 | WHERE pid = {?}", $this->pid()); | |
576777d7 FB |
569 | $this->values['photo_pub'] = $res->fetchOneCell(); |
570 | ||
e5bcd851 FB |
571 | if ($this->owner) { |
572 | $res = XDB::query("SELECT COUNT(*) | |
573 | FROM requests | |
58bb2d9c | 574 | WHERE type = 'photo' AND pid = {?}", |
e5bcd851 FB |
575 | $this->owner->id()); |
576 | $this->values['nouvellephoto'] = $res->fetchOneCell(); | |
577 | } else { | |
578 | $this->values['nouvellephoto'] = 0; | |
579 | } | |
93553cea FB |
580 | } |
581 | ||
7c2e0f0d | 582 | protected function _saveData() |
93553cea | 583 | { |
e5bcd851 | 584 | if ($this->changed['nationality1'] || $this->changed['nationality2'] || $this->changed['nationality3'] |
ce0b2c6f FB |
585 | || $this->changed['birthdate'] || $this->changed['freetext'] || $this->changed['freetext_pub'] |
586 | || $this->changed['email_directory']) { | |
e5bcd851 FB |
587 | if ($this->values['nationality3'] == "") { |
588 | $this->values['nationality3'] = NULL; | |
8450c2aa | 589 | } |
e5bcd851 FB |
590 | if ($this->values['nationality2'] == "") { |
591 | $this->values['nationality2'] = $this->values['nationality3']; | |
592 | $this->values['nationality3'] = NULL; | |
8450c2aa | 593 | } |
e5bcd851 | 594 | if ($this->values['nationality1'] == "") { |
48a4525c | 595 | $this->values['nationality1'] = $this->values['nationality2']; |
e5bcd851 FB |
596 | $this->values['nationality2'] = $this->values['nationality3']; |
597 | $this->values['nationality3'] = NULL; | |
8450c2aa | 598 | } |
48a4525c SJ |
599 | if ($this->values['nationality1'] == $this->values['nationality2'] |
600 | && $this->values['nationality2'] == $this->values['nationality3']) { | |
601 | $this->values['nationality2'] = NULL; | |
602 | $this->values['nationality3'] = NULL; | |
603 | } else if ($this->values['nationality1'] == $this->values['nationality2']) { | |
604 | $this->values['nationality2'] = $this->values['nationality3']; | |
605 | $this->values['nationality3'] = NULL; | |
606 | } else if ($this->values['nationality2'] == $this->values['nationality3'] | |
607 | || $this->values['nationality1'] == $this->values['nationality3']) { | |
608 | $this->values['nationality3'] = NULL; | |
609 | } | |
610 | ||
ce0b2c6f FB |
611 | $new_email = ($this->values['email_directory'] == "new@example.org") ? |
612 | $this->values['email_directory_new'] : $this->values['email_directory']; | |
613 | if ($new_email == "") { | |
614 | $new_email = NULL; | |
615 | } | |
8450c2aa | 616 | |
e5bcd851 FB |
617 | XDB::execute("UPDATE profiles |
618 | SET nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?}, | |
ce0b2c6f | 619 | freetext = {?}, freetext_pub = {?}, email_directory = {?} |
d1e61677 | 620 | WHERE pid = {?}", |
e5bcd851 FB |
621 | $this->values['nationality1'], $this->values['nationality2'], $this->values['nationality3'], |
622 | preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values['birthdate']), | |
ce0b2c6f | 623 | $this->values['freetext'], $this->values['freetext_pub'], $new_email, $this->pid()); |
b715c1e1 | 624 | } |
a7c28fff | 625 | if ($this->changed['photo_pub']) { |
5c4ea53f | 626 | XDB::execute("UPDATE profile_photos |
a7c28fff | 627 | SET pub = {?} |
5c4ea53f | 628 | WHERE pid = {?}", |
e5bcd851 | 629 | $this->values['photo_pub'], $this->pid()); |
a7c28fff | 630 | } |
c4b45374 | 631 | if ($this->changed['yourself']) { |
cb0af6e5 FB |
632 | if ($this->owner) { |
633 | XDB::execute('UPDATE accounts | |
634 | SET display_name = {?} | |
635 | WHERE uid = {?}', | |
636 | $this->values['yourself'], $this->owner->id()); | |
637 | } | |
638 | XDB::execute('UPDATE profile_display | |
639 | SET yourself = {?} | |
640 | WHERE pid = {?}', $this->values['yourself'], | |
641 | $this->pid()); | |
fb2c09c9 | 642 | } |
7e233317 | 643 | if ($this->changed['promo_display']) { |
86ced4d4 SJ |
644 | if ($this->values['promo_display']{0} == $this->profile->mainEducation()) { |
645 | if (($this->profile->mainEducation() == 'X' | |
646 | && intval(substr($this->values['promo_display'], 1, 4)) >= $this->profile->entry_year) | |
647 | || ($this->profile->mainEducation() != 'X' | |
648 | && intval(substr($this->values['promo_display'], 1, 4)) >= $this->profile->entry_year + $this->profile->mainEducationDuration())) { | |
649 | XDB::execute('UPDATE profile_display | |
650 | SET promo = {?} | |
651 | WHERE pid = {?}', | |
652 | $this->values['promo_display'], $this->pid()); | |
653 | } | |
7e233317 | 654 | } |
b04882ff | 655 | } |
fd38b30e FB |
656 | } |
657 | ||
04334c61 | 658 | public function _prepare(PlPage &$page, $id) |
fd38b30e | 659 | { |
f711b03f | 660 | require_once "education.func.inc.php"; |
d1a2252a | 661 | |
111b2736 FB |
662 | $res = XDB::query("SELECT id, field |
663 | FROM profile_education_field_enum | |
664 | ORDER BY field"); | |
043bbacf SJ |
665 | $page->assign('edu_fields', $res->fetchAllAssoc()); |
666 | ||
b715c1e1 | 667 | require_once "emails.combobox.inc.php"; |
e5bcd851 | 668 | fill_email_combobox($page, $this->owner, $this->profile); |
b715c1e1 | 669 | |
1f5cd004 | 670 | $res = XDB::query("SELECT nw.nwid AS type, nw.name |
111b2736 FB |
671 | FROM profile_networking_enum AS nw |
672 | ORDER BY name"); | |
d1a2252a | 673 | $page->assign('network_list', $res->fetchAllAssoc()); |
c4b45374 SJ |
674 | |
675 | $res = XDB::query("SELECT public_name, private_name | |
676 | FROM profile_display | |
677 | WHERE pid = {?}", | |
111b2736 | 678 | $this->pid()); |
c4b45374 SJ |
679 | $res = $res->fetchOneRow(); |
680 | $page->assign('public_name', $res[0]); | |
681 | $page->assign('private_name', $res[1]); | |
e8a7cf31 | 682 | $page->assign('isFemale', $this->profile->isFemale() ? 1 : 0); |
fd38b30e FB |
683 | } |
684 | } | |
685 | ||
686 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
687 | ?> |