2 /***************************************************************************
3 * Copyright (C) 2003-2013 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 function gpex_prepare_param($name, $val, &$to_hash, $charset)
24 $val = iconv('UTF-8', $charset, $val);
26 return '&' . $name . '=' . urlencode($val);
29 function gpex_make($chlg, $privkey, $datafields, $charset)
31 $tohash = "1$chlg$privkey";
33 $fieldarr = explode(',', $datafields);
36 if ($user->hasProfile()) {
37 /* Transition table for authentification. */
38 $personnal_data = $user->profile()->data();
39 $personnal_data['full_promo'] = $personnal_data['promo'];
40 $personnal_data['promo'] = $personnal_data['entry_year'];
41 $personnal_data['matricule'] = $personnal_data['xorg_id'];
42 $personnal_data['matricule_ax'] = $personnal_data['ax_id'];
43 $personnal_data['promo_sortie'] = $personnal_data['grad_year'];
44 $personnal_data['nationalite'] = $personnal_data['nationality1'];
45 $personnal_data['naissance'] = $personnal_data['birthdate'];
46 $personnal_data['deces'] = $personnal_data['deathdate'];
47 $personnal_data['nom'] = $personnal_data['lastname'];
48 $personnal_data['prenom'] = $personnal_data['firstname'];
49 $personnal_data['flags'] = $user->profile()->isFemale() ?
'femme' : '';
51 // Missing fields: promo, entry_year, grad_year, ax_id, xorg_id, forlife
52 $personnal_data = array(
53 'lastname' => $user->lastname
,
54 'firstname' => $user->firstname
,
55 'sex' => $user->gender
59 foreach ($fieldarr as $val) {
60 // Determine the requested value, and add it to the answer.
61 if ($val == 'perms') {
62 $params .= gpex_prepare_param($val, S
::admin() ?
'admin' : 'user', $tohash, $charset);
63 } else if ($val == 'forlife') {
64 $params .= gpex_prepare_param($val, S
::v('hruid'), $tohash, $charset);
65 } else if (S
::has($val)) {
66 $params .= gpex_prepare_param($val, S
::v($val), $tohash, $charset);
67 } else if (isset($personnal_data[$val])) {
68 $params .= gpex_prepare_param($val, $personnal_data[$val], $tohash, $charset);
69 } else if ($val == 'username') {
70 $min_username = XDB
::fetchOneCell('SELECT email
71 FROM email_source_account
72 WHERE uid = {?} AND FIND_IN_SET(\'bestalias\', flags)',
74 $params .= gpex_prepare_param($val, (is_null($min_username) ?
'' : $min_username), $tohash, $charset);
75 } else if ($val == 'grpauth') {
76 if (isset($_GET['group'])) {
77 $res = XDB
::query("SELECT perms
79 INNER JOIN groups ON(id = asso_id)
80 WHERE uid = {?} AND diminutif = {?}",
81 S
::v('uid'), $_GET['group']);
82 $perms = $res->fetchOneCell();
84 // if no group asked, return main rights
85 $perms = S
::admin() ?
'admin' : 'membre';
87 $params .= gpex_prepare_param($val, $perms, $tohash, $charset);
89 $params .= gpex_prepare_param($val, '', $tohash, $charset);
94 return array($auth, "&auth=" . $auth . $params);
97 /* cree les parametres de l'URL de retour avec les champs demandes */
98 function gpex_make_params($chlg, $privkey, $datafields, $charset)
100 list ($auth, $param) = gpex_make($chlg, $privkey, $datafields, $charset);
104 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: