File: /home/bigisxfd/public_html/cowork/scan.php
<?php
// Include necessary files
include_once("header.php");
include_once("sidebar.php");
// Initialize variables to store member details
$memberId = "";
$memberName = "";
$birthday = "";
$email = "";
$activeBooking = null;
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["rfid"])) {
$rfid = $_POST["rfid"];
// Fetch member details from the database based on RFID
$query = "SELECT memberid, firstname, lastname, birthday, email FROM Members WHERE rfid = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("s", $rfid);
$stmt->execute();
$stmt->bind_result($memberId, $firstname, $lastname, $birthday, $email);
$stmt->fetch();
$stmt->close();
// Check if the member has an active booking
$activeBookingQuery = "SELECT B.bookingid, B.startdate, B.enddate, M.packagename FROM Bookings B
INNER JOIN Memberships M ON B.packageid = M.packageid
WHERE B.memberid = ? AND B.active = 1";
$activeBookingStmt = $conn->prepare($activeBookingQuery);
$activeBookingStmt->bind_param("i", $memberId);
$activeBookingStmt->execute();
$activeBookingResult = $activeBookingStmt->get_result();
if ($activeBookingResult->num_rows > 0) {
$activeBooking = $activeBookingResult->fetch_assoc();
$currentDate = date('Y-m-d H:i:s');
$remainingTime = strtotime($activeBooking['enddate']) - strtotime($currentDate);
// Update the login data in the Booking table
$updateLoginQuery = "UPDATE Bookings SET login = ? WHERE active = 1 AND memberid = ?";
$updateLoginStmt = $conn->prepare($updateLoginQuery);
// Check if the statement was prepared successfully
if ($updateLoginStmt === false) {
die('Error preparing statement: ' . $conn->error);
}
// Bind the parameters
$updateLoginStmt->bind_param("si", $currentDate, $memberId);
// Execute the update query
$updateResult = $updateLoginStmt->execute();
}
}
// Fetch inactive bookings
$onlineBookings = getOnlineBookings(); // Define this function to fetch inactive bookings
?>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.column {
width: 80%;
margin: auto;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
margin-top: 0;
}
form {
margin-bottom: 20px;
}
label {
font-weight: bold;
}
input[type="text"] {
padding: 8px;
width: 200px;
}
button[type="submit"] {
padding: 8px 20px;
background-color: #3498db;
color: white;
border: none;
cursor: pointer;
}
h3 {
font-size: 1.2em;
margin-top: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
strong {
font-weight: bold;
}
</style>
<section>
<div class="column">
<h2>Member Details</h2>
<form action="" method="post">
<input type="text" name="rfid" id="rfid">
<button type="submit">Lookup</button>
</form>
<?php if ($memberId !== ""): ?>
<h3>Member Information:</h3>
<table>
<tr>
<td width="30%"><strong>Name</strong></td>
<td width="70%"><?php echo $firstname . " " . $lastname; ?></td>
</tr>
<tr>
<td><strong>Birthday</strong></td>
<td><?php echo $birthday; ?></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td><?php echo $email; ?></td>
</tr>
</table>
<?php if ($activeBooking): ?>
<h3>Active Booking:</h3>
<table>
<tr>
<td width="30%"><strong>Package Name</strong></td>
<td width="70%"><?php echo $activeBooking['packagename']; ?></td>
</tr>
<tr>
<td><strong>Start Date</strong></td>
<td><?php echo date("F j, Y", strtotime($activeBooking['startdate'])); ?></td>
</tr>
<tr>
<td><strong>End Date</strong></td>
<td><?php echo date("F j, Y", strtotime($activeBooking['enddate'])); ?></td>
</tr>
<tr>
<td><strong>Remaining Time</strong></td>
<td><?php echo getRemainingTime($remainingTime); ?></td>
</tr>
</table>
<?php else: ?>
<h2>No current active booking</h2>
<?php endif; ?>
<?php endif; ?>
</div>
</section>
</body>
</html>
<?php
function getRemainingTime($seconds) {
$days = floor($seconds / (60 * 60 * 24));
$hours = floor(($seconds % (60 * 60 * 24)) / (60 * 60));
$minutes = floor(($seconds % (60 * 60)) / 60);
$timeRemaining = "";
if ($days > 0) {
$timeRemaining .= "$days days, ";
}
if ($hours > 0) {
$timeRemaining .= "$hours hours, ";
}
$timeRemaining .= "$minutes minutes";
return $timeRemaining;
}
?>