summaryrefslogtreecommitdiff
path: root/Application
diff options
context:
space:
mode:
Diffstat (limited to 'Application')
-rw-r--r--Application/AddTransaction/index.php13
-rw-r--r--Application/RemoveTransaction/index.php17
-rw-r--r--Application/TransactionsList/index.php8
3 files changed, 22 insertions, 16 deletions
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"],