Merge commit 'origin/fusionax' into account
[platal.git] / modules / profile.php
CommitLineData
7d8b17cb 1<?php
2/***************************************************************************
8d84c630 3 * Copyright (C) 2003-2009 Polytechnique.org *
7d8b17cb 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
22class ProfileModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
2398e553
SJ
27 'photo' => $this->make_hook('photo', AUTH_PUBLIC),
28 'photo/change' => $this->make_hook('photo_change', AUTH_MDP),
e49018a7 29
2398e553
SJ
30 'fiche.php' => $this->make_hook('fiche', AUTH_PUBLIC),
31 'profile' => $this->make_hook('profile', AUTH_PUBLIC),
32 'profile/private' => $this->make_hook('profile', AUTH_COOKIE),
33 'profile/ax' => $this->make_hook('ax', AUTH_COOKIE, 'admin'),
34 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP),
35 'profile/ajax/address' => $this->make_hook('ajax_address', AUTH_COOKIE, 'user', NO_AUTH),
36 'profile/ajax/tel' => $this->make_hook('ajax_tel', AUTH_COOKIE, 'user', NO_AUTH),
37 'profile/ajax/edu' => $this->make_hook('ajax_edu', AUTH_COOKIE, 'user', NO_AUTH),
38 'profile/ajax/medal' => $this->make_hook('ajax_medal', AUTH_COOKIE, 'user', NO_AUTH),
39 'profile/networking' => $this->make_hook('networking', AUTH_PUBLIC),
40 'profile/ajax/job' => $this->make_hook('ajax_job', AUTH_COOKIE, 'user', NO_AUTH),
41 'profile/ajax/secteur' => $this->make_hook('ajax_secteur', AUTH_COOKIE, 'user', NO_AUTH),
c7139c07 42 'profile/ajax/ssecteur' => $this->make_hook('ajax_ssecteur', AUTH_COOKIE, 'user', NO_AUTH),
2398e553
SJ
43 'profile/ajax/skill' => $this->make_hook('ajax_skill', AUTH_COOKIE, 'user', NO_AUTH),
44 'profile/ajax/searchname' => $this->make_hook('ajax_searchname', AUTH_COOKIE, 'user', NO_AUTH),
6e32823c 45 'profile/ajax/buildnames' => $this->make_hook('ajax_buildnames', AUTH_COOKIE, 'user', NO_AUTH),
f711b03f 46 'javascript/education.js' => $this->make_hook('education_js', AUTH_COOKIE),
2398e553
SJ
47 'javascript/grades.js' => $this->make_hook('grades_js', AUTH_COOKIE),
48 'profile/medal' => $this->make_hook('medal', AUTH_PUBLIC),
70c65f3a 49 'profile/name_info' => $this->make_hook('name_info', AUTH_PUBLIC),
2398e553 50 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP),
e49018a7 51
2398e553
SJ
52 'referent' => $this->make_hook('referent', AUTH_COOKIE),
53 'emploi' => $this->make_hook('ref_search', AUTH_COOKIE),
54 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE),
55 'referent/ssect' => $this->make_hook('ref_sect', AUTH_COOKIE, 'user', NO_AUTH),
56 'referent/country' => $this->make_hook('ref_country', AUTH_COOKIE, 'user', NO_AUTH),
2f678da1 57
2398e553 58 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE),
926f16d7 59
2398e553
SJ
60 'vcard' => $this->make_hook('vcard', AUTH_COOKIE, 'user', NO_HTTPS),
61 'admin/binets' => $this->make_hook('admin_binets', AUTH_MDP, 'admin'),
62 'admin/medals' => $this->make_hook('admin_medals', AUTH_MDP, 'admin'),
63 'admin/education' => $this->make_hook('admin_education', AUTH_MDP, 'admin'),
64 'admin/education_field' => $this->make_hook('admin_education_field', AUTH_MDP, 'admin'),
65 'admin/education_degree' => $this->make_hook('admin_education_degree', AUTH_MDP, 'admin'),
043bbacf 66 'admin/education_degree_set' => $this->make_hook('admin_education_degree_set', AUTH_MDP, 'admin'),
2398e553
SJ
67 'admin/sections' => $this->make_hook('admin_sections', AUTH_MDP, 'admin'),
68 'admin/secteurs' => $this->make_hook('admin_secteurs', AUTH_MDP, 'admin'),
69 'admin/networking' => $this->make_hook('admin_networking', AUTH_MDP, 'admin'),
70 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP, 'admin'),
71 'admin/ss_secteurs' => $this->make_hook('admin_ss_secteurs', AUTH_MDP, 'admin'),
72 'admin/fonctions' => $this->make_hook('admin_fonctions', AUTH_MDP, 'admin'),
4962a9ce
SJ
73 'admin/corps_enum' => $this->make_hook('admin_corps_enum', AUTH_MDP, 'admin'),
74 'admin/corps_rank' => $this->make_hook('admin_corps_rank', AUTH_MDP, 'admin'),
b62db02e 75 'admin/names' => $this->make_hook('admin_names', AUTH_MDP, 'admin'),
92423144 76
7d8b17cb 77 );
78 }
79
e8599c21 80 /* XXX COMPAT */
81 function handler_fiche(&$page)
82 {
5e2307dc 83 return $this->handler_profile($page, Env::v('user'));
e8599c21 84 }
85
adbdf493 86 function handler_photo(&$page, $x = null, $req = null)
87 {
954cfb01 88 if (!$x || !($user = User::getSilent($x))) {
adbdf493 89 return PL_NOT_FOUND;
90 }
91
954cfb01
VZ
92 // Retrieve the photo and its mime type.
93 $photo_data = null;
94 $photo_type = null;
adbdf493 95
cab08090 96 if ($req && S::logged()) {
adbdf493 97 include 'validations.inc.php';
954cfb01
VZ
98 $myphoto = PhotoReq::get_request($user->id());
99 if ($myphoto) {
100 $photo_data = $myphoto->data;
101 $photo_type = $myphoto->mimetype;
102 }
adbdf493 103 } else {
08cce2ff 104 $res = XDB::query(
954cfb01 105 "SELECT attachmime, attach, pub
adbdf493 106 FROM photo
954cfb01
VZ
107 WHERE uid = {?}", $user->id());
108 list($photo_type, $photo_data, $photo_pub) = $res->fetchOneRow();
109 if ($photo_pub != 'public' && !S::logged()) {
110 $photo_type = $photo_data = null;
adbdf493 111 }
112 }
954cfb01
VZ
113
114 // Display the photo, or a default one when not available.
115 if ($photo_type && $photo_data != null) {
116 header('Content-type: image/' . $photo_type);
117 echo $photo_data;
118 } else {
119 header('Content-type: image/png');
120 echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png');
121 }
adbdf493 122 exit;
123 }
124
85cc366b
FB
125 function handler_medal(&$page, $mid)
126 {
bd6a5fe3
VZ
127 $thumb = ($mid == 'thumb');
128 $mid = $thumb ? @func_get_arg(2) : $mid;
129
85cc366b
FB
130 $res = XDB::query("SELECT img
131 FROM profile_medals
132 WHERE id = {?}",
133 $mid);
bd6a5fe3
VZ
134 $img = $thumb ?
135 dirname(__FILE__).'/../htdocs/images/medals/thumb/' . $res->fetchOneCell() :
136 dirname(__FILE__).'/../htdocs/images/medals/' . $res->fetchOneCell();
85cc366b
FB
137 $type = mime_content_type($img);
138 header("Content-Type: $type");
139 echo file_get_contents($img);
140 exit;
141 }
142
70c65f3a
SJ
143 function handler_name_info(&$page)
144 {
145 header('Content-Type: text/html; charset=utf-8');
146 $page->changeTpl('profile/name_info.tpl', SIMPLE);
147 $res = XDB::iterator("SELECT name, explanations,
148 FIND_IN_SET('public', flags) AS public,
149 FIND_IN_SET('has_particle', flags) AS has_particle
97a98687 150 FROM profile_name_enum
70c65f3a
SJ
151 WHERE NOT FIND_IN_SET('not_displayed', flags)
152 ORDER BY NOT FIND_IN_SET('public', flags)");
153 $page->assign('types', $res);
154 }
155
40176c6c
GB
156 function handler_networking(&$page, $mid)
157 {
158 $res = XDB::query("SELECT icon
159 FROM profile_networking_enum
160 WHERE network_type = {?}",
161 $mid);
162 $img = dirname(__FILE__) . '/../htdocs/images/networking/' . $res->fetchOneCell();
163 $type = mime_content_type($img);
164 header("Content-Type: $type");
165 echo file_get_contents($img);
166 exit;
167 }
168
fb9a56cb 169 function handler_photo_change(&$page)
170 {
ebfdf077 171 global $globals;
8b1f8e12 172 $page->changeTpl('profile/trombino.tpl');
fb9a56cb 173
174 require_once('validations.inc.php');
175
54cabe90 176 $trombi_x = '/home/web/trombino/photos' . S::v('promo') . '/' . S::user()->login() . '.jpg';
fb9a56cb 177 if (Env::has('upload')) {
8827fc52
VZ
178 S::assert_xsrf_token();
179
954cfb01 180 $upload = new PlUpload(S::user()->login(), 'photo');
abe7e055 181 if (!$upload->upload($_FILES['userfile']) && !$upload->download(Env::v('photo'))) {
a7d35093 182 $page->trigError('Une erreur est survenue lors du téléchargement du fichier');
abe7e055 183 } else {
5daf68f6 184 $myphoto = new PhotoReq(S::user(), $upload);
abe7e055 185 if ($myphoto->isValid()) {
186 $myphoto->submit();
fb9a56cb 187 }
fb9a56cb 188 }
189 } elseif (Env::has('trombi')) {
8827fc52
VZ
190 S::assert_xsrf_token();
191
954cfb01 192 $upload = new PlUpload(S::user()->login(), 'photo');
abe7e055 193 if ($upload->copyFrom($trombi_x)) {
5daf68f6 194 $myphoto = new PhotoReq(S::user(), $upload);
abe7e055 195 if ($myphoto->isValid()) {
196 $myphoto->commit();
197 $myphoto->clean();
198 }
fb9a56cb 199 }
5e2307dc 200 } elseif (Env::v('suppr')) {
8827fc52
VZ
201 S::assert_xsrf_token();
202
84868ee9
FB
203 XDB::execute('DELETE FROM photo
204 WHERE uid = {?}',
205 S::v('uid'));
206 XDB::execute('DELETE FROM requests
207 WHERE user_id = {?} AND type="photo"',
208 S::v('uid'));
ebfdf077 209 $globals->updateNbValid();
5e2307dc 210 } elseif (Env::v('cancel')) {
8827fc52
VZ
211 S::assert_xsrf_token();
212
84868ee9
FB
213 $sql = XDB::query('DELETE FROM requests
214 WHERE user_id={?} AND type="photo"',
215 S::v('uid'));
ebfdf077 216 $globals->updateNbValid();
fb9a56cb 217 }
218
84868ee9
FB
219 $sql = XDB::query('SELECT COUNT(*)
220 FROM requests
221 WHERE user_id={?} AND type="photo"',
abe7e055 222 S::v('uid'));
fb9a56cb 223 $page->assign('submited', $sql->fetchOneCell());
224 $page->assign('has_trombi_x', file_exists($trombi_x));
fb9a56cb 225 }
226
e8599c21 227 function handler_profile(&$page, $x = null)
228 {
54cabe90
VZ
229 // TODO/note for upcoming developers:
230 // We currently maintain both $user and $login; $user is the old way of
231 // obtaining information, and eventually everything will be loaded
232 // through $login. That is the reason why in the template $user is named
233 // $x, and $login $user (sorry for the confusion).
234
235 // Determines which user to display the profile of, and retrieves basic
236 // information on this user.
e8599c21 237 if (is_null($x)) {
238 return PL_NOT_FOUND;
239 }
240
efe597c5 241 $login = (!is_numeric($x) || S::has_perms()) ? Profile::get($x) : null;
344234db 242 if (!$login) {
efe597c5
FB
243 if (S::logged()) {
244 $page->trigError($x . ' inconnu dans l\'annuaire');
245 }
344234db 246 return PL_NOT_FOUND;
e8599c21 247 }
e8599c21 248
54cabe90
VZ
249 // Now that we know this is the profile of an existing user, we can
250 // switch to the appropriate template.
b13048df 251 $page->changeTpl('profile/profile.tpl', SIMPLE);
54cabe90 252 require_once 'user.func.inc.php';
e8599c21 253
54cabe90
VZ
254 // Determines the access level at which the profile will be displayed.
255 if (!S::logged() || Env::v('view') == 'public') {
256 $view = 'public';
257 } else if (S::logged() && Env::v('view') == 'ax') {
258 $view = 'ax';
e8599c21 259 } else {
54cabe90 260 $view = 'private';
e8599c21 261 }
262
54cabe90
VZ
263 // Determines is the user is registered, and fetches the user infos in
264 // the appropriate way.
344234db
VZ
265 $res = XDB::query("SELECT perms IN ('admin','user','disabled')
266 FROM auth_user_md5
267 WHERE user_id = {?}", $login->id());
54cabe90
VZ
268 if ($res->fetchOneCell()) {
269 $new = Env::v('modif') == 'new';
efe597c5 270 $user = get_user_details($login->hrid(), S::v('uid'), $view);
54cabe90
VZ
271 } else {
272 $new = false;
273 $user = array();
ba25f663 274 if (S::logged()) {
efe597c5 275 pl_redirect('marketing/public/' . $login->hrid());
ba25f663 276 }
e8599c21 277 }
ba25f663 278
54cabe90 279 // Profile view are logged.
e31c1c3e 280 if (S::logged()) {
efe597c5 281 S::logger()->log('view_profile', $login->hrid());
e8599c21 282 }
283
54cabe90
VZ
284 // Sets the title of the html page.
285 $page->setTitle($login->fullName());
e8599c21 286
54cabe90 287 // Prepares the display of the user's mugshot.
efe597c5 288 $photo = 'photo/' . $login->hrid() . ($new ? '/req' : '');
54cabe90
VZ
289 if (!isset($user['photo_pub']) || !has_user_right($user['photo_pub'], $view)) {
290 $photo = "";
291 }
292 $page->assign('photo_url', $photo);
e8599c21 293
2f678da1 294 if (!isset($user['y']) and !isset($user['x'])) {
e8599c21 295 list($user['x'], $user['y']) = getimagesize("images/none.png");
296 }
2f678da1 297 if (!isset($user['y']) or $user['y'] < 1) $user['y']=1;
298 if (!isset($user['x']) or $user['x'] < 1) $user['x']=1;
299 if ($user['x'] > 240) {
e8599c21 300 $user['y'] = (integer)($user['y']*240/$user['x']);
301 $user['x'] = 240;
302 }
2f678da1 303 if ($user['y'] > 300) {
e8599c21 304 $user['x'] = (integer)($user['x']*300/$user['y']);
305 $user['y'] = 300;
306 }
2f678da1 307 if ($user['x'] < 160) {
e8599c21 308 $user['y'] = (integer)($user['y']*160/$user['x']);
309 $user['x'] = 160;
310 }
311
54cabe90
VZ
312 // Determines and displays the virtual alias.
313 global $globals;
efe597c5
FB
314 $owner = $login->owner();
315 if ($owner) {
316 $page->assign('virtualalias', $owner->emailAlias());
317 }
54cabe90
VZ
318
319 // Adds miscellaneous properties to the display.
320 // Adds the global user property array to the display.
321 $page->assign_by_ref('x', $user);
efe597c5 322 $page->assign_by_ref('user', $owner);
54cabe90 323 $page->assign('logged', has_user_right('private', $view));
24f4c06a 324 $page->assign('view', $view);
e8599c21 325
c99ef281 326 $page->addJsLink('close_on_esc.js');
54cabe90
VZ
327 if (isset($user['date'])) {
328 header('Last-Modified: ' . date('r', strtotime($user['date'])));
329 }
e8599c21 330 }
331
5122b820 332 function handler_ax(&$page, $user = null)
333 {
34ca2048 334 $user = User::get($user);
5122b820 335 if (!$user) {
336 return PL_NOT_FOUND;
337 }
34ca2048
VZ
338
339 $res = XDB::query("SELECT matricule_ax
340 FROM auth_user_md5
341 WHERE user_id = {?}", $user->id());
5122b820 342 $mat = $res->fetchOneCell();
343 if (!intval($mat)) {
34ca2048 344 $page->kill("Le matricule AX de {$user->login()} est inconnu");
5122b820 345 }
346 http_redirect("http://www.polytechniciens.com/?page=AX_FICHE_ANCIEN&anc_id=$mat");
347 }
348
3af21f99 349 function handler_p_edit(&$page, $user = null, $opened_tab = null, $mode = null)
2f678da1 350 {
351 global $globals;
352
3af21f99
FB
353 if (is_null($user)) {
354 $user = S::user();
355 if (!$user->hasProfile()) {
356 return PL_NOT_FOUND;
357 } else {
358 pl_redirect('profile/edit/' . $user->profile()->hrid());
359 }
360 } else {
361 $user = Profile::get($user);
362 if (!$user) {
363 return PL_NOT_FOUND;
364 } else if (!S::user()->canEdit($user) && Platal::notAllowed()) {
365 return PL_FORBIDDEN;
366 }
367 }
368
e1635d16
FB
369 // AX Synchronization
370 require_once 'synchro_ax.inc.php';
2f678da1 371 if (is_ax_key_missing()) {
372 $page->assign('no_private_key', true);
373 }
5e2307dc 374 if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) {
b3bf7395 375 ax_synchronize(S::user()->login(), S::v('uid'));
a7d35093 376 $page->trigSuccess('Ton profil a été synchronisé avec celui du site polytechniciens.com');
2f678da1 377 }
378
7bff4cb0 379 // Build the page
c6a7beb2 380 $page->addJsLink('ajax.js');
f711b03f 381 $page->addJsLink('education.js');
46ae38a9 382 $page->addJsLink('grades.js');
16594a1a 383 $page->addJsLink('profile.js');
4b4b4b67 384 $page->addJsLink('jquery.autocomplete.js');
e5bcd851
FB
385 $wiz = new PlWizard('Profil', PlPage::getCoreTpl('plwizard.tpl'), true, true, false);
386 $wiz->addUserData('profile', $user);
387 $wiz->addUserData('owner', $user->owner());
460d8f55 388 $this->load('page.inc.php');
e1635d16 389 $wiz->addPage('ProfileGeneral', 'Général', 'general');
0b14f91d 390 $wiz->addPage('ProfileAddresses', 'Adresses personnelles', 'adresses');
e1635d16 391 $wiz->addPage('ProfileGroups', 'Groupes X - Binets', 'poly');
a7c28fff 392 $wiz->addPage('ProfileDecos', 'Décorations - Medailles', 'deco');
3950bc21 393 $wiz->addPage('ProfileJobs', 'Informations professionnelles', 'emploi');
e1635d16
FB
394 $wiz->addPage('ProfileSkills', 'Compétences diverses', 'skill');
395 $wiz->addPage('ProfileMentor', 'Mentoring', 'mentor');
3af21f99 396 $wiz->apply($page, 'profile/edit/' . $user->hrid(), $opened_tab, $mode);
35aedff2 397
7bff4cb0
FB
398 // Misc checks
399 $res = XDB::query("SELECT user_id
400 FROM auth_user_md5
401 WHERE user_id = {?} AND naissance = '0000-00-00'", S::i('uid'));
402 if ($res->numRows()) {
a7d35093 403 $page->trigWarning("Ta date de naissance n'est pas renseignée, ce qui t'empêcheras de réaliser"
6e32823c 404 . " la procédure de récupération de mot de passe si un jour tu le perdais.");
7bff4cb0
FB
405 }
406
46f272fe 407 $page->setTitle('Mon Profil');
2f678da1 408 }
409
f711b03f 410 function handler_education_js(&$page)
46ae38a9
FB
411 {
412 header('Content-Type: text/javascript; charset=utf-8');
413 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
414 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
415 header('Cache-Control: no-cache, must-revalidate');
416 header('Pragma: no-cache');
f711b03f
SJ
417 $page->changeTpl('profile/education.js.tpl', NO_SKIN);
418 require_once "education.func.inc.php";
46ae38a9
FB
419 }
420
421 function handler_grades_js(&$page)
422 {
423 header('Content-Type: text/javascript; charset=utf-8');
424 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
425 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
426 header('Cache-Control: no-cache, must-revalidate');
427 header('Pragma: no-cache');
428 $page->changeTpl('profile/grades.js.tpl', NO_SKIN);
429 $res = XDB::iterator("SELECT *
430 FROM profile_medals_grades
431 ORDER BY mid, pos");
432 $grades = array();
433 while ($tmp = $res->next()) {
434 $grades[$tmp['mid']][] = $tmp;
435 }
436 $page->assign('grades', $grades);
437
438 $res = XDB::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate
439 FROM profile_medals
440 ORDER BY type, text");
441 $mlist = array();
442 while ($tmp = $res->next()) {
443 $mlist[$tmp['type']][] = $tmp;
444 }
445 $page->assign('medal_list', $mlist);
446 }
447
c6a7beb2
FB
448 function handler_ajax_address(&$page, $adid)
449 {
46ae38a9 450 header('Content-Type: text/html; charset=utf-8');
c6a7beb2
FB
451 $page->changeTpl('profile/adresses.address.tpl', NO_SKIN);
452 $page->assign('i', $adid);
453 $page->assign('adr', array());
c6a7beb2
FB
454 }
455
bde2be3b 456 function handler_ajax_tel(&$page, $prefid, $prefname, $telid)
c6a7beb2 457 {
46ae38a9 458 header('Content-Type: text/html; charset=utf-8');
bde2be3b
GB
459 $page->changeTpl('profile/phone.tpl', NO_SKIN);
460 $page->assign('prefid', $prefid);
461 $page->assign('prefname', $prefname);
462 $page->assign('telid', $telid);
c6a7beb2 463 $page->assign('tel', array());
c6a7beb2
FB
464 }
465
58acfe8b 466 function handler_ajax_edu(&$page, $eduid, $class)
043bbacf
SJ
467 {
468 header('Content-Type: text/html; charset=utf-8');
2700a4f5 469 $page->changeTpl('profile/general.edu.tpl', NO_SKIN);
043bbacf
SJ
470 $res = XDB::iterator("SELECT id, field
471 FROM profile_education_field_enum
472 ORDER BY field");
473 $page->assign('edu_fields', $res->fetchAllAssoc());
474 $page->assign('eduid', $eduid);
58acfe8b 475 $page->assign('class', $class);
f711b03f 476 require_once "education.func.inc.php";
043bbacf
SJ
477 }
478
85cc366b
FB
479 function handler_ajax_medal(&$page, $id)
480 {
46ae38a9 481 header('Content-Type: text/html; charset=utf-8');
85cc366b
FB
482 $page->changeTpl('profile/deco.medal.tpl', NO_SKIN);
483 $page->assign('id', $id);
484 $page->assign('medal', array('valid' => 0, 'grade' => 0));
85cc366b
FB
485 }
486
2dcac0f5
FB
487 function handler_ajax_job(&$page, $id)
488 {
46ae38a9 489 header('Content-Type: text/html; charset=utf-8');
2dcac0f5
FB
490 $page->changeTpl('profile/jobs.job.tpl', NO_SKIN);
491 $page->assign('i', $id);
492 $page->assign('job', array());
2dcac0f5 493 $page->assign('new', true);
b814a8b8
SJ
494 $res = XDB::query("SELECT id, name AS label
495 FROM profile_job_sector_enum");
daa66175
SJ
496 $page->assign('secteurs', $res->fetchAllAssoc());
497 $res = XDB::query("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
498 FROM fonctions_def
499 ORDER BY id");
500 $page->assign('fonctions', $res->fetchAllAssoc());
06a99865
SJ
501 require_once "emails.combobox.inc.php";
502 fill_email_combobox($page);
2dcac0f5
FB
503 }
504
c7139c07 505 function handler_ajax_secteur(&$page, $id, $jobid, $jobpref, $sect, $ssect = -1)
2dcac0f5 506 {
46ae38a9 507 header('Content-Type: text/html; charset=utf-8');
c7139c07
SJ
508 $res = XDB::iterator("SELECT id, name AS label, FIND_IN_SET('optgroup', flags) AS optgroup
509 FROM profile_job_subsector_enum
510 WHERE sectorid = {?}", $sect);
2dcac0f5
FB
511 $page->changeTpl('profile/jobs.secteur.tpl', NO_SKIN);
512 $page->assign('id', $id);
513 $page->assign('ssecteurs', $res);
514 $page->assign('sel', $ssect);
5fecdf6d
SJ
515 if ($id != -1) {
516 $page->assign('change', 1);
517 $page->assign('jobid', $jobid);
518 $page->assign('jobpref', $jobpref);
519 }
c7139c07
SJ
520 }
521
522 function handler_ajax_ssecteur(&$page, $id, $ssect, $sssect = -1)
523 {
524 header('Content-Type: text/html; charset=utf-8');
525 $res = XDB::iterator("SELECT id, name AS label
526 FROM profile_job_subsubsector_enum
527 WHERE subsectorid = {?}", $ssect);
528 $page->changeTpl('profile/jobs.soussecteur.tpl', NO_SKIN);
529 $page->assign('id', $id);
530 $page->assign('sssecteurs', $res);
531 $page->assign('sel', $sssect);
2dcac0f5
FB
532 }
533
f25e1a56
FB
534 function handler_ajax_skill(&$page, $cat, $id)
535 {
46ae38a9 536 header('Content-Type: text/html; charset=utf-8');
f25e1a56 537 $page->changeTpl('profile/skill.skill.tpl', NO_SKIN);
f25e1a56
FB
538 $page->assign('cat', $cat);
539 $page->assign('id', $id);
540 if ($cat == 'competences') {
541 $page->assign('levels', array('initié' => 'initié',
542 'bonne connaissance' => 'bonne connaissance',
543 'expert' => 'expert'));
544 } else {
545 $page->assign('levels', array(1 => 'connaissance basique',
546 2 => 'maîtrise des bases',
547 3 => 'maîtrise limitée',
548 4 => 'maîtrise générale',
549 5 => 'bonne maîtrise',
550 6 => 'maîtrise complète'));
551 }
552 }
553
6e32823c 554 function handler_ajax_searchname(&$page, $id)
b04882ff
PC
555 {
556 header('Content-Type: text/html; charset=utf-8');
557 $page->changeTpl('profile/general.searchname.tpl', NO_SKIN);
6e32823c 558 $res = XDB::query("SELECT id, name, FIND_IN_SET('public', flags) AS pub
97a98687 559 FROM profile_name_enum
6e32823c
SJ
560 WHERE NOT FIND_IN_SET('not_displayed', flags)
561 AND NOT FIND_IN_SET('always_displayed', flags)");
562 $page->assign('sn_type_list', $res->fetchAllAssoc());
563 $page->assign('i', $id);
b04882ff 564 }
6e32823c
SJ
565
566 function handler_ajax_buildnames(&$page, $data)
567 {
568 header('Content-Type: text/html; charset=utf-8');
569 $page->changeTpl('profile/general.buildnames.tpl', NO_SKIN);
570 require_once 'name.func.inc.php';
dced83b4 571 $page->assign('names', build_javascript_names($data));
b04882ff 572 }
6e32823c 573
9b0fa329 574 function handler_p_orange(&$page)
575 {
8b1f8e12 576 $page->changeTpl('profile/orange.tpl');
9b0fa329 577
578 require_once 'validations.inc.php';
9b0fa329 579
d1319488 580 $res = XDB::query("SELECT e.entry_year, e.grad_year, d.promo, FIND_IN_SET('femme', u.flags) AS sexe
fb2c09c9 581 FROM auth_user_md5 AS u
d1319488 582 INNER JOIN profile_display AS d ON (d.pid = u.user_id)
fb2c09c9
SJ
583 INNER JOIN profile_education AS e ON (e.uid = u.user_id AND FIND_IN_SET('primary', e.flags))
584 WHERE u.user_id = {?}", S::v('uid'));
9b0fa329 585
fb2c09c9 586 list($promo, $promo_sortie_old, $promo_display, $sexe) = $res->fetchOneRow();
9b0fa329 587 $page->assign('promo_sortie_old', $promo_sortie_old);
fb2c09c9
SJ
588 $page->assign('promo', $promo);
589 $page->assign('promo_display', $promo_display);
590 $page->assign('sexe', $sexe);
9b0fa329 591
592 if (!Env::has('promo_sortie')) {
fd8f77de 593 return;
8827fc52
VZ
594 } else {
595 S::assert_xsrf_token();
9b0fa329 596 }
597
5e2307dc 598 $promo_sortie = Env::i('promo_sortie');
9b0fa329 599
600 if ($promo_sortie < 1000 || $promo_sortie > 9999) {
fb2c09c9 601 $page->trigError('L\'année de sortie doit être un nombre de quatre chiffres.');
9b0fa329 602 }
603 elseif ($promo_sortie < $promo + 3) {
fb2c09c9 604 $page->trigError('Trop tôt !');
9b0fa329 605 }
606 elseif ($promo_sortie == $promo_sortie_old) {
a7d35093 607 $page->trigWarning('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
9b0fa329 608 }
609 elseif ($promo_sortie == $promo + 3) {
fb2c09c9
SJ
610 XDB::execute("UPDATE profile_education
611 SET grad_year = {?}
612 WHERE uid = {?} AND FIND_IN_SET('primary', flags)", $promo_sortie, S::v('uid'));
a7d35093 613 $page->trigSuccess('Ton statut "orange" a été supprimé.');
9b0fa329 614 $page->assign('promo_sortie_old', $promo_sortie);
615 }
616 else {
617 $page->assign('promo_sortie', $promo_sortie);
618
619 if (Env::has('submit')) {
5daf68f6 620 $myorange = new OrangeReq(S::user(), $promo_sortie);
9b0fa329 621 $myorange->submit();
622 $page->assign('myorange', $myorange);
623 }
624 }
9b0fa329 625 }
626
2f678da1 627 function handler_referent(&$page, $x = null)
28e16d4d 628 {
28e16d4d 629 require_once 'user.func.inc.php';
8b1f8e12 630 $page->changeTpl('profile/fiche_referent.tpl', SIMPLE);
28e16d4d 631
b3bf7395
VZ
632 $user = User::get($x);
633 if ($user == null) {
28e16d4d 634 return PL_NOT_FOUND;
635 }
636
b3bf7395
VZ
637 $res = XDB::query("SELECT cv FROM auth_user_md5 WHERE user_id = {?}", $user->id());
638 $cv = $res->fetchOneCell();
28e16d4d 639
b3bf7395
VZ
640 $page->assign_by_ref('user', $user);
641 $page->assign('cv', MiniWiki::WikiToHTML($cv, true));
642 $page->assign('adr_pro', get_user_details_pro($user->id()));
28e16d4d 643
644 ///// recuperations infos referent
645
646 //expertise
5fecdf6d 647 $res = XDB::query("SELECT expertise FROM profile_mentor WHERE uid = {?}", $user->id());
28e16d4d 648 $page->assign('expertise', $res->fetchOneCell());
649
650 //secteurs
651 $secteurs = $ss_secteurs = Array();
08cce2ff 652 $res = XDB::iterRow(
f926f2b8 653 "SELECT s.name AS label, ss.name AS label
5fecdf6d
SJ
654 FROM profile_mentor_sector AS m
655 LEFT JOIN profile_job_sector_enum AS s ON(m.sectorid = s.id)
656 LEFT JOIN profile_job_subsector_enum AS ss ON(m.sectorid = ss.sectorid AND m.subsectorid = ss.id)
b3bf7395 657 WHERE uid = {?}", $user->id());
28e16d4d 658 while (list($sec, $ssec) = $res->next()) {
659 $secteurs[] = $sec;
660 $ss_secteurs[] = $ssec;
661 }
662 $page->assign_by_ref('secteurs', $secteurs);
663 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
664
665 //pays
08cce2ff 666 $res = XDB::query(
28e16d4d 667 "SELECT gp.pays
5fecdf6d
SJ
668 FROM profile_mentor_country AS m
669 LEFT JOIN geoloc_pays AS gp ON (m.country = gp.a2)
b3bf7395 670 WHERE uid = {?}", $user->id());
28e16d4d 671 $page->assign('pays', $res->fetchColumn());
672
c99ef281 673 $page->addJsLink('close_on_esc.js');
28e16d4d 674 }
675
ff3eb9b7 676 function handler_ref_search(&$page, $action = null, $subaction = null)
2f678da1 677 {
8f201b69
FB
678 $wp = new PlWikiPage('Docs.Emploi');
679 $wp->buildCache();
680
46f272fe 681 $page->setTitle('Conseil Pro');
2f678da1 682
2f678da1 683 //recuperation des noms de secteurs
5fecdf6d 684 $res = XDB::iterRow("SELECT id, name AS label FROM profile_job_sector_enum");
2f678da1 685 $secteurs[''] = '';
686 while (list($tmp_id, $tmp_label) = $res->next()) {
687 $secteurs[$tmp_id] = $tmp_label;
688 }
689 $page->assign_by_ref('secteurs', $secteurs);
690
2f678da1 691 // nb de mentors
5fecdf6d 692 $res = XDB::query("SELECT count(*) FROM profile_mentor");
2f678da1 693 $page->assign('mentors_number', $res->fetchOneCell());
694
2f678da1 695 // On vient d'un formulaire
ff3eb9b7 696 $where = array();
697 $pays_sel = XDB::escape(Env::v('pays_sel'));
698 $secteur_sel = XDB::escape(Env::v('secteur'));
699 $ss_secteur_sel = XDB::escape(Env::v('ss_secteur'));
700 $expertise_champ = XDB::escape(Env::v('expertise'));
701
702 if ($pays_sel != "''") {
5fecdf6d 703 $where[] = "mp.country = $pays_sel";
ff3eb9b7 704 }
705 if ($secteur_sel != "''") {
5fecdf6d 706 $where[] = "ms.sectorid = $secteur_sel";
ff3eb9b7 707 if ($ss_secteur_sel != "''") {
5fecdf6d 708 $where[] = "ms.subsectorid = $ss_secteur_sel";
2f678da1 709 }
710 }
ff3eb9b7 711 if ($expertise_champ != "''") {
712 $where[] = "MATCH(m.expertise) AGAINST($expertise_champ)";
2f678da1 713 }
714
715 if ($where) {
716 $where = join(' AND ', $where);
717
5fecdf6d
SJ
718 $set = new UserSet("INNER JOIN profile_mentor AS m ON (m.uid = u.user_id)
719 LEFT JOIN profile_mentor_country AS mp ON (mp.uid = m.uid)
720 LEFT JOIN profile_mentor_sector AS ms ON (ms.uid = m.uid)",
ff3eb9b7 721 $where);
722 $set->addMod('mentor', 'Référents');
723 $set->apply('referent/search', $page, $action, $subaction);
724 if ($set->count() > 100) {
e1635d16 725 $page->assign('recherche_trop_large', true);
2f678da1 726 }
ff3eb9b7 727 }
e1635d16 728 $page->changeTpl('profile/referent.tpl');
ff3eb9b7 729 }
2f678da1 730
e1635d16 731 function handler_ref_sect(&$page, $sect)
ff3eb9b7 732 {
733 header('Content-Type: text/html; charset=utf-8');
05cb05c0 734 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 735 $page->assign('onchange', 'setSSecteurs()');
736 $page->assign('id', 'ssect_field');
737 $page->assign('name', 'ss_secteur');
5fecdf6d
SJ
738 $it = XDB::iterator("SELECT id, name AS field
739 FROM profile_job_subsector_enum
740 WHERE sectorid = {?}", $sect);
ff3eb9b7 741 $page->assign('list', $it);
742 }
2f678da1 743
ff3eb9b7 744 function handler_ref_country(&$page, $sect, $ssect = '')
745 {
746 header('Content-Type: text/html; charset=utf-8');
05cb05c0 747 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 748 $page->assign('name', 'pays_sel');
5fecdf6d 749 $where = ($ssect ? ' AND ms.subsectorid = {?}' : '');
ff3eb9b7 750 $it = XDB::iterator("SELECT a2 AS id, pays AS field
5fecdf6d
SJ
751 FROM geoloc_pays AS g
752 INNER JOIN profile_mentor_country AS mp ON (mp.country = g.a2)
753 INNER JOIN profile_mentor_sector AS ms ON (ms.uid = mp.uid)
754 WHERE ms.sectorid = {?} $where
755 GROUP BY a2
756 ORDER BY pays", $sect, $ssect);
ff3eb9b7 757 $page->assign('list', $it);
2f678da1 758 }
759
a1d79217 760 function handler_xnet(&$page)
761 {
8b1f8e12 762 $page->changeTpl('profile/groupesx.tpl');
46f272fe 763 $page->setTitle('Promo, Groupes X, Binets');
e1635d16 764
a1d79217 765 $req = XDB::query('
e1635d16 766 SELECT m.asso_id, a.nom, diminutif, a.logo IS NOT NULL AS has_logo,
46e1d3ba 767 COUNT(e.eid) AS events, mail_domain AS lists
e1635d16 768 FROM groupex.membres AS m
46e1d3ba 769 INNER JOIN groupex.asso AS a ON(m.asso_id = a.id)
770 LEFT JOIN groupex.evenements AS e ON(e.asso_id = m.asso_id AND e.archive = 0)
771 WHERE uid = {?} GROUP BY m.asso_id ORDER BY a.nom', S::i('uid'));
a1d79217 772 $page->assign('assos', $req->fetchAllAssoc());
773 }
e1635d16 774
e49018a7 775 function handler_vcard(&$page, $x = null)
776 {
777 if (is_null($x)) {
778 return PL_NOT_FOUND;
779 }
780
781 global $globals;
782
783 if (substr($x, -4) == '.vcf') {
784 $x = substr($x, 0, strlen($x) - 4);
785 }
786
5d42c993
FB
787 $vcard = new VCard();
788 $vcard->addUser($x);
789 $vcard->show();
e49018a7 790 }
92423144 791
54cabe90 792 function handler_admin_trombino(&$page, $login = null, $action = null) {
8b1f8e12 793 $page->changeTpl('profile/admin_trombino.tpl');
46f272fe 794 $page->setTitle('Administration - Trombino');
e1635d16 795
54cabe90
VZ
796 if (!$login || !($user = User::get($login))) {
797 return PL_NOT_FOUND;
798 } else {
799 $page->assign_by_ref('user', $user);
800 }
e1635d16 801
92423144 802 switch ($action) {
92423144 803 case "original":
804 header("Content-type: image/jpeg");
54cabe90 805 readfile("/home/web/trombino/photos" . $user->promo() . "/" . $user->login() . ".jpg");
92423144 806 exit;
807 break;
e1635d16 808
92423144 809 case "new":
8827fc52
VZ
810 S::assert_xsrf_token();
811
92423144 812 $data = file_get_contents($_FILES['userfile']['tmp_name']);
813 list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']);
814 $mimetype = substr($_FILES['userfile']['type'], 6);
815 unlink($_FILES['userfile']['tmp_name']);
816 XDB::execute(
817 "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
54cabe90 818 $user->id(), $mimetype, $data, $x, $y);
92423144 819 break;
e1635d16 820
92423144 821 case "delete":
8827fc52
VZ
822 S::assert_xsrf_token();
823
54cabe90 824 XDB::execute('DELETE FROM photo WHERE uid = {?}', $user->id());
92423144 825 break;
826 }
92423144 827 }
b62db02e
SJ
828 function handler_admin_names(&$page, $action = 'list', $id = null) {
829 $page->setTitle('Administration - Types de noms');
830 $page->assign('title', 'Gestion des types de noms');
831 $table_editor = new PLTableEditor('admin/names', 'profile_name_enum', 'id', true);
832 $table_editor->describe('name', 'Nom', true);
833 $table_editor->describe('explanations', 'Explications', true);
834 $table_editor->describe('type', 'Type', true);
835 $table_editor->describe('flags', 'Flags', true);
836 $table_editor->describe('score', 'Score', true);
837 $table_editor->apply($page, $action, $id);
838 }
92423144 839 function handler_admin_binets(&$page, $action = 'list', $id = null) {
46f272fe 840 $page->setTitle('Administration - Binets');
92423144 841 $page->assign('title', 'Gestion des binets');
842 $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id');
843 $table_editor->add_join_table('binets_ins','binet_id',true);
a7de4ef7 844 $table_editor->describe('text','intitulé',true);
92423144 845 $table_editor->apply($page, $action, $id);
846 }
043bbacf 847 function handler_admin_education(&$page, $action = 'list', $id = null) {
46f272fe 848 $page->setTitle('Administration - Formations');
92423144 849 $page->assign('title', 'Gestion des formations');
043bbacf
SJ
850 $table_editor = new PLTableEditor('admin/education', 'profile_education_enum', 'id');
851 $table_editor->add_join_table('profile_education', 'eduid', true);
852 $table_editor->add_join_table('profile_education_degree', 'eduid', true);
853 $table_editor->describe('name', 'intitulé', true);
854 $table_editor->describe('url', 'site web', false);
855 $table_editor->apply($page, $action, $id);
856 }
857 function handler_admin_education_field(&$page, $action = 'list', $id = null) {
858 $page->setTitle('Administration - Domaines de formation');
859 $page->assign('title', 'Gestion des domaines de formation');
860 $table_editor = new PLTableEditor('admin/education_field', 'profile_education_field_enum', 'id', true);
861 $table_editor->add_join_table('profile_education', 'fieldid', true);
862 $table_editor->describe('field', 'domaine', true);
863 $table_editor->apply($page, $action, $id);
864 }
865 function handler_admin_education_degree(&$page, $action = 'list', $id = null) {
866 $page->setTitle('Administration - Niveau de formation');
867 $page->assign('title', 'Gestion des niveau de formation');
868 $table_editor = new PLTableEditor('admin/education_degree', 'profile_education_degree_enum', 'id', true);
869 $table_editor->add_join_table('profile_education_degree', 'degreeid', true);
870 $table_editor->add_join_table('profile_education', 'degreeid', true);
871 $table_editor->describe('degree', 'niveau', true);
872 $table_editor->apply($page, $action, $id);
873 }
874 function handler_admin_education_degree_set(&$page, $action = 'list', $id = null) {
875 $page->setTitle('Administration - Correspondances formations - niveau de formation');
876 $page->assign('title', 'Gestion des correspondances formations - niveau de formation');
877 $table_editor = new PLTableEditor('admin/education_degree_set', 'profile_education_degree', 'eduid', true);
878 $table_editor->describe('eduid', 'formation', true);
879 $table_editor->describe('degreeid', 'niveau', true);
92423144 880 $table_editor->apply($page, $action, $id);
e1635d16 881 }
b09690be 882 function handler_admin_sections(&$page, $action = 'list', $id = null) {
46f272fe 883 $page->setTitle('Administration - Sections');
a20aab02 884 $page->assign('title', 'Gestion des sections');
b09690be 885 $table_editor = new PLTableEditor('admin/sections','sections','id');
886 $table_editor->describe('text','intitulé',true);
887 $table_editor->apply($page, $action, $id);
e1635d16 888 }
a20aab02 889 function handler_admin_ss_secteurs(&$page, $action = 'list', $id = null) {
46f272fe 890 $page->setTitle('Administration - Sous-secteurs');
a20aab02
SJ
891 $page->assign('title', 'Gestion des sous-secteurs');
892 $table_editor = new PLTableEditor('admin/ss_secteurs', 'emploi_ss_secteur', 'id', true);
893 $table_editor->describe('label', 'intitulé', true);
894 $table_editor->apply($page, $action, $id);
895 }
896 function handler_admin_fonctions(&$page, $action = 'list', $id = null) {
46f272fe 897 $page->setTitle('Administration - Fonctions');
a20aab02
SJ
898 $page->assign('title', 'Gestion des fonctions');
899 $table_editor = new PLTableEditor('admin/fonctions', 'fonctions_def', 'id', true);
900 $table_editor->describe('fonction_fr', 'intitulé', true);
901 $table_editor->describe('fonction_en', 'intitulé (ang)', true);
902 $table_editor->describe('flags', 'titre', true);
903 $table_editor->apply($page, $action, $id);
904 }
b09690be 905 function handler_admin_secteurs(&$page, $action = 'list', $id = null) {
46f272fe 906 $page->setTitle('Administration - Secteurs');
a20aab02
SJ
907 $page->assign('title', 'Gestion des secteurs');
908 $table_editor = new PLTableEditor('admin/secteurs', 'emploi_secteur', 'id', true);
909 $table_editor->describe('label', 'intitulé', true);
b09690be 910 $table_editor->apply($page, $action, $id);
e1635d16 911 }
15beefb3
GB
912 function handler_admin_networking(&$page, $action = 'list', $id = null) {
913 $page->assign('xorg_title', 'Polytechnique.org - Administration - Networking');
914 $page->assign('title', 'Gestion des types de networking');
915 $table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'network_type');
916 $table_editor->describe('name', 'intitulé', true);
917 $table_editor->describe('icon', 'nom de l\'icône', false);
dc6378df
GB
918 $table_editor->describe('filter', 'filtre', true);
919 $table_editor->describe('link', 'lien web', true);
15beefb3
GB
920 $table_editor->apply($page, $action, $id);
921 }
4962a9ce
SJ
922 function handler_admin_corps_enum(&$page, $action = 'list', $id = null) {
923 $page->setTitle('Administration - Corps');
924 $page->assign('title', 'Gestion des Corps');
925 $table_editor = new PLTableEditor('admin/corps_enum', 'profile_corps_enum', 'id');
926 $table_editor->describe('name', 'intitulé', true);
927 $table_editor->describe('abbreviation', 'abbréviation', true);
928 $table_editor->describe('still_exists', 'existe encore ?', true);
929 $table_editor->apply($page, $action, $id);
930 }
931 function handler_admin_corps_rank(&$page, $action = 'list', $id = null) {
932 $page->setTitle('Administration - Grade dans les Corps');
933 $page->assign('title', 'Gestion des grade dans les Corps');
934 $table_editor = new PLTableEditor('admin/corps_rank', 'profile_corps_rank_enum', 'id');
935 $table_editor->describe('name', 'intitulé', true);
936 $table_editor->describe('abbreviation', 'abbréviation', true);
937 $table_editor->apply($page, $action, $id);
938 }
92423144 939 function handler_admin_medals(&$page, $action = 'list', $id = null) {
46f272fe 940 $page->setTitle('Administration - Distinctions');
92423144 941 $page->assign('title', 'Gestion des Distinctions');
942 $table_editor = new PLTableEditor('admin/medals','profile_medals','id');
a7de4ef7 943 $table_editor->describe('text', 'intitulé', true);
92423144 944 $table_editor->describe('img', 'nom de l\'image', false);
d02b8359 945 $table_editor->describe('flags', 'valider', true);
92423144 946 $table_editor->apply($page, $action, $id);
947 if ($id && $action == 'edit') {
8b1f8e12 948 $page->changeTpl('profile/admin_decos.tpl');
e1635d16 949
92423144 950 $mid = $id;
e1635d16 951
92423144 952 if (Post::v('act') == 'del') {
75a17710
FB
953 XDB::execute('DELETE FROM profile_medals_grades
954 WHERE mid={?} AND gid={?}', $mid, Post::i('gid'));
92423144 955 } else {
956 foreach (Post::v('grades', array()) as $gid=>$text) {
154ee23a
OLF
957 if ($gid === 0) {
958 if (!empty($text)) {
959 $res = XDB::query('SELECT MAX(gid)
960 FROM profile_medals_grades
961 WHERE mid = {?}', $mid);
962 $gid = $res->fetchOneCell() + 1;
963
964 XDB::execute('INSERT INTO profile_medals_grades (mid, gid, text, pos)
965 VALUES ({?}, {?}, {?}, {?})',
966 $mid, $gid, $text, $_POST['pos']['0']);
967 }
968 } else {
969 XDB::execute('UPDATE profile_medals_grades
970 SET pos={?}, text={?}
971 WHERE gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid);
972 }
92423144 973 }
974 }
975 $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid);
976 $page->assign('grades', $res);
977 }
e1635d16 978 }
7d8b17cb 979}
980
a7de4ef7 981// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
7d8b17cb 982?>