<?php

//require_once "_include/calendar/autoload.php";

function gen_calendar_header()
{
	$months = array(1 => "Jänner", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
	$today = date("w") ; // 0 = Sonntag
	if ($today == 0) $today = 7;
	// Zeitraum 5 Wochen
	$first_day = strtotime("-1 week") - ((60*60*24)*($today-1)) ; // Erster Montag
	$last_day = strtotime("+3 weeks") + ((60*60*24)*(7-$today)) ; // letzter Sonntag
	if (date("F", $first_day) != date("F", $last_day)) {  // 2 Monate
		return $months[date("n", $first_day)] . " - " . $months[date("n", $last_day)] . date(" Y", $last_day) ;
	} else {
		return $months[date("F", $first_day)] . date(" Y", $first_day) ;
	}
}

function gen_calendar_content()
{
	$today = date("w") ; // 0 = Sonntag
	if ($today == 0) $today = 7;
	// Zeitraum 5 Wochen
	$first_day = strtotime("-1 week") - ((60*60*24)*($today-1)) ; // Erster Montag
	$last_day = strtotime("+3 weeks") + ((60*60*24)*(7-$today)) ; // letzter Sonntag
	$output = "";
	$day = $first_day;
	
	
	for ($w = 0; $w < 5; $w++) {
		$output .= "<tr>";
		for ($d = 0; $d < 7; $d++) {
			if (date("Y-m-d", $day) == date("Y-m-d", time())) {
				$output .= '<td class="cal_today">'.date("d",$day)."</td>";
			} else {
				$output .= "<td>".date("d",$day)."</td>";
			}
			$day = $day + (60*60*24);
		}
		$output .= "</tr>\n";
	}
	return $output;
}

function check_for_event($events, $date)
{
	foreach ( $events as $event ) {
		if (date("Y-m-d", $event->dtstart_array[2]) == date("Y-m-d", $date)) {
			return $event->summary;
		}
	}
	return false;	
}

?>