<?php
   @include_once("functions.php");
   $config = getConfig();
   authenticate();
?>
<html>
   <head>
      <meta http-equiv="Content-type" content="text/html; charset=utf-8">
      <title><?php echo $config['galleryName'];?> | admin</title>
      <link rel="stylesheet" href="admin.css" type="text/css" />
      <script type="text/javascript" src="functions.js"></script>
   </head>
   <body>
      <div id="page">
         <span class="homeLink"><a href="index.php">&lt;&lt; home</a></span>
         <hgroup>
            <h1><?php echo $config['galleryName'];?></h1><h2> | admin</h2>
         </hgroup>
         <p><a class="mainbutton" href="uploader.php">Upload</a> (create new album or add to existing album)</p>
         <p><a class="mainbutton" href="" onclick="logoutMessage()">Log Out</a></p>
         <p><a class="mainbutton" href="settings.php">Settings</a></p>
<?php
$albums = array();
if (file_exists('albums')) {
   foreach (new DirectoryIterator('albums') as $file) {
      if (!$file->isDot() && $file->isDir()) {
         $albumDir = $file->getFilename();
         $albums[] = $file->getFileName();
      }
   }
}
if (!empty($albums)) {
   echo '         <p>or click below to edit manage an album (edit info and captions, rename or delete)</p>';
}
echo '         <ul id="albums">';
rsort($albums);
foreach ($albums as $album) {
   $albumDir = 'albums/' . $album;
   $jsonPath = $albumDir . '/album.json';
   $albumInfo = readJSON($jsonPath);
   $albumName = $albumInfo['title'];
   $albumMonth = $albumInfo['month'];
   $albumYear = $albumInfo['year'];
   $featuredImage = $featuredSourcePath = null;
   if ($albumInfo && array_key_exists('featured', $albumInfo)) {
      $featuredImage = $albumInfo['featured'];
      $featuredSourcePath = $albumDir . '/thumbs/thumb_' . $featuredImage;
   }
   echo '<a href="editalbum.php?album=' . $album . '"><li class="album">
            <img class="albumThumb" src="' . $featuredSourcePath . '"/><span class="albumName">' . 
            $albumName . '</span><span class="albumDate">' . $albumMonth . ' ' . $albumYear . '</span>
         </li></a>';
}
?>            
         </ul>
      </div>
</body>
</html>
