2cf9509119a70436ac98ff3ef4059f37f6b5261b
[platal.git] / include / validations / aliases.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 AliasReq {{{1
23 class AliasReq extends Validate
24 {
25 // properties {{{2
26 public $alias;
27 public $reason;
28 public $unique = true;
29
30 public $old;
31 public $public = 'private';
32
33 public $rules = "Interdire ce qui peut nous servir (virus@, postmaster@&hellip;),
34 les alias vulgaires, et les prenom.nom (sauf si c'est pour l'utilisateur prenom.nom).
35 Pas de contrainte pour les tirets ou les points, en revanche le souligné (_) est interdit.";
36
37 // constructor {{{2
38 public function __construct(User $_user, $_alias, $_reason, $_public, $_old, $_stamp = 0)
39 {
40 global $globals;
41 parent::__construct($_user, true, 'alias', $_stamp);
42 $this->alias = $_alias;
43 $this->reason = $_reason;
44 $this->public = $_public;
45 $this->old = $_old;
46 }
47
48 // function get_request() {{{2
49 static public function get_request($uid)
50 {
51 return parent::get_typed_request($uid, 'alias');
52 }
53
54 // function formu() {{{2
55 public function formu()
56 {
57 return 'include/form.valid.aliases.tpl';
58 }
59
60 // function _mail_subj {{{2
61 protected function _mail_subj()
62 {
63 global $globals;
64 return "[Polytechnique.org/MELIX] Demande de l'alias {$this->alias}@{$globals->mail->alias_dom}";
65 }
66
67 // function _mail_body {{{2
68 protected function _mail_body($isok)
69 {
70 global $globals;
71 if ($isok) {
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."
73 . ($this->public == 'public' ? ' À ta demande, cette adresse apparaît maintenant sur ta fiche.' : '');
74 } else {
75 return " La demande que tu avais faite pour l'alias {$this->alias}@{$globals->mail->alias_dom} a été refusée.";
76 }
77 }
78
79 // function commit() {{{2
80 public function commit()
81 {
82 global $globals;
83
84 if ($this->user->hasProfile()) {
85 XDB::execute('UPDATE profiles
86 SET alias_pub = {?}
87 WHERE pid = {?}',
88 $this->public, $this->user->profile()->id());
89 }
90
91 if ($this->old) {
92 $success = XDB::execute('UPDATE email_source_account AS s
93 INNER JOIN email_virtual_domains AS d ON (s.domain = d.id)
94 SET s.email = {?}
95 WHERE s.uid = {?} AND d.name = {?}',
96 $this->alias, $this->user->id(), $globals->mail->alias_dom);
97 } else {
98 $success = XDB::execute('INSERT INTO email_source_account (email, uid, domain, type, flags)
99 SELECT {?}, {?}, id, \'alias\', \'\'
100 FROM email_virtual_domains
101 WHERE name = {?}',
102 $this->alias, $this->user->id(), $globals->mail->alias_dom);
103 }
104
105 return $success;
106 }
107 }
108
109 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
110 ?>