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