-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathical.php
More file actions
67 lines (54 loc) · 1.73 KB
/
ical.php
File metadata and controls
67 lines (54 loc) · 1.73 KB
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
<?php
$classes = explode(",", $_GET["classes"]);
$events = array();
$valid = false;
foreach ($classes as $class) {
if (!isset($class) || empty($class)) continue;
$check = file_get_contents("http://api.windesheim.nl/api/Klas/$class");
if ($check == "null") continue;
$rooster = json_decode(file_get_contents("http://api.windesheim.nl/api/Klas/$class/Les"), true);
foreach ($rooster as $event) {
if (!$valid) $valid = true;
array_push($events, $event);
}
}
if (!$valid) {
http_response_code(404);
die();
}
function longToDate($long) {
$seconds = $long / 1000;
$date = new DateTime("@$seconds", new DateTimeZone("Europe/Amsterdam"));
return "TZID=Europe/Amsterdam:" . $date->format("Ymd\THis");
}
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
echo "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Under_Koen//NONSGML Windesheim ICAL//EN
";
foreach ($events as $event) {
echo "BEGIN:VEVENT
UID:" . $event["id"] . "@" . $_SERVER["HTTP_HOST"] . "
DTSTAMP;TZID=Europe/Amsterdam:" . gmdate("Ymd\THis") . "
DTSTART;" . longToDate($event["starttijd"]) . "
DTEND;" . longToDate($event["eindtijd"]) . "
SUMMARY:" . $event["commentaar"] . "
";
if (!empty($event["docentnamen"])) {
$docenten = "";
foreach ($event["docentnamen"] as $docentnaam) {
if (!empty($docenten)) $docenten = "$docenten, ";
$docenten = "$docenten$docentnaam";
}
echo "DESCRIPTION:Klas: " . $event["groepcode"] . "\\nDocent(en): $docenten\n";
} else {
echo "DESCRIPTION:Klas: " . $event["groepcode"] . "\n";
}
echo "LOCATION:" . $event["lokaal"] . "
END:VEVENT
";
}
echo "END:VCALENDAR
";
exit();