-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirm_booking.php
203 lines (159 loc) · 7.92 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
<!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('include/links.php') ?>
<title><?php echo $settings_r['site_title'] ?> - CONFIRM BOOKING</title>
</head>
<body class="bg-light">
<?php require('include/header.php'); ?>
<?php
/*
Check room 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('rooms.php');
}
else if(!(isset($_SESSION['login']) && $_SESSION['login']==true)){
redirect('rooms.php');
}
// filter and get room and user data
$data = filtration($_GET);
$room_res = select("SELECT * FROM `rooms` WHERE `id`=? AND `status`=? AND `removed`=?",[$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" => 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="rooms.php" class="text-secondary text-decoration-none">ROOMS</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
$room_thumb = ROOMS_IMG_PATH."default_thumbnail.jpg";
$thumb_q = mysqli_query($con, "SELECT * FROM `room_images` WHERE `room_id`='$room_data[id]' AND `thumb`='1'");
if(mysqli_num_rows($thumb_q)>0){
$thumb_res = mysqli_fetch_assoc($thumb_q);
$room_thumb = ROOMS_IMG_PATH.$thumb_res['image'];
}
echo <<<data
<div class="card p-3 shadow-sm rounded">
<img src="$room_thumb" class="img-fluid rounded mb-3">
<h5>$room_data[name]</h5>
<h6>₹$room_data[price] per night</h6>
</div>
data;
?>
</div>
<div class="col-lg-5 col-md-12 px-4">
<div class="card mb-4 border-0 shadow-sm rounded-3">
<div class="card-body">
<form action="pay_now.php" method="POST" id="booking_form">
<h6 class="mb-3">BOOKING DETAILS</h6>
<div class="row">
<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>
<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>
<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>
<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>
<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>
<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>
<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>
</div>
<?php require("include/footer.php"); ?>
<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;
booking_form.elements['pay_now'].setAttribute('disabled',true);
if(checkin_val!='' && checkout_val!='')
{
pay_info.classList.add('d-none');
pay_info.classList.replace('text-dark','text-danger');
info_loader.classList.remove('d-none');
let data = new FormData();
data.append('check_availability','');
data.append('check_in',checkin_val);
data.append('check_out',checkout_val);
let xhr = new XMLHttpRequest();
xhr.open("POST","ajax/confirm_booking_crud.php",true);
xhr.onload = function()
{
let data = JSON.parse(this.responseText);
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 = "Room 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');
booking_form.elements['pay_now'].removeAttribute('disabled');
}
pay_info.classList.remove('d-none');
info_loader.classList.add('d-none');
}
xhr.send(data);
}
}
</script>
</body>
</html>