2 /***************************************************************************
3 * Copyright (C) 2003-2011 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)
76 require_once 'emails.inc.php';
78 if (!$globals->asso('mail_domain')) {
81 $this->prepare_client($page);
82 $page->changeTpl('xnetlists/index.tpl');
84 if (Get
::has('del')) {
85 S
::assert_xsrf_token();
86 $this->client
->unsubscribe(Get
::v('del'));
89 if (Get
::has('add')) {
90 S
::assert_xsrf_token();
91 $this->client
->subscribe(Get
::v('add'));
95 if (Post
::has('del_alias') && may_update()) {
96 S
::assert_xsrf_token();
98 $alias = Post
::t('del_alias');
99 list($local_part, ) = explode('@', $alias);
100 delete_list_alias($local_part, $globals->asso('mail_domain'));
101 $page->trigSuccess($alias . ' supprimé !');
104 $listes = $this->client
->get_lists();
105 $page->assign('listes', $listes);
106 $page->assign('aliases', iterate_list_alias($globals->asso('mail_domain')));
107 $page->assign('may_update', may_update());
109 if (count($listes) > 0 && !$globals->asso('has_ml')) {
110 XDB
::execute("UPDATE groups
111 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'has_ml')
113 $globals->asso('id'));
117 function handler_create($page)
121 if (!$globals->asso('mail_domain')) {
124 $this->prepare_client($page);
125 $page->changeTpl('xnetlists/create.tpl');
127 if (!Post
::has('submit')) {
130 S
::assert_xsrf_token();
133 if (!Post
::has('liste') ||
!Post
::t('liste')) {
134 $page->trigError('Le champs « adresse souhaitée » est vide.');
138 $list = strtolower(Post
::t('liste'));
139 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $list)) {
140 $page->trigError('le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets');
144 require_once 'emails.inc.php';
145 if (list_exist($list, $globals->asso('mail_domain'))) {
146 $page->trigError('Cet alias est déjà pris.');
149 if (!Post
::t('desc')) {
150 $page->trigError('Le sujet est vide.');
154 $success = $this->client
->create_list($list, utf8_decode(Post
::t('desc')), Post
::t('advertise'),
155 Post
::t('modlevel'), Post
::t('inslevel'),
156 array(S
::user()->forlifeEmail()), array(S
::user()->forlifeEmail()));
159 $page->kill("Un problème est survenu, contacter "
160 ."<a href='mailto:support@m4x.org'>support@m4x.org</a>");
163 create_list($list, $globals->asso('mail_domain'));
165 XDB
::execute("UPDATE groups
166 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'has_ml')
168 $globals->asso('id'));
170 pl_redirect('lists/admin/' . $list);
173 function handler_sync($page, $liste = null
)
177 if (!$globals->asso('mail_domain')) {
180 $this->prepare_client($page);
181 $page->changeTpl('xnetlists/sync.tpl');
183 if (Env
::has('add')) {
184 S
::assert_xsrf_token();
185 $this->client
->mass_subscribe($liste, array_keys(Env
::v('add')));
188 list(,$members) = $this->client
->get_members($liste);
189 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
190 $subscribers = array_unique($mails);
192 $ann = XDB
::fetchColumn('SELECT uid
194 WHERE asso_id = {?}', $globals->asso('id'));
195 $users = User
::getBulkUsersWithUIDs($ann);
197 $not_in_list = array();
198 foreach ($users as $user) {
199 if (!in_array(strtolower($user->forlifeEmail()), $subscribers)) {
200 $not_in_list[] = $user;
204 $page->assign('not_in_list', $not_in_list);
207 function handler_aadmin($page, $lfull = null
)
211 if (!$globals->asso('mail_domain') ||
is_null($lfull)) {
214 $page->changeTpl('xnetlists/alias-admin.tpl');
216 require_once 'emails.inc.php';
217 list($local_part, $domain) = explode('@', $lfull);
218 if (Env
::has('add_member')) {
219 S
::assert_xsrf_token();
221 $email = Env
::t('add_member');
222 $user = User
::getSilent($email);
224 add_to_list_alias($user, $local_part, $domain);
225 $page->trigSuccess($email . ' ajouté.');
227 $page->trigError($email . " n'existe pas.");
231 if (Env
::has('del_member')) {
232 S
::assert_xsrf_token();
234 $user = User
::getSilent(Env
::t('del_member'));
235 delete_from_list_alias($user, $local_part, $domain);
236 $page->trigSuccess($user->fullName() . ' supprimé.');
239 $page->assign('members', list_alias_members($local_part, $domain));
242 function handler_acreate($page)
246 if (!$globals->asso('mail_domain')) {
249 $page->changeTpl('xnetlists/alias-create.tpl');
251 if (!Post
::has('submit')) {
254 S
::assert_xsrf_token();
257 if (!Post
::has('liste')) {
258 $page->trigError('Le champs « adresse souhaitée » est vide.');
261 $list = Post
::v('liste');
262 if (!preg_match("/^[a-zA-Z0-9\-\.]*$/", $list)) {
263 $page->trigError('Le nom de l\'alias ne doit contenir que des lettres,'
264 .' chiffres, tirets et points.');
268 require_once 'emails.inc.php';
269 if (list_exist($list, $globals->asso('mail_domain'))) {
270 $page->trigError('Cet alias est déjà pris.');
274 add_to_list_alias(S
::user(), $list, $globals->asso('mail_domain'));
275 pl_redirect('alias/admin/' . $list . '@' . $globals->asso('mail_domain'));
278 function handler_profile($page, $user = null
)
280 http_redirect('https://www.polytechnique.org/profile/'.$user);
284 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: