From d67f6a0547700aded74e2429c4f13d6a9dbf29ce Mon Sep 17 00:00:00 2001 From: Minteck Date: Fri, 17 Jun 2022 15:23:02 +0200 Subject: Fix major bug --- Application/RemoveTransaction/index.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'Application/RemoveTransaction') diff --git a/Application/RemoveTransaction/index.php b/Application/RemoveTransaction/index.php index 138f6a8..be78185 100644 --- a/Application/RemoveTransaction/index.php +++ b/Application/RemoveTransaction/index.php @@ -43,11 +43,18 @@ if (!isset($_GET['Transaction'])) { die(); } -$list = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json"), true); +$list = array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions"), function ($i) { + return !str_starts_with($i, ".") && str_ends_with($i, ".json"); +}); -$list = array_filter($list, function ($item) { - return ($item["date"] !== base64url_decode($_GET['Transaction'])); +$list = array_filter(array_map(function ($item) { + $i = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions/" . $item), true); + $i["__file_id"] = $item; + return $i; +}, $list), function ($item) { + return ($item["date"] === base64url_decode($_GET['Transaction'])); }); +sort($list); +var_dump($list); -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions." . str_replace(":", "-", date('c')) . ".json", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json")); -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json", json_encode($list)); \ No newline at end of file +unlink($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions/" . $list[0]["__file_id"]); \ No newline at end of file -- cgit