Adds XSRF protection to the Carnet module.
[platal.git] / include / homonymes.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
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
22 function select_if_homonyme($uid) {
23 $res = XDB::query("SELECT prenom,nom,a.alias AS forlife,h.alias AS loginbis
24 FROM auth_user_md5 AS u
25 INNER JOIN aliases AS a ON (a.id=u.user_id AND a.type='a_vie')
26 INNER JOIN aliases AS h ON (h.id=u.user_id AND h.expire!='')
27 WHERE user_id = {?}", $uid);
28 return $res->fetchOneRow();
29 }
30
31 function send_warning_homonyme($prenom, $nom, $forlife, $loginbis) {
32 global $globals;
33 $cc = "support+homonyme@" . $globals->mail->domain;
34 $FROM = "\"Support Polytechnique.org\" <$cc>";
35 $mymail = new PlMailer();
36 $mymail->setFrom($FROM);
37 $mymail->setSubject("Dans 2 semaines, suppression de $loginbis@" . $globals->mail->domain);
38 $mymail->addTo("$prenom $nom <$forlife@" . $globals->mail->domain . '>');
39 $mymail->addCc($cc);
40 $mymail->setTxtBody(Env::v('mailbody'));
41 $mymail->send();
42 }
43
44 function send_robot_homonyme($prenom, $nom, $forlife, $loginbis) {
45 global $globals;
46 $cc = "support+homonyme@" . $globals->mail->domain;
47 $FROM = "\"Support Polytechnique.org\" <$cc>";
48 $mymail = new PlMailer();
49 $mymail->setFrom($FROM);
50 $mymail->setSubject("Mise en place du robot $loginbis@" . $globals->mail->domain);
51 $mymail->addTo("$prenom $nom <$forlife@" . $globals->mail->domain . '>');
52 $mymail->addCc($cc);
53 $mymail->setTxtBody(Env::v('mailbody'));
54 $mymail->send();
55 }
56
57 function switch_bestalias($uid, $loginbis) {
58 // check if loginbis was the bestalias
59 $res = XDB::query("SELECT alias FROM aliases WHERE id = {?} AND FIND_IN_SET('bestalias', flags)", $uid);
60 $bestalias = $res->fetchOneCell();
61 if ($bestalias && $bestalias != $loginbis) return false;
62
63 // select the shortest alias still alive
64 $res = XDB::query("SELECT alias FROM aliases WHERE id = {?} AND alias != {?} AND expire IS NULL ORDER BY LENGTH(alias) LIMIT 1", $uid, $loginbis);
65 $newbest = $res->fetchOneCell();
66 // change the bestalias flag
67 XDB::execute("UPDATE aliases SET flags = (flags & (255 - 1)) | IF(alias = {?}, 1, 0) WHERE id = {?}", $newbest, $uid);
68
69 return $newbest;
70 }
71
72 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
73 ?>