<?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.
*/
  echo '<p class="Headline">'.$L_Headline01.'</p>';
  if (!loggedIn())
    echo $L_003;
  else {
    // Inhalt hier einfügen  
      if (AnzahlAllerGigsInDatenbank()=='0') {
        echo $L_156.'<br /><br />'; }
      else {
        // Publish or Not
          if (isset($_POST['GigPublish_x'])) { changeGigPublishing ($_POST['GigID']); }
        // IsPrivate or Not
          if (isset($_POST['GigIsPrivate_x'])) { changeGigIsPrivate ($_POST['GigID']); }
        // Seiten-Navigation definieren
        // Session-Variable 'Zeitraum' definieren
          if (isset($_POST['Zeitraum'])) {
            $_SESSION["Zeitraum"] = $_POST['Zeitraum'];
            $_SESSION['CurrentPageShowAllGigs']=1; }
          if (!isset($_SESSION["Zeitraum"])) {
            $_SESSION["Zeitraum"] = "future"; }
          $Zeitraum = $_SESSION["Zeitraum"];
        // Session-Variable 'Anzahl' definieren
          if (isset($_POST['Anzahl'])) {
            $_SESSION["Anzahl"] = $_POST['Anzahl'];
            $_SESSION['CurrentPageShowAllGigs']=1; }
          if (!isset($_SESSION["Anzahl"])) { $_SESSION["Anzahl"] = "25"; }
          $EntriesPerPage = $_SESSION["Anzahl"];
        // Session-Variable 'GigStatus' definieren
          if (isset($_POST['AuswahlGigStatus'])) {
            $_SESSION["AuswahlGigStatus"] = $_POST['AuswahlGigStatus'];
            $_SESSION['CurrentPageShowAllGigs']=1; }
          if (!isset($_SESSION["AuswahlGigStatus"])) {
            $_SESSION["AuswahlGigStatus"] = "all"; }
          $AuswahlGigStatus = $_SESSION["AuswahlGigStatus"];
        // Parameter für Navigation definieren
          $NumberOfGigsInPeriod = AnzahlGigsImZeitraum($Zeitraum, $AuswahlGigStatus);
          if ($EntriesPerPage!='all') {
            $NumberOfPages = ceil($NumberOfGigsInPeriod/$EntriesPerPage); }
          else {
            $NumberOfPages = 0;
            $EntriesPerPage = 99999; } // Bugfix v1.2.77_011
          if (isset($_REQUEST['page'])) {
            $_SESSION['CurrentPageShowAllGigs'] = $_REQUEST['page']; }
          else
            $_SESSION['CurrentPageShowAllGigs'] = 1; // For new Pagination since v1.2.76_016
          if (!isset($_SESSION['CurrentPageShowAllGigs'])) {
            $_SESSION['CurrentPageShowAllGigs'] = "1"; }
          $CurrentPage = $_SESSION['CurrentPageShowAllGigs'];
          $obersterGig  = $EntriesPerPage*($CurrentPage-1);
        // Ansichts-Parameter
        echo '<div id="Box_ParameterShowGigs">
                <form method="post" action="index.php?submenue=calendar&amp;content=backend_showAllGigs" accept-charset="UTF-8">
                  <fieldset>
                    <input type="hidden" name="thread[threadid]" value="$thread[threadid]" />                 
                    <select name="Anzahl" onchange="this.form.submit()">
                      <option value="all"'; if ($EntriesPerPage=="all") echo ' selected="selected"'; echo'>'.$L_ShowAllGigs.'</option>';
                    for ($i=10; $i<=100; $i++) {
                      echo '<option value="'.$i.'"'; if ($EntriesPerPage==$i) echo ' selected="selected"'; echo'>'.$i.'</option>'; }
                  echo '</select>
                  </fieldset>
                </form>
                <form method="post" action="index.php?submenue=calendar&amp;content=backend_showAllGigs" accept-charset="UTF-8">
                  <fieldset>
                    <input type="hidden" name="thread[threadid]" value="$thread[threadid]" />
                    <select name="Zeitraum" onchange="this.form.submit()">
                      <option value="all"'; if ($Zeitraum=="all") echo ' selected="selected"'; echo'>'.$L_ShowAllGigs.'</option>
                      <option value="future"'; if ($Zeitraum=="future") echo ' selected="selected"'; echo'>'.$L_ShowFutureGigs.'</option>
                      <option value="past"'; if ($Zeitraum=="past") echo ' selected="selected"'; echo'>'.$L_ShowPastGigs.'</option>
                    </select>
                  </fieldset>
                </form>        
                <form method="post" action="index.php?submenue=calendar&amp;content=backend_showAllGigs" accept-charset="UTF-8">
                  <fieldset>
                    <input type="hidden" name="thread[threadid]" value="$thread[threadid]" />
                    <select name="AuswahlGigStatus" onchange="this.form.submit()">
                      <option value="all"'; if ($AuswahlGigStatus=="all") echo ' selected="selected"'; echo'>'.$L_ShowAllGigs.'</option>
                      <option value="Gig"'; if ($AuswahlGigStatus=="Gig") echo ' selected="selected"'; echo'>'.$L_GigStatusGig.'</option>
                      <option value="Option"'; if ($AuswahlGigStatus=="Option") echo ' selected="selected"'; echo'>'.$L_GigStatusOption.'</option>
                      <option value="Rehearsal"'; if ($AuswahlGigStatus=="Rehearsal") echo ' selected="selected"'; echo'>'.$L_GigStatusRehearsal.'</option>
                      <option value="Blocked"'; if ($AuswahlGigStatus=="Blocked") echo ' selected="selected"'; echo'>'.$L_GigStatusBlocked.'</option>
                    </select>
                  </fieldset>
                </form>';
        // Attribute-Editor
      echo '<form method="post" action="index.php?submenue=calendar&amp;content=backend_editAttributes&amp;referer=backend_showAllGigs&amp;job=0&amp;id=0&amp;timestamp=0" accept-charset="UTF-8">
               <fieldset>
                 <input style="font-size:0.9em;" type="submit" value="'.$L_Button28.'" class="SmallButton" />
                 <input type="hidden" name="Selector" value="backend_showAllGigs" />
                  <input type="hidden" name="referer" value="backend_showAllGigs" />
               </fieldset>
             </form>';
        echo getCalendarBackEndPagination();
        
        echo '</div>';
      // Datensatz-Ausgabe festlegen
        $TimestampOfToday = getTimestampFromDate(date("d"), date("m"), date("y"));
        $SQLQuery = "SELECT * FROM ".$prefix."gigs";
        if ($Zeitraum!='all' OR $AuswahlGigStatus!='all') {
          $SQLQuery = $SQLQuery.' WHERE '; }
        if ($Zeitraum =="future") {
          $SQLQuery = $SQLQuery."GigDate>=".$TimestampOfToday; }
        if ($Zeitraum =="past") {
          $SQLQuery = $SQLQuery."GigDate<".$TimestampOfToday; }
        if ($Zeitraum!='all' AND $AuswahlGigStatus!='all') {
          $SQLQuery = $SQLQuery.' AND '; }
        if ($AuswahlGigStatus!='all') {
          $SQLQuery = $SQLQuery." GigStatus='".$AuswahlGigStatus."'"; }
        if ($Zeitraum =="future") {
          $SQLQuery = $SQLQuery." order by GigDate, GigBeginning"; }
        if ($Zeitraum =="past") {
          $SQLQuery = $SQLQuery." order by GigDate DESC, GigBeginning DESC"; }
        if ($Zeitraum =="all") {
          $SQLQuery = $SQLQuery." order by GigDate"; }
        $SQLQuery = $SQLQuery." LIMIT ".$obersterGig.", "; 
        if ($EntriesPerPage=='all') {
          $SQLQuery = $SQLQuery.$NumberOfGigsInPeriod; }
        else {
          $SQLQuery = $SQLQuery.$EntriesPerPage; }
        $Result = mysqli_query($db, $SQLQuery);

      // Ausgabe der Gig-Übersicht
        if ($NumberOfGigsInPeriod!=0) { // Einträge vorhanden
          $UserBackendCalenderListCols = getCurrentUserVar('UserBackendCalenderListCols');
          if ($UserBackendCalenderListCols!="")
            $Attribute = explode(', ', $UserBackendCalenderListCols);
          else
            $Attribute = array();
          echo '<table id="WideTable" summary="Tabelle_Zeige-Gigs">';
          // Spalten definieren
            echo '<colgroup>';
            if (IsUserAdmin()) { echo '<col class="SpalteIcon" />'; }
            echo '<col class="SpalteIcon" />
                  <col class="GigDate" />';
            if (!in_array("GigStatus", $Attribute)) { // to avoid two columns Status in print
              echo '<col class="GigStatus" />'; }
            for ($i=0; $i<(count($Attribute)); $i++)
              echo '<col class="'.$Attribute[$i].'" />';
            echo '</colgroup>';
          // Spaltenköpfe definieren
            echo '<tr>';
            if (IsUserAdmin())
              echo '<th class="Screen">&nbsp;</th>';
            echo '<th class="Screen">&nbsp;</th>
              <th>'.$L_GigDate.'</th>';
            if (!in_array("GigStatus", $Attribute)) { // to avoid two columns Status in print
              echo '<th class="GigPrint">'.$L_GigStatus.'</th>'; }
            // Definierte Spalten
              for ($x = 0; $x<count($Attribute); $x++) {
                if ($x!=count($Attribute)-1) echo '<th>';
                  else echo '<th class="TabellenSpalte_Rechts">';
                switch ($Attribute[$x]) {
                  case "GigIsPrivate": echo '<img src="images/private.gif" alt="'.$L_Private.'" title="'.$L_Private.'" />'; break;
                  case "GigPublish": echo '<img src="images/frontend.gif" alt="'.$L_Publish.'" title="'.$L_Publish.'" />'; break;
                  case "GigBeginning": echo '<img src="images/time.gif" alt="'.$L_GigBeginning.'" title="'.$L_GigBeginning.'" />'; break;
                  default: echo ''.${'L_'.$Attribute[$x]}; break; }
                echo "</th>"; }
            echo '</tr>';
          // Zeilen ausgeben
          while ($row = mysqli_fetch_array($Result)) {
            extract($row);
            echo '<tr>';
            if (IsUserAdmin()) {
              echo '<td class="Screen '.$GigStatus.'">
                      <a href="index.php?submenue=calendar&amp;content=backend_delGig&amp;id='.$GigID.'">
                        <img src="images/delete.gif" alt="'.$L_009.'" title="'.$L_009.'" /></a>
                    </td>
                    <td class="Screen '.$GigStatus.'">
                      <a href="index.php?submenue=calendar&amp;content=backend_addGig&amp;job=edit&amp;id='.$GigID.'">
                        <img src="images/edit.gif" alt="'.$L_010.'" title="'.$L_010.'" /></a>
                    </td>'; }
            else {
              echo '<td class="Screen '.$GigStatus.'">
                      <a href="index.php?submenue=calendar&amp;content=backend_showGig&amp;id='.$GigID.'">
                        <img src="images/show.png" alt="'.$L_153.'" title="'.$L_153.'" /></a>
                    </td>'; }
            // GigDate
            echo '<td class="'.$GigStatus.'">'.date($SetupBackendDateFormat, $GigDate).'</td>';
            // GigStatus for printing only
            if (!in_array("GigStatus", $Attribute)) { // to avoid two columns Status in print
              echo '<td class="'.$GigStatus.' GigPrint">'.${'L_GigStatus'.$GigStatus}.'</td>'; }
            // Definierte Spalten
            for ($x=0; $x<count($Attribute); $x++) {
              if ($x!=count($Attribute)-1)
                echo '<td class="'.$GigStatus.'">';
              else
                echo '<td class="'.$GigStatus.' TabellenSpalte_Rechts">';
              if ($Attribute[$x]=="GigLocation")
                include('calendar/includes/showAllGigs/GigLocation.php');
              elseif (${$Attribute[$x]}!="")
                include('calendar/includes/showAllGigs/'.$Attribute[$x].'.php');
              echo '</td>'; }
            echo '</tr>'; }
          echo '</table>';
          include("calendar/backend_legende.php"); }
        else {
          echo '<br />'.$L_154."<br /><br />"; }}
      if (IsUserAdmin()) {
        echo '<a href="index.php?submenue=calendar&amp;content=backend_addGig&amp;job=add">
                <img src="images/add.gif" alt="'.$L_002.'" title="'.$L_002.'" /></a>'; }
      include('includes/toolbar.php');
    // Inhalt zuende      
  }
?>