-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransactions_overview.php
186 lines (168 loc) · 6.16 KB
/
transactions_overview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Transactions Overview</title>
<link rel="stylesheet" href="style.css">
<style>
/* Your existing styles */
body {
font-family: Arial, sans-serif;
}
.container {
width: 80%;
margin: auto;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.error {
color: red;
}
.pagination {
display: flex;
justify-content: center;
margin-top: 20px;
}
.pagination a {
margin: 0 5px;
text-decoration: none;
color: white;
background-color: #007bff; /* Bootstrap primary color */
padding: 10px 15px;
border: none;
border-radius: 5px;
transition: background-color 0.3s, transform 0.2s;
font-weight: bold;
}
.pagination a:hover {
background-color: #0056b3; /* Darker shade for hover */
transform: scale(1.05); /* Slightly enlarge on hover */
}
.pagination .active {
background-color: #0056b3; /* Active page color */
color: white;
pointer-events: none; /* Disable clicking on active page */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Shadow effect */
}
.pagination .disabled {
background-color: #ccc; /* Disabled state color */
color: #999; /* Disabled text color */
pointer-events: none; /* Disable clicking */
}
</style>
</head>
<body>
<div class="container">
<h1>Transactions Overview</h1>
<?php
// Include database configuration
include 'config_1.php'; // Ensure this file has the function getDbConnection()
// Create a new database connection
$conn = getDbConnection();
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Query to fetch blocks from the database
$query = "SELECT blockHash, timestamp, transactions FROM blocks ORDER BY id DESC";
$result = $conn->query($query);
if (!$result) {
die("Query failed: " . $conn->error);
}
// Load transactions data from blocks
$transactions = [];
if ($result && $result->num_rows > 0) {
while ($block = $result->fetch_assoc()) {
// Directly use blockHash and timestamp without decryption
if (isset($block['blockHash']) && isset($block['timestamp'])) {
// Decode transactions JSON field
if (isset($block['transactions'])) {
$decodedTransactions = json_decode($block['transactions'], true); // Decode JSON into an array
if (is_array($decodedTransactions)) {
foreach ($decodedTransactions as $transaction) {
// Check if transaction has required fields before adding to the list
if (isset($transaction['id'], $transaction['sender'], $transaction['recipient'], $transaction['amount'], $transaction['timestamp'])) {
// Add transaction to the list without decryption
$transactionDetails = [
'id' => htmlspecialchars($transaction['id']),
'sender' => htmlspecialchars($transaction['sender']),
'recipient' => htmlspecialchars($transaction['recipient']),
'amount' => floatval($transaction['amount']),
'timestamp' => htmlspecialchars($transaction['timestamp'])
];
// Add transaction to the transactions array
$transactions[] = $transactionDetails;
}
}
}
}
}
}
}
// Check if there are any transactions
if (empty($transactions)) {
echo '<div class="error">No transactions found.</div>';
} else {
// Calculate total number of pages for pagination
$totalPages = ceil(count($transactions) / 19);
// Determine current page
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
// Validate current page
if ($currentPage < 1 || $currentPage > $totalPages) {
$currentPage = 1;
}
// Slice transactions array based on current page
$start = ($currentPage - 1) * 19;
$paginatedTransactions = array_slice($transactions, $start, 19);
// Display transactions in a table
echo '<table>';
echo '<tr>';
echo '<th>Transaction ID</th>';
echo '<th>Sender</th>';
echo '<th>Recipient</th>';
echo '<th>Amount (Tahcoins)</th>';
echo '<th>Date</th>';
echo '</tr>';
foreach ($paginatedTransactions as $transaction) {
echo '<tr>';
echo '<td><a href="transaction_details.php?transactionId=' . htmlspecialchars($transaction['id']) . '">' . htmlspecialchars($transaction['id']) . '</a></td>';
echo '<td>' . htmlspecialchars($transaction['sender']) . '</td>';
echo '<td>' . htmlspecialchars($transaction['recipient']) . '</td>';
echo '<td>' . htmlspecialchars($transaction['amount']) . '</td>';
echo '<td>' . htmlspecialchars($transaction['timestamp']) . '</td>';
echo '</tr>';
}
echo '</table>';
// Display pagination links below the table
echo '<div class="pagination">';
// Previous button
if ($currentPage > 1) {
echo '<a href="?page=' . ($currentPage - 1) . '">Previous</a>';
} else {
echo '<span class="disabled">Previous</span>';
}
// Next button
if ($currentPage < $totalPages) {
echo '<a href="?page=' . ($currentPage + 1) . '">Next</a>';
} else {
echo '<span class="disabled">Next</span>';
}
echo '</div>';
}
// Close the database connection
$conn->close();
?>
</div>
</body>
</html>