0337d704 |
1 | <?php |
2 | /*************************************************************************** |
179afa7f |
3 | * Copyright (C) 2003-2008 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) { |
361a5c15 |
32 | global $globals; |
1d55fe45 |
33 | $cc = "support+homonyme@" . $globals->mail->domain; |
0337d704 |
34 | $FROM = "\"Support Polytechnique.org\" <$cc>"; |
1e33266a |
35 | $mymail = new PlMailer(); |
0337d704 |
36 | $mymail->setFrom($FROM); |
1d55fe45 |
37 | $mymail->setSubject("Dans 2 semaines, suppression de $loginbis@" . $globals->mail->domain); |
38 | $mymail->addTo("$prenom $nom <$forlife@" . $globals->mail->domain . '>'); |
0337d704 |
39 | $mymail->addCc($cc); |
5e2307dc |
40 | $mymail->setTxtBody(Env::v('mailbody')); |
0337d704 |
41 | $mymail->send(); |
42 | } |
43 | |
44 | function send_robot_homonyme($prenom, $nom, $forlife, $loginbis) { |
361a5c15 |
45 | global $globals; |
1d55fe45 |
46 | $cc = "support+homonyme@" . $globals->mail->domain; |
0337d704 |
47 | $FROM = "\"Support Polytechnique.org\" <$cc>"; |
1e33266a |
48 | $mymail = new PlMailer(); |
0337d704 |
49 | $mymail->setFrom($FROM); |
1d55fe45 |
50 | $mymail->setSubject("Mise en place du robot $loginbis@" . $globals->mail->domain); |
51 | $mymail->addTo("$prenom $nom <$forlife@" . $globals->mail->domain . '>'); |
0337d704 |
52 | $mymail->addCc($cc); |
5e2307dc |
53 | $mymail->setTxtBody(Env::v('mailbody')); |
0337d704 |
54 | $mymail->send(); |
55 | } |
56 | |
57 | function switch_bestalias($uid, $loginbis) { |
0337d704 |
58 | // check if loginbis was the bestalias |
08cce2ff |
59 | $res = XDB::query("SELECT alias FROM aliases WHERE id = {?} AND FIND_IN_SET('bestalias', flags)", $uid); |
0337d704 |
60 | $bestalias = $res->fetchOneCell(); |
61 | if ($bestalias && $bestalias != $loginbis) return false; |
eaf30d86 |
62 | |
0337d704 |
63 | // select the shortest alias still alive |
08cce2ff |
64 | $res = XDB::query("SELECT alias FROM aliases WHERE id = {?} AND alias != {?} AND expire IS NULL ORDER BY LENGTH(alias) LIMIT 1", $uid, $loginbis); |
0337d704 |
65 | $newbest = $res->fetchOneCell(); |
66 | // change the bestalias flag |
08cce2ff |
67 | XDB::execute("UPDATE aliases SET flags = (flags & (255 - 1)) | IF(alias = {?}, 1, 0) WHERE id = {?}", $newbest, $uid); |
0337d704 |
68 | |
69 | return $newbest; |
70 | } |
71 | |
a7de4ef7 |
72 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 |
73 | ?> |