0) {
$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
if (!$calendar) {
$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_READ);
$calendars = array();
} else {
$calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
}
if ($calendar == null) return "Calendar not found";
$obj_uri = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($uri);
$vObject = dav_get_current_user_calendarobject($server, $calendar, $obj_uri["uri"], DAV_ACL_WRITE);
$component = dav_get_eventComponent($vObject);
if ($component == null) return L10n::t('Could not open component for editing');
/** @var Sabre\VObject\Property\DateTime $dtstart */
$dtstart = $component->__get("DTSTART");
$event = array(
"id" => IntVal($uri),
"Summary" => ($component->__get("SUMMARY") ? $component->__get("SUMMARY")->value : null),
"StartTime" => $dtstart->getDateTime()->getTimeStamp(),
"EndTime" => Sabre_CalDAV_Backend_Common::getDtEndTimeStamp($component),
"IsAllDayEvent" => (strlen($dtstart->value) == 8),
"Description" => ($component->__get("DESCRIPTION") ? $component->__get("DESCRIPTION")->value : null),
"Location" => ($component->__get("LOCATION") ? $component->__get("LOCATION")->value : null),
"Color" => ($component->__get("X-ANIMEXX-COLOR") ? $component->__get("X-ANIMEXX-COLOR")->value : null),
);
$exdates = $component->select("EXDATE");
$recurrentce_exdates = array();
/** @var Sabre\VObject\Property\MultiDateTime $x */
foreach ($exdates as $x) {
/** @var DateTime $y */
$z = $x->getDateTimes();
foreach ($z as $y) $recurrentce_exdates[] = $y->getTimeStamp();
}
$notifications = array();
$alarms = $component->select("VALARM");
foreach ($alarms as $alarm) {
/** @var Sabre_VObject_Component_VAlarm $alarm */
$action = $alarm->__get("ACTION")->value;
$trigger = $alarm->__get("TRIGGER");
if(isset($trigger['VALUE']) && strtoupper($trigger['VALUE']) !== 'DURATION') {
notice("The notification of this event cannot be parsed");
continue;
}
/** @var DateInterval $triggerDuration */
$triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($trigger);
$unit = "hour";
$value = 1;
if ($triggerDuration->s > 0) {
$unit = "second";
$value = $triggerDuration->s + $triggerDuration->i * 60 + $triggerDuration->h * 3600 + $triggerDuration->d * 3600 * 24; // @TODO support more than days?
} elseif ($triggerDuration->i) {
$unit = "minute";
$value = $triggerDuration->i + $triggerDuration->h * 60 + $triggerDuration->d * 60 * 24;
} elseif ($triggerDuration->h) {
$unit = "hour";
$value = $triggerDuration->h + $triggerDuration->d * 24;
} elseif ($triggerDuration->d > 0) {
$unit = "day";
$value = $triggerDuration->d;
}
$rel = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'end' : 'start';
$notifications[] = array(
"action" => strtolower($action),
"rel" => $rel,
"trigger_unit" => $unit,
"trigger_value" => $value,
);
}
if ($component->select("RRULE")) $recurrence = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
else $recurrence = null;
} elseif (isset($_REQUEST["start"]) && $_REQUEST["start"] > 0) {
$calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
//$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
$event = array(
"id" => 0,
"Summary" => $_REQUEST["title"],
"StartTime" => InTVal($_REQUEST["start"]),
"EndTime" => IntVal($_REQUEST["end"]),
"IsAllDayEvent" => $_REQUEST["isallday"],
"Description" => "",
"Location" => "",
"Color" => null,
);
if ($_REQUEST["isallday"]) {
$notifications = array();
} else {
$notifications = array(array("action" => "email", "rel" => "start", "trigger_unit" => "hour", "trigger_value" => 1));
}
$recurrence = null;
$recurrentce_exdates = array();
} else {
$calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
//$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
$event = array(
"id" => 0,
"Summary" => "",
"StartTime" => time(),
"EndTime" => time() + 3600,
"IsAllDayEvent" => "0",
"Description" => "",
"Location" => "",
"Color" => null,
);
$notifications = array(array("action" => "email", "rel" => "start", "trigger_unit" => "hour", "trigger_value" => 1));
$recurrence = null;
$recurrentce_exdates = array();
}
$postto = $baseurl . "/dav/wdcal/" . ($uri == 0 ? "new/" : $calendar_id . "/" . $uri . "/edit/");
$out = "" . L10n::t("Go back to the calendar") . "
";
$out .= "