From 98a84f3aa735f31b08e807c8a4f0549742cbd1b0 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Tue, 16 May 2023 22:17:15 +0200 Subject: Updated 8 files (automated) --- pages/api/money/account.php | 2 +- pages/api/money/accounts.php | 4 +- pages/api/rename.php | 26 +++++++-- pages/api/session.php | 5 +- pages/money.inc | 124 +++++++++++++++++++++++++++++++++++++++++-- pages/pair.inc | 2 +- 6 files changed, 151 insertions(+), 12 deletions(-) (limited to 'pages') diff --git a/pages/api/money/account.php b/pages/api/money/account.php index 6620733..1801b28 100644 --- a/pages/api/money/account.php +++ b/pages/api/money/account.php @@ -29,7 +29,7 @@ foreach ($accounts as $account) { $acc["total"] = round(calculateFullAmount($account, true), 2); $acc["interests"] = $account["interests"]; $acc["max"] = $account["max"]; - $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null; + $acc["used_percentage"] = isset($account["max"]) ? round((calculateFullAmount($account, true) / $account["max"]) * 100, 2) : null; $acc["transactions"] = []; foreach ($account["transactions"] as $index => $transaction) { diff --git a/pages/api/money/accounts.php b/pages/api/money/accounts.php index 22d8c77..9f85323 100644 --- a/pages/api/money/accounts.php +++ b/pages/api/money/accounts.php @@ -58,7 +58,7 @@ foreach ($accounts as $index => $account) { $acc["total"] = round(calculateFullAmount($account, true), 2); $acc["interests"] = $account["interests"]; $acc["max"] = $account["max"]; - $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null; + $acc["used_percentage"] = isset($account["max"]) ? round((calculateFullAmount($account, true) / $account["max"]) * 100, 2) : null; $obj["users"]["cloudburst"]["accounts"][] = $acc; } @@ -84,7 +84,7 @@ foreach ($accounts as $index => $account) { $acc["total"] = round(calculateFullAmount($account, true), 2); $acc["interests"] = $account["interests"]; $acc["max"] = $account["max"]; - $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null; + $acc["used_percentage"] = isset($account["max"]) ? round((calculateFullAmount($account, true) / $account["max"]) * 100, 2) : null; $acc["transactions"] = null; $obj["users"]["raindrops"]["accounts"][] = $acc; diff --git a/pages/api/rename.php b/pages/api/rename.php index d450557..abec81e 100644 --- a/pages/api/rename.php +++ b/pages/api/rename.php @@ -10,8 +10,28 @@ if (!$isLoggedIn || $isLowerLoggedIn) { die(); } -$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $_COOKIE['PEH2_SESSION_TOKEN'])), true); +$obj = [ + "success" => true +]; -$data["name"] = $_GET["name"] ?? $data["name"]; +global $token; +$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $token)), true); -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $_COOKIE['PEH2_SESSION_TOKEN']), json_encode($data)); \ No newline at end of file +$data["name"] = $_POST["name"] ?? $_GET["name"] ?? $data["name"]; +$obj["pre_name"] = $data["name"]; + +$request_raw = file_get_contents('php://input'); +$json_object = json_decode($request_raw, true); + +if (json_last_error() === JSON_ERROR_NONE) { + $obj["json_error"] = [ json_last_error(), json_last_error_msg() ]; + if (isset($json_object["name"])) { + $data["name"] = $json_object["name"]; + $obj["json_name"] = $json_object["name"]; + } +} + +$obj["new_name"] = $data["name"]; + +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $token), json_encode($data)); +die(json_encode($obj)); \ No newline at end of file diff --git a/pages/api/session.php b/pages/api/session.php index f91288e..53e1845 100644 --- a/pages/api/session.php +++ b/pages/api/session.php @@ -14,11 +14,12 @@ if (!$isLoggedIn || $isLowerLoggedIn) { ], JSON_PRETTY_PRINT)); } -$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $_COOKIE['PEH2_SESSION_TOKEN'])), true); +global $token; +$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $token)), true); die(json_encode([ "name" => $data["name"], "created" => date('c', $data["created"]), "last_seen" => date('c', $data["last"]), - "seen_at" => array_keys($data["addresses"]) + "seen_at" => array_keys($data["addresses"] ?? []) ], JSON_PRETTY_PRINT)); \ No newline at end of file diff --git a/pages/money.inc b/pages/money.inc index 4d93398..1338a3a 100644 --- a/pages/money.inc +++ b/pages/money.inc @@ -100,6 +100,76 @@ if ((isset($_GET["create"]) || isset($_GET["delete"])) && isset($parts[2])) { $rate = (float)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/exchange.txt")); require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; +$transactionMonths = []; + +foreach ($accounts as $account) { + array_push($transactionMonths, ...array_map(function ($i) { return date('Y-m', strtotime($i["date"])); }, array_filter($account["transactions"], function ($i) { return !isset($i["initial"]) || !$i["initial"]; }))); +} + +$months = [ + ...[ + "2022-12", "2022-11", "2022-10", "2022-09", + "2022-08", "2022-07", "2022-06" + ], + ...array_values(array_filter(array_unique(array_reduce($transactionMonths, function ($a, $b) { + return [...$a, $b]; + }, [])), function ($i) { + return $i !== date('Y-m'); + })) +]; + +$monthlyCloudburst = []; +$monthlyRaindrops = []; + +$bits = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/bits.json"), true); +$projects = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/projects.json"), true); + +foreach ($bits["cloudburst"] as $month => $value) { + $monthlyCloudburst[$month] = $value; +} + +foreach ($bits["raindrops"] as $month => $value) { + $monthlyRaindrops[$month] = $value; +} + +foreach ($months as $month) { + $gainedCloudburst = $monthlyCloudburst[$month] ?? 0; + $gainedRaindrops = $monthlyRaindrops[$month] ?? 0; + + foreach ($accounts as $account) { + foreach ($account["transactions"] as $transaction) { + if (isset($transaction["initial"]) && $transaction["initial"]) continue; + if (date('Y-m', strtotime($transaction["date"])) !== $month) continue; + + if ($account["owner"] === "raindrops") { + $gainedRaindrops += $transaction["amount"]; + } else { + $gainedCloudburst += $transaction["amount"]; + } + } + } + + $monthlyCloudburst[$month] = $gainedCloudburst; + $monthlyRaindrops[$month] = $gainedRaindrops; +} + +uksort($monthlyCloudburst, function ($k1, $k2) { + return strtotime($k2) - strtotime($k1); +}); + +uksort($monthlyRaindrops, function ($k1, $k2) { + return strtotime($k2) - strtotime($k1); +}); + +function getMonthlyEarnings(): array { + global $monthlyRaindrops; + global $monthlyCloudburst; + + return [ + "cloudburst" => array_sum(array_values($monthlyCloudburst)) / count($monthlyCloudburst), + "raindrops" => array_sum(array_values($monthlyRaindrops)) / count($monthlyRaindrops) + ]; +} ?> @@ -267,7 +337,21 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; return $a + $b; }); - ?>£) + ?>£, earning £/month) +
+
+ Show monthly earnings + + + $value): ?> + + + + + +
:">£
+
+
$account): if ($account["owner"] === "cloudburst"): ?> "> @@ -385,7 +469,21 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; return $a + $b; }); - ?>€) + ?>€, earning €/month) +
+
+ Show monthly earnings + + + $value): ?> + + + + + +
:">€
+
+
$account): if ($account["owner"] === "raindrops"): ?> "> @@ -423,6 +521,26 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc';

