-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal.php
77 lines (60 loc) · 1.98 KB
/
cal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
//------------------------------------------------------------------------------
/// Filename: cal.php
/// Description: Examfilter Calendar file
/// Authors: Tommy Sparber
///
/// Created: 14.10.2012
//------------------------------------------------------------------------------
error_reporting(E_ALL|E_STRICT);
require_once('./classes/tools.class.php');
require_once('./classes/caltools.class.php');
main();
//------------------------------------------------------------------------------
function main()
{
$ids = CalTools::loadIds();
$id = $_GET['id'];
if(!in_array($id, $ids))
{
header('HTTP/1.0 403 Forbidden');
//die('Not allowed');
die('403 Forbidden');
}
if(!isset($_GET['debug']))
{
header("Content-Type: text/calendar; charset=UTF-8");
header('Content-Disposition: attachment; filename="Pruefungstermine.ics"');
}
$data = CalTools::getData();
$events = CalTools::parseCalendar($data);
$ignore = file("./storage/cal_$id.txt", FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
$filter_events = array();
//replace url
foreach($events as $key => $event)
{
if(!in_array(trim($event['SUMMARY']), $ignore))
{
$filter_events[$key] = $event;
$match = array();
$eid = 0;
if(preg_match('/^https:\/\/online.tugraz.at\/tug_online\/wbregisterexam\.lv_termine\?cstp_sp_nr=([0-9]+)&cheader=J&pLvGroupFlag=J$/', $event['URL'], $match))
{
$eid = $match[1];
}
$filter_events[$key]['URL'] = CalTools::getEventURL($id, $eid);
if(FALSE == preg_match('/^iOS/', $_SERVER['HTTP_USER_AGENT']) &&
FALSE == preg_match('/^Mac OS X/', $_SERVER['HTTP_USER_AGENT']))
{
$filter_events[$key]['DESCRIPTION'] = CalTools::getEventURL($id, $eid);
}
else { /* do not abuse description for url on OSX or iOS */ }
}
}
if(isset($_GET['debug']))
print '<pre>';
print CalTools::generateCalendar($filter_events);
if(isset($_GET['debug']))
print '</pre>';
}
?>