| 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_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 | if ($isok && !$this->m_reactive) { |
| 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"; |
| 74 | } elseif ($isok) { |
| 75 | return " L'adresse de redirection {$this->m_email} de {$this->m_user->fullName()} ({$this->m_user->promo()}) " |
| 76 | ."vient d'être réactivée. Un email lui a été envoyé pour l'en informer.\n\n" |
| 77 | ."Merci de ta participation !\n"; |
| 78 | } else { |
| 79 | return " Nous n'utiliserons pas cette adresse pour contacter {$this->m_user->fullName()} ({$this->m_user->promo()})."; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // }}} |
| 84 | // {{{ function commit() |
| 85 | |
| 86 | public function commit() |
| 87 | { |
| 88 | global $globals; |
| 89 | $email = $this->m_user->bestEmail(); |
| 90 | |
| 91 | XDB::execute("UPDATE emails |
| 92 | SET flags = 'active', panne_level = 2 |
| 93 | WHERE uid = {?} AND email = {?}", $this->m_user->id(), $this->m_email); |
| 94 | if (XDB::affectedRows() > 0) { |
| 95 | $this->m_reactive = true; |
| 96 | $mailer = new PlMailer(); |
| 97 | $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>'); |
| 98 | $mailer->addTo($email); |
| 99 | $mailer->setSubject("Mise à jour de ton adresse {$email}"); |
| 100 | $mailer->setTxtBody(wordwrap("Cher Camarade,\n\n" |
| 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")); |
| 108 | $mailer->send(); |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | if ($this->m_user->email) { |
| 113 | $subject = "Ton adresse $email semble ne plus fonctionner"; |
| 114 | $reason = "Nous avons été informés que ton adresse $email ne fonctionne plus correctement par un camarade"; |
| 115 | } else { |
| 116 | $res = XDB::iterRow("SELECT email FROM emails WHERE uid = {?} AND flags = 'panne'", $this->m_user->id()); |
| 117 | $redirect = array(); |
| 118 | while (list($red) = $res->next()) { |
| 119 | list(, $redirect[]) = explode('@', $red); |
| 120 | } |
| 121 | $subject = "Ton adresse $email ne fonctionne plus"; |
| 122 | $reason = "Ton adresse $email ne fonctionne plus"; |
| 123 | if (!count($redirect)) { |
| 124 | $reason .= '.'; |
| 125 | } elseif (count($redirect) == 1) { |
| 126 | $reason .= ' car sa redirection vers ' . $redirect[0] . ' est hors-service depuis plusieurs mois.'; |
| 127 | } else { |
| 128 | $reason .= ' car ses redirections vers ' . implode(', ', $redirect) |
| 129 | . ' sont hors-services depuis plusieurs mois.'; |
| 130 | } |
| 131 | } |
| 132 | $body = ($this->m_user->isFemale() ? 'Chère ' : 'Cher ') . $this->m_user->displayName() . ",\n\n" |
| 133 | . $reason . "\n\n" |
| 134 | . "L'adresse {$this->m_email} nous a été communiquée, veux-tu que cette adresse devienne ta nouvelle " |
| 135 | . "adresse de redirection ? Si oui, envoie nous des informations qui " |
| 136 | . "nous permettront de nous assurer de ton identité (par exemple ta date de naissance et ta promotion).\n\n" |
| 137 | . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n"; |
| 138 | $body = wordwrap($body, 78); |
| 139 | $mailer = new PlMailer(); |
| 140 | $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>'); |
| 141 | $mailer->addTo($this->m_email); |
| 142 | $mailer->setSubject($subject); |
| 143 | $mailer->setTxtBody($body); |
| 144 | return $mailer->send(); |
| 145 | } |
| 146 | |
| 147 | // }}} |
| 148 | } |
| 149 | |
| 150 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 151 | ?> |