Commit | Line | Data |
---|---|---|
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 | ||
22 | // {{{ class AliasReq | |
23 | ||
24 | class AliasReq extends Validate | |
25 | { | |
26 | // {{{ properties | |
27 | ||
612a2d8a | 28 | public $alias; |
29 | public $raison; | |
30 | public $unique = true; | |
0337d704 | 31 | |
612a2d8a | 32 | public $old=''; |
33 | public $public='private'; | |
eaf30d86 | 34 | |
612a2d8a | 35 | public $rules = "Interdire ce qui peut nous servir (virus@, postmaster@, ...), |
0337d704 | 36 | les alias vulgaires, et les prenom.nom (sauf si c'est pour l'utilisateur prenom.nom). |
a7de4ef7 | 37 | Pas de contrainte pour les tirets ou les points, en revanche le souligné (_) est interdit"; |
0337d704 | 38 | |
39 | // }}} | |
40 | // {{{ constructor | |
41 | ||
532c06cf | 42 | public function __construct(User &$_user, $_alias, $_raison, $_public, $_stamp=0) |
0337d704 | 43 | { |
44 | global $globals; | |
5daf68f6 | 45 | parent::__construct($_user, true, 'alias', $_stamp); |
0337d704 | 46 | $this->alias = $_alias.'@'.$globals->mail->alias_dom; |
47 | $this->raison = $_raison; | |
48 | $this->public = $_public; | |
49 | ||
08cce2ff | 50 | $res = XDB::query(" |
0337d704 | 51 | SELECT v.alias |
52 | FROM virtual_redirect AS vr | |
53 | INNER JOIN virtual AS v ON (v.vid=vr.vid AND v.alias LIKE '%@{$globals->mail->alias_dom}') | |
5daf68f6 VZ |
54 | WHERE vr.redirect = {?} OR vr.redirect = {?}", |
55 | $this->user->forlifeEmail(), | |
56 | // TODO: remove this über-ugly hack. The issue is that you need | |
57 | // to remove all @m4x.org addresses in virtual_redirect first. | |
58 | $this->user->login() . '@' . $globals->mail->domain2); | |
0337d704 | 59 | $this->old = $res->fetchOneCell(); |
5daf68f6 VZ |
60 | if (empty($this->old)) { |
61 | unset($this->old); | |
62 | } | |
0337d704 | 63 | } |
64 | ||
65 | // }}} | |
66 | // {{{ function get_request() | |
67 | ||
612a2d8a | 68 | static public function get_request($uid) |
0337d704 | 69 | { |
5daf68f6 | 70 | return parent::get_typed_request($uid, 'alias'); |
0337d704 | 71 | } |
72 | ||
73 | // }}} | |
74 | // {{{ function formu() | |
75 | ||
612a2d8a | 76 | public function formu() |
77 | { | |
78 | return 'include/form.valid.aliases.tpl'; | |
79 | } | |
0337d704 | 80 | |
81 | // }}} | |
82 | // {{{ function _mail_subj | |
83 | ||
612a2d8a | 84 | protected function _mail_subj() |
0337d704 | 85 | { |
86 | return "[Polytechnique.org/MELIX] Demande de l'alias {$this->alias}"; | |
87 | } | |
88 | ||
89 | // }}} | |
90 | // {{{ function _mail_body | |
91 | ||
612a2d8a | 92 | protected function _mail_body($isok) |
0337d704 | 93 | { |
94 | if ($isok) { | |
faefdbb7 | 95 | return " L'adresse email {$this->alias} que tu avais demandée vient d'être créée, tu peux désormais l'utiliser à ta convenance.".(($this->public == 'public')?" A ta demande, cette adresse apparaît maintenant sur ta fiche.":""); |
0337d704 | 96 | } else { |
a7de4ef7 | 97 | return " La demande que tu avais faite pour l'alias {$this->alias} a été refusée."; |
0337d704 | 98 | } |
99 | } | |
100 | ||
101 | // }}} | |
4c6fce94 | 102 | // {{{ function shorter_domain |
103 | ||
612a2d8a | 104 | private function shorter_domain() |
4c6fce94 | 105 | { |
106 | global $globals; | |
107 | ||
29d908fa | 108 | $mail = $globals->mail; |
109 | ||
110 | if (empty($mail->domain2) || strlen($mail->domain2) > strlen($mail->domain)) { | |
111 | return $mail->domain; | |
4c6fce94 | 112 | } else { |
29d908fa | 113 | return $mail->domain2; |
4c6fce94 | 114 | } |
115 | } | |
116 | ||
117 | // }}} | |
0337d704 | 118 | // {{{ function commit() |
119 | ||
612a2d8a | 120 | public function commit () |
0337d704 | 121 | { |
4c6fce94 | 122 | XDB::execute("UPDATE auth_user_quick SET emails_alias_pub = {?} WHERE user_id = {?}", |
5daf68f6 | 123 | $this->public, $this->user->id()); |
0337d704 | 124 | |
125 | if ($this->old) { | |
5daf68f6 | 126 | return XDB::execute("UPDATE virtual SET alias = {?} WHERE alias = {?}", |
29d908fa | 127 | $this->alias, $this->old); |
0337d704 | 128 | } else { |
5daf68f6 | 129 | XDB::execute("INSERT INTO virtual SET alias = {?},type='user'", $this->alias); |
8b83a166 | 130 | $vid = XDB::insertId(); |
5daf68f6 VZ |
131 | return XDB::query("INSERT INTO virtual_redirect (vid,redirect) VALUES ({?}, {?})", |
132 | $vid, $this->user->forlifeEmail()); | |
0337d704 | 133 | } |
134 | } | |
135 | ||
136 | // }}} | |
137 | } | |
138 | ||
139 | // }}} | |
140 | ||
a7de4ef7 | 141 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 142 | ?> |