forked from MarcusHNBRN/KOOPERATIV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
67 lines (51 loc) · 1.81 KB
/
index.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
<?php
declare(strict_types=1);
include 'db.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$available_room_types = getAvailableRoomTypes($pdo, $start_date, $end_date);
if (!empty($available_room_types)) {
header("Location: room_selection.php?start_date=$start_date&end_date=$end_date");
exit();
} else {
echo "<p>Sorry, the selected dates are not available. Please choose different dates or room types.</p>";
}
}
function getAvailableRoomTypes($pdo, $start_date, $end_date) {
$available_room_types = [];
foreach (['basic', 'standard', 'luxury'] as $room_type) {
$stmt = $pdo->prepare("SELECT COUNT(*) FROM bookings WHERE room_type = ? AND NOT ((end_date < ?) OR (start_date > ?))");
$stmt->execute([$room_type, $start_date, $end_date]);
$count = $stmt->fetchColumn();
$total_rooms = 1;
if ($count < $total_rooms) {
$available_room_types[] = $room_type;
}
}
return $available_room_types;
}
?>
<!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="style.css" />
</head>
<body>
<div class="logo-container">
<img class="logoimage" src="./images/frame.png"/>
<img class="bgimg" src="./images/hotel.png" />
</div>
<div class="booking">
<form action="index.php" method="post">
<label for="start_date">Arrival:</label>
<input type="date" id="start_date" name="start_date" required />
<label for="end_date">Depature:</label>
<input type="date" id="end_date" name="end_date" required />
<input type="submit" value="Next" />
</form>
</div>
</body>
</html>