-
Notifications
You must be signed in to change notification settings - Fork 0
/
Accomodation.php
139 lines (124 loc) · 4.01 KB
/
Accomodation.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
<?php
session_start();
if (!isset($_SESSION['username'])) {
header("Location: hks.php");
exit();
}
$username = $_SESSION['username'];
include 'db_connect.php';
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['room_id'])) {
$room_id = $_POST['room_id'];
$check_out = $_POST['check_out'];
$check_in = date('Y-m-d H:i:s');
$payment_number = uniqid();
$sql = "UPDATE rooms SET is_occupied = TRUE, username = ?, payment_status = 'pending', check_in = ?, check_out = ?, payment_number = ? WHERE id = ?";
$stmt = $conn->prepare($sql);
if ($stmt) {
$stmt->bind_param("ssssi", $_SESSION['username'], $check_in, $check_out, $payment_number, $room_id);
if ($stmt->execute()) {
$_SESSION['success_message'] = "Room booked successfully! Your payment number is: " . $payment_number;
} else {
echo "Error booking room: " . $stmt->error;
}
$stmt->close();
} else {
echo "Error preparing statement: " . $conn->error;
}
}
$sql = "SELECT * FROM rooms";
$result = $conn->query($sql);
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accommodation</title>
<link rel="stylesheet" href="Style.css">
<style>
table {
width: 50%;
border-collapse: collapse;
margin: 15px;
}
th, td {
padding: 10px;
border: 1px solid #dddddd;
text-align: center;
}
th {
background-color: #ffc107;
}
.book-button {
padding: 5px 10px;
background-color: #28a745;
color: #fff;
border: none;
cursor: pointer;
border-radius: 5px;
}
.book-button[disabled] {
background-color: #ffc107;
cursor: not-allowed;
}
.input-checkout {
width: 100%;
padding: 5px;
margin: 5px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="container">
<header>
<div class="status">
<h4><b>Accommodation Services</b></h4>
</div>
</header>
<section class="quantify-section">
<h2>© Guest House Room Booking<br> After booking return to Dashboard to confirm your payment (€)</h2>
</section>
<table>
<tr>
<th>Room Number</th>
<th>Room Type</th>
<th>Status</th>
<th>Action</th>
</tr>
<?php if ($result->num_rows > 0): ?>
<?php while($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row["room_number"]; ?></td>
<td><?php echo $row["room_type"]; ?></td>
<td><?php echo $row["is_occupied"] ? "Occupied" : "Available"; ?></td>
<td>
<?php if (!$row["is_occupied"]): ?>
<form method="POST" action="">
<input type="hidden" name="room_id" value="<?php echo $row['id']; ?>">
<input type="datetime-local" name="check_out" class="input-checkout" required>
<button type="submit" class="book-button">Book Now</button>
</form>
<?php else: ?>
<button class="book-button" disabled>Occupied</button>
<?php endif; ?>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="4">No rooms available</td>
</tr>
<?php endif; ?>
</table>
<nav class="bottom-nav">
<a href="Dashboard.php" class="nav-button">Dashboard</a>
<a href="FOOD.php" class="nav-button">Food</a>
<a href="Accommodation.php">Accommodation</a>
<a href="Me.php" class="nav-button">Me</a>
</nav>
</div>
</body>
</html>