3 use Friendica\Core\L10n;
6 * @param wdcal_local $localization
7 * @param string $baseurl
8 * @param int $calendar_id
12 function wdcal_getEditPage_str(&$localization, $baseurl, $calendar_id, $uri)
14 $server = dav_create_server(true, true, false);
17 $calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
19 $calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_READ);
22 $calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
25 if ($calendar == null) return "Calendar not found";
27 $obj_uri = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($uri);
29 $vObject = dav_get_current_user_calendarobject($server, $calendar, $obj_uri["uri"], DAV_ACL_WRITE);
30 $component = dav_get_eventComponent($vObject);
32 if ($component == null) return L10n::t('Could not open component for editing');
34 /** @var Sabre\VObject\Property\DateTime $dtstart */
35 $dtstart = $component->__get("DTSTART");
38 "Summary" => ($component->__get("SUMMARY") ? $component->__get("SUMMARY")->value : null),
39 "StartTime" => $dtstart->getDateTime()->getTimeStamp(),
40 "EndTime" => Sabre_CalDAV_Backend_Common::getDtEndTimeStamp($component),
41 "IsAllDayEvent" => (strlen($dtstart->value) == 8),
42 "Description" => ($component->__get("DESCRIPTION") ? $component->__get("DESCRIPTION")->value : null),
43 "Location" => ($component->__get("LOCATION") ? $component->__get("LOCATION")->value : null),
44 "Color" => ($component->__get("X-ANIMEXX-COLOR") ? $component->__get("X-ANIMEXX-COLOR")->value : null),
47 $exdates = $component->select("EXDATE");
48 $recurrentce_exdates = array();
49 /** @var Sabre\VObject\Property\MultiDateTime $x */
50 foreach ($exdates as $x) {
51 /** @var DateTime $y */
52 $z = $x->getDateTimes();
53 foreach ($z as $y) $recurrentce_exdates[] = $y->getTimeStamp();
56 $notifications = array();
57 $alarms = $component->select("VALARM");
58 foreach ($alarms as $alarm) {
59 /** @var Sabre_VObject_Component_VAlarm $alarm */
60 $action = $alarm->__get("ACTION")->value;
61 $trigger = $alarm->__get("TRIGGER");
63 if(isset($trigger['VALUE']) && strtoupper($trigger['VALUE']) !== 'DURATION') {
64 notice("The notification of this event cannot be parsed");
68 /** @var DateInterval $triggerDuration */
69 $triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($trigger);
72 if ($triggerDuration->s > 0) {
74 $value = $triggerDuration->s + $triggerDuration->i * 60 + $triggerDuration->h * 3600 + $triggerDuration->d * 3600 * 24; // @TODO support more than days?
75 } elseif ($triggerDuration->i) {
77 $value = $triggerDuration->i + $triggerDuration->h * 60 + $triggerDuration->d * 60 * 24;
78 } elseif ($triggerDuration->h) {
80 $value = $triggerDuration->h + $triggerDuration->d * 24;
81 } elseif ($triggerDuration->d > 0) {
83 $value = $triggerDuration->d;
86 $rel = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'end' : 'start';
89 $notifications[] = array(
90 "action" => strtolower($action),
92 "trigger_unit" => $unit,
93 "trigger_value" => $value,
97 if ($component->select("RRULE")) $recurrence = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
98 else $recurrence = null;
100 } elseif (isset($_REQUEST["start"]) && $_REQUEST["start"] > 0) {
101 $calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
102 //$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
106 "Summary" => $_REQUEST["title"],
107 "StartTime" => InTVal($_REQUEST["start"]),
108 "EndTime" => IntVal($_REQUEST["end"]),
109 "IsAllDayEvent" => $_REQUEST["isallday"],
114 if ($_REQUEST["isallday"]) {
115 $notifications = array();
117 $notifications = array(array("action" => "email", "rel" => "start", "trigger_unit" => "hour", "trigger_value" => 1));
120 $recurrentce_exdates = array();
122 $calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
123 //$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
128 "StartTime" => time(),
129 "EndTime" => time() + 3600,
130 "IsAllDayEvent" => "0",
135 $notifications = array(array("action" => "email", "rel" => "start", "trigger_unit" => "hour", "trigger_value" => 1));
137 $recurrentce_exdates = array();
140 $postto = $baseurl . "/dav/wdcal/" . ($uri == 0 ? "new/" : $calendar_id . "/" . $uri . "/edit/");
142 $out = "<a href='" . $baseurl . "/dav/wdcal/'>" . L10n::t("Go back to the calendar") . "</a><br><br>";
143 $out .= "<form method='POST' action='$postto'>
144 <input type='hidden' name='form_security_token' value='" . get_form_security_token('caledit') . "'>\n";
146 $out .= "<h2>" . L10n::t("Event data") . "</h2>";
148 $out .= "<label for='calendar' class='block'>" . L10n::t("Calendar") . ":</label><select id='calendar' name='calendar' size='1'>";
151 foreach ($calendars as $cal) {
152 $prop = $cal->getProperties(array("id", DAV_DISPLAYNAME, DAV_CALENDARCOLOR));
153 $out .= "<option value='" . $prop["id"] . "' ";
154 if ($prop["id"] == $calendar_id) {
156 $cal_col = $prop[DAV_CALENDARCOLOR];
158 } elseif (!$found) $cal_col = $prop[DAV_CALENDARCOLOR];
159 $out .= ">" . escape_tags($prop[DAV_DISPLAYNAME]) . "</option>\n";
163 $out .= " <label class='plain'><input type='checkbox' name='color_override' id='color_override' ";
164 if (!is_null($event["Color"])) $out .= "checked";
165 $out .= "> " . L10n::t("Special color") . ":</label>";
166 $out .= "<span id='cal_color_holder' ";
167 if (is_null($event["Color"])) $out .= "style='display: none;'";
168 $out .= "><input name='color' id='cal_color' value='" . (is_null($event["Color"]) ? "#" . $cal_col : escape_tags($event["Color"])) . "'></span>";
171 $out .= "<label class='block' for='cal_summary'>" . L10n::t("Subject") . ":</label>
172 <input name='summary' id='cal_summary' value=\"" . escape_tags($event["Summary"]) . "\"><br>\n";
173 $out .= "<label class='block' for='cal_allday'>Is All-Day event:</label><input type='checkbox' name='allday' id='cal_allday' " . ($event["IsAllDayEvent"] ? "checked" : "") . "><br>\n";
175 $out .= "<label class='block' for='cal_start_date'>" . L10n::t("Starts") . ":</label>";
176 $out .= "<input name='start_date' value='" . $localization->dateformat_datepicker_php($event["StartTime"]) . "' id='cal_start_date'>";
177 $out .= "<input name='start_time' value='" . date("H:i", $event["StartTime"]) . "' id='cal_start_time'>";
180 $out .= "<label class='block' for='cal_end_date'>" . L10n::t("Ends") . ":</label>";
181 $out .= "<input name='end_date' value='" . $localization->dateformat_datepicker_php($event["EndTime"]) . "' id='cal_end_date'>";
182 $out .= "<input name='end_time' value='" . date("H:i", $event["EndTime"]) . "' id='cal_end_time'>";
185 $out .= "<label class='block' for='cal_location'>" . L10n::t("Location") . ":</label><input name='location' id='cal_location' value=\"" . escape_tags($event["Location"]) . "\"><br>\n";
187 $out .= "<label class='block' for='event-desc-textarea'>" . L10n::t("Description") . ":</label> <textarea id='event-desc-textarea' name='wdcal_desc' style='vertical-align: top; width: 400px; height: 100px;'>" . escape_tags($event["Description"]) . "</textarea>";
188 $out .= "<br style='clear: both;'>";
190 $out .= "<h2>" . L10n::t("Recurrence") . "</h2>";
192 $out .= "<label class='block' for='rec_frequency'>" . L10n::t("Frequency") . ":</label> <select id='rec_frequency' name='rec_frequency' size='1'>";
193 $out .= "<option value=''>" . L10n::t("None") . "</option>\n";
194 $out .= "<option value='daily' ";
195 if ($recurrence && $recurrence->frequency == "daily") $out .= "selected";
196 $out .= ">" . L10n::t("Daily") . "</option>\n";
197 $out .= "<option value='weekly' ";
198 if ($recurrence && $recurrence->frequency == "weekly") $out .= "selected";
199 $out .= ">" . L10n::t("Weekly") . "</option>\n";
200 $out .= "<option value='monthly' ";
201 if ($recurrence && $recurrence->frequency == "monthly") $out .= "selected";
202 $out .= ">" . L10n::t("Monthly") . "</option>\n";
203 $out .= "<option value='yearly' ";
204 if ($recurrence && $recurrence->frequency == "yearly") $out .= "selected";
205 $out .= ">" . L10n::t("Yearly") . "</option>\n";
206 $out .= "</select><br>\n";
207 $out .= "<div id='rec_details'>";
209 $select = "<select id='rec_interval' name='rec_interval' size='1'>";
210 for ($i = 1; $i < 50; $i++) {
211 $select .= "<option value='$i' ";
212 if ($recurrence && $i == $recurrence->interval) $select .= "selected";
213 $select .= ">$i</option>\n";
215 $select .= "</select>";
216 $time = "<span class='rec_daily'>" . L10n::t("days") . "</span>";
217 $time .= "<span class='rec_weekly'>" . L10n::t("weeks") . "</span>";
218 $time .= "<span class='rec_monthly'>" . L10n::t("months") . "</span>";
219 $time .= "<span class='rec_yearly'>" . L10n::t("years") . "</span>";
220 $out .= "<label class='block'>" . L10n::t("Interval") . ":</label> " . str_replace(array("%select%", "%time%"), array($select, $time), L10n::t("All %select% %time%")) . "<br>";
223 $out .= "<div class='rec_daily'>";
224 $out .= "<label class='block'>" . L10n::t("Days") . ":</label>";
225 if ($recurrence && $recurrence->byDay) {
226 $byday = $recurrence->byDay;
228 $byday = array("MO", "TU", "WE", "TH", "FR", "SA", "SU");
230 if ($localization->getFirstDayOfWeek() == 0) {
231 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='SU' ";
232 if (in_array("SU", $byday)) $out .= "checked";
233 $out .= ">" . L10n::t("Sunday") . "</label> ";
235 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='MO' ";
236 if (in_array("MO", $byday)) $out .= "checked";
237 $out .= ">" . L10n::t("Monday") . "</label> ";
238 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='TU' ";
239 if (in_array("TU", $byday)) $out .= "checked";
240 $out .= ">" . L10n::t("Tuesday") . "</label> ";
241 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='WE' ";
242 if (in_array("WE", $byday)) $out .= "checked";
243 $out .= ">" . L10n::t("Wednesday") . "</label> ";
244 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='TH' ";
245 if (in_array("TH", $byday)) $out .= "checked";
246 $out .= ">" . L10n::t("Thursday") . "</label> ";
247 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='FR' ";
248 if (in_array("FR", $byday)) $out .= "checked";
249 $out .= ">" . L10n::t("Friday") . "</label> ";
250 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='SA' ";
251 if (in_array("SA", $byday)) $out .= "checked";
252 $out .= ">" . L10n::t("Saturday") . "</label> ";
253 if ($localization->getFirstDayOfWeek() != 0) {
254 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='SU' ";
255 if (in_array("SU", $byday)) $out .= "checked";
256 $out .= ">" . L10n::t("Sunday") . "</label> ";
261 $out .= "<div class='rec_weekly'>";
262 $out .= "<label class='block'>" . L10n::t("Days") . ":</label>";
263 if ($recurrence && $recurrence->byDay) {
264 $byday = $recurrence->byDay;
266 $days = array("MO", "TU", "WE", "TH", "FR", "SA", "SU");
267 $byday = array($days[date("N", $event["StartTime"]) - 1]);
269 if ($localization->getFirstDayOfWeek() == 0) {
270 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='SU' ";
271 if (in_array("SU", $byday)) $out .= "checked";
272 $out .= ">" . L10n::t("Sunday") . "</label> ";
274 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='MO' ";
275 if (in_array("MO", $byday)) $out .= "checked";
276 $out .= ">" . L10n::t("Monday") . "</label> ";
277 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='TU' ";
278 if (in_array("TU", $byday)) $out .= "checked";
279 $out .= ">" . L10n::t("Tuesday") . "</label> ";
280 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='WE' ";
281 if (in_array("WE", $byday)) $out .= "checked";
282 $out .= ">" . L10n::t("Wednesday") . "</label> ";
283 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='TH' ";
284 if (in_array("TH", $byday)) $out .= "checked";
285 $out .= ">" . L10n::t("Thursday") . "</label> ";
286 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='FR' ";
287 if (in_array("FR", $byday)) $out .= "checked";
288 $out .= ">" . L10n::t("Friday") . "</label> ";
289 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='SA' ";
290 if (in_array("SA", $byday)) $out .= "checked";
291 $out .= ">" . L10n::t("Saturday") . "</label> ";
292 if ($localization->getFirstDayOfWeek() != 0) {
293 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='SU' ";
294 if (in_array("SU", $byday)) $out .= "checked";
295 $out .= ">" . L10n::t("Sunday") . "</label> ";
299 $out .= "<label class='block'>" . L10n::t("First day of week:") . "</label>";
300 if ($recurrence && $recurrence->weekStart != "") $wkst = $recurrence->weekStart;
302 if ($localization->getFirstDayOfWeek() == 0) $wkst = "SU";
305 $out .= "<label class='plain'><input type='radio' name='rec_weekly_wkst' value='SU' ";
306 if ($wkst == "SU") $out .= "checked";
307 $out .= ">" . L10n::t("Sunday") . "</label> ";
308 $out .= "<label class='plain'><input type='radio' name='rec_weekly_wkst' value='MO' ";
309 if ($wkst == "MO") $out .= "checked";
310 $out .= ">" . L10n::t("Monday") . "</label><br>\n";
315 if ($recurrence && ($recurrence->frequency == "monthly" || $recurrence->frequency == "yearly")) {
316 if (is_null($recurrence->byDay) && !is_null($recurrence->byMonthDay) && count($recurrence->byMonthDay) == 1) {
317 $day = date("j", $event["StartTime"]);
318 if ($recurrence->byMonthDay[0] == $day) $monthly_rule = "bymonthday";
320 $lastday = date("t", $event["StartTime"]);
321 if ($recurrence->byMonthDay[0] == -1 * ($lastday - $day + 1)) $monthly_rule = "bymonthday_neg";
324 if (is_null($recurrence->byMonthDay) && !is_null($recurrence->byDay) && count($recurrence->byDay) == 1) {
325 $num = IntVal($recurrence->byDay[0]);
338 $weekday = $dayMap[$recurrence->byDay[0]];
340 $weekday = $dayMap[substr($recurrence->byDay[0], strlen($num))];
343 echo $num . " - " . $weekday;
345 if ($num > 0) $monthly_rule = "byday";
346 if ($num < 0) $monthly_rule = "byday_neg";
348 if ($monthly_rule == "") notice("The recurrence of this event cannot be parsed");
351 $out .= "<div class='rec_monthly'>";
352 $out .= "<label class='block' for='rec_monthly_day'>" . L10n::t("Day of month") . ":</label>";
353 $out .= "<select id='rec_monthly_day' name='rec_monthly_day' size='1'>";
354 $out .= "<option value='bymonthday' ";
355 if ($monthly_rule == "bymonthday") $out .= "selected";
356 $out .= ">" . L10n::t("#num#th of each month") . "</option>\n";
357 $out .= "<option value='bymonthday_neg' ";
358 if ($monthly_rule == "bymonthday_neg") $out .= "selected";
359 $out .= ">" . L10n::t("#num#th-last of each month") . "</option>\n";
360 $out .= "<option value='byday' ";
361 if ($monthly_rule == "byday") $out .= "selected";
362 $out .= ">" . L10n::t("#num#th #wkday# of each month") . "</option>\n";
363 $out .= "<option value='byday_neg' ";
364 if ($monthly_rule == "byday_neg") $out .= "selected";
365 $out .= ">" . L10n::t("#num#th-last #wkday# of each month") . "</option>\n";
369 if ($recurrence && $recurrence->frequency == "yearly") {
370 if (count($recurrence->byMonth) != 1 || $recurrence->byMonth[0] != date("n", $event["StartTime"])) notice("The recurrence of this event cannot be parsed!");
373 $out .= "<div class='rec_yearly'>";
374 $out .= "<label class='block'>" . L10n::t("Month") . ":</label> <span class='rec_month_name'>#month#</span><br>\n";
375 $out .= "<label class='block' for='rec_yearly_day'>" . L10n::t("Day of month") . ":</label>";
376 $out .= "<select id='rec_yearly_day' name='rec_yearly_day' size='1'>";
377 $out .= "<option value='bymonthday' ";
378 if ($monthly_rule == "bymonthday") $out .= "selected";
379 $out .= ">" . L10n::t("#num#th of the given month") . "</option>\n";
380 $out .= "<option value='bymonthday_neg' ";
381 if ($monthly_rule == "bymonthday_neg") $out .= "selected";
382 $out .= ">" . L10n::t("#num#th-last of the given month") . "</option>\n";
383 $out .= "<option value='byday' ";
384 if ($monthly_rule == "byday") $out .= "selected";
385 $out .= ">" . L10n::t("#num#th #wkday# of the given month") . "</option>\n";
386 $out .= "<option value='byday_neg' ";
387 if ($monthly_rule == "byday_neg") $out .= "selected";
388 $out .= ">" . L10n::t("#num#th-last #wkday# of the given month") . "</option>\n";
394 $until = $recurrence->until;
395 $count = $recurrence->count;
396 if (is_a($until, "DateTime")) {
397 /** @var DateTime $until */
399 $rule_until_date = $until->getTimestamp();
400 $rule_until_count = 1;
401 } elseif ($count > 0) {
402 $rule_type = "count";
403 $rule_until_date = time();
404 $rule_until_count = $count;
406 $rule_type = "infinite";
407 $rule_until_date = time();
408 $rule_until_count = 1;
411 $rule_type = "infinite";
412 $rule_until_date = time();
413 $rule_until_count = 1;
415 $out .= "<label class='block' for='rec_until_type'>" . L10n::t("Repeat until") . ":</label> ";
416 $out .= "<select name='rec_until_type' id='rec_until_type' size='1'>";
417 $out .= "<option value='infinite' ";
418 if ($rule_type == "infinite") $out .= "selected";
419 $out .= ">" . L10n::t("Infinite") . "</option>\n";
420 $out .= "<option value='date' ";
421 if ($rule_type == "date") $out .= "selected";
422 $out .= ">" . L10n::t("Until the following date") . ":</option>\n";
423 $out .= "<option value='count' ";
424 if ($rule_type == "count") $out .= "selected";
425 $out .= ">" . L10n::t("Number of times") . ":</option>\n";
428 $out .= "<input name='rec_until_date' value='" . $localization->dateformat_datepicker_php($rule_until_date) . "' id='rec_until_date'>";
429 $out .= "<input name='rec_until_count' value='$rule_until_count' id='rec_until_count'><br>";
431 $out .= "<label class='block'>" . L10n::t("Exceptions") . ":</label><div class='rec_exceptions'>";
432 $out .= "<div class='rec_exceptions_none' ";
433 if (count($recurrentce_exdates) > 0) $out .= "style='display: none;'";
434 $out .= ">" . L10n::t("none") . "</div>";
435 $out .= "<div class='rec_exceptions_holder' ";
436 if (count($recurrentce_exdates) == 0) $out .= "style='display: none;'";
439 foreach ($recurrentce_exdates as $exdate) {
440 $out .= "<div data-timestamp='$exdate' class='except'><input type='hidden' class='rec_exception' name='rec_exceptions[]' value='$exdate'>";
441 $out .= "<a href='#' class='exception_remover'>[remove]</a> ";
442 $out .= $localization->date_timestamp2localDate($exdate);
445 $out .= "</div><div><a href='#' class='exception_adder'>[add]</a></div>";
449 $out .= "</div><br>";
451 $out .= "<h2>" . L10n::t("Notification") . "</h2>";
453 if (!$notifications) $notifications = array();
454 $notifications["new"] = array(
456 "trigger_value" => 60,
457 "trigger_unit" => "minute",
461 foreach ($notifications as $index => $noti) {
464 if (!in_array($noti["action"], array("email", "display"))) $unparsable = true;
466 $out .= "<div class='noti_holder' ";
467 if (!is_numeric($index) && $index == "new") $out .= "style='display: none;' id='noti_new_row'";
468 $out .= "><label class='block' for='noti_type_" . $index . "'>" . L10n::t("Notify by") . ":</label>";
469 $out .= "<select name='noti_type[$index]' size='1' id='noti_type_" . $index . "'>";
470 $out .= "<option value=''>- " . L10n::t("Remove") . " -</option>\n";
471 $out .= "<option value='email' "; if (!$unparsable && $noti["action"] == "email") $out .= "selected"; $out .= ">" . L10n::t("E-Mail") . "</option>\n";
472 $out .= "<option value='display' "; if (!$unparsable && $noti["action"] == "display") $out .= "selected"; $out .= ">" . L10n::t("On Friendica / Display") . "</option>\n";
473 //$out .= "<option value='other' "; if ($unparsable) $out .= "selected"; $out .= ">- " . L10n::t("other (leave it untouched)") . " -</option>\n"; // @TODO
474 $out .= "</select><br>";
476 $out .= "<label class='block'>" . L10n::t("Time") . ":</label>";
477 $out .= "<input name='noti_value[$index]' size='5' style='width: 5em;' value='" . $noti["trigger_value"] . "'>";
479 $out .= "<select name='noti_unit[$index]' size='1'>";
480 $out .= "<option value='H' "; if ($noti["trigger_unit"] == "hour") $out .= "selected"; $out .= ">" . L10n::t("Hours") . "</option>\n";
481 $out .= "<option value='M' "; if ($noti["trigger_unit"] == "minute") $out .= "selected"; $out .= ">" . L10n::t("Minutes") . "</option>\n";
482 $out .= "<option value='S' "; if ($noti["trigger_unit"] == "second") $out .= "selected"; $out .= ">" . L10n::t("Seconds") . "</option>\n";
483 $out .= "<option value='D' "; if ($noti["trigger_unit"] == "day") $out .= "selected"; $out .= ">" . L10n::t("Days") . "</option>\n";
484 $out .= "<option value='W' "; if ($noti["trigger_unit"] == "week") $out .= "selected"; $out .= ">" . L10n::t("Weeks") . "</option>\n";
487 $out .= " <label class='plain'>" . L10n::t("before the") . " <select name='noti_ref[$index]' size='1'>";
488 $out .= "<option value='start' "; if ($noti["rel"] == "start") $out .= "selected"; $out .= ">" . L10n::t("start of the event") . "</option>\n";
489 $out .= "<option value='end' "; if ($noti["rel"] == "end") $out .= "selected"; $out .= ">" . L10n::t("end of the event") . "</option>\n";
490 $out .= "</select></label>\n";
494 $out .= "<input type='hidden' name='new_alarm' id='new_alarm' value='0'><div id='new_alarm_adder'><a href='#'>" . L10n::t("Add a notification") . "</a></div>";
496 $out .= "<script>\$(function() {
497 wdcal_edit_init('" . $localization->dateformat_datepicker_js() . "', '${baseurl}/dav/');
500 $out .= "<br><input type='submit' name='save' value='Save'></form>";
507 * @param Sabre_VObject_Component_VEvent $component
508 * @param wdcal_local $localization
511 function wdcal_set_component_date(&$component, &$localization)
513 if (isset($_REQUEST["allday"])) {
514 $ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " 00:00");
515 $ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " 00:00");
516 $type = Sabre\VObject\Property\DateTime::DATE;
518 $ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " " . $_REQUEST["start_time"]);
519 $ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " " . $_REQUEST["end_time"]);
520 $type = Sabre\VObject\Property\DateTime::LOCALTZ;
522 $datetime_start = new Sabre\VObject\Property\DateTime("DTSTART");
523 $datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_start)), $type);
524 $datetime_end = new Sabre\VObject\Property\DateTime("DTEND");
525 $datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_end)), $type);
527 $component->__unset("DTSTART");
528 $component->__unset("DTEND");
529 $component->add($datetime_start);
530 $component->add($datetime_end);
536 * @param Sabre_VObject_Component_VEvent $component
541 function wdcal_set_component_recurrence_special(&$component, $str) {
544 /** @var Sabre\VObject\Property\DateTime $start */
545 $start = $component->__get("DTSTART");
558 $day = $start->getDateTime()->format("j");
559 $ret = ";BYMONTHDAY=" . $day;
561 case "bymonthday_neg":
562 $day = $start->getDateTime()->format("j");
563 $day_max = $start->getDateTime()->format("t");
564 $ret = ";BYMONTHDAY=" . (-1 * ($day_max - $day + 1));
567 $day = $start->getDateTime()->format("j");
568 $weekday = $dayMap[$start->getDateTime()->format("w")];
569 $num = IntVal(ceil($day / 7));
570 $ret = ";BYDAY=${num}${weekday}";
573 $day = $start->getDateTime()->format("j");
574 $weekday = $dayMap[$start->getDateTime()->format("w")];
575 $day_max = $start->getDateTime()->format("t");
576 $day_last = ($day_max - $day + 1);
577 $num = IntVal(ceil($day_last / 7));
578 $ret = ";BYDAY=-${num}${weekday}";
585 * @param Sabre_VObject_Component_VEvent $component
586 * @param wdcal_local $localization
588 function wdcal_set_component_recurrence(&$component, &$localization)
590 $component->__unset("RRULE");
591 $component->__unset("EXRULE");
592 $component->__unset("EXDATE");
593 $component->__unset("RDATE");
596 switch ($_REQUEST["rec_until_type"]) {
598 $date = $localization->date_local2timestamp($_REQUEST["rec_until_date"]);
599 $part_until = ";UNTIL=" . date("Ymd", $date);
600 $datetime_until = new Sabre\VObject\Property\DateTime("UNTIL");
601 $datetime_until->setDateTime(new DateTime(date("Y-m-d H:i:s", $date)), Sabre\VObject\Property\DateTime::DATE);
604 $part_until = ";COUNT=" . IntVal($_REQUEST["rec_until_count"]);
608 switch ($_REQUEST["rec_frequency"]) {
610 $part_freq = "FREQ=DAILY";
611 if (isset($_REQUEST["rec_daily_byday"])) {
613 foreach ($_REQUEST["rec_daily_byday"] as $x) if (in_array($x, array("MO", "TU", "WE", "TH", "FR", "SA", "SU"))) $days[] = $x;
614 if (count($days) > 0) $part_freq .= ";BYDAY=" . implode(",", $days);
618 $part_freq = "FREQ=WEEKLY";
619 if (isset($_REQUEST["rec_weekly_wkst"]) && in_array($_REQUEST["rec_weekly_wkst"], array("MO", "SU"))) $part_freq .= ";WKST=" . $_REQUEST["rec_weekly_wkst"];
620 if (isset($_REQUEST["rec_weekly_byday"])) {
622 foreach ($_REQUEST["rec_weekly_byday"] as $x) if (in_array($x, array("MO", "TU", "WE", "TH", "FR", "SA", "SU"))) $days[] = $x;
623 if (count($days) > 0) $part_freq .= ";BYDAY=" . implode(",", $days);
627 $part_freq = "FREQ=MONTHLY";
628 $part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_monthly_day"]);
631 /** @var Sabre\VObject\Property\DateTime $start */
632 $start = $component->__get("DTSTART");
633 $part_freq = "FREQ=YEARLY";
634 $part_freq .= ";BYMONTH=" . $start->getDateTime()->format("n");
635 $part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_yearly_day"]);
641 if ($part_freq == "") return;
643 if (isset($_REQUEST["rec_interval"])) $part_freq .= ";INTERVAL=" . InTVal($_REQUEST["rec_interval"]);
645 if (isset($_REQUEST["rec_exceptions"])) {
647 foreach ($_REQUEST["rec_exceptions"] as $except) {
648 $arr[] = new DateTime(date("Y-m-d H:i:s", $except));
650 /** @var Sabre\VObject\Property\MultiDateTime $prop */
651 $prop = Sabre\VObject\Property::create("EXDATE");
652 $prop->setDateTimes($arr);
653 $component->add($prop);
656 $rrule = $part_freq . $part_until;
657 $component->add(new Sabre\VObject\Property("RRULE", $rrule));
663 * @param Sabre\VObject\Component\VEvent $component
664 * @param wdcal_local $localization
665 * @param string $summary
666 * @param int $dtstart
668 function wdcal_set_component_alerts(&$component, &$localization, $summary, $dtstart)
672 $prev_alarms = $component->select("VALARM");
673 $component->__unset("VALARM");
675 foreach ($prev_alarms as $al) {
676 /** @var Sabre\VObject\Component\VAlarm $al */
677 // @TODO Parse notifications that have been there before; e.g. from Lightning
680 foreach (array_keys($_REQUEST["noti_type"]) as $key) if (is_numeric($key) || ($key == "new" && $_REQUEST["new_alarm"] == 1)) {
681 $alarm = new Sabre\VObject\Component\VAlarm("VALARM");
683 switch ($_REQUEST["noti_type"][$key]) {
685 $mailtext = str_replace(array(
688 $localization->date_timestamp2local($dtstart), $summary,
689 ), L10n::t("The event #name# will start at #date"));
691 $alarm->add(new Sabre\VObject\Property("ACTION", "EMAIL"));
692 $alarm->add(new Sabre\VObject\Property("SUMMARY", $summary));
693 $alarm->add(new Sabre\VObject\Property("DESCRIPTION", $mailtext));
694 $alarm->add(new Sabre\VObject\Property("ATTENDEE", "MAILTO:" . $a->user["email"]));
697 $alarm->add(new Sabre\VObject\Property("ACTION", "DISPLAY"));
698 $text = str_replace("#name#", $summary, L10n::t("#name# is about to begin."));
699 $alarm->add(new Sabre\VObject\Property("DESCRIPTION", $text));
705 $trigger_name = "TRIGGER";
706 $trigger_val = ""; // @TODO Bugfix : und ; sind evtl. vertauscht vgl. http://www.kanzaki.com/docs/ical/trigger.html
707 if ($_REQUEST["noti_ref"][$key] == "end") $trigger_name .= ";RELATED=END";
708 $trigger_val .= "-P";
709 if (in_array($_REQUEST["noti_unit"][$key], array("H", "M", "S"))) $trigger_val .= "T";
710 $trigger_val .= IntVal($_REQUEST["noti_value"][$key]) . $_REQUEST["noti_unit"][$key];
711 $alarm->add(new Sabre\VObject\Property($trigger_name, $trigger_val));
713 $component->add($alarm);
721 * @param string $timezone
722 * @param string $goaway_url
725 function wdcal_postEditPage($uri, $uid = 0, $timezone = "", $goaway_url = "")
728 $localization = wdcal_local::getInstanceByUser($uid);
730 $server = dav_create_server(true, true, false);
733 $calendar = dav_get_current_user_calendar_by_id($server, $_REQUEST["calendar"], DAV_ACL_READ);
734 $obj_uri = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($uri);
735 $obj_uri = $obj_uri["uri"];
737 $vObject = dav_get_current_user_calendarobject($server, $calendar, $obj_uri, DAV_ACL_WRITE);
738 $component = dav_get_eventComponent($vObject);
740 if ($component == null) return array("ok" => false, "msg" => L10n::t('Could not open component for editing'));
742 $calendar = dav_get_current_user_calendar_by_id($server, $_REQUEST["calendar"], DAV_ACL_WRITE);
743 $vObject = dav_create_empty_vevent();
744 $component = dav_get_eventComponent($vObject);
745 $obj_uri = $component->__get("UID");
748 $ts_start = wdcal_set_component_date($component, $localization);
749 wdcal_set_component_recurrence($component, $localization);
750 wdcal_set_component_alerts($component, $localization, icalendar_sanitize_string(dav_compat_parse_text_serverside("summary")), $ts_start);
752 $component->__unset("LOCATION");
753 $component->__unset("SUMMARY");
754 $component->__unset("DESCRIPTION");
755 $component->__unset("X-ANIMEXX-COLOR");
756 $component->add("SUMMARY", icalendar_sanitize_string(dav_compat_parse_text_serverside("summary")));
757 $component->add("LOCATION", icalendar_sanitize_string(dav_compat_parse_text_serverside("location")));
758 $component->add("DESCRIPTION", icalendar_sanitize_string(dav_compat_parse_text_serverside("wdcal_desc")));
759 if (isset($_REQUEST["color_override"])) {
760 $component->add("X-ANIMEXX-COLOR", $_REQUEST["color"]);
763 $data = $vObject->serialize();
766 $calendar->createFile($obj_uri . ".ics", $data);
768 $obj = $calendar->getChild($obj_uri);
771 return array("ok" => false, "msg" => L10n::t("Saved"));
778 function wdcal_getEditPage_exception_selector()
780 header("Content-type: application/json");
783 $localization = wdcal_local::getInstanceByUser($a->user["uid"]);
785 $vObject = dav_create_empty_vevent();
787 foreach ($vObject->getComponents() as $component) {
788 if ($component->name !== 'VTIMEZONE') break;
790 /** @var Sabre\VObject\Component\VEvent $component */
791 wdcal_set_component_date($component, $localization);
792 wdcal_set_component_recurrence($component, $localization);
795 $it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID"));
796 $max_ts = mktime(0, 0, 0, 1, 1, CALDAV_MAX_YEAR + 1);
802 while ($it->valid() && $last_start < $max_ts && $i++ < 1000) {
803 $last_start = $it->getDtStart()->getTimestamp();
804 $o .= "<li><a href='#' class='exception_selector_link' data-timestamp='$last_start'>" . $localization->date_timestamp2localDate($last_start) . "</a></li>\n";