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