Commit | Line | Data |
---|---|---|
ae7bb180 | 1 | <?php |
2 | /*************************************************************************** | |
5ddeb07c | 3 | * Copyright (C) 2003-2007 Polytechnique.org * |
ae7bb180 | 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 | ||
ef7c8560 | 22 | function get_infos($email) |
23 | { | |
24 | global $globals; | |
25 | // look for uid instead of email if numeric | |
ed21e24a | 26 | $field = is_numeric($email) ? 'uid' : 'email'; |
ef7c8560 | 27 | |
28 | if ($field == 'email') { | |
29 | $email = strtolower($email); | |
30 | if (strpos($email, '@') === false) { | |
31 | $email .= '@m4x.org'; | |
32 | } | |
33 | list($mbox,$dom) = explode('@', $email); | |
34 | } | |
35 | ||
08cce2ff | 36 | $res = XDB::query( |
dc2073c3 | 37 | "SELECT uid, nom, prenom, email, email AS email2, perms='admin', origine, sexe |
ef7c8560 | 38 | FROM groupex.membres |
39 | WHERE $field = {?} AND asso_id = {?}", $email, $globals->asso('id')); | |
40 | ||
41 | if ($res->numRows()) { | |
dc2073c3 | 42 | $user = $res->fetchOneAssoc(); |
43 | if ($user['origine'] == 'X') { | |
010268b2 | 44 | $res = XDB::query("SELECT nom, prenom, promo, FIND_IN_SET('femme', flags) AS sexe |
dc2073c3 | 45 | FROM auth_user_md5 |
46 | WHERE user_id = {?}", $user['uid']); | |
47 | $user = array_merge($user, $res->fetchOneAssoc()); | |
48 | } | |
eaf30d86 | 49 | return $user; |
ef7c8560 | 50 | } elseif ($dom == 'polytechnique.org' || $dom == 'm4x.org') { |
08cce2ff | 51 | $res = XDB::query( |
ef7c8560 | 52 | "SELECT user_id AS uid, u.promo, |
53 | IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom, | |
54 | u.prenom, b.alias, | |
55 | CONCAT(b.alias, '@m4x.org') AS email, | |
56 | CONCAT(b.alias, '@polytechnique.org') AS email2, | |
e1594f65 | 57 | m.perms = 'admin' AS perms, m.origine, |
010268b2 | 58 | FIND_IN_SET('femme', u.flags) AS sexe |
ef7c8560 | 59 | FROM auth_user_md5 AS u |
60 | INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type != 'homonyme' ) | |
61 | INNER JOIN aliases AS b ON ( u.user_id = b.id AND b.type = 'a_vie' ) | |
e1594f65 | 62 | LEFT JOIN groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?}) |
ef7c8560 | 63 | WHERE a.alias = {?} AND u.user_id < 50000", $globals->asso('id'), $mbox); |
64 | return $res->fetchOneAssoc(); | |
65 | } | |
66 | ||
67 | return null; | |
68 | } | |
69 | ||
70 | ||
ae7bb180 | 71 | class XnetGrpModule extends PLModule |
72 | { | |
73 | function handlers() | |
74 | { | |
75 | return array( | |
5e193297 | 76 | '%grp' => $this->make_hook('index', AUTH_PUBLIC), |
77 | '%grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC), | |
78 | '%grp/logo' => $this->make_hook('logo', AUTH_PUBLIC), | |
d430f4d8 | 79 | '%grp/site' => $this->make_hook('site', AUTH_PUBLIC), |
c6c10b6b | 80 | '%grp/edit' => $this->make_hook('edit', AUTH_MDP, 'groupadmin'), |
81 | '%grp/mail' => $this->make_hook('mail', AUTH_MDP, 'groupadmin'), | |
1490093c | 82 | '%grp/forum' => $this->make_hook('forum', AUTH_MDP, 'groupmember'), |
35fa92e8 | 83 | '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP, 'groupannu'), |
84 | '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP, 'groupmember:groupannu'), | |
85 | '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP, 'groupannu'), | |
a91fb584 | 86 | '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP, 'groupannu'), |
5e193297 | 87 | '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP), |
1490093c | 88 | '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP, 'groupmember'), |
4e310c61 | 89 | |
b8e265bf | 90 | '%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP), |
91 | ||
d1ebc57a | 92 | '%grp/admin/annuaire' |
35fa92e8 | 93 | => $this->make_hook('admin_annuaire', AUTH_MDP, 'groupadmin'), |
ef7c8560 | 94 | |
d1ebc57a | 95 | '%grp/member' |
c6c10b6b | 96 | => $this->make_hook('admin_member', AUTH_MDP, 'groupadmin'), |
d1ebc57a | 97 | '%grp/member/new' |
c6c10b6b | 98 | => $this->make_hook('admin_member_new', AUTH_MDP, 'groupadmin'), |
dc2073c3 | 99 | '%grp/member/new/ajax' |
8fc4efa3 | 100 | => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH), |
d1ebc57a | 101 | '%grp/member/del' |
c6c10b6b | 102 | => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'), |
24bcf50c | 103 | |
8fc4efa3 | 104 | '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS), |
c6c10b6b | 105 | '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'), |
106 | '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'), | |
107 | '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP, 'groupadmin'), | |
ae7bb180 | 108 | ); |
109 | } | |
110 | ||
2e94d2b8 | 111 | function handler_index(&$page, $arg = null) |
ae7bb180 | 112 | { |
24bcf50c | 113 | global $globals, $platal; |
ae7bb180 | 114 | |
2e94d2b8 | 115 | if (!is_null($arg)) { |
ae7bb180 | 116 | return PL_NOT_FOUND; |
117 | } | |
1490093c | 118 | $page->changeTpl('xnetgrp/asso.tpl'); |
ae7bb180 | 119 | |
24bcf50c | 120 | if (S::logged()) { |
121 | if (Env::has('read')) { | |
122 | XDB::query('DELETE r.* | |
123 | FROM groupex.announces_read AS r | |
124 | INNER JOIN groupex.announces AS a ON a.id = r.announce_id | |
eaf30d86 | 125 | WHERE peremption < CURRENT_DATE()'); |
24bcf50c | 126 | XDB::query('INSERT INTO groupex.announces_read |
127 | VALUES ({?}, {?})', | |
128 | Env::i('read'), S::i('uid')); | |
129 | pl_redirect(""); | |
130 | } | |
131 | if (Env::has('unread')) { | |
132 | XDB::query('DELETE FROM groupex.announces_read | |
133 | WHERE announce_id={?} AND user_id={?}', | |
134 | Env::i('unread'), S::i('uid')); | |
135 | pl_redirect("#art" . Env::i('unread')); | |
136 | } | |
137 | $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife | |
138 | FROM groupex.announces AS a | |
139 | INNER JOIN auth_user_md5 AS u USING(user_id) | |
140 | INNER JOIN aliases AS l ON (u.user_id = l.id AND l.type = 'a_vie') | |
141 | LEFT JOIN groupex.announces_read AS r ON (r.user_id = {?} AND r.announce_id = a.id) | |
142 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() | |
143 | AND (promo_min = 0 OR promo_min <= {?}) | |
144 | AND (promo_max = 0 OR promo_max >= {?}) | |
145 | AND r.announce_id IS NULL | |
146 | ORDER BY a.peremption", | |
147 | S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); | |
148 | $index = XDB::iterator("SELECT a.id, a.titre, r.user_id IS NULL AS nonlu | |
149 | FROM groupex.announces AS a | |
150 | LEFT JOIN groupex.announces_read AS r ON (a.id = r.announce_id AND r.user_id = {?}) | |
151 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() | |
152 | AND (promo_min = 0 OR promo_min <= {?}) | |
153 | AND (promo_max = 0 OR promo_max >= {?}) | |
154 | ORDER BY a.peremption", | |
155 | S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); | |
156 | $page->assign('article_index', $index); | |
157 | } else { | |
158 | $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo | |
159 | FROM groupex.announces AS a | |
160 | INNER JOIN auth_user_md5 AS u USING(user_id) | |
161 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() | |
010268b2 | 162 | AND FIND_IN_SET('public', u.flags)", |
24bcf50c | 163 | $globals->asso('id')); |
164 | } | |
165 | ||
166 | if (!S::has('core_rss_hash')) { | |
167 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques", | |
168 | "rss/rss.xml"); | |
169 | } else { | |
170 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News", | |
171 | 'rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml'); | |
172 | } | |
eaf30d86 | 173 | |
24bcf50c | 174 | $page->assign('articles', $arts); |
ae7bb180 | 175 | } |
dd798f38 | 176 | |
177 | function handler_logo(&$page) | |
178 | { | |
179 | global $globals; | |
180 | ||
08cce2ff | 181 | $res = XDB::query("SELECT logo, logo_mime |
24bcf50c | 182 | FROM groupex.asso WHERE id = {?}", |
183 | $globals->asso('id')); | |
dd798f38 | 184 | list($logo, $logo_mime) = $res->fetchOneRow(); |
185 | ||
186 | if (!empty($logo)) { | |
187 | header("Content-type: $mime"); | |
188 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | |
189 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); | |
190 | header('Cache-Control: no-cache, must-revalidate'); | |
191 | header('Pragma: no-cache'); | |
192 | echo $logo; | |
193 | } else { | |
194 | header('Content-type: image/jpeg'); | |
195 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | |
196 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); | |
197 | header('Cache-Control: no-cache, must-revalidate'); | |
198 | header('Pragma: no-cache'); | |
831fae47 | 199 | readfile(dirname(__FILE__).'/../htdocs/images/dflt_carre.jpg'); |
dd798f38 | 200 | } |
201 | ||
202 | exit; | |
203 | } | |
2e94d2b8 | 204 | |
d430f4d8 | 205 | function handler_site(&$page) |
206 | { | |
207 | global $globals; | |
208 | $site = $globals->asso('site'); | |
209 | if (!$site) { | |
210 | $page->trig('Le groupe n\'a pas de site web'); | |
211 | return $this->handler_index($page); | |
212 | } | |
02838718 | 213 | http_redirect($site); |
d430f4d8 | 214 | exit; |
215 | } | |
216 | ||
2e94d2b8 | 217 | function handler_edit(&$page) |
218 | { | |
219 | global $globals; | |
1490093c | 220 | $page->changeTpl('xnetgrp/edit.tpl'); |
2e94d2b8 | 221 | |
222 | if (Post::has('submit')) { | |
cab08090 | 223 | if (S::has_perms()) { |
5e2307dc | 224 | if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) { |
a7de4ef7 | 225 | $page->trig("le domaine doit être un FQDN (aucune modif effectuée) !!!"); |
c9110c6c | 226 | return; |
2e94d2b8 | 227 | } |
08cce2ff | 228 | XDB::execute( |
2e94d2b8 | 229 | "UPDATE groupex.asso |
230 | SET nom={?}, diminutif={?}, cat={?}, dom={?}, | |
231 | descr={?}, site={?}, mail={?}, resp={?}, | |
232 | forum={?}, mail_domain={?}, ax={?}, pub={?}, | |
794feea7 FB |
233 | sub_url={?}, inscriptible={?}, unsub_url={?}, |
234 | flags='wiki_desc' | |
2e94d2b8 | 235 | WHERE id={?}", |
5e2307dc | 236 | Post::v('nom'), Post::v('diminutif'), |
237 | Post::v('cat'), Post::i('dom'), | |
238 | Post::v('descr'), Post::v('site'), | |
239 | Post::v('mail'), Post::v('resp'), | |
240 | Post::v('forum'), Post::v('mail_domain'), | |
2c86d368 | 241 | Post::has('ax'), Post::v('pub'), |
5e2307dc | 242 | Post::v('sub_url'), Post::v('inscriptible'), |
30032578 | 243 | Post::v('unsub_url'),$globals->asso('id')); |
5e2307dc | 244 | if (Post::v('mail_domain')) { |
08cce2ff | 245 | XDB::execute('INSERT INTO virtual_domains (domain) VALUES({?})', |
5e2307dc | 246 | Post::v('mail_domain')); |
2e94d2b8 | 247 | } |
248 | } else { | |
08cce2ff | 249 | XDB::execute( |
2e94d2b8 | 250 | "UPDATE groupex.asso |
251 | SET descr={?}, site={?}, mail={?}, resp={?}, | |
30032578 | 252 | forum={?}, ax={?}, pub= {?}, sub_url={?}, |
794feea7 | 253 | unsub_url={?},flags='wiki_desc' |
2e94d2b8 | 254 | WHERE id={?}", |
5e2307dc | 255 | Post::v('descr'), Post::v('site'), |
256 | Post::v('mail'), Post::v('resp'), | |
257 | Post::v('forum'), Post::has('ax'), | |
2c86d368 | 258 | Post::has('pub'), |
30032578 | 259 | Post::v('sub_url'), Post::v('unsub_url'), |
260 | $globals->asso('id')); | |
2e94d2b8 | 261 | } |
262 | ||
263 | if ($_FILES['logo']['name']) { | |
264 | $logo = file_get_contents($_FILES['logo']['tmp_name']); | |
265 | $mime = $_FILES['logo']['type']; | |
08cce2ff | 266 | XDB::execute('UPDATE groupex.asso |
794feea7 FB |
267 | SET logo={?}, logo_mime={?} |
268 | WHERE id={?}', $logo, $mime, | |
269 | $globals->asso('id')); | |
2e94d2b8 | 270 | } |
271 | ||
5e2307dc | 272 | pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit'); |
2e94d2b8 | 273 | } |
274 | ||
cab08090 | 275 | if (S::has_perms()) { |
08cce2ff | 276 | $dom = XDB::iterator('SELECT * FROM groupex.dom ORDER BY nom'); |
2e94d2b8 | 277 | $page->assign('dom', $dom); |
278 | $page->assign('super', true); | |
279 | } | |
794feea7 FB |
280 | if (!$globals->asso('wiki_desc') && $globals->asso('descr')) { |
281 | $page->trig("Attention, le format de la description a changé et utilise désormais la syntaxe wiki " | |
da4195dc | 282 | . "intégrée au site. Il te faudra probablement adapter le formatage du texte actuel pour " |
794feea7 FB |
283 | . "qu'il s'affiche correctement avec cette nouvelle syntaxe."); |
284 | } | |
2e94d2b8 | 285 | } |
286 | ||
479d2787 | 287 | function handler_mail(&$page) |
288 | { | |
289 | global $globals; | |
290 | ||
1490093c | 291 | $page->changeTpl('xnetgrp/mail.tpl'); |
9bb8bf21 | 292 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
293 | $globals->asso('mail_domain')); | |
294 | $page->assign('listes', $mmlist->get_lists()); | |
fdbeba4f | 295 | $page->addJsLink('ajax.js'); |
479d2787 | 296 | |
297 | if (Post::has('send')) { | |
5e2307dc | 298 | $from = Post::v('from'); |
299 | $sujet = Post::v('sujet'); | |
300 | $body = Post::v('body'); | |
479d2787 | 301 | |
5e2307dc | 302 | $mls = array_keys(Env::v('ml', array())); |
06db561e | 303 | $mbr = array_keys(Env::v('membres', array())); |
479d2787 | 304 | |
06db561e | 305 | require_once dirname(__FILE__) . '/xnetgrp/mail.inc.php'; |
306 | $tos = get_all_redirects($mbr, $mls, $mmlist); | |
13627bef | 307 | $upload = PlUpload::get($_FILES['uploaded'], S::v('forlife'), 'xnet.emails', true); |
5b21237d | 308 | send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']); |
13627bef | 309 | if ($upload) { |
310 | $upload->rm(); | |
311 | } | |
a7de4ef7 | 312 | $page->kill("Mail envoyé !"); |
479d2787 | 313 | $page->assign('sent', true); |
314 | } | |
315 | } | |
316 | ||
4f355064 | 317 | function handler_forum(&$page, $group = null, $artid = null) |
318 | { | |
319 | global $globals; | |
1490093c | 320 | $page->changeTpl('xnetgrp/forum.tpl'); |
4f355064 | 321 | if (!$globals->asso('forum')) { |
322 | return PL_NOT_FOUND; | |
323 | } | |
324 | require_once 'banana/forum.inc.php'; | |
325 | $get = array(); | |
326 | get_banana_params($get, $globals->asso('forum'), $group, $artid); | |
327 | run_banana($page, 'ForumsBanana', $get); | |
328 | } | |
329 | ||
a91fb584 | 330 | function handler_annuaire(&$page, $action = null, $subaction = null) |
2e94d2b8 | 331 | { |
332 | global $globals; | |
a91fb584 | 333 | |
9ee54baf FB |
334 | if ($action == 'search') { |
335 | http_redirect("https://www.polytechnique.org/search/adv?rechercher=Chercher&groupex={$globals->asso('id')}" | |
336 | . "&cityid=" . Env::v('cityid') . "&mapid=" . Env::v('mapid')); | |
337 | } else if ($action == 'geoloc' || $action == 'trombi') { | |
a91fb584 | 338 | $view = new UserSet(); |
339 | $view->addMod('trombi', 'Trombinoscope'); | |
9ee54baf | 340 | $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'annuaire/search')); |
a91fb584 | 341 | $view->apply('annuaire', $page, $action, $subaction); |
342 | if ($action == 'geoloc' && $subaction) { | |
343 | return; | |
344 | } | |
345 | } | |
35fa92e8 | 346 | $page->changeTpl('xnetgrp/annuaire.tpl'); |
2e94d2b8 | 347 | |
e02ecfce | 348 | $sort = Env::v('order'); |
5e2307dc | 349 | switch (Env::v('order')) { |
2e94d2b8 | 350 | case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break; |
351 | case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break; | |
352 | case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break; | |
e02ecfce | 353 | default : $group = 'initiale'; $tri = 'nom, prenom, promo'; $sort = 'alpha'; |
2e94d2b8 | 354 | } |
e02ecfce | 355 | $page->assign('sort', $sort); |
2e94d2b8 | 356 | |
06db561e | 357 | if ($group == 'initiale') { |
08cce2ff | 358 | $res = XDB::iterRow( |
2e94d2b8 | 359 | 'SELECT UPPER(SUBSTRING( |
dc2073c3 | 360 | IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom), |
2e94d2b8 | 361 | 1, 1)) as letter, COUNT(*) |
362 | FROM groupex.membres AS m | |
310d50da | 363 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid) |
0fe005cc | 364 | WHERE asso_id = {?} and (u.perms != \'pending\' OR m.email IS NOT NULL) |
2e94d2b8 | 365 | GROUP BY letter |
366 | ORDER BY letter', $globals->asso('id')); | |
06db561e | 367 | } else { |
08cce2ff | 368 | $res = XDB::iterRow( |
06db561e | 369 | 'SELECT IF(m.origine="X",u.promo, |
a7de4ef7 | 370 | IF(m.origine="ext", "extérieur", "personne morale")) AS promo, |
2e94d2b8 | 371 | COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o |
372 | FROM groupex.membres AS m | |
373 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) | |
374 | WHERE asso_id = {?} | |
375 | GROUP BY promo | |
376 | ORDER BY promo_o DESC', $globals->asso('id')); | |
06db561e | 377 | } |
2e94d2b8 | 378 | $alphabet = array(); |
379 | $nb_tot = 0; | |
380 | while (list($char, $nb) = $res->next()) { | |
381 | $alphabet[] = $char; | |
382 | $nb_tot += $nb; | |
5e2307dc | 383 | if (Env::has($group) && $char == strtoupper(Env::v($group))) { |
2e94d2b8 | 384 | $tot = $nb; |
385 | } | |
386 | } | |
387 | $page->assign('group', $group); | |
5e2307dc | 388 | $page->assign('request_group', Env::v($group)); |
f2900e25 | 389 | $page->assign('only_admin', Env::has('admin')); |
2e94d2b8 | 390 | $page->assign('alphabet', $alphabet); |
391 | $page->assign('nb_tot', $nb_tot); | |
392 | ||
5e2307dc | 393 | $ofs = Env::i('offset'); |
394 | $tot = Env::v($group) ? $tot : $nb_tot; | |
2e94d2b8 | 395 | $nbp = intval(($tot-1)/NB_PER_PAGE); |
396 | $links = array(); | |
397 | if ($ofs) { | |
a7de4ef7 | 398 | $links['précédent'] = $ofs-1; |
2e94d2b8 | 399 | } |
400 | for ($i = 0; $i <= $nbp; $i++) { | |
401 | $links[(string)($i+1)] = $i; | |
402 | } | |
403 | if ($ofs < $nbp) { | |
404 | $links['suivant'] = $ofs+1; | |
405 | } | |
406 | if (count($links)>1) { | |
407 | $page->assign('links', $links); | |
408 | } | |
409 | ||
410 | $ini = ''; | |
411 | if (Env::has('initiale')) { | |
412 | $ini = 'AND IF(m.origine="X", | |
413 | IF(u.nom_usage<>"", u.nom_usage, u.nom), | |
5e2307dc | 414 | m.nom) LIKE "'.addslashes(Env::v('initiale')).'%"'; |
2e94d2b8 | 415 | } elseif (Env::has('promo')) { |
a7de4ef7 | 416 | $ini = 'AND IF(m.origine="X", u.promo, IF(m.origine="ext", "extérieur", "personne morale")) = "' |
5e2307dc | 417 | .addslashes(Env::v('promo')).'"'; |
f2900e25 | 418 | } elseif (Env::has('admin')) { |
419 | $ini = 'AND m.perms = "admin"'; | |
2e94d2b8 | 420 | } |
421 | ||
08cce2ff | 422 | $ann = XDB::iterator( |
2e94d2b8 | 423 | "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom, |
424 | IF(m.origine='X',u.prenom,m.prenom) AS prenom, | |
a7de4ef7 | 425 | IF(m.origine='X', u.promo, IF(m.origine='ext', 'extérieur', 'personne morale')) AS promo, |
2e94d2b8 | 426 | IF(m.origine='X',u.promo,'') AS promo_o, |
dc2073c3 | 427 | IF(m.origine='X' AND u.perms != 'pending',a.alias,m.email) AS email, |
0cc4c07d | 428 | IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme, |
2e94d2b8 | 429 | m.perms='admin' AS admin, |
430 | m.origine='X' AS x, | |
dc2073c3 | 431 | u.perms!='pending' AS inscrit, |
4a8a1e0a | 432 | m.uid, IF(e.email IS NULL,NULL,1) AS actif |
2e94d2b8 | 433 | FROM groupex.membres AS m |
434 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) | |
435 | LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' ) | |
e429fff0 | 436 | LEFT JOIN emails AS e ON ( e.flags = 'active' AND e.uid = m.uid) |
2e94d2b8 | 437 | WHERE m.asso_id = {?} $ini |
06db561e | 438 | AND (m.origine != 'X' OR u.perms != 'pending' OR m.email IS NOT NULL) |
eaf30d86 | 439 | GROUP BY m.uid |
2e94d2b8 | 440 | ORDER BY $tri |
441 | LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE); | |
2e94d2b8 | 442 | $page->assign('ann', $ann); |
4a8a1e0a | 443 | $page->jsonAssign('ann', $ann); |
2e94d2b8 | 444 | } |
4e310c61 | 445 | |
a91fb584 | 446 | function handler_trombi(&$page) |
447 | { | |
448 | pl_redirect('annuaire/trombi'); | |
449 | } | |
450 | ||
451 | function handler_geoloc(&$page) | |
28929cf0 | 452 | { |
a91fb584 | 453 | pl_redirect('annuaire/geoloc'); |
28929cf0 | 454 | } |
eaf30d86 | 455 | |
917c4d11 | 456 | function handler_vcard(&$page, $photos = null) |
5e193297 | 457 | { |
458 | global $globals; | |
35fa92e8 | 459 | $res = XDB::query('SELECT uid |
460 | FROM groupex.membres | |
461 | WHERE asso_id = {?}', $globals->asso('id')); | |
462 | $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); | |
463 | $vcard->do_page($page); | |
5e193297 | 464 | } |
465 | ||
fdf0200a | 466 | function handler_subscribe(&$page, $u = null) |
467 | { | |
c8faf82a | 468 | global $globals; |
1490093c | 469 | $page->changeTpl('xnetgrp/inscrire.tpl'); |
fdf0200a | 470 | |
471 | if (!$globals->asso('inscriptible')) | |
a7de4ef7 | 472 | $page->kill("Il n'est pas possible de s'inscire en ligne à ce " |
473 | ."groupe. Essaie de joindre le contact indiqué " | |
474 | ."sur la page de présentation."); | |
fdf0200a | 475 | |
476 | if (!is_null($u) && may_update()) { | |
477 | $page->assign('u', $u); | |
3c0031cd FB |
478 | $res = XDB::query("SELECT u.nom, u.prenom, u.promo, u.user_id, FIND_IN_SET('femme', u.flags) |
479 | FROM auth_user_md5 AS u | |
480 | INNER JOIN aliases AS al ON (al.id = u.user_id AND al.type != 'liste') | |
481 | WHERE al.alias = {?}", $u); | |
fdf0200a | 482 | |
3c0031cd | 483 | if (list($nom, $prenom, $promo, $uid, $sexe) = $res->fetchOneRow()) { |
08cce2ff | 484 | $res = XDB::query("SELECT COUNT(*) |
86cdc38d FB |
485 | FROM groupex.membres AS m |
486 | INNER JOIN aliases AS a ON (m.uid = a.id AND a.type != 'homonyme') | |
487 | WHERE a.alias = {?} AND m.asso_id = {?}", | |
488 | $u, $globals->asso('id')); | |
fdf0200a | 489 | $n = $res->fetchOneCell(); |
490 | if ($n) { | |
a7de4ef7 | 491 | $page->kill("$prenom $nom est déjà membre du groupe !"); |
c9110c6c | 492 | return; |
fdf0200a | 493 | } |
494 | elseif (Env::has('accept')) | |
495 | { | |
86cdc38d FB |
496 | XDB::execute("INSERT INTO groupex.membres (asso_id, uid) |
497 | VALUES ({?}, {?})", | |
fdf0200a | 498 | $globals->asso('id'), $uid); |
1e33266a | 499 | $mailer = new PlMailer(); |
fdf0200a | 500 | $mailer->addTo("$u@polytechnique.org"); |
cab08090 | 501 | $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom') |
502 | .'" <'.S::v('forlife').'@polytechnique.org>'); | |
fdf0200a | 503 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
3c0031cd | 504 | $message = ($sexe ? 'Chère' : 'Cher') . " Camarade,\n" |
fdf0200a | 505 | . "\n" |
a7de4ef7 | 506 | . " Suite à ta demande d'adhésion à ".$globals->asso('nom').",\n" |
507 | . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" | |
fdf0200a | 508 | . "\n" |
509 | . "Bien cordialement,\n" | |
510 | . "{$_SESSION["prenom"]} {$_SESSION["nom"]}."; | |
511 | $mailer->setTxtBody($message); | |
512 | $mailer->send(); | |
3c0031cd | 513 | $page->kill("$prenom $nom a bien été inscrit" . ($sexe ? 'e' : '')); |
fdf0200a | 514 | } |
515 | elseif (Env::has('refuse')) | |
516 | { | |
1e33266a | 517 | $mailer = new PlMailer(); |
fdf0200a | 518 | $mailer->addTo("$u@polytechnique.org"); |
cab08090 | 519 | $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom') |
520 | .'" <'.S::v('forlife').'@polytechnique.org>'); | |
a7de4ef7 | 521 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée'); |
5e2307dc | 522 | $mailer->setTxtBody(Env::v('motif')); |
fdf0200a | 523 | $mailer->send(); |
a7de4ef7 | 524 | $page->kill("la demande $prenom $nom a bien été refusée"); |
fdf0200a | 525 | } else { |
526 | $page->assign('show_form', true); | |
527 | $page->assign('prenom', $prenom); | |
528 | $page->assign('nom', $nom); | |
529 | $page->assign('promo', $promo); | |
530 | $page->assign('uid', $uid); | |
531 | } | |
532 | return; | |
533 | } | |
534 | return PL_NOT_FOUND; | |
535 | } | |
536 | ||
537 | if (is_member()) { | |
a7de4ef7 | 538 | $page->kill("tu es déjà membre !"); |
fdf0200a | 539 | return; |
540 | } | |
541 | ||
542 | if (Post::has('inscrire')) { | |
08cce2ff | 543 | $res = XDB::query('SELECT IF(m.email IS NULL, |
fdf0200a | 544 | CONCAT(al.alias,"@polytechnique.org"), |
545 | m.email) | |
546 | FROM groupex.membres AS m | |
547 | INNER JOIN aliases AS al ON (al.type = "a_vie" | |
548 | AND al.id = m.uid) | |
549 | WHERE perms="admin" AND m.asso_id = {?}', | |
550 | $globals->asso('id')); | |
551 | $emails = $res->fetchColumn(); | |
552 | $to = implode(',', $emails); | |
553 | ||
554 | $append = "\n" | |
555 | . "-- \n" | |
a7de4ef7 | 556 | . "Ce message a été envoyé suite à la demande d'inscription de\n" |
cab08090 | 557 | . S::v('prenom').' '.S::v('nom').' (X'.S::v('promo').")\n" |
fdf0200a | 558 | . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n" |
559 | . "de refuser sa demande d'inscription depuis la page :\n" | |
560 | . | |
561 | "http://www.polytechnique.net/".$globals->asso("diminutif")."/subscribe/" | |
cab08090 | 562 | .S::v('forlife')."\n" |
fdf0200a | 563 | . "\n" |
a7de4ef7 | 564 | . "En cas de problème, contacter l'équipe de Polytechnique.org\n" |
565 | . "à l'adresse : support@polytechnique.org\n"; | |
fdf0200a | 566 | |
567 | if (!$to) { | |
568 | $to = $globals->asso("mail").", support@polytechnique.org"; | |
569 | $append = "\n-- \nLe groupe ".$globals->asso("nom") | |
a7de4ef7 | 570 | ." n'a pas d'administrateur, l'équipe de" |
571 | ." Polytechnique.org a été prévenue et va rapidement" | |
572 | ." résoudre ce problème.\n"; | |
fdf0200a | 573 | } |
574 | ||
1e33266a | 575 | $mailer = new PlMailer(); |
fdf0200a | 576 | $mailer->addTo($to); |
cab08090 | 577 | $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom') |
578 | .'" <'.S::v('forlife').'@polytechnique.org>'); | |
fdf0200a | 579 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
5e2307dc | 580 | $mailer->setTxtBody(Post::v('message').$append); |
fdf0200a | 581 | $mailer->send(); |
582 | } | |
583 | } | |
584 | ||
b8e265bf | 585 | function handler_change_rights(&$page) |
586 | { | |
587 | if (Env::has('right') && (may_update() || S::has('suid'))) { | |
588 | switch (Env::v('right')) { | |
eaf30d86 | 589 | case 'admin': |
0deaff1d | 590 | XnetSession::killSuid(); |
b8e265bf | 591 | break; |
592 | case 'anim': | |
0deaff1d | 593 | XnetSession::doSelfSuid(); |
b8e265bf | 594 | may_update(true); |
595 | is_member(true); | |
596 | break; | |
597 | case 'member': | |
eaf30d86 | 598 | XnetSession::doSelfSuid(); |
b8e265bf | 599 | may_update(false, true); |
600 | is_member(true); | |
601 | break; | |
602 | case 'logged': | |
0deaff1d | 603 | XnetSession::doSelfSuid(); |
b8e265bf | 604 | may_update(false, true); |
605 | is_member(false, true); | |
606 | break; | |
607 | } | |
608 | } | |
5603d2ce | 609 | http_redirect($_SERVER['HTTP_REFERER']); |
b8e265bf | 610 | } |
611 | ||
4e310c61 | 612 | function handler_admin_annuaire(&$page) |
613 | { | |
614 | global $globals; | |
615 | ||
dd3c9785 | 616 | require_once dirname(__FILE__) . '/xnetgrp/mail.inc.php'; |
1490093c | 617 | $page->changeTpl('xnetgrp/annuaire-admin.tpl'); |
9bb8bf21 | 618 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
619 | $globals->asso('mail_domain')); | |
620 | $lists = $mmlist->get_lists(); | |
4e310c61 | 621 | if (!$lists) $lists = array(); |
622 | $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists); | |
623 | ||
624 | $subscribers = array(); | |
625 | ||
626 | foreach ($listes as $list) { | |
9bb8bf21 | 627 | list(,$members) = $mmlist->get_members($list); |
4e310c61 | 628 | $mails = array_map(create_function('$arr', 'return $arr[1];'), $members); |
629 | $subscribers = array_unique(array_merge($subscribers, $mails)); | |
630 | } | |
631 | ||
632 | $not_in_group_x = array(); | |
633 | $not_in_group_ext = array(); | |
634 | ||
635 | foreach ($subscribers as $mail) { | |
08cce2ff | 636 | $res = XDB::query( |
4e310c61 | 637 | 'SELECT COUNT(*) |
638 | FROM groupex.membres AS m | |
639 | LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000) | |
640 | LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie") | |
641 | WHERE asso_id = {?} AND | |
642 | (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})', | |
643 | $globals->asso('id'), $mail, $mail); | |
644 | if ($res->fetchOneCell() == 0) { | |
645 | if (strstr($mail, '@polytechnique.org') === false) { | |
646 | $not_in_group_ext[] = $mail; | |
647 | } else { | |
648 | $not_in_group_x[] = $mail; | |
649 | } | |
650 | } | |
651 | } | |
652 | ||
653 | $page->assign('not_in_group_ext', $not_in_group_ext); | |
654 | $page->assign('not_in_group_x', $not_in_group_x); | |
655 | $page->assign('lists', $lists); | |
656 | } | |
ef7c8560 | 657 | |
658 | function handler_admin_member_new(&$page, $email = null) | |
659 | { | |
660 | global $globals; | |
661 | ||
1490093c | 662 | $page->changeTpl('xnetgrp/membres-add.tpl'); |
dc2073c3 | 663 | $page->addJsLink('ajax.js'); |
ef7c8560 | 664 | |
665 | if (is_null($email)) { | |
666 | return; | |
667 | } | |
668 | ||
b9dcbddd | 669 | if (strpos($email, '@') === false) { |
670 | $x = true; | |
671 | } else { | |
672 | list(,$fqdn) = explode('@', $email, 2); | |
673 | $fqdn = strtolower($fqdn); | |
674 | $x = ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org' || | |
675 | $fqdn == 'm4x.org' || $fqdn == 'melix.net'); | |
676 | } | |
ef7c8560 | 677 | if ($x) { |
678 | require_once 'user.func.inc.php'; | |
679 | if ($forlife = get_user_forlife($email)) { | |
08cce2ff | 680 | XDB::execute( |
ef7c8560 | 681 | 'INSERT INTO groupex.membres (uid,asso_id,origine) |
ed21e24a | 682 | SELECT user_id,{?},"X" |
683 | FROM auth_user_md5 AS u | |
684 | INNER JOIN aliases AS a ON (u.user_id = a.id) | |
685 | WHERE a.alias={?}', $globals->asso('id'), $forlife); | |
65e7b636 | 686 | pl_redirect("member/$forlife"); |
ef7c8560 | 687 | } else { |
688 | $page->trig($email." n'est pas un alias polytechnique.org valide"); | |
689 | } | |
690 | } else { | |
b9dcbddd | 691 | require_once 'xorg.misc.inc.php'; |
ef7c8560 | 692 | if (isvalid_email($email)) { |
dc2073c3 | 693 | if (Env::v('x') && Env::has('userid') && Env::i('userid')) { |
694 | $uid = Env::i('userid'); | |
695 | $res = XDB::query("SELECT * | |
696 | FROM auth_user_md5 | |
06db561e | 697 | WHERE user_id = {?} AND perms = 'pending'", $uid); |
dc2073c3 | 698 | if ($res->numRows() == 1) { |
dc2073c3 | 699 | if (Env::v('market')) { |
e654517d | 700 | $market = Marketing::get($uid, $email); |
701 | if (!$market) { | |
702 | $market = new Marketing($uid, $email, 'group', $globals->asso('nom'), | |
703 | Env::v('market_from'), S::v('uid')); | |
704 | $market->add(); | |
eaf30d86 | 705 | } |
dc2073c3 | 706 | } |
e654517d | 707 | XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email) |
708 | VALUES ({?}, {?}, "X", {?})', | |
709 | $uid, $globals->asso('id'), $email); | |
dc2073c3 | 710 | pl_redirect("member/$email"); |
711 | } | |
712 | $page->trig("Utilisateur invalide"); | |
713 | } else { | |
714 | $res = XDB::query('SELECT MAX(uid)+1 FROM groupex.membres'); | |
715 | $uid = max(intval($res->fetchOneCell()), 50001); | |
716 | XDB::execute('INSERT INTO groupex.membres (uid,asso_id,origine,email) | |
717 | VALUES({?},{?},"ext",{?})', $uid, | |
718 | $globals->asso('id'), $email); | |
719 | pl_redirect("member/$email"); | |
720 | } | |
ef7c8560 | 721 | } else { |
a7de4ef7 | 722 | $page->trig("« <strong>$email</strong> » n'est pas une adresse mail valide"); |
ef7c8560 | 723 | } |
724 | } | |
725 | } | |
726 | ||
dc2073c3 | 727 | function handler_admin_member_new_ajax(&$page) |
728 | { | |
493b6abe | 729 | header('Content-Type: text/html; charset="UTF-8"'); |
8b1f8e12 | 730 | $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); |
e2b0a45c | 731 | $res = null; |
0baf0741 | 732 | if (Env::has('login')) { |
733 | require_once 'user.func.inc.php'; | |
734 | $res = get_not_registered_user(Env::v('login'), true); | |
e2b0a45c | 735 | } |
736 | if (is_null($res)) { | |
0baf0741 | 737 | list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom'))); |
738 | $where = "perms = 'pending'"; | |
739 | if (!empty($nom)) { | |
740 | $where .= " AND nom LIKE '%$nom%'"; | |
741 | } | |
742 | if (!empty($prenom)) { | |
743 | $where .= " AND prenom LIKE '%$prenom%'"; | |
744 | } | |
745 | if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) { | |
746 | $where .= " AND promo = " . Env::i('promo'); | |
747 | } elseif (preg_match('/^[0-9]{2}$/', Env::v('promo'))) { | |
748 | $where .= " AND MOD(promo, 100) = " . Env::i('promo'); | |
749 | } elseif (Env::has('promo')) { | |
750 | return; | |
751 | } | |
752 | $res = XDB::iterator("SELECT user_id, nom, prenom, promo | |
753 | FROM auth_user_md5 | |
754 | WHERE $where"); | |
dc2073c3 | 755 | } |
89d5acb4 | 756 | if ($res && $res->total() < 30) { |
dc2073c3 | 757 | $page->assign("choix", $res); |
758 | } | |
759 | } | |
760 | ||
30032578 | 761 | function unsubscribe(&$user) |
ef7c8560 | 762 | { |
30032578 | 763 | global $globals, $page; |
08cce2ff | 764 | XDB::execute( |
ef7c8560 | 765 | "DELETE FROM groupex.membres WHERE uid={?} AND asso_id={?}", |
766 | $user['uid'], $globals->asso('id')); | |
767 | ||
ef7c8560 | 768 | $user_same_email = get_infos($user['email']); |
30032578 | 769 | $domain = $globals->asso('mail_domain'); |
ef7c8560 | 770 | |
30032578 | 771 | if (!$domain || !empty($user_same_email)) { |
772 | return true; | |
773 | } | |
ef7c8560 | 774 | |
30032578 | 775 | $mmlist = new MMList(S::v('uid'), S::v('password'), $domain); |
776 | $listes = $mmlist->get_lists($user['email2']); | |
ef7c8560 | 777 | |
30032578 | 778 | $may_update = may_update(); |
779 | $warning = false; | |
780 | foreach ($listes as $liste) { | |
781 | if ($liste['sub'] == 2) { | |
782 | if ($may_update) { | |
9bb8bf21 | 783 | $mmlist->mass_unsubscribe($liste['list'], Array($user['email2'])); |
30032578 | 784 | } else { |
785 | $mmlist->unsubscribe($liste['list']); | |
ef7c8560 | 786 | } |
30032578 | 787 | } elseif ($liste['sub']) { |
788 | $page->trig("{$user['prenom']} {$user['nom']} a une" | |
789 | ." demande d'inscription en cours sur la" | |
790 | ." liste {$liste['list']}@ !"); | |
791 | $warning = true; | |
ef7c8560 | 792 | } |
30032578 | 793 | } |
ef7c8560 | 794 | |
30032578 | 795 | XDB::execute( |
796 | "DELETE FROM virtual_redirect | |
797 | USING virtual_redirect | |
798 | INNER JOIN virtual USING(vid) | |
799 | WHERE redirect={?} AND alias LIKE {?}", $user['email'], '%@'.$domain); | |
800 | return !$warning; | |
801 | } | |
802 | ||
803 | function handler_unsubscribe(&$page) | |
804 | { | |
1490093c | 805 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
30032578 | 806 | $user = get_infos(S::v('forlife')); |
807 | if (empty($user)) { | |
808 | return PL_NOT_FOUND; | |
ef7c8560 | 809 | } |
30032578 | 810 | $page->assign('self', true); |
811 | $page->assign('user', $user); | |
ef7c8560 | 812 | |
30032578 | 813 | if (!Post::has('confirm')) { |
814 | return; | |
815 | } | |
816 | ||
817 | if ($this->unsubscribe($user)) { | |
da4195dc | 818 | $page->trig('Vous avez été désinscrit du groupe avec succès.'); |
30032578 | 819 | } else { |
a7de4ef7 | 820 | $page->trig('Vous avez été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des mailing-lists.'); |
30032578 | 821 | } |
c1863ee9 | 822 | $page->assign('is_member', is_member(true)); |
30032578 | 823 | } |
824 | ||
825 | function handler_admin_member_del(&$page, $user = null) | |
826 | { | |
1490093c | 827 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
30032578 | 828 | $user = get_infos($user); |
829 | if (empty($user)) { | |
830 | return PL_NOT_FOUND; | |
831 | } | |
832 | $page->assign('user', $user); | |
833 | ||
834 | if (!Post::has('confirm')) { | |
835 | return; | |
836 | } | |
837 | ||
838 | if ($this->unsubscribe($user)) { | |
a7de4ef7 | 839 | $page->trig("{$user['prenom']} {$user['nom']} a été désabonné du groupe !"); |
30032578 | 840 | } else { |
a7de4ef7 | 841 | $page->trig("{$user['prenom']} {$user['nom']} a été désabonné du groupe, mais des erreurs subsistent !"); |
30032578 | 842 | } |
ef7c8560 | 843 | } |
844 | ||
631565e1 FB |
845 | private function changeLogin(PlatalPage &$page, array &$user, MMList &$mmlist, $login) |
846 | { | |
847 | require_once 'user.func.inc.php'; | |
848 | // Search the uid of the user... | |
849 | $res = XDB::query("SELECT f.id, f.alias | |
850 | FROM aliases AS a | |
851 | INNER JOIN aliases AS f ON (f.id = a.id AND f.type = 'a_vie') | |
852 | WHERE a.alias = {?}", | |
853 | $login); | |
854 | if ($res->numRows() == 0) { | |
855 | $x = get_not_registered_user($login); | |
856 | if (!$x) { | |
857 | $page->trig("Le login $login ne correspond à aucun X"); | |
858 | return false; | |
859 | } else if (count($x) > 1) { | |
860 | $page->trig("Le login $login correspond a plusieurs camarades"); | |
861 | return false; | |
862 | } | |
863 | $uid = $x[0]['user_id']; | |
864 | $sub = false; | |
865 | } else { | |
866 | list($uid, $login) = $res->fetchOneRow(); | |
867 | $sub = true; | |
868 | } | |
869 | ||
870 | // Check if the user is already in the group | |
871 | global $globals; | |
872 | $res = XDB::query("SELECT uid, email | |
873 | FROM groupex.membres | |
874 | WHERE uid = {?} AND asso_id = {?}", | |
875 | $uid, $globals->asso('id')); | |
876 | if ($res->numRows()) { | |
877 | list($uid, $email) = $res->fetchOneRow(); | |
878 | XDB::execute("DELETE FROM groupex.membres | |
879 | WHERE uid = {?}", | |
880 | $user['uid']); | |
881 | } else { | |
882 | $email = $user['email']; | |
883 | XDB::execute("UPDATE groupex.membres | |
884 | SET uid = {?}, origine = 'X' | |
885 | WHERE uid = {?} AND asso_id = {?}", | |
886 | $uid, $user['uid'], $globals->asso('id')); | |
887 | } | |
888 | if ($sub) { | |
889 | $email = $login . '@' . $globals->mail->domain; | |
890 | } | |
891 | ||
892 | // Update subscription to aliases | |
893 | if ($email != $user['email']) { | |
894 | XDB::execute("UPDATE IGNORE virtual_redirect AS vr | |
895 | INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', 2) = {?}) | |
896 | SET vr.redirect = {?} | |
897 | WHERE vr.redirect = {?}", | |
898 | $globals->asso('mail_domain'), $email, $user['email']); | |
899 | XDB::execute("DELETE vr.* | |
900 | FROM virtual_redirect AS vr | |
901 | INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', 2) = {?}) | |
902 | WHERE vr.redirect = {?}", | |
903 | $globals->asso('mail_domain'), $user['email']); | |
904 | foreach (Env::v('ml1', array()) as $ml => $state) { | |
905 | $mmlist->replace_email($ml, $user['email'], $email); | |
906 | } | |
907 | } | |
908 | return $login; | |
909 | } | |
910 | ||
ef7c8560 | 911 | function handler_admin_member(&$page, $user) |
912 | { | |
913 | global $globals; | |
914 | ||
1490093c | 915 | $page->changeTpl('xnetgrp/membres-edit.tpl'); |
ef7c8560 | 916 | |
917 | $user = get_infos($user); | |
918 | if (empty($user)) { | |
919 | return PL_NOT_FOUND; | |
920 | } | |
921 | ||
9bb8bf21 | 922 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
923 | $globals->asso('mail_domain')); | |
ef7c8560 | 924 | |
925 | if (Post::has('change')) { | |
631565e1 FB |
926 | // Convert user status to X |
927 | if ($user['origine'] == 'ext' && trim(Post::v('login_X'))) { | |
928 | $forlife = $this->changeLogin($page, $user, $mmlist, trim(Post::v('login_X'))); | |
929 | if ($forlife) { | |
930 | pl_redirect('member/' . $forlife); | |
931 | } | |
932 | } | |
933 | ||
934 | // Update user info | |
cf5e8ef1 | 935 | $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email'))); |
c4d57bd8 | 936 | $from_email = $user['email']; |
ef7c8560 | 937 | if ($user['origine'] != 'X') { |
06db561e | 938 | $user['nom'] = Post::v('nom'); |
939 | $user['prenom'] = (Post::v('origine') == 'ext') ? Post::v('prenom') : ''; | |
940 | $user['sexe'] = (Post::v('origine') == 'ext') ? Post::v('sexe') : 0; | |
941 | $user['origine'] = Post::v('origine'); | |
08cce2ff | 942 | XDB::query('UPDATE groupex.membres |
06db561e | 943 | SET prenom={?}, nom={?}, email={?}, sexe={?}, origine={?} |
0cc4c07d | 944 | WHERE uid={?} AND asso_id={?}', |
06db561e | 945 | $user['prenom'], $user['nom'], Post::v('email'), |
946 | $user['sexe'], $user['origine'], $user['uid'], | |
947 | $globals->asso('id')); | |
948 | $user['email'] = Post::v('email'); | |
949 | $user['email2'] = Post::v('email'); | |
ef7c8560 | 950 | } |
951 | ||
5e2307dc | 952 | $perms = Post::i('is_admin'); |
ef7c8560 | 953 | if ($user['perms'] != $perms) { |
08cce2ff | 954 | XDB::query('UPDATE groupex.membres SET perms={?} |
0cc4c07d | 955 | WHERE uid={?} AND asso_id={?}', |
956 | $perms ? 'admin' : 'membre', | |
957 | $user['uid'], $globals->asso('id')); | |
ef7c8560 | 958 | $user['perms'] = $perms; |
a7de4ef7 | 959 | $page->trig('permissions modifiées'); |
ef7c8560 | 960 | } |
961 | ||
631565e1 | 962 | // Update ML subscriptions |
5e2307dc | 963 | foreach (Env::v('ml1', array()) as $ml => $state) { |
ef7c8560 | 964 | $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; |
c4d57bd8 | 965 | if ($ask == $state) { |
06db561e | 966 | if ($state && $email_changed) { |
c4d57bd8 | 967 | $mmlist->replace_email($ml, $from_email, $user['email2']); |
a7de4ef7 | 968 | $page->trig("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour"); |
c4d57bd8 | 969 | } |
970 | continue; | |
971 | } | |
ef7c8560 | 972 | if ($state == '1') { |
973 | $page->trig("{$user['prenom']} {$user['nom']} a " | |
974 | ."actuellement une demande d'inscription en " | |
975 | ."cours sur <strong>$ml@</strong> !!!"); | |
976 | } elseif ($ask) { | |
9bb8bf21 | 977 | $mmlist->mass_subscribe($ml, Array($user['email2'])); |
a7de4ef7 | 978 | $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml@"); |
ef7c8560 | 979 | } else { |
c4d57bd8 | 980 | if ($email_changed) { |
981 | $mmlist->mass_unsubscribe($ml, Array($from_email)); | |
982 | } else { | |
983 | $mmlist->mass_unsubscribe($ml, Array($user['email2'])); | |
984 | } | |
a7de4ef7 | 985 | $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml@"); |
ef7c8560 | 986 | } |
987 | } | |
988 | ||
631565e1 | 989 | // Change subscriptioin to aliases |
5e2307dc | 990 | foreach (Env::v('ml3', array()) as $ml => $state) { |
ef7c8560 | 991 | $ask = !empty($_REQUEST['ml4'][$ml]); |
992 | if($state == $ask) continue; | |
993 | if($ask) { | |
08cce2ff | 994 | XDB::query("INSERT INTO virtual_redirect (vid,redirect) |
dc2073c3 | 995 | SELECT vid,{?} FROM virtual WHERE alias={?}", |
996 | $user['email'], $ml); | |
a7de4ef7 | 997 | $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml"); |
ef7c8560 | 998 | } else { |
08cce2ff | 999 | XDB::query("DELETE FROM virtual_redirect |
dc2073c3 | 1000 | USING virtual_redirect |
1001 | INNER JOIN virtual USING(vid) | |
1002 | WHERE redirect={?} AND alias={?}", | |
1003 | $user['email'], $ml); | |
a7de4ef7 | 1004 | $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml"); |
ef7c8560 | 1005 | } |
1006 | } | |
1007 | } | |
1008 | ||
1009 | $page->assign('user', $user); | |
9bb8bf21 | 1010 | $listes = $mmlist->get_lists($user['email2']); |
ef7c8560 | 1011 | $page->assign('listes', $listes); |
1012 | ||
08cce2ff | 1013 | $res = XDB::query( |
ef7c8560 | 1014 | 'SELECT alias, redirect IS NOT NULL as sub |
1015 | FROM virtual AS v | |
1016 | LEFT JOIN virtual_redirect AS vr ON(v.vid=vr.vid AND redirect={?}) | |
1017 | WHERE alias LIKE {?} AND type="user"', | |
1018 | $user['email'], '%@'.$globals->asso('mail_domain')); | |
1019 | $page->assign('alias', $res->fetchAllAssoc()); | |
1020 | } | |
24bcf50c | 1021 | |
1022 | function handler_rss(&$page, $user = null, $hash = null) | |
1023 | { | |
1024 | global $globals; | |
1025 | require_once('rss.inc.php'); | |
8b1f8e12 | 1026 | $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false); |
24bcf50c | 1027 | |
1028 | if ($uid) { | |
1029 | $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date, | |
1030 | IF(u2.nom_usage != '', u2.nom_usage, u2.nom) AS nom, u2.prenom, u2.promo | |
1031 | FROM auth_user_md5 AS u | |
1032 | INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo) | |
1033 | AND (a.promo_max = 0 OR a.promo_max <= u.promo)) | |
1034 | INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id) | |
98a7e9dc | 1035 | WHERE u.user_id = {?} AND peremption >= NOW() AND a.asso_id = {?}", |
1036 | $uid, $globals->asso('id')); | |
24bcf50c | 1037 | } else { |
1038 | $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.create_date, | |
1039 | IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo | |
1040 | FROM groupex.announces AS a | |
1041 | INNER JOIN auth_user_md5 AS u USING(user_id) | |
010268b2 | 1042 | WHERE FIND_IN_SET('public', a.flags) AND peremption >= NOW() AND a.asso_id = {?}", |
98a7e9dc | 1043 | $globals->asso('id')); |
24bcf50c | 1044 | } |
1045 | $page->assign('asso', $globals->asso()); | |
1046 | $page->assign('rss', $rss); | |
1047 | } | |
1048 | ||
1049 | function handler_edit_announce(&$page, $aid = null) | |
1050 | { | |
1051 | global $globals, $platal; | |
1490093c | 1052 | $page->changeTpl('xnetgrp/announce-edit.tpl'); |
24bcf50c | 1053 | $page->assign('new', is_null($aid)); |
1054 | $art = array(); | |
1055 | ||
1056 | if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer') { | |
1057 | if (!is_null($aid)) { | |
1058 | $art['id'] = $aid; | |
1059 | } | |
1060 | $art['titre'] = Post::v('titre'); | |
1061 | $art['texte'] = Post::v('texte'); | |
1062 | $art['contacts'] = Post::v('contacts'); | |
1063 | $art['promo_min'] = Post::i('promo_min'); | |
1064 | $art['promo_max'] = Post::i('promo_max'); | |
1065 | $art['nom'] = S::v('nom'); | |
1066 | $art['prenom'] = S::v('prenom'); | |
1067 | $art['promo'] = S::v('promo'); | |
1068 | $art['forlife'] = S::v('forlife'); | |
1069 | $art['peremption'] = Post::v('peremption'); | |
1070 | $art['public'] = Post::has('public'); | |
1071 | $art['xorg'] = Post::has('xorg'); | |
1072 | $art['nl'] = Post::has('nl'); | |
1073 | $art['event'] = Post::v('event'); | |
1074 | ||
1075 | $art['contact_html'] = $art['contacts']; | |
b9a1ba64 | 1076 | if ($art['event']) { |
1077 | $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}"; | |
24bcf50c | 1078 | } |
2a557a09 | 1079 | |
1080 | if (!$art['public'] && | |
d1c97e42 | 1081 | (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) || |
2a557a09 | 1082 | ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) || |
1083 | ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020)))) | |
1084 | { | |
1085 | $page->trig("L'intervalle de promotions est invalide"); | |
1086 | Post::kill('valid'); | |
1087 | } | |
1970c12b | 1088 | |
1089 | if (!trim($art['titre']) || !trim($art['texte'])) { | |
1090 | $page->trig("L'article doit avoir un titre et un contenu"); | |
1091 | Post::kill('valid'); | |
1092 | } | |
24bcf50c | 1093 | } |
1094 | ||
1095 | if (Post::v('valid') == 'Enregistrer') { | |
2a557a09 | 1096 | $promo_min = ($art['public'] ? 0 : $art['promo_min']); |
1097 | $promo_max = ($art['public'] ? 0 : $art['promo_max']); | |
24bcf50c | 1098 | if (is_null($aid)) { |
eaf30d86 PH |
1099 | $fulltext = $art['texte']; |
1100 | if (!empty($art['contact_html'])) { | |
1101 | $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html']; | |
e219710a | 1102 | } |
1103 | $post = null; | |
1104 | if ($globals->asso('forum')) { | |
1105 | require_once 'banana/forum.inc.php'; | |
1106 | $banana = new ForumsBanana(S::v('forlife')); | |
1107 | $post = $banana->post($globals->asso('forum'), null, | |
1108 | $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80)); | |
1109 | } | |
24bcf50c | 1110 | XDB::query("INSERT INTO groupex.announces |
1111 | (user_id, asso_id, create_date, titre, texte, contacts, | |
e219710a | 1112 | peremption, promo_min, promo_max, flags, post_id) |
1113 | VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", | |
24bcf50c | 1114 | S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], |
e219710a | 1115 | $art['peremption'], $promo_min, $promo_max, $art['public'] ? 'public' : '', $post); |
8b83a166 | 1116 | $aid = XDB::insertId(); |
24bcf50c | 1117 | if ($art['xorg']) { |
1118 | require_once('validations.inc.php'); | |
794feea7 | 1119 | $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, |
24bcf50c | 1120 | $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid')); |
1121 | $article->submit(); | |
1122 | $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation"); | |
1123 | } | |
1124 | if ($art['nl']) { | |
1125 | require_once('validations.inc.php'); | |
2a557a09 | 1126 | $article = new NLReq(S::v('uid'), $globals->asso('nom') . " : " .$art['titre'], |
1127 | $art['texte'], $art['contact_html']); | |
24bcf50c | 1128 | $article->submit(); |
1129 | $page->trig("La parution dans la Lettre Mensuelle est en attente de validation"); | |
1130 | } | |
1131 | } else { | |
1132 | XDB::query("UPDATE groupex.announces | |
1133 | SET titre={?}, texte={?}, contacts={?}, peremption={?}, | |
1134 | promo_min={?}, promo_max={?}, flags={?} | |
1135 | WHERE id={?} AND asso_id={?}", | |
1136 | $art['titre'], $art['texte'], $art['contacts'], $art['peremption'], | |
2a557a09 | 1137 | $promo_min, $promo_max, $art['public'] ? 'public' : '', |
24bcf50c | 1138 | $art['id'], $globals->asso('id')); |
1139 | } | |
2a557a09 | 1140 | } |
1141 | if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') { | |
24bcf50c | 1142 | pl_redirect(""); |
eaf30d86 | 1143 | } |
24bcf50c | 1144 | |
1145 | if (empty($art) && !is_null($aid)) { | |
1146 | $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife, | |
010268b2 | 1147 | FIND_IN_SET('public', a.flags) AS public |
24bcf50c | 1148 | FROM groupex.announces AS a |
1149 | INNER JOIN auth_user_md5 AS u USING(user_id) | |
1150 | INNER JOIN aliases AS l ON (l.id = u.user_id AND l.type = 'a_vie') | |
1151 | WHERE asso_id = {?} AND a.id = {?}", | |
1152 | $globals->asso('id'), $aid); | |
1153 | if ($res->numRows()) { | |
1154 | $art = $res->fetchOneAssoc(); | |
1155 | $art['contact_html'] = $art['contacts']; | |
1156 | } else { | |
a7de4ef7 | 1157 | $page->kill("Aucun article correspond à l'identifiant indiqué"); |
24bcf50c | 1158 | } |
1159 | } | |
1160 | ||
24bcf50c | 1161 | if (is_null($aid)) { |
1162 | $events = XDB::iterator("SELECT * | |
1163 | FROM groupex.evenements | |
1164 | WHERE asso_id = {?} AND archive = 0", | |
1165 | $globals->asso('id')); | |
1166 | if ($events->total()) { | |
1167 | $page->assign('events', $events); | |
1168 | } | |
eaf30d86 | 1169 | } |
24bcf50c | 1170 | |
72b2f8bb | 1171 | $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']); |
24bcf50c | 1172 | $page->assign('art', $art); |
1173 | } | |
1174 | ||
1175 | function handler_admin_announce(&$page) | |
1176 | { | |
1177 | global $globals; | |
1490093c | 1178 | $page->changeTpl('xnetgrp/announce-admin.tpl'); |
24bcf50c | 1179 | |
1180 | if (Env::has('del')) { | |
e219710a | 1181 | XDB::execute("DELETE FROM groupex.announces |
1182 | WHERE id = {?} AND asso_id = {?}", | |
24bcf50c | 1183 | Env::i('del'), $globals->asso('id')); |
1184 | } | |
e219710a | 1185 | $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime |
1186 | FROM groupex.announces AS a | |
1187 | WHERE a.asso_id = {?} | |
1188 | ORDER BY a.peremption DESC", | |
24bcf50c | 1189 | $globals->asso('id')); |
1190 | $page->assign('articles', $res); | |
1191 | } | |
ae7bb180 | 1192 | } |
1193 | ||
a7de4ef7 | 1194 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
ae7bb180 | 1195 | ?> |