fix for deleting recurrent event
[openemr.git] / interface / main / calendar / add_edit_event.php
blob7bb37dea57329b569078cb2e85f9c4f726782334
1 <?php
2 /*
3 * Add or edit an event in the calendar.
5 * Can be displayed as a popup window, or as an iframe via
6 * fancybox.
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 ________________________________________________ //
19 * // //
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>;.
38 * @package OpenEMR
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");
57 require_once($GLOBALS['srcdir'].'/group.inc');
59 //Check access control
60 if (!acl_check('patients','appt','',array('write','wsome') ))
61 die(xl('Access not allowed'));
63 /* Things that might be passed by our opener. */
64 $eid = $_GET['eid']; // only for existing events
65 $date = $_GET['date']; // this and below only for new events
66 $userid = $_GET['userid'];
67 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
69 if ($date)
70 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
71 else
72 $date = date("Y-m-d");
74 $starttimem = '00';
75 if (isset($_GET['starttimem']))
76 $starttimem = substr('00' . $_GET['starttimem'], -2);
78 if (isset($_GET['starttimeh'])) {
79 $starttimeh = $_GET['starttimeh'];
80 if (isset($_GET['startampm'])) {
81 if ($_GET['startampm'] == '2' && $starttimeh < 12)
82 $starttimeh += 12;
84 } else {
85 $starttimeh = date("G");
87 $startampm = '';
89 $info_msg = "";
92 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js?v=<?php echo $v_js_includes; ?>"></script>
93 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative'] ?>/jquery-min-3-1-1/index.js"></script>
95 <!-- validation library -->
96 <!--//Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation-->
97 <?php $use_validate_js = 1;?>
98 <?php require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?>
99 <?php
100 //Gets validation rules from Page Validation list.
101 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
102 if($_GET['group'] == true)
103 //groups tab
104 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php?group=true");
105 elseif($_GET['prov'])
106 //providers tab
107 $collectthis = '';
108 else
109 //patient tab
110 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php");
112 if (empty($collectthis)) {
113 $collectthis = "undefined";
115 else {
116 $collectthis = $collectthis[array_keys($collectthis)[0]]["rules"];
120 <?php
122 function InsertEventFull()
124 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
125 // =======================================
126 // multi providers case
127 // =======================================
128 if (is_array($_POST['form_provider'])) {
130 // obtain the next available unique key to group multiple providers around some event
131 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
132 $max = sqlFetchArray($q);
133 $new_multiple_value = $max['max'] + 1;
135 $pc_eid = null;
136 foreach ($_POST['form_provider'] as $provider) {
137 $args = $_POST;
138 // specify some special variables needed for the INSERT
139 $args['new_multiple_value'] = $new_multiple_value;
140 $args['form_provider'] = $provider;
141 $args['event_date'] = $event_date;
142 $args['duration'] = $duration * 60;
143 $args['recurrspec'] = $recurrspec;
144 $args['starttime'] = $starttime;
145 $args['endtime'] = $endtime;
146 $args['locationspec'] = $locationspec;
147 $pc_eid_temp = InsertEvent($args);
148 if($pc_eid == null) $pc_eid = $pc_eid_temp;
150 return $pc_eid;
153 // ====================================
154 // single provider
155 // ====================================
156 } else {
157 $args = $_POST;
158 // specify some special variables needed for the INSERT
159 $args['new_multiple_value'] = "";
160 $args['event_date'] = $event_date;
161 $args['duration'] = $duration * 60;
162 $args['recurrspec'] = $recurrspec;
163 $args['starttime'] = $starttime;
164 $args['endtime'] = $endtime;
165 $args['locationspec'] = $locationspec;
166 $pc_eid = InsertEvent($args);
167 return $pc_eid;
170 function DOBandEncounter($pc_eid)
172 global $event_date,$info_msg;
173 // Save new DOB if it's there.
174 $patient_dob = trim($_POST['form_dob']);
175 $tmph = $_POST['form_hour'] + 0;
176 $tmpm = $_POST['form_minute'] + 0;
177 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
178 $appttime = "$tmph:$tmpm:00";
180 if ($patient_dob && $_POST['form_pid']) {
181 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
182 "pid = ?", array($patient_dob,$_POST['form_pid']) );
185 // Manage tracker status.
186 // And auto-create a new encounter if appropriate.
187 if (!empty($_POST['form_pid'])) {
188 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']))
190 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
191 if($encounter){
192 $info_msg .= xl("New encounter created with id");
193 $info_msg .= " $encounter";
195 # Capture the appt status and room number for patient tracker. This will map the encounter to it also.
196 if ( isset($GLOBALS['temporary-eid-for-manage-tracker']) || !empty($_GET['eid']) ) {
197 // Note that the temporary-eid-for-manage-tracker is used to capture the eid for new appointments and when separate a recurring
198 // appointment. It is set in the InsertEvent() function. Note that in the case of spearating a recurrent appointment, the get eid
199 // parameter is actually erroneous(is eid of the recurrent appt and not the new separated appt), so need to use the
200 // temporary-eid-for-manage-tracker global instead.
201 $temp_eid = (isset($GLOBALS['temporary-eid-for-manage-tracker'])) ? $GLOBALS['temporary-eid-for-manage-tracker'] : $_GET['eid'];
202 manage_tracker_status($event_date,$appttime,$temp_eid,$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room'],$encounter);
205 else
207 # Capture the appt status and room number for patient tracker.
208 if (!empty($_GET['eid'])) {
209 manage_tracker_status($event_date,$appttime,$_GET['eid'],$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room']);
213 // auto create encounter for therapy group
214 if(!empty($_POST['form_gid'])){
215 // status Took Place is the check in of therapy group
216 if ($GLOBALS['auto_create_new_encounters'] && $event_date == date('Y-m-d') && $_POST['form_apptstatus'] == '=') {
217 $encounter = todaysTherapyGroupEncounterCheck($_POST['form_gid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false, $pc_eid);
218 if ($encounter) {
219 $info_msg .= xl("New group encounter created with id");
220 $info_msg .= " $encounter";
228 /*This function is used for setting the date of the first event when using the "day_every_week" repetition mechanism.
229 When the 'start date' is not one of the days chosen for the repetition, the start date needs to be changed to the first
230 occurrence of one of these set days. */
231 function setEventDate($start_date, $recurrence){
232 $timestamp = strtotime($start_date);
233 $day = date('w', $timestamp);
234 //If the 'start date' is one of the set days
235 if(in_array(($day+1), explode(',',$recurrence))){
236 return $start_date;
238 //else: (we need to change start date to first occurrence of one of the set days)
240 $new_date = getTheNextAppointment($start_date, $recurrence);
242 return $new_date;
246 //================================================================================================================
248 // EVENTS TO FACILITIES (lemonsoftware)
249 //(CHEMED) get facility name
250 // edit event case - if there is no association made, then insert one with the first facility
251 if ( $eid ) {
252 $selfacil = '';
253 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
254 FROM openemr_postcalendar_events
255 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
256 WHERE pc_eid = ?", array($eid) );
257 // if ( !$facility['pc_facility'] ) {
258 if ( is_array($facility) && !$facility['pc_facility'] ) {
259 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']) );
260 $min = $qmin['minId'];
261 $min_name = $qmin['facility'];
263 // multiple providers case
264 if ( $GLOBALS['select_multi_providers'] ) {
265 $mul = $facility['pc_multiple'];
266 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min,$mul) );
268 // EOS multiple
270 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min,$eid) );
271 $e2f = $min;
272 $e2f_name = $min_name;
273 } else {
274 // not edit event
275 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
276 $e2f = $_SESSION['pc_facility'];
277 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
278 $e2f = $_COOKIE['pc_facility'];
279 } else {
280 $e2f = $facility['pc_facility'];
281 $e2f_name = $facility['name'];
285 // EOS E2F
286 // ===========================
287 //=============================================================================================================================
288 if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
291 // Compute start and end time strings to be saved.
292 if ($_POST['form_allday']) {
293 $tmph = 0;
294 $tmpm = 0;
295 $duration = 24 * 60;
296 } else {
297 $tmph = $_POST['form_hour'] + 0;
298 $tmpm = $_POST['form_minute'] + 0;
299 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
300 $duration = abs($_POST['form_duration']); // fixes #395
302 $starttime = "$tmph:$tmpm:00";
304 $tmpm += $duration;
305 while ($tmpm >= 60) {
306 $tmpm -= 60;
307 ++$tmph;
309 $endtime = "$tmph:$tmpm:00";
311 // Set up working variables related to repeated events.
312 $my_recurrtype = 0;
313 $my_repeat_freq = 0 + $_POST['form_repeat_freq'];
314 $my_repeat_type = 0 + $_POST['form_repeat_type'];
315 $my_repeat_on_num = 1;
316 $my_repeat_on_day = 0;
317 $my_repeat_on_freq = 0;
319 // the starting date of the event, pay attention with this value
320 // when editing recurring events -- JRM Oct-08
321 $event_date = fixDate($_POST['form_date']);
323 //If used new recurrence mechanism of set days every week
324 if(!empty($_POST['days_every_week'])){
325 $my_recurrtype = 3;
326 //loop through checkboxes and insert encounter days into array
327 $days_every_week_arr = array();
328 for($i=1; $i<=7; $i++){
329 if(!empty($_POST['day_' . $i])){
330 array_push($days_every_week_arr, $i);
333 $my_repeat_freq = implode(",",$days_every_week_arr);
334 $my_repeat_type = 6;
335 $event_date = fixDate(setEventDate($_POST['form_date'], $my_repeat_freq));
338 elseif (!empty($_POST['form_repeat'])){
340 $my_recurrtype = 1;
341 if ($my_repeat_type > 4) {
342 $my_recurrtype = 2;
343 $time = strtotime($event_date);
344 $my_repeat_on_day = 0 + date('w', $time);
345 $my_repeat_on_freq = $my_repeat_freq;
346 if ($my_repeat_type == 5) {
347 $my_repeat_on_num = intval((date('j', $time) - 1) / 7) + 1;
348 } else {
349 // Last occurence of this weekday on the month
350 $my_repeat_on_num = 5;
352 // Maybe not needed, but for consistency with postcalendar:
353 $my_repeat_freq = 0;
354 $my_repeat_type = 0;
359 // Useless garbage that we must save.
360 $locationspecs = array("event_location" => "",
361 "event_street1" => "",
362 "event_street2" => "",
363 "event_city" => "",
364 "event_state" => "",
365 "event_postal" => ""
367 $locationspec = serialize($locationspecs);
369 // capture the recurring specifications
370 $recurrspec = array("event_repeat_freq" => "$my_repeat_freq",
371 "event_repeat_freq_type" => "$my_repeat_type",
372 "event_repeat_on_num" => "$my_repeat_on_num",
373 "event_repeat_on_day" => "$my_repeat_on_day",
374 "event_repeat_on_freq" => "$my_repeat_on_freq",
375 "exdate" => $_POST['form_repeat_exdate']
379 if($my_recurrtype == 2) { // Added by epsdky 2016 (details in commit)
380 if($_POST['old_repeats'] == 2) {
381 if($_POST['rt2_flag2']) $recurrspec['rt2_pf_flag'] = "1";
382 } else $recurrspec['rt2_pf_flag'] = "1";
383 } // End of addition by epsdky
385 // no recurr specs, this is used for adding a new non-recurring event
386 $noRecurrspec = array("event_repeat_freq" => "",
387 "event_repeat_freq_type" => "",
388 "event_repeat_on_num" => "1",
389 "event_repeat_on_day" => "0",
390 "event_repeat_on_freq" => "0",
391 "exdate" => ""
394 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
395 //=============================================================================================================================
396 if ($_POST['form_action'] == "duplicate") {
398 $eid = InsertEventFull();
399 DOBandEncounter($eid);
403 // If we are saving, then save and close the window.
405 if ($_POST['form_action'] == "save") {
406 /* =======================================================
407 * UPDATE EVENTS
408 * =====================================================*/
409 if ($eid) {
411 // what is multiple key around this $eid?
412 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
414 // ====================================
415 // multiple providers
416 // ====================================
417 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
419 // obtain current list of providers regarding the multiple key
420 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
421 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
423 // get the new list of providers from the submitted form
424 $providers_new = $_POST['form_provider'];
426 // ===== Only current event of repeating series =====
427 if ($_POST['recurr_affect'] == 'current') {
429 // update all existing event records to exlude the current date
430 foreach ($providers_current as $provider) {
431 // update the provider's original event
432 // get the original event's repeat specs
433 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
434 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
435 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
436 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
437 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
438 else { $oldRecurrspec['exdate'] .= $selected_date; }
440 // mod original event recur specs to exclude this date
441 sqlStatement("UPDATE openemr_postcalendar_events SET " .
442 " pc_recurrspec = ? ".
443 " WHERE pc_aid = ? AND pc_multiple=?", array(serialize($oldRecurrspec),$provider,$row['pc_multiple']) );
446 // obtain the next available unique key to group multiple providers around some event
447 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
448 $max = sqlFetchArray($q);
449 $new_multiple_value = $max['max'] + 1;
451 // insert a new event record for each provider selected on the form
452 foreach ($providers_new as $provider) {
453 // insert a new event on this date with POST form data
454 $args = $_POST;
455 // specify some special variables needed for the INSERT
456 $args['new_multiple_value'] = $new_multiple_value;
457 $args['form_provider'] = $provider;
458 $args['event_date'] = $event_date;
459 $args['duration'] = $duration * 60;
460 // this event is forced to NOT REPEAT
461 $args['form_repeat'] = "0";
462 $args['days_every_week'] = "0";
463 $args['recurrspec'] = $noRecurrspec;
464 $args['form_enddate'] = "0000-00-00";
465 $args['starttime'] = $starttime;
466 $args['endtime'] = $endtime;
467 $args['locationspec'] = $locationspec;
468 InsertEvent($args);
472 // ===== Future Recurring events of a repeating series =====
473 else if ($_POST['recurr_affect'] == 'future') {
474 // update all existing event records to
475 // stop recurring on this date-1
476 $selected_date = date("Y-m-d", (strtotime($_POST['selected_date'])-24*60*60));
477 foreach ($providers_current as $provider) {
478 // In case of a change in the middle of the event
479 if (strcmp($_POST['event_start_date'],$_POST['selected_date'])!=0) {
480 // mod original event recur specs to end on this date
481 sqlStatement("UPDATE openemr_postcalendar_events SET " .
482 " pc_enddate = ? " .
483 " WHERE pc_aid = ? AND pc_multiple=?", array($selected_date, $provider, $row['pc_multiple']));
485 // In case of a change in the event head
486 else {
487 sqlStatement("DELETE FROM openemr_postcalendar_events " .
488 " WHERE pc_aid = ? AND pc_multiple=?" , array($provider, $row['pc_multiple']));
493 // obtain the next available unique key to group multiple providers around some event
494 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
495 $max = sqlFetchArray($q);
496 $new_multiple_value = $max['max'] + 1;
498 // insert a new event record for each provider selected on the form
499 foreach ($providers_new as $provider) {
500 // insert a new event on this date with POST form data
501 $args = $_POST;
502 // specify some special variables needed for the INSERT
503 $args['new_multiple_value'] = $new_multiple_value;
504 $args['form_provider'] = $provider;
505 $args['event_date'] = $event_date;
506 $args['duration'] = $duration * 60;
507 $args['recurrspec'] = $recurrspec;
508 $args['starttime'] = $starttime;
509 $args['endtime'] = $endtime;
510 $args['locationspec'] = $locationspec;
511 InsertEvent($args);
515 else {
516 /* =================================================================== */
517 // ===== a Single event or All events in a repeating series ==========
518 /* =================================================================== */
520 // this difference means that some providers from current was UNCHECKED
521 // so we must delete this event for them
522 $r1 = array_diff ($providers_current, $providers_new);
523 if (count ($r1)) {
524 foreach ($r1 as $to_be_removed) {
525 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']) );
529 // perform a check to see if user changed event date
530 // this is important when editing an existing recurring event
531 // oct-08 JRM
532 if ($_POST['form_date'] == $_POST['selected_date']) {
533 // user has NOT changed the start date of the event (and not recurrtype 3)
534 if($my_recurrtype != 3) $event_date = fixDate($_POST['event_start_date']);
537 // this difference means that some providers were added
538 // so we must insert this event for them
539 $r2 = array_diff ($providers_new, $providers_current);
540 if (count ($r2)) {
541 foreach ($r2 as $to_be_inserted) {
542 $args = $_POST;
543 // specify some special variables needed for the INSERT
544 $args['new_multiple_value'] = $row['pc_multiple'];
545 $args['form_provider'] = $to_be_inserted;
546 $args['event_date'] = $event_date;
547 $args['duration'] = $duration * 60;
548 $args['recurrspec'] = $recurrspec;
549 $args['starttime'] = $starttime;
550 $args['endtime'] = $endtime;
551 $args['locationspec'] = $locationspec;
552 InsertEvent($args);
556 // after the two diffs above, we must update for remaining providers
557 // those who are intersected in $providers_current and $providers_new
558 foreach ($_POST['form_provider'] as $provider) {
559 sqlStatement("UPDATE openemr_postcalendar_events SET " .
560 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
561 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
562 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
563 "pc_time = NOW(), " .
564 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
565 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
566 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
567 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
568 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
569 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
570 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
571 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
572 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
573 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
574 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
575 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
576 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
577 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
578 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
579 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'");
580 } // foreach
583 // ====================================
584 // single provider
585 // ====================================
586 } elseif ( !$row['pc_multiple'] ) {
587 if ( $GLOBALS['select_multi_providers'] ) {
588 $prov = $_POST['form_provider'][0];
589 } else {
590 $prov = $_POST['form_provider'];
593 if ($_POST['recurr_affect'] == 'current') {
594 // get the original event's repeat specs
595 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
596 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
597 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
598 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
599 else { $oldRecurrspec['exdate'] .= $selected_date; }
601 // mod original event recur specs to exclude this date
602 sqlStatement("UPDATE openemr_postcalendar_events SET " .
603 " pc_recurrspec = ? ".
604 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
606 // insert a new event on this date with POST form data
607 $args = $_POST;
608 // specify some special variables needed for the INSERT
609 $args['event_date'] = $event_date;
610 $args['duration'] = $duration * 60;
611 // this event is forced to NOT REPEAT
612 $args['form_repeat'] = "0";
613 $args['days_every_week'] = "0";
614 $args['recurrspec'] = $noRecurrspec;
615 $args['form_enddate'] = "0000-00-00";
616 $args['starttime'] = $starttime;
617 $args['endtime'] = $endtime;
618 $args['locationspec'] = $locationspec;
619 InsertEvent($args);
621 else if ($_POST['recurr_affect'] == 'future') {
622 // mod original event to stop recurring on this date-1
623 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
624 sqlStatement("UPDATE openemr_postcalendar_events SET " .
625 " pc_enddate = ? ".
626 " WHERE pc_eid = ?", array($selected_date,$eid) );
628 // insert a new event starting on this date with POST form data
629 $args = $_POST;
630 // specify some special variables needed for the INSERT
631 $args['event_date'] = $event_date;
632 $args['duration'] = $duration * 60;
633 $args['recurrspec'] = $recurrspec;
634 $args['starttime'] = $starttime;
635 $args['endtime'] = $endtime;
636 $args['locationspec'] = $locationspec;
637 InsertEvent($args);
639 else {
641 // perform a check to see if user changed event date
642 // this is important when editing an existing recurring event
643 // oct-08 JRM
644 if ($_POST['form_date'] == $_POST['selected_date']) {
645 // user has NOT changed the start date of the event (and not recurrtype 3)
646 if($my_recurrtype != 3) $event_date = fixDate($_POST['event_start_date']);
649 // mod the SINGLE event or ALL EVENTS in a repeating series
650 // simple provider case
651 sqlStatement("UPDATE openemr_postcalendar_events SET " .
652 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
653 "pc_aid = '" . add_escape_custom($prov) . "', " .
654 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
655 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
656 "pc_time = NOW(), " .
657 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
658 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
659 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
660 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
661 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
662 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
663 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
664 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
665 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
666 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
667 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
668 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
669 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
670 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
671 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
672 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
676 // =======================================
677 // end Update Multi providers case
678 // =======================================
680 // EVENTS TO FACILITIES
681 $e2f = (int)$eid;
684 } else {
685 /* =======================================================
686 * INSERT NEW EVENT(S)
687 * ======================================================*/
689 $eid = InsertEventFull();
693 // done with EVENT insert/update statements
695 DOBandEncounter(isset($eid) ? $eid : null);
699 // =======================================
700 // DELETE EVENT(s)
701 // =======================================
702 else if ($_POST['form_action'] == "delete") {
703 // =======================================
704 // multi providers event
705 // =======================================
706 if ($GLOBALS['select_multi_providers']) {
708 // what is multiple key around this $eid?
709 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
711 // obtain current list of providers regarding the multiple key
712 $providers_current = array();
713 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
714 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
716 // establish a WHERE clause
717 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = '{$row['pc_multiple']}'"; }
718 else { $whereClause = "pc_eid = '$eid'"; }
720 if ($_POST['recurr_affect'] == 'current') {
721 // update all existing event records to exlude the current date
722 foreach ($providers_current as $provider) {
723 // update the provider's original event
724 // get the original event's repeat specs
725 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
726 " WHERE pc_aid <=> ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
727 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
728 $selected_date = date("Y-m-d", strtotime($_POST['selected_date']));
729 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
730 else { $oldRecurrspec['exdate'] .= $selected_date; }
732 // mod original event recur specs to exclude this date
733 sqlStatement("UPDATE openemr_postcalendar_events SET " .
734 " pc_recurrspec = ? ".
735 " WHERE ". $whereClause, array(serialize($oldRecurrspec)) );
738 else if ($_POST['recurr_affect'] == 'future') {
739 // update all existing event records to stop recurring on this date-1
740 $selected_date = date("Y-m-d", (strtotime($_POST['selected_date'])-24*60*60));
741 foreach ($providers_current as $provider) {
742 // In case of a change in the middle of the event
743 if (strcmp($_POST['event_start_date'],$_POST['selected_date'])!=0) {
744 // update the provider's original event
745 sqlStatement("UPDATE openemr_postcalendar_events SET " .
746 " pc_enddate = ? " .
747 " WHERE " . $whereClause, array($selected_date));
749 // In case of a change in the event head
750 else{
751 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
755 else {
756 // really delete the event from the database
757 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
761 // =======================================
762 // single provider event
763 // =======================================
764 else {
766 if ($_POST['recurr_affect'] == 'current') {
767 // mod original event recur specs to exclude this date
769 // get the original event's repeat specs
770 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
771 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
772 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
773 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
774 else { $oldRecurrspec['exdate'] .= $selected_date; }
775 sqlStatement("UPDATE openemr_postcalendar_events SET " .
776 " pc_recurrspec = ? ".
777 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
780 else if ($_POST['recurr_affect'] == 'future') {
781 // mod original event to stop recurring on this date-1
782 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
783 sqlStatement("UPDATE openemr_postcalendar_events SET " .
784 " pc_enddate = ? ".
785 " WHERE pc_eid = ?", array($selected_date,$eid) );
788 else {
789 // fully delete the event from the database
790 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
795 if ($_POST['form_action'] != "") {
796 // Close this window and refresh the calendar (or the patient_tracker) display.
797 echo "<html>\n<body>\n<script language='JavaScript'>\n";
798 if ($info_msg) echo " alert('" . addslashes($info_msg) . "');\n";
799 echo " if (opener && !opener.closed && opener.refreshme) {\n " .
800 " opener.refreshme();\n " . // This is for standard calendar page refresh
801 " } else {\n " .
802 " if(window.opener.pattrk){" .
803 " window.opener.pattrk.submit()\n " . // This is for patient flow board page refresh}
804 " }};\n";
805 echo " window.close();\n";
806 echo "</script>\n</body>\n</html>\n";
807 exit();
810 //*********************************
811 // If we get this far then we are displaying the form.
812 //*********************************
814 /*********************************************************************
815 This has been migrate to the administration->lists
816 $statuses = array(
817 '-' => '',
818 '*' => xl('* Reminder done'),
819 '+' => xl('+ Chart pulled'),
820 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
821 '?' => xl('? No show'),
822 '@' => xl('@ Arrived'),
823 '~' => xl('~ Arrived late'),
824 '!' => xl('! Left w/o visit'),
825 '#' => xl('# Ins/fin issue'),
826 '<' => xl('< In exam room'),
827 '>' => xl('> Checked out'),
828 '$' => xl('$ Coding done'),
829 '%' => xl('% Cancelled < 24h ')
831 *********************************************************************/
833 $repeats = 0; // if the event repeats
834 $repeattype = '0';
835 $repeatfreq = '0';
836 $patientid = '';
837 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
838 $patientname = null;
839 $patienttitle = Array();
840 $pcroom = "";
841 $hometext = "";
842 $row = array();
843 $informant = "";
844 $groupid = '';
845 if ($_REQUEST['groupid']) $groupid = $_REQUEST['groupid'];
846 $groupname = null;
847 $group_statuses = getGroupStatuses();
850 // If we are editing an existing event, then get its data.
851 if ($eid) {
852 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
854 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
855 "FROM openemr_postcalendar_events AS e " .
856 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
857 "WHERE pc_eid = ?", array($eid) );
858 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
860 // instead of using the event's starting date, keep what has been provided
861 // via the GET array, see the top of this file
862 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
863 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
864 $userid = $row['pc_aid'];
865 $patientid = $row['pc_pid'];
866 $groupid = $row['pc_gid'];
867 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
868 $starttimem = substr($row['pc_startTime'], 3, 2);
869 $repeats = $row['pc_recurrtype'];
870 $multiple_value = $row['pc_multiple'];
872 // parse out the repeating data, if any
873 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
874 $repeattype = $rspecs['event_repeat_freq_type'];
875 $repeatfreq = $rspecs['event_repeat_freq'];
876 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
878 // Adjustments for repeat type 2, a particular weekday of the month.
879 if ($repeats == 2) {
880 $repeatfreq = $rspecs['event_repeat_on_freq'];
881 if ($rspecs['event_repeat_on_num'] < 5) {
882 $repeattype = 5;
884 else {
885 $repeattype = 6;
888 $recurrence_end_date = ($row['pc_endDate'] && $row['pc_endDate'] != '0000-00-00') ? $row['pc_endDate'] : NULL;
889 $pcroom = $row['pc_room'];
890 $hometext = $row['pc_hometext'];
891 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
893 else {
894 // a NEW event
895 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
897 //-------------------------------------
898 //(CHEMED)
899 //Set default facility for a new event based on the given 'userid'
900 if ($userid) {
901 /*************************************************************
902 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
903 *************************************************************/
904 if ($_SESSION['pc_facility']) {
905 $pref_facility = sqlFetchArray(sqlStatement("
906 SELECT f.id as facility_id,
907 f.name as facility
908 FROM facility f
909 WHERE f.id = ?
911 array($_SESSION['pc_facility'])
913 } else {
914 $pref_facility = sqlFetchArray(sqlStatement("
915 SELECT u.facility_id,
916 f.name as facility
917 FROM users u
918 LEFT JOIN facility f on (u.facility_id = f.id)
919 WHERE u.id = ?
920 ", array($userid) ));
922 /************************************************************/
923 $e2f = $pref_facility['facility_id'];
924 $e2f_name = $pref_facility['facility'];
926 //END of CHEMED -----------------------
929 // If we have a patient ID, get the name and phone numbers to display.
930 if ($patientid) {
931 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
932 "FROM patient_data WHERE pid = ?", array($patientid) );
933 $patientname = $prow['lname'] . ", " . $prow['fname'];
934 if ($prow['phone_home']) $patienttitle['phone_home'] = xl("Home Phone").": " . $prow['phone_home'];
935 if ($prow['phone_biz']) $patienttitle['phone_biz'] = xl("Work Phone").": " . $prow['phone_biz'];
938 // If we have a group id, get group data
939 if ($groupid){
940 $group_data = getGroup($groupid);
941 $groupname = $group_data['group_name'];
942 $group_end_date = $group_data['group_end_date'];
943 if(!$recurrence_end_date && $group_end_date && $group_end_date != '0000-00-00'){
944 $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)
948 // Get the providers list.
949 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
950 "authorized != 0 AND active = 1 ORDER BY lname, fname");
952 // Get event categories.
953 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
954 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
956 // Fix up the time format for AM/PM.
957 $startampm = '1';
958 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
959 $startampm = '2';
960 if ($starttimeh > 12) $starttimeh -= 12;
964 <html>
965 <head>
966 <?php html_header_show(); ?>
967 <title><?php echo $eid ? xlt('Edit') : xlt('Add New') ?> <?php echo xlt('Event');?></title>
968 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
969 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
971 <style>
972 td { font-size:0.8em; }
973 </style>
975 <script type="text/javascript" src="../../../library/topdialog.js?v=<?php echo $v_js_includes; ?>"></script>
976 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
977 <script type="text/javascript" src="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
978 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
980 <script language="JavaScript">
982 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
984 var durations = new Array();
985 // var rectypes = new Array();
986 <?php
987 // Read the event categories, generate their options list, and get
988 // the default event duration from them if this is a new event.
989 $cattype=0;
990 if($_GET['prov']==true){
991 $cattype=1;
993 if($_GET['group'] == true){
994 $cattype=3;
996 $cres = sqlStatement("SELECT pc_catid, pc_cattype, pc_catname, " .
997 "pc_recurrtype, pc_duration, pc_end_all_day " .
998 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
999 $catoptions = "";
1000 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
1001 $thisduration = 0;
1002 if ($eid) {
1003 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
1005 while ($crow = sqlFetchArray($cres)) {
1006 $duration = round($crow['pc_duration'] / 60);
1007 if ($crow['pc_end_all_day']) $duration = 1440;
1009 // This section is to build the list of preferred categories:
1010 if ($duration) {
1011 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
1012 if ($eid) {
1013 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
1015 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
1018 if ($crow['pc_cattype'] != $cattype) continue;
1020 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
1021 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
1022 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
1023 if ($eid) {
1024 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
1025 } else {
1026 if ($crow['pc_catid'] == $default_catid) {
1027 $catoptions .= " selected";
1028 $thisduration = $duration;
1031 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
1035 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
1037 // This is for callback by the find-patient popup.
1038 function setpatient(pid, lname, fname, dob) {
1039 var f = document.forms[0];
1040 f.form_patient.value = lname + ', ' + fname;
1041 f.form_pid.value = pid;
1042 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
1043 document.getElementById('dob_row').style.display = dobstyle;
1046 // This invokes the find-patient popup.
1047 function sel_patient() {
1048 dlgopen('find_patient_popup.php', '_blank', 500, 400);
1051 // This is for callback by the find-group popup.
1052 function setgroup(gid, name, end_date) {
1053 var f = document.forms[0];
1054 f.form_group.value = name;
1055 f.form_gid.value = gid;
1056 if(f.form_enddate.value == ""){
1057 f.form_enddate.value = end_date;
1062 // This invokes the find-group popup.
1063 function sel_group() {
1064 top.restoreSession();
1065 dlgopen('find_group_popup.php', '_blank', 500, 400);
1068 // Do whatever is needed when a new event category is selected.
1069 // For now this means changing the event title and duration.
1070 function set_display() {
1071 var f = document.forms[0];
1072 var s = f.form_category;
1073 if (s.selectedIndex >= 0) {
1074 var catid = s.options[s.selectedIndex].value;
1075 var style_apptstatus = document.getElementById('title_apptstatus').style;
1076 var style_prefcat = document.getElementById('title_prefcat').style;
1077 if (catid == '2') { // In Office
1078 style_apptstatus.display = 'none';
1079 style_prefcat.display = '';
1080 f.form_apptstatus.style.display = 'none';
1081 f.form_prefcat.style.display = '';
1082 } else {
1083 style_prefcat.display = 'none';
1084 style_apptstatus.display = '';
1085 f.form_prefcat.style.display = 'none';
1086 f.form_apptstatus.style.display = '';
1091 // Do whatever is needed when a new event category is selected.
1092 // For now this means changing the event title and duration.
1093 function set_category() {
1094 var f = document.forms[0];
1095 var s = f.form_category;
1096 if (s.selectedIndex >= 0) {
1097 var catid = s.options[s.selectedIndex].value;
1098 f.form_title.value = s.options[s.selectedIndex].text;
1099 f.form_duration.value = durations[catid];
1100 set_display();
1104 // Modify some visual attributes when the all-day or timed-event
1105 // radio buttons are clicked.
1106 function set_allday() {
1107 var f = document.forms[0];
1108 var color1 = '#777777';
1109 var color2 = '#777777';
1110 var disabled2 = true;
1111 if (document.getElementById('rballday1').checked) {
1112 color1 = '#000000';
1114 if (document.getElementById('rballday2').checked) {
1115 color2 = '#000000';
1116 disabled2 = false;
1118 document.getElementById('tdallday1').style.color = color1;
1119 document.getElementById('tdallday2').style.color = color2;
1120 document.getElementById('tdallday3').style.color = color2;
1121 document.getElementById('tdallday4').style.color = color2;
1122 document.getElementById('tdallday5').style.color = color2;
1123 f.form_hour.disabled = disabled2;
1124 f.form_minute.disabled = disabled2;
1125 f.form_ampm.disabled = disabled2;
1126 f.form_duration.disabled = disabled2;
1129 // Modify some visual attributes when the Repeat checkbox is clicked.
1130 function set_repeat() {
1131 var f = document.forms[0];
1132 var isdisabled = true;
1133 var mycolor = '#777777';
1134 var myvisibility = 'hidden';
1135 if (f.form_repeat.checked) {
1136 f.days_every_week.checked = false;
1137 document.getElementById("days_label").style.color = mycolor;
1138 var days = document.getElementById("days").getElementsByTagName('input');
1139 var labels = document.getElementById("days").getElementsByTagName('label');
1140 for(var i=0; i < days.length; i++){
1141 days[i].disabled = isdisabled;
1142 labels[i].style.color = mycolor;
1144 isdisabled = false;
1145 mycolor = '#000000';
1146 myvisibility = 'visible';
1148 f.form_repeat_type.disabled = isdisabled;
1149 f.form_repeat_freq.disabled = isdisabled;
1150 f.form_enddate.disabled = isdisabled;
1151 document.getElementById('tdrepeat1').style.color = mycolor;
1152 document.getElementById('tdrepeat2').style.color = mycolor;
1155 // Event when days_every_week is checked.
1156 function set_days_every_week() {
1157 var f = document.forms[0];
1158 if (f.days_every_week.checked) {
1159 //disable regular repeat
1160 f.form_repeat.checked = false;
1161 f.form_repeat_type.disabled = true;
1162 f.form_repeat_freq.disabled = true;
1163 document.getElementById('tdrepeat1').style.color = '#777777';
1165 //enable end_date setting
1166 document.getElementById('tdrepeat2').style.color = '#000000';
1167 f.form_enddate.disabled = false;
1169 var isdisabled = false;
1170 var mycolor = '#000000';
1171 var myvisibility = 'visible';
1173 else{
1174 var isdisabled = true;
1175 var mycolor = '#777777';
1176 var myvisibility = 'hidden';
1178 document.getElementById("days_label").style.color = mycolor;
1179 var days = document.getElementById("days").getElementsByTagName('input');
1180 var labels = document.getElementById("days").getElementsByTagName('label');
1181 for(var i=0; i < days.length; i++){
1182 days[i].disabled = isdisabled;
1183 labels[i].style.color = mycolor;
1186 //If no repetition is checked, disable end_date setting.
1187 if(!f.days_every_week.checked && !f.form_repeat.checked){
1188 //disable end_date setting
1189 document.getElementById('tdrepeat2').style.color = mycolor;
1190 f.form_enddate.disabled = isdisabled;
1196 // Constants used by dateChanged() function.
1197 var occurNames = new Array(
1198 '<?php echo xls("1st"); ?>',
1199 '<?php echo xls("2nd"); ?>',
1200 '<?php echo xls("3rd"); ?>',
1201 '<?php echo xls("4th"); ?>'
1204 var weekDays = new Array(
1205 '<?php echo xls("Sunday"); ?>',
1206 '<?php echo xls("Monday"); ?>',
1207 '<?php echo xls("Tuesday"); ?>',
1208 '<?php echo xls("Wednesday"); ?>',
1209 '<?php echo xls("Thursday"); ?>',
1210 '<?php echo xls("Friday"); ?>',
1211 '<?php echo xls("Saturday"); ?>'
1214 // Monitor start date changes to adjust repeat type options.
1215 function dateChanged() {
1216 var f = document.forms[0];
1217 if (!f.form_date.value) return;
1218 var d = new Date(f.form_date.value);
1219 var downame = weekDays[d.getUTCDay()];
1220 var nthtext = '';
1221 var occur = Math.floor((d.getUTCDate() - 1) / 7);
1222 if (occur < 4) { // 5th is not allowed
1223 nthtext = occurNames[occur] + ' ' + downame;
1225 var lasttext = '';
1226 var tmp = new Date(d.getUTCFullYear(), d.getUTCMonth() + 1, 0);
1227 if (tmp.getDate() - d.getUTCDate() < 7) { // Modified by epsdky 2016 (details in commit)
1228 // This is a last occurrence of the specified weekday in the month,
1229 // so permit that as an option.
1230 lasttext = '<?php echo xls("Last"); ?> ' + downame;
1232 var si = f.form_repeat_type.selectedIndex;
1233 var opts = f.form_repeat_type.options;
1234 opts.length = 5; // remove any nth and Last entries
1235 if (nthtext ) opts[opts.length] = new Option(nthtext , '5');
1236 if (lasttext) opts[opts.length] = new Option(lasttext, '6');
1237 if (si < opts.length) f.form_repeat_type.selectedIndex = si;
1238 else f.form_repeat_type.selectedIndex = 5; // Added by epsdky 2016 (details in commit)
1241 // This is for callback by the find-available popup.
1242 function setappt(year,mon,mday,hours,minutes) {
1243 var f = document.forms[0];
1244 f.form_date.value = '' + year + '-' +
1245 ('' + (mon + 100)).substring(1) + '-' +
1246 ('' + (mday + 100)).substring(1);
1247 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
1248 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
1249 f.form_minute.value = ('' + (minutes + 100)).substring(1);
1252 // Invoke the find-available popup.
1253 function find_available(extra) {
1254 top.restoreSession();
1255 // (CHEMED) Conditional value selection, because there is no <select> element
1256 // when making an appointment for a specific provider
1257 var s = document.forms[0].form_provider;
1258 var f = document.forms[0].facility;
1259 <?php if ($userid != 0) { ?>
1260 s = document.forms[0].form_provider.value;
1261 f = document.forms[0].facility.value;
1262 <?php } else {?>
1263 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1264 f = document.forms[0].facility.options[f.selectedIndex].value;
1265 <?php }?>
1266 var c = document.forms[0].form_category;
1267 var formDate = document.forms[0].form_date;
1268 dlgopen('<?php echo $GLOBALS['web_root']; ?>/interface/main/calendar/find_appt_popup.php' +
1269 '?providerid=' + s +
1270 '&catid=' + c.options[c.selectedIndex].value +
1271 '&facility=' + f +
1272 '&startdate=' + formDate.value +
1273 '&evdur=' + document.forms[0].form_duration.value +
1274 '&eid=<?php echo 0 + $eid; ?>' +
1275 extra,
1276 '_blank', 500, 400);
1281 </script>
1283 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1285 </head>
1287 <body class="body_top main-calendar-add_edit_event" onunload='imclosing()'>
1289 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1290 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1291 <input type='hidden' size='2' name='resname' value='empty' />
1292 <?php
1293 if ($_POST["resname"]=="noresult"){
1294 echo '
1295 <script language="Javascript">
1296 // refresh and redirect the parent window
1297 if (!opener.closed && opener.refreshme) opener.refreshme();
1298 top.restoreSession();
1299 opener.document.location="../../new/new.php";
1300 // Close the window
1301 window.close();
1302 </script>';
1304 $classprov='current';
1305 $classpati='';
1307 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1308 <input type="hidden" name="form_action" id="form_action" value="">
1309 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1310 <!-- used for recurring events -->
1311 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo attr($date); ?>">
1312 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo attr($eventstartdate); ?>">
1313 <!-- Following added by epsdky 2016 (details in commit) -->
1314 <input type="hidden" name="old_repeats" id="old_repeats" value="<?php echo attr($repeats); ?>">
1315 <input type="hidden" name="rt2_flag2" id="rt2_flag2" value="<?php echo attr(isset($rspecs['rt2_pf_flag']) ? $rspecs['rt2_pf_flag'] : '0'); ?>">
1316 <!-- End of addition by epsdky -->
1317 <center>
1318 <table border='0' >
1319 <?php
1320 $provider_class='';
1321 $group_class='';
1322 $normal='';
1323 if($_GET['prov']==true){
1324 $provider_class="class='current'";
1326 elseif($_GET['group']==true){
1327 $group_class="class='current'";
1329 else{
1330 $normal="class='current'";
1333 <tr><th><ul class="tabNav">
1334 <?php
1335 $eid=$_REQUEST["eid"];
1336 $startm=$_REQUEST["startampm"];
1337 $starth=$_REQUEST["starttimeh"];
1338 $uid=$_REQUEST["userid"];
1339 $starttm=$_REQUEST["starttimem"];
1340 $dt=$_REQUEST["date"];
1341 $cid=$_REQUEST["catid"];
1343 <li <?php echo $normal;?>>
1344 <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);?>'>
1345 <?php echo xlt('Patient');?></a>
1346 </li>
1347 <li <?php echo $provider_class;?>>
1348 <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);?>'>
1349 <?php echo xlt('Provider');?></a>
1350 </li>
1351 <?php if($GLOBALS['enable_group_therapy']) :?>
1352 <li <?php echo $group_class ;?>>
1353 <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);?>'>
1354 <?php echo xlt('Group');?></a>
1355 </li>
1356 <?php endif ?>
1357 </ul>
1358 </th></tr>
1359 <tr><td colspan='10'>
1360 <table border='0' width='100%' bgcolor='#DDDDDD'>
1361 <tr>
1362 <td width='1%' nowrap>
1363 <b><?php echo xlt('Category'); ?>:</b>
1364 </td>
1365 <td nowrap>
1366 <select name='form_category' onchange='set_category()' style='width:100%'>
1367 <?php echo $catoptions ?>
1368 </select>
1369 </td>
1370 <td width='1%' nowrap>
1371 &nbsp;&nbsp;
1372 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1373 <?php if ($thisduration == 1440) echo "checked " ?>/>
1374 </td>
1375 <td colspan='2' nowrap id='tdallday1'>
1376 <?php echo xlt('All day event'); ?>
1377 </td>
1378 </tr>
1379 <tr>
1380 <td nowrap>
1381 <b><?php echo xlt('Date'); ?>:</b>
1382 </td>
1383 <td nowrap>
1384 <input type='text' size='10' class='datepicker' name='form_date' id='form_date'
1385 value='<?php echo attr($date) ?>'
1386 title='<?php echo xla('yyyy-mm-dd event date or starting date'); ?>'
1387 onchange='dateChanged()' />
1388 </td>
1389 <td nowrap>
1390 &nbsp;&nbsp;
1391 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1392 </td>
1393 <td width='1%' nowrap id='tdallday2'>
1394 <?php echo xlt('Time'); ?>
1395 </td>
1396 <td width='1%' nowrap id='tdallday3'>
1397 <span>
1398 <input type='text' size='2' name='form_hour' value='<?php echo attr($starttimeh) ?>'
1399 title='<?php echo xla('Event start time'); ?>' /> :
1400 <input type='text' size='2' name='form_minute' value='<?php echo attr($starttimem) ?>'
1401 title='<?php echo xla('Event start time'); ?>' />&nbsp;
1402 </span>
1403 <select name='form_ampm' title='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1404 <option value='1'><?php echo xlt('AM'); ?></option>
1405 <option value='2'<?php if ($startampm == '2') echo " selected" ?>><?php echo xlt('PM'); ?></option>
1406 </select>
1407 </td>
1408 </tr>
1409 <tr>
1410 <td nowrap>
1411 <b><?php echo xlt('Title'); ?>:</b>
1412 </td>
1413 <td nowrap>
1414 <input type='text' size='10' name='form_title' value='<?php echo attr($row['pc_title']); ?>'
1415 style='width:100%'
1416 title='<?php echo xla('Event title'); ?>' />
1417 </td>
1418 <td nowrap>&nbsp;
1420 </td>
1421 <td nowrap id='tdallday4'><?php echo xlt('duration'); ?>
1422 </td>
1423 <td nowrap id='tdallday5'>
1424 <input type='text' size='4' name='form_duration' value='<?php echo attr($thisduration) ?>' title='<?php echo xla('Event duration in minutes'); ?>' />
1425 <?php echo xlt('minutes'); ?>
1426 </td>
1427 </tr>
1429 <tr>
1430 <td nowrap><b><?php echo xlt('Facility'); ?>:</b></td>
1431 <td>
1432 <select name="facility" id="facility" >
1433 <?php
1435 // ===========================
1436 // EVENTS TO FACILITIES
1437 //(CHEMED) added service_location WHERE clause
1438 // get the facilities
1439 /***************************************************************
1440 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1441 ***************************************************************/
1442 $facils = getUserFacilities($_SESSION['authId']);
1443 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1444 /**************************************************************/
1445 while ($facrow = sqlFetchArray($qsql)) {
1446 /*************************************************************
1447 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1448 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1449 *************************************************************/
1450 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1451 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1452 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1454 else{
1455 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1456 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1458 /************************************************************/
1460 // EOS E2F
1461 // ===========================
1463 <?php
1464 //END (CHEMED) IF ?>
1465 </td>
1466 </select>
1467 </tr>
1468 <tr>
1469 <td nowrap>
1470 <b><?php echo xlt('Billing Facility'); ?>:</b>
1471 </td>
1472 <td>
1473 <?php
1474 billing_facility('billing_facility',$row['pc_billing_location']);
1476 </td>
1477 </tr>
1478 <?php
1479 if($_GET['prov']!=true && $_GET['group']!=true){
1481 <tr id="patient_details">
1482 <td nowrap>
1483 <b><?php echo xlt('Patient'); ?>:</b>
1484 </td>
1485 <td nowrap>
1486 <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 />
1487 <input type='hidden' name='form_pid' value='<?php echo attr($patientid) ?>' />
1488 </td>
1489 <td colspan='3' nowrap style='font-size:8pt'>
1490 <span class="infobox">
1491 <?php foreach($patienttitle as $value){
1492 if ($value != "") {
1493 echo text(trim($value));
1496 if(count($patienttitle) > 1){
1497 echo "<br />";
1501 </span>
1502 </td>
1503 </tr>
1504 <?php
1507 <?php
1508 if($_GET['group']==true){
1510 <tr id="group_details">
1511 <td nowrap>
1512 <b><?php echo xlt('Group'); ?>:</b>
1513 </td>
1514 <td nowrap>
1515 <input 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 />
1516 <input type='hidden' name='form_gid' value='<?php echo attr($groupid) ?>' />
1517 </td>
1518 <td colspan='3' nowrap style='font-size:8pt'>
1519 <span class="infobox">
1520 <?php foreach($patienttitle as $value){
1521 if ($value != "") {
1522 echo trim($value);
1525 if(count($patienttitle) > 1){
1526 echo "<br />";
1530 </span>
1531 </td>
1532 </tr>
1533 <?php
1536 <tr>
1537 <td nowrap>
1538 <b><?php if($_GET['group']==true) echo xlt('Coordinating Counselors'); else echo xlt('Provider'); ?>:</b>
1539 </td>
1540 <td nowrap>
1542 <?php
1544 // =======================================
1545 // multi providers
1546 // =======================================
1547 if ($GLOBALS['select_multi_providers']) {
1549 // there are two posible situations: edit and new record
1550 $providers_array = array();
1551 // this is executed only on edit ($eid)
1552 if ($eid) {
1553 if ( $multiple_value ) {
1554 // find all the providers around multiple key
1555 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value) );
1556 while ($r = sqlFetchArray($qall)) {
1557 $providers_array[] = $r['providers'];
1559 } else {
1560 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1561 $providers_array = sqlFetchArray($qall);
1565 // build the selection tool
1566 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1568 while ($urow = sqlFetchArray($ures)) {
1569 echo " <option value='" . attr($urow['id']) . "'";
1571 if ($userid) {
1572 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1575 echo ">" . text($urow['lname']);
1576 if ($urow['fname']) echo ", " . text($urow['fname']);
1577 echo "</option>\n";
1580 echo '</select>';
1582 // =======================================
1583 // single provider
1584 // =======================================
1585 } else {
1587 if ($eid) {
1588 // get provider from existing event
1589 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1590 $provider = sqlFetchArray($qprov);
1591 $defaultProvider = $provider['pc_aid'];
1593 else {
1594 // this is a new event so smartly choose a default provider
1595 /*****************************************************************
1596 if ($userid) {
1597 // Provider already given to us as a GET parameter.
1598 $defaultProvider = $userid;
1600 else {
1601 // default to the currently logged-in user
1602 $defaultProvider = $_SESSION['authUserID'];
1603 // or, if we have chosen a provider in the calendar, default to them
1604 // choose the first one if multiple have been selected
1605 if (count($_SESSION['pc_username']) >= 1) {
1606 // get the numeric ID of the first provider in the array
1607 $pc_username = $_SESSION['pc_username'];
1608 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1609 $defaultProvider = $firstProvider['id'];
1614 echo "<select name='form_provider' style='width:100%' />";
1615 while ($urow = sqlFetchArray($ures)) {
1616 echo " <option value='" . $urow['id'] . "'";
1617 if ($urow['id'] == $defaultProvider) echo " selected";
1618 echo ">" . $urow['lname'];
1619 if ($urow['fname']) echo ", " . $urow['fname'];
1620 echo "</option>\n";
1622 echo "</select>";
1623 *****************************************************************/
1624 // default to the currently logged-in user
1625 $defaultProvider = $_SESSION['authUserID'];
1626 // or, if we have chosen a provider in the calendar, default to them
1627 // choose the first one if multiple have been selected
1628 if (count($_SESSION['pc_username']) >= 1) {
1629 // get the numeric ID of the first provider in the array
1630 $pc_username = $_SESSION['pc_username'];
1631 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0]) ));
1632 $defaultProvider = $firstProvider['id'];
1634 // if we clicked on a provider's schedule to add the event, use THAT.
1635 if ($userid) $defaultProvider = $userid;
1637 echo "<select name='form_provider' style='width:100%' />";
1638 while ($urow = sqlFetchArray($ures)) {
1639 echo " <option value='" . attr($urow['id']) . "'";
1640 if ($urow['id'] == $defaultProvider) echo " selected";
1641 echo ">" . text($urow['lname']);
1642 if ($urow['fname']) echo ", " . text($urow['fname']);
1643 echo "</option>\n";
1645 echo "</select>";
1646 /****************************************************************/
1651 </td>
1652 <td nowrap>
1653 &nbsp;&nbsp;
1654 <?php
1655 //Check if repeat is using the new 'days every week' mechanism.
1656 function isDaysEveryWeek($repeat){
1657 if($repeat == 3){
1658 return true;
1660 else{
1661 return false;
1665 //Check if using the regular repeat mechanism.
1666 function isRegularRepeat($repeat){
1667 if($repeat == 1 || $repeat == 2){
1668 return true;
1670 else{
1671 return false;
1677 If the appointment was set with the regular (old) repeat mechanism (using 'every', 'every 2', etc.), then will be
1678 checked when editing and will select the proper recurrence pattern. If using the new repeat mechanism, then only that box (and the proper set
1679 days) will be checked. That's why I had to add the functions 'isRegularRepeat' and 'isDaysEveryWeek', to check which
1680 repeating mechanism is being used, and load settings accordingly.
1683 <input type='checkbox' name='form_repeat' id="form_repeat" onclick='set_repeat(this)' value='1'<?php if (isRegularRepeat($repeats)) echo " checked" ?>/>
1684 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat -->
1685 </td>
1686 <td nowrap id='tdrepeat1'><?php echo xlt('Repeats'); ?>
1687 </td>
1688 <td nowrap>
1690 <select name='form_repeat_freq' title='<?php echo xla('Every, every other, every 3rd, etc.'); ?>'>
1691 <?php
1692 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1693 as $key => $value)
1695 echo " <option value='" . attr($key) . "'";
1696 if ($key == $repeatfreq && isRegularRepeat($repeats)) echo " selected";
1697 echo ">" . text($value) . "</option>\n";
1700 </select>
1702 <select name='form_repeat_type'>
1703 <?php
1704 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1705 // when the start date is set.
1706 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1707 5 => '?', 6 => '?') as $key => $value)
1709 echo " <option value='" . attr($key) . "'";
1710 if ($key == $repeattype && isRegularRepeat($repeats)) echo " selected";
1711 echo ">" . text($value) . "</option>\n";
1714 </select>
1716 </td>
1717 </tr>
1719 <style>
1720 #days_every_week_row input[type="checkbox"]{float:right;}
1721 #days_every_week_row div{display: inline-block; text-align: center; width: 12%;}
1722 #days_every_week_row div input{width: 100%;}
1723 </style>
1725 <tr id="days_every_week_row">
1726 <td></td>
1727 <td></td>
1728 <td><input type='checkbox' id='days_every_week' name='days_every_week' onclick='set_days_every_week()' <?php if (isDaysEveryWeek($repeats)) echo " checked" ?>/></td>
1729 <td id="days_label"><?php echo xlt('Days Of Week') . ": "; ?></td>
1730 <td id="days">
1731 <?php
1732 foreach (array(1 => xl('Su{{Sunday}}') , 2 => xl('Mo{{Monday}}'), 3 => xl('Tu{{Tuesday}}'), 4 => xl('We{{Wednesday}}'),
1733 5 => xl('Th{{Thursday}}'), 6 => xl('Fr{{Friday}}'), 7 => xl('Sa{{Saturday}}')) as $key => $value)
1735 echo " <div><input type='checkbox' name='day_". attr($key) ."'";
1736 //Checks appropriate days according to days in recurrence string.
1737 if (in_array($key, explode(',',$repeatfreq)) && isDaysEveryWeek($repeats)) echo " checked";
1738 echo " /><label>" . text($value) . "</label></div>\n";
1741 </td>
1743 </tr>
1746 <tr>
1747 <td nowrap>
1748 <span id='title_apptstatus'><b><?php echo xlt('Status'); ?>:</b></span>
1749 <span id='title_prefcat' style='display:none'><b><?php echo xlt('Pref Cat'); ?>:</b></span>
1750 </td>
1751 <td nowrap>
1753 <?php
1754 if($_GET['group']!=true) {
1755 generate_form_field(array('data_type' => 1, 'field_id' => 'apptstatus', 'list_id' => 'apptstat', 'empty_title' => 'SKIP'), $row['pc_apptstatus']);
1757 else{
1758 generate_form_field(array('data_type' => 1, 'field_id' => 'apptstatus', 'list_id' => 'groupstat', 'empty_title' => 'SKIP'), $row['pc_apptstatus']);
1762 <!--
1763 The following list will be invisible unless this is an In Office
1764 event, in which case form_apptstatus (above) is to be invisible.
1766 <select name='form_prefcat' style='width:100%;display:none' title='<?php echo xla('Preferred Event Category');?>'>
1767 <?php echo $prefcat_options ?>
1768 </select>
1770 </td>
1771 <td nowrap>&nbsp;
1773 </td>
1774 <td nowrap id='tdrepeat2'><?php echo xlt('until'); ?>
1775 </td>
1776 <td nowrap>
1777 <input type='text' size='10' class='datepicker' name='form_enddate' id='form_enddate' value='<?php echo attr($recurrence_end_date) ?>' title='<?php echo xla('yyyy-mm-dd last date of this event');?>' />
1778 <?php
1779 if ($repeatexdate != "") {
1780 $tmptitle = "The following dates are excluded from the repeating series";
1781 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1782 else { $tmptitle .= "\n"; }
1783 $max = $GLOBALS['number_of_ex_appts_to_show'];
1785 $exdates = explode(",", $repeatexdate);
1786 if(!empty($exdates)){
1787 $exdates=array_slice($exdates,0,$max,true);
1789 foreach ($exdates as $exdate) {
1790 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1792 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1795 </td>
1796 </tr>
1797 <?php
1798 if($_GET['prov']!=true){
1800 <tr>
1801 <td nowrap>
1802 <b><?php echo xlt('Room Number'); ?>:</b>
1803 </td>
1804 <td colspan='4' nowrap>
1805 <?php
1806 echo generate_select_list('form_room', 'patient_flow_board_rooms',$pcroom, xl('Room Number'));
1808 </td>
1809 </tr>
1810 <?php } ?>
1811 <tr>
1812 <td nowrap>
1813 <b><?php echo xlt('Comments'); ?>:</b>
1814 </td>
1815 <td colspan='4' nowrap>
1816 <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');?>' />
1817 </td>
1818 </tr>
1821 <?php
1822 // DOB is important for the clinic, so if it's missing give them a chance
1823 // to enter it right here. We must display or hide this row dynamically
1824 // in case the patient-select popup is used.
1825 $patient_dob = trim($prow['DOB']);
1826 $is_group = $groupname;
1827 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00') && !$is_group) ?
1828 '' : 'none';
1830 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1831 <td colspan='4' nowrap>
1832 <b><font color='red'><?php echo xlt('DOB is missing, please enter if possible'); ?>:</font></b>
1833 </td>
1834 <td nowrap>
1835 <input type='text' size='10' class='datepicker' name='form_dob' id='form_dob' title='<?php echo xla('yyyy-mm-dd date of birth');?>' />
1836 </td>
1837 </tr>
1839 </table></td></tr>
1840 <tr class='text'><td colspan='10' class="buttonbar">
1842 <input type='button' name='form_save' id='form_save' value='<?php echo xla('Save');?>' />
1843 &nbsp;
1845 <?php if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1846 <input type='button' id='find_available' value='<?php echo xla('Find Available');?>' />
1847 <?php } ?>
1849 &nbsp;
1850 <input type='button' name='form_delete' id='form_delete' value='<?php echo xla('Delete');?>'<?php if (!$eid) echo " disabled" ?> />
1851 &nbsp;
1852 <input type='button' id='cancel' value='<?php echo xla('Cancel');?>' />
1853 &nbsp;
1854 <input type='button' name='form_duplicate' id='form_duplicate' value='<?php echo xla('Create Duplicate');?>' />
1855 </p></td></tr></table>
1856 <?php if ($informant) echo "<p class='text'>" . xlt('Last update by') . " " .
1857 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n"; ?>
1858 </center>
1859 </form>
1861 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1862 <?php echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?>
1863 <br>
1864 <?php if($GLOBALS['submit_changes_for_all_appts_at_once']) {?>
1865 <input type="button" name="all_events" id="all_events" value=" <?php echo xla('All'); ?> ">
1866 <?php } ?>
1867 <input type="button" name="future_events" id="future_events" value="<?php echo xla('Future'); ?>">
1868 <input type="button" name="current_event" id="current_event" value="<?php echo xla('Current'); ?>">
1869 <input type="button" name="recurr_cancel" id="recurr_cancel" value="<?php echo xla('Cancel'); ?>">
1870 </div>
1872 </body>
1874 <script language='JavaScript'>
1875 <?php if ($eid) { ?>
1876 set_display();
1877 <?php } else { ?>
1878 set_category();
1879 <?php } ?>
1880 set_allday();
1881 set_repeat();
1882 set_days_every_week();
1884 </script>
1886 <script language="javascript">
1887 // jQuery stuff to make the page a little easier to use
1889 $(document).ready(function(){
1890 $("#form_save").click(function(e) { validateform(e,"save"); });
1891 $("#form_duplicate").click(function(e) { validateform(e,"duplicate"); });
1892 $("#find_available").click(function() { find_available(''); });
1893 $("#form_delete").click(function() { deleteEvent(); });
1894 $("#cancel").click(function() { window.close(); });
1896 // buttons affecting the modification of a repeating event
1897 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1898 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1899 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1900 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1902 // Initialize repeat options.
1903 dateChanged();
1905 $('.datepicker').datetimepicker({
1906 <?php $datetimepicker_timepicker = false; ?>
1907 <?php $datetimepicker_showseconds = false; ?>
1908 <?php $datetimepicker_formatInput = false; ?>
1909 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
1910 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
1915 function are_days_checked(){
1916 var days = document.getElementById("days").getElementsByTagName('input');
1917 var counter = 0;
1918 for(var i=0; i < days.length; i++){
1919 if(days[i].checked){
1920 counter++;
1923 return counter;
1927 * validation on the form with new client side validation (using validate.js).
1928 * this enable to add new rules for this form in the pageValidation list.
1929 * */
1930 var collectvalidation = <?php echo($collectthis); ?>;
1931 function validateform(event,valu){
1933 $('#form_save').attr('disabled', true);
1935 //Make sure if days_every_week is checked that at least one weekday is checked.
1936 if($('#days_every_week').is(':checked') && !are_days_checked()){
1937 alert('<?php echo xls("Must choose at least one day!"); ?>');
1938 $('#form_save').attr('disabled', false);
1939 return false;
1942 //add rule if choose repeating event
1943 if ($('#form_repeat').is(':checked') || $('#days_every_week').is(':checked')){
1944 collectvalidation.form_enddate = {
1945 datetime: {
1946 dateOnly: true,
1947 earliest: $('#form_date').val(),
1948 message: "An end date later than the start date is required for repeated events!"
1950 presence: true
1952 } else {
1953 if(typeof (collectvalidation) != 'undefined'){
1954 delete collectvalidation.form_enddate;
1959 <?php
1960 if($GLOBALS['select_multi_providers']){
1962 //If multiple providers is enabled, create provider validation (Note: if no provider is chosen it causes bugs when deleting recurrent events).
1963 collectvalidation.form_provider = {presence: true};
1964 <?php
1969 var submit = submitme(1, event, 'theform', collectvalidation);
1970 if(!submit)return $('#form_save').attr('disabled', false);
1972 $('#form_action').val(valu);
1974 <?php if ($repeats): ?>
1975 // existing repeating events need additional prompt
1976 if ($("#recurr_affect").val() == "") {
1977 DisableForm();
1978 // show the current/future/all DIV for the user to choose one
1979 $("#recurr_popup").css("visibility", "visible");
1980 $('#form_save').attr('disabled', false);
1981 return false;
1983 <?php endif; ?>
1985 SubmitForm();
1989 // disable all the form elements outside the recurr_popup
1990 function DisableForm() {
1991 $("#theform").children().attr("disabled", "true");
1993 function EnableForm() {
1994 $("#theform").children().removeAttr("disabled");
1996 // hide the recurring popup DIV
1997 function HideRecurrPopup() {
1998 $("#recurr_popup").css("visibility", "hidden");
2001 function deleteEvent() {
2002 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?')); ?>")) {
2003 $('#form_action').val("delete");
2005 <?php if ($repeats): ?>
2006 // existing repeating events need additional prompt
2007 if ($("#recurr_affect").val() == "") {
2008 DisableForm();
2009 // show the current/future/all DIV for the user to choose one
2010 $("#recurr_popup").css("visibility", "visible");
2011 return false;
2013 <?php endif; ?>
2015 return SubmitForm();
2017 return false;
2020 function SubmitForm() {
2021 var f = document.forms[0];
2022 <?php if (!($GLOBALS['select_multi_providers'])) { // multi providers appt is not supported by check slot avail window, so skip ?>
2023 if (f.form_action.value != 'delete') {
2024 // Check slot availability.
2025 var mins = parseInt(f.form_hour.value) * 60 + parseInt(f.form_minute.value);
2026 if (f.form_ampm.value == '2' && mins < 720) mins += 720;
2027 find_available('&cktime=' + mins);
2029 else {
2030 top.restoreSession();
2031 f.submit();
2033 <?php } else { ?>
2034 top.restoreSession();
2035 f.submit();
2036 <?php } ?>
2038 return true;
2041 </script>
2043 </html>