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