From a96c8ce6704b68b840c51c016ac5763f438904b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Fri, 13 Jul 2012 19:38:33 +0000 Subject: [PATCH] Monthly / Yearly recurrences --- dav/common/wdcal.js | 16 ++--- dav/common/wdcal_edit.inc.php | 126 ++++++++++++++++++++++++++++++---- 2 files changed, 121 insertions(+), 21 deletions(-) diff --git a/dav/common/wdcal.js b/dav/common/wdcal.js index 13069eba..58e36243 100644 --- a/dav/common/wdcal.js +++ b/dav/common/wdcal.js @@ -42,19 +42,19 @@ function wdcal_edit_recur_recalc() { var start = $("#cal_start_date").datepicker("getDate"); $(".rec_month_name").text($.datepicker._defaults.monthNames[start.getMonth()]); - $("#rec_yearly_day option[value=bymonthday], #rec_monthly_day option[value=bymonthday]").text($("#rec_yearly_day option[value=bymonthday]").data("orig").replace("#num#", start.getDate())); + $("#rec_yearly_day option[value=bymonthday]").text($("#rec_yearly_day option[value=bymonthday]").data("orig").replace("#num#", start.getDate())); + $("#rec_monthly_day option[value=bymonthday]").text($("#rec_monthly_day option[value=bymonthday]").data("orig").replace("#num#", start.getDate())); var month = new Date(start.getFullYear(), start.getMonth() + 1, 0); var monthlast = month.getDate() - start.getDate() + 1; - $("#rec_yearly_day option[value=bymonthday_neg], #rec_monthly_day option[value=bymonthday_neg]").text($("#rec_yearly_day option[value=bymonthday_neg]").data("orig").replace("#num#", monthlast)); + $("#rec_yearly_day option[value=bymonthday_neg]").text($("#rec_yearly_day option[value=bymonthday_neg]").data("orig").replace("#num#", monthlast)); + $("#rec_monthly_day option[value=bymonthday_neg]").text($("#rec_monthly_day option[value=bymonthday_neg]").data("orig").replace("#num#", monthlast)); var wk = Math.ceil(start.getDate() / 7); var wkname = $.datepicker._defaults.dayNames[start.getDay()]; - $("#rec_yearly_day option[value=byday], #rec_monthly_day option[value=byday]").text( - $("#rec_yearly_day option[value=byday]").data("orig").replace("#num#", wk).replace("#wkday#", wkname) - ); + $("#rec_yearly_day option[value=byday]").text($("#rec_yearly_day option[value=byday]").data("orig").replace("#num#", wk).replace("#wkday#", wkname)); + $("#rec_monthly_day option[value=byday]").text($("#rec_monthly_day option[value=byday]").data("orig").replace("#num#", wk).replace("#wkday#", wkname)); var wk_inv = Math.ceil(monthlast / 7); - $("#rec_yearly_day option[value=byday_neg], #rec_monthly_day option[value=byday_neg]").text( - $("#rec_yearly_day option[value=byday_neg]").data("orig").replace("#num#", wk_inv).replace("#wkday#", wkname) - ); + $("#rec_yearly_day option[value=byday_neg]").text($("#rec_yearly_day option[value=byday_neg]").data("orig").replace("#num#", wk_inv).replace("#wkday#", wkname)); + $("#rec_monthly_day option[value=byday_neg]").text($("#rec_monthly_day option[value=byday_neg]").data("orig").replace("#num#", wk_inv).replace("#wkday#", wkname)); } function wdcal_edit_init(dateFormat, base_path) { diff --git a/dav/common/wdcal_edit.inc.php b/dav/common/wdcal_edit.inc.php index 63e39e8c..b3f8889b 100644 --- a/dav/common/wdcal_edit.inc.php +++ b/dav/common/wdcal_edit.inc.php @@ -104,7 +104,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur $out .= "

" . t("Event data") . "

"; - $out .= ""; $found = false; $cal_col = "aaaaaa"; foreach ($calendars as $cal) { @@ -131,12 +131,12 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur
\n"; $out .= "
\n"; - $out .= ""; + $out .= ""; $out .= ""; $out .= ""; $out .= "
\n"; - $out .= ""; + $out .= ""; $out .= ""; $out .= ""; $out .= "
\n"; @@ -176,7 +176,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur $time .= "" . t("weeks") . ""; $time .= "" . t("months") . ""; $time .= "" . t("years") . ""; - $out .= " " . str_replace(array("%select%", "%time%"), array($select, $time), t("All %select% %time%")) . "
"; + $out .= " " . str_replace(array("%select%", "%time%"), array($select, $time), t("All %select% %time%")) . "
"; $out .= "
"; @@ -269,9 +269,45 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $uid, $calendar_id, $ur $out .= "
"; - $monthly_rule = "bymonthday"; // @TODO + $monthly_rule = ""; + if ($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"; + else { + $lastday = date("t", $event["StartTime"]); + if ($recurrence->byMonthDay[0] == -1 * ($lastday - $day + 1)) $monthly_rule = "bymonthday_neg"; + } + } + if (is_null($recurrence->byMonthDay) && !is_null($recurrence->byDay) && count($recurrence->byDay) == 1) { + $num = IntVal($recurrence->byDay[0]); + /* + $dayMap = array( + 'SU' => 0, + 'MO' => 1, + 'TU' => 2, + 'WE' => 3, + 'TH' => 4, + 'FR' => 5, + 'SA' => 6, + ); + if ($num == 0) { + $num = 1; + $weekday = $dayMap[$recurrence->byDay[0]]; + } else { + $weekday = $dayMap[substr($recurrence->byDay[0], strlen($num))]; + } + + echo $num . " - " . $weekday; + */ + if ($num > 0) $monthly_rule = "byday"; + if ($num < 0) $monthly_rule = "byday_neg"; + } + if ($monthly_rule == "") notice("The recurrence of this event cannot be parsed"); + } + $out .= "
"; - $out .= ""; + $out .= ""; $out .= ""; $out .= "\n"; $out .= "\n"; $out .= "\n"; $out .= "\n"; $out .= ""; $out .= "
\n"; @@ -425,6 +464,55 @@ function wdcal_set_component_date(&$component, &$localization) $component->add($datetime_end); } +/** + * @param Sabre_VObject_Component_VEvent $component + * @param string $str + * @return string + */ + +function wdcal_set_component_recurrence_special(&$component, $str) { + $ret = ""; + + /** @var Sabre_VObject_Property_DateTime $start */ + $start = $component->__get("DTSTART"); + $dayMap = array( + 0 => 'SU', + 1 => 'MO', + 2 => 'TU', + 3 => 'WE', + 4 => 'TH', + 5 => 'FR', + 6 => 'SA', + ); + + switch ($str) { + case "bymonthday": + $day = $start->getDateTime()->format("j"); + $ret = ";BYMONTHDAY=" . $day; + break; + case "bymonthday_neg": + $day = $start->getDateTime()->format("j"); + $day_max = $start->getDateTime()->format("t"); + $ret = ";BYMONTHDAY=" . (-1 * ($day_max - $day + 1)); + break; + case "byday": + $day = $start->getDateTime()->format("j"); + $weekday = $dayMap[$start->getDateTime()->format("w")]; + $num = IntVal(ceil($day / 7)); + $ret = ";BYDAY=${num}${weekday}"; + break; + case "byday_neg": + $day = $start->getDateTime()->format("j"); + $weekday = $dayMap[$start->getDateTime()->format("w")]; + $day_max = $start->getDateTime()->format("t"); + $day_last = ($day_max - $day + 1); + $num = IntVal(ceil($day_last / 7)); + $ret = ";BYDAY=-${num}${weekday}"; + break; + } + return $ret; +} + /** * @param Sabre_VObject_Component_VEvent $component * @param wdcal_local $localization @@ -469,13 +557,25 @@ function wdcal_set_component_recurrence(&$component, &$localization) break; case "monthly": $part_freq = "FREQ=MONTHLY"; + $part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_monthly_day"]); break; - case "FREQ=yearly": + case "yearly": + /** @var Sabre_VObject_Property_DateTime $start */ + $start = $component->__get("DTSTART"); $part_freq = "FREQ=YEARLY"; + $part_freq .= ";BYMONTH=" . $start->getDateTime()->format("n"); + $part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_yearly_day"]); break; default: $part_freq = ""; } +/* + echo "
!";
+	 echo $part_freq . "\n";
+	 var_dump($_REQUEST);
+	 echo "
"; + die(); +*/ if ($part_freq == "") return; -- 2.39.5