-
Notifications
You must be signed in to change notification settings - Fork 0
/
slotManagement.php
177 lines (149 loc) · 8.3 KB
/
slotManagement.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
<?php
session_start();
if (!isset($_SESSION['name']) || !isset($_SESSION['role'])) {
header('Location: login.php');
exit;
}
include_once('includes/header.php');
?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Slot Management</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
<div class="card ml-2">
<div class="card-body">
<form action="slotManagement.php" method="POST">
<h5 class="card-title mb-0">Create Slots</h5>
<div class="form-group mt-3">
<label>
Start Time
<small class="text-muted">HH:MM</small></label>
<input type="time" class="form-control date-inputmask" name="stime" id="stime" placeholder="Enter Start Time" />
</div>
<div class="form-group mt-3">
<label>
Finish Time
<small class="text-muted">HH:MM</small></label>
<input type="time" class="form-control date-inputmask" name="ftime" id="ftime" placeholder="Enter Finish Time" />
</div>
<div class="form-group">
<label>Slot Interval
<small class="text-muted">Interval between slots in minutes</small></label>
<input type="number" class="form-control phone-inputmask" name="slotInterval" id="slotInterval" placeholder="Enter Time Interval" />
</div>
<div class="form-group">
<label>Number of Slots
<small class="text-muted">Number of slots can be generated</small></label>
<input type="number" disabled name="slotNumber" class="form-control purchase-inputmask" id="slotNumber" placeholder="Number of slots" />
</div>
<button type="submit" disabled name="submit" id="submit" class="btn btn-primary">
Proceed
</button>
</form>
</div>
</div>
</div>
<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).ready(function() {
$("#slotInterval").change(function(event) {
$('#submit').removeAttr('disabled');
var startTime = $("#stime").val();
var endTime = $("#ftime").val();
var intervalInMinutes = $("#slotInterval").val();
// console.log(startTime, endTime, intervalInMinutes);
// var userHtml = '<div class="d-flex justify-content-end mb-4"><div class="msg_cotainer_send">' + rawText + '<span class="msg_time_send">'+ str_time + '</span></div><div class="img_cont_msg"><img src="https://i.ibb.co/d5b84Xw/Untitled-design.png" class="rounded-circle user_img_msg"></div></div>';
// $("#text").val("");
// $("#messageFormeight").append(userHtml);
// window.setTimeout(function(){
// var loadingHtml = '<div class="d-flex justify-content-start mb-4"><div class="img_cont_msg"><img src="https://i.ibb.co/MRVSZRX/DALL-E-2023-12-30-11-50-00-A-lifelike-shaggy-brown-dog-inspired-by-the-first-generated-image-of-Prim.jpg" class="rounded-circle user_img_msg"></div><div class="msg_cotainer">Fetching from thread history, please wait...<span class="msg_time">' + str_time + '</span></div></div>';
// $("#messageFormeight").append(loadingHtml);
// }, 800);
const totalHours = calculateTotalHours(startTime, endTime);
const timeSlots = generateTimeSlots(startTime, endTime, intervalInMinutes);
// console.log(`Total hours between ${startTime} and ${endTime}: ${totalHours} hours.`);
console.log("Time slots:");
// timeSlots.forEach(timeSlot => console.log(timeSlot));
// console.log(timeSlots.length);
// for (var li of timeSlots) {
// console.log($(li));
// }
event.preventDefault();
});
function calculateTotalHours(startTime, endTime) {
const startTime24 = new Date('2000-01-01 ' + startTime).toLocaleTimeString('en-US', { hour12: false });
const endTime24 = new Date('2000-01-01 ' + endTime).toLocaleTimeString('en-US', { hour12: false });
const startDateTime = new Date('2000-01-01 ' + startTime24);
const endDateTime = new Date('2000-01-01 ' + endTime24);
const interval = Math.abs(endDateTime - startDateTime);
const totalHours = interval / (1000 * 60 * 60);
return totalHours;
}
// function generateTimeSlots(startTime, endTime, intervalInMinutes) {
// const timeSlots = [];
// let currentDateTime = new Date('2000-01-01 ' + startTime);
// while (currentDateTime <= new Date('2000-01-01 ' + endTime)) {
// timeSlots.push(currentDateTime.toLocaleTimeString('en-US', { hour: 'numeric', minute: 'numeric' }));
// currentDateTime.setMinutes(currentDateTime.getMinutes() + intervalInMinutes);
// }
// return timeSlots;
// }
function generateTimeSlots(startTime, endTime, intervalInMinutes) {
const timeSlots = [];
let currentDateTime = new Date('2000-01-01 ' + startTime);
let endDateTime = new Date('2000-01-01 ' + endTime)
while (currentDateTime < endDateTime) {
console.log("## "+currentDateTime);
const hours = currentDateTime.getHours().toString().padStart(2, '0');
const minutes = currentDateTime.getMinutes().toString().padStart(2, '0');
const formattedTime = hours + ':' + minutes;
timeSlots.push(formattedTime);
console.log(">> "+formattedTime);
currentDateTime.setMinutes(currentDateTime.getMinutes() + intervalInMinutes);
}
return timeSlots;
}
});
</script>
</div>
<?php
// function calculateTotalHours($startTime, $endTime) {
// $startTime24 = date('H:i', strtotime($startTime));
// $endTime24 = date('H:i', strtotime($endTime));
// $startDateTime = new DateTime($startTime24);
// $endDateTime = new DateTime($endTime24);
// $interval = $startDateTime->diff($endDateTime);
// $totalHours = $interval->format('%H') + ($interval->format('%i') / 60);
// return $totalHours;
// }
// function generateTimeSlots($startTime, $endTime, $intervalInMinutes) {
// $timeSlots = [];
// $currentDateTime = new DateTime($startTime);
// while ($currentDateTime <= new DateTime($endTime)) {
// $timeSlots[] = $currentDateTime->format('h:i A');
// $currentDateTime->add(new DateInterval('PT' . $intervalInMinutes . 'M'));
// }
// return $timeSlots;
// }
// if (isset($_POST['submit'])) {
// // Example usage
// $startTime = $_POST['stime'];
// $endTime = $_POST['ftime'];
// $intervalInMinutes = $_POST['slotInterval'];
// $totalHours = calculateTotalHours($startTime, $endTime);
// $timeSlots = generateTimeSlots($startTime, $endTime, $intervalInMinutes);
// echo "Total hours between $startTime and $endTime: $totalHours hours.<br>". count($timeSlots) ."<br>";
// echo "<h3>Time slots:</h3><br>";
// foreach ($timeSlots as $timeSlot) {
// echo $timeSlot."<br>";
// }
// echo "<br><h3>------------</h3>";
// }
// $totalHours = calculateTotalHours($startTime, $endTime);
// echo "Total hours between $startTime and $endTime: $totalHours hours.";
?>