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 | } |
b270577e | 129 | $value = $this->clean($value); |
c4b45374 | 130 | } else { |
6cb58d39 SJ |
131 | require_once 'name.func.inc.php'; |
132 | ||
b270577e | 133 | $value = $this->clean($value); |
c4b45374 | 134 | $res = XDB::query("SELECT s.particle, s.name |
97a98687 SJ |
135 | FROM profile_name AS s |
136 | INNER JOIN profile_name_enum AS e ON (e.id = s.typeid) | |
2fa91df0 SJ |
137 | WHERE s.pid = {?} AND (e.type = 'lastname' OR e.type = 'firstname') |
138 | ORDER BY e.type = 'firstname'", | |
111b2736 | 139 | $page->pid()); |
c4b45374 SJ |
140 | $res = $res->fetchAllAssoc(); |
141 | $initial = array(); | |
6cb58d39 SJ |
142 | $initial['lastname'] = $res[0]['particle'] . $res[0]['name']; |
143 | $initial['firstname'] = $res[1]['name']; | |
144 | $sn_types = build_types(); | |
dced83b4 SJ |
145 | $this->search_names = array(); |
146 | foreach ($value as &$sn) { | |
c4b45374 | 147 | $sn['name'] = trim($sn['name']); |
6cb58d39 | 148 | if ($sn['type'] == 'firstname' || $sn['type'] == 'lastname') { |
c4b45374 SJ |
149 | $sn['name'] = $this->prepare($page, $sn['type'], $sn['name'], |
150 | $initial[$sn['type']], $success_tmp); | |
151 | $success = $success && $success_tmp; | |
152 | } | |
dced83b4 SJ |
153 | if ($sn['pub']) { |
154 | if (isset($sn['particle']) && ($sn['particle'] != '')) { | |
faf5f834 | 155 | // particle is before first blank |
dced83b4 SJ |
156 | list($particle, $name) = explode(' ', $sn['name'], 2); |
157 | $particle = trim($particle) . ' '; | |
158 | if (!$name) { | |
faf5f834 | 159 | // particle is before first quote |
dced83b4 SJ |
160 | list($particle, $name) = explode('\'', $sn['name'], 2); |
161 | $particle = trim($particle); | |
faf5f834 PC |
162 | if (!$name) { |
163 | // actually there is no particle | |
164 | $particle = ''; | |
165 | $name = $sn['name']; | |
166 | } | |
dced83b4 SJ |
167 | } |
168 | } else { | |
169 | $particle = ''; | |
170 | $name = $sn['name']; | |
171 | } | |
172 | } | |
c4b45374 | 173 | if ($sn['name'] != '') { |
dced83b4 SJ |
174 | if ($sn['pub']) { |
175 | $this->search_names[$sn['typeid']] = array('fullname' => $sn['name'], | |
176 | 'name' => $name, | |
177 | 'particle' => $particle, | |
178 | 'pub' => $sn['pub']); | |
c4b45374 | 179 | } else { |
dced83b4 SJ |
180 | if (isset($this->search_names[$sn['typeid']])) { |
181 | $this->search_names[$sn['typeid']][] = $sn['name']; | |
182 | } else { | |
183 | $this->search_names[$sn['typeid']] = array('fullname' => $sn['name']); | |
184 | } | |
6cb58d39 | 185 | $sn['type_name'] = $sn_types[$sn['typeid']]; |
c4b45374 SJ |
186 | } |
187 | } | |
188 | } | |
dced83b4 SJ |
189 | $res = XDB::query("SELECT public_name, private_name |
190 | FROM profile_display | |
191 | WHERE pid = {?}", | |
f41cf525 | 192 | $page->pid()); |
dced83b4 SJ |
193 | list($public_name, $private_name) = $res->fetchOneRow(); |
194 | if ($success) { | |
dced83b4 SJ |
195 | $sn_types_private = build_types('private'); |
196 | $this->private_name_end = build_private_name($this->search_names, $sn_types_private); | |
197 | $private_name = $public_name . $this->private_name_end; | |
198 | } | |
199 | Platal::page()->assign('public_name', $public_name); | |
200 | Platal::page()->assign('private_name', $private_name); | |
fd38b30e | 201 | } |
09f9ebea | 202 | |
c4b45374 | 203 | return $value; |
fd38b30e FB |
204 | } |
205 | ||
c4b45374 | 206 | public function save(ProfilePage &$page, $field, $value) |
fd38b30e | 207 | { |
dced83b4 | 208 | require_once 'name.func.inc.php'; |
024ec1e5 SJ |
209 | require_once 'validations.inc.php'; |
210 | ||
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) { | |
024ec1e5 | 221 | $new_names = new NamesReq(S::user(), $this->profile, $this->search_names, $this->private_name_end); |
dced83b4 | 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 | 234 | class ProfileSettingEdu implements ProfileSetting |
576777d7 | 235 | { |
e5bcd851 FB |
236 | public function __construct() { |
237 | } | |
043bbacf | 238 | |
5ba8842e | 239 | static function sortByGradYear($line1, $line2) { |
be6806fa SJ |
240 | $a = (isset($line1['grad_year'])) ? (int) $line1['grad_year'] : 0; |
241 | $b = (isset($line2['grad_year'])) ? (int) $line2['grad_year'] : 0; | |
22f0a0a8 | 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; | |
885fa398 | 251 | if (is_null($value)) { |
043bbacf | 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()); | |
885fa398 SJ |
258 | } else if (!is_array($value)) { |
259 | $value = null; | |
043bbacf SJ |
260 | } else { |
261 | $i = 0; | |
262 | foreach ($value as $key=>&$edu) { | |
263 | if (($edu['grad_year'] < 1921) || ($edu['grad_year'] > (date('Y') + 4))) { | |
be6806fa | 264 | Platal::page()->trigWarning('L\'année d\'obtention du diplôme est mal ou non renseignée, elle doit être du type : 2004.'); |
83065276 | 265 | $edu['grad_year'] = null; |
be6806fa | 266 | $edu['warning'] = true; |
043bbacf SJ |
267 | } |
268 | if ($key != $i) { | |
269 | $value[$i] = $edu; | |
270 | unset($value[$key]); | |
271 | } | |
272 | $i++; | |
273 | } | |
12bcf04b | 274 | usort($value, array("ProfileSettingEdu", "sortByGradYear")); |
576777d7 FB |
275 | } |
276 | return $value; | |
277 | } | |
278 | ||
043bbacf | 279 | public function save(ProfilePage &$page, $field, $value) |
576777d7 | 280 | { |
043bbacf | 281 | XDB::execute("DELETE FROM profile_education |
ce0b2c6f | 282 | WHERE pid = {?} AND !FIND_IN_SET('primary', flags)", |
e5bcd851 | 283 | $page->pid()); |
043bbacf SJ |
284 | foreach ($value as $eduid=>&$edu) { |
285 | if ($edu['eduid'] != '') { | |
286 | XDB::execute("INSERT INTO profile_education | |
ce0b2c6f | 287 | SET id = {?}, pid = {?}, eduid = {?}, degreeid = {?}, |
1504ac45 | 288 | fieldid = {?}, grad_year = {?}, program = {?}", |
e5bcd851 | 289 | $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'], |
1504ac45 | 290 | $edu['fieldid'], $edu['grad_year'], $edu['program']); |
043bbacf | 291 | } |
576777d7 FB |
292 | } |
293 | } | |
294 | } | |
295 | ||
12bcf04b | 296 | class ProfileSettingEmailDirectory implements ProfileSetting |
b715c1e1 | 297 | { |
b814a8b8 SJ |
298 | public function __construct(){} |
299 | public function save(ProfilePage &$page, $field, $value){} | |
b715c1e1 SJ |
300 | |
301 | public function value(ProfilePage &$page, $field, $value, &$success) | |
302 | { | |
ad3fee9d | 303 | $p = Platal::page(); |
b715c1e1 SJ |
304 | |
305 | $success = true; | |
306 | if (!is_null($value)) { | |
307 | $email_stripped = strtolower(trim($value)); | |
ad3fee9d SJ |
308 | if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values['email_directory'] == "new@example.org")) { |
309 | $p->assign('email_error', '1'); | |
310 | $p->assign('email_directory_error', $email_stripped); | |
311 | $p->trigError('Adresse Email invalide'); | |
b715c1e1 SJ |
312 | $success = false; |
313 | } else { | |
ad3fee9d | 314 | $p->assign('email_error', '0'); |
b715c1e1 SJ |
315 | } |
316 | } | |
317 | return $value; | |
318 | } | |
b715c1e1 SJ |
319 | } |
320 | ||
12bcf04b | 321 | class ProfileSettingNetworking implements ProfileSetting |
d1a2252a GB |
322 | { |
323 | private $email; | |
324 | private $pub; | |
325 | private $web; | |
92446a53 | 326 | private $number; |
d1a2252a GB |
327 | |
328 | public function __construct() | |
329 | { | |
12bcf04b RB |
330 | $this->email = new ProfileSettingEmail(); |
331 | $this->pub = new ProfileSettingPub(); | |
332 | $this->web = new ProfileSettingWeb(); | |
333 | $this->number = new ProfileSettingNumber(); | |
d1a2252a GB |
334 | } |
335 | ||
336 | public function value(ProfilePage &$page, $field, $value, &$success) | |
337 | { | |
338 | if (is_null($value)) { | |
1f5cd004 | 339 | $value = XDB::fetchAllAssoc("SELECT n.address, n.pub, n.nwid AS type |
111b2736 | 340 | FROM profile_networking AS n |
ce0b2c6f | 341 | WHERE n.pid = {?}", |
111b2736 | 342 | $page->pid()); |
d1a2252a GB |
343 | } |
344 | if (!is_array($value)) { | |
345 | $value = array(); | |
346 | } | |
1f5cd004 | 347 | $filters = XDB::fetchAllAssoc('type', 'SELECT filter, nwid AS type, name |
111b2736 | 348 | FROM profile_networking_enum;'); |
d1a2252a GB |
349 | $success = true; |
350 | foreach($value as $i=>&$network) { | |
92c3f9e5 GB |
351 | if (!trim($network['address'])) { |
352 | unset($value[$i]); | |
353 | } else { | |
354 | if (!isset($network['pub'])) { | |
355 | $network['pub'] = 'private'; | |
356 | } | |
357 | $network['error'] = false; | |
358 | $network['pub'] = $this->pub->value($page, 'pub', $network['pub'], $s); | |
359 | $s = true; | |
1f5cd004 PC |
360 | $network['name'] = $filters[$network['type']]['name']; |
361 | if ($filters[$network['type']]['filter'] == 'web') { | |
92c3f9e5 | 362 | $network['address'] = $this->web->value($page, 'address', $network['address'], $s); |
1f5cd004 | 363 | } elseif ($filters[$network['type']]['filter'] == 'email') { |
92c3f9e5 | 364 | $network['address'] = $this->email->value($page, 'address', $network['address'], $s); |
1f5cd004 | 365 | } elseif ($filters[$network['type']]['filter'] == 'number') { |
92c3f9e5 GB |
366 | $network['address'] = $this->number->value($page, 'address', $network['address'], $s); |
367 | } | |
368 | if (!$s) { | |
369 | $success = false; | |
370 | $network['error'] = true; | |
371 | } | |
d1a2252a GB |
372 | } |
373 | } | |
374 | return $value; | |
375 | } | |
376 | ||
377 | public function save(ProfilePage &$page, $field, $value) | |
378 | { | |
379 | XDB::execute("DELETE FROM profile_networking | |
ce0b2c6f | 380 | WHERE pid = {?}", |
e5bcd851 | 381 | $page->pid()); |
d1a2252a GB |
382 | if (!count($value)) { |
383 | return; | |
384 | } | |
385 | $insert = array(); | |
386 | foreach ($value as $id=>$network) { | |
1f5cd004 | 387 | XDB::execute("INSERT INTO profile_networking (pid, id, nwid, address, pub) |
d1a2252a | 388 | VALUES ({?}, {?}, {?}, {?}, {?})", |
e5bcd851 | 389 | $page->pid(), $id, $network['type'], $network['address'], $network['pub']); |
d1a2252a GB |
390 | } |
391 | } | |
392 | } | |
393 | ||
7e233317 SJ |
394 | class ProfileSettingPromo implements ProfileSetting |
395 | { | |
396 | public function __construct(){} | |
397 | ||
398 | public function save(ProfilePage &$page, $field, $value) | |
399 | { | |
400 | $gradYearNew = $value; | |
401 | if ($page->profile->mainEducation() == 'X') { | |
402 | $gradYearNew += $page->profile->mainEducationDuration(); | |
403 | } | |
86ced4d4 SJ |
404 | if (($page->profile->mainEducation() != 'X' |
405 | && $value == $page->profile->entry_year + $page->profile->mainEducationDuration()) | |
406 | || ($page->profile->mainEducation() == 'X' && $value == $page->profile->entry_year)) { | |
7e233317 SJ |
407 | XDB::execute('UPDATE profile_display |
408 | SET promo = {?} | |
409 | WHERE pid = {?}', | |
410 | $page->profile->mainEducation() . strval($value), $page->profile->id()); | |
411 | XDB::execute('UPDATE profile_education | |
412 | SET grad_year = {?} | |
413 | WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)', | |
414 | $gradYearNew, $page->profile->id()); | |
86ced4d4 | 415 | Platal::page()->trigSuccess('Ton statut « orange » a été supprimé.'); |
7e233317 SJ |
416 | } else { |
417 | require_once 'validations.inc.php'; | |
418 | ||
024ec1e5 | 419 | $myorange = new OrangeReq(S::user(), $this->profile, $gradYearNew); |
7e233317 SJ |
420 | $myorange->submit(); |
421 | Platal::page()->trigSuccess('Tu pourras changer l\'affichage de ta promotion dès que ta nouvelle promotion aura été validée.'); | |
422 | } | |
423 | } | |
424 | ||
425 | public function value(ProfilePage &$page, $field, $value, &$success) | |
426 | { | |
427 | $entryYear = $page->profile->entry_year; | |
428 | $gradYear = $page->profile->grad_year; | |
86ced4d4 SJ |
429 | $yearpromo = $page->profile->grad_year; |
430 | if ($page->profile->mainEducation() == 'X') { | |
431 | $yearpromo -= $page->profile->mainEducationDuration(); | |
432 | } | |
7e233317 | 433 | $success = true; |
86ced4d4 | 434 | if (is_null($value) || $value == $yearpromo) { |
7e233317 SJ |
435 | if ($gradYear != $entryYear + $page->profile->mainEducationDuration()) { |
436 | $promoChoice = array(); | |
86ced4d4 SJ |
437 | for ($i = $entryYear; $i <= $gradYear - $page->profile->mainEducationDuration(); ++$i) { |
438 | if ($page->profile->mainEducation() == 'X') { | |
439 | $promoChoice[] = $page->profile->mainEducation() . strval($i); | |
440 | } else { | |
441 | $promoChoice[] = $page->profile->mainEducation() . strval($i + $page->profile->mainEducationDuration()); | |
442 | } | |
7e233317 SJ |
443 | } |
444 | Platal::page()->assign('promo_choice', $promoChoice); | |
445 | } | |
86ced4d4 | 446 | return $yearpromo; |
7e233317 SJ |
447 | } |
448 | ||
449 | // If this profile belongs to an X, $promoNew needs to be changed to | |
450 | // the graduation year. | |
451 | $gradYearNew = $value; | |
452 | if ($page->profile->mainEducation() == 'X') { | |
453 | $gradYearNew += $page->profile->mainEducationDuration(); | |
454 | } | |
455 | ||
456 | if ($value < 1000 || $value > 9999) { | |
457 | Platal::page()->trigError('L\'année de sortie doit être un nombre de quatre chiffres.'); | |
458 | $success = false; | |
459 | } elseif ($gradYearNew < $entryYear + $page->profile->mainEducationDuration()) { | |
460 | Platal::page()->trigError('Trop tôt !'); | |
461 | $success = false; | |
462 | } | |
463 | return intval($value); | |
464 | } | |
465 | } | |
466 | ||
467 | ||
12bcf04b | 468 | class ProfileSettingGeneral extends ProfilePage |
fd38b30e FB |
469 | { |
470 | protected $pg_template = 'profile/general.tpl'; | |
471 | ||
472 | public function __construct(PlWizard &$wiz) | |
473 | { | |
474 | parent::__construct($wiz); | |
c4b45374 | 475 | $this->settings['search_names'] |
12bcf04b RB |
476 | = new ProfileSettingSearchNames(); |
477 | $this->settings['birthdate'] = new ProfileSettingDate(); | |
bde2be3b | 478 | $this->settings['freetext_pub'] |
576777d7 | 479 | = $this->settings['photo_pub'] |
12bcf04b | 480 | = new ProfileSettingPub(); |
93553cea | 481 | $this->settings['freetext'] |
e5bcd851 FB |
482 | = $this->settings['nationality1'] |
483 | = $this->settings['nationality2'] | |
484 | = $this->settings['nationality3'] | |
b04882ff | 485 | = $this->settings['yourself'] |
7e233317 | 486 | = $this->settings['promo_display'] |
93553cea | 487 | = null; |
b715c1e1 | 488 | $this->settings['email_directory'] |
12bcf04b | 489 | = new ProfileSettingEmail(); |
b715c1e1 | 490 | $this->settings['email_directory_new'] |
12bcf04b RB |
491 | = new ProfileSettingEmailDirectory(); |
492 | $this->settings['networking'] = new ProfileSettingNetworking(); | |
493 | $this->settings['tels'] = new ProfileSettingPhones('user', 0); | |
494 | $this->settings['edus'] = new ProfileSettingEdu(); | |
7e233317 | 495 | $this->settings['promo'] = new ProfileSettingPromo(); |
6e32823c | 496 | $this->watched= array('freetext' => true, 'tels' => true, |
043bbacf | 497 | 'networking' => true, 'edus' => true, |
e5bcd851 | 498 | 'nationality1' => true, 'nationality2' => true, |
4ca15c31 | 499 | 'nationality3' => true, 'search_names' => true); |
93553cea FB |
500 | } |
501 | ||
7c2e0f0d | 502 | protected function _fetchData() |
93553cea | 503 | { |
576777d7 | 504 | // Checkout all data... |
7e233317 SJ |
505 | $res = XDB::query("SELECT p.nationality1, p.nationality2, p.nationality3, p.birthdate, |
506 | pp.display_tel as mobile, pp.pub as mobile_pub, | |
507 | p.email_directory as email_directory, pd.promo AS promo_display, | |
508 | p.freetext, p.freetext_pub, p.ax_id AS matricule_ax, pd.yourself | |
509 | FROM profiles AS p | |
510 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
511 | LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND link_type = 'user') | |
512 | WHERE p.pid = {?}", $this->pid()); | |
93553cea | 513 | $this->values = $res->fetchOneAssoc(); |
4ca15c31 FB |
514 | if ($this->owner) { |
515 | $this->values['yourself'] = $this->owner->displayName(); | |
516 | } | |
576777d7 | 517 | |
576777d7 FB |
518 | // Retreive photo informations |
519 | $res = XDB::query("SELECT pub | |
5c4ea53f FB |
520 | FROM profile_photos |
521 | WHERE pid = {?}", $this->pid()); | |
576777d7 FB |
522 | $this->values['photo_pub'] = $res->fetchOneCell(); |
523 | ||
e5bcd851 FB |
524 | if ($this->owner) { |
525 | $res = XDB::query("SELECT COUNT(*) | |
526 | FROM requests | |
58bb2d9c | 527 | WHERE type = 'photo' AND pid = {?}", |
e5bcd851 FB |
528 | $this->owner->id()); |
529 | $this->values['nouvellephoto'] = $res->fetchOneCell(); | |
530 | } else { | |
531 | $this->values['nouvellephoto'] = 0; | |
532 | } | |
93553cea FB |
533 | } |
534 | ||
7c2e0f0d | 535 | protected function _saveData() |
93553cea | 536 | { |
e5bcd851 | 537 | if ($this->changed['nationality1'] || $this->changed['nationality2'] || $this->changed['nationality3'] |
ce0b2c6f FB |
538 | || $this->changed['birthdate'] || $this->changed['freetext'] || $this->changed['freetext_pub'] |
539 | || $this->changed['email_directory']) { | |
e5bcd851 FB |
540 | if ($this->values['nationality3'] == "") { |
541 | $this->values['nationality3'] = NULL; | |
8450c2aa | 542 | } |
e5bcd851 FB |
543 | if ($this->values['nationality2'] == "") { |
544 | $this->values['nationality2'] = $this->values['nationality3']; | |
545 | $this->values['nationality3'] = NULL; | |
8450c2aa | 546 | } |
e5bcd851 | 547 | if ($this->values['nationality1'] == "") { |
48a4525c | 548 | $this->values['nationality1'] = $this->values['nationality2']; |
e5bcd851 FB |
549 | $this->values['nationality2'] = $this->values['nationality3']; |
550 | $this->values['nationality3'] = NULL; | |
8450c2aa | 551 | } |
48a4525c SJ |
552 | if ($this->values['nationality1'] == $this->values['nationality2'] |
553 | && $this->values['nationality2'] == $this->values['nationality3']) { | |
554 | $this->values['nationality2'] = NULL; | |
555 | $this->values['nationality3'] = NULL; | |
556 | } else if ($this->values['nationality1'] == $this->values['nationality2']) { | |
557 | $this->values['nationality2'] = $this->values['nationality3']; | |
558 | $this->values['nationality3'] = NULL; | |
559 | } else if ($this->values['nationality2'] == $this->values['nationality3'] | |
560 | || $this->values['nationality1'] == $this->values['nationality3']) { | |
561 | $this->values['nationality3'] = NULL; | |
562 | } | |
563 | ||
ce0b2c6f FB |
564 | $new_email = ($this->values['email_directory'] == "new@example.org") ? |
565 | $this->values['email_directory_new'] : $this->values['email_directory']; | |
566 | if ($new_email == "") { | |
567 | $new_email = NULL; | |
568 | } | |
8450c2aa | 569 | |
e5bcd851 FB |
570 | XDB::execute("UPDATE profiles |
571 | SET nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?}, | |
ce0b2c6f | 572 | freetext = {?}, freetext_pub = {?}, email_directory = {?} |
d1e61677 | 573 | WHERE pid = {?}", |
e5bcd851 FB |
574 | $this->values['nationality1'], $this->values['nationality2'], $this->values['nationality3'], |
575 | preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values['birthdate']), | |
ce0b2c6f | 576 | $this->values['freetext'], $this->values['freetext_pub'], $new_email, $this->pid()); |
b715c1e1 | 577 | } |
a7c28fff | 578 | if ($this->changed['photo_pub']) { |
5c4ea53f | 579 | XDB::execute("UPDATE profile_photos |
a7c28fff | 580 | SET pub = {?} |
5c4ea53f | 581 | WHERE pid = {?}", |
e5bcd851 | 582 | $this->values['photo_pub'], $this->pid()); |
a7c28fff | 583 | } |
c4b45374 | 584 | if ($this->changed['yourself']) { |
cb0af6e5 FB |
585 | if ($this->owner) { |
586 | XDB::execute('UPDATE accounts | |
587 | SET display_name = {?} | |
588 | WHERE uid = {?}', | |
589 | $this->values['yourself'], $this->owner->id()); | |
590 | } | |
591 | XDB::execute('UPDATE profile_display | |
592 | SET yourself = {?} | |
593 | WHERE pid = {?}', $this->values['yourself'], | |
594 | $this->pid()); | |
fb2c09c9 | 595 | } |
7e233317 | 596 | if ($this->changed['promo_display']) { |
86ced4d4 SJ |
597 | if ($this->values['promo_display']{0} == $this->profile->mainEducation()) { |
598 | if (($this->profile->mainEducation() == 'X' | |
599 | && intval(substr($this->values['promo_display'], 1, 4)) >= $this->profile->entry_year) | |
600 | || ($this->profile->mainEducation() != 'X' | |
601 | && intval(substr($this->values['promo_display'], 1, 4)) >= $this->profile->entry_year + $this->profile->mainEducationDuration())) { | |
602 | XDB::execute('UPDATE profile_display | |
603 | SET promo = {?} | |
604 | WHERE pid = {?}', | |
605 | $this->values['promo_display'], $this->pid()); | |
606 | } | |
7e233317 | 607 | } |
b04882ff | 608 | } |
fd38b30e FB |
609 | } |
610 | ||
04334c61 | 611 | public function _prepare(PlPage &$page, $id) |
fd38b30e | 612 | { |
f711b03f | 613 | require_once "education.func.inc.php"; |
d1a2252a | 614 | |
111b2736 FB |
615 | $res = XDB::query("SELECT id, field |
616 | FROM profile_education_field_enum | |
617 | ORDER BY field"); | |
043bbacf SJ |
618 | $page->assign('edu_fields', $res->fetchAllAssoc()); |
619 | ||
b715c1e1 | 620 | require_once "emails.combobox.inc.php"; |
e5bcd851 | 621 | fill_email_combobox($page, $this->owner, $this->profile); |
b715c1e1 | 622 | |
1f5cd004 | 623 | $res = XDB::query("SELECT nw.nwid AS type, nw.name |
111b2736 FB |
624 | FROM profile_networking_enum AS nw |
625 | ORDER BY name"); | |
d1a2252a | 626 | $page->assign('network_list', $res->fetchAllAssoc()); |
c4b45374 SJ |
627 | |
628 | $res = XDB::query("SELECT public_name, private_name | |
629 | FROM profile_display | |
630 | WHERE pid = {?}", | |
111b2736 | 631 | $this->pid()); |
c4b45374 SJ |
632 | $res = $res->fetchOneRow(); |
633 | $page->assign('public_name', $res[0]); | |
634 | $page->assign('private_name', $res[1]); | |
e8a7cf31 | 635 | $page->assign('isFemale', $this->profile->isFemale() ? 1 : 0); |
fd38b30e FB |
636 | } |
637 | } | |
638 | ||
639 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
640 | ?> |