<?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; }
// Sort by AM and PM
switch ($SetupFrontendCalendarPeriodSelector) {
  case 'all': $SQL .= ', STR_TO_DATE(GigBeginning, "%l:%i %p") ASC'; break;
  case 'future': $SQL .= ', STR_TO_DATE(GigBeginning, "%l:%i %p") ASC'; break;
  case 'past': $SQL .= ', STR_TO_DATE(GigBeginning, "%l:%i %p") DESC'; break; }
// Limit number of results
$SQL .= " LIMIT ".getSetup('SetupFrontendCalendarMaxAmountOfGigs');
$Result = mysqli_query($db, $SQL);
$gigCount = mysqli_num_rows ($Result);
?>