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