Location: PHPKode > scripts > Kalendar > kalendar/class_kalendar.php
<?php
/##
#  Title: Class_kalendar.php
#  Date: 2003-02-09
#
#  Functions:
#     function Calendar($colorTop ="FF0000",$colorHead = "CFCFCF",$colorCell= "F3F3F3",$classTop=NULL,$classHead=NULL,$classCell=NULL)
#
#      function show();
#      function GetMonthName($monat_nr)
#      function Feiertag($aktuell_tag,$aktuell_monat,$aktuell_jahr)
#/


class Calendar
{
	var $Day;
	var $Month ;
	var $Year;
  //Color der Tabellezellen Monat
	var $topcolor;
  //Color der Tabellezellen Tag
	var $headcellcolor;
  //Color der Zelle des Tages
	var $cellcolor ;
  //Class der Tabellezellen Monat
	var $classtop;
  //Class der Tabellezellen Tag
	var $classhead;
  //Class der Zelle des Tages
	var $classcell;
  //Color der heutigen Datum
	var $ChosenDayColor = "D0C0F5";
	//URL
  var $ExtraURI = "";

	function Calendar($colorTop ="FF0000",$colorHead = "CFCFCF",$colorCell= "F3F3F3",$classTop=NULL,$classHead=NULL,$classCell=NULL)
	{
    $this->topcolor       = $colorTop;
    $this->headcellcolor  = $colorHead;
    $this->cellcolor      = $colorCell;
    $this->classtop       = $classTop;
    $this->classhead      = $classHead;
    $this->classcell      = $classCell;	
  }