">€ $minimumRaindrops): ?> (%) $minimumRaindrops ? "over" : "under" ?> the minimum

+ +
+
+ " style="width: 100%;"> +
+
+
+

+
+
%">
+
+ 0): $months = ceil($missing / getMonthlyEarnings()["raindrops"]); ?> +
Costs € · Missing € · Can afford it in (in month 1 ? "s" : "" ?>)
+
You can afford it now, this will take you to the minimum.
+
You can afford it now, this will take you € above the minimum.
+
+
+
+ +
Add new transaction
$transaction): $member = getMemberWithoutSystem($transaction["author"]) ?? getMemberWithoutSystem("zdtsg"); ?> -
" style="border-radius: 999px; width: 32px; height: 32px; margin-right: 10px;">
 "> :
+
" style="border-radius: 999px; width: 32px; height: 32px; margin-right: 10px;">
 "> : Initial amount
diff --git a/pages/pair.inc b/pages/pair.inc index fa301ad..2fafc31 100644 --- a/pages/pair.inc +++ b/pages/pair.inc @@ -89,7 +89,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; glob const modal = new bootstrap.Modal(document.getElementById("confirm")); function getIconForName(name) { - if (name.startsWith("Luna Desktop ")) { + if (name.startsWith("Luna Desktop ") || name.startsWith("Luna Mobile ")) { return "https://git.equestria.dev/equestria.dev/luna/raw/branch/mane/icons/logo.png"; } -- cgit