<%
// include path
set_include_path('../scripts');
// xpath library
require_once('xml.php');
// xml encoding
require_once('encode.php');
// input parameters
if (isset($_GET['year']))
$year = $_GET['year'];
else
$year = gmdate('Y');
$series = $_GET['series'];
$id = $_GET['id'];
// grab the calendar file
$doc = new XML('../services/scripts/'.$series.$year.'.xml');
// find the race we want (ignore the first from last year)
$races = $doc->evaluate('//race');
$first = true;
foreach ($races as $race)
if ($first)
$first = false;
elseif ($doc->get_content($race.'/id[1]') == $id)
break;
// grab the race data
$date = $doc->get_content($race.'/date[1]');
$sdate = date("Ymd", strtotime($date));
$edate = date("Ymd", strtotime($date) + 24 * 60 * 60);
$name = xml_decode($doc->get_content($race.'/name[1]'));
$location = $doc->get_content($race.'/location[1]');
// set the title
switch ($series)
{
case "cart":
case "ccws":
$title = "Champ Car";
break;
case "f1":
$title = "Formula One";
break;
case "irl":
$title = "IndyCar";
break;
case "alms":
$title = "Am Le Mans";
break;
default:
$title = "Error";
$cid = 0;
break;
}
// send vCalendar header
header('Content-type: text/Calendar');
header("Content-Disposition: inline; filename=$name.ics");
%>
BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART;VALUE=DATE:<% echo($sdate); %>
DTEND;VALUE=DATE:<% echo($edate); %>
LOCATION:<% echo($location); %>
TRANSP:TRANSPARENT
SEQUENCE:0
UID:<% echo($series.$sdate); %>T000000Z@racebyrace.com
DTSTAMP:<% echo gmdate('Ymd'); %>T000000Z
DESCRIPTION: See http://www.racebyrace.com/schedules for details
SUMMARY:<% echo($title.': '.$name); %>
PRIORITY:5
CLASS:PUBLIC
BEGIN:VALARM
TRIGGER:-PT5D
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR