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