3 * Add or edit an event in the calendar.
5 * Can be displayed as a popup window, or as an iframe via
9 * The event editor looks something like this:
11 * //------------------------------------------------------------//
12 * // Category __________________V O All day event //
13 * // Date _____________ [?] O Time ___:___ __V //
14 * // Title ___________________ duration ____ minutes //
15 * // Patient _(Click_to_select)_ //
16 * // Provider __________________V X Repeats ______V ______V //
17 * // Status __________________V until __________ [?] //
18 * // Comments ________________________________________________ //
20 * // [Save] [Find Available] [Delete] [Cancel] //
21 * //------------------------------------------------------------//
24 * Copyright (C) 2005-2013 Rod Roark <rod@sunsetsystems.com>
25 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
27 * LICENSE: This program is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU General Public License
29 * as published by the Free Software Foundation; either version 3
30 * of the License, or (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
39 * @author Rod Roark <rod@sunsetsystems.com>
40 * @author Brady Miller <brady.g.miller@gmail.com>
41 * @link http://www.open-emr.org
45 $fake_register_globals=false;
46 $sanitize_all_escapes=true;
48 require_once('../../globals.php');
49 require_once($GLOBALS['srcdir'].'/patient.inc');
50 require_once($GLOBALS['srcdir'].'/forms.inc');
51 require_once($GLOBALS['srcdir'].'/calendar.inc');
52 require_once($GLOBALS['srcdir'].'/options.inc.php');
53 require_once($GLOBALS['srcdir'].'/encounter_events.inc.php');
54 require_once($GLOBALS['srcdir'].'/acl.inc');
55 require_once($GLOBALS['srcdir'].'/patient_tracker.inc.php');
56 require_once($GLOBALS['incdir']."/main/holidays/Holidays_Controller.php");
58 //Check access control
59 if (!acl_check('patients','appt','',array('write','wsome') ))
60 die(xl('Access not allowed'));
62 /* Things that might be passed by our opener. */
63 $eid = $_GET['eid']; // only for existing events
64 $date = $_GET['date']; // this and below only for new events
65 $userid = $_GET['userid'];
66 $default_catid = $_GET['catid'] ?
$_GET['catid'] : '5';
69 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
71 $date = date("Y-m-d");
74 if (isset($_GET['starttimem']))
75 $starttimem = substr('00' . $_GET['starttimem'], -2);
77 if (isset($_GET['starttimeh'])) {
78 $starttimeh = $_GET['starttimeh'];
79 if (isset($_GET['startampm'])) {
80 if ($_GET['startampm'] == '2' && $starttimeh < 12)
84 $starttimeh = date("G");
91 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js?v=<?php echo $v_js_includes; ?>"></script
>
92 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative'] ?>/jquery-min-3-1-1/index.js"></script
>
94 <!-- validation library
-->
95 <!--//Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation-->
96 <?php
$use_validate_js = 1;?
>
97 <?php
require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?
>
99 //Gets validation rules from Page Validation list.
100 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
101 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php");
102 if (empty($collectthis)) {
103 $collectthis = "undefined";
106 $collectthis = $collectthis["theform"]["rules"];
112 function InsertEventFull()
114 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
115 // =======================================
116 // multi providers case
117 // =======================================
118 if (is_array($_POST['form_provider'])) {
120 // obtain the next available unique key to group multiple providers around some event
121 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
122 $max = sqlFetchArray($q);
123 $new_multiple_value = $max['max'] +
1;
125 foreach ($_POST['form_provider'] as $provider) {
127 // specify some special variables needed for the INSERT
128 $args['new_multiple_value'] = $new_multiple_value;
129 $args['form_provider'] = $provider;
130 $args['event_date'] = $event_date;
131 $args['duration'] = $duration * 60;
132 $args['recurrspec'] = $recurrspec;
133 $args['starttime'] = $starttime;
134 $args['endtime'] = $endtime;
135 $args['locationspec'] = $locationspec;
139 // ====================================
141 // ====================================
144 // specify some special variables needed for the INSERT
145 $args['new_multiple_value'] = "";
146 $args['event_date'] = $event_date;
147 $args['duration'] = $duration * 60;
148 $args['recurrspec'] = $recurrspec;
149 $args['starttime'] = $starttime;
150 $args['endtime'] = $endtime;
151 $args['locationspec'] = $locationspec;
155 function DOBandEncounter()
157 global $event_date,$info_msg;
158 // Save new DOB if it's there.
159 $patient_dob = trim($_POST['form_dob']);
160 $tmph = $_POST['form_hour'] +
0;
161 $tmpm = $_POST['form_minute'] +
0;
162 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph +
= 12;
163 $appttime = "$tmph:$tmpm:00";
165 if ($patient_dob && $_POST['form_pid']) {
166 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
167 "pid = ?", array($patient_dob,$_POST['form_pid']) );
170 // Manage tracker status.
171 // And auto-create a new encounter if appropriate.
172 if (!empty($_POST['form_pid'])) {
173 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']))
175 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
177 $info_msg .= xl("New encounter created with id");
178 $info_msg .= " $encounter";
180 # Capture the appt status and room number for patient tracker. This will map the encounter to it also.
181 if ( isset($GLOBALS['temporary-eid-for-manage-tracker']) ||
!empty($_GET['eid']) ) {
182 // Note that the temporary-eid-for-manage-tracker is used to capture the eid for new appointments and when separate a recurring
183 // appointment. It is set in the InsertEvent() function. Note that in the case of spearating a recurrent appointment, the get eid
184 // parameter is actually erroneous(is eid of the recurrent appt and not the new separated appt), so need to use the
185 // temporary-eid-for-manage-tracker global instead.
186 $temp_eid = (isset($GLOBALS['temporary-eid-for-manage-tracker'])) ?
$GLOBALS['temporary-eid-for-manage-tracker'] : $_GET['eid'];
187 manage_tracker_status($event_date,$appttime,$temp_eid,$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room'],$encounter);
192 # Capture the appt status and room number for patient tracker.
193 if (!empty($_GET['eid'])) {
194 manage_tracker_status($event_date,$appttime,$_GET['eid'],$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room']);
202 /*This function is used for setting the date of the first event when using the "day_every_week" repetition mechanism.
203 When the 'start date' is not one of the days chosen for the repetition, the start date needs to be changed to the first
204 occurrence of one of these set days. */
205 function setEventDate($start_date, $recurrence){
206 $timestamp = strtotime($start_date);
207 $day = date('w', $timestamp);
208 //If the 'start date' is one of the set days
209 if(in_array(($day+
1), explode(',',$recurrence))){
212 //else: (we need to change start date to first occurrence of one of the set days)
214 $new_date = getTheNextAppointment($start_date, $recurrence);
220 //================================================================================================================
222 // EVENTS TO FACILITIES (lemonsoftware)
223 //(CHEMED) get facility name
224 // edit event case - if there is no association made, then insert one with the first facility
227 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
228 FROM openemr_postcalendar_events
229 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
230 WHERE pc_eid = ?", array($eid) );
231 // if ( !$facility['pc_facility'] ) {
232 if ( is_array($facility) && !$facility['pc_facility'] ) {
233 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']) );
234 $min = $qmin['minId'];
235 $min_name = $qmin['facility'];
237 // multiple providers case
238 if ( $GLOBALS['select_multi_providers'] ) {
239 $mul = $facility['pc_multiple'];
240 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min,$mul) );
244 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min,$eid) );
246 $e2f_name = $min_name;
249 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
250 $e2f = $_SESSION['pc_facility'];
251 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
252 $e2f = $_COOKIE['pc_facility'];
254 $e2f = $facility['pc_facility'];
255 $e2f_name = $facility['name'];
260 // ===========================
261 //=============================================================================================================================
262 if ($_POST['form_action'] == "duplicate" ||
$_POST['form_action'] == "save")
265 // Compute start and end time strings to be saved.
266 if ($_POST['form_allday']) {
271 $tmph = $_POST['form_hour'] +
0;
272 $tmpm = $_POST['form_minute'] +
0;
273 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph +
= 12;
274 $duration = abs($_POST['form_duration']); // fixes #395
276 $starttime = "$tmph:$tmpm:00";
279 while ($tmpm >= 60) {
283 $endtime = "$tmph:$tmpm:00";
285 // Set up working variables related to repeated events.
287 $my_repeat_freq = 0 +
$_POST['form_repeat_freq'];
288 $my_repeat_type = 0 +
$_POST['form_repeat_type'];
289 $my_repeat_on_num = 1;
290 $my_repeat_on_day = 0;
291 $my_repeat_on_freq = 0;
293 // the starting date of the event, pay attention with this value
294 // when editing recurring events -- JRM Oct-08
295 $event_date = fixDate($_POST['form_date']);
297 //If used new recurrence mechanism of set days every week
298 if(!empty($_POST['days_every_week'])){
300 //loop through checkboxes and insert encounter days into array
301 $days_every_week_arr = array();
302 for($i=1; $i<=7; $i++
){
303 if(!empty($_POST['day_' . $i])){
304 array_push($days_every_week_arr, $i);
307 $my_repeat_freq = implode(",",$days_every_week_arr);
309 $event_date = fixDate(setEventDate($_POST['form_date'], $my_repeat_freq));
312 elseif (!empty($_POST['form_repeat'])){
315 if ($my_repeat_type > 4) {
317 $time = strtotime($event_date);
318 $my_repeat_on_day = 0 +
date('w', $time);
319 $my_repeat_on_freq = $my_repeat_freq;
320 if ($my_repeat_type == 5) {
321 $my_repeat_on_num = intval((date('j', $time) - 1) / 7) +
1;
323 // Last occurence of this weekday on the month
324 $my_repeat_on_num = 5;
326 // Maybe not needed, but for consistency with postcalendar:
333 // Useless garbage that we must save.
334 $locationspecs = array("event_location" => "",
335 "event_street1" => "",
336 "event_street2" => "",
341 $locationspec = serialize($locationspecs);
343 // capture the recurring specifications
344 $recurrspec = array("event_repeat_freq" => "$my_repeat_freq",
345 "event_repeat_freq_type" => "$my_repeat_type",
346 "event_repeat_on_num" => "$my_repeat_on_num",
347 "event_repeat_on_day" => "$my_repeat_on_day",
348 "event_repeat_on_freq" => "$my_repeat_on_freq",
349 "exdate" => $_POST['form_repeat_exdate']
353 if($my_recurrtype == 2) { // Added by epsdky 2016 (details in commit)
354 if($_POST['old_repeats'] == 2) {
355 if($_POST['rt2_flag2']) $recurrspec['rt2_pf_flag'] = "1";
356 } else $recurrspec['rt2_pf_flag'] = "1";
357 } // End of addition by epsdky
359 // no recurr specs, this is used for adding a new non-recurring event
360 $noRecurrspec = array("event_repeat_freq" => "",
361 "event_repeat_freq_type" => "",
362 "event_repeat_on_num" => "1",
363 "event_repeat_on_day" => "0",
364 "event_repeat_on_freq" => "0",
368 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
369 //=============================================================================================================================
370 if ($_POST['form_action'] == "duplicate") {
377 // If we are saving, then save and close the window.
379 if ($_POST['form_action'] == "save") {
380 /* =======================================================
382 * =====================================================*/
385 // what is multiple key around this $eid?
386 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
388 // ====================================
389 // multiple providers
390 // ====================================
391 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
393 // obtain current list of providers regarding the multiple key
394 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
395 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
397 // get the new list of providers from the submitted form
398 $providers_new = $_POST['form_provider'];
400 // ===== Only current event of repeating series =====
401 if ($_POST['recurr_affect'] == 'current') {
403 // update all existing event records to exlude the current date
404 foreach ($providers_current as $provider) {
405 // update the provider's original event
406 // get the original event's repeat specs
407 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
408 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
409 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
410 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
411 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
412 else { $oldRecurrspec['exdate'] .= $selected_date; }
414 // mod original event recur specs to exclude this date
415 sqlStatement("UPDATE openemr_postcalendar_events SET " .
416 " pc_recurrspec = ? ".
417 " WHERE pc_aid = ? AND pc_multiple=?", array(serialize($oldRecurrspec),$provider,$row['pc_multiple']) );
420 // obtain the next available unique key to group multiple providers around some event
421 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
422 $max = sqlFetchArray($q);
423 $new_multiple_value = $max['max'] +
1;
425 // insert a new event record for each provider selected on the form
426 foreach ($providers_new as $provider) {
427 // insert a new event on this date with POST form data
429 // specify some special variables needed for the INSERT
430 $args['new_multiple_value'] = $new_multiple_value;
431 $args['form_provider'] = $provider;
432 $args['event_date'] = $event_date;
433 $args['duration'] = $duration * 60;
434 // this event is forced to NOT REPEAT
435 $args['form_repeat'] = "0";
436 $args['days_every_week'] = "0";
437 $args['recurrspec'] = $noRecurrspec;
438 $args['form_enddate'] = "0000-00-00";
439 $args['starttime'] = $starttime;
440 $args['endtime'] = $endtime;
441 $args['locationspec'] = $locationspec;
446 // ===== Future Recurring events of a repeating series =====
447 else if ($_POST['recurr_affect'] == 'future') {
448 // update all existing event records to
449 // stop recurring on this date-1
450 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
451 foreach ($providers_current as $provider) {
452 // mod original event recur specs to end on this date
453 sqlStatement("UPDATE openemr_postcalendar_events SET " .
455 " WHERE pc_aid = ? AND pc_multiple=?", array($selected_date,$provider,$row['pc_multiple']) );
458 // obtain the next available unique key to group multiple providers around some event
459 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
460 $max = sqlFetchArray($q);
461 $new_multiple_value = $max['max'] +
1;
463 // insert a new event record for each provider selected on the form
464 foreach ($providers_new as $provider) {
465 // insert a new event on this date with POST form data
467 // specify some special variables needed for the INSERT
468 $args['new_multiple_value'] = $new_multiple_value;
469 $args['form_provider'] = $provider;
470 $args['event_date'] = $event_date;
471 $args['duration'] = $duration * 60;
472 $args['recurrspec'] = $recurrspec;
473 $args['starttime'] = $starttime;
474 $args['endtime'] = $endtime;
475 $args['locationspec'] = $locationspec;
481 /* =================================================================== */
482 // ===== a Single event or All events in a repeating series ==========
483 /* =================================================================== */
485 // this difference means that some providers from current was UNCHECKED
486 // so we must delete this event for them
487 $r1 = array_diff ($providers_current, $providers_new);
489 foreach ($r1 as $to_be_removed) {
490 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']) );
494 // perform a check to see if user changed event date
495 // this is important when editing an existing recurring event
497 if ($_POST['form_date'] == $_POST['selected_date']) {
498 // user has NOT changed the start date of the event (and not recurrtype 3)
499 if($my_recurrtype != 3) $event_date = fixDate($_POST['event_start_date']);
502 // this difference means that some providers were added
503 // so we must insert this event for them
504 $r2 = array_diff ($providers_new, $providers_current);
506 foreach ($r2 as $to_be_inserted) {
508 // specify some special variables needed for the INSERT
509 $args['new_multiple_value'] = $row['pc_multiple'];
510 $args['form_provider'] = $to_be_inserted;
511 $args['event_date'] = $event_date;
512 $args['duration'] = $duration * 60;
513 $args['recurrspec'] = $recurrspec;
514 $args['starttime'] = $starttime;
515 $args['endtime'] = $endtime;
516 $args['locationspec'] = $locationspec;
521 // after the two diffs above, we must update for remaining providers
522 // those who are intersected in $providers_current and $providers_new
523 foreach ($_POST['form_provider'] as $provider) {
524 sqlStatement("UPDATE openemr_postcalendar_events SET " .
525 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
526 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
527 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
528 "pc_time = NOW(), " .
529 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
530 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
531 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
532 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
533 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
534 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
535 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
536 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
537 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
538 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
539 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
540 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
541 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
542 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
543 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
544 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'");
548 // ====================================
550 // ====================================
551 } elseif ( !$row['pc_multiple'] ) {
552 if ( $GLOBALS['select_multi_providers'] ) {
553 $prov = $_POST['form_provider'][0];
555 $prov = $_POST['form_provider'];
558 if ($_POST['recurr_affect'] == 'current') {
559 // get the original event's repeat specs
560 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
561 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
562 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
563 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
564 else { $oldRecurrspec['exdate'] .= $selected_date; }
566 // mod original event recur specs to exclude this date
567 sqlStatement("UPDATE openemr_postcalendar_events SET " .
568 " pc_recurrspec = ? ".
569 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
571 // insert a new event on this date with POST form data
573 // specify some special variables needed for the INSERT
574 $args['event_date'] = $event_date;
575 $args['duration'] = $duration * 60;
576 // this event is forced to NOT REPEAT
577 $args['form_repeat'] = "0";
578 $args['days_every_week'] = "0";
579 $args['recurrspec'] = $noRecurrspec;
580 $args['form_enddate'] = "0000-00-00";
581 $args['starttime'] = $starttime;
582 $args['endtime'] = $endtime;
583 $args['locationspec'] = $locationspec;
586 else if ($_POST['recurr_affect'] == 'future') {
587 // mod original event to stop recurring on this date-1
588 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
589 sqlStatement("UPDATE openemr_postcalendar_events SET " .
591 " WHERE pc_eid = ?", array($selected_date,$eid) );
593 // insert a new event starting on this date with POST form data
595 // specify some special variables needed for the INSERT
596 $args['event_date'] = $event_date;
597 $args['duration'] = $duration * 60;
598 $args['recurrspec'] = $recurrspec;
599 $args['starttime'] = $starttime;
600 $args['endtime'] = $endtime;
601 $args['locationspec'] = $locationspec;
606 // perform a check to see if user changed event date
607 // this is important when editing an existing recurring event
609 if ($_POST['form_date'] == $_POST['selected_date']) {
610 // user has NOT changed the start date of the event (and not recurrtype 3)
611 if($my_recurrtype != 3) $event_date = fixDate($_POST['event_start_date']);
614 // mod the SINGLE event or ALL EVENTS in a repeating series
615 // simple provider case
616 sqlStatement("UPDATE openemr_postcalendar_events SET " .
617 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
618 "pc_aid = '" . add_escape_custom($prov) . "', " .
619 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
620 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
621 "pc_time = NOW(), " .
622 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
623 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
624 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
625 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
626 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
627 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
628 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
629 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
630 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
631 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
632 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
633 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
634 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
635 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
636 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
637 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
641 // =======================================
642 // end Update Multi providers case
643 // =======================================
645 // EVENTS TO FACILITIES
650 /* =======================================================
651 * INSERT NEW EVENT(S)
652 * ======================================================*/
658 // done with EVENT insert/update statements
664 // =======================================
666 // =======================================
667 else if ($_POST['form_action'] == "delete") {
668 // =======================================
669 // multi providers event
670 // =======================================
671 if ($GLOBALS['select_multi_providers']) {
673 // what is multiple key around this $eid?
674 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
676 // obtain current list of providers regarding the multiple key
677 $providers_current = array();
678 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
679 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
681 // establish a WHERE clause
682 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = '{$row['pc_multiple']}'"; }
683 else { $whereClause = "pc_eid = '$eid'"; }
685 if ($_POST['recurr_affect'] == 'current') {
686 // update all existing event records to exlude the current date
687 foreach ($providers_current as $provider) {
688 // update the provider's original event
689 // get the original event's repeat specs
690 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
691 " WHERE pc_aid <=> ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
692 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
693 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
694 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
695 else { $oldRecurrspec['exdate'] .= $selected_date; }
697 // mod original event recur specs to exclude this date
698 sqlStatement("UPDATE openemr_postcalendar_events SET " .
699 " pc_recurrspec = ? ".
700 " WHERE ". $whereClause, array(serialize($oldRecurrspec)) );
703 else if ($_POST['recurr_affect'] == 'future') {
704 // update all existing event records to stop recurring on this date-1
705 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
706 foreach ($providers_current as $provider) {
707 // update the provider's original event
708 sqlStatement("UPDATE openemr_postcalendar_events SET " .
710 " WHERE ".$whereClause, array($selected_date) );
714 // really delete the event from the database
715 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
719 // =======================================
720 // single provider event
721 // =======================================
724 if ($_POST['recurr_affect'] == 'current') {
725 // mod original event recur specs to exclude this date
727 // get the original event's repeat specs
728 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
729 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
730 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
731 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
732 else { $oldRecurrspec['exdate'] .= $selected_date; }
733 sqlStatement("UPDATE openemr_postcalendar_events SET " .
734 " pc_recurrspec = ? ".
735 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
738 else if ($_POST['recurr_affect'] == 'future') {
739 // mod original event to stop recurring on this date-1
740 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
741 sqlStatement("UPDATE openemr_postcalendar_events SET " .
743 " WHERE pc_eid = ?", array($selected_date,$eid) );
747 // fully delete the event from the database
748 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
753 if ($_POST['form_action'] != "") {
754 // Close this window and refresh the calendar (or the patient_tracker) display.
755 echo "<html>\n<body>\n<script language='JavaScript'>\n";
756 if ($info_msg) echo " alert('" . addslashes($info_msg) . "');\n";
757 echo " if (opener && !opener.closed && opener.refreshme) {\n " .
758 " opener.refreshme();\n " . // This is for standard calendar page refresh
760 " window.opener.pattrk.submit()\n " . // This is for patient flow board page refresh
762 echo " window.close();\n";
763 echo "</script>\n</body>\n</html>\n";
767 //*********************************
768 // If we get this far then we are displaying the form.
769 //*********************************
771 /*********************************************************************
772 This has been migrate to the administration->lists
775 '*' => xl('* Reminder done'),
776 '+' => xl('+ Chart pulled'),
777 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
778 '?' => xl('? No show'),
779 '@' => xl('@ Arrived'),
780 '~' => xl('~ Arrived late'),
781 '!' => xl('! Left w/o visit'),
782 '#' => xl('# Ins/fin issue'),
783 '<' => xl('< In exam room'),
784 '>' => xl('> Checked out'),
785 '$' => xl('$ Coding done'),
786 '%' => xl('% Cancelled < 24h ')
788 *********************************************************************/
790 $repeats = 0; // if the event repeats
794 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
802 // If we are editing an existing event, then get its data.
804 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
806 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
807 "FROM openemr_postcalendar_events AS e " .
808 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
809 "WHERE pc_eid = ?", array($eid) );
810 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
812 // instead of using the event's starting date, keep what has been provided
813 // via the GET array, see the top of this file
814 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
815 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
816 $userid = $row['pc_aid'];
817 $patientid = $row['pc_pid'];
818 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
819 $starttimem = substr($row['pc_startTime'], 3, 2);
820 $repeats = $row['pc_recurrtype'];
821 $multiple_value = $row['pc_multiple'];
823 // parse out the repeating data, if any
824 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
825 $repeattype = $rspecs['event_repeat_freq_type'];
826 $repeatfreq = $rspecs['event_repeat_freq'];
827 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
829 // Adjustments for repeat type 2, a particular weekday of the month.
831 $repeatfreq = $rspecs['event_repeat_on_freq'];
832 if ($rspecs['event_repeat_on_num'] < 5) {
839 $pcroom = $row['pc_room'];
840 $hometext = $row['pc_hometext'];
841 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
845 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
847 //-------------------------------------
849 //Set default facility for a new event based on the given 'userid'
851 /*************************************************************
852 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
853 *************************************************************/
854 if ($_SESSION['pc_facility']) {
855 $pref_facility = sqlFetchArray(sqlStatement("
856 SELECT f.id as facility_id,
861 array($_SESSION['pc_facility'])
864 $pref_facility = sqlFetchArray(sqlStatement("
865 SELECT u.facility_id,
868 LEFT JOIN facility f on (u.facility_id = f.id)
870 ", array($userid) ));
872 /************************************************************/
873 $e2f = $pref_facility['facility_id'];
874 $e2f_name = $pref_facility['facility'];
876 //END of CHEMED -----------------------
879 // If we have a patient ID, get the name and phone numbers to display.
881 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
882 "FROM patient_data WHERE pid = ?", array($patientid) );
883 $patientname = $prow['lname'] . ", " . $prow['fname'];
884 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
885 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
888 // Get the providers list.
889 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
890 "authorized != 0 AND active = 1 ORDER BY lname, fname");
892 // Get event categories.
893 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
894 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
896 // Fix up the time format for AM/PM.
898 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
900 if ($starttimeh > 12) $starttimeh -= 12;
906 <?php
html_header_show(); ?
>
907 <title
><?php
echo $eid ?
xlt('Edit') : xlt('Add New') ?
> <?php
echo xlt('Event');?
></title
>
908 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
909 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
912 td
{ font
-size
:0.8em
; }
915 <script type
="text/javascript" src
="../../../library/topdialog.js?v=<?php echo $v_js_includes; ?>"></script
>
916 <script type
="text/javascript" src
="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
917 <script type
="text/javascript" src
="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
918 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
920 <script language
="JavaScript">
922 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
924 var durations
= new Array();
925 // var rectypes = new Array();
927 // Read the event categories, generate their options list, and get
928 // the default event duration from them if this is a new event.
930 if($_GET['prov']==true){
933 $cres = sqlStatement("SELECT pc_catid, pc_cattype, pc_catname, " .
934 "pc_recurrtype, pc_duration, pc_end_all_day " .
935 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
937 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
940 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
942 while ($crow = sqlFetchArray($cres)) {
943 $duration = round($crow['pc_duration'] / 60);
944 if ($crow['pc_end_all_day']) $duration = 1440;
946 // This section is to build the list of preferred categories:
948 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
950 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
952 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
955 if ($crow['pc_cattype'] != $cattype) continue;
957 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
958 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
959 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
961 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
963 if ($crow['pc_catid'] == $default_catid) {
964 $catoptions .= " selected";
965 $thisduration = $duration;
968 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
972 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
974 // This is for callback by the find-patient popup.
975 function setpatient(pid
, lname
, fname
, dob
) {
976 var f
= document
.forms
[0];
977 f
.form_patient
.value
= lname +
', ' + fname
;
978 f
.form_pid
.value
= pid
;
979 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
980 document
.getElementById('dob_row').style
.display
= dobstyle
;
983 // This invokes the find-patient popup.
984 function sel_patient() {
985 dlgopen('find_patient_popup.php', '_blank', 500, 400);
988 // Do whatever is needed when a new event category is selected.
989 // For now this means changing the event title and duration.
990 function set_display() {
991 var f
= document
.forms
[0];
992 var s
= f
.form_category
;
993 if (s
.selectedIndex
>= 0) {
994 var catid
= s
.options
[s
.selectedIndex
].value
;
995 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
996 var style_prefcat
= document
.getElementById('title_prefcat').style
;
997 if (catid
== '2') { // In Office
998 style_apptstatus
.display
= 'none';
999 style_prefcat
.display
= '';
1000 f
.form_apptstatus
.style
.display
= 'none';
1001 f
.form_prefcat
.style
.display
= '';
1003 style_prefcat
.display
= 'none';
1004 style_apptstatus
.display
= '';
1005 f
.form_prefcat
.style
.display
= 'none';
1006 f
.form_apptstatus
.style
.display
= '';
1011 // Do whatever is needed when a new event category is selected.
1012 // For now this means changing the event title and duration.
1013 function set_category() {
1014 var f
= document
.forms
[0];
1015 var s
= f
.form_category
;
1016 if (s
.selectedIndex
>= 0) {
1017 var catid
= s
.options
[s
.selectedIndex
].value
;
1018 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
1019 f
.form_duration
.value
= durations
[catid
];
1024 // Modify some visual attributes when the all-day or timed-event
1025 // radio buttons are clicked.
1026 function set_allday() {
1027 var f
= document
.forms
[0];
1028 var color1
= '#777777';
1029 var color2
= '#777777';
1030 var disabled2
= true;
1031 if (document
.getElementById('rballday1').checked
) {
1034 if (document
.getElementById('rballday2').checked
) {
1038 document
.getElementById('tdallday1').style
.color
= color1
;
1039 document
.getElementById('tdallday2').style
.color
= color2
;
1040 document
.getElementById('tdallday3').style
.color
= color2
;
1041 document
.getElementById('tdallday4').style
.color
= color2
;
1042 document
.getElementById('tdallday5').style
.color
= color2
;
1043 f
.form_hour
.disabled
= disabled2
;
1044 f
.form_minute
.disabled
= disabled2
;
1045 f
.form_ampm
.disabled
= disabled2
;
1046 f
.form_duration
.disabled
= disabled2
;
1049 // Modify some visual attributes when the Repeat checkbox is clicked.
1050 function set_repeat() {
1051 var f
= document
.forms
[0];
1052 var isdisabled
= true;
1053 var mycolor
= '#777777';
1054 var myvisibility
= 'hidden';
1055 if (f
.form_repeat
.checked
) {
1056 f
.days_every_week
.checked
= false;
1057 document
.getElementById("days_label").style
.color
= mycolor
;
1058 var days
= document
.getElementById("days").getElementsByTagName('input');
1059 var labels
= document
.getElementById("days").getElementsByTagName('label');
1060 for(var i
=0; i
< days
.length
; i++
){
1061 days
[i
].disabled
= isdisabled
;
1062 labels
[i
].style
.color
= mycolor
;
1065 mycolor
= '#000000';
1066 myvisibility
= 'visible';
1068 f
.form_repeat_type
.disabled
= isdisabled
;
1069 f
.form_repeat_freq
.disabled
= isdisabled
;
1070 f
.form_enddate
.disabled
= isdisabled
;
1071 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
1072 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
1075 // Event when days_every_week is checked.
1076 function set_days_every_week() {
1077 var f
= document
.forms
[0];
1078 if (f
.days_every_week
.checked
) {
1079 //disable regular repeat
1080 f
.form_repeat
.checked
= false;
1081 f
.form_repeat_type
.disabled
= true;
1082 f
.form_repeat_freq
.disabled
= true;
1083 document
.getElementById('tdrepeat1').style
.color
= '#777777';
1085 //enable end_date setting
1086 document
.getElementById('tdrepeat2').style
.color
= '#000000';
1087 f
.form_enddate
.disabled
= false;
1089 var isdisabled
= false;
1090 var mycolor
= '#000000';
1091 var myvisibility
= 'visible';
1094 var isdisabled
= true;
1095 var mycolor
= '#777777';
1096 var myvisibility
= 'hidden';
1098 document
.getElementById("days_label").style
.color
= mycolor
;
1099 var days
= document
.getElementById("days").getElementsByTagName('input');
1100 var labels
= document
.getElementById("days").getElementsByTagName('label');
1101 for(var i
=0; i
< days
.length
; i++
){
1102 days
[i
].disabled
= isdisabled
;
1103 labels
[i
].style
.color
= mycolor
;
1106 //If no repetition is checked, disable end_date setting.
1107 if(!f
.days_every_week
.checked
&& !f
.form_repeat
.checked
){
1108 //disable end_date setting
1109 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
1110 f
.form_enddate
.disabled
= isdisabled
;
1116 // Constants used by dateChanged() function.
1117 var occurNames
= new Array(
1118 '<?php echo xls("1st"); ?>',
1119 '<?php echo xls("2nd"); ?>',
1120 '<?php echo xls("3rd"); ?>',
1121 '<?php echo xls("4th"); ?>'
1124 var weekDays
= new Array(
1125 '<?php echo xls("Sunday"); ?>',
1126 '<?php echo xls("Monday"); ?>',
1127 '<?php echo xls("Tuesday"); ?>',
1128 '<?php echo xls("Wednesday"); ?>',
1129 '<?php echo xls("Thursday"); ?>',
1130 '<?php echo xls("Friday"); ?>',
1131 '<?php echo xls("Saturday"); ?>'
1134 // Monitor start date changes to adjust repeat type options.
1135 function dateChanged() {
1136 var f
= document
.forms
[0];
1137 if (!f
.form_date
.value
) return;
1138 var d
= new Date(f
.form_date
.value
);
1139 var downame
= weekDays
[d
.getUTCDay()];
1141 var occur
= Math
.floor((d
.getUTCDate() - 1) / 7);
1142 if (occur
< 4) { // 5th is not allowed
1143 nthtext
= occurNames
[occur
] +
' ' + downame
;
1146 var tmp
= new Date(d
.getUTCFullYear(), d
.getUTCMonth() +
1, 0);
1147 if (tmp
.getDate() - d
.getUTCDate() < 7) { // Modified by epsdky 2016 (details in commit)
1148 // This is a last occurrence of the specified weekday in the month,
1149 // so permit that as an option.
1150 lasttext
= '<?php echo xls("Last"); ?> ' + downame
;
1152 var si
= f
.form_repeat_type
.selectedIndex
;
1153 var opts
= f
.form_repeat_type
.options
;
1154 opts
.length
= 5; // remove any nth and Last entries
1155 if (nthtext
) opts
[opts
.length
] = new Option(nthtext
, '5');
1156 if (lasttext
) opts
[opts
.length
] = new Option(lasttext
, '6');
1157 if (si
< opts
.length
) f
.form_repeat_type
.selectedIndex
= si
;
1158 else f
.form_repeat_type
.selectedIndex
= 5; // Added by epsdky 2016 (details in commit)
1161 // This is for callback by the find-available popup.
1162 function setappt(year
,mon
,mday
,hours
,minutes
) {
1163 var f
= document
.forms
[0];
1164 f
.form_date
.value
= '' + year +
'-' +
1165 ('' +
(mon +
100)).substring(1) +
'-' +
1166 ('' +
(mday +
100)).substring(1);
1167 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
1168 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
1169 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
1172 // Invoke the find-available popup.
1173 function find_available(extra
) {
1174 top
.restoreSession();
1175 // (CHEMED) Conditional value selection, because there is no <select> element
1176 // when making an appointment for a specific provider
1177 var s
= document
.forms
[0].form_provider
;
1178 var f
= document
.forms
[0].facility
;
1179 <?php
if ($userid != 0) { ?
>
1180 s
= document
.forms
[0].form_provider
.value
;
1181 f
= document
.forms
[0].facility
.value
;
1183 s
= document
.forms
[0].form_provider
.options
[s
.selectedIndex
].value
;
1184 f
= document
.forms
[0].facility
.options
[f
.selectedIndex
].value
;
1186 var c
= document
.forms
[0].form_category
;
1187 var formDate
= document
.forms
[0].form_date
;
1188 dlgopen('<?php echo $GLOBALS['web_root
']; ?>/interface/main/calendar/find_appt_popup.php' +
1189 '?providerid=' + s +
1190 '&catid=' + c
.options
[c
.selectedIndex
].value +
1192 '&startdate=' + formDate
.value +
1193 '&evdur=' + document
.forms
[0].form_duration
.value +
1194 '&eid=<?php echo 0 + $eid; ?>' +
1196 '_blank', 500, 400);
1203 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8" />
1207 <body
class="body_top main-calendar-add_edit_event" onunload
='imclosing()'>
1209 <form method
='post' name
='theform' id
='theform' action
='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1210 <!-- ViSolve
: Requirement
- Redirect to Create
New Patient Page
-->
1211 <input type
='hidden' size
='2' name
='resname' value
='empty' />
1213 if ($_POST["resname"]=="noresult"){
1215 <script language="Javascript">
1216 // refresh and redirect the parent window
1217 if (!opener.closed && opener.refreshme) opener.refreshme();
1218 top.restoreSession();
1219 opener.document.location="../../new/new.php";
1224 $classprov='current';
1227 <!-- ViSolve
: Requirement
- Redirect to Create
New Patient Page
-->
1228 <input type
="hidden" name
="form_action" id
="form_action" value
="">
1229 <input type
="hidden" name
="recurr_affect" id
="recurr_affect" value
="">
1230 <!-- used
for recurring events
-->
1231 <input type
="hidden" name
="selected_date" id
="selected_date" value
="<?php echo attr($date); ?>">
1232 <input type
="hidden" name
="event_start_date" id
="event_start_date" value
="<?php echo attr($eventstartdate); ?>">
1233 <!-- Following added by epsdky
2016 (details in commit
) -->
1234 <input type
="hidden" name
="old_repeats" id
="old_repeats" value
="<?php echo attr($repeats); ?>">
1235 <input type
="hidden" name
="rt2_flag2" id
="rt2_flag2" value
="<?php echo attr(isset($rspecs['rt2_pf_flag']) ? $rspecs['rt2_pf_flag'] : '0'); ?>">
1236 <!-- End of addition by epsdky
-->
1242 if($_GET['prov']==true){
1243 $provider_class="class='current'";
1246 $normal="class='current'";
1249 <tr
><th
><ul
class="tabNav">
1251 $eid=$_REQUEST["eid"];
1252 $startm=$_REQUEST["startampm"];
1253 $starth=$_REQUEST["starttimeh"];
1254 $uid=$_REQUEST["userid"];
1255 $starttm=$_REQUEST["starttimem"];
1256 $dt=$_REQUEST["date"];
1257 $cid=$_REQUEST["catid"];
1259 <li
<?php
echo $normal;?
>>
1260 <a href
='add_edit_event.php?eid=<?php echo attr($eid);?>&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);?>'>
1261 <?php
echo xlt('Patient');?
></a
>
1263 <li
<?php
echo $provider_class;?
>>
1264 <a href
='add_edit_event.php?prov=true&eid=<?php echo attr($eid);?>&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);?>'>
1265 <?php
echo xlt('Provider');?
></a
>
1269 <tr
><td colspan
='10'>
1270 <table border
='0' width
='100%' bgcolor
='#DDDDDD'>
1272 <td width
='1%' nowrap
>
1273 <b
><?php
echo xlt('Category'); ?
>:</b
>
1276 <select name
='form_category' onchange
='set_category()' style
='width:100%'>
1277 <?php
echo $catoptions ?
>
1280 <td width
='1%' nowrap
>
1282 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='1' id
='rballday1'
1283 <?php
if ($thisduration == 1440) echo "checked " ?
>/>
1285 <td colspan
='2' nowrap id
='tdallday1'>
1286 <?php
echo xlt('All day event'); ?
>
1291 <b
><?php
echo xlt('Date'); ?
>:</b
>
1294 <input type
='text' size
='10' class='datepicker' name
='form_date' id
='form_date'
1295 value
='<?php echo attr($date) ?>'
1296 title
='<?php echo xla('yyyy
-mm
-dd event date
or starting date
'); ?>'
1297 onchange
='dateChanged()' />
1301 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='0' id
='rballday2' <?php
if ($thisduration != 1440) echo "checked " ?
>/>
1303 <td width
='1%' nowrap id
='tdallday2'>
1304 <?php
echo xlt('Time'); ?
>
1306 <td width
='1%' nowrap id
='tdallday3'>
1308 <input type
='text' size
='2' name
='form_hour' value
='<?php echo attr($starttimeh) ?>'
1309 title
='<?php echo xla('Event start time
'); ?>' /> :
1310 <input type
='text' size
='2' name
='form_minute' value
='<?php echo attr($starttimem) ?>'
1311 title
='<?php echo xla('Event start time
'); ?>' /> 
;
1313 <select name
='form_ampm' title
='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1314 <option value
='1'><?php
echo xlt('AM'); ?
></option
>
1315 <option value
='2'<?php
if ($startampm == '2') echo " selected" ?
>><?php
echo xlt('PM'); ?
></option
>
1321 <b
><?php
echo xlt('Title'); ?
>:</b
>
1324 <input type
='text' size
='10' name
='form_title' value
='<?php echo attr($row['pc_title
']); ?>'
1326 title
='<?php echo xla('Event title
'); ?>' />
1331 <td nowrap id
='tdallday4'><?php
echo xlt('duration'); ?
>
1333 <td nowrap id
='tdallday5'>
1334 <input type
='text' size
='4' name
='form_duration' value
='<?php echo attr($thisduration) ?>' title
='<?php echo xla('Event duration in minutes
'); ?>' />
1335 <?php
echo xlt('minutes'); ?
>
1340 <td nowrap
><b
><?php
echo xlt('Facility'); ?
>:</b
></td
>
1342 <select name
="facility" id
="facility" >
1345 // ===========================
1346 // EVENTS TO FACILITIES
1347 //(CHEMED) added service_location WHERE clause
1348 // get the facilities
1349 /***************************************************************
1350 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1351 ***************************************************************/
1352 $facils = getUserFacilities($_SESSION['authId']);
1353 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1354 /**************************************************************/
1355 while ($facrow = sqlFetchArray($qsql)) {
1356 /*************************************************************
1357 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1358 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1359 *************************************************************/
1360 if ($_SESSION['authorizedUser'] ||
in_array($facrow, $facils)) {
1361 $selected = ( $facrow['id'] == $e2f ) ?
'selected="selected"' : '' ;
1362 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1365 $selected = ( $facrow['id'] == $e2f ) ?
'selected="selected"' : '' ;
1366 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1368 /************************************************************/
1371 // ===========================
1374 //END (CHEMED) IF ?>
1380 <b
><?php
echo xlt('Billing Facility'); ?
>:</b
>
1384 billing_facility('billing_facility',$row['pc_billing_location']);
1389 if($_GET['prov']!=true){
1391 <tr id
="patient_details">
1393 <b
><?php
echo xlt('Patient'); ?
>:</b
>
1396 <input 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
/>
1397 <input type
='hidden' name
='form_pid' value
='<?php echo attr($patientid) ?>' />
1399 <td colspan
='3' nowrap style
='font-size:8pt'>
1401 <span
class="infobox">
1402 <?php
if ($patienttitle != "") { echo $patienttitle; } ?
>
1411 <b
><?php
echo xlt('Provider'); ?
>:</b
>
1417 // =======================================
1419 // =======================================
1420 if ($GLOBALS['select_multi_providers']) {
1422 // there are two posible situations: edit and new record
1423 $providers_array = array();
1424 // this is executed only on edit ($eid)
1426 if ( $multiple_value ) {
1427 // find all the providers around multiple key
1428 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value) );
1429 while ($r = sqlFetchArray($qall)) {
1430 $providers_array[] = $r['providers'];
1433 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1434 $providers_array = sqlFetchArray($qall);
1438 // build the selection tool
1439 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1441 while ($urow = sqlFetchArray($ures)) {
1442 echo " <option value='" . attr($urow['id']) . "'";
1445 if ( in_array($urow['id'], $providers_array) ||
($urow['id'] == $userid) ) echo " selected";
1448 echo ">" . text($urow['lname']);
1449 if ($urow['fname']) echo ", " . text($urow['fname']);
1455 // =======================================
1457 // =======================================
1461 // get provider from existing event
1462 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1463 $provider = sqlFetchArray($qprov);
1464 $defaultProvider = $provider['pc_aid'];
1467 // this is a new event so smartly choose a default provider
1468 /*****************************************************************
1470 // Provider already given to us as a GET parameter.
1471 $defaultProvider = $userid;
1474 // default to the currently logged-in user
1475 $defaultProvider = $_SESSION['authUserID'];
1476 // or, if we have chosen a provider in the calendar, default to them
1477 // choose the first one if multiple have been selected
1478 if (count($_SESSION['pc_username']) >= 1) {
1479 // get the numeric ID of the first provider in the array
1480 $pc_username = $_SESSION['pc_username'];
1481 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1482 $defaultProvider = $firstProvider['id'];
1487 echo "<select name='form_provider' style='width:100%' />";
1488 while ($urow = sqlFetchArray($ures)) {
1489 echo " <option value='" . $urow['id'] . "'";
1490 if ($urow['id'] == $defaultProvider) echo " selected";
1491 echo ">" . $urow['lname'];
1492 if ($urow['fname']) echo ", " . $urow['fname'];
1496 *****************************************************************/
1497 // default to the currently logged-in user
1498 $defaultProvider = $_SESSION['authUserID'];
1499 // or, if we have chosen a provider in the calendar, default to them
1500 // choose the first one if multiple have been selected
1501 if (count($_SESSION['pc_username']) >= 1) {
1502 // get the numeric ID of the first provider in the array
1503 $pc_username = $_SESSION['pc_username'];
1504 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0]) ));
1505 $defaultProvider = $firstProvider['id'];
1507 // if we clicked on a provider's schedule to add the event, use THAT.
1508 if ($userid) $defaultProvider = $userid;
1510 echo "<select name='form_provider' style='width:100%' />";
1511 while ($urow = sqlFetchArray($ures)) {
1512 echo " <option value='" . attr($urow['id']) . "'";
1513 if ($urow['id'] == $defaultProvider) echo " selected";
1514 echo ">" . text($urow['lname']);
1515 if ($urow['fname']) echo ", " . text($urow['fname']);
1519 /****************************************************************/
1528 //Check if repeat is using the new 'days every week' mechanism.
1529 function isDaysEveryWeek($repeat){
1538 //Check if using the regular repeat mechanism.
1539 function isRegularRepeat($repeat){
1540 if($repeat == 1 ||
$repeat == 2){
1550 If the appointment was set with the regular (old) repeat mechanism (using 'every', 'every 2', etc.), then will be
1551 checked when editing and will select the proper recurrence pattern. If using the new repeat mechanism, then only that box (and the proper set
1552 days) will be checked. That's why I had to add the functions 'isRegularRepeat' and 'isDaysEveryWeek', to check which
1553 repeating mechanism is being used, and load settings accordingly.
1556 <input type
='checkbox' name
='form_repeat' id
="form_repeat" onclick
='set_repeat(this)' value
='1'<?php
if (isRegularRepeat($repeats)) echo " checked" ?
>/>
1557 <input type
='hidden' name
='form_repeat_exdate' id
='form_repeat_exdate' value
='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat
-->
1559 <td nowrap id
='tdrepeat1'><?php
echo xlt('Repeats'); ?
>
1563 <select name
='form_repeat_freq' title
='<?php echo xla('Every
, every other
, every
3rd
, etc
.'); ?>'>
1565 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1568 echo " <option value='" . attr($key) . "'";
1569 if ($key == $repeatfreq && isRegularRepeat($repeats)) echo " selected";
1570 echo ">" . text($value) . "</option>\n";
1575 <select name
='form_repeat_type'>
1577 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1578 // when the start date is set.
1579 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1580 5 => '?', 6 => '?') as $key => $value)
1582 echo " <option value='" . attr($key) . "'";
1583 if ($key == $repeattype && isRegularRepeat($repeats)) echo " selected";
1584 echo ">" . text($value) . "</option>\n";
1593 #days_every_week_row input[type="checkbox"]{float:right;}
1594 #days_every_week_row div{display: inline-block; text-align: center; width: 12%;}
1595 #days_every_week_row div input{width: 100%;}
1598 <tr id
="days_every_week_row">
1601 <td
><input type
='checkbox' id
='days_every_week' name
='days_every_week' onclick
='set_days_every_week()' <?php
if (isDaysEveryWeek($repeats)) echo " checked" ?
>/></td
>
1602 <td id
="days_label"><?php
echo xlt('Days Of Week') . ": "; ?
></td
>
1605 foreach (array(1 => xl('Su{{Sunday}}') , 2 => xl('Mo{{Monday}}'), 3 => xl('Tu{{Tuesday}}'), 4 => xl('We{{Wednesday}}'),
1606 5 => xl('Th{{Thursday}}'), 6 => xl('Fr{{Friday}}'), 7 => xl('Sa{{Saturday}}')) as $key => $value)
1608 echo " <div><input type='checkbox' name='day_". attr($key) ."'";
1609 //Checks appropriate days according to days in recurrence string.
1610 if (in_array($key, explode(',',$repeatfreq)) && isDaysEveryWeek($repeats)) echo " checked";
1611 echo " /><label>" . text($value) . "</label></div>\n";
1621 <span id
='title_apptstatus'><b
><?php
echo xlt('Status'); ?
>:</b
></span
>
1622 <span id
='title_prefcat' style
='display:none'><b
><?php
echo xlt('Pref Cat'); ?
>:</b
></span
>
1627 generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'SKIP'), $row['pc_apptstatus']);
1630 The following
list will be invisible unless this is an In Office
1631 event
, in which
case form_apptstatus (above
) is to be invisible
.
1633 <select name
='form_prefcat' style
='width:100%;display:none' title
='<?php echo xla('Preferred Event Category
');?>'>
1634 <?php
echo $prefcat_options ?
>
1641 <td nowrap id
='tdrepeat2'><?php
echo xlt('until'); ?
>
1644 <input type
='text' size
='10' class='datepicker' name
='form_enddate' id
='form_enddate' value
='<?php echo attr($row['pc_endDate
']) ?>' title
='<?php echo xla('yyyy
-mm
-dd last date of this event
');?>' />
1646 if ($repeatexdate != "") {
1647 $tmptitle = "The following dates are excluded from the repeating series";
1648 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1649 else { $tmptitle .= "\n"; }
1650 $exdates = explode(",", $repeatexdate);
1651 foreach ($exdates as $exdate) {
1652 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1654 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1660 if($_GET['prov']!=true){
1664 <b
><?php
echo xlt('Room Number'); ?
>:</b
>
1666 <td colspan
='4' nowrap
>
1668 echo generate_select_list('form_room', 'patient_flow_board_rooms',$pcroom, xl('Room Number'));
1675 <b
><?php
echo xlt('Comments'); ?
>:</b
>
1677 <td colspan
='4' nowrap
>
1678 <input type
='text' size
='40' name
='form_comments' style
='width:100%' value
='<?php echo attr($hometext); ?>' title
='<?php echo xla('Optional information about this event
');?>' />
1684 // DOB is important for the clinic, so if it's missing give them a chance
1685 // to enter it right here. We must display or hide this row dynamically
1686 // in case the patient-select popup is used.
1687 $patient_dob = trim($prow['DOB']);
1688 $dobstyle = ($prow && (!$patient_dob ||
substr($patient_dob, 5) == '00-00')) ?
1691 <tr id
='dob_row' style
='display:<?php echo $dobstyle ?>'>
1692 <td colspan
='4' nowrap
>
1693 <b
><font color
='red'><?php
echo xlt('DOB is missing, please enter if possible'); ?
>:</font
></b
>
1696 <input type
='text' size
='10' class='datepicker' name
='form_dob' id
='form_dob' title
='<?php echo xla('yyyy
-mm
-dd date of birth
');?>' />
1701 <tr
class='text'><td colspan
='10' class="buttonbar">
1703 <input type
='button' name
='form_save' id
='form_save' value
='<?php echo xla('Save
');?>' />
1706 <?php
if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1707 <input type
='button' id
='find_available' value
='<?php echo xla('Find Available
');?>' />
1711 <input type
='button' name
='form_delete' id
='form_delete' value
='<?php echo xla('Delete
');?>'<?php
if (!$eid) echo " disabled" ?
> />
1713 <input type
='button' id
='cancel' value
='<?php echo xla('Cancel
');?>' />
1715 <input type
='button' name
='form_duplicate' id
='form_duplicate' value
='<?php echo xla('Create Duplicate
');?>' />
1716 </p
></td
></tr
></table
>
1717 <?php
if ($informant) echo "<p class='text'>" . xlt('Last update by') . " " .
1718 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n"; ?
>
1722 <div id
="recurr_popup" style
="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1723 <?php
echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?
>
1725 <?php
if($GLOBALS['submit_changes_for_all_appts_at_once']) {?
>
1726 <input type
="button" name
="all_events" id
="all_events" value
=" <?php echo xla('All'); ?> ">
1728 <input type
="button" name
="future_events" id
="future_events" value
="<?php echo xla('Future'); ?>">
1729 <input type
="button" name
="current_event" id
="current_event" value
="<?php echo xla('Current'); ?>">
1730 <input type
="button" name
="recurr_cancel" id
="recurr_cancel" value
="<?php echo xla('Cancel'); ?>">
1735 <script language
='JavaScript'>
1736 <?php
if ($eid) { ?
>
1743 set_days_every_week();
1747 <script language
="javascript">
1748 // jQuery stuff to make the page a little easier to use
1750 $
(document
).ready(function(){
1751 $
("#form_save").click(function(e
) { validateform(e
,"save"); });
1752 $
("#form_duplicate").click(function(e
) { validateform(e
,"duplicate"); });
1753 $
("#find_available").click(function() { find_available(''); });
1754 $
("#form_delete").click(function() { deleteEvent(); });
1755 $
("#cancel").click(function() { window
.close(); });
1757 // buttons affecting the modification of a repeating event
1758 $
("#all_events").click(function() { $
("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1759 $
("#future_events").click(function() { $
("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1760 $
("#current_event").click(function() { $
("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1761 $
("#recurr_cancel").click(function() { $
("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1763 // Initialize repeat options.
1766 $
('.datepicker').datetimepicker({
1767 <?php
$datetimepicker_timepicker = false; ?
>
1768 <?php
$datetimepicker_formatInput = false; ?
>
1769 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
1770 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
1775 function are_days_checked(){
1776 var days
= document
.getElementById("days").getElementsByTagName('input');
1778 for(var i
=0; i
< days
.length
; i++
){
1779 if(days
[i
].checked
){
1787 * validation on the form with new client side validation (using validate.js).
1788 * this enable to add new rules for this form in the pageValidation list.
1790 var collectvalidation
= <?php
echo($collectthis); ?
>;
1791 function validateform(event
,valu
){
1793 //Make sure if days_every_week is checked that at least one weekday is checked.
1794 if($
('#days_every_week').is(':checked') && !are_days_checked()){
1795 alert('<?php echo xls("Must choose at least one day!"); ?>');
1799 //add rule if choose repeating event
1800 if ($
('#form_repeat').is(':checked') || $
('#days_every_week').is(':checked')){
1801 collectvalidation
.form_enddate
= {
1804 earliest
: $
('#form_date').val(),
1805 message
: "An end date later than the start date is required for repeated events!"
1810 if(typeof (collectvalidation
) != 'undefined'){
1811 delete collectvalidation
.form_enddate
;
1816 if($_GET['prov']==true){
1818 //remove rule if it's provider event
1819 if(collectvalidation
.form_patient
!= undefined
){
1820 delete collectvalidation
.form_patient
;
1827 if($GLOBALS['select_multi_providers']){
1829 //If multiple providers is enabled, create provider validation (Note: if no provider is chosen it causes bugs when deleting recurrent events).
1830 collectvalidation
.form_provider
= {presence
: true};
1836 var submit
= submitme(1, event
, 'theform', collectvalidation
);
1839 $
('#form_action').val(valu
);
1841 <?php
if ($repeats): ?
>
1842 // existing repeating events need additional prompt
1843 if ($
("#recurr_affect").val() == "") {
1845 // show the current/future/all DIV for the user to choose one
1846 $
("#recurr_popup").css("visibility", "visible");
1855 // disable all the form elements outside the recurr_popup
1856 function DisableForm() {
1857 $
("#theform").children().attr("disabled", "true");
1859 function EnableForm() {
1860 $
("#theform").children().removeAttr("disabled");
1862 // hide the recurring popup DIV
1863 function HideRecurrPopup() {
1864 $
("#recurr_popup").css("visibility", "hidden");
1867 function deleteEvent() {
1868 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?')); ?>")) {
1869 $
('#form_action').val("delete");
1871 <?php
if ($repeats): ?
>
1872 // existing repeating events need additional prompt
1873 if ($
("#recurr_affect").val() == "") {
1875 // show the current/future/all DIV for the user to choose one
1876 $
("#recurr_popup").css("visibility", "visible");
1881 return SubmitForm();
1886 function SubmitForm() {
1887 var f
= document
.forms
[0];
1888 <?php
if (!($GLOBALS['select_multi_providers'])) { // multi providers appt is not supported by check slot avail window, so skip ?>
1889 if (f
.form_action
.value
!= 'delete') {
1890 // Check slot availability.
1891 var mins
= parseInt(f
.form_hour
.value
) * 60 +
parseInt(f
.form_minute
.value
);
1892 if (f
.form_ampm
.value
== '2' && mins
< 720) mins +
= 720;
1893 find_available('&cktime=' + mins
);
1896 top
.restoreSession();
1900 top
.restoreSession();