<?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.
*/
  $Path = str_replace('\\','/', __FILE__);
  $Path = str_replace('gallery/gallery.php', '', $Path);

  include_once ($Path.'gigkalender.ini.php');
  include_once ($Path.'includes/error_reporting.php');
  include_once ($Path.'/functions/standard.php');
  include_once ($Path.'/gallery/functions.php');
  include_once($Path."includes/frontend_language_selector.php");

  $GalleryURL = getFrontendURL('SetupGalleryURL');
  $AlbumsPath = GIGKALENDERPATH.'gallery/albums/';
  $AlbumsPathLocal = $Path.'gallery/albums/';

  echo '<div class="GigKalender">';
  echo '<div id="Gallery">';
  foreach ($_REQUEST as $key => $value) { $$key = $value; };
  if (!isset($gallery)) // Gallery
  {
    $Albums = array();
    $ArrayOfAllAlbums = getArrayOfAllAlbums ( $AlbumsPathLocal );
    //natcasesort ($ArrayOfAllAlbums);
    $amountAlbums = count($ArrayOfAllAlbums);
    for ($i=0; $i<$amountAlbums; $i++)
    {
      $Album = $ArrayOfAllAlbums[$i];
      $ArrayOfThumbnailsInAlbum = getArrayOfImagesInFolder($Album.'/thumbnails');
      $Thumbnail = rand(0,count($ArrayOfThumbnailsInAlbum)-1);
      $GalleryThumbnailPath = $AlbumsPath.$Album.'/thumbnails/'.$ArrayOfThumbnailsInAlbum[$Thumbnail];
      $AlbumURL = $GalleryURL.'?gallery='.$Album;
      $AlbumTitle = getTextFile ( $Album, 'title', '' );
      $AlbumDescription = getTextFile ( $Album, 'description', '' );
      $AmountImagesInAlbum = countImages($AlbumsPathLocal.$Album.'/images');
      //
      ob_start();
      include($Path.'gallery/templates/gallery_entry.php');
      $GalleryEntry=ob_get_contents();
      ob_end_clean();
      array_push ($Albums, $GalleryEntry);
    }
    include_once $Path.'gallery/templates/gallery.php';
  }
  else // Album
  {
    $ImageDirectory = $AlbumsPath.$gallery.'/images/';
    $ThumbnailDirectory = $AlbumsPath.$gallery.'/thumbnails/';
    $TextDirectory = $AlbumsPath.$gallery.'/text/';
    $ArrayOfImagesInFolder = getArrayOfImagesInFolder ( $gallery.'/images/' );
    $ArrayOfThumbnailsInFolder = getArrayOfImagesInFolder ( $gallery.'/thumbnails/' );
    $AnzahlBilder = count($ArrayOfImagesInFolder);
    if (!isset($image)) //Album
    {
      $IconGallery = '<a href="'.$GalleryURL.'"><img src="'.GIGKALENDERPATH.'gallery/images/gallery.gif" alt="'.$L_Back_to_gallery.'" title="'.$L_Back_to_gallery.'" /></a>';
      $AlbumDescription = getTextFile ( $gallery, 'description', '' );
      $AlbumTitle = getTextFile ( $gallery, 'title', '' );
      // Thumbnails
      $Thumbnails = array();
      for ($i=0; $i<$AnzahlBilder; $i++)
      {
        $ThumbnailFileName = $ArrayOfThumbnailsInFolder[$i];
        $Text = getTextFile ( $gallery, 'image', $ArrayOfImagesInFolder[$i] );
        array_push ($Thumbnails, '<a href="'.$GalleryURL.'?gallery='.$gallery.'&amp;image='.$i.'"><img src="'.$ThumbnailDirectory.$ThumbnailFileName.'" alt="'.$Text.'" title="'.$Text.'" /></a>');
      }
      include_once ($Path.'gallery/templates/album.php');
    }
    else // Einzelbild
    {
      $IconGallery = '<a href="'.$GalleryURL.'"><img src="'.GIGKALENDERPATH.'gallery/images/gallery.gif" alt="'.$L_Back_to_gallery.'" title="'.$L_Back_to_gallery.'" /></a>';
      $IconAlbums = '<a href="'.$GalleryURL.'?gallery='.$gallery.'"><img src="'.GIGKALENDERPATH.'gallery/images/album.gif" alt="'.$L_Back_to_album.'" title="'.$L_Back_to_album.'" /></a>';
      if ( $image>0 )
      {
        $IconFirst = '<a href="'.$GalleryURL.'?gallery='.$gallery.'&amp;image=0"><img src="'.GIGKALENDERPATH.'gallery/images/first.gif" alt="'.$L_First.'" title="'.$L_First.'" /></a>';
        $IconPrevious = '<a href="'.$GalleryURL.'?gallery='.$gallery.'&amp;image='.($image-1).'"><img src="'.GIGKALENDERPATH.'gallery/images/previous.gif" alt="'.$L_Previous.'" title="'.$L_Previous.'" /></a>';
      }
      else
      {
        $IconFirst = '<a href="'.$GalleryURL.'?gallery='.$gallery.'&amp;image=0"><img src="'.GIGKALENDERPATH.'gallery/images/first_deactive.gif" alt="" /></a>';
        $IconPrevious = '<img src="'.GIGKALENDERPATH.'gallery/images/previous_deactive.gif" alt="" />';
      }
      if ( $image<$AnzahlBilder-1 )
      {
        $IconLast = '<a href="'.$GalleryURL.'?gallery='.$gallery.'&amp;image='.($AnzahlBilder-1).'"><img src="'.GIGKALENDERPATH.'gallery/images/last.gif" alt="'.$L_Last.'" title="'.$L_Last.'" /></a>';
        $IconNext =  ' <a href="'.$GalleryURL.'?gallery='.$gallery.'&amp;image='.($image+1).'"><img src="'.GIGKALENDERPATH.'gallery/images/next.gif" alt="'.$L_Next.'" title="'.$L_Next.'" /></a>';
      }
      else
      {
        $IconLast = '<a href="'.$GalleryURL.'?gallery='.$gallery.'&amp;image='.($AnzahlBilder-1).'"><img src="'.GIGKALENDERPATH.'gallery/images/last_deactive.gif" alt="" /></a>';
        $IconNext =  ' <img src="'.GIGKALENDERPATH.'gallery/images/next_deactive.gif" alt="" />';
      }
      //print_r($ArrayOfImagesInFolder);
      $ImageFileName = $ArrayOfImagesInFolder[$image];
      $Original = checkIfOriginalIsPresent($gallery, $ImageFileName);
      if ( $Original ) $IconLens = '<a href="'.$AlbumsPath.$gallery.'/original/'.$Original.'"><img src="'.GIGKALENDERPATH.'gallery/images/lens.gif" alt="'.$L_Lens.'" title="'.$L_Lens.'" /></a>';
        else $IconLens = '<img src="'.GIGKALENDERPATH.'gallery/images/lens_deactive.gif" alt="" title="" />';
      $AmountOfImages = $AnzahlBilder;
      $NumberOfCurrentImage = $image+1;
      $AlbumTitle = getTextFile ( $gallery, 'title', '' );
      $AlbumURL = $GalleryURL.'?gallery='.$gallery;
      // Image
      $Text = getTextFile ( $gallery, 'image', $ImageFileName );
      $Image = '<img src="'.$ImageDirectory.$ImageFileName.'" alt="'.$Text.'" title="'.$Text.'" />';
      // Text
      $Text = '<br />'.nl2br($Text);
      include_once ($Path.'gallery/templates/image.php');
    }
  }
  echo '</div>';
  echo '</div>';
?>

