Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
c441aabe | 3 | * Copyright (C) 2003-2014 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 | ||
6a4f0f01 | 22 | // class AliasReq {{{1 |
0337d704 | 23 | class AliasReq extends Validate |
24 | { | |
6a4f0f01 | 25 | // properties {{{2 |
612a2d8a | 26 | public $alias; |
b4503762 | 27 | public $reason; |
612a2d8a | 28 | public $unique = true; |
0337d704 | 29 | |
b4503762 | 30 | public $old; |
6a4f0f01 | 31 | public $public = 'private'; |
eaf30d86 | 32 | |
6e828e47 | 33 | public $rules = "Interdire ce qui peut nous servir (virus@, postmaster@…), |
0337d704 | 34 | les alias vulgaires, et les prenom.nom (sauf si c'est pour l'utilisateur prenom.nom). |
6e828e47 | 35 | Pas de contrainte pour les tirets ou les points, en revanche le souligné (_) est interdit."; |
0337d704 | 36 | |
6a4f0f01 | 37 | // constructor {{{2 |
b4503762 | 38 | public function __construct(User $_user, $_alias, $_reason, $_public, $_old, $_stamp = 0) |
0337d704 | 39 | { |
40 | global $globals; | |
5daf68f6 | 41 | parent::__construct($_user, true, 'alias', $_stamp); |
b4503762 SJ |
42 | $this->alias = $_alias; |
43 | $this->reason = $_reason; | |
0337d704 | 44 | $this->public = $_public; |
b4503762 | 45 | $this->old = $_old; |
0337d704 | 46 | } |
47 | ||
6a4f0f01 | 48 | // function get_request() {{{2 |
612a2d8a | 49 | static public function get_request($uid) |
0337d704 | 50 | { |
5daf68f6 | 51 | return parent::get_typed_request($uid, 'alias'); |
0337d704 | 52 | } |
53 | ||
6a4f0f01 | 54 | // function formu() {{{2 |
612a2d8a | 55 | public function formu() |
56 | { | |
57 | return 'include/form.valid.aliases.tpl'; | |
58 | } | |
0337d704 | 59 | |
6a4f0f01 | 60 | // function _mail_subj {{{2 |
612a2d8a | 61 | protected function _mail_subj() |
0337d704 | 62 | { |
b4503762 SJ |
63 | global $globals; |
64 | return "[Polytechnique.org/MELIX] Demande de l'alias {$this->alias}@{$globals->mail->alias_dom}"; | |
0337d704 | 65 | } |
66 | ||
6a4f0f01 | 67 | // function _mail_body {{{2 |
612a2d8a | 68 | protected function _mail_body($isok) |
0337d704 | 69 | { |
b4503762 | 70 | global $globals; |
0337d704 | 71 | if ($isok) { |
b4503762 | 72 | return " L'adresse email {$this->alias}@{$globals->mail->alias_dom} que tu avais demandée vient d'être créée, tu peux désormais l'utiliser à ta convenance." |
e46cf8c4 | 73 | . ($this->public == 'public' ? ' À ta demande, cette adresse apparaît maintenant sur ta fiche.' : ''); |
0337d704 | 74 | } else { |
b4503762 | 75 | return " La demande que tu avais faite pour l'alias {$this->alias}@{$globals->mail->alias_dom} a été refusée."; |
0337d704 | 76 | } |
77 | } | |
78 | ||
6a4f0f01 FB |
79 | // function commit() {{{2 |
80 | public function commit() | |
4c6fce94 | 81 | { |
6a4f0f01 FB |
82 | if ($this->user->hasProfile()) { |
83 | XDB::execute('UPDATE profiles | |
84 | SET alias_pub = {?} | |
85 | WHERE pid = {?}', | |
86 | $this->public, $this->user->profile()->id()); | |
4c6fce94 | 87 | } |
0337d704 | 88 | |
89 | if ($this->old) { | |
08d33afc SJ |
90 | $success = XDB::execute('UPDATE email_source_account |
91 | SET email = {?} | |
92 | WHERE uid = {?} AND type = \'alias_aux\'', | |
93 | $this->alias, $this->user->id()); | |
0337d704 | 94 | } else { |
b4503762 | 95 | $success = XDB::execute('INSERT INTO email_source_account (email, uid, domain, type, flags) |
08d33afc | 96 | SELECT {?}, {?}, id, \'alias_aux\', \'\' |
b4503762 SJ |
97 | FROM email_virtual_domains |
98 | WHERE name = {?}', | |
08d33afc | 99 | $this->alias, $this->user->id(), Platal::globals()->mail->alias_dom); |
0337d704 | 100 | } |
b4503762 | 101 | |
b4d831e0 SJ |
102 | if ($success) { |
103 | // Update the local User object, to pick up the new bestalias. | |
ff231bdd | 104 | require_once 'emails.inc.php'; |
b4d831e0 SJ |
105 | fix_bestalias($this->user); |
106 | $this->user = User::getSilentWithUID($this->user->id()); | |
107 | } | |
108 | ||
b4503762 | 109 | return $success; |
0337d704 | 110 | } |
0337d704 | 111 | } |
112 | ||
a7de4ef7 | 113 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 114 | ?> |