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