+ You are viewing your own wishlist! + You will be able to see which products have already been bought for you. + Don't you want to be surprised? +
++ It's probably best to just close this tab. +
+diff --git a/includes/api/products.php b/includes/api/products.php new file mode 100644 index 00000000..d7111af1 --- /dev/null +++ b/includes/api/products.php @@ -0,0 +1,47 @@ + + */ + +use wishthis\User; + +$api = true; +$response = array( + 'success' => false, +); + +require '../../index.php'; + +switch ($_SERVER['REQUEST_METHOD']) { + case 'PUT': + parse_str(file_get_contents("php://input"), $_PUT); + + if (isset($_PUT['productID'], $_PUT['productStatus'])) { + $database->query('UPDATE `products` + SET `status` = "' . $_PUT['productStatus'] . '" + WHERE `id` = ' . $_PUT['productID'] . ' + ;'); + + $response['success'] = true; + } + break; + + case 'DELETE': + parse_str(file_get_contents("php://input"), $_DELETE); + + if (isset($_DELETE['productID'])) { + $database->query('DELETE FROM `products` + WHERE `id` = ' . $_DELETE['productID'] . ' + ;'); + + $response['success'] = true; + } + break; +} + +echo json_encode($response); +header('Content-type: application/json; charset=utf-8'); +die(); diff --git a/includes/api/wishlists.php b/includes/api/wishlists.php index 0bf4be8a..d174b9f9 100644 --- a/includes/api/wishlists.php +++ b/includes/api/wishlists.php @@ -8,7 +8,7 @@ use wishthis\User; -$api = true; +$api = true; $response = array( 'success' => false, ); diff --git a/includes/assets/css/default.css b/includes/assets/css/default.css index 7234d370..095ab884 100644 --- a/includes/assets/css/default.css +++ b/includes/assets/css/default.css @@ -19,3 +19,19 @@ .ui.progress.nolabel:last-child { margin: 0; } + +/** + * Card + */ +.ui.card .header > img { + height: 1.25em; +} + +/** + * Label + */ +p .ui.horizontal.label { + margin: 0; + cursor: default; + user-select: none; +} diff --git a/includes/assets/js/default.js b/includes/assets/js/default.js index ec00a022..7ab59f3e 100644 --- a/includes/assets/js/default.js +++ b/includes/assets/js/default.js @@ -3,15 +3,143 @@ $(function() { * Fomantic UI */ $.fn.api.settings.api = { - 'get wishlists' : '/includes/api/wishlists.php', - 'delete wishlist' : '/includes/api/wishlists.php' + 'get wishlists' : '/includes/api/wishlists.php', + 'delete wishlist' : '/includes/api/wishlists.php', + 'update product status': '/includes/api/products.php', + 'delete product' : '/includes/api/products.php', }; $('.ui.dropdown.wishlists').dropdown({ filterRemoteData: true }); + /** + * Refresh Wishlist + */ wishlistRefresh(); + + /** + * Commit to Product + */ + $('.ui.button.commit').on('click', function() { + var button = $(this); + var card = button.closest('.ui.card'); + var column = card.closest('.column'); + + $('body') + .modal({ + title: 'Really commit?', + content: 'Would you really like to commit to this purchase? It will no longer appear in the wishlist anymore.', + class: 'tiny', + actions: [ + { + text: 'Yes, commit', + class: 'approve primary' + }, + { + text: 'Cancel', + class: '' + } + ], + onApprove: function() { + /** + * Update product status + */ + button.api({ + action: 'update product status', + method: 'PUT', + data: { + productID: card.data('id'), + productStatus: 'unavailable' + }, + on: 'now', + onResponse: function(response) { + return response; + }, + successTest: function(response) { + return response.success || false; + }, + onComplete: function(response, element, xhr) { + + }, + onSuccess: function(response, element, xhr) { + column.fadeOut(); + }, + onFailure: function(response, element, xhr) { + + }, + onError: function(errorMessage, element, xhr) { + + }, + onAbort: function(errorMessage, element, xhr) { + + } + }); + } + }) + .modal('show'); + }); + + /** + * Delete Product + */ + $('.ui.button.delete').on('click', function() { + var button = $(this); + var card = button.closest('.ui.card'); + var column = card.closest('.column'); + + $('body') + .modal({ + title: 'Really delete?', + content: 'Would you really like to delete to this product? It will be gone forever.', + class: 'tiny', + actions: [ + { + text: 'Yes, delete', + class: 'approve primary' + }, + { + text: 'Cancel', + class: '' + } + ], + onApprove: function() { + /** + * Delete product + */ + button.api({ + action: 'delete product', + method: 'DELETE', + data: { + productID: card.data('id'), + }, + on: 'now', + onResponse: function(response) { + return response; + }, + successTest: function(response) { + return response.success || false; + }, + onComplete: function(response, element, xhr) { + + }, + onSuccess: function(response, element, xhr) { + column.fadeOut(); + }, + onFailure: function(response, element, xhr) { + + }, + onError: function(errorMessage, element, xhr) { + + }, + onAbort: function(errorMessage, element, xhr) { + + } + }); + } + }) + .modal('show'); + }); }); function wishlistRefresh() { diff --git a/includes/assets/js/wishlist-view.js b/includes/assets/js/wishlist-view.js index 10dee88d..cd7b040e 100644 --- a/includes/assets/js/wishlist-view.js +++ b/includes/assets/js/wishlist-view.js @@ -9,10 +9,16 @@ $(function() { if (wishlistValue) { $('.wishlist-view').removeClass('disabled'); + } else { + $('.wishlist-view').addClass('disabled'); + } + + const urlParams = new URLSearchParams(window.location.search); + + if (wishlistValue === urlParams.get('wishlist')) { $('.wishlist-share').removeClass('disabled'); $('.wishlist-delete button').removeClass('disabled'); } else { - $('.wishlist-view').addClass('disabled'); $('.wishlist-share').addClass('disabled'); $('.wishlist-delete button').addClass('disabled'); } diff --git a/includes/assets/js/wishlist.js b/includes/assets/js/wishlist.js new file mode 100644 index 00000000..c0d70cd7 --- /dev/null +++ b/includes/assets/js/wishlist.js @@ -0,0 +1,25 @@ +$(function() { + /** + * User Warning + */ + if ($('.wishlist-own').length) { + $('body') + .modal({ + title: $('.wishlist-own .header').text(), + content: $('.wishlist-own .text').html(), + class: '', + blurring: true, + closable: false, + actions: [ + { + text: 'Show wishlist anyway', + class: 'approve primary' + } + ], + onApprove: function() { + $('.wishlist-own').slideUp(); + } + }) + .modal('show'); + } +}); diff --git a/includes/classes/options.php b/includes/classes/options.php index e1130aa4..a20761f6 100644 --- a/includes/classes/options.php +++ b/includes/classes/options.php @@ -43,15 +43,9 @@ class Options public function setOption(string $key, string $value): void { - try { - $option = $this->database->query('UPDATE `options` - SET `value` - WHERE `key` = ' . $key . ' - ;'); - - $value = $option['value'] ?? ''; - } catch (\Throwable $th) { - //throw $th; - } + $this->database->query('UPDATE `options` + SET `value` = "' . $value . '" + WHERE `key` = "' . $key . '" + ;'); } } diff --git a/includes/classes/page.php b/includes/classes/page.php index 47d7b6fe..502c4b84 100644 --- a/includes/classes/page.php +++ b/includes/classes/page.php @@ -177,9 +177,6 @@ class Page Update -
The requested Wishlist was not found and likely deleted by its creator.
+ data['name']); $page->header(); $page->navigation(); - -$wishlist = $database->query('SELECT * FROM `wishlists` - WHERE `hash` = "' . $_GET['wishlist'] . '"') - ->fetch(); - -$products = $user->getProducts($wishlist['id']); ?>+ If you found something you would like to buy, + click the Commit button + and it will become unavailable for others. +