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