<?php

require '../header.php';

$data = array();
$data["albumcontents"] = "";
$data["albumtitle"] = "";
$data["albumdescription"] = "";
$data["images"] = array();
$data["loggedin"] = $currentuser->isLoggedIn();

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["albumscale"] = $album->getScale();
        $data["albummanufacturer"] = $album->getManufacturer();
        $data["albumdescription"] = $album->getDescription();
        $data["thumbnailid"] = $album->getThumbnailID();
        $data["images"] = $griditems;
    }
}
if ( $_SESSION['currentalbum'] == 0 ) {
    $griditems = Album::getList();
}
foreach ( $griditems as $griditem ) {
    $data["albumcontents"] .= "<div class=\"thumbnail_grid\" id=\"griditem_{$griditem->getID()}\">";
    $data["albumcontents"] .= "<img class=\"thumbnail_grid_image albumthumbnail\" id=\"griditem_img_{$griditem->getID()}\" src=\"{$griditem->getThumbnail(URLSAFE)}\" />";
    $data["albumcontents"] .= "<div class=\"thumbnail_grid_title\"><span class='textlink griditem_title' id=\"title_{$griditem->getID()}\">{$griditem->getTitle(HTMLSAFE)}</span>";
    if ( $currentuser->isLoggedIn() && ($_SESSION['currentalbum'] != 0) ) {
        $data["albumcontents"] .= " <span class=\"textlink btn_setthumbnail\" id=\"setthumbnail_" . $griditem->getID() . "\">(SetThumb)</span>";
    }
    $data["albumcontents"] .= "</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
