<?php

require '../header.php';

$data = array();
$data["albumcontents"] = "";
$data["albumtitle"] = "";
$data["albumdescription"] = "";
$data["images"] = array();

if ( $_SESSION['currentalbum'] != 0 ) {
    $album = new Album($_SESSION['currentalbum']);
    if ( $album->getID() == 0 ) {
        $_SESSION['currentalbum'] = 0;
    } else {
        $griditems = Image::getImagesForAlbum($album->getID());
        $data["albumtitle"] = $album->getTitle();
        $data["albumdescription"] = $album->getDescription();
        $data["images"] = $griditems;
    }
}
if ( $_SESSION['currentalbum'] == 0 ) {
    $griditems = Album::getList();
}
foreach ( $griditems as $griditem ) {
    $data["albumcontents"] .= "<div class=\"thumbnail_grid\">";
    $data["albumcontents"] .= "<img class=\"thumbnail_grid_image albumthumbnail\" id=\"griditem_{$griditem->getID()}\" src=\"{$griditem->getThumbnail(URLSAFE)}\" />";
    $data["albumcontents"] .= "<div class=\"thumbnail_grid_title textlink griditem_title\" id=\"title_{$griditem->getID()}\">{$griditem->getTitle(HTMLSAFE)}</div>";
    $data["albumcontents"] .= "</div>\n";
}
$data["currentalbum"] = $_SESSION['currentalbum'];

header('Content-Type: application/json');
echo json_encode($data);
exit();

// vim: set ts=4:sw=4
