2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 require_once dirname(__FILE__
).'/lists.php';
24 class XnetListsModule
extends ListsModule
31 'grp/lists' => $this->make_hook('lists', AUTH_MDP
),
32 'grp/lists/create' => $this->make_hook('create', AUTH_MDP
),
34 'grp/lists/members' => $this->make_hook('members', AUTH_COOKIE
),
35 'grp/lists/archives' => $this->make_hook('archives', AUTH_COOKIE
),
37 'grp/lists/moderate' => $this->make_hook('moderate', AUTH_MDP
),
38 'grp/lists/admin' => $this->make_hook('admin', AUTH_MDP
),
39 'grp/lists/options' => $this->make_hook('options', AUTH_MDP
),
40 'grp/lists/delete' => $this->make_hook('delete', AUTH_MDP
),
42 'grp/lists/soptions' => $this->make_hook('soptions', AUTH_MDP
),
43 'grp/lists/check' => $this->make_hook('check', AUTH_MDP
),
44 'grp/lists/sync' => $this->make_hook('sync', AUTH_MDP
),
46 /* hack: lists uses that */
47 'profile' => $this->make_hook('profile', AUTH_PUBLIC
),
51 function prepare_client(&$page)
55 require_once 'lists.inc.php';
57 $this->client
=& lists_xmlrpc(Session
::getInt('uid'),
58 Session
::get('password'),
59 $globals->asso('mail_domain'));
62 $page->assign('asso', $globals->asso());
63 $page->setType($globals->asso('cat'));
66 function handler_lists(&$page)
70 $this->prepare_client($page);
72 $page->changeTpl('xnet/groupe/listes.tpl');
74 if (Get
::has('del')) {
75 $this->client
->unsubscribe(Get
::get('del'));
78 if (Get
::has('add')) {
79 $this->client
->subscribe(Get
::get('add'));
83 if (Post
::has('del_alias') && may_update()) {
84 $alias = Post
::get('del_alias');
85 // prevent group admin from erasing aliases from other groups
86 $alias = substr($alias, 0, strpos($alias, '@')).'@'.$globals->asso('mail_domain');
88 'DELETE FROM x4dat.virtual_redirect, x4dat.virtual
89 USING x4dat.virtual AS v
90 LEFT JOIN x4dat.virtual_redirect USING(vid)
91 WHERE v.alias={?}', $alias);
92 $page->trig(Post
::get('del_alias')." supprimé !");
95 $listes = $this->client
->get_lists();
96 $page->assign('listes',$listes);
98 $alias = $globals->xdb
->iterator(
102 LIKE {?} AND type="user"
103 ORDER BY alias', '%@'.$globals->asso('mail_domain'));
104 $page->assign('alias', $alias);
106 $page->assign('may_update', may_update());
109 function handler_create(&$page)
113 $this->prepare_client($page);
115 $page->changeTpl('xnet/groupe/listes-create.tpl');
116 $page->assign('force_list_super', may_update());
118 if (!Post
::has('submit')) {
122 if (!Post
::has('liste')) {
123 $page->trig_run('champs «addresse souhaitée» vide');
126 $liste = Post
::get('liste');
128 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
129 $page->trig_run('le nom de la liste ne doit contenir que des lettres, chiffres et tirets');
132 $new = $liste.'@'.$globals->asso('mail_domain');
133 $res = $globals->xdb
->query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
134 $n = $res->fetchOneCell();
137 $page->trig_run('cet alias est déjà pris');
139 if(!Post
::get('desc')) {
140 $page->trig_run('le sujet est vide');
143 require_once('platal/xmlrpc-client.inc.php');
144 require_once('lists.inc.php');
145 $ret = $this->client
->create_list(
146 $liste, Post
::get('desc'), Post
::get('advertise'),
147 Post
::get('modlevel'), Post
::get('inslevel'),
148 array(Session
::get('forlife')), array());
150 $dom = strtolower($globals->asso("mail_domain"));
151 $red = $dom.'_'.$liste;
154 $page->kill("Un problème est survenu, contacter "
155 ."<a href='mailto:support@m4x.org'>support@m4x.org</a>");
158 $globals->xdb
->execute('INSERT INTO x4dat.virtual (alias,type)
159 VALUES({?},{?})', $liste.'@'.$dom, 'list');
160 $globals->xdb
->execute('INSERT INTO x4dat.virtual_redirect (vid,redirect)
161 VALUES ({?}, {?})', mysql_insert_id(),
162 "$red+post@listes.polytechnique.org");
163 $globals->xdb
->execute('INSERT INTO x4dat.virtual (alias,type)
164 VALUES({?},{?})', $liste.'-owner@'.$dom, 'list');
165 $globals->xdb
->execute('INSERT INTO x4dat.virtual_redirect (vid,redirect)
166 VALUES ({?}, {?})', mysql_insert_id(),
167 "$red+owner@listes.polytechnique.org");
168 $globals->xdb
->execute('INSERT INTO x4dat.virtual (alias,type)
169 VALUES({?},{?})', $liste.'-admin@'.$dom, 'list');
170 $globals->xdb
->execute('INSERT INTO x4dat.virtual_redirect (vid,redirect)
171 VALUES ({?}, {?})', mysql_insert_id(),
172 "$red+admin@listes.polytechnique.org");
173 $globals->xdb
->execute('INSERT INTO x4dat.virtual (alias,type)
174 VALUES({?},{?})', $liste.'-bounces@'.$dom, 'list');
175 $globals->xdb
->execute('INSERT INTO x4dat.virtual_redirect (vid,redirect)
176 VALUES ({?}, {?})', mysql_insert_id(),
177 "$red+bounces@listes.polytechnique.org");
180 redirect(smarty_function_rel().'/'.$platal->ns
.'lists/admin/'.$liste);
183 function handler_sync(&$page, $liste = null
)
187 $this->prepare_client($page);
189 $page->changeTpl('xnet/groupe/listes-sync.tpl');
191 if (Env
::has('add')) {
192 $this->client
->mass_subscribe($liste, array_keys(Env
::getMixed('add')));
195 list(,$members) = $this->client
->get_members($liste);
196 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
197 $subscribers = array_unique(array_merge($subscribers, $mails));
199 $not_in_group_x = array();
200 $not_in_group_ext = array();
202 $ann = $globals->xdb
->iterator(
203 "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom,
204 IF(m.origine='X',u.prenom,m.prenom) AS prenom,
205 IF(m.origine='X',u.promo,'extérieur') AS promo,
206 IF(m.origine='X',CONCAT(a.alias, '@polytechnique.org'),m.email) AS email,
207 IF(m.origine='X',FIND_IN_SET('femme', u.flags),0) AS femme,
208 m.perms='admin' AS admin,
210 FROM groupex.membres AS m
211 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
212 LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' )
213 WHERE m.asso_id = {?}", $globals->asso('id'));
215 $not_in_list = array();
217 while ($tmp = $ann->next()) {
218 if (!in_array($tmp['email'], $subscribers)) {
219 $not_in_list[] = $tmp;
223 $page->assign('not_in_list', $not_in_list);
226 function handler_profile(&$page, $user = null
)
228 redirect('https://www.polytechnique.org/profile/'.$user);