3 use Friendica\Core\L10n;
4 use Friendica\Util\DateTimeFormat;
7 * @param wdcal_local $localization
8 * @param string $baseurl
9 * @param int $calendar_id
13 function wdcal_getEditPage_str(&$localization, $baseurl, $calendar_id, $uri)
15 $server = dav_create_server(true, true, false);
18 $calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
20 $calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_READ);
23 $calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
26 if ($calendar == null) return "Calendar not found";
28 $obj_uri = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($uri);
30 $vObject = dav_get_current_user_calendarobject($server, $calendar, $obj_uri["uri"], DAV_ACL_WRITE);
31 $component = dav_get_eventComponent($vObject);
33 if ($component == null) return L10n::t('Could not open component for editing');
35 /** @var Sabre\VObject\Property\DateTime $dtstart */
36 $dtstart = $component->__get("DTSTART");
39 "Summary" => ($component->__get("SUMMARY") ? $component->__get("SUMMARY")->value : null),
40 "StartTime" => $dtstart->getDateTime()->getTimeStamp(),
41 "EndTime" => Sabre_CalDAV_Backend_Common::getDtEndTimeStamp($component),
42 "IsAllDayEvent" => (strlen($dtstart->value) == 8),
43 "Description" => ($component->__get("DESCRIPTION") ? $component->__get("DESCRIPTION")->value : null),
44 "Location" => ($component->__get("LOCATION") ? $component->__get("LOCATION")->value : null),
45 "Color" => ($component->__get("X-ANIMEXX-COLOR") ? $component->__get("X-ANIMEXX-COLOR")->value : null),
48 $exdates = $component->select("EXDATE");
49 $recurrentce_exdates = array();
50 /** @var Sabre\VObject\Property\MultiDateTime $x */
51 foreach ($exdates as $x) {
52 /** @var DateTime $y */
53 $z = $x->getDateTimes();
54 foreach ($z as $y) $recurrentce_exdates[] = $y->getTimeStamp();
57 $notifications = array();
58 $alarms = $component->select("VALARM");
59 foreach ($alarms as $alarm) {
60 /** @var Sabre_VObject_Component_VAlarm $alarm */
61 $action = $alarm->__get("ACTION")->value;
62 $trigger = $alarm->__get("TRIGGER");
64 if(isset($trigger['VALUE']) && strtoupper($trigger['VALUE']) !== 'DURATION') {
65 notice("The notification of this event cannot be parsed");
69 /** @var DateInterval $triggerDuration */
70 $triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($trigger);
73 if ($triggerDuration->s > 0) {
75 $value = $triggerDuration->s + $triggerDuration->i * 60 + $triggerDuration->h * 3600 + $triggerDuration->d * 3600 * 24; // @TODO support more than days?
76 } elseif ($triggerDuration->i) {
78 $value = $triggerDuration->i + $triggerDuration->h * 60 + $triggerDuration->d * 60 * 24;
79 } elseif ($triggerDuration->h) {
81 $value = $triggerDuration->h + $triggerDuration->d * 24;
82 } elseif ($triggerDuration->d > 0) {
84 $value = $triggerDuration->d;
87 $rel = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'end' : 'start';
90 $notifications[] = array(
91 "action" => strtolower($action),
93 "trigger_unit" => $unit,
94 "trigger_value" => $value,
98 if ($component->select("RRULE")) $recurrence = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
99 else $recurrence = null;
101 } elseif (isset($_REQUEST["start"]) && $_REQUEST["start"] > 0) {
102 $calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
103 //$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
107 "Summary" => $_REQUEST["title"],
108 "StartTime" => InTVal($_REQUEST["start"]),
109 "EndTime" => IntVal($_REQUEST["end"]),
110 "IsAllDayEvent" => $_REQUEST["isallday"],
115 if ($_REQUEST["isallday"]) {
116 $notifications = array();
118 $notifications = array(array("action" => "email", "rel" => "start", "trigger_unit" => "hour", "trigger_value" => 1));
121 $recurrentce_exdates = array();
123 $calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
124 //$calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
129 "StartTime" => time(),
130 "EndTime" => time() + 3600,
131 "IsAllDayEvent" => "0",
136 $notifications = array(array("action" => "email", "rel" => "start", "trigger_unit" => "hour", "trigger_value" => 1));
138 $recurrentce_exdates = array();
141 $postto = $baseurl . "/dav/wdcal/" . ($uri == 0 ? "new/" : $calendar_id . "/" . $uri . "/edit/");
143 $out = "<a href='" . $baseurl . "/dav/wdcal/'>" . L10n::t("Go back to the calendar") . "</a><br><br>";
144 $out .= "<form method='POST' action='$postto'>
145 <input type='hidden' name='form_security_token' value='" . get_form_security_token('caledit') . "'>\n";
147 $out .= "<h2>" . L10n::t("Event data") . "</h2>";
149 $out .= "<label for='calendar' class='block'>" . L10n::t("Calendar") . ":</label><select id='calendar' name='calendar' size='1'>";
152 foreach ($calendars as $cal) {
153 $prop = $cal->getProperties(array("id", DAV_DISPLAYNAME, DAV_CALENDARCOLOR));
154 $out .= "<option value='" . $prop["id"] . "' ";
155 if ($prop["id"] == $calendar_id) {
157 $cal_col = $prop[DAV_CALENDARCOLOR];
159 } elseif (!$found) $cal_col = $prop[DAV_CALENDARCOLOR];
160 $out .= ">" . escape_tags($prop[DAV_DISPLAYNAME]) . "</option>\n";
164 $out .= " <label class='plain'><input type='checkbox' name='color_override' id='color_override' ";
165 if (!is_null($event["Color"])) $out .= "checked";
166 $out .= "> " . L10n::t("Special color") . ":</label>";
167 $out .= "<span id='cal_color_holder' ";
168 if (is_null($event["Color"])) $out .= "style='display: none;'";
169 $out .= "><input name='color' id='cal_color' value='" . (is_null($event["Color"]) ? "#" . $cal_col : escape_tags($event["Color"])) . "'></span>";
172 $out .= "<label class='block' for='cal_summary'>" . L10n::t("Subject") . ":</label>
173 <input name='summary' id='cal_summary' value=\"" . escape_tags($event["Summary"]) . "\"><br>\n";
174 $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";
176 $out .= "<label class='block' for='cal_start_date'>" . L10n::t("Starts") . ":</label>";
177 $out .= "<input name='start_date' value='" . $localization->dateformat_datepicker_php($event["StartTime"]) . "' id='cal_start_date'>";
178 $out .= "<input name='start_time' value='" . date("H:i", $event["StartTime"]) . "' id='cal_start_time'>";
181 $out .= "<label class='block' for='cal_end_date'>" . L10n::t("Ends") . ":</label>";
182 $out .= "<input name='end_date' value='" . $localization->dateformat_datepicker_php($event["EndTime"]) . "' id='cal_end_date'>";
183 $out .= "<input name='end_time' value='" . date("H:i", $event["EndTime"]) . "' id='cal_end_time'>";
186 $out .= "<label class='block' for='cal_location'>" . L10n::t("Location") . ":</label><input name='location' id='cal_location' value=\"" . escape_tags($event["Location"]) . "\"><br>\n";
188 $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>";
189 $out .= "<br style='clear: both;'>";
191 $out .= "<h2>" . L10n::t("Recurrence") . "</h2>";
193 $out .= "<label class='block' for='rec_frequency'>" . L10n::t("Frequency") . ":</label> <select id='rec_frequency' name='rec_frequency' size='1'>";
194 $out .= "<option value=''>" . L10n::t("None") . "</option>\n";
195 $out .= "<option value='daily' ";
196 if ($recurrence && $recurrence->frequency == "daily") $out .= "selected";
197 $out .= ">" . L10n::t("Daily") . "</option>\n";
198 $out .= "<option value='weekly' ";
199 if ($recurrence && $recurrence->frequency == "weekly") $out .= "selected";
200 $out .= ">" . L10n::t("Weekly") . "</option>\n";
201 $out .= "<option value='monthly' ";
202 if ($recurrence && $recurrence->frequency == "monthly") $out .= "selected";
203 $out .= ">" . L10n::t("Monthly") . "</option>\n";
204 $out .= "<option value='yearly' ";
205 if ($recurrence && $recurrence->frequency == "yearly") $out .= "selected";
206 $out .= ">" . L10n::t("Yearly") . "</option>\n";
207 $out .= "</select><br>\n";
208 $out .= "<div id='rec_details'>";
210 $select = "<select id='rec_interval' name='rec_interval' size='1'>";
211 for ($i = 1; $i < 50; $i++) {
212 $select .= "<option value='$i' ";
213 if ($recurrence && $i == $recurrence->interval) $select .= "selected";
214 $select .= ">$i</option>\n";
216 $select .= "</select>";
217 $time = "<span class='rec_daily'>" . L10n::t("days") . "</span>";
218 $time .= "<span class='rec_weekly'>" . L10n::t("weeks") . "</span>";
219 $time .= "<span class='rec_monthly'>" . L10n::t("months") . "</span>";
220 $time .= "<span class='rec_yearly'>" . L10n::t("years") . "</span>";
221 $out .= "<label class='block'>" . L10n::t("Interval") . ":</label> " . str_replace(array("%select%", "%time%"), array($select, $time), L10n::t("All %select% %time%")) . "<br>";
224 $out .= "<div class='rec_daily'>";
225 $out .= "<label class='block'>" . L10n::t("Days") . ":</label>";
226 if ($recurrence && $recurrence->byDay) {
227 $byday = $recurrence->byDay;
229 $byday = array("MO", "TU", "WE", "TH", "FR", "SA", "SU");
231 if ($localization->getFirstDayOfWeek() == 0) {
232 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='SU' ";
233 if (in_array("SU", $byday)) $out .= "checked";
234 $out .= ">" . L10n::t("Sunday") . "</label> ";
236 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='MO' ";
237 if (in_array("MO", $byday)) $out .= "checked";
238 $out .= ">" . L10n::t("Monday") . "</label> ";
239 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='TU' ";
240 if (in_array("TU", $byday)) $out .= "checked";
241 $out .= ">" . L10n::t("Tuesday") . "</label> ";
242 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='WE' ";
243 if (in_array("WE", $byday)) $out .= "checked";
244 $out .= ">" . L10n::t("Wednesday") . "</label> ";
245 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='TH' ";
246 if (in_array("TH", $byday)) $out .= "checked";
247 $out .= ">" . L10n::t("Thursday") . "</label> ";
248 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='FR' ";
249 if (in_array("FR", $byday)) $out .= "checked";
250 $out .= ">" . L10n::t("Friday") . "</label> ";
251 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='SA' ";
252 if (in_array("SA", $byday)) $out .= "checked";
253 $out .= ">" . L10n::t("Saturday") . "</label> ";
254 if ($localization->getFirstDayOfWeek() != 0) {
255 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='SU' ";
256 if (in_array("SU", $byday)) $out .= "checked";
257 $out .= ">" . L10n::t("Sunday") . "</label> ";
262 $out .= "<div class='rec_weekly'>";
263 $out .= "<label class='block'>" . L10n::t("Days") . ":</label>";
264 if ($recurrence && $recurrence->byDay) {
265 $byday = $recurrence->byDay;
267 $days = array("MO", "TU", "WE", "TH", "FR", "SA", "SU");
268 $byday = array($days[date("N", $event["StartTime"]) - 1]);
270 if ($localization->getFirstDayOfWeek() == 0) {
271 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='SU' ";
272 if (in_array("SU", $byday)) $out .= "checked";
273 $out .= ">" . L10n::t("Sunday") . "</label> ";
275 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='MO' ";
276 if (in_array("MO", $byday)) $out .= "checked";
277 $out .= ">" . L10n::t("Monday") . "</label> ";
278 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='TU' ";
279 if (in_array("TU", $byday)) $out .= "checked";
280 $out .= ">" . L10n::t("Tuesday") . "</label> ";
281 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='WE' ";
282 if (in_array("WE", $byday)) $out .= "checked";
283 $out .= ">" . L10n::t("Wednesday") . "</label> ";
284 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='TH' ";
285 if (in_array("TH", $byday)) $out .= "checked";
286 $out .= ">" . L10n::t("Thursday") . "</label> ";
287 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='FR' ";
288 if (in_array("FR", $byday)) $out .= "checked";
289 $out .= ">" . L10n::t("Friday") . "</label> ";
290 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='SA' ";
291 if (in_array("SA", $byday)) $out .= "checked";
292 $out .= ">" . L10n::t("Saturday") . "</label> ";
293 if ($localization->getFirstDayOfWeek() != 0) {
294 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='SU' ";
295 if (in_array("SU", $byday)) $out .= "checked";
296 $out .= ">" . L10n::t("Sunday") . "</label> ";
300 $out .= "<label class='block'>" . L10n::t("First day of week:") . "</label>";
301 if ($recurrence && $recurrence->weekStart != "") $wkst = $recurrence->weekStart;
303 if ($localization->getFirstDayOfWeek() == 0) $wkst = "SU";
306 $out .= "<label class='plain'><input type='radio' name='rec_weekly_wkst' value='SU' ";
307 if ($wkst == "SU") $out .= "checked";
308 $out .= ">" . L10n::t("Sunday") . "</label> ";
309 $out .= "<label class='plain'><input type='radio' name='rec_weekly_wkst' value='MO' ";
310 if ($wkst == "MO") $out .= "checked";
311 $out .= ">" . L10n::t("Monday") . "</label><br>\n";
316 if ($recurrence && ($recurrence->frequency == "monthly" || $recurrence->frequency == "yearly")) {
317 if (is_null($recurrence->byDay) && !is_null($recurrence->byMonthDay) && count($recurrence->byMonthDay) == 1) {
318 $day = date("j", $event["StartTime"]);
319 if ($recurrence->byMonthDay[0] == $day) $monthly_rule = "bymonthday";
321 $lastday = date("t", $event["StartTime"]);
322 if ($recurrence->byMonthDay[0] == -1 * ($lastday - $day + 1)) $monthly_rule = "bymonthday_neg";
325 if (is_null($recurrence->byMonthDay) && !is_null($recurrence->byDay) && count($recurrence->byDay) == 1) {
326 $num = IntVal($recurrence->byDay[0]);
339 $weekday = $dayMap[$recurrence->byDay[0]];
341 $weekday = $dayMap[substr($recurrence->byDay[0], strlen($num))];
344 echo $num . " - " . $weekday;
346 if ($num > 0) $monthly_rule = "byday";
347 if ($num < 0) $monthly_rule = "byday_neg";
349 if ($monthly_rule == "") notice("The recurrence of this event cannot be parsed");
352 $out .= "<div class='rec_monthly'>";
353 $out .= "<label class='block' for='rec_monthly_day'>" . L10n::t("Day of month") . ":</label>";
354 $out .= "<select id='rec_monthly_day' name='rec_monthly_day' size='1'>";
355 $out .= "<option value='bymonthday' ";
356 if ($monthly_rule == "bymonthday") $out .= "selected";
357 $out .= ">" . L10n::t("#num#th of each month") . "</option>\n";
358 $out .= "<option value='bymonthday_neg' ";
359 if ($monthly_rule == "bymonthday_neg") $out .= "selected";
360 $out .= ">" . L10n::t("#num#th-last of each month") . "</option>\n";
361 $out .= "<option value='byday' ";
362 if ($monthly_rule == "byday") $out .= "selected";
363 $out .= ">" . L10n::t("#num#th #wkday# of each month") . "</option>\n";
364 $out .= "<option value='byday_neg' ";
365 if ($monthly_rule == "byday_neg") $out .= "selected";
366 $out .= ">" . L10n::t("#num#th-last #wkday# of each month") . "</option>\n";
370 if ($recurrence && $recurrence->frequency == "yearly") {
371 if (count($recurrence->byMonth) != 1 || $recurrence->byMonth[0] != date("n", $event["StartTime"])) notice("The recurrence of this event cannot be parsed!");
374 $out .= "<div class='rec_yearly'>";
375 $out .= "<label class='block'>" . L10n::t("Month") . ":</label> <span class='rec_month_name'>#month#</span><br>\n";
376 $out .= "<label class='block' for='rec_yearly_day'>" . L10n::t("Day of month") . ":</label>";
377 $out .= "<select id='rec_yearly_day' name='rec_yearly_day' size='1'>";
378 $out .= "<option value='bymonthday' ";
379 if ($monthly_rule == "bymonthday") $out .= "selected";
380 $out .= ">" . L10n::t("#num#th of the given month") . "</option>\n";
381 $out .= "<option value='bymonthday_neg' ";
382 if ($monthly_rule == "bymonthday_neg") $out .= "selected";
383 $out .= ">" . L10n::t("#num#th-last of the given month") . "</option>\n";
384 $out .= "<option value='byday' ";
385 if ($monthly_rule == "byday") $out .= "selected";
386 $out .= ">" . L10n::t("#num#th #wkday# of the given month") . "</option>\n";
387 $out .= "<option value='byday_neg' ";
388 if ($monthly_rule == "byday_neg") $out .= "selected";
389 $out .= ">" . L10n::t("#num#th-last #wkday# of the given month") . "</option>\n";
395 $until = $recurrence->until;
396 $count = $recurrence->count;
397 if (is_a($until, "DateTime")) {
398 /** @var DateTime $until */
400 $rule_until_date = $until->getTimestamp();
401 $rule_until_count = 1;
402 } elseif ($count > 0) {
403 $rule_type = "count";
404 $rule_until_date = time();
405 $rule_until_count = $count;
407 $rule_type = "infinite";
408 $rule_until_date = time();
409 $rule_until_count = 1;
412 $rule_type = "infinite";
413 $rule_until_date = time();
414 $rule_until_count = 1;
416 $out .= "<label class='block' for='rec_until_type'>" . L10n::t("Repeat until") . ":</label> ";
417 $out .= "<select name='rec_until_type' id='rec_until_type' size='1'>";
418 $out .= "<option value='infinite' ";
419 if ($rule_type == "infinite") $out .= "selected";
420 $out .= ">" . L10n::t("Infinite") . "</option>\n";
421 $out .= "<option value='date' ";
422 if ($rule_type == "date") $out .= "selected";
423 $out .= ">" . L10n::t("Until the following date") . ":</option>\n";
424 $out .= "<option value='count' ";
425 if ($rule_type == "count") $out .= "selected";
426 $out .= ">" . L10n::t("Number of times") . ":</option>\n";
429 $out .= "<input name='rec_until_date' value='" . $localization->dateformat_datepicker_php($rule_until_date) . "' id='rec_until_date'>";
430 $out .= "<input name='rec_until_count' value='$rule_until_count' id='rec_until_count'><br>";
432 $out .= "<label class='block'>" . L10n::t("Exceptions") . ":</label><div class='rec_exceptions'>";
433 $out .= "<div class='rec_exceptions_none' ";
434 if (count($recurrentce_exdates) > 0) $out .= "style='display: none;'";
435 $out .= ">" . L10n::t("none") . "</div>";
436 $out .= "<div class='rec_exceptions_holder' ";
437 if (count($recurrentce_exdates) == 0) $out .= "style='display: none;'";
440 foreach ($recurrentce_exdates as $exdate) {
441 $out .= "<div data-timestamp='$exdate' class='except'><input type='hidden' class='rec_exception' name='rec_exceptions[]' value='$exdate'>";
442 $out .= "<a href='#' class='exception_remover'>[remove]</a> ";
443 $out .= $localization->date_timestamp2localDate($exdate);
446 $out .= "</div><div><a href='#' class='exception_adder'>[add]</a></div>";
450 $out .= "</div><br>";
452 $out .= "<h2>" . L10n::t("Notification") . "</h2>";
454 if (!$notifications) $notifications = array();
455 $notifications["new"] = array(
457 "trigger_value" => 60,
458 "trigger_unit" => "minute",
462 foreach ($notifications as $index => $noti) {
465 if (!in_array($noti["action"], array("email", "display"))) $unparsable = true;
467 $out .= "<div class='noti_holder' ";
468 if (!is_numeric($index) && $index == "new") $out .= "style='display: none;' id='noti_new_row'";
469 $out .= "><label class='block' for='noti_type_" . $index . "'>" . L10n::t("Notify by") . ":</label>";
470 $out .= "<select name='noti_type[$index]' size='1' id='noti_type_" . $index . "'>";
471 $out .= "<option value=''>- " . L10n::t("Remove") . " -</option>\n";
472 $out .= "<option value='email' "; if (!$unparsable && $noti["action"] == "email") $out .= "selected"; $out .= ">" . L10n::t("E-Mail") . "</option>\n";
473 $out .= "<option value='display' "; if (!$unparsable && $noti["action"] == "display") $out .= "selected"; $out .= ">" . L10n::t("On Friendica / Display") . "</option>\n";
474 //$out .= "<option value='other' "; if ($unparsable) $out .= "selected"; $out .= ">- " . L10n::t("other (leave it untouched)") . " -</option>\n"; // @TODO
475 $out .= "</select><br>";
477 $out .= "<label class='block'>" . L10n::t("Time") . ":</label>";
478 $out .= "<input name='noti_value[$index]' size='5' style='width: 5em;' value='" . $noti["trigger_value"] . "'>";
480 $out .= "<select name='noti_unit[$index]' size='1'>";
481 $out .= "<option value='H' "; if ($noti["trigger_unit"] == "hour") $out .= "selected"; $out .= ">" . L10n::t("Hours") . "</option>\n";
482 $out .= "<option value='M' "; if ($noti["trigger_unit"] == "minute") $out .= "selected"; $out .= ">" . L10n::t("Minutes") . "</option>\n";
483 $out .= "<option value='S' "; if ($noti["trigger_unit"] == "second") $out .= "selected"; $out .= ">" . L10n::t("Seconds") . "</option>\n";
484 $out .= "<option value='D' "; if ($noti["trigger_unit"] == "day") $out .= "selected"; $out .= ">" . L10n::t("Days") . "</option>\n";
485 $out .= "<option value='W' "; if ($noti["trigger_unit"] == "week") $out .= "selected"; $out .= ">" . L10n::t("Weeks") . "</option>\n";
488 $out .= " <label class='plain'>" . L10n::t("before the") . " <select name='noti_ref[$index]' size='1'>";
489 $out .= "<option value='start' "; if ($noti["rel"] == "start") $out .= "selected"; $out .= ">" . L10n::t("start of the event") . "</option>\n";
490 $out .= "<option value='end' "; if ($noti["rel"] == "end") $out .= "selected"; $out .= ">" . L10n::t("end of the event") . "</option>\n";
491 $out .= "</select></label>\n";
495 $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>";
497 $out .= "<script>\$(function() {
498 wdcal_edit_init('" . $localization->dateformat_datepicker_js() . "', '${baseurl}/dav/');
501 $out .= "<br><input type='submit' name='save' value='Save'></form>";
508 * @param Sabre_VObject_Component_VEvent $component
509 * @param wdcal_local $localization
512 function wdcal_set_component_date(&$component, &$localization)
514 if (isset($_REQUEST["allday"])) {
515 $ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " 00:00");
516 $ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " 00:00");
517 $type = Sabre\VObject\Property\DateTime::DATE;
519 $ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " " . $_REQUEST["start_time"]);
520 $ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " " . $_REQUEST["end_time"]);
521 $type = Sabre\VObject\Property\DateTime::LOCALTZ;
523 $datetime_start = new Sabre\VObject\Property\DateTime("DTSTART");
524 $datetime_start->setDateTime(new DateTime(date(DateTimeFormat::MYSQL, $ts_start)), $type);
525 $datetime_end = new Sabre\VObject\Property\DateTime("DTEND");
526 $datetime_end->setDateTime(new DateTime(date(DateTimeFormat::MYSQL, $ts_end)), $type);
528 $component->__unset("DTSTART");
529 $component->__unset("DTEND");
530 $component->add($datetime_start);
531 $component->add($datetime_end);
537 * @param Sabre_VObject_Component_VEvent $component
542 function wdcal_set_component_recurrence_special(&$component, $str) {
545 /** @var Sabre\VObject\Property\DateTime $start */
546 $start = $component->__get("DTSTART");
559 $day = $start->getDateTime()->format("j");
560 $ret = ";BYMONTHDAY=" . $day;
562 case "bymonthday_neg":
563 $day = $start->getDateTime()->format("j");
564 $day_max = $start->getDateTime()->format("t");
565 $ret = ";BYMONTHDAY=" . (-1 * ($day_max - $day + 1));
568 $day = $start->getDateTime()->format("j");
569 $weekday = $dayMap[$start->getDateTime()->format("w")];
570 $num = IntVal(ceil($day / 7));
571 $ret = ";BYDAY=${num}${weekday}";
574 $day = $start->getDateTime()->format("j");
575 $weekday = $dayMap[$start->getDateTime()->format("w")];
576 $day_max = $start->getDateTime()->format("t");
577 $day_last = ($day_max - $day + 1);
578 $num = IntVal(ceil($day_last / 7));
579 $ret = ";BYDAY=-${num}${weekday}";
586 * @param Sabre_VObject_Component_VEvent $component
587 * @param wdcal_local $localization
589 function wdcal_set_component_recurrence(&$component, &$localization)
591 $component->__unset("RRULE");
592 $component->__unset("EXRULE");
593 $component->__unset("EXDATE");
594 $component->__unset("RDATE");
597 switch ($_REQUEST["rec_until_type"]) {
599 $date = $localization->date_local2timestamp($_REQUEST["rec_until_date"]);
600 $part_until = ";UNTIL=" . date("Ymd", $date);
601 $datetime_until = new Sabre\VObject\Property\DateTime("UNTIL");
602 $datetime_until->setDateTime(new DateTime(date(DateTimeFormat::MYSQL, $date)), Sabre\VObject\Property\DateTime::DATE);
605 $part_until = ";COUNT=" . IntVal($_REQUEST["rec_until_count"]);
609 switch ($_REQUEST["rec_frequency"]) {
611 $part_freq = "FREQ=DAILY";
612 if (isset($_REQUEST["rec_daily_byday"])) {
614 foreach ($_REQUEST["rec_daily_byday"] as $x) if (in_array($x, array("MO", "TU", "WE", "TH", "FR", "SA", "SU"))) $days[] = $x;
615 if (count($days) > 0) $part_freq .= ";BYDAY=" . implode(",", $days);
619 $part_freq = "FREQ=WEEKLY";
620 if (isset($_REQUEST["rec_weekly_wkst"]) && in_array($_REQUEST["rec_weekly_wkst"], array("MO", "SU"))) $part_freq .= ";WKST=" . $_REQUEST["rec_weekly_wkst"];
621 if (isset($_REQUEST["rec_weekly_byday"])) {
623 foreach ($_REQUEST["rec_weekly_byday"] as $x) if (in_array($x, array("MO", "TU", "WE", "TH", "FR", "SA", "SU"))) $days[] = $x;
624 if (count($days) > 0) $part_freq .= ";BYDAY=" . implode(",", $days);
628 $part_freq = "FREQ=MONTHLY";
629 $part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_monthly_day"]);
632 /** @var Sabre\VObject\Property\DateTime $start */
633 $start = $component->__get("DTSTART");
634 $part_freq = "FREQ=YEARLY";
635 $part_freq .= ";BYMONTH=" . $start->getDateTime()->format("n");
636 $part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_yearly_day"]);
642 if ($part_freq == "") return;
644 if (isset($_REQUEST["rec_interval"])) $part_freq .= ";INTERVAL=" . InTVal($_REQUEST["rec_interval"]);
646 if (isset($_REQUEST["rec_exceptions"])) {
648 foreach ($_REQUEST["rec_exceptions"] as $except) {
649 $arr[] = new DateTime(date(DateTimeFormat::MYSQL, $except));
651 /** @var Sabre\VObject\Property\MultiDateTime $prop */
652 $prop = Sabre\VObject\Property::create("EXDATE");
653 $prop->setDateTimes($arr);
654 $component->add($prop);
657 $rrule = $part_freq . $part_until;
658 $component->add(new Sabre\VObject\Property("RRULE", $rrule));
664 * @param Sabre\VObject\Component\VEvent $component
665 * @param wdcal_local $localization
666 * @param string $summary
667 * @param int $dtstart
669 function wdcal_set_component_alerts(&$component, &$localization, $summary, $dtstart)
673 $prev_alarms = $component->select("VALARM");
674 $component->__unset("VALARM");
676 foreach ($prev_alarms as $al) {
677 /** @var Sabre\VObject\Component\VAlarm $al */
678 // @TODO Parse notifications that have been there before; e.g. from Lightning
681 foreach (array_keys($_REQUEST["noti_type"]) as $key) if (is_numeric($key) || ($key == "new" && $_REQUEST["new_alarm"] == 1)) {
682 $alarm = new Sabre\VObject\Component\VAlarm("VALARM");
684 switch ($_REQUEST["noti_type"][$key]) {
686 $mailtext = str_replace(array(
689 $localization->date_timestamp2local($dtstart), $summary,
690 ), L10n::t("The event #name# will start at #date"));
692 $alarm->add(new Sabre\VObject\Property("ACTION", "EMAIL"));
693 $alarm->add(new Sabre\VObject\Property("SUMMARY", $summary));
694 $alarm->add(new Sabre\VObject\Property("DESCRIPTION", $mailtext));
695 $alarm->add(new Sabre\VObject\Property("ATTENDEE", "MAILTO:" . $a->user["email"]));
698 $alarm->add(new Sabre\VObject\Property("ACTION", "DISPLAY"));
699 $text = str_replace("#name#", $summary, L10n::t("#name# is about to begin."));
700 $alarm->add(new Sabre\VObject\Property("DESCRIPTION", $text));
706 $trigger_name = "TRIGGER";
707 $trigger_val = ""; // @TODO Bugfix : und ; sind evtl. vertauscht vgl. http://www.kanzaki.com/docs/ical/trigger.html
708 if ($_REQUEST["noti_ref"][$key] == "end") $trigger_name .= ";RELATED=END";
709 $trigger_val .= "-P";
710 if (in_array($_REQUEST["noti_unit"][$key], array("H", "M", "S"))) $trigger_val .= "T";
711 $trigger_val .= IntVal($_REQUEST["noti_value"][$key]) . $_REQUEST["noti_unit"][$key];
712 $alarm->add(new Sabre\VObject\Property($trigger_name, $trigger_val));
714 $component->add($alarm);
722 * @param string $timezone
723 * @param string $goaway_url
726 function wdcal_postEditPage($uri, $uid = 0, $timezone = "", $goaway_url = "")
729 $localization = wdcal_local::getInstanceByUser($uid);
731 $server = dav_create_server(true, true, false);
734 $calendar = dav_get_current_user_calendar_by_id($server, $_REQUEST["calendar"], DAV_ACL_READ);
735 $obj_uri = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($uri);
736 $obj_uri = $obj_uri["uri"];
738 $vObject = dav_get_current_user_calendarobject($server, $calendar, $obj_uri, DAV_ACL_WRITE);
739 $component = dav_get_eventComponent($vObject);
741 if ($component == null) return array("ok" => false, "msg" => L10n::t('Could not open component for editing'));
743 $calendar = dav_get_current_user_calendar_by_id($server, $_REQUEST["calendar"], DAV_ACL_WRITE);
744 $vObject = dav_create_empty_vevent();
745 $component = dav_get_eventComponent($vObject);
746 $obj_uri = $component->__get("UID");
749 $ts_start = wdcal_set_component_date($component, $localization);
750 wdcal_set_component_recurrence($component, $localization);
751 wdcal_set_component_alerts($component, $localization, icalendar_sanitize_string(dav_compat_parse_text_serverside("summary")), $ts_start);
753 $component->__unset("LOCATION");
754 $component->__unset("SUMMARY");
755 $component->__unset("DESCRIPTION");
756 $component->__unset("X-ANIMEXX-COLOR");
757 $component->add("SUMMARY", icalendar_sanitize_string(dav_compat_parse_text_serverside("summary")));
758 $component->add("LOCATION", icalendar_sanitize_string(dav_compat_parse_text_serverside("location")));
759 $component->add("DESCRIPTION", icalendar_sanitize_string(dav_compat_parse_text_serverside("wdcal_desc")));
760 if (isset($_REQUEST["color_override"])) {
761 $component->add("X-ANIMEXX-COLOR", $_REQUEST["color"]);
764 $data = $vObject->serialize();
767 $calendar->createFile($obj_uri . ".ics", $data);
769 $obj = $calendar->getChild($obj_uri);
772 return array("ok" => false, "msg" => L10n::t("Saved"));
779 function wdcal_getEditPage_exception_selector()
781 header("Content-type: application/json");
784 $localization = wdcal_local::getInstanceByUser($a->user["uid"]);
786 $vObject = dav_create_empty_vevent();
788 foreach ($vObject->getComponents() as $component) {
789 if ($component->name !== 'VTIMEZONE') break;
791 /** @var Sabre\VObject\Component\VEvent $component */
792 wdcal_set_component_date($component, $localization);
793 wdcal_set_component_recurrence($component, $localization);
796 $it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID"));
797 $max_ts = mktime(0, 0, 0, 1, 1, CALDAV_MAX_YEAR + 1);
803 while ($it->valid() && $last_start < $max_ts && $i++ < 1000) {
804 $last_start = $it->getDtStart()->getTimestamp();
805 $o .= "<li><a href='#' class='exception_selector_link' data-timestamp='$last_start'>" . $localization->date_timestamp2localDate($last_start) . "</a></li>\n";