File: /home/bigisxfd/public_html/cowork/extend.php
<?php $tkn_parameter_group='';
// Include necessary files
include_once("header.php");
include_once("sidebar.php");
// Fetch active bookings with customer names and package details
$activeBookings = getActiveBookingsWithDetails(); // Define this function to fetch active bookings with customer names and package details
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Extend Booking</title>
<!-- Include your CSS stylesheets here -->
</head>
<body>
<section>
<div class="column">
<div class="extend-form">
<h2>Select Extension Duration:</h2>
<form id="extensionForm">
<input type="hidden" name="bookingId" value="<?php echo $_GET['bookingId']; ?>">
<button type="button" class="extend-option-button" data-duration="1" style="background-color: #28a745; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; transition: background-color 0.2s;">1 Hour Extension</button>
<button type="button" class="extend-option-button" data-duration="3" style="background-color: #28a745; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; transition: background-color 0.2s;">3 Hours Extension</button>
</form>
</div>
</div>
</section>
<script>
document.addEventListener("DOMContentLoaded", function() {
const extensionForm = document.getElementById("extensionForm");
extensionForm.addEventListener("click", function(event) {
const extendOptionButton = event.target.closest(".extend-option-button");
if (extendOptionButton) {
const bookingId = extensionForm.querySelector("input[name='bookingId']").value;
const extensionDuration = extendOptionButton.getAttribute("data-duration");
// Make an AJAX request to update the booking with the selected extension
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
alert(`Booking extended by ${extensionDuration} hours.`);
window.location.href = "bookings.php"; // Redirect back to the main page
}
};
xhr.open("POST", "extend_booking.php", true); // Define this endpoint to handle booking extension
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(`bookingId=${bookingId}&extensionDuration=${extensionDuration}`);
}
});
});
</script>
</body>
</html>