12 || $requested_month < 1 ) { $requested_month = idate("m"); } return $requested_month; } /** * Echoes the requested months' name */ function echoMonthName () { echo getLocalizedMonthName (getRequestedMonth ()); } /** * Returns HTML for a days' events list (CSS class day-events-scrollbox) * * @param ICal $ical ICal object * @param int $day Day of month * @param int $month Month (defaults to current month) * @param int $year Year (defaults to current year) * * @return string HTML containing DIV of class day-events-scrollbox * @return false False on failure */ function generateDayEventsList ($ical, $day, $month = null, $year = null) { if (! $ical) return false; $html = '
%s
'; foreach (getEventsForDay ($ical, $day, $month, $year) as $event) { $dtstart = $ical -> iCalDateToDateTime($event -> dtstart_array[3]); $dtend = $ical -> iCalDateToDateTime($event -> dtend_array[3]); $today_start = new DateTime( date('Y-m-d H:i:s', mktime(0, 0, 0, $month, $day, $year)), $dtstart -> getTimezone() ); $today_end = clone $today_start; $today_end -> modify("+1 day"); $time_separator = "-"; $time_prefix = ""; $time_start = $dtstart -> format('H:i'); $time_end = $dtend -> format('H:i'); // When start date is in past, don't display start time if ($dtstart < $today_start) { $time_start = ""; $time_separator = "Bis "; } // When end date is in future, don't display end time if ($dtend > $today_end) { $time_end = ""; $time_separator = ""; $time_prefix = "Ab "; } // Assemble time display string $time_str = "{$time_prefix}{$time_start}{$time_separator}{$time_end}"; // Check if event is all day if ($time_start == "00:00" && $time_end == "00:00") { //$time_str = "Ganztägig"; $time_str = ""; } // Check if event is multi day if ($time_start == "" && $time_end == "") { $time_str = "Mehrtägig"; } // Check if multi day event without start times if ($time_start . $time_end == "00:00") { $time_str = "Mehrtägig"; } $html = sprintf ( $html, sprintf( ' %s %s %%s', $time_str, $event -> summary ), ); } $html = sprintf ($html, ""); return $html; } /** * Returns HTML with all elements going in the DIV with CSS class calendar-body * * @param ICal $Ical ICal object * @param int $month Month * * @return string HTML containing elements for calendar body * @return false False on failure */ function generateCalendarBodyItems ($ical, $month) { if ($month > 12 || $month < 1) return false; $html = '%s'; $odd_row = false; // Number of days in month $month_max_days = idate ("t", mktime (0, 0, 0, $month)); // First of month unix timestamp $first_of_month = new DateTime ( date('Y-m-d H:i:s', mktime (0, 0, 0, $month, 1)) ); // Days needed to pad the calendar at the start $pad_days = idate ("N", $first_of_month -> getTimestamp()) - 1; // First of the month, minus the pad days $day = $first_of_month -> modify ("-{$pad_days} days"); // Number of total entries in calendar $num_rows = ceil (($pad_days + $month_max_days) / 7); $num_entries = ($num_rows * 8); // Loop over all entry slots and generate entries for ($item_index = 0; $item_index < $num_entries; $item_index ++) { // If item_index is beginning of row, add week number entry if ($item_index % 8 == 0) { $week = $day -> format ("W"); $html = sprintf ( $html, "
Woche {$week}
%s", ); // Swap odd and even rows $odd_row = ! $odd_row; continue; } $calendar_entry_html = '
%d.
%s
%s '; $html = sprintf ( $html, sprintf( $calendar_entry_html, $odd_row? "odd-row" : "even-row", (isDateTimeWithinMonth ($day, $month)) ? "" : "other-month", (isDateTimeDuringWeekend ($day)) ? "weekend" : "", (isDateTimeToday ($day))? "today" : "", $day -> format ("d"), generateDayEventsList( $ical, intval ($day -> format ("d")), intval ($day -> format ("m")), ), "%s" ) ); $day -> modify ("+1 day"); } return sprintf($html, ""); } /** * Echoes HTML to insert all calendar day entries */ function echoCalendarEntries() { global $ical; echo generateCalendarBodyItems($ical, getRequestedMonth()); }