Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
5e1513f6 | 3 | * Copyright (C) 2003-2011 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 ListeReq | |
23 | ||
24 | class ListeReq extends Validate | |
25 | { | |
26 | // {{{ properties | |
eaf30d86 | 27 | |
612a2d8a | 28 | public $liste; |
29 | public $desc; | |
59887c4a SJ |
30 | public $asso; |
31 | public $domain; | |
0337d704 | 32 | |
612a2d8a | 33 | public $advertise; |
34 | public $modlevel; | |
35 | public $inslevel; | |
0337d704 | 36 | |
612a2d8a | 37 | public $owners; |
38 | public $members; | |
0337d704 | 39 | |
612a2d8a | 40 | public $rules = "Refuser les listes de binets si elles ne sont pas datées (oui : apv2002@, non : apv@). |
6e828e47 | 41 | Refuser également des listes qui pourraient nous servir (admin, postmaster…)"; |
0337d704 | 42 | // }}} |
43 | // {{{ constructor | |
eaf30d86 | 44 | |
532c06cf | 45 | public function __construct(User &$_user, $_asso, $_liste, $_domain, $_desc, $_advertise, |
59887c4a | 46 | $_modlevel, $_inslevel, $_owners, $_members, $_stamp=0) |
0337d704 | 47 | { |
5daf68f6 | 48 | parent::__construct($_user, false, 'liste', $_stamp); |
eaf30d86 | 49 | |
59887c4a | 50 | $this->asso = $_asso; |
0337d704 | 51 | $this->liste = $_liste; |
59887c4a | 52 | $this->domain = $_domain; |
0337d704 | 53 | $this->desc = $_desc; |
54 | $this->advertise = $_advertise; | |
55 | $this->modlevel = $_modlevel; | |
56 | $this->inslevel = $_inslevel; | |
57 | $this->owners = $_owners; | |
58 | $this->members = $_members; | |
59 | } | |
60 | ||
61 | // }}} | |
62 | // {{{ function formu() | |
63 | ||
612a2d8a | 64 | public function formu() |
65 | { | |
66 | return 'include/form.valid.listes.tpl'; | |
67 | } | |
0337d704 | 68 | |
69 | // }}} | |
e2a78862 | 70 | // {{{ function editor() |
71 | ||
612a2d8a | 72 | public function editor() |
e2a78862 | 73 | { |
74 | return 'include/form.valid.edit-listes.tpl'; | |
75 | } | |
76 | ||
77 | // }}} | |
78 | // {{{ function handle_editor() | |
79 | ||
612a2d8a | 80 | protected function handle_editor() |
e2a78862 | 81 | { |
032b244e SJ |
82 | global $globals; |
83 | ||
e2a78862 | 84 | if (Env::has('listname')) { |
6373bfc4 | 85 | $this->liste = Post::t('listname'); |
e2a78862 | 86 | } |
59887c4a | 87 | if (Env::has('domainname')) { |
6373bfc4 | 88 | $this->domain = Post::t('domainname'); |
59887c4a SJ |
89 | } |
90 | if (Env::has('assotype')) { | |
6373bfc4 | 91 | $this->asso = Post::t('assotype'); |
59887c4a SJ |
92 | } |
93 | if (!$this->asso) { | |
032b244e | 94 | $this->domain = $globals->mail->domain; |
59887c4a | 95 | } |
cc7d3217 SJ |
96 | foreach ($this->owners as $key => &$email) { |
97 | $email = Post::t('owners_' . $key); | |
98 | } | |
99 | foreach ($this->members as $key => &$email) { | |
100 | $email = Post::t('members_' . $key); | |
101 | } | |
e2a78862 | 102 | return true; |
103 | } | |
104 | ||
105 | // }}} | |
0337d704 | 106 | // {{{ function _mail_subj |
107 | ||
612a2d8a | 108 | protected function _mail_subj() |
0337d704 | 109 | { |
655f5314 | 110 | return "[Polytechnique.org/LISTES] Demande de la liste {$this->liste}@{$this->domain}"; |
0337d704 | 111 | } |
112 | ||
113 | // }}} | |
114 | // {{{ function _mail_body | |
115 | ||
612a2d8a | 116 | protected function _mail_body($isok) |
0337d704 | 117 | { |
118 | if ($isok) { | |
de1b96b6 | 119 | return " Suite à ta demande de création de liste de diffusion, nous avons créé l'adresse {$this->liste}@{$this->domain}, qui est maintenant à ta disposition."; |
0337d704 | 120 | } else { |
655f5314 | 121 | return " La demande que tu avais faite pour la liste de diffusion {$this->liste}@{$this->domain} a été refusée."; |
0337d704 | 122 | } |
123 | } | |
124 | ||
125 | // }}} | |
126 | // {{{ function commit() | |
9bb8bf21 | 127 | |
612a2d8a | 128 | public function commit() |
0337d704 | 129 | { |
59887c4a SJ |
130 | global $globals; |
131 | ||
132 | if ($this->asso == "alias") { | |
133 | $new = $this->liste . '@' . $this->domain; | |
00112b2e | 134 | XDB::query('INSERT INTO virtual (alias, type) VALUES({?}, "user")', $new); |
59887c4a | 135 | foreach ($this->members as $member) { |
385c5e94 SJ |
136 | $user = User::get($member); |
137 | if ($user != null) { | |
138 | XDB::query( | |
00112b2e | 139 | "INSERT INTO virtual_redirect (vid, redirect) |
385c5e94 | 140 | SELECT vid, {?} |
00112b2e | 141 | FROM virtual |
385c5e94 SJ |
142 | WHERE alias = {?}", $user->forlifeEmail(), $new); |
143 | } | |
59887c4a SJ |
144 | } |
145 | return 1; | |
146 | } | |
147 | ||
de212580 | 148 | $list = new MMList(S::user(), $this->domain); |
92144f3e | 149 | $ret = $list->create_list($this->liste, utf8_decode($this->desc), $this->advertise, |
9bb8bf21 | 150 | $this->modlevel, $this->inslevel, |
151 | $this->owners, $this->members); | |
0337d704 | 152 | $liste = strtolower($this->liste); |
59887c4a SJ |
153 | if ($ret && !$this->asso) { |
154 | foreach(Array($liste, $liste . "-owner", $liste . "-admin", $liste . "-bounces", $liste . "-unsubscribe") as $l) { | |
385c5e94 | 155 | XDB::execute("INSERT INTO aliases (alias, type) VALUES({?}, 'liste')", $l); |
0337d704 | 156 | } |
032b244e SJ |
157 | } elseif ($ret) { |
158 | foreach (Array('', 'owner', 'admin', 'bounces', 'unsubscribe') as $app) { | |
159 | $mdir = $app == '' ? '+post' : '+' . $app; | |
160 | if (!empty($app)) { | |
161 | $app = '-' . $app; | |
59887c4a | 162 | } |
032b244e | 163 | $red = $this->domain . '_' . $liste; |
00112b2e | 164 | XDB::execute('INSERT INTO virtual (alias, type) |
385c5e94 | 165 | VALUES({?}, {?})', $liste . $app . '@' . $this->domain, 'list'); |
00112b2e | 166 | XDB::execute('INSERT INTO virtual_redirect (vid, redirect) |
032b244e SJ |
167 | VALUES ({?}, {?})', XDB::insertId(), |
168 | $red . $mdir . '@listes.polytechnique.org'); | |
169 | $list->mass_subscribe($liste, join(' ', $this->members)); | |
59887c4a | 170 | } |
0337d704 | 171 | } |
172 | return $ret; | |
173 | } | |
174 | ||
175 | // }}} | |
176 | } | |
177 | ||
178 | // }}} | |
179 | ||
a7de4ef7 | 180 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 181 | ?> |