Happy New Year !
[platal.git] / include / validations / broken.inc.php
CommitLineData
0d693e2f 1<?php
2/***************************************************************************
ba6ae046 3 * Copyright (C) 2003-2013 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 {
a3923909 69 $your = ($this->formal ? 'votre' : 'ta');
0381e170 70 if ($isok && !$this->m_reactive) {
5daf68f6
VZ
71 return " Un email de contact vient d'être envoyé à {$this->m_user->fullName()}"
72 . " ({$this->m_user->promo()}) pour confirmer sa volonté de"
73 . " mettre à jour sa redirection Polytechnique.org !\n\n"
a3923909 74 . "Merci de $your participation !\n";
0381e170 75 } elseif ($isok) {
5daf68f6 76 return " L'adresse de redirection {$this->m_email} de {$this->m_user->fullName()} ({$this->m_user->promo()}) "
faefdbb7 77 ."vient d'être réactivée. Un email lui a été envoyé pour l'en informer.\n\n"
a3923909 78 ."Merci de $your participation !\n";
0d693e2f 79 } else {
5daf68f6 80 return " Nous n'utiliserons pas cette adresse pour contacter {$this->m_user->fullName()} ({$this->m_user->promo()}).";
0d693e2f 81 }
82 }
83
84 // }}}
85 // {{{ function commit()
86
612a2d8a 87 public function commit()
0d693e2f 88 {
89 global $globals;
5daf68f6 90 $email = $this->m_user->bestEmail();
0381e170 91
a9fd3272
SJ
92 XDB::execute('UPDATE email_redirect_account
93 SET flags = \'active\', broken_level = 2
94 WHERE uid = {?} AND redirect = {?}',
95 $this->m_user->id(), $this->m_email);
0381e170 96 if (XDB::affectedRows() > 0) {
97 $this->m_reactive = true;
98 $mailer = new PlMailer();
1d55fe45 99 $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>');
0381e170 100 $mailer->addTo($email);
5daf68f6 101 $mailer->setSubject("Mise à jour de ton adresse {$email}");
0381e170 102 $mailer->setTxtBody(wordwrap("Cher Camarade,\n\n"
5daf68f6
VZ
103 . "Ton adresse {$email} étant en panne et ayant été informés que ta redirection {$this->m_email}, jusqu'à présent inactive, "
104 . "est fonctionnelle, nous venons de réactiver cette adresse.\n\n"
105 . "N'hésite pas à aller gérer toi-même tes redirections en te rendant à la page :\n"
106 . "https://www.polytechnique.org/emails/redirect\n"
107 . "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"
108 . "https://www.polytechnique.org/recovery\n\n"
109 . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n"));
0381e170 110 $mailer->send();
111 return true;
112 }
eaf30d86 113
5daf68f6 114 if ($this->m_user->email) {
0d693e2f 115 $subject = "Ton adresse $email semble ne plus fonctionner";
a7de4ef7 116 $reason = "Nous avons été informés que ton adresse $email ne fonctionne plus correctement par un camarade";
0d693e2f 117 } else {
a9fd3272
SJ
118 $res = XDB::iterRow('SELECT redirect
119 FROM email_redirect_account
120 WHERE uid = {?} AND flags = \'broken\'',
121 $this->m_user->id());
0d693e2f 122 $redirect = array();
123 while (list($red) = $res->next()) {
124 list(, $redirect[]) = explode('@', $red);
125 }
126 $subject = "Ton adresse $email ne fonctionne plus";
fe1f0019 127 $reason = "Ton adresse $email ne fonctionne plus";
0d693e2f 128 if (!count($redirect)) {
129 $reason .= '.';
130 } elseif (count($redirect) == 1) {
0b79c292 131 $reason .= ' car sa redirection vers ' . $redirect[0] . ' est hors-service depuis plusieurs mois.';
0d693e2f 132 } else {
eaf30d86 133 $reason .= ' car ses redirections vers ' . implode(', ', $redirect)
0d693e2f 134 . ' sont hors-services depuis plusieurs mois.';
135 }
136 }
5daf68f6 137 $body = ($this->m_user->isFemale() ? 'Chère ' : 'Cher ') . $this->m_user->displayName() . ",\n\n"
0d693e2f 138 . $reason . "\n\n"
a7de4ef7 139 . "L'adresse {$this->m_email} nous a été communiquée, veux-tu que cette adresse devienne ta nouvelle "
80e89cb5 140 . "adresse de redirection ? Si oui, envoie nous des informations qui "
2abaa1e5 141 . "nous permettront de nous assurer de ton identité (par exemple ta date de naissance et ta promotion).\n\n"
0b79c292 142 . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n";
0d693e2f 143 $body = wordwrap($body, 78);
144 $mailer = new PlMailer();
1d55fe45 145 $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>');
0d693e2f 146 $mailer->addTo($this->m_email);
147 $mailer->setSubject($subject);
148 $mailer->setTxtBody($body);
149 return $mailer->send();
150 }
151
152 // }}}
153}
154
a7de4ef7 155// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0d693e2f 156?>