summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-06-06 18:15:32 +0200
committerMinteck <contact@minteck.org>2022-06-06 18:15:32 +0200
commite18b9890f9c40950b331e829072f63b38ef72d11 (patch)
tree6dcb3b6d9231e33e2dbd0ad232c2673a467a442e
parent10b1ace835d908d32f99874facf8811534087d5b (diff)
downloadbits-server-e18b9890f9c40950b331e829072f63b38ef72d11.tar.gz
bits-server-e18b9890f9c40950b331e829072f63b38ef72d11.tar.bz2
bits-server-e18b9890f9c40950b331e829072f63b38ef72d11.zip
Commit
-rw-r--r--Application/AddTransaction/index.php82
-rw-r--r--Application/RemoveTransaction/index.php52
-rw-r--r--Private/ExchangeRate.txt1
3 files changed, 135 insertions, 0 deletions
diff --git a/Application/AddTransaction/index.php b/Application/AddTransaction/index.php
new file mode 100644
index 0000000..1c3d35f
--- /dev/null
+++ b/Application/AddTransaction/index.php
@@ -0,0 +1,82 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/Private/SessionManager.php"; global $_PROFILE;
+
+/**
+ * Encode data to Base64URL
+ * @param string $data
+ * @return boolean|string
+ */
+function base64url_encode($data)
+{
+ // First of all you should encode $data to Base64 string
+ $b64 = base64_encode($data);
+
+ // Make sure you get a valid result, otherwise, return FALSE, as the base64_encode() function do
+ if ($b64 === false) {
+ return false;
+ }
+
+ // Convert Base64 to Base64URL by replacing “+” with “-” and “/” with “_”
+ $url = strtr($b64, '+/', '-_');
+
+ // Remove padding character from the end of line and return the Base64URL result
+ return rtrim($url, '=');
+}
+
+/**
+ * Decode data from Base64URL
+ * @param string $data
+ * @param boolean $strict
+ * @return boolean|string
+ */
+function base64url_decode($data, $strict = false)
+{
+ // Convert Base64URL to Base64 by replacing “-” with “+” and “_” with “/”
+ $b64 = strtr($data, '-_', '+/');
+
+ // Decode Base64 string and return the original data
+ return base64_decode($b64, $strict);
+}
+
+if (!isset($_GET['Currency']) || !isset($_GET['Amount']) || !is_numeric($_GET['Amount']) || !isset($_GET['Description']) || !isset($_GET['Operation'])) {
+ die();
+}
+
+$list = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json"), true);
+$exchangeRate = (float)file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/ExchangeRate.txt");
+
+$eurToGbp = $exchangeRate;
+$gbpToEur = 1 / $eurToGbp;
+
+$list = array_reverse($list);
+
+if ($_GET['Currency'] === "€") {
+ $list[] = [
+ 'author' => $_PROFILE['id'],
+ 'type' => $_GET['Operation'] === "+" || $_GET['Operation'] === " " ? "gain" : "pay",
+ 'amount' => [
+ 'eur' => (float)$_GET['Amount'],
+ 'gbp' => (float)$_GET['Amount'] * $eurToGbp,
+ 'original' => 'eur'
+ ],
+ 'date' => date("c"),
+ 'description' => base64url_decode($_GET['Description'])
+ ];
+} else {
+ $list[] = [
+ 'author' => $_PROFILE['id'],
+ 'type' => $_GET['Operation'] === "+" || $_GET['Operation'] === " " ? "gain" : "pay",
+ 'amount' => [
+ 'eur' => (float)$_GET['Amount'] * $gbpToEur,
+ 'gbp' => (float)$_GET['Amount'],
+ 'original' => 'gbp'
+ ],
+ 'date' => date("c"),
+ 'description' => base64url_decode($_GET['Description'])
+ ];
+}
+
+$list = array_reverse($list);
+
+file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json", json_encode($list)); \ No newline at end of file
diff --git a/Application/RemoveTransaction/index.php b/Application/RemoveTransaction/index.php
new file mode 100644
index 0000000..ad0ed5d
--- /dev/null
+++ b/Application/RemoveTransaction/index.php
@@ -0,0 +1,52 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/Private/SessionManager.php"; global $_PROFILE;
+
+/**
+ * Encode data to Base64URL
+ * @param string $data
+ * @return boolean|string
+ */
+function base64url_encode($data)
+{
+ // First of all you should encode $data to Base64 string
+ $b64 = base64_encode($data);
+
+ // Make sure you get a valid result, otherwise, return FALSE, as the base64_encode() function do
+ if ($b64 === false) {
+ return false;
+ }
+
+ // Convert Base64 to Base64URL by replacing “+” with “-” and “/” with “_”
+ $url = strtr($b64, '+/', '-_');
+
+ // Remove padding character from the end of line and return the Base64URL result
+ return rtrim($url, '=');
+}
+
+/**
+ * Decode data from Base64URL
+ * @param string $data
+ * @param boolean $strict
+ * @return boolean|string
+ */
+function base64url_decode($data, $strict = false)
+{
+ // Convert Base64URL to Base64 by replacing “-” with “+” and “_” with “/”
+ $b64 = strtr($data, '-_', '+/');
+
+ // Decode Base64 string and return the original data
+ return base64_decode($b64, $strict);
+}
+
+if (!isset($_GET['Transaction'])) {
+ die();
+}
+
+$list = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json"), true);
+
+$list = array_filter($list, function ($item) {
+ return ($item["date"] !== base64url_decode($_GET['Transaction']));
+});
+
+file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json", json_encode($list)); \ No newline at end of file
diff --git a/Private/ExchangeRate.txt b/Private/ExchangeRate.txt
new file mode 100644
index 0000000..401600f
--- /dev/null
+++ b/Private/ExchangeRate.txt
@@ -0,0 +1 @@
+0.85 \ No newline at end of file