Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 Polytechnique.org * |
0337d704 | 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 | ||
670b0ac0 | 22 | function gpex_prepare_param($name, $val, &$to_hash, $charset) |
23 | { | |
24 | $val = iconv('UTF-8', $charset, $val); | |
25 | $to_hash .= $val; | |
15dec88f | 26 | return '&' . $name . '=' . urlencode($val); |
670b0ac0 | 27 | } |
28 | ||
29 | function gpex_make($chlg, $privkey, $datafields, $charset) | |
9881e0b2 | 30 | { |
0337d704 | 31 | $tohash = "1$chlg$privkey"; |
9881e0b2 | 32 | $params = ""; |
670b0ac0 | 33 | $fieldarr = explode(',', $datafields); |
0337d704 | 34 | |
94b72319 FB |
35 | $user =& S::user(); |
36 | if ($user->hasProfile()) { | |
37 | // XXX: Transition table for auth. | |
38 | $personnal_data = $user->profile()->data(); | |
39 | $personnal_data['matricule'] = $personnal_data['xorg_id']; | |
40 | $personnal_data['matricule_ax'] = $personnal_data['ax_id']; | |
41 | $personnal_data['promo_sortie'] = $personnal_data['promo'] + 3; // FIXME: Hum, not that good | |
42 | $personnal_data['nationalite'] = $personnal_data['nationality1']; | |
43 | $personnal_data['naissance'] = $personnal_data['birthdate']; | |
44 | $personnal_data['deces'] = $personnal_data['deathdate']; | |
45 | $personnal_data['flags'] = $user->profile()->isFemale() ? 'femme' : ''; | |
46 | } else { | |
47 | $personnal_data = array(); | |
48 | } | |
5d292fd8 | 49 | |
50 | foreach ($fieldarr as $val) { | |
6e181f3e | 51 | // Determine the requested value, and add it to the answer. |
b3454c7f FB |
52 | if ($val == 'perms') { |
53 | $params .= gpex_prepare_param($val, S::has_perms() ? 'admin' : 'user', $tohash, $charset); | |
6e181f3e VZ |
54 | } else if ($val == 'forlife') { |
55 | $params .= gpex_prepare_param($val, S::v('hruid'), $tohash, $charset); | |
b3454c7f | 56 | } else if (S::has($val)) { |
670b0ac0 | 57 | $params .= gpex_prepare_param($val, S::v($val), $tohash, $charset); |
9f3acd20 | 58 | } else if (isset($personnal_data[$val])) { |
670b0ac0 | 59 | $params .= gpex_prepare_param($val, $personnal_data[$val], $tohash, $charset); |
0337d704 | 60 | } else if ($val == 'username') { |
94b72319 FB |
61 | $res = XDB::query("SELECT alias |
62 | FROM aliases | |
670b0ac0 | 63 | WHERE id = {?} AND FIND_IN_SET('bestalias', flags)", |
94b72319 | 64 | S::i('uid')); |
0337d704 | 65 | $min_username = $res->fetchOneCell(); |
670b0ac0 | 66 | $params .= gpex_prepare_param($val, $min_username, $tohash, $charset); |
b49f3f40 | 67 | } else if ($val == 'grpauth') { |
670b0ac0 | 68 | if (isset($_GET['group'])) { |
69 | $res = XDB::query("SELECT perms | |
70 | FROM groupex.membres | |
eaf30d86 | 71 | INNER JOIN groupex.asso ON(id = asso_id) |
670b0ac0 | 72 | WHERE uid = {?} AND diminutif = {?}", |
73 | S::v('uid'), $_GET['group']); | |
74 | $perms = $res->fetchOneCell(); | |
75 | } else { | |
76 | // if no group asked, return main rights | |
03849c3e | 77 | $perms = S::has_perms() ? 'admin' : 'membre'; |
670b0ac0 | 78 | } |
79 | $params .= gpex_prepare_param($val, $perms, $tohash, $charset); | |
94b72319 FB |
80 | } else { |
81 | $params .= gpex_prepare_param($val, '', $tohash, $charset); | |
5d292fd8 | 82 | } |
0337d704 | 83 | } |
84 | $tohash .= "1"; | |
9881e0b2 | 85 | $auth = md5($tohash); |
670b0ac0 | 86 | return array($auth, "&auth=" . $auth . $params); |
0337d704 | 87 | } |
88 | ||
89 | /* cree les parametres de l'URL de retour avec les champs demandes */ | |
670b0ac0 | 90 | function gpex_make_params($chlg, $privkey, $datafields, $charset) |
91 | { | |
92 | list ($auth, $param) = gpex_make($chlg, $privkey, $datafields, $charset); | |
93 | return $param; | |
0337d704 | 94 | } |
95 | ||
a7de4ef7 | 96 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 97 | ?> |