-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirm_booking.php
220 lines (177 loc) · 7.82 KB
/
confirm_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
<!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">
<?php require('inc/links.php'); ?>
<title><?php echo $settings_r['site_title'] ?> - CONFIRM BOOKING</title>
</head>
<body class="bg-light">
<?php require('inc/header.php'); ?>
<?php
/*
Check guesthouse id from url is present or not
Shutdown mode is active or not
User is logged in or not
*/
if (!isset($_GET['id']) || $settings_r['shutdown'] == true) {
redirect('guesthouses.php');
} else if (!(isset($_SESSION['login']) && $_SESSION['login'] == true)) {
redirect('guesthouses.php');
}
// filter and get guesthouse and user data
$data = filteration($_GET);
$guesthouse_res = select("SELECT * FROM guesthouses WHERE id=? AND status=? AND removed=?", [$data['id'], 1, 0], 'iii');
if (mysqli_num_rows($guesthouse_res) == 0) {
redirect('guesthouses.php');
}
$guesthouse_data = mysqli_fetch_assoc($guesthouse_res);
$_SESSION['guesthouse'] = [
"id" => $guesthouse_data['id'],
"name" => $guesthouse_data['name'],
"price" => $guesthouse_data['price'],
"payment" => null,
"available" => false,
];
$user_res = select("SELECT * FROM user_cred WHERE id=? LIMIT 1", [$_SESSION['uId']], "i");
$user_data = mysqli_fetch_assoc($user_res);
?>
<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-secondary"> > </span>
<a href="guesthouses.php" class="text-secondary text-decoration-none">GUESTHOUSESS</a>
<span class="text-secondary"> > </span>
<a href="#" class="text-secondary text-decoration-none">CONFIRM</a>
</div>
</div>
<div class="col-lg-7 col-md-12 px-4">
<?php
$guesthouse_thumb = GUESTHOUSES_IMG_PATH . "thumbnail.jpg";
$thumb_q = mysqli_query($con, "SELECT * FROM guesthouse_images
WHERE guesthouse_id='$guesthouse_data[id]'
AND thumb='1'");
if (mysqli_num_rows($thumb_q) > 0) {
$thumb_res = mysqli_fetch_assoc($thumb_q);
$guesthouse_thumb = GUESTHOUSES_IMG_PATH . $thumb_res['image'];
}
echo <<<data
<div class="card p-3 shadow-sm rounded">
<img src="$guesthouse_thumb" class="img-fluid rounded mb-3">
<h5>$guesthouse_data[name]</h5>
<h6>$$guesthouse_data[price] per night</h6>
</div>
data;
?>
</div>
<!-- Booking Details Section -->
<div class="col-lg-5 col-md-12 px-4">
<!-- Card for booking details -->
<div class="card mb-4 border-0 shadow-sm rounded-3">
<div class="card-body">
<!-- Form for booking -->
<form action="pay_now.php" method="POST" id="booking_form">
<h6 class="mb-3">BOOKING DETAILS</h6>
<div class="row">
<!-- Name input field -->
<div class="col-md-6 mb-3">
<label class="form-label">Name</label>
<input name="name" type="text" value="<?php echo $user_data['name'] ?>" class="form-control shadow-none" required>
</div>
<!-- Phone number input field -->
<div class="col-md-6 mb-3">
<label class="form-label">Phone Number</label>
<input name="phonenum" type="number" value="<?php echo $user_data['phonenum'] ?>" class="form-control shadow-none" required>
</div>
<!-- Address input field -->
<div class="col-md-12 mb-3">
<label class="form-label">Address</label>
<textarea name="address" class="form-control shadow-none" rows="1" required><?php echo $user_data['address'] ?></textarea>
</div>
<!-- Check-in date input field -->
<div class="col-md-6 mb-3">
<label class="form-label">Check-in</label>
<input name="checkin" onchange="check_availability()" type="date" class="form-control shadow-none" required>
</div>
<!-- Check-out date input field -->
<div class="col-md-6 mb-4">
<label class="form-label">Check-out</label>
<input name="checkout" onchange="check_availability()" type="date" class="form-control shadow-none" required>
</div>
<!-- Status and action buttons -->
<div class="col-12">
<!-- Loading spinner -->
<div class="spinner-border text-info mb-3 d-none" id="info_loader" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<!-- Message to user if availability isn't provided -->
<h6 class="mb-3 text-danger" id="pay_info">Provide check-in & check-out date !</h6>
<!-- Pay now button (initially disabled) -->
<button name="pay_now" class="btn w-100 text-white custom-bg shadow-none mb-1" disabled>Pay Now</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col-12 text-center mt-4">
<a href="rate_guesthouse.php?id=<?php echo $guesthouse_data['id']; ?>" class="btn text-white" style="background-color: #2ec1ac; border-color: #2ec1ac;">Rate Now!</a>
</div>
<!-- Footer inclusion -->
<?php require('inc/footer.php'); ?>
<!-- Script to handle availability check and update booking status -->
<script>
let booking_form = document.getElementById('booking_form');
let info_loader = document.getElementById('info_loader');
let pay_info = document.getElementById('pay_info');
function check_availability() {
let checkin_val = booking_form.elements['checkin'].value;
let checkout_val = booking_form.elements['checkout'].value;
// Disable pay now button while checking availability
booking_form.elements['pay_now'].setAttribute('disabled', true);
// Check if both check-in and check-out dates are selected
if (checkin_val != '' && checkout_val != '') {
// Hide payment information initially and show loader
pay_info.classList.add('d-none');
pay_info.classList.replace('text-dark', 'text-danger');
info_loader.classList.remove('d-none');
let data = new FormData();
// Append data to check availability
data.append('check_availability', '');
data.append('check_in', checkin_val);
data.append('check_out', checkout_val);
// Create a new AJAX request to confirm booking
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/confirm_booking.php", true);
xhr.onload = function() {
let data = JSON.parse(this.responseText);
// Check the availability response and update the UI accordingly
if (data.status == 'check_in_out_equal') {
pay_info.innerText = "You cannot check-out on the same day!";
} else if (data.status == 'check_out_earlier') {
pay_info.innerText = "Check-out date is earlier than check-in date!";
} else if (data.status == 'check_in_earlier') {
pay_info.innerText = "Check-in date is earlier than today's date!";
} else if (data.status == 'unavailable') {
pay_info.innerText = "GuestHouse not available for this check-in date!";
} else {
pay_info.innerHTML = "No. of Days: " + data.days + "<br>Total Amount to Pay: $" + data.payment;
pay_info.classList.replace('text-danger', 'text-dark');
// Enable the Pay Now button
booking_form.elements['pay_now'].removeAttribute('disabled');
}
// Display the final result and hide the loader
pay_info.classList.remove('d-none');
info_loader.classList.add('d-none');
}
// Send the request to the server
xhr.send(data);
}
}
</script>
</body>
</html>