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