changelog entry.
[platal.git] / htdocs / emails / broken.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 require_once('xorg.inc.php');
23 new_skinned_page('emails/broken.tpl',AUTH_COOKIE);
24 $page->assign('xorg_title','Polytechnique.org - Patte cassée');
25 require_once('emails.inc.php');
26
27 if (Get::has('email') && Get::has('action')) {
28 $email = valide_email(Get::get('email'));
29 // vérifications d'usage
30 $sel = $globals->xdb->query(
31 "SELECT e.uid, a.alias
32 FROM emails AS e
33 INNER JOIN auth_user_md5 AS u ON e.uid = u.user_id
34 INNER JOIN aliases AS a ON (e.uid = a.id AND type!='homonyme' AND FIND_IN_SET('bestalias',a.flags))
35 WHERE e.email={?}", $email);
36
37 if (list($uid, $dest) = $sel->fetchOneRow()) {
38 // envoi du mail
39 $message = "Bonjour !
40
41 Ce mail a été généré automatiquement par le service de patte cassée de
42 Polytechnique.org car un autre utilisateur, ".Session::get('prenom').' '.Session::get('nom').",
43 nous a signalé qu'en t'envoyant un mail, il avait reçu un message d'erreur
44 indiquant que ton adresse de redirection $email
45 ne fonctionnait plus !
46
47 Nous te suggérons de vérifier cette adresse, et le cas échéant de mettre
48 à jour sur le site <{$globals->baseurl}/emails.php> tes adresses
49 de redirection...
50
51 Pour plus de rensignements sur le service de patte cassée, n'hésites pas à
52 consulter la page <{$globals->baseurl}/emails/broken.php>.
53
54
55 A bientôt sur Polytechnique.org !
56 L'équipe d'administration <support@polytechnique.org>";
57
58 require_once("diogenes/diogenes.hermes.inc.php");
59 $mail = new HermesMailer();
60 $mail->setFrom('"Polytechnique.org" <support@polytechnique.org>');
61 $mail->addTo("$dest@polytechnique.org");
62 $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!");
63 $mail->setTxtBody($message);
64 $mail->send();
65 $page->trig("Mail envoyé ! :o)");
66 }
67 } elseif (Post::has('email')) {
68 $email = valide_email(Post::get('email'));
69
70 list(,$fqdn) = explode('@', $email);
71 $fqdn = strtolower($fqdn);
72 if ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org' || $fqdn == 'm4x.org' || $fqdn == 'melix.net') {
73 $page->assign('neuneu', true);
74 } else {
75 $page->assign('email',$email);
76 $sel = $globals->xdb->query(
77 "SELECT e1.uid, e1.panne != 0 AS panne, count(e2.uid) AS nb_mails, u.nom, u.prenom, u.promo
78 FROM emails as e1
79 LEFT JOIN emails as e2 ON(e1.uid = e2.uid AND FIND_IN_SET('active', e2.flags) AND e1.email != e2.email)
80 INNER JOIN auth_user_md5 as u ON(e1.uid = u.user_id)
81 WHERE e1.email = {?}
82 GROUP BY e1.uid", $email);
83 if ($x = $sel->fetchOneAssoc()) {
84 // on écrit dans la base que l'adresse est cassée
85 if (!$x['panne']) {
86 $globals->xdb->execute("UPDATE emails SET panne=NOW() WHERE email = {?}", $email);
87 }
88 $page->assign_by_ref('x', $x);
89 }
90 }
91 }
92
93 $page->run();
94 ?>