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