<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?
  
class kalendar
  
{
    var
$mesic;
    var
$rok;
    function
kalendar ($mesic, $rok)
    {
      
$this->mesic=$mesic;
      
$this->rok=$rok;
    }
    
    function
PocetDnu ()
    {
      return
cal_days_in_month(CAL_GREGORIAN, $this->mesic, $this->rok);
    }

    function
PrvniDen ()
    {
      
$anglickeporadi = date("w", mktime(0, 0, 0, $this->mesic, 1, $this->rok));
      return (
$anglickeporadi==0) ? 7 : $anglickeporadi;
    }

    function
Bunka ($radek, $sloupec, $PrvniDen, $PocetDnu)
    {
      
$dny=Array(1=>"Po", "Út", "St", "Čt", "Pá", "So", "Ne");
      if (
$sloupec==1) return $dny[$radek];
      
$chcivratit = ($sloupec-2)*7 + $radek - $PrvniDen+1;
      if (
$chcivratit<1 || $chcivratit>$PocetDnu) return "&nbsp;"; else return $chcivratit;
    }

    function
vypis ()
    {
      
$mesice=Array(1=>"leden", "únor", "březen", "duben", "květen", "červen", "červenec", "srpen", "září", "říjen", "listopad", "prosinec");
      if (!
is_numeric($this->mesic))
      {
        echo
"Měsíc musí být číslo!";
        return;
      }
      if (!
is_numeric($this->rok))
      {
        echo
"Rok musí být číslo!";
        return;
      }
      if (
$this->mesic<1 || $this->mesic>12)
      {
        echo
"Měsíc musí být číslo od 1 do 12";
        return;
      }
      if (
$this->rok<1980 || $this->rok>2050)
      {
        echo
"Rok musí být číslo od 1980 do 2050";
        return;
      }
      
$PocetDnu = $this->PocetDnu ($this->mesic, $this->rok); $PrvniDen = $this->PrvniDen($this->mesic,$this->rok);
      
$sloupcu = date("W", mktime(0, 0, 0, $this->mesic, $PocetDnu-7, $this->rok)) - date("W", mktime(0, 0, 0, $this->mesic, 1+7, $this->rok))+4;
      echo
"<TABLE border=\"1\" style=\"border-collapse: collapse\" width=\"",$sloupcu*30,"\">";
      echo
"<TR><TD colspan=$sloupcu width=\"",$sloupcu*30,"\" align=\"center\">".$mesice[$this->mesic]."&nbsp;".$rok."</TD></TR>\n";
      for (
$radek=1;$radek<=7;$radek++)
      {
        echo
"<TR align=\"center\">";
        for (
$sloupec=1; $sloupec<=$sloupcu; $sloupec++) echo "<TD width=\"30\">".$this->Bunka($radek, $sloupec, $PrvniDen, $PocetDnu)."</TD>";
        echo
"</TR>\n";
      }
      echo
"</TABLE>";
    }
  }

  
$prvni_kalendar= new kalendar(7,2004);
  
$prvni_kalendar->vypis();

?>