Adds support for database tablename prefixs.
[platal.git] / modules / auth / auth.inc.php
CommitLineData
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 22function 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
29function gpex_make($chlg, $privkey, $datafields, $charset)
9881e0b2 30{
0337d704 31 $tohash = "1$chlg$privkey";
9881e0b2 32 $params = "";
670b0ac0 33 $fieldarr = explode(',', $datafields);
0337d704 34
670b0ac0 35 $res = XDB::query("SELECT matricule, matricule_ax, promo,
36 promo_sortie, flags, deces, nom,
37 prenom, nationalite, section,
38 naissance
39 FROM auth_user_md5 WHERE user_id = {?}",
40 S::v('uid'));
9f3acd20 41 $personnal_data = $res->fetchOneAssoc();
5d292fd8 42
43 foreach ($fieldarr as $val) {
6e181f3e 44 // Determine the requested value, and add it to the answer.
b3454c7f 45 if ($val == 'perms') {
dd70cd28 46 $params .= gpex_prepare_param($val, S::admin() ? 'admin' : 'user', $tohash, $charset);
6e181f3e
VZ
47 } else if ($val == 'forlife') {
48 $params .= gpex_prepare_param($val, S::v('hruid'), $tohash, $charset);
b3454c7f 49 } else if (S::has($val)) {
670b0ac0 50 $params .= gpex_prepare_param($val, S::v($val), $tohash, $charset);
9f3acd20 51 } else if (isset($personnal_data[$val])) {
670b0ac0 52 $params .= gpex_prepare_param($val, $personnal_data[$val], $tohash, $charset);
0337d704 53 } else if ($val == 'username') {
670b0ac0 54 $res = XDB::query("SELECT alias FROM aliases
55 WHERE id = {?} AND FIND_IN_SET('bestalias', flags)",
56 S::v('uid'));
0337d704 57 $min_username = $res->fetchOneCell();
670b0ac0 58 $params .= gpex_prepare_param($val, $min_username, $tohash, $charset);
b49f3f40 59 } else if ($val == 'grpauth') {
670b0ac0 60 if (isset($_GET['group'])) {
61 $res = XDB::query("SELECT perms
00112b2e
VZ
62 FROM #groupex#.membres
63 INNER JOIN #groupex#.asso ON(id = asso_id)
670b0ac0 64 WHERE uid = {?} AND diminutif = {?}",
65 S::v('uid'), $_GET['group']);
66 $perms = $res->fetchOneCell();
67 } else {
68 // if no group asked, return main rights
dd70cd28 69 $perms = S::admin() ? 'admin' : 'membre';
670b0ac0 70 }
71 $params .= gpex_prepare_param($val, $perms, $tohash, $charset);
5d292fd8 72 }
0337d704 73 }
74 $tohash .= "1";
9881e0b2 75 $auth = md5($tohash);
670b0ac0 76 return array($auth, "&auth=" . $auth . $params);
0337d704 77}
78
79/* cree les parametres de l'URL de retour avec les champs demandes */
670b0ac0 80function gpex_make_params($chlg, $privkey, $datafields, $charset)
81{
82 list ($auth, $param) = gpex_make($chlg, $privkey, $datafields, $charset);
83 return $param;
0337d704 84}
85
a7de4ef7 86// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 87?>