fix: faxsms psr7 vendor fix (#7794)
[openemr.git] / portal / find_appt_popup_user.php
blob278ba25ef5bf3f116b61768215ad942ef0255222
1 <?php
3 /**
5 * Modified from main codebase for the patient portal.
7 * @package OpenEMR
8 * @link http://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Jerry Padgett <sjpadgett@gmail.com>
11 * @author Brady Miller <brady.g.miller@gmail.com>
12 * @author Ian Jardine ( github.com/epsdky )
13 * @copyright Copyright (C) 2005-2013 Rod Roark <rod@sunsetsystems.com>
14 * @copyright Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
15 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
16 * @copyright Copyright (C) 2019 Ian Jardine ( github.com/epsdky )
17 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
20 // Note from Rod 2013-01-22:
21 // This module needs to be refactored to share the same code that is in
22 // interface/main/calendar/find_appt_popup.php. It contains an old version
23 // of that logic and does not support exception dates for repeating events.
25 // Rod mentioned in the previous comment that the code "does not support exception dates for repeating events".
26 // This issue no longer exists - epsdky 2019
28 //continue session
29 // Will start the (patient) portal OpenEMR session/cookie.
30 require_once(dirname(__FILE__) . "/../src/Common/Session/SessionUtil.php");
31 OpenEMR\Common\Session\SessionUtil::portalSessionStart();
34 //landing page definition -- where to go if something goes wrong
35 $landingpage = "index.php?site=" . urlencode($_SESSION['site_id']);
38 // kick out if patient not authenticated
39 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
40 $pid = $_SESSION['pid'];
41 } else {
42 OpenEMR\Common\Session\SessionUtil::portalSessionCookieDestroy();
43 header('Location: ' . $landingpage . '&w');
44 exit();
49 $ignoreAuth_onsite_portal = true;
51 require_once("../interface/globals.php");
52 require_once("$srcdir/patient.inc.php");
53 require_once(dirname(__FILE__) . "/../library/appointments.inc.php");
55 use OpenEMR\Core\Header;
56 use OpenEMR\Services\Utils\DateFormatterUtils;
58 $input_catid = $_REQUEST['catid'];
60 // Record an event into the slots array for a specified day.
61 function doOneDay($catid, $udate, $starttime, $duration, $prefcatid)
63 global $slots, $slotsecs, $slotstime, $slotbase, $slotcount, $input_catid;
64 $udate = strtotime($starttime, $udate);
65 if ($udate < $slotstime) {
66 return;
69 $i = (int)($udate / $slotsecs) - $slotbase;
70 $iend = (int)(($duration + $slotsecs - 1) / $slotsecs) + $i;
71 if ($iend > $slotcount) {
72 $iend = $slotcount;
75 if ($iend <= $i) {
76 $iend = $i + 1;
79 for (; $i < $iend; ++$i) {
80 if ($catid == 2) { // in office
81 // If a category ID was specified when this popup was invoked, then select
82 // only IN events with a matching preferred category or with no preferred
83 // category; other IN events are to be treated as OUT events.
84 if ($input_catid) {
85 if (!empty($slots[$i])) {
86 if ($prefcatid == $input_catid || !$prefcatid) {
87 $slots[$i] |= 1;
88 } else {
89 $slots[$i] |= 2;
91 } else {
92 $slots[$i] |= 1;
94 } else {
95 $slots[$i] |= 1;
98 break; // ignore any positive duration for IN
99 } elseif ($catid == 3) { // out of office
100 $slots[$i] |= 2;
101 break; // ignore any positive duration for OUT
102 } else { // all other events reserve time
103 $slots[$i] |= 4;
108 // seconds per time slot
109 $slotsecs = $GLOBALS['calendar_interval'] * 60;
111 $catslots = 1;
112 if ($input_catid) {
113 $srow = sqlQuery("SELECT pc_duration FROM openemr_postcalendar_categories WHERE pc_catid = ?", array($input_catid));
114 if ($srow['pc_duration']) {
115 $catslots = ceil($srow['pc_duration'] / $slotsecs);
119 $info_msg = "";
121 $searchdays = 7; // default to a 1-week lookahead
122 if ($_REQUEST['searchdays'] ?? null) {
123 $searchdays = $_REQUEST['searchdays'];
126 // Get a start date.
127 if (!empty($_REQUEST['startdate'])) {
128 $sdate = DateFormatterUtils::DateToYYYYMMDD($_REQUEST['startdate']);
129 } else {
130 $sdate = date("Y-m-d");
133 // Get an end date - actually the date after the end date.
134 preg_match("/(\d\d\d\d)\D*(\d\d)\D*(\d\d)/", $sdate, $matches);
135 $edate = date(
136 "Y-m-d",
137 mktime(0, 0, 0, $matches[2], $matches[3] + $searchdays, $matches[1])
140 // compute starting time slot number and number of slots.
141 $slotstime = strtotime("$sdate 00:00:00");
142 $slotetime = strtotime("$edate 00:00:00");
143 $slotbase = (int)($slotstime / $slotsecs);
144 $slotcount = (int)($slotetime / $slotsecs) - $slotbase;
146 if ($slotcount <= 0 || $slotcount > 100000) {
147 die("Invalid date range.");
150 $slotsperday = (int)(60 * 60 * 24 / $slotsecs);
152 // If we have a provider, search.
154 if ($_REQUEST['providerid']) {
155 $providerid = $_REQUEST['providerid'];
157 // Create and initialize the slot array. Values are bit-mapped:
158 // bit 0 = in-office occurs here
159 // bit 1 = out-of-office occurs here
160 // bit 2 = reserved
161 // So, values may range from 0 to 7.
163 $slots = array_pad(array(), $slotcount, 0);
165 // Note there is no need to sort the query results.
166 // echo $sdate." -- ".$edate;
167 $query = "SELECT pc_eventDate, pc_endDate, pc_startTime, pc_duration, " .
168 "pc_recurrtype, pc_recurrspec, pc_alldayevent, pc_catid, pc_prefcatid, pc_title " .
169 "FROM openemr_postcalendar_events " .
170 "WHERE pc_aid = ? AND " .
171 "((pc_endDate >= ? AND pc_eventDate < ?) OR " .
172 "(pc_endDate = '0000-00-00' AND pc_eventDate >= ? AND pc_eventDate < ?))";
174 $sqlBindArray = array();
175 array_push($sqlBindArray, $providerid, $sdate, $edate, $sdate, $edate);
176 //////
177 $events2 = fetchEvents($sdate, $edate, null, null, false, 0, $sqlBindArray, $query);
178 foreach ($events2 as $row) {
179 $thistime = strtotime($row['pc_eventDate'] . " 00:00:00");
180 doOneDay(
181 $row['pc_catid'],
182 $thistime,
183 $row['pc_startTime'],
184 $row['pc_duration'],
185 $row['pc_prefcatid']
188 //////
190 // Mark all slots reserved where the provider is not in-office.
191 // Actually we could do this in the display loop instead.
192 $inoffice = false;
193 for ($i = 0; $i < $slotcount; ++$i) {
194 if (($i % $slotsperday) == 0) {
195 $inoffice = false;
198 if ($slots[$i] & 1) {
199 $inoffice = true;
202 if ($slots[$i] & 2) {
203 $inoffice = false;
206 if (!$inoffice) {
207 $slots[$i] |= 4;
212 <!DOCTYPE html>
213 <html>
214 <head>
215 <title><?php echo xlt('Find Available Appointments'); ?></title>
216 <?php Header::setupHeader(['no_main-theme', 'portal-theme', 'datetime-picker', 'opener']); ?>
217 <script>
219 function setappt(year, mon, mday, hours, minutes) {
220 opener.setappt(year, mon, mday, hours, minutes);
221 dlgclose();
222 return false;
225 </script>
227 <style>
228 form {
229 /* this eliminates the padding normally around a FORM tag */
230 padding: 0;
231 margin: 0;
234 #searchCriteria {
235 text-align: center;
236 width: 100%;
237 font-weight: bold;
238 padding: 0.1875rem;
241 #searchResults {
242 width: 100%;
243 height: 100%;
244 overflow: auto;
247 #searchResults table {
248 width: 100%;
249 border-collapse: collapse;
250 background-color: var(--white);
253 #searchResults td {
254 border-bottom: 1px solid var(--gray600);
255 padding: 1px 5px;
258 .blue_highlight {
259 background-color: #BBCCDD;
260 color: var(--white);
263 #am a, #am a:hover {
264 padding: 4px;
265 text-decoration: none;
268 #pm a, #pm a:hover {
269 color: var(--danger);
270 padding: 4px;
271 text-decoration: none;
273 </style>
275 </head>
277 <body class="body_top">
279 <div class="table-primary" id="searchCriteria">
280 <form method='post' name='theform' action='./find_appt_popup_user.php?providerid=<?php echo attr_url($providerid); ?>&catid=<?php echo attr_url($input_catid); ?>'>
281 <input type="hidden" name='bypatient' />
282 <div class="form-row mx-0 align-items-center">
283 <label for="startdate" class="col-1 mx-2 col-form-label"><?php echo xlt('Start date:'); ?></label>
284 <div class="col-auto">
285 <input type='text' class='datepicker form-control' name='startdate' id='startdate' size='10' value='<?php echo attr(DateFormatterUtils::oeFormatShortDate($sdate)); ?>' title='starting date for search' />
286 </div>
287 <label for="searchdays" class="col-auto col-form-label"><?php echo xlt('for'); ?></label>
288 <div class="col-auto">
289 <input type='text' class="form-control" name='searchdays' id='searchdays' size='3' value='<?php echo attr($searchdays); ?>' title='Number of days to search from the start date' />
290 </div>
291 <label for="searchdays" class="col-auto col-form-label"><?php echo xlt('days'); ?></label>
292 <div class="col-auto">
293 <input type='submit' class="btn btn-primary btn-sm btn-block" value='<?php echo xla('Search'); ?>' />
294 </div>
295 </div>
296 </div>
298 <?php if (!empty($slots)) : ?>
299 <div id="searchResultsHeader">
300 <table class='table table-bordered'>
302 </table>
303 </div>
305 <div id="searchResults" class="container-fluid">
306 <div class="table-responsive">
307 <table class='table table-sm table-striped table-bordered'>
308 <thead id="searchResultsHeader">
309 <tr>
310 <th class="table-dark text-light"><?php echo xlt('Day'); ?></th>
311 <th class="srTimes"><?php echo xlt('Available Times'); ?></th>
312 </tr>
313 </thead>
314 <?php
315 $lastdate = "";
316 $ampmFlag = "am"; // establish an AM-PM line break flag
317 for ($i = 0; $i < $slotcount; ++$i) {
318 $available = true;
319 for ($j = $i; $j < $i + $catslots; ++$j) {
320 if ($slots[$j] >= 4) {
321 $available = false;
325 if (!$available) {
326 continue; // skip reserved slots
329 $utime = ($slotbase + $i) * $slotsecs;
330 $thisdate = date("Y-m-d", $utime);
331 if ($thisdate != $lastdate) {
332 // if a new day, start a new row
333 if ($lastdate) {
334 echo "</div>";
335 echo "</td>\n";
336 echo " </tr>\n";
339 $lastdate = $thisdate;
340 echo " <tr class='oneresult'>\n";
341 echo " <td class='table-dark text-light'>" . date("l", $utime) . "<br />" . date("Y-m-d", $utime) . "</td>\n";
342 echo " <td class='srTimes'>";
343 echo "<div id='am'>AM<hr class='m-0 p-0 mb-n3'/><br/>";
344 $ampmFlag = "am"; // reset the AMPM flag
347 $ampm = date('a', $utime);
348 if ($ampmFlag != $ampm) {
349 echo "</div><div id='pm'><hr class='m-0 p-0' />PM<hr class='m-0 p-0 mb-n3' /><br/>";
352 $ampmFlag = $ampm;
354 $atitle = "Choose " . date("h:i a", $utime);
355 $adate = getdate($utime);
357 $anchor = "<a href='' onclick='return setappt(" .
358 attr_js(date("Y", $utime)) . "," .
359 attr_js($adate['mon']) . "," .
360 attr_js($adate['mday']) . "," .
361 attr_js(date("G", $utime)) . "," .
362 attr_js(date("i", $utime)) . "," .
363 attr_js(date('a', $utime)) . ")'" .
364 " title='" . attr($atitle) . "' alt='" . attr($atitle) . "'" .
365 ">";
366 echo (strlen(date('g', $utime)) < 2 ? "<span style='visibility:hidden'>0</span>" : "") .
367 $anchor . date("g:i", $utime) . "</a> ";
369 // If category duration is more than 1 slot, increment $i appropriately.
370 // This is to avoid reporting available times on undesirable boundaries.
371 $i += $catslots - 1;
374 if ($lastdate) {
375 echo "</td>\n";
376 echo " </tr>\n";
377 } else {
378 echo " <tr><td colspan='2'> " . xlt('No openings were found for this period.') . "</td></tr>\n";
381 </table>
382 </div>
383 </div>
384 </div>
385 <?php endif; ?>
387 </form>
389 <script>
391 // jQuery stuff to make the page a little easier to use
392 $(function () {
393 $(".oneresult").hover(function () {
394 $(this).toggleClass("highlight");
395 }, function () {
396 $(this).toggleClass("highlight");
398 $(".oneresult a").hover(function () {
399 $(this).toggleClass("blue_highlight");
400 $(this).children().toggleClass("blue_highlight");
401 }, function () {
402 $(this).toggleClass("blue_highlight");
403 $(this).children().toggleClass("blue_highlight");
406 $('.datepicker').datetimepicker({
407 <?php $datetimepicker_timepicker = false; ?>
408 <?php $datetimepicker_formatInput = true; ?>
409 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
410 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
415 </script>
416 </body>
417 </html>