Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 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; |
27 | public $raison; | |
28 | public $unique = true; | |
0337d704 | 29 | |
6a4f0f01 FB |
30 | public $old = ''; |
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 |
532c06cf | 38 | public function __construct(User &$_user, $_alias, $_raison, $_public, $_stamp=0) |
0337d704 | 39 | { |
40 | global $globals; | |
5daf68f6 | 41 | parent::__construct($_user, true, 'alias', $_stamp); |
0337d704 | 42 | $this->alias = $_alias.'@'.$globals->mail->alias_dom; |
43 | $this->raison = $_raison; | |
44 | $this->public = $_public; | |
f55843d1 | 45 | $this->old = $_user->emailAlias(); |
5daf68f6 VZ |
46 | if (empty($this->old)) { |
47 | unset($this->old); | |
48 | } | |
0337d704 | 49 | } |
50 | ||
6a4f0f01 | 51 | // function get_request() {{{2 |
612a2d8a | 52 | static public function get_request($uid) |
0337d704 | 53 | { |
5daf68f6 | 54 | return parent::get_typed_request($uid, 'alias'); |
0337d704 | 55 | } |
56 | ||
6a4f0f01 | 57 | // function formu() {{{2 |
612a2d8a | 58 | public function formu() |
59 | { | |
60 | return 'include/form.valid.aliases.tpl'; | |
61 | } | |
0337d704 | 62 | |
6a4f0f01 | 63 | // function _mail_subj {{{2 |
612a2d8a | 64 | protected function _mail_subj() |
0337d704 | 65 | { |
66 | return "[Polytechnique.org/MELIX] Demande de l'alias {$this->alias}"; | |
67 | } | |
68 | ||
6a4f0f01 | 69 | // function _mail_body {{{2 |
612a2d8a | 70 | protected function _mail_body($isok) |
0337d704 | 71 | { |
72 | if ($isok) { | |
6a4f0f01 | 73 | return " L'adresse email {$this->alias} que tu avais demandée vient d'être créée, tu peux désormais l'utiliser à ta convenance." |
e46cf8c4 | 74 | . ($this->public == 'public' ? ' À ta demande, cette adresse apparaît maintenant sur ta fiche.' : ''); |
0337d704 | 75 | } else { |
a7de4ef7 | 76 | return " La demande que tu avais faite pour l'alias {$this->alias} a été refusée."; |
0337d704 | 77 | } |
78 | } | |
79 | ||
6a4f0f01 FB |
80 | // function commit() {{{2 |
81 | public function commit() | |
4c6fce94 | 82 | { |
6a4f0f01 FB |
83 | if ($this->user->hasProfile()) { |
84 | XDB::execute('UPDATE profiles | |
85 | SET alias_pub = {?} | |
86 | WHERE pid = {?}', | |
87 | $this->public, $this->user->profile()->id()); | |
4c6fce94 | 88 | } |
0337d704 | 89 | |
90 | if ($this->old) { | |
6a4f0f01 FB |
91 | return XDB::execute('UPDATE virtual |
92 | SET alias = {?} | |
93 | WHERE alias = {?}', | |
29d908fa | 94 | $this->alias, $this->old); |
0337d704 | 95 | } else { |
6a4f0f01 FB |
96 | XDB::execute('INSERT INTO virtual |
97 | SET alias = {?}, type=\'user\'', | |
98 | $this->alias); | |
8b83a166 | 99 | $vid = XDB::insertId(); |
6a4f0f01 FB |
100 | return XDB::execute('INSERT INTO virtual_redirect (vid, redirect) |
101 | VALUES ({?}, {?})', | |
102 | $vid, $this->user->forlifeEmail()); | |
0337d704 | 103 | } |
104 | } | |
0337d704 | 105 | } |
106 | ||
a7de4ef7 | 107 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 108 | ?> |