Migrate sql billing copay items to ar_session/ar_activity sql tables.
[openemr.git] / interface / main / calendar / add_edit_event.php
blob1f0f1971cff76788be0e332c01b421bfca0bfc0b
1 <?php
2 // Copyright (C) 2005-2011 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 include_once("../../globals.php");
24 include_once("$srcdir/patient.inc");
25 include_once("$srcdir/forms.inc");
26 include_once("$srcdir/calendar.inc");
27 include_once("$srcdir/formdata.inc.php");
28 include_once("$srcdir/options.inc.php");
29 include_once("$srcdir/encounter_events.inc.php");
31 // Things that might be passed by our opener.
33 $eid = $_GET['eid']; // only for existing events
34 $date = $_GET['date']; // this and below only for new events
35 $userid = $_GET['userid'];
36 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
38 if ($date)
39 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
40 else
41 $date = date("Y-m-d");
43 $starttimem = '00';
44 if (isset($_GET['starttimem']))
45 $starttimem = substr('00' . $_GET['starttimem'], -2);
47 if (isset($_GET['starttimeh'])) {
48 $starttimeh = $_GET['starttimeh'];
49 if (isset($_GET['startampm'])) {
50 if ($_GET['startampm'] == '2' && $starttimeh < 12)
51 $starttimeh += 12;
53 } else {
54 $starttimeh = date("G");
56 $startampm = '';
58 $info_msg = "";
62 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
64 <?php
66 function InsertEventFull()
68 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
69 // =======================================
70 // multi providers case
71 // =======================================
72 if (is_array($_POST['form_provider'])) {
74 // obtain the next available unique key to group multiple providers around some event
75 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
76 $max = sqlFetchArray($q);
77 $new_multiple_value = $max['max'] + 1;
79 foreach ($_POST['form_provider'] as $provider) {
80 $args = $_POST;
81 // specify some special variables needed for the INSERT
82 $args['new_multiple_value'] = $new_multiple_value;
83 $args['form_provider'] = $provider;
84 $args['event_date'] = $event_date;
85 $args['duration'] = $duration * 60;
86 $args['recurrspec'] = $recurrspec;
87 $args['starttime'] = $starttime;
88 $args['endtime'] = $endtime;
89 $args['locationspec'] = $locationspec;
90 InsertEvent($args);
93 // ====================================
94 // single provider
95 // ====================================
96 } else {
97 $args = $_POST;
98 // specify some special variables needed for the INSERT
99 $args['new_multiple_value'] = "";
100 $args['event_date'] = $event_date;
101 $args['duration'] = $duration * 60;
102 $args['recurrspec'] = $recurrspec;
103 $args['starttime'] = $starttime;
104 $args['endtime'] = $endtime;
105 $args['locationspec'] = $locationspec;
106 InsertEvent($args);
109 function DOBandEncounter()
111 global $event_date,$info_msg;
112 // Save new DOB if it's there.
113 $patient_dob = trim($_POST['form_dob']);
114 if ($patient_dob && $_POST['form_pid']) {
115 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
116 "pid = '" . $_POST['form_pid'] . "'");
119 // Auto-create a new encounter if appropriate.
121 if ($GLOBALS['auto_create_new_encounters'] && $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
123 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, formData("form_comments"), $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
124 if($encounter){
125 $info_msg .= xl("New encounter created with id");
126 $info_msg .= " $encounter";
130 //================================================================================================================
132 // EVENTS TO FACILITIES (lemonsoftware)
133 //(CHEMED) get facility name
134 // edit event case - if there is no association made, then insert one with the first facility
135 if ( $eid ) {
136 $selfacil = '';
137 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
138 FROM openemr_postcalendar_events
139 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
140 WHERE pc_eid = $eid");
141 // if ( !$facility['pc_facility'] ) {
142 if ( is_array($facility) && !$facility['pc_facility'] ) {
143 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
144 $min = $qmin['minId'];
145 $min_name = $qmin['facility'];
147 // multiple providers case
148 if ( $GLOBALS['select_multi_providers'] ) {
149 $mul = $facility['pc_multiple'];
150 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
152 // EOS multiple
154 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
155 $e2f = $min;
156 $e2f_name = $min_name;
157 } else {
158 // not edit event
159 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
160 $e2f = $_SESSION['pc_facility'];
161 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
162 $e2f = $_COOKIE['pc_facility'];
163 } else {
164 $e2f = $facility['pc_facility'];
165 $e2f_name = $facility['name'];
169 // EOS E2F
170 // ===========================
171 //=============================================================================================================================
172 if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
174 // the starting date of the event, pay attention with this value
175 // when editing recurring events -- JRM Oct-08
176 $event_date = fixDate($_POST['form_date']);
178 // Compute start and end time strings to be saved.
179 if ($_POST['form_allday']) {
180 $tmph = 0;
181 $tmpm = 0;
182 $duration = 24 * 60;
183 } else {
184 $tmph = $_POST['form_hour'] + 0;
185 $tmpm = $_POST['form_minute'] + 0;
186 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
187 $duration = $_POST['form_duration'];
189 $starttime = "$tmph:$tmpm:00";
191 $tmpm += $duration;
192 while ($tmpm >= 60) {
193 $tmpm -= 60;
194 ++$tmph;
196 $endtime = "$tmph:$tmpm:00";
198 // Useless garbage that we must save.
199 $locationspecs = array("event_location" => "",
200 "event_street1" => "",
201 "event_street2" => "",
202 "event_city" => "",
203 "event_state" => "",
204 "event_postal" => ""
206 $locationspec = serialize($locationspecs);
208 // capture the recurring specifications
209 $recurrspec = array("event_repeat_freq" => $_POST['form_repeat_freq'],
210 "event_repeat_freq_type" => $_POST['form_repeat_type'],
211 "event_repeat_on_num" => "1",
212 "event_repeat_on_day" => "0",
213 "event_repeat_on_freq" => "0",
214 "exdate" => $_POST['form_repeat_exdate']
217 // no recurr specs, this is used for adding a new non-recurring event
218 $noRecurrspec = array("event_repeat_freq" => "",
219 "event_repeat_freq_type" => "",
220 "event_repeat_on_num" => "1",
221 "event_repeat_on_day" => "0",
222 "event_repeat_on_freq" => "0",
223 "exdate" => ""
226 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
227 //=============================================================================================================================
228 if ($_POST['form_action'] == "duplicate") {
230 InsertEventFull();
231 DOBandEncounter();
235 // If we are saving, then save and close the window.
237 if ($_POST['form_action'] == "save") {
238 /* =======================================================
239 * UPDATE EVENTS
240 * =====================================================*/
241 if ($eid) {
243 // what is multiple key around this $eid?
244 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
246 // ====================================
247 // multiple providers
248 // ====================================
249 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
251 // obtain current list of providers regarding the multiple key
252 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
253 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
255 // get the new list of providers from the submitted form
256 $providers_new = $_POST['form_provider'];
258 // ===== Only current event of repeating series =====
259 if ($_POST['recurr_affect'] == 'current') {
261 // update all existing event records to exlude the current date
262 foreach ($providers_current as $provider) {
263 // update the provider's original event
264 // get the original event's repeat specs
265 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
266 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
267 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
268 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
269 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
270 else { $oldRecurrspec['exdate'] .= $selected_date; }
272 // mod original event recur specs to exclude this date
273 sqlStatement("UPDATE openemr_postcalendar_events SET " .
274 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
275 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
278 // obtain the next available unique key to group multiple providers around some event
279 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
280 $max = sqlFetchArray($q);
281 $new_multiple_value = $max['max'] + 1;
283 // insert a new event record for each provider selected on the form
284 foreach ($providers_new as $provider) {
285 // insert a new event on this date with POST form data
286 $args = $_POST;
287 // specify some special variables needed for the INSERT
288 $args['new_multiple_value'] = $new_multiple_value;
289 $args['form_provider'] = $provider;
290 $args['event_date'] = $event_date;
291 $args['duration'] = $duration * 60;
292 // this event is forced to NOT REPEAT
293 $args['form_repeat'] = "0";
294 $args['recurrspec'] = $noRecurrspec;
295 $args['form_enddate'] = "0000-00-00";
296 $args['starttime'] = $starttime;
297 $args['endtime'] = $endtime;
298 $args['locationspec'] = $locationspec;
299 InsertEvent($args);
303 // ===== Future Recurring events of a repeating series =====
304 else if ($_POST['recurr_affect'] == 'future') {
305 // update all existing event records to
306 // stop recurring on this date-1
307 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
308 foreach ($providers_current as $provider) {
309 // mod original event recur specs to end on this date
310 sqlStatement("UPDATE openemr_postcalendar_events SET " .
311 " pc_enddate = '" . $selected_date ."' ".
312 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
315 // obtain the next available unique key to group multiple providers around some event
316 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
317 $max = sqlFetchArray($q);
318 $new_multiple_value = $max['max'] + 1;
320 // insert a new event record for each provider selected on the form
321 foreach ($providers_new as $provider) {
322 // insert a new event on this date with POST form data
323 $args = $_POST;
324 // specify some special variables needed for the INSERT
325 $args['new_multiple_value'] = $new_multiple_value;
326 $args['form_provider'] = $provider;
327 $args['event_date'] = $event_date;
328 $args['duration'] = $duration * 60;
329 $args['recurrspec'] = $recurrspec;
330 $args['starttime'] = $starttime;
331 $args['endtime'] = $endtime;
332 $args['locationspec'] = $locationspec;
333 InsertEvent($args);
337 else {
338 /* =================================================================== */
339 // ===== a Single event or All events in a repeating series ==========
340 /* =================================================================== */
342 // this difference means that some providers from current was UNCHECKED
343 // so we must delete this event for them
344 $r1 = array_diff ($providers_current, $providers_new);
345 if (count ($r1)) {
346 foreach ($r1 as $to_be_removed) {
347 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
351 // perform a check to see if user changed event date
352 // this is important when editing an existing recurring event
353 // oct-08 JRM
354 if ($_POST['form_date'] == $_POST['selected_date']) {
355 // user has NOT changed the start date of the event
356 $event_date = fixDate($_POST['event_start_date']);
359 // this difference means that some providers were added
360 // so we must insert this event for them
361 $r2 = array_diff ($providers_new, $providers_current);
362 if (count ($r2)) {
363 foreach ($r2 as $to_be_inserted) {
364 $args = $_POST;
365 // specify some special variables needed for the INSERT
366 $args['new_multiple_value'] = $row['pc_multiple'];
367 $args['form_provider'] = $to_be_inserted;
368 $args['event_date'] = $event_date;
369 $args['duration'] = $duration * 60;
370 $args['recurrspec'] = $recurrspec;
371 $args['starttime'] = $starttime;
372 $args['endtime'] = $endtime;
373 $args['locationspec'] = $locationspec;
374 InsertEvent($args);
378 // after the two diffs above, we must update for remaining providers
379 // those who are intersected in $providers_current and $providers_new
380 foreach ($_POST['form_provider'] as $provider) {
381 sqlStatement("UPDATE openemr_postcalendar_events SET " .
382 "pc_catid = '" . $_POST['form_category'] . "', " .
383 "pc_pid = '" . $_POST['form_pid'] . "', " .
384 "pc_title = '" . formData("form_title") . "', " .
385 "pc_time = NOW(), " .
386 "pc_hometext = '" . formData("form_comments") . "', " .
387 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
388 "pc_eventDate = '" . $event_date . "', " .
389 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
390 "pc_duration = '" . ($duration * 60) . "', " .
391 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
392 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
393 "pc_startTime = '$starttime', " .
394 "pc_endTime = '$endtime', " .
395 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
396 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
397 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
398 "pc_facility = '" .(int)$_POST['facility'] ."' ," . // FF stuff
399 "pc_billing_location = '" .(int)$_POST['billing_facility'] ."' " .
400 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
401 } // foreach
405 // ====================================
406 // single provider
407 // ====================================
408 } elseif ( !$row['pc_multiple'] ) {
409 if ( $GLOBALS['select_multi_providers'] ) {
410 $prov = $_POST['form_provider'][0];
411 } else {
412 $prov = $_POST['form_provider'];
415 if ($_POST['recurr_affect'] == 'current') {
416 // get the original event's repeat specs
417 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
418 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
419 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
420 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
421 else { $oldRecurrspec['exdate'] .= $selected_date; }
423 // mod original event recur specs to exclude this date
424 sqlStatement("UPDATE openemr_postcalendar_events SET " .
425 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
426 " WHERE pc_eid = '$eid'");
428 // insert a new event on this date with POST form data
429 $args = $_POST;
430 // specify some special variables needed for the INSERT
431 $args['event_date'] = $event_date;
432 $args['duration'] = $duration * 60;
433 // this event is forced to NOT REPEAT
434 $args['form_repeat'] = "0";
435 $args['recurrspec'] = $noRecurrspec;
436 $args['form_enddate'] = "0000-00-00";
437 $args['starttime'] = $starttime;
438 $args['endtime'] = $endtime;
439 $args['locationspec'] = $locationspec;
440 InsertEvent($args);
442 else if ($_POST['recurr_affect'] == 'future') {
443 // mod original event to stop recurring on this date-1
444 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
445 sqlStatement("UPDATE openemr_postcalendar_events SET " .
446 " pc_enddate = '" . $selected_date ."' ".
447 " WHERE pc_eid = '$eid'");
449 // insert a new event starting on this date with POST form data
450 $args = $_POST;
451 // specify some special variables needed for the INSERT
452 $args['event_date'] = $event_date;
453 $args['duration'] = $duration * 60;
454 $args['recurrspec'] = $recurrspec;
455 $args['starttime'] = $starttime;
456 $args['endtime'] = $endtime;
457 $args['locationspec'] = $locationspec;
458 InsertEvent($args);
460 else {
462 // perform a check to see if user changed event date
463 // this is important when editing an existing recurring event
464 // oct-08 JRM
465 if ($_POST['form_date'] == $_POST['selected_date']) {
466 // user has NOT changed the start date of the event
467 $event_date = fixDate($_POST['event_start_date']);
470 // mod the SINGLE event or ALL EVENTS in a repeating series
471 // simple provider case
472 sqlStatement("UPDATE openemr_postcalendar_events SET " .
473 "pc_catid = '" . $_POST['form_category'] . "', " .
474 "pc_aid = '" . $prov . "', " .
475 "pc_pid = '" . $_POST['form_pid'] . "', " .
476 "pc_title = '" . formData("form_title") . "', " .
477 "pc_time = NOW(), " .
478 "pc_hometext = '" . formData("form_comments") . "', " .
479 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
480 "pc_eventDate = '" . $event_date . "', " .
481 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
482 "pc_duration = '" . ($duration * 60) . "', " .
483 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
484 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
485 "pc_startTime = '$starttime', " .
486 "pc_endTime = '$endtime', " .
487 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
488 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
489 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
490 "pc_facility = '" .(int)$_POST['facility'] ."' ," . // FF stuff
491 "pc_billing_location = '" .(int)$_POST['billing_facility'] ."' " .
492 "WHERE pc_eid = '$eid'");
496 // =======================================
497 // end Update Multi providers case
498 // =======================================
500 // EVENTS TO FACILITIES
501 $e2f = (int)$eid;
504 } else {
505 /* =======================================================
506 * INSERT NEW EVENT(S)
507 * ======================================================*/
509 InsertEventFull();
513 // done with EVENT insert/update statements
515 DOBandEncounter();
519 // =======================================
520 // DELETE EVENT(s)
521 // =======================================
522 else if ($_POST['form_action'] == "delete") {
523 // =======================================
524 // multi providers event
525 // =======================================
526 if ($GLOBALS['select_multi_providers']) {
528 // what is multiple key around this $eid?
529 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
531 // obtain current list of providers regarding the multiple key
532 $providers_current = array();
533 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
534 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
536 // establish a WHERE clause
537 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = {$row['pc_multiple']}"; }
538 else { $whereClause = "pc_eid = $eid"; }
540 if ($_POST['recurr_affect'] == 'current') {
541 // update all existing event records to exlude the current date
542 foreach ($providers_current as $provider) {
543 // update the provider's original event
544 // get the original event's repeat specs
545 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
546 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
547 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
548 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
549 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
550 else { $oldRecurrspec['exdate'] .= $selected_date; }
552 // mod original event recur specs to exclude this date
553 sqlStatement("UPDATE openemr_postcalendar_events SET " .
554 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
555 " WHERE ". $whereClause);
558 else if ($_POST['recurr_affect'] == 'future') {
559 // update all existing event records to stop recurring on this date-1
560 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
561 foreach ($providers_current as $provider) {
562 // update the provider's original event
563 sqlStatement("UPDATE openemr_postcalendar_events SET " .
564 " pc_enddate = '" . $selected_date ."' ".
565 " WHERE ".$whereClause);
568 else {
569 // really delete the event from the database
570 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
574 // =======================================
575 // single provider event
576 // =======================================
577 else {
579 if ($_POST['recurr_affect'] == 'current') {
580 // mod original event recur specs to exclude this date
582 // get the original event's repeat specs
583 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
584 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
585 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
586 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
587 else { $oldRecurrspec['exdate'] .= $selected_date; }
588 sqlStatement("UPDATE openemr_postcalendar_events SET " .
589 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
590 " WHERE pc_eid = '$eid'");
593 else if ($_POST['recurr_affect'] == 'future') {
594 // mod original event to stop recurring on this date-1
595 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
596 sqlStatement("UPDATE openemr_postcalendar_events SET " .
597 " pc_enddate = '" . $selected_date ."' ".
598 " WHERE pc_eid = '$eid'");
601 else {
602 // fully delete the event from the database
603 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
608 if ($_POST['form_action'] != "") {
609 // Close this window and refresh the calendar display.
610 echo "<html>\n<body>\n<script language='JavaScript'>\n";
611 if ($info_msg) echo " alert('$info_msg');\n";
612 echo " if (opener && !opener.closed && opener.refreshme) opener.refreshme();\n";
613 echo " window.close();\n";
614 echo "</script>\n</body>\n</html>\n";
615 exit();
618 //*********************************
619 // If we get this far then we are displaying the form.
620 //*********************************
622 /*********************************************************************
623 This has been migrate to the administration->lists
624 $statuses = array(
625 '-' => '',
626 '*' => xl('* Reminder done'),
627 '+' => xl('+ Chart pulled'),
628 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
629 '?' => xl('? No show'),
630 '@' => xl('@ Arrived'),
631 '~' => xl('~ Arrived late'),
632 '!' => xl('! Left w/o visit'),
633 '#' => xl('# Ins/fin issue'),
634 '<' => xl('< In exam room'),
635 '>' => xl('> Checked out'),
636 '$' => xl('$ Coding done'),
637 '%' => xl('% Cancelled < 24h ')
639 *********************************************************************/
641 $repeats = 0; // if the event repeats
642 $repeattype = '0';
643 $repeatfreq = '0';
644 $patientid = '';
645 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
646 $patientname = xl('Click to select');
647 $patienttitle = "";
648 $hometext = "";
649 $row = array();
650 $informant = "";
652 // If we are editing an existing event, then get its data.
653 if ($eid) {
654 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
656 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
657 "FROM openemr_postcalendar_events AS e " .
658 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
659 "WHERE pc_eid = $eid");
660 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
662 // instead of using the event's starting date, keep what has been provided
663 // via the GET array, see the top of this file
664 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
665 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
666 $userid = $row['pc_aid'];
667 $patientid = $row['pc_pid'];
668 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
669 $starttimem = substr($row['pc_startTime'], 3, 2);
670 $repeats = $row['pc_recurrtype'];
671 $multiple_value = $row['pc_multiple'];
673 // parse out the repeating data, if any
674 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
675 $repeattype = $rspecs['event_repeat_freq_type'];
676 $repeatfreq = $rspecs['event_repeat_freq'];
677 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
679 $hometext = $row['pc_hometext'];
680 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
682 else {
683 // a NEW event
684 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
686 //-------------------------------------
687 //(CHEMED)
688 //Set default facility for a new event based on the given 'userid'
689 if ($userid) {
690 /*************************************************************
691 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
692 *************************************************************/
693 if ($_SESSION['pc_facility']) {
694 $pref_facility = sqlFetchArray(sqlStatement(sprintf("
695 SELECT f.id as facility_id,
696 f.name as facility
697 FROM facility f
698 WHERE f.id = %d
700 $_SESSION['pc_facility']
701 )));
702 } else {
703 $pref_facility = sqlFetchArray(sqlStatement("
704 SELECT u.facility_id,
705 f.name as facility
706 FROM users u
707 LEFT JOIN facility f on (u.facility_id = f.id)
708 WHERE u.id = $userid
709 "));
711 /************************************************************/
712 $e2f = $pref_facility['facility_id'];
713 $e2f_name = $pref_facility['facility'];
715 //END of CHEMED -----------------------
718 // If we have a patient ID, get the name and phone numbers to display.
719 if ($patientid) {
720 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
721 "FROM patient_data WHERE pid = '" . $patientid . "'");
722 $patientname = $prow['lname'] . ", " . $prow['fname'];
723 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
724 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
727 // Get the providers list.
728 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
729 "authorized != 0 AND active = 1 ORDER BY lname, fname");
731 // Get event categories.
732 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
733 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
735 // Fix up the time format for AM/PM.
736 $startampm = '1';
737 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
738 $startampm = '2';
739 if ($starttimeh > 12) $starttimeh -= 12;
743 <html>
744 <head>
745 <?php html_header_show(); ?>
746 <title><?php echo $eid ? xl('Edit','e') : xl('Add New','e') ?> <?php xl('Event','e');?></title>
747 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
749 <style>
750 td { font-size:0.8em; }
751 </style>
753 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
754 <script type="text/javascript" src="../../../library/topdialog.js"></script>
755 <script type="text/javascript" src="../../../library/dialog.js"></script>
756 <script type="text/javascript" src="../../../library/textformat.js"></script>
757 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
758 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
759 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
761 <script language="JavaScript">
763 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
765 var durations = new Array();
766 // var rectypes = new Array();
767 <?php
768 // Read the event categories, generate their options list, and get
769 // the default event duration from them if this is a new event.
770 $cattype=0;
771 if($_GET['prov']==true){
772 $cattype=1;
774 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
775 "FROM openemr_postcalendar_categories WHERE pc_cattype='".$cattype."' ORDER BY pc_catname");
776 $catoptions = "";
777 $prefcat_options = " <option value='0'>-- None --</option>\n";
778 $thisduration = 0;
779 if ($eid) {
780 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
782 while ($crow = sqlFetchArray($cres)) {
783 $duration = round($crow['pc_duration'] / 60);
784 if ($crow['pc_end_all_day']) $duration = 1440;
785 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
786 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
787 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
788 if ($eid) {
789 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
790 } else {
791 if ($crow['pc_catid'] == $default_catid) {
792 $catoptions .= " selected";
793 $thisduration = $duration;
796 $catoptions .= ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
798 // This section is to build the list of preferred categories:
799 if ($duration) {
800 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
801 if ($eid) {
802 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
804 $prefcat_options .= ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
810 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
812 // This is for callback by the find-patient popup.
813 function setpatient(pid, lname, fname, dob) {
814 var f = document.forms[0];
815 f.form_patient.value = lname + ', ' + fname;
816 f.form_pid.value = pid;
817 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
818 document.getElementById('dob_row').style.display = dobstyle;
821 // This invokes the find-patient popup.
822 function sel_patient() {
823 dlgopen('find_patient_popup.php', '_blank', 500, 400);
826 // Do whatever is needed when a new event category is selected.
827 // For now this means changing the event title and duration.
828 function set_display() {
829 var f = document.forms[0];
830 var s = f.form_category;
831 if (s.selectedIndex >= 0) {
832 var catid = s.options[s.selectedIndex].value;
833 var style_apptstatus = document.getElementById('title_apptstatus').style;
834 var style_prefcat = document.getElementById('title_prefcat').style;
835 if (catid == '2') { // In Office
836 style_apptstatus.display = 'none';
837 style_prefcat.display = '';
838 f.form_apptstatus.style.display = 'none';
839 f.form_prefcat.style.display = '';
840 } else {
841 style_prefcat.display = 'none';
842 style_apptstatus.display = '';
843 f.form_prefcat.style.display = 'none';
844 f.form_apptstatus.style.display = '';
849 // Do whatever is needed when a new event category is selected.
850 // For now this means changing the event title and duration.
851 function set_category() {
852 var f = document.forms[0];
853 var s = f.form_category;
854 if (s.selectedIndex >= 0) {
855 var catid = s.options[s.selectedIndex].value;
856 f.form_title.value = s.options[s.selectedIndex].text;
857 f.form_duration.value = durations[catid];
858 set_display();
862 // Modify some visual attributes when the all-day or timed-event
863 // radio buttons are clicked.
864 function set_allday() {
865 var f = document.forms[0];
866 var color1 = '#777777';
867 var color2 = '#777777';
868 var disabled2 = true;
869 if (document.getElementById('rballday1').checked) {
870 color1 = '#000000';
872 if (document.getElementById('rballday2').checked) {
873 color2 = '#000000';
874 disabled2 = false;
876 document.getElementById('tdallday1').style.color = color1;
877 document.getElementById('tdallday2').style.color = color2;
878 document.getElementById('tdallday3').style.color = color2;
879 document.getElementById('tdallday4').style.color = color2;
880 document.getElementById('tdallday5').style.color = color2;
881 f.form_hour.disabled = disabled2;
882 f.form_minute.disabled = disabled2;
883 f.form_ampm.disabled = disabled2;
884 f.form_duration.disabled = disabled2;
887 // Modify some visual attributes when the Repeat checkbox is clicked.
888 function set_repeat() {
889 var f = document.forms[0];
890 var isdisabled = true;
891 var mycolor = '#777777';
892 var myvisibility = 'hidden';
893 if (f.form_repeat.checked) {
894 isdisabled = false;
895 mycolor = '#000000';
896 myvisibility = 'visible';
898 f.form_repeat_type.disabled = isdisabled;
899 f.form_repeat_freq.disabled = isdisabled;
900 f.form_enddate.disabled = isdisabled;
901 document.getElementById('tdrepeat1').style.color = mycolor;
902 document.getElementById('tdrepeat2').style.color = mycolor;
903 document.getElementById('img_enddate').style.visibility = myvisibility;
906 // This is for callback by the find-available popup.
907 function setappt(year,mon,mday,hours,minutes) {
908 var f = document.forms[0];
909 f.form_date.value = '' + year + '-' +
910 ('' + (mon + 100)).substring(1) + '-' +
911 ('' + (mday + 100)).substring(1);
912 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
913 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
914 f.form_minute.value = ('' + (minutes + 100)).substring(1);
917 // Invoke the find-available popup.
918 function find_available() {
919 top.restoreSession();
920 // (CHEMED) Conditional value selection, because there is no <select> element
921 // when making an appointment for a specific provider
922 var s = document.forms[0].form_provider;
923 var f = document.forms[0].facility;
924 <?php if ($userid != 0) { ?>
925 s = document.forms[0].form_provider.value;
926 f = document.forms[0].facility.value;
927 <?php } else {?>
928 s = document.forms[0].form_provider.options[s.selectedIndex].value;
929 f = document.forms[0].facility.options[f.selectedIndex].value;
930 <?php }?>
931 var c = document.forms[0].form_category;
932 var formDate = document.forms[0].form_date;
933 dlgopen('find_appt_popup.php?providerid=' + s +
934 '&catid=' + c.options[c.selectedIndex].value +
935 '&facility=' + f +
936 '&startdate=' + formDate.value, '_blank', 500, 400);
937 //END (CHEMED) modifications
940 </script>
942 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
944 </head>
946 <body class="body_top" onunload='imclosing()'>
948 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo $eid ?>' />
949 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
950 <input type='hidden' size='2' name='resname' value='empty' />
951 <?php
952 if ($_POST["resname"]=="noresult"){
953 echo '
954 <script language="Javascript">
955 // refresh and redirect the parent window
956 if (!opener.closed && opener.refreshme) opener.refreshme();
957 top.restoreSession();
958 opener.document.location="../../new/new.php";
959 // Close the window
960 window.close();
961 </script>';
963 $classprov='current';
964 $classpati='';
966 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
967 <input type="hidden" name="form_action" id="form_action" value="">
968 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
969 <!-- used for recurring events -->
970 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo $date; ?>">
971 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo $eventstartdate; ?>">
972 <center>
973 <table border='0' >
974 <?php
975 $provider_class='';
976 $normal='';
977 if($_GET['prov']==true){
978 $provider_class="class='current'";
980 else{
981 $normal="class='current'";
984 <tr><th><ul class="tabNav">
985 <?php
986 $eid=$_REQUEST["eid"];
987 $startm=$_REQUEST["startampm"];
988 $starth=$_REQUEST["starttimeh"];
989 $uid=$_REQUEST["userid"];
990 $starttm=$_REQUEST["starttimem"];
991 $dt=$_REQUEST["date"];
992 $cid=$_REQUEST["catid"];
994 <li <?php echo $normal;?>>
995 <a href='add_edit_event.php?eid=<?php echo $eid;?>&startampm=<?php echo $startm;?>&starttimeh=<?php echo $starth;?>&userid=<?php echo $uid;?>&starttimem=<?php echo $starttm;?>&date=<?php echo $dt;?>&catid=<?php echo $cid;?>'>
996 <?php echo htmlspecialchars(xl('Patient'),ENT_QUOTES);?></a>
997 </li>
998 <li <?php echo $provider_class;?>>
999 <a href='add_edit_event.php?prov=true&eid=<?php echo $eid;?>&startampm=<?php echo $startm;?>&starttimeh=<?php echo $starth;?>&userid=<?php echo $uid;?>&starttimem=<?php echo $starttm;?>&date=<?php echo $dt;?>&catid=<?php echo $cid;?>'>
1000 <?php echo htmlspecialchars(xl('Provider'),ENT_QUOTES);?></a>
1001 </li>
1002 </ul>
1003 </th></tr>
1004 <tr><td colspan='10'>
1005 <table border='0' width='100%' bgcolor='#DDDDDD' >
1007 <tr>
1008 <td width='1%' nowrap>
1009 <b><?php echo htmlspecialchars($GLOBALS['athletic_team'] ? xl('Team/Squad') : xl('Category')); ?>:</b>
1010 </td>
1011 <td nowrap>
1012 <select name='form_category' onchange='set_category()' style='width:100%'>
1013 <?php echo $catoptions ?>
1014 </select>
1015 </td>
1016 <td width='1%' nowrap>
1017 &nbsp;&nbsp;
1018 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1019 <?php if ($thisduration == 1440) echo "checked " ?>/>
1020 </td>
1021 <td colspan='2' nowrap id='tdallday1'>
1022 <?php xl('All day event','e'); ?>
1023 </td>
1024 </tr>
1026 <tr>
1027 <td nowrap>
1028 <b><?php xl('Date','e'); ?>:</b>
1029 </td>
1030 <td nowrap>
1031 <input type='text' size='10' name='form_date' id='form_date'
1032 value='<?php echo $date ?>'
1033 title='<?php xl('yyyy-mm-dd event date or starting date','e'); ?>'
1034 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
1035 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1036 id='img_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1037 title='<?php xl('Click here to choose a date','e'); ?>'>
1038 </td>
1039 <td nowrap>
1040 &nbsp;&nbsp;
1041 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1042 </td>
1043 <td width='1%' nowrap id='tdallday2'>
1044 <?php xl('Time','e'); ?>
1045 </td>
1046 <td width='1%' nowrap id='tdallday3'>
1047 <input type='text' size='2' name='form_hour' value='<?php echo $starttimeh ?>'
1048 title='<?php xl('Event start time','e'); ?>' /> :
1049 <input type='text' size='2' name='form_minute' value='<?php echo $starttimem ?>'
1050 title='<?php xl('Event start time','e'); ?>' />&nbsp;
1051 <select name='form_ampm' title='Note: 12:00 noon is PM, not AM'>
1052 <option value='1'><?php xl('AM','e'); ?></option>
1053 <option value='2'<?php if ($startampm == '2') echo " selected" ?>><?php xl('PM','e'); ?></option>
1054 </select>
1055 </td>
1056 </tr>
1058 <tr>
1059 <td nowrap>
1060 <b><?php echo htmlspecialchars($GLOBALS['athletic_team'] ? xl('Team/Squad') : xl('Title')); ?>:</b>
1061 </td>
1062 <td nowrap>
1063 <input type='text' size='10' name='form_title' value='<?php echo htmlspecialchars($row['pc_title'], ENT_QUOTES); ?>'
1064 style='width:100%'
1065 title='<?php xl('Event title','e'); ?>' />
1066 </td>
1067 <td nowrap>&nbsp;
1069 </td>
1070 <td nowrap id='tdallday4'><?php xl('duration','e'); ?>
1071 </td>
1072 <td nowrap id='tdallday5'>
1073 <input type='text' size='4' name='form_duration' value='<?php echo $thisduration ?>' title='<?php xl('Event duration in minutes','e'); ?>' />
1074 <?php xl('minutes','e'); ?>
1075 </td>
1076 </tr>
1078 <tr>
1079 <td nowrap><b><?php xl('Facility','e'); ?>:</b></td>
1080 <td>
1081 <select name="facility" id="facility" >
1082 <?php
1084 // ===========================
1085 // EVENTS TO FACILITIES
1086 //(CHEMED) added service_location WHERE clause
1087 // get the facilities
1088 /***************************************************************
1089 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1090 ***************************************************************/
1091 $facils = getUserFacilities($_SESSION['authId']);
1092 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1093 /**************************************************************/
1094 while ($facrow = sqlFetchArray($qsql)) {
1095 /*************************************************************
1096 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1097 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1098 *************************************************************/
1099 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1100 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1101 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1103 else{
1104 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1105 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1107 /************************************************************/
1109 // EOS E2F
1110 // ===========================
1112 <?php
1113 //END (CHEMED) IF ?>
1114 </td>
1115 </select>
1116 </tr>
1117 <tr>
1118 <td nowrap>
1119 <b><?php echo htmlspecialchars( xl('Billing Facility'), ENT_NOQUOTES); ?>:</b>
1120 </td>
1121 <td>
1122 <?php
1123 billing_facility('billing_facility',$row['pc_billing_location']);
1125 </td>
1126 </tr>
1127 <?php
1128 if($_GET['prov']!=true){
1130 <tr id="patient_details">
1131 <td nowrap>
1132 <b><?php xl('Patient','e'); ?>:</b>
1133 </td>
1134 <td nowrap>
1135 <input type='text' size='10' name='form_patient' style='width:100%;cursor:pointer;cursor:hand' value='<?php echo htmlspecialchars($patientname, ENT_QUOTES); ?>' onclick='sel_patient()' title='<?php xl('Click to select patient','e'); ?>' readonly />
1136 <input type='hidden' name='form_pid' value='<?php echo $patientid ?>' />
1137 </td>
1138 <td colspan='3' nowrap style='font-size:8pt'>
1139 &nbsp;
1140 <span class="infobox">
1141 <?php if ($patienttitle != "") { echo $patienttitle; } ?>
1142 </span>
1143 </td>
1144 </tr>
1145 <?php
1148 <tr>
1149 <td nowrap>
1150 <b><?php xl('Provider','e'); ?>:</b>
1151 </td>
1152 <td nowrap>
1154 <?php
1156 // =======================================
1157 // multi providers
1158 // =======================================
1159 if ($GLOBALS['select_multi_providers']) {
1161 // there are two posible situations: edit and new record
1163 // this is executed only on edit ($eid)
1164 if ($eid) {
1165 if ( $multiple_value ) {
1166 // find all the providers around multiple key
1167 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = $multiple_value");
1168 while ($r = sqlFetchArray($qall)) {
1169 $providers_array[] = $r['providers'];
1171 } else {
1172 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1173 $providers_array = sqlFetchArray($qall);
1177 // build the selection tool
1178 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1180 while ($urow = sqlFetchArray($ures)) {
1181 echo " <option value='" . $urow['id'] . "'";
1183 if ($userid) {
1184 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1187 echo ">" . $urow['lname'];
1188 if ($urow['fname']) echo ", " . $urow['fname'];
1189 echo "</option>\n";
1192 echo '</select>';
1194 // =======================================
1195 // single provider
1196 // =======================================
1197 } else {
1199 if ($eid) {
1200 // get provider from existing event
1201 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1202 $provider = sqlFetchArray($qprov);
1203 $defaultProvider = $provider['pc_aid'];
1205 else {
1206 // this is a new event so smartly choose a default provider
1207 /*****************************************************************
1208 if ($userid) {
1209 // Provider already given to us as a GET parameter.
1210 $defaultProvider = $userid;
1212 else {
1213 // default to the currently logged-in user
1214 $defaultProvider = $_SESSION['authUserID'];
1215 // or, if we have chosen a provider in the calendar, default to them
1216 // choose the first one if multiple have been selected
1217 if (count($_SESSION['pc_username']) >= 1) {
1218 // get the numeric ID of the first provider in the array
1219 $pc_username = $_SESSION['pc_username'];
1220 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1221 $defaultProvider = $firstProvider['id'];
1226 echo "<select name='form_provider' style='width:100%' />";
1227 while ($urow = sqlFetchArray($ures)) {
1228 echo " <option value='" . $urow['id'] . "'";
1229 if ($urow['id'] == $defaultProvider) echo " selected";
1230 echo ">" . $urow['lname'];
1231 if ($urow['fname']) echo ", " . $urow['fname'];
1232 echo "</option>\n";
1234 echo "</select>";
1235 *****************************************************************/
1236 // default to the currently logged-in user
1237 $defaultProvider = $_SESSION['authUserID'];
1238 // or, if we have chosen a provider in the calendar, default to them
1239 // choose the first one if multiple have been selected
1240 if (count($_SESSION['pc_username']) >= 1) {
1241 // get the numeric ID of the first provider in the array
1242 $pc_username = $_SESSION['pc_username'];
1243 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1244 $defaultProvider = $firstProvider['id'];
1246 // if we clicked on a provider's schedule to add the event, use THAT.
1247 if ($userid) $defaultProvider = $userid;
1249 echo "<select name='form_provider' style='width:100%' />";
1250 while ($urow = sqlFetchArray($ures)) {
1251 echo " <option value='" . $urow['id'] . "'";
1252 if ($urow['id'] == $defaultProvider) echo " selected";
1253 echo ">" . $urow['lname'];
1254 if ($urow['fname']) echo ", " . $urow['fname'];
1255 echo "</option>\n";
1257 echo "</select>";
1258 /****************************************************************/
1263 </td>
1264 <td nowrap>
1265 &nbsp;&nbsp;
1266 <input type='checkbox' name='form_repeat' onclick='set_repeat(this)' value='1'<?php if ($repeats) echo " checked" ?>/>
1267 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo $repeatexdate; ?>' /> <!-- dates excluded from the repeat -->
1268 </td>
1269 <td nowrap id='tdrepeat1'><?php xl('Repeats','e'); ?>
1270 </td>
1271 <td nowrap>
1273 <select name='form_repeat_freq' title=<?php xl('Every, every other, every 3rd, etc.','e','\'','\''); ?>>
1274 <?php
1275 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1276 as $key => $value)
1278 echo " <option value='$key'";
1279 if ($key == $repeatfreq) echo " selected";
1280 echo ">$value</option>\n";
1283 </select>
1285 <select name='form_repeat_type'>
1286 <?php
1287 // See common.api.php for these:
1288 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'))
1289 as $key => $value)
1291 echo " <option value='$key'";
1292 if ($key == $repeattype) echo " selected";
1293 echo ">$value</option>\n";
1296 </select>
1298 </td>
1299 </tr>
1301 <tr>
1302 <td nowrap>
1303 <span id='title_apptstatus'><b><?php echo htmlspecialchars($GLOBALS['athletic_team'] ? xl('Session Type') : xl('Status')); ?>:</b></span>
1304 <span id='title_prefcat' style='display:none'><b><?php xl('Pref Cat','e'); ?>:</b></span>
1305 </td>
1306 <td nowrap>
1308 <?php
1309 generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'SKIP'), $row['pc_apptstatus']);
1311 <!--
1312 The following list will be invisible unless this is an In Office
1313 event, in which case form_apptstatus (above) is to be invisible.
1315 <select name='form_prefcat' style='width:100%;display:none' title='<?php xl('Preferred Event Category','e');?>'>
1316 <?php echo $prefcat_options ?>
1317 </select>
1319 </td>
1320 <td nowrap>&nbsp;
1322 </td>
1323 <td nowrap id='tdrepeat2'><?php xl('until','e'); ?>
1324 </td>
1325 <td nowrap>
1326 <input type='text' size='10' name='form_enddate' id='form_enddate' value='<?php echo $row['pc_endDate'] ?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php xl('yyyy-mm-dd last date of this event','e');?>' />
1327 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1328 id='img_enddate' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1329 title='<?php xl('Click here to choose a date','e');?>'>
1330 <?php
1331 if ($repeatexdate != "") {
1332 $tmptitle = "The following dates are excluded from the repeating series";
1333 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1334 else { $tmptitle .= "\n"; }
1335 $exdates = explode(",", $repeatexdate);
1336 foreach ($exdates as $exdate) {
1337 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1339 echo "<a href='#' title='$tmptitle' alt='$tmptitle'><img src='../../pic/warning.gif' title='$tmptitle' alt='*!*' style='border:none;'/></a>";
1342 </td>
1343 </tr>
1345 <tr>
1346 <td nowrap>
1347 <b><?php xl('Comments','e'); ?>:</b>
1348 </td>
1349 <td colspan='4' nowrap>
1350 <input type='text' size='40' name='form_comments' style='width:100%' value='<?php echo htmlspecialchars($hometext, ENT_QUOTES); ?>' title='<?php xl('Optional information about this event','e');?>' />
1351 </td>
1352 </tr>
1354 <?php
1355 // DOB is important for the clinic, so if it's missing give them a chance
1356 // to enter it right here. We must display or hide this row dynamically
1357 // in case the patient-select popup is used.
1358 $patient_dob = trim($prow['DOB']);
1359 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00')) ?
1360 '' : 'none';
1362 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1363 <td colspan='4' nowrap>
1364 <b><font color='red'><?php xl('DOB is missing, please enter if possible','e'); ?>:</font></b>
1365 </td>
1366 <td nowrap>
1367 <input type='text' size='10' name='form_dob' id='form_dob' title='<?php xl('yyyy-mm-dd date of birth','e');?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
1368 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1369 id='img_dob' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1370 title='<?php xl('Click here to choose a date','e');?>'>
1371 </td>
1372 </tr>
1374 </table></td></tr>
1375 <tr class='text'><td colspan='10'>
1377 <input type='button' name='form_save' id='form_save' value='<?php xl('Save','e');?>' />
1378 &nbsp;
1379 <input type='button' id='find_available' value='<?php xl('Find Available','e');?>' />
1380 &nbsp;
1381 <input type='button' name='form_delete' id='form_delete' value='<?php xl('Delete','e');?>'<?php if (!$eid) echo " disabled" ?> />
1382 &nbsp;
1383 <input type='button' id='cancel' value='<?php xl('Cancel','e');?>' />
1384 &nbsp;
1385 <input type='button' name='form_duplicate' id='form_duplicate' value='<?php xl('Create Duplicate','e');?>' />
1386 </p></td></tr></table>
1387 <?php if ($informant) echo "<p class='text'>" . xl('Last update by') . " $informant " . xl('on') . " " . $row['pc_time'] . "</p>\n"; ?>
1388 </center>
1389 </form>
1391 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1392 <?php echo htmlspecialchars(xl('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?')) ?>
1393 <br>
1394 <input type="button" name="all_events" id="all_events" value=" All ">
1395 <input type="button" name="future_events" id="future_events" value="Future">
1396 <input type="button" name="current_event" id="current_event" value="Current">
1397 <input type="button" name="recurr_cancel" id="recurr_cancel" value="Cancel">
1398 </div>
1400 </body>
1402 <script language='JavaScript'>
1403 <?php if ($eid) { ?>
1404 set_display();
1405 <?php } else { ?>
1406 set_category();
1407 <?php } ?>
1408 set_allday();
1409 set_repeat();
1411 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
1412 Calendar.setup({inputField:"form_enddate", ifFormat:"%Y-%m-%d", button:"img_enddate"});
1413 Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});
1414 </script>
1416 <script language="javascript">
1417 // jQuery stuff to make the page a little easier to use
1419 $(document).ready(function(){
1420 $("#form_save").click(function() { validate("save"); });
1421 $("#form_duplicate").click(function() { validate("duplicate"); });
1422 $("#find_available").click(function() { find_available(); });
1423 $("#form_delete").click(function() { deleteEvent(); });
1424 $("#cancel").click(function() { window.close(); });
1426 // buttons affecting the modification of a repeating event
1427 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1428 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1429 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1430 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1433 // Check for errors when the form is submitted.
1434 function validate(valu) {
1435 var f = document.getElementById('theform');
1436 if (f.form_repeat.checked &&
1437 (! f.form_enddate.value || f.form_enddate.value < f.form_date.value)) {
1438 alert('An end date later than the start date is required for repeated events!');
1439 return false;
1441 <?php
1442 if($_GET['prov']!=true){
1444 if(f.form_pid.value == ''){
1445 alert('<?php echo htmlspecialchars(xl('Patient Name Required'),ENT_QUOTES);?>');
1446 return false;
1448 <?php
1451 $('#form_action').val(valu);
1453 <?php if ($repeats): ?>
1454 // existing repeating events need additional prompt
1455 if ($("#recurr_affect").val() == "") {
1456 DisableForm();
1457 // show the current/future/all DIV for the user to choose one
1458 $("#recurr_popup").css("visibility", "visible");
1459 return false;
1461 <?php endif; ?>
1463 return SubmitForm();
1466 // disable all the form elements outside the recurr_popup
1467 function DisableForm() {
1468 $("#theform").children().attr("disabled", "true");
1470 function EnableForm() {
1471 $("#theform").children().removeAttr("disabled");
1473 // hide the recurring popup DIV
1474 function HideRecurrPopup() {
1475 $("#recurr_popup").css("visibility", "hidden");
1478 function deleteEvent() {
1479 if (confirm("Deleting this event cannot be undone. It cannot be recovered once it is gone.\nAre you sure you wish to delete this event?")) {
1480 $('#form_action').val("delete");
1482 <?php if ($repeats): ?>
1483 // existing repeating events need additional prompt
1484 if ($("#recurr_affect").val() == "") {
1485 DisableForm();
1486 // show the current/future/all DIV for the user to choose one
1487 $("#recurr_popup").css("visibility", "visible");
1488 return false;
1490 <?php endif; ?>
1492 return SubmitForm();
1494 return false;
1497 function SubmitForm() {
1498 $('#theform').submit();
1499 top.restoreSession();
1500 return true;
1503 </script>
1505 </html>