7b9d64a8 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 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 | require_once dirname(__FILE__).'/lists.php'; |
23 | |
24 | class XnetListsModule extends ListsModule |
25 | { |
26 | var $client; |
27 | |
28 | function handlers() |
29 | { |
30 | return array( |
31 | 'grp/lists' => $this->make_hook('lists', AUTH_MDP), |
32 | 'grp/lists/create' => $this->make_hook('create', AUTH_MDP), |
33 | |
34 | 'grp/lists/members' => $this->make_hook('members', AUTH_COOKIE), |
7b9d64a8 |
35 | 'grp/lists/archives' => $this->make_hook('archives', AUTH_COOKIE), |
36 | |
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), |
41 | |
42 | 'grp/lists/soptions' => $this->make_hook('soptions', AUTH_MDP), |
43 | 'grp/lists/check' => $this->make_hook('check', AUTH_MDP), |
9fdacf8d |
44 | 'grp/lists/sync' => $this->make_hook('sync', AUTH_MDP), |
7b9d64a8 |
45 | |
46 | /* hack: lists uses that */ |
47 | 'profile' => $this->make_hook('profile', AUTH_PUBLIC), |
48 | ); |
49 | } |
50 | |
51 | function prepare_client(&$page) |
52 | { |
53 | global $globals; |
54 | |
55 | require_once 'lists.inc.php'; |
56 | |
57 | $this->client =& lists_xmlrpc(Session::getInt('uid'), |
58 | Session::get('password'), |
59 | $globals->asso('mail_domain')); |
60 | |
61 | $page->useMenu(); |
62 | $page->assign('asso', $globals->asso()); |
63 | $page->setType($globals->asso('cat')); |
64 | } |
65 | |
9fdacf8d |
66 | function handler_lists(&$page) |
67 | { |
68 | global $globals; |
69 | |
70 | $this->prepare_client($page); |
71 | |
72 | $page->changeTpl('xnet/groupe/listes.tpl'); |
73 | |
74 | if (Get::has('del')) { |
75 | $this->client->unsubscribe(Get::get('del')); |
76 | redirect('lists'); |
77 | } |
78 | if (Get::has('add')) { |
79 | $this->client->subscribe(Get::get('add')); |
80 | redirect('lists'); |
81 | } |
82 | |
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'); |
87 | $globals->xdb->query( |
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); |
f7a0a7ad |
92 | $page->trig(Post::get('del_alias')." supprimé !"); |
9fdacf8d |
93 | } |
94 | |
95 | $listes = $this->client->get_lists(); |
96 | $page->assign('listes',$listes); |
97 | |
98 | $alias = $globals->xdb->iterator( |
99 | 'SELECT alias,type |
100 | FROM x4dat.virtual |
101 | WHERE alias |
102 | LIKE {?} AND type="user" |
103 | ORDER BY alias', '%@'.$globals->asso('mail_domain')); |
104 | $page->assign('alias', $alias); |
105 | |
106 | $page->assign('may_update', may_update()); |
107 | } |
108 | |
109 | function handler_sync(&$page, $liste = null) |
110 | { |
111 | global $globals; |
112 | |
113 | $this->prepare_client($page); |
114 | |
115 | $page->changeTpl('xnet/groupe/listes-sync.tpl'); |
116 | |
117 | if (Env::has('add')) { |
118 | $this->client->mass_subscribe($liste, array_keys(Env::getMixed('add'))); |
119 | } |
120 | |
121 | list(,$members) = $this->client->get_members($liste); |
122 | $mails = array_map(create_function('$arr', 'return $arr[1];'), $members); |
123 | $subscribers = array_unique(array_merge($subscribers, $mails)); |
124 | |
125 | $not_in_group_x = array(); |
126 | $not_in_group_ext = array(); |
127 | |
128 | $ann = $globals->xdb->iterator( |
129 | "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom, |
130 | IF(m.origine='X',u.prenom,m.prenom) AS prenom, |
f7a0a7ad |
131 | IF(m.origine='X',u.promo,'extérieur') AS promo, |
9fdacf8d |
132 | IF(m.origine='X',CONCAT(a.alias, '@polytechnique.org'),m.email) AS email, |
133 | IF(m.origine='X',FIND_IN_SET('femme', u.flags),0) AS femme, |
134 | m.perms='admin' AS admin, |
135 | m.origine='X' AS x |
136 | FROM groupex.membres AS m |
137 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) |
138 | LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' ) |
139 | WHERE m.asso_id = {?}", $globals->asso('id')); |
140 | |
141 | $not_in_list = array(); |
142 | |
143 | while ($tmp = $ann->next()) { |
144 | if (!in_array($tmp['email'], $subscribers)) { |
145 | $not_in_list[] = $tmp; |
146 | } |
147 | } |
148 | |
149 | $page->assign('not_in_list', $not_in_list); |
150 | } |
151 | |
7b9d64a8 |
152 | function handler_profile(&$page, $user = null) |
153 | { |
154 | redirect('https://www.polytechnique.org/profile/'.$user); |
155 | } |
156 | } |
157 | |
158 | ?> |