Commit | Line | Data |
---|---|---|
ae7bb180 | 1 | <?php |
2 | /*************************************************************************** | |
c441aabe | 3 | * Copyright (C) 2003-2014 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), | |
bfe9f4c7 SJ |
32 | '%grp/edit' => $this->make_hook('edit', AUTH_PASSWD, 'groupadmin'), |
33 | '%grp/mail' => $this->make_hook('mail', AUTH_PASSWD, 'groupadmin'), | |
32bc85cc | 34 | '%grp/forum' => $this->make_hook('forum', AUTH_PASSWD, 'groupannu'), |
bfe9f4c7 SJ |
35 | '%grp/former_users' => $this->make_hook('former_users', AUTH_PASSWD, 'admin'), |
36 | '%grp/annuaire' => $this->make_hook('annuaire', AUTH_PASSWD, 'groupannu'), | |
37 | '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_PASSWD, 'groupmember:groupannu'), | |
38 | '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_PASSWD, 'groupmember:groupannu'), | |
39 | '%grp/directory/sync' => $this->make_hook('directory_sync', AUTH_PASSWD, 'groupadmin'), | |
40 | '%grp/directory/unact' => $this->make_hook('non_active', AUTH_PASSWD, 'groupadmin'), | |
8408316e | 41 | '%grp/directory/awact' => $this->make_hook('awaiting_active', AUTH_PASSWD, 'groupadmin'), |
bfe9f4c7 SJ |
42 | '%grp/trombi' => $this->make_hook('trombi', AUTH_PASSWD, 'groupannu'), |
43 | '%grp/geoloc' => $this->make_hook('geoloc', AUTH_PASSWD, 'groupannu'), | |
44 | '%grp/subscribe' => $this->make_hook('subscribe', AUTH_PASSWD, 'groups'), | |
45 | '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_PASSWD, 'groupadmin'), | |
46 | '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_PASSWD, 'groupmember'), | |
4e310c61 | 47 | |
bfe9f4c7 SJ |
48 | '%grp/change_rights' => $this->make_hook('change_rights', AUTH_PASSWD, 'groups'), |
49 | '%grp/admin/annuaire' => $this->make_hook('admin_annuaire', AUTH_PASSWD, 'groupadmin'), | |
50 | '%grp/member' => $this->make_hook('admin_member', AUTH_PASSWD, 'groupadmin'), | |
51 | '%grp/member/new' => $this->make_hook('admin_member_new', AUTH_PASSWD, 'groupadmin'), | |
52 | '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_PASSWD, 'groups', NO_AUTH), | |
53 | '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_PASSWD, 'groupadmin'), | |
54 | '%grp/member/suggest' => $this->make_hook('admin_member_suggest', AUTH_PASSWD, 'groupadmin'), | |
8773c4c2 | 55 | '%grp/member/reg' => $this->make_hook('admin_member_reg', AUTH_PASSWD, 'groupadmin'), |
b8e265bf | 56 | |
190efb3a | 57 | '%grp/rss' => $this->make_token_hook('rss', AUTH_PUBLIC), |
bfe9f4c7 SJ |
58 | '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_PASSWD, 'groupadmin'), |
59 | '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_PASSWD, 'groupadmin'), | |
020c8ed0 | 60 | '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC), |
bfe9f4c7 | 61 | '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_PASSWD, 'groupadmin'), |
ae7bb180 | 62 | ); |
63 | } | |
64 | ||
26ba053e | 65 | function handler_index($page, $arg = null) |
ae7bb180 | 66 | { |
24bcf50c | 67 | global $globals, $platal; |
2e94d2b8 | 68 | if (!is_null($arg)) { |
ae7bb180 | 69 | return PL_NOT_FOUND; |
70 | } | |
1490093c | 71 | $page->changeTpl('xnetgrp/asso.tpl'); |
ae7bb180 | 72 | |
24bcf50c | 73 | if (S::logged()) { |
74 | if (Env::has('read')) { | |
14bc135e SJ |
75 | XDB::query('DELETE r.* |
76 | FROM group_announces_read AS r | |
77 | INNER JOIN group_announces AS a ON (a.id = r.announce_id) | |
b58e5ac2 | 78 | WHERE expiration < CURRENT_DATE()'); |
14bc135e SJ |
79 | XDB::query('INSERT INTO group_announces_read |
80 | VALUES ({?}, {?})', | |
24bcf50c | 81 | Env::i('read'), S::i('uid')); |
82 | pl_redirect(""); | |
83 | } | |
84 | if (Env::has('unread')) { | |
14bc135e SJ |
85 | XDB::query('DELETE FROM group_announces_read |
86 | WHERE announce_id = {?} AND uid = {?}', | |
24bcf50c | 87 | Env::i('unread'), S::i('uid')); |
88 | pl_redirect("#art" . Env::i('unread')); | |
89 | } | |
5a9ad4b0 SJ |
90 | |
91 | /* TODO: refines this filter on promotions by using userfilter. */ | |
92 | $user = S::user(); | |
93 | if ($user->hasProfile()) { | |
94 | $promo = XDB::format('{?}', $user->profile()->entry_year); | |
95 | $minCondition = ' OR promo_min <= ' . $promo; | |
96 | $maxCondition = ' OR promo_max >= ' . $promo; | |
97 | } else { | |
98 | $minCondition = ''; | |
99 | $maxCondition = ''; | |
100 | } | |
101 | $arts = XDB::iterator('SELECT a.*, FIND_IN_SET(\'photo\', a.flags) AS photo | |
14bc135e SJ |
102 | FROM group_announces AS a |
103 | LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id) | |
b58e5ac2 | 104 | WHERE asso_id = {?} AND expiration >= CURRENT_DATE() |
5a9ad4b0 SJ |
105 | AND (promo_min = 0' . $minCondition . ') |
106 | AND (promo_max = 0' . $maxCondition . ') | |
5660032a | 107 | AND r.announce_id IS NULL |
5a9ad4b0 SJ |
108 | ORDER BY a.expiration', |
109 | S::i('uid'), $globals->asso('id')); | |
110 | $index = XDB::iterator('SELECT a.id, a.titre, r.uid IS NULL AS nonlu | |
14bc135e SJ |
111 | FROM group_announces AS a |
112 | LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?}) | |
b58e5ac2 | 113 | WHERE asso_id = {?} AND expiration >= CURRENT_DATE() |
5a9ad4b0 SJ |
114 | AND (promo_min = 0' . $minCondition . ') |
115 | AND (promo_max = 0' . $maxCondition . ') | |
116 | ORDER BY a.expiration', | |
117 | S::i('uid'), $globals->asso('id')); | |
24bcf50c | 118 | $page->assign('article_index', $index); |
119 | } else { | |
14bc135e SJ |
120 | $arts = XDB::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo |
121 | FROM group_announces | |
b58e5ac2 | 122 | WHERE asso_id = {?} AND expiration >= CURRENT_DATE() |
14bc135e | 123 | AND FIND_IN_SET('public', flags)", |
24bcf50c | 124 | $globals->asso('id')); |
a85ce13e SJ |
125 | $payments = XDB::fetchAllAssoc("SELECT id, text |
126 | FROM payments | |
127 | WHERE asso_id = {?} AND NOT FIND_IN_SET('old', flags) AND FIND_IN_SET('public', flags) | |
128 | ORDER BY id DESC", | |
129 | $globals->asso('id')); | |
130 | $page->assign('payments', $payments); | |
24bcf50c | 131 | } |
4af7fd22 FB |
132 | if (may_update()) { |
133 | $subs_valid = XDB::query("SELECT uid | |
eb41eda9 | 134 | FROM group_member_sub_requests |
4af7fd22 FB |
135 | WHERE asso_id = {?}", |
136 | $globals->asso('id')); | |
137 | $page->assign('requests', $subs_valid->numRows()); | |
138 | } | |
24bcf50c | 139 | |
84fc72ff | 140 | if (!S::hasAuthToken()) { |
24bcf50c | 141 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques", |
5700a250 | 142 | $platal->ns . "rss/rss.xml"); |
24bcf50c | 143 | } else { |
144 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News", | |
2ab3486b | 145 | $platal->ns . 'rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml'); |
24bcf50c | 146 | } |
eaf30d86 | 147 | |
24bcf50c | 148 | $page->assign('articles', $arts); |
ae7bb180 | 149 | } |
dd798f38 | 150 | |
26ba053e | 151 | function handler_logo($page) |
dd798f38 | 152 | { |
153 | global $globals; | |
833a6e86 | 154 | $globals->asso()->getLogo()->send(); |
dd798f38 | 155 | } |
2e94d2b8 | 156 | |
26ba053e | 157 | function handler_site($page) |
d430f4d8 | 158 | { |
159 | global $globals; | |
160 | $site = $globals->asso('site'); | |
161 | if (!$site) { | |
a7d35093 | 162 | $page->trigError('Le groupe n\'a pas de site web.'); |
d430f4d8 | 163 | return $this->handler_index($page); |
164 | } | |
02838718 | 165 | http_redirect($site); |
d430f4d8 | 166 | exit; |
167 | } | |
168 | ||
26ba053e | 169 | function handler_edit($page) |
2e94d2b8 | 170 | { |
171 | global $globals; | |
1490093c | 172 | $page->changeTpl('xnetgrp/edit.tpl'); |
f611c8bd | 173 | $error = false; |
2e94d2b8 | 174 | |
d70edc30 | 175 | if (S::admin()) { |
f611c8bd SJ |
176 | $domains = XDB::iterator('SELECT * |
177 | FROM group_dom | |
178 | ORDER BY nom'); | |
179 | $page->assign('domains', $domains); | |
d70edc30 SJ |
180 | $page->assign('super', true); |
181 | } | |
182 | ||
40d428d8 VZ |
183 | if (Post::has('submit')) { |
184 | S::assert_xsrf_token(); | |
185 | ||
113f6de8 | 186 | $flags = new PlFlagSet('wiki_desc'); |
a6761ca9 FB |
187 | $flags->addFlag('notif_unsub', Post::i('notif_unsub') == 1); |
188 | $site = Post::t('site'); | |
ffe73cf7 SJ |
189 | if ($site && ($site != "http://")) { |
190 | $scheme = parse_url($site, PHP_URL_SCHEME); | |
191 | if (!$scheme) { | |
192 | $site = "http://" . $site; | |
193 | } | |
194 | } else { | |
195 | $site = ""; | |
196 | } | |
7c8b692c SJ |
197 | |
198 | $notify_all = (Post::v('notify_all') ? true : false); | |
199 | if (!$notify_all) { | |
200 | $to_notify = array(); | |
201 | $uf = New UserFilter(New UFC_Group($globals->asso('id'), true)); | |
202 | $uids = $uf->getIds(); | |
203 | foreach ($uids as $uid) { | |
204 | if (Post::b('to_notify_' . $uid)) { | |
205 | $to_notify[] = $uid; | |
206 | } | |
207 | } | |
208 | if (count($to_notify) == 0) { | |
209 | $notify_all = true; | |
210 | $page->trigWarning("Aucun animateur n'ayant été selectionné pour recevoir les demandes d'inscriptions, tous le seront."); | |
211 | } | |
212 | } | |
213 | $flags->addFlag('notify_all', $notify_all); | |
214 | ||
23ff6dd6 | 215 | if (S::admin()) { |
c3d959ce SJ |
216 | $page->assign('super', true); |
217 | ||
5e2307dc | 218 | if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) { |
6bb2f79a | 219 | $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!'); |
f611c8bd | 220 | $error = true; |
2e94d2b8 | 221 | } |
c3d959ce SJ |
222 | if (Post::t('nom') == '' || Post::t('diminutif') == '') { |
223 | $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.'); | |
f611c8bd SJ |
224 | $error = true; |
225 | } | |
226 | if ($error) { | |
227 | $page->assign('nom', Post::t('nom')); | |
228 | $page->assign('diminutif', Post::t('diminutif')); | |
229 | $page->assign('mail_domain', Post::t('mail_domain')); | |
230 | $page->assign('cat', Post::v('cat')); | |
231 | $page->assign('dom', Post::v('dom')); | |
232 | $page->assign('ax', Post::v('ax')); | |
233 | $page->assign('axDate', Post::t('axDate')); | |
234 | $page->assign('site', $site); | |
235 | $page->assign('resp', Post::t('resp')); | |
236 | $page->assign('mail', Post::t('mail')); | |
237 | $page->assign('phone', Post::t('phone')); | |
238 | $page->assign('fax', Post::t('fax')); | |
239 | $page->assign('address', Post::t('address')); | |
240 | $page->assign('forum', Post::t('forum')); | |
241 | $page->assign('inscriptible', Post::v('inscriptible')); | |
242 | $page->assign('sub_url', Post::t('sub_url')); | |
243 | $page->assign('unsub_url', Post::t('unsub_url')); | |
244 | $page->assign('welcome_msg', Post::t('welcome_msg')); | |
245 | $page->assign('pub', Post::v('pub')); | |
246 | $page->assign('notif_unsub', Post::i('notif_unsub')); | |
247 | $page->assign('descr', Post::t('descr')); | |
08906e89 | 248 | $page->assign('disable_mails', Post::b('disable_mails')); |
f611c8bd | 249 | $page->assign('error', $error); |
c3d959ce SJ |
250 | return; |
251 | } | |
f611c8bd | 252 | |
004ff79e SJ |
253 | $axDate = make_datetime(Post::v('axDate')); |
254 | if (Post::t('axDate') != '') { | |
255 | $axDate = make_datetime(Post::v('axDate'))->format('Y-m-d'); | |
256 | } else { | |
257 | $axDate = null; | |
258 | } | |
08cce2ff | 259 | XDB::execute( |
eb41eda9 | 260 | "UPDATE groups |
2e94d2b8 | 261 | SET nom={?}, diminutif={?}, cat={?}, dom={?}, |
262 | descr={?}, site={?}, mail={?}, resp={?}, | |
004ff79e | 263 | forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?}, |
794feea7 | 264 | sub_url={?}, inscriptible={?}, unsub_url={?}, |
08906e89 | 265 | flags = {?}, welcome_msg = {?}, disable_mails = {?} |
2e94d2b8 | 266 | WHERE id={?}", |
5e2307dc | 267 | Post::v('nom'), Post::v('diminutif'), |
ca46cc12 | 268 | Post::v('cat'), (Post::i('dom') == 0) ? null : Post::i('dom'), |
ffe73cf7 | 269 | Post::v('descr'), $site, |
5e2307dc | 270 | Post::v('mail'), Post::v('resp'), |
271 | Post::v('forum'), Post::v('mail_domain'), | |
004ff79e | 272 | Post::has('ax'), $axDate, Post::v('pub'), |
5e2307dc | 273 | Post::v('sub_url'), Post::v('inscriptible'), |
73ac0916 | 274 | Post::v('unsub_url'), $flags, Post::t('welcome_msg'), |
08906e89 | 275 | Post::b('disable_mails'), |
73ac0916 | 276 | $globals->asso('id')); |
5e2307dc | 277 | if (Post::v('mail_domain')) { |
831aa467 SJ |
278 | XDB::execute('INSERT IGNORE INTO email_virtual_domains (name) |
279 | VALUES ({?})', | |
280 | Post::t('mail_domain')); | |
281 | XDB::execute('UPDATE email_virtual_domains | |
282 | SET aliasing = id | |
283 | WHERE name = {?}', | |
284 | Post::t('mail_domain')); | |
2e94d2b8 | 285 | } |
286 | } else { | |
08cce2ff | 287 | XDB::execute( |
eb41eda9 | 288 | "UPDATE groups |
2e94d2b8 | 289 | SET descr={?}, site={?}, mail={?}, resp={?}, |
c2f19630 | 290 | forum={?}, pub= {?}, sub_url={?}, |
73ac0916 | 291 | unsub_url = {?}, flags = {?}, welcome_msg = {?} |
2e94d2b8 | 292 | WHERE id={?}", |
ffe73cf7 | 293 | Post::v('descr'), $site, |
5e2307dc | 294 | Post::v('mail'), Post::v('resp'), |
c2f19630 | 295 | Post::v('forum'), Post::v('pub'), |
30032578 | 296 | Post::v('sub_url'), Post::v('unsub_url'), |
73ac0916 SJ |
297 | $flags, Post::t('welcome_msg'), |
298 | $globals->asso('id')); | |
2e94d2b8 | 299 | } |
300 | ||
a174a707 SJ |
301 | Phone::deletePhones(0, Phone::LINK_GROUP, $globals->asso('id')); |
302 | $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0, | |
303 | 'type' => 'fixed', 'display' => Post::v('phone'), 'pub' => 'public')); | |
304 | $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1, | |
305 | 'type' => 'fax', 'display' => Post::v('fax'), 'pub' => 'public')); | |
306 | $phone->save(); | |
307 | $fax->save(); | |
baab50c7 SJ |
308 | Address::deleteAddresses(null, Address::LINK_GROUP, null, $globals->asso('id')); |
309 | $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address::LINK_GROUP, 'text' => Post::v('address'))); | |
310 | $address->save(); | |
a6761ca9 | 311 | |
2e94d2b8 | 312 | if ($_FILES['logo']['name']) { |
a6761ca9 FB |
313 | $upload = PlUpload::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true); |
314 | if (!$upload) { | |
5660032a | 315 | $page->trigError("Impossible de télécharger le logo."); |
a6761ca9 | 316 | } else { |
eb41eda9 | 317 | XDB::execute('UPDATE groups |
5660032a SJ |
318 | SET logo = {?}, logo_mime = {?} |
319 | WHERE id = {?}', $upload->getContents(), $upload->contentType(), | |
a6761ca9 FB |
320 | $globals->asso('id')); |
321 | $upload->rm(); | |
322 | } | |
2e94d2b8 | 323 | } |
324 | ||
7c8b692c SJ |
325 | XDB::execute("UPDATE group_members |
326 | SET flags = '' | |
327 | WHERE asso_id = {?}", | |
328 | $globals->asso('id')); | |
329 | if (!$notify_all) { | |
330 | XDB::execute("UPDATE group_members | |
331 | SET flags = 'notify' | |
332 | WHERE asso_id = {?} AND uid IN {?}", | |
333 | $globals->asso('id'), $to_notify); | |
334 | } | |
335 | ||
fc4714d6 SJ |
336 | pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit'); |
337 | } | |
7c8b692c SJ |
338 | |
339 | $uf = New UserFilter(New UFC_Group($globals->asso('id'), true, UFC_Group::NOTIFIED)); | |
340 | $page->assign('notified', $uf->getUsers()); | |
341 | $uf = New UserFilter(New UFC_Group($globals->asso('id'), true, UFC_Group::UNNOTIFIED)); | |
342 | $page->assign('unnotified', $uf->getUsers()); | |
343 | ||
f611c8bd SJ |
344 | $page->assign('error', $error); |
345 | $page->assign('cat', $globals->asso('cat')); | |
346 | $page->assign('dom', $globals->asso('dom')); | |
347 | $page->assign('ax', $globals->asso('ax')); | |
348 | $page->assign('inscriptible', $globals->asso('inscriptible')); | |
349 | $page->assign('pub', $globals->asso('pub')); | |
350 | $page->assign('notif_unsub', $globals->asso('notif_unsub')); | |
7c8b692c | 351 | $page->assign('notify_all', $globals->asso('notify_all')); |
08906e89 | 352 | $page->assign('disable_mails', $globals->asso('disable_mails')); |
2e94d2b8 | 353 | } |
354 | ||
26ba053e | 355 | function handler_mail($page) |
479d2787 | 356 | { |
357 | global $globals; | |
08906e89 RB |
358 | if ($globals->asso('disable_mails')) { |
359 | return PL_FORBIDDEN; | |
360 | } | |
479d2787 | 361 | |
1490093c | 362 | $page->changeTpl('xnetgrp/mail.tpl'); |
5c36f345 | 363 | $mmlist = new MMList(S::user(), $globals->asso('mail_domain')); |
9bb8bf21 | 364 | $page->assign('listes', $mmlist->get_lists()); |
7912097e | 365 | $page->assign('user', S::user()); |
479d2787 | 366 | |
367 | if (Post::has('send')) { | |
e7fdf9dd | 368 | S::assert_xsrf_token(); |
5e2307dc | 369 | $from = Post::v('from'); |
370 | $sujet = Post::v('sujet'); | |
371 | $body = Post::v('body'); | |
479d2787 | 372 | |
5e2307dc | 373 | $mls = array_keys(Env::v('ml', array())); |
06db561e | 374 | $mbr = array_keys(Env::v('membres', array())); |
479d2787 | 375 | |
460d8f55 | 376 | $this->load('mail.inc.php'); |
c974e61c | 377 | set_time_limit(120); |
06db561e | 378 | $tos = get_all_redirects($mbr, $mls, $mmlist); |
eab2f6f5 | 379 | |
f3df6d38 | 380 | $upload = PlUpload::get($_FILES['uploaded'], S::user()->login(), 'xnet.emails', true); |
eab2f6f5 VZ |
381 | if (!$upload && @$_FILES['uploaded']['name'] && PlUpload::$lastError != null) { |
382 | $page->trigError(PlUpload::$lastError); | |
383 | return; | |
384 | } | |
385 | ||
5b21237d | 386 | send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']); |
13627bef | 387 | if ($upload) { |
388 | $upload->rm(); | |
389 | } | |
6bb2f79a | 390 | $page->killSuccess("Email envoyé !"); |
479d2787 | 391 | $page->assign('sent', true); |
392 | } | |
393 | } | |
394 | ||
26ba053e | 395 | function handler_forum($page, $group = null, $artid = null) |
4f355064 | 396 | { |
397 | global $globals; | |
1490093c | 398 | $page->changeTpl('xnetgrp/forum.tpl'); |
4f355064 | 399 | if (!$globals->asso('forum')) { |
400 | return PL_NOT_FOUND; | |
401 | } | |
402 | require_once 'banana/forum.inc.php'; | |
403 | $get = array(); | |
404 | get_banana_params($get, $globals->asso('forum'), $group, $artid); | |
405 | run_banana($page, 'ForumsBanana', $get); | |
406 | } | |
407 | ||
26ba053e | 408 | function handler_annuaire($page, $action = null, $subaction = null) |
2e94d2b8 | 409 | { |
410 | global $globals; | |
a91fb584 | 411 | |
4b866888 RB |
412 | __autoload('userset'); |
413 | $admins = false; | |
027b16e3 RB |
414 | if ($action == 'admins') { |
415 | $admins = true; | |
416 | $action = $subaction; | |
a91fb584 | 417 | } |
027b16e3 RB |
418 | $view = new UserSet(new UFC_Group($globals->asso('id'), $admins)); |
419 | $view->addMod('groupmember', 'Annuaire'); | |
4b866888 | 420 | $view->addMod('trombi', 'Trombinoscope'); |
3c1f9614 | 421 | $view->addMod('map', 'Planisphère'); |
4b866888 RB |
422 | $view->apply('annuaire', $page, $action); |
423 | $page->assign('only_admin', $admins); | |
316120eb | 424 | $page->changeTpl('xnetgrp/annuaire.tpl'); |
2e94d2b8 | 425 | } |
4e310c61 | 426 | |
486bc076 SJ |
427 | function handler_former_users($page) |
428 | { | |
429 | global $globals; | |
430 | require_once 'userset.inc.php'; | |
431 | ||
432 | $view = new UserSet(new UFC_GroupFormerMember($globals->asso('id'))); | |
433 | $view->addMod('groupmember', 'Anciens membres', true, array('noadmin' => true)); | |
434 | $view->apply('former_users', $page); | |
435 | $page->changeTpl('xnetgrp/former_users.tpl'); | |
436 | } | |
437 | ||
26ba053e | 438 | function handler_trombi($page) |
a91fb584 | 439 | { |
440 | pl_redirect('annuaire/trombi'); | |
441 | } | |
442 | ||
26ba053e | 443 | function handler_geoloc($page) |
28929cf0 | 444 | { |
a91fb584 | 445 | pl_redirect('annuaire/geoloc'); |
28929cf0 | 446 | } |
eaf30d86 | 447 | |
26ba053e | 448 | function handler_vcard($page, $photos = null) |
5e193297 | 449 | { |
450 | global $globals; | |
5d42c993 | 451 | $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); |
801adeec | 452 | $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null, Profile::FETCH_ALL)); |
5d42c993 | 453 | $vcard->show(); |
5e193297 | 454 | } |
455 | ||
26ba053e | 456 | function handler_csv($page, $filename = null) |
102f4e64 FB |
457 | { |
458 | global $globals; | |
459 | if (is_null($filename)) { | |
460 | $filename = $globals->asso('diminutif') . '.csv'; | |
461 | } | |
1a074f45 | 462 | $users = $globals->asso()->getMembersFilter(null, new UFO_Name())->getUsers(); |
23281bb3 | 463 | $admin = may_update(); |
ee923b43 SJ |
464 | pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1); |
465 | ||
23281bb3 AL |
466 | echo utf8_decode("Nom;Prénom;Sexe;Promotion;Commentaire"); |
467 | if ($admin) { | |
468 | echo utf8_decode(";Société;Poste\n"); | |
469 | } else { | |
470 | echo utf8_decode("\n"); | |
471 | } | |
ee923b43 SJ |
472 | foreach ($users as $user) { |
473 | $line = $user->lastName() . ';' . $user->firstName() . ';' . ($user->isFemale() ? 'F' : 'M') | |
23281bb3 AL |
474 | . ';' . $user->promo() . ';' . strtr($user->group_comm, ';', ','); |
475 | if ($admin) { | |
476 | if ($user->hasProfile()) { | |
477 | $line .= ';' . $user->profile()->getMainJob()->company->name . ';' . $user->profile()->getMainJob()->description; | |
478 | } else { | |
479 | $line .= ';;'; | |
480 | } | |
481 | } | |
ee923b43 SJ |
482 | echo utf8_decode($line) . "\n"; |
483 | } | |
484 | exit(); | |
102f4e64 FB |
485 | } |
486 | ||
52366335 SJ |
487 | function handler_directory_sync($page) |
488 | { | |
489 | global $globals; | |
490 | require_once 'emails.inc.php'; | |
491 | ||
492 | $page->changeTpl('xnetgrp/sync.tpl'); | |
493 | Platal::load('lists', 'lists.inc.php'); | |
494 | ||
495 | if (Env::has('add_users')) { | |
496 | S::assert_xsrf_token(); | |
497 | ||
498 | $users = array_keys(Env::v('add_users')); | |
a208363f SJ |
499 | $former_users = XDB::fetchColumn('SELECT uid |
500 | FROM group_former_members | |
0259ec56 AL |
501 | WHERE remember = TRUE AND asso_id = {?} AND uid IN {?}', |
502 | $globals->asso('id'), $users); | |
a208363f SJ |
503 | $new_users = array_diff($users, $former_users); |
504 | ||
505 | foreach ($former_users as $uid) { | |
506 | $user = User::getSilentWithUID($uid); | |
507 | $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir.'); | |
508 | } | |
509 | if (count($former_users) > 1) { | |
510 | $page->trigWarning('S\'ils souhaitent revenir dans le groupe, il faut qu\'ils en fassent la demande sur la page d\'accueil du groupe.'); | |
511 | } elseif (count($former_users)) { | |
512 | $page->trigWarning('S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.'); | |
513 | } | |
514 | ||
52366335 | 515 | $data = array(); |
a208363f | 516 | foreach ($new_users as $uid) { |
c4643e47 | 517 | Group::subscribe($globals->asso('id'), $uid); |
52366335 | 518 | } |
52366335 SJ |
519 | } |
520 | ||
521 | if (Env::has('add_nonusers')) { | |
522 | S::assert_xsrf_token(); | |
523 | ||
524 | $nonusers = array_keys(Env::v('add_nonusers')); | |
525 | foreach ($nonusers as $email) { | |
526 | if ($user = User::getSilent($email) || !isvalid_email($email)) { | |
527 | continue; | |
528 | } | |
529 | ||
530 | list($local_part, $domain) = explode('@', strtolower($email)); | |
531 | $hruid = User::makeHrid($local_part, $domain, 'ext'); | |
532 | if ($user = User::getSilent($hruid)) { | |
533 | continue; | |
534 | } | |
535 | ||
3ba2fdf6 | 536 | require_once 'name.func.inc.php'; |
52366335 SJ |
537 | $parts = explode('.', $local_part); |
538 | if (count($parts) == 1) { | |
3ba2fdf6 | 539 | $lastname = $display_name = capitalize_name($mbox); |
52366335 SJ |
540 | $firstname = ''; |
541 | } else { | |
3ba2fdf6 SJ |
542 | $display_name = $firstname = capitalize_name($parts[0]); |
543 | $lastname = capitalize_name(implode(' ', array_slice($parts, 1))); | |
52366335 | 544 | } |
3ba2fdf6 SJ |
545 | $full_name = build_full_name($firstname, $lastname); |
546 | $directory_name = build_directory_name($firstname, $lastname); | |
b0788bf4 SJ |
547 | $sort_name = build_sort_name($firstname, $lastname); |
548 | XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name, | |
549 | firstname, lastname, email, type, state) | |
550 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')', | |
551 | $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email); | |
52366335 | 552 | $uid = XDB::insertId(); |
c4643e47 | 553 | Group::subscribe($globals->asso('id'), $uid); |
52366335 SJ |
554 | } |
555 | } | |
556 | ||
557 | if (Env::has('add_users') || Env::has('add_nonusers')) { | |
558 | $page->trigSuccess('Ajouts réalisés avec succès.'); | |
559 | } | |
560 | ||
561 | $user = S::user(); | |
562 | $client = new MMList($user, $globals->asso('mail_domain')); | |
563 | $lists = $client->get_lists(); | |
564 | $members = array(); | |
565 | foreach ($lists as $list) { | |
566 | $details = $client->get_members($list['list']); | |
567 | $members = array_merge($members, list_extract_members($details[1])); | |
568 | } | |
569 | $members = array_unique($members); | |
570 | $uids = array(); | |
571 | $users = array(); | |
572 | $nonusers = array(); | |
573 | foreach ($members as $email) { | |
574 | if ($user = User::getSilent($email)) { | |
575 | $uids[] = $user->id(); | |
576 | } else { | |
577 | $nonusers[] = $email; | |
578 | } | |
579 | } | |
580 | ||
581 | $aliases = iterate_list_alias($globals->asso('mail_domain')); | |
582 | foreach ($aliases as $alias) { | |
583 | list($local_part, $domain) = explode('@', $alias); | |
584 | $aliases_members = list_alias_members($local_part, $domain); | |
585 | $users = array_merge($users, $aliases_members['users']); | |
586 | $nonusers = array_merge($nonusers, $aliases_members['nonusers']); | |
587 | } | |
588 | foreach ($users as $user) { | |
589 | $uids[] = $user->id(); | |
590 | } | |
591 | $nonusers = array_unique($nonusers); | |
592 | $uids = array_unique($uids); | |
d522f92b SJ |
593 | if (count($uids)) { |
594 | $uids = XDB::fetchColumn('SELECT a.uid | |
595 | FROM accounts AS a | |
596 | WHERE a.uid IN {?} AND NOT EXISTS (SELECT * | |
597 | FROM group_members AS g | |
598 | WHERE a.uid = g.uid AND g.asso_id = {?})', | |
599 | $uids, $globals->asso('id')); | |
600 | ||
601 | $users = User::getBulkUsersWithUIDs($uids); | |
602 | usort($users, 'User::compareDirectoryName'); | |
603 | } else { | |
604 | $users = array(); | |
605 | } | |
52366335 SJ |
606 | sort($nonusers); |
607 | ||
608 | $page->assign('users', $users); | |
609 | $page->assign('nonusers', $nonusers); | |
610 | } | |
611 | ||
c329751f SJ |
612 | function handler_non_active($page) |
613 | { | |
614 | global $globals; | |
615 | $page->changeTpl('xnetgrp/non_active.tpl'); | |
616 | ||
617 | $uids = XDB::fetchColumn('SELECT g.uid | |
618 | FROM group_members AS g | |
619 | INNER JOIN accounts AS a ON (a.uid = g.uid) | |
620 | LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid) | |
621 | WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL', | |
622 | $globals->asso('id')); | |
623 | foreach ($uids as $key => $uid) { | |
624 | if (AccountReq::isPending($uid) || BulkAccountsReq::isPending($uid)) { | |
625 | unset($uids[$key]); | |
626 | } | |
627 | } | |
628 | ||
629 | if (Post::has('enable_accounts')) { | |
630 | S::assert_xsrf_token(); | |
631 | ||
632 | $uids_to_enable = array_intersect(array_keys(Post::v('enable_accounts')), $uids); | |
633 | ||
634 | $user = S::user(); | |
09c8f0ce | 635 | $request = new BulkAccountsReq($user, $uids_to_enable, $globals->asso('nom'), $globals->asso('diminutif')); |
c329751f SJ |
636 | $request->submit(); |
637 | $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.'); | |
638 | ||
639 | foreach ($uids as $key => $uid) { | |
640 | if (in_array($uid, $uids_to_enable)) { | |
641 | unset($uids[$key]); | |
642 | } | |
643 | } | |
644 | } | |
645 | ||
646 | $users = User::getBulkUsersWithUIDs($uids); | |
647 | $page->assign('users', $users); | |
648 | } | |
649 | ||
8408316e SJ |
650 | private function again($uid) |
651 | { | |
652 | $data = XDB::fetchOneAssoc('SELECT hash, group_name, sender_name, email | |
653 | FROM register_pending_xnet | |
654 | WHERE uid = {?}', | |
655 | $uid); | |
b50bf10c SJ |
656 | XDB::execute('UPDATE register_pending_xnet |
657 | SET last_date = NOW() | |
658 | WHERE uid = {?}', | |
659 | $uid); | |
8408316e SJ |
660 | |
661 | $mailer = new PlMailer('xnet/account.mail.tpl'); | |
662 | $mailer->addCc('validation+xnet_account@polytechnique.org'); | |
663 | $mailer->setTo($data['email']); | |
664 | $mailer->assign('hash', $data['hash']); | |
665 | $mailer->assign('email', $data['email']); | |
666 | $mailer->assign('group', $data['group_name']); | |
667 | $mailer->assign('sender_name', $data['sender_name']); | |
668 | $mailer->assign('again', true); | |
669 | $mailer->assign('baseurl', Platal::globals()->xnet->xorg_baseurl); | |
670 | $mailer->send(); | |
671 | } | |
672 | ||
673 | function handler_awaiting_active($page) | |
674 | { | |
675 | global $globals; | |
676 | $page->changeTpl('xnetgrp/awaiting_active.tpl'); | |
677 | ||
678 | XDB::execute('DELETE FROM register_pending_xnet | |
679 | WHERE DATE_SUB(NOW(), INTERVAL 1 MONTH) > date'); | |
680 | ||
681 | $uids = XDB::fetchColumn('SELECT g.uid | |
682 | FROM group_members AS g | |
683 | INNER JOIN accounts AS a ON (a.uid = g.uid) | |
684 | INNER JOIN register_pending_xnet AS p ON (p.uid = g.uid) | |
685 | WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'pending\'', | |
686 | $globals->asso('id')); | |
687 | ||
688 | if (Post::has('again')) { | |
689 | S::assert_xsrf_token(); | |
690 | ||
691 | $uids_to_again = array_intersect(array_keys(Post::v('again')), $uids); | |
692 | foreach ($uids_to_again as $uid) { | |
693 | $this->again($uid); | |
694 | } | |
695 | $page->trigSuccess('Relances effectuées avec succès.'); | |
696 | } | |
697 | ||
82f1afde SJ |
698 | if ($uids) { |
699 | $registration_date = XDB::fetchAllAssoc('uid', 'SELECT uid, date | |
700 | FROM register_pending_xnet | |
701 | WHERE uid IN {?}', $uids); | |
702 | $last_date = XDB::fetchAllAssoc('uid', 'SELECT uid, last_date | |
703 | FROM register_pending_xnet | |
704 | WHERE uid IN {?}', $uids); | |
8408316e | 705 | |
82f1afde SJ |
706 | $users = User::getBulkUsersWithUIDs($uids); |
707 | $page->assign('users', $users); | |
708 | $page->assign('registration_date', $registration_date); | |
709 | $page->assign('last_date', $last_date); | |
710 | } | |
8408316e SJ |
711 | |
712 | } | |
713 | ||
4af7fd22 FB |
714 | private function removeSubscriptionRequest($uid) |
715 | { | |
716 | global $globals; | |
eb41eda9 | 717 | XDB::execute("DELETE FROM group_member_sub_requests |
4af7fd22 FB |
718 | WHERE asso_id = {?} AND uid = {?}", |
719 | $globals->asso('id'), $uid); | |
720 | } | |
721 | ||
26ba053e | 722 | private function validSubscription(User $user) |
4af7fd22 FB |
723 | { |
724 | global $globals; | |
0fab5209 | 725 | $this->removeSubscriptionRequest($user->id()); |
3a299a1a SJ |
726 | Group::subscribe($globals->asso('id'), $user->id()); |
727 | ||
7fbaf66b | 728 | if (XDB::affectedRows() == 1 && $user->forlifeEmail()) { |
cac7dc37 FB |
729 | $mailer = new PlMailer(); |
730 | $mailer->addTo($user->forlifeEmail()); | |
731 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); | |
732 | $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription'); | |
733 | $message = ($user->isFemale() ? 'Chère' : 'Cher') . " Camarade,\n" | |
734 | . "\n" | |
f41e70e9 SJ |
735 | . " Suite à ta demande d'adhésion à " . $globals->asso('nom') |
736 | . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" | |
73ac0916 | 737 | . (is_null($globals->asso('welcome_msg')) ? '' : "\n" . $globals->asso('welcome_msg') . "\n") |
cac7dc37 FB |
738 | . "\n" |
739 | . "Bien cordialement,\n" | |
740 | . "-- \n" | |
741 | . S::user()->fullName() . '.'; | |
f41e70e9 | 742 | $mailer->setTxtBody(wordwrap($message, 72)); |
cac7dc37 FB |
743 | $mailer->send(); |
744 | } | |
4af7fd22 FB |
745 | } |
746 | ||
26ba053e | 747 | function handler_subscribe($page, $u = null) |
fdf0200a | 748 | { |
c8faf82a | 749 | global $globals; |
1490093c | 750 | $page->changeTpl('xnetgrp/inscrire.tpl'); |
fdf0200a | 751 | |
752 | if (!$globals->asso('inscriptible')) | |
a7de4ef7 | 753 | $page->kill("Il n'est pas possible de s'inscire en ligne à ce " |
754 | ."groupe. Essaie de joindre le contact indiqué " | |
755 | ."sur la page de présentation."); | |
fdf0200a | 756 | |
757 | if (!is_null($u) && may_update()) { | |
0fab5209 VZ |
758 | $user = User::get($u); |
759 | if (!$user) { | |
760 | return PL_NOT_FOUND; | |
761 | } else { | |
762 | $page->assign('user', $user); | |
fdf0200a | 763 | } |
0fab5209 VZ |
764 | |
765 | // Retrieves the subscription status, and the reason. | |
766 | $res = XDB::query("SELECT reason | |
eb41eda9 | 767 | FROM group_member_sub_requests |
0fab5209 VZ |
768 | WHERE asso_id = {?} AND uid = {?}", |
769 | $globals->asso('id'), $user->id()); | |
770 | $reason = ($res->numRows() ? $res->fetchOneCell() : null); | |
771 | ||
772 | $res = XDB::query("SELECT COUNT(*) | |
eb41eda9 | 773 | FROM group_members |
0fab5209 VZ |
774 | WHERE asso_id = {?} AND uid = {?}", |
775 | $globals->asso('id'), $user->id()); | |
776 | $already_member = ($res->fetchOneCell() > 0); | |
777 | ||
778 | // Handles the membership request. | |
779 | if ($already_member) { | |
780 | $this->removeSubscriptionRequest($user->id()); | |
6bb2f79a | 781 | $page->kill($user->fullName() . ' est déjà membre du groupe !'); |
0fab5209 VZ |
782 | } elseif (Env::has('accept')) { |
783 | S::assert_xsrf_token(); | |
784 | ||
785 | $this->validSubscription($user); | |
786 | pl_redirect("member/" . $user->login()); | |
787 | } elseif (Env::has('refuse')) { | |
788 | S::assert_xsrf_token(); | |
789 | ||
790 | $this->removeSubscriptionRequest($user->id()); | |
7fbaf66b NI |
791 | if ($user->forlifeEmail()) { |
792 | $mailer = new PlMailer(); | |
793 | $mailer->addTo($user->forlifeEmail()); | |
794 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); | |
795 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée'); | |
796 | $mailer->setTxtBody(Env::v('motif')); | |
797 | $mailer->send(); | |
798 | } | |
354adb18 | 799 | $page->killSuccess("La demande de {$user->fullName()} a bien été refusée."); |
0fab5209 VZ |
800 | } else { |
801 | $page->assign('show_form', true); | |
802 | $page->assign('reason', $reason); | |
803 | } | |
804 | return; | |
fdf0200a | 805 | } |
806 | ||
807 | if (is_member()) { | |
6bb2f79a | 808 | $page->kill("Tu es déjà membre !"); |
fdf0200a | 809 | return; |
810 | } | |
811 | ||
4af7fd22 | 812 | $res = XDB::query("SELECT uid |
eb41eda9 | 813 | FROM group_member_sub_requests |
4af7fd22 FB |
814 | WHERE uid = {?} AND asso_id = {?}", |
815 | S::i('uid'), $globals->asso('id')); | |
816 | if ($res->numRows() != 0) { | |
817 | $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation."); | |
818 | return; | |
819 | } | |
820 | ||
fdf0200a | 821 | if (Post::has('inscrire')) { |
e7fdf9dd VZ |
822 | S::assert_xsrf_token(); |
823 | ||
eb41eda9 | 824 | XDB::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason) |
4af7fd22 FB |
825 | VALUES ({?}, {?}, NOW(), {?})", |
826 | $globals->asso('id'), S::i('uid'), Post::v('message')); | |
a208363f SJ |
827 | XDB::execute('DELETE FROM group_former_members |
828 | WHERE uid = {?} AND asso_id = {?}', | |
829 | S::i('uid'), $globals->asso('id')); | |
674333e7 | 830 | $admins = $globals->asso()->iterToNotify(); |
ae775de9 | 831 | $admin = $admins->next(); |
4f22e856 NI |
832 | if (!is_null($admin)) { |
833 | $to = $admin->bestEmail(); | |
834 | while ($admin = $admins->next()) { | |
835 | $to .= ', ' . $admin->bestEmail(); | |
836 | } | |
837 | } else { | |
838 | $to = ''; | |
ae775de9 | 839 | } |
fdf0200a | 840 | |
841 | $append = "\n" | |
842 | . "-- \n" | |
a7de4ef7 | 843 | . "Ce message a été envoyé suite à la demande d'inscription de\n" |
8d2853fa | 844 | . S::user()->fullName(true) . "\n" |
fdf0200a | 845 | . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n" |
846 | . "de refuser sa demande d'inscription depuis la page :\n" | |
0fab5209 | 847 | . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S::user()->login() . "\n" |
fdf0200a | 848 | . "\n" |
a7de4ef7 | 849 | . "En cas de problème, contacter l'équipe de Polytechnique.org\n" |
850 | . "à l'adresse : support@polytechnique.org\n"; | |
fdf0200a | 851 | |
852 | if (!$to) { | |
6f2b23a4 SJ |
853 | $to = ($globals->asso('mail') != '') ? $globals->asso('mail') . ', ' : ''; |
854 | $to .= 'support@polytechnique.org'; | |
fdf0200a | 855 | $append = "\n-- \nLe groupe ".$globals->asso("nom") |
a7de4ef7 | 856 | ." n'a pas d'administrateur, l'équipe de" |
857 | ." Polytechnique.org a été prévenue et va rapidement" | |
858 | ." résoudre ce problème.\n"; | |
fdf0200a | 859 | } |
860 | ||
1e33266a | 861 | $mailer = new PlMailer(); |
fdf0200a | 862 | $mailer->addTo($to); |
0fab5209 | 863 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); |
fdf0200a | 864 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
5e2307dc | 865 | $mailer->setTxtBody(Post::v('message').$append); |
fdf0200a | 866 | $mailer->send(); |
867 | } | |
868 | } | |
869 | ||
26ba053e | 870 | function handler_subscribe_valid($page) |
4af7fd22 FB |
871 | { |
872 | global $globals; | |
873 | ||
874 | if (Post::has('valid')) { | |
875 | S::assert_xsrf_token(); | |
876 | $subs = Post::v('subs'); | |
877 | if (is_array($subs)) { | |
878 | $users = array(); | |
0fab5209 | 879 | foreach ($subs as $hruid => $val) { |
4af7fd22 | 880 | if ($val == '1') { |
0fab5209 VZ |
881 | $user = User::get($hruid); |
882 | if ($user) { | |
883 | $this->validSubscription($user); | |
4af7fd22 FB |
884 | } |
885 | } | |
886 | } | |
887 | } | |
888 | } | |
889 | ||
aa21c568 | 890 | $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date |
eb41eda9 | 891 | FROM group_member_sub_requests AS s |
c8d75c58 | 892 | INNER JOIN accounts AS a ON(s.uid = a.uid) |
aa21c568 FB |
893 | WHERE s.asso_id = {?} |
894 | ORDER BY s.ts', $globals->asso('id')); | |
4af7fd22 FB |
895 | $page->changeTpl('xnetgrp/subscribe-valid.tpl'); |
896 | $page->assign('valid', $it); | |
897 | } | |
898 | ||
26ba053e | 899 | function handler_change_rights($page) |
b8e265bf | 900 | { |
0c02607e | 901 | if (Env::has('right') && (may_update() || S::suid())) { |
b8e265bf | 902 | switch (Env::v('right')) { |
eaf30d86 | 903 | case 'admin': |
ab694eb5 | 904 | Platal::session()->stopSUID(); |
b8e265bf | 905 | break; |
906 | case 'anim': | |
ab694eb5 | 907 | Platal::session()->doSelfSuid(); |
b8e265bf | 908 | may_update(true); |
909 | is_member(true); | |
910 | break; | |
911 | case 'member': | |
ab694eb5 | 912 | Platal::session()->doSelfSuid(); |
b8e265bf | 913 | may_update(false, true); |
914 | is_member(true); | |
915 | break; | |
916 | case 'logged': | |
ab694eb5 | 917 | Platal::session()->doSelfSuid(); |
b8e265bf | 918 | may_update(false, true); |
919 | is_member(false, true); | |
920 | break; | |
921 | } | |
922 | } | |
5603d2ce | 923 | http_redirect($_SERVER['HTTP_REFERER']); |
b8e265bf | 924 | } |
925 | ||
26ba053e | 926 | function handler_admin_annuaire($page) |
4e310c61 | 927 | { |
928 | global $globals; | |
929 | ||
460d8f55 | 930 | $this->load('mail.inc.php'); |
1490093c | 931 | $page->changeTpl('xnetgrp/annuaire-admin.tpl'); |
aa21c568 FB |
932 | $user = S::user(); |
933 | $mmlist = new MMList($user, $globals->asso('mail_domain')); | |
9bb8bf21 | 934 | $lists = $mmlist->get_lists(); |
4e310c61 | 935 | if (!$lists) $lists = array(); |
936 | $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists); | |
937 | ||
938 | $subscribers = array(); | |
939 | ||
940 | foreach ($listes as $list) { | |
9bb8bf21 | 941 | list(,$members) = $mmlist->get_members($list); |
4e310c61 | 942 | $mails = array_map(create_function('$arr', 'return $arr[1];'), $members); |
943 | $subscribers = array_unique(array_merge($subscribers, $mails)); | |
944 | } | |
945 | ||
946 | $not_in_group_x = array(); | |
947 | $not_in_group_ext = array(); | |
948 | ||
949 | foreach ($subscribers as $mail) { | |
c8763ca3 | 950 | $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')), |
aa21c568 FB |
951 | new UFC_Email($mail))); |
952 | if ($uf->getTotalCount() == 0) { | |
953 | if (User::isForeignEmailAddress($mail)) { | |
4e310c61 | 954 | $not_in_group_ext[] = $mail; |
955 | } else { | |
956 | $not_in_group_x[] = $mail; | |
957 | } | |
958 | } | |
959 | } | |
960 | ||
961 | $page->assign('not_in_group_ext', $not_in_group_ext); | |
962 | $page->assign('not_in_group_x', $not_in_group_x); | |
963 | $page->assign('lists', $lists); | |
964 | } | |
ef7c8560 | 965 | |
26ba053e | 966 | function handler_admin_member_new($page, $email = null) |
ef7c8560 | 967 | { |
968 | global $globals; | |
969 | ||
1490093c | 970 | $page->changeTpl('xnetgrp/membres-add.tpl'); |
8773c4c2 | 971 | $page->addJsLink('xnet_members.js'); |
ef7c8560 | 972 | |
973 | if (is_null($email)) { | |
974 | return; | |
975 | } | |
976 | ||
bb88d138 | 977 | S::assert_xsrf_token(); |
bc6e8005 | 978 | $suggest_account_activation = false; |
bb88d138 | 979 | |
41905adf RB |
980 | // FS#703 : $_GET is urldecoded twice, hence |
981 | // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding) | |
982 | // Since there can be no spaces in emails, we can fix this with : | |
983 | $email = str_replace(' ', '+', $email); | |
79ba1555 | 984 | $is_valid_email = isvalid_email($email); |
41905adf | 985 | |
79ba1555 SJ |
986 | // X not registered to main site. |
987 | if (Env::v('x') && Env::i('userid') && $is_valid_email) { | |
5142a832 | 988 | $user = User::getSilentWithUID(Env::i('userid')); |
bb88d138 | 989 | if (!$user) { |
33a4f3f9 | 990 | $page->trigError('Utilisateur invalide.'); |
bb88d138 PC |
991 | return; |
992 | } | |
33a4f3f9 SJ |
993 | |
994 | // User has an account but is not yet registered. | |
995 | if ($user->state == 'pending') { | |
996 | // Add email in account table. | |
997 | XDB::query('UPDATE accounts | |
998 | SET email = {?} | |
999 | WHERE uid = {?} AND email IS NULL', | |
8773c4c2 | 1000 | $email, $user->id()); |
33a4f3f9 | 1001 | // Add email for marketing if required. |
8773c4c2 | 1002 | if (Env::v('marketing')) { |
33a4f3f9 SJ |
1003 | $market = Marketing::get($user->uid, $email); |
1004 | if (!$market) { | |
1005 | $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'), | |
8773c4c2 | 1006 | Env::v('marketing_from'), S::v('uid')); |
33a4f3f9 SJ |
1007 | $market->add(); |
1008 | } | |
dc2073c3 | 1009 | } |
8773c4c2 SJ |
1010 | } elseif (Env::v('broken')) { |
1011 | // Add email for broken if required. | |
1012 | $valid = new BrokenReq(S::user(), $user, $email, 'Groupe : ' . $globals->asso('nom')); | |
1013 | $valid->submit(); | |
bb88d138 PC |
1014 | } |
1015 | } else { | |
12f38333 SJ |
1016 | $user = User::getSilent($email); |
1017 | ||
79ba1555 | 1018 | // Wrong email and no user: failure. |
ae4057b8 | 1019 | if (is_null($user) && (!$is_valid_email || !User::isForeignEmailAddress($email))) { |
79ba1555 SJ |
1020 | $page->trigError('« <strong>' . $email . '</strong> » n\'est pas une adresse email valide.'); |
1021 | return; | |
1022 | } | |
1023 | ||
1024 | // Deals with xnet accounts. | |
12f38333 SJ |
1025 | if (is_null($user) || $user->type == 'xnet') { |
1026 | // User is of type xnet. There are 3 possible cases: | |
1027 | // * the email is not known yet: we create a new account and | |
1028 | // propose to send an email to the user so he can activate | |
1029 | // his account, | |
1030 | // * the email is known but the user was not contacted in order to | |
1031 | // activate yet: we propose to send an email to the user so he | |
1032 | // can activate his account, | |
1033 | // * the email is known and the user was already contacted or has | |
1034 | // an active account: nothing to be done. | |
1035 | list($mbox, $domain) = explode('@', strtolower($email)); | |
1036 | $hruid = User::makeHrid($mbox, $domain, 'ext'); | |
1037 | // User might already have an account (in another group for example). | |
5142a832 | 1038 | $user = User::getSilent($hruid); |
bc6e8005 | 1039 | |
12f38333 SJ |
1040 | // If the user has no account yet, creates new account: build names from email address. |
1041 | if (empty($user)) { | |
75e295ff | 1042 | require_once 'name.func.inc.php'; |
12f38333 SJ |
1043 | $parts = explode('.', $mbox); |
1044 | if (count($parts) == 1) { | |
3ba2fdf6 | 1045 | $lastname = $display_name = capitalize_name($mbox); |
12f38333 SJ |
1046 | $firstname = ''; |
1047 | } else { | |
3ba2fdf6 | 1048 | $display_name = $firstname = capitalize_name($parts[0]); |
75e295ff | 1049 | $lastname = capitalize_name(implode(' ', array_slice($parts, 1))); |
12f38333 | 1050 | } |
3ba2fdf6 SJ |
1051 | $full_name = build_full_name($firstname, $lastname); |
1052 | $directory_name = build_directory_name($firstname, $lastname); | |
b0788bf4 SJ |
1053 | $sort_name = build_sort_name($firstname, $lastname); |
1054 | XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name, | |
1055 | firstname, lastname, email, type, state) | |
1056 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')', | |
1057 | $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email); | |
12f38333 SJ |
1058 | $user = User::getSilent($hruid); |
1059 | } | |
1060 | ||
1061 | $suggest_account_activation = $this->suggest($user); | |
1062 | } | |
ef7c8560 | 1063 | } |
33a4f3f9 | 1064 | |
bb88d138 | 1065 | if ($user) { |
a208363f SJ |
1066 | // First check if the user used to be in this group. |
1067 | XDB::rawExecute('DELETE FROM group_former_members | |
1068 | WHERE remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date'); | |
1069 | $former_member = XDB::fetchOneCell('SELECT remember | |
1070 | FROM group_former_members | |
1071 | WHERE uid = {?} AND asso_id = {?}', | |
1072 | $user->id(), $globals->asso('id')); | |
1073 | if ($former_member === 1) { | |
1074 | $page->trigError($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir. S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.'); | |
1075 | return; | |
1076 | } elseif (!is_null($former_member) && Post::i('force_continue') == 0) { | |
1077 | $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui s\'est récemment désinscrit. Malgré cela, si tu penses qu\'il souhaite revenir, cliquer sur « Ajouter » l\'ajoutera bien au groupe cette fois.'); | |
1078 | $page->assign('force_continue', 1); | |
1079 | return; | |
1080 | } | |
1081 | ||
1082 | Group::subscribe($globals->asso('id'), $user->id()); | |
bb88d138 | 1083 | $this->removeSubscriptionRequest($user->id()); |
7fbaf66b | 1084 | if ($user->isActive() && $user->bestEmail()) { |
85e4dd49 AL |
1085 | $mailer = new PlMailer('xnetgrp/forced-subscription.mail.tpl'); |
1086 | $mailer->addTo($user->bestEmail()); | |
1087 | $mailer->assign('group', $globals->asso('nom')); | |
1088 | $mailer->assign('anim', S::user()->fullname()); | |
1089 | $mailer->assign('diminutif', $globals->asso('diminutif')); | |
1090 | $mailer->send(); | |
1091 | } | |
1092 | ||
3d84dcc5 TM |
1093 | // Check if the group has more than 1000 members, if so, disable the "send mail" function. |
1094 | $full_count = XDB::fetchOneCell('SELECT COUNT(*) | |
1095 | FROM group_members | |
1096 | WHERE asso_id = {?}', | |
1097 | $globals->asso('id')); | |
1098 | if ($full_count > 999) { | |
1099 | XDB::execute( | |
1100 | "UPDATE groups | |
1101 | SET disable_mails = 1 | |
1102 | WHERE id = {?}", | |
1103 | $globals->asso('id')); | |
1104 | } | |
1105 | ||
bc6e8005 SJ |
1106 | if ($suggest_account_activation) { |
1107 | pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom')); | |
1108 | } else { | |
1109 | pl_redirect('member/' . $user->login()); | |
1110 | } | |
1111 | } | |
1112 | } | |
1113 | ||
fb422cab SJ |
1114 | // Check if the user has a pending or active account, and thus if we should her account's activation. |
1115 | private function suggest(PlUser $user) | |
1116 | { | |
1117 | $active = XDB::fetchOneCell('SELECT state = \'active\' | |
1118 | FROM accounts | |
1119 | WHERE uid = {?}', | |
1120 | $user->id()); | |
1121 | $pending = XDB::fetchOneCell('SELECT uid | |
1122 | FROM register_pending_xnet | |
1123 | WHERE uid = {?}', | |
1124 | $user->id()); | |
c329751f | 1125 | $requested = AccountReq::isPending($user->id()) || BulkAccountsReq::isPending($user->id()); |
fb422cab SJ |
1126 | |
1127 | if ($active || $pending || $requested) { | |
1128 | return false; | |
1129 | } | |
1130 | return true; | |
1131 | } | |
1132 | ||
bc6e8005 SJ |
1133 | function handler_admin_member_suggest($page, $hruid, $email) |
1134 | { | |
1135 | $page->changeTpl('xnetgrp/membres-suggest.tpl'); | |
41905adf RB |
1136 | |
1137 | // FS#703 : $_GET is urldecoded twice, hence | |
1138 | // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding) | |
1139 | // Since there can be no spaces in emails, we can fix this with : | |
1140 | $email = str_replace(' ', '+', $email); | |
bc6e8005 SJ |
1141 | |
1142 | if (Post::has('suggest')) { | |
1143 | if (Post::t('suggest') == 'yes') { | |
09c8f0ce SJ |
1144 | global $globals; |
1145 | ||
bc6e8005 | 1146 | $user = S::user(); |
09c8f0ce | 1147 | $request = new AccountReq($user, $hruid, $email, $globals->asso('nom'), $globals->asso('diminutif')); |
bc6e8005 SJ |
1148 | $request->submit(); |
1149 | $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.', | |
09c8f0ce | 1150 | $globals->asso('diminutif') . '/member/' . $hruid); |
bc6e8005 SJ |
1151 | } else { |
1152 | pl_redirect('member/' . $hruid); | |
1153 | } | |
bb88d138 | 1154 | } |
bc6e8005 SJ |
1155 | $page->assign('email', $email); |
1156 | $page->assign('hruid', $hruid); | |
ef7c8560 | 1157 | } |
1158 | ||
8773c4c2 SJ |
1159 | function handler_admin_member_reg($page, $uid) |
1160 | { | |
1161 | pl_content_headers('text/plain'); | |
1162 | ||
1163 | $user = User::getSilentWithUID($uid); | |
1164 | if ($user && $user->state != 'pending' && $user->hasProfile()) { | |
1165 | echo true; | |
1166 | } | |
1167 | echo false; | |
1168 | exit(); | |
1169 | } | |
1170 | ||
26ba053e | 1171 | function handler_admin_member_new_ajax($page) |
dc2073c3 | 1172 | { |
3cb500d5 | 1173 | pl_content_headers("text/html"); |
8b1f8e12 | 1174 | $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); |
aa21c568 | 1175 | $users = array(); |
8773c4c2 | 1176 | $same_email = false; |
0baf0741 | 1177 | if (Env::has('login')) { |
aa21c568 FB |
1178 | $user = User::getSilent(Env::t('login')); |
1179 | if ($user && $user->state != 'pending') { | |
8773c4c2 SJ |
1180 | $users = array($user->id() => $user); |
1181 | $same_email = true; | |
aa21c568 | 1182 | } |
e2b0a45c | 1183 | } |
aa21c568 | 1184 | if (empty($users)) { |
33a4f3f9 | 1185 | list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom'))); |
8773c4c2 | 1186 | $cond = new PFC_And(); |
33a4f3f9 | 1187 | if (!empty($lastname)) { |
3731beb2 | 1188 | $cond->addChild(new UFC_NameTokens($lastname, array(), false, false, Profile::LASTNAME)); |
0baf0741 | 1189 | } |
33a4f3f9 | 1190 | if (!empty($firstname)) { |
3731beb2 | 1191 | $cond->addChild(new UFC_NameTokens($firstname, array(), false, false, Profile::FIRSTNAME)); |
0baf0741 | 1192 | } |
33a4f3f9 SJ |
1193 | if (Env::t('promo')) { |
1194 | $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo'))); | |
aa21c568 FB |
1195 | } |
1196 | $uf = new UserFilter($cond); | |
e1406965 | 1197 | $users = $uf->getUsers(new PlLimit(30)); |
aa21c568 FB |
1198 | if ($uf->getTotalCount() > 30) { |
1199 | $page->assign('too_many', true); | |
1200 | $users = array(); | |
0baf0741 | 1201 | } |
dc2073c3 | 1202 | } |
8773c4c2 | 1203 | |
aa21c568 | 1204 | $page->assign('users', $users); |
8773c4c2 | 1205 | $page->assign('same_email', $same_email); |
dc2073c3 | 1206 | } |
1207 | ||
49056fe2 | 1208 | function unsubscribe(PlUser $user, $remember = false) |
ef7c8560 | 1209 | { |
d7610c35 | 1210 | global $globals; |
49056fe2 | 1211 | Group::unsubscribe($globals->asso('id'), $user->id(), $remember); |
ef7c8560 | 1212 | |
fa9493fe FB |
1213 | if ($globals->asso('notif_unsub')) { |
1214 | $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl'); | |
674333e7 | 1215 | $admins = $globals->asso()->iterToNotify(); |
57c1f1d7 SJ |
1216 | while ($admin = $admins->next()) { |
1217 | $mailer->addTo($admin); | |
fa9493fe FB |
1218 | } |
1219 | $mailer->assign('group', $globals->asso('nom')); | |
45dcd6dd FB |
1220 | $mailer->assign('user', $user); |
1221 | $mailer->assign('selfdone', $user->id() == S::i('uid')); | |
fa9493fe FB |
1222 | $mailer->send(); |
1223 | } | |
eca5d69f | 1224 | |
30032578 | 1225 | $domain = $globals->asso('mail_domain'); |
45dcd6dd | 1226 | if (!$domain) { |
30032578 | 1227 | return true; |
1228 | } | |
ef7c8560 | 1229 | |
dc81a0b2 | 1230 | $mmlist = new MMList(S::user(), $domain); |
45dcd6dd | 1231 | $listes = $mmlist->get_lists($user->forlifeEmail()); |
ef7c8560 | 1232 | |
30032578 | 1233 | $may_update = may_update(); |
1234 | $warning = false; | |
23ba40c4 PC |
1235 | if (is_array($listes)) { |
1236 | foreach ($listes as $liste) { | |
1237 | if ($liste['sub'] == 2) { | |
1238 | if ($may_update) { | |
1239 | $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail())); | |
1240 | } else { | |
1241 | $mmlist->unsubscribe($liste['list']); | |
1242 | } | |
1243 | } elseif ($liste['sub']) { | |
1244 | Platal::page()->trigWarning($user->fullName() . " a une" | |
1245 | ." demande d'inscription en cours sur la" | |
1246 | ." liste {$liste['list']}@ !"); | |
1247 | $warning = true; | |
ef7c8560 | 1248 | } |
1249 | } | |
30032578 | 1250 | } |
ef7c8560 | 1251 | |
831aa467 SJ |
1252 | XDB::execute('DELETE v |
1253 | FROM email_virtual AS v | |
1254 | INNER JOIN email_virtual_domains AS d ON (v.domain = d.id) | |
1255 | WHERE v.redirect = {?} AND d.name = {?}', | |
1256 | $user->forlifeEmail(), $domain); | |
30032578 | 1257 | return !$warning; |
1258 | } | |
1259 | ||
26ba053e | 1260 | function handler_unsubscribe($page) |
30032578 | 1261 | { |
1490093c | 1262 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
035de9c1 | 1263 | $user = S::user(); |
cb1f5408 | 1264 | if (empty($user)) { |
30032578 | 1265 | return PL_NOT_FOUND; |
ef7c8560 | 1266 | } |
30032578 | 1267 | $page->assign('self', true); |
cb1f5408 | 1268 | $page->assign('user', $user); |
ef7c8560 | 1269 | |
30032578 | 1270 | if (!Post::has('confirm')) { |
1271 | return; | |
e7fdf9dd VZ |
1272 | } else { |
1273 | S::assert_xsrf_token(); | |
30032578 | 1274 | } |
1275 | ||
9a7f3d8e | 1276 | $hasSingleGroup = ($user->groupCount() == 1); |
cb1f5408 | 1277 | |
49056fe2 | 1278 | if ($this->unsubscribe($user, Post::b('remember'))) { |
cb1f5408 | 1279 | $page->trigSuccess('Tu as été désinscrit du groupe avec succès.'); |
30032578 | 1280 | } else { |
cb1f5408 SJ |
1281 | $page->trigWarning('Tu as été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des listes de diffusion.'); |
1282 | } | |
8d014576 SJ |
1283 | |
1284 | // If user is of type xnet account and this was her last group, disable the account. | |
1285 | if ($user->type == 'xnet' && $hasSingleGroup) { | |
1286 | $user->clear(true); | |
30032578 | 1287 | } |
c1863ee9 | 1288 | $page->assign('is_member', is_member(true)); |
30032578 | 1289 | } |
1290 | ||
26ba053e | 1291 | function handler_admin_member_del($page, $user = null) |
30032578 | 1292 | { |
1490093c | 1293 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
45dcd6dd | 1294 | $user = User::getSilent($user); |
30032578 | 1295 | if (empty($user)) { |
1296 | return PL_NOT_FOUND; | |
1297 | } | |
4a648e80 SJ |
1298 | |
1299 | global $globals; | |
1300 | ||
1301 | if (!$user->inGroup($globals->asso('id'))) { | |
1302 | pl_redirect('annuaire'); | |
1303 | } | |
1304 | ||
cb1f5408 | 1305 | $page->assign('self', false); |
30032578 | 1306 | $page->assign('user', $user); |
1307 | ||
1308 | if (!Post::has('confirm')) { | |
1309 | return; | |
e7fdf9dd VZ |
1310 | } else { |
1311 | S::assert_xsrf_token(); | |
30032578 | 1312 | } |
1313 | ||
9a7f3d8e | 1314 | $hasSingleGroup = ($user->groupCount() == 1); |
91d2135c | 1315 | |
30032578 | 1316 | if ($this->unsubscribe($user)) { |
e46cf8c4 | 1317 | $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !"); |
30032578 | 1318 | } else { |
e46cf8c4 | 1319 | $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !"); |
30032578 | 1320 | } |
91d2135c | 1321 | |
8d014576 | 1322 | // If user is of type xnet account and this was her last group, disable the account. |
91d2135c | 1323 | if ($user->type == 'xnet' && $hasSingleGroup) { |
8d014576 | 1324 | $user->clear(true); |
91d2135c | 1325 | } |
ef7c8560 | 1326 | } |
1327 | ||
8773c4c2 | 1328 | private function changeLogin(PlPage $page, PlUser $user, $login, $req_broken = false, $req_marketing = false, $marketing_from = 'user') |
631565e1 | 1329 | { |
33a4f3f9 | 1330 | // Search the user's uid. |
bb88d138 PC |
1331 | $xuser = User::getSilent($login); |
1332 | if (!$xuser) { | |
61a7d279 SJ |
1333 | $accounts = User::getPendingAccounts($login); |
1334 | if (!$accounts) { | |
1335 | $page->trigError("L'identifiant $login ne correspond à aucun X."); | |
631565e1 | 1336 | return false; |
61a7d279 SJ |
1337 | } else if (count($accounts) > 1) { |
1338 | $page->trigError("L'identifiant $login correspond à plusieurs camarades."); | |
631565e1 FB |
1339 | return false; |
1340 | } | |
bb88d138 | 1341 | $xuser = User::getSilent($accounts[0]['uid']); |
631565e1 FB |
1342 | } |
1343 | ||
bb88d138 PC |
1344 | if (!$xuser) { |
1345 | return false; | |
631565e1 FB |
1346 | } |
1347 | ||
8773c4c2 SJ |
1348 | // Market or suggest new redirection if required. |
1349 | $email = $user->bestEmail(); | |
1350 | if ($req_broken) { | |
1351 | $valid = new BrokenReq(S::user(), $xuser, $email, 'Groupe : ' . Platal::globals()->asso('nom')); | |
1352 | $valid->submit(); | |
1353 | } elseif ($req_marketing) { | |
1354 | $market = Marketing::get($xuser->uid, $email); | |
1355 | if (!$market) { | |
1356 | $market = new Marketing($xuser->uid, $email, 'group', Platal::globals()->asso('nom'), $marketing_from, S::i('uid')); | |
1357 | $market->add(); | |
1358 | } | |
1359 | } | |
1360 | ||
33a4f3f9 SJ |
1361 | if ($user->mergeIn($xuser)) { |
1362 | return $xuser->login(); | |
1363 | } | |
1364 | return $user->login(); | |
631565e1 FB |
1365 | } |
1366 | ||
26ba053e | 1367 | function handler_admin_member($page, $user) |
ef7c8560 | 1368 | { |
1369 | global $globals; | |
1370 | ||
45dcd6dd | 1371 | $user = User::getSilent($user); |
ef7c8560 | 1372 | if (empty($user)) { |
1373 | return PL_NOT_FOUND; | |
1374 | } | |
1375 | ||
7ae5c545 SJ |
1376 | if (!$user->inGroup($globals->asso('id'))) { |
1377 | pl_redirect('annuaire'); | |
1378 | } | |
1379 | ||
1380 | $page->changeTpl('xnetgrp/membres-edit.tpl'); | |
8773c4c2 | 1381 | $page->addJsLink('xnet_members.js'); |
7ae5c545 | 1382 | |
dc81a0b2 | 1383 | $mmlist = new MMList(S::user(), $globals->asso('mail_domain')); |
ef7c8560 | 1384 | |
1385 | if (Post::has('change')) { | |
e7fdf9dd | 1386 | S::assert_xsrf_token(); |
3ba2fdf6 SJ |
1387 | require_once 'emails.inc.php'; |
1388 | require_once 'name.func.inc.php'; | |
e7fdf9dd | 1389 | |
631565e1 | 1390 | // Convert user status to X |
8773c4c2 SJ |
1391 | if (!Post::blank('x')) { |
1392 | $forlife = $this->changeLogin($page, $user, Post::i('userid'), Post::b('broken'), Post::b('marketing'), Post::v('marketing_from')); | |
631565e1 FB |
1393 | if ($forlife) { |
1394 | pl_redirect('member/' . $forlife); | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | // Update user info | |
1d6870e1 | 1399 | if ($user->type == 'virtual' || ($user->type == 'xnet' && !$user->perms)) { |
75e295ff | 1400 | $lastname = capitalize_name(Post::t('lastname')); |
b7753795 | 1401 | if (Post::s('type') != 'virtual') { |
75e295ff | 1402 | $firstname = capitalize_name(Post::t('firstname')); |
b7753795 SJ |
1403 | } else { |
1404 | $firstname = ''; | |
b7753795 | 1405 | } |
3ba2fdf6 SJ |
1406 | $full_name = build_full_name($firstname, $lastname); |
1407 | $directory_name = build_directory_name($firstname, $lastname); | |
b0788bf4 | 1408 | $sort_name = build_sort_name($firstname, $lastname); |
bb88d138 | 1409 | XDB::query('UPDATE accounts |
b0788bf4 | 1410 | SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?}, |
8a41e7f9 | 1411 | firstname = {?}, lastname = {?}, sex = {?}, type = {?} |
bb88d138 | 1412 | WHERE uid = {?}', |
b0788bf4 | 1413 | $full_name, $directory_name, $sort_name, Post::t('display_name'), $firstname, $lastname, |
8a41e7f9 | 1414 | (Post::t('sex') == 'male') ? 'male' : 'female', |
33a4f3f9 | 1415 | (Post::t('type') == 'xnet') ? 'xnet' : 'virtual', $user->id()); |
8a41e7f9 SJ |
1416 | } |
1417 | ||
1418 | // Updates email. | |
1419 | $new_email = strtolower(Post::t('email')); | |
147078a5 SJ |
1420 | if (($user->type == 'virtual' || ($user->type == 'xnet' && !$user->perms)) |
1421 | && require_email_update($user, $new_email)) { | |
33a4f3f9 SJ |
1422 | XDB::query('UPDATE accounts |
1423 | SET email = {?} | |
1424 | WHERE uid = {?}', | |
8a41e7f9 | 1425 | $new_email, $user->id()); |
db05227f SJ |
1426 | if ($user->forlifeEmail()) { |
1427 | $listClient = new MMList(S::user()); | |
1428 | $listClient->change_user_email($user->forlifeEmail(), $new_email); | |
1429 | update_alias_user($user->forlifeEmail(), $new_email); | |
1430 | } | |
1431 | $user = User::getWithUID($user->id()); | |
ca6980dc | 1432 | } |
33a4f3f9 | 1433 | if (XDB::affectedRows()) { |
94bf736e | 1434 | $page->trigSuccess('Données de l\'utilisateur mises à jour.'); |
ef7c8560 | 1435 | } |
1436 | ||
d49b4a9a SJ |
1437 | if (($user->type == 'xnet' && !$user->perms)) { |
1438 | if (Post::b('suggest')) { | |
09c8f0ce | 1439 | $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom'), $globals->asso('diminutif')); |
d49b4a9a SJ |
1440 | $request->submit(); |
1441 | $page->trigSuccess('Le compte va bientôt être activé.'); | |
1442 | } | |
1443 | if (Post::b('again')) { | |
8408316e | 1444 | $this->again($user->id()); |
d49b4a9a SJ |
1445 | $page->trigSuccess('Relance effectuée avec succès.'); |
1446 | } | |
fb422cab SJ |
1447 | } |
1448 | ||
bb88d138 PC |
1449 | // Update group params for user |
1450 | $perms = Post::v('group_perms'); | |
a6761ca9 | 1451 | $comm = Post::t('comm'); |
33fcb12c SJ |
1452 | $position = (Post::t('group_position') == '') ? null : Post::v('group_position'); |
1453 | if ($user->group_perms != $perms || $user->group_comm != $comm || $user->group_position != $position) { | |
eb41eda9 | 1454 | XDB::query('UPDATE group_members |
33fcb12c | 1455 | SET perms = {?}, comm = {?}, position = {?} |
00112b2e | 1456 | WHERE uid = {?} AND asso_id = {?}', |
33fcb12c | 1457 | ($perms == 'admin') ? 'admin' : 'membre', $comm, $position, |
bb88d138 | 1458 | $user->id(), $globals->asso('id')); |
33a4f3f9 SJ |
1459 | if (XDB::affectedRows()) { |
1460 | if ($perms != $user->group_perms) { | |
1461 | $page->trigSuccess('Permissions modifiées !'); | |
1462 | } | |
1463 | if ($comm != $user->group_comm) { | |
1464 | $page->trigSuccess('Commentaire mis à jour.'); | |
1465 | } | |
58149849 SJ |
1466 | if ($position != $user->group_position) { |
1467 | $page->trigSuccess('Poste mis à jour.'); | |
1468 | } | |
54b24ba2 | 1469 | } |
ef7c8560 | 1470 | } |
1471 | ||
bb88d138 PC |
1472 | // Gets user info again as they might have change |
1473 | $user = User::getSilent($user->id()); | |
1474 | ||
631565e1 | 1475 | // Update ML subscriptions |
5e2307dc | 1476 | foreach (Env::v('ml1', array()) as $ml => $state) { |
ef7c8560 | 1477 | $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; |
c4d57bd8 | 1478 | if ($ask == $state) { |
c4d57bd8 | 1479 | continue; |
1480 | } | |
ef7c8560 | 1481 | if ($state == '1') { |
bb88d138 | 1482 | $page->trigWarning("{$user->fullName()} a " |
ef7c8560 | 1483 | ."actuellement une demande d'inscription en " |
1484 | ."cours sur <strong>$ml@</strong> !!!"); | |
1485 | } elseif ($ask) { | |
bb88d138 PC |
1486 | $mmlist->mass_subscribe($ml, Array($user->forlifeEmail())); |
1487 | $page->trigSuccess("{$user->fullName()} a été abonné à $ml@."); | |
ef7c8560 | 1488 | } else { |
65fae027 | 1489 | $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail())); |
bb88d138 | 1490 | $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@."); |
ef7c8560 | 1491 | } |
1492 | } | |
1493 | ||
631565e1 | 1494 | // Change subscriptioin to aliases |
5e2307dc | 1495 | foreach (Env::v('ml3', array()) as $ml => $state) { |
831aa467 | 1496 | require_once 'emails.inc.php'; |
ef7c8560 | 1497 | $ask = !empty($_REQUEST['ml4'][$ml]); |
7e82b545 | 1498 | list($local_part, ) = explode('@', $ml); |
65fae027 SJ |
1499 | if ($ask == $state) { |
1500 | continue; | |
1501 | } | |
1502 | if ($ask) { | |
7e82b545 | 1503 | add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain')); |
bb88d138 | 1504 | $page->trigSuccess("{$user->fullName()} a été abonné à $ml."); |
ef7c8560 | 1505 | } else { |
7e82b545 | 1506 | delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain')); |
bb88d138 | 1507 | $page->trigSuccess("{$user->fullName()} a été désabonné de $ml."); |
ef7c8560 | 1508 | } |
1509 | } | |
bf26b317 SJ |
1510 | |
1511 | if ($globals->asso('has_nl')) { | |
20d37dc0 | 1512 | $nl = NewsLetter::forGroup($globals->asso('shortname')); |
bf26b317 SJ |
1513 | // Updates group's newsletter subscription. |
1514 | if (Post::i('newsletter') == 1) { | |
e4b8520c | 1515 | $nl->subscribe($user); |
bf26b317 | 1516 | } else { |
72aed335 | 1517 | $nl->unsubscribe(null, $user->id()); |
bf26b317 SJ |
1518 | } |
1519 | } | |
ef7c8560 | 1520 | } |
1521 | ||
33fcb12c SJ |
1522 | $res = XDB::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\''); |
1523 | $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']); | |
e4b8520c RB |
1524 | if ($globals->asso('has_nl')) { |
1525 | $nl = NewsLetter::forGroup($globals->asso('shortname')); | |
1526 | $nl_registered = $nl->subscriptionState($user); | |
1527 | } else { | |
1528 | $nl_registered = false; | |
1529 | } | |
33fcb12c | 1530 | |
ef7c8560 | 1531 | $page->assign('user', $user); |
fb422cab | 1532 | $page->assign('suggest', $this->suggest($user)); |
a6761ca9 | 1533 | $page->assign('listes', $mmlist->get_lists($user->forlifeEmail())); |
06a548e5 | 1534 | $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain'))); |
33fcb12c | 1535 | $page->assign('positions', explode(',', $positions)); |
bf26b317 | 1536 | $page->assign('nl_registered', $nl_registered); |
d49b4a9a SJ |
1537 | $page->assign('pending_xnet_account', XDB::fetchOneCell('SELECT 1 |
1538 | FROM register_pending_xnet | |
1539 | WHERE uid = {?}', | |
1540 | $user->id())); | |
ef7c8560 | 1541 | } |
24bcf50c | 1542 | |
82af3fc3 | 1543 | function handler_rss(PlPage $page, PlUser $user) |
24bcf50c | 1544 | { |
1545 | global $globals; | |
24bcf50c | 1546 | $page->assign('asso', $globals->asso()); |
4f18bb11 | 1547 | |
460d8f55 | 1548 | $this->load('feed.inc.php'); |
4f18bb11 | 1549 | $feed = new XnetGrpEventFeed(); |
190efb3a | 1550 | return $feed->run($page, $user, false); |
24bcf50c | 1551 | } |
1552 | ||
26ba053e | 1553 | private function upload_image(PlPage $page, PlUpload $upload) |
ff95a302 FB |
1554 | { |
1555 | if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) { | |
1556 | return true; | |
1557 | } | |
1558 | if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) { | |
a7d35093 | 1559 | $page->trigError('Impossible de télécharger l\'image'); |
ff95a302 FB |
1560 | return false; |
1561 | } elseif (!$upload->isType('image')) { | |
a7d35093 | 1562 | $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.'); |
ff95a302 FB |
1563 | $upload->rm(); |
1564 | return false; | |
a6f76d68 | 1565 | } elseif (!$upload->resizeImage(80, 100, 100, 100, 32284)) { |
a7d35093 | 1566 | $page->trigError('Impossible de retraiter l\'image'); |
ff95a302 FB |
1567 | return false; |
1568 | } | |
1569 | return true; | |
1570 | } | |
1571 | ||
26ba053e | 1572 | function handler_photo_announce($page, $eid = null) { |
ff95a302 | 1573 | if ($eid) { |
14bc135e SJ |
1574 | $res = XDB::query('SELECT * |
1575 | FROM group_announces_photo | |
1576 | WHERE eid = {?}', $eid); | |
ff95a302 FB |
1577 | if ($res->numRows()) { |
1578 | $photo = $res->fetchOneAssoc(); | |
3cb500d5 | 1579 | pl_cached_dynamic_content_headers("image/" . $photo['attachmime']); |
ff95a302 FB |
1580 | echo $photo['attach']; |
1581 | exit; | |
1582 | } | |
1583 | } else { | |
f3df6d38 | 1584 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 | 1585 | if ($upload->exists() && $upload->isType('image')) { |
3cb500d5 | 1586 | pl_cached_dynamic_content_headers($upload->contentType()); |
ff95a302 FB |
1587 | echo $upload->getContents(); |
1588 | exit; | |
1589 | } | |
1590 | } | |
1591 | global $globals; | |
3cb500d5 | 1592 | pl_cached_dynamic_content_headers("image/png"); |
ff95a302 FB |
1593 | echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png'); |
1594 | exit; | |
1595 | } | |
1596 | ||
26ba053e | 1597 | function handler_edit_announce($page, $aid = null) |
24bcf50c | 1598 | { |
1599 | global $globals, $platal; | |
1490093c | 1600 | $page->changeTpl('xnetgrp/announce-edit.tpl'); |
24bcf50c | 1601 | $page->assign('new', is_null($aid)); |
1602 | $art = array(); | |
1603 | ||
ff95a302 | 1604 | if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer' |
2f8677c2 | 1605 | || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') { |
e7fdf9dd VZ |
1606 | S::assert_xsrf_token(); |
1607 | ||
24bcf50c | 1608 | if (!is_null($aid)) { |
1609 | $art['id'] = $aid; | |
1610 | } | |
1611 | $art['titre'] = Post::v('titre'); | |
1612 | $art['texte'] = Post::v('texte'); | |
1613 | $art['contacts'] = Post::v('contacts'); | |
1614 | $art['promo_min'] = Post::i('promo_min'); | |
1615 | $art['promo_max'] = Post::i('promo_max'); | |
1616 | $art['nom'] = S::v('nom'); | |
1617 | $art['prenom'] = S::v('prenom'); | |
1618 | $art['promo'] = S::v('promo'); | |
0fab5209 | 1619 | $art['hruid'] = S::user()->login(); |
79e610a9 | 1620 | $art['uid'] = S::user()->id(); |
b58e5ac2 | 1621 | $art['expiration'] = Post::v('expiration'); |
24bcf50c | 1622 | $art['public'] = Post::has('public'); |
1623 | $art['xorg'] = Post::has('xorg'); | |
1624 | $art['nl'] = Post::has('nl'); | |
1625 | $art['event'] = Post::v('event'); | |
f3df6d38 | 1626 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 | 1627 | $this->upload_image($page, $upload); |
24bcf50c | 1628 | |
1629 | $art['contact_html'] = $art['contacts']; | |
b9a1ba64 | 1630 | if ($art['event']) { |
1631 | $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}"; | |
24bcf50c | 1632 | } |
2a557a09 | 1633 | |
1634 | if (!$art['public'] && | |
d1c97e42 | 1635 | (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) || |
2a557a09 | 1636 | ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) || |
1637 | ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020)))) | |
1638 | { | |
a7d35093 | 1639 | $page->trigError("L'intervalle de promotions est invalide."); |
2a557a09 | 1640 | Post::kill('valid'); |
1641 | } | |
1970c12b | 1642 | |
1643 | if (!trim($art['titre']) || !trim($art['texte'])) { | |
a7d35093 | 1644 | $page->trigError("L'article doit avoir un titre et un contenu."); |
1970c12b | 1645 | Post::kill('valid'); |
1646 | } | |
ff95a302 FB |
1647 | |
1648 | if (Post::v('valid') == 'Supprimer l\'image') { | |
1649 | $upload->rm(); | |
1650 | Post::kill('valid'); | |
1651 | } | |
2f8677c2 FB |
1652 | $art['photo'] = $upload->exists() || Post::i('photo'); |
1653 | if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) { | |
14bc135e SJ |
1654 | XDB::query('DELETE FROM group_announces_photo |
1655 | WHERE eid = {?}', $aid); | |
2f8677c2 FB |
1656 | $upload->rm(); |
1657 | Post::kill('valid'); | |
1658 | $art['photo'] = false; | |
1659 | } | |
24bcf50c | 1660 | } |
1661 | ||
1662 | if (Post::v('valid') == 'Enregistrer') { | |
2a557a09 | 1663 | $promo_min = ($art['public'] ? 0 : $art['promo_min']); |
1664 | $promo_max = ($art['public'] ? 0 : $art['promo_max']); | |
113f6de8 | 1665 | $flags = new PlFlagSet(); |
ff95a302 | 1666 | if ($art['public']) { |
77e786e1 | 1667 | $flags->addFlag('public'); |
ff95a302 FB |
1668 | } |
1669 | if ($art['photo']) { | |
77e786e1 | 1670 | $flags->addFlag('photo'); |
ff95a302 | 1671 | } |
24bcf50c | 1672 | if (is_null($aid)) { |
eaf30d86 PH |
1673 | $fulltext = $art['texte']; |
1674 | if (!empty($art['contact_html'])) { | |
1675 | $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html']; | |
e219710a | 1676 | } |
91cf1bdb | 1677 | $post = null; |
e219710a | 1678 | if ($globals->asso('forum')) { |
1679 | require_once 'banana/forum.inc.php'; | |
e3a55098 | 1680 | $banana = new ForumsBanana(S::user()); |
e219710a | 1681 | $post = $banana->post($globals->asso('forum'), null, |
1682 | $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80)); | |
91cf1bdb | 1683 | } |
14bc135e | 1684 | XDB::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts, |
b58e5ac2 | 1685 | expiration, promo_min, promo_max, flags, post_id) |
14bc135e | 1686 | VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', |
24bcf50c | 1687 | S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], |
b58e5ac2 | 1688 | $art['expiration'], $promo_min, $promo_max, $flags, $post); |
8b83a166 | 1689 | $aid = XDB::insertId(); |
ff95a302 FB |
1690 | if ($art['photo']) { |
1691 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
14bc135e SJ |
1692 | XDB::execute('INSERT INTO group_announces_photo |
1693 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}', | |
ff95a302 FB |
1694 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); |
1695 | } | |
24bcf50c | 1696 | if ($art['xorg']) { |
794feea7 | 1697 | $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, |
b58e5ac2 | 1698 | $art['promo_min'], $art['promo_max'], $art['expiration'], "", S::user(), |
ff95a302 | 1699 | $upload); |
24bcf50c | 1700 | $article->submit(); |
a7d35093 | 1701 | $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation."); |
ff95a302 FB |
1702 | } else if ($upload && $upload->exists()) { |
1703 | $upload->rm(); | |
24bcf50c | 1704 | } |
1705 | if ($art['nl']) { | |
5daf68f6 | 1706 | $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'], |
2a557a09 | 1707 | $art['texte'], $art['contact_html']); |
24bcf50c | 1708 | $article->submit(); |
a7d35093 | 1709 | $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation."); |
24bcf50c | 1710 | } |
1711 | } else { | |
14bc135e | 1712 | XDB::query('UPDATE group_announces |
b58e5ac2 | 1713 | SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?}, |
14bc135e SJ |
1714 | promo_min = {?}, promo_max = {?}, flags = {?} |
1715 | WHERE id = {?} AND asso_id = {?}', | |
b58e5ac2 | 1716 | $art['titre'], $art['texte'], $art['contacts'], $art['expiration'], |
ff95a302 | 1717 | $promo_min, $promo_max, $flags, |
24bcf50c | 1718 | $art['id'], $globals->asso('id')); |
2f8677c2 FB |
1719 | if ($art['photo'] && $upload->exists()) { |
1720 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
00ba8a74 SJ |
1721 | XDB::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y) |
1722 | VALUES ({?}, {?}, {?}, {?}, {?}) | |
1723 | ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)', | |
1724 | $aid, $imgtype, $upload->getContents(), $imgx, $imgy); | |
2f8677c2 FB |
1725 | $upload->rm(); |
1726 | } | |
24bcf50c | 1727 | } |
2a557a09 | 1728 | } |
1729 | if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') { | |
24bcf50c | 1730 | pl_redirect(""); |
eaf30d86 | 1731 | } |
24bcf50c | 1732 | |
1733 | if (empty($art) && !is_null($aid)) { | |
14bc135e SJ |
1734 | $res = XDB::query("SELECT *, FIND_IN_SET('public', flags) AS public, |
1735 | FIND_IN_SET('photo', flags) AS photo | |
1736 | FROM group_announces | |
1737 | WHERE asso_id = {?} AND id = {?}", | |
24bcf50c | 1738 | $globals->asso('id'), $aid); |
1739 | if ($res->numRows()) { | |
1740 | $art = $res->fetchOneAssoc(); | |
1741 | $art['contact_html'] = $art['contacts']; | |
1742 | } else { | |
567553ac | 1743 | $page->kill("Aucun article correspond à l'identifiant indiqué."); |
24bcf50c | 1744 | } |
1745 | } | |
1746 | ||
24bcf50c | 1747 | if (is_null($aid)) { |
1748 | $events = XDB::iterator("SELECT * | |
eb41eda9 | 1749 | FROM group_events |
24bcf50c | 1750 | WHERE asso_id = {?} AND archive = 0", |
1751 | $globals->asso('id')); | |
1752 | if ($events->total()) { | |
1753 | $page->assign('events', $events); | |
1754 | } | |
eaf30d86 | 1755 | } |
24bcf50c | 1756 | |
72b2f8bb | 1757 | $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']); |
24bcf50c | 1758 | $page->assign('art', $art); |
ff95a302 | 1759 | $page->assign_by_ref('upload', $upload); |
24bcf50c | 1760 | } |
1761 | ||
26ba053e | 1762 | function handler_admin_announce($page) |
24bcf50c | 1763 | { |
1764 | global $globals; | |
1490093c | 1765 | $page->changeTpl('xnetgrp/announce-admin.tpl'); |
24bcf50c | 1766 | |
1767 | if (Env::has('del')) { | |
e7fdf9dd | 1768 | S::assert_xsrf_token(); |
14bc135e SJ |
1769 | XDB::execute('DELETE FROM group_announces |
1770 | WHERE id = {?} AND asso_id = {?}', | |
24bcf50c | 1771 | Env::i('del'), $globals->asso('id')); |
1772 | } | |
b58e5ac2 | 1773 | $res = XDB::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime |
14bc135e SJ |
1774 | FROM group_announces |
1775 | WHERE asso_id = {?} | |
b58e5ac2 | 1776 | ORDER BY expiration DESC', |
24bcf50c | 1777 | $globals->asso('id')); |
1778 | $page->assign('articles', $res); | |
1779 | } | |
ae7bb180 | 1780 | } |
1781 | ||
448c8cdc | 1782 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: |
ae7bb180 | 1783 | ?> |