<?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.
*/
  $GigDate  = '';
  $GigStatus = '';
  $GigIsPrivate = '';
  $GigPublish = '';
  $GigVenueID = '';
  $GigEvent = '';
  $GigEventURL = '';
  $GigEntranceFee = '';
  $GigOrganizerID = '';
  $GigArtistID = '';
  $GigLineup = '';
  $GigVisitors = '';
  $GigStageBuilding = '';
  $GigBeginning = '';
  $GigDuration = '';
  $GigEnding = '';
  $GigNotes = '';
  $GigDateDay = '';
  $GigDateMonth = '';
  $GigDateYear = '';
  $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) )
             && $GigStatus
             && $GigPublish!=""
             && $GigIsPrivate!=""
             && (
                  ( $_REQUEST['job']=='add' AND ( getSetup('SetupAllowDoubleDates')
                                                  OR !testDoppelteGigs($GigDateDay, $GigDateMonth, $GigDateYear) ))
                  OR
                  ( $_REQUEST['job']=='edit' AND (  $_REQUEST['GigDate']==strtotime($GigDateYear.'-'.$GigDateMonth.'-'.$GigDateDay)
                                                    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')
      { 
        $SQL = "SELECT * FROM ".DB_PREFIX."gigs Where GigID = '$GigID'";
        $resultat = mysql_query($SQL);
        while ($row = mysql_fetch_array($resultat)) { extract($row); }
      }
      if ( $GigID )
      {
        $GigDateDay = date('d', $GigDate);
        $GigDateMonth = date('m', $GigDate);
        $GigDateYear = date('Y', $GigDate);
      }
      $FormularKorrektAusgefuellt = false;
      $senden = ''; 
    }
  if ( !IsUserAdmin() ) echo $L_015;
  else
  {
    // Content Begin
      if ($FormularKorrektAusgefuellt == true)
      { 
          $Gig = array( $GigID,
          	            $GigDateDay,
          	            $GigDateMonth,
                        $GigDateYear,
                        $GigEvent,
                        $GigEventURL,
                        $GigEntranceFee,                      
                        $GigLineup,
                        $GigVisitors,
                        $GigStageBuilding,
                        $GigBeginning,
                        $GigDuration,
                        $GigEnding,
                        $GigNotes,
                        $GigStatus,
                        $GigPublish,
                        $GigIsPrivate,
                        '',
                        '',
                        getCurrentUserVar("UserName"),
                        date("U"),
                        $GigVenueID,
                        $GigOrganizerID,
                        $GigArtistID);

        // 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?submenu=calendar&amp;page=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)
          {
            if (get_magic_quotes_gpc()) $$key = stripslashes($value);
            else $$key = $value;
          }
          // PageMenu
            if ( !isset($timestamp) ) $timestamp = '';
            echo '<form name="myForm" method="post" action="index.php?submenu=calendar&amp;page=backend_addGig" accept-charset="UTF-8">
                    <fieldset id="PageMenu">
                      <input type="submit" name="senden" value="'.$L_Button01.'" />
                      <input type="button" value="'.$L_Button03.'" onclick="self.location.href=\'index.php?submenu=calendar\'" />
                      <input type="reset" value="'.$L_Button38.'" />
                      <input type="button" value="'.$L_Button28.'" onclick="self.location.href=\'index.php?submenu=calendar&amp;page=backend_editAttributes&amp;Selector=backend_addGig&amp;referer=backend_addGig&amp;job='.$job.'&amp;id='.$GigID.'&amp;timestamp='.$timestamp.'\'" />
                      </fieldset>
                  </form>';
          // Gig-Form
        echo '<form method="post" action="index.php?submenu=calendar&amp;page=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 );
              while ( list ( $key, $val ) = each ( $result ) )
              { 
                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="hidden" name="GigID" value="'.$GigID.'" />
                <input type="hidden" name="GigDate" value="'.$GigDate.'" />
              </td>
            </tr>
          </table>
          <table style="float:right;">
            <tr>
              <td>'.$L_GigDateOfAdding.':</td>
              <td>'.getDateAndTimeFromTimestamp($GigDateOfAdding);
                if ($GigAddedFrom) echo ' (';
                echo $GigAddedFrom;
                if ($GigAddedFrom) echo ')';
                echo'</td>
            </tr>
            <tr>
              <td>'.$L_GigDateOfLastEdit.':</td>
              <td>'.getDateAndTimeFromTimestamp($GigDateOfLastEdit);
                if ($GigLastEditor) echo ' (';
                echo $GigLastEditor;
                if ($GigLastEditor) echo ')';
                echo'</td>
            </tr>
            <tr>
              <td>';
                
              echo '</td>
              <td></td>
            </tr>
          </table>
          </form>          
        ';
      }
    // Inhalt zuende
  }
?>