-
Notifications
You must be signed in to change notification settings - Fork 0
/
Roomlistpage.php
238 lines (200 loc) · 7.43 KB
/
Roomlistpage.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
include 'db.php'; // Including the database connection file
function refreshPage() {
header("Refresh:1"); // This will refresh the page after 0 seconds
}
// Fetch rooms from the database
$query = "SELECT * FROM rooms";
$stmt = mysqli_prepare($conn, $query);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
// Check if rooms are fetched successfully
if ($result) {
$rooms = mysqli_fetch_all($result, MYSQLI_ASSOC);
} else {
$rooms = []; // Empty array if no rooms are fetched
}
$selectedRoom = isset($_POST['selectedRoom']) ? $_POST['selectedRoom'] : '';
$similarRooms = [];
if (isset($_POST['similar'])) {
$selectedRoomView = '';
foreach ($rooms as $room) {
if ($room['room_number'] == $selectedRoom) {
$selectedRoomView = $room['room_view'];
break;
}
}
if (!empty($selectedRoomView)) {
$query = "SELECT * FROM rooms WHERE room_view = '$selectedRoomView' AND room_number != '$selectedRoom'";
$result = mysqli_query($conn, $query);
if ($result && mysqli_num_rows($result) > 0) {
$similarRooms = mysqli_fetch_all($result, MYSQLI_ASSOC);
} else {
$noSimilarRooms = true; // Flag to indicate no similar rooms
}
}
}
if (isset($_POST['remove'])) {
$selectedRoomNumber = $_POST['selectedRoom'];
$deleteQuery = "DELETE FROM rooms WHERE room_number = '$selectedRoomNumber'";
//$stmt = mysqli_prepare($conn, $deleteQuery);
//mysqli_stmt_bind_param($stmt, 's', $selectedRoomNumber);
if ($conn->query($deleteQuery) === TRUE) {
echo "<p>Room removed successfully.</p>";
refreshPage();
} else {
echo "<p>Error canceling reservation: " . $conn->error . "</p>";
}
}
// Handle room unassignment
if (isset($_POST['unassign'])) {
$selectedRoomNumber = $_POST['selectedRoom'];
echo "$selectedRoomNumber";
$updateStatusQuery = "UPDATE rooms SET status = 'available' WHERE room_number ='$selectedRoomNumber'";
if ($conn->query($updateStatusQuery) === TRUE) {
echo "<p>Unassigned successfully.</p>";
refreshPage();
} else {
echo "<p>Error canceling reservation: " . $conn->error . "</p>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Select Room</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f4;
}
h1, h2 {
color: #333;
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
table, th, td {
border: 1px solid #ccc;
}
th, td {
padding: 8px 12px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
td input[type="radio"] {
margin-right: 5px;
}
button, input[type="submit"], input[type="button"] {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover, input[type="submit"]:hover, input[type="button"]:hover {
background-color: #0056b3;
}
p {
color: red;
}
/* Add more styles as needed */
</style>
</head>
<body>
<h1>Select Room</h1>
<button onclick="redirectToAdminPage()">Home</button>
<form action="" method="post">
<br><br>
<table border="1">
<tr>
<th>Select</th>
<th>Room Number</th>
<th>Type</th>
<th>Price</th>
<th>Size</th>
<th>Maximum Occupancy</th>
<th>Room View</th>
<th>Air Conditioning</th>
<th>Coffee Maker</th>
<th>Status</th>
</tr>
<?php foreach ($rooms as $room): ?>
<tr>
<td>
<input type="radio" name="selectedRoom" value="<?php echo $room['room_number']; ?>"
<?php echo ($selectedRoom == $room['room_number']) ? 'checked' : ''; ?>>
</td>
<td><?php echo $room['room_number']; ?></td>
<td><?php echo $room['type']; ?></td>
<td><?php echo $room['price']; ?></td>
<td><?php echo $room['size']; ?></td>
<td><?php echo $room['maximum_occupancy']; ?></td>
<td><?php echo $room['room_view']; ?></td>
<td><?php echo $room['air_conditioning']; ?></td>
<td><?php echo $room['coffee_maker']; ?></td>
<td><?php echo $room['status']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<!-- Buttons for actions -->
<input type="submit" name="remove" value="Remove Room" onclick="return confirm('Are you sure you want to remove this room?');">
<input type="submit" name="unassign" value="Unassign Room" onclick="return confirmUnassign();">
<input type="submit" name="similar" value="Show Similar Room">
<br><br>
<input type="button" name="assign" value="Room Form" onclick="redirectToRoomForm()">
<!-- Display Similar Rooms -->
<?php if (!empty($similarRooms)): ?>
<h2>Similar Rooms</h2>
<table border="1">
<tr>
<th>Room Number</th>
<th>Type</th>
<th>Price</th>
<th>Size</th>
<th>Maximum Occupancy</th>
<th>Room View</th>
<th>Air Conditioning</th>
<th>Coffee Maker</th>
<th>Status</th>
</tr>
<?php foreach ($similarRooms as $room): ?>
<tr>
<td><?php echo $room['room_number']; ?></td>
<td><?php echo $room['type']; ?></td>
<td><?php echo $room['price']; ?></td>
<td><?php echo $room['size']; ?></td>
<td><?php echo $room['maximum_occupancy']; ?></td>
<td><?php echo $room['room_view']; ?></td>
<td><?php echo $room['air_conditioning']; ?></td>
<td><?php echo $room['coffee_maker']; ?></td>
<td><?php echo $room['status']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php elseif (isset($noSimilarRooms)): ?>
<p>No similar rooms found for the selected room view.</p>
<?php endif; ?>
</form>
<!-- Include any other scripts or styles if necessary -->
<script>
function redirectToRoomForm() {
window.location.href = 'roomform.php';
}
function confirmUnassign() {
return confirm('Are you sure you want to unassign this room?');
}
function redirectToAdminPage() {
window.location.href = 'admin.php';
}
</script>
</body>
</html>