//	$duration = $durationSeconds > 0 ? '+' : '-';
     //	$duration .= 'P' . $durationSeconds . 'S';
     // however, when formatted seemingly correctly you then get an error saying it's not in integer! :(
     // so just removing duration for now as it's implied by the start and end anyway - TODO better
     // $ea['Duration']=($duration);
     $ea['Contact'] = array($event['user']);
     if (!empty($event['organizers'])) {
         $ea['organizer'] = array($event['organizers']);
     }
     if (!empty($event['url'])) {
         $ea['URL'] = $event['url'];
     }
     $ea['DateStamp'] = $event['created'];
     //$ea['RequestStatus']=$event['status'];
     $ea['UID'] = 'tiki-' . $event['calendarId'] . '-' . $event['calitemId'];
     $c = $iCal->factory('Event', $ea);
     $cal->addEvent($c);
 }
 $iCal->addCalendar($cal);
 $iCal->sendHeader("calendar");
 $calendar_str = $iCal->__toString();
 header("Content-Length: " . strlen($calendar_str));
 header("Expires: 0");
 // These two lines fix pb with IE and HTTPS
 header("Cache-Control: private");
 header("Pragma: dummy=bogus");
 // Outlook needs iso8859 encoding
 header("Content-Type:text/calendar; method=REQUEST; charset=iso-8859-15");
 header("Content-Transfer-Encoding:quoted-printable");
 $re_encode = stripos($_SERVER['HTTP_USER_AGENT'], 'windows');
 // only re-encode to ISO-8859-15 if client on Windows
            $ea = array();
            $ea["Summary"] = $day_data[$i]["result"]["name"];
            $ea["dateStart"] = $day_data[$i]["result"]["start"];
            $ea["dateEnd"] = $day_data[$i]["result"]["end"];
            $ea["Description"] = preg_replace("/\n/", "\\n", $day_data[$i]["result"]["description"]);
            if ($day_data[$i]["result"]["participants"]) {
                $ea["Attendees"] = $day_data[$i]["result"]["participants"];
            }
            $ea["LastModified"] = $day_data[$i]["result"]["lastModif"];
            // Second character of duration value must be a 'P' ??
            //$ea["Duration"]=($day_data[$i]["result"]["end"] - $day_data[$i]["result"]["start"]);
            //$ea["Contact"]=array($day_data[$i]["result"]["user"]);
            //$ea["organizer"]=array($day_data[$i]["result"]["organizers"]);
            //$ea["URL"]=$day_data[$i]["result"]["url"];
            $ea["DateStamp"] = $day_data[$i]["result"]["created"];
            //$ea["RequestStatus"]=$day_data[$i]["result"]["status"];
            $ea["UID"] = "tiki-" . $day_data[$i]["result"]["calendarId"] . "-" . $day_data[$i]["result"]["calitemId"];
            $c = $iCal->factory("Event", $ea);
            $cal->addEvent($c);
        }
    }
    $iCal->addCalendar($cal);
    $iCal->sendHeader();
    print $iCal->__toString();
    die;
}
$smarty->assign('iCal', $iCal);
//$smarty->assign('filedata', $data);
// Display the template
$smarty->assign('mid', 'tiki-calendar_export_ical.tpl');
$smarty->display("tiki.tpl");