	function Show()
	{
		$monat = $this->Month;
		$jahr = $this->Year;

		$letzteDay = date ("d", mktime (0,0,0,$monat+1,0,$jahr));		
		$monat_nr = date ("n", mktime (0,0,0,$monat+1,0,$jahr));		
		$monat_name = $this->GetMonthName($monat_nr);
    $feierTage= $this->Feiertag($this->Day,$this->Month,$jahr);
		$aantalrijen = 1;
		$spanstart = "<span class=";
		$spanend = "</span>";


		print"<style>\n";
		print"<!--\n";
		print"a {text-decoration:none}\n";
		print"A:hover {text-decoration:underline}\n";
		print"-->\n";
		print"</style>\n";

		// Toon kalender.
		// Month-handling up/down.
		if (($this->Month-1) == 0)
		{
			$monatNext = 12;
			$jahrNext = $this->Year-1;
		}
		else
		{
			$monatNext = $this->Month-1;
			$jahrNext = $this->Year;
		}

		if (($this->Month+1) == 13)
		{
			$monatBack = 1;
			$jahrBack = $this->Year+1;
		}
		else
		{
			$monatBack = $this->Month+1;
			$jahrBack = $this->Year;
		}
		print"<table bgcolor='#000000' border=0 cellpadding=0 cellspacing=1>\n";
    print"  <tr><td colspan=7>";
		print"<table border=0 cellpadding=0 cellspacing=0  width='100%'>\n";
    print"  <tr>\n";
    print"    <td bgcolor=".$this->topcolor." width='10'>\n";

    print"<TABLE WIDTH=20 BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
	  print" <TR>\n";
		print"<TD ROWSPAN=2>\n";
    echo"      <a href='".$PHP_SELF."?ChosenDay=".$this->Day."&ChosenMonth=".$monatNext."&ChosenYear=".$jahrNext.$this->ExtraURI."'>";
		print"	     <IMG SRC='zu.gif' WIDTH=7 HEIGHT=20 ALT='Monat zurück' border=0></a></TD>\n";
		print"<TD>\n";
    echo"      <a href='".$PHP_SELF."?ChosenDay=".$this->Day."&ChosenMonth=".$this->Month."&ChosenYear=".($this->Year+1).$this->ExtraURI."'>";
		print"	<IMG SRC='oben.gif' WIDTH=13 HEIGHT=10 ALT='Jahr vor' border=0></a></TD>\n";
    print"</TR>\n";
    print"<TR>\n";
		print"<TD>\n";
    echo"      <a href='".$PHP_SELF."?ChosenDay=".$this->Day."&ChosenMonth=".$this->Month."&ChosenYear=".($this->Year-1).$this->ExtraURI."'>";
		print"	<IMG SRC='unten.gif' WIDTH=13 HEIGHT=10 ALT='Jahr zu' border=0></a></TD>\n";
    print"</TR>\n";
    print"</TABLE> \n";
    print"</td>\n";
    print"    <td bgcolor=".$this->topcolor." align=center width='110'>\n";
    print"      ".$spanstart.$this->classtop.">".$monat_name." ".$jahr.$spanend;
    print"</td>\n";
    print"    <td bgcolor=".$this->topcolor." width='10'>\n";

    print"<TABLE WIDTH=20 BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
	  print" <TR>\n";
		print"<TD>\n";
    echo"      <a href='".$PHP_SELF."?ChosenDay=".$this->Day."&ChosenMonth=".$this->Month."&ChosenYear=".($this->Year+1).$this->ExtraURI."'>";
		print"	<IMG SRC='oben.gif' WIDTH=13 HEIGHT=10 ALT='Jahr vor' border=0></a></TD>\n";
		print"<TD ROWSPAN=2>\n";
		echo"      <a href='".$PHP_SELF."?ChosenDay=".$this->Day."&ChosenMonth=".$monatBack."&ChosenYear=".$jahrBack.$this->ExtraURI."'>";
		print"	     <IMG SRC='vor.gif' WIDTH=7 HEIGHT=20 ALT='Monat vorwärst' border=0></a></TD>\n";
    print"</TR>\n";
    print"<TR>\n";
		print"<TD>\n";
    echo"      <a href='".$PHP_SELF."?ChosenDay=".$this->Day."&ChosenMonth=".$this->Month."&ChosenYear=".($this->Year-1).$this->ExtraURI."'>";
		print"	<IMG SRC='unten.gif' WIDTH=13 HEIGHT=10 ALT='Jahr zu' border=0></a></TD>\n";
    print"</TR>\n";
    print"</TABLE> \n";
    print"    </td>\n";
    print"  </tr>\n";
    print"</table>\n";
    print"</td></tr>";
    print"  <tr>\n";	// Toon header.
		print"    <td align=center bgcolor=".$this->headcellcolor.">".$spanstart.$this->classhead.">M".$spanend."</td>\n";
    print"    <td align=center bgcolor=".$this->headcellcolor.">".$spanstart.$this->classhead.">D".$spanend."</td>\n";
    print"    <td align=center bgcolor=".$this->headcellcolor.">".$spanstart.$this->classhead.">M".$spanend."</td>\n";
    print"    <td align=center bgcolor=".$this->headcellcolor.">".$spanstart.$this->classhead.">D".$spanend."</td>\n";
    print"    <td align=center bgcolor=".$this->headcellcolor.">".$spanstart.$this->classhead.">F".$spanend."</td>\n";
    print"    <td align=center bgcolor=".$this->headcellcolor.">".$spanstart.$this->classhead.">S".$spanend."</td>\n";
    print"    <td align=center bgcolor=".$this->headcellcolor.">".$spanstart.$this->classhead.">So".$spanend."</td>\n";
    print"  </tr>";
    print"  <tr>";

		$dagnr = date ("w", mktime (0,0,0,$monat,1,$jahr));
		//leere Zellen vor den ersten Monatstag
    if ($dagnr == 0) $dagnr = 7;
		for ($i = 1; $i < $dagnr; $i++)
        print " <td bgcolor=".$this->cellcolor.">".$spanstart.$this->classcell.">&nbsp;".$spanend."</td>\n";


		$monatDays = 1;
		while ($monatDays <= $letzteDay)
		{
			$printDay = date ("j", mktime (0,0,0,$monat,$monatDays,$jahr));

			print "  <td align=center bgcolor=";
			if ($printDay == $this->Day) print $this->ChosenDayColor;
				else print $this->cellcolor;
	
			print">".$spanstart.$this->classcell."><a href='".$PHP_SELF."?ChosenDay=".$printDay."&ChosenMonth=".$monat."&ChosenYear=".$jahr.$this->ExtraURI."'>".$printDay."</a>".$spanend;
			print"</td>\n";
			$dagnr = date ("w", mktime (0,0,0,$monat,$monatDays,$jahr));
			if ($dagnr == 0) $dagnr = 7;
			if ($dagnr == 7)
			{
				print "</tr><tr>\n";	
				$aantalrijen++;
			}
			$monatDays++;
		}


		if ($dagnr == 7)
		{
			$dagnr = 1;
			print "  <td bgcolor=".$this->cellcolor.">".$spanstart.$this->classcell.">&nbsp;".$spanend."</td>\n";
		}
		for ($i = $dagnr; $i <= 6; $i++) print "  <td bgcolor=".$this->cellcolor.">".$spanstart.$this->classcell.">&nbsp;".$spanend."</td>\n";
		print "</tr>\n";

		if ($aantalrijen == 5)
		{
			print "<tr>\n";
			for ($i = 0; $i < 7;$i++) print "  <td bgcolor=".$this->cellcolor.">".$spanstart.$this->classcell.">&nbsp;".$spanend."</td>\n";
			print "</tr>\n";
		}
    if($feierTage)
    {print"<tr bgcolor=".$this->cellcolor."><td colspan=7>".$spanstart.$this->classcell.">".$feierTage.$spanend."</td></tr>";}

		print "</table>\n";

	}

