b07cd19736774bfa04b826d38138fddda09f53d4
[platal.git] / modules / carnet.php
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 CarnetModule extends PLModule
23 {
24 function handlers()
25 {
26 return array(
27 'carnet/rss' => $this->make_hook('rss', AUTH_PUBLIC),
28 'carnet/ical' => $this->make_hook('ical', AUTH_PUBLIC),
29 );
30 }
31
32 function handler_rss(&$page, $user = null, $hash = null)
33 {
34 require_once 'rss.inc.php';
35 require_once 'notifs.inc.php';
36
37 $uid = init_rss('carnet/rss.tpl', $user, $hash);
38 $notifs = new Notifs($uid, false);
39 $page->assign('notifs', $notifs);
40
41 return PL_OK;
42 }
43
44 function handler_ical(&$page, $user = null, $hash = null, $all = null)
45 {
46 global $globals;
47
48 new_nonhtml_page('carnet/calendar.tpl', AUTH_PUBLIC);
49
50 if ($alias && $hash) {
51 $res = $globals->xdb->query(
52 'SELECT a.id
53 FROM aliases AS a
54 INNER JOIN auth_user_quick AS q ON ( a.id = q.user_id AND q.core_rss_hash = {?} )
55 WHERE a.alias = {?} AND a.type != "homonyme"', $hash, $alias);
56 $uid = $res->fetchOneCell();
57 }
58
59 require_once 'notifs.inc.php';
60 $notifs = new Notifs($uid, true);
61
62 $annivcat = false;
63 foreach ($notifs->_cats as $cat) {
64 if (preg_match('/anniv/i', $cat['short']))
65 $annivcat = $cat['id'];
66 }
67
68 if ($annivcat !== false) {
69 $annivs = array();
70 foreach ($notifs->_data[$annivcat] as $promo) {
71 foreach ($promo as $notif) {
72 if ($all == 'all' || $notif['contact']) {
73 $annivs[] = array(
74 'timestamp' => $notif['known'],
75 'date' => strtotime($notif['date']),
76 'tomorrow' => strtotime("+1 day", strtotime($notif['date'])),
77 'bestalias' => $notif['bestalias'],
78 'summary' => 'Anniversaire de '.$notif['prenom']
79 .' '.$notif['nom'].' - x '.$notif['promo'],
80 );
81 }
82 }
83 }
84 $page->assign('events', $annivs);
85 }
86
87 header('Content-Type: text/calendar; charset=utf-8');
88
89 return PL_OK;
90 }
91 }
92
93 ?>