<?php
/*
    CREATIVE COMMONS - Attribution-No Derivative Works 3.0 Germany:
    - You may not alter, transform, or build upon this work.
    - Dieses Werk darf nicht bearbeitet oder in anderer Weise verändert werden.
*/
  $Path = str_replace('\\','/', __FILE__);
  $Path = str_replace('calendar/month.php', '', $Path);

  include_once($Path."gigkalender.ini.php");
  include_once($Path."functions/standard.php");
  include_once($Path."includes/frontend_language_selector.php");
  
  if (isset($_REQUEST['month'])) { $monat=$_REQUEST['month']; }
    else { $monat = date("n"); }
  if (isset($_REQUEST['year'])) { $Jahr=$_REQUEST['year']; }
    else { $Jahr = date("Y"); }
  if (isset($_REQUEST['GigID']))
  {
    $Timestamp = getGigVarFromGigID ($_REQUEST['GigID'], 'GigDate');
    $monat=date("n", $Timestamp);
    $Jahr=date("Y", $Timestamp);
  }

  $ErsterWochentag = getWeekdayFromDate (1, $monat, $Jahr);
  $TimestampFromToday = strtotime('today');
  $Tag = 1;
  $Zelle = 1;
  $NumberOfDaysInMonth = getNumberOfDaysInMonth ($monat, $Jahr);
  
  $MonthBackwards = $monat-1;
  $YearBackwards = $Jahr;
  if ( $MonthBackwards == '0') 
  {
    $MonthBackwards = '12';
    $YearBackwards  = $Jahr-1;
  }
  $MonthForwards = $monat+1;
  $YearForwards = $Jahr;
  if ( $MonthForwards == '13') 
  {
    $MonthForwards = '1';
    $YearForwards  = $Jahr+1;
  }
  // Kalender-Grenzen bestimmen
    $TimestampOfFirstDayOfShownMonth = strtotime( $Jahr.'-'.$monat.'-1');
    // Limit der Vergangenheit bestimmen
      $LimitPastMonth = date("m")-getSetup('SetupFrontendCalendarCurrentMonthLimitPast');
      $LimitPastYear = date("y");
      if ($LimitPastMonth<1)
      {
        $LimitPastMonth = $LimitPastMonth+12;
        $LimitPastYear--;
      }
    // Limit der Zukunft bestimmen
      $LimitPast = strtotime($LimitPastYear.'-'.$LimitPastMonth.'-1');
      $LimitFutureMonth = date("m")+getSetup('SetupFrontendCalendarCurrentMonthLimitFuture');
      $LimitFutureYear = date("y");
      if ($LimitFutureMonth>12)
      {
        $LimitFutureMonth = $LimitFutureMonth-12;
        $LimitFutureYear++;
      }
      $LimitFuture = strtotime($LimitFutureYear.'-'.$LimitFutureMonth.'-1');
  echo '<div id="CalendarCurrentMonth">
        <table summary="CalendarCurrentMonth">
          <tr>';
  // URL bestimmen
    $URL = getFrontendURL ( 'SetupFrontendCalendarCurrentMonthURL' );
  echo '<td class="NavigationBackwards"><a href="'.$URL.'year='.$YearBackwards.'&amp;month='.$MonthBackwards.'">';
  if ( $TimestampOfFirstDayOfShownMonth>$LimitPast ) echo '&laquo;';
    else echo ' ';
  echo '</a></td>
            <td colspan="5"><span class="MonthName">'.getMonthNameFromMonthNumber ($monat).' '.$Jahr.'</span></td>
            <td class="NavigationForwards"><a href="'.$URL.'year='.$YearForwards.'&amp;month='.$MonthForwards.'">';
  if ( $LimitFuture>$TimestampOfFirstDayOfShownMonth ) echo '&raquo;';
    else echo ' ';
  echo '</a></td>
          </tr>
          <tr id="Weekdays">
            <td>'.$L_Mo.'</td>
            <td>'.$L_Tu.'</td>
            <td>'.$L_We.'</td>
            <td>'.$L_Th.'</td>
            <td>'.$L_Fr.'</td>
            <td>'.$L_Sa.'</td>
            <td>'.$L_Su.'</td>
          </tr>
          <tr>';
          
  for ($z=1; $z<=6 AND $Tag <= $NumberOfDaysInMonth; $z++)
      {
        for ($s=1; $s<=7; $s++)
        {
          if (($Zelle < $ErsterWochentag) OR ($Tag > $NumberOfDaysInMonth)) {echo "<td></td>";}
          else
          {
            $Timestamp = strtotime($Jahr.'-'.$monat.'-'.$Tag);
            if ( !getDateIsInFuture($Timestamp) AND !getSetup('SetupFrontendCalendarCurrentMonthShowPastGigs') )
            {
              $PublishedGigPresent = false;
            }
            else  $PublishedGigPresent = publishedGigOnTimestamp($Timestamp);
            echo '<td>';
            echo '<div class="'.getWeekdayNameFromDate ($Tag, $monat, $Jahr).'">';
            if ($Timestamp == $TimestampFromToday) { echo '<span class="Today">'; }

            // Wochentags-Zahl mit Link
            if ( !$PublishedGigPresent )
            { 
              echo $Tag;
            }
            else
            {
              echo '<div class="Gig">';
              $ToolTip = GetTooltip($Timestamp);
              $URL = getFrontendURL ( 'SetupFrontendCalendarGigDetailsURL' );
              $URL = $URL.'&amp;year='.$Jahr.'&amp;month='.$monat;
              echo '<form style="margin: 0; padding: 0; display: inline;" id="form'.$Timestamp.'" method="post" action="'.$URL.'" accept-charset="UTF-8">
                      <p style="margin: 0; padding: 0; display: inline;" title="'.$ToolTip.'">
                        <input type="hidden" name="Timestamp" value="'.$Timestamp.'" />
                        <a href="'.$URL.'" onclick="javascript:document.forms[\'form'.$Timestamp.'\'].submit()">'.$Tag.'</a>
                      </p>
                    </form>';
              echo '</div>';
            }
            if ($Timestamp == $TimestampFromToday) {echo "</span>"; }
            echo "</div>";
            echo "</td>\n";
            $Tag++;
          }
          if ($s == "7")
          {
            if ($z < "6" AND $Tag <= $NumberOfDaysInMonth)
            {
              echo "</tr><tr>";
 	          }
            else
            {
              echo "</tr>";
            }
          }
          $Zelle++;
        }
      }
  echo '</table></div>';
?>