<?php

$day = date('D');
$month = date('M');
$year = date('Y');
echo $day."xx".$month."xx".$year;
$startMonth = sprintf("01 %s %s", $month, $year);
    $unix = strtotime($startMonth);
    $daysInMonth = date("t", $unix);
    $endMonth = sprintf("%s %s %s", $daysInMonth, $month, $year);

    // First and last day of month
    $firstDayOfMonth = date("N", strtotime($startMonth));
    $lastDayOfMonth = date("N", strtotime($endMonth));
echo $firstDayOfMonth;
    // YYYY-MM date format for later use
    $ym = date("Y-m-", $unix);

    // GET ALL EVENTS FOR SELECTED PERIOD
    //........$events = $calLib->getRange($ym."01", $ym.$daysInMonth);

    // DRAWING CALCULATION
    // Determine the number of blank squares before start of month
    $squares = [];
    if ($firstDayOfMonth != 7)
	{
      for ($i=1; $i<$firstDayOfMonth; $i++) 
	  {
        $squares[] = "b";
      }
    }

    // Populate the days of the month
    for ($i=1; $i<=$daysInMonth; $i++) {
      $squares[] = $i;
    }

    // Determine the number of blank squares after end of month
    if ($lastDayOfMonth != 6) {
      $blanks = $lastDayOfMonth==7 ? 6 : 6-$lastDayOfMonth;
      for ($i=0; $i<$blanks; $i++) {
        $squares[] = "b";
      }
    }

    // DRAW ?>
    <table id="calendar">
      <tr class="day">
         <td>Δευτέρα</td> <td>Τρίτη</td> <td>Τετάρτη</td>
        <td>Πέμπτη</td> <td>Παρασκευή</td> <td>Σάββατο</td><td>Κυριακή</td>
      </tr>
      <tr><?php
        $total = count($squares);
        for ($i=1; $i<=$total; $i++) {
          $thisDay = $squares[$i-1];
          if ($thisDay=="b") {
            echo "<td class='blank'></td>";
          } else {
            $fullDay = sprintf("%s%02u", $ym, $thisDay);
            printf("<td onclick=\"cal.show('%s')\">%s%s</td>", 
              $fullDay, $thisDay,
              $events[$fullDay] ? "<div class='evt'>" . $events[$fullDay] . "</div>" : ""
            );
          }
          if ($i!=$total && $i%7==0) { echo "</tr><tr>"; }
        }
      ?></tr>
    </table>
    <?php 