-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfirm_booing.php
More file actions
314 lines (279 loc) · 14.1 KB
/
confirm_booing.php
File metadata and controls
314 lines (279 loc) · 14.1 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>GrandStay - CONFIRM BOOKING</title>
<link rel="icon" href="images/logo/hotel-logo.avif">
<?php require('inc/links.php'); ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
</head>
<body class="bg-light">
<?php require('inc/header.php'); ?>
<?php
if(!isset($_GET['id'])){
redirect('rooms.php');
}
else if(!(isset($_SESSION['login']) && $_SESSION['login'] === true)){
redirect('rooms.php');
}
$data = filteration($_GET);
$room_res = select("SELECT * FROM `rooms` WHERE `id`=? AND `status`=? AND `remove`=?",[$data['id'],1,0],'iii');
if(mysqli_num_rows($room_res)==0){
redirect('rooms.php');
}
$room_data = mysqli_fetch_assoc($room_res);
$_SESSION['room'] = [
"id"=> $room_data['id'],
"name"=> $room_data['name'],
"price"=> $room_data['price'],
"payment"=> null,
"available"=> null,
];
?>
<div class="container">
<div class="row">
<div class="col-12 my-5 mb-4 px-4">
<h2 class="fw-bold">CONFIRM BOOKING</h2>
<div style="font-size: 14px;">
<a href="index.php" class="text-secondary text-decoration-none">HOME</a>
<span class="text-dark"> > </span>
<a href="rooms.php" class="text-secondary text-decoration-none">ROOMS</a>
<span class="text-dark"> > </span>
<a href="#" class="text-secondary text-decoration-none">CONFIRM</a>
</div>
</div>
<div class="col-lg-7 col-md-12 px-4 card p-3 shadow-sm rounded">
<div id="roomCarousel" class="carousel slide mb-3" data-bs-ride="carousel">
<div class="carousel-inner rounded">
<?php
// Get thumbnail of the image
$room_img = ROOMS_IMG_PATH . "thumbnail.jpg"; // Default thumbnail
$thumb_q = mysqli_query($con, "SELECT `image` FROM `room_image`
WHERE `room_id` = '$room_data[id]' AND `thumb` = '1'");
if ($thumb_q && mysqli_num_rows($thumb_q) > 0) {
$thumb_res = mysqli_fetch_assoc($thumb_q);
if (!empty($thumb_res['image'])) {
$room_thumb = ROOMS_IMG_PATH . $thumb_res['image']; // Update with the actual thumbnail
}
}
?>
<!-- Use the fetched thumbnail image or the default one -->
<div class="carousel-item active">
<img src="<?php echo isset($room_thumb) ? $room_thumb : 'images/rooms/6.jpg'; ?>" class="d-block w-100" >
</div>
<div class="carousel-item">
<img src="images/rooms/1.jpg" class="d-block w-100" >
</div>
<div class="carousel-item">
<img src="images/rooms/2.jpg" class="d-block w-100">
</div>
<div class="carousel-item">
<img src="images/rooms/3.jpg" class="d-block w-100" >
</div>
<div class="carousel-item">
<img src="images/rooms/4.jpg" class="d-block w-100" >
</div>
<div class="carousel-item">
<img src="images/rooms/5.jpg" class="d-block w-100" >
</div>
<div class="carousel-item">
<img src="images/rooms/7.jpg" class="d-block w-100" >
</div>
<div class="carousel-item">
<img src="images/rooms/8.jpg" class="d-block w-100" >
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#roomCarousel" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#roomCarousel" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<?php
echo<<<data
<h5>$room_data[name]</h5>
<h6>₹$room_data[price]/- per night</h6>
data;
?>
</div>
<div class="col-lg-5 col-mb-12 px-4">
<div class="card mb-4 border-0 shadow-sm rounded-3">
<div class="card-body">
<form action="confirmbooking.php" method="POST" id="booking_form">
<h6 class="mb-3">BOOKING DETAILS</h6>
<div class="row">
<div class="col-md-12 mb-3">
<label class="form-label">Name</label>
<input type="text" name="billing_name" id="billing_name" class="form-control shadow-none" placeholder="Enter name" autofocus="" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Email</label>
<input type="email" name="billing_email" id="billing_email" class="form-control shadow-none" placeholder="Enter Email" required autofocus="">
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Phone Number</label>
<input type="number" name="billing_mobile" id="billing_mobile" class="form-control shadow-none" placeholder="Enter Phone No." required autofocus="" oninput="if(this.value.length > 10) this.value = this.value.slice(0, 10);">
</div>
<br>
<div class="col-md-6 mb-3">
<label class="form-label">Check-In</label>
<input type="Date" onchange="check_availability()" name="checkin" class="form-control shadow-none" required>
</div>
<div class="col-md-6 mb-4">
<label class="form-label">Check-Out</label>
<input type="Date" onchange="check_availability()" name="checkout" class="form-control shadow-none" required>
</div>
<div class="col-12">
<div class="spinner-border text-info mb-3 d-none" id="info_loader" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<h6 class="mb-3 text-danger" id="pay_info">Provide Check-In and Check-Out date!</h6>
<div class="col-md-6 mb-3">
<label class="form-label">Total Amount</label>
<input type="text" class="form-control shadow-none" name="payAmount" id="payAmount" placeholder="Total Amount" required autofocus="" readonly>
</div>
<button id="PayNow" name="pay_now" type="submit" class="btn w-100 text-white custom-bg shadow-sm mb-1" disabled >Pay Now</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require('inc/footer.php');?>
<script>
// Reference to form and elements
let booking_form = document.getElementById('booking_form');
let info_loader = document.getElementById('info_loader');
let pay_info = document.getElementById('pay_info');
let pay_now_button = booking_form.querySelector('button[name="pay_now"]');
let room_price_per_night = <?php echo $room_data['price']; ?>; // Room price fetched from the database
function check_availability() {
// Get values from check-in and check-out fields
let checkin_val = booking_form.elements['checkin'].value;
let checkout_val = booking_form.elements['checkout'].value;
if (checkin_val && checkout_val) {
// Show loader and reset messages
info_loader.classList.remove('d-none'); // Show loader
pay_info.textContent = ''; // Clear message
pay_info.style.color = ''; // Reset text color
pay_now_button.disabled = true; // Disable Pay Now button
setTimeout(() => {
// Hide loader after 2 seconds
info_loader.classList.add('d-none');
// Parse dates and calculate the difference in days
let checkin_date = new Date(checkin_val);
let checkout_date = new Date(checkout_val);
let time_difference = checkout_date - checkin_date;
let days = time_difference / (1000 * 3600 * 24); // Convert milliseconds to days
if (days > 0) {
// Calculate total price for the stay
let total_price = room_price_per_night * days;
// Update the value of the Total Amount input field
let payAmountInput = document.getElementById('payAmount');
payAmountInput.value = total_price; // Set calculated amount
// Display the total price in the availability message
pay_info.textContent = `Room is available! Total price for ${days} night(s): ₹${total_price}`;
pay_info.style.cssText = 'color: green !important;'; // Set text color to green
pay_now_button.disabled = false; // Enable Pay Now button
} else {
// If date range is invalid
pay_info.textContent = "Please select a valid date range.";
pay_info.style.color = 'red'; // Set text color to red
// Clear the Total Amount input field
let payAmountInput = document.getElementById('payAmount');
payAmountInput.value = ''; // Clear value
}
}, 2000); // Loader delay (2 seconds)
} else {
// If dates are missing
pay_info.textContent = "Provide Check-In and Check-Out date!";
pay_info.style.color = 'red'; // Set text color to red
// Clear the Total Amount input field
let payAmountInput = document.getElementById('payAmount');
payAmountInput.value = ''; // Clear value
}
}
//Pay Amount
jQuery(document).ready(function ($) {
jQuery('#PayNow').click(function (e) {
e.preventDefault(); // Prevent form submission
console.log("Pay Now clicked"); // Debug log
var paymentOption = 'netbanking';
let billing_name = $('#billing_name').val();
let billing_mobile = $('#billing_mobile').val();
let billing_email = $('#billing_email').val();
var shipping_name = $('#billing_name').val();
var shipping_mobile = $('#billing_mobile').val();
var shipping_email = $('#billing_email').val();
var payAmount = $('#payAmount').val();
var request_url = "submitpayment.php";
var formData = {
billing_name: billing_name,
billing_mobile: billing_mobile,
billing_email: billing_email,
shipping_name: shipping_name,
shipping_mobile: shipping_mobile,
shipping_email: shipping_email,
paymentOption: paymentOption,
payAmount: payAmount,
action: 'payOrder'
};
$.ajax({
type: 'POST',
url: request_url,
data: formData,
dataType: 'json',
encode: true,
}).done(function (data) {
if (data.res == 'success') {
var orderID = data.order_number;
var orderNumber = data.order_number;
var options = {
"key": data.razorpay_key,
"amount": data.userData.amount,
"currency": "INR",
"name": "GrandStay Hotel Bookings",
"description": data.userData.description,
"image": "https://img.freepik.com/premium-vector/hotel-logo-design_423075-16.jpg?w=740",
"order_id": data.userData.rpay_order_id,
"handler": function (response) {
window.location.replace("payment-success.php?oid=" + orderID + "&rp_payment_id=" + response.razorpay_payment_id + "&rp_signature=" + response.razorpay_signature);
},
"modal": {
"ondismiss": function () {
window.location.replace("payment-success.php?oid=" + orderID);
}
},
"prefill": {
"name": data.userData.name,
"email": data.userData.email,
"contact": data.userData.mobile
},
"notes": {
"address": "GrandStayHotelBookingWebsite"
},
"theme": {
"color": "#33cc54"
}
};
var rzp1 = new Razorpay(options);
rzp1.on('payment.failed', function (response) {
window.location.replace("payment-failed.php?oid=" + orderID + "&reason=" + response.error.description + "&paymentid=" + response.error.metadata.payment_id);
});
rzp1.open();
}
});
});
});
</script>
</body>
</html>