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 class XnetGrpModule
extends PLModule
27 'grp' => $this->make_hook('index', AUTH_PUBLIC
),
28 'grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC
),
29 'grp/logo' => $this->make_hook('logo', AUTH_PUBLIC
),
30 'grp/edit' => $this->make_hook('edit', AUTH_MDP
),
31 'grp/mail' => $this->make_hook('mail', AUTH_MDP
),
32 'grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP
),
35 => $this->make_hook('admin_annuaire', AUTH_MDP
),
39 function handler_index(&$page, $arg = null
)
47 $page->changeTpl('xnet/groupe/asso.tpl');
49 $page->setType($globals->asso('cat'));
50 $page->assign('is_member', is_member());
51 $page->assign('logged', logged());
53 $page->assign('asso', $globals->asso());
56 function handler_logo(&$page)
60 $res = $globals->xdb
->query("SELECT logo, logo_mime
61 FROM groupex.asso WHERE id = {?}",
62 $globals->asso('id'));
63 list($logo, $logo_mime) = $res->fetchOneRow();
66 header("Content-type: $mime");
67 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
68 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
69 header('Cache-Control: no-cache, must-revalidate');
70 header('Pragma: no-cache');
73 header('Content-type: image/jpeg');
74 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
75 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
76 header('Cache-Control: no-cache, must-revalidate');
77 header('Pragma: no-cache');
78 readfile(dirname(__FILE__
).'/../htdocs.net/images/dflt_carre.jpg');
84 function handler_edit(&$page)
88 new_groupadmin_page('xnet/groupe/edit.tpl');
90 if (Post
::has('submit')) {
92 if (Post
::get('mail_domain') && (strstr(Post
::get('mail_domain'), '.') === false
)) {
93 $page->trig_run("le domaine doit être un FQDN (aucune modif effectuée) !!!");
95 $globals->xdb
->execute(
97 SET nom={?}, diminutif={?}, cat={?}, dom={?},
98 descr={?}, site={?}, mail={?}, resp={?},
99 forum={?}, mail_domain={?}, ax={?}, pub={?},
100 sub_url={?}, inscriptible={?}
102 Post
::get('nom'), Post
::get('diminutif'),
103 Post
::get('cat'), Post
::getInt('dom'),
104 Post
::get('descr'), Post
::get('site'),
105 Post
::get('mail'), Post
::get('resp'),
106 Post
::get('forum'), Post
::get('mail_domain'),
107 Post
::has('ax'), Post
::has('pub')?
'private':'public',
108 Post
::get('sub_url'), Post
::get('inscriptible'),
109 $globals->asso('id'));
110 if (Post
::get('mail_domain')) {
111 $globals->xdb
->execute('INSERT INTO virtual_domains (domain) VALUES({?})',
112 Post
::get('mail_domain'));
115 $globals->xdb
->execute(
117 SET descr={?}, site={?}, mail={?}, resp={?},
118 forum={?}, ax={?}, pub= {?}, sub_url={?}
120 Post
::get('descr'), Post
::get('site'),
121 Post
::get('mail'), Post
::get('resp'),
122 Post
::get('forum'), Post
::has('ax'),
123 Post
::has('pub')?
'private':'public',
124 Post
::get('sub_url'), $globals->asso('id'));
127 if ($_FILES['logo']['name']) {
128 $logo = file_get_contents($_FILES['logo']['tmp_name']);
129 $mime = $_FILES['logo']['type'];
130 $globals->xdb
->execute('UPDATE groupex.asso
131 SET logo={?}, logo_mime={?}
132 WHERE id={?}', $logo, $mime,
133 $globals->asso('id'));
136 redirect('../'.Post
::get('diminutif', $globals->asso('diminutif')).'/edit');
140 $dom = $globals->xdb
->iterator('SELECT * FROM groupex.dom ORDER BY nom');
141 $page->assign('dom', $dom);
142 $page->assign('super', true
);
146 function handler_mail(&$page)
150 require_once 'lists.inc.php';
152 new_groupadmin_page('xnet/groupe/mail.tpl');
153 $client =& lists_xmlrpc(Session
::getInt('uid'),
154 Session
::get('password'),
155 $globals->asso('mail_domain'));
156 $page->assign('listes', $client->get_lists());
158 if (Post
::has('send')) {
159 $from = Post
::get('from');
160 $sujet = Post
::get('sujet');
161 $body = Post
::get('body');
163 $mls = array_keys(Env
::getMixed('ml', array()));
165 require_once 'xnet/mail.inc.php';
166 $tos = get_all_redirects(Post
::has('membres'), $mls, $client);
167 send_xnet_mails($from, $sujet, $body, $tos, Post
::get('replyto'));
168 $page->kill("Mail envoyé !");
169 $page->assign('sent', true
);
173 function handler_annuaire(&$page)
177 define('NB_PER_PAGE', 25);
179 if ($globals->asso('pub') == 'public') {
180 new_group_page('xnet/groupe/annuaire.tpl');
182 new_groupadmin_page('xnet/groupe/annuaire.tpl');
185 $page->assign('admin', may_update());
187 switch (Env
::get('order')) {
188 case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break;
189 case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break;
190 case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break;
191 default : $group = 'initiale'; $tri = 'nom, prenom, promo';
194 if ($group == 'initiale')
195 $res = $globals->xdb
->iterRow(
196 'SELECT UPPER(SUBSTRING(
197 IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom),
198 1, 1)) as letter, COUNT(*)
199 FROM groupex.membres AS m
200 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
203 ORDER BY letter', $globals->asso('id'));
205 $res = $globals->xdb
->iterRow(
206 'SELECT IF(m.origine="X",u.promo,"extérieur") AS promo,
207 COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o
208 FROM groupex.membres AS m
209 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
212 ORDER BY promo_o DESC', $globals->asso('id'));
216 while (list($char, $nb) = $res->next()) {
219 if (Env
::has($group) && $char == strtoupper(Env
::get($group))) {
223 $page->assign('group', $group);
224 $page->assign('request_group', Env
::get($group));
225 $page->assign('alphabet', $alphabet);
226 $page->assign('nb_tot', $nb_tot);
228 $ofs = Env
::getInt('offset');
229 $tot = Env
::get($group) ?
$tot : $nb_tot;
230 $nbp = intval(($tot-1)/NB_PER_PAGE
);
233 $links['précédent'] = $ofs-1;
235 for ($i = 0; $i <= $nbp; $i++
) {
236 $links[(string)($i+
1)] = $i;
239 $links['suivant'] = $ofs+
1;
241 if (count($links)>1) {
242 $page->assign('links', $links);
246 if (Env
::has('initiale')) {
247 $ini = 'AND IF(m.origine="X",
248 IF(u.nom_usage<>"", u.nom_usage, u.nom),
249 m.nom) LIKE "'.addslashes(Env
::get('initiale')).'%"';
250 } elseif (Env
::has('promo')) {
251 $ini = 'AND IF(m.origine="X", u.promo, "extérieur") = "'
252 .addslashes(Env
::get('promo')).'"';
255 $ann = $globals->xdb
->iterator(
256 "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom,
257 IF(m.origine='X',u.prenom,m.prenom) AS prenom,
258 IF(m.origine='X',u.promo,'extérieur') AS promo,
259 IF(m.origine='X',u.promo,'') AS promo_o,
260 IF(m.origine='X',a.alias,m.email) AS email,
261 IF(m.origine='X',FIND_IN_SET('femme', u.flags),0) AS femme,
262 m.perms='admin' AS admin,
265 FROM groupex.membres AS m
266 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
267 LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' )
268 WHERE m.asso_id = {?} $ini
270 LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE
, NB_PER_PAGE
);
272 $page->assign('ann', $ann);
275 function handler_admin_annuaire(&$page)
279 require_once 'lists.inc.php';
280 require_once 'xnet/mail.inc.php';
282 new_groupadmin_page('xnet/groupe/annuaire-admin.tpl');
283 $client =& lists_xmlrpc(Session
::getInt('uid'),
284 Session
::get('password'),
285 $globals->asso('mail_domain'));
286 $lists = $client->get_lists();
287 if (!$lists) $lists = array();
288 $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
290 $subscribers = array();
292 foreach ($listes as $list) {
293 list(,$members) = $client->get_members($list);
294 $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
295 $subscribers = array_unique(array_merge($subscribers, $mails));
298 $not_in_group_x = array();
299 $not_in_group_ext = array();
301 foreach ($subscribers as $mail) {
302 $res = $globals->xdb
->query(
304 FROM groupex.membres AS m
305 LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000)
306 LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie")
307 WHERE asso_id = {?} AND
308 (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})',
309 $globals->asso('id'), $mail, $mail);
310 if ($res->fetchOneCell() == 0) {
311 if (strstr($mail, '@polytechnique.org') === false
) {
312 $not_in_group_ext[] = $mail;
314 $not_in_group_x[] = $mail;
319 $page->assign('not_in_group_ext', $not_in_group_ext);
320 $page->assign('not_in_group_x', $not_in_group_x);
321 $page->assign('lists', $lists);