2 // Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
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 ________________________________________________ //
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");
28 // Things that might be passed by our opener.
30 $eid = $_GET['eid']; // only for existing events
31 $date = $_GET['date']; // this and below only for new events
32 $userid = $_GET['userid'];
33 $default_catid = $_GET['catid'] ?
$_GET['catid'] : '5';
36 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
38 $date = date("Y-m-d");
41 if (isset($_GET['starttimem']))
42 $starttimem = substr('00' . $_GET['starttimem'], -2);
44 if (isset($_GET['starttimeh'])) {
45 $starttimeh = $_GET['starttimeh'];
46 if (isset($_GET['startampm'])) {
47 if ($_GET['startampm'] == '2' && $starttimeh < 12)
51 $starttimeh = date("G");
57 // used for DBC Dutch System
58 $_SESSION['event_date'] = $date;
59 $link = '../../../library/DBC_functions.php'; // ajax stuff and db work
63 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
68 // $args is mainly filled with content from the POST http var
69 function InsertEvent($args) {
70 return sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
71 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
72 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
73 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
74 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
76 "'" . $args['form_category'] . "', " .
77 "'" . $args['new_multiple_value'] . "', " .
78 "'" . $args['form_provider'] . "', " .
79 "'" . $args['form_pid'] . "', " .
80 "'" . $args['form_title'] . "', " .
82 "'" . $args['form_comments'] . "', " .
83 "'" . $_SESSION['authUserID'] . "', " .
84 "'" . $args['event_date'] . "', " .
85 "'" . fixDate($args['form_enddate']) . "', " .
86 "'" . $args['duration'] . "', " .
87 "'" . ($args['form_repeat'] ?
'1' : '0') . "', " .
88 "'" . serialize($args['recurrspec']) . "', " .
89 "'" . $args['starttime'] ."', " .
90 "'" . $args['endtime'] ."', " .
91 "'" . $args['form_allday'] . "', " .
92 "'" . $args['form_apptstatus'] . "', " .
93 "'" . $args['form_prefcat'] . "', " .
94 "'" . $args['locationspec'] ."', " .
96 "1, " .(int)$args['facility']. " )"
100 // =====================================
102 // ACTIVITIES / TIMES
103 if ( $GLOBALS['dutchpc'] ) {
105 if ( $GLOBALS['select_multi_providers'] ) {
106 // ------------------------------------------
107 // what is multiple key around this $eid?
108 $rowmulti = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
110 // what are all pc_eid's grouped by multiple key
111 $eventsrow = array();
112 $rezev = mysql_query("SELECT pc_eid FROM openemr_postcalendar_events WHERE pc_multiple = {$rowmulti['pc_multiple']}");
113 while ( $row = mysql_fetch_array($rezev) ) {
114 $eventsrow[] = $row['pc_eid'];
117 // we look in cl_event_activiteit / cl_time_activiteit for a matching record
118 foreach ( $eventsrow as $ev) {
119 $activ = sqlQuery("SELECT * FROM cl_event_activiteit WHERE event_id = $ev");
120 if ( $activ['event_id'] ) $singleeid = $activ['event_id'];
122 $time = sqlQuery("SELECT * FROM cl_time_activiteit WHERE event_id = $ev");
123 if ( $time ) $timerow = $time;
126 // prevent blank values for $singleeid
127 if ( !$singleeid) $singleeid = $eid;
129 // ------------------------------------------
131 // ------------------------------------------
132 // single providers case
133 $timerow = sqlQuery("SELECT * FROM cl_time_activiteit WHERE event_id = $eid");
135 // ------------------------------------------
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
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 = $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 = ".$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 = $min WHERE pc_multiple = $mul");
162 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
164 $e2f_name = $min_name;
167 if (!$facility['pc_facility'] && ($_SESSION['pc_facility'] ||
$_COOKIE['pc_facility'])) {
168 $e2f = $_SESSION['pc_facility'] ?
$_SESSION['pc_facility'] : $_COOKIE['pc_facility'];
170 $e2f = $facility['pc_facility'];
171 $e2f_name = $facility['name'];
176 // ===========================
179 // If we are saving, then save and close the window.
181 if ($_POST['form_action'] == "save") {
183 // ========================================
185 // check if for activity act_3.2 we have times completed
187 if ( $GLOBALS['dutchpc'] ) {
189 if ( $sa == 'act_3.2') {
190 $duration = (int)$_POST['form_duration'];
191 if ( empty($duration) ) exit();
194 // ========================================
196 // the starting date of the event, pay attention with this value
197 // when editing recurring events -- JRM Oct-08
198 $event_date = fixDate($_POST['form_date']);
200 // Compute start and end time strings to be saved.
201 if ($_POST['form_allday']) {
206 $tmph = $_POST['form_hour'] +
0;
207 $tmpm = $_POST['form_minute'] +
0;
208 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph +
= 12;
209 $duration = $_POST['form_duration'];
211 $starttime = "$tmph:$tmpm:00";
214 while ($tmpm >= 60) {
218 $endtime = "$tmph:$tmpm:00";
220 // Useless garbage that we must save.
221 $locationspecs = array("event_location" => "",
222 "event_street1" => "",
223 "event_street2" => "",
228 $locationspec = serialize($locationspecs);
230 // capture the recurring specifications
231 $recurrspec = array("event_repeat_freq" => $_POST['form_repeat_freq'],
232 "event_repeat_freq_type" => $_POST['form_repeat_type'],
233 "event_repeat_on_num" => "1",
234 "event_repeat_on_day" => "0",
235 "event_repeat_on_freq" => "0",
236 "exdate" => $_POST['form_repeat_exdate']
239 // no recurr specs, this is used for adding a new non-recurring event
240 $noRecurrspec = array("event_repeat_freq" => "",
241 "event_repeat_freq_type" => "",
242 "event_repeat_on_num" => "1",
243 "event_repeat_on_day" => "0",
244 "event_repeat_on_freq" => "0",
248 /* =======================================================
250 * =====================================================*/
253 // what is multiple key around this $eid?
254 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
256 // timing-activity validation - larry :: DBC ????
258 if ( $GLOBALS['dutchpc'] ) {
259 if ( $_SESSION['editactiv'] ) { $activ = selected_ac(); }
260 else { $activ = what_activity($eid); }
264 // ====================================
265 // multiple providers
266 // ====================================
267 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
269 // obtain current list of providers regarding the multiple key
270 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
271 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
273 // get the new list of providers from the submitted form
274 $providers_new = $_POST['form_provider'];
276 // ===== Only current event of repeating series =====
277 if ($_POST['recurr_affect'] == 'current') {
279 // update all existing event records to exlude the current date
280 foreach ($providers_current as $provider) {
281 // update the provider's original event
282 // get the original event's repeat specs
283 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
284 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
285 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
286 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
287 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
288 else { $oldRecurrspec['exdate'] .= $selected_date; }
290 // mod original event recur specs to exclude this date
291 sqlStatement("UPDATE openemr_postcalendar_events SET " .
292 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
293 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
296 // obtain the next available unique key to group multiple providers around some event
297 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
298 $max = sqlFetchArray($q);
299 $new_multiple_value = $max['max'] +
1;
301 // insert a new event record for each provider selected on the form
302 foreach ($providers_new as $provider) {
303 // insert a new event on this date with POST form data
305 // specify some special variables needed for the INSERT
306 $args['new_multiple_value'] = $new_multiple_value;
307 $args['form_provider'] = $provider;
308 $args['event_date'] = $event_date;
309 $args['duration'] = $duration * 60;
310 // this event is forced to NOT REPEAT
311 $args['form_repeat'] = "0";
312 $args['recurrspec'] = $noRecurrspec;
313 $args['form_enddate'] = "0000-00-00";
314 $args['starttime'] = $starttime;
315 $args['endtime'] = $endtime;
316 $args['locationspec'] = $locationspec;
321 // ===== Future Recurring events of a repeating series =====
322 else if ($_POST['recurr_affect'] == 'future') {
323 // update all existing event records to
324 // stop recurring on this date-1
325 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
326 foreach ($providers_current as $provider) {
327 // mod original event recur specs to end on this date
328 sqlStatement("UPDATE openemr_postcalendar_events SET " .
329 " pc_enddate = '" . $selected_date ."' ".
330 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
333 // obtain the next available unique key to group multiple providers around some event
334 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
335 $max = sqlFetchArray($q);
336 $new_multiple_value = $max['max'] +
1;
338 // insert a new event record for each provider selected on the form
339 foreach ($providers_new as $provider) {
340 // insert a new event on this date with POST form data
342 // specify some special variables needed for the INSERT
343 $args['new_multiple_value'] = $new_multiple_value;
344 $args['form_provider'] = $provider;
345 $args['event_date'] = $event_date;
346 $args['duration'] = $duration * 60;
347 $args['recurrspec'] = $recurrspec;
348 $args['starttime'] = $starttime;
349 $args['endtime'] = $endtime;
350 $args['locationspec'] = $locationspec;
356 /* =================================================================== */
357 // ===== a Single event or All events in a repeating series ==========
358 /* =================================================================== */
360 // this difference means that some providers from current was UNCHECKED
361 // so we must delete this event for them
362 $r1 = array_diff ($providers_current, $providers_new);
364 foreach ($r1 as $to_be_removed) {
365 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
369 // perform a check to see if user changed event date
370 // this is important when editing an existing recurring event
372 if ($_POST['form_date'] == $_POST['selected_date']) {
373 // user has NOT changed the start date of the event
374 $event_date = fixDate($_POST['event_start_date']);
377 // this difference means that some providers were added
378 // so we must insert this event for them
379 $r2 = array_diff ($providers_new, $providers_current);
381 foreach ($r2 as $to_be_inserted) {
383 // specify some special variables needed for the INSERT
384 $args['new_multiple_value'] = $row['pc_multiple'];
385 $args['form_provider'] = $to_be_inserted;
386 $args['event_date'] = $event_date;
387 $args['duration'] = $duration * 60;
388 $args['recurrspec'] = $recurrspec;
389 $args['starttime'] = $starttime;
390 $args['endtime'] = $endtime;
391 $args['locationspec'] = $locationspec;
396 // after the two diffs above, we must update for remaining providers
397 // those who are intersected in $providers_current and $providers_new
398 foreach ($_POST['form_provider'] as $provider) {
399 sqlStatement("UPDATE openemr_postcalendar_events SET " .
400 "pc_catid = '" . $_POST['form_category'] . "', " .
401 "pc_pid = '" . $_POST['form_pid'] . "', " .
402 "pc_title = '" . $_POST['form_title'] . "', " .
403 "pc_time = NOW(), " .
404 "pc_hometext = '" . $_POST['form_comments'] . "', " .
405 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
406 "pc_eventDate = '" . $event_date . "', " .
407 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
408 "pc_duration = '" . ($duration * 60) . "', " .
409 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
410 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
411 "pc_startTime = '$starttime', " .
412 "pc_endTime = '$endtime', " .
413 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
414 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
415 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
416 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
417 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
422 // ====================================
424 // ====================================
425 } elseif ( !$row['pc_multiple'] ) {
426 if ( $GLOBALS['select_multi_providers'] ) {
427 $prov = $_POST['form_provider'][0];
429 $prov = $_POST['form_provider'];
432 if ($_POST['recurr_affect'] == 'current') {
433 // get the original event's repeat specs
434 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
435 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
436 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
437 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
438 else { $oldRecurrspec['exdate'] .= $selected_date; }
440 // mod original event recur specs to exclude this date
441 sqlStatement("UPDATE openemr_postcalendar_events SET " .
442 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
443 " WHERE pc_eid = '$eid'");
445 // insert a new event on this date with POST form data
447 // specify some special variables needed for the INSERT
448 $args['event_date'] = $event_date;
449 $args['duration'] = $duration * 60;
450 // this event is forced to NOT REPEAT
451 $args['form_repeat'] = "0";
452 $args['recurrspec'] = $noRecurrspec;
453 $args['form_enddate'] = "0000-00-00";
454 $args['starttime'] = $starttime;
455 $args['endtime'] = $endtime;
456 $args['locationspec'] = $locationspec;
459 else if ($_POST['recurr_affect'] == 'future') {
460 // mod original event to stop recurring on this date-1
461 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
462 sqlStatement("UPDATE openemr_postcalendar_events SET " .
463 " pc_enddate = '" . $selected_date ."' ".
464 " WHERE pc_eid = '$eid'");
466 // insert a new event starting on this date with POST form data
468 // specify some special variables needed for the INSERT
469 $args['event_date'] = $event_date;
470 $args['duration'] = $duration * 60;
471 $args['recurrspec'] = $recurrspec;
472 $args['starttime'] = $starttime;
473 $args['endtime'] = $endtime;
474 $args['locationspec'] = $locationspec;
479 // perform a check to see if user changed event date
480 // this is important when editing an existing recurring event
482 if ($_POST['form_date'] == $_POST['selected_date']) {
483 // user has NOT changed the start date of the event
484 $event_date = fixDate($_POST['event_start_date']);
487 // mod the SINGLE event or ALL EVENTS in a repeating series
488 // simple provider case
489 sqlStatement("UPDATE openemr_postcalendar_events SET " .
490 "pc_catid = '" . $_POST['form_category'] . "', " .
491 "pc_aid = '" . $prov . "', " .
492 "pc_pid = '" . $_POST['form_pid'] . "', " .
493 "pc_title = '" . $_POST['form_title'] . "', " .
494 "pc_time = NOW(), " .
495 "pc_hometext = '" . $_POST['form_comments'] . "', " .
496 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
497 "pc_eventDate = '" . $event_date . "', " .
498 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
499 "pc_duration = '" . ($duration * 60) . "', " .
500 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
501 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
502 "pc_startTime = '$starttime', " .
503 "pc_endTime = '$endtime', " .
504 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
505 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
506 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
507 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
508 "WHERE pc_eid = '$eid'");
512 // ===================================
513 // DBC change activity / times
514 $activ = ''; // activity could be an old value or a new one
515 if ( $GLOBALS['dutchpc'] ) {
516 if ( $_SESSION['editactiv'] ) {
517 $ac = selected_ac(); $activ = $ac;
518 $acid = what_sysid($ac);
520 if ( $acid ) sqlInsert("INSERT INTO cl_event_activiteit (event_id, activity_sysid)".
521 " VALUES ('" .$singleeid. "', '" .$acid. "') ON DUPLICATE KEY UPDATE activity_sysid = " .$acid );
523 $_SESSION['editactiv'] = FALSE; // otherwise you'll get a nasty bug!
525 $activcode = what_activity($singleeid);
526 $activ = what_code_activity($activcode);
529 // timing-activity validation
530 if ( vl_activity_travel($activ) ) {
531 $itime = (int)$_POST['form_duration_indirect']; $ttime = 0;
533 $itime = (int)$_POST['form_duration_indirect']; $ttime = (int)$_POST['form_duration_travel'];
535 sqlInsert("INSERT INTO cl_time_activiteit (event_id, indirect_time, travel_time)".
536 " VALUES ('" .$singleeid. "', '" .$itime. "', '" .$ttime. "') ON DUPLICATE KEY UPDATE indirect_time = " .$itime.
537 ", travel_time = " . $ttime);
540 // end DBC change activity / times
541 // ===================================
543 // =======================================
544 // end Update Multi providers case
545 // =======================================
547 // EVENTS TO FACILITIES
552 /* =======================================================
553 * INSERT NEW EVENT(S)
554 * ======================================================*/
556 // =======================================
557 // multi providers case
558 // =======================================
559 if (is_array($_POST['form_provider'])) {
561 // obtain the next available unique key to group multiple providers around some event
562 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
563 $max = sqlFetchArray($q);
564 $new_multiple_value = $max['max'] +
1;
566 foreach ($_POST['form_provider'] as $provider) {
568 // specify some special variables needed for the INSERT
569 $args['new_multiple_value'] = $new_multiple_value;
570 $args['form_provider'] = $provider;
571 $args['event_date'] = $event_date;
572 $args['duration'] = $duration * 60;
573 $args['recurrspec'] = $recurrspec;
574 $args['starttime'] = $starttime;
575 $args['endtime'] = $endtime;
576 $args['locationspec'] = $locationspec;
580 // ====================================
582 // ====================================
585 // specify some special variables needed for the INSERT
586 $args['new_multiple_value'] = "";
587 $args['event_date'] = $event_date;
588 $args['duration'] = $duration * 60;
589 $args['recurrspec'] = $recurrspec;
590 $args['starttime'] = $starttime;
591 $args['endtime'] = $endtime;
592 $args['locationspec'] = $locationspec;
596 // ==============================================
597 // DBC Dutch System (insert case)
598 $lid = mysql_insert_id($GLOBALS['dbh']); // obtain last inserted id
601 if ( $GLOBALS['dutchpc'] ) {
603 $acid = what_sysid($ac);
604 sqlInsert("INSERT INTO cl_event_activiteit (event_id, activity_sysid) VALUES ('" .$lid. "', '" .$acid. "')");
606 // timing-activity validation
607 if ( vl_activity_travel($activ) ) {
608 $itime = (int)$_POST['form_duration_indirect']; $ttime = 0;
610 $itime = (int)$_POST['form_duration_indirect']; $ttime = (int)$_POST['form_duration_travel'];
612 sqlInsert("INSERT INTO cl_time_activiteit (event_id, indirect_time, travel_time)".
613 " VALUES ('" .$lid. "', '" .$itime. "', '" .$ttime. "')");
615 // DBC Dutch System (insert case)
616 // ==============================================
619 $pid1007 = ( $_POST['form_pid'] ) ?
$_POST['form_pid'] : $pid;
621 $a = generate_id1007($pid1007, $event_date); //var_dump($a); exit();
625 // ==============================================
629 // done with EVENT insert/update statements
631 // Save new DOB if it's there.
632 $patient_dob = trim($_POST['form_dob']);
633 if ($patient_dob && $_POST['form_pid']) {
634 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
635 "pid = '" . $_POST['form_pid'] . "'");
638 // Auto-create a new encounter if appropriate.
640 if ($GLOBALS['auto_create_new_encounters'] &&
641 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
643 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
644 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
645 if ($tmprow['count'] == 0) {
646 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
647 $_POST['form_provider'] . "'");
648 $username = $tmprow['username'];
649 $facility = $tmprow['facility'];
650 // $facility_id = $tmprow['facility_id'];
651 // use the session facility if it is set, otherwise the one from the provider.
652 $facility_id = $_SESSION['pc_facility'] ?
$_SESSION['pc_facility'] : $tmprow['facility_id'];
653 $conn = $GLOBALS['adodb']['db'];
654 $encounter = $conn->GenID("sequences");
655 addForm($encounter, "New Patient Encounter",
656 sqlInsert("INSERT INTO form_encounter SET " .
657 "date = '$event_date', " .
658 "onset_date = '$event_date', " .
659 "reason = '" . $_POST['form_comments'] . "', " .
660 "facility = '$facility', " .
661 // "facility_id = '$facility_id', " .
662 "facility_id = '" . (int)$_POST['facility'] . "', " .
663 "pid = '" . $_POST['form_pid'] . "', " .
664 "encounter = '$encounter'"
666 "newpatient", $_POST['form_pid'], "1", "NOW()", $username
668 $info_msg .= "New encounter $encounter was created. ";
673 // =======================================
675 // =======================================
676 else if ($_POST['form_action'] == "delete") {
677 // =======================================
678 // multi providers event
679 // =======================================
680 if ($GLOBALS['select_multi_providers']) {
682 // what is multiple key around this $eid?
683 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
685 // obtain current list of providers regarding the multiple key
686 $providers_current = array();
687 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
688 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
690 // establish a WHERE clause
691 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = {$row['pc_multiple']}"; }
692 else { $whereClause = "pc_eid = $eid"; }
694 if ($_POST['recurr_affect'] == 'current') {
695 // update all existing event records to exlude the current date
696 foreach ($providers_current as $provider) {
697 // update the provider's original event
698 // get the original event's repeat specs
699 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
700 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
701 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
702 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
703 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
704 else { $oldRecurrspec['exdate'] .= $selected_date; }
706 // mod original event recur specs to exclude this date
707 sqlStatement("UPDATE openemr_postcalendar_events SET " .
708 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
709 " WHERE ". $whereClause);
712 else if ($_POST['recurr_affect'] == 'future') {
713 // update all existing event records to stop recurring on this date-1
714 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
715 foreach ($providers_current as $provider) {
716 // update the provider's original event
717 sqlStatement("UPDATE openemr_postcalendar_events SET " .
718 " pc_enddate = '" . $selected_date ."' ".
719 " WHERE ".$whereClause);
723 // really delete the event from the database
724 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
728 // =======================================
729 // single provider event
730 // =======================================
733 if ($_POST['recurr_affect'] == 'current') {
734 // mod original event recur specs to exclude this date
736 // get the original event's repeat specs
737 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
738 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
739 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
740 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
741 else { $oldRecurrspec['exdate'] .= $selected_date; }
742 sqlStatement("UPDATE openemr_postcalendar_events SET " .
743 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
744 " WHERE pc_eid = '$eid'");
747 else if ($_POST['recurr_affect'] == 'future') {
748 // mod original event to stop recurring on this date-1
749 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
750 sqlStatement("UPDATE openemr_postcalendar_events SET " .
751 " pc_enddate = '" . $selected_date ."' ".
752 " WHERE pc_eid = '$eid'");
756 // fully delete the event from the database
757 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
762 if ($_POST['form_action'] != "") {
763 // Close this window and refresh the calendar display.
764 echo "<html>\n<body>\n<script language='JavaScript'>\n";
765 if ($info_msg) echo " alert('$info_msg');\n";
766 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
767 echo " window.close();\n";
768 echo "</script>\n</body>\n</html>\n";
772 //*********************************
773 // If we get this far then we are displaying the form.
774 //*********************************
778 '*' => xl('* Reminder done'),
779 '+' => xl('+ Chart pulled'),
780 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
781 '?' => xl('? No show'),
782 '@' => xl('@ Arrived'),
783 '~' => xl('~ Arrived late'),
784 '!' => xl('! Left w/o visit'),
785 '#' => xl('# Ins/fin issue'),
786 '<' => xl('< In exam room'),
787 '>' => xl('> Checked out'),
788 '$' => xl('$ Coding done'),
789 '%' => xl('% Cancelled < 24h ')
792 $repeats = 0; // if the event repeats
796 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
797 $patientname = xl('Click to select');
803 // If we are editing an existing event, then get its data.
805 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
807 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
808 "FROM openemr_postcalendar_events AS e " .
809 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
810 "WHERE pc_eid = $eid");
811 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
813 // instead of using the event's starting date, keep what has been provided
814 // via the GET array, see the top of this file
815 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
816 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
817 $userid = $row['pc_aid'];
818 $patientid = $row['pc_pid'];
819 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
820 $starttimem = substr($row['pc_startTime'], 3, 2);
821 $repeats = $row['pc_recurrtype'];
822 $multiple_value = $row['pc_multiple'];
824 // parse out the repeating data, if any
825 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
826 $repeattype = $rspecs['event_repeat_freq_type'];
827 $repeatfreq = $rspecs['event_repeat_freq'];
828 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
830 $hometext = $row['pc_hometext'];
831 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
835 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
837 //-------------------------------------
839 //Set default facility for a new event based on the given 'userid'
841 /*************************************************************
842 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
843 *************************************************************/
844 if ($_SESSION['pc_facility']) {
845 $pref_facility = sqlFetchArray(sqlStatement(sprintf("
846 SELECT f.id as facility_id,
851 $_SESSION['pc_facility']
854 $pref_facility = sqlFetchArray(sqlStatement("
855 SELECT u.facility_id,
858 LEFT JOIN facility f on (u.facility_id = f.id)
862 /************************************************************/
863 $e2f = $pref_facility['facility_id'];
864 $e2f_name = $pref_facility['facility'];
866 //END of CHEMED -----------------------
869 // If we have a patient ID, get the name and phone numbers to display.
871 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
872 "FROM patient_data WHERE pid = '" . $patientid . "'");
873 $patientname = $prow['lname'] . ", " . $prow['fname'];
874 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
875 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
878 // Get the providers list.
879 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
880 "authorized != 0 AND active = 1 ORDER BY lname, fname");
882 // Get event categories.
883 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
884 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
886 // Fix up the time format for AM/PM.
888 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
890 if ($starttimeh > 12) $starttimeh -= 12;
896 <?php
html_header_show(); ?
>
897 <title
><?php
echo $eid ?
xl('Edit','e') : xl('Add New','e') ?
> <?php
xl('Event','e');?
></title
>
898 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
901 td
{ font
-size
:0.8em
; }
904 <style type
="text/css">@import
url(../../../library
/dynarch_calendar
.css
);</style
>
905 <script type
="text/javascript" src
="../../../library/topdialog.js"></script
>
906 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
907 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
908 <script type
="text/javascript" src
="../../../library/dynarch_calendar.js"></script
>
909 <script type
="text/javascript" src
="../../../library/dynarch_calendar_en.js"></script
>
910 <script type
="text/javascript" src
="../../../library/dynarch_calendar_setup.js"></script
>
913 // ============================================================================
914 // DBC SYSTEM JAVASCRIPT FILE
916 if ( $GLOBALS['dutchpc'] ) { ?
>
917 <script type
="text/javascript" src
="../../../library/js/add_edit_event.js"></script
>
920 // ============================================================================
923 <script language
="JavaScript">
925 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
927 var durations
= new Array();
928 // var rectypes = new Array();
930 // Read the event categories, generate their options list, and get
931 // the default event duration from them if this is a new event.
933 $prefcat_options = " <option value='0'>-- None --</option>\n";
936 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
938 while ($crow = sqlFetchArray($cres)) {
939 $duration = round($crow['pc_duration'] / 60);
940 if ($crow['pc_end_all_day']) $duration = 1440;
941 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
942 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
943 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
945 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
947 if ($crow['pc_catid'] == $default_catid) {
948 $catoptions .= " selected";
949 $thisduration = $duration;
952 $catoptions .= ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
954 // This section is to build the list of preferred categories:
956 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
958 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
960 $prefcat_options .= ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
966 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
968 // This is for callback by the find-patient popup.
969 function setpatient(pid
, lname
, fname
, dob
) {
970 var f
= document
.forms
[0];
971 f
.form_patient
.value
= lname +
', ' + fname
;
972 f
.form_pid
.value
= pid
;
973 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
974 document
.getElementById('dob_row').style
.display
= dobstyle
;
977 // This invokes the find-patient popup.
978 function sel_patient() {
979 dlgopen('find_patient_popup.php', '_blank', 500, 400);
982 // Do whatever is needed when a new event category is selected.
983 // For now this means changing the event title and duration.
984 function set_display() {
985 var f
= document
.forms
[0];
986 var s
= f
.form_category
;
987 if (s
.selectedIndex
>= 0) {
988 var catid
= s
.options
[s
.selectedIndex
].value
;
989 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
990 var style_prefcat
= document
.getElementById('title_prefcat').style
;
991 if (catid
== '2') { // In Office
992 style_apptstatus
.display
= 'none';
993 style_prefcat
.display
= '';
994 f
.form_apptstatus
.style
.display
= 'none';
995 f
.form_prefcat
.style
.display
= '';
997 style_prefcat
.display
= 'none';
998 style_apptstatus
.display
= '';
999 f
.form_prefcat
.style
.display
= 'none';
1000 f
.form_apptstatus
.style
.display
= '';
1005 // Do whatever is needed when a new event category is selected.
1006 // For now this means changing the event title and duration.
1007 function set_category() {
1008 var f
= document
.forms
[0];
1009 var s
= f
.form_category
;
1010 if (s
.selectedIndex
>= 0) {
1011 var catid
= s
.options
[s
.selectedIndex
].value
;
1012 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
1013 f
.form_duration
.value
= durations
[catid
];
1018 // Modify some visual attributes when the all-day or timed-event
1019 // radio buttons are clicked.
1020 function set_allday() {
1021 var f
= document
.forms
[0];
1022 var color1
= '#777777';
1023 var color2
= '#777777';
1024 var disabled2
= true;
1025 if (document
.getElementById('rballday1').checked
) {
1028 if (document
.getElementById('rballday2').checked
) {
1032 document
.getElementById('tdallday1').style
.color
= color1
;
1033 document
.getElementById('tdallday2').style
.color
= color2
;
1034 document
.getElementById('tdallday3').style
.color
= color2
;
1035 document
.getElementById('tdallday4').style
.color
= color2
;
1036 document
.getElementById('tdallday5').style
.color
= color2
;
1037 f
.form_hour
.disabled
= disabled2
;
1038 f
.form_minute
.disabled
= disabled2
;
1039 f
.form_ampm
.disabled
= disabled2
;
1040 f
.form_duration
.disabled
= disabled2
;
1043 // Modify some visual attributes when the Repeat checkbox is clicked.
1044 function set_repeat() {
1045 var f
= document
.forms
[0];
1046 var isdisabled
= true;
1047 var mycolor
= '#777777';
1048 var myvisibility
= 'hidden';
1049 if (f
.form_repeat
.checked
) {
1051 mycolor
= '#000000';
1052 myvisibility
= 'visible';
1054 f
.form_repeat_type
.disabled
= isdisabled
;
1055 f
.form_repeat_freq
.disabled
= isdisabled
;
1056 f
.form_enddate
.disabled
= isdisabled
;
1057 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
1058 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
1059 document
.getElementById('img_enddate').style
.visibility
= myvisibility
;
1062 // This is for callback by the find-available popup.
1063 function setappt(year
,mon
,mday
,hours
,minutes
) {
1064 var f
= document
.forms
[0];
1065 f
.form_date
.value
= '' + year +
'-' +
1066 ('' +
(mon +
100)).substring(1) +
'-' +
1067 ('' +
(mday +
100)).substring(1);
1068 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
1069 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
1070 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
1073 // Invoke the find-available popup.
1074 function find_available() {
1075 top
.restoreSession();
1076 // (CHEMED) Conditional value selection, because there is no <select> element
1077 // when making an appointment for a specific provider
1078 var s
= document
.forms
[0].form_provider
;
1079 <?php
if ($userid != 0) { ?
>
1080 s
= document
.forms
[0].form_provider
.value
;
1082 s
= document
.forms
[0].form_provider
.options
[s
.selectedIndex
].value
;
1084 var c
= document
.forms
[0].form_category
;
1085 var formDate
= document
.forms
[0].form_date
;
1086 dlgopen('find_appt_popup.php?providerid=' + s +
1087 '&facility=' + f
.options
[f
.selectedIndex
].value +
1088 '&catid=' + c
.options
[c
.selectedIndex
].value +
1089 '&startdate=' + formDate
.value
, '_blank', 500, 400);
1090 //END (CHEMED) modifications
1093 // ==============================
1095 function verify_selecteerbaar (a
) {
1096 var f
= document
.forms
[0]; var a
;
1097 if (f
.box5
.value
!= 0) a
= f
.box5
.value
;
1098 else if (f
.box4
.value
!= 0) a
= f
.box4
.value
;
1099 else if (f
.box3
.value
!= 0) a
= f
.box3
.value
;
1100 else if (f
.box2
.value
!= 0) a
= f
.box2
.value
;
1101 else if (f
.box1
.value
!= 0) a
= f
.box1
.value
;
1102 else { alert('You must choose an activity.'); return false;
1105 var answer
= $
.ajax({
1111 if ( answer
== 'false') { alert("Please select again"); return false; }
1119 if ( $GLOBALS['dutchpc'])
1122 <script type
="text/javascript">
1126 if ( $eid ) { // editing case
1130 } // EOS editing case
1136 } // EOS DBC DUTCH AJAX PART
1139 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8" />
1143 <body
class="body_top" onunload
='imclosing()'>
1145 <form method
='post' name
='theform' id
='theform' action
='add_edit_event.php?eid=<?php echo $eid ?>' />
1146 <input type
="hidden" name
="form_action" id
="form_action" value
="">
1147 <input type
="hidden" name
="recurr_affect" id
="recurr_affect" value
="">
1148 <!-- used
for recurring events
-->
1149 <input type
="hidden" name
="selected_date" id
="selected_date" value
="<?php echo $date; ?>">
1150 <input type
="hidden" name
="event_start_date" id
="event_start_date" value
="<?php echo $eventstartdate; ?>">
1153 <table border
='0' width
='100%'>
1156 <td width
='1%' nowrap
>
1157 <b
><?php
xl('Category','e'); ?
>:</b
>
1160 <select name
='form_category' onchange
='set_category()' style
='width:100%'>
1161 <?php
echo $catoptions ?
>
1164 <td width
='1%' nowrap
>
1166 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='1' id
='rballday1'
1167 <?php
if ($thisduration == 1440) echo "checked " ?
>/>
1169 <td colspan
='2' nowrap id
='tdallday1'>
1170 <?php
xl('All day event','e'); ?
>
1176 <b
><?php
xl('Date','e'); ?
>:</b
>
1179 <input type
='text' size
='10' name
='form_date' id
='form_date'
1180 value
='<?php echo $date ?>'
1181 title
='<?php xl('yyyy
-mm
-dd event date
or starting date
','e
'); ?>'
1182 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
1183 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1184 id
='img_date' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1185 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
1189 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='0' id
='rballday2' <?php
if ($thisduration != 1440) echo "checked " ?
>/>
1191 <td width
='1%' nowrap id
='tdallday2'>
1192 <?php
xl('Time','e'); ?
>
1194 <td width
='1%' nowrap id
='tdallday3'>
1195 <input type
='text' size
='2' name
='form_hour' value
='<?php echo $starttimeh ?>'
1196 title
='<?php xl('Event start time
','e
'); ?>' /> :
1197 <input type
='text' size
='2' name
='form_minute' value
='<?php echo $starttimem ?>'
1198 title
='<?php xl('Event start time
','e
'); ?>' /> 
;
1199 <select name
='form_ampm' title
='Note: 12:00 noon is PM, not AM'>
1200 <option value
='1'><?php
xl('AM','e'); ?
></option
>
1201 <option value
='2'<?php
if ($startampm == '2') echo " selected" ?
>><?php
xl('PM','e'); ?
></option
>
1207 <b
><?php
xl('Title','e'); ?
>:</b
>
1210 <input type
='text' size
='10' name
='form_title' value
='<?php echo addslashes($row['pc_title
']) ?>'
1212 title
='<?php xl('Event title
','e
'); ?>' />
1217 <td nowrap id
='tdallday4'><?php
xl('duration','e'); ?
>
1219 <td nowrap id
='tdallday5'>
1220 <input type
='text' size
='4' name
='form_duration' value
='<?php echo $thisduration ?>' title
='<?php xl('Event duration in minutes
','e
'); ?>' />
1221 <?php
xl('minutes','e'); ?
>
1226 // =============================================
1227 // DBC DUTCH SYSTEMS
1229 if ( $GLOBALS['dutchpc'] ) { ?
>
1231 <td colspan
="3"> 
;</td
>
1233 <td
><input type
='text' name
='form_duration_indirect' id
='form_duration_indirect' size
='4'
1234 value
='<?php if ( isset($timerow['indirect_time
']) ) echo $timerow['indirect_time
']; ?>'/>minutes
</td
>
1237 <td colspan
="3"> 
;</td
>
1239 <td
><input type
='text' name
='form_duration_travel' name
='form_duration_travel' size
='4'
1240 value
='<?php if ( isset($timerow['travel_time
']) ) echo $timerow['travel_time
']; ?>'/>minutes
</td
>
1243 // =======================================================
1245 // cascading dropdowns
1246 // =======================================================
1247 if ( $GLOBALS['dutchpc'] ) {
1248 if ( $eid ) { // editing mode
1249 $activ = what_activity( $singleeid );
1251 if ( empty($activ) ) {
1252 $activ = "No activity selected.";
1254 $activ = what_full_sysid($activ);
1255 $_SESSION['editactiv'] = FALSE;
1259 // end DBC DUTCH SYSTEM
1262 <td
><b
>Current activity
:</b
><br
/><a href
="#" id
="addc"><
;<
;Add
/Change
>
;>
;</a
></td
>
1263 <td
><?
=$activ?
><br
/> <td colspan
="3"> 
;</td
></td
>
1266 <td nowrap
><b
>Activiteit
:</b
></td
>
1267 <td width
='1%' nowrap
>
1268 <select name
="box1" id
="box1">
1270 $rlvone = records_level1('ev');
1271 foreach ($rlvone as $rlv) {
1272 echo '<option value=\'' .$rlv['cl_activiteit_code']. '\'>' .$rlv['cl_activiteit_element']. '</option>';
1276 <td colspan
="3"><?php
if ( $patientid ) $are = has_ztndbc($patientid); else $are = ' '; ?
>
1277 <p style
="background-color: #78AEBC; padding: 3px; text-align: center"><?
=$are['str']?
></p
>
1281 <tr colspan
="2"><td
></td
><td
>
1282 <select id
="box2" name
="box2">
1285 <tr colspan
="2"><td
></td
><td
>
1286 <select id
="box3" name
="box3"></select
>
1289 <tr colspan
="2"><td
></td
><td
>
1290 <select id
="box4" name
="box4"></select
>
1293 <tr colspan
="2"><td
></td
><td
>
1294 <select id
="box5" name
="box5"></select
>
1300 <td nowrap
><b
><?php
xl('Facility','e'); ?
>:</b
></td
>
1303 if ($userid != 0) { ?
>
1304 <input type
='hidden' name
="facility" id
="facility" value
='<?php echo $e2f; ?>'/>
1305 <input type
='input' readonly name
="facility_txt" value
='<?php echo $e2f_name; ?>'/>
1307 <select name
="facility" id
="facility" >
1310 // ===========================
1311 // EVENTS TO FACILITIES
1312 //(CHEMED) added service_location WHERE clause
1313 // get the facilities
1314 /***************************************************************
1315 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1316 ***************************************************************/
1317 $facils = getUserFacilities($_SESSION['authId']);
1318 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1319 /**************************************************************/
1320 while ($facrow = sqlFetchArray($qsql)) {
1321 /*************************************************************
1322 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1323 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1324 *************************************************************/
1325 if ($_SESSION['authorizedUser'] ||
in_array($facrow, $facils)) {
1326 $selected = ( $facrow['id'] == $e2f ) ?
'selected="selected"' : '' ;
1327 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1329 /************************************************************/
1332 // ===========================
1335 //END (CHEMED) IF ?>
1342 <b
><?php
xl('Patient','e'); ?
>:</b
>
1345 <input type
='text' size
='10' name
='form_patient' style
='width:100%;cursor:pointer;cursor:hand' value
='<?php echo $patientname ?>' onclick
='sel_patient()' title
='<?php xl('Click to select patient
','e
'); ?>' readonly
/>
1346 <input type
='hidden' name
='form_pid' value
='<?php echo $patientid ?>' />
1348 <td colspan
='3' nowrap style
='font-size:8pt'>
1350 <span
class="infobox">
1351 <?php
if ($patienttitle != "") { echo $patienttitle; } ?
>
1358 <b
><?php
xl('Provider','e'); ?
>:</b
>
1364 // =======================================
1366 // =======================================
1367 if ($GLOBALS['select_multi_providers']) {
1369 // there are two posible situations: edit and new record
1371 // this is executed only on edit ($eid)
1373 if ( $multiple_value ) {
1374 // find all the providers around multiple key
1375 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = $multiple_value");
1376 while ($r = sqlFetchArray($qall)) {
1377 $providers_array[] = $r['providers'];
1380 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1381 $providers_array = sqlFetchArray($qall);
1385 // build the selection tool
1386 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1388 while ($urow = sqlFetchArray($ures)) {
1389 echo " <option value='" . $urow['id'] . "'";
1392 if ( in_array($urow['id'], $providers_array) ||
($urow['id'] == $userid) ) echo " selected";
1395 echo ">" . $urow['lname'];
1396 if ($urow['fname']) echo ", " . $urow['fname'];
1402 // =======================================
1404 // =======================================
1408 // get provider from existing event
1409 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1410 $provider = sqlFetchArray($qprov);
1411 $defaultProvider = $provider['pc_aid'];
1414 // this is a new event so smartly choose a default provider
1415 /*****************************************************************
1417 // Provider already given to us as a GET parameter.
1418 $defaultProvider = $userid;
1421 // default to the currently logged-in user
1422 $defaultProvider = $_SESSION['authUserID'];
1423 // or, if we have chosen a provider in the calendar, default to them
1424 // choose the first one if multiple have been selected
1425 if (count($_SESSION['pc_username']) >= 1) {
1426 // get the numeric ID of the first provider in the array
1427 $pc_username = $_SESSION['pc_username'];
1428 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1429 $defaultProvider = $firstProvider['id'];
1434 echo "<select name='form_provider' style='width:100%' />";
1435 while ($urow = sqlFetchArray($ures)) {
1436 echo " <option value='" . $urow['id'] . "'";
1437 if ($urow['id'] == $defaultProvider) echo " selected";
1438 echo ">" . $urow['lname'];
1439 if ($urow['fname']) echo ", " . $urow['fname'];
1443 *****************************************************************/
1444 // default to the currently logged-in user
1445 $defaultProvider = $_SESSION['authUserID'];
1446 // or, if we have chosen a provider in the calendar, default to them
1447 // choose the first one if multiple have been selected
1448 if (count($_SESSION['pc_username']) >= 1) {
1449 // get the numeric ID of the first provider in the array
1450 $pc_username = $_SESSION['pc_username'];
1451 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1452 $defaultProvider = $firstProvider['id'];
1454 // if we clicked on a provider's schedule to add the event, use THAT.
1455 if ($userid) $defaultProvider = $userid;
1457 echo "<select name='form_provider' style='width:100%' />";
1458 while ($urow = sqlFetchArray($ures)) {
1459 echo " <option value='" . $urow['id'] . "'";
1460 if ($urow['id'] == $defaultProvider) echo " selected";
1461 echo ">" . $urow['lname'];
1462 if ($urow['fname']) echo ", " . $urow['fname'];
1466 /****************************************************************/
1474 <input type
='checkbox' name
='form_repeat' onclick
='set_repeat(this)' value
='1'<?php
if ($repeats) echo " checked" ?
>/>
1475 <input type
='hidden' name
='form_repeat_exdate' id
='form_repeat_exdate' value
='<?php echo $repeatexdate; ?>' /> <!-- dates excluded from the repeat
-->
1477 <td nowrap id
='tdrepeat1'><?php
xl('Repeats','e'); ?
>
1481 <select name
='form_repeat_freq' title
=<?php
xl('Every, every other, every 3rd, etc.','e','\'','\''); ?
>>
1483 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1486 echo " <option value='$key'";
1487 if ($key == $repeatfreq) echo " selected";
1488 echo ">$value</option>\n";
1493 <select name
='form_repeat_type'>
1495 // See common.api.php for these:
1496 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'))
1499 echo " <option value='$key'";
1500 if ($key == $repeattype) echo " selected";
1501 echo ">$value</option>\n";
1511 <span id
='title_apptstatus'><b
><?php
xl('Status','e'); ?
>:</b
></span
>
1512 <span id
='title_prefcat' style
='display:none'><b
><?php
xl('Pref Cat','e'); ?
>:</b
></span
>
1516 <select name
='form_apptstatus' style
='width:100%' title
='<?php xl('Appointment status
','e
'); ?>'>
1518 foreach ($statuses as $key => $value) {
1519 echo " <option value='$key'";
1520 if ($key == $row['pc_apptstatus']) echo " selected";
1521 echo ">" . htmlspecialchars($value) . "</option>\n";
1526 The following
list will be invisible unless this is an In Office
1527 event
, in which
case form_apptstatus (above
) is to be invisible
.
1529 <select name
='form_prefcat' style
='width:100%;display:none' title
='<?php xl('Preferred Event Category
','e
');?>'>
1530 <?php
echo $prefcat_options ?
>
1537 <td nowrap id
='tdrepeat2'><?php
xl('until','e'); ?
>
1540 <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
');?>' />
1541 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1542 id
='img_enddate' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1543 title
='<?php xl('Click here to choose a date
','e
');?>'>
1545 if ($repeatexdate != "") {
1546 $tmptitle = "The following dates are excluded from the repeating series";
1547 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1548 else { $tmptitle .= "\n"; }
1549 $exdates = explode(",", $repeatexdate);
1550 foreach ($exdates as $exdate) {
1551 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1553 echo "<a href='#' title='$tmptitle' alt='$tmptitle'><img src='../../pic/warning.gif' title='$tmptitle' alt='*!*' style='border:none;'/></a>";
1561 <b
><?php
xl('Comments','e'); ?
>:</b
>
1563 <td colspan
='4' nowrap
>
1564 <input type
='text' size
='40' name
='form_comments' style
='width:100%' value
='<?php echo $hometext ?>' title
='<?php xl('Optional information about this event
','e
');?>' />
1569 // DOB is important for the clinic, so if it's missing give them a chance
1570 // to enter it right here. We must display or hide this row dynamically
1571 // in case the patient-select popup is used.
1572 $patient_dob = trim($prow['DOB']);
1573 $dobstyle = ($prow && (!$patient_dob ||
substr($patient_dob, 5) == '00-00')) ?
1576 <tr id
='dob_row' style
='display:<?php echo $dobstyle ?>'>
1577 <td colspan
='4' nowrap
>
1578 <b
><font color
='red'><?php
xl('DOB is missing, please enter if possible','e'); ?
>:</font
></b
>
1581 <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)' />
1582 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1583 id
='img_dob' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1584 title
='<?php xl('Click here to choose a date
','e
');?>'>
1591 <input type
='button' name
='form_save' id
='form_save' value
='<?php xl('Save
','e
');?>' />
1593 <input type
='button' id
='find_available' value
='<?php xl('Find Available
','e
');?>' />
1595 <input type
='button' name
='form_delete' id
='form_delete' value
='<?php xl('Delete
','e
');?>'<?php
if (!$eid) echo " disabled" ?
> />
1597 <input type
='button' id
='cancel' value
='<?php xl('Cancel
','e
');?>' />
1599 <?php
if ($informant) echo "<p class='text'>" . xl('Last update by') . " $informant</p>\n"; ?
>
1603 <div id
="recurr_popup" style
="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1604 Apply the changes to the Current event only
, to this
and all Future occurrences
, or to All occurances?
1606 <input type
="button" name
="all_events" id
="all_events" value
=" All ">
1607 <input type
="button" name
="future_events" id
="future_events" value
="Future">
1608 <input type
="button" name
="current_event" id
="current_event" value
="Current">
1609 <input type
="button" name
="recurr_cancel" id
="recurr_cancel" value
="Cancel">
1614 <script language
='JavaScript'>
1615 <?php
if ($eid) { ?
>
1623 Calendar
.setup({inputField
:"form_date", ifFormat
:"%Y-%m-%d", button
:"img_date"});
1624 Calendar
.setup({inputField
:"form_enddate", ifFormat
:"%Y-%m-%d", button
:"img_enddate"});
1625 Calendar
.setup({inputField
:"form_dob", ifFormat
:"%Y-%m-%d", button
:"img_dob"});
1628 <script language
="javascript">
1629 // jQuery stuff to make the page a little easier to use
1631 $
(document
).ready(function(){
1632 $
("#form_save").click(function() { validate(); });
1633 $
("#find_available").click(function() { find_available(); });
1634 $
("#form_delete").click(function() { deleteEvent(); });
1635 $
("#cancel").click(function() { window
.close(); });
1637 // buttons affecting the modification of a repeating event
1638 $
("#all_events").click(function() { $
("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1639 $
("#future_events").click(function() { $
("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1640 $
("#current_event").click(function() { $
("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1641 $
("#recurr_cancel").click(function() { $
("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1644 // Check for errors when the form is submitted.
1645 function validate() {
1646 var f
= document
.getElementById('theform');
1647 if (f
.form_repeat
.checked
&&
1648 (! f
.form_enddate
.value || f
.form_enddate
.value
< f
.form_date
.value
)) {
1649 alert('An end date later than the start date is required for repeated events!');
1652 $
('#form_action').val("save");
1654 <?php
if ($repeats): ?
>
1655 // existing repeating events need additional prompt
1656 if ($
("#recurr_affect").val() == "") {
1658 // show the current/future/all DIV for the user to choose one
1659 $
("#recurr_popup").css("visibility", "visible");
1664 return SubmitForm();
1667 // disable all the form elements outside the recurr_popup
1668 function DisableForm() {
1669 $
("#theform").children().attr("disabled", "true");
1671 function EnableForm() {
1672 $
("#theform").children().removeAttr("disabled");
1674 // hide the recurring popup DIV
1675 function HideRecurrPopup() {
1676 $
("#recurr_popup").css("visibility", "hidden");
1679 function deleteEvent() {
1680 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?")) {
1681 $
('#form_action').val("delete");
1683 <?php
if ($repeats): ?
>
1684 // existing repeating events need additional prompt
1685 if ($
("#recurr_affect").val() == "") {
1687 // show the current/future/all DIV for the user to choose one
1688 $
("#recurr_popup").css("visibility", "visible");
1693 return SubmitForm();
1698 function SubmitForm() {
1699 // DBC Dutch System validation
1700 <?php
if ( $GLOBALS['dutchpc'] && $_SESSION['editactiv']) { ?
>
1701 var a
= verify_selecteerbaar();
1702 if ( !a
) return false;
1706 $
('#theform').submit();
1707 top
.restoreSession();