Adapts broken addresses processing to new mail chain.
[platal.git] / include / validations / broken.inc.php
CommitLineData
0d693e2f 1<?php
2/***************************************************************************
12262f13 3 * Copyright (C) 2003-2011 Polytechnique.org *
0d693e2f 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
23class BrokenReq extends Validate
24{
25 // {{{ properties
26
5daf68f6 27 public $m_user;
612a2d8a 28 public $m_comment;
5daf68f6 29 public $m_email;
0d693e2f 30
0381e170 31 private $m_reactive = false;
32
faefdbb7
SJ
33 public $rules = "Accepter si l'adresse email parait correcte, et pas absurde (ou si le marketeur est de confiance).
34 Si le demandeur marque sa propre adresse email, refuser dans tous les cas.
a7de4ef7 35 Si l'adresse proposée est surveillée, refuser.
2abaa1e5 36 Si le compte associé est désactivé, étudier le cas en fonction de la raison de la désactivation.";
0d693e2f 37 // }}}
38 // {{{ constructor
39
26ba053e 40 public function __construct(User $sender, User $user, $email, $comment = null)
0d693e2f 41 {
612a2d8a 42 parent::__construct($sender, false, 'broken');
532c06cf 43 $this->m_user = &$user;
0d693e2f 44 $this->m_comment = trim($comment);
5daf68f6 45 $this->m_email = $email;
0d693e2f 46 }
47
48 // }}}
49 // {{{ function formu()
50
612a2d8a 51 public function formu()
0d693e2f 52 {
53 return 'include/form.valid.broken.tpl';
54 }
55
56 // }}}
57 // {{{ function _mail_subj
eaf30d86 58
612a2d8a 59 protected function _mail_subj()
0d693e2f 60 {
5daf68f6 61 return "[Polytechnique.org] Récupération de {$this->m_user->fullName()} ({$this->m_user->promo()})";
0d693e2f 62 }
63
64 // }}}
65 // {{{ function _mail_body
66
612a2d8a 67 protected function _mail_body($isok)
0d693e2f 68 {
0381e170 69 if ($isok && !$this->m_reactive) {
5daf68f6
VZ
70 return " Un email de contact vient d'être envoyé à {$this->m_user->fullName()}"
71 . " ({$this->m_user->promo()}) pour confirmer sa volonté de"
72 . " mettre à jour sa redirection Polytechnique.org !\n\n"
73 . "Merci de ta participation !\n";
0381e170 74 } elseif ($isok) {
5daf68f6 75 return " L'adresse de redirection {$this->m_email} de {$this->m_user->fullName()} ({$this->m_user->promo()}) "
faefdbb7 76 ."vient d'être réactivée. Un email lui a été envoyé pour l'en informer.\n\n"
0381e170 77 ."Merci de ta participation !\n";
0d693e2f 78 } else {
5daf68f6 79 return " Nous n'utiliserons pas cette adresse pour contacter {$this->m_user->fullName()} ({$this->m_user->promo()}).";
0d693e2f 80 }
81 }
82
83 // }}}
84 // {{{ function commit()
85
612a2d8a 86 public function commit()
0d693e2f 87 {
88 global $globals;
5daf68f6 89 $email = $this->m_user->bestEmail();
0381e170 90
a9fd3272
SJ
91 XDB::execute('UPDATE email_redirect_account
92 SET flags = \'active\', broken_level = 2
93 WHERE uid = {?} AND redirect = {?}',
94 $this->m_user->id(), $this->m_email);
0381e170 95 if (XDB::affectedRows() > 0) {
96 $this->m_reactive = true;
97 $mailer = new PlMailer();
1d55fe45 98 $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>');
0381e170 99 $mailer->addTo($email);
5daf68f6 100 $mailer->setSubject("Mise à jour de ton adresse {$email}");
0381e170 101 $mailer->setTxtBody(wordwrap("Cher Camarade,\n\n"
5daf68f6
VZ
102 . "Ton adresse {$email} étant en panne et ayant été informés que ta redirection {$this->m_email}, jusqu'à présent inactive, "
103 . "est fonctionnelle, nous venons de réactiver cette adresse.\n\n"
104 . "N'hésite pas à aller gérer toi-même tes redirections en te rendant à la page :\n"
105 . "https://www.polytechnique.org/emails/redirect\n"
106 . "Si tu as perdu ton mot de passe d'accès au site, tu peux également effectuer la procédure de récupération à l'adresse :\n"
107 . "https://www.polytechnique.org/recovery\n\n"
108 . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n"));
0381e170 109 $mailer->send();
110 return true;
111 }
eaf30d86 112
5daf68f6 113 if ($this->m_user->email) {
0d693e2f 114 $subject = "Ton adresse $email semble ne plus fonctionner";
a7de4ef7 115 $reason = "Nous avons été informés que ton adresse $email ne fonctionne plus correctement par un camarade";
0d693e2f 116 } else {
a9fd3272
SJ
117 $res = XDB::iterRow('SELECT redirect
118 FROM email_redirect_account
119 WHERE uid = {?} AND flags = \'broken\'',
120 $this->m_user->id());
0d693e2f 121 $redirect = array();
122 while (list($red) = $res->next()) {
123 list(, $redirect[]) = explode('@', $red);
124 }
125 $subject = "Ton adresse $email ne fonctionne plus";
fe1f0019 126 $reason = "Ton adresse $email ne fonctionne plus";
0d693e2f 127 if (!count($redirect)) {
128 $reason .= '.';
129 } elseif (count($redirect) == 1) {
0b79c292 130 $reason .= ' car sa redirection vers ' . $redirect[0] . ' est hors-service depuis plusieurs mois.';
0d693e2f 131 } else {
eaf30d86 132 $reason .= ' car ses redirections vers ' . implode(', ', $redirect)
0d693e2f 133 . ' sont hors-services depuis plusieurs mois.';
134 }
135 }
5daf68f6 136 $body = ($this->m_user->isFemale() ? 'Chère ' : 'Cher ') . $this->m_user->displayName() . ",\n\n"
0d693e2f 137 . $reason . "\n\n"
a7de4ef7 138 . "L'adresse {$this->m_email} nous a été communiquée, veux-tu que cette adresse devienne ta nouvelle "
80e89cb5 139 . "adresse de redirection ? Si oui, envoie nous des informations qui "
2abaa1e5 140 . "nous permettront de nous assurer de ton identité (par exemple ta date de naissance et ta promotion).\n\n"
0b79c292 141 . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n";
0d693e2f 142 $body = wordwrap($body, 78);
143 $mailer = new PlMailer();
1d55fe45 144 $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>');
0d693e2f 145 $mailer->addTo($this->m_email);
146 $mailer->setSubject($subject);
147 $mailer->setTxtBody($body);
148 return $mailer->send();
149 }
150
151 // }}}
152}
153
a7de4ef7 154// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0d693e2f 155?>