bug fix to include getUserFacilities function
[openemr.git] / interface / main / calendar / add_edit_event.php
blob07662a98d864fff56d273d08c71360981e5aa0c2
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");
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';
35 if ($date)
36 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
37 else
38 $date = date("Y-m-d");
40 $starttimem = '00';
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)
48 $starttimeh += 12;
50 } else {
51 $starttimeh = date("G");
53 $startampm = '';
55 $info_msg = "";
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>
65 <?php
67 // insert an event
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 " .
75 ") VALUES ( " .
76 "'" . $args['form_category'] . "', " .
77 "'" . $args['new_multiple_value'] . "', " .
78 "'" . $args['form_provider'] . "', " .
79 "'" . $args['form_pid'] . "', " .
80 "'" . $args['form_title'] . "', " .
81 "NOW(), " .
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'] ."', " .
95 "1, " .
96 "1, " .(int)$args['facility']. " )"
100 // =====================================
101 // DBC Dutch System
102 // ACTIVITIES / TIMES
103 if ( $GLOBALS['dutchpc'] ) {
104 if ( $eid ) {
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 // ------------------------------------------
130 } else {
131 // ------------------------------------------
132 // single providers case
133 $timerow = sqlQuery("SELECT * FROM cl_time_activiteit WHERE event_id = $eid");
134 $singleeid = $eid;
135 // ------------------------------------------
137 } // if ($eid)
138 } // if (dutchpc)
140 // EVENTS TO FACILITIES (lemonsoftware)
141 //(CHEMED) get facility name
142 // edit event case - if there is no association made, then insert one with the first facility
143 if ( $eid ) {
144 $selfacil = '';
145 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
146 FROM openemr_postcalendar_events
147 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
148 WHERE pc_eid = $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");
160 // EOS multiple
162 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
163 $e2f = $min;
164 $e2f_name = $min_name;
165 } else {
166 // not edit event
167 if (!$facility['pc_facility'] && ($_SESSION['pc_facility'] || $_COOKIE['pc_facility'])) {
168 $e2f = $_SESSION['pc_facility'] ? $_SESSION['pc_facility'] : $_COOKIE['pc_facility'];
169 } else {
170 $e2f = $facility['pc_facility'];
171 $e2f_name = $facility['name'];
175 // EOS E2F
176 // ===========================
179 // If we are saving, then save and close the window.
181 if ($_POST['form_action'] == "save") {
183 // ========================================
184 // DBC SYSTEM
185 // check if for activity act_3.2 we have times completed
186 // larry :: fix dbc
187 if ( $GLOBALS['dutchpc'] ) {
188 $sa = selected_ac();
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']) {
202 $tmph = 0;
203 $tmpm = 0;
204 $duration = 24 * 60;
205 } else {
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";
213 $tmpm += $duration;
214 while ($tmpm >= 60) {
215 $tmpm -= 60;
216 ++$tmph;
218 $endtime = "$tmph:$tmpm:00";
220 // Useless garbage that we must save.
221 $locationspecs = array("event_location" => "",
222 "event_street1" => "",
223 "event_street2" => "",
224 "event_city" => "",
225 "event_state" => "",
226 "event_postal" => ""
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",
245 "exdate" => ""
248 /* =======================================================
249 * UPDATE EVENTS
250 * =====================================================*/
251 if ($eid) {
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 ????
257 $activ = "";
258 if ( $GLOBALS['dutchpc'] ) {
259 if ( $_SESSION['editactiv'] ) { $activ = selected_ac(); }
260 else { $activ = what_activity($eid); }
262 // eof DBC
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
304 $args = $_POST;
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;
317 InsertEvent($args);
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
341 $args = $_POST;
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;
351 InsertEvent($args);
355 else {
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);
363 if (count ($r1)) {
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
371 // oct-08 JRM
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);
380 if (count ($r2)) {
381 foreach ($r2 as $to_be_inserted) {
382 $args = $_POST;
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;
392 InsertEvent($args);
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']}");
418 } // foreach
422 // ====================================
423 // single provider
424 // ====================================
425 } elseif ( !$row['pc_multiple'] ) {
426 if ( $GLOBALS['select_multi_providers'] ) {
427 $prov = $_POST['form_provider'][0];
428 } else {
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
446 $args = $_POST;
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;
457 InsertEvent($args);
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
467 $args = $_POST;
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;
475 InsertEvent($args);
477 else {
479 // perform a check to see if user changed event date
480 // this is important when editing an existing recurring event
481 // oct-08 JRM
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!
524 } else {
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;
532 } else {
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
548 $e2f = (int)$eid;
551 } else {
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) {
567 $args = $_POST;
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;
577 InsertEvent($args);
580 // ====================================
581 // single provider
582 // ====================================
583 } else {
584 $args = $_POST;
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;
593 InsertEvent($args);
596 // ==============================================
597 // DBC Dutch System (insert case)
598 $lid = mysql_insert_id($GLOBALS['dbh']); // obtain last inserted id
600 // larry :: fix dbc
601 if ( $GLOBALS['dutchpc'] ) {
602 $ac = selected_ac();
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;
609 } else {
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 // ==============================================
618 // new ZTN ?
619 $pid1007 = ( $_POST['form_pid'] ) ? $_POST['form_pid'] : $pid;
620 if ( $pid1007 ) {
621 $a = generate_id1007($pid1007, $event_date); //var_dump($a); exit();
624 // end DBC
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 // =======================================
674 // DELETE EVENT(s)
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);
722 else {
723 // really delete the event from the database
724 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
728 // =======================================
729 // single provider event
730 // =======================================
731 else {
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'");
755 else {
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";
769 exit();
772 //*********************************
773 // If we get this far then we are displaying the form.
774 //*********************************
776 $statuses = array(
777 '-' => '',
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
793 $repeattype = '0';
794 $repeatfreq = '0';
795 $patientid = '';
796 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
797 $patientname = xl('Click to select');
798 $patienttitle = "";
799 $hometext = "";
800 $row = array();
801 $informant = "";
803 // If we are editing an existing event, then get its data.
804 if ($eid) {
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);
833 else {
834 // a NEW event
835 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
837 //-------------------------------------
838 //(CHEMED)
839 //Set default facility for a new event based on the given 'userid'
840 if ($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,
847 f.name as facility
848 FROM facility f
849 WHERE f.id = %d
851 $_SESSION['pc_facility']
852 )));
853 } else {
854 $pref_facility = sqlFetchArray(sqlStatement("
855 SELECT u.facility_id,
856 f.name as facility
857 FROM users u
858 LEFT JOIN facility f on (u.facility_id = f.id)
859 WHERE u.id = $userid
860 "));
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.
870 if ($patientid) {
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.
887 $startampm = '1';
888 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
889 $startampm = '2';
890 if ($starttimeh > 12) $starttimeh -= 12;
894 <html>
895 <head>
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'>
900 <style>
901 td { font-size:0.8em; }
902 </style>
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>
912 <?php
913 // ============================================================================
914 // DBC SYSTEM JAVASCRIPT FILE
916 if ( $GLOBALS['dutchpc'] ) { ?>
917 <script type="text/javascript" src="../../../library/js/add_edit_event.js"></script>
919 <?php }
920 // ============================================================================
923 <script language="JavaScript">
925 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
927 var durations = new Array();
928 // var rectypes = new Array();
929 <?php
930 // Read the event categories, generate their options list, and get
931 // the default event duration from them if this is a new event.
932 $catoptions = "";
933 $prefcat_options = " <option value='0'>-- None --</option>\n";
934 $thisduration = 0;
935 if ($eid) {
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'] . "'";
944 if ($eid) {
945 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
946 } else {
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:
955 if ($duration) {
956 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
957 if ($eid) {
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 = '';
996 } else {
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];
1014 set_display();
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) {
1026 color1 = '#000000';
1028 if (document.getElementById('rballday2').checked) {
1029 color2 = '#000000';
1030 disabled2 = false;
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) {
1050 isdisabled = false;
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;
1081 <?php } else {?>
1082 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1083 <?php }?>
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 // ==============================
1094 // DBC BOS
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({
1106 url: "<?=$link?>",
1107 type: 'POST',
1108 data: 'vcode='+a,
1109 async: false
1110 }).responseText;
1111 if ( answer == 'false') { alert("Please select again"); return false; }
1112 else return true;
1114 // EOS DBC
1116 </script>
1118 <?php
1119 if ( $GLOBALS['dutchpc'])
1120 { ?>
1122 <script type="text/javascript">
1123 boxes();
1125 <?php
1126 if ( $eid ) { // editing case
1128 editcase();
1129 <?php
1130 } // EOS editing case
1133 </script>
1135 <?php
1136 } // EOS DBC DUTCH AJAX PART
1139 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1141 </head>
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; ?>">
1151 <center>
1153 <table border='0' width='100%'>
1155 <tr>
1156 <td width='1%' nowrap>
1157 <b><?php xl('Category','e'); ?>:</b>
1158 </td>
1159 <td nowrap>
1160 <select name='form_category' onchange='set_category()' style='width:100%'>
1161 <?php echo $catoptions ?>
1162 </select>
1163 </td>
1164 <td width='1%' nowrap>
1165 &nbsp;&nbsp;
1166 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1167 <?php if ($thisduration == 1440) echo "checked " ?>/>
1168 </td>
1169 <td colspan='2' nowrap id='tdallday1'>
1170 <?php xl('All day event','e'); ?>
1171 </td>
1172 </tr>
1174 <tr>
1175 <td nowrap>
1176 <b><?php xl('Date','e'); ?>:</b>
1177 </td>
1178 <td nowrap>
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'); ?>'>
1186 </td>
1187 <td nowrap>
1188 &nbsp;&nbsp;
1189 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1190 </td>
1191 <td width='1%' nowrap id='tdallday2'>
1192 <?php xl('Time','e'); ?>
1193 </td>
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'); ?>' />&nbsp;
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>
1202 </select>
1203 </td>
1204 </tr>
1205 <tr>
1206 <td nowrap>
1207 <b><?php xl('Title','e'); ?>:</b>
1208 </td>
1209 <td nowrap>
1210 <input type='text' size='10' name='form_title' value='<?php echo addslashes($row['pc_title']) ?>'
1211 style='width:100%'
1212 title='<?php xl('Event title','e'); ?>' />
1213 </td>
1214 <td nowrap>
1215 &nbsp;
1216 </td>
1217 <td nowrap id='tdallday4'><?php xl('duration','e'); ?>
1218 </td>
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'); ?>
1222 </td>
1223 </tr>
1225 <?php
1226 // =============================================
1227 // DBC DUTCH SYSTEMS
1228 // minutes issue
1229 if ( $GLOBALS['dutchpc'] ) { ?>
1230 <tr>
1231 <td colspan="3">&nbsp;</td>
1232 <td>indirect</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>
1235 </tr>
1236 <tr>
1237 <td colspan="3">&nbsp;</td>
1238 <td>travel</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>
1241 </tr>
1242 <?php
1243 // =======================================================
1244 // DBC DUTCH SYSTEM
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.";
1253 } else {
1254 $activ = what_full_sysid($activ);
1255 $_SESSION['editactiv'] = FALSE;
1259 // end DBC DUTCH SYSTEM
1261 <tr>
1262 <td><b>Current activity:</b><br /><a href="#" id="addc">&lt;&lt;Add/Change&gt;&gt;</a></td>
1263 <td><?=$activ?><br /> <td colspan="3">&nbsp;</td></td>
1264 </tr>
1265 <tr>
1266 <td nowrap><b>Activiteit:</b></td>
1267 <td width='1%' nowrap>
1268 <select name="box1" id="box1">
1269 <?php
1270 $rlvone = records_level1('ev');
1271 foreach ($rlvone as $rlv) {
1272 echo '<option value=\'' .$rlv['cl_activiteit_code']. '\'>' .$rlv['cl_activiteit_element']. '</option>';
1273 } ?>
1274 </select>
1275 </td>
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>
1278 </td>
1279 </tr>
1281 <tr colspan="2"><td></td><td>
1282 <select id="box2" name="box2">
1283 </select></td></tr>
1285 <tr colspan="2"><td></td><td>
1286 <select id="box3" name="box3"></select>
1287 </td></tr>
1289 <tr colspan="2"><td></td><td>
1290 <select id="box4" name="box4"></select>
1291 </td></tr>
1293 <tr colspan="2"><td></td><td>
1294 <select id="box5" name="box5"></select>
1295 </td></tr>
1297 <?php } ?>
1299 <tr>
1300 <td nowrap><b><?php xl('Facility','e'); ?>:</b></td>
1301 <td>
1302 <?php /*{CHEMED}*/
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; ?>'/>
1306 <?php } else {?>
1307 <select name="facility" id="facility" >
1308 <?php
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 /************************************************************/
1331 // EOS E2F
1332 // ===========================
1334 <?php }
1335 //END (CHEMED) IF ?>
1336 </td>
1337 </select>
1338 </tr>
1340 <tr>
1341 <td nowrap>
1342 <b><?php xl('Patient','e'); ?>:</b>
1343 </td>
1344 <td nowrap>
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 ?>' />
1347 </td>
1348 <td colspan='3' nowrap style='font-size:8pt'>
1349 &nbsp;
1350 <span class="infobox">
1351 <?php if ($patienttitle != "") { echo $patienttitle; } ?>
1352 </span>
1353 </td>
1354 </tr>
1356 <tr>
1357 <td nowrap>
1358 <b><?php xl('Provider','e'); ?>:</b>
1359 </td>
1360 <td nowrap>
1362 <?php
1364 // =======================================
1365 // multi providers
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)
1372 if ($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'];
1379 } else {
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'] . "'";
1391 if ($userid) {
1392 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1395 echo ">" . $urow['lname'];
1396 if ($urow['fname']) echo ", " . $urow['fname'];
1397 echo "</option>\n";
1400 echo '</select>';
1402 // =======================================
1403 // single provider
1404 // =======================================
1405 } else {
1407 if ($eid) {
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'];
1413 else {
1414 // this is a new event so smartly choose a default provider
1415 /*****************************************************************
1416 if ($userid) {
1417 // Provider already given to us as a GET parameter.
1418 $defaultProvider = $userid;
1420 else {
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'];
1440 echo "</option>\n";
1442 echo "</select>";
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'];
1463 echo "</option>\n";
1465 echo "</select>";
1466 /****************************************************************/
1471 </td>
1472 <td nowrap>
1473 &nbsp;&nbsp;
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 -->
1476 </td>
1477 <td nowrap id='tdrepeat1'><?php xl('Repeats','e'); ?>
1478 </td>
1479 <td nowrap>
1481 <select name='form_repeat_freq' title=<?php xl('Every, every other, every 3rd, etc.','e','\'','\''); ?>>
1482 <?php
1483 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1484 as $key => $value)
1486 echo " <option value='$key'";
1487 if ($key == $repeatfreq) echo " selected";
1488 echo ">$value</option>\n";
1491 </select>
1493 <select name='form_repeat_type'>
1494 <?php
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'))
1497 as $key => $value)
1499 echo " <option value='$key'";
1500 if ($key == $repeattype) echo " selected";
1501 echo ">$value</option>\n";
1504 </select>
1506 </td>
1507 </tr>
1509 <tr>
1510 <td nowrap>
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>
1513 </td>
1514 <td nowrap>
1516 <select name='form_apptstatus' style='width:100%' title='<?php xl('Appointment status','e'); ?>'>
1517 <?php
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";
1524 </select>
1525 <!--
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 ?>
1531 </select>
1533 </td>
1534 <td nowrap>
1535 &nbsp;
1536 </td>
1537 <td nowrap id='tdrepeat2'><?php xl('until','e'); ?>
1538 </td>
1539 <td nowrap>
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');?>'>
1544 <?php
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>";
1556 </td>
1557 </tr>
1559 <tr>
1560 <td nowrap>
1561 <b><?php xl('Comments','e'); ?>:</b>
1562 </td>
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');?>' />
1565 </td>
1566 </tr>
1568 <?php
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')) ?
1574 '' : 'none';
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>
1579 </td>
1580 <td nowrap>
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');?>'>
1585 </td>
1586 </tr>
1588 </table>
1591 <input type='button' name='form_save' id='form_save' value='<?php xl('Save','e');?>' />
1592 &nbsp;
1593 <input type='button' id='find_available' value='<?php xl('Find Available','e');?>' />
1594 &nbsp;
1595 <input type='button' name='form_delete' id='form_delete' value='<?php xl('Delete','e');?>'<?php if (!$eid) echo " disabled" ?> />
1596 &nbsp;
1597 <input type='button' id='cancel' value='<?php xl('Cancel','e');?>' />
1598 </p>
1599 <?php if ($informant) echo "<p class='text'>" . xl('Last update by') . " $informant</p>\n"; ?>
1600 </center>
1601 </form>
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?
1605 <br>
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">
1610 </div>
1612 </body>
1614 <script language='JavaScript'>
1615 <?php if ($eid) { ?>
1616 set_display();
1617 <?php } else { ?>
1618 set_category();
1619 <?php } ?>
1620 set_allday();
1621 set_repeat();
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"});
1626 </script>
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!');
1650 return false;
1652 $('#form_action').val("save");
1654 <?php if ($repeats): ?>
1655 // existing repeating events need additional prompt
1656 if ($("#recurr_affect").val() == "") {
1657 DisableForm();
1658 // show the current/future/all DIV for the user to choose one
1659 $("#recurr_popup").css("visibility", "visible");
1660 return false;
1662 <?php endif; ?>
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() == "") {
1686 DisableForm();
1687 // show the current/future/all DIV for the user to choose one
1688 $("#recurr_popup").css("visibility", "visible");
1689 return false;
1691 <?php endif; ?>
1693 return SubmitForm();
1695 return false;
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;
1703 <?php } ?>
1704 // DBC EOS
1706 $('#theform').submit();
1707 top.restoreSession();
1708 return true;
1711 </script>
1713 </html>