4 * @param wdcal_local $localization
5 * @param string $baseurl
7 * @param int $calendar_id
9 * @param string $recurr_uri
12 function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $uri, $recurr_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 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 if ($component->select("RRULE")) $recurrence = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
57 else $recurrence = null;
59 } elseif (isset($_REQUEST["start"]) && $_REQUEST["start"] > 0) {
60 $calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
61 $calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
65 "Summary" => $_REQUEST["title"],
66 "StartTime" => InTVal($_REQUEST["start"]),
67 "EndTime" => IntVal($_REQUEST["end"]),
68 "IsAllDayEvent" => $_REQUEST["isallday"],
73 if ($_REQUEST["isallday"]) {
74 $notifications = array(array("rel" => "start", "type" => "duration", "period" => "hour", "period_val" => 24));
76 $notifications = array(array("rel" => "start", "type" => "duration", "period" => "hour", "period_val" => 1));
79 $recurrentce_exdates = array();
81 $calendars = dav_get_current_user_calendars($server, DAV_ACL_WRITE);
82 $calendar = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_WRITE);
87 "StartTime" => time(),
88 "EndTime" => time() + 3600,
89 "IsAllDayEvent" => "0",
94 $notifications = array(array("rel" => "start", "type" => "duration", "period" => "hour", "period_val" => 1));
96 $recurrentce_exdates = array();
99 $postto = $baseurl . "/dav/wdcal/" . ($uri == 0 ? "new/" : $calendar_id . "/" . $uri . "/edit/");
101 $out = "<a href='" . $baseurl . "/dav/wdcal/'>" . t("Go back to the calendar") . "</a><br><br>";
102 $out .= "<form method='POST' action='$postto'>
103 <input type='hidden' name='form_security_token' value='" . get_form_security_token('caledit') . "'>\n";
105 $out .= "<h2>" . t("Event data") . "</h2>";
107 $out .= "<label for='calendar'>" . t("Calendar") . ":</label><select id='calendar' name='calendar' size='1'>";
110 foreach ($calendars as $cal) {
111 $prop = $cal->getProperties(array("id", DAV_DISPLAYNAME, DAV_CALENDARCOLOR));
112 $out .= "<option value='" . $prop["id"] . "' ";
113 if ($prop["id"] == $calendar_id) {
115 $cal_col = $prop[DAV_CALENDARCOLOR];
117 } elseif (!$found) $cal_col = $prop[DAV_CALENDARCOLOR];
118 $out .= ">" . escape_tags($prop[DAV_DISPLAYNAME]) . "</option>\n";
122 $out .= " <label class='plain'><input type='checkbox' name='color_override' id='color_override' ";
123 if (!is_null($event["Color"])) $out .= "checked";
124 $out .= "> " . t("Special color") . ":</label>";
125 $out .= "<span id='cal_color_holder' ";
126 if (is_null($event["Color"])) $out .= "style='display: none;'";
127 $out .= "><input name='color' id='cal_color' value='" . (is_null($event["Color"]) ? "#" . $cal_col : escape_tags($event["Color"])) . "'></span>";
130 $out .= "<label class='block' for='cal_summary'>" . t("Subject") . ":</label>
131 <input name='summary' id='cal_summary' value=\"" . escape_tags($event["Summary"]) . "\"><br>\n";
132 $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";
134 $out .= "<label class='block' for='cal_start_date'>" . t("Starts") . ":</label>";
135 $out .= "<input name='start_date' value='" . $localization->dateformat_datepicker_php($event["StartTime"]) . "' id='cal_start_date'>";
136 $out .= "<input name='start_time' value='" . date("H:i", $event["StartTime"]) . "' id='cal_start_time'>";
139 $out .= "<label class='block' for='cal_end_date'>" . t("Ends") . ":</label>";
140 $out .= "<input name='end_date' value='" . $localization->dateformat_datepicker_php($event["EndTime"]) . "' id='cal_end_date'>";
141 $out .= "<input name='end_time' value='" . date("H:i", $event["EndTime"]) . "' id='cal_end_time'>";
144 $out .= "<label class='block' for='cal_location'>" . t("Location") . ":</label><input name='location' id='cal_location' value=\"" . escape_tags($event["Location"]) . "\"><br>\n";
146 $out .= "<label class='block' for='event-desc-textarea'>" . t("Description") . ":</label> <textarea id='event-desc-textarea' name='wdcal_desc' style='vertical-align: top; width: 400px; height: 100px;'>" . escape_tags($event["Description"]) . "</textarea>";
147 $out .= "<br style='clear: both;'>";
149 $out .= "<h2>" . t("Recurrence") . "</h2>";
151 $out .= "<label class='block' for='rec_frequency'>" . t("Frequency") . ":</label> <select id='rec_frequency' name='rec_frequency' size='1'>";
152 $out .= "<option value=''>" . t("None") . "</option>\n";
153 $out .= "<option value='daily' ";
154 if ($recurrence && $recurrence->frequency == "daily") $out .= "selected";
155 $out .= ">" . t("Daily") . "</option>\n";
156 $out .= "<option value='weekly' ";
157 if ($recurrence && $recurrence->frequency == "weekly") $out .= "selected";
158 $out .= ">" . t("Weekly") . "</option>\n";
159 $out .= "<option value='monthly' ";
160 if ($recurrence && $recurrence->frequency == "monthly") $out .= "selected";
161 $out .= ">" . t("Monthly") . "</option>\n";
162 $out .= "<option value='yearly' ";
163 if ($recurrence && $recurrence->frequency == "yearly") $out .= "selected";
164 $out .= ">" . t("Yearly") . "</option>\n";
165 $out .= "</select><br>\n";
166 $out .= "<div id='rec_details'>";
168 $select = "<select id='rec_interval' name='rec_interval' size='1'>";
169 for ($i = 1; $i < 50; $i++) {
170 $select .= "<option value='$i' ";
171 if ($recurrence && $i == $recurrence->interval) $select .= "selected";
172 $select .= ">$i</option>\n";
174 $select .= "</select>";
175 $time = "<span class='rec_daily'>" . t("days") . "</span>";
176 $time .= "<span class='rec_weekly'>" . t("weeks") . "</span>";
177 $time .= "<span class='rec_monthly'>" . t("months") . "</span>";
178 $time .= "<span class='rec_yearly'>" . t("years") . "</span>";
179 $out .= "<label class='block'>" . t("Interval") . ":</label> " . str_replace(array("%select%", "%time%"), array($select, $time), t("All %select% %time%")) . "<br>";
182 $out .= "<div class='rec_daily'>";
183 $out .= "<label class='block'>" . t("Days") . ":</label>";
184 if ($recurrence && $recurrence->byDay) {
185 $byday = $recurrence->byDay;
187 $byday = array("MO", "TU", "WE", "TH", "FR", "SA", "SU");
189 if ($localization->getFirstDayOfWeek() == 0) {
190 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='SU' ";
191 if (in_array("SU", $byday)) $out .= "checked";
192 $out .= ">" . t("Sunday") . "</label> ";
194 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='MO' ";
195 if (in_array("MO", $byday)) $out .= "checked";
196 $out .= ">" . t("Monday") . "</label> ";
197 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='TU' ";
198 if (in_array("TU", $byday)) $out .= "checked";
199 $out .= ">" . t("Tuesday") . "</label> ";
200 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='WE' ";
201 if (in_array("WE", $byday)) $out .= "checked";
202 $out .= ">" . t("Wednesday") . "</label> ";
203 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='TH' ";
204 if (in_array("TH", $byday)) $out .= "checked";
205 $out .= ">" . t("Thursday") . "</label> ";
206 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='FR' ";
207 if (in_array("FR", $byday)) $out .= "checked";
208 $out .= ">" . t("Friday") . "</label> ";
209 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='SA' ";
210 if (in_array("SA", $byday)) $out .= "checked";
211 $out .= ">" . t("Saturday") . "</label> ";
212 if ($localization->getFirstDayOfWeek() != 0) {
213 $out .= "<label class='plain'><input class='rec_daily_byday' type='checkbox' name='rec_daily_byday[]' value='SU' ";
214 if (in_array("SU", $byday)) $out .= "checked";
215 $out .= ">" . t("Sunday") . "</label> ";
220 $out .= "<div class='rec_weekly'>";
221 $out .= "<label class='block'>" . t("Days") . ":</label>";
222 if ($recurrence && $recurrence->byDay) {
223 $byday = $recurrence->byDay;
225 $byday = array("MO", "TU", "WE", "TH", "FR", "SA", "SU");
227 if ($localization->getFirstDayOfWeek() == 0) {
228 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='SU' ";
229 if (in_array("SU", $byday)) $out .= "checked";
230 $out .= ">" . t("Sunday") . "</label> ";
232 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='MO' ";
233 if (in_array("MO", $byday)) $out .= "checked";
234 $out .= ">" . t("Monday") . "</label> ";
235 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='TU' ";
236 if (in_array("TU", $byday)) $out .= "checked";
237 $out .= ">" . t("Tuesday") . "</label> ";
238 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='WE' ";
239 if (in_array("WE", $byday)) $out .= "checked";
240 $out .= ">" . t("Wednesday") . "</label> ";
241 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='TH' ";
242 if (in_array("TH", $byday)) $out .= "checked";
243 $out .= ">" . t("Thursday") . "</label> ";
244 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='FR' ";
245 if (in_array("FR", $byday)) $out .= "checked";
246 $out .= ">" . t("Friday") . "</label> ";
247 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='SA' ";
248 if (in_array("SA", $byday)) $out .= "checked";
249 $out .= ">" . t("Saturday") . "</label> ";
250 if ($localization->getFirstDayOfWeek() != 0) {
251 $out .= "<label class='plain'><input class='rec_weekly_byday' type='checkbox' name='rec_weekly_byday[]' value='SU' ";
252 if (in_array("SU", $byday)) $out .= "checked";
253 $out .= ">" . t("Sunday") . "</label> ";
257 $out .= "<label class='block'>" . t("First day of week:") . "</label>";
258 if ($recurrence && $recurrence->weekStart != "") $wkst = $recurrence->weekStart;
260 if ($localization->getFirstDayOfWeek() == 0) $wkst = "SU";
263 $out .= "<label class='plain'><input type='radio' name='rec_weekly_wkst' value='SU' ";
264 if ($wkst == "SU") $out .= "checked";
265 $out .= ">" . t("Sunday") . "</label> ";
266 $out .= "<label class='plain'><input type='radio' name='rec_weekly_wkst' value='MO' ";
267 if ($wkst == "MO") $out .= "checked";
268 $out .= ">" . t("Monday") . "</label><br>\n";
273 if ($recurrence->frequency == "monthly" || $recurrence->frequency == "yearly") {
274 if (is_null($recurrence->byDay) && !is_null($recurrence->byMonthDay) && count($recurrence->byMonthDay) == 1) {
275 $day = date("j", $event["StartTime"]);
276 if ($recurrence->byMonthDay[0] == $day) $monthly_rule = "bymonthday";
278 $lastday = date("t", $event["StartTime"]);
279 if ($recurrence->byMonthDay[0] == -1 * ($lastday - $day + 1)) $monthly_rule = "bymonthday_neg";
282 if (is_null($recurrence->byMonthDay) && !is_null($recurrence->byDay) && count($recurrence->byDay) == 1) {
283 $num = IntVal($recurrence->byDay[0]);
296 $weekday = $dayMap[$recurrence->byDay[0]];
298 $weekday = $dayMap[substr($recurrence->byDay[0], strlen($num))];
301 echo $num . " - " . $weekday;
303 if ($num > 0) $monthly_rule = "byday";
304 if ($num < 0) $monthly_rule = "byday_neg";
306 if ($monthly_rule == "") notice("The recurrence of this event cannot be parsed");
309 $out .= "<div class='rec_monthly'>";
310 $out .= "<label class='block' for='rec_monthly_day'>" . t("Day of month") . ":</label>";
311 $out .= "<select id='rec_monthly_day' name='rec_monthly_day' size='1'>";
312 $out .= "<option value='bymonthday' ";
313 if ($monthly_rule == "bymonthday") $out .= "selected";
314 $out .= ">" . t("#num#th of each month") . "</option>\n";
315 $out .= "<option value='bymonthday_neg' ";
316 if ($monthly_rule == "bymonthday_neg") $out .= "selected";
317 $out .= ">" . t("#num#th-last of each month") . "</option>\n";
318 $out .= "<option value='byday' ";
319 if ($monthly_rule == "byday") $out .= "selected";
320 $out .= ">" . t("#num#th #wkday# of each month") . "</option>\n";
321 $out .= "<option value='byday_neg' ";
322 if ($monthly_rule == "byday_neg") $out .= "selected";
323 $out .= ">" . t("#num#th-last #wkday# of each month") . "</option>\n";
327 if ($recurrence->frequency == "yearly") {
328 if (count($recurrence->byMonth) != 1 || $recurrence->byMonth[0] != date("n", $event["StartTime"])) notice("The recurrence of this event cannot be parsed!");
331 $out .= "<div class='rec_yearly'>";
332 $out .= "<label class='block'>" . t("Month") . ":</label> <span class='rec_month_name'>#month#</span><br>\n";
333 $out .= "<label class='block' for='rec_yearly_day'>" . t("Day of month") . ":</label>";
334 $out .= "<select id='rec_yearly_day' name='rec_yearly_day' size='1'>";
335 $out .= "<option value='bymonthday' ";
336 if ($monthly_rule == "bymonthday") $out .= "selected";
337 $out .= ">" . t("#num#th of the given month") . "</option>\n";
338 $out .= "<option value='bymonthday_neg' ";
339 if ($monthly_rule == "bymonthday_neg") $out .= "selected";
340 $out .= ">" . t("#num#th-last of the given month") . "</option>\n";
341 $out .= "<option value='byday' ";
342 if ($monthly_rule == "byday") $out .= "selected";
343 $out .= ">" . t("#num#th #wkday# of the given month") . "</option>\n";
344 $out .= "<option value='byday_neg' ";
345 if ($monthly_rule == "byday_neg") $out .= "selected";
346 $out .= ">" . t("#num#th-last #wkday# of the given month") . "</option>\n";
352 $until = $recurrence->until;
353 $count = $recurrence->count;
354 if (is_a($until, "DateTime")) {
355 /** @var DateTime $until */
357 $rule_until_date = $until->getTimestamp();
358 $rule_until_count = 1;
359 } elseif ($count > 0) {
360 $rule_type = "count";
361 $rule_until_date = time();
362 $rule_until_count = $count;
364 $rule_type = "infinite";
365 $rule_until_date = time();
366 $rule_until_count = 1;
369 $rule_type = "infinite";
370 $rule_until_date = time();
371 $rule_until_count = 1;
373 $out .= "<label class='block' for='rec_until_type'>" . t("Repeat until") . ":</label> ";
374 $out .= "<select name='rec_until_type' id='rec_until_type' size='1'>";
375 $out .= "<option value='infinite' ";
376 if ($rule_type == "infinite") $out .= "selected";
377 $out .= ">" . t("Infinite") . "</option>\n";
378 $out .= "<option value='date' ";
379 if ($rule_type == "date") $out .= "selected";
380 $out .= ">" . t("Until the following date") . ":</option>\n";
381 $out .= "<option value='count' ";
382 if ($rule_type == "count") $out .= "selected";
383 $out .= ">" . t("Number of times") . ":</option>\n";
386 $out .= "<input name='rec_until_date' value='" . $localization->dateformat_datepicker_php($rule_until_date) . "' id='rec_until_date'>";
387 $out .= "<input name='rec_until_count' value='$rule_until_count' id='rec_until_count'><br>";
389 $out .= "<label class='block'>" . t("Exceptions") . ":</label><div class='rec_exceptions'>";
390 $out .= "<div class='rec_exceptions_none' ";
391 if (count($recurrentce_exdates) > 0) $out .= "style='display: none;'";
392 $out .= ">" . t("none") . "</div>";
393 $out .= "<div class='rec_exceptions_holder' ";
394 if (count($recurrentce_exdates) == 0) $out .= "style='display: none;'";
397 foreach ($recurrentce_exdates as $exdate) {
398 $out .= "<div data-timestamp='$exdate' class='except'><input type='hidden' class='rec_exception' name='rec_exceptions[]' value='$exdate'>";
399 $out .= "<a href='#' class='exception_remover'>[remove]</a> ";
400 $out .= $localization->date_timestamp2localDate($exdate);
403 $out .= "</div><div><a href='#' class='exception_adder'>[add]</a></div>";
407 $out .= "</div><br>";
409 $out .= "<h2>" . t("Notification") . "</h2>";
412 $out .= '<input type="checkbox" name="notification" id="notification" ';
413 if ($notification) $out .= "checked";
415 $out .= '<span id="notification_detail" style="display: none;">
416 <input name="notification_value" value="' . $notification_value . '" size="3">
417 <select name="notification_type" size="1">
418 <option value="minute" ';
419 if ($notification_type == "minute") $out .= "selected";
420 $out .= '> ' . t('Minutes') . '</option>
421 <option value="hour" ';
422 if ($notification_type == "hour") $out .= "selected";
423 $out .= '> ' . t('Hours') . '</option>
424 <option value="day" ';
425 if ($notification_type == "day") echo "selected";
426 $out .= '> ' . t('Days') . '</option>
427 </select> ' . t('before') . '
431 $out .= "<script>\$(function() {
432 wdcal_edit_init('" . $localization->dateformat_datepicker_js() . "', '${baseurl}/dav/');
435 $out .= "<input type='submit' name='save' value='Save'></form>";
442 * @param Sabre_VObject_Component_VEvent $component
443 * @param wdcal_local $localization
445 function wdcal_set_component_date(&$component, &$localization)
447 if (isset($_REQUEST["allday"])) {
448 $ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " 00:00");
449 $ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " 00:00");
450 $type = Sabre_VObject_Property_DateTime::DATE;
452 $ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " " . $_REQUEST["start_time"]);
453 $ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " " . $_REQUEST["end_time"]);
454 $type = Sabre_VObject_Property_DateTime::LOCALTZ;
456 $datetime_start = new Sabre_VObject_Property_DateTime("DTSTART");
457 $datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_start)), $type);
458 $datetime_end = new Sabre_VObject_Property_DateTime("DTEND");
459 $datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_end)), $type);
461 $component->__unset("DTSTART");
462 $component->__unset("DTEND");
463 $component->add($datetime_start);
464 $component->add($datetime_end);
468 * @param Sabre_VObject_Component_VEvent $component
473 function wdcal_set_component_recurrence_special(&$component, $str) {
476 /** @var Sabre_VObject_Property_DateTime $start */
477 $start = $component->__get("DTSTART");
490 $day = $start->getDateTime()->format("j");
491 $ret = ";BYMONTHDAY=" . $day;
493 case "bymonthday_neg":
494 $day = $start->getDateTime()->format("j");
495 $day_max = $start->getDateTime()->format("t");
496 $ret = ";BYMONTHDAY=" . (-1 * ($day_max - $day + 1));
499 $day = $start->getDateTime()->format("j");
500 $weekday = $dayMap[$start->getDateTime()->format("w")];
501 $num = IntVal(ceil($day / 7));
502 $ret = ";BYDAY=${num}${weekday}";
505 $day = $start->getDateTime()->format("j");
506 $weekday = $dayMap[$start->getDateTime()->format("w")];
507 $day_max = $start->getDateTime()->format("t");
508 $day_last = ($day_max - $day + 1);
509 $num = IntVal(ceil($day_last / 7));
510 $ret = ";BYDAY=-${num}${weekday}";
517 * @param Sabre_VObject_Component_VEvent $component
518 * @param wdcal_local $localization
520 function wdcal_set_component_recurrence(&$component, &$localization)
522 $component->__unset("RRULE");
523 $component->__unset("EXRULE");
524 $component->__unset("EXDATE");
525 $component->__unset("RDATE");
528 switch ($_REQUEST["rec_until_type"]) {
530 $date = $localization->date_local2timestamp($_REQUEST["rec_until_date"]);
531 $part_until = ";UNTIL=" . date("Ymd", $date);
532 $datetime_until = new Sabre_VObject_Property_DateTime("UNTIL");
533 $datetime_until->setDateTime(new DateTime(date("Y-m-d H:i:s", $date)), Sabre_VObject_Property_DateTime::DATE);
536 $part_until = ";COUNT=" . IntVal($_REQUEST["rec_until_count"]);
540 switch ($_REQUEST["rec_frequency"]) {
542 $part_freq = "FREQ=DAILY";
543 if (isset($_REQUEST["rec_daily_byday"])) {
545 foreach ($_REQUEST["rec_daily_byday"] as $x) if (in_array($x, array("MO", "TU", "WE", "TH", "FR", "SA", "SU"))) $days[] = $x;
546 if (count($days) > 0) $part_freq .= ";BYDAY=" . implode(",", $days);
550 $part_freq = "FREQ=WEEKLY";
551 if (isset($_REQUEST["rec_weekly_wkst"]) && in_array($_REQUEST["rec_weekly_wkst"], array("MO", "SU"))) $part_freq .= ";WKST=" . $_REQUEST["rec_weekly_wkst"];
552 if (isset($_REQUEST["rec_weekly_byday"])) {
554 foreach ($_REQUEST["rec_weekly_byday"] as $x) if (in_array($x, array("MO", "TU", "WE", "TH", "FR", "SA", "SU"))) $days[] = $x;
555 if (count($days) > 0) $part_freq .= ";BYDAY=" . implode(",", $days);
559 $part_freq = "FREQ=MONTHLY";
560 $part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_monthly_day"]);
563 /** @var Sabre_VObject_Property_DateTime $start */
564 $start = $component->__get("DTSTART");
565 $part_freq = "FREQ=YEARLY";
566 $part_freq .= ";BYMONTH=" . $start->getDateTime()->format("n");
567 $part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_yearly_day"]);
574 echo $part_freq . "\n";
580 if ($part_freq == "") return;
582 if (isset($_REQUEST["rec_interval"])) $part_freq .= ";INTERVAL=" . InTVal($_REQUEST["rec_interval"]);
584 if (isset($_REQUEST["rec_exceptions"])) {
586 foreach ($_REQUEST["rec_exceptions"] as $except) {
587 $arr[] = new DateTime(date("Y-m-d H:i:s", $except));
589 /** @var Sabre_VObject_Property_MultiDateTime $prop */
590 $prop = Sabre_VObject_Property::create("EXDATE");
591 $prop->setDateTimes($arr);
592 $component->add($prop);
595 $rrule = $part_freq . $part_until;
596 $component->add(new Sabre_VObject_Property("RRULE", $rrule));
603 * @param string $recurr_uri
605 * @param string $timezone
606 * @param string $goaway_url
609 function wdcal_postEditPage($uri, $recurr_uri = "", $uid = 0, $timezone = "", $goaway_url = "")
612 $localization = wdcal_local::getInstanceByUser($uid);
614 $server = dav_create_server(true, true, false);
617 $calendar = dav_get_current_user_calendar_by_id($server, $_REQUEST["calendar"], DAV_ACL_READ);
618 $obj_uri = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($uri);
619 $obj_uri = $obj_uri["uri"];
621 $vObject = dav_get_current_user_calendarobject($server, $calendar, $obj_uri, DAV_ACL_WRITE);
622 $component = dav_get_eventComponent($vObject);
624 if ($component == null) return array("ok" => false, "msg" => t('Could not open component for editing'));
626 $calendar = dav_get_current_user_calendar_by_id($server, $_REQUEST["calendar"], DAV_ACL_WRITE);
627 $vObject = dav_create_empty_vevent();
628 $component = dav_get_eventComponent($vObject);
629 $obj_uri = $component->__get("UID");
632 wdcal_set_component_date($component, $localization);
633 wdcal_set_component_recurrence($component, $localization);
635 $component->__unset("LOCATION");
636 $component->__unset("SUMMARY");
637 $component->__unset("DESCRIPTION");
638 $component->__unset("X-ANIMEXX-COLOR");
639 $component->add("SUMMARY", icalendar_sanitize_string(dav_compat_parse_text_serverside("summary")));
640 $component->add("LOCATION", icalendar_sanitize_string(dav_compat_parse_text_serverside("location")));
641 $component->add("DESCRIPTION", icalendar_sanitize_string(dav_compat_parse_text_serverside("wdcal_desc")));
642 if (isset($_REQUEST["color_override"])) {
643 $component->add("X-ANIMEXX-COLOR", $_REQUEST["color"]);
646 $data = $vObject->serialize();
649 $calendar->createFile($obj_uri . ".ics", $data);
651 $obj = $calendar->getChild($obj_uri);
654 return array("ok" => false, "msg" => t("Saved"));
661 function wdcal_getEditPage_exception_selector()
663 header("Content-type: application/json");
666 $localization = wdcal_local::getInstanceByUser($a->user["uid"]);
668 $vObject = dav_create_empty_vevent();
670 foreach ($vObject->getComponents() as $component) {
671 if ($component->name !== 'VTIMEZONE') break;
673 /** @var Sabre_VObject_Component_VEvent $component */
674 wdcal_set_component_date($component, $localization);
675 wdcal_set_component_recurrence($component, $localization);
678 $it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
679 $max_ts = mktime(0, 0, 0, 1, 1, CALDAV_MAX_YEAR + 1);
685 while ($it->valid() && $last_start < $max_ts && $i++ < 1000) {
686 $last_start = $it->getDtStart()->getTimestamp();
687 $o .= "<li><a href='#' class='exception_selector_link' data-timestamp='$last_start'>" . $localization->date_timestamp2localDate($last_start) . "</a></li>\n";