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 | |
22 | function select_if_homonyme($uid) { |
08cce2ff |
23 | $res = XDB::query("SELECT prenom,nom,a.alias AS forlife,h.alias AS loginbis |
0337d704 |
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) { |
0337d704 |
32 | $cc = "support+homonyme@polytechnique.org"; |
33 | $FROM = "\"Support Polytechnique.org\" <$cc>"; |
1e33266a |
34 | $mymail = new PlMailer(); |
0337d704 |
35 | $mymail->setFrom($FROM); |
36 | $mymail->setSubject("Dans 2 semaines, suppression de $loginbis@polytechnique.org"); |
37 | $mymail->addTo("$prenom $nom <$forlife@polytechnique.org>"); |
38 | $mymail->addCc($cc); |
5e2307dc |
39 | $mymail->setTxtBody(Env::v('mailbody')); |
0337d704 |
40 | $mymail->send(); |
41 | } |
42 | |
43 | function send_robot_homonyme($prenom, $nom, $forlife, $loginbis) { |
0337d704 |
44 | $cc = "support+homonyme@polytechnique.org"; |
45 | $FROM = "\"Support Polytechnique.org\" <$cc>"; |
1e33266a |
46 | $mymail = new PlMailer(); |
0337d704 |
47 | $mymail->setFrom($FROM); |
48 | $mymail->setSubject("Mise en place du robot $loginbis@polytechnique.org"); |
49 | $mymail->addTo("$prenom $nom <$forlife@polytechnique.org>"); |
50 | $mymail->addCc($cc); |
5e2307dc |
51 | $mymail->setTxtBody(Env::v('mailbody')); |
0337d704 |
52 | $mymail->send(); |
53 | } |
54 | |
55 | function switch_bestalias($uid, $loginbis) { |
0337d704 |
56 | // check if loginbis was the bestalias |
08cce2ff |
57 | $res = XDB::query("SELECT alias FROM aliases WHERE id = {?} AND FIND_IN_SET('bestalias', flags)", $uid); |
0337d704 |
58 | $bestalias = $res->fetchOneCell(); |
59 | if ($bestalias && $bestalias != $loginbis) return false; |
60 | |
61 | // select the shortest alias still alive |
08cce2ff |
62 | $res = XDB::query("SELECT alias FROM aliases WHERE id = {?} AND alias != {?} AND expire IS NULL ORDER BY LENGTH(alias) LIMIT 1", $uid, $loginbis); |
0337d704 |
63 | $newbest = $res->fetchOneCell(); |
64 | // change the bestalias flag |
08cce2ff |
65 | XDB::execute("UPDATE aliases SET flags = (flags & (255 - 1)) | IF(alias = {?}, 1, 0) WHERE id = {?}", $newbest, $uid); |
0337d704 |
66 | |
67 | return $newbest; |
68 | } |
69 | |
70 | ?> |