	function GetMonthName($monat_nr)
	{
		switch($monat_nr)
		{
			case 1:$monat_name = 'Januar';	break;
			case 2:$monat_name = 'Februar';	break;
			case 3:$monat_name = 'März'; 		break;
			case 4:$monat_name = 'April';		break;
			case 5:$monat_name = 'Mai';  		break;
			case 6:$monat_name = 'Juni';    break;
			case 7:$monat_name = 'Juli';    break;
			case 8:$monat_name = 'August'; 	break;
			case 9:$monat_name = 'September';	break;
			case 10:$monat_name = 'Oktober';	break;
			case 11:$monat_name = 'November'; break;
			case 12:$monat_name = 'Dezember'; break;
		}
		return $monat_name;
	}

  function Feiertag($aktuell_tag,$aktuell_monat,$aktuell_jahr)
  {
    $tmp=$aktuell_monat."-".$aktuell_tag;
    if($tmp ==date ("n-j", mktime (0,0,0,12,31,$aktuell_jahr)))
      return "Silvester";
    elseif($tmp ==date ("n-j", mktime (0,0,0,1,1,$aktuell_jahr)))
      return "Neujahr";
    elseif($tmp ==date ("n-j", mktime (0,0,0,1,6,$aktuell_jahr)))
      return "Heilig. Drei Könige";
    elseif($tmp ==date ("n-j", mktime (0,0,0,5,1,$aktuell_jahr)))
      return "Tag der Arbeit";
    elseif($tmp ==date ("n-j", mktime (0,0,0,8,15,$aktuell_jahr)))
      return "Maria Himmelfahrt";
    elseif($tmp ==date ("n-j", mktime (0,0,0,10,3,$aktuell_jahr)))
      return "Tag der deutsche Einheit";
    elseif($tmp ==date ("n-j", mktime (0,0,0,11,1,$aktuell_jahr)))
      return "Allerheiligen";
    elseif($tmp ==date ("n-j", mktime (0,0,0,12,24,$aktuell_jahr)))
      return "Heiligabend";
    elseif($tmp ==date ("n-j", mktime (0,0,0,12,25,$aktuell_jahr)))
      return "1. Weihnachtstag";
    elseif($tmp ==date ("n-j", mktime (0,0,0,12,26,$aktuell_jahr)))
      return "2. Weihnachtstag";
  }


}

?>
Return current item: Kalendar