diff --git a/ajax/getalbum.php b/ajax/getalbum.php
new file mode 100644
index 0000000..e9bdabd
--- /dev/null
+++ b/ajax/getalbum.php
@@ -0,0 +1,30 @@
+getID() == 0 ) {
+ sendResponse($data);
+}
+
+$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/ajax/getalbuminfo.php b/ajax/getalbuminfo.php
index 034fe18..1ac4faf 100644
--- a/ajax/getalbuminfo.php
+++ b/ajax/getalbuminfo.php
@@ -25,7 +25,7 @@ if ( $_SESSION['currentalbum'] == 0 ) {
foreach ( $griditems as $griditem ) {
$data["albumcontents"] .= "
";
$data["albumcontents"] .= "
![]()
getID()}\" src=\"{$griditem->getThumbnail(URLSAFE)}\" />";
- $data["albumcontents"] .= "
{$griditem->getTitle(HTMLSAFE)}
";
+ $data["albumcontents"] .= "
getID()}\">{$griditem->getTitle(HTMLSAFE)}
";
$data["albumcontents"] .= "
\n";
}
$data["currentalbum"] = $_SESSION['currentalbum'];
diff --git a/ajax/getimage.php b/ajax/getimage.php
new file mode 100644
index 0000000..a05ef4a
--- /dev/null
+++ b/ajax/getimage.php
@@ -0,0 +1,30 @@
+getID() == 0 ) {
+ sendResponse($data);
+}
+
+$data["image"] = $image;
+
+$data["success"] = true;
+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/ajax/savealbum.php b/ajax/savealbum.php
new file mode 100644
index 0000000..5299fea
--- /dev/null
+++ b/ajax/savealbum.php
@@ -0,0 +1,33 @@
+getID() == 0 ) {
+ sendResponse($data);
+}
+
+$album->setTitle($_REQUEST['title']);
+$album->setDescription($_REQUEST['description']);
+$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/ajax/saveimage.php b/ajax/saveimage.php
new file mode 100644
index 0000000..84506f8
--- /dev/null
+++ b/ajax/saveimage.php
@@ -0,0 +1,34 @@
+getID() == 0 ) {
+ sendResponse($data);
+}
+$album = new Album($image->getAlbumID());
+
+$image->setTitle($_REQUEST['title']);
+$image->setDescription($_REQUEST['description']);
+$image->save();
+$data["success"] = true;
+$data["image"] = $image;
+
+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_image.php b/class_image.php
index 1574162..d931976 100644
--- a/class_image.php
+++ b/class_image.php
@@ -278,7 +278,7 @@ class Image implements JsonSerializable {
$query = "INSERT INTO " . AppDB::TABLE_IMAGES . " ";
$query .= "(id, album_id, filename, title, description, createtime) ";
- $query .= "VALUES(NULL, :album_id, :filename, :title, :description, NOW()) ";
+ $query .= "VALUES(:id, :album_id, :filename, :title, :description, NOW()) ";
$query .= "ON DUPLICATE KEY UPDATE ";
$query .= "album_id=:album_id, filename=:filename, title=:title, description=:description";
$sth = $globaldbh->prepare($query);
diff --git a/js/scalemodels.js b/js/scalemodels.js
index 3aaad7f..ebfe521 100644
--- a/js/scalemodels.js
+++ b/js/scalemodels.js
@@ -1,6 +1,52 @@
var lightboxImages = [];
+var editAlbumID = 0;
+var editImageID = 0;
$(document).ready(function() {
+ $("#edit_album").dialog({
+ autoOpen: false,
+ height: 250,
+ width: 350,
+ closeOnEscape: true,
+ draggable: false,
+ close: function() {
+ editAlbumID = 0;
+ $("#edit_album_title").val("");
+ $("#edit_album_description").val("");
+ },
+ buttons: [
+ {
+ text: "Save",
+ click: function() { saveAlbumInfo(); }
+ },
+ {
+ text: "Cancel",
+ click: function() { $(this).dialog("close"); }
+ }
+ ]
+ });
+ $("#edit_image").dialog({
+ autoOpen: false,
+ height: 250,
+ width: 350,
+ closeOnEscape: true,
+ draggable: false,
+ close: function() {
+ editImageID = 0;
+ $("#edit_image_title").val("");
+ $("#edit_image_description").val("");
+ },
+ buttons: [
+ {
+ text: "Save",
+ click: function() { saveImageInfo(); }
+ },
+ {
+ text: "Cancel",
+ click: function() { $(this).dialog("close"); }
+ }
+ ]
+ });
$("#btn_refresh").click(function() { refreshAlbums() });
$("#btn_album_0").click(function() { showAlbum($(this)) });
getAlbumInfo();
@@ -21,6 +67,20 @@ function refreshAlbums() {
});
}
+function updateLightboxImages() {
+ $.ajax({
+ type: 'GET',
+ url: 'ajax/getalbuminfo.php',
+ dataType: 'json',
+ success: function(data, stat, jqo) {
+ lightboxImages = data.images;
+ lightboxImages.forEach(function(image, index) {
+ $("#title_"+image.id).text(image.title);
+ });
+ },
+ });
+}
+
function getAlbumInfo() {
$.ajax({
type: 'GET',
@@ -44,6 +104,13 @@ function getAlbumInfo() {
showImage($(this));
}
});
+ $(".griditem_title").click(function() {
+ if ( data.currentalbum == 0 ) {
+ editAlbum($(this));
+ } else {
+ editImage($(this));
+ }
+ });
console.log(lightboxImages);
},
error: function(jqp, status, error) {
@@ -62,11 +129,6 @@ function showImage(clickedElement) {
images.push(image.imageurl);
captions.push(image.description);
});
- /*
- images.forEach(function(image, index) {
- if ( basename(image, "/") == basename(clickedElement.attr("src"), "/") ) startIndex = index;
- });
- */
SimpleLightbox.open({
items: images,
captions: captions,
@@ -93,4 +155,113 @@ function showAlbum(clickedElement) {
});
}
+function saveImageInfo() {
+ if ( editImageID == 0 ) return;
+ if ( $("#edit_image_title").val() == "" ) {
+ toastr.error("Image title cannot be blank!", "Image Title Error");
+ return;
+ }
+ $.ajax({
+ type: 'POST',
+ url: 'ajax/saveimage.php',
+ dataType: 'json',
+ data: {
+ imageid: editImageID,
+ title: $("#edit_image_title").val(),
+ description: $("#edit_image_description").val()
+ },
+ success: function(data, stat, jqo) {
+ if ( data.success ) {
+ $("#edit_image").dialog("close");
+ $("#title_"+data.image.id).text(data.image.title);
+ updateLightboxImages();
+ } else {
+ toastr.error("Could not get image information!", "Image Data Error");
+ }
+ },
+ error: function(jqp, status, error) {
+ toastr.error("Error saving image!\n" + error, "Server Error");
+ }
+ });
+}
+
+function saveAlbumInfo() {
+ if ( editAlbumID == 0 ) return;
+ if ( $("#edit_album_title").val() == "" ) {
+ toastr.error("Album title cannot be blank!", "Album Title Error");
+ return;
+ }
+ $.ajax({
+ type: 'POST',
+ url: 'ajax/savealbum.php',
+ dataType: 'json',
+ data: {
+ albumid: editAlbumID,
+ title: $("#edit_album_title").val(),
+ description: $("#edit_album_description").val()
+ },
+ success: function(data, stat, jqo) {
+ if ( data.success ) {
+ $("#edit_album").dialog("close");
+ $("#title_"+data.album.id).text(data.album.title);
+ } else {
+ toastr.error("Could not get album information!", "Album Data Error");
+ }
+ },
+ error: function(jqp, status, error) {
+ toastr.error("Error saving album!\n" + error, "Server Error");
+ }
+ });
+}
+
+function editAlbum(clickedElement) {
+ var albumid = clickedElement.attr("id").substring(clickedElement.attr("id").lastIndexOf("_") + 1);
+ $.ajax({
+ type: 'GET',
+ url: 'ajax/getalbum.php',
+ dataType: 'json',
+ data: {
+ albumid: albumid
+ },
+ success: function(data, stat, jqo) {
+ if ( data.success ) {
+ editAlbumID = data.album.id;
+ $("#edit_album_title").val(data.album.title);
+ $("#edit_album_description").val(data.album.description);
+ $("#edit_album").dialog("open");
+ } else {
+ toastr.error("Could not get album information!", "Album Data Error");
+ }
+ },
+ error: function(jqp, status, error) {
+ toastr.error("Error getting album!\n" + error, "Server Error");
+ }
+ });
+}
+
+function editImage(clickedElement) {
+ var imageid = clickedElement.attr("id").substring(clickedElement.attr("id").lastIndexOf("_") + 1);
+ $.ajax({
+ type: 'GET',
+ url: 'ajax/getimage.php',
+ dataType: 'json',
+ data: {
+ imageid: imageid
+ },
+ success: function(data, stat, jqo) {
+ if ( data.success ) {
+ editImageID = data.image.id;
+ $("#edit_image_title").val(data.image.title);
+ $("#edit_image_description").val(data.image.description);
+ $("#edit_image").dialog("open");
+ } else {
+ toastr.error("Could not get image information!", "Image Data Error");
+ }
+ },
+ error: function(jqp, status, error) {
+ toastr.error("Error getting image!\n" + error, "Server Error");
+ }
+ });
+}
+
// vim: ts=4:sw=4
diff --git a/scalemodels.php b/scalemodels.php
index ae44498..61ca1d8 100755
--- a/scalemodels.php
+++ b/scalemodels.php
@@ -21,6 +21,30 @@ if ( $currentuser->isLoggedIn() ) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+