-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
427 lines (353 loc) · 15.6 KB
/
test.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
420
421
422
423
424
425
426
427
<?php
session_start();
if (!isset($_SESSION['id']) || !isset($_SESSION['role'])) {
header('Location: login.php');
exit;
}
include_once('includes/header.php');
?>
<style>
#time-intervals {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
</style>
<div id="page-wrapper">
<style>
.myElement{margin-top: -80px; }
@media (max-width: 767px) {
.myElement {margin-top: 80px; }
}
/* Media query for large screens (lg) */
@media (min-width: 1200px) {
.myElement {margin-top: -120px; }
}
</style>
<!-- /.row -->
<div class="row">
<div class="calendar-body py-5">
<div class="calendar">
<div class="header">
<button id="prevBtn"><</button>
<h2 id="monthYear"></h2>
<button id="nextBtn">></button>
</div>
<div class="days"></div>
</div>
</div>
<div class="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header text-center">Select your time slot</h1>
</div>
</div>
<div class="row">
<div class="col-lg-12 text-center">
<div id="time-intervals" class="d-flex justify-content-center align-items-center mx-auto">
<!-- here is the buttons -->
</div>
</div>
</div>
</div>
<!-- Modal for the booking form -->
<div class="modal fade" role="dialog" id="bookingModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Booking Form</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="selectedDate">Selected Date:</label>
<input type="text" class="form-control" id="selectedDate" readonly>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="selectedDate">Enter Name:</label>
<input type="text" class="form-control" id="name" placeholder="Enter name" name="name" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="selectedDate">Enter Contact:</label>
<input type="text" class="form-control" id="contact" placeholder="Enter contact" name="contact" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="startTime">Start Time:</label>
<input type="text" class="form-control" id="startTime" readonly>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="endTime">End Time:</label>
<select class="form-control" id="endTime" required>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="advance">Enter Advance:</label>
<input type="text" class="form-control" id="advance" placeholder="Enter advance" name="advance" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="total">Enter Total:</label>
<input type="text" class="form-control" id="total" placeholder="Enter total" name="total" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="total">Payment Method:</label>
<select class="form-control" id="method" required>
<option value="bkash"> BKash </option>
<option value="nagad"> Nagad </option>
<option value="cash"> Cash </option>
</select>
</div>
</div>
</div>
<button type="button" class="btn btn-success" onclick="submitBookingForm()">Book</button>
</form>
</div>
</div>
</div>
</div>
<?php
include 'connection.php';
$sql = "SELECT * FROM slot_management WHERE status=1";
$result = mysqli_query($conn, $sql);
echo "<script> var periods = [];";
$row = mysqli_fetch_array($result);
echo "var admin = '".$_SESSION['id']."';";
echo "periods.push('".$row['start_time']."');"."periods.push('".$row['end_time']."');";
while($r = mysqli_fetch_array($result)){
echo "periods.push('".$r['end_time']."');";
}
echo "console.log(periods);</script>";
?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const daysContainer = document.querySelector('.days');
const monthYearElement = document.getElementById('monthYear');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
let flag = true;
let currentDate = new Date();
let currentMonth = currentDate.getMonth();
let currentYear = currentDate.getFullYear();
if (flag) {
renderCalendar(currentMonth, currentYear);
flag = false;
}
function renderCalendar(month, year) {
daysContainer.innerHTML = '';
const firstDay = new Date(year, month, 1);
const lastDay = new Date(year, month + 1, 0);
const totalDays = lastDay.getDate();
monthYearElement.textContent = `${getMonthName(month)} ${year}`;
for (let i = 1; i <= totalDays; i++) {
const day = document.createElement('div');
day.classList.add('day');
day.textContent = i;
day.addEventListener('click', () => selectDate(i));
daysContainer.appendChild(day);
day.classList.remove('today');
const currentDate = new Date();
if (i == currentDate.getDate() && month == currentDate.getMonth() && year == currentDate.getFullYear()) {
selectDate(i);
day.classList.add('today');
var temp = document.getElementById('selectedDate');
temp.value = currentDate.toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
}
}
const todayIndex = new Date().getDate() - 1;
}
function getMonthName(month) {
const months = [
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'
];
return months[month];
}
function selectDate(day) {
const selectedDay = new Date(currentYear, currentMonth, day);
var inputDate = new Date(selectedDay);
var month = String(inputDate.getMonth() + 1).padStart(2, '0');
var mysqlDate = inputDate.getFullYear() + '-' + month + '-' + inputDate.getDate();
var live_slots = [];
var slotsArray = [];
$.ajax({
url: 'api/get_slot_status.php',
type: 'POST',
dataType: 'json',
data: {
date: mysqlDate,
},
success: function(response) {
slotsArray = response;
const today = new Date();
var dateWithoutTime = new Date(today.getFullYear(), today.getMonth(), today.getDate());
var fg = true;
if (selectedDay < dateWithoutTime) {
fg = false;
}
const selectedElement = document.querySelector('.selected');
if (selectedElement) {
selectedElement.classList.remove('selected');
}
const clickedDayElement = daysContainer.children[day - 1];
clickedDayElement.classList.add('selected');
const selectedDateStr = selectedDay.toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
var temp = document.getElementById('selectedDate');
temp.value = selectedDateStr;
var time_interval = document.getElementById('time-intervals');
time_interval.innerHTML = "";
for (let i=0; i<periods.length-1; i++){
var startTime = periods[i];
var endTime = periods[i+1];
if (fg) {
var isBooked = false;
for (let j=0; j<slotsArray.length; j++){
if(periods[i]==slotsArray[j].start){
isBooked = true;
while(slotsArray[j].end!=periods[i]){
i++;
}
var span = `<span class="btn btn-danger m-2 col-lg-3 col-md-4 col-sm-6 col-xs-6 text-center" style= "padding: 10px; margin: 5px; " >${slotsArray[j].start} - ${periods[i]} booked by <br> ${slotsArray[j].name}</span>`;
i--;
break;
}
}
if(isBooked === false){
var span = `<span class="btn btn-primary m-2 col-lg-3 col-md-4 col-sm-6 col-xs-6 text-center" style= "padding: 10px; margin: 5px; " onclick="openBookingForm('${periods[i]}', '${periods[i+1]}')">${periods[i]} - ${periods[i+1]} <br> --- </span>`;
}
} else {
var span = `<span class="btn btn-primary m-2 col-lg-3 col-xs-6 col-md-3 text-center" style= "padding: 10px; margin: 5px; " >${startTime}-${endTime}</span>`;
}
time_interval.innerHTML += span;
}
},
});
}
prevBtn.addEventListener('click', () => {
currentMonth--;
if (currentMonth < 0) {
currentMonth = 11;
currentYear--;
}
renderCalendar(currentMonth, currentYear);
});
nextBtn.addEventListener('click', () => {
currentMonth++;
if (currentMonth > 11) {
currentMonth = 0;
currentYear++;
}
renderCalendar(currentMonth, currentYear);
});
});
function openBookingForm(startTime, endTime) {
document.getElementById('startTime').value = startTime;
populateEndTimeDropdown(startTime);
$('#bookingModal').modal('show');
}
function populateEndTimeDropdown(startTime) {
var endTimeDropdown = document.getElementById('endTime');
endTimeDropdown.innerHTML = '';
var x=periods.length+1;
for (let i=0; i<periods.length; i++){
if(x<i){
var option = document.createElement('option');
option.value = periods[i];
option.text = periods[i];
endTimeDropdown.add(option);
}
if(periods[i]==startTime){
x=i;
}
}
}
function submitBookingForm() {
let date = document.getElementById('selectedDate').value;
let startTime = document.getElementById('startTime').value;
let endTime = document.getElementById('endTime').value;
let name = document.getElementById('name').value;
let contact = document.getElementById('contact').value;
let advance = document.getElementById('advance').value;
let total = document.getElementById('total').value;
let method = document.getElementById('method').value;
var inputDate = new Date(date);
var month = String(inputDate.getMonth() + 1).padStart(2, '0');
var mysqlDate = inputDate.getFullYear() + '-' + month + '-' + inputDate.getDate();
if (name === "") {
alert("Please enter a valid Name");
} else if (contact === "") {
alert("Please provide a Contact Number");
} else if(advance===""){
alert("Please provide a advance");
}else if(total===""){
alert("Please provide a Total");
}else {
$.ajax({
url: 'api/submit_booking.php',
type: 'POST',
data: {
date: mysqlDate,
startTime: startTime,
endTime: endTime,
name: name,
contact: contact,
ref_id: admin,
advance: advance,
total: total,
method: method
},
success: function(response) {
if (response==='1'){
alert("Booked successfully");
$('#bookingModal').modal('hide');
window.location.replace('bookingManagement.php');
}
else {
alert('An error occurred. Please try again later.');
}
},
});
}
}
</script>
</section>
</div>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /#page-wrapper -->
<?php include_once('includes/footer.php'); ?>