From 3ba6dc6eb358aef97d0dd301f1ce4c161c53d09d Mon Sep 17 00:00:00 2001 From: junior Date: Sun, 20 Feb 2022 16:37:56 +0000 Subject: [PATCH] Add ability to set album thumbnails --- ajax/getalbuminfo.php | 11 ++++++++--- ajax/setthumbnail.php | 35 +++++++++++++++++++++++++++++++++++ class_album.php | 10 ++++++++-- js/scalemodels.js | 24 ++++++++++++++++++++++++ style/style.css | 3 +++ 5 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 ajax/setthumbnail.php diff --git a/ajax/getalbuminfo.php b/ajax/getalbuminfo.php index db4308e..d17be87 100644 --- a/ajax/getalbuminfo.php +++ b/ajax/getalbuminfo.php @@ -18,6 +18,7 @@ if ( $_SESSION['currentalbum'] != 0 ) { $data["albumscale"] = $album->getScale(); $data["albummanufacturer"] = $album->getManufacturer(); $data["albumdescription"] = $album->getDescription(); + $data["thumbnailid"] = $album->getThumbnailID(); $data["images"] = $griditems; } } @@ -25,9 +26,13 @@ if ( $_SESSION['currentalbum'] == 0 ) { $griditems = Album::getList(); } foreach ( $griditems as $griditem ) { - $data["albumcontents"] .= "
"; - $data["albumcontents"] .= "getID()}\" src=\"{$griditem->getThumbnail(URLSAFE)}\" />"; - $data["albumcontents"] .= "
getID()}\">{$griditem->getTitle(HTMLSAFE)}
"; + $data["albumcontents"] .= "
getID()}\">"; + $data["albumcontents"] .= "getID()}\" src=\"{$griditem->getThumbnail(URLSAFE)}\" />"; + $data["albumcontents"] .= "
getID()}\">{$griditem->getTitle(HTMLSAFE)}"; + if ( $currentuser->isLoggedIn() && ($_SESSION['currentalbum'] != 0) ) { + $data["albumcontents"] .= " getID() . "\">(SetThumb)"; + } + $data["albumcontents"] .= "
"; $data["albumcontents"] .= "
\n"; } $data["currentalbum"] = $_SESSION['currentalbum']; diff --git a/ajax/setthumbnail.php b/ajax/setthumbnail.php new file mode 100644 index 0000000..ec8c4de --- /dev/null +++ b/ajax/setthumbnail.php @@ -0,0 +1,35 @@ +getID() == 0 ) { + sendResponse($data); +} +$album = new Album($image->getAlbumID()); +$album->setThumbnail($image->getFileName()); +$album->save(); + +$data["success"] = true; +$data["album"] = $album; + +sendResponse($data); + +function sendResponse($data) { + header('Content-Type: application/json'); + echo json_encode($data); + exit(); +} + +exit(); + +// vim: set ts=4:sw=4 diff --git a/class_album.php b/class_album.php index a9860cb..b5efa33 100644 --- a/class_album.php +++ b/class_album.php @@ -5,6 +5,7 @@ class Album implements JsonSerializable { private $foldername = ""; private $title = ""; private $thumbnail = ""; + private $thumbnailid = 0; private $description = ""; private $manufacturer = ""; private $scale = ""; @@ -72,6 +73,10 @@ class Album implements JsonSerializable { } } + public function getThumbnailID() { + return intval($this->thumbnailid); + } + public function getDescription($flag = 0) { switch ($flag) { case HTMLSAFE: @@ -324,8 +329,8 @@ class Album implements JsonSerializable { global $globaldbh; $reqid = intval($reqid); - $query = "SELECT id, foldername, title, thumbnail, description, manufacturer, scale, createtime " . - "FROM " . AppDB::TABLE_ALBUMS . " WHERE id=:id"; + $query = "SELECT a.id, a.foldername, a.title, a.thumbnail, a.description, a.manufacturer, a.scale, a.createtime, i.id AS thumbnailid " . + "FROM " . AppDB::TABLE_ALBUMS . " AS a LEFT JOIN " . AppDB::TABLE_IMAGES . " AS i ON i.filename=a.thumbnail WHERE a.id=:id"; $sth = $globaldbh->prepare($query); $sth->bindValue(":id", $reqid, PDO::PARAM_INT); $sth->execute(); @@ -334,6 +339,7 @@ class Album implements JsonSerializable { $this->setFolderName($row['foldername']); $this->setTitle($row['title']); $this->setThumbnail($row['thumbnail']); + $this->thumbnailid = $row['thumbnailid']; $this->setDescription($row['description']); $this->setManufacturer($row['manufacturer']); $this->setScale($row['scale']); diff --git a/js/scalemodels.js b/js/scalemodels.js index e679c4b..46100ec 100644 --- a/js/scalemodels.js +++ b/js/scalemodels.js @@ -53,6 +53,7 @@ $(document).ready(function() { $("#btn_refresh").click(function() { refreshAlbums() }); $("#btn_album_0").click(function() { showAlbum($(this)) }); $(".albuminfo_label").click(function() { editAlbum(currentAlbum); }); + $(".btn_setthumbnail").click(function() { setAlbumThumbnail($(this)) }); getAlbumInfo(); }); @@ -104,6 +105,10 @@ function getAlbumInfo() { $("#albumscale").text(data.albumscale); $("#albumdescription").text(data.albumdescription); $("#albumcontents").html(data.albumcontents); + if ( data.currentalbum != 0 ) { + $("#griditem_"+data.thumbnailid).addClass("activethumbnail"); + $(".btn_setthumbnail").click(function() { setAlbumThumbnail($(this)) }); + } $(".albumthumbnail").click(function() { if ( data.currentalbum == 0 ) { showAlbum($(this)); @@ -126,6 +131,25 @@ function getAlbumInfo() { }); } +function setAlbumThumbnail(clickedElement) { + var imageid = clickedElement.attr("id").substring(clickedElement.attr("id").lastIndexOf("_") + 1); + $.ajax({ + type: 'GET', + url: 'ajax/setthumbnail.php', + dataType: 'json', + data: { + imageid: imageid + }, + success: function(data, stat, jqo) { + $(".thumbnail_grid").removeClass("activethumbnail"); + $("#griditem_"+imageid).addClass("activethumbnail"); + }, + error: function(jqp, status, error) { + toastr.error("Error setting thumbnail!\n" + error, "Server Error"); + } + }); +} + function showImage(clickedElement) { var imageid = clickedElement.attr("id").substring(clickedElement.attr("id").lastIndexOf("_") + 1); var startIndex = 0; diff --git a/style/style.css b/style/style.css index ffdb9c6..4655abd 100755 --- a/style/style.css +++ b/style/style.css @@ -281,3 +281,6 @@ table tr td .spacebelow_small { margin-bottom: 1em; } +.activethumbnail { + border: 2px solid orange; +}