Added support for repeating events like "2nd Tuesday" or "Last Friday" of the month.
[openemr.git] / interface / main / calendar / add_edit_event.php
blob19c1257d3706fbcbc63eb7326be47b734485ef90
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 f.form_repeat_type.options[5].text = nthtext;
971 var lasttext = '';
972 var tmp = new Date(d.getUTCFullYear(), d.getUTCMonth() + 1, 0);
973 if (tmp.getUTCDate() - d.getUTCDate() < 7) {
974 // This is a last occurrence of the specified weekday in the month,
975 // so permit that as an option.
976 lasttext = '<?php echo xls("Last"); ?> ' + downame;
978 f.form_repeat_type.options[6].text = lasttext;
981 // This is for callback by the find-available popup.
982 function setappt(year,mon,mday,hours,minutes) {
983 var f = document.forms[0];
984 f.form_date.value = '' + year + '-' +
985 ('' + (mon + 100)).substring(1) + '-' +
986 ('' + (mday + 100)).substring(1);
987 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
988 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
989 f.form_minute.value = ('' + (minutes + 100)).substring(1);
992 // Invoke the find-available popup.
993 function find_available(extra) {
994 top.restoreSession();
995 // (CHEMED) Conditional value selection, because there is no <select> element
996 // when making an appointment for a specific provider
997 var s = document.forms[0].form_provider;
998 var f = document.forms[0].facility;
999 <?php if ($userid != 0) { ?>
1000 s = document.forms[0].form_provider.value;
1001 f = document.forms[0].facility.value;
1002 <?php } else {?>
1003 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1004 f = document.forms[0].facility.options[f.selectedIndex].value;
1005 <?php }?>
1006 var c = document.forms[0].form_category;
1007 var formDate = document.forms[0].form_date;
1008 dlgopen('<?php echo $GLOBALS['web_root']; ?>/interface/main/calendar/find_appt_popup.php' +
1009 '?providerid=' + s +
1010 '&catid=' + c.options[c.selectedIndex].value +
1011 '&facility=' + f +
1012 '&startdate=' + formDate.value +
1013 '&evdur=' + document.forms[0].form_duration.value +
1014 '&eid=<?php echo 0 + $eid; ?>' +
1015 extra,
1016 '_blank', 500, 400);
1017 //END (CHEMED) modifications
1020 </script>
1022 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1024 </head>
1026 <body class="body_top" onunload='imclosing()'>
1028 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1029 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1030 <input type='hidden' size='2' name='resname' value='empty' />
1031 <?php
1032 if ($_POST["resname"]=="noresult"){
1033 echo '
1034 <script language="Javascript">
1035 // refresh and redirect the parent window
1036 if (!opener.closed && opener.refreshme) opener.refreshme();
1037 top.restoreSession();
1038 opener.document.location="../../new/new.php";
1039 // Close the window
1040 window.close();
1041 </script>';
1043 $classprov='current';
1044 $classpati='';
1046 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1047 <input type="hidden" name="form_action" id="form_action" value="">
1048 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1049 <!-- used for recurring events -->
1050 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo attr($date); ?>">
1051 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo attr($eventstartdate); ?>">
1052 <center>
1053 <table border='0' >
1054 <?php
1055 $provider_class='';
1056 $normal='';
1057 if($_GET['prov']==true){
1058 $provider_class="class='current'";
1060 else{
1061 $normal="class='current'";
1064 <tr><th><ul class="tabNav">
1065 <?php
1066 $eid=$_REQUEST["eid"];
1067 $startm=$_REQUEST["startampm"];
1068 $starth=$_REQUEST["starttimeh"];
1069 $uid=$_REQUEST["userid"];
1070 $starttm=$_REQUEST["starttimem"];
1071 $dt=$_REQUEST["date"];
1072 $cid=$_REQUEST["catid"];
1074 <li <?php echo $normal;?>>
1075 <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);?>'>
1076 <?php echo xlt('Patient');?></a>
1077 </li>
1078 <li <?php echo $provider_class;?>>
1079 <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);?>'>
1080 <?php echo xlt('Provider');?></a>
1081 </li>
1082 </ul>
1083 </th></tr>
1084 <tr><td colspan='10'>
1085 <table border='0' width='100%' bgcolor='#DDDDDD' >
1087 <tr>
1088 <td width='1%' nowrap>
1089 <b><?php echo ($GLOBALS['athletic_team'] ? xlt('Team/Squad') : xlt('Category')); ?>:</b>
1090 </td>
1091 <td nowrap>
1092 <select name='form_category' onchange='set_category()' style='width:100%'>
1093 <?php echo $catoptions ?>
1094 </select>
1095 </td>
1096 <td width='1%' nowrap>
1097 &nbsp;&nbsp;
1098 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1099 <?php if ($thisduration == 1440) echo "checked " ?>/>
1100 </td>
1101 <td colspan='2' nowrap id='tdallday1'>
1102 <?php echo xlt('All day event'); ?>
1103 </td>
1104 </tr>
1106 <tr>
1107 <td nowrap>
1108 <b><?php echo xlt('Date'); ?>:</b>
1109 </td>
1110 <td nowrap>
1111 <input type='text' size='10' name='form_date' id='form_date'
1112 value='<?php echo attr($date) ?>'
1113 title='<?php echo xla('yyyy-mm-dd event date or starting date'); ?>'
1114 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' onchange='dateChanged()' />
1115 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1116 id='img_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1117 title='<?php echo xla('Click here to choose a date'); ?>'>
1118 </td>
1119 <td nowrap>
1120 &nbsp;&nbsp;
1121 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1122 </td>
1123 <td width='1%' nowrap id='tdallday2'>
1124 <?php echo xlt('Time'); ?>
1125 </td>
1126 <td width='1%' nowrap id='tdallday3'>
1127 <input type='text' size='2' name='form_hour' value='<?php echo attr($starttimeh) ?>'
1128 title='<?php echo xla('Event start time'); ?>' /> :
1129 <input type='text' size='2' name='form_minute' value='<?php echo attr($starttimem) ?>'
1130 title='<?php echo xla('Event start time'); ?>' />&nbsp;
1131 <select name='form_ampm' title='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1132 <option value='1'><?php echo xlt('AM'); ?></option>
1133 <option value='2'<?php if ($startampm == '2') echo " selected" ?>><?php echo xlt('PM'); ?></option>
1134 </select>
1135 </td>
1136 </tr>
1138 <tr>
1139 <td nowrap>
1140 <b><?php echo ($GLOBALS['athletic_team'] ? xlt('Team/Squad') : xlt('Title')); ?>:</b>
1141 </td>
1142 <td nowrap>
1143 <input type='text' size='10' name='form_title' value='<?php echo attr($row['pc_title']); ?>'
1144 style='width:100%'
1145 title='<?php echo xla('Event title'); ?>' />
1146 </td>
1147 <td nowrap>&nbsp;
1149 </td>
1150 <td nowrap id='tdallday4'><?php echo xlt('duration'); ?>
1151 </td>
1152 <td nowrap id='tdallday5'>
1153 <input type='text' size='4' name='form_duration' value='<?php echo attr($thisduration) ?>' title='<?php echo xla('Event duration in minutes'); ?>' />
1154 <?php echo xlt('minutes'); ?>
1155 </td>
1156 </tr>
1158 <tr>
1159 <td nowrap><b><?php echo xlt('Facility'); ?>:</b></td>
1160 <td>
1161 <select name="facility" id="facility" >
1162 <?php
1164 // ===========================
1165 // EVENTS TO FACILITIES
1166 //(CHEMED) added service_location WHERE clause
1167 // get the facilities
1168 /***************************************************************
1169 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1170 ***************************************************************/
1171 $facils = getUserFacilities($_SESSION['authId']);
1172 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1173 /**************************************************************/
1174 while ($facrow = sqlFetchArray($qsql)) {
1175 /*************************************************************
1176 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1177 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1178 *************************************************************/
1179 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1180 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1181 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1183 else{
1184 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1185 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1187 /************************************************************/
1189 // EOS E2F
1190 // ===========================
1192 <?php
1193 //END (CHEMED) IF ?>
1194 </td>
1195 </select>
1196 </tr>
1197 <tr>
1198 <td nowrap>
1199 <b><?php echo xlt('Billing Facility'); ?>:</b>
1200 </td>
1201 <td>
1202 <?php
1203 billing_facility('billing_facility',$row['pc_billing_location']);
1205 </td>
1206 </tr>
1207 <?php
1208 if($_GET['prov']!=true){
1210 <tr id="patient_details">
1211 <td nowrap>
1212 <b><?php echo xlt('Patient'); ?>:</b>
1213 </td>
1214 <td nowrap>
1215 <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 />
1216 <input type='hidden' name='form_pid' value='<?php echo attr($patientid) ?>' />
1217 </td>
1218 <td colspan='3' nowrap style='font-size:8pt'>
1219 &nbsp;
1220 <span class="infobox">
1221 <?php if ($patienttitle != "") { echo $patienttitle; } ?>
1222 </span>
1223 </td>
1224 </tr>
1225 <?php
1228 <tr>
1229 <td nowrap>
1230 <b><?php echo xlt('Provider'); ?>:</b>
1231 </td>
1232 <td nowrap>
1234 <?php
1236 // =======================================
1237 // multi providers
1238 // =======================================
1239 if ($GLOBALS['select_multi_providers']) {
1241 // there are two posible situations: edit and new record
1243 // this is executed only on edit ($eid)
1244 if ($eid) {
1245 if ( $multiple_value ) {
1246 // find all the providers around multiple key
1247 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value) );
1248 while ($r = sqlFetchArray($qall)) {
1249 $providers_array[] = $r['providers'];
1251 } else {
1252 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1253 $providers_array = sqlFetchArray($qall);
1257 // build the selection tool
1258 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1260 while ($urow = sqlFetchArray($ures)) {
1261 echo " <option value='" . attr($urow['id']) . "'";
1263 if ($userid) {
1264 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1267 echo ">" . text($urow['lname']);
1268 if ($urow['fname']) echo ", " . text($urow['fname']);
1269 echo "</option>\n";
1272 echo '</select>';
1274 // =======================================
1275 // single provider
1276 // =======================================
1277 } else {
1279 if ($eid) {
1280 // get provider from existing event
1281 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1282 $provider = sqlFetchArray($qprov);
1283 $defaultProvider = $provider['pc_aid'];
1285 else {
1286 // this is a new event so smartly choose a default provider
1287 /*****************************************************************
1288 if ($userid) {
1289 // Provider already given to us as a GET parameter.
1290 $defaultProvider = $userid;
1292 else {
1293 // default to the currently logged-in user
1294 $defaultProvider = $_SESSION['authUserID'];
1295 // or, if we have chosen a provider in the calendar, default to them
1296 // choose the first one if multiple have been selected
1297 if (count($_SESSION['pc_username']) >= 1) {
1298 // get the numeric ID of the first provider in the array
1299 $pc_username = $_SESSION['pc_username'];
1300 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1301 $defaultProvider = $firstProvider['id'];
1306 echo "<select name='form_provider' style='width:100%' />";
1307 while ($urow = sqlFetchArray($ures)) {
1308 echo " <option value='" . $urow['id'] . "'";
1309 if ($urow['id'] == $defaultProvider) echo " selected";
1310 echo ">" . $urow['lname'];
1311 if ($urow['fname']) echo ", " . $urow['fname'];
1312 echo "</option>\n";
1314 echo "</select>";
1315 *****************************************************************/
1316 // default to the currently logged-in user
1317 $defaultProvider = $_SESSION['authUserID'];
1318 // or, if we have chosen a provider in the calendar, default to them
1319 // choose the first one if multiple have been selected
1320 if (count($_SESSION['pc_username']) >= 1) {
1321 // get the numeric ID of the first provider in the array
1322 $pc_username = $_SESSION['pc_username'];
1323 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0]) ));
1324 $defaultProvider = $firstProvider['id'];
1326 // if we clicked on a provider's schedule to add the event, use THAT.
1327 if ($userid) $defaultProvider = $userid;
1329 echo "<select name='form_provider' style='width:100%' />";
1330 while ($urow = sqlFetchArray($ures)) {
1331 echo " <option value='" . attr($urow['id']) . "'";
1332 if ($urow['id'] == $defaultProvider) echo " selected";
1333 echo ">" . text($urow['lname']);
1334 if ($urow['fname']) echo ", " . text($urow['fname']);
1335 echo "</option>\n";
1337 echo "</select>";
1338 /****************************************************************/
1343 </td>
1344 <td nowrap>
1345 &nbsp;&nbsp;
1346 <input type='checkbox' name='form_repeat' onclick='set_repeat(this)' value='1'<?php if ($repeats) echo " checked" ?>/>
1347 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat -->
1348 </td>
1349 <td nowrap id='tdrepeat1'><?php echo xlt('Repeats'); ?>
1350 </td>
1351 <td nowrap>
1353 <select name='form_repeat_freq' title='<?php echo xla('Every, every other, every 3rd, etc.'); ?>'>
1354 <?php
1355 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1356 as $key => $value)
1358 echo " <option value='" . attr($key) . "'";
1359 if ($key == $repeatfreq) echo " selected";
1360 echo ">" . text($value) . "</option>\n";
1363 </select>
1365 <select name='form_repeat_type'>
1366 <?php
1367 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1368 // when the start date is set.
1369 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1370 5 => '', 6 => '') as $key => $value)
1372 echo " <option value='" . attr($key) . "'";
1373 if ($key == $repeattype) echo " selected";
1374 echo ">" . text($value) . "</option>\n";
1377 </select>
1379 </td>
1380 </tr>
1382 <tr>
1383 <td nowrap>
1384 <span id='title_apptstatus'><b><?php echo ($GLOBALS['athletic_team'] ? xlt('Session Type') : xlt('Status')); ?>:</b></span>
1385 <span id='title_prefcat' style='display:none'><b><?php echo xlt('Pref Cat'); ?>:</b></span>
1386 </td>
1387 <td nowrap>
1389 <?php
1390 generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'SKIP'), $row['pc_apptstatus']);
1392 <!--
1393 The following list will be invisible unless this is an In Office
1394 event, in which case form_apptstatus (above) is to be invisible.
1396 <select name='form_prefcat' style='width:100%;display:none' title='<?php echo xla('Preferred Event Category');?>'>
1397 <?php echo $prefcat_options ?>
1398 </select>
1400 </td>
1401 <td nowrap>&nbsp;
1403 </td>
1404 <td nowrap id='tdrepeat2'><?php echo xlt('until'); ?>
1405 </td>
1406 <td nowrap>
1407 <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');?>' />
1408 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1409 id='img_enddate' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1410 title='<?php echo xla('Click here to choose a date');?>'>
1411 <?php
1412 if ($repeatexdate != "") {
1413 $tmptitle = "The following dates are excluded from the repeating series";
1414 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1415 else { $tmptitle .= "\n"; }
1416 $exdates = explode(",", $repeatexdate);
1417 foreach ($exdates as $exdate) {
1418 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1420 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1423 </td>
1424 </tr>
1426 <tr>
1427 <td nowrap>
1428 <b><?php echo xlt('Comments'); ?>:</b>
1429 </td>
1430 <td colspan='4' nowrap>
1431 <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');?>' />
1432 </td>
1433 </tr>
1435 <?php
1436 // DOB is important for the clinic, so if it's missing give them a chance
1437 // to enter it right here. We must display or hide this row dynamically
1438 // in case the patient-select popup is used.
1439 $patient_dob = trim($prow['DOB']);
1440 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00')) ?
1441 '' : 'none';
1443 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1444 <td colspan='4' nowrap>
1445 <b><font color='red'><?php echo xlt('DOB is missing, please enter if possible'); ?>:</font></b>
1446 </td>
1447 <td nowrap>
1448 <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)' />
1449 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1450 id='img_dob' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1451 title='<?php echo xla('Click here to choose a date');?>'>
1452 </td>
1453 </tr>
1455 </table></td></tr>
1456 <tr class='text'><td colspan='10'>
1458 <input type='button' name='form_save' id='form_save' value='<?php echo xla('Save');?>' />
1459 &nbsp;
1461 <?php if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1462 <input type='button' id='find_available' value='<?php echo xla('Find Available');?>' />
1463 <?php } ?>
1465 &nbsp;
1466 <input type='button' name='form_delete' id='form_delete' value='<?php echo xla('Delete');?>'<?php if (!$eid) echo " disabled" ?> />
1467 &nbsp;
1468 <input type='button' id='cancel' value='<?php echo xla('Cancel');?>' />
1469 &nbsp;
1470 <input type='button' name='form_duplicate' id='form_duplicate' value='<?php echo xla('Create Duplicate');?>' />
1471 </p></td></tr></table>
1472 <?php if ($informant) echo "<p class='text'>" . xlt('Last update by') . " text($informant) " . xlt('on') . " " . text($row['pc_time']) . "</p>\n"; ?>
1473 </center>
1474 </form>
1476 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1477 <?php echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?>
1478 <br>
1479 <input type="button" name="all_events" id="all_events" value=" All ">
1480 <input type="button" name="future_events" id="future_events" value="Future">
1481 <input type="button" name="current_event" id="current_event" value="Current">
1482 <input type="button" name="recurr_cancel" id="recurr_cancel" value="Cancel">
1483 </div>
1485 </body>
1487 <script language='JavaScript'>
1488 <?php if ($eid) { ?>
1489 set_display();
1490 <?php } else { ?>
1491 set_category();
1492 <?php } ?>
1493 set_allday();
1494 set_repeat();
1496 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
1497 Calendar.setup({inputField:"form_enddate", ifFormat:"%Y-%m-%d", button:"img_enddate"});
1498 Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});
1499 </script>
1501 <script language="javascript">
1502 // jQuery stuff to make the page a little easier to use
1504 $(document).ready(function(){
1505 $("#form_save").click(function() { validate("save"); });
1506 $("#form_duplicate").click(function() { validate("duplicate"); });
1507 $("#find_available").click(function() { find_available(''); });
1508 $("#form_delete").click(function() { deleteEvent(); });
1509 $("#cancel").click(function() { window.close(); });
1511 // buttons affecting the modification of a repeating event
1512 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1513 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1514 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1515 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1517 // Initialize repeat options.
1518 dateChanged();
1521 // Check for errors when the form is submitted.
1522 function validate(valu) {
1523 var f = document.getElementById('theform');
1524 if (f.form_repeat.checked &&
1525 (! f.form_enddate.value || f.form_enddate.value < f.form_date.value)) {
1526 alert('<?php echo addslashes(xl("An end date later than the start date is required for repeated events!")); ?>');
1527 return false;
1529 <?php
1530 if($_GET['prov']!=true){
1532 if(f.form_pid.value == ''){
1533 alert('<?php echo addslashes(xl('Patient Name Required'));?>');
1534 return false;
1536 <?php
1539 $('#form_action').val(valu);
1541 <?php if ($repeats): ?>
1542 // existing repeating events need additional prompt
1543 if ($("#recurr_affect").val() == "") {
1544 DisableForm();
1545 // show the current/future/all DIV for the user to choose one
1546 $("#recurr_popup").css("visibility", "visible");
1547 return false;
1549 <?php endif; ?>
1551 return SubmitForm();
1554 // disable all the form elements outside the recurr_popup
1555 function DisableForm() {
1556 $("#theform").children().attr("disabled", "true");
1558 function EnableForm() {
1559 $("#theform").children().removeAttr("disabled");
1561 // hide the recurring popup DIV
1562 function HideRecurrPopup() {
1563 $("#recurr_popup").css("visibility", "hidden");
1566 function deleteEvent() {
1567 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?')); ?>")) {
1568 $('#form_action').val("delete");
1570 <?php if ($repeats): ?>
1571 // existing repeating events need additional prompt
1572 if ($("#recurr_affect").val() == "") {
1573 DisableForm();
1574 // show the current/future/all DIV for the user to choose one
1575 $("#recurr_popup").css("visibility", "visible");
1576 return false;
1578 <?php endif; ?>
1580 return SubmitForm();
1582 return false;
1585 function SubmitForm() {
1586 var f = document.forms[0];
1587 <?php if (!($GLOBALS['select_multi_providers'])) { // multi providers appt is not supported by check slot avail window, so skip ?>
1588 if (f.form_action.value != 'delete') {
1589 // Check slot availability.
1590 var mins = parseInt(f.form_hour.value) * 60 + parseInt(f.form_minute.value);
1591 if (f.form_ampm.value == '2' && mins < 720) mins += 720;
1592 find_available('&cktime=' + mins);
1594 else {
1595 top.restoreSession();
1596 f.submit();
1598 <?php } else { ?>
1599 top.restoreSession();
1600 f.submit();
1601 <?php } ?>
1603 return true;
1606 </script>
1608 </html>