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