2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class CarnetModule
extends PLModule
27 'carnet/panel' => $this->make_hook('panel', AUTH_COOKIE
),
29 'carnet/rss' => $this->make_hook('rss', AUTH_PUBLIC
),
30 'carnet/ical' => $this->make_hook('ical', AUTH_PUBLIC
),
34 function _add_rss_link(&$page)
36 if (!Session
::has('core_rss_hash'))
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')
45 function handler_panel(&$page)
47 $page->changeTpl('carnet/panel.tpl');
49 if (Get
::has('read')) {
52 $_SESSION['watch_last'] = Get
::get('read');
53 redirect($globals->baseurl
.'/carnet/panel');
56 require_once 'notifs.inc.php';
58 $page->assign('now',date('YmdHis'));
59 $notifs = new Notifs(Session
::getInt('uid'), true
);
61 $page->assign('notifs', $notifs);
62 $page->assign('today', date('Y-m-d'));
63 $this->_add_rss_link($page);
68 function handler_rss(&$page, $user = null
, $hash = null
)
70 require_once 'rss.inc.php';
71 require_once 'notifs.inc.php';
73 $uid = init_rss('carnet/rss.tpl', $user, $hash);
74 $notifs = new Notifs($uid, false
);
75 $page->assign('notifs', $notifs);
80 function handler_ical(&$page, $user = null
, $hash = null
, $all = null
)
84 new_nonhtml_page('carnet/calendar.tpl', AUTH_PUBLIC
);
86 if ($alias && $hash) {
87 $res = $globals->xdb
->query(
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();
95 require_once 'notifs.inc.php';
96 $notifs = new Notifs($uid, true
);
99 foreach ($notifs->_cats
as $cat) {
100 if (preg_match('/anniv/i', $cat['short']))
101 $annivcat = $cat['id'];
104 if ($annivcat !== false
) {
106 foreach ($notifs->_data
[$annivcat] as $promo) {
107 foreach ($promo as $notif) {
108 if ($all == 'all' ||
$notif['contact']) {
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'],
120 $page->assign('events', $annivs);
123 header('Content-Type: text/calendar; charset=utf-8');