Merge branch 'xorg/maint'
[platal.git] / include / validations / broken.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2014 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
23 class BrokenReq extends Validate
24 {
25 // {{{ properties
26
27 public $m_user;
28 public $m_comment;
29 public $m_email;
30
31 private $m_reactive = false;
32
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.
35 Si l'adresse proposée est surveillée, refuser.
36 Si le compte associé est désactivé, étudier le cas en fonction de la raison de la désactivation.";
37 // }}}
38 // {{{ constructor
39
40 public function __construct(User $sender, User $user, $email, $comment = null)
41 {
42 parent::__construct($sender, false, 'broken');
43 $this->m_user = &$user;
44 $this->m_comment = trim($comment);
45 $this->m_email = $email;
46 }
47
48 // }}}
49 // {{{ function formu()
50
51 public function formu()
52 {
53 return 'include/form.valid.broken.tpl';
54 }
55
56 // }}}
57 // {{{ function _mail_subj
58
59 protected function _mail_subj()
60 {
61 return "[Polytechnique.org] Récupération de {$this->m_user->fullName()} ({$this->m_user->promo()})";
62 }
63
64 // }}}
65 // {{{ function _mail_body
66
67 protected function _mail_body($isok)
68 {
69 $your = ($this->formal ? 'votre' : 'ta');
70 if ($isok && !$this->m_reactive) {
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"
74 . "Merci de $your participation !\n";
75 } elseif ($isok) {
76 return " L'adresse de redirection {$this->m_email} de {$this->m_user->fullName()} ({$this->m_user->promo()}) "
77 ."vient d'être réactivée. Un email lui a été envoyé pour l'en informer.\n\n"
78 ."Merci de $your participation !\n";
79 } else {
80 return " Nous n'utiliserons pas cette adresse pour contacter {$this->m_user->fullName()} ({$this->m_user->promo()}).";
81 }
82 }
83
84 // }}}
85 // {{{ function commit()
86
87 public function commit()
88 {
89 global $globals;
90 $email = $this->m_user->bestEmail();
91
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);
96 if (XDB::affectedRows() > 0) {
97 $this->m_reactive = true;
98 $mailer = new PlMailer();
99 $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>');
100 $mailer->addTo($email);
101 $mailer->setSubject("Mise à jour de ton adresse {$email}");
102 $mailer->setTxtBody(wordwrap("Cher Camarade,\n\n"
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"));
110 $mailer->send();
111 return true;
112 }
113
114 if ($this->m_user->email) {
115 $subject = "Ton adresse $email semble ne plus fonctionner";
116 $reason = "Nous avons été informés que ton adresse $email ne fonctionne plus correctement par un camarade";
117 } else {
118 $res = XDB::iterRow('SELECT redirect
119 FROM email_redirect_account
120 WHERE uid = {?} AND flags = \'broken\'',
121 $this->m_user->id());
122 $redirect = array();
123 while (list($red) = $res->next()) {
124 list(, $redirect[]) = explode('@', $red);
125 }
126 $subject = "Ton adresse $email ne fonctionne plus";
127 $reason = "Ton adresse $email ne fonctionne plus";
128 if (!count($redirect)) {
129 $reason .= '.';
130 } elseif (count($redirect) == 1) {
131 $reason .= ' car sa redirection vers ' . $redirect[0] . ' est hors-service depuis plusieurs mois.';
132 } else {
133 $reason .= ' car ses redirections vers ' . implode(', ', $redirect)
134 . ' sont hors-services depuis plusieurs mois.';
135 }
136 }
137 $body = ($this->m_user->isFemale() ? 'Chère ' : 'Cher ') . $this->m_user->displayName() . ",\n\n"
138 . $reason . "\n\n"
139 . "L'adresse {$this->m_email} nous a été communiquée, veux-tu que cette adresse devienne ta nouvelle "
140 . "adresse de redirection ? Si oui, envoie nous des informations qui "
141 . "nous permettront de nous assurer de ton identité (par exemple ta date de naissance et ta promotion).\n\n"
142 . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n";
143 $body = wordwrap($body, 78);
144 $mailer = new PlMailer();
145 $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>');
146 $mailer->addTo($this->m_email);
147 $mailer->setSubject($subject);
148 $mailer->setTxtBody($body);
149 return $mailer->send();
150 }
151
152 // }}}
153 }
154
155 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
156 ?>