-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredit_card_details.php
256 lines (227 loc) · 8.56 KB
/
credit_card_details.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
session_start();
include 'db_user_connection.php';
if (!isset($_SESSION['username'])) {
header("Location: index.html"); // If not logged in, redirect to login page.
exit();
}
$current_username = $_SESSION['username']; // Currently logged-in username
// Handle POST request to freeze or unlock the card
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'], $_POST['card_number'])) {
$action = $_POST['action'];
$card_number = $_POST['card_number'];
// Validate action
if (!in_array($action, ['freeze', 'unlock'])) {
$error_message = "Invalid action.";
} else {
// Check if the card belongs to the logged-in user
$stmt = $conn->prepare("
SELECT cards.id, cards.blocked
FROM cards
INNER JOIN users ON cards.cardholder_id = users.id
WHERE cards.card_number = ? AND users.username = ?
");
$stmt->bind_param("ss", $card_number, $current_username);
$stmt->execute();
$result = $stmt->get_result();
$card_data = $result->fetch_assoc();
$stmt->close();
if (!$card_data) {
$error_message = "Card not found or access denied.";
} else {
// Update card's blocked status
$new_blocked_status = ($action === 'freeze') ? 1 : 0;
$stmt = $conn->prepare("UPDATE cards SET blocked = ? WHERE card_number = ?");
$stmt->bind_param("is", $new_blocked_status, $card_number);
if ($stmt->execute()) {
$success_message = "Card status updated successfully.";
} else {
$error_message = "Failed to update card status.";
}
$stmt->close();
}
}
}
// Get the card number from the query string
$card_number = isset($_GET['card']) ? $_GET['card'] : null;
if (!$card_number) {
header("Location: 404.php"); // If no card number is provided, redirect to 404 page.
exit();
}
// Start timing
$start_time = microtime(true);
// Query to check if the credit card exists and belongs to the current user
$stmt = $conn->prepare("
SELECT creditcards.*, cards.card_number, cards.blocked, users.username
FROM creditcards
INNER JOIN cards ON creditcards.id = cards.id
INNER JOIN users ON cards.cardholder_id = users.id
WHERE cards.card_number = ? AND users.username = ?
");
$stmt->bind_param("ss", $card_number, $current_username);
$stmt->execute();
$result = $stmt->get_result();
// Fetch card details
$card_data = $result->fetch_assoc();
$stmt->close();
// If no card is found or it does not belong to the current user, redirect to 404
if (!$card_data) {
header("Location: 404.php");
exit();
}
// 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>Credit Card Details | 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>Credit Card Details</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">
<h1>Credit Card Details</h1>
<div class="details">
<p><strong>Card Number:</strong> <?php echo htmlspecialchars($card_data['card_number']); ?></p>
<p><strong>Repayment Date:</strong> <?php echo htmlspecialchars($card_data['repayment_date'] ?? 'N/A'); ?></p>
<p><strong>Credit Limit:</strong> <?php echo number_format($card_data['quota'], 2); ?> HKD</p>
<p><strong>Available Balance:</strong> <?php echo number_format($card_data['remaining_quota'], 2); ?> HKD</p>
<p><strong>Card Status:</strong> <?php echo $card_data['blocked'] == 0 ? 'Active' : 'Frozen'; ?></p>
</div>
<!-- Display messages -->
<?php if (isset($success_message)): ?>
<p style="color: green;"><?php echo $success_message; ?></p>
<?php elseif (isset($error_message)): ?>
<p style="color: red;"><?php echo $error_message; ?></p>
<?php endif; ?>
<div class="button-group">
<!-- Freeze button -->
<form method="POST" style="display: inline;">
<input type="hidden" name="card_number" value="<?php echo htmlspecialchars($card_data['card_number']); ?>">
<input type="hidden" name="action" value="freeze">
<button
class="freeze-button"
<?php echo $card_data['blocked'] == 1 ? 'disabled' : ''; ?>
onmouseover="handleMouseOver(this, <?php echo $card_data['blocked'] == 1 ? 'true' : 'false'; ?>)"
onmouseout="handleMouseOut(this)"
>
Freeze Card
</button>
</form>
<!-- Unlock button -->
<form method="POST" style="display: inline;">
<input type="hidden" name="card_number" value="<?php echo htmlspecialchars($card_data['card_number']); ?>">
<input type="hidden" name="action" value="unlock">
<button
class="unlock-button"
<?php echo $card_data['blocked'] == 0 ? 'disabled' : ''; ?>
onmouseover="handleMouseOver(this, <?php echo $card_data['blocked'] == 0 ? 'true' : 'false'; ?>)"
onmouseout="handleMouseOut(this)"
>
Unlock Card
</button>
</form>
</div>
<div style="text-align: center;">
<a href="./user_card_management.php" style="text-decoration: none; color: #007BFF;">Back to Card Management</a>
</div>
</div>
<footer class="footer">
<?php if ($execution_time): ?>
It took <?php echo $execution_time; ?> milliseconds to get data from the server.
<?php endif; ?>
©2024 Global Banking Corporation Limited. All rights reserved.
</footer>
<script>
function handleCardAction(action) {
const cardNumber = "<?php echo htmlspecialchars($card_data['card_number']); ?>";
const confirmation = confirm(`Are you sure you want to ${action} the card ending in ${cardNumber.slice(-4)}?`);
if (confirmation) {
alert(`Card ending in ${cardNumber.slice(-4)} has been ${action}ed.`);
}
}
function handleMouseOver(button, isDisabled) {
if (isDisabled) {
button.classList.add('hover-disabled');
button.title = "This action is currently disabled";
}
}
function handleMouseOut(button) {
button.classList.remove('hover-disabled');
button.title = "";
}
</script>
<style>
.container {
max-width: 600px;
margin: 50px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
}
.details {
margin: 20px 0;
}
.details p {
font-size: 16px;
margin-bottom: 10px;
}
.button-group {
text-align: center;
margin-top: 20px;
}
.button-group button {
padding: 10px 20px;
margin: 10px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.freeze-button {
background-color: #FF4C4C;
color: white;
}
.freeze-button:hover {
background-color: #E53935;
}
.unlock-button {
background-color: #4CAF50;
color: white;
}
.unlock-button:hover {
background-color: #388E3C;
}
.freeze-button.hover-disabled,
.unlock-button.hover-disabled {
background-color: #cccccc !important;
cursor: not-allowed !important;
color: #666666 !important;
}
.freeze-button:hover:not(.hover-disabled) {
background-color: #E53935;
}
.unlock-button:hover:not(.hover-disabled) {
background-color: #388E3C;
}
</style>
</body>
</html>