-
Notifications
You must be signed in to change notification settings - Fork 9
/
rooms.php
312 lines (292 loc) · 17.3 KB
/
rooms.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?php
require_once('config/config.php');
require_once('config/codeGen.php');
if (isset($_POST['Add_Reservation'])) {
/* Error Handling And Add Room */
$error = 0;
if (isset($_POST['id']) && !empty($_POST['id'])) {
$id = mysqli_real_escape_string($mysqli, trim($_POST['id']));
} else {
$error = 1;
$err = "Reservation ID Cannot Be Empty";
}
if (isset($_POST['room_id']) && !empty($_POST['room_id'])) {
$room_id = mysqli_real_escape_string($mysqli, trim($_POST['room_id']));
} else {
$error = 1;
$err = "Room ID Cannot Be Empty";
}
if (isset($_POST['room_number']) && !empty($_POST['room_number'])) {
$room_number = mysqli_real_escape_string($mysqli, trim($_POST['room_number']));
} else {
$error = 1;
$err = "Room Number Cannot Be Empty";
}
if (isset($_POST['room_cost']) && !empty($_POST['room_cost'])) {
$room_cost = mysqli_real_escape_string($mysqli, trim($_POST['room_cost']));
} else {
$error = 1;
$err = "Room Price Cannot Be Empty";
}
if (isset($_POST['room_type']) && !empty($_POST['room_type'])) {
$room_type = mysqli_real_escape_string($mysqli, trim($_POST['room_type']));
} else {
$error = 1;
$err = "Room Type Cannot Be Empty";
}
if (isset($_POST['check_in']) && !empty($_POST['check_in'])) {
$check_in = mysqli_real_escape_string($mysqli, trim($_POST['check_in']));
} else {
$error = 1;
$err = "Check In Cannot Be Empty";
}
if (isset($_POST['check_out']) && !empty($_POST['check_out'])) {
$check_out = mysqli_real_escape_string($mysqli, trim($_POST['check_out']));
} else {
$error = 1;
$err = "Check Out Cannot Be Empty";
}
if (isset($_POST['cust_name']) && !empty($_POST['cust_name'])) {
$cust_name = mysqli_real_escape_string($mysqli, trim($_POST['cust_name']));
} else {
$error = 1;
$err = "Customer Name Cannot Be Empty";
}
if (isset($_POST['cust_id']) && !empty($_POST['cust_id'])) {
$cust_id = mysqli_real_escape_string($mysqli, trim($_POST['cust_id']));
} else {
$error = 1;
$err = "Customer National ID Cannot Be Empty";
}
if (isset($_POST['cust_phone']) && !empty($_POST['cust_phone'])) {
$cust_phone = mysqli_real_escape_string($mysqli, trim($_POST['cust_phone']));
} else {
$error = 1;
$err = "Customer Phone Number Cannot Be Empty";
}
if (isset($_POST['cust_email']) && !empty($_POST['cust_email'])) {
$cust_email = mysqli_real_escape_string($mysqli, trim($_POST['cust_email']));
} else {
$error = 1;
$err = "Customer Email Number Cannot Be Empty";
}
if (isset($_POST['cust_adr']) && !empty($_POST['cust_adr'])) {
$cust_adr = mysqli_real_escape_string($mysqli, trim($_POST['cust_adr']));
} else {
$error = 1;
$err = "Customer Address Cannot Be Empty";
}
if (isset($_POST['status']) && !empty($_POST['status'])) {
$status = mysqli_real_escape_string($mysqli, trim($_POST['status']));
} else {
$error = 1;
$err = "Status Cannot Be Empty";
}
if (!$error) {
//Update Room That It Has Been Occupied
$room_status = $_POST['room_status'];
$query = "INSERT INTO reservations (id, room_id, room_number, room_cost, room_type, check_in, check_out, cust_name, cust_id, cust_phone, cust_email, cust_adr, status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
$room_querry = "UPDATE rooms SET status =? WHERE id =?";
$stmt = $mysqli->prepare($query);
$roomstmt = $mysqli->prepare($room_querry);
$rc = $stmt->bind_param('sssssssssssss', $id, $room_id, $room_number, $room_cost, $room_type, $check_in, $check_out, $cust_name, $cust_id, $cust_phone, $cust_email, $cust_adr, $status);
$rc = $roomstmt->bind_param('ss', $room_status, $room_id);
$stmt->execute();
$roomstmt->execute();
if ($stmt && $roomstmt) {
$success = "Added" && header("refresh:1; url=rooms.php");
} else {
//inject alert that task failed
$info = "Please Try Again Or Try Later";
}
}
}
/* Persist System Settigs On Landing Pages */
$ret = "SELECT * FROM `system_settings` ";
$stmt = $mysqli->prepare($ret);
$stmt->execute(); //ok
$res = $stmt->get_result();
while ($sys = $res->fetch_object()) {
if ($sys_logo = '') {
$logo_dir = 'public/uploads/sys_logo/logo.png';
} else {
$logo_dir = "public/uploads/sys_logo/$sys->sys_logo";
}
require_once('partials/cms_head.php');
?>
<body>
<div class="super_container">
<?php require_once("partials/cms_nav.php"); ?>
<div class="home">
<div class="parallax_background parallax-window" data-parallax="scroll" data-image-src="public/cms_assets/images/home.jpg" data-speed="0.8"></div>
<div class="home_container d-flex flex-column align-items-center justify-content-center">
<div class="home_title">
<h1><?php echo $sys->sys_name; ?> Rooms</h1>
</div>
</div>
</div>
<br>
<div class="rooms">
<div class="container">
<div class="row">
<div class="col">
<div class="card-columns">
<?php
$ret = "SELECT * FROM `rooms` WHERE status = 'Vacant' ORDER BY RAND() ";
$stmt = $mysqli->prepare($ret);
$stmt->execute(); //ok
$res = $stmt->get_result();
while ($rooms = $res->fetch_object()) {
if ($rooms->image == '') {
//Load Default Image
$img_dir = "public/uploads/sys_logo/logo.png";
} else {
$img_dir = "public/uploads/rooms/$rooms->image";
}
?>
<div class="card">
<img class="card-img-top" src="<?php echo $img_dir; ?>" alt="Room image description">
<div class="card-body">
<div class="rooms_title">
<h2><?php echo $rooms->type; ?></h2>
</div>
<div class="rooms_price">Ksh <?php echo $rooms->price; ?> /<span>Night</span></div>
<div class="button rooms_button"><a data-toggle="modal" href="#book-<?php echo $rooms->id; ?>">Book Now</a></div>
</div>
</div>
<!-- Book Room Modal -->
<div class="modal fade" id="book-<?php echo $rooms->id; ?>">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Fill All Values </h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" enctype="multipart/form-data">
<div class="form-row mb-4">
<div style="display:none" class="form-group col-md-6">
<label for="inputEmail4">Id</label>
<input type="text" name="id" value="<?php echo $ID; ?>" class="form-control">
<input type="text" name="room_id" value="<?php echo $rooms->id; ?>" class="form-control">
<input type="text" name="status" value="Pending" class="form-control">
<input type="text" name="room_status" value="Occupied" class="form-control">
</div>
</div>
<div class="form-row mb-4" style="display: none;">
<div class="form-group col-md-4">
<label for="inputEmail4">Room Number</label>
<input type="text" readonly value="<?php echo $rooms->number; ?>" name="room_number" class="form-control">
</div>
<div class="form-group col-md-4">
<label for="inputEmail4">Room Cost</label>
<input type="text" readonly value="<?php echo $rooms->price; ?>" name="room_cost" class="form-control">
</div>
<div class="form-group col-md-4">
<label for="inputEmail4">Room Type</label>
<input type="text" readonly value="<?php echo $rooms->type; ?>" name="room_type" class="form-control">
</div>
</div>
<div class="form-row mb-4">
<div class="form-group col-md-6">
<label for="inputEmail4">Check In</label>
<input type="date" name="check_in" class="form-control">
</div>
<div class="form-group col-md-6">
<label for="inputEmail4">Check Out</label>
<input type="date" name="check_out" class="form-control">
</div>
</div>
<hr>
<div class="form-row mb-4">
<div class="form-group col-md-12">
<label for="inputEmail4">Full Name</label>
<input type="text" name="cust_name" class="form-control">
</div>
<div class="form-group col-md-6">
<label for="inputEmail4">National ID Number</label>
<input type="text" name="cust_id" class="form-control">
</div>
<div class="form-group col-md-6">
<label for="inputEmail4">Phone No</label>
<input type="text" name="cust_phone" class="form-control">
</div>
</div>
<div class="form-row mb-4">
<div class="form-group col-md-12">
<label for="inputEmail4">Email</label>
<input type="email" name="cust_email" class="form-control">
</div>
<div class="form-group col-md-12">
<label for="inputEmail4">Address</label>
<input type="text" name="cust_adr" class="form-control">
</div>
</div>
<div class="text-right">
<button type="submit" name="Add_Reservation" class="btn btn-warning mt-3">Submit</button>
</div>
</form>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- End Room Modal -->
<?php
} ?>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="parallax_background parallax-window" data-parallax="scroll" data-image-src="public/cms_assets/images/footer.jpg" data-speed="0.8"></div>
<div class="container">
<div class="row">
<div class="col">
<div class="footer_logo text-center">
<a href="#"><img src="images/logo.png" alt=""></a>
</div>
<div class="footer_content">
<div class="row">
<div class="col-lg-4 footer_col">
<div class="footer_info d-flex flex-column align-items-lg-end align-items-center justify-content-start">
<div class="text-center">
<div>Phone:</div>
<div><?php echo $sys->contacts_phone; ?></div>
</div>
</div>
</div>
<div class="col-lg-4 footer_col">
<div class="footer_info d-flex flex-column align-items-center justify-content-start">
<div class="text-center">
<div>Address:</div>
<div><?php echo $sys->contacts_addres; ?></div>
</div>
</div>
</div>
<div class="col-lg-4 footer_col">
<div class="footer_info d-flex flex-column align-items-lg-start align-items-center justify-content-start">
<div class="text-center">
<div>Mail:</div>
<div><?php echo $sys->contacts_email; ?></div>
</div>
</div>
</div>
</div>
</div>
<?php require_once("partials/cms_footer.php"); ?>
</div>
</div>
</div>
</footer>
</div>
<?php require_once("partials/cms_scripts.php"); ?>
</body>
</html>
<?php
} ?>