Happy New Year!
[platal.git] / include / validations / broken.inc.php
CommitLineData
0d693e2f 1<?php
2/***************************************************************************
5e1513f6 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
532c06cf 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
5daf68f6
VZ
91 XDB::execute("UPDATE emails
92 SET flags = 'active', panne_level = 2
93 WHERE uid = {?} AND email = {?}", $this->m_user->id(), $this->m_email);
0381e170 94 if (XDB::affectedRows() > 0) {
95 $this->m_reactive = true;
96 $mailer = new PlMailer();
1d55fe45 97 $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>');
0381e170 98 $mailer->addTo($email);
5daf68f6 99 $mailer->setSubject("Mise à jour de ton adresse {$email}");
0381e170 100 $mailer->setTxtBody(wordwrap("Cher Camarade,\n\n"
5daf68f6
VZ
101 . "Ton adresse {$email} étant en panne et ayant été informés que ta redirection {$this->m_email}, jusqu'à présent inactive, "
102 . "est fonctionnelle, nous venons de réactiver cette adresse.\n\n"
103 . "N'hésite pas à aller gérer toi-même tes redirections en te rendant à la page :\n"
104 . "https://www.polytechnique.org/emails/redirect\n"
105 . "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"
106 . "https://www.polytechnique.org/recovery\n\n"
107 . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n"));
0381e170 108 $mailer->send();
109 return true;
110 }
eaf30d86 111
5daf68f6 112 if ($this->m_user->email) {
0d693e2f 113 $subject = "Ton adresse $email semble ne plus fonctionner";
a7de4ef7 114 $reason = "Nous avons été informés que ton adresse $email ne fonctionne plus correctement par un camarade";
0d693e2f 115 } else {
5daf68f6 116 $res = XDB::iterRow("SELECT email FROM emails WHERE uid = {?} AND flags = 'panne'", $this->m_user->id());
0d693e2f 117 $redirect = array();
118 while (list($red) = $res->next()) {
119 list(, $redirect[]) = explode('@', $red);
120 }
121 $subject = "Ton adresse $email ne fonctionne plus";
fe1f0019 122 $reason = "Ton adresse $email ne fonctionne plus";
0d693e2f 123 if (!count($redirect)) {
124 $reason .= '.';
125 } elseif (count($redirect) == 1) {
0b79c292 126 $reason .= ' car sa redirection vers ' . $redirect[0] . ' est hors-service depuis plusieurs mois.';
0d693e2f 127 } else {
eaf30d86 128 $reason .= ' car ses redirections vers ' . implode(', ', $redirect)
0d693e2f 129 . ' sont hors-services depuis plusieurs mois.';
130 }
131 }
5daf68f6 132 $body = ($this->m_user->isFemale() ? 'Chère ' : 'Cher ') . $this->m_user->displayName() . ",\n\n"
0d693e2f 133 . $reason . "\n\n"
a7de4ef7 134 . "L'adresse {$this->m_email} nous a été communiquée, veux-tu que cette adresse devienne ta nouvelle "
80e89cb5 135 . "adresse de redirection ? Si oui, envoie nous des informations qui "
2abaa1e5 136 . "nous permettront de nous assurer de ton identité (par exemple ta date de naissance et ta promotion).\n\n"
0b79c292 137 . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n";
0d693e2f 138 $body = wordwrap($body, 78);
139 $mailer = new PlMailer();
1d55fe45 140 $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>');
0d693e2f 141 $mailer->addTo($this->m_email);
142 $mailer->setSubject($subject);
143 $mailer->setTxtBody($body);
144 return $mailer->send();
145 }
146
147 // }}}
148}
149
a7de4ef7 150// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0d693e2f 151?>