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