diff options
-rw-r--r-- | .DS_Store | bin | 0 -> 6148 bytes | |||
-rw-r--r-- | Application/AddTransaction/index.php | 13 | ||||
-rw-r--r-- | Application/RemoveTransaction/index.php | 17 | ||||
-rw-r--r-- | Application/TransactionsList/index.php | 8 | ||||
-rw-r--r-- | Private/.DS_Store | bin | 0 -> 6148 bytes | |||
-rw-r--r-- | Private/SessionManager.php | 2 |
6 files changed, 23 insertions, 17 deletions
diff --git a/.DS_Store b/.DS_Store Binary files differnew file mode 100644 index 0000000..7fd6dd1 --- /dev/null +++ b/.DS_Store diff --git a/Application/AddTransaction/index.php b/Application/AddTransaction/index.php index e6b7d34..ef2f339 100644 --- a/Application/AddTransaction/index.php +++ b/Application/AddTransaction/index.php @@ -43,16 +43,14 @@ if (!isset($_GET['Currency']) || !isset($_GET['Amount']) || !is_numeric($_GET['A die(); } -$list = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json"), true); +$transaction = []; $exchangeRate = (float)file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/ExchangeRate.txt"); $eurToGbp = $exchangeRate; $gbpToEur = 1 / $eurToGbp; -$list = array_reverse($list); - if ($_GET['Currency'] === "€") { - $list[] = [ + $transaction = [ 'author' => $_PROFILE['id'], 'type' => $_GET['Operation'] === "+" || $_GET['Operation'] === " " ? "gain" : "pay", 'amount' => [ @@ -64,7 +62,7 @@ if ($_GET['Currency'] === "€") { 'description' => base64url_decode($_GET['Description']) ]; } else { - $list[] = [ + $transaction = [ 'author' => $_PROFILE['id'], 'type' => $_GET['Operation'] === "+" || $_GET['Operation'] === " " ? "gain" : "pay", 'amount' => [ @@ -77,7 +75,4 @@ if ($_GET['Currency'] === "€") { ]; } -$list = array_reverse($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 +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions/" . date('U') . ".json", json_encode($transaction));
\ No newline at end of file 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 diff --git a/Application/TransactionsList/index.php b/Application/TransactionsList/index.php index 185e94b..4bb56e0 100644 --- a/Application/TransactionsList/index.php +++ b/Application/TransactionsList/index.php @@ -33,10 +33,14 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/Private/SessionManager.php"; header("Content-Type: application/json"); $users = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Users.json"), true); -$list = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json"), true); +$list = array_reverse(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions"), function ($i) { + return !str_starts_with($i, ".") && str_ends_with($i, ".json"); +})); $plist = []; -foreach ($list as $item) { +foreach ($list as $id) { + $item = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions/" . $id), true); + $item["author"] = [ "id" => $item["author"], "name" => $users[$item["author"]] ?? $item["author"], diff --git a/Private/.DS_Store b/Private/.DS_Store Binary files differnew file mode 100644 index 0000000..2294be5 --- /dev/null +++ b/Private/.DS_Store diff --git a/Private/SessionManager.php b/Private/SessionManager.php index 05b443f..ad86ea6 100644 --- a/Private/SessionManager.php +++ b/Private/SessionManager.php @@ -1,7 +1,7 @@ <?php if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/Data")) mkdir($_SERVER['DOCUMENT_ROOT'] . "/Data"); -if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/Data/Transactions.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Data/Transactions.json", "[]"); +if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/Data/Transactions")) mkdir($_SERVER['DOCUMENT_ROOT'] . "/Data/Transactions"); if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/Data/Goal.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Data/Goal.json", '{"name": "No goal","amount": {"eur": 0,"gbp": 0}}'); if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/Data/Users.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Data/Users.json", "{}"); |