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