<?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.
*/
  $GigCountry = '';
  $GigDistrict = '';
  $GigPostalCode = '';
  $GigDate  = '';
  $GigCity = '';
  $GigEvent = '';
  $GigEventURL = '';
  $GigVenue = '';
  $GigVenueURL = '';
  $GigOrganizer = '';
  $GigOrganizerURL = '';
  $GigLineup = '';
  $GigVisitors = '';
  $GigStageBuilding = '';
  $GigBeginning = '';
  $GigDuration = '';
  $GigEnding = '';
  $GigNotes = '';
  $GigEntranceFee = '';
  $GigDateDay = '';
  $GigDateMonth = '';
  $GigDateYear = '';
  $GigArtist = '';
  $GigArtistURL = '';
  $GigStatus = '';
  $GigPublish = '';
  $GigIsPrivate = '';
  $GigDateOfLastEdit = '';
  $GigLastEditor = '';
  $GigAddedFrom = '';
  $GigDateOfAdding = '';
  $GigIDToEdit = '';
  // POST-Variablen definieren
    if ( isset($_POST['senden']) )
    {
      foreach ($_POST as $key => $value)
      {
        if (get_magic_quotes_gpc()) $$key = stripslashes($value);
        else $$key = $value;
      }
      // Formular überprüfen
        if ( $senden
             && $GigDateDay
             && $GigDateMonth
             && $GigDateYear
             && checkGigDatum ( $GigDateDay, $GigDateMonth, $GigDateYear )
             && ( !$GigEventURL OR checkURL( $GigEventURL) )
             && ( !$GigVenueURL OR checkURL( $GigVenueURL ) )
             && ( !$GigOrganizerURL OR checkURL( $GigOrganizerURL) )
             && ( !$GigArtistURL OR checkURL( $GigArtistURL ) )
             && $GigStatus
             && $GigPublish!=""
             && $GigIsPrivate!=""
             && (
                  ( $_REQUEST['job']=='add' AND ( getSetup('SetupAllowDoubleDates')
                                                  OR !testDoppelteGigs($GigDateDay, $GigDateMonth, $GigDateYear) ))
                  OR
                  ( $_REQUEST['job']=='edit' AND (  $_REQUEST['GigDate']==getTimestampFromDate($GigDateDay, $GigDateMonth, $GigDateYear)
                                                    OR
                                                    (
                                                      getSetup('SetupAllowDoubleDates')
                                                      OR !testDoppelteGigs($GigDateDay, $GigDateMonth, $GigDateYear)
                                                    )
                                                 )
                  )
                )
           )
        {
          $FormularKorrektAusgefuellt = true;
        }
        else 
        { 
          $FormularKorrektAusgefuellt = false; 
          $GigIDToEdit = '';
          $GigDateOfAdding = '';
          $GigAddedFrom = '';
          $GigDateOfLastEdit = '';
          $GigLastEditor = '';
        }
    }
    else
    {  
      if ( isset($_REQUEST['id'])  ) $GigID = $_REQUEST['id'];
        else $GigID ="";
      if ($_REQUEST['job']=='edit')
      {
        $SQLQuery = "SELECT * FROM ".$prefix."gigs Where GigID = '$GigID'";
        $Result = mysqli_query($db, $SQLQuery);
        while ($row = mysqli_fetch_array($Result)) { extract($row); }
      }
      if ( $GigID )
      {
        $GigDateDay = date('d', $GigDate);
        $GigDateMonth = date('m', $GigDate);
        $GigDateYear = date('Y', $GigDate);
      }
      $FormularKorrektAusgefuellt = false;
      $senden = ''; 
    }
  // Überschrift ausgeben
    echo '<p class="Headline">';
    if ($_REQUEST['job']=='add') echo $L_Headline16;
    if ($_REQUEST['job']=='edit') echo $L_Headline15;
    echo '</p>';
  if ( !IsUserAdmin() ) { echo $L_015; }
  else
  {
    // Inhalt hier einfügen
      if ($FormularKorrektAusgefuellt == true)
      { 
          $Gig = array( $GigID,
          	            $GigDateDay,
          	            $GigDateMonth,
                        $GigDateYear,
                        $GigCountry,
                        $GigDistrict,
                        $GigPostalCode,
                        $GigCity,
                        $GigEvent,
                        $GigEventURL,
                        $GigEntranceFee,
                        $GigVenue,
                        $GigVenueURL,
                        $GigOrganizer,
                        $GigOrganizerURL, 
                        $GigArtist,
                        $GigArtistURL,                       
                        $GigLineup,
                        $GigVisitors,
                        $GigStageBuilding,
                        $GigBeginning,
                        $GigDuration,
                        $GigEnding,
                        $GigNotes,
                        $GigStatus,
                        $GigPublish,
                        $GigIsPrivate,
                        '',
                        '',
                        getCurrentUserVar("UserName"),
                        date("U"));

        // Gig hinzufügen
        if ($_REQUEST['job']=='add')
        {
          if (addGig($Gig, "add"))
          {
            echo $L_043.'<br />';
          }
          else
          {
            echo $L_044.'<br />';
          }
        }
        // Gig bearbeiten
        if ($_REQUEST['job']=='edit')
        {
          if (addGig($Gig, "edit"))
          {
            echo $L_040.'<br />';
          }
          else
          {
            echo $L_041.'<br />';
          }
        }
      echo '<br />
        <form method="post" action="index.php?submenue=calendar&amp;content=backend_showAllGigs" accept-charset="UTF-8">
          <fieldset>
            <input type="submit" value="'.$L_Button26.'" class="button" />
          </fieldset>
        </form>'
      ;

      }
      else
      {
        // Post-Variablen in Variablen speichern
          foreach ($_POST as $key => $value) $$key = stripslashes($value);
        echo '<form method="post" action="index.php?submenue=calendar&amp;content=backend_addGig&amp;job='.$_REQUEST['job'].'" accept-charset="UTF-8">
          <table summary="AddGig" style="float:left;">';
            include ('calendar/includes/addGig/GigDate.php');
            include ('calendar/includes/addGig/GigStatus.php');
            include ('calendar/includes/addGig/GigIsPrivate.php');
            include ('calendar/includes/addGig/GigPublish.php');        	          	  
            // Attribute definieren
              $SetupCalendarAttributeInAddGigForm = getSetup('SetupCalendarAttributeInAddGigForm');
              if ( $SetupCalendarAttributeInAddGigForm!="" ) $Attribute = explode (', ',$SetupCalendarAttributeInAddGigForm);
              else $Attribute = array();
            // Attribute ausgeben
            for ( $x = 0; $x < count ( $Attribute ); $x++ )
            {   
              ${$Attribute[$x]} = htmlspecialchars(${$Attribute[$x]});
              include ('calendar/includes/addGig/'.$Attribute[$x].'.php');
            }
            // evtl. Ausgeblendete Attribute-Inhalte übergeben
              $allBackendCalenderFormAttributes = explode (', ',$allBackendCalenderFormAttributes);
              $Result = array_diff ( $allBackendCalenderFormAttributes, $Attribute );
              foreach ($Result as $key => $val)
              { 
                if ( $val!='GigNotes')
                {
                  echo '<tr><td></td><td><input type="hidden" name="'.$val.'" value="'.${$val}.'" /></td></tr>';
                }
                else
                {
                  echo '<tr>
                          <td></td>
                          <td>
                            <textarea style="display:none" id="'.$val.'" name="'.$val.'" rows="" cols="">'.wordwrap(${$val}).'</textarea>
                          </td>
                        </tr>';
                }
                
              }
            // Formular-Buttons
            echo '<tr>
              <td></td>
              <td>
                <input type="submit" name="senden" value="'.$L_Button01.'" class="button" />
                <input type="button" value="'.$L_Button03.'" onclick="history.go(-1)" class="button"/>
                <input type="hidden" name="GigID" value="'.$GigID.'" />
                <input type="hidden" name="GigDate" value="'.$GigDate.'" />
                <input type="reset" value="'.$L_Button38.'" class="button" />
              </td>
            </tr>
          </table>
          <table style="float:right;">
            <tr>
              <td>'.$L_GigDateOfAdding.':</td>
              <td>'.DatumMitUhrzeitAusTimestamp($GigDateOfAdding);
                if ($GigAddedFrom) echo ' (';
                echo $GigAddedFrom;
                if ($GigAddedFrom) echo ')';
                echo'</td>
            </tr>
            <tr>
              <td>'.$L_GigDateOfLastEdit.':</td>
              <td>'.DatumMitUhrzeitAusTimestamp($GigDateOfLastEdit);
                if ($GigLastEditor) echo ' (';
                echo $GigLastEditor;
                if ($GigLastEditor) echo ')';
                echo'</td>
            </tr>
            <tr>
              <td>';
                // Attribut-Editor
                  if (!isset($timestamp)) $timestamp = '';
                  echo '<button name="Klickmich" type="button" value="'.$L_Button28.'" onclick="self.location.href=\'index.php?submenue=calendar&amp;content=backend_editAttributes&amp;Selector=backend_addGig&amp;referer=backend_addGig&amp;job='.$job.'&amp;id='.$GigID.'&amp;timestamp='.$timestamp.'\'" class="SmallButton" >
                          '.$L_Button28.'
                        </button>';
              echo '</td>
              <td></td>
            </tr>
          </table>
          </form>          
        ';
      }
    // Inhalt zuende
  }
?>