Proof of concept:
[platal.git] / htdocs / carnet / calendar.php
CommitLineData
f2ee531a 1<?php
2/***************************************************************************
50a40a33 3 * Copyright (C) 2003-2006 Polytechnique.org *
f2ee531a 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
22require_once("xorg.inc.php");
23new_nonhtml_page('carnet/calendar.tpl', AUTH_PUBLIC);
24
25if (preg_match(',^/([^/]+)/([^/_]+)(_all)?\.ics$,', $_SERVER['PATH_INFO'], $m)) {
26 $alias = $m[1];
27 $hash = $m[2];
28 $all = $m[3];
29} else {
30 $alias = Env::get('alias');
31 $hash = Env::get('hash');
32 $all = Env::has('all');
33}
34if ($alias && $hash) {
35 $res = $globals->xdb->query(
36 'SELECT a.id
37 FROM aliases AS a
38 INNER JOIN auth_user_quick AS q ON ( a.id = q.user_id AND q.core_rss_hash = {?} )
39 WHERE a.alias = {?} AND a.type != "homonyme"', $hash, $alias);
40 $uid = $res->fetchOneCell();
41}
42
43require_once('notifs.inc.php');
44$notifs = new Notifs($uid, true);
45
46$annivcat = false;
47foreach ($notifs->_cats as $cat)
48 if (preg_match('/anniv/i', $cat['short']))
49 $annivcat = $cat['id'];
50
51if ($annivcat !== false) {
52 $annivs = array();
53 foreach ($notifs->_data[$annivcat] as $promo) foreach ($promo as $notif)
54 if ($all || $notif['contact']) {
55 $annivs[] = array(
56 'timestamp' => $notif['known'],
57 'date' => strtotime($notif['date']),
58 'tomorrow' => strtotime("+1 day", strtotime($notif['date'])),
59 'bestalias' => $notif['bestalias'],
60 'summary' => 'Anniversaire de '.$notif['prenom'].' '.$notif['nom'].' - x '.$notif['promo'],
61 );
62 }
63 $page->assign('events', $annivs);
64}
65
66header('Content-Type: text/calendar; charset=utf-8');
67
68$page->run();
69?>