<?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.
*/
  $SQL = "SELECT * FROM ".$prefix."gigs WHERE GigPublish=1 AND (GigStatus='Gig'";
  // respect also optional gigs?
  if (getSetup('SetupFrontendAllowOptionalGigs')==1)
    $SQL .= " OR GigStatus='Option'";
  // close bracket
  $SQL .= ")";
  // filter private gigs
  if (getSetup('SetupFrontendAllowPrivateGigs')==0)
    $SQL .= " AND GigIsPrivate!=1";
  // Limit to defined period
  $Timestamp = getTimestampFromDate(date("d"), date("m"), date("y"));
  switch ($SetupFrontendCalendarPeriodSelector) {
    case 'future': $SQL .= ' AND GigDate>='.$Timestamp; break;
    case 'past': $SQL .= ' AND GigDate<'.$Timestamp; break; }
  // ???
  $SetupFrontendCalendarArtistFilter = trim($SetupFrontendCalendarArtistFilter);
  if ($SetupFrontendCalendarArtistFilter!='')
    $SQL .= " AND GigArtist='".$SetupFrontendCalendarArtistFilter."' ";
  // Define the sorting
  switch ($SetupFrontendCalendarPeriodSelector) {
    case 'all': $SQL .= ' ORDER by GigDate'; break;
    case 'future': $SQL .= ' ORDER by GigDate'; break;
    case 'past': $SQL .= ' ORDER by GigDate DESC'; break; }
  // Limit number of results
  $SQL .= " LIMIT ".getSetup('SetupFrontendCalendarMaxAmountOfGigs');
  $Result = mysqli_query($db, $SQL);
  $gigCount = mysqli_num_rows ($Result);
?>