-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin_Card_Management.php
More file actions
143 lines (127 loc) · 5.3 KB
/
Copy pathAdmin_Card_Management.php
File metadata and controls
143 lines (127 loc) · 5.3 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
<?php
session_start();
include 'db_connection.php';
// Check if the user is an administrator
if (!isset($_SESSION['username']) || $_SESSION['role'] !== 'admin') {
header("Location: admin_login.html"); // Redirect to login page if not logged in or non-administrator
exit();
}
$search_result = '';
$execution_time = ''; // Used to store execution time
$cards = []; // Used to store searched card information
$user_id = ''; // Initialize user ID to null
// Handling Search User IDs
if (isset($_POST['search_user'])) {
$user_id = $_POST['user_id']; // Get the user ID entered by the user
// start counting
$start_time = microtime(true);
// Query all card information under this user ID
$stmt = $conn->prepare("SELECT * FROM cards WHERE cardholder_id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
// If the card information is queried, it is stored in an array
if ($result->num_rows > 0) {
$cards = [];
while ($row = $result->fetch_assoc()) {
$cards[] = $row; // Storing card information into an array
}
$search_result = "<table border='1'><tr><th>Card Type</th><th>Card Number</th><th>Status</th><th>Actions</th></tr>";
foreach ($cards as $card) {
$search_result .= "<tr>
<td>" . htmlspecialchars($card['type']) . "</td>
<td>" . htmlspecialchars($card['card_number']) . "</td> <!-- 直接显示卡号 -->
<td>" . ($card['blocked'] == 0 ? 'Active' : 'Blocked') . "</td>
<td>
" . ($card['blocked'] == 0 ?
"<button onclick=\"location.href='block_card.php?card_id=" . $card['id'] . "'\">Block Card</button>" :
"<button onclick=\"location.href='unblock_card.php?card_id=" . $card['id'] . "'\">Unblock Card</button>") .
</td>
</tr>";
}
$search_result .= "</table>";
} else {
$search_result = "No cards found for this user.";
}
$stmt->close();
//End timing
$end_time = microtime(true);
$execution_time = round(($end_time - $start_time) * 1000, 2); // Convert to milliseconds
}
// Processing clear search results
if (isset($_POST['clear'])) {
$search_result = ''; // Clear Search Results
$execution_time = ''; // Clear execution time
$user_id = ''; // Clear User ID
}
?>
<!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>Card Management | GBC Internet Banking</title>
</head>
<body>
<!-- Header -->
<header class="header">
<div class="header__content">
<div class="header__logo">
<a href="./admin_dashboard.php"><img src="./assets/logo.png" alt="Bank Logo"></a>
</div>
<h1>Card Management</h1>
<div class="header__right">
Current Administrator: <?php echo htmlspecialchars($_SESSION['username']); ?>
<button class="logout-button" style="margin-left: 10px;" onclick="window.location.href='logout.php'">Logout</button>
</div>
</div>
</header>
<!-- Main Dashboard Content -->
<main class="dashboard">
<!-- Search User ID Function -->
<section class="user-search">
<h2>Search User's Cards</h2>
<form method="post" action="">
<label for="user_id">User ID:</label>
<input type="text" name="user_id" id="user_id" value="<?php echo htmlspecialchars($user_id); ?>" required>
<input type="submit" name="search_user" value="Search">
<input type="submit" name="clear" value="Clear"> <!-- Clear Search Results button -->
</form>
<!-- Show search results -->
<div>
<?php if ($execution_time): ?>
<p>Search executed in <span><?php echo $execution_time; ?></span> milliseconds.</p><br>
<?php endif; ?>
<?php
// Output search results
if ($search_result) {
echo $search_result;
}
?>
</div>
</section>
<!-- Return to Admin Panel -->
<div class="back-link">
<p><a href="javascript:history.back()">Return to the previous page</a></p>
</div>
</main>
<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>
</body>
</html>
<style>
.back-link {
text-align: center;
margin-top: 20px;
}
.back-link a {
text-decoration: none;
color: #0064d2;
}
</style>