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