Location: PHPKode > projects > Content*Builder > modules/event/eventBox.php
<?php
require_once("Date.php");

/* 
* Periode in Session speichern, wenn neue Periode gewählt wurde 
*/
if(isset($newSelectedMonth) && isset($newSelectedYear)) {
	if(strlen($newSelectedMonth) < 2) {
		$newSelectedMonth = "0".$newSelectedMonth;
	}
	$_SESSION[selectedMonth] = $newSelectedMonth;
	$_SESSION[selectedYear]  = $newSelectedYear;
}

/* 
* Wenn kein spezieller Monat im Jahr angezeigt werden soll, 
* wird der aktuelle Monat genommen
*/
if(!session_is_registered("selectedMonth") || !session_is_registered("selectedYear")) {
	$calendarDate  = new Date();
	$calendarDate->setDay("01");
	$calendarMonth = $calendarDate->getMonth();
	$calendarYear  = $calendarDate->getYear();
} else {
	$calendarDate  = new Date($_SESSION[selectedYear].$_SESSION[selectedMonth]."01");
	$calendarYear  = $_SESSION[selectedYear];
	$calendarMonth = $_SESSION[selectedMonth];
}

/*
* tage herausfinden, an denen im Zielmonat Events stattfinden.
*/
$eventQuery = mysql_query("SELECT * FROM ".TABLE."_events WHERE MONTH(eventDate) = '$calendarMonth' AND YEAR(eventDate) = '$calendarYear'");
while($eventRow = mysql_fetch_object($eventQuery)) {
	$eventDate = new Date($eventRow->eventDate);
	$calendarEvents[$eventDate->getDay()] = 1;
	$eventContent[$eventDate->getDay()][$eventDate->getHour()][title][]  = $eventRow->title;
	$eventContent[$eventDate->getDay()][$eventDate->getHour()][desc][]   = $eventRow->description;
	$eventContent[$eventDate->getDay()][$eventDate->getHour()][hour][]   = $eventDate->getHour();
	$eventContent[$eventDate->getDay()][$eventDate->getHour()][minute][] = $eventDate->getMinute();
}

if(is_array($eventContent)) {
	foreach($eventContent as $day => $eventsPerHour) {
		sort($eventsPerHour);
		$tpl->assign("dayEvents", $eventsPerHour);
		$eventsPerDayContent[$day] = $tpl->fetch("dayEvents.template");
	}
}

/*
* oft gebrauchte globale Variablen ans Template senden
*/
$tpl->assign(
	array ( "CURRENT_MONTH"        => Date_Calc::getMonthFullname($calendarDate->getMonth()),
			"CURRENT_MONTH_NUMBER" => $calendarDate->getMonth(),
			"CURRENT_YEAR"         => $calendarYear
	)
);

/*
* Default Wert für $templateDaysOfWeek setzen. Somit mehrfache Verwendung
* dieser Datei möglich
*/
$templateDaysOfWeek = $templateDaysOfWeek or $templateDaysOfWeek = "event:month:days";

$calendarMonthArray = Date_Calc::getCalendarMonth($calendarDate->getMonth(), $calendarDate->getYear());
$daysInMonth        = Date_Calc::daysInMonth($calendarDate->getMonth(), $calendarDate->getYear());

/* 
* Durchlaufen aller Tage eines Monats
*/
$dayNumber = array();
$daySet    = array();
$dayEvent  = array();
$counter   = 0;

/*
* Sonntag ist bei getDayOfWeek 0 ... ändern auf 7, damit Berechnungen einfacher werden
*/
$thisWeekDayNumber = $calendarDate->getDayOfWeek();
if($thisWeekDayNumber == 0) {
	$thisWeekDayNumber = 7;
}

/*
* Tages Array mit den Tagen der ersten Woche auffüllen, die nicht
* im Zielmonat liegen
*/
if($thisWeekDayNumber > 1) {
	for($z = 1; $z < $thisWeekDayNumber; $z++) {
		$dayNumber[] = "";
		$dayEvent[] = "";
		$dayEventContent[] = "";
		$daySet[]    = 0;
	}
}

/*
* Tage und Events des Zielmonats in die Array's eintragen
*/
for($y = 1; $y <= $daysInMonth; $y++) {
	if(strlen($y) < 2) {
		$thisDayNumber = "0".$y;
	} else {
		$thisDayNumber = $y;
	}
	
	$dayNumber[] = $thisDayNumber;
	$dayEvent[]  = $calendarEvents[$thisDayNumber];
	$dayEventContent[]  = $eventsPerDayContent[$thisDayNumber];
	$daySet[]    = 1;
}

/*
* letzten Tag des Monats als aktuelles Datum setzen, um herauszufinden
* welcher Wochentag der letzte Tag ist.
*/
$calendarDate->setDay($thisDayNumber);

/*
* Auffüllen des Array mit den Tagen der letzten Woche, die im
* nächsten Monat liegen
*/
if($calendarDate->getDayOfWeek() != 0) {
	for($z = $calendarDate->getDayOfWeek(); $z <= 6; $z++) {
		$dayNumber[] = "";
		$dayEvent[] = "";
		$dayEventContent[] = "";
		$daySet[]    = 0;
	}
}

/*
* Date Objekt für den nächsten und den vorherigen Monat ableiten
*/
$nextMonthDate = & new Date(Date_Calc::beginOfNextMonth($calendarDate->getDay(), $calendarDate->getMonth(), $calendarDate->getYear()));
$prevMonthDate = & new Date(Date_Calc::beginOfPrevMonth($calendarDate->getDay(), $calendarDate->getMonth(), $calendarDate->getYear()));

$tpl->assign("eventDayArray", 
	array ( "DAY_NUMBER" => $dayNumber,
			"DAY_SET"    => $daySet,
			"DAY_EVENT"  => $dayEvent,
			"DAY_EVENT_CONTENT" => $dayEventContent,
			"LAST_MONTH_YEAR"  => $prevMonthDate->getYear(),
			"LAST_MONTH_MONTH" => $prevMonthDate->getMonth(),
			"NEXT_MONTH_YEAR"  => $nextMonthDate->getYear(),
			"NEXT_MONTH_MONTH" => $nextMonthDate->getMonth()
	)
);

$tpl->display("eventBox.template");
?>
Return current item: Content*Builder