<?php
/*Skrypt pochodzi z książki "PHP. 101 praktycznych skryptów"
  autor: Marcin Lis                    http://marcinlis.com*/

function printCalendar()
{
  $year = date("Y");
  $monthNum = date("n");
  $daysofmonth = date("t");
  $dayofweek = date("w");
  $dayofmonth = date("j");
  $firstdayofmonth = date("w", mktime(0,0,0,$monthNum, 1, $year));

  if($dayofweek == 0) $dayofweek = 7;
  if($firstdayofmonth == 0) $firstdayofmonth = 7;

  switch($monthNum){
    case 1 : $monthName = "Styczeń";break;
    case 2 : $monthName = "Luty";break;
    case 3 : $monthName = "Marzec";break;
    case 4 : $monthName = "Kwiecień";break;
    case 5 : $monthName = "Maj";break;
    case 6 : $monthName = "Czerwiec";break;
    case 7 : $monthName = "Lipiec";break;
    case 8 : $monthName = "Sierpień";break;
    case 9 : $monthName = "Wrzesień";break;
    case 10 : $monthName = "Październik";break;
    case 11 : $monthName = "Listopad";break;
    case 12 : $monthName = "Grudzień";break;
  }

  echo("<table border = \"1\"><tr>");
  echo("<td bgcolor=\"yellow\" align=\"center\" colspan=\"7\">");
  echo($monthName." ".$year);
  echo("</td></tr>\n");
  ?>
  <tr>
  <td align="center" bgcolor="#FFC0CB">Pn</td>
  <td align="center" bgcolor="#FFC0CB">Wt</td>
  <td align="center" bgcolor="#FFC0CB">Sr</td>
  <td align="center" bgcolor="#FFC0CB">Cz</td>
  <td align="center" bgcolor="#FFC0CB">Pi</td>
  <td align="center" bgcolor="#FFC0CB">So</td>
  <td align="center" bgcolor="#FFC0CB">Nd</td>
  </tr><tr>
  <?
  $j = $daysofmonth + $firstdayofmonth - 1;

  for($i = 0; $i < $j; $i++){
    if($i < $firstdayofmonth - 1){
      echo("<td bgcolor=\"white\"></td>\n");
      continue;
    }
    if(($i % 7) == 0){
      echo("</tr><tr>");
    }
    if(($i - $firstdayofmonth + 2) == $dayofmonth){
      $color = "yellow";
    }
    else{
      $color = "green";
    }
    echo("<td bgcolor=\"$color\" align=\"center\">");
    echo($i - $firstdayofmonth + 2);
    echo("</td>\n");
  }
  echo("</tr></table>");
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<title>Kalendarz</title>
</head>
<body>
<div>
<?php printCalendar(); ?>
</div>
</body>
</html>
