Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
0337d704 | 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 | ||
0337d704 | 22 | // {{{ class HomonymeReq |
23 | ||
24 | class HomonymeReq extends Validate | |
25 | { | |
26 | // {{{ properties | |
eaf30d86 | 27 | |
612a2d8a | 28 | public $loginbis; |
0337d704 | 29 | |
612a2d8a | 30 | public $warning = true; |
0337d704 | 31 | |
64b8f057 | 32 | public $homonymes_hruid; |
0337d704 | 33 | |
6e828e47 | 34 | public $rules = "Accepter, sauf cas particulier d'utilisateur dont l'homonymie est traité plus … manuellement."; |
0337d704 | 35 | |
36 | // }}} | |
37 | // {{{ constructor | |
eaf30d86 | 38 | |
64b8f057 | 39 | public function __construct(User &$_user, $_loginbis, $_homonymes_hruid, $warning=true) |
0337d704 | 40 | { |
0337d704 | 41 | $this->warning = $warning; |
42 | ||
5daf68f6 | 43 | parent::__construct($_user, true, $this->title()); |
0337d704 | 44 | |
45 | $this->refuse = false; | |
0337d704 | 46 | $this->loginbis = $_loginbis; |
64b8f057 | 47 | $this->homonymes_hruid = $_homonymes_hruid; |
0337d704 | 48 | } |
eaf30d86 | 49 | |
0337d704 | 50 | // }}} |
51 | // {{{ title() | |
eaf30d86 | 52 | |
612a2d8a | 53 | private function title() |
54 | { | |
5daf68f6 | 55 | return ($this->warning ? 'alerte alias' : 'robot répondeur'); |
0337d704 | 56 | } |
57 | ||
58 | // }}} | |
0337d704 | 59 | // {{{ function formu() |
60 | ||
612a2d8a | 61 | public function formu() |
62 | { | |
63 | return 'include/form.valid.homonymes.tpl'; | |
64 | } | |
0337d704 | 65 | |
66 | // }}} | |
67 | // {{{ function _mail_subj | |
68 | ||
612a2d8a | 69 | protected function _mail_subj() |
0337d704 | 70 | { |
115c90db | 71 | global $globals; |
5daf68f6 VZ |
72 | return "[Polytechnique.org/Support] " |
73 | . ($this->warning ? "Dans une semaine : suppression de l'alias " : "Mise en place du robot") | |
74 | . " $loginbis@" . $globals->mail->domain; | |
0337d704 | 75 | } |
76 | ||
77 | // }}} | |
78 | // {{{ function _mail_body | |
eaf30d86 | 79 | |
612a2d8a | 80 | protected function _mail_body($isok) |
0337d704 | 81 | { |
82 | global $globals; | |
83 | return | |
84 | " | |
faefdbb7 SJ |
85 | Comme nous t'en avons informé par email il y a quelques temps, |
86 | pour respecter nos engagements en terme d'adresses email devinables, | |
a7de4ef7 | 87 | tu te verras bientôt retirer l'alias ".$this->loginbis."@".$globals->mail->domain." pour |
5daf68f6 | 88 | ne garder que " . $this->user->forlifeEmail() . ". |
0337d704 | 89 | |
a7de4ef7 | 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." | |
0337d704 | 92 | est ambigu pour des raisons d'homonymie et signalera ton email exact."; |
93 | } | |
94 | ||
95 | // }}} | |
96 | // {{{ function sendmail() | |
97 | ||
612a2d8a | 98 | protected function sendmail($isok) |
0337d704 | 99 | { |
100 | if (!$isok) return false; | |
101 | global $globals; | |
1e33266a | 102 | $mailer = new PlMailer; |
5daf68f6 VZ |
103 | $cc = "support+homonyme@" . $globals->mail->domain; |
104 | $from = "\"Support Polytechnique.org\" <$cc>"; | |
0337d704 | 105 | $mailer->setSubject($this->_mail_subj()); |
5daf68f6 VZ |
106 | $mailer->setFrom($from); |
107 | $mailer->addTo("\"{$this->user->fullName()}\" <{$this->user->bestEmail()}>"); | |
0337d704 | 108 | $mailer->addCc($cc); |
109 | ||
5daf68f6 | 110 | $body = $this->user->displayName() . ",\n\n" |
0337d704 | 111 | . $this->_mail_body($isok) |
5e2307dc | 112 | . (Env::has('comm') ? "\n\n".Env::v('comm') : '') |
780bc68d | 113 | . "\n\nCordialement,\n\n-- \nL'équipe de Polytechnique.org\n"; |
0337d704 | 114 | |
115 | $mailer->setTxtBody(wordwrap($body)); | |
116 | $mailer->send(); | |
117 | } | |
118 | // }}} | |
119 | // {{{ function commit() | |
eaf30d86 | 120 | |
612a2d8a | 121 | public function commit() |
0337d704 | 122 | { |
191711d5 FB |
123 | Platal::load('admin', 'homonyms.inc.php'); |
124 | switch_bestalias($this->user, $this->loginbis); | |
0337d704 | 125 | if (!$this->warning) { |
5daf68f6 | 126 | XDB::execute("UPDATE aliases SET type = 'homonyme', expire = NOW() WHERE alias = {?}", $this->loginbis); |
05240425 | 127 | XDB::execute("REPLACE INTO homonyms (homonyme_id, uid) VALUES({?}, {?})", $this->user->id(), $this->user->id()); |
0337d704 | 128 | } |
eaf30d86 | 129 | |
0337d704 | 130 | return true; |
131 | } | |
132 | ||
133 | // }}} | |
134 | } | |
135 | ||
136 | // }}} | |
137 | ||
a7de4ef7 | 138 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 139 | ?> |