2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 Platal
::load('lists');
24 class XnetListsModule
extends ListsModule
31 '%grp/lists' => $this->make_hook('lists', AUTH_MDP
, 'groupmember'),
32 '%grp/lists/create' => $this->make_hook('create', AUTH_MDP
, 'groupmember'),
34 '%grp/lists/members' => $this->make_hook('members', AUTH_COOKIE
),
35 '%grp/lists/csv' => $this->make_hook('csv', AUTH_COOKIE
),
36 '%grp/lists/annu' => $this->make_hook('annu', AUTH_COOKIE
),
37 '%grp/lists/archives' => $this->make_hook('archives', AUTH_COOKIE
),
38 '%grp/lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC
),
40 '%grp/lists/moderate' => $this->make_hook('moderate', AUTH_MDP
),
41 '%grp/lists/admin' => $this->make_hook('admin', AUTH_MDP
),
42 '%grp/lists/options' => $this->make_hook('options', AUTH_MDP
),
43 '%grp/lists/delete' => $this->make_hook('delete', AUTH_MDP
),
45 '%grp/lists/soptions' => $this->make_hook('soptions', AUTH_MDP
),
46 '%grp/lists/check' => $this->make_hook('check', AUTH_MDP
),
47 '%grp/lists/sync' => $this->make_hook('sync', AUTH_MDP
),
49 '%grp/alias/admin' => $this->make_hook('aadmin', AUTH_MDP
, 'groupadmin'),
50 '%grp/alias/create' => $this->make_hook('acreate', AUTH_MDP
, 'groupadmin'),
52 /* hack: lists uses that */
53 'profile' => $this->make_hook('profile', AUTH_PUBLIC
),
57 function prepare_client(&$page, $user = null
)
60 Platal
::load('lists', 'lists.inc.php');
65 $this->client
= new MMList($user, $globals->asso('mail_domain'));
67 $page->assign('asso', $globals->asso());
68 $page->setType($globals->asso('cat'));
70 return $globals->asso('mail_domain');
73 function handler_lists(&$page)
77 if (!$globals->asso('mail_domain')) {
80 $this->prepare_client($page);
81 $page->changeTpl('xnetlists/index.tpl');
83 if (Get
::has('del')) {
84 S
::assert_xsrf_token();
85 $this->client
->unsubscribe(Get
::v('del'));
88 if (Get
::has('add')) {
89 S
::assert_xsrf_token();
90 $this->client
->subscribe(Get
::v('add'));
94 if (Post
::has('del_alias') && may_update()) {
95 S
::assert_xsrf_token();
97 $alias = Post
::v('del_alias');
98 // prevent group admin from erasing aliases from other groups
99 $alias = substr($alias, 0, strpos($alias, '@')).'@'.$globals->asso('mail_domain');
102 USING x4dat.virtual AS v
103 LEFT JOIN x4dat.virtual_redirect AS r USING(vid)
104 WHERE v.alias={?}', $alias);
105 $page->trigSuccess(Post
::v('del_alias')." supprimé !");
108 $listes = $this->client
->get_lists();
109 $page->assign('listes',$listes);
111 $alias = XDB
::iterator(
115 LIKE {?} AND type="user"
116 ORDER BY alias', '%@'.$globals->asso('mail_domain'));
117 $page->assign('alias', $alias);
119 $page->assign('may_update', may_update());
122 function handler_create(&$page)
126 if (!$globals->asso('mail_domain')) {
129 $this->prepare_client($page);
130 $page->changeTpl('xnetlists/create.tpl');
132 if (!Post
::has('submit')) {
135 S
::assert_xsrf_token();
138 if (!Post
::has('liste')) {
139 $page->trigError('champs «adresse souhaitée» vide');
143 $liste = strtolower(Post
::v('liste'));
145 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
146 $page->trigError('le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets');
150 $new = $liste.'@'.$globals->asso('mail_domain');
151 $res = XDB
::query('SELECT alias FROM x4dat.virtual WHERE alias={?}', $new);
153 if ($res->numRows()) {
154 $page->trigError('cet alias est déjà pris');
157 if (!Post
::v('desc')) {
158 $page->trigError('le sujet est vide');
162 $ret = $this->client
->create_list(
163 $liste, utf8_decode(Post
::v('desc')), Post
::v('advertise'),
164 Post
::v('modlevel'), Post
::v('inslevel'),
165 array(S
::user()->forlifeEmail()), array(S
::user()->forlifeEmail()));
167 $dom = strtolower($globals->asso("mail_domain"));
168 $red = $dom.'_'.$liste;
171 $page->kill("Un problème est survenu, contacter "
172 ."<a href='mailto:support@m4x.org'>support@m4x.org</a>");
175 foreach (array('', 'owner', 'admin', 'bounces', 'unsubscribe') as $app) {
176 $mdir = $app == '' ?
'+post' : '+' . $app;
180 XDB
::execute('INSERT INTO x4dat.virtual (alias,type)
181 VALUES({?},{?})', $liste. $app . '@'.$dom, 'list');
182 XDB
::execute('INSERT INTO x4dat.virtual_redirect (vid,redirect)
183 VALUES ({?}, {?})', XDB
::insertId(),
184 $red . $mdir . '@listes.polytechnique.org');
186 pl_redirect('lists/admin/'.$liste);
189 function handler_sync(&$page, $liste = null
)
193 if (!$globals->asso('mail_domain')) {
196 $this->prepare_client($page);
197 $page->changeTpl('xnetlists/sync.tpl');
199 if (Env
::has('add')) {
200 S
::assert_xsrf_token();
201 $this->client
->mass_subscribe($liste, array_keys(Env
::v('add')));
204 list(,$members) = $this->client
->get_members($liste);
205 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
206 $subscribers = array_unique($mails);
208 $not_in_group_x = array();
209 $not_in_group_ext = array();
211 $ann = XDB
::fetchColumn('SELECT uid
213 WHERE asso_id = {?}', $globals->asso('id'));
214 $users = User
::getBuildUsersWithUIDs($ann, 'promo,full_name');
215 $not_in_list = array();
216 foreach ($users as $user) {
217 if (!in_array(strtolower($user->forlifeEmail()), $subscribers)) {
218 $not_in_list[] = $user;
222 $page->assign('not_in_list', $not_in_list);
225 function handler_aadmin(&$page, $lfull = null
)
229 if (!$globals->asso('mail_domain') ||
is_null($lfull)) {
232 $page->changeTpl('xnetlists/alias-admin.tpl');
234 if (Env
::has('add_member')) {
235 S
::assert_xsrf_token();
237 $add = Env
::t('add_member');
238 $user = User
::getSilent($add);
240 $add = $user->forlifeEmail();
241 } else if (!User
::isForeignEmailAddress($add)) {
245 XDB
::execute('INSERT INTO x4dat.virtual_redirect (vid, redirect)
248 WHERE alias = {?}', strtolower($add), $lfull);
249 $page->trigSuccess($add . ' ajouté.');
251 $page->trigError($add . ' n\'existe pas.');
255 if (Env
::has('del_member')) {
256 S
::assert_xsrf_token();
258 "DELETE FROM x4dat.virtual_redirect
259 USING x4dat.virtual_redirect
260 INNER JOIN x4dat.virtual USING(vid)
261 WHERE redirect={?} AND alias={?}", Env
::v('del_member'), $lfull);
262 pl_redirect('alias/admin/'.$lfull);
266 $emails = XDB
::fetchColumn('SELECT redirect
267 FROM virtual_redirect AS vr
268 INNER JOIN virtual AS v USING(vid)
270 ORDER BY redirect', $lfull);
272 foreach ($emails as $email) {
273 $user = User
::getSilent($email);
275 $mem[] = array('user' => $user, 'email' => $email);
277 $mem[] = array('email' => $email);
280 $page->assign('mem', $mem);
283 function handler_acreate(&$page)
287 if (!$globals->asso('mail_domain')) {
290 $page->changeTpl('xnetlists/alias-create.tpl');
292 if (!Post
::has('submit')) {
295 S
::assert_xsrf_token();
298 if (!Post
::has('liste')) {
299 $page->trigError('champs «adresse souhaitée» vide');
302 $liste = Post
::v('liste');
303 if (!preg_match("/^[a-zA-Z0-9\-\.]*$/", $liste)) {
304 $page->trigError('le nom de l\'alias ne doit contenir que des lettres,'
305 .' chiffres, tirets et points');
309 $new = $liste.'@'.$globals->asso('mail_domain');
310 $res = XDB
::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
311 $n = $res->fetchOneCell();
313 $page->trigError('cet alias est déjà pris');
317 XDB
::query('INSERT INTO x4dat.virtual (alias,type) VALUES({?}, "user")', $new);
319 pl_redirect("alias/admin/$new");
322 function handler_profile(&$page, $user = null
)
324 http_redirect('https://www.polytechnique.org/profile/'.$user);
328 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: