-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathonline_booking.php
419 lines (371 loc) · 19.7 KB
/
online_booking.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My hotel</title>
<!--bootstrap 5 css link-->
</head>
<body>
<!-- loading pages -->
<div class="box ">
<div class="spinner-grow spinner-grow-sm text-white me-4"></div>
<div class="spinner-grow spinner-grow-sm text-white me-4"></div>
<div class="spinner-grow spinner-grow-sm text-white me-4"></div>
</div>
<!--------------------------------- navbar ---------------------------------->
<?php include 'navbar.php' ?>
<br>
<br><br>
<?php
// Include database connection
include_once('admin/include/conn.php');
// Check if room_type_id is provided in the URL
if (isset($_REQUEST['id'])) {
// Get the room_type_id from the URL
$room_type_id = $_REQUEST['id'];
// SQL query to fetch room details based on the provided room_type_id
$query = "SELECT room_type.*, room.room_no
FROM room_type
JOIN room ON room_type.room_type_id = room.room_type_id
WHERE room_type.room_type_id = $room_type_id";
// Execute the query
$result = mysqli_query($conn, $query);
// Check if the query executed successfully
if ($result && mysqli_num_rows($result) > 0) {
// Fetch room details
$room = mysqli_fetch_assoc($result);
?>
<div class="container mt-5">
<div class="row">
<!-- Room details card -->
<div class="col-xxl-12 col-xl-12 col-sm-12 col-md-12">
<div class="card">
<img class="card-img-top" src="img/<?php echo $room['image']; ?>" alt="<?php echo $room['room_type']; ?>">
<div class="card-body">
<h5 class="card-title"><?php echo $room['room_type']; ?></h5>
<p class="card-text">Price: ₹<?php echo $room['price']; ?></p>
<p class="card-text">Off Today: <?php echo $room['offers']; ?></p>
</div>
</div>
</div>
<!-- /razorrr pay api -->
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<!-- Booking form -->
<div class="container-fluid p-3 my-container">
<form action="online_booking.php" method="post" enctype="multipart/form-data" id="booking">
<div class="row">
<div class="col-lg-6">
<div class="response"></div>
<div class="panel panel-default">
<div class="panel-heading">
<h1>Customer Details:</h1>
</div>
<div class="panel-body">
<div class="panel-body">
<div class="form-group">
<label for="firstName">First Name</label>
<input type="text" class="form-control" id="firstName" name="f_name" placeholder="Enter First Name" required>
<span id="name_err" class="text-danger"></span>
</div>
<br>
<div class="form-group">
<label for="lastName">Last Name</label>
<input type="text" class="form-control" id="lastName" name="l_name" placeholder="Enter Last Name" required>
</div>
<br>
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter Email Address" required>
</div>
<br>
<div class="form-group">
<label for="contactNumber">Contact Number</label>
<input type="tel" class="form-control" id="contactNumber" name="number" placeholder="Enter Contact Number" required>
</div>
<br>
<div class="form-group">
<label for="address">Residential Address</label>
<input type="text" class="form-control" id="address" name="add" placeholder="Enter Residential Address" required>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="panel panel-default">
<div class="panel-heading ">
<h1>Room Information:</h1>
</div>
<div class="panel-body">
<div class="form-group">
<label for="roomType">Room Type:</label>
<select class="form-select" name="roomType" id="roomType">
<option value="<?php echo $room['room_type_id']; ?>"><?php echo $room['room_type']; ?></option>
</select>
</div>
<br>
<!-- Room No dropdown -->
<!-- <div class="form-group">
<label for="roomNo">Room No</label>
<select class="form-select" id="roomNo" name="roomNo" required>
<option selected disabled>Select Room No</option>
<?php
$query = "SELECT * FROM room WHERE room_type_id = $room_type_id";
$result = mysqli_query($conn, $query);
if ($result && mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['room_no'] . "'>" . $row['room_no'] . "</option>";
}
} else {
echo "<option disabled>No rooms available for this room type</option>";
}
?>
</select>
</div>
<br> -->
<div class="form-group">
<label for="checkInDate">Check-In Date</label>
<input type="text" class="form-control" id="checkInDate" name="checkInDate" placeholder="Enter Check-In Date" required>
</div>
<br>
<div class="form-group">
<label for="checkOutDates">Check-Out Date</label>
<input type="text" class="form-control" id="checkOutDates" name="checkOutDates" placeholder="Enter Check-Out Date" required>
</div>
<br>
<div class="form-group">
<label for="roomNo">Room No</label>
<select class="form-select" id="roomNo" name="roomNo" required>
<option selected disabled>Select Room No</option>
</select>
</div>
<br>
<div class="form-group">
<label for="max_person">Max Persons</label>
<input type="number" class="form-control" id="max_person" name="max_person" placeholder="Enter the number of persons" required>
</div>
</div>
</div>
</div>
</div>
<div class="container btn-light text-dark py-5">
<div class="row">
<div class="col-lg-12">
<div class="col-lg-6">
<button id="payNowButton" class="btn btn-primary mt-3">Pay Now</button>
</div>
<div class="form-group col-6">
<label for="price">Price:</label>
<h1><span id="price" name="price">₹<?php echo $room['price']; ?></span></h1>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- razorpay model -->
<?php
} else {
echo "Room not found.";
}
} else {
// Handle case when room_type_id is not provided
echo "Room type ID not provided.";
}
?>
<!-- ----------------------------------------Footer--------------------------------------------->
<?php include 'footer.php'; ?>
<!-- End of .container -->
<script src="hotel.js"></script>
<script>
$(document).ready(function() {
// Define custom validation method for address
$.validator.addMethod("validAddress", function(value, element) {
var regex = /^[a-zA-Z0-9,\s-]+$/;
return regex.test(value);
}, "Please enter a valid address");
$.validator.addMethod("emailregex", function(value, element) {
var regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return regex.test(value);
}, "Please enter a valid email address");
$.validator.addMethod("noDigits", function(value, element) {
return this.optional(element) || !/\d/.test(value);
}, "Digits are not allowed.");
$(document).ready(function() {
// Define the form validation rules using jQuery Validate plugin
$("#booking").validate({
rules: {
f_name: {
required: true,
noDigits: true
},
l_name: {
required: true,
noDigits: true
},
email: {
required: true,
email: true,
emailregex: true
},
number: {
required: true,
digits: true
},
add: {
required: true,
validAddress: true
},
roomType: {
required: true
},
roomNo: {
required: true
},
checkInDate: {
required: true
},
checkOutDates: {
required: true
},
max_person: {
required: true,
digits: true
}
},
messages: {
// Define custom error messages for each rule
f_name: {
required: "Please enter your first name",
noDigits: "First name cannot contain digits"
},
l_name: {
required: "Please enter your last name",
noDigits: "Last name cannot contain digits"
},
email: {
required: "Please enter your email address",
email: "Please enter a valid email address"
},
number: {
required: "Please enter your contact number",
digits: "Please enter only digits"
},
add: {
required: "Please enter your residential address",
validAddress: "Please enter a valid address"
},
roomType: {
required: "Please select a room type"
},
roomNo: {
required: "Please select a room number"
},
checkInDate: {
required: "Please enter the check-in date"
},
checkOutDates: {
required: "Please enter the check-out date"
},
max_person: {
required: "Please enter the number of persons",
digits: "Please enter a valid number"
}
},
// Handler for form submission
submitHandler: function(form, event) {
event.preventDefault(); // Prevent default form submission
initiatePayment(); // Call initiatePayment function when form is valid
return false; // Prevent form submission until payment success
}
});
// Function to initiate Razorpay payment
function initiatePayment() {
var form = $('#booking');
var amount = <?php echo $room['price'] * 100; ?>; // Convert price to paise
var options = {
key: 'rzp_test_Zdl1fc8tBJdYLP', // Replace with your Razorpay key
amount: amount,
currency: 'INR',
name: 'Your Hotel Name',
description: 'Room Booking Payment',
image: 'https://buffer.com/library/content/images/size/w1200/2023/10/free-images.jpg', // URL of your logo
handler: function(response) {
// After successful payment, submit the form to process booking
$.ajax({
url: 'insert_data.php', // URL of the PHP script to handle insertion into second table
type: 'POST',
data: form.serialize(), // Serialize form data
success: function(data) {
console.log(data); // Log response from the server
form.unbind('submit').submit(); // Submit the form
},
error: function(xhr, status, error) {
console.error(xhr.responseText); // Log error message
}
});
},
prefill: {
name: $('#firstName').val() + ' ' + $('#lastName').val(),
email: $('#email').val(),
contact: $('#contactNumber').val()
}
};
var rzp = new Razorpay(options);
rzp.open(); // Open Razorpay checkout modal
}
});
});
</script>
<script>
$(document).ready(function() {
// Initialize Datepicker for check-in date
$("#checkInDate").datepicker({
dateFormat: 'yy-mm-dd',
minDate: 0,
onSelect: function(selectedDate) {
$("#checkOutDates").datepicker("option", "minDate", selectedDate);
fetchAvailableRooms();
}
});
// Initialize Datepicker for check-out date
$("#checkOutDates").datepicker({
dateFormat: 'yy-mm-dd',
minDate: 0,
onSelect: function(selectedDate) {
$("#checkInDate").datepicker("option", "maxDate", selectedDate);
fetchAvailableRooms();
}
});
// Function to fetch available rooms based on selected dates and room type
function fetchAvailableRooms() {
var checkInDate = $("#checkInDate").val();
var checkOutDates = $("#checkOutDates").val();
var roomTypeId = $("#roomType").val(); // Get selected room type ID
$.ajax({
url: "fetch_available_rooms.php", // Provide the URL to fetch available rooms
type: "POST",
data: {
checkInDate: checkInDate,
checkOutDates: checkOutDates,
roomTypeId: roomTypeId // Include room type ID in the data
},
success: function(response) {
$("#roomNo").html(response); // Update room number select options
}
});
}
});
</script>
</body>
</html>
<?php
include('online_booking_insert_data.php');
include('drop.php');
include('drop1.php');
include('drop2.php');
?>