| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 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 | require_once('validations.inc.php'); |
| 23 | // {{{ class HomonymeReq |
| 24 | |
| 25 | class HomonymeReq extends Validate |
| 26 | { |
| 27 | // {{{ properties |
| 28 | |
| 29 | var $loginbis; |
| 30 | |
| 31 | var $warning = true; |
| 32 | |
| 33 | var $homonymes_forlife; |
| 34 | |
| 35 | var $rules = "Accepter, sauf cas particulier d'utilisateur dont l'homonymie est traité plus ... manuellement"; |
| 36 | |
| 37 | // }}} |
| 38 | // {{{ constructor |
| 39 | |
| 40 | function HomonymeReq($_uid, $_loginbis, $_homonymes_forlife, $warning=true) |
| 41 | { |
| 42 | global $global; |
| 43 | |
| 44 | $this->warning = $warning; |
| 45 | |
| 46 | $this->Validate($_uid, true, $this->title()); |
| 47 | |
| 48 | $this->refuse = false; |
| 49 | |
| 50 | $this->loginbis = $_loginbis; |
| 51 | |
| 52 | $this->homonymes_forlife = $_homonymes_forlife; |
| 53 | |
| 54 | } |
| 55 | |
| 56 | // }}} |
| 57 | // {{{ title() |
| 58 | |
| 59 | function title() { |
| 60 | return $this->warning?'alerte alias':'robot répondeur'; |
| 61 | } |
| 62 | |
| 63 | // }}} |
| 64 | // {{{ function formu() |
| 65 | |
| 66 | function formu() |
| 67 | { return 'include/form.valid.homonymes.tpl'; } |
| 68 | |
| 69 | // }}} |
| 70 | // {{{ function _mail_subj |
| 71 | |
| 72 | function _mail_subj() |
| 73 | { |
| 74 | return "[Polytechnique.org/Support] ".($this->warning?"Dans une semaine : suppression de l'alias":"Mise en place du robot")." $loginbis@polytechnique.org"; |
| 75 | } |
| 76 | |
| 77 | // }}} |
| 78 | // {{{ function _mail_body |
| 79 | |
| 80 | function _mail_body($isok) |
| 81 | { |
| 82 | global $globals; |
| 83 | return |
| 84 | " |
| 85 | Comme nous t'en avons informé par mail il y a quelques temps, |
| 86 | pour respecter nos engagements en terme d'adresses e-mail devinables, |
| 87 | tu te verras bientôt retirer l'alias ".$this->loginbis."@".$globals->mail->domain." pour |
| 88 | ne garder que ".$this->forlife."@".$globals->mail->domain.". |
| 89 | |
| 90 | Toute personne qui écrira à ".$this->loginbis."@".$globals->mail->domain." recevra la |
| 91 | réponse d'un robot qui l'informera que ".$this->loginbis."@".$globals->mail->domain." |
| 92 | est ambigu pour des raisons d'homonymie et signalera ton email exact."; |
| 93 | } |
| 94 | |
| 95 | // }}} |
| 96 | // {{{ function sendmail() |
| 97 | |
| 98 | function sendmail($isok) |
| 99 | { |
| 100 | if (!$isok) return false; |
| 101 | global $globals; |
| 102 | $mailer = new PlMailer; |
| 103 | $cc = "support+homonyme@".$globals->mail->domain; |
| 104 | $FROM = "\"Support Polytechnique.org\" <$cc>"; |
| 105 | $mailer->setSubject($this->_mail_subj()); |
| 106 | $mailer->setFrom($FROM); |
| 107 | $mailer->addTo("\"{$this->prenom} {$this->nom}\" <{$this->bestalias}@{$globals->mail->domain}>"); |
| 108 | $mailer->addCc($cc); |
| 109 | |
| 110 | $body = $this->prenom.",\n\n" |
| 111 | . $this->_mail_body($isok) |
| 112 | . (Env::has('comm') ? "\n\n".Env::v('comm') : '') |
| 113 | . "\n\nCordialement,\nL'équipe Polytechnique.org\n"; |
| 114 | |
| 115 | $mailer->setTxtBody(wordwrap($body)); |
| 116 | $mailer->send(); |
| 117 | } |
| 118 | // }}} |
| 119 | // {{{ function commit() |
| 120 | |
| 121 | function commit() |
| 122 | { |
| 123 | require_once('homonymes.inc.php'); |
| 124 | |
| 125 | switch_bestalias($this->uid, $this->loginbis); |
| 126 | if (!$this->warning) { |
| 127 | XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $this->loginbis); |
| 128 | XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $this->uid, $this->uid); |
| 129 | } |
| 130 | |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | // }}} |
| 135 | } |
| 136 | |
| 137 | // }}} |
| 138 | |
| 139 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
| 140 | ?> |