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