Feature to add new patient info from calender pop up - contributed by Visolve
[openemr.git] / interface / main / calendar / add_edit_event.php
blob30e1df767f6b8e1d0619cc1621b96dd484a6bde9
1 <?php
2 // Copyright (C) 2005-2006 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");
29 // Things that might be passed by our opener.
31 $eid = $_GET['eid']; // only for existing events
32 $date = $_GET['date']; // this and below only for new events
33 $userid = $_GET['userid'];
34 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
36 if ($date)
37 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
38 else
39 $date = date("Y-m-d");
41 $starttimem = '00';
42 if (isset($_GET['starttimem']))
43 $starttimem = substr('00' . $_GET['starttimem'], -2);
45 if (isset($_GET['starttimeh'])) {
46 $starttimeh = $_GET['starttimeh'];
47 if (isset($_GET['startampm'])) {
48 if ($_GET['startampm'] == '2' && $starttimeh < 12)
49 $starttimeh += 12;
51 } else {
52 $starttimeh = date("G");
54 $startampm = '';
56 $info_msg = "";
58 // used for DBC Dutch System
59 $_SESSION['event_date'] = $date;
60 $link = '../../../library/DBC_functions.php'; // ajax stuff and db work
64 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
66 <?php
68 // insert an event
69 // $args is mainly filled with content from the POST http var
70 function InsertEvent($args) {
71 return sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
72 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
73 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
74 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
75 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
76 ") VALUES ( " .
77 "'" . $args['form_category'] . "', " .
78 "'" . $args['new_multiple_value'] . "', " .
79 "'" . $args['form_provider'] . "', " .
80 "'" . $args['form_pid'] . "', " .
81 "'" . formDataCore($args['form_title']) . "', " .
82 "NOW(), " .
83 "'" . formDataCore($args['form_comments']) . "', " .
84 "'" . $_SESSION['authUserID'] . "', " .
85 "'" . $args['event_date'] . "', " .
86 "'" . fixDate($args['form_enddate']) . "', " .
87 "'" . $args['duration'] . "', " .
88 "'" . ($args['form_repeat'] ? '1' : '0') . "', " .
89 "'" . serialize($args['recurrspec']) . "', " .
90 "'" . $args['starttime'] ."', " .
91 "'" . $args['endtime'] ."', " .
92 "'" . $args['form_allday'] . "', " .
93 "'" . $args['form_apptstatus'] . "', " .
94 "'" . $args['form_prefcat'] . "', " .
95 "'" . $args['locationspec'] ."', " .
96 "1, " .
97 "1, " .(int)$args['facility']. " )"
101 // =====================================
102 // DBC Dutch System
103 // ACTIVITIES / TIMES
104 if ( $GLOBALS['dutchpc'] ) {
105 if ( $eid ) {
106 if ( $GLOBALS['select_multi_providers'] ) {
107 // ------------------------------------------
108 // what is multiple key around this $eid?
109 $rowmulti = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
111 // what are all pc_eid's grouped by multiple key
112 $eventsrow = array();
113 $rezev = mysql_query("SELECT pc_eid FROM openemr_postcalendar_events WHERE pc_multiple = {$rowmulti['pc_multiple']}");
114 while ( $row = mysql_fetch_array($rezev) ) {
115 $eventsrow[] = $row['pc_eid'];
118 // we look in cl_event_activiteit / cl_time_activiteit for a matching record
119 foreach ( $eventsrow as $ev) {
120 $activ = sqlQuery("SELECT * FROM cl_event_activiteit WHERE event_id = $ev");
121 if ( $activ['event_id'] ) $singleeid = $activ['event_id'];
123 $time = sqlQuery("SELECT * FROM cl_time_activiteit WHERE event_id = $ev");
124 if ( $time ) $timerow = $time;
127 // prevent blank values for $singleeid
128 if ( !$singleeid) $singleeid = $eid;
130 // ------------------------------------------
131 } else {
132 // ------------------------------------------
133 // single providers case
134 $timerow = sqlQuery("SELECT * FROM cl_time_activiteit WHERE event_id = $eid");
135 $singleeid = $eid;
136 // ------------------------------------------
138 } // if ($eid)
139 } // if (dutchpc)
141 // EVENTS TO FACILITIES (lemonsoftware)
142 //(CHEMED) get facility name
143 // edit event case - if there is no association made, then insert one with the first facility
144 if ( $eid ) {
145 $selfacil = '';
146 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
147 FROM openemr_postcalendar_events
148 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
149 WHERE pc_eid = $eid");
150 // if ( !$facility['pc_facility'] ) {
151 if ( is_array($facility) && !$facility['pc_facility'] ) {
152 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
153 $min = $qmin['minId'];
154 $min_name = $qmin['facility'];
156 // multiple providers case
157 if ( $GLOBALS['select_multi_providers'] ) {
158 $mul = $facility['pc_multiple'];
159 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
161 // EOS multiple
163 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
164 $e2f = $min;
165 $e2f_name = $min_name;
166 } else {
167 // not edit event
168 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
169 $e2f = $_SESSION['pc_facility'];
170 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
171 $e2f = $_COOKIE['pc_facility'];
172 } else {
173 $e2f = $facility['pc_facility'];
174 $e2f_name = $facility['name'];
178 // EOS E2F
179 // ===========================
182 // If we are saving, then save and close the window.
184 if ($_POST['form_action'] == "save") {
186 // ========================================
187 // DBC SYSTEM
188 // check if for activity act_3.2 we have times completed
189 // larry :: fix dbc
190 if ( $GLOBALS['dutchpc'] ) {
191 $sa = selected_ac();
192 if ( $sa == 'act_3.2') {
193 $duration = (int)$_POST['form_duration'];
194 if ( empty($duration) ) exit();
197 // ========================================
199 // the starting date of the event, pay attention with this value
200 // when editing recurring events -- JRM Oct-08
201 $event_date = fixDate($_POST['form_date']);
203 // Compute start and end time strings to be saved.
204 if ($_POST['form_allday']) {
205 $tmph = 0;
206 $tmpm = 0;
207 $duration = 24 * 60;
208 } else {
209 $tmph = $_POST['form_hour'] + 0;
210 $tmpm = $_POST['form_minute'] + 0;
211 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
212 $duration = $_POST['form_duration'];
214 $starttime = "$tmph:$tmpm:00";
216 $tmpm += $duration;
217 while ($tmpm >= 60) {
218 $tmpm -= 60;
219 ++$tmph;
221 $endtime = "$tmph:$tmpm:00";
223 // Useless garbage that we must save.
224 $locationspecs = array("event_location" => "",
225 "event_street1" => "",
226 "event_street2" => "",
227 "event_city" => "",
228 "event_state" => "",
229 "event_postal" => ""
231 $locationspec = serialize($locationspecs);
233 // capture the recurring specifications
234 $recurrspec = array("event_repeat_freq" => $_POST['form_repeat_freq'],
235 "event_repeat_freq_type" => $_POST['form_repeat_type'],
236 "event_repeat_on_num" => "1",
237 "event_repeat_on_day" => "0",
238 "event_repeat_on_freq" => "0",
239 "exdate" => $_POST['form_repeat_exdate']
242 // no recurr specs, this is used for adding a new non-recurring event
243 $noRecurrspec = array("event_repeat_freq" => "",
244 "event_repeat_freq_type" => "",
245 "event_repeat_on_num" => "1",
246 "event_repeat_on_day" => "0",
247 "event_repeat_on_freq" => "0",
248 "exdate" => ""
251 /* =======================================================
252 * UPDATE EVENTS
253 * =====================================================*/
254 if ($eid) {
256 // what is multiple key around this $eid?
257 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
259 // timing-activity validation - larry :: DBC ????
260 $activ = "";
261 if ( $GLOBALS['dutchpc'] ) {
262 if ( $_SESSION['editactiv'] ) { $activ = selected_ac(); }
263 else { $activ = what_activity($eid); }
265 // eof DBC
267 // ====================================
268 // multiple providers
269 // ====================================
270 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
272 // obtain current list of providers regarding the multiple key
273 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
274 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
276 // get the new list of providers from the submitted form
277 $providers_new = $_POST['form_provider'];
279 // ===== Only current event of repeating series =====
280 if ($_POST['recurr_affect'] == 'current') {
282 // update all existing event records to exlude the current date
283 foreach ($providers_current as $provider) {
284 // update the provider's original event
285 // get the original event's repeat specs
286 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
287 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
288 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
289 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
290 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
291 else { $oldRecurrspec['exdate'] .= $selected_date; }
293 // mod original event recur specs to exclude this date
294 sqlStatement("UPDATE openemr_postcalendar_events SET " .
295 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
296 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
299 // obtain the next available unique key to group multiple providers around some event
300 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
301 $max = sqlFetchArray($q);
302 $new_multiple_value = $max['max'] + 1;
304 // insert a new event record for each provider selected on the form
305 foreach ($providers_new as $provider) {
306 // insert a new event on this date with POST form data
307 $args = $_POST;
308 // specify some special variables needed for the INSERT
309 $args['new_multiple_value'] = $new_multiple_value;
310 $args['form_provider'] = $provider;
311 $args['event_date'] = $event_date;
312 $args['duration'] = $duration * 60;
313 // this event is forced to NOT REPEAT
314 $args['form_repeat'] = "0";
315 $args['recurrspec'] = $noRecurrspec;
316 $args['form_enddate'] = "0000-00-00";
317 $args['starttime'] = $starttime;
318 $args['endtime'] = $endtime;
319 $args['locationspec'] = $locationspec;
320 InsertEvent($args);
324 // ===== Future Recurring events of a repeating series =====
325 else if ($_POST['recurr_affect'] == 'future') {
326 // update all existing event records to
327 // stop recurring on this date-1
328 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
329 foreach ($providers_current as $provider) {
330 // mod original event recur specs to end on this date
331 sqlStatement("UPDATE openemr_postcalendar_events SET " .
332 " pc_enddate = '" . $selected_date ."' ".
333 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
336 // obtain the next available unique key to group multiple providers around some event
337 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
338 $max = sqlFetchArray($q);
339 $new_multiple_value = $max['max'] + 1;
341 // insert a new event record for each provider selected on the form
342 foreach ($providers_new as $provider) {
343 // insert a new event on this date with POST form data
344 $args = $_POST;
345 // specify some special variables needed for the INSERT
346 $args['new_multiple_value'] = $new_multiple_value;
347 $args['form_provider'] = $provider;
348 $args['event_date'] = $event_date;
349 $args['duration'] = $duration * 60;
350 $args['recurrspec'] = $recurrspec;
351 $args['starttime'] = $starttime;
352 $args['endtime'] = $endtime;
353 $args['locationspec'] = $locationspec;
354 InsertEvent($args);
358 else {
359 /* =================================================================== */
360 // ===== a Single event or All events in a repeating series ==========
361 /* =================================================================== */
363 // this difference means that some providers from current was UNCHECKED
364 // so we must delete this event for them
365 $r1 = array_diff ($providers_current, $providers_new);
366 if (count ($r1)) {
367 foreach ($r1 as $to_be_removed) {
368 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
372 // perform a check to see if user changed event date
373 // this is important when editing an existing recurring event
374 // oct-08 JRM
375 if ($_POST['form_date'] == $_POST['selected_date']) {
376 // user has NOT changed the start date of the event
377 $event_date = fixDate($_POST['event_start_date']);
380 // this difference means that some providers were added
381 // so we must insert this event for them
382 $r2 = array_diff ($providers_new, $providers_current);
383 if (count ($r2)) {
384 foreach ($r2 as $to_be_inserted) {
385 $args = $_POST;
386 // specify some special variables needed for the INSERT
387 $args['new_multiple_value'] = $row['pc_multiple'];
388 $args['form_provider'] = $to_be_inserted;
389 $args['event_date'] = $event_date;
390 $args['duration'] = $duration * 60;
391 $args['recurrspec'] = $recurrspec;
392 $args['starttime'] = $starttime;
393 $args['endtime'] = $endtime;
394 $args['locationspec'] = $locationspec;
395 InsertEvent($args);
399 // after the two diffs above, we must update for remaining providers
400 // those who are intersected in $providers_current and $providers_new
401 foreach ($_POST['form_provider'] as $provider) {
402 sqlStatement("UPDATE openemr_postcalendar_events SET " .
403 "pc_catid = '" . $_POST['form_category'] . "', " .
404 "pc_pid = '" . $_POST['form_pid'] . "', " .
405 "pc_title = '" . formData("form_title") . "', " .
406 "pc_time = NOW(), " .
407 "pc_hometext = '" . formData("form_comments") . "', " .
408 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
409 "pc_eventDate = '" . $event_date . "', " .
410 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
411 "pc_duration = '" . ($duration * 60) . "', " .
412 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
413 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
414 "pc_startTime = '$starttime', " .
415 "pc_endTime = '$endtime', " .
416 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
417 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
418 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
419 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
420 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
421 } // foreach
425 // ====================================
426 // single provider
427 // ====================================
428 } elseif ( !$row['pc_multiple'] ) {
429 if ( $GLOBALS['select_multi_providers'] ) {
430 $prov = $_POST['form_provider'][0];
431 } else {
432 $prov = $_POST['form_provider'];
435 if ($_POST['recurr_affect'] == 'current') {
436 // get the original event's repeat specs
437 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
438 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
439 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
440 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
441 else { $oldRecurrspec['exdate'] .= $selected_date; }
443 // mod original event recur specs to exclude this date
444 sqlStatement("UPDATE openemr_postcalendar_events SET " .
445 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
446 " WHERE pc_eid = '$eid'");
448 // insert a new event on this date with POST form data
449 $args = $_POST;
450 // specify some special variables needed for the INSERT
451 $args['event_date'] = $event_date;
452 $args['duration'] = $duration * 60;
453 // this event is forced to NOT REPEAT
454 $args['form_repeat'] = "0";
455 $args['recurrspec'] = $noRecurrspec;
456 $args['form_enddate'] = "0000-00-00";
457 $args['starttime'] = $starttime;
458 $args['endtime'] = $endtime;
459 $args['locationspec'] = $locationspec;
460 InsertEvent($args);
462 else if ($_POST['recurr_affect'] == 'future') {
463 // mod original event to stop recurring on this date-1
464 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
465 sqlStatement("UPDATE openemr_postcalendar_events SET " .
466 " pc_enddate = '" . $selected_date ."' ".
467 " WHERE pc_eid = '$eid'");
469 // insert a new event starting on this date with POST form data
470 $args = $_POST;
471 // specify some special variables needed for the INSERT
472 $args['event_date'] = $event_date;
473 $args['duration'] = $duration * 60;
474 $args['recurrspec'] = $recurrspec;
475 $args['starttime'] = $starttime;
476 $args['endtime'] = $endtime;
477 $args['locationspec'] = $locationspec;
478 InsertEvent($args);
480 else {
482 // perform a check to see if user changed event date
483 // this is important when editing an existing recurring event
484 // oct-08 JRM
485 if ($_POST['form_date'] == $_POST['selected_date']) {
486 // user has NOT changed the start date of the event
487 $event_date = fixDate($_POST['event_start_date']);
490 // mod the SINGLE event or ALL EVENTS in a repeating series
491 // simple provider case
492 sqlStatement("UPDATE openemr_postcalendar_events SET " .
493 "pc_catid = '" . $_POST['form_category'] . "', " .
494 "pc_aid = '" . $prov . "', " .
495 "pc_pid = '" . $_POST['form_pid'] . "', " .
496 "pc_title = '" . formData("form_title") . "', " .
497 "pc_time = NOW(), " .
498 "pc_hometext = '" . formData("form_comments") . "', " .
499 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
500 "pc_eventDate = '" . $event_date . "', " .
501 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
502 "pc_duration = '" . ($duration * 60) . "', " .
503 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
504 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
505 "pc_startTime = '$starttime', " .
506 "pc_endTime = '$endtime', " .
507 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
508 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
509 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
510 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
511 "WHERE pc_eid = '$eid'");
515 // ===================================
516 // DBC change activity / times
517 $activ = ''; // activity could be an old value or a new one
518 if ( $GLOBALS['dutchpc'] ) {
519 if ( $_SESSION['editactiv'] ) {
520 $ac = selected_ac(); $activ = $ac;
521 $acid = what_sysid($ac);
523 if ( $acid ) sqlInsert("INSERT INTO cl_event_activiteit (event_id, activity_sysid)".
524 " VALUES ('" .$singleeid. "', '" .$acid. "') ON DUPLICATE KEY UPDATE activity_sysid = " .$acid );
526 $_SESSION['editactiv'] = FALSE; // otherwise you'll get a nasty bug!
527 } else {
528 $activcode = what_activity($singleeid);
529 $activ = what_code_activity($activcode);
532 // timing-activity validation
533 if ( vl_activity_travel($activ) ) {
534 $itime = (int)$_POST['form_duration_indirect']; $ttime = 0;
535 } else {
536 $itime = (int)$_POST['form_duration_indirect']; $ttime = (int)$_POST['form_duration_travel'];
538 sqlInsert("INSERT INTO cl_time_activiteit (event_id, indirect_time, travel_time)".
539 " VALUES ('" .$singleeid. "', '" .$itime. "', '" .$ttime. "') ON DUPLICATE KEY UPDATE indirect_time = " .$itime.
540 ", travel_time = " . $ttime);
543 // end DBC change activity / times
544 // ===================================
546 // =======================================
547 // end Update Multi providers case
548 // =======================================
550 // EVENTS TO FACILITIES
551 $e2f = (int)$eid;
554 } else {
555 /* =======================================================
556 * INSERT NEW EVENT(S)
557 * ======================================================*/
559 // =======================================
560 // multi providers case
561 // =======================================
562 if (is_array($_POST['form_provider'])) {
564 // obtain the next available unique key to group multiple providers around some event
565 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
566 $max = sqlFetchArray($q);
567 $new_multiple_value = $max['max'] + 1;
569 foreach ($_POST['form_provider'] as $provider) {
570 $args = $_POST;
571 // specify some special variables needed for the INSERT
572 $args['new_multiple_value'] = $new_multiple_value;
573 $args['form_provider'] = $provider;
574 $args['event_date'] = $event_date;
575 $args['duration'] = $duration * 60;
576 $args['recurrspec'] = $recurrspec;
577 $args['starttime'] = $starttime;
578 $args['endtime'] = $endtime;
579 $args['locationspec'] = $locationspec;
580 InsertEvent($args);
583 // ====================================
584 // single provider
585 // ====================================
586 } else {
587 $args = $_POST;
588 // specify some special variables needed for the INSERT
589 $args['new_multiple_value'] = "";
590 $args['event_date'] = $event_date;
591 $args['duration'] = $duration * 60;
592 $args['recurrspec'] = $recurrspec;
593 $args['starttime'] = $starttime;
594 $args['endtime'] = $endtime;
595 $args['locationspec'] = $locationspec;
596 InsertEvent($args);
599 // ==============================================
600 // DBC Dutch System (insert case)
601 $lid = mysql_insert_id($GLOBALS['dbh']); // obtain last inserted id
603 // larry :: fix dbc
604 if ( $GLOBALS['dutchpc'] ) {
605 $ac = selected_ac();
606 $acid = what_sysid($ac);
607 sqlInsert("INSERT INTO cl_event_activiteit (event_id, activity_sysid) VALUES ('" .$lid. "', '" .$acid. "')");
609 // timing-activity validation
610 if ( vl_activity_travel($activ) ) {
611 $itime = (int)$_POST['form_duration_indirect']; $ttime = 0;
612 } else {
613 $itime = (int)$_POST['form_duration_indirect']; $ttime = (int)$_POST['form_duration_travel'];
615 sqlInsert("INSERT INTO cl_time_activiteit (event_id, indirect_time, travel_time)".
616 " VALUES ('" .$lid. "', '" .$itime. "', '" .$ttime. "')");
618 // DBC Dutch System (insert case)
619 // ==============================================
621 // new ZTN ?
622 $pid1007 = ( $_POST['form_pid'] ) ? $_POST['form_pid'] : $pid;
623 if ( $pid1007 ) {
624 $a = generate_id1007($pid1007, $event_date); //var_dump($a); exit();
627 // end DBC
628 // ==============================================
632 // done with EVENT insert/update statements
634 // Save new DOB if it's there.
635 $patient_dob = trim($_POST['form_dob']);
636 if ($patient_dob && $_POST['form_pid']) {
637 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
638 "pid = '" . $_POST['form_pid'] . "'");
641 // Auto-create a new encounter if appropriate.
643 if ($GLOBALS['auto_create_new_encounters'] &&
644 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
646 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
647 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
648 if ($tmprow['count'] == 0) {
649 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
650 $_POST['form_provider'] . "'");
651 $username = $tmprow['username'];
652 $facility = $tmprow['facility'];
653 // $facility_id = $tmprow['facility_id'];
654 // use the session facility if it is set, otherwise the one from the provider.
655 $facility_id = $_SESSION['pc_facility'] ? $_SESSION['pc_facility'] : $tmprow['facility_id'];
656 $conn = $GLOBALS['adodb']['db'];
657 $encounter = $conn->GenID("sequences");
658 addForm($encounter, "New Patient Encounter",
659 sqlInsert("INSERT INTO form_encounter SET " .
660 "date = '$event_date', " .
661 "onset_date = '$event_date', " .
662 "reason = '" . formData("form_comments") . "', " .
663 "facility = '$facility', " .
664 // "facility_id = '$facility_id', " .
665 "facility_id = '" . (int)$_POST['facility'] . "', " .
666 "pid = '" . $_POST['form_pid'] . "', " .
667 "encounter = '$encounter'"
669 "newpatient", $_POST['form_pid'], "1", "NOW()", $username
671 $info_msg .= "New encounter $encounter was created. ";
676 // =======================================
677 // DELETE EVENT(s)
678 // =======================================
679 else if ($_POST['form_action'] == "delete") {
680 // =======================================
681 // multi providers event
682 // =======================================
683 if ($GLOBALS['select_multi_providers']) {
685 // what is multiple key around this $eid?
686 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
688 // obtain current list of providers regarding the multiple key
689 $providers_current = array();
690 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
691 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
693 // establish a WHERE clause
694 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = {$row['pc_multiple']}"; }
695 else { $whereClause = "pc_eid = $eid"; }
697 if ($_POST['recurr_affect'] == 'current') {
698 // update all existing event records to exlude the current date
699 foreach ($providers_current as $provider) {
700 // update the provider's original event
701 // get the original event's repeat specs
702 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
703 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
704 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
705 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
706 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
707 else { $oldRecurrspec['exdate'] .= $selected_date; }
709 // mod original event recur specs to exclude this date
710 sqlStatement("UPDATE openemr_postcalendar_events SET " .
711 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
712 " WHERE ". $whereClause);
715 else if ($_POST['recurr_affect'] == 'future') {
716 // update all existing event records to stop recurring on this date-1
717 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
718 foreach ($providers_current as $provider) {
719 // update the provider's original event
720 sqlStatement("UPDATE openemr_postcalendar_events SET " .
721 " pc_enddate = '" . $selected_date ."' ".
722 " WHERE ".$whereClause);
725 else {
726 // really delete the event from the database
727 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
731 // =======================================
732 // single provider event
733 // =======================================
734 else {
736 if ($_POST['recurr_affect'] == 'current') {
737 // mod original event recur specs to exclude this date
739 // get the original event's repeat specs
740 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
741 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
742 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
743 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
744 else { $oldRecurrspec['exdate'] .= $selected_date; }
745 sqlStatement("UPDATE openemr_postcalendar_events SET " .
746 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
747 " WHERE pc_eid = '$eid'");
750 else if ($_POST['recurr_affect'] == 'future') {
751 // mod original event to stop recurring on this date-1
752 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
753 sqlStatement("UPDATE openemr_postcalendar_events SET " .
754 " pc_enddate = '" . $selected_date ."' ".
755 " WHERE pc_eid = '$eid'");
758 else {
759 // fully delete the event from the database
760 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
765 if ($_POST['form_action'] != "") {
766 // Close this window and refresh the calendar display.
767 echo "<html>\n<body>\n<script language='JavaScript'>\n";
768 if ($info_msg) echo " alert('$info_msg');\n";
769 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
770 echo " window.close();\n";
771 echo "</script>\n</body>\n</html>\n";
772 exit();
775 //*********************************
776 // If we get this far then we are displaying the form.
777 //*********************************
779 $statuses = array(
780 '-' => '',
781 '*' => xl('* Reminder done'),
782 '+' => xl('+ Chart pulled'),
783 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
784 '?' => xl('? No show'),
785 '@' => xl('@ Arrived'),
786 '~' => xl('~ Arrived late'),
787 '!' => xl('! Left w/o visit'),
788 '#' => xl('# Ins/fin issue'),
789 '<' => xl('< In exam room'),
790 '>' => xl('> Checked out'),
791 '$' => xl('$ Coding done'),
792 '%' => xl('% Cancelled < 24h ')
795 $repeats = 0; // if the event repeats
796 $repeattype = '0';
797 $repeatfreq = '0';
798 $patientid = '';
799 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
800 $patientname = xl('Click to select');
801 $patienttitle = "";
802 $hometext = "";
803 $row = array();
804 $informant = "";
806 // If we are editing an existing event, then get its data.
807 if ($eid) {
808 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
810 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
811 "FROM openemr_postcalendar_events AS e " .
812 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
813 "WHERE pc_eid = $eid");
814 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
816 // instead of using the event's starting date, keep what has been provided
817 // via the GET array, see the top of this file
818 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
819 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
820 $userid = $row['pc_aid'];
821 $patientid = $row['pc_pid'];
822 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
823 $starttimem = substr($row['pc_startTime'], 3, 2);
824 $repeats = $row['pc_recurrtype'];
825 $multiple_value = $row['pc_multiple'];
827 // parse out the repeating data, if any
828 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
829 $repeattype = $rspecs['event_repeat_freq_type'];
830 $repeatfreq = $rspecs['event_repeat_freq'];
831 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
833 $hometext = $row['pc_hometext'];
834 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
836 else {
837 // a NEW event
838 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
840 //-------------------------------------
841 //(CHEMED)
842 //Set default facility for a new event based on the given 'userid'
843 if ($userid) {
844 /*************************************************************
845 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
846 *************************************************************/
847 if ($_SESSION['pc_facility']) {
848 $pref_facility = sqlFetchArray(sqlStatement(sprintf("
849 SELECT f.id as facility_id,
850 f.name as facility
851 FROM facility f
852 WHERE f.id = %d
854 $_SESSION['pc_facility']
855 )));
856 } else {
857 $pref_facility = sqlFetchArray(sqlStatement("
858 SELECT u.facility_id,
859 f.name as facility
860 FROM users u
861 LEFT JOIN facility f on (u.facility_id = f.id)
862 WHERE u.id = $userid
863 "));
865 /************************************************************/
866 $e2f = $pref_facility['facility_id'];
867 $e2f_name = $pref_facility['facility'];
869 //END of CHEMED -----------------------
872 // If we have a patient ID, get the name and phone numbers to display.
873 if ($patientid) {
874 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
875 "FROM patient_data WHERE pid = '" . $patientid . "'");
876 $patientname = $prow['lname'] . ", " . $prow['fname'];
877 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
878 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
881 // Get the providers list.
882 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
883 "authorized != 0 AND active = 1 ORDER BY lname, fname");
885 // Get event categories.
886 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
887 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
889 // Fix up the time format for AM/PM.
890 $startampm = '1';
891 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
892 $startampm = '2';
893 if ($starttimeh > 12) $starttimeh -= 12;
897 <html>
898 <head>
899 <?php html_header_show(); ?>
900 <title><?php echo $eid ? xl('Edit','e') : xl('Add New','e') ?> <?php xl('Event','e');?></title>
901 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
903 <style>
904 td { font-size:0.8em; }
905 </style>
907 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
908 <script type="text/javascript" src="../../../library/topdialog.js"></script>
909 <script type="text/javascript" src="../../../library/dialog.js"></script>
910 <script type="text/javascript" src="../../../library/textformat.js"></script>
911 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
912 <script type="text/javascript" src="../../../library/dynarch_calendar_en.js"></script>
913 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
915 <?php
916 // ============================================================================
917 // DBC SYSTEM JAVASCRIPT FILE
919 if ( $GLOBALS['dutchpc'] ) { ?>
920 <script type="text/javascript" src="../../../library/js/add_edit_event.js"></script>
922 <?php }
923 // ============================================================================
926 <script language="JavaScript">
928 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
930 var durations = new Array();
931 // var rectypes = new Array();
932 <?php
933 // Read the event categories, generate their options list, and get
934 // the default event duration from them if this is a new event.
935 $catoptions = "";
936 $prefcat_options = " <option value='0'>-- None --</option>\n";
937 $thisduration = 0;
938 if ($eid) {
939 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
941 while ($crow = sqlFetchArray($cres)) {
942 $duration = round($crow['pc_duration'] / 60);
943 if ($crow['pc_end_all_day']) $duration = 1440;
944 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
945 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
946 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
947 if ($eid) {
948 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
949 } else {
950 if ($crow['pc_catid'] == $default_catid) {
951 $catoptions .= " selected";
952 $thisduration = $duration;
955 $catoptions .= ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
957 // This section is to build the list of preferred categories:
958 if ($duration) {
959 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
960 if ($eid) {
961 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
963 $prefcat_options .= ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
969 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
971 // This is for callback by the find-patient popup.
972 function setpatient(pid, lname, fname, dob) {
973 var f = document.forms[0];
974 f.form_patient.value = lname + ', ' + fname;
975 f.form_pid.value = pid;
976 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
977 document.getElementById('dob_row').style.display = dobstyle;
980 // This invokes the find-patient popup.
981 function sel_patient() {
982 dlgopen('find_patient_popup.php', '_blank', 500, 400);
985 // Do whatever is needed when a new event category is selected.
986 // For now this means changing the event title and duration.
987 function set_display() {
988 var f = document.forms[0];
989 var s = f.form_category;
990 if (s.selectedIndex >= 0) {
991 var catid = s.options[s.selectedIndex].value;
992 var style_apptstatus = document.getElementById('title_apptstatus').style;
993 var style_prefcat = document.getElementById('title_prefcat').style;
994 if (catid == '2') { // In Office
995 style_apptstatus.display = 'none';
996 style_prefcat.display = '';
997 f.form_apptstatus.style.display = 'none';
998 f.form_prefcat.style.display = '';
999 } else {
1000 style_prefcat.display = 'none';
1001 style_apptstatus.display = '';
1002 f.form_prefcat.style.display = 'none';
1003 f.form_apptstatus.style.display = '';
1008 // Do whatever is needed when a new event category is selected.
1009 // For now this means changing the event title and duration.
1010 function set_category() {
1011 var f = document.forms[0];
1012 var s = f.form_category;
1013 if (s.selectedIndex >= 0) {
1014 var catid = s.options[s.selectedIndex].value;
1015 f.form_title.value = s.options[s.selectedIndex].text;
1016 f.form_duration.value = durations[catid];
1017 set_display();
1021 // Modify some visual attributes when the all-day or timed-event
1022 // radio buttons are clicked.
1023 function set_allday() {
1024 var f = document.forms[0];
1025 var color1 = '#777777';
1026 var color2 = '#777777';
1027 var disabled2 = true;
1028 if (document.getElementById('rballday1').checked) {
1029 color1 = '#000000';
1031 if (document.getElementById('rballday2').checked) {
1032 color2 = '#000000';
1033 disabled2 = false;
1035 document.getElementById('tdallday1').style.color = color1;
1036 document.getElementById('tdallday2').style.color = color2;
1037 document.getElementById('tdallday3').style.color = color2;
1038 document.getElementById('tdallday4').style.color = color2;
1039 document.getElementById('tdallday5').style.color = color2;
1040 f.form_hour.disabled = disabled2;
1041 f.form_minute.disabled = disabled2;
1042 f.form_ampm.disabled = disabled2;
1043 f.form_duration.disabled = disabled2;
1046 // Modify some visual attributes when the Repeat checkbox is clicked.
1047 function set_repeat() {
1048 var f = document.forms[0];
1049 var isdisabled = true;
1050 var mycolor = '#777777';
1051 var myvisibility = 'hidden';
1052 if (f.form_repeat.checked) {
1053 isdisabled = false;
1054 mycolor = '#000000';
1055 myvisibility = 'visible';
1057 f.form_repeat_type.disabled = isdisabled;
1058 f.form_repeat_freq.disabled = isdisabled;
1059 f.form_enddate.disabled = isdisabled;
1060 document.getElementById('tdrepeat1').style.color = mycolor;
1061 document.getElementById('tdrepeat2').style.color = mycolor;
1062 document.getElementById('img_enddate').style.visibility = myvisibility;
1065 // This is for callback by the find-available popup.
1066 function setappt(year,mon,mday,hours,minutes) {
1067 var f = document.forms[0];
1068 f.form_date.value = '' + year + '-' +
1069 ('' + (mon + 100)).substring(1) + '-' +
1070 ('' + (mday + 100)).substring(1);
1071 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
1072 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
1073 f.form_minute.value = ('' + (minutes + 100)).substring(1);
1076 // Invoke the find-available popup.
1077 function find_available() {
1078 top.restoreSession();
1079 // (CHEMED) Conditional value selection, because there is no <select> element
1080 // when making an appointment for a specific provider
1081 var s = document.forms[0].form_provider;
1082 var f = document.forms[0].facility;
1083 <?php if ($userid != 0) { ?>
1084 s = document.forms[0].form_provider.value;
1085 f = document.forms[0].facility.value;
1086 <?php } else {?>
1087 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1088 f = document.forms[0].facility.options[f.selectedIndex].value;
1089 <?php }?>
1090 var c = document.forms[0].form_category;
1091 var formDate = document.forms[0].form_date;
1092 dlgopen('find_appt_popup.php?providerid=' + s +
1093 '&catid=' + c.options[c.selectedIndex].value +
1094 '&facility=' + f +
1095 '&startdate=' + formDate.value, '_blank', 500, 400);
1096 //END (CHEMED) modifications
1099 // ==============================
1100 // DBC BOS
1101 function verify_selecteerbaar (a) {
1102 var f = document.forms[0]; var a;
1103 if (f.box5.value != 0) a = f.box5.value;
1104 else if (f.box4.value != 0) a = f.box4.value;
1105 else if (f.box3.value != 0) a = f.box3.value;
1106 else if (f.box2.value != 0) a = f.box2.value;
1107 else if (f.box1.value != 0) a = f.box1.value;
1108 else { alert('You must choose an activity.'); return false;
1111 var answer = $.ajax({
1112 url: "<?=$link?>",
1113 type: 'POST',
1114 data: 'vcode='+a,
1115 async: false
1116 }).responseText;
1117 if ( answer == 'false') { alert("Please select again"); return false; }
1118 else return true;
1120 // EOS DBC
1122 </script>
1124 <?php
1125 if ( $GLOBALS['dutchpc'])
1126 { ?>
1128 <script type="text/javascript">
1129 boxes();
1131 <?php
1132 if ( $eid ) { // editing case
1134 editcase();
1135 <?php
1136 } // EOS editing case
1139 </script>
1141 <?php
1142 } // EOS DBC DUTCH AJAX PART
1145 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1147 </head>
1149 <body class="body_top" onunload='imclosing()'>
1151 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo $eid ?>' />
1152 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1153 <input type='hidden' size='2' name='resname' value='empty' />
1154 <?php
1155 if ($_POST["resname"]=="noresult"){
1156 echo '
1157 <script language="Javascript">
1158 // refresh and redirect the parent window
1159 if (!opener.closed && opener.refreshme) opener.refreshme();
1160 top.restoreSession();
1161 opener.document.location="../../new/new.php";
1162 // Close the window
1163 window.close();
1164 </script>';
1167 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1168 <input type="hidden" name="form_action" id="form_action" value="">
1169 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1170 <!-- used for recurring events -->
1171 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo $date; ?>">
1172 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo $eventstartdate; ?>">
1173 <center>
1175 <table border='0' width='100%'>
1177 <tr>
1178 <td width='1%' nowrap>
1179 <b><?php xl('Category','e'); ?>:</b>
1180 </td>
1181 <td nowrap>
1182 <select name='form_category' onchange='set_category()' style='width:100%'>
1183 <?php echo $catoptions ?>
1184 </select>
1185 </td>
1186 <td width='1%' nowrap>
1187 &nbsp;&nbsp;
1188 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1189 <?php if ($thisduration == 1440) echo "checked " ?>/>
1190 </td>
1191 <td colspan='2' nowrap id='tdallday1'>
1192 <?php xl('All day event','e'); ?>
1193 </td>
1194 </tr>
1196 <tr>
1197 <td nowrap>
1198 <b><?php xl('Date','e'); ?>:</b>
1199 </td>
1200 <td nowrap>
1201 <input type='text' size='10' name='form_date' id='form_date'
1202 value='<?php echo $date ?>'
1203 title='<?php xl('yyyy-mm-dd event date or starting date','e'); ?>'
1204 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
1205 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1206 id='img_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1207 title='<?php xl('Click here to choose a date','e'); ?>'>
1208 </td>
1209 <td nowrap>
1210 &nbsp;&nbsp;
1211 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1212 </td>
1213 <td width='1%' nowrap id='tdallday2'>
1214 <?php xl('Time','e'); ?>
1215 </td>
1216 <td width='1%' nowrap id='tdallday3'>
1217 <input type='text' size='2' name='form_hour' value='<?php echo $starttimeh ?>'
1218 title='<?php xl('Event start time','e'); ?>' /> :
1219 <input type='text' size='2' name='form_minute' value='<?php echo $starttimem ?>'
1220 title='<?php xl('Event start time','e'); ?>' />&nbsp;
1221 <select name='form_ampm' title='Note: 12:00 noon is PM, not AM'>
1222 <option value='1'><?php xl('AM','e'); ?></option>
1223 <option value='2'<?php if ($startampm == '2') echo " selected" ?>><?php xl('PM','e'); ?></option>
1224 </select>
1225 </td>
1226 </tr>
1227 <tr>
1228 <td nowrap>
1229 <b><?php xl('Title','e'); ?>:</b>
1230 </td>
1231 <td nowrap>
1232 <input type='text' size='10' name='form_title' value='<?php echo htmlspecialchars($row['pc_title'], ENT_QUOTES); ?>'
1233 style='width:100%'
1234 title='<?php xl('Event title','e'); ?>' />
1235 </td>
1236 <td nowrap>
1237 &nbsp;
1238 </td>
1239 <td nowrap id='tdallday4'><?php xl('duration','e'); ?>
1240 </td>
1241 <td nowrap id='tdallday5'>
1242 <input type='text' size='4' name='form_duration' value='<?php echo $thisduration ?>' title='<?php xl('Event duration in minutes','e'); ?>' />
1243 <?php xl('minutes','e'); ?>
1244 </td>
1245 </tr>
1247 <?php
1248 // =============================================
1249 // DBC DUTCH SYSTEMS
1250 // minutes issue
1251 if ( $GLOBALS['dutchpc'] ) { ?>
1252 <tr>
1253 <td colspan="3">&nbsp;</td>
1254 <td>indirect</td>
1255 <td><input type='text' name='form_duration_indirect' id='form_duration_indirect' size='4'
1256 value='<?php if ( isset($timerow['indirect_time']) ) echo $timerow['indirect_time']; ?>'/>minutes</td>
1257 </tr>
1258 <tr>
1259 <td colspan="3">&nbsp;</td>
1260 <td>travel</td>
1261 <td><input type='text' name='form_duration_travel' name='form_duration_travel' size='4'
1262 value='<?php if ( isset($timerow['travel_time']) ) echo $timerow['travel_time']; ?>'/>minutes</td>
1263 </tr>
1264 <?php
1265 // =======================================================
1266 // DBC DUTCH SYSTEM
1267 // cascading dropdowns
1268 // =======================================================
1269 if ( $GLOBALS['dutchpc'] ) {
1270 if ( $eid ) { // editing mode
1271 $activ = what_activity( $singleeid );
1273 if ( empty($activ) ) {
1274 $activ = "No activity selected.";
1275 } else {
1276 $activ = what_full_sysid($activ);
1277 $_SESSION['editactiv'] = FALSE;
1281 // end DBC DUTCH SYSTEM
1283 <tr>
1284 <td><b>Current activity:</b><br /><a href="#" id="addc">&lt;&lt;Add/Change&gt;&gt;</a></td>
1285 <td><?=$activ?><br /> <td colspan="3">&nbsp;</td></td>
1286 </tr>
1287 <tr>
1288 <td nowrap><b>Activiteit:</b></td>
1289 <td width='1%' nowrap>
1290 <select name="box1" id="box1">
1291 <?php
1292 $rlvone = records_level1('ev');
1293 foreach ($rlvone as $rlv) {
1294 echo '<option value=\'' .$rlv['cl_activiteit_code']. '\'>' .$rlv['cl_activiteit_element']. '</option>';
1295 } ?>
1296 </select>
1297 </td>
1298 <td colspan="3"><?php if ( $patientid ) $are = has_ztndbc($patientid); else $are = ' '; ?>
1299 <p style="background-color: #78AEBC; padding: 3px; text-align: center"><?=$are['str']?></p>
1300 </td>
1301 </tr>
1303 <tr colspan="2"><td></td><td>
1304 <select id="box2" name="box2">
1305 </select></td></tr>
1307 <tr colspan="2"><td></td><td>
1308 <select id="box3" name="box3"></select>
1309 </td></tr>
1311 <tr colspan="2"><td></td><td>
1312 <select id="box4" name="box4"></select>
1313 </td></tr>
1315 <tr colspan="2"><td></td><td>
1316 <select id="box5" name="box5"></select>
1317 </td></tr>
1319 <?php } ?>
1321 <tr>
1322 <td nowrap><b><?php xl('Facility','e'); ?>:</b></td>
1323 <td>
1324 <?php /*{CHEMED}*/
1325 if ($userid != 0) { ?>
1326 <input type='hidden' name="facility" id="facility" value='<?php echo $e2f; ?>'/>
1327 <input type='input' readonly name="facility_txt" value='<?php echo $e2f_name; ?>'/>
1328 <?php } else {?>
1329 <select name="facility" id="facility" >
1330 <?php
1332 // ===========================
1333 // EVENTS TO FACILITIES
1334 //(CHEMED) added service_location WHERE clause
1335 // get the facilities
1336 /***************************************************************
1337 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1338 ***************************************************************/
1339 $facils = getUserFacilities($_SESSION['authId']);
1340 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1341 /**************************************************************/
1342 while ($facrow = sqlFetchArray($qsql)) {
1343 /*************************************************************
1344 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1345 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1346 *************************************************************/
1347 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1348 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1349 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1351 /************************************************************/
1353 // EOS E2F
1354 // ===========================
1356 <?php }
1357 //END (CHEMED) IF ?>
1358 </td>
1359 </select>
1360 </tr>
1362 <tr>
1363 <td nowrap>
1364 <b><?php xl('Patient','e'); ?>:</b>
1365 </td>
1366 <td nowrap>
1367 <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 />
1368 <input type='hidden' name='form_pid' value='<?php echo $patientid ?>' />
1369 </td>
1370 <td colspan='3' nowrap style='font-size:8pt'>
1371 &nbsp;
1372 <span class="infobox">
1373 <?php if ($patienttitle != "") { echo $patienttitle; } ?>
1374 </span>
1375 </td>
1376 </tr>
1378 <tr>
1379 <td nowrap>
1380 <b><?php xl('Provider','e'); ?>:</b>
1381 </td>
1382 <td nowrap>
1384 <?php
1386 // =======================================
1387 // multi providers
1388 // =======================================
1389 if ($GLOBALS['select_multi_providers']) {
1391 // there are two posible situations: edit and new record
1393 // this is executed only on edit ($eid)
1394 if ($eid) {
1395 if ( $multiple_value ) {
1396 // find all the providers around multiple key
1397 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = $multiple_value");
1398 while ($r = sqlFetchArray($qall)) {
1399 $providers_array[] = $r['providers'];
1401 } else {
1402 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1403 $providers_array = sqlFetchArray($qall);
1407 // build the selection tool
1408 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1410 while ($urow = sqlFetchArray($ures)) {
1411 echo " <option value='" . $urow['id'] . "'";
1413 if ($userid) {
1414 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1417 echo ">" . $urow['lname'];
1418 if ($urow['fname']) echo ", " . $urow['fname'];
1419 echo "</option>\n";
1422 echo '</select>';
1424 // =======================================
1425 // single provider
1426 // =======================================
1427 } else {
1429 if ($eid) {
1430 // get provider from existing event
1431 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1432 $provider = sqlFetchArray($qprov);
1433 $defaultProvider = $provider['pc_aid'];
1435 else {
1436 // this is a new event so smartly choose a default provider
1437 /*****************************************************************
1438 if ($userid) {
1439 // Provider already given to us as a GET parameter.
1440 $defaultProvider = $userid;
1442 else {
1443 // default to the currently logged-in user
1444 $defaultProvider = $_SESSION['authUserID'];
1445 // or, if we have chosen a provider in the calendar, default to them
1446 // choose the first one if multiple have been selected
1447 if (count($_SESSION['pc_username']) >= 1) {
1448 // get the numeric ID of the first provider in the array
1449 $pc_username = $_SESSION['pc_username'];
1450 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1451 $defaultProvider = $firstProvider['id'];
1456 echo "<select name='form_provider' style='width:100%' />";
1457 while ($urow = sqlFetchArray($ures)) {
1458 echo " <option value='" . $urow['id'] . "'";
1459 if ($urow['id'] == $defaultProvider) echo " selected";
1460 echo ">" . $urow['lname'];
1461 if ($urow['fname']) echo ", " . $urow['fname'];
1462 echo "</option>\n";
1464 echo "</select>";
1465 *****************************************************************/
1466 // default to the currently logged-in user
1467 $defaultProvider = $_SESSION['authUserID'];
1468 // or, if we have chosen a provider in the calendar, default to them
1469 // choose the first one if multiple have been selected
1470 if (count($_SESSION['pc_username']) >= 1) {
1471 // get the numeric ID of the first provider in the array
1472 $pc_username = $_SESSION['pc_username'];
1473 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1474 $defaultProvider = $firstProvider['id'];
1476 // if we clicked on a provider's schedule to add the event, use THAT.
1477 if ($userid) $defaultProvider = $userid;
1479 echo "<select name='form_provider' style='width:100%' />";
1480 while ($urow = sqlFetchArray($ures)) {
1481 echo " <option value='" . $urow['id'] . "'";
1482 if ($urow['id'] == $defaultProvider) echo " selected";
1483 echo ">" . $urow['lname'];
1484 if ($urow['fname']) echo ", " . $urow['fname'];
1485 echo "</option>\n";
1487 echo "</select>";
1488 /****************************************************************/
1493 </td>
1494 <td nowrap>
1495 &nbsp;&nbsp;
1496 <input type='checkbox' name='form_repeat' onclick='set_repeat(this)' value='1'<?php if ($repeats) echo " checked" ?>/>
1497 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo $repeatexdate; ?>' /> <!-- dates excluded from the repeat -->
1498 </td>
1499 <td nowrap id='tdrepeat1'><?php xl('Repeats','e'); ?>
1500 </td>
1501 <td nowrap>
1503 <select name='form_repeat_freq' title=<?php xl('Every, every other, every 3rd, etc.','e','\'','\''); ?>>
1504 <?php
1505 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1506 as $key => $value)
1508 echo " <option value='$key'";
1509 if ($key == $repeatfreq) echo " selected";
1510 echo ">$value</option>\n";
1513 </select>
1515 <select name='form_repeat_type'>
1516 <?php
1517 // See common.api.php for these:
1518 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'))
1519 as $key => $value)
1521 echo " <option value='$key'";
1522 if ($key == $repeattype) echo " selected";
1523 echo ">$value</option>\n";
1526 </select>
1528 </td>
1529 </tr>
1531 <tr>
1532 <td nowrap>
1533 <span id='title_apptstatus'><b><?php xl('Status','e'); ?>:</b></span>
1534 <span id='title_prefcat' style='display:none'><b><?php xl('Pref Cat','e'); ?>:</b></span>
1535 </td>
1536 <td nowrap>
1538 <select name='form_apptstatus' style='width:100%' title='<?php xl('Appointment status','e'); ?>'>
1539 <?php
1540 foreach ($statuses as $key => $value) {
1541 echo " <option value='$key'";
1542 if ($key == $row['pc_apptstatus']) echo " selected";
1543 echo ">" . htmlspecialchars($value) . "</option>\n";
1546 </select>
1547 <!--
1548 The following list will be invisible unless this is an In Office
1549 event, in which case form_apptstatus (above) is to be invisible.
1551 <select name='form_prefcat' style='width:100%;display:none' title='<?php xl('Preferred Event Category','e');?>'>
1552 <?php echo $prefcat_options ?>
1553 </select>
1555 </td>
1556 <td nowrap>
1557 &nbsp;
1558 </td>
1559 <td nowrap id='tdrepeat2'><?php xl('until','e'); ?>
1560 </td>
1561 <td nowrap>
1562 <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');?>' />
1563 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1564 id='img_enddate' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1565 title='<?php xl('Click here to choose a date','e');?>'>
1566 <?php
1567 if ($repeatexdate != "") {
1568 $tmptitle = "The following dates are excluded from the repeating series";
1569 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1570 else { $tmptitle .= "\n"; }
1571 $exdates = explode(",", $repeatexdate);
1572 foreach ($exdates as $exdate) {
1573 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1575 echo "<a href='#' title='$tmptitle' alt='$tmptitle'><img src='../../pic/warning.gif' title='$tmptitle' alt='*!*' style='border:none;'/></a>";
1578 </td>
1579 </tr>
1581 <tr>
1582 <td nowrap>
1583 <b><?php xl('Comments','e'); ?>:</b>
1584 </td>
1585 <td colspan='4' nowrap>
1586 <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');?>' />
1587 </td>
1588 </tr>
1590 <?php
1591 // DOB is important for the clinic, so if it's missing give them a chance
1592 // to enter it right here. We must display or hide this row dynamically
1593 // in case the patient-select popup is used.
1594 $patient_dob = trim($prow['DOB']);
1595 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00')) ?
1596 '' : 'none';
1598 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1599 <td colspan='4' nowrap>
1600 <b><font color='red'><?php xl('DOB is missing, please enter if possible','e'); ?>:</font></b>
1601 </td>
1602 <td nowrap>
1603 <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)' />
1604 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1605 id='img_dob' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1606 title='<?php xl('Click here to choose a date','e');?>'>
1607 </td>
1608 </tr>
1610 </table>
1613 <input type='button' name='form_save' id='form_save' value='<?php xl('Save','e');?>' />
1614 &nbsp;
1615 <input type='button' id='find_available' value='<?php xl('Find Available','e');?>' />
1616 &nbsp;
1617 <input type='button' name='form_delete' id='form_delete' value='<?php xl('Delete','e');?>'<?php if (!$eid) echo " disabled" ?> />
1618 &nbsp;
1619 <input type='button' id='cancel' value='<?php xl('Cancel','e');?>' />
1620 </p>
1621 <?php if ($informant) echo "<p class='text'>" . xl('Last update by') . " $informant</p>\n"; ?>
1622 </center>
1623 </form>
1625 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1626 Apply the changes to the Current event only, to this and all Future occurrences, or to All occurances?
1627 <br>
1628 <input type="button" name="all_events" id="all_events" value=" All ">
1629 <input type="button" name="future_events" id="future_events" value="Future">
1630 <input type="button" name="current_event" id="current_event" value="Current">
1631 <input type="button" name="recurr_cancel" id="recurr_cancel" value="Cancel">
1632 </div>
1634 </body>
1636 <script language='JavaScript'>
1637 <?php if ($eid) { ?>
1638 set_display();
1639 <?php } else { ?>
1640 set_category();
1641 <?php } ?>
1642 set_allday();
1643 set_repeat();
1645 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
1646 Calendar.setup({inputField:"form_enddate", ifFormat:"%Y-%m-%d", button:"img_enddate"});
1647 Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});
1648 </script>
1650 <script language="javascript">
1651 // jQuery stuff to make the page a little easier to use
1653 $(document).ready(function(){
1654 $("#form_save").click(function() { validate(); });
1655 $("#find_available").click(function() { find_available(); });
1656 $("#form_delete").click(function() { deleteEvent(); });
1657 $("#cancel").click(function() { window.close(); });
1659 // buttons affecting the modification of a repeating event
1660 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1661 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1662 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1663 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1666 // Check for errors when the form is submitted.
1667 function validate() {
1668 var f = document.getElementById('theform');
1669 if (f.form_repeat.checked &&
1670 (! f.form_enddate.value || f.form_enddate.value < f.form_date.value)) {
1671 alert('An end date later than the start date is required for repeated events!');
1672 return false;
1674 $('#form_action').val("save");
1676 <?php if ($repeats): ?>
1677 // existing repeating events need additional prompt
1678 if ($("#recurr_affect").val() == "") {
1679 DisableForm();
1680 // show the current/future/all DIV for the user to choose one
1681 $("#recurr_popup").css("visibility", "visible");
1682 return false;
1684 <?php endif; ?>
1686 return SubmitForm();
1689 // disable all the form elements outside the recurr_popup
1690 function DisableForm() {
1691 $("#theform").children().attr("disabled", "true");
1693 function EnableForm() {
1694 $("#theform").children().removeAttr("disabled");
1696 // hide the recurring popup DIV
1697 function HideRecurrPopup() {
1698 $("#recurr_popup").css("visibility", "hidden");
1701 function deleteEvent() {
1702 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?")) {
1703 $('#form_action').val("delete");
1705 <?php if ($repeats): ?>
1706 // existing repeating events need additional prompt
1707 if ($("#recurr_affect").val() == "") {
1708 DisableForm();
1709 // show the current/future/all DIV for the user to choose one
1710 $("#recurr_popup").css("visibility", "visible");
1711 return false;
1713 <?php endif; ?>
1715 return SubmitForm();
1717 return false;
1720 function SubmitForm() {
1721 // DBC Dutch System validation
1722 <?php if ( $GLOBALS['dutchpc'] && $_SESSION['editactiv']) { ?>
1723 var a = verify_selecteerbaar();
1724 if ( !a ) return false;
1725 <?php } ?>
1726 // DBC EOS
1728 $('#theform').submit();
1729 top.restoreSession();
1730 return true;
1733 </script>
1735 </html>