2022-01-13 15:43:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wishlists.php
|
|
|
|
*
|
|
|
|
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
use wishthis\User;
|
|
|
|
|
2022-01-20 12:45:09 +00:00
|
|
|
$api = true;
|
2022-01-13 15:43:07 +00:00
|
|
|
$response = array(
|
|
|
|
'success' => false,
|
|
|
|
);
|
|
|
|
|
|
|
|
require '../../index.php';
|
|
|
|
|
|
|
|
switch ($_SERVER['REQUEST_METHOD']) {
|
|
|
|
case 'GET':
|
2022-01-17 11:26:11 +00:00
|
|
|
if (isset($_GET['userid']) || isset($_SESSION['user']['id'])) {
|
|
|
|
$user = isset($_GET['userid']) ? new User($_GET['userid']) : new User();
|
2022-01-13 15:43:07 +00:00
|
|
|
$wishlists = $user->getWishlists();
|
|
|
|
$wishlists = array_map(function ($wishlist) {
|
|
|
|
return array(
|
|
|
|
'name' => $wishlist['name'],
|
|
|
|
'value' => $wishlist['id'],
|
|
|
|
'text' => $wishlist['name'],
|
|
|
|
);
|
|
|
|
}, $wishlists);
|
|
|
|
|
|
|
|
$response['results'] = $wishlists;
|
|
|
|
$response['success'] = true;
|
|
|
|
}
|
|
|
|
break;
|
2022-01-17 15:06:17 +00:00
|
|
|
|
|
|
|
case 'DELETE':
|
|
|
|
parse_str(file_get_contents("php://input"), $_DELETE);
|
|
|
|
|
|
|
|
$database->query('DELETE FROM `wishlists`
|
|
|
|
WHERE `id` = ' . $_DELETE['wishlistID'] . '
|
|
|
|
;');
|
|
|
|
|
|
|
|
$response['success'] = true;
|
|
|
|
break;
|
2022-01-13 15:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode($response);
|
|
|
|
header('Content-type: application/json; charset=utf-8');
|
|
|
|
die();
|