74e0093f |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
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 | |
22 | class EventsModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
1a828cd4 |
27 | 'events' => $this->make_hook('ev', AUTH_COOKIE), |
28 | 'events/submit' => $this->make_hook('ev_submit', AUTH_MDP), |
92423144 |
29 | 'admin/events' => $this->make_hook('admin_events', AUTH_MDP, 'admin'), |
b829e258 |
30 | |
164ca57a |
31 | 'nl' => $this->make_hook('nl', AUTH_COOKIE), |
32 | 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE), |
33 | 'nl/submit' => $this->make_hook('nl_submit', AUTH_COOKIE), |
92423144 |
34 | 'admin/newsletter' => $this->make_hook('admin_nl', AUTH_MDP, 'admin'), |
35 | 'admin/newsletter/categories' => $this->make_hook('admin_nl_cat', AUTH_MDP, 'admin'), |
36 | 'admin/newsletter/edit' => $this->make_hook('admin_nl_edit', AUTH_MDP, 'admin'), |
74e0093f |
37 | ); |
38 | } |
39 | |
8d8f7607 |
40 | function on_subscribe($forlife, $uid, $promo, $password) |
41 | { |
42 | require_once 'newsletter.inc.php'; |
43 | subscribe_nl($uid); |
44 | } |
45 | |
4e61caea |
46 | function handler_ev(&$page, $action = 'list', $eid = null) |
1a828cd4 |
47 | { |
1a828cd4 |
48 | $page->changeTpl('login.tpl'); |
49 | |
08cce2ff |
50 | $res = XDB::query('SELECT date, naissance FROM auth_user_md5 |
cab08090 |
51 | WHERE user_id={?}', S::v('uid')); |
1a828cd4 |
52 | list($date, $naissance) = $res->fetchOneRow(); |
53 | |
089a5801 |
54 | // incitation à mettre à jour la fiche |
1a828cd4 |
55 | |
56 | $d2 = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2), |
57 | substr($date, 0, 4)); |
58 | if( (time() - $d2) > 60 * 60 * 24 * 400 ) { |
59 | // si fiche date de + de 400j; |
60 | $page->assign('fiche_incitation', $date); |
61 | } |
62 | |
63 | // Souhaite bon anniversaire |
64 | |
65 | if (substr($naissance, 5) == date('m-d')) { |
66 | $page->assign('birthday', date('Y') - substr($naissance, 0, 4)); |
67 | } |
68 | |
089a5801 |
69 | // incitation à mettre une photo |
1a828cd4 |
70 | |
08cce2ff |
71 | $res = XDB::query('SELECT COUNT(*) FROM photo |
cab08090 |
72 | WHERE uid={?}', S::v('uid')); |
1a828cd4 |
73 | $page->assign('photo_incitation', $res->fetchOneCell() == 0); |
74 | |
089a5801 |
75 | // Incitation à se géolocaliser |
1a828cd4 |
76 | require_once 'geoloc.inc.php'; |
cab08090 |
77 | $res = localize_addresses(S::v('uid', -1)); |
1a828cd4 |
78 | $page->assign('geoloc_incitation', count($res)); |
79 | |
089a5801 |
80 | // affichage de la boîte avec quelques liens |
9f40c29f |
81 | /* Bandeau de publicité sur la page de login */ |
82 | $publicite = array( |
83 | 'password' => 'Changer mon mot de passe' , |
84 | 'Docs/Dons' => 'Faire un don à l\'association Polytechnique.org' |
85 | ) ; |
86 | |
87 | // Liens apparaissant de façon aléatoire |
88 | $pub_rnd = array( |
89 | 'nl/show' => 'Afficher la dernière newsletter' , |
90 | 'http://www.polytechnique.net' => 'Vers les autres sites polytechniciens' , |
91 | "trombi/{$_SESSION["promo"]}" => "Voir le trombi de ma promo" , |
92 | 'banana' => 'Un petit tour du côté des forums !!' |
93 | ) ; |
94 | |
95 | $choix = array_rand($pub_rnd, 2); |
96 | foreach ($choix as $url) { |
97 | $publicite[$url] = $pub_rnd[$url] ; |
1a828cd4 |
98 | } |
9f40c29f |
99 | $page->assign('publicite', array_chunk($publicite, 2, true)); |
1a828cd4 |
100 | |
101 | // ajout du lien RSS |
cab08090 |
102 | if (S::has('core_rss_hash')) { |
1a828cd4 |
103 | $page->assign('xorg_rss', |
104 | array('title' => 'Polytechnique.org :: News', |
cab08090 |
105 | 'href' => '/rss/'.S::v('forlife') |
106 | .'/'.S::v('core_rss_hash').'/rss.xml') |
1a828cd4 |
107 | ); |
108 | } |
109 | |
110 | // cache les evenements lus et raffiche les evenements a relire |
4e61caea |
111 | if ($action == 'read' && $eid) { |
08cce2ff |
112 | XDB::execute('DELETE FROM evenements_vus AS ev |
1a828cd4 |
113 | INNER JOIN evenements AS e ON e.id = ev.evt_id |
114 | WHERE peremption < NOW)'); |
08cce2ff |
115 | XDB::execute('REPLACE INTO evenements_vus VALUES({?},{?})', |
4e61caea |
116 | $eid, S::v('uid')); |
1a828cd4 |
117 | } |
118 | |
4e61caea |
119 | if ($action == 'unread' && $eid) { |
08cce2ff |
120 | XDB::execute('DELETE FROM evenements_vus |
1a828cd4 |
121 | WHERE evt_id = {?} AND user_id = {?}', |
4e61caea |
122 | $eid, S::v('uid')); |
1a828cd4 |
123 | } |
124 | |
125 | // affichage des evenements |
089a5801 |
126 | // annonces promos triées par présence d'une limite sur les promos |
1a828cd4 |
127 | // puis par dates croissantes d'expiration |
cab08090 |
128 | $promo = S::v('promo'); |
1a828cd4 |
129 | $sql = "SELECT e.id,e.titre,e.texte,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife |
2f678da1 |
130 | FROM evenements AS e |
131 | INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id |
132 | INNER JOIN aliases AS l ON ( a.user_id=l.id AND l.type='a_vie' ) |
133 | LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?}) |
1a828cd4 |
134 | WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW() |
135 | AND (e.promo_min = 0 || e.promo_min <= {?}) |
136 | AND (e.promo_max = 0 || e.promo_max >= {?}) |
137 | AND ev.user_id IS NULL |
138 | ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption"; |
139 | $page->assign('evenement', |
cab08090 |
140 | XDB::iterator($sql, S::v('uid'), |
1a828cd4 |
141 | $promo, $promo) |
142 | ); |
143 | |
144 | $sql = "SELECT e.id,e.titre, ev.user_id IS NULL AS nonlu |
145 | FROM evenements AS e |
146 | LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?}) |
147 | WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW() |
148 | AND (e.promo_min = 0 || e.promo_min <= {?}) |
149 | AND (e.promo_max = 0 || e.promo_max >= {?}) |
150 | ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption"; |
151 | $page->assign('evenement_summary', |
cab08090 |
152 | XDB::iterator($sql, S::v('uid'), |
1a828cd4 |
153 | $promo, $promo) |
154 | ); |
1a828cd4 |
155 | } |
156 | |
157 | function handler_ev_submit(&$page) |
74e0093f |
158 | { |
74e0093f |
159 | $page->changeTpl('evenements.tpl'); |
160 | |
5e2307dc |
161 | $titre = Post::v('titre'); |
162 | $texte = Post::v('texte'); |
163 | $promo_min = Post::i('promo_min'); |
164 | $promo_max = Post::i('promo_max'); |
165 | $peremption = Post::i('peremption'); |
166 | $valid_mesg = Post::v('valid_mesg'); |
167 | $action = Post::v('action'); |
74e0093f |
168 | |
169 | $page->assign('titre', $titre); |
170 | $page->assign('texte', $texte); |
171 | $page->assign('promo_min', $promo_min); |
172 | $page->assign('promo_max', $promo_max); |
173 | $page->assign('peremption', $peremption); |
174 | $page->assign('valid_mesg', $valid_mesg); |
175 | $page->assign('action', strtolower($action)); |
176 | |
177 | if ($action == 'Confirmer') { |
178 | $texte = preg_replace('/((http|ftp)+(s)?:\/\/[^<>\s]+)/i', |
179 | '<a href=\"\\0\">\\0</a>', $texte); |
180 | $texte = preg_replace('/([^,\s]+@[^,\s]+)/i', |
181 | '<a href=\"mailto:\\0\">\\0</a>', $texte); |
182 | require_once 'validations.inc.php'; |
183 | $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max, |
cab08090 |
184 | $peremption, $valid_mesg, S::v('uid')); |
74e0093f |
185 | $evtreq->submit(); |
186 | $page->assign('ok', true); |
187 | } |
188 | |
189 | $select = ''; |
190 | for ($i = 1 ; $i < 30 ; $i++) { |
191 | $time = time() + 3600 * 24 * $i; |
192 | $p_stamp = date('Ymd', $time); |
193 | $year = date('Y', $time); |
194 | $month = date('m', $time); |
195 | $day = date('d', $time); |
196 | |
197 | $select .= "<option value=\"$p_stamp\""; |
198 | if ($p_stamp == strtr($peremption, array("-" => ""))) { |
199 | $select .= " selected='selected'"; |
200 | } |
201 | $select .= "> $day / $month / $year</option>\n"; |
202 | } |
203 | $page->assign('select',$select); |
74e0093f |
204 | } |
b829e258 |
205 | |
164ca57a |
206 | function handler_nl(&$page, $action = null) |
207 | { |
208 | require_once 'newsletter.inc.php'; |
209 | |
210 | $page->changeTpl('newsletter/index.tpl'); |
211 | $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles'); |
212 | |
213 | switch ($action) { |
214 | case 'out': unsubscribe_nl(); break; |
215 | case 'in': subscribe_nl(); break; |
216 | default: ; |
217 | } |
218 | |
219 | $page->assign('nls', get_nl_state()); |
220 | $page->assign_by_ref('nl_list', get_nl_list()); |
164ca57a |
221 | } |
222 | |
223 | function handler_nl_show(&$page, $nid = 'last') |
b829e258 |
224 | { |
225 | $page->changeTpl('newsletter/show.tpl'); |
226 | |
227 | require_once 'newsletter.inc.php'; |
228 | |
229 | $nl = new NewsLetter($nid); |
230 | $page->assign_by_ref('nl', $nl); |
231 | |
232 | if (Post::has('send')) { |
cab08090 |
233 | $nl->sendTo(S::v('prenom'), S::v('nom'), |
234 | S::v('bestalias'), S::v('femme'), |
235 | S::v('mail_fmt') != 'text'); |
b829e258 |
236 | } |
b829e258 |
237 | } |
164ca57a |
238 | |
239 | function handler_nl_submit(&$page) |
240 | { |
241 | $page->changeTpl('newsletter/submit.tpl'); |
242 | |
243 | require_once 'newsletter.inc.php'; |
244 | |
245 | if (Post::has('see')) { |
5e2307dc |
246 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append')); |
164ca57a |
247 | $page->assign('art', $art); |
248 | } elseif (Post::has('valid')) { |
249 | require_once('validations.inc.php'); |
5e2307dc |
250 | $art = new NLReq(S::v('uid'), Post::v('title'), |
251 | Post::v('body'), Post::v('append')); |
164ca57a |
252 | $art->submit(); |
253 | $page->assign('submited', true); |
254 | } |
164ca57a |
255 | } |
92423144 |
256 | |
506a46ed |
257 | function handler_admin_events(&$page, $action = 'list', $eid = null) |
258 | { |
92423144 |
259 | $page->changeTpl('admin/evenements.tpl'); |
260 | $page->assign('xorg_title','Polytechnique.org - Administration - Evenements'); |
506a46ed |
261 | $page->register_modifier('hde', 'html_entity_decode'); |
262 | |
263 | $arch = $action == 'archives'; |
264 | $page->assign('action', $action); |
265 | |
01248e3a |
266 | if (Post::v('action') == "Proposer" && $eid) { |
506a46ed |
267 | XDB::execute('UPDATE evenements |
268 | SET titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?} |
269 | WHERE id = {?}', |
270 | Post::v('titre'), Post::v('texte'), Post::v('peremption'), |
01248e3a |
271 | Post::v('promo_min'), Post::v('promo_max'), $eid); |
92423144 |
272 | } |
506a46ed |
273 | |
274 | if ($action == 'edit') { |
275 | $res = XDB::query('SELECT titre, texte, peremption, promo_min, promo_max |
276 | FROM evenements |
277 | WHERE id={?}', $eid); |
278 | list($titre, $texte, $peremption, $promo_min, $promo_max) = $res->fetchOneRow(); |
279 | $page->assign('titre',$titre); |
280 | $page->assign('texte',$texte); |
281 | $page->assign('promo_min',$promo_min); |
282 | $page->assign('promo_max',$promo_max); |
283 | $page->assign('peremption',$peremption); |
284 | |
285 | $select = ""; |
286 | for ($i = 1 ; $i < 30 ; $i++) { |
287 | $p_stamp=date("Ymd",time()+3600*24*$i); |
288 | $year=substr($p_stamp,0,4); |
289 | $month=substr($p_stamp,4,2); |
290 | $day=substr($p_stamp,6,2); |
291 | |
292 | $select .= "<option value=\"$p_stamp\"" |
293 | . (($p_stamp == strtr($peremption, array("-" => ""))) ? " selected" : "") |
294 | . "> $day / $month / $year</option>\n"; |
295 | } |
296 | $page->assign('select',$select); |
297 | } else { |
298 | switch ($action) { |
299 | case 'delete': |
300 | XDB::execute('DELETE from evenements |
301 | WHERE id = {?}', $eid); |
302 | break; |
303 | |
304 | case "archive": |
305 | XDB::execute('UPDATE evenements |
306 | SET creation_date = creation_date, flags = CONCAT(flags,",archive") |
307 | WHERE id = {?}', $eid); |
308 | break; |
309 | |
310 | case "unarchive": |
311 | XDB::execute('UPDATE evenements |
312 | SET creation_date = creation_date, flags = REPLACE(flags,"archive","") |
313 | WHERE id = {?}', $eid); |
314 | $action = 'archives'; |
315 | $arch = true; |
316 | break; |
317 | |
318 | case "valid": |
319 | XDB::execute('UPDATE evenements |
320 | SET creation_date = creation_date, flags = CONCAT(flags,",valide") |
321 | WHERE id = {?}', $eid); |
322 | break; |
323 | |
324 | case "unvalid": |
325 | XDB::execute('UPDATE evenements |
326 | SET creation_date = creation_date, flags = REPLACE(flags,"valide", "") |
327 | WHERE id = {?}', $eid); |
328 | break; |
329 | } |
330 | |
331 | $pid = ($eid && $action == 'preview') ? $eid : -1; |
332 | $sql = "SELECT e.id, e.titre, e.texte,e.id = $pid AS preview, |
92423144 |
333 | DATE_FORMAT(e.creation_date,'%d/%m/%Y %T') AS creation_date, |
334 | DATE_FORMAT(e.peremption,'%d/%m/%Y') AS peremption, |
335 | e.promo_min, e.promo_max, |
336 | FIND_IN_SET('valide', e.flags) AS fvalide, |
337 | FIND_IN_SET('archive', e.flags) AS farch, |
338 | u.promo, u.nom, u.prenom, a.alias AS forlife |
339 | FROM evenements AS e |
340 | INNER JOIN auth_user_md5 AS u ON(e.user_id = u.user_id) |
341 | INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie') |
342 | WHERE ".($arch ? "" : "!")."FIND_IN_SET('archive',e.flags) |
506a46ed |
343 | ORDER BY FIND_IN_SET('valide',e.flags), e.peremption DESC"; |
92423144 |
344 | $page->assign('evs', XDB::iterator($sql)); |
345 | } |
506a46ed |
346 | $page->assign('arch', $arch); |
92423144 |
347 | } |
348 | |
349 | function handler_admin_nl(&$page, $new = false) { |
163eddd2 |
350 | $page->changeTpl('newsletter/admin.tpl'); |
92423144 |
351 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste'); |
352 | require_once("newsletter.inc.php"); |
353 | |
354 | if($new) { |
355 | insert_new_nl(); |
356 | pl_redirect("admin/newsletter"); |
357 | } |
358 | |
359 | $page->assign_by_ref('nl_list', get_nl_slist()); |
360 | } |
361 | |
362 | function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') { |
163eddd2 |
363 | $page->changeTpl('newsletter/edit.tpl'); |
92423144 |
364 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition'); |
365 | require_once("newsletter.inc.php"); |
366 | |
367 | $nl = new NewsLetter($nid); |
368 | |
369 | if($action == 'delete') { |
370 | $nl->delArticle($aid); |
371 | pl_redirect("admin/newsletter/edit/$nid"); |
372 | } |
373 | |
374 | if($aid == 'update') { |
375 | $nl->_title = Post::v('title'); |
376 | $nl->_date = Post::v('date'); |
377 | $nl->_head = Post::v('head'); |
378 | $nl->save(); |
379 | } |
380 | |
381 | if(Post::v('save')) { |
382 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
383 | $aid, Post::v('cid'), Post::v('pos')); |
384 | $nl->saveArticle($art); |
385 | pl_redirect("admin/newsletter/edit/$nid"); |
386 | } |
387 | |
388 | if($action == 'edit') { |
389 | $eaid = $aid; |
390 | if(Post::has('title')) { |
391 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
392 | $eaid, Post::v('cid'), Post::v('pos')); |
393 | } else { |
394 | $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); |
395 | } |
396 | $page->assign('art', $art); |
397 | } |
398 | |
399 | $page->assign_by_ref('nl',$nl); |
400 | } |
401 | function handler_admin_nl_cat(&$page, $action = 'list', $id = null) { |
402 | require_once('../classes/PLTableEditor.php'); |
403 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories'); |
404 | $page->assign('title', 'Gestion des catégories de la newsletter'); |
405 | $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid'); |
406 | $table_editor->describe('titre','intitulé',true); |
407 | $table_editor->describe('pos','position',true); |
408 | $table_editor->apply($page, $action, $id); |
409 | } |
410 | |
74e0093f |
411 | } |
412 | |
413 | ?> |