Two cosmetic fixes for the event editor.
[openemr.git] / interface / main / calendar / add_edit_event.php
blobda48b412115f0a38dfdd37fe7f413c46b0d52a4f
1 <?php
2 // Copyright (C) 2005-2013 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
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 //------------------------------------------------------------//
23 $fake_register_globals=false;
24 $sanitize_all_escapes=true;
26 require_once("../../globals.php");
27 require_once("$srcdir/patient.inc");
28 require_once("$srcdir/forms.inc");
29 require_once("$srcdir/calendar.inc");
30 require_once("$srcdir/formdata.inc.php");
31 require_once("$srcdir/options.inc.php");
32 require_once("$srcdir/encounter_events.inc.php");
33 require_once("$srcdir/acl.inc");
35 //Check access control
36 if (!acl_check('patients','appt','',array('write','wsome') ))
37 die(xl('Access not allowed'));
39 // Things that might be passed by our opener.
41 $eid = $_GET['eid']; // only for existing events
42 $date = $_GET['date']; // this and below only for new events
43 $userid = $_GET['userid'];
44 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
46 if ($date)
47 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
48 else
49 $date = date("Y-m-d");
51 $starttimem = '00';
52 if (isset($_GET['starttimem']))
53 $starttimem = substr('00' . $_GET['starttimem'], -2);
55 if (isset($_GET['starttimeh'])) {
56 $starttimeh = $_GET['starttimeh'];
57 if (isset($_GET['startampm'])) {
58 if ($_GET['startampm'] == '2' && $starttimeh < 12)
59 $starttimeh += 12;
61 } else {
62 $starttimeh = date("G");
64 $startampm = '';
66 $info_msg = "";
70 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
72 <?php
74 function InsertEventFull()
76 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
77 // =======================================
78 // multi providers case
79 // =======================================
80 if (is_array($_POST['form_provider'])) {
82 // obtain the next available unique key to group multiple providers around some event
83 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
84 $max = sqlFetchArray($q);
85 $new_multiple_value = $max['max'] + 1;
87 foreach ($_POST['form_provider'] as $provider) {
88 $args = $_POST;
89 // specify some special variables needed for the INSERT
90 $args['new_multiple_value'] = $new_multiple_value;
91 $args['form_provider'] = $provider;
92 $args['event_date'] = $event_date;
93 $args['duration'] = $duration * 60;
94 $args['recurrspec'] = $recurrspec;
95 $args['starttime'] = $starttime;
96 $args['endtime'] = $endtime;
97 $args['locationspec'] = $locationspec;
98 InsertEvent($args);
101 // ====================================
102 // single provider
103 // ====================================
104 } else {
105 $args = $_POST;
106 // specify some special variables needed for the INSERT
107 $args['new_multiple_value'] = "";
108 $args['event_date'] = $event_date;
109 $args['duration'] = $duration * 60;
110 $args['recurrspec'] = $recurrspec;
111 $args['starttime'] = $starttime;
112 $args['endtime'] = $endtime;
113 $args['locationspec'] = $locationspec;
114 InsertEvent($args);
117 function DOBandEncounter()
119 global $event_date,$info_msg;
120 // Save new DOB if it's there.
121 $patient_dob = trim($_POST['form_dob']);
122 if ($patient_dob && $_POST['form_pid']) {
123 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
124 "pid = ?", array($patient_dob,$_POST['form_pid']) );
127 // Auto-create a new encounter if appropriate.
129 if ($GLOBALS['auto_create_new_encounters'] && $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
131 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
132 if($encounter){
133 $info_msg .= xl("New encounter created with id");
134 $info_msg .= " $encounter";
138 //================================================================================================================
140 // EVENTS TO FACILITIES (lemonsoftware)
141 //(CHEMED) get facility name
142 // edit event case - if there is no association made, then insert one with the first facility
143 if ( $eid ) {
144 $selfacil = '';
145 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
146 FROM openemr_postcalendar_events
147 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
148 WHERE pc_eid = ?", array($eid) );
149 // if ( !$facility['pc_facility'] ) {
150 if ( is_array($facility) && !$facility['pc_facility'] ) {
151 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']) );
152 $min = $qmin['minId'];
153 $min_name = $qmin['facility'];
155 // multiple providers case
156 if ( $GLOBALS['select_multi_providers'] ) {
157 $mul = $facility['pc_multiple'];
158 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min,$mul) );
160 // EOS multiple
162 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min,$eid) );
163 $e2f = $min;
164 $e2f_name = $min_name;
165 } else {
166 // not edit event
167 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
168 $e2f = $_SESSION['pc_facility'];
169 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
170 $e2f = $_COOKIE['pc_facility'];
171 } else {
172 $e2f = $facility['pc_facility'];
173 $e2f_name = $facility['name'];
177 // EOS E2F
178 // ===========================
179 //=============================================================================================================================
180 if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
182 // the starting date of the event, pay attention with this value
183 // when editing recurring events -- JRM Oct-08
184 $event_date = fixDate($_POST['form_date']);
186 // Compute start and end time strings to be saved.
187 if ($_POST['form_allday']) {
188 $tmph = 0;
189 $tmpm = 0;
190 $duration = 24 * 60;
191 } else {
192 $tmph = $_POST['form_hour'] + 0;
193 $tmpm = $_POST['form_minute'] + 0;
194 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
195 $duration = $_POST['form_duration'];
197 $starttime = "$tmph:$tmpm:00";
199 $tmpm += $duration;
200 while ($tmpm >= 60) {
201 $tmpm -= 60;
202 ++$tmph;
204 $endtime = "$tmph:$tmpm:00";
206 // Set up working variables related to repeated events.
207 $my_recurrtype = 0;
208 $my_repeat_freq = 0 + $_POST['form_repeat_freq'];
209 $my_repeat_type = 0 + $_POST['form_repeat_type'];
210 $my_repeat_on_num = 1;
211 $my_repeat_on_day = 0;
212 $my_repeat_on_freq = 0;
213 if (!empty($_POST['form_repeat'])) {
214 $my_recurrtype = 1;
215 if ($my_repeat_type > 4) {
216 $my_recurrtype = 2;
217 $time = strtotime($event_date);
218 $my_repeat_on_day = 0 + date('w', $time);
219 $my_repeat_on_freq = $my_repeat_freq;
220 if ($my_repeat_type == 5) {
221 $my_repeat_on_num = intval((date('j', $time) - 1) / 7) + 1;
223 else {
224 // Last occurence of this weekday on the month
225 $my_repeat_on_num = 5;
227 // Maybe not needed, but for consistency with postcalendar:
228 $my_repeat_freq = 0;
229 $my_repeat_type = 0;
233 // Useless garbage that we must save.
234 $locationspecs = array("event_location" => "",
235 "event_street1" => "",
236 "event_street2" => "",
237 "event_city" => "",
238 "event_state" => "",
239 "event_postal" => ""
241 $locationspec = serialize($locationspecs);
243 // capture the recurring specifications
244 $recurrspec = array("event_repeat_freq" => "$my_repeat_freq",
245 "event_repeat_freq_type" => "$my_repeat_type",
246 "event_repeat_on_num" => "$my_repeat_on_num",
247 "event_repeat_on_day" => "$my_repeat_on_day",
248 "event_repeat_on_freq" => "$my_repeat_on_freq",
249 "exdate" => $_POST['form_repeat_exdate']
252 // no recurr specs, this is used for adding a new non-recurring event
253 $noRecurrspec = array("event_repeat_freq" => "",
254 "event_repeat_freq_type" => "",
255 "event_repeat_on_num" => "1",
256 "event_repeat_on_day" => "0",
257 "event_repeat_on_freq" => "0",
258 "exdate" => ""
261 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
262 //=============================================================================================================================
263 if ($_POST['form_action'] == "duplicate") {
265 InsertEventFull();
266 DOBandEncounter();
270 // If we are saving, then save and close the window.
272 if ($_POST['form_action'] == "save") {
273 /* =======================================================
274 * UPDATE EVENTS
275 * =====================================================*/
276 if ($eid) {
278 // what is multiple key around this $eid?
279 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
281 // ====================================
282 // multiple providers
283 // ====================================
284 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
286 // obtain current list of providers regarding the multiple key
287 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
288 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
290 // get the new list of providers from the submitted form
291 $providers_new = $_POST['form_provider'];
293 // ===== Only current event of repeating series =====
294 if ($_POST['recurr_affect'] == 'current') {
296 // update all existing event records to exlude the current date
297 foreach ($providers_current as $provider) {
298 // update the provider's original event
299 // get the original event's repeat specs
300 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
301 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
302 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
303 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
304 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
305 else { $oldRecurrspec['exdate'] .= $selected_date; }
307 // mod original event recur specs to exclude this date
308 sqlStatement("UPDATE openemr_postcalendar_events SET " .
309 " pc_recurrspec = ? ".
310 " WHERE pc_aid = ? AND pc_multiple=?", array(serialize($oldRecurrspec),$provider,$row['pc_multiple']) );
313 // obtain the next available unique key to group multiple providers around some event
314 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
315 $max = sqlFetchArray($q);
316 $new_multiple_value = $max['max'] + 1;
318 // insert a new event record for each provider selected on the form
319 foreach ($providers_new as $provider) {
320 // insert a new event on this date with POST form data
321 $args = $_POST;
322 // specify some special variables needed for the INSERT
323 $args['new_multiple_value'] = $new_multiple_value;
324 $args['form_provider'] = $provider;
325 $args['event_date'] = $event_date;
326 $args['duration'] = $duration * 60;
327 // this event is forced to NOT REPEAT
328 $args['form_repeat'] = "0";
329 $args['recurrspec'] = $noRecurrspec;
330 $args['form_enddate'] = "0000-00-00";
331 $args['starttime'] = $starttime;
332 $args['endtime'] = $endtime;
333 $args['locationspec'] = $locationspec;
334 InsertEvent($args);
338 // ===== Future Recurring events of a repeating series =====
339 else if ($_POST['recurr_affect'] == 'future') {
340 // update all existing event records to
341 // stop recurring on this date-1
342 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
343 foreach ($providers_current as $provider) {
344 // mod original event recur specs to end on this date
345 sqlStatement("UPDATE openemr_postcalendar_events SET " .
346 " pc_enddate = ? ".
347 " WHERE pc_aid = ? AND pc_multiple=?", array($selected_date,$provider,$row['pc_multiple']) );
350 // obtain the next available unique key to group multiple providers around some event
351 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
352 $max = sqlFetchArray($q);
353 $new_multiple_value = $max['max'] + 1;
355 // insert a new event record for each provider selected on the form
356 foreach ($providers_new as $provider) {
357 // insert a new event on this date with POST form data
358 $args = $_POST;
359 // specify some special variables needed for the INSERT
360 $args['new_multiple_value'] = $new_multiple_value;
361 $args['form_provider'] = $provider;
362 $args['event_date'] = $event_date;
363 $args['duration'] = $duration * 60;
364 $args['recurrspec'] = $recurrspec;
365 $args['starttime'] = $starttime;
366 $args['endtime'] = $endtime;
367 $args['locationspec'] = $locationspec;
368 InsertEvent($args);
372 else {
373 /* =================================================================== */
374 // ===== a Single event or All events in a repeating series ==========
375 /* =================================================================== */
377 // this difference means that some providers from current was UNCHECKED
378 // so we must delete this event for them
379 $r1 = array_diff ($providers_current, $providers_new);
380 if (count ($r1)) {
381 foreach ($r1 as $to_be_removed) {
382 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']) );
386 // perform a check to see if user changed event date
387 // this is important when editing an existing recurring event
388 // oct-08 JRM
389 if ($_POST['form_date'] == $_POST['selected_date']) {
390 // user has NOT changed the start date of the event
391 $event_date = fixDate($_POST['event_start_date']);
394 // this difference means that some providers were added
395 // so we must insert this event for them
396 $r2 = array_diff ($providers_new, $providers_current);
397 if (count ($r2)) {
398 foreach ($r2 as $to_be_inserted) {
399 $args = $_POST;
400 // specify some special variables needed for the INSERT
401 $args['new_multiple_value'] = $row['pc_multiple'];
402 $args['form_provider'] = $to_be_inserted;
403 $args['event_date'] = $event_date;
404 $args['duration'] = $duration * 60;
405 $args['recurrspec'] = $recurrspec;
406 $args['starttime'] = $starttime;
407 $args['endtime'] = $endtime;
408 $args['locationspec'] = $locationspec;
409 InsertEvent($args);
413 // after the two diffs above, we must update for remaining providers
414 // those who are intersected in $providers_current and $providers_new
415 foreach ($_POST['form_provider'] as $provider) {
416 sqlStatement("UPDATE openemr_postcalendar_events SET " .
417 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
418 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
419 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
420 "pc_time = NOW(), " .
421 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
422 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
423 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
424 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
425 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
426 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
427 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
428 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
429 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
430 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
431 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
432 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
433 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
434 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
435 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'");
436 } // foreach
439 // ====================================
440 // single provider
441 // ====================================
442 } elseif ( !$row['pc_multiple'] ) {
443 if ( $GLOBALS['select_multi_providers'] ) {
444 $prov = $_POST['form_provider'][0];
445 } else {
446 $prov = $_POST['form_provider'];
449 if ($_POST['recurr_affect'] == 'current') {
450 // get the original event's repeat specs
451 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
452 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
453 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
454 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
455 else { $oldRecurrspec['exdate'] .= $selected_date; }
457 // mod original event recur specs to exclude this date
458 sqlStatement("UPDATE openemr_postcalendar_events SET " .
459 " pc_recurrspec = ? ".
460 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
462 // insert a new event on this date with POST form data
463 $args = $_POST;
464 // specify some special variables needed for the INSERT
465 $args['event_date'] = $event_date;
466 $args['duration'] = $duration * 60;
467 // this event is forced to NOT REPEAT
468 $args['form_repeat'] = "0";
469 $args['recurrspec'] = $noRecurrspec;
470 $args['form_enddate'] = "0000-00-00";
471 $args['starttime'] = $starttime;
472 $args['endtime'] = $endtime;
473 $args['locationspec'] = $locationspec;
474 InsertEvent($args);
476 else if ($_POST['recurr_affect'] == 'future') {
477 // mod original event to stop recurring on this date-1
478 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
479 sqlStatement("UPDATE openemr_postcalendar_events SET " .
480 " pc_enddate = ? ".
481 " WHERE pc_eid = ?", array($selected_date,$eid) );
483 // insert a new event starting on this date with POST form data
484 $args = $_POST;
485 // specify some special variables needed for the INSERT
486 $args['event_date'] = $event_date;
487 $args['duration'] = $duration * 60;
488 $args['recurrspec'] = $recurrspec;
489 $args['starttime'] = $starttime;
490 $args['endtime'] = $endtime;
491 $args['locationspec'] = $locationspec;
492 InsertEvent($args);
494 else {
496 // perform a check to see if user changed event date
497 // this is important when editing an existing recurring event
498 // oct-08 JRM
499 if ($_POST['form_date'] == $_POST['selected_date']) {
500 // user has NOT changed the start date of the event
501 $event_date = fixDate($_POST['event_start_date']);
504 // mod the SINGLE event or ALL EVENTS in a repeating series
505 // simple provider case
506 sqlStatement("UPDATE openemr_postcalendar_events SET " .
507 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
508 "pc_aid = '" . add_escape_custom($prov) . "', " .
509 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
510 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
511 "pc_time = NOW(), " .
512 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
513 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
514 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
515 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
516 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
517 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
518 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
519 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
520 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
521 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
522 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
523 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
524 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
525 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
526 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
530 // =======================================
531 // end Update Multi providers case
532 // =======================================
534 // EVENTS TO FACILITIES
535 $e2f = (int)$eid;
538 } else {
539 /* =======================================================
540 * INSERT NEW EVENT(S)
541 * ======================================================*/
543 InsertEventFull();
547 // done with EVENT insert/update statements
549 DOBandEncounter();
553 // =======================================
554 // DELETE EVENT(s)
555 // =======================================
556 else if ($_POST['form_action'] == "delete") {
557 // =======================================
558 // multi providers event
559 // =======================================
560 if ($GLOBALS['select_multi_providers']) {
562 // what is multiple key around this $eid?
563 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
565 // obtain current list of providers regarding the multiple key
566 $providers_current = array();
567 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
568 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
570 // establish a WHERE clause
571 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = '{$row['pc_multiple']}'"; }
572 else { $whereClause = "pc_eid = '$eid'"; }
574 if ($_POST['recurr_affect'] == 'current') {
575 // update all existing event records to exlude the current date
576 foreach ($providers_current as $provider) {
577 // update the provider's original event
578 // get the original event's repeat specs
579 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
580 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
581 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
582 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
583 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
584 else { $oldRecurrspec['exdate'] .= $selected_date; }
586 // mod original event recur specs to exclude this date
587 sqlStatement("UPDATE openemr_postcalendar_events SET " .
588 " pc_recurrspec = ? ".
589 " WHERE ". $whereClause, array(serialize($oldRecurrspec)) );
592 else if ($_POST['recurr_affect'] == 'future') {
593 // update all existing event records to stop recurring on this date-1
594 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
595 foreach ($providers_current as $provider) {
596 // update the provider's original event
597 sqlStatement("UPDATE openemr_postcalendar_events SET " .
598 " pc_enddate = ? ".
599 " WHERE ".$whereClause, array($selected_date) );
602 else {
603 // really delete the event from the database
604 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
608 // =======================================
609 // single provider event
610 // =======================================
611 else {
613 if ($_POST['recurr_affect'] == 'current') {
614 // mod original event recur specs to exclude this date
616 // get the original event's repeat specs
617 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
618 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
619 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
620 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
621 else { $oldRecurrspec['exdate'] .= $selected_date; }
622 sqlStatement("UPDATE openemr_postcalendar_events SET " .
623 " pc_recurrspec = ? ".
624 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
627 else if ($_POST['recurr_affect'] == 'future') {
628 // mod original event to stop recurring on this date-1
629 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
630 sqlStatement("UPDATE openemr_postcalendar_events SET " .
631 " pc_enddate = ? ".
632 " WHERE pc_eid = ?", array($selected_date,$eid) );
635 else {
636 // fully delete the event from the database
637 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
642 if ($_POST['form_action'] != "") {
643 // Close this window and refresh the calendar display.
644 echo "<html>\n<body>\n<script language='JavaScript'>\n";
645 if ($info_msg) echo " alert('" . addslashes($info_msg) . "');\n";
646 echo " if (opener && !opener.closed && opener.refreshme) opener.refreshme();\n";
647 echo " window.close();\n";
648 echo "</script>\n</body>\n</html>\n";
649 exit();
652 //*********************************
653 // If we get this far then we are displaying the form.
654 //*********************************
656 /*********************************************************************
657 This has been migrate to the administration->lists
658 $statuses = array(
659 '-' => '',
660 '*' => xl('* Reminder done'),
661 '+' => xl('+ Chart pulled'),
662 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
663 '?' => xl('? No show'),
664 '@' => xl('@ Arrived'),
665 '~' => xl('~ Arrived late'),
666 '!' => xl('! Left w/o visit'),
667 '#' => xl('# Ins/fin issue'),
668 '<' => xl('< In exam room'),
669 '>' => xl('> Checked out'),
670 '$' => xl('$ Coding done'),
671 '%' => xl('% Cancelled < 24h ')
673 *********************************************************************/
675 $repeats = 0; // if the event repeats
676 $repeattype = '0';
677 $repeatfreq = '0';
678 $patientid = '';
679 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
680 $patientname = xl('Click to select');
681 $patienttitle = "";
682 $hometext = "";
683 $row = array();
684 $informant = "";
686 // If we are editing an existing event, then get its data.
687 if ($eid) {
688 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
690 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
691 "FROM openemr_postcalendar_events AS e " .
692 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
693 "WHERE pc_eid = ?", array($eid) );
694 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
696 // instead of using the event's starting date, keep what has been provided
697 // via the GET array, see the top of this file
698 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
699 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
700 $userid = $row['pc_aid'];
701 $patientid = $row['pc_pid'];
702 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
703 $starttimem = substr($row['pc_startTime'], 3, 2);
704 $repeats = $row['pc_recurrtype'];
705 $multiple_value = $row['pc_multiple'];
707 // parse out the repeating data, if any
708 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
709 $repeattype = $rspecs['event_repeat_freq_type'];
710 $repeatfreq = $rspecs['event_repeat_freq'];
711 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
713 // Adjustments for repeat type 2, a particular weekday of the month.
714 if ($repeats == 2) {
715 $repeatfreq = $rspecs['event_repeat_on_freq'];
716 if ($rspecs['event_repeat_on_num'] < 5) {
717 $repeattype = 5;
719 else {
720 $repeattype = 6;
724 $hometext = $row['pc_hometext'];
725 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
727 else {
728 // a NEW event
729 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
731 //-------------------------------------
732 //(CHEMED)
733 //Set default facility for a new event based on the given 'userid'
734 if ($userid) {
735 /*************************************************************
736 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
737 *************************************************************/
738 if ($_SESSION['pc_facility']) {
739 $pref_facility = sqlFetchArray(sqlStatement("
740 SELECT f.id as facility_id,
741 f.name as facility
742 FROM facility f
743 WHERE f.id = ?
745 array($_SESSION['pc_facility'])
746 ));
747 } else {
748 $pref_facility = sqlFetchArray(sqlStatement("
749 SELECT u.facility_id,
750 f.name as facility
751 FROM users u
752 LEFT JOIN facility f on (u.facility_id = f.id)
753 WHERE u.id = ?
754 ", array($userid) ));
756 /************************************************************/
757 $e2f = $pref_facility['facility_id'];
758 $e2f_name = $pref_facility['facility'];
760 //END of CHEMED -----------------------
763 // If we have a patient ID, get the name and phone numbers to display.
764 if ($patientid) {
765 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
766 "FROM patient_data WHERE pid = ?", array($patientid) );
767 $patientname = $prow['lname'] . ", " . $prow['fname'];
768 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
769 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
772 // Get the providers list.
773 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
774 "authorized != 0 AND active = 1 ORDER BY lname, fname");
776 // Get event categories.
777 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
778 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
780 // Fix up the time format for AM/PM.
781 $startampm = '1';
782 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
783 $startampm = '2';
784 if ($starttimeh > 12) $starttimeh -= 12;
788 <html>
789 <head>
790 <?php html_header_show(); ?>
791 <title><?php echo $eid ? xlt('Edit') : xlt('Add New') ?> <?php echo xlt('Event');?></title>
792 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
794 <style>
795 td { font-size:0.8em; }
796 </style>
798 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
799 <script type="text/javascript" src="../../../library/topdialog.js"></script>
800 <script type="text/javascript" src="../../../library/dialog.js"></script>
801 <script type="text/javascript" src="../../../library/textformat.js"></script>
802 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
803 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
804 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
806 <script language="JavaScript">
808 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
810 var durations = new Array();
811 // var rectypes = new Array();
812 <?php
813 // Read the event categories, generate their options list, and get
814 // the default event duration from them if this is a new event.
815 $cattype=0;
816 if($_GET['prov']==true){
817 $cattype=1;
819 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
820 "FROM openemr_postcalendar_categories WHERE pc_cattype=? ORDER BY pc_catname", array($cattype) );
821 $catoptions = "";
822 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
823 $thisduration = 0;
824 if ($eid) {
825 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
827 while ($crow = sqlFetchArray($cres)) {
828 $duration = round($crow['pc_duration'] / 60);
829 if ($crow['pc_end_all_day']) $duration = 1440;
830 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
831 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
832 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
833 if ($eid) {
834 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
835 } else {
836 if ($crow['pc_catid'] == $default_catid) {
837 $catoptions .= " selected";
838 $thisduration = $duration;
841 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
843 // This section is to build the list of preferred categories:
844 if ($duration) {
845 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
846 if ($eid) {
847 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
849 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
855 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
857 // This is for callback by the find-patient popup.
858 function setpatient(pid, lname, fname, dob) {
859 var f = document.forms[0];
860 f.form_patient.value = lname + ', ' + fname;
861 f.form_pid.value = pid;
862 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
863 document.getElementById('dob_row').style.display = dobstyle;
866 // This invokes the find-patient popup.
867 function sel_patient() {
868 dlgopen('find_patient_popup.php', '_blank', 500, 400);
871 // Do whatever is needed when a new event category is selected.
872 // For now this means changing the event title and duration.
873 function set_display() {
874 var f = document.forms[0];
875 var s = f.form_category;
876 if (s.selectedIndex >= 0) {
877 var catid = s.options[s.selectedIndex].value;
878 var style_apptstatus = document.getElementById('title_apptstatus').style;
879 var style_prefcat = document.getElementById('title_prefcat').style;
880 if (catid == '2') { // In Office
881 style_apptstatus.display = 'none';
882 style_prefcat.display = '';
883 f.form_apptstatus.style.display = 'none';
884 f.form_prefcat.style.display = '';
885 } else {
886 style_prefcat.display = 'none';
887 style_apptstatus.display = '';
888 f.form_prefcat.style.display = 'none';
889 f.form_apptstatus.style.display = '';
894 // Do whatever is needed when a new event category is selected.
895 // For now this means changing the event title and duration.
896 function set_category() {
897 var f = document.forms[0];
898 var s = f.form_category;
899 if (s.selectedIndex >= 0) {
900 var catid = s.options[s.selectedIndex].value;
901 f.form_title.value = s.options[s.selectedIndex].text;
902 f.form_duration.value = durations[catid];
903 set_display();
907 // Modify some visual attributes when the all-day or timed-event
908 // radio buttons are clicked.
909 function set_allday() {
910 var f = document.forms[0];
911 var color1 = '#777777';
912 var color2 = '#777777';
913 var disabled2 = true;
914 if (document.getElementById('rballday1').checked) {
915 color1 = '#000000';
917 if (document.getElementById('rballday2').checked) {
918 color2 = '#000000';
919 disabled2 = false;
921 document.getElementById('tdallday1').style.color = color1;
922 document.getElementById('tdallday2').style.color = color2;
923 document.getElementById('tdallday3').style.color = color2;
924 document.getElementById('tdallday4').style.color = color2;
925 document.getElementById('tdallday5').style.color = color2;
926 f.form_hour.disabled = disabled2;
927 f.form_minute.disabled = disabled2;
928 f.form_ampm.disabled = disabled2;
929 f.form_duration.disabled = disabled2;
932 // Modify some visual attributes when the Repeat checkbox is clicked.
933 function set_repeat() {
934 var f = document.forms[0];
935 var isdisabled = true;
936 var mycolor = '#777777';
937 var myvisibility = 'hidden';
938 if (f.form_repeat.checked) {
939 isdisabled = false;
940 mycolor = '#000000';
941 myvisibility = 'visible';
943 f.form_repeat_type.disabled = isdisabled;
944 f.form_repeat_freq.disabled = isdisabled;
945 f.form_enddate.disabled = isdisabled;
946 document.getElementById('tdrepeat1').style.color = mycolor;
947 document.getElementById('tdrepeat2').style.color = mycolor;
948 document.getElementById('img_enddate').style.visibility = myvisibility;
951 // Constants used by dateChanged() function.
952 var occurNames = new Array(
953 '<?php echo xls("1st"); ?>',
954 '<?php echo xls("2nd"); ?>',
955 '<?php echo xls("3rd"); ?>',
956 '<?php echo xls("4th"); ?>'
959 // Monitor start date changes to adjust repeat type options.
960 function dateChanged() {
961 var f = document.forms[0];
962 if (!f.form_date.value) return;
963 var d = new Date(f.form_date.value);
964 var downame = Calendar._DN[d.getUTCDay()];
965 var nthtext = '';
966 var occur = Math.floor((d.getUTCDate() - 1) / 7);
967 if (occur < 4) { // 5th is not allowed
968 nthtext = occurNames[occur] + ' ' + downame;
970 var lasttext = '';
971 var tmp = new Date(d.getUTCFullYear(), d.getUTCMonth() + 1, 0);
972 if (tmp.getUTCDate() - d.getUTCDate() < 7) {
973 // This is a last occurrence of the specified weekday in the month,
974 // so permit that as an option.
975 lasttext = '<?php echo xls("Last"); ?> ' + downame;
977 var si = f.form_repeat_type.selectedIndex;
978 var opts = f.form_repeat_type.options;
979 opts.length = 5; // remove any nth and Last entries
980 if (nthtext ) opts[opts.length] = new Option(nthtext , '5');
981 if (lasttext) opts[opts.length] = new Option(lasttext, '6');
982 if (si < opts.length) f.form_repeat_type.selectedIndex = si;
985 // This is for callback by the find-available popup.
986 function setappt(year,mon,mday,hours,minutes) {
987 var f = document.forms[0];
988 f.form_date.value = '' + year + '-' +
989 ('' + (mon + 100)).substring(1) + '-' +
990 ('' + (mday + 100)).substring(1);
991 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
992 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
993 f.form_minute.value = ('' + (minutes + 100)).substring(1);
996 // Invoke the find-available popup.
997 function find_available(extra) {
998 top.restoreSession();
999 // (CHEMED) Conditional value selection, because there is no <select> element
1000 // when making an appointment for a specific provider
1001 var s = document.forms[0].form_provider;
1002 var f = document.forms[0].facility;
1003 <?php if ($userid != 0) { ?>
1004 s = document.forms[0].form_provider.value;
1005 f = document.forms[0].facility.value;
1006 <?php } else {?>
1007 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1008 f = document.forms[0].facility.options[f.selectedIndex].value;
1009 <?php }?>
1010 var c = document.forms[0].form_category;
1011 var formDate = document.forms[0].form_date;
1012 dlgopen('<?php echo $GLOBALS['web_root']; ?>/interface/main/calendar/find_appt_popup.php' +
1013 '?providerid=' + s +
1014 '&catid=' + c.options[c.selectedIndex].value +
1015 '&facility=' + f +
1016 '&startdate=' + formDate.value +
1017 '&evdur=' + document.forms[0].form_duration.value +
1018 '&eid=<?php echo 0 + $eid; ?>' +
1019 extra,
1020 '_blank', 500, 400);
1021 //END (CHEMED) modifications
1024 </script>
1026 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1028 </head>
1030 <body class="body_top" onunload='imclosing()'>
1032 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1033 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1034 <input type='hidden' size='2' name='resname' value='empty' />
1035 <?php
1036 if ($_POST["resname"]=="noresult"){
1037 echo '
1038 <script language="Javascript">
1039 // refresh and redirect the parent window
1040 if (!opener.closed && opener.refreshme) opener.refreshme();
1041 top.restoreSession();
1042 opener.document.location="../../new/new.php";
1043 // Close the window
1044 window.close();
1045 </script>';
1047 $classprov='current';
1048 $classpati='';
1050 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1051 <input type="hidden" name="form_action" id="form_action" value="">
1052 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1053 <!-- used for recurring events -->
1054 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo attr($date); ?>">
1055 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo attr($eventstartdate); ?>">
1056 <center>
1057 <table border='0' >
1058 <?php
1059 $provider_class='';
1060 $normal='';
1061 if($_GET['prov']==true){
1062 $provider_class="class='current'";
1064 else{
1065 $normal="class='current'";
1068 <tr><th><ul class="tabNav">
1069 <?php
1070 $eid=$_REQUEST["eid"];
1071 $startm=$_REQUEST["startampm"];
1072 $starth=$_REQUEST["starttimeh"];
1073 $uid=$_REQUEST["userid"];
1074 $starttm=$_REQUEST["starttimem"];
1075 $dt=$_REQUEST["date"];
1076 $cid=$_REQUEST["catid"];
1078 <li <?php echo $normal;?>>
1079 <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);?>'>
1080 <?php echo xlt('Patient');?></a>
1081 </li>
1082 <li <?php echo $provider_class;?>>
1083 <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);?>'>
1084 <?php echo xlt('Provider');?></a>
1085 </li>
1086 </ul>
1087 </th></tr>
1088 <tr><td colspan='10'>
1089 <table border='0' width='100%' bgcolor='#DDDDDD' >
1091 <tr>
1092 <td width='1%' nowrap>
1093 <b><?php echo ($GLOBALS['athletic_team'] ? xlt('Team/Squad') : xlt('Category')); ?>:</b>
1094 </td>
1095 <td nowrap>
1096 <select name='form_category' onchange='set_category()' style='width:100%'>
1097 <?php echo $catoptions ?>
1098 </select>
1099 </td>
1100 <td width='1%' nowrap>
1101 &nbsp;&nbsp;
1102 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1103 <?php if ($thisduration == 1440) echo "checked " ?>/>
1104 </td>
1105 <td colspan='2' nowrap id='tdallday1'>
1106 <?php echo xlt('All day event'); ?>
1107 </td>
1108 </tr>
1110 <tr>
1111 <td nowrap>
1112 <b><?php echo xlt('Date'); ?>:</b>
1113 </td>
1114 <td nowrap>
1115 <input type='text' size='10' name='form_date' id='form_date'
1116 value='<?php echo attr($date) ?>'
1117 title='<?php echo xla('yyyy-mm-dd event date or starting date'); ?>'
1118 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' onchange='dateChanged()' />
1119 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1120 id='img_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1121 title='<?php echo xla('Click here to choose a date'); ?>'>
1122 </td>
1123 <td nowrap>
1124 &nbsp;&nbsp;
1125 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1126 </td>
1127 <td width='1%' nowrap id='tdallday2'>
1128 <?php echo xlt('Time'); ?>
1129 </td>
1130 <td width='1%' nowrap id='tdallday3'>
1131 <input type='text' size='2' name='form_hour' value='<?php echo attr($starttimeh) ?>'
1132 title='<?php echo xla('Event start time'); ?>' /> :
1133 <input type='text' size='2' name='form_minute' value='<?php echo attr($starttimem) ?>'
1134 title='<?php echo xla('Event start time'); ?>' />&nbsp;
1135 <select name='form_ampm' title='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1136 <option value='1'><?php echo xlt('AM'); ?></option>
1137 <option value='2'<?php if ($startampm == '2') echo " selected" ?>><?php echo xlt('PM'); ?></option>
1138 </select>
1139 </td>
1140 </tr>
1142 <tr>
1143 <td nowrap>
1144 <b><?php echo ($GLOBALS['athletic_team'] ? xlt('Team/Squad') : xlt('Title')); ?>:</b>
1145 </td>
1146 <td nowrap>
1147 <input type='text' size='10' name='form_title' value='<?php echo attr($row['pc_title']); ?>'
1148 style='width:100%'
1149 title='<?php echo xla('Event title'); ?>' />
1150 </td>
1151 <td nowrap>&nbsp;
1153 </td>
1154 <td nowrap id='tdallday4'><?php echo xlt('duration'); ?>
1155 </td>
1156 <td nowrap id='tdallday5'>
1157 <input type='text' size='4' name='form_duration' value='<?php echo attr($thisduration) ?>' title='<?php echo xla('Event duration in minutes'); ?>' />
1158 <?php echo xlt('minutes'); ?>
1159 </td>
1160 </tr>
1162 <tr>
1163 <td nowrap><b><?php echo xlt('Facility'); ?>:</b></td>
1164 <td>
1165 <select name="facility" id="facility" >
1166 <?php
1168 // ===========================
1169 // EVENTS TO FACILITIES
1170 //(CHEMED) added service_location WHERE clause
1171 // get the facilities
1172 /***************************************************************
1173 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1174 ***************************************************************/
1175 $facils = getUserFacilities($_SESSION['authId']);
1176 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1177 /**************************************************************/
1178 while ($facrow = sqlFetchArray($qsql)) {
1179 /*************************************************************
1180 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1181 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1182 *************************************************************/
1183 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1184 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1185 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1187 else{
1188 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1189 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1191 /************************************************************/
1193 // EOS E2F
1194 // ===========================
1196 <?php
1197 //END (CHEMED) IF ?>
1198 </td>
1199 </select>
1200 </tr>
1201 <tr>
1202 <td nowrap>
1203 <b><?php echo xlt('Billing Facility'); ?>:</b>
1204 </td>
1205 <td>
1206 <?php
1207 billing_facility('billing_facility',$row['pc_billing_location']);
1209 </td>
1210 </tr>
1211 <?php
1212 if($_GET['prov']!=true){
1214 <tr id="patient_details">
1215 <td nowrap>
1216 <b><?php echo xlt('Patient'); ?>:</b>
1217 </td>
1218 <td nowrap>
1219 <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 />
1220 <input type='hidden' name='form_pid' value='<?php echo attr($patientid) ?>' />
1221 </td>
1222 <td colspan='3' nowrap style='font-size:8pt'>
1223 &nbsp;
1224 <span class="infobox">
1225 <?php if ($patienttitle != "") { echo $patienttitle; } ?>
1226 </span>
1227 </td>
1228 </tr>
1229 <?php
1232 <tr>
1233 <td nowrap>
1234 <b><?php echo xlt('Provider'); ?>:</b>
1235 </td>
1236 <td nowrap>
1238 <?php
1240 // =======================================
1241 // multi providers
1242 // =======================================
1243 if ($GLOBALS['select_multi_providers']) {
1245 // there are two posible situations: edit and new record
1247 // this is executed only on edit ($eid)
1248 if ($eid) {
1249 if ( $multiple_value ) {
1250 // find all the providers around multiple key
1251 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value) );
1252 while ($r = sqlFetchArray($qall)) {
1253 $providers_array[] = $r['providers'];
1255 } else {
1256 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1257 $providers_array = sqlFetchArray($qall);
1261 // build the selection tool
1262 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1264 while ($urow = sqlFetchArray($ures)) {
1265 echo " <option value='" . attr($urow['id']) . "'";
1267 if ($userid) {
1268 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1271 echo ">" . text($urow['lname']);
1272 if ($urow['fname']) echo ", " . text($urow['fname']);
1273 echo "</option>\n";
1276 echo '</select>';
1278 // =======================================
1279 // single provider
1280 // =======================================
1281 } else {
1283 if ($eid) {
1284 // get provider from existing event
1285 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1286 $provider = sqlFetchArray($qprov);
1287 $defaultProvider = $provider['pc_aid'];
1289 else {
1290 // this is a new event so smartly choose a default provider
1291 /*****************************************************************
1292 if ($userid) {
1293 // Provider already given to us as a GET parameter.
1294 $defaultProvider = $userid;
1296 else {
1297 // default to the currently logged-in user
1298 $defaultProvider = $_SESSION['authUserID'];
1299 // or, if we have chosen a provider in the calendar, default to them
1300 // choose the first one if multiple have been selected
1301 if (count($_SESSION['pc_username']) >= 1) {
1302 // get the numeric ID of the first provider in the array
1303 $pc_username = $_SESSION['pc_username'];
1304 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1305 $defaultProvider = $firstProvider['id'];
1310 echo "<select name='form_provider' style='width:100%' />";
1311 while ($urow = sqlFetchArray($ures)) {
1312 echo " <option value='" . $urow['id'] . "'";
1313 if ($urow['id'] == $defaultProvider) echo " selected";
1314 echo ">" . $urow['lname'];
1315 if ($urow['fname']) echo ", " . $urow['fname'];
1316 echo "</option>\n";
1318 echo "</select>";
1319 *****************************************************************/
1320 // default to the currently logged-in user
1321 $defaultProvider = $_SESSION['authUserID'];
1322 // or, if we have chosen a provider in the calendar, default to them
1323 // choose the first one if multiple have been selected
1324 if (count($_SESSION['pc_username']) >= 1) {
1325 // get the numeric ID of the first provider in the array
1326 $pc_username = $_SESSION['pc_username'];
1327 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0]) ));
1328 $defaultProvider = $firstProvider['id'];
1330 // if we clicked on a provider's schedule to add the event, use THAT.
1331 if ($userid) $defaultProvider = $userid;
1333 echo "<select name='form_provider' style='width:100%' />";
1334 while ($urow = sqlFetchArray($ures)) {
1335 echo " <option value='" . attr($urow['id']) . "'";
1336 if ($urow['id'] == $defaultProvider) echo " selected";
1337 echo ">" . text($urow['lname']);
1338 if ($urow['fname']) echo ", " . text($urow['fname']);
1339 echo "</option>\n";
1341 echo "</select>";
1342 /****************************************************************/
1347 </td>
1348 <td nowrap>
1349 &nbsp;&nbsp;
1350 <input type='checkbox' name='form_repeat' onclick='set_repeat(this)' value='1'<?php if ($repeats) echo " checked" ?>/>
1351 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat -->
1352 </td>
1353 <td nowrap id='tdrepeat1'><?php echo xlt('Repeats'); ?>
1354 </td>
1355 <td nowrap>
1357 <select name='form_repeat_freq' title='<?php echo xla('Every, every other, every 3rd, etc.'); ?>'>
1358 <?php
1359 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1360 as $key => $value)
1362 echo " <option value='" . attr($key) . "'";
1363 if ($key == $repeatfreq) echo " selected";
1364 echo ">" . text($value) . "</option>\n";
1367 </select>
1369 <select name='form_repeat_type'>
1370 <?php
1371 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1372 // when the start date is set.
1373 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1374 5 => '?', 6 => '?') as $key => $value)
1376 echo " <option value='" . attr($key) . "'";
1377 if ($key == $repeattype) echo " selected";
1378 echo ">" . text($value) . "</option>\n";
1381 </select>
1383 </td>
1384 </tr>
1386 <tr>
1387 <td nowrap>
1388 <span id='title_apptstatus'><b><?php echo ($GLOBALS['athletic_team'] ? xlt('Session Type') : xlt('Status')); ?>:</b></span>
1389 <span id='title_prefcat' style='display:none'><b><?php echo xlt('Pref Cat'); ?>:</b></span>
1390 </td>
1391 <td nowrap>
1393 <?php
1394 generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'SKIP'), $row['pc_apptstatus']);
1396 <!--
1397 The following list will be invisible unless this is an In Office
1398 event, in which case form_apptstatus (above) is to be invisible.
1400 <select name='form_prefcat' style='width:100%;display:none' title='<?php echo xla('Preferred Event Category');?>'>
1401 <?php echo $prefcat_options ?>
1402 </select>
1404 </td>
1405 <td nowrap>&nbsp;
1407 </td>
1408 <td nowrap id='tdrepeat2'><?php echo xlt('until'); ?>
1409 </td>
1410 <td nowrap>
1411 <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');?>' />
1412 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1413 id='img_enddate' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1414 title='<?php echo xla('Click here to choose a date');?>'>
1415 <?php
1416 if ($repeatexdate != "") {
1417 $tmptitle = "The following dates are excluded from the repeating series";
1418 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1419 else { $tmptitle .= "\n"; }
1420 $exdates = explode(",", $repeatexdate);
1421 foreach ($exdates as $exdate) {
1422 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1424 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1427 </td>
1428 </tr>
1430 <tr>
1431 <td nowrap>
1432 <b><?php echo xlt('Comments'); ?>:</b>
1433 </td>
1434 <td colspan='4' nowrap>
1435 <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');?>' />
1436 </td>
1437 </tr>
1439 <?php
1440 // DOB is important for the clinic, so if it's missing give them a chance
1441 // to enter it right here. We must display or hide this row dynamically
1442 // in case the patient-select popup is used.
1443 $patient_dob = trim($prow['DOB']);
1444 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00')) ?
1445 '' : 'none';
1447 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1448 <td colspan='4' nowrap>
1449 <b><font color='red'><?php echo xlt('DOB is missing, please enter if possible'); ?>:</font></b>
1450 </td>
1451 <td nowrap>
1452 <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)' />
1453 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1454 id='img_dob' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1455 title='<?php echo xla('Click here to choose a date');?>'>
1456 </td>
1457 </tr>
1459 </table></td></tr>
1460 <tr class='text'><td colspan='10'>
1462 <input type='button' name='form_save' id='form_save' value='<?php echo xla('Save');?>' />
1463 &nbsp;
1465 <?php if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1466 <input type='button' id='find_available' value='<?php echo xla('Find Available');?>' />
1467 <?php } ?>
1469 &nbsp;
1470 <input type='button' name='form_delete' id='form_delete' value='<?php echo xla('Delete');?>'<?php if (!$eid) echo " disabled" ?> />
1471 &nbsp;
1472 <input type='button' id='cancel' value='<?php echo xla('Cancel');?>' />
1473 &nbsp;
1474 <input type='button' name='form_duplicate' id='form_duplicate' value='<?php echo xla('Create Duplicate');?>' />
1475 </p></td></tr></table>
1476 <?php if ($informant) echo "<p class='text'>" . xlt('Last update by') . " " .
1477 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n"; ?>
1478 </center>
1479 </form>
1481 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1482 <?php echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?>
1483 <br>
1484 <input type="button" name="all_events" id="all_events" value=" All ">
1485 <input type="button" name="future_events" id="future_events" value="Future">
1486 <input type="button" name="current_event" id="current_event" value="Current">
1487 <input type="button" name="recurr_cancel" id="recurr_cancel" value="Cancel">
1488 </div>
1490 </body>
1492 <script language='JavaScript'>
1493 <?php if ($eid) { ?>
1494 set_display();
1495 <?php } else { ?>
1496 set_category();
1497 <?php } ?>
1498 set_allday();
1499 set_repeat();
1501 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
1502 Calendar.setup({inputField:"form_enddate", ifFormat:"%Y-%m-%d", button:"img_enddate"});
1503 Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});
1504 </script>
1506 <script language="javascript">
1507 // jQuery stuff to make the page a little easier to use
1509 $(document).ready(function(){
1510 $("#form_save").click(function() { validate("save"); });
1511 $("#form_duplicate").click(function() { validate("duplicate"); });
1512 $("#find_available").click(function() { find_available(''); });
1513 $("#form_delete").click(function() { deleteEvent(); });
1514 $("#cancel").click(function() { window.close(); });
1516 // buttons affecting the modification of a repeating event
1517 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1518 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1519 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1520 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1522 // Initialize repeat options.
1523 dateChanged();
1526 // Check for errors when the form is submitted.
1527 function validate(valu) {
1528 var f = document.getElementById('theform');
1529 if (f.form_repeat.checked &&
1530 (! f.form_enddate.value || f.form_enddate.value < f.form_date.value)) {
1531 alert('<?php echo addslashes(xl("An end date later than the start date is required for repeated events!")); ?>');
1532 return false;
1534 <?php
1535 if($_GET['prov']!=true){
1537 if(f.form_pid.value == ''){
1538 alert('<?php echo addslashes(xl('Patient Name Required'));?>');
1539 return false;
1541 <?php
1544 $('#form_action').val(valu);
1546 <?php if ($repeats): ?>
1547 // existing repeating events need additional prompt
1548 if ($("#recurr_affect").val() == "") {
1549 DisableForm();
1550 // show the current/future/all DIV for the user to choose one
1551 $("#recurr_popup").css("visibility", "visible");
1552 return false;
1554 <?php endif; ?>
1556 return SubmitForm();
1559 // disable all the form elements outside the recurr_popup
1560 function DisableForm() {
1561 $("#theform").children().attr("disabled", "true");
1563 function EnableForm() {
1564 $("#theform").children().removeAttr("disabled");
1566 // hide the recurring popup DIV
1567 function HideRecurrPopup() {
1568 $("#recurr_popup").css("visibility", "hidden");
1571 function deleteEvent() {
1572 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?')); ?>")) {
1573 $('#form_action').val("delete");
1575 <?php if ($repeats): ?>
1576 // existing repeating events need additional prompt
1577 if ($("#recurr_affect").val() == "") {
1578 DisableForm();
1579 // show the current/future/all DIV for the user to choose one
1580 $("#recurr_popup").css("visibility", "visible");
1581 return false;
1583 <?php endif; ?>
1585 return SubmitForm();
1587 return false;
1590 function SubmitForm() {
1591 var f = document.forms[0];
1592 <?php if (!($GLOBALS['select_multi_providers'])) { // multi providers appt is not supported by check slot avail window, so skip ?>
1593 if (f.form_action.value != 'delete') {
1594 // Check slot availability.
1595 var mins = parseInt(f.form_hour.value) * 60 + parseInt(f.form_minute.value);
1596 if (f.form_ampm.value == '2' && mins < 720) mins += 720;
1597 find_available('&cktime=' + mins);
1599 else {
1600 top.restoreSession();
1601 f.submit();
1603 <?php } else { ?>
1604 top.restoreSession();
1605 f.submit();
1606 <?php } ?>
1608 return true;
1611 </script>
1613 </html>