<?php 

$today = new DateTimeEx();

if($day == null)
{
  //echo("<div class=\"page-header\">");
  echo("<h2><div class=\"icon-calendar\"></div> ".t('Gate')." $gate->GateName - ");
  echo(ucwords(DateHelper::getMonthName($month))." $year");
  echo("</h2>\n");

  echo("<table width=\"100%\"><tr><td align=\"left\"><h5><a href=\"$prev_month_url\">$prev_month_text</a></h5></td><td align=\"center\"><h5><a href=\"?gate=$gate->Gate&year=$today->year&month=$today->month\">".t('Current month')."</a></h5></td><td align=\"right\"><h5><a href=\"$next_month_url\">$next_month_text</a></h5></td></tr></table>\n");

  $index=0;
  echo("<table width=\"100%\" height=\"100%\" cellspacing=\"10px\" bordercolor=\"black\" border=\"2px\">\n");
  foreach($days as $d)
  {
    if($index%7==0)
    {
      if($index > 0)
        echo("</tr>\n");
      echo("<tr height=\"50px\">\n");
    }
    echo("<td bgcolor=\"#F2F2F2\">\n");//echo("<td bgcolor=\"$d->color\">\n");
    //echo("<font color=\"$d->fontcolor\">\n");
    
    //$heightT3S_tr = ' style="height: 20%;"';
    $heightT3S_td = ' style="height: 20%;"';
    if($d->isDay) echo("<table border=\"0\" width=\"100%\" height=\"100%\"><tr $heightT3S_tr><td $heightT3S_td>");// T3S = tabella 3 sezioni (numero/fasce/permessi)
        
    echo("<center>");
    if($d->isDay)
      echo("<a href=\"?gate=$gate->Gate&year=$year&month=$month&day=$d->day\">");
    if($d->isDay && $d->dateex->isToday())
      echo("<u><i>");
    if($d->isDay)
      echo("<h3>$d->text</h3><br>");
    else
      echo($d->text);
    if($d->isDay && $d->dateex->isToday())
      echo("</i></u>");
    if($d->isDay)
      echo("</a>");
    echo("</center>");
    
    if($d->isDay) echo("</td></tr><tr $heightT3S_tr><td $heightT3S_td>");// T3S fasce
    
    if($d->isDay)
    {
      $tags = $gate->getZtlIconTagsForDay($d->dateex);
      if(!(empty($tags)))
      {
        echo("<center>");
        echo $tags;
        echo("<br><br>");
        echo("</center>");
      }
    }
    
    if($d->isDay) echo("</td></tr><tr $heightT3S_tr><td $heightT3S_td>");// T3S permessi
    
    if($d->isDay)
    {  /*
      $tags = $gate->getZtlIconTagsForDay($d->dateex);
      if(!(empty($tags)))
      {
        echo("<center>");
        echo $tags;
        echo("<br><br>");
        echo("</center>");
      }
    
       echo("<center>");
      echo(t("Rules").':');
      echo("<br />");
      echo(t("Active plate authorizations").':');
      echo("</center>");*/
    }
    
    if($d->isDay) echo("</tr></table>");// T3S
        
    //echo("</font>");
    echo("</td>");
    $index++;
  }
  echo("</td></tr></table>\n");

  //echo("</div>\n");
}
else
{
  $theDay= new DateTimeEx();
  $theDay->year = $year;
  $theDay->month = $month;
  $theDay->day = $day;

  //echo("<div class=\"page-header\">");
  echo("<h2><div class=\"icon-time\"></div> ".t('Gate')." $gate->GateName - ");
  echo("<a href=\"?gate=$gate->Gate&year=$year&month=$month\">".ucwords($theDay->getMonthName())." $theDay->year</a>");
  echo("  ".$theDay->getDayOfWeekName()." $theDay->day </h2>\n");

  echo('<div class="row">');

  $anomalia = false;
  echo("<table class=\"table table-condensed span12\">");
  echo("<thead><tr><th>".t('Start time')."</th><th>".t('End time')."</th><th>".t('Status')."</th><th>".t('Active plate authorizations')."</th></tr></thead>");
  echo("<tbody>");
  foreach($hours as $zone)
  {
    echo("<tr>");
    echo("<td>");
    echo($zone->inizia->datetime);
    echo("</td>");
    echo("<td>");
    echo($zone->finisce->datetime);
    echo("</td>");
    echo("<td>");

    $ztl = null;
    if($zone->inizia->ztl!=null)
      $ztl = $zone->inizia->ztl;
    else
    {
      if($zone->inizia->ztl_last!=null)
        $ztl = $zone->inizia->ztl_last;
    }

    if($ztl!=null)
      echo($ztl->getIconTag());
      
    echo(" <font color=\"".($zone->inizia->limited ? 'red':'green')."\">".t($zone->inizia->limited ? 'Limited access':'Free access')."</font>");
    echo("</td>");
    echo("<td>");    
    foreach($zone->inizia->exceptions as $excTimeSchedule)
    {
      if($ztl->time != null && $ztl->time->ID == $excTimeSchedule->ID)
      {
        echo(" ".$excTimeSchedule->getIconTagFinal(null,24,'border: thin; border-color: red; border-style: solid;').'<font color="red"><i>*</i></font>');
        $anomalia = true;
      }
      else
        echo(" ".$excTimeSchedule->getIconTagFinal());
    }
    echo("</td>");
    echo("</tr>");
  }
  if($anomalia)
    echo('<tr><td colspan="4" align="right"><font color="red"><i>*'.t('Anomaly found: some plate authorization(s) have the same Time Schedule of the current gate!').'</i></font></td></tr>');
  echo("</tbody>");
  echo("</table>");
  
  //echo("</div>");
}

?>