0337d704 |
1 | <?php |
2 | /*************************************************************************** |
5ddeb07c |
3 | * Copyright (C) 2003-2007 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 | |
9881e0b2 |
22 | function gpex_make($chlg, $privkey, $datafields) |
23 | { |
0337d704 |
24 | $tohash = "1$chlg$privkey"; |
9881e0b2 |
25 | $params = ""; |
26 | $fieldarr = explode(",",$datafields); |
0337d704 |
27 | |
08cce2ff |
28 | $res = XDB::query("SELECT matricule, matricule_ax, promo, |
5d292fd8 |
29 | promo_sortie, flags, deces, nom, |
30 | prenom, nationalite, section, |
31 | naissance |
32 | FROM auth_user_md5 WHERE user_id = {?}", |
cab08090 |
33 | S::v('uid')); |
9f3acd20 |
34 | $personnal_data = $res->fetchOneAssoc(); |
5d292fd8 |
35 | |
36 | foreach ($fieldarr as $val) { |
a7de4ef7 |
37 | /* on verifie qu'on n'a pas demandé une variable inexistante ! */ |
cab08090 |
38 | if (S::has($val)) { |
39 | $tohash .= S::v($val); |
37448723 |
40 | $params .= "&$val=".S::v($val); |
9f3acd20 |
41 | } else if (isset($personnal_data[$val])) { |
42 | $tohash .= $personnal_data[$val]; |
37448723 |
43 | $params .= "&$val=".$personnal_data[$val]; |
0337d704 |
44 | } else if ($val == 'username') { |
08cce2ff |
45 | $res = XDB::query("SELECT alias FROM aliases |
5d292fd8 |
46 | WHERE id = {?} AND FIND_IN_SET('bestalias', flags)", |
cab08090 |
47 | S::v('uid')); |
0337d704 |
48 | $min_username = $res->fetchOneCell(); |
49 | $tohash .= $min_username; |
9881e0b2 |
50 | $params .= "&$val=".$min_username; |
51 | } else if ($val == 'grpauth' && isset($_GET['group'])) { |
52 | $res = XDB::query("SELECT perms FROM groupex.membres |
53 | INNER JOIN groupex.asso ON(id = asso_id) |
54 | WHERE uid = {?} AND diminutif = {?}", S::v('uid'), $_GET['group']); |
55 | $perms = $res->fetchOneCell(); |
56 | $tohash .= $perms; |
57 | $params .= "&$val=".$perms; |
5d292fd8 |
58 | } |
0337d704 |
59 | } |
60 | $tohash .= "1"; |
9881e0b2 |
61 | $auth = md5($tohash); |
62 | return array($auth, "&auth=".$auth.$params); |
63 | } |
64 | |
65 | /* cree le champs "auth" renvoye au Groupe X */ |
66 | function gpex_make_auth($chlg, $privkey, $datafields) { |
67 | list ($auth, $param) = gpex_make($chlg, $privkey, $datafields); |
68 | return $auth; |
0337d704 |
69 | } |
70 | |
71 | /* cree les parametres de l'URL de retour avec les champs demandes */ |
72 | function gpex_make_params($chlg, $privkey, $datafields) { |
9881e0b2 |
73 | list ($auth, $param) = gpex_make($chlg, $privkey, $datafields); |
74 | return $param; |
0337d704 |
75 | } |
76 | |
a7de4ef7 |
77 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 |
78 | ?> |