-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_card_management.php
More file actions
212 lines (188 loc) · 6.22 KB
/
Copy pathuser_card_management.php
File metadata and controls
212 lines (188 loc) · 6.22 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
session_start();
include 'db_user_connection.php';
if (!isset($_SESSION['username'])) {
header("Location: index.html"); // Jump to login page if not logged in
exit();
}
$current_username = $_SESSION['username'];
// Start timing
$start_time = microtime(true);
// Query to fetch current user's cards
$stmt = $conn->prepare("
SELECT cards.card_number, cards.card_type, cards.blocked
FROM cards
INNER JOIN users ON cards.cardholder_id = users.id
WHERE users.username = ?
");
$stmt->bind_param("s", $current_username);
$stmt->execute();
$result = $stmt->get_result();
$user_cards = [];
while ($row = $result->fetch_assoc()) {
$user_cards[] = [
'cardNumber' => $row['card_number'],
'type' => $row['card_type'] === 'credit' ? 'Credit Card' : 'Debit Card',
'detailsPage' => $row['card_type'] === 'credit' ? "credit_card_details.php?card={$row['card_number']}" : "debit_card_details.php?card={$row['card_number']}"
];
}
$stmt->close();
// End timing
$end_time = microtime(true);
$execution_time = round(($end_time - $start_time) * 1000, 2); // Convert to milliseconds
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./css/dashboard.css" />
<link rel="icon" href="assets/logo.png" type="image/png">
<title>My Cards | GBC Internet Banking</title>
</head>
<body>
<!-- Header -->
<header class="header">
<div class="header__content">
<div class="header__logo">
<a href="./dashboard.php"><img src="./assets/logo.png" alt="Bank Logo"></a>
</div>
<h1>Cards Overview</h1>
<div class="header__right">
Current User: <?php echo htmlspecialchars($_SESSION['username']); ?>
<button class="logout-button" style="margin-left: 10px;" onclick="window.location.href='logout.php'">Logout</button>
</div>
</div>
</header>
<div class="container" style="margin-top: 150px;">
<!-- Filter Buttons -->
<div class="filter-buttons">
<button onclick="filterCards('all')">Show All</button>
<button onclick="filterCards('Credit Card')">Credit Cards</button>
<button onclick="filterCards('Debit Card')">Debit Cards</button>
</div>
<!-- Card List -->
<div class="card-list" id="cardList">
<!-- Cards will be displayed here dynamically -->
</div>
</div>
<div class="back-link">
<p><a href="./dashboard.php">Return to the Dashboard</a></p>
</div>
<!-- Footer -->
<footer class="footer">
<?php if ($execution_time): ?>
It took <?php echo $execution_time; ?> milliseconds to get data from the server.</p>
<?php endif; ?>
©2024 Global Banking Corporation Limited. All rights reserved.
</footer>
<script>
// Dynamically load cards from PHP
const userCards = <?php echo json_encode($user_cards); ?>;
// Function to load and filter cards
function filterCards(filter) {
const cardList = document.getElementById('cardList');
cardList.innerHTML = ''; // Clear the list
const filteredCards = filter === 'all' ? userCards : userCards.filter(card => card.type === filter);
renderCards(filteredCards);
}
// Function to filter by search
function filterBySearch() {
const searchValue = document.getElementById('searchBox').value.toLowerCase();
const filteredCards = userCards.filter(card => card.cardNumber.toLowerCase().includes(searchValue));
renderCards(filteredCards);
}
// Function to render cards
function renderCards(cards) {
const cardList = document.getElementById('cardList');
cardList.innerHTML = '';
if (cards.length === 0) {
cardList.innerHTML = '<p>No cards found.</p>';
return;
}
cards.forEach(card => {
const cardItem = document.createElement('div');
cardItem.classList.add('card-item');
cardItem.innerHTML = `
<span>${card.cardNumber} (${card.type})</span>
<button class="details-button" onclick="window.location.href='${card.detailsPage}'">View Details</button>
`;
cardList.appendChild(cardItem);
});
}
// Load all cards on page load
window.onload = () => filterCards('all');
</script>
</body>
</html>
<style>
.container {
width: 80%;
margin: 120px auto 20px;
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.filter-buttons {
text-align: center;
margin-bottom: 20px;
}
.filter-buttons button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin: 0 10px;
}
.filter-buttons button:hover {
background-color: #45a049;
}
.search-container {
text-align: center;
margin: 20px auto;
}
.search-container input {
width: 60%;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
}
.card-list {
max-width: 800px;
margin: 20px auto;
text-align: left;
}
.card-item {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
background-color: #fff;
}
.card-item .details-button {
padding: 5px 10px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.card-item .details-button:hover {
background-color: #0056b3;
}
.back-link {
text-align: center;
margin-top: 20px;
}
.back-link a {
text-decoration: none;
color: #0064d2;
}
</style>