Fix for issue reported in 'Scheduling Failures' on forum
[openemr.git] / interface / main / calendar / add_edit_event.php
blob41bc43ef1867e207ab5769315057436cd4a60c94
1 <?php
2 /*
3 * Add or edit an event in the calendar.
5 * The event editor looks something like this:
7 * //------------------------------------------------------------//
8 * // Category __________________V O All day event //
9 * // Date _____________ [?] O Time ___:___ __V //
10 * // Title ___________________ duration ____ minutes //
11 * // Patient _(Click_to_select)_ //
12 * // Provider __________________V X Repeats ______V ______V //
13 * // Status __________________V until __________ [?] //
14 * // Comments ________________________________________________ //
15 * // //
16 * // [Save] [Find Available] [Delete] [Cancel] //
17 * //------------------------------------------------------------//
20 * Copyright (C) 2005-2013 Rod Roark <rod@sunsetsystems.com>
21 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
23 * LICENSE: This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation; either version 3
26 * of the License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
34 * @package OpenEMR
35 * @author Rod Roark <rod@sunsetsystems.com>
36 * @author Brady Miller <brady.g.miller@gmail.com>
37 * @link http://www.open-emr.org
41 require_once('../../globals.php');
42 require_once($GLOBALS['srcdir'].'/patient.inc');
43 require_once($GLOBALS['srcdir'].'/forms.inc');
44 require_once($GLOBALS['srcdir'].'/calendar.inc');
45 require_once($GLOBALS['srcdir'].'/options.inc.php');
46 require_once($GLOBALS['srcdir'].'/encounter_events.inc.php');
47 require_once($GLOBALS['srcdir'].'/acl.inc');
48 require_once($GLOBALS['srcdir'].'/patient_tracker.inc.php');
49 require_once($GLOBALS['incdir']."/main/holidays/Holidays_Controller.php");
50 require_once($GLOBALS['srcdir'].'/group.inc');
52 //Check access control
53 if (!acl_check('patients', 'appt', '', array('write','wsome'))) {
54 die(xl('Access not allowed'));
57 use OpenEMR\Core\Header;
59 /* Things that might be passed by our opener. */
60 $eid = $_GET['eid']; // only for existing events
61 $date = $_GET['date']; // this and below only for new events
62 $userid = $_GET['userid'];
63 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
65 $_POST['form_date'] = DateToYYYYMMDD($_POST['form_date']);
66 $_POST['form_enddate'] = DateToYYYYMMDD($_POST['form_enddate']);
68 if ($date) {
69 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
70 } else {
71 $date = date("Y-m-d");
75 $starttimem = '00';
76 if (isset($_GET['starttimem'])) {
77 $starttimem = substr('00' . $_GET['starttimem'], -2);
81 if (isset($_GET['starttimeh'])) {
82 $starttimeh = $_GET['starttimeh'];
83 if (isset($_GET['startampm'])) {
84 if ($_GET['startampm'] == '2' && $starttimeh < 12) {
85 $starttimeh += 12;
88 } else {
89 $starttimeh = date("G");
92 $startampm = '';
94 $info_msg = "";
98 <?php $g_edit = acl_check("groups", "gcalendar", false, 'write');?>
99 <?php $g_view = acl_check("groups", "gcalendar", false, 'view');?>
101 <?php Header::setupHeader(['common', 'datetime-picker', 'opener']); ?>
103 <!-- validation library -->
104 <!--//Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation-->
105 <?php $use_validate_js = 1;?>
106 <?php require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?>
107 <?php
108 //Gets validation rules from Page Validation list.
109 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
110 $have_group_global_enabled = true;
111 if ((!$g_edit && !$g_view) || (!$GLOBALS['enable_group_therapy'])) {
112 $_GET['group'] = false;
113 $have_group_global_enabled = false;
116 if ($_GET['group'] == true) {
117 //groups tab
118 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php?group=true");
119 } elseif ($_GET['prov']) {
120 //providers tab
121 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php?prov=true");
122 } else { //patient tab
123 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php");
126 if (empty($collectthis)) {
127 $collectthis = "undefined";
128 } else {
129 $collectthis = $collectthis[array_keys($collectthis)[0]]["rules"];
132 <?php $group_disabled = ($_GET['group'] && !$g_edit && $have_group_global_enabled )?' disabled=true; ':'';?>
133 <?php if ($group_disabled) {
134 echo '<script>$( document ).ready(function(){
135 $("input").prop("disabled", true);
136 $("select").prop("disabled", true);
137 }) </script>';
140 <?php
144 function InsertEventFull()
146 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
147 // =======================================
148 // multi providers case
149 // =======================================
150 if (is_array($_POST['form_provider'])) {
151 // obtain the next available unique key to group multiple providers around some event
152 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
153 $max = sqlFetchArray($q);
154 $new_multiple_value = $max['max'] + 1;
156 $pc_eid = null;
157 foreach ($_POST['form_provider'] as $provider) {
158 $args = $_POST;
159 // specify some special variables needed for the INSERT
160 $args['new_multiple_value'] = $new_multiple_value;
161 $args['form_provider'] = $provider;
162 $args['event_date'] = $event_date;
163 $args['duration'] = $duration * 60;
164 $args['recurrspec'] = $recurrspec;
165 $args['starttime'] = $starttime;
166 $args['endtime'] = $endtime;
167 $args['locationspec'] = $locationspec;
168 $pc_eid_temp = InsertEvent($args);
169 if ($pc_eid == null) {
170 $pc_eid = $pc_eid_temp;
174 return $pc_eid;
177 // ====================================
178 // single provider
179 // ====================================
180 } else {
181 $args = $_POST;
182 // specify some special variables needed for the INSERT
183 $args['new_multiple_value'] = "";
184 $args['event_date'] = $event_date;
185 $args['duration'] = $duration * 60;
186 $args['recurrspec'] = $recurrspec;
187 $args['starttime'] = $starttime;
188 $args['endtime'] = $endtime;
189 $args['locationspec'] = $locationspec;
190 $pc_eid = InsertEvent($args);
191 return $pc_eid;
194 function DOBandEncounter($pc_eid)
196 global $event_date,$info_msg;
197 // Save new DOB if it's there.
198 $patient_dob = trim($_POST['form_dob']);
199 $tmph = $_POST['form_hour'] + 0;
200 $tmpm = $_POST['form_minute'] + 0;
201 if ($_POST['form_ampm'] == '2' && $tmph < 12) {
202 $tmph += 12;
205 $appttime = "$tmph:$tmpm:00";
207 if ($patient_dob && $_POST['form_pid']) {
208 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
209 "pid = ?", array($patient_dob,$_POST['form_pid']));
212 // Manage tracker status.
213 // And auto-create a new encounter if appropriate.
214 if (!empty($_POST['form_pid'])) {
215 if ($GLOBALS['auto_create_new_encounters'] && $event_date == date('Y-m-d') && (is_checkin($_POST['form_apptstatus']) == '1') && !is_tracker_encounter_exist($event_date, $appttime, $_POST['form_pid'], $_GET['eid'])) {
216 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
217 if ($encounter) {
218 $info_msg .= xl("New encounter created with id");
219 $info_msg .= " $encounter";
222 # Capture the appt status and room number for patient tracker. This will map the encounter to it also.
223 if (isset($GLOBALS['temporary-eid-for-manage-tracker']) || !empty($_GET['eid'])) {
224 // Note that the temporary-eid-for-manage-tracker is used to capture the eid for new appointments and when separate a recurring
225 // appointment. It is set in the InsertEvent() function. Note that in the case of spearating a recurrent appointment, the get eid
226 // parameter is actually erroneous(is eid of the recurrent appt and not the new separated appt), so need to use the
227 // temporary-eid-for-manage-tracker global instead.
228 $temp_eid = (isset($GLOBALS['temporary-eid-for-manage-tracker'])) ? $GLOBALS['temporary-eid-for-manage-tracker'] : $_GET['eid'];
229 manage_tracker_status($event_date, $appttime, $temp_eid, $_POST['form_pid'], $_SESSION["authUser"], $_POST['form_apptstatus'], $_POST['form_room'], $encounter);
231 } else {
232 # Capture the appt status and room number for patient tracker.
233 if (!empty($_GET['eid'])) {
234 manage_tracker_status($event_date, $appttime, $_GET['eid'], $_POST['form_pid'], $_SESSION["authUser"], $_POST['form_apptstatus'], $_POST['form_room']);
239 // auto create encounter for therapy group
240 if (!empty($_POST['form_gid'])) {
241 // status Took Place is the check in of therapy group
242 if ($GLOBALS['auto_create_new_encounters'] && $event_date == date('Y-m-d') && $_POST['form_apptstatus'] == '=') {
243 $encounter = todaysTherapyGroupEncounterCheck($_POST['form_gid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false, $pc_eid);
244 if ($encounter) {
245 $info_msg .= xl("New group encounter created with id");
246 $info_msg .= " $encounter";
253 /*This function is used for setting the date of the first event when using the "day_every_week" repetition mechanism.
254 When the 'start date' is not one of the days chosen for the repetition, the start date needs to be changed to the first
255 occurrence of one of these set days. */
256 function setEventDate($start_date, $recurrence)
258 $timestamp = strtotime($start_date);
259 $day = date('w', $timestamp);
260 //If the 'start date' is one of the set days
261 if (in_array(($day+1), explode(',', $recurrence))) {
262 return $start_date;
265 //else: (we need to change start date to first occurrence of one of the set days)
267 $new_date = getTheNextAppointment($start_date, $recurrence);
269 return $new_date;
271 //================================================================================================================
273 // EVENTS TO FACILITIES (lemonsoftware)
274 //(CHEMED) get facility name
275 // edit event case - if there is no association made, then insert one with the first facility
276 if ($eid) {
277 $selfacil = '';
278 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
279 FROM openemr_postcalendar_events
280 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
281 WHERE pc_eid = ?", array($eid));
282 // if ( !$facility['pc_facility'] ) {
283 if (is_array($facility) && !$facility['pc_facility']) {
284 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']));
285 $min = $qmin['minId'];
286 $min_name = $qmin['facility'];
288 // multiple providers case
289 if ($GLOBALS['select_multi_providers']) {
290 $mul = $facility['pc_multiple'];
291 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min,$mul));
294 // EOS multiple
296 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min,$eid));
297 $e2f = $min;
298 $e2f_name = $min_name;
299 } else {
300 // not edit event
301 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
302 $e2f = $_SESSION['pc_facility'];
303 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
304 $e2f = $_COOKIE['pc_facility'];
305 } else {
306 $e2f = $facility['pc_facility'];
307 $e2f_name = $facility['name'];
312 // EOS E2F
313 // ===========================
314 //=============================================================================================================================
315 if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save") {
316 // Compute start and end time strings to be saved.
317 if ($_POST['form_allday']) {
318 $tmph = 0;
319 $tmpm = 0;
320 $duration = 24 * 60;
321 } else {
322 $tmph = $_POST['form_hour'] + 0;
323 $tmpm = $_POST['form_minute'] + 0;
324 if ($_POST['form_ampm'] == '2' && $tmph < 12) {
325 $tmph += 12;
328 $duration = abs($_POST['form_duration']); // fixes #395
331 $starttime = "$tmph:$tmpm:00";
333 $tmpm += $duration;
334 while ($tmpm >= 60) {
335 $tmpm -= 60;
336 ++$tmph;
339 $endtime = "$tmph:$tmpm:00";
341 // Set up working variables related to repeated events.
342 $my_recurrtype = 0;
343 $my_repeat_freq = 0 + $_POST['form_repeat_freq'];
344 $my_repeat_type = 0 + $_POST['form_repeat_type'];
345 $my_repeat_on_num = 1;
346 $my_repeat_on_day = 0;
347 $my_repeat_on_freq = 0;
349 // the starting date of the event, pay attention with this value
350 // when editing recurring events -- JRM Oct-08
351 $event_date = $_POST['form_date'];
353 //If used new recurrence mechanism of set days every week
354 if (!empty($_POST['days_every_week'])) {
355 $my_recurrtype = 3;
356 //loop through checkboxes and insert encounter days into array
357 $days_every_week_arr = array();
358 for ($i=1; $i<=7; $i++) {
359 if (!empty($_POST['day_' . $i])) {
360 array_push($days_every_week_arr, $i);
364 $my_repeat_freq = implode(",", $days_every_week_arr);
365 $my_repeat_type = 6;
366 $event_date = setEventDate($_POST['form_date'], $my_repeat_freq);
367 } elseif (!empty($_POST['form_repeat'])) {
368 $my_recurrtype = 1;
369 if ($my_repeat_type > 4) {
370 $my_recurrtype = 2;
371 $time = strtotime($event_date);
372 $my_repeat_on_day = 0 + date('w', $time);
373 $my_repeat_on_freq = $my_repeat_freq;
374 if ($my_repeat_type == 5) {
375 $my_repeat_on_num = intval((date('j', $time) - 1) / 7) + 1;
376 } else {
377 // Last occurence of this weekday on the month
378 $my_repeat_on_num = 5;
381 // Maybe not needed, but for consistency with postcalendar:
382 $my_repeat_freq = 0;
383 $my_repeat_type = 0;
388 // Useless garbage that we must save.
389 $locationspecs = array("event_location" => "",
390 "event_street1" => "",
391 "event_street2" => "",
392 "event_city" => "",
393 "event_state" => "",
394 "event_postal" => ""
396 $locationspec = serialize($locationspecs);
398 // capture the recurring specifications
399 $recurrspec = array("event_repeat_freq" => "$my_repeat_freq",
400 "event_repeat_freq_type" => "$my_repeat_type",
401 "event_repeat_on_num" => "$my_repeat_on_num",
402 "event_repeat_on_day" => "$my_repeat_on_day",
403 "event_repeat_on_freq" => "$my_repeat_on_freq",
404 "exdate" => $_POST['form_repeat_exdate']
408 if ($my_recurrtype == 2) { // Added by epsdky 2016 (details in commit)
409 if ($_POST['old_repeats'] == 2) {
410 if ($_POST['rt2_flag2']) {
411 $recurrspec['rt2_pf_flag'] = "1";
413 } else {
414 $recurrspec['rt2_pf_flag'] = "1";
416 } // End of addition by epsdky
418 // no recurr specs, this is used for adding a new non-recurring event
419 $noRecurrspec = array("event_repeat_freq" => "",
420 "event_repeat_freq_type" => "",
421 "event_repeat_on_num" => "1",
422 "event_repeat_on_day" => "0",
423 "event_repeat_on_freq" => "0",
424 "exdate" => ""
426 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
427 //=============================================================================================================================
428 if ($_POST['form_action'] == "duplicate") {
429 $eid = InsertEventFull();
430 DOBandEncounter($eid);
433 // If we are saving, then save and close the window.
435 if ($_POST['form_action'] == "save") {
436 /* =======================================================
437 * UPDATE EVENTS
438 * =====================================================*/
439 if ($eid) {
440 // what is multiple key around this $eid?
441 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
443 // ====================================
444 // multiple providers
445 // ====================================
446 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
447 // obtain current list of providers regarding the multiple key
448 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']));
449 while ($current = sqlFetchArray($up)) {
450 $providers_current[] = $current['pc_aid'];
453 // get the new list of providers from the submitted form
454 $providers_new = $_POST['form_provider'];
456 // ===== Only current event of repeating series =====
457 if ($_POST['recurr_affect'] == 'current') {
458 // update all existing event records to exlude the current date
459 foreach ($providers_current as $provider) {
460 // update the provider's original event
461 // get the original event's repeat specs
462 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
463 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']));
464 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
465 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
466 if ($oldRecurrspec['exdate'] != "") {
467 $oldRecurrspec['exdate'] .= ",".$selected_date;
468 } else {
469 $oldRecurrspec['exdate'] .= $selected_date;
472 // mod original event recur specs to exclude this date
473 sqlStatement("UPDATE openemr_postcalendar_events SET " .
474 " pc_recurrspec = ? ".
475 " WHERE pc_aid = ? AND pc_multiple=?", array(serialize($oldRecurrspec),$provider,$row['pc_multiple']));
478 // obtain the next available unique key to group multiple providers around some event
479 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
480 $max = sqlFetchArray($q);
481 $new_multiple_value = $max['max'] + 1;
483 // insert a new event record for each provider selected on the form
484 foreach ($providers_new as $provider) {
485 // insert a new event on this date with POST form data
486 $args = $_POST;
487 // specify some special variables needed for the INSERT
488 $args['new_multiple_value'] = $new_multiple_value;
489 $args['form_provider'] = $provider;
490 $args['event_date'] = $event_date;
491 $args['duration'] = $duration * 60;
492 // this event is forced to NOT REPEAT
493 $args['form_repeat'] = "0";
494 $args['days_every_week'] = "0";
495 $args['recurrspec'] = $noRecurrspec;
496 $args['form_enddate'] = "0000-00-00";
497 $args['starttime'] = $starttime;
498 $args['endtime'] = $endtime;
499 $args['locationspec'] = $locationspec;
500 InsertEvent($args);
502 } // ===== Future Recurring events of a repeating series =====
503 else if ($_POST['recurr_affect'] == 'future') {
504 // update all existing event records to
505 // stop recurring on this date-1
506 $selected_date = date("Y-m-d", (strtotime($_POST['selected_date'])-24*60*60));
507 foreach ($providers_current as $provider) {
508 // In case of a change in the middle of the event
509 if (strcmp($_POST['event_start_date'], $_POST['selected_date'])!=0) {
510 // mod original event recur specs to end on this date
511 sqlStatement("UPDATE openemr_postcalendar_events SET " .
512 " pc_enddate = ? " .
513 " WHERE pc_aid = ? AND pc_multiple=?", array($selected_date, $provider, $row['pc_multiple']));
514 } // In case of a change in the event head
515 else {
516 sqlStatement("DELETE FROM openemr_postcalendar_events " .
517 " WHERE pc_aid = ? AND pc_multiple=?", array($provider, $row['pc_multiple']));
521 // obtain the next available unique key to group multiple providers around some event
522 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
523 $max = sqlFetchArray($q);
524 $new_multiple_value = $max['max'] + 1;
526 // insert a new event record for each provider selected on the form
527 foreach ($providers_new as $provider) {
528 // insert a new event on this date with POST form data
529 $args = $_POST;
530 // specify some special variables needed for the INSERT
531 $args['new_multiple_value'] = $new_multiple_value;
532 $args['form_provider'] = $provider;
533 $args['event_date'] = $event_date;
534 $args['duration'] = $duration * 60;
535 $args['recurrspec'] = $recurrspec;
536 $args['starttime'] = $starttime;
537 $args['endtime'] = $endtime;
538 $args['locationspec'] = $locationspec;
539 InsertEvent($args);
541 } else {
542 /* =================================================================== */
543 // ===== a Single event or All events in a repeating series ==========
544 /* =================================================================== */
546 // this difference means that some providers from current was UNCHECKED
547 // so we must delete this event for them
548 $r1 = array_diff($providers_current, $providers_new);
549 $old_eid = null;
550 if (count($r1)) {
551 foreach ($r1 as $to_be_removed) {
552 if (!empty($_POST['form_gid'])) {
553 $old_eid = sqlQuery("SELECT pc_eid FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']));
555 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']));
559 // perform a check to see if user changed event date
560 // this is important when editing an existing recurring event
561 // oct-08 JRM
562 if ($_POST['form_date'] == $_POST['selected_date']) {
563 // user has NOT changed the start date of the event (and not recurrtype 3)
564 if ($my_recurrtype != 3) {
565 $event_date = $_POST['event_start_date'];
569 // this difference means that some providers were added
570 // so we must insert this event for them
571 $r2 = array_diff($providers_new, $providers_current);
572 if (count($r2)) {
573 foreach ($r2 as $to_be_inserted) {
574 $args = $_POST;
575 // specify some special variables needed for the INSERT
576 $args['new_multiple_value'] = $row['pc_multiple'];
577 $args['form_provider'] = $to_be_inserted;
578 $args['event_date'] = $event_date;
579 $args['duration'] = $duration * 60;
580 $args['recurrspec'] = $recurrspec;
581 $args['starttime'] = $starttime;
582 $args['endtime'] = $endtime;
583 $args['locationspec'] = $locationspec;
584 $new_eid = InsertEvent($args);
588 if (!is_null($old_eid) && !empty($old_eid)) {
589 // update group encounter is connected to event.
590 sqlQuery("UPDATE form_groups_encounter SET appt_id = ? WHERE appt_id = ?", array($new_eid, $old_eid['pc_eid']));
593 // after the two diffs above, we must update for remaining providers
594 // those who are intersected in $providers_current and $providers_new
595 foreach ($_POST['form_provider'] as $provider) {
596 sqlStatement("UPDATE openemr_postcalendar_events SET " .
597 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
598 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
599 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
600 "pc_time = NOW(), " .
601 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
602 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
603 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
604 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
605 "pc_endDate = '" . add_escape_custom($_POST['form_enddate']) . "', " .
606 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
607 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
608 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
609 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
610 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
611 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
612 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
613 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
614 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
615 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
616 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'");
617 } // foreach
620 // ====================================
621 // single provider
622 // ====================================
623 } elseif (!$row['pc_multiple']) {
624 if ($GLOBALS['select_multi_providers']) {
625 $prov = $_POST['form_provider'][0];
626 $_POST['form_provider'] = $prov;
627 } else {
628 $prov = $_POST['form_provider'];
631 if ($_POST['recurr_affect'] == 'current') {
632 // get the original event's repeat specs
633 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
634 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
635 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
636 if ($oldRecurrspec['exdate'] != "") {
637 $oldRecurrspec['exdate'] .= ",".$selected_date;
638 } else {
639 $oldRecurrspec['exdate'] .= $selected_date;
642 // mod original event recur specs to exclude this date
643 sqlStatement("UPDATE openemr_postcalendar_events SET " .
644 " pc_recurrspec = ? ".
645 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid));
647 // insert a new event on this date with POST form data
648 $args = $_POST;
649 // specify some special variables needed for the INSERT
650 $args['event_date'] = $event_date;
651 $args['duration'] = $duration * 60;
652 // this event is forced to NOT REPEAT
653 $args['form_repeat'] = "0";
654 $args['days_every_week'] = "0";
655 $args['recurrspec'] = $noRecurrspec;
656 $args['form_enddate'] = "0000-00-00";
657 $args['starttime'] = $starttime;
658 $args['endtime'] = $endtime;
659 $args['locationspec'] = $locationspec;
660 InsertEvent($args);
661 } else if ($_POST['recurr_affect'] == 'future') {
662 // mod original event to stop recurring on this date-1
663 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
664 sqlStatement("UPDATE openemr_postcalendar_events SET " .
665 " pc_enddate = ? ".
666 " WHERE pc_eid = ?", array($selected_date,$eid));
668 // insert a new event starting on this date with POST form data
669 $args = $_POST;
670 // specify some special variables needed for the INSERT
671 $args['event_date'] = $event_date;
672 $args['duration'] = $duration * 60;
673 $args['recurrspec'] = $recurrspec;
674 $args['starttime'] = $starttime;
675 $args['endtime'] = $endtime;
676 $args['locationspec'] = $locationspec;
677 InsertEvent($args);
678 } else {
679 // perform a check to see if user changed event date
680 // this is important when editing an existing recurring event
681 // oct-08 JRM
682 if ($_POST['form_date'] == $_POST['selected_date']) {
683 // user has NOT changed the start date of the event (and not recurrtype 3)
684 if ($my_recurrtype != 3) {
685 $event_date = $_POST['event_start_date'];
689 // mod the SINGLE event or ALL EVENTS in a repeating series
690 // simple provider case
691 sqlStatement("UPDATE openemr_postcalendar_events SET " .
692 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
693 "pc_aid = '" . add_escape_custom($prov) . "', " .
694 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
695 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
696 "pc_time = NOW(), " .
697 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
698 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
699 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
700 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
701 "pc_endDate = '" . add_escape_custom($_POST['form_enddate']) . "', " .
702 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
703 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
704 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
705 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
706 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
707 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
708 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
709 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
710 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
711 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
712 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
716 // =======================================
717 // end Update Multi providers case
718 // =======================================
720 // EVENTS TO FACILITIES
721 $e2f = (int)$eid;
722 } else {
723 /* =======================================================
724 * INSERT NEW EVENT(S)
725 * ======================================================*/
727 $eid = InsertEventFull();
730 // done with EVENT insert/update statements
732 DOBandEncounter(isset($eid) ? $eid : null);
733 } // =======================================
734 // DELETE EVENT(s)
735 // =======================================
736 else if ($_POST['form_action'] == "delete") {
737 // =======================================
738 // multi providers event
739 // =======================================
740 if ($GLOBALS['select_multi_providers']) {
741 // what is multiple key around this $eid?
742 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
744 // obtain current list of providers regarding the multiple key
745 $providers_current = array();
746 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']));
747 while ($current = sqlFetchArray($up)) {
748 $providers_current[] = $current['pc_aid'];
751 // establish a WHERE clause
752 if ($row['pc_multiple']) {
753 $whereClause = "pc_multiple = '{$row['pc_multiple']}'";
754 } else {
755 $whereClause = "pc_eid = '$eid'";
758 if ($_POST['recurr_affect'] == 'current') {
759 // update all existing event records to exlude the current date
760 foreach ($providers_current as $provider) {
761 // update the provider's original event
762 // get the original event's repeat specs
763 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
764 " WHERE pc_aid <=> ? AND pc_multiple=?", array($provider,$row['pc_multiple']));
765 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
766 $selected_date = date("Y-m-d", strtotime($_POST['selected_date']));
767 if ($oldRecurrspec['exdate'] != "") {
768 $oldRecurrspec['exdate'] .= ",".$selected_date;
769 } else {
770 $oldRecurrspec['exdate'] .= $selected_date;
773 // mod original event recur specs to exclude this date
774 sqlStatement("UPDATE openemr_postcalendar_events SET " .
775 " pc_recurrspec = ? ".
776 " WHERE ". $whereClause, array(serialize($oldRecurrspec)));
778 } else if ($_POST['recurr_affect'] == 'future') {
779 // update all existing event records to stop recurring on this date-1
780 $selected_date = date("Y-m-d", (strtotime($_POST['selected_date'])-24*60*60));
781 foreach ($providers_current as $provider) {
782 // In case of a change in the middle of the event
783 if (strcmp($_POST['event_start_date'], $_POST['selected_date'])!=0) {
784 // update the provider's original event
785 sqlStatement("UPDATE openemr_postcalendar_events SET " .
786 " pc_enddate = ? " .
787 " WHERE " . $whereClause, array($selected_date));
788 } // In case of a change in the event head
789 else {
790 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
793 } else {
794 // really delete the event from the database
795 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
797 } // =======================================
798 // single provider event
799 // =======================================
800 else {
801 if ($_POST['recurr_affect'] == 'current') {
802 // mod original event recur specs to exclude this date
804 // get the original event's repeat specs
805 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
806 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
807 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
808 if ($oldRecurrspec['exdate'] != "") {
809 $oldRecurrspec['exdate'] .= ",".$selected_date;
810 } else {
811 $oldRecurrspec['exdate'] .= $selected_date;
814 sqlStatement("UPDATE openemr_postcalendar_events SET " .
815 " pc_recurrspec = ? ".
816 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid));
817 } else if ($_POST['recurr_affect'] == 'future') {
818 // mod original event to stop recurring on this date-1
819 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
820 sqlStatement("UPDATE openemr_postcalendar_events SET " .
821 " pc_enddate = ? ".
822 " WHERE pc_eid = ?", array($selected_date,$eid));
823 } else {
824 // fully delete the event from the database
825 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
830 if ($_POST['form_action'] != "") {
831 // Close this window and refresh the calendar (or the patient_tracker) display.
832 echo "<html>\n<body>\n<script language='JavaScript'>\n";
833 if ($info_msg) {
834 echo " alert('" . addslashes($info_msg) . "');\n";
837 echo " if (opener && !opener.closed && opener.refreshme) {\n " .
838 " opener.refreshme();\n " . // This is for standard calendar page refresh
839 " } else {\n " .
840 " if(window.opener.pattrk){" .
841 " window.opener.pattrk.submit()\n " . // This is for patient flow board page refresh}
842 " }};\n";
843 echo " dlgclose();\n";
844 echo "</script>\n</body>\n</html>\n";
845 exit();
848 //*********************************
849 // If we get this far then we are displaying the form.
850 //*********************************
852 /*********************************************************************
853 This has been migrate to the administration->lists
854 $statuses = array(
855 '-' => '',
856 '*' => xl('* Reminder done'),
857 '+' => xl('+ Chart pulled'),
858 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
859 '?' => xl('? No show'),
860 '@' => xl('@ Arrived'),
861 '~' => xl('~ Arrived late'),
862 '!' => xl('! Left w/o visit'),
863 '#' => xl('# Ins/fin issue'),
864 '<' => xl('< In exam room'),
865 '>' => xl('> Checked out'),
866 '$' => xl('$ Coding done'),
867 '%' => xl('% Cancelled < 24h ')
869 *********************************************************************/
871 $repeats = 0; // if the event repeats
872 $repeattype = '0';
873 $repeatfreq = '0';
874 $patientid = '';
875 if ($_REQUEST['patientid']) {
876 $patientid = $_REQUEST['patientid'];
879 $patientname = null;
880 $patienttitle = array();
881 $pcroom = "";
882 $hometext = "";
883 $row = array();
884 $informant = "";
885 $groupid = '';
886 if ($_REQUEST['groupid']) {
887 $groupid = $_REQUEST['groupid'];
890 $groupname = null;
891 $group_statuses = getGroupStatuses();
894 // If we are editing an existing event, then get its data.
895 if ($eid) {
896 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
898 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
899 "FROM openemr_postcalendar_events AS e " .
900 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
901 "WHERE pc_eid = ?", array($eid));
902 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
904 // instead of using the event's starting date, keep what has been provided
905 // via the GET array, see the top of this file
906 if (empty($_GET['date'])) {
907 $date = $row['pc_eventDate'];
910 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
911 $userid = $row['pc_aid'];
912 $patientid = $row['pc_pid'];
913 $groupid = $row['pc_gid'];
914 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
915 $starttimem = substr($row['pc_startTime'], 3, 2);
916 $repeats = $row['pc_recurrtype'];
917 $multiple_value = $row['pc_multiple'];
919 // parse out the repeating data, if any
920 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
921 $repeattype = $rspecs['event_repeat_freq_type'];
922 $repeatfreq = $rspecs['event_repeat_freq'];
923 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
925 // Adjustments for repeat type 2, a particular weekday of the month.
926 if ($repeats == 2) {
927 $repeatfreq = $rspecs['event_repeat_on_freq'];
928 if ($rspecs['event_repeat_on_num'] < 5) {
929 $repeattype = 5;
930 } else {
931 $repeattype = 6;
935 $recurrence_end_date = ($row['pc_endDate'] && $row['pc_endDate'] != '0000-00-00') ? $row['pc_endDate'] : null;
936 $pcroom = $row['pc_room'];
937 $hometext = $row['pc_hometext'];
938 if (substr($hometext, 0, 6) == ':text:') {
939 $hometext = substr($hometext, 6);
941 } else {
942 // a NEW event
943 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
945 //-------------------------------------
946 //(CHEMED)
947 //Set default facility for a new event based on the given 'userid'
948 if ($userid) {
949 /*************************************************************
950 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
951 *************************************************************/
952 if ($_SESSION['pc_facility']) {
953 $pref_facility = sqlFetchArray(sqlStatement(
955 SELECT f.id as facility_id,
956 f.name as facility
957 FROM facility f
958 WHERE f.id = ?
960 array($_SESSION['pc_facility'])
962 } else {
963 $pref_facility = sqlFetchArray(sqlStatement("
964 SELECT u.facility_id,
965 f.name as facility
966 FROM users u
967 LEFT JOIN facility f on (u.facility_id = f.id)
968 WHERE u.id = ?
969 ", array($userid)));
972 /************************************************************/
973 $e2f = $pref_facility['facility_id'];
974 $e2f_name = $pref_facility['facility'];
977 //END of CHEMED -----------------------
980 // If we have a patient ID, get the name and phone numbers to display.
981 if ($patientid) {
982 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
983 "FROM patient_data WHERE pid = ?", array($patientid));
984 $patientname = $prow['lname'] . ", " . $prow['fname'];
985 if ($prow['phone_home']) {
986 $patienttitle['phone_home'] = xl("Home Phone").": " . $prow['phone_home'];
989 if ($prow['phone_biz']) {
990 $patienttitle['phone_biz'] = xl("Work Phone").": " . $prow['phone_biz'];
994 // If we have a group id, get group data
995 if ($groupid) {
996 $group_data = getGroup($groupid);
997 $groupname = $group_data['group_name'];
998 $group_end_date = $group_data['group_end_date'];
999 if (!$recurrence_end_date && $group_end_date && $group_end_date != '0000-00-00') {
1000 $recurrence_end_date = $group_end_date;// If there is no recurr end date get group's end date as default (only if group has an end date)
1004 // Get the providers list.
1005 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
1006 "authorized != 0 AND active = 1 ORDER BY lname, fname");
1008 // Get event categories.
1009 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
1010 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
1012 // Fix up the time format for AM/PM.
1013 $startampm = '1';
1014 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
1015 $startampm = '2';
1016 if ($starttimeh > 12) {
1017 $starttimeh -= 12;
1022 <!DOCTYPE html>
1023 <html>
1024 <head>
1026 <title><?php echo $eid ? xlt('Edit') : xlt('Add New') ?> <?php echo xlt('Event');?></title>
1028 <style>
1029 td { font-size:0.8em; }
1030 </style>
1032 <script language="JavaScript">
1034 <?php require $GLOBALS['srcdir'] . "/formatting_DateToYYYYMMDD_js.js.php" ?>
1036 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
1038 var durations = new Array();
1039 // var rectypes = new Array();
1040 <?php
1041 // Read the event categories, generate their options list, and get
1042 // the default event duration from them if this is a new event.
1043 $cattype=0;
1044 if ($_GET['prov']==true) {
1045 $cattype=1;
1048 if ($_GET['group'] == true) {
1049 $cattype=3;
1052 $cres = sqlStatement("SELECT pc_catid, pc_cattype, pc_catname, " .
1053 "pc_recurrtype, pc_duration, pc_end_all_day " .
1054 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
1055 $catoptions = "";
1056 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
1057 $thisduration = 0;
1058 if ($eid) {
1059 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
1062 while ($crow = sqlFetchArray($cres)) {
1063 $duration = round($crow['pc_duration'] / 60);
1064 if ($crow['pc_end_all_day']) {
1065 $duration = 1440;
1068 // This section is to build the list of preferred categories:
1069 if ($duration) {
1070 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
1071 if ($eid) {
1072 if ($crow['pc_catid'] == $row['pc_prefcatid']) {
1073 $prefcat_options .= " selected";
1077 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
1080 if ($crow['pc_cattype'] != $cattype) {
1081 continue;
1084 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
1085 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
1086 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
1087 if ($eid) {
1088 if ($crow['pc_catid'] == $row['pc_catid']) {
1089 $catoptions .= " selected";
1091 } else {
1092 if ($crow['pc_catid'] == $default_catid) {
1093 $catoptions .= " selected";
1094 $thisduration = $duration;
1098 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
1102 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
1104 // This is for callback by the find-patient popup.
1105 function setpatient(pid, lname, fname, dob) {
1106 var f = document.forms[0];
1107 f.form_patient.value = lname + ', ' + fname;
1108 f.form_pid.value = pid;
1109 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
1110 document.getElementById('dob_row').style.display = dobstyle;
1113 // This invokes the find-patient popup.
1114 function sel_patient() {
1115 let title = '<?php echo xlt('Patient Search'); ?>';
1116 dlgopen('find_patient_popup.php', 'findPatient', 650, 300, '', title);
1119 // This is for callback by the find-group popup.
1120 function setgroup(gid, name, end_date) {
1121 var f = document.forms[0];
1122 f.form_group.value = name;
1123 f.form_gid.value = gid;
1124 if(f.form_enddate.value == ""){
1125 f.form_enddate.value = end_date;
1130 // This invokes the find-group popup.
1131 function sel_group() {
1132 top.restoreSession();
1133 let title = '<?php echo xlt('Group Search'); ?>';
1134 dlgopen('find_group_popup.php', '_blank', 650, 300, '', title);
1137 // Do whatever is needed when a new event category is selected.
1138 // For now this means changing the event title and duration.
1139 function set_display() {
1140 var f = document.forms[0];
1141 var s = f.form_category;
1142 if (s.selectedIndex >= 0) {
1143 var catid = s.options[s.selectedIndex].value;
1144 var style_apptstatus = document.getElementById('title_apptstatus').style;
1145 var style_prefcat = document.getElementById('title_prefcat').style;
1146 if (catid == '2') { // In Office
1147 style_apptstatus.display = 'none';
1148 style_prefcat.display = '';
1149 f.form_apptstatus.style.display = 'none';
1150 f.form_prefcat.style.display = '';
1151 } else {
1152 style_prefcat.display = 'none';
1153 style_apptstatus.display = '';
1154 f.form_prefcat.style.display = 'none';
1155 f.form_apptstatus.style.display = '';
1160 // Do whatever is needed when a new event category is selected.
1161 // For now this means changing the event title and duration.
1162 function set_category() {
1163 var f = document.forms[0];
1164 var s = f.form_category;
1165 if (s.selectedIndex >= 0) {
1166 var catid = s.options[s.selectedIndex].value;
1167 f.form_title.value = s.options[s.selectedIndex].text;
1168 f.form_duration.value = durations[catid];
1169 set_display();
1173 // Modify some visual attributes when the all-day or timed-event
1174 // radio buttons are clicked.
1175 function set_allday() {
1176 var f = document.forms[0];
1177 var color1 = '#777777';
1178 var color2 = '#777777';
1179 var disabled2 = true;
1180 if (document.getElementById('rballday1').checked) {
1181 color1 = '#000000';
1183 if (document.getElementById('rballday2').checked) {
1184 color2 = '#000000';
1185 disabled2 = false;
1187 document.getElementById('tdallday1').style.color = color1;
1188 document.getElementById('tdallday2').style.color = color2;
1189 document.getElementById('tdallday3').style.color = color2;
1190 document.getElementById('tdallday4').style.color = color2;
1191 document.getElementById('tdallday5').style.color = color2;
1192 f.form_hour.disabled = disabled2;
1193 f.form_minute.disabled = disabled2;
1194 f.form_ampm.disabled = disabled2;
1195 f.form_duration.disabled = disabled2;
1198 // Modify some visual attributes when the Repeat checkbox is clicked.
1199 function set_repeat() {
1200 var f = document.forms[0];
1201 var isdisabled = true;
1202 var mycolor = '#777777';
1203 var myvisibility = 'hidden';
1204 if (f.form_repeat.checked) {
1205 f.days_every_week.checked = false;
1206 document.getElementById("days_label").style.color = mycolor;
1207 var days = document.getElementById("days").getElementsByTagName('input');
1208 var labels = document.getElementById("days").getElementsByTagName('label');
1209 for(var i=0; i < days.length; i++){
1210 days[i].disabled = isdisabled;
1211 labels[i].style.color = mycolor;
1213 isdisabled = false;
1214 mycolor = '#000000';
1215 myvisibility = 'visible';
1217 f.form_repeat_type.disabled = isdisabled;
1218 f.form_repeat_freq.disabled = isdisabled;
1219 f.form_enddate.disabled = isdisabled;
1220 document.getElementById('tdrepeat1').style.color = mycolor;
1221 document.getElementById('tdrepeat2').style.color = mycolor;
1224 // Event when days_every_week is checked.
1225 function set_days_every_week() {
1226 var f = document.forms[0];
1227 if (f.days_every_week.checked) {
1228 //disable regular repeat
1229 f.form_repeat.checked = false;
1230 f.form_repeat_type.disabled = true;
1231 f.form_repeat_freq.disabled = true;
1232 document.getElementById('tdrepeat1').style.color = '#777777';
1234 //enable end_date setting
1235 document.getElementById('tdrepeat2').style.color = '#000000';
1236 f.form_enddate.disabled = false;
1238 var isdisabled = false;
1239 var mycolor = '#000000';
1240 var myvisibility = 'visible';
1242 else{
1243 var isdisabled = true;
1244 var mycolor = '#777777';
1245 var myvisibility = 'hidden';
1247 document.getElementById("days_label").style.color = mycolor;
1248 var days = document.getElementById("days").getElementsByTagName('input');
1249 var labels = document.getElementById("days").getElementsByTagName('label');
1250 for(var i=0; i < days.length; i++){
1251 days[i].disabled = isdisabled;
1252 labels[i].style.color = mycolor;
1255 //If no repetition is checked, disable end_date setting.
1256 if(!f.days_every_week.checked && !f.form_repeat.checked){
1257 //disable end_date setting
1258 document.getElementById('tdrepeat2').style.color = mycolor;
1259 f.form_enddate.disabled = isdisabled;
1265 // Constants used by dateChanged() function.
1266 var occurNames = new Array(
1267 '<?php echo xls("1st"); ?>',
1268 '<?php echo xls("2nd"); ?>',
1269 '<?php echo xls("3rd"); ?>',
1270 '<?php echo xls("4th"); ?>'
1273 var weekDays = new Array(
1274 '<?php echo xls("Sunday"); ?>',
1275 '<?php echo xls("Monday"); ?>',
1276 '<?php echo xls("Tuesday"); ?>',
1277 '<?php echo xls("Wednesday"); ?>',
1278 '<?php echo xls("Thursday"); ?>',
1279 '<?php echo xls("Friday"); ?>',
1280 '<?php echo xls("Saturday"); ?>'
1283 // Monitor start date changes to adjust repeat type options.
1284 function dateChanged() {
1285 var f = document.forms[0];
1286 if (!f.form_date.value) return;
1287 var d = new Date(DateToYYYYMMDD_js(f.form_date.value));
1288 var downame = weekDays[d.getUTCDay()];
1289 var nthtext = '';
1290 var occur = Math.floor((d.getUTCDate() - 1) / 7);
1291 if (occur < 4) { // 5th is not allowed
1292 nthtext = occurNames[occur] + ' ' + downame;
1294 var lasttext = '';
1295 var tmp = new Date(d.getUTCFullYear(), d.getUTCMonth() + 1, 0);
1296 if (tmp.getDate() - d.getUTCDate() < 7) { // Modified by epsdky 2016 (details in commit)
1297 // This is a last occurrence of the specified weekday in the month,
1298 // so permit that as an option.
1299 lasttext = '<?php echo xls("Last"); ?> ' + downame;
1301 var si = f.form_repeat_type.selectedIndex;
1302 var opts = f.form_repeat_type.options;
1303 opts.length = 5; // remove any nth and Last entries
1304 if (nthtext ) opts[opts.length] = new Option(nthtext , '5');
1305 if (lasttext) opts[opts.length] = new Option(lasttext, '6');
1306 if (si < opts.length) f.form_repeat_type.selectedIndex = si;
1307 else f.form_repeat_type.selectedIndex = 5; // Added by epsdky 2016 (details in commit)
1310 // This is for callback by the find-available popup.
1311 function setappt(year,mon,mday,hours,minutes) {
1312 var f = document.forms[0];
1313 <?php
1314 $currentDateFormat = $GLOBALS['date_display_format'];
1315 if ($currentDateFormat == 0) { ?>
1316 f.form_date.value = '' + year + '-' +
1317 ('' + (mon + 100)).substring(1) + '-' +
1318 ('' + (mday + 100)).substring(1);
1319 <?php } elseif ($currentDateFormat == 1) { ?>
1320 f.form_date.value = ('' + (mon + 100)).substring(1) + '/' +
1321 ('' + (mday + 100)).substring(1) + '/' +
1322 '' + year;
1323 <?php } elseif ($currentDateFormat == 2) { ?>
1324 f.form_date.value = ('' + (mday + 100)).substring(1) + '/' +
1325 ('' + (mon + 100)).substring(1) + '/' +
1326 '' + year;
1327 <?php } ?>
1328 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
1329 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
1330 f.form_minute.value = ('' + (minutes + 100)).substring(1);
1333 // Invoke the find-available popup.
1334 function find_available(extra) {
1335 top.restoreSession();
1336 // (CHEMED) Conditional value selection, because there is no <select> element
1337 // when making an appointment for a specific provider
1338 var s = document.forms[0].form_provider;
1339 var f = document.forms[0].facility;
1340 <?php if ($userid != 0) { ?>
1341 s = document.forms[0].form_provider.value;
1342 f = document.forms[0].facility.value;
1343 <?php } else {?>
1344 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1345 f = document.forms[0].facility.options[f.selectedIndex].value;
1346 <?php }?>
1347 var c = document.forms[0].form_category;
1348 var formDate = document.forms[0].form_date;
1349 let title = '<?php echo xlt('Available Appointments Calendar'); ?>';
1350 dlgopen('<?php echo $GLOBALS['web_root']; ?>/interface/main/calendar/find_appt_popup.php' +
1351 '?providerid=' + s +
1352 '&catid=' + c.options[c.selectedIndex].value +
1353 '&facility=' + f +
1354 '&startdate=' + formDate.value +
1355 '&evdur=' + document.forms[0].form_duration.value +
1356 '&eid=<?php echo 0 + $eid; ?>' + extra,
1357 '', 725, 200, '', title);
1360 </script>
1362 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1364 </head>
1366 <body class="body_top main-calendar-add_edit_event">
1367 <div class="container-responsive">
1368 <form class="form-inline" method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1369 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1370 <input type='hidden' size='2' name='resname' value='empty' />
1371 <?php
1372 if ($_POST["resname"]=="noresult") {
1373 echo '
1374 <script language="Javascript">
1375 // refresh and redirect the parent window
1376 if (!opener.closed && opener.refreshme) opener.refreshme();
1377 top.restoreSession();
1378 opener.document.location="../../new/new.php";
1379 // Close the window
1380 dlgclose();
1381 </script>';
1384 $classprov='current';
1385 $classpati='';
1387 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1388 <input type="hidden" name="form_action" id="form_action" value="">
1389 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1390 <!-- used for recurring events -->
1391 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo attr($date); ?>">
1392 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo attr($eventstartdate); ?>">
1393 <!-- Following added by epsdky 2016 (details in commit) -->
1394 <input type="hidden" name="old_repeats" id="old_repeats" value="<?php echo attr($repeats); ?>">
1395 <input type="hidden" name="rt2_flag2" id="rt2_flag2" value="<?php echo attr(isset($rspecs['rt2_pf_flag']) ? $rspecs['rt2_pf_flag'] : '0'); ?>">
1396 <!-- End of addition by epsdky -->
1397 <center>
1398 <table class="table table-condensed" border='0' >
1399 <?php
1400 $provider_class='';
1401 $group_class='';
1402 $normal='';
1403 if ($_GET['prov']==true) {
1404 $provider_class="class='current'";
1405 } elseif ($_GET['group']==true) {
1406 $group_class="class='current'";
1407 } else {
1408 $normal="class='current'";
1411 <tr><th><ul class="tabNav">
1412 <?php
1413 $eid=$_REQUEST["eid"];
1414 $startm=$_REQUEST["startampm"];
1415 $starth=$_REQUEST["starttimeh"];
1416 $uid=$_REQUEST["userid"];
1417 $starttm=$_REQUEST["starttimem"];
1418 $dt=$_REQUEST["date"];
1419 $cid=$_REQUEST["catid"];
1421 <li <?php echo $normal;?>>
1422 <a href='add_edit_event.php?startampm=<?php echo attr($startm);?>&starttimeh=<?php echo attr($starth);?>&userid=<?php echo attr($uid);?>&starttimem=<?php echo attr($starttm);?>&date=<?php echo attr($dt);?>&catid=<?php echo attr($cid);?>'>
1423 <?php echo xlt('Patient');?></a>
1424 </li>
1425 <li <?php echo $provider_class;?>>
1426 <a href='add_edit_event.php?prov=true&startampm=<?php echo attr($startm);?>&starttimeh=<?php echo attr($starth);?>&userid=<?php echo attr($uid);?>&starttimem=<?php echo attr($starttm);?>&date=<?php echo attr($dt);?>&catid=<?php echo attr($cid);?>'>
1427 <?php echo xlt('Provider');?></a>
1428 </li>
1429 <?php if ($have_group_global_enabled) :?>
1430 <li <?php echo $group_class ;?>>
1431 <a href='add_edit_event.php?group=true&startampm=<?php echo attr($startm);?>&starttimeh=<?php echo attr($starth);?>&userid=<?php echo attr($uid);?>&starttimem=<?php echo attr($starttm);?>&date=<?php echo attr($dt);?>&catid=<?php echo attr($cid);?>'>
1432 <?php echo xlt('Group');?></a>
1433 </li>
1434 <?php endif ?>
1435 </ul>
1436 </th></tr>
1437 <tr><td colspan='10'>
1438 <table class="table table-condensed" border='0' width='100%' bgcolor='#DDDDDD'>
1439 <tr>
1440 <td width='1%' nowrap>
1441 <b><?php echo xlt('Category'); ?>:</b>
1442 </td>
1443 <td nowrap>
1444 <select class='input-sm' name='form_category' onchange='set_category()' style='width:100%'>
1445 <?php echo $catoptions ?>
1446 </select>
1447 </td>
1448 <td width='1%' nowrap>
1449 &nbsp;&nbsp;
1450 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'<?php echo ($thisduration == 1440) ? " checked" : ""; ?>/>
1451 </td>
1452 <td colspan='2' nowrap id='tdallday1'>
1453 <?php echo xlt('All day event'); ?>
1454 </td>
1455 </tr>
1456 <tr>
1457 <td nowrap>
1458 <b><?php echo xlt('Date'); ?>:</b>
1459 </td>
1460 <td nowrap>
1461 <input type='text' size='10' class='datepicker input-sm' name='form_date' id='form_date'
1462 value='<?php echo attr(oeFormatShortDate($date)) ?>'
1463 title='<?php echo xla('event date or starting date'); ?>'
1464 onchange='dateChanged()' />
1465 </td>
1466 <td nowrap>
1467 &nbsp;&nbsp;
1468 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2'<?php echo ($thisduration != 1440) ? " checked " : ""; ?>/>
1469 </td>
1470 <td width='1%' nowrap id='tdallday2'>
1471 <?php echo xlt('Time'); ?>
1472 </td>
1473 <td width='1%' nowrap id='tdallday3'>
1474 <span>
1475 <input class='input-sm' type='text' size='2' name='form_hour' value='<?php echo attr($starttimeh) ?>'
1476 title='<?php echo xla('Event start time'); ?>' /> :
1477 <input class='input-sm' type='text' size='2' name='form_minute' value='<?php echo attr($starttimem) ?>'
1478 title='<?php echo xla('Event start time'); ?>' />&nbsp;
1479 </span>
1480 <select class='input-sm' name='form_ampm' title='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1481 <option value='1'><?php echo xlt('AM'); ?></option>
1482 <option value='2'<?php echo ($startampm == '2') ? " selected" : ""; ?>><?php echo xlt('PM'); ?></option>
1483 </select>
1484 </td>
1485 </tr>
1486 <tr>
1487 <td nowrap>
1488 <b><?php echo xlt('Title'); ?>:</b>
1489 </td>
1490 <td nowrap>
1491 <input class="input-sm" type='text' size='10' name='form_title' value='<?php echo attr($row['pc_title']); ?>'
1492 style='width:100%'
1493 title='<?php echo xla('Event title'); ?>' />
1494 </td>
1495 <td nowrap>&nbsp;
1497 </td>
1498 <td nowrap id='tdallday4'><?php echo xlt('duration'); ?>
1499 </td>
1500 <td nowrap id='tdallday5'>
1501 <input class='input-sm' type='text' size='4' name='form_duration' value='<?php echo attr($thisduration) ?>' title='<?php echo xla('Event duration in minutes'); ?>' />
1502 <?php echo xlt('minutes'); ?>
1503 </td>
1504 </tr>
1506 <tr>
1507 <td nowrap><b><?php echo xlt('Facility'); ?>:</b></td>
1508 <td>
1509 <select class="input-sm" name="facility" id="facility" >
1510 <?php
1512 // ===========================
1513 // EVENTS TO FACILITIES
1514 //(CHEMED) added service_location WHERE clause
1515 // get the facilities
1516 /***************************************************************
1517 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1518 ***************************************************************/
1519 $facils = getUserFacilities($_SESSION['authId']);
1520 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1521 /**************************************************************/
1522 while ($facrow = sqlFetchArray($qsql)) {
1523 /*************************************************************
1524 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1525 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1526 *************************************************************/
1527 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1528 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1529 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1530 } else {
1531 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1532 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1535 /************************************************************/
1538 // EOS E2F
1539 // ===========================
1541 <?php
1542 //END (CHEMED) IF ?>
1543 </td>
1544 </select>
1545 </tr>
1546 <tr>
1547 <td nowrap>
1548 <b><?php echo xlt('Billing Facility'); ?>:</b>
1549 </td>
1550 <td>
1551 <?php
1552 billing_facility('billing_facility', $row['pc_billing_location']);
1554 </td>
1555 </tr>
1556 <?php
1557 if ($_GET['prov']!=true && $_GET['group']!=true) {
1559 <tr id="patient_details">
1560 <td nowrap>
1561 <b><?php echo xlt('Patient'); ?>:</b>
1562 </td>
1563 <td nowrap>
1564 <input class='input-sm' type='text' size='10' name='form_patient' id="form_patient" style='width:100%;cursor:pointer;cursor:hand' placeholder='<?php echo xla('Click to select');?>' value='<?php echo is_null($patientname) ? '' : attr($patientname); ?>' onclick='sel_patient()' title='<?php echo xla('Click to select patient'); ?>' readonly />
1565 <input class='input-sm' type='hidden' name='form_pid' value='<?php echo attr($patientid) ?>' />
1566 </td>
1567 <td colspan='3' nowrap style='font-size:8pt'>
1568 <span class="infobox">
1569 <?php
1570 foreach ($patienttitle as $value) {
1571 if ($value != "") {
1572 echo text(trim($value));
1575 if (count($patienttitle) > 1) {
1576 echo "<br />";
1580 </span>
1581 </td>
1582 </tr>
1583 <?php
1586 <?php
1587 if ($_GET['group']==true && $have_group_global_enabled) {
1589 <tr id="group_details">
1590 <td nowrap>
1591 <b><?php echo xlt('Group'); ?>:</b>
1592 </td>
1593 <td nowrap>
1594 <input class='input-sm' type='text' size='10' name='form_group' id="form_group" style='width:100%;cursor:pointer;cursor:hand' placeholder='<?php echo xla('Click to select');?>' value='<?php echo is_null($groupname) ? '' : attr($groupname); ?>' onclick='sel_group()' title='<?php echo xla('Click to select group'); ?>' readonly />
1595 <input class='input-sm' type='hidden' name='form_gid' value='<?php echo attr($groupid) ?>' />
1596 </td>
1597 <td colspan='3' nowrap style='font-size:8pt'>
1598 <span class="infobox">
1599 <?php
1600 foreach ($patienttitle as $value) {
1601 if ($value != "") {
1602 echo trim($value);
1605 if (count($patienttitle) > 1) {
1606 echo "<br />";
1610 </span>
1611 </td>
1612 </tr>
1613 <?php
1616 <tr>
1617 <td nowrap>
1619 <?php if ($_GET['group']==true) {
1620 echo xlt('Coordinating Counselors');
1621 } else {
1622 echo xlt('Provider');
1623 } ?>:</b>
1624 </td>
1625 <td nowrap>
1627 <?php
1629 // =======================================
1630 // multi providers
1631 // =======================================
1632 if ($GLOBALS['select_multi_providers']) {
1633 // there are two posible situations: edit and new record
1634 $providers_array = array();
1635 // this is executed only on edit ($eid)
1636 if ($eid) {
1637 if ($multiple_value) {
1638 // find all the providers around multiple key
1639 $qall = sqlStatement("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value));
1640 while ($r = sqlFetchArray($qall)) {
1641 $providers_array[] = $r['providers'];
1643 } else {
1644 $qall = sqlStatement("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
1645 $providers_array = sqlFetchArray($qall);
1649 // build the selection tool
1650 echo "<select class='input-sm' name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1652 while ($urow = sqlFetchArray($ures)) {
1653 echo " <option value='" . attr($urow['id']) . "'";
1655 if ($userid) {
1656 if (in_array($urow['id'], $providers_array) || ($urow['id'] == $userid)) {
1657 echo " selected";
1661 echo ">" . text($urow['lname']);
1662 if ($urow['fname']) {
1663 echo ", " . text($urow['fname']);
1666 echo "</option>\n";
1669 echo '</select>';
1671 // =======================================
1672 // single provider
1673 // =======================================
1674 } else {
1675 if ($eid) {
1676 // get provider from existing event
1677 $qprov = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
1678 $provider = sqlFetchArray($qprov);
1679 $defaultProvider = $provider['pc_aid'];
1680 } else {
1681 // this is a new event so smartly choose a default provider
1682 /*****************************************************************
1683 if ($userid) {
1684 // Provider already given to us as a GET parameter.
1685 $defaultProvider = $userid;
1687 else {
1688 // default to the currently logged-in user
1689 $defaultProvider = $_SESSION['authUserID'];
1690 // or, if we have chosen a provider in the calendar, default to them
1691 // choose the first one if multiple have been selected
1692 if (count($_SESSION['pc_username']) >= 1) {
1693 // get the numeric ID of the first provider in the array
1694 $pc_username = $_SESSION['pc_username'];
1695 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1696 $defaultProvider = $firstProvider['id'];
1701 echo "<select name='form_provider' style='width:100%' />";
1702 while ($urow = sqlFetchArray($ures)) {
1703 echo " <option value='" . $urow['id'] . "'";
1704 if ($urow['id'] == $defaultProvider) echo " selected";
1705 echo ">" . $urow['lname'];
1706 if ($urow['fname']) echo ", " . $urow['fname'];
1707 echo "</option>\n";
1709 echo "</select>";
1710 *****************************************************************/
1711 // default to the currently logged-in user
1712 $defaultProvider = $_SESSION['authUserID'];
1713 // or, if we have chosen a provider in the calendar, default to them
1714 // choose the first one if multiple have been selected
1715 if (count($_SESSION['pc_username']) >= 1) {
1716 // get the numeric ID of the first provider in the array
1717 $pc_username = $_SESSION['pc_username'];
1718 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0])));
1719 $defaultProvider = $firstProvider['id'];
1722 // if we clicked on a provider's schedule to add the event, use THAT.
1723 if ($userid) {
1724 $defaultProvider = $userid;
1728 echo "<select class='input-sm' name='form_provider' style='width:100%' />";
1729 while ($urow = sqlFetchArray($ures)) {
1730 echo " <option value='" . attr($urow['id']) . "'";
1731 if ($urow['id'] == $defaultProvider) {
1732 echo " selected";
1735 echo ">" . text($urow['lname']);
1736 if ($urow['fname']) {
1737 echo ", " . text($urow['fname']);
1740 echo "</option>\n";
1743 echo "</select>";
1744 /****************************************************************/
1749 </td>
1750 <td nowrap>
1751 &nbsp;&nbsp;
1752 <?php
1753 //Check if repeat is using the new 'days every week' mechanism.
1754 function isDaysEveryWeek($repeat)
1756 if ($repeat == 3) {
1757 return true;
1758 } else {
1759 return false;
1763 //Check if using the regular repeat mechanism.
1764 function isRegularRepeat($repeat)
1766 if ($repeat == 1 || $repeat == 2) {
1767 return true;
1768 } else {
1769 return false;
1775 If the appointment was set with the regular (old) repeat mechanism (using 'every', 'every 2', etc.), then will be
1776 checked when editing and will select the proper recurrence pattern. If using the new repeat mechanism, then only that box (and the proper set
1777 days) will be checked. That's why I had to add the functions 'isRegularRepeat' and 'isDaysEveryWeek', to check which
1778 repeating mechanism is being used, and load settings accordingly.
1781 <input type='checkbox' name='form_repeat' id="form_repeat" onclick='set_repeat(this)' value='1'<?php echo (isRegularRepeat($repeats)) ? " checked" : "";?>/>
1782 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat -->
1783 </td>
1784 <td nowrap id='tdrepeat1'><?php echo xlt('Repeats'); ?>
1785 </td>
1786 <td nowrap>
1788 <select class='input-sm' name='form_repeat_freq' title='<?php echo xla('Every, every other, every 3rd, etc.'); ?>'>
1789 <?php
1790 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1791 as $key => $value) {
1792 echo " <option value='" . attr($key) . "'";
1793 if ($key == $repeatfreq && isRegularRepeat($repeats)) {
1794 echo " selected";
1797 echo ">" . text($value) . "</option>\n";
1800 </select>
1802 <select class='input-sm' name='form_repeat_type'>
1803 <?php
1804 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1805 // when the start date is set.
1806 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1807 5 => '?', 6 => '?') as $key => $value) {
1808 echo " <option value='" . attr($key) . "'";
1809 if ($key == $repeattype && isRegularRepeat($repeats)) {
1810 echo " selected";
1813 echo ">" . text($value) . "</option>\n";
1816 </select>
1818 </td>
1819 </tr>
1821 <style>
1822 #days_every_week_row input[type="checkbox"]{float:right;}
1823 #days_every_week_row div{display: inline-block; text-align: center; width: 12%;}
1824 #days_every_week_row div input{width: 100%;}
1825 </style>
1827 <tr id="days_every_week_row">
1828 <td></td>
1829 <td></td>
1830 <td><input type='checkbox' id='days_every_week' name='days_every_week' onclick='set_days_every_week()' <?php echo (isDaysEveryWeek($repeats)) ? " checked" : ""; ?>/></td>
1831 <td id="days_label"><?php echo xlt('Days Of Week') . ": "; ?></td>
1832 <td id="days">
1833 <?php
1834 foreach (array(1 => xl('Su{{Sunday}}') , 2 => xl('Mo{{Monday}}'), 3 => xl('Tu{{Tuesday}}'), 4 => xl('We{{Wednesday}}'),
1835 5 => xl('Th{{Thursday}}'), 6 => xl('Fr{{Friday}}'), 7 => xl('Sa{{Saturday}}')) as $key => $value) {
1836 echo " <div><input type='checkbox' name='day_". attr($key) ."'";
1837 //Checks appropriate days according to days in recurrence string.
1838 if (in_array($key, explode(',', $repeatfreq)) && isDaysEveryWeek($repeats)) {
1839 echo " checked";
1842 echo " /><label>" . text($value) . "</label></div>\n";
1845 </td>
1847 </tr>
1850 <tr>
1851 <td nowrap>
1852 <span id='title_apptstatus'><b><?php echo xlt('Status'); ?>:</b></span>
1853 <span id='title_prefcat' style='display:none'><b><?php echo xlt('Pref Cat'); ?>:</b></span>
1854 </td>
1855 <td nowrap>
1857 <?php
1858 if ($_GET['group']!=true) {
1859 generate_form_field(array('data_type' => 1, 'field_id' => 'apptstatus', 'list_id' => 'apptstat', 'empty_title' => 'SKIP'), $row['pc_apptstatus']);
1860 } else {
1861 generate_form_field(array('data_type' => 1, 'field_id' => 'apptstatus', 'list_id' => 'groupstat', 'empty_title' => 'SKIP'), $row['pc_apptstatus']);
1865 <!--
1866 The following list will be invisible unless this is an In Office
1867 event, in which case form_apptstatus (above) is to be invisible.
1869 <select class='input-sm' name='form_prefcat' style='width:100%;display:none' title='<?php echo xla('Preferred Event Category');?>'>
1870 <?php echo $prefcat_options ?>
1871 </select>
1873 </td>
1874 <td nowrap>&nbsp;
1876 </td>
1877 <td nowrap id='tdrepeat2'><?php echo xlt('until date'); ?>
1878 </td>
1879 <td nowrap>
1880 <input type='text' size='10' class='datepicker' name='form_enddate' id='form_enddate' value='<?php echo attr(oeFormatShortDate($recurrence_end_date)) ?>' title='<?php echo xla('last date of this event');?>' />
1881 <?php
1882 if ($repeatexdate != "") {
1883 $tmptitle = "The following dates are excluded from the repeating series";
1884 if ($multiple_value) {
1885 $tmptitle .= " for one or more providers:\n";
1886 } else {
1887 $tmptitle .= "\n";
1890 $max = $GLOBALS['number_of_ex_appts_to_show'];
1892 $exdates = explode(",", $repeatexdate);
1893 if (!empty($exdates)) {
1894 $exdates=array_slice($exdates, 0, $max, true);
1897 foreach ($exdates as $exdate) {
1898 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1901 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1904 </td>
1905 </tr>
1906 <?php
1907 if ($_GET['prov']!=true) {
1909 <tr>
1910 <td nowrap>
1911 <b><?php echo xlt('Room Number'); ?>:</b>
1912 </td>
1913 <td colspan='4' nowrap>
1914 <?php
1915 echo generate_select_list('form_room', 'patient_flow_board_rooms', $pcroom, xl('Room Number'));
1917 </td>
1918 </tr>
1919 <?php
1920 } ?>
1921 <tr>
1922 <td nowrap>
1923 <b><?php echo xlt('Comments'); ?>:</b>
1924 </td>
1925 <td colspan='4' nowrap>
1926 <input class='input-sm' type='text' size='40' name='form_comments' style='width:100%' value='<?php echo attr($hometext); ?>' title='<?php echo xla('Optional information about this event');?>' />
1927 </td>
1928 </tr>
1931 <?php
1932 // DOB is important for the clinic, so if it's missing give them a chance
1933 // to enter it right here. We must display or hide this row dynamically
1934 // in case the patient-select popup is used.
1935 $patient_dob = trim($prow['DOB']);
1936 $is_group = $groupname;
1937 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00') && !$is_group) ?
1938 '' : 'none';
1940 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1941 <td colspan='4' nowrap>
1942 <b><font color='red'><?php echo xlt('DOB is missing, please enter if possible'); ?>:</font></b>
1943 </td>
1944 <td nowrap>
1945 <input type='text' size='10' class='datepicker' name='form_dob' id='form_dob' title='<?php echo xla('yyyy-mm-dd date of birth');?>' />
1946 </td>
1947 </tr>
1949 </table></td></tr>
1951 <tr class='text'><td colspan='10' class="buttonbar">
1953 <input type='button' name='form_save' id='form_save' value='<?php echo xla('Save');?>' />
1954 &nbsp;
1956 <?php if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1957 <input type='button' id='find_available' value='<?php echo xla('Find Available');?>' />
1958 <?php } ?>
1960 &nbsp;
1961 <input type='button' name='form_delete' id='form_delete' value='<?php echo xla('Delete');?>'<?php echo (!$eid) ? " disabled" : "";?> />
1962 &nbsp;
1963 <input type='button' id='cancel' value='<?php echo xla('Cancel');?>' />
1964 &nbsp;
1965 <input type='button' name='form_duplicate' id='form_duplicate' value='<?php echo xla('Create Duplicate');?>' />
1966 </p></td></tr></table>
1967 <?php if ($informant) {
1968 echo "<p class='text'>" . xlt('Last update by') . " " .
1969 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n";
1970 } ?>
1971 </center>
1972 </form>
1974 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1975 <?php echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?>
1976 <br>
1977 <?php if ($GLOBALS['submit_changes_for_all_appts_at_once']) {?>
1978 <input type="button" name="all_events" id="all_events" value=" <?php echo xla('All'); ?> ">
1979 <?php } ?>
1980 <input type="button" name="recurr_cancel" id="recurr_cancel" value="<?php echo xla('Cancel'); ?>">
1981 <input type="button" name="future_events" id="future_events" value="<?php echo xla('Future'); ?>">
1982 <input type="button" name="current_event" id="current_event" value="<?php echo xla('Current'); ?>">
1983 </div>
1984 </div>
1985 </body>
1987 <script language='JavaScript'>
1988 <?php if ($eid) { ?>
1989 set_display();
1990 <?php } else { ?>
1991 set_category();
1992 <?php } ?>
1993 set_allday();
1994 set_repeat();
1995 set_days_every_week();
1997 </script>
1999 <script language="javascript">
2000 // jQuery stuff to make the page a little easier to use
2002 $(document).ready(function(){
2003 $("#form_save").click(function(e) { validateform(e,"save"); });
2004 $("#form_duplicate").click(function(e) { validateform(e,"duplicate"); });
2005 $("#find_available").click(function() { find_available(''); });
2006 $("#form_delete").click(function() { deleteEvent(); });
2007 $("#cancel").click(function() { dlgclose(); });
2009 // buttons affecting the modification of a repeating event
2010 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
2011 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
2012 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
2013 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
2015 // Initialize repeat options.
2016 dateChanged();
2018 $('.datepicker').datetimepicker({
2019 <?php $datetimepicker_timepicker = false; ?>
2020 <?php $datetimepicker_showseconds = false; ?>
2021 <?php $datetimepicker_formatInput = true; ?>
2022 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
2023 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
2028 function are_days_checked(){
2029 var days = document.getElementById("days").getElementsByTagName('input');
2030 var counter = 0;
2031 for(var i=0; i < days.length; i++){
2032 if(days[i].checked){
2033 counter++;
2036 return counter;
2040 * validation on the form with new client side validation (using validate.js).
2041 * this enable to add new rules for this form in the pageValidation list.
2042 * */
2043 var collectvalidation = <?php echo($collectthis); ?>;
2044 function validateform(event,valu){
2046 $('#form_save').attr('disabled', true);
2048 //Make sure if days_every_week is checked that at least one weekday is checked.
2049 if($('#days_every_week').is(':checked') && !are_days_checked()){
2050 alert('<?php echo xls("Must choose at least one day!"); ?>');
2051 $('#form_save').attr('disabled', false);
2052 return false;
2055 <?php if (!$GLOBALS['allow_early_check_in']) { ?>
2056 //Prevent from user to change status to Arrive before the time
2057 //Dependent in globals setting - allow_early_check_in
2058 if($('#form_apptstatus').val() == '@' && new Date(DateToYYYYMMDD_js($('#form_date').val())).getTime() > new Date().getTime()){
2059 alert('<?php echo xls("You can not change status to 'Arrive' before the appointment's time") .'.'; ?>');
2060 $('#form_save').attr('disabled', false);
2061 return false;
2063 <?php } ?>
2065 //add rule if choose repeating event
2066 if ($('#form_repeat').is(':checked') || $('#days_every_week').is(':checked')){
2068 var format = '<?php echo DateFormatRead('validateJS'); ?>';
2070 collectvalidation.form_enddate = {
2071 datetime: {
2072 dateOnly: true,
2073 earliest: $('#form_date').val(),
2074 format: format,
2075 message: "An end date later than the start date is required for repeated events!"
2077 presence: true
2079 } else {
2080 if(typeof (collectvalidation) != 'undefined'){
2081 delete collectvalidation.form_enddate;
2086 <?php
2087 if ($GLOBALS['select_multi_providers']) {
2089 //If multiple providers is enabled, create provider validation (Note: if no provider is chosen it causes bugs when deleting recurrent events).
2090 if(typeof (collectvalidation) == 'undefined'){
2091 collectvalidation = {form_provider:{presence: true}};
2093 else{
2094 collectvalidation.form_provider = {presence: true};
2096 <?php
2101 var submit = submitme(1, event, 'theform', collectvalidation);
2102 if(!submit)return $('#form_save').attr('disabled', false);
2104 $('#form_action').val(valu);
2106 <?php if ($repeats) : ?>
2107 // existing repeating events need additional prompt
2108 if ($("#recurr_affect").val() == "") {
2109 DisableForm();
2110 // show the current/future/all DIV for the user to choose one
2111 $("#recurr_popup").css("visibility", "visible");
2112 $('#form_save').attr('disabled', false);
2113 return false;
2115 <?php endif; ?>
2117 SubmitForm();
2121 // disable all the form elements outside the recurr_popup
2122 function DisableForm() {
2123 $("#theform").children().attr("disabled", "true");
2125 function EnableForm() {
2126 $("#theform").children().removeAttr("disabled");
2128 // hide the recurring popup DIV
2129 function HideRecurrPopup() {
2130 $("#recurr_popup").css("visibility", "hidden");
2133 function deleteEvent() {
2134 if (confirm("<?php echo addslashes(xl('Deleting this event cannot be undone. It cannot be recovered once it is gone. Are you sure you wish to delete this event?')); ?>")) {
2135 $('#form_action').val("delete");
2137 <?php if ($repeats) : ?>
2138 // existing repeating events need additional prompt
2139 if ($("#recurr_affect").val() == "") {
2140 DisableForm();
2141 // show the current/future/all DIV for the user to choose one
2142 $("#recurr_popup").css("visibility", "visible");
2143 return false;
2145 <?php endif; ?>
2147 return SubmitForm();
2149 return false;
2152 function SubmitForm() {
2153 var f = document.forms[0];
2154 <?php if (!($GLOBALS['select_multi_providers']) && !$_GET['prov']) { // multi providers appt is not supported by check slot avail window, so skip. && is not provider tab. ?>
2155 if (f.form_action.value != 'delete') {
2156 // Check slot availability.
2157 var mins = parseInt(f.form_hour.value) * 60 + parseInt(f.form_minute.value);
2158 if (f.form_ampm.value == '2' && mins < 720) mins += 720;
2159 find_available('&cktime=' + mins);
2161 else {
2162 top.restoreSession();
2163 f.submit();
2165 <?php } else { ?>
2166 <?php
2167 /*Support Multi-Provider Events in features*/
2168 $sdate=$date;
2169 $edate=new DateTime($date);
2170 $edate->modify('tomorrow');
2171 $edate=$edate->format('Y-m-d');
2172 $is_holiday=false;
2173 $holidays_controller = new Holidays_Controller();
2174 $holidays = $holidays_controller->get_holidays_by_date_range($sdate, $edate);
2175 if (in_array($sdate, $holidays)) {
2176 $is_holiday=true;
2178 if (f.form_action.value != 'delete') {
2179 <?php if ($is_holiday) {?>
2180 if (!confirm('<?php echo xls('On this date there is a holiday, use it anyway?'); ?>')) {
2181 top.restoreSession();
2183 <?php }?>
2185 top.restoreSession();
2186 f.submit();
2187 <?php } ?>
2189 return true;
2192 </script>
2194 </html>