Backport
[platal.git] / modules / carnet.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
50a40a33 3 * Copyright (C) 2003-2006 Polytechnique.org *
0337d704 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
c9f82d49 22class CarnetModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
fc12cbd1 27 'carnet/panel' => $this->make_hook('panel', AUTH_COOKIE),
28
29 'carnet/rss' => $this->make_hook('rss', AUTH_PUBLIC),
30 'carnet/ical' => $this->make_hook('ical', AUTH_PUBLIC),
c9f82d49 31 );
32 }
0337d704 33
fc12cbd1 34 function _add_rss_link(&$page)
35 {
36 if (!Session::has('core_rss_hash'))
37 return;
38 $page->assign('xorg_rss',
39 array('title' => 'Polytechnique.org :: Carnet',
40 'href' => '/carnet/rss/'.Session::get('forlife')
41 .'/'.Session::get('core_rss_hash').'/rss.xml')
42 );
43 }
44
45 function handler_panel(&$page)
46 {
47 $page->changeTpl('carnet/panel.tpl');
48
49 if (Get::has('read')) {
50 global $globals;
51
52 $_SESSION['watch_last'] = Get::get('read');
53 redirect($globals->baseurl.'/carnet/panel');
54 }
55
56 require_once 'notifs.inc.php';
57
58 $page->assign('now',date('YmdHis'));
59 $notifs = new Notifs(Session::getInt('uid'), true);
60
61 $page->assign('notifs', $notifs);
62 $page->assign('today', date('Y-m-d'));
63 $this->_add_rss_link($page);
64
65 return PL_OK;
66 }
67
c9f82d49 68 function handler_rss(&$page, $user = null, $hash = null)
69 {
70 require_once 'rss.inc.php';
71 require_once 'notifs.inc.php';
0337d704 72
c9f82d49 73 $uid = init_rss('carnet/rss.tpl', $user, $hash);
74 $notifs = new Notifs($uid, false);
75 $page->assign('notifs', $notifs);
76
77 return PL_OK;
78 }
fbfb06dc 79
80 function handler_ical(&$page, $user = null, $hash = null, $all = null)
81 {
82 global $globals;
83
84 new_nonhtml_page('carnet/calendar.tpl', AUTH_PUBLIC);
85
86 if ($alias && $hash) {
87 $res = $globals->xdb->query(
88 'SELECT a.id
89 FROM aliases AS a
90 INNER JOIN auth_user_quick AS q ON ( a.id = q.user_id AND q.core_rss_hash = {?} )
91 WHERE a.alias = {?} AND a.type != "homonyme"', $hash, $alias);
92 $uid = $res->fetchOneCell();
93 }
94
95 require_once 'notifs.inc.php';
96 $notifs = new Notifs($uid, true);
97
98 $annivcat = false;
99 foreach ($notifs->_cats as $cat) {
100 if (preg_match('/anniv/i', $cat['short']))
101 $annivcat = $cat['id'];
102 }
103
104 if ($annivcat !== false) {
105 $annivs = array();
106 foreach ($notifs->_data[$annivcat] as $promo) {
107 foreach ($promo as $notif) {
108 if ($all == 'all' || $notif['contact']) {
109 $annivs[] = array(
110 'timestamp' => $notif['known'],
111 'date' => strtotime($notif['date']),
112 'tomorrow' => strtotime("+1 day", strtotime($notif['date'])),
113 'bestalias' => $notif['bestalias'],
114 'summary' => 'Anniversaire de '.$notif['prenom']
115 .' '.$notif['nom'].' - x '.$notif['promo'],
116 );
117 }
118 }
119 }
120 $page->assign('events', $annivs);
121 }
122
123 header('Content-Type: text/calendar; charset=utf-8');
124
125 return PL_OK;
126 }
4da0b8d7 127}
c9f82d49 128
129?>