1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Smr\Pages\Player\Bank; |
4
|
|
|
|
5
|
|
|
use AbstractSmrPlayer; |
6
|
|
|
use Menu; |
7
|
|
|
use Smr\Database; |
8
|
|
|
use Smr\Page\PlayerPage; |
9
|
|
|
use Smr\Session; |
10
|
|
|
use Smr\Template; |
11
|
|
|
use SmrPlayer; |
12
|
|
|
|
13
|
|
|
class AnonBankDetail extends PlayerPage { |
14
|
|
|
|
15
|
|
|
public string $file = 'bank_anon_detail.php'; |
16
|
|
|
|
17
|
|
|
public function __construct( |
18
|
|
|
private readonly int $anonBankID, |
19
|
|
|
) {} |
20
|
|
|
|
21
|
|
|
public function build(AbstractSmrPlayer $player, Template $template): void { |
22
|
|
|
$session = Session::getInstance(); |
23
|
|
|
|
24
|
|
|
$account_num = $this->anonBankID; |
25
|
|
|
$maxValue = $session->getRequestVarInt('maxValue', 0); |
26
|
|
|
$minValue = $session->getRequestVarInt('minValue', 0); |
27
|
|
|
|
28
|
|
|
$db = Database::getInstance(); |
29
|
|
|
$dbResult = $db->read('SELECT * |
30
|
|
|
FROM anon_bank |
31
|
|
|
WHERE anon_id=' . $db->escapeNumber($account_num) . ' |
32
|
|
|
AND game_id=' . $db->escapeNumber($player->getGameID())); |
33
|
|
|
$dbRecord = $dbResult->record(); |
34
|
|
|
|
35
|
|
|
$balance = $dbRecord->getInt('amount'); |
36
|
|
|
$template->assign('Balance', $balance); |
37
|
|
|
|
38
|
|
|
if ($maxValue <= 0) { |
39
|
|
|
$dbResult = $db->read('SELECT IFNULL(MAX(transaction_id), 5) as max_transaction_id FROM anon_bank_transactions |
40
|
|
|
WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' |
41
|
|
|
AND anon_id=' . $db->escapeNumber($account_num)); |
42
|
|
|
$maxValue = $dbResult->record()->getInt('max_transaction_id'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ($minValue <= 0 || $minValue >= $maxValue) { |
46
|
|
|
$minValue = max(1, $maxValue - 5); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$query = 'SELECT * |
50
|
|
|
FROM player |
51
|
|
|
JOIN anon_bank_transactions USING (game_id, account_id) |
52
|
|
|
WHERE player.game_id=' . $db->escapeNumber($player->getGameID()) . ' |
53
|
|
|
AND anon_bank_transactions.anon_id=' . $db->escapeNumber($account_num); |
54
|
|
|
|
55
|
|
|
if ($maxValue > 0) { |
56
|
|
|
$query .= ' AND transaction_id>=' . $db->escapeNumber($minValue) . ' |
57
|
|
|
AND transaction_id<=' . $db->escapeNumber($maxValue) . ' |
58
|
|
|
ORDER BY time LIMIT ' . (1 + $maxValue - $minValue); |
59
|
|
|
} else { |
60
|
|
|
$query .= ' ORDER BY time LIMIT 10'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$dbResult = $db->read($query); |
64
|
|
|
|
65
|
|
|
// only if we have at least one result |
66
|
|
|
if ($dbResult->hasRecord()) { |
67
|
|
|
$template->assign('MinValue', $minValue); |
68
|
|
|
$template->assign('MaxValue', $maxValue); |
69
|
|
|
$container = new self($account_num); |
70
|
|
|
$template->assign('ShowHREF', $container->href()); |
71
|
|
|
|
72
|
|
|
$transactions = []; |
73
|
|
|
foreach ($dbResult->records() as $dbRecord) { |
74
|
|
|
$transactionPlayer = SmrPlayer::getPlayer($dbRecord->getInt('account_id'), $player->getGameID(), false, $dbRecord); |
75
|
|
|
$transaction = $dbRecord->getString('transaction'); |
76
|
|
|
$amount = number_format($dbRecord->getInt('amount')); |
77
|
|
|
$transactions[$dbRecord->getInt('transaction_id')] = [ |
78
|
|
|
'date' => date($player->getAccount()->getDateTimeFormatSplit(), $dbRecord->getInt('time')), |
79
|
|
|
'payment' => $transaction == 'Payment' ? $amount : '', |
80
|
|
|
'deposit' => $transaction == 'Deposit' ? $amount : '', |
81
|
|
|
'link' => $transactionPlayer->getLinkedDisplayName(), |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
$template->assign('Transactions', $transactions); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$container = new AnonBankDetailProcessor($account_num); |
88
|
|
|
$template->assign('TransactionHREF', $container->href()); |
89
|
|
|
|
90
|
|
|
$template->assign('PageTopic', 'Anonymous Account #' . $account_num); |
91
|
|
|
Menu::bank(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|