PHP7 project, commit 1.
[openemr.git] / interface / main / calendar / add_edit_event.php
blobedc41046758ed43a366b8ad708735926067e6b43
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.
8 * Copyright (C) 2005-2013 Rod Roark <rod@sunsetsystems.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * @package OpenEMR
16 * @author Rod Roark <rod@sunsetsystems.com>
17 * @link http://www.open-emr.org
20 // The event editor looks something like this:
22 //------------------------------------------------------------//
23 // Category __________________V O All day event //
24 // Date _____________ [?] O Time ___:___ __V //
25 // Title ___________________ duration ____ minutes //
26 // Patient _(Click_to_select)_ //
27 // Provider __________________V X Repeats ______V ______V //
28 // Status __________________V until __________ [?] //
29 // Comments ________________________________________________ //
30 // //
31 // [Save] [Find Available] [Delete] [Cancel] //
32 //------------------------------------------------------------//
34 $fake_register_globals=false;
35 $sanitize_all_escapes=true;
37 require_once('../../globals.php');
38 require_once($GLOBALS['srcdir'].'/patient.inc');
39 require_once($GLOBALS['srcdir'].'/forms.inc');
40 require_once($GLOBALS['srcdir'].'/calendar.inc');
41 require_once($GLOBALS['srcdir'].'/options.inc.php');
42 require_once($GLOBALS['srcdir'].'/encounter_events.inc.php');
43 require_once($GLOBALS['srcdir'].'/acl.inc');
44 require_once($GLOBALS['srcdir'].'/patient_tracker.inc.php');
46 //Check access control
47 if (!acl_check('patients','appt','',array('write','wsome') ))
48 die(xl('Access not allowed'));
50 /* Things that might be passed by our opener. */
51 $eid = $_GET['eid']; // only for existing events
52 $date = $_GET['date']; // this and below only for new events
53 $userid = $_GET['userid'];
54 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
56 if ($date)
57 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
58 else
59 $date = date("Y-m-d");
61 $starttimem = '00';
62 if (isset($_GET['starttimem']))
63 $starttimem = substr('00' . $_GET['starttimem'], -2);
65 if (isset($_GET['starttimeh'])) {
66 $starttimeh = $_GET['starttimeh'];
67 if (isset($_GET['startampm'])) {
68 if ($_GET['startampm'] == '2' && $starttimeh < 12)
69 $starttimeh += 12;
71 } else {
72 $starttimeh = date("G");
74 $startampm = '';
76 $info_msg = "";
80 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
82 <?php
84 function InsertEventFull()
86 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
87 // =======================================
88 // multi providers case
89 // =======================================
90 if (is_array($_POST['form_provider'])) {
92 // obtain the next available unique key to group multiple providers around some event
93 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
94 $max = sqlFetchArray($q);
95 $new_multiple_value = $max['max'] + 1;
97 foreach ($_POST['form_provider'] as $provider) {
98 $args = $_POST;
99 // specify some special variables needed for the INSERT
100 $args['new_multiple_value'] = $new_multiple_value;
101 $args['form_provider'] = $provider;
102 $args['event_date'] = $event_date;
103 $args['duration'] = $duration * 60;
104 $args['recurrspec'] = $recurrspec;
105 $args['starttime'] = $starttime;
106 $args['endtime'] = $endtime;
107 $args['locationspec'] = $locationspec;
108 InsertEvent($args);
111 // ====================================
112 // single provider
113 // ====================================
114 } else {
115 $args = $_POST;
116 // specify some special variables needed for the INSERT
117 $args['new_multiple_value'] = "";
118 $args['event_date'] = $event_date;
119 $args['duration'] = $duration * 60;
120 $args['recurrspec'] = $recurrspec;
121 $args['starttime'] = $starttime;
122 $args['endtime'] = $endtime;
123 $args['locationspec'] = $locationspec;
124 InsertEvent($args);
127 function DOBandEncounter()
129 global $event_date,$info_msg;
130 // Save new DOB if it's there.
131 $patient_dob = trim($_POST['form_dob']);
132 $tmph = $_POST['form_hour'] + 0;
133 $tmpm = $_POST['form_minute'] + 0;
134 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
135 $appttime = "$tmph:$tmpm:00";
137 if ($patient_dob && $_POST['form_pid']) {
138 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
139 "pid = ?", array($patient_dob,$_POST['form_pid']) );
142 // Manage tracker status.
143 // And auto-create a new encounter if appropriate.
144 if (!empty($_POST['form_pid'])) {
145 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']))
147 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
148 if($encounter){
149 $info_msg .= xl("New encounter created with id");
150 $info_msg .= " $encounter";
152 # Capture the appt status and room number for patient tracker. This will map the encounter to it also.
153 if ( isset($GLOBALS['temporary-eid-for-manage-tracker']) || !empty($_GET['eid']) ) {
154 // Note that the temporary-eid-for-manage-tracker is used to capture the eid for new appointments and when separate a recurring
155 // appointment. It is set in the InsertEvent() function. Note that in the case of spearating a recurrent appointment, the get eid
156 // parameter is actually erroneous(is eid of the recurrent appt and not the new separated appt), so need to use the
157 // temporary-eid-for-manage-tracker global instead.
158 $temp_eid = (isset($GLOBALS['temporary-eid-for-manage-tracker'])) ? $GLOBALS['temporary-eid-for-manage-tracker'] : $_GET['eid'];
159 manage_tracker_status($event_date,$appttime,$temp_eid,$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room'],$encounter);
162 else
164 # Capture the appt status and room number for patient tracker.
165 if (!empty($_GET['eid'])) {
166 manage_tracker_status($event_date,$appttime,$_GET['eid'],$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room']);
172 //================================================================================================================
174 // EVENTS TO FACILITIES (lemonsoftware)
175 //(CHEMED) get facility name
176 // edit event case - if there is no association made, then insert one with the first facility
177 if ( $eid ) {
178 $selfacil = '';
179 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
180 FROM openemr_postcalendar_events
181 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
182 WHERE pc_eid = ?", array($eid) );
183 // if ( !$facility['pc_facility'] ) {
184 if ( is_array($facility) && !$facility['pc_facility'] ) {
185 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']) );
186 $min = $qmin['minId'];
187 $min_name = $qmin['facility'];
189 // multiple providers case
190 if ( $GLOBALS['select_multi_providers'] ) {
191 $mul = $facility['pc_multiple'];
192 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min,$mul) );
194 // EOS multiple
196 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min,$eid) );
197 $e2f = $min;
198 $e2f_name = $min_name;
199 } else {
200 // not edit event
201 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
202 $e2f = $_SESSION['pc_facility'];
203 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
204 $e2f = $_COOKIE['pc_facility'];
205 } else {
206 $e2f = $facility['pc_facility'];
207 $e2f_name = $facility['name'];
211 // EOS E2F
212 // ===========================
213 //=============================================================================================================================
214 if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
216 // the starting date of the event, pay attention with this value
217 // when editing recurring events -- JRM Oct-08
218 $event_date = fixDate($_POST['form_date']);
220 // Compute start and end time strings to be saved.
221 if ($_POST['form_allday']) {
222 $tmph = 0;
223 $tmpm = 0;
224 $duration = 24 * 60;
225 } else {
226 $tmph = $_POST['form_hour'] + 0;
227 $tmpm = $_POST['form_minute'] + 0;
228 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
229 $duration = abs($_POST['form_duration']); // fixes #395
231 $starttime = "$tmph:$tmpm:00";
233 $tmpm += $duration;
234 while ($tmpm >= 60) {
235 $tmpm -= 60;
236 ++$tmph;
238 $endtime = "$tmph:$tmpm:00";
240 // Set up working variables related to repeated events.
241 $my_recurrtype = 0;
242 $my_repeat_freq = 0 + $_POST['form_repeat_freq'];
243 $my_repeat_type = 0 + $_POST['form_repeat_type'];
244 $my_repeat_on_num = 1;
245 $my_repeat_on_day = 0;
246 $my_repeat_on_freq = 0;
247 if (!empty($_POST['form_repeat'])) {
248 $my_recurrtype = 1;
249 if ($my_repeat_type > 4) {
250 $my_recurrtype = 2;
251 $time = strtotime($event_date);
252 $my_repeat_on_day = 0 + date('w', $time);
253 $my_repeat_on_freq = $my_repeat_freq;
254 if ($my_repeat_type == 5) {
255 $my_repeat_on_num = intval((date('j', $time) - 1) / 7) + 1;
257 else {
258 // Last occurence of this weekday on the month
259 $my_repeat_on_num = 5;
261 // Maybe not needed, but for consistency with postcalendar:
262 $my_repeat_freq = 0;
263 $my_repeat_type = 0;
267 // Useless garbage that we must save.
268 $locationspecs = array("event_location" => "",
269 "event_street1" => "",
270 "event_street2" => "",
271 "event_city" => "",
272 "event_state" => "",
273 "event_postal" => ""
275 $locationspec = serialize($locationspecs);
277 // capture the recurring specifications
278 $recurrspec = array("event_repeat_freq" => "$my_repeat_freq",
279 "event_repeat_freq_type" => "$my_repeat_type",
280 "event_repeat_on_num" => "$my_repeat_on_num",
281 "event_repeat_on_day" => "$my_repeat_on_day",
282 "event_repeat_on_freq" => "$my_repeat_on_freq",
283 "exdate" => $_POST['form_repeat_exdate']
286 // no recurr specs, this is used for adding a new non-recurring event
287 $noRecurrspec = array("event_repeat_freq" => "",
288 "event_repeat_freq_type" => "",
289 "event_repeat_on_num" => "1",
290 "event_repeat_on_day" => "0",
291 "event_repeat_on_freq" => "0",
292 "exdate" => ""
295 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
296 //=============================================================================================================================
297 if ($_POST['form_action'] == "duplicate") {
299 InsertEventFull();
300 DOBandEncounter();
304 // If we are saving, then save and close the window.
306 if ($_POST['form_action'] == "save") {
307 /* =======================================================
308 * UPDATE EVENTS
309 * =====================================================*/
310 if ($eid) {
312 // what is multiple key around this $eid?
313 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
315 // ====================================
316 // multiple providers
317 // ====================================
318 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
320 // obtain current list of providers regarding the multiple key
321 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
322 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
324 // get the new list of providers from the submitted form
325 $providers_new = $_POST['form_provider'];
327 // ===== Only current event of repeating series =====
328 if ($_POST['recurr_affect'] == 'current') {
330 // update all existing event records to exlude the current date
331 foreach ($providers_current as $provider) {
332 // update the provider's original event
333 // get the original event's repeat specs
334 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
335 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
336 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
337 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
338 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
339 else { $oldRecurrspec['exdate'] .= $selected_date; }
341 // mod original event recur specs to exclude this date
342 sqlStatement("UPDATE openemr_postcalendar_events SET " .
343 " pc_recurrspec = ? ".
344 " WHERE pc_aid = ? AND pc_multiple=?", array(serialize($oldRecurrspec),$provider,$row['pc_multiple']) );
347 // obtain the next available unique key to group multiple providers around some event
348 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
349 $max = sqlFetchArray($q);
350 $new_multiple_value = $max['max'] + 1;
352 // insert a new event record for each provider selected on the form
353 foreach ($providers_new as $provider) {
354 // insert a new event on this date with POST form data
355 $args = $_POST;
356 // specify some special variables needed for the INSERT
357 $args['new_multiple_value'] = $new_multiple_value;
358 $args['form_provider'] = $provider;
359 $args['event_date'] = $event_date;
360 $args['duration'] = $duration * 60;
361 // this event is forced to NOT REPEAT
362 $args['form_repeat'] = "0";
363 $args['recurrspec'] = $noRecurrspec;
364 $args['form_enddate'] = "0000-00-00";
365 $args['starttime'] = $starttime;
366 $args['endtime'] = $endtime;
367 $args['locationspec'] = $locationspec;
368 InsertEvent($args);
372 // ===== Future Recurring events of a repeating series =====
373 else if ($_POST['recurr_affect'] == 'future') {
374 // update all existing event records to
375 // stop recurring on this date-1
376 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
377 foreach ($providers_current as $provider) {
378 // mod original event recur specs to end on this date
379 sqlStatement("UPDATE openemr_postcalendar_events SET " .
380 " pc_enddate = ? ".
381 " WHERE pc_aid = ? AND pc_multiple=?", array($selected_date,$provider,$row['pc_multiple']) );
384 // obtain the next available unique key to group multiple providers around some event
385 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
386 $max = sqlFetchArray($q);
387 $new_multiple_value = $max['max'] + 1;
389 // insert a new event record for each provider selected on the form
390 foreach ($providers_new as $provider) {
391 // insert a new event on this date with POST form data
392 $args = $_POST;
393 // specify some special variables needed for the INSERT
394 $args['new_multiple_value'] = $new_multiple_value;
395 $args['form_provider'] = $provider;
396 $args['event_date'] = $event_date;
397 $args['duration'] = $duration * 60;
398 $args['recurrspec'] = $recurrspec;
399 $args['starttime'] = $starttime;
400 $args['endtime'] = $endtime;
401 $args['locationspec'] = $locationspec;
402 InsertEvent($args);
406 else {
407 /* =================================================================== */
408 // ===== a Single event or All events in a repeating series ==========
409 /* =================================================================== */
411 // this difference means that some providers from current was UNCHECKED
412 // so we must delete this event for them
413 $r1 = array_diff ($providers_current, $providers_new);
414 if (count ($r1)) {
415 foreach ($r1 as $to_be_removed) {
416 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']) );
420 // perform a check to see if user changed event date
421 // this is important when editing an existing recurring event
422 // oct-08 JRM
423 if ($_POST['form_date'] == $_POST['selected_date']) {
424 // user has NOT changed the start date of the event
425 $event_date = fixDate($_POST['event_start_date']);
428 // this difference means that some providers were added
429 // so we must insert this event for them
430 $r2 = array_diff ($providers_new, $providers_current);
431 if (count ($r2)) {
432 foreach ($r2 as $to_be_inserted) {
433 $args = $_POST;
434 // specify some special variables needed for the INSERT
435 $args['new_multiple_value'] = $row['pc_multiple'];
436 $args['form_provider'] = $to_be_inserted;
437 $args['event_date'] = $event_date;
438 $args['duration'] = $duration * 60;
439 $args['recurrspec'] = $recurrspec;
440 $args['starttime'] = $starttime;
441 $args['endtime'] = $endtime;
442 $args['locationspec'] = $locationspec;
443 InsertEvent($args);
447 // after the two diffs above, we must update for remaining providers
448 // those who are intersected in $providers_current and $providers_new
449 foreach ($_POST['form_provider'] as $provider) {
450 sqlStatement("UPDATE openemr_postcalendar_events SET " .
451 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
452 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
453 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
454 "pc_time = NOW(), " .
455 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
456 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
457 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
458 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
459 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
460 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
461 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
462 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
463 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
464 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
465 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
466 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
467 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
468 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
469 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
470 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'");
471 } // foreach
474 // ====================================
475 // single provider
476 // ====================================
477 } elseif ( !$row['pc_multiple'] ) {
478 if ( $GLOBALS['select_multi_providers'] ) {
479 $prov = $_POST['form_provider'][0];
480 } else {
481 $prov = $_POST['form_provider'];
484 if ($_POST['recurr_affect'] == 'current') {
485 // get the original event's repeat specs
486 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
487 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
488 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
489 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
490 else { $oldRecurrspec['exdate'] .= $selected_date; }
492 // mod original event recur specs to exclude this date
493 sqlStatement("UPDATE openemr_postcalendar_events SET " .
494 " pc_recurrspec = ? ".
495 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
497 // insert a new event on this date with POST form data
498 $args = $_POST;
499 // specify some special variables needed for the INSERT
500 $args['event_date'] = $event_date;
501 $args['duration'] = $duration * 60;
502 // this event is forced to NOT REPEAT
503 $args['form_repeat'] = "0";
504 $args['recurrspec'] = $noRecurrspec;
505 $args['form_enddate'] = "0000-00-00";
506 $args['starttime'] = $starttime;
507 $args['endtime'] = $endtime;
508 $args['locationspec'] = $locationspec;
509 InsertEvent($args);
511 else if ($_POST['recurr_affect'] == 'future') {
512 // mod original event to stop recurring on this date-1
513 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
514 sqlStatement("UPDATE openemr_postcalendar_events SET " .
515 " pc_enddate = ? ".
516 " WHERE pc_eid = ?", array($selected_date,$eid) );
518 // insert a new event starting on this date with POST form data
519 $args = $_POST;
520 // specify some special variables needed for the INSERT
521 $args['event_date'] = $event_date;
522 $args['duration'] = $duration * 60;
523 $args['recurrspec'] = $recurrspec;
524 $args['starttime'] = $starttime;
525 $args['endtime'] = $endtime;
526 $args['locationspec'] = $locationspec;
527 InsertEvent($args);
529 else {
531 // perform a check to see if user changed event date
532 // this is important when editing an existing recurring event
533 // oct-08 JRM
534 if ($_POST['form_date'] == $_POST['selected_date']) {
535 // user has NOT changed the start date of the event
536 $event_date = fixDate($_POST['event_start_date']);
539 // mod the SINGLE event or ALL EVENTS in a repeating series
540 // simple provider case
541 sqlStatement("UPDATE openemr_postcalendar_events SET " .
542 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
543 "pc_aid = '" . add_escape_custom($prov) . "', " .
544 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
545 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
546 "pc_time = NOW(), " .
547 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
548 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
549 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
550 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
551 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
552 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
553 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
554 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
555 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
556 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
557 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
558 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
559 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
560 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
561 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
562 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
566 // =======================================
567 // end Update Multi providers case
568 // =======================================
570 // EVENTS TO FACILITIES
571 $e2f = (int)$eid;
574 } else {
575 /* =======================================================
576 * INSERT NEW EVENT(S)
577 * ======================================================*/
579 InsertEventFull();
583 // done with EVENT insert/update statements
585 DOBandEncounter();
589 // =======================================
590 // DELETE EVENT(s)
591 // =======================================
592 else if ($_POST['form_action'] == "delete") {
593 // =======================================
594 // multi providers event
595 // =======================================
596 if ($GLOBALS['select_multi_providers']) {
598 // what is multiple key around this $eid?
599 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
601 // obtain current list of providers regarding the multiple key
602 $providers_current = array();
603 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
604 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
606 // establish a WHERE clause
607 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = '{$row['pc_multiple']}'"; }
608 else { $whereClause = "pc_eid = '$eid'"; }
610 if ($_POST['recurr_affect'] == 'current') {
611 // update all existing event records to exlude the current date
612 foreach ($providers_current as $provider) {
613 // update the provider's original event
614 // get the original event's repeat specs
615 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
616 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
617 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
618 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
619 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
620 else { $oldRecurrspec['exdate'] .= $selected_date; }
622 // mod original event recur specs to exclude this date
623 sqlStatement("UPDATE openemr_postcalendar_events SET " .
624 " pc_recurrspec = ? ".
625 " WHERE ". $whereClause, array(serialize($oldRecurrspec)) );
628 else if ($_POST['recurr_affect'] == 'future') {
629 // update all existing event records to stop recurring on this date-1
630 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
631 foreach ($providers_current as $provider) {
632 // update the provider's original event
633 sqlStatement("UPDATE openemr_postcalendar_events SET " .
634 " pc_enddate = ? ".
635 " WHERE ".$whereClause, array($selected_date) );
638 else {
639 // really delete the event from the database
640 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
644 // =======================================
645 // single provider event
646 // =======================================
647 else {
649 if ($_POST['recurr_affect'] == 'current') {
650 // mod original event recur specs to exclude this date
652 // get the original event's repeat specs
653 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
654 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
655 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
656 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
657 else { $oldRecurrspec['exdate'] .= $selected_date; }
658 sqlStatement("UPDATE openemr_postcalendar_events SET " .
659 " pc_recurrspec = ? ".
660 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
663 else if ($_POST['recurr_affect'] == 'future') {
664 // mod original event to stop recurring on this date-1
665 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
666 sqlStatement("UPDATE openemr_postcalendar_events SET " .
667 " pc_enddate = ? ".
668 " WHERE pc_eid = ?", array($selected_date,$eid) );
671 else {
672 // fully delete the event from the database
673 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
678 if ($_POST['form_action'] != "") {
679 // Close this window and refresh the calendar (or the patient_tracker) display.
680 echo "<html>\n<body>\n<script language='JavaScript'>\n";
681 if ($info_msg) echo " alert('" . addslashes($info_msg) . "');\n";
682 echo " if (opener && !opener.closed && opener.refreshme) {\n " .
683 " opener.refreshme();\n " . // This is for standard calendar page refresh
684 " } else {\n " .
685 " window.opener.pattrk.submit()\n " . // This is for patient flow board page refresh
686 " };\n";
687 echo " window.close();\n";
688 echo "</script>\n</body>\n</html>\n";
689 exit();
692 //*********************************
693 // If we get this far then we are displaying the form.
694 //*********************************
696 /*********************************************************************
697 This has been migrate to the administration->lists
698 $statuses = array(
699 '-' => '',
700 '*' => xl('* Reminder done'),
701 '+' => xl('+ Chart pulled'),
702 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
703 '?' => xl('? No show'),
704 '@' => xl('@ Arrived'),
705 '~' => xl('~ Arrived late'),
706 '!' => xl('! Left w/o visit'),
707 '#' => xl('# Ins/fin issue'),
708 '<' => xl('< In exam room'),
709 '>' => xl('> Checked out'),
710 '$' => xl('$ Coding done'),
711 '%' => xl('% Cancelled < 24h ')
713 *********************************************************************/
715 $repeats = 0; // if the event repeats
716 $repeattype = '0';
717 $repeatfreq = '0';
718 $patientid = '';
719 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
720 $patientname = xl('Click to select');
721 $patienttitle = "";
722 $pcroom = "";
723 $hometext = "";
724 $row = array();
725 $informant = "";
727 // If we are editing an existing event, then get its data.
728 if ($eid) {
729 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
731 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
732 "FROM openemr_postcalendar_events AS e " .
733 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
734 "WHERE pc_eid = ?", array($eid) );
735 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
737 // instead of using the event's starting date, keep what has been provided
738 // via the GET array, see the top of this file
739 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
740 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
741 $userid = $row['pc_aid'];
742 $patientid = $row['pc_pid'];
743 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
744 $starttimem = substr($row['pc_startTime'], 3, 2);
745 $repeats = $row['pc_recurrtype'];
746 $multiple_value = $row['pc_multiple'];
748 // parse out the repeating data, if any
749 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
750 $repeattype = $rspecs['event_repeat_freq_type'];
751 $repeatfreq = $rspecs['event_repeat_freq'];
752 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
754 // Adjustments for repeat type 2, a particular weekday of the month.
755 if ($repeats == 2) {
756 $repeatfreq = $rspecs['event_repeat_on_freq'];
757 if ($rspecs['event_repeat_on_num'] < 5) {
758 $repeattype = 5;
760 else {
761 $repeattype = 6;
764 $pcroom = $row['pc_room'];
765 $hometext = $row['pc_hometext'];
766 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
768 else {
769 // a NEW event
770 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
772 //-------------------------------------
773 //(CHEMED)
774 //Set default facility for a new event based on the given 'userid'
775 if ($userid) {
776 /*************************************************************
777 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
778 *************************************************************/
779 if ($_SESSION['pc_facility']) {
780 $pref_facility = sqlFetchArray(sqlStatement("
781 SELECT f.id as facility_id,
782 f.name as facility
783 FROM facility f
784 WHERE f.id = ?
786 array($_SESSION['pc_facility'])
787 ));
788 } else {
789 $pref_facility = sqlFetchArray(sqlStatement("
790 SELECT u.facility_id,
791 f.name as facility
792 FROM users u
793 LEFT JOIN facility f on (u.facility_id = f.id)
794 WHERE u.id = ?
795 ", array($userid) ));
797 /************************************************************/
798 $e2f = $pref_facility['facility_id'];
799 $e2f_name = $pref_facility['facility'];
801 //END of CHEMED -----------------------
804 // If we have a patient ID, get the name and phone numbers to display.
805 if ($patientid) {
806 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
807 "FROM patient_data WHERE pid = ?", array($patientid) );
808 $patientname = $prow['lname'] . ", " . $prow['fname'];
809 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
810 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
813 // Get the providers list.
814 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
815 "authorized != 0 AND active = 1 ORDER BY lname, fname");
817 // Get event categories.
818 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
819 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
821 // Fix up the time format for AM/PM.
822 $startampm = '1';
823 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
824 $startampm = '2';
825 if ($starttimeh > 12) $starttimeh -= 12;
829 <html>
830 <head>
831 <?php html_header_show(); ?>
832 <title><?php echo $eid ? xlt('Edit') : xlt('Add New') ?> <?php echo xlt('Event');?></title>
833 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
835 <style>
836 td { font-size:0.8em; }
837 </style>
839 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
840 <script type="text/javascript" src="../../../library/topdialog.js"></script>
841 <script type="text/javascript" src="../../../library/dialog.js"></script>
842 <script type="text/javascript" src="../../../library/textformat.js"></script>
843 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
844 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
845 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
847 <script language="JavaScript">
849 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
851 var durations = new Array();
852 // var rectypes = new Array();
853 <?php
854 // Read the event categories, generate their options list, and get
855 // the default event duration from them if this is a new event.
856 $cattype=0;
857 if($_GET['prov']==true){
858 $cattype=1;
860 $cres = sqlStatement("SELECT pc_catid, pc_cattype, pc_catname, " .
861 "pc_recurrtype, pc_duration, pc_end_all_day " .
862 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
863 $catoptions = "";
864 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
865 $thisduration = 0;
866 if ($eid) {
867 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
869 while ($crow = sqlFetchArray($cres)) {
870 $duration = round($crow['pc_duration'] / 60);
871 if ($crow['pc_end_all_day']) $duration = 1440;
873 // This section is to build the list of preferred categories:
874 if ($duration) {
875 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
876 if ($eid) {
877 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
879 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
882 if ($crow['pc_cattype'] != $cattype) continue;
884 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
885 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
886 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
887 if ($eid) {
888 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
889 } else {
890 if ($crow['pc_catid'] == $default_catid) {
891 $catoptions .= " selected";
892 $thisduration = $duration;
895 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
899 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
901 // This is for callback by the find-patient popup.
902 function setpatient(pid, lname, fname, dob) {
903 var f = document.forms[0];
904 f.form_patient.value = lname + ', ' + fname;
905 f.form_pid.value = pid;
906 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
907 document.getElementById('dob_row').style.display = dobstyle;
910 // This invokes the find-patient popup.
911 function sel_patient() {
912 dlgopen('find_patient_popup.php', '_blank', 500, 400);
915 // Do whatever is needed when a new event category is selected.
916 // For now this means changing the event title and duration.
917 function set_display() {
918 var f = document.forms[0];
919 var s = f.form_category;
920 if (s.selectedIndex >= 0) {
921 var catid = s.options[s.selectedIndex].value;
922 var style_apptstatus = document.getElementById('title_apptstatus').style;
923 var style_prefcat = document.getElementById('title_prefcat').style;
924 if (catid == '2') { // In Office
925 style_apptstatus.display = 'none';
926 style_prefcat.display = '';
927 f.form_apptstatus.style.display = 'none';
928 f.form_prefcat.style.display = '';
929 } else {
930 style_prefcat.display = 'none';
931 style_apptstatus.display = '';
932 f.form_prefcat.style.display = 'none';
933 f.form_apptstatus.style.display = '';
938 // Do whatever is needed when a new event category is selected.
939 // For now this means changing the event title and duration.
940 function set_category() {
941 var f = document.forms[0];
942 var s = f.form_category;
943 if (s.selectedIndex >= 0) {
944 var catid = s.options[s.selectedIndex].value;
945 f.form_title.value = s.options[s.selectedIndex].text;
946 f.form_duration.value = durations[catid];
947 set_display();
951 // Modify some visual attributes when the all-day or timed-event
952 // radio buttons are clicked.
953 function set_allday() {
954 var f = document.forms[0];
955 var color1 = '#777777';
956 var color2 = '#777777';
957 var disabled2 = true;
958 if (document.getElementById('rballday1').checked) {
959 color1 = '#000000';
961 if (document.getElementById('rballday2').checked) {
962 color2 = '#000000';
963 disabled2 = false;
965 document.getElementById('tdallday1').style.color = color1;
966 document.getElementById('tdallday2').style.color = color2;
967 document.getElementById('tdallday3').style.color = color2;
968 document.getElementById('tdallday4').style.color = color2;
969 document.getElementById('tdallday5').style.color = color2;
970 f.form_hour.disabled = disabled2;
971 f.form_minute.disabled = disabled2;
972 f.form_ampm.disabled = disabled2;
973 f.form_duration.disabled = disabled2;
976 // Modify some visual attributes when the Repeat checkbox is clicked.
977 function set_repeat() {
978 var f = document.forms[0];
979 var isdisabled = true;
980 var mycolor = '#777777';
981 var myvisibility = 'hidden';
982 if (f.form_repeat.checked) {
983 isdisabled = false;
984 mycolor = '#000000';
985 myvisibility = 'visible';
987 f.form_repeat_type.disabled = isdisabled;
988 f.form_repeat_freq.disabled = isdisabled;
989 f.form_enddate.disabled = isdisabled;
990 document.getElementById('tdrepeat1').style.color = mycolor;
991 document.getElementById('tdrepeat2').style.color = mycolor;
992 document.getElementById('img_enddate').style.visibility = myvisibility;
995 // Constants used by dateChanged() function.
996 var occurNames = new Array(
997 '<?php echo xls("1st"); ?>',
998 '<?php echo xls("2nd"); ?>',
999 '<?php echo xls("3rd"); ?>',
1000 '<?php echo xls("4th"); ?>'
1003 // Monitor start date changes to adjust repeat type options.
1004 function dateChanged() {
1005 var f = document.forms[0];
1006 if (!f.form_date.value) return;
1007 var d = new Date(f.form_date.value);
1008 var downame = Calendar._DN[d.getUTCDay()];
1009 var nthtext = '';
1010 var occur = Math.floor((d.getUTCDate() - 1) / 7);
1011 if (occur < 4) { // 5th is not allowed
1012 nthtext = occurNames[occur] + ' ' + downame;
1014 var lasttext = '';
1015 var tmp = new Date(d.getUTCFullYear(), d.getUTCMonth() + 1, 0);
1016 if (tmp.getUTCDate() - d.getUTCDate() < 7) {
1017 // This is a last occurrence of the specified weekday in the month,
1018 // so permit that as an option.
1019 lasttext = '<?php echo xls("Last"); ?> ' + downame;
1021 var si = f.form_repeat_type.selectedIndex;
1022 var opts = f.form_repeat_type.options;
1023 opts.length = 5; // remove any nth and Last entries
1024 if (nthtext ) opts[opts.length] = new Option(nthtext , '5');
1025 if (lasttext) opts[opts.length] = new Option(lasttext, '6');
1026 if (si < opts.length) f.form_repeat_type.selectedIndex = si;
1029 // This is for callback by the find-available popup.
1030 function setappt(year,mon,mday,hours,minutes) {
1031 var f = document.forms[0];
1032 f.form_date.value = '' + year + '-' +
1033 ('' + (mon + 100)).substring(1) + '-' +
1034 ('' + (mday + 100)).substring(1);
1035 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
1036 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
1037 f.form_minute.value = ('' + (minutes + 100)).substring(1);
1040 // Invoke the find-available popup.
1041 function find_available(extra) {
1042 top.restoreSession();
1043 // (CHEMED) Conditional value selection, because there is no <select> element
1044 // when making an appointment for a specific provider
1045 var s = document.forms[0].form_provider;
1046 var f = document.forms[0].facility;
1047 <?php if ($userid != 0) { ?>
1048 s = document.forms[0].form_provider.value;
1049 f = document.forms[0].facility.value;
1050 <?php } else {?>
1051 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1052 f = document.forms[0].facility.options[f.selectedIndex].value;
1053 <?php }?>
1054 var c = document.forms[0].form_category;
1055 var formDate = document.forms[0].form_date;
1056 dlgopen('<?php echo $GLOBALS['web_root']; ?>/interface/main/calendar/find_appt_popup.php' +
1057 '?providerid=' + s +
1058 '&catid=' + c.options[c.selectedIndex].value +
1059 '&facility=' + f +
1060 '&startdate=' + formDate.value +
1061 '&evdur=' + document.forms[0].form_duration.value +
1062 '&eid=<?php echo 0 + $eid; ?>' +
1063 extra,
1064 '_blank', 500, 400);
1067 </script>
1069 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1071 </head>
1073 <body class="body_top" onunload='imclosing()'>
1075 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1076 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1077 <input type='hidden' size='2' name='resname' value='empty' />
1078 <?php
1079 if ($_POST["resname"]=="noresult"){
1080 echo '
1081 <script language="Javascript">
1082 // refresh and redirect the parent window
1083 if (!opener.closed && opener.refreshme) opener.refreshme();
1084 top.restoreSession();
1085 opener.document.location="../../new/new.php";
1086 // Close the window
1087 window.close();
1088 </script>';
1090 $classprov='current';
1091 $classpati='';
1093 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1094 <input type="hidden" name="form_action" id="form_action" value="">
1095 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1096 <!-- used for recurring events -->
1097 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo attr($date); ?>">
1098 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo attr($eventstartdate); ?>">
1099 <center>
1100 <table border='0' >
1101 <?php
1102 $provider_class='';
1103 $normal='';
1104 if($_GET['prov']==true){
1105 $provider_class="class='current'";
1107 else{
1108 $normal="class='current'";
1111 <tr><th><ul class="tabNav">
1112 <?php
1113 $eid=$_REQUEST["eid"];
1114 $startm=$_REQUEST["startampm"];
1115 $starth=$_REQUEST["starttimeh"];
1116 $uid=$_REQUEST["userid"];
1117 $starttm=$_REQUEST["starttimem"];
1118 $dt=$_REQUEST["date"];
1119 $cid=$_REQUEST["catid"];
1121 <li <?php echo $normal;?>>
1122 <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);?>'>
1123 <?php echo xlt('Patient');?></a>
1124 </li>
1125 <li <?php echo $provider_class;?>>
1126 <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);?>'>
1127 <?php echo xlt('Provider');?></a>
1128 </li>
1129 </ul>
1130 </th></tr>
1131 <tr><td colspan='10'>
1132 <table border='0' width='100%' bgcolor='#DDDDDD' >
1134 <tr>
1135 <td width='1%' nowrap>
1136 <b><?php echo ($GLOBALS['athletic_team'] ? xlt('Team/Squad') : xlt('Category')); ?>:</b>
1137 </td>
1138 <td nowrap>
1139 <select name='form_category' onchange='set_category()' style='width:100%'>
1140 <?php echo $catoptions ?>
1141 </select>
1142 </td>
1143 <td width='1%' nowrap>
1144 &nbsp;&nbsp;
1145 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1146 <?php if ($thisduration == 1440) echo "checked " ?>/>
1147 </td>
1148 <td colspan='2' nowrap id='tdallday1'>
1149 <?php echo xlt('All day event'); ?>
1150 </td>
1151 </tr>
1153 <tr>
1154 <td nowrap>
1155 <b><?php echo xlt('Date'); ?>:</b>
1156 </td>
1157 <td nowrap>
1158 <input type='text' size='10' name='form_date' id='form_date'
1159 value='<?php echo attr($date) ?>'
1160 title='<?php echo xla('yyyy-mm-dd event date or starting date'); ?>'
1161 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' onchange='dateChanged()' />
1162 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1163 id='img_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1164 title='<?php echo xla('Click here to choose a date'); ?>'>
1165 </td>
1166 <td nowrap>
1167 &nbsp;&nbsp;
1168 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1169 </td>
1170 <td width='1%' nowrap id='tdallday2'>
1171 <?php echo xlt('Time'); ?>
1172 </td>
1173 <td width='1%' nowrap id='tdallday3'>
1174 <input type='text' size='2' name='form_hour' value='<?php echo attr($starttimeh) ?>'
1175 title='<?php echo xla('Event start time'); ?>' /> :
1176 <input type='text' size='2' name='form_minute' value='<?php echo attr($starttimem) ?>'
1177 title='<?php echo xla('Event start time'); ?>' />&nbsp;
1178 <select name='form_ampm' title='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1179 <option value='1'><?php echo xlt('AM'); ?></option>
1180 <option value='2'<?php if ($startampm == '2') echo " selected" ?>><?php echo xlt('PM'); ?></option>
1181 </select>
1182 </td>
1183 </tr>
1185 <tr>
1186 <td nowrap>
1187 <b><?php echo ($GLOBALS['athletic_team'] ? xlt('Team/Squad') : xlt('Title')); ?>:</b>
1188 </td>
1189 <td nowrap>
1190 <input type='text' size='10' name='form_title' value='<?php echo attr($row['pc_title']); ?>'
1191 style='width:100%'
1192 title='<?php echo xla('Event title'); ?>' />
1193 </td>
1194 <td nowrap>&nbsp;
1196 </td>
1197 <td nowrap id='tdallday4'><?php echo xlt('duration'); ?>
1198 </td>
1199 <td nowrap id='tdallday5'>
1200 <input type='text' size='4' name='form_duration' value='<?php echo attr($thisduration) ?>' title='<?php echo xla('Event duration in minutes'); ?>' />
1201 <?php echo xlt('minutes'); ?>
1202 </td>
1203 </tr>
1205 <tr>
1206 <td nowrap><b><?php echo xlt('Facility'); ?>:</b></td>
1207 <td>
1208 <select name="facility" id="facility" >
1209 <?php
1211 // ===========================
1212 // EVENTS TO FACILITIES
1213 //(CHEMED) added service_location WHERE clause
1214 // get the facilities
1215 /***************************************************************
1216 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1217 ***************************************************************/
1218 $facils = getUserFacilities($_SESSION['authId']);
1219 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1220 /**************************************************************/
1221 while ($facrow = sqlFetchArray($qsql)) {
1222 /*************************************************************
1223 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1224 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1225 *************************************************************/
1226 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1227 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1228 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1230 else{
1231 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1232 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1234 /************************************************************/
1236 // EOS E2F
1237 // ===========================
1239 <?php
1240 //END (CHEMED) IF ?>
1241 </td>
1242 </select>
1243 </tr>
1244 <tr>
1245 <td nowrap>
1246 <b><?php echo xlt('Billing Facility'); ?>:</b>
1247 </td>
1248 <td>
1249 <?php
1250 billing_facility('billing_facility',$row['pc_billing_location']);
1252 </td>
1253 </tr>
1254 <?php
1255 if($_GET['prov']!=true){
1257 <tr id="patient_details">
1258 <td nowrap>
1259 <b><?php echo xlt('Patient'); ?>:</b>
1260 </td>
1261 <td nowrap>
1262 <input type='text' size='10' name='form_patient' style='width:100%;cursor:pointer;cursor:hand' value='<?php echo attr($patientname); ?>' onclick='sel_patient()' title='<?php echo xla('Click to select patient'); ?>' readonly />
1263 <input type='hidden' name='form_pid' value='<?php echo attr($patientid) ?>' />
1264 </td>
1265 <td colspan='3' nowrap style='font-size:8pt'>
1266 &nbsp;
1267 <span class="infobox">
1268 <?php if ($patienttitle != "") { echo $patienttitle; } ?>
1269 </span>
1270 </td>
1271 </tr>
1272 <?php
1275 <tr>
1276 <td nowrap>
1277 <b><?php echo xlt('Provider'); ?>:</b>
1278 </td>
1279 <td nowrap>
1281 <?php
1283 // =======================================
1284 // multi providers
1285 // =======================================
1286 if ($GLOBALS['select_multi_providers']) {
1288 // there are two posible situations: edit and new record
1290 // this is executed only on edit ($eid)
1291 if ($eid) {
1292 if ( $multiple_value ) {
1293 // find all the providers around multiple key
1294 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value) );
1295 while ($r = sqlFetchArray($qall)) {
1296 $providers_array[] = $r['providers'];
1298 } else {
1299 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1300 $providers_array = sqlFetchArray($qall);
1304 // build the selection tool
1305 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1307 while ($urow = sqlFetchArray($ures)) {
1308 echo " <option value='" . attr($urow['id']) . "'";
1310 if ($userid) {
1311 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1314 echo ">" . text($urow['lname']);
1315 if ($urow['fname']) echo ", " . text($urow['fname']);
1316 echo "</option>\n";
1319 echo '</select>';
1321 // =======================================
1322 // single provider
1323 // =======================================
1324 } else {
1326 if ($eid) {
1327 // get provider from existing event
1328 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1329 $provider = sqlFetchArray($qprov);
1330 $defaultProvider = $provider['pc_aid'];
1332 else {
1333 // this is a new event so smartly choose a default provider
1334 /*****************************************************************
1335 if ($userid) {
1336 // Provider already given to us as a GET parameter.
1337 $defaultProvider = $userid;
1339 else {
1340 // default to the currently logged-in user
1341 $defaultProvider = $_SESSION['authUserID'];
1342 // or, if we have chosen a provider in the calendar, default to them
1343 // choose the first one if multiple have been selected
1344 if (count($_SESSION['pc_username']) >= 1) {
1345 // get the numeric ID of the first provider in the array
1346 $pc_username = $_SESSION['pc_username'];
1347 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1348 $defaultProvider = $firstProvider['id'];
1353 echo "<select name='form_provider' style='width:100%' />";
1354 while ($urow = sqlFetchArray($ures)) {
1355 echo " <option value='" . $urow['id'] . "'";
1356 if ($urow['id'] == $defaultProvider) echo " selected";
1357 echo ">" . $urow['lname'];
1358 if ($urow['fname']) echo ", " . $urow['fname'];
1359 echo "</option>\n";
1361 echo "</select>";
1362 *****************************************************************/
1363 // default to the currently logged-in user
1364 $defaultProvider = $_SESSION['authUserID'];
1365 // or, if we have chosen a provider in the calendar, default to them
1366 // choose the first one if multiple have been selected
1367 if (count($_SESSION['pc_username']) >= 1) {
1368 // get the numeric ID of the first provider in the array
1369 $pc_username = $_SESSION['pc_username'];
1370 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0]) ));
1371 $defaultProvider = $firstProvider['id'];
1373 // if we clicked on a provider's schedule to add the event, use THAT.
1374 if ($userid) $defaultProvider = $userid;
1376 echo "<select name='form_provider' style='width:100%' />";
1377 while ($urow = sqlFetchArray($ures)) {
1378 echo " <option value='" . attr($urow['id']) . "'";
1379 if ($urow['id'] == $defaultProvider) echo " selected";
1380 echo ">" . text($urow['lname']);
1381 if ($urow['fname']) echo ", " . text($urow['fname']);
1382 echo "</option>\n";
1384 echo "</select>";
1385 /****************************************************************/
1390 </td>
1391 <td nowrap>
1392 &nbsp;&nbsp;
1393 <input type='checkbox' name='form_repeat' onclick='set_repeat(this)' value='1'<?php if ($repeats) echo " checked" ?>/>
1394 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat -->
1395 </td>
1396 <td nowrap id='tdrepeat1'><?php echo xlt('Repeats'); ?>
1397 </td>
1398 <td nowrap>
1400 <select name='form_repeat_freq' title='<?php echo xla('Every, every other, every 3rd, etc.'); ?>'>
1401 <?php
1402 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1403 as $key => $value)
1405 echo " <option value='" . attr($key) . "'";
1406 if ($key == $repeatfreq) echo " selected";
1407 echo ">" . text($value) . "</option>\n";
1410 </select>
1412 <select name='form_repeat_type'>
1413 <?php
1414 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1415 // when the start date is set.
1416 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1417 5 => '?', 6 => '?') as $key => $value)
1419 echo " <option value='" . attr($key) . "'";
1420 if ($key == $repeattype) echo " selected";
1421 echo ">" . text($value) . "</option>\n";
1424 </select>
1426 </td>
1427 </tr>
1429 <tr>
1430 <td nowrap>
1431 <span id='title_apptstatus'><b><?php echo ($GLOBALS['athletic_team'] ? xlt('Session Type') : xlt('Status')); ?>:</b></span>
1432 <span id='title_prefcat' style='display:none'><b><?php echo xlt('Pref Cat'); ?>:</b></span>
1433 </td>
1434 <td nowrap>
1436 <?php
1437 generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'SKIP'), $row['pc_apptstatus']);
1439 <!--
1440 The following list will be invisible unless this is an In Office
1441 event, in which case form_apptstatus (above) is to be invisible.
1443 <select name='form_prefcat' style='width:100%;display:none' title='<?php echo xla('Preferred Event Category');?>'>
1444 <?php echo $prefcat_options ?>
1445 </select>
1447 </td>
1448 <td nowrap>&nbsp;
1450 </td>
1451 <td nowrap id='tdrepeat2'><?php echo xlt('until'); ?>
1452 </td>
1453 <td nowrap>
1454 <input type='text' size='10' name='form_enddate' id='form_enddate' value='<?php echo attr($row['pc_endDate']) ?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo xla('yyyy-mm-dd last date of this event');?>' />
1455 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1456 id='img_enddate' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1457 title='<?php echo xla('Click here to choose a date');?>'>
1458 <?php
1459 if ($repeatexdate != "") {
1460 $tmptitle = "The following dates are excluded from the repeating series";
1461 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1462 else { $tmptitle .= "\n"; }
1463 $exdates = explode(",", $repeatexdate);
1464 foreach ($exdates as $exdate) {
1465 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1467 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1470 </td>
1471 </tr>
1472 <?php
1473 if($_GET['prov']!=true){
1475 <tr>
1476 <td nowrap>
1477 <b><?php echo xlt('Room Number'); ?>:</b>
1478 </td>
1479 <td colspan='4' nowrap>
1480 <?php
1481 echo generate_select_list('form_room', 'patient_flow_board_rooms',$pcroom, xl('Room Number'));
1483 </td>
1484 </tr>
1485 <?php } ?>
1486 <tr>
1487 <td nowrap>
1488 <b><?php echo xlt('Comments'); ?>:</b>
1489 </td>
1490 <td colspan='4' nowrap>
1491 <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');?>' />
1492 </td>
1493 </tr>
1496 <?php
1497 // DOB is important for the clinic, so if it's missing give them a chance
1498 // to enter it right here. We must display or hide this row dynamically
1499 // in case the patient-select popup is used.
1500 $patient_dob = trim($prow['DOB']);
1501 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00')) ?
1502 '' : 'none';
1504 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1505 <td colspan='4' nowrap>
1506 <b><font color='red'><?php echo xlt('DOB is missing, please enter if possible'); ?>:</font></b>
1507 </td>
1508 <td nowrap>
1509 <input type='text' size='10' name='form_dob' id='form_dob' title='<?php echo xla('yyyy-mm-dd date of birth');?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
1510 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1511 id='img_dob' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1512 title='<?php echo xla('Click here to choose a date');?>'>
1513 </td>
1514 </tr>
1516 </table></td></tr>
1517 <tr class='text'><td colspan='10'>
1519 <input type='button' name='form_save' id='form_save' value='<?php echo xla('Save');?>' />
1520 &nbsp;
1522 <?php if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1523 <input type='button' id='find_available' value='<?php echo xla('Find Available');?>' />
1524 <?php } ?>
1526 &nbsp;
1527 <input type='button' name='form_delete' id='form_delete' value='<?php echo xla('Delete');?>'<?php if (!$eid) echo " disabled" ?> />
1528 &nbsp;
1529 <input type='button' id='cancel' value='<?php echo xla('Cancel');?>' />
1530 &nbsp;
1531 <input type='button' name='form_duplicate' id='form_duplicate' value='<?php echo xla('Create Duplicate');?>' />
1532 </p></td></tr></table>
1533 <?php if ($informant) echo "<p class='text'>" . xlt('Last update by') . " " .
1534 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n"; ?>
1535 </center>
1536 </form>
1538 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1539 <?php echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?>
1540 <br>
1541 <input type="button" name="all_events" id="all_events" value=" <?php echo xla('All'); ?> ">
1542 <input type="button" name="future_events" id="future_events" value="<?php echo xla('Future'); ?>">
1543 <input type="button" name="current_event" id="current_event" value="<?php echo xla('Current'); ?>">
1544 <input type="button" name="recurr_cancel" id="recurr_cancel" value="<?php echo xla('Cancel'); ?>">
1545 </div>
1547 </body>
1549 <script language='JavaScript'>
1550 <?php if ($eid) { ?>
1551 set_display();
1552 <?php } else { ?>
1553 set_category();
1554 <?php } ?>
1555 set_allday();
1556 set_repeat();
1558 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
1559 Calendar.setup({inputField:"form_enddate", ifFormat:"%Y-%m-%d", button:"img_enddate"});
1560 Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});
1561 </script>
1563 <script language="javascript">
1564 // jQuery stuff to make the page a little easier to use
1566 $(document).ready(function(){
1567 $("#form_save").click(function() { validate("save"); });
1568 $("#form_duplicate").click(function() { validate("duplicate"); });
1569 $("#find_available").click(function() { find_available(''); });
1570 $("#form_delete").click(function() { deleteEvent(); });
1571 $("#cancel").click(function() { window.close(); });
1573 // buttons affecting the modification of a repeating event
1574 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1575 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1576 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1577 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1579 // Initialize repeat options.
1580 dateChanged();
1583 // Check for errors when the form is submitted.
1584 function validate(valu) {
1585 var f = document.getElementById('theform');
1586 if (f.form_repeat.checked &&
1587 (! f.form_enddate.value || f.form_enddate.value < f.form_date.value)) {
1588 alert('<?php echo addslashes(xl("An end date later than the start date is required for repeated events!")); ?>');
1589 return false;
1591 <?php
1592 if($_GET['prov']!=true){
1594 if(f.form_pid.value == ''){
1595 alert('<?php echo addslashes(xl('Patient Name Required'));?>');
1596 return false;
1598 <?php
1601 $('#form_action').val(valu);
1603 <?php if ($repeats): ?>
1604 // existing repeating events need additional prompt
1605 if ($("#recurr_affect").val() == "") {
1606 DisableForm();
1607 // show the current/future/all DIV for the user to choose one
1608 $("#recurr_popup").css("visibility", "visible");
1609 return false;
1611 <?php endif; ?>
1613 return SubmitForm();
1616 // disable all the form elements outside the recurr_popup
1617 function DisableForm() {
1618 $("#theform").children().attr("disabled", "true");
1620 function EnableForm() {
1621 $("#theform").children().removeAttr("disabled");
1623 // hide the recurring popup DIV
1624 function HideRecurrPopup() {
1625 $("#recurr_popup").css("visibility", "hidden");
1628 function deleteEvent() {
1629 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?')); ?>")) {
1630 $('#form_action').val("delete");
1632 <?php if ($repeats): ?>
1633 // existing repeating events need additional prompt
1634 if ($("#recurr_affect").val() == "") {
1635 DisableForm();
1636 // show the current/future/all DIV for the user to choose one
1637 $("#recurr_popup").css("visibility", "visible");
1638 return false;
1640 <?php endif; ?>
1642 return SubmitForm();
1644 return false;
1647 function SubmitForm() {
1648 var f = document.forms[0];
1649 <?php if (!($GLOBALS['select_multi_providers'])) { // multi providers appt is not supported by check slot avail window, so skip ?>
1650 if (f.form_action.value != 'delete') {
1651 // Check slot availability.
1652 var mins = parseInt(f.form_hour.value) * 60 + parseInt(f.form_minute.value);
1653 if (f.form_ampm.value == '2' && mins < 720) mins += 720;
1654 find_available('&cktime=' + mins);
1656 else {
1657 top.restoreSession();
1658 f.submit();
1660 <?php } else { ?>
1661 top.restoreSession();
1662 f.submit();
1663 <?php } ?>
1665 return true;
1668 </script>
1670 </html>