<?php
$oDocument = Context::get('oDocument');
if($oDocument->isExtraVarsExists() && (!$oDocument->isSecret() || $oDocument->isGranted()) ) {
	$tpl_path = $__Context->tpl_path;
	if(!class_exists('planner123_main')) {
		require_once($tpl_path.'function/class.planner123_main.php');
	}
	$oEvent = new stdClass;
	foreach($oDocument->getExtraVars() as $key => $val) {
		$oEvent->ext_val[$key] = $val->value;
	}
	$oEvent->reservation = $module_info->reservation;
	$oEvent->title = $oDocument->getTitle($module_info->subject_cut_size);
	$oEvent->content = $oDocument->getSummary($module_info->content_cut_size);
	$oEvent->doc_srl = $oDocument->document_srl;
	$oEvent->time_interval = $module_info->time_interval;
	$oEvent->category = $category_list[$oDocument->get('category_srl')]->title;
	$oEvent->location = '';
	$events[$oDocument->document_srl] = $oEvent;
	$str_ics = planner123_main::fn_creatICS($events);

	header('Content-type: text/calendar; charset=utf-8');
	header('Content-Disposition: attachment; filename="ics_'.$_SERVER['HTTP_HOST'].'_'.$oDocument->document_srl.'.ics"');
	header("Content-Length: " . strlen($str_ics));
	header("Connection: close");
	print $str_ics;
	exit();
}
?>