Location: PHPKode > scripts > Kalender classes > kalender-classes/class/class.kalendar.php
<?

/**
 * Title:  Class_kalendar.php 
 * Date:  2005-21-06	
 */
class Calendar {
	var $vars;
	var $varDay;
	var $varMonth;
	var $varYear;
	var $varOsterTag;
	var $varOsterMonat;
	var $template;


	function Calendar($day, $month, $year) {
		$this->varDay = $day;
		$this->varMonth = $month;
		$this->varYear = $year;
		if ($GLOBALS['lang']) {
			$_tmp[] = "lang=".$GLOBALS['lang'];
		}
		if ($GLOBALS['country']) {
			$_tmp[] = "country=".$GLOBALS['country'];
		}
		$this->ExtraURI = "&".implode("&", $_tmp);
	}

	function showTemplate($template) {

		$monthNumber = date("n", mktime(0, 0, 0, $this->varMonth + 1, 0, $this->varYear));
		$monthName = $GLOBALS['CONF'][$GLOBALS['lang']]['months'][$GLOBALS['INI']['months']][$monthNumber];

		// weekday first and last
		$lastMonthDay = date("d", mktime(0, 0, 0, $this->varMonth + 1, 0, $this->varYear));
		$firstMonthWeekDay = date("w", mktime(0, 0, 0, $this->varMonth, 1, $this->varYear));
		$firstMonthWeekDay = ($firstMonthWeekDay == 0) ? 7 : $firstMonthWeekDay;
		$lastMonthWeekDay = date("w", mktime(0, 0, 0, $this->varMonth, $lastMonthDay, $this->varYear));
		$lastMonthWeekDay = ($lastMonthWeekDay == 0) ? 7 : $lastMonthWeekDay;

		// Week - Counter
		$mothBeginWithWeek = date("W", mktime(0, 0, 0, $this->varMonth, 1, $this->varYear));
		$mothBeginWithWeek = ($mothBeginWithWeek == 53 || $mothBeginWithWeek == 52) ? 0 : $mothBeginWithWeek;
		$mothEndWithWeek = date("W", mktime(0, 0, 0, $this->varMonth, $lastMonthDay, $this->varYear));
		$mothEndWithWeek = ($mothEndWithWeek == 1) ? 52 + 1 : $mothEndWithWeek;
		$countWeek = $mothEndWithWeek - $mothBeginWithWeek +1;

		// check Holidays		
		$holiday = $this->Feiertag();

		$templ = new Template("template");
		$templ->set_file("skin", $template);

		// Toon kalender.
		// Month-handling up/down.
		if (($this->varMonth - 1) == 0) {
			$monatBack = 12;
			$jahrBack = $this->varYear - 1;
		} else {
			$monatBack = $this->varMonth - 1;
			$jahrBack = $this->varYear;
		}
		if (($this->varMonth + 1) == 13) {
			$monatNext = 1;
			$jahrNext = $this->varYear + 1;
		} else {
			$monatNext = $this->varMonth + 1;
			$jahrNext = $this->varYear;
		}
		$aux .= "<span><a href='".$PHP_SELF."?day=".$this->varDay."&month=1&year=".$jahrBack.$this->ExtraURI."'>|&laquo;</a></span>";
		$aux .= "<span><a href='".$PHP_SELF."?day=".$this->varDay."&month=".$monatBack."&year=".$jahrBack.$this->ExtraURI."'>&laquo;</a></span>";
		$aux .= "<span style=\"width:110px;\">".$monthName."&nbsp;".$this->varYear."</span>";
		$aux .= "<span><a href='".$PHP_SELF."?day=".$this->varDay."&month=".$monatNext."&year=".$jahrNext.$this->ExtraURI."'>&raquo;</a></span>";
		$aux .= "<span><a href='".$PHP_SELF."?day=".$this->varDay."&month=12&year=".$jahrNext.$this->ExtraURI."'>&raquo;|</a></span>";
		$templ->set_var('month', $aux);

		for ($i = 1; $i <= 7; $i ++) {
			$templ->set_var('weekdays', $GLOBALS['CONF'][$GLOBALS['lang']]['weekdays'][$GLOBALS['INI']['weekdays']][$i]);
			if ($i >= 6) {
				$templ->set_var('classweekdays', $GLOBALS['INI']['stlyeclassdays']);
			} else {
				$templ->set_var('classweekdays', $GLOBALS['INI']['styleclassweekend']);
			}
			$templ->parse("WEEKDAYS", "WEEKDAYS", true);
		}
		$_day = 1;
		for ($j = 1; $j <= $countWeek; $j ++) {
			for ($ii = 1; $ii <= 7; $ii ++) {
				if ($j == 1) {
					if ($ii >= $firstMonthWeekDay) {
						$templ->set_var('days', "<a href='".$PHP_SELF."?day=".$_day."&month=".$this->varMonth."&year=".$this->varYear.$this->ExtraURI."'>".$_day."</a>");
						$_day ++;
					} else {
						$templ->set_var('days', '&nbsp;');
					}
				}
				elseif ($j == $countWeek) {
					if ($ii <= $lastMonthWeekDay) {
						$templ->set_var('days', "<a href='".$PHP_SELF."?day=".$_day."&month=".$this->varMonth."&year=".$this->varYear.$this->ExtraURI."'>".$_day."</a>");
						$_day ++;
					} else {
						$templ->set_var('days', '&nbsp;');
					}
				} else {
					$templ->set_var('days', "<a href='".$PHP_SELF."?day=".$_day."&month=".$this->varMonth."&year=".$this->varYear.$this->ExtraURI."'>".$_day."</a>");
					$_day ++;
				}
				if ($ii >= 6) {
					$templ->set_var('_classdays', $GLOBALS['INI']['styleday']);
				} else {
					$templ->set_var('_classdays', $GLOBALS['INI']['styledayweekend']);
				}
				if ($_day == ($this->varDay + 1)) {
					$templ->set_var('_classdays', $GLOBALS['INI']['styledayactiv']);
				}
				$templ->parse("DAYS", "DAYS", true);
			}
			$templ->parse("WEEK", "WEEK", true);
			$templ->vars['/{DAYS}/'] = "";
		}
		// Holiday
		if ($holiday) {
			$templ->set_var('holiday', "<div ".$GLOBALS['INI']['styleholiday'].">".$holiday."</div>");
		}
		$templ->pparse('skin');
	}

	function Feiertag() {
		$tmp = $this->varMonth."-".$this->varDay;
		if ($tmp == $this->Oster())
			$_tmp = $GLOBALS['_LOCALLANG'][$GLOBALS['lang']]['eastersunday'];
		elseif ($tmp == $this->OsterMontag()) $_tmp = $GLOBALS['_LOCALLANG'][$GLOBALS['lang']]['eastermonday'];
		elseif ($tmp == $this->KarFreitag()) $_tmp = $GLOBALS['_LOCALLANG'][$GLOBALS['lang']]['goodfriday'];
		elseif ($tmp == $this->HimmelFahrt()) $_tmp = $GLOBALS['_LOCALLANG'][$GLOBALS['lang']]['assumptionofmary'];
		elseif ($tmp == $this->PfingstSonntag()) $_tmp = $GLOBALS['_LOCALLANG'][$GLOBALS['lang']]['pentecost'];
		elseif ($tmp == $this->PfingstMontag()) $_tmp = $GLOBALS['_LOCALLANG'][$GLOBALS['lang']]['whitmonday'];
		elseif ($tmp == $this->Fronleichnam()) $_tmp = $GLOBALS['_LOCALLANG'][$GLOBALS['lang']]['corpuschristi'];
		else {
			$_aux = $this->checkData();
			$_tmp = $GLOBALS['_LOCALLANG'][$GLOBALS['lang']][$_aux];
		}
		return $_tmp;
	}
	function Oster() {
		// Goldene Zahl
		$Gz = (int) ($this->varYear % 19 + 1);
		// Zahl des Jahrhunderts
		$Jh = (int) ($this->varYear / 100 + 1);
		// Anzahl ausgelassener Schaltjahre
		$Schalt = (int) (((3 * $Jh) / 4) - 12);
		// Korrektur des metonischen Zyklus
		$Meton = (int) (((8 * $Jh) + 5) / 25 - 5);
		// Sonntag
		$Wotag = (int) (($this->varYear * 5) / 4 - $Schalt -10);
		// Epact
		$Epact = ((($Gz * 11) + 20 + $Meton - $Schalt) % 30);
		If (($Epact == 25 && $Gz > 11) || $Epact == 24) {
			$Epact = $Epact +1;
		}
		$OsterTag = 44 - $Epact;
		If ($OsterTag < 21) {
			$OsterTag = $OsterTag +30;
		}
		$OsterTag = $OsterTag +7 - (($Wotag + $OsterTag) % 7);
		if ($OsterTag > 31) {
			$Monat = 4;
			$OsterTag = $OsterTag -31;
		} else {
			$Monat = 3;
		}
		$this->varOsterMonat = $Monat;
		$this->varOsterTag = $OsterTag;
		return $this->varOsterMonat."-".$this->varOsterTag;
	}
	function OsterMontag() {
		$dates = date("z", mktime(0, 0, 0, $this->varOsterMonat, $this->varOsterTag, $this->varYear)) + 1;
		return date("n-j", mktime(0, 0, 0, 1, 1, $this->varYear) + 60 * 60 * 24 * $dates);
	}
	function KarFreitag() {
		$dates = date("z", mktime(0, 0, 0, $this->varOsterMonat, $this->varOsterTag, $this->varYear)) - 2;
		return date("n-j", mktime(0, 0, 0, 1, 1, $this->varYear) + 60 * 60 * 24 * $dates);
	}
	function HimmelFahrt() {
		$dates = date("z", mktime(0, 0, 0, $this->varOsterMonat, $this->varOsterTag, $this->varYear)) + 39;
		return date("n-j", mktime(0, 0, 0, 1, 1, $this->varYear) + 60 * 60 * 24 * $dates);
	}
	function PfingstSonntag() {
		$dates = date("z", mktime(0, 0, 0, $this->varOsterMonat, $this->varOsterTag, $this->varYear)) + 49;
		return date("n-j", mktime(0, 0, 0, 1, 1, $this->varYear) + 60 * 60 * 24 * $dates);
	}
	function PfingstMontag() {
		$dates = date("z", mktime(0, 0, 0, $this->varOsterMonat, $this->varOsterTag, $this->varYear)) + 50;
		return date("n-j", mktime(0, 0, 0, 1, 1, $this->varYear) + 60 * 60 * 24 * $dates);
	}
	function Fronleichnam() {
		$dates = date("z", mktime(0, 0, 0, $this->varOsterMonat, $this->varOsterTag, $this->varYear)) + 60;
		return date("n-j", mktime(0, 0, 0, 1, 1, $this->varYear) + 60 * 60 * 24 * $dates);
	}
	function checkData() {
		$this->vars = $this->loadInit();
		if (array_key_exists($this->varDay.".".$this->varMonth, $this->vars['universal'])) {
			return $this->vars['universal'][$this->varDay.".".$this->varMonth];
		}
		elseif (array_key_exists($this->varDay.".".$this->varMonth, $this->vars['country'])) {
			return $this->vars['country'][$this->varDay.".".$this->varMonth];
		}
		elseif (array_key_exists($this->varDay.".".$this->varMonth, $this->vars['personal'])) {
			return $this->vars['personal'][$this->varDay.".".$this->varMonth];
		}
	}
	function loadInit() {
		return @ parse_ini_file("country/init_".$GLOBALS['country'].".ini", true);
	}
}
?>
Return current item: Kalender classes