';
@@ -121,7 +68,6 @@ class Sabre_DAV_XMLUtilTest extends PHPUnit_Framework_TestCase {
}
/**
- * @depends testConvertDAVNamespace
* @expectedException Sabre_DAV_Exception_BadRequest
*/
function testLoadDOMDocumentInvalid() {
diff --git a/dav/SabreDAV/tests/Sabre/VObject/ComponentTest.php b/dav/SabreDAV/tests/Sabre/VObject/ComponentTest.php
index 71b33c07..42f836db 100644
--- a/dav/SabreDAV/tests/Sabre/VObject/ComponentTest.php
+++ b/dav/SabreDAV/tests/Sabre/VObject/ComponentTest.php
@@ -340,11 +340,14 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
new Sabre_VObject_Component('VEVENT'),
new Sabre_VObject_Component('VTODO')
);
- $this->assertEquals("BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", $comp->serialize());
+
+ $str = $comp->serialize();
+
+ $this->assertEquals("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n", $str);
}
- function testSerializeOrder() {
+ function testSerializeOrderCompAndProp() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp->add(new Sabre_VObject_Component('VEVENT'));
@@ -358,4 +361,30 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
}
+ function testAnotherSerializeOrderProp() {
+
+ $prop4s=array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
+
+ $comp = new Sabre_VObject_Component('VCARD');
+ $comp->__set('SOMEPROP','FOO');
+ $comp->__set('ANOTHERPROP','FOO');
+ $comp->__set('THIRDPROP','FOO');
+ foreach ($prop4s as $prop4) {
+ $comp->add('PROP4', 'FOO '.$prop4);
+ }
+ $comp->__set('PROPNUMBERFIVE', 'FOO');
+ $comp->__set('PROPNUMBERSIX', 'FOO');
+ $comp->__set('PROPNUMBERSEVEN', 'FOO');
+ $comp->__set('PROPNUMBEREIGHT', 'FOO');
+ $comp->__set('PROPNUMBERNINE', 'FOO');
+ $comp->__set('PROPNUMBERTEN', 'FOO');
+ $comp->__set('VERSION','2.0');
+ $comp->__set('UID', 'FOO');
+
+ $str = $comp->serialize();
+
+ $this->assertEquals("BEGIN:VCARD\r\nVERSION:2.0\r\nSOMEPROP:FOO\r\nANOTHERPROP:FOO\r\nTHIRDPROP:FOO\r\nPROP4:FOO 1\r\nPROP4:FOO 2\r\nPROP4:FOO 3\r\nPROP4:FOO 4\r\nPROP4:FOO 5\r\nPROP4:FOO 6\r\nPROP4:FOO 7\r\nPROP4:FOO 8\r\nPROP4:FOO 9\r\nPROP4:FOO 10\r\nPROPNUMBERFIVE:FOO\r\nPROPNUMBERSIX:FOO\r\nPROPNUMBERSEVEN:FOO\r\nPROPNUMBEREIGHT:FOO\r\nPROPNUMBERNINE:FOO\r\nPROPNUMBERTEN:FOO\r\nUID:FOO\r\nEND:VCARD\r\n", $str);
+
+ }
+
}
diff --git a/dav/SabreDAV/tests/Sabre/VObject/Issue154Test.php b/dav/SabreDAV/tests/Sabre/VObject/Issue154Test.php
index a004eb08..f5136be1 100644
--- a/dav/SabreDAV/tests/Sabre/VObject/Issue154Test.php
+++ b/dav/SabreDAV/tests/Sabre/VObject/Issue154Test.php
@@ -6,9 +6,9 @@ class Sabre_VObject_Issue154Test extends PHPUnit_Framework_TestCase {
$vcard = new Sabre_VObject_Component('VCARD');
$vcard->VERSION = '3.0';
- $vcard->UID = 'foo-bar';
$vcard->PHOTO = base64_encode('random_stuff');
$vcard->PHOTO->add('BASE64',null);
+ $vcard->UID = 'foo-bar';
$result = $vcard->serialize();
$expected = array(
diff --git a/dav/common/calendar.fnk.php b/dav/common/calendar.fnk.php
index 22f1d18c..01af64fb 100644
--- a/dav/common/calendar.fnk.php
+++ b/dav/common/calendar.fnk.php
@@ -301,7 +301,7 @@ function dav_get_current_user_calendars(&$server, $with_privilege = "")
* @param Sabre_CalDAV_Calendar $calendar
* @param string $calendarobject_uri
* @param string $with_privilege
- * @return null|Sabre_VObject_Component_VEvent
+ * @return null|Sabre_VObject_Component_VCalendar
*/
function dav_get_current_user_calendarobject(&$server, &$calendar, $calendarobject_uri, $with_privilege = "")
{
diff --git a/dav/common/calendar_rendering.fnk.php b/dav/common/calendar_rendering.fnk.php
index b6c009db..e97de36b 100644
--- a/dav/common/calendar_rendering.fnk.php
+++ b/dav/common/calendar_rendering.fnk.php
@@ -12,7 +12,7 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent)
{
$trigger = $alarm->__get("TRIGGER");
if (!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') {
- $triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($trigger);
+ $triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($trigger->value);
$related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START';
diff --git a/dav/common/wdcal.js b/dav/common/wdcal.js
index 58e36243..adcaf15f 100644
--- a/dav/common/wdcal.js
+++ b/dav/common/wdcal.js
@@ -120,6 +120,13 @@ function wdcal_edit_init(dateFormat, base_path) {
$(this).data("orig", $(this).text());
});
+ $("#new_alarm_adder a").click(function(ev) {
+ $("#new_alarm").val("1");
+ $("#noti_new_row").show();
+ $("#new_alarm_adder").hide();
+ ev.preventDefault();
+ });
+
wdcal_edit_recur_recalc();
$(document).on("click", ".exception_remover", function(ev) {
diff --git a/dav/common/wdcal_edit.inc.php b/dav/common/wdcal_edit.inc.php
index c652d974..5595369f 100644
--- a/dav/common/wdcal_edit.inc.php
+++ b/dav/common/wdcal_edit.inc.php
@@ -3,13 +3,11 @@
/**
* @param wdcal_local $localization
* @param string $baseurl
- * @param int $uid
* @param int $calendar_id
* @param int $uri
- * @param string $recurr_uri
* @return string
*/
-function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $uri, $recurr_uri = "")
+function wdcal_getEditPage_str(&$localization, $baseurl, $calendar_id, $uri)
{
$server = dav_create_server(true, true, false);
@@ -53,12 +51,53 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur
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->m) {
+ $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);
+ //$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
$event = array(
"id" => 0,
@@ -71,15 +110,15 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur
"Color" => null,
);
if ($_REQUEST["isallday"]) {
- $notifications = array(array("rel" => "start", "type" => "duration", "period" => "hour", "period_val" => 24));
+ $notifications = array();
} else {
- $notifications = array(array("rel" => "start", "type" => "duration", "period" => "hour", "period_val" => 1));
+ $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);
+ //$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
$event = array(
"id" => 0,
@@ -91,7 +130,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur
"Location" => "",
"Color" => null,
);
- $notifications = array(array("rel" => "start", "type" => "duration", "period" => "hour", "period_val" => 1));
+ $notifications = array(array("action" => "email", "rel" => "start", "trigger_unit" => "hour", "trigger_value" => 1));
$recurrence = null;
$recurrentce_exdates = array();
}
@@ -270,7 +309,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur
$out .= "";
$monthly_rule = "";
- if ($recurrence->frequency == "monthly" || $recurrence->frequency == "yearly") {
+ if ($recurrence && ($recurrence->frequency == "monthly" || $recurrence->frequency == "yearly")) {
if (is_null($recurrence->byDay) && !is_null($recurrence->byMonthDay) && count($recurrence->byMonthDay) == 1) {
$day = date("j", $event["StartTime"]);
if ($recurrence->byMonthDay[0] == $day) $monthly_rule = "bymonthday";
@@ -324,7 +363,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur
$out .= "";
$out .= "\n";
- if ($recurrence->frequency == "yearly") {
+ if ($recurrence && $recurrence->frequency == "yearly") {
if (count($recurrence->byMonth) != 1 || $recurrence->byMonth[0] != date("n", $event["StartTime"])) notice("The recurrence of this event cannot be parsed!");
}
@@ -408,31 +447,53 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur
$out .= "" . t("Notification") . "
";
- /*
- $out .= '
- ' . t('before') . '
-
';
- */
+ if (!$notifications) $notifications = array();
+ $notifications["new"] = array(
+ "action" => "email",
+ "trigger_value" => 60,
+ "trigger_unit" => "minute",
+ "rel" => "start",
+ );
+
+ foreach ($notifications as $index => $noti) {
+
+ $unparsable = false;
+ if (!in_array($noti["action"], array("email", "display"))) $unparsable = true;
+
+ $out .= "\n";
+ $out .= "
";
+ }
+ $out .= "";
$out .= "";
- $out .= "";
+ $out .= "
";
return $out;
}
@@ -441,6 +502,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur
/**
* @param Sabre_VObject_Component_VEvent $component
* @param wdcal_local $localization
+ * @return int
*/
function wdcal_set_component_date(&$component, &$localization)
{
@@ -462,6 +524,8 @@ function wdcal_set_component_date(&$component, &$localization)
$component->__unset("DTEND");
$component->add($datetime_start);
$component->add($datetime_end);
+
+ return $ts_start;
}
/**
@@ -569,13 +633,6 @@ function wdcal_set_component_recurrence(&$component, &$localization)
default:
$part_freq = "";
}
-/*
- echo "!";
- echo $part_freq . "\n";
- var_dump($_REQUEST);
- echo "
";
- die();
-*/
if ($part_freq == "") return;
@@ -598,15 +655,69 @@ function wdcal_set_component_recurrence(&$component, &$localization)
}
-/**
+ /**
+ * @param Sabre_VObject_Component_VEvent $component
+ * @param wdcal_local $localization
+ * @param string $summary
+ * @param int $dtstart
+ */
+function wdcal_set_component_alerts(&$component, &$localization, $summary, $dtstart)
+{
+ $a = get_app();
+
+ $prev_alarms = $component->select("VALARM");
+ $component->__unset("VALARM");
+
+ foreach ($prev_alarms as $al) {
+ /** @var Sabre_VObject_Component_VAlarm $al */
+ }
+
+ foreach (array_keys($_REQUEST["noti_type"]) as $key) if (is_numeric($key) || ($key == "new" && $_REQUEST["new_alarm"] == 1)) {
+ $alarm = new Sabre_VObject_Component_VAlarm("VALARM");
+
+ switch ($_REQUEST["noti_type"][$key]) {
+ case "email":
+ $mailtext = str_replace(array(
+ "#date#", "#name",
+ ), array(
+ $localization->date_timestamp2local($dtstart), $summary,
+ ), t("The event #name# will start at #date"));
+
+ $alarm->add(new Sabre_VObject_Property("ACTION", "EMAIL"));
+ $alarm->add(new Sabre_VObject_Property("SUMMARY", $summary));
+ $alarm->add(new Sabre_VObject_Property("DESCRIPTION", $mailtext));
+ $alarm->add(new Sabre_VObject_Property("ATTENDEE", "MAILTO:" . $a->user["email"]));
+ break;
+ case "display":
+ $alarm->add(new Sabre_VObject_Property("ACTION", "DISPLAY"));
+ $text = str_replace("#name#", $summary, t("#name# is about to begin."));
+ $alarm->add(new Sabre_VObject_Property("DESCRIPTION", $text));
+ break;
+ default:
+ continue;
+ }
+
+ $trigger_name = "TRIGGER";
+ $trigger_val = ""; // @TODO Bugfix : und ; sind evtl. vertauscht vgl. http://www.kanzaki.com/docs/ical/trigger.html
+ if ($_REQUEST["noti_ref"][$key] == "end") $trigger_name .= ";RELATED=END";
+ $trigger_val .= "-P";
+ if (in_array($_REQUEST["noti_unit"][$key], array("H", "M", "S"))) $trigger_val .= "T";
+ $trigger_val .= IntVal($_REQUEST["noti_value"][$key]) . $_REQUEST["noti_unit"][$key];
+ $alarm->add(new Sabre_VObject_Property($trigger_name, $trigger_val));
+
+ $component->add($alarm);
+ }
+
+}
+
+ /**
* @param string $uri
- * @param string $recurr_uri
* @param int $uid
* @param string $timezone
* @param string $goaway_url
* @return array
*/
-function wdcal_postEditPage($uri, $recurr_uri = "", $uid = 0, $timezone = "", $goaway_url = "")
+function wdcal_postEditPage($uri, $uid = 0, $timezone = "", $goaway_url = "")
{
$uid = IntVal($uid);
$localization = wdcal_local::getInstanceByUser($uid);
@@ -629,8 +740,9 @@ function wdcal_postEditPage($uri, $recurr_uri = "", $uid = 0, $timezone = "", $g
$obj_uri = $component->__get("UID");
}
- wdcal_set_component_date($component, $localization);
+ $ts_start = wdcal_set_component_date($component, $localization);
wdcal_set_component_recurrence($component, $localization);
+ wdcal_set_component_alerts($component, $localization, icalendar_sanitize_string(dav_compat_parse_text_serverside("summary")), $ts_start);
$component->__unset("LOCATION");
$component->__unset("SUMMARY");
diff --git a/dav/layout.fnk.php b/dav/layout.fnk.php
index 6f59d745..597e773d 100644
--- a/dav/layout.fnk.php
+++ b/dav/layout.fnk.php
@@ -290,10 +290,9 @@ function wdcal_printCalendar($calendars, $calendars_selected, $data_feed_url, $v
/**
* @param int $calendar_id
* @param int $calendarobject_id
- * @param string $recurr_uri
* @return string
*/
-function wdcal_getDetailPage($calendar_id, $calendarobject_id, $recurr_uri)
+function wdcal_getDetailPage($calendar_id, $calendarobject_id)
{
$a = get_app();
@@ -322,15 +321,14 @@ function wdcal_getDetailPage($calendar_id, $calendarobject_id, $recurr_uri)
/**
* @param int $calendar_id
* @param int $uri
- * @param string $recurr_uri
* @return string
*/
-function wdcal_getEditPage($calendar_id, $uri, $recurr_uri = "")
+function wdcal_getEditPage($calendar_id, $uri)
{
$a = get_app();
$localization = wdcal_local::getInstanceByUser($a->user["uid"]);
- return wdcal_getEditPage_str($localization, $a->get_baseurl(), $a->user["uid"], $calendar_id, $uri, $recurr_uri);
+ return wdcal_getEditPage_str($localization, $a->get_baseurl(), $calendar_id, $uri);
}
/**
@@ -341,7 +339,7 @@ function wdcal_getNewPage()
$a = get_app();
$localization = wdcal_local::getInstanceByUser($a->user["uid"]);
- return wdcal_getEditPage_str($localization, $a->get_baseurl(), $a->user["uid"], 0, 0);
+ return wdcal_getEditPage_str($localization, $a->get_baseurl(), 0, 0);
}
diff --git a/dav/main.php b/dav/main.php
index 2a0092ac..14c98724 100644
--- a/dav/main.php
+++ b/dav/main.php
@@ -24,12 +24,6 @@ function dav_module()
function dav_include_files()
{
- /*
- require_once (__DIR__ . "/SabreDAV/lib/Sabre.includes.php");
- require_once (__DIR__ . "/SabreDAV/lib/Sabre/VObject/includes.php");
- require_once (__DIR__ . "/SabreDAV/lib/Sabre/DAVACL/includes.php");
- require_once (__DIR__ . "/SabreDAV/lib/Sabre/CalDAV/includes.php");
- */
require_once (__DIR__ . "/SabreDAV/lib/Sabre/autoload.php");
require_once (__DIR__ . "/common/calendar.fnk.php");
@@ -145,20 +139,19 @@ function dav_content()
} elseif (isset($a->argv[3]) && $a->argv[3] == "ics-import") {
return wdcal_import_user_ics($calendar_id);
} elseif (isset($a->argv[3]) && $a->argv[3] > 0) {
- $recurr_uri = ""; // @TODO
if (isset($a->argv[4]) && $a->argv[4] == "edit") {
$o = "";
if (isset($_REQUEST["save"])) {
check_form_security_token_redirectOnErr($a->get_baseurl() . "/dav/wdcal/", "caledit");
- $ret = wdcal_postEditPage($a->argv[3], $recurr_uri, $a->user["uid"], $a->timezone, $a->get_baseurl() . "/dav/wdcal/");
+ $ret = wdcal_postEditPage($a->argv[3], $a->user["uid"], $a->timezone, $a->get_baseurl() . "/dav/wdcal/");
if ($ret["ok"]) notice($ret["msg"]);
else info($ret["msg"]);
goaway($a->get_baseurl() . "/dav/wdcal/");
}
- $o .= wdcal_getEditPage($calendar_id, $a->argv[3], $recurr_uri);
+ $o .= wdcal_getEditPage($calendar_id, $a->argv[3]);
return $o;
} else {
- return wdcal_getDetailPage($calendar_id, $a->argv[3], $recurr_uri);
+ return wdcal_getDetailPage($calendar_id, $a->argv[3]);
}
} else {
// @TODO Edit Calendar