diff --git a/includes/api/products.php b/includes/api/products.php
new file mode 100644
index 00000000..fbf6ffa1
--- /dev/null
+++ b/includes/api/products.php
@@ -0,0 +1,35 @@
+
+ */
+
+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;
+}
+
+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..1cd407d5 100644
--- a/includes/assets/js/default.js
+++ b/includes/assets/js/default.js
@@ -3,8 +3,9 @@ $(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',
};
$('.ui.dropdown.wishlists').dropdown({
diff --git a/includes/assets/js/wishlist.js b/includes/assets/js/wishlist.js
index e5c8466c..c91e9d65 100644
--- a/includes/assets/js/wishlist.js
+++ b/includes/assets/js/wishlist.js
@@ -1,4 +1,7 @@
$(function() {
+ /**
+ * User Warning
+ */
if ($('.wishlist-own').length) {
$('body')
.modal({
@@ -19,4 +22,66 @@ $(function() {
})
.modal('show');
}
+
+ /**
+ * Commit
+ */
+ $('.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');
+ });
});
diff --git a/includes/classes/wishlist.php b/includes/classes/wishlist.php
new file mode 100644
index 00000000..657ebfca
--- /dev/null
+++ b/includes/classes/wishlist.php
@@ -0,0 +1,147 @@
+
+ */
+
+namespace wishthis;
+
+class Wishlist
+{
+ private int $id;
+ private string $hash;
+
+ public mixed $data;
+ public mixed $products;
+
+ public bool $exists = false;
+
+ public function __construct(int|string $id_or_hash)
+ {
+ global $database;
+
+ $column;
+
+ if (is_int($id_or_hash)) {
+ $column = 'id';
+ }
+ if (is_string($id_or_hash)) {
+ $column = 'hash';
+ $id_or_hash = '"' . $id_or_hash . '"';
+ }
+
+ /**
+ * Get Wishlist
+ */
+ $this->data = $database->query('SELECT *
+ FROM `wishlists`
+ WHERE `' . $column . '` = ' . $id_or_hash . ';')
+ ->fetch();
+
+ /** Exists */
+ if (isset($this->data['id'])) {
+ $this->id = $this->data['id'];
+ $this->exists = true;
+ } else {
+ return;
+ }
+
+ /**
+ * Get Products
+ */
+ $this->products = $database->query('SELECT *
+ FROM `products`
+ WHERE `wishlist` = ' . $this->id . ';')
+ ->fetchAll();
+ }
+
+ public function getCards(): void
+ {
+ $products = array_filter($this->products, function ($product) {
+ if ('unavailable' !== $product['status']) {
+ return true;
+ }
+ });
+
+ if (!empty($products)) { ?>
+
+
+ get($product['url']);
+ ?>
+
+
+
+ image) { ?>
+
+
+
+
+
+
+ title) { ?>
+
+
+
+ keywords) { ?>
+
+ = $info->keywords ?>
+
+
+
+ description) { ?>
+
+ = $info->description ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This wishlist seems to be empty.
+
+
query('ALTER TABLE `users` ADD INDEX(`password`);');
$database->query('ALTER TABLE `wishlists`
- ADD `hash` VARCHAR(128) NOT NULL AFTER `name`
+ ADD `hash` VARCHAR(128) NOT NULL AFTER `name`
;');
$database->query('ALTER TABLE `wishlists` ADD INDEX(`hash`);');
$database->query('INSERT INTO `options` (`key`, `value`) VALUES ("version", "' . VERSION . '");');
}
+ /** Current version is below 0.3.0 */
+ if (-1 === version_compare($options->version, '0.3.0')) {
+ $database->query('ALTER TABLE `products`
+ ADD `status` VARCHAR(32) NOT NULL AFTER `url`
+ ;');
+ }
+
+ /** Update version */
$options->setOption('version', VERSION);
header('Location: /?page=home');
diff --git a/includes/pages/wishlist.php b/includes/pages/wishlist.php
index e04fe6c3..d2ee814b 100644
--- a/includes/pages/wishlist.php
+++ b/includes/pages/wishlist.php
@@ -1,25 +1,16 @@
*/
-use wishthis\{Page, User};
-use Embed\Embed;
+use wishthis\{Page, User, Wishlist};
-$page = new page(__FILE__, 'Wishlist');
-$page->header();
-$page->navigation();
+$wishlist = new Wishlist($_GET['wishlist']);
-$wishlist = $database->query('SELECT * FROM `wishlists`
- WHERE `hash` = "' . $_GET['wishlist'] . '"')
- ->fetch();
-
-if ($wishlist) {
- $products = $user->getProducts($wishlist['id']);
-} else {
+if (!$wishlist->exists) {
http_response_code(404);
?>
Not found
@@ -27,6 +18,10 @@ if ($wishlist) {
data['name']);
+$page->header();
+$page->navigation();
?>
@@ -37,7 +32,7 @@ if ($wishlist) {
/**
* Warn the wishlist creator
*/
- if (isset($user->id) && $user->id === intval($wishlist['user'])) { ?>
+ if (isset($user->id) && $user->id === intval($wishlist->data['user'])) { ?>
@@ -59,88 +54,15 @@ if ($wishlist) {
-
+
+
+ If you found something you would like to buy,
+ click the Commit button
+ and it will become unavailable for others.
+
-
-
-
-
- get($product['url']);
- ?>
-
-
-
- image) { ?>
-
-
-
-
-
-
- title) { ?>
-
-
-
- keywords) { ?>
-
- = $info->keywords ?>
-
-
-
- description) { ?>
-
- = $info->description ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
This wishlist seems to be empty.
-
-
-
-
+ getCards() ?>