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