separating facility from user maintenance, improved support for multiple facilities...
[openemr.git] / interface / main / calendar / add_edit_event.php
blob02e7eccc6bb1a5f559ea5b1d9a1a1ce50c8b90f3
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");
27 // Things that might be passed by our opener.
29 $eid = $_GET['eid']; // only for existing events
30 $date = $_GET['date']; // this and below only for new events
31 $userid = $_GET['userid'];
32 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
34 if ($date)
35 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
36 else
37 $date = date("Y-m-d");
39 $starttimem = '00';
40 if (isset($_GET['starttimem']))
41 $starttimem = substr('00' . $_GET['starttimem'], -2);
43 if (isset($_GET['starttimeh'])) {
44 $starttimeh = $_GET['starttimeh'];
45 if (isset($_GET['startampm'])) {
46 if ($_GET['startampm'] == '2' && $starttimeh < 12)
47 $starttimeh += 12;
49 } else {
50 $starttimeh = date("G");
52 $startampm = '';
54 $info_msg = "";
56 // used for DBC Dutch System
57 $_SESSION['event_date'] = $date;
58 $link = '../../../library/DBC_functions.php'; // ajax stuff and db work
62 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
64 <?php
66 // insert an event
67 // $args is mainly filled with content from the POST http var
68 function InsertEvent($args) {
69 return sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
70 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
71 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
72 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
73 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
74 ") VALUES ( " .
75 "'" . $args['form_category'] . "', " .
76 "'" . $args['new_multiple_value'] . "', " .
77 "'" . $args['form_provider'] . "', " .
78 "'" . $args['form_pid'] . "', " .
79 "'" . $args['form_title'] . "', " .
80 "NOW(), " .
81 "'" . $args['form_comments'] . "', " .
82 "'" . $_SESSION['authUserID'] . "', " .
83 "'" . $args['event_date'] . "', " .
84 "'" . fixDate($args['form_enddate']) . "', " .
85 "'" . $args['duration'] . "', " .
86 "'" . ($args['form_repeat'] ? '1' : '0') . "', " .
87 "'" . serialize($args['recurrspec']) . "', " .
88 "'" . $args['starttime'] ."', " .
89 "'" . $args['endtime'] ."', " .
90 "'" . $args['form_allday'] . "', " .
91 "'" . $args['form_apptstatus'] . "', " .
92 "'" . $args['form_prefcat'] . "', " .
93 "'" . $args['locationspec'] ."', " .
94 "1, " .
95 "1, " .(int)$args['facility']. " )"
99 // =====================================
100 // DBC Dutch System
101 // ACTIVITIES / TIMES
102 if ( $GLOBALS['dutchpc'] ) {
103 if ( $eid ) {
104 if ( $GLOBALS['select_multi_providers'] ) {
105 // ------------------------------------------
106 // what is multiple key around this $eid?
107 $rowmulti = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
109 // what are all pc_eid's grouped by multiple key
110 $eventsrow = array();
111 $rezev = mysql_query("SELECT pc_eid FROM openemr_postcalendar_events WHERE pc_multiple = {$rowmulti['pc_multiple']}");
112 while ( $row = mysql_fetch_array($rezev) ) {
113 $eventsrow[] = $row['pc_eid'];
116 // we look in cl_event_activiteit / cl_time_activiteit for a matching record
117 foreach ( $eventsrow as $ev) {
118 $activ = sqlQuery("SELECT * FROM cl_event_activiteit WHERE event_id = $ev");
119 if ( $activ['event_id'] ) $singleeid = $activ['event_id'];
121 $time = sqlQuery("SELECT * FROM cl_time_activiteit WHERE event_id = $ev");
122 if ( $time ) $timerow = $time;
125 // prevent blank values for $singleeid
126 if ( !$singleeid) $singleeid = $eid;
128 // ------------------------------------------
129 } else {
130 // ------------------------------------------
131 // single providers case
132 $timerow = sqlQuery("SELECT * FROM cl_time_activiteit WHERE event_id = $eid");
133 $singleeid = $eid;
134 // ------------------------------------------
136 } // if ($eid)
137 } // if (dutchpc)
139 // EVENTS TO FACILITIES (lemonsoftware)
140 //(CHEMED) get facility name
141 // edit event case - if there is no association made, then insert one with the first facility
142 if ( $eid ) {
143 $selfacil = '';
144 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
145 FROM openemr_postcalendar_events
146 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
147 WHERE pc_eid = $eid");
148 // if ( !$facility['pc_facility'] ) {
149 if ( is_array($facility) && !$facility['pc_facility'] ) {
150 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
151 $min = $qmin['minId'];
152 $min_name = $qmin['facility'];
154 // multiple providers case
155 if ( $GLOBALS['select_multi_providers'] ) {
156 $mul = $facility['pc_multiple'];
157 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
159 // EOS multiple
161 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
162 $e2f = $min;
163 $e2f_name = $min_name;
164 } else {
165 // not edit event
166 if (!$facility['pc_facility'] && ($_SESSION['pc_facility'] || $_COOKIE['pc_facility'])) {
167 $e2f = $_SESSION['pc_facility'] ? $_SESSION['pc_facility'] : $_COOKIE['pc_facility'];
168 } else {
169 $e2f = $facility['pc_facility'];
170 $e2f_name = $facility['name'];
174 // EOS E2F
175 // ===========================
178 // If we are saving, then save and close the window.
180 if ($_POST['form_action'] == "save") {
182 // ========================================
183 // DBC SYSTEM
184 // check if for activity act_3.2 we have times completed
185 // larry :: fix dbc
186 if ( $GLOBALS['dutchpc'] ) {
187 $sa = selected_ac();
188 if ( $sa == 'act_3.2') {
189 $duration = (int)$_POST['form_duration'];
190 if ( empty($duration) ) exit();
193 // ========================================
195 // the starting date of the event, pay attention with this value
196 // when editing recurring events -- JRM Oct-08
197 $event_date = fixDate($_POST['form_date']);
199 // Compute start and end time strings to be saved.
200 if ($_POST['form_allday']) {
201 $tmph = 0;
202 $tmpm = 0;
203 $duration = 24 * 60;
204 } else {
205 $tmph = $_POST['form_hour'] + 0;
206 $tmpm = $_POST['form_minute'] + 0;
207 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
208 $duration = $_POST['form_duration'];
210 $starttime = "$tmph:$tmpm:00";
212 $tmpm += $duration;
213 while ($tmpm >= 60) {
214 $tmpm -= 60;
215 ++$tmph;
217 $endtime = "$tmph:$tmpm:00";
219 // Useless garbage that we must save.
220 $locationspecs = array("event_location" => "",
221 "event_street1" => "",
222 "event_street2" => "",
223 "event_city" => "",
224 "event_state" => "",
225 "event_postal" => ""
227 $locationspec = serialize($locationspecs);
229 // capture the recurring specifications
230 $recurrspec = array("event_repeat_freq" => $_POST['form_repeat_freq'],
231 "event_repeat_freq_type" => $_POST['form_repeat_type'],
232 "event_repeat_on_num" => "1",
233 "event_repeat_on_day" => "0",
234 "event_repeat_on_freq" => "0",
235 "exdate" => $_POST['form_repeat_exdate']
238 // no recurr specs, this is used for adding a new non-recurring event
239 $noRecurrspec = array("event_repeat_freq" => "",
240 "event_repeat_freq_type" => "",
241 "event_repeat_on_num" => "1",
242 "event_repeat_on_day" => "0",
243 "event_repeat_on_freq" => "0",
244 "exdate" => ""
247 /* =======================================================
248 * UPDATE EVENTS
249 * =====================================================*/
250 if ($eid) {
252 // what is multiple key around this $eid?
253 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
255 // timing-activity validation - larry :: DBC ????
256 $activ = "";
257 if ( $GLOBALS['dutchpc'] ) {
258 if ( $_SESSION['editactiv'] ) { $activ = selected_ac(); }
259 else { $activ = what_activity($eid); }
261 // eof DBC
263 // ====================================
264 // multiple providers
265 // ====================================
266 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
268 // obtain current list of providers regarding the multiple key
269 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
270 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
272 // get the new list of providers from the submitted form
273 $providers_new = $_POST['form_provider'];
275 // ===== Only current event of repeating series =====
276 if ($_POST['recurr_affect'] == 'current') {
278 // update all existing event records to exlude the current date
279 foreach ($providers_current as $provider) {
280 // update the provider's original event
281 // get the original event's repeat specs
282 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
283 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
284 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
285 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
286 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
287 else { $oldRecurrspec['exdate'] .= $selected_date; }
289 // mod original event recur specs to exclude this date
290 sqlStatement("UPDATE openemr_postcalendar_events SET " .
291 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
292 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
295 // obtain the next available unique key to group multiple providers around some event
296 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
297 $max = sqlFetchArray($q);
298 $new_multiple_value = $max['max'] + 1;
300 // insert a new event record for each provider selected on the form
301 foreach ($providers_new as $provider) {
302 // insert a new event on this date with POST form data
303 $args = $_POST;
304 // specify some special variables needed for the INSERT
305 $args['new_multiple_value'] = $new_multiple_value;
306 $args['form_provider'] = $provider;
307 $args['event_date'] = $event_date;
308 $args['duration'] = $duration * 60;
309 // this event is forced to NOT REPEAT
310 $args['form_repeat'] = "0";
311 $args['recurrspec'] = $noRecurrspec;
312 $args['form_enddate'] = "0000-00-00";
313 $args['starttime'] = $starttime;
314 $args['endtime'] = $endtime;
315 $args['locationspec'] = $locationspec;
316 InsertEvent($args);
320 // ===== Future Recurring events of a repeating series =====
321 else if ($_POST['recurr_affect'] == 'future') {
322 // update all existing event records to
323 // stop recurring on this date-1
324 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
325 foreach ($providers_current as $provider) {
326 // mod original event recur specs to end on this date
327 sqlStatement("UPDATE openemr_postcalendar_events SET " .
328 " pc_enddate = '" . $selected_date ."' ".
329 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
332 // obtain the next available unique key to group multiple providers around some event
333 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
334 $max = sqlFetchArray($q);
335 $new_multiple_value = $max['max'] + 1;
337 // insert a new event record for each provider selected on the form
338 foreach ($providers_new as $provider) {
339 // insert a new event on this date with POST form data
340 $args = $_POST;
341 // specify some special variables needed for the INSERT
342 $args['new_multiple_value'] = $new_multiple_value;
343 $args['form_provider'] = $provider;
344 $args['event_date'] = $event_date;
345 $args['duration'] = $duration * 60;
346 $args['recurrspec'] = $recurrspec;
347 $args['starttime'] = $starttime;
348 $args['endtime'] = $endtime;
349 $args['locationspec'] = $locationspec;
350 InsertEvent($args);
354 else {
355 /* =================================================================== */
356 // ===== a Single event or All events in a repeating series ==========
357 /* =================================================================== */
359 // this difference means that some providers from current was UNCHECKED
360 // so we must delete this event for them
361 $r1 = array_diff ($providers_current, $providers_new);
362 if (count ($r1)) {
363 foreach ($r1 as $to_be_removed) {
364 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
368 // perform a check to see if user changed event date
369 // this is important when editing an existing recurring event
370 // oct-08 JRM
371 if ($_POST['form_date'] == $_POST['selected_date']) {
372 // user has NOT changed the start date of the event
373 $event_date = fixDate($_POST['event_start_date']);
376 // this difference means that some providers were added
377 // so we must insert this event for them
378 $r2 = array_diff ($providers_new, $providers_current);
379 if (count ($r2)) {
380 foreach ($r2 as $to_be_inserted) {
381 $args = $_POST;
382 // specify some special variables needed for the INSERT
383 $args['new_multiple_value'] = $row['pc_multiple'];
384 $args['form_provider'] = $to_be_inserted;
385 $args['event_date'] = $event_date;
386 $args['duration'] = $duration * 60;
387 $args['recurrspec'] = $recurrspec;
388 $args['starttime'] = $starttime;
389 $args['endtime'] = $endtime;
390 $args['locationspec'] = $locationspec;
391 InsertEvent($args);
395 // after the two diffs above, we must update for remaining providers
396 // those who are intersected in $providers_current and $providers_new
397 foreach ($_POST['form_provider'] as $provider) {
398 sqlStatement("UPDATE openemr_postcalendar_events SET " .
399 "pc_catid = '" . $_POST['form_category'] . "', " .
400 "pc_pid = '" . $_POST['form_pid'] . "', " .
401 "pc_title = '" . $_POST['form_title'] . "', " .
402 "pc_time = NOW(), " .
403 "pc_hometext = '" . $_POST['form_comments'] . "', " .
404 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
405 "pc_eventDate = '" . $event_date . "', " .
406 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
407 "pc_duration = '" . ($duration * 60) . "', " .
408 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
409 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
410 "pc_startTime = '$starttime', " .
411 "pc_endTime = '$endtime', " .
412 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
413 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
414 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
415 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
416 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
417 } // foreach
421 // ====================================
422 // single provider
423 // ====================================
424 } elseif ( !$row['pc_multiple'] ) {
425 if ( $GLOBALS['select_multi_providers'] ) {
426 $prov = $_POST['form_provider'][0];
427 } else {
428 $prov = $_POST['form_provider'];
431 if ($_POST['recurr_affect'] == 'current') {
432 // get the original event's repeat specs
433 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
434 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
435 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
436 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
437 else { $oldRecurrspec['exdate'] .= $selected_date; }
439 // mod original event recur specs to exclude this date
440 sqlStatement("UPDATE openemr_postcalendar_events SET " .
441 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
442 " WHERE pc_eid = '$eid'");
444 // insert a new event on this date with POST form data
445 $args = $_POST;
446 // specify some special variables needed for the INSERT
447 $args['event_date'] = $event_date;
448 $args['duration'] = $duration * 60;
449 // this event is forced to NOT REPEAT
450 $args['form_repeat'] = "0";
451 $args['recurrspec'] = $noRecurrspec;
452 $args['form_enddate'] = "0000-00-00";
453 $args['starttime'] = $starttime;
454 $args['endtime'] = $endtime;
455 $args['locationspec'] = $locationspec;
456 InsertEvent($args);
458 else if ($_POST['recurr_affect'] == 'future') {
459 // mod original event to stop recurring on this date-1
460 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
461 sqlStatement("UPDATE openemr_postcalendar_events SET " .
462 " pc_enddate = '" . $selected_date ."' ".
463 " WHERE pc_eid = '$eid'");
465 // insert a new event starting on this date with POST form data
466 $args = $_POST;
467 // specify some special variables needed for the INSERT
468 $args['event_date'] = $event_date;
469 $args['duration'] = $duration * 60;
470 $args['recurrspec'] = $recurrspec;
471 $args['starttime'] = $starttime;
472 $args['endtime'] = $endtime;
473 $args['locationspec'] = $locationspec;
474 InsertEvent($args);
476 else {
478 // perform a check to see if user changed event date
479 // this is important when editing an existing recurring event
480 // oct-08 JRM
481 if ($_POST['form_date'] == $_POST['selected_date']) {
482 // user has NOT changed the start date of the event
483 $event_date = fixDate($_POST['event_start_date']);
486 // mod the SINGLE event or ALL EVENTS in a repeating series
487 // simple provider case
488 sqlStatement("UPDATE openemr_postcalendar_events SET " .
489 "pc_catid = '" . $_POST['form_category'] . "', " .
490 "pc_aid = '" . $prov . "', " .
491 "pc_pid = '" . $_POST['form_pid'] . "', " .
492 "pc_title = '" . $_POST['form_title'] . "', " .
493 "pc_time = NOW(), " .
494 "pc_hometext = '" . $_POST['form_comments'] . "', " .
495 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
496 "pc_eventDate = '" . $event_date . "', " .
497 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
498 "pc_duration = '" . ($duration * 60) . "', " .
499 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
500 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
501 "pc_startTime = '$starttime', " .
502 "pc_endTime = '$endtime', " .
503 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
504 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
505 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
506 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
507 "WHERE pc_eid = '$eid'");
511 // ===================================
512 // DBC change activity / times
513 $activ = ''; // activity could be an old value or a new one
514 if ( $GLOBALS['dutchpc'] ) {
515 if ( $_SESSION['editactiv'] ) {
516 $ac = selected_ac(); $activ = $ac;
517 $acid = what_sysid($ac);
519 if ( $acid ) sqlInsert("INSERT INTO cl_event_activiteit (event_id, activity_sysid)".
520 " VALUES ('" .$singleeid. "', '" .$acid. "') ON DUPLICATE KEY UPDATE activity_sysid = " .$acid );
522 $_SESSION['editactiv'] = FALSE; // otherwise you'll get a nasty bug!
523 } else {
524 $activcode = what_activity($singleeid);
525 $activ = what_code_activity($activcode);
528 // timing-activity validation
529 if ( vl_activity_travel($activ) ) {
530 $itime = (int)$_POST['form_duration_indirect']; $ttime = 0;
531 } else {
532 $itime = (int)$_POST['form_duration_indirect']; $ttime = (int)$_POST['form_duration_travel'];
534 sqlInsert("INSERT INTO cl_time_activiteit (event_id, indirect_time, travel_time)".
535 " VALUES ('" .$singleeid. "', '" .$itime. "', '" .$ttime. "') ON DUPLICATE KEY UPDATE indirect_time = " .$itime.
536 ", travel_time = " . $ttime);
539 // end DBC change activity / times
540 // ===================================
542 // =======================================
543 // end Update Multi providers case
544 // =======================================
546 // EVENTS TO FACILITIES
547 $e2f = (int)$eid;
550 } else {
551 /* =======================================================
552 * INSERT NEW EVENT(S)
553 * ======================================================*/
555 // =======================================
556 // multi providers case
557 // =======================================
558 if (is_array($_POST['form_provider'])) {
560 // obtain the next available unique key to group multiple providers around some event
561 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
562 $max = sqlFetchArray($q);
563 $new_multiple_value = $max['max'] + 1;
565 foreach ($_POST['form_provider'] as $provider) {
566 $args = $_POST;
567 // specify some special variables needed for the INSERT
568 $args['new_multiple_value'] = $new_multiple_value;
569 $args['form_provider'] = $provider;
570 $args['event_date'] = $event_date;
571 $args['duration'] = $duration * 60;
572 $args['recurrspec'] = $recurrspec;
573 $args['starttime'] = $starttime;
574 $args['endtime'] = $endtime;
575 $args['locationspec'] = $locationspec;
576 InsertEvent($args);
579 // ====================================
580 // single provider
581 // ====================================
582 } else {
583 $args = $_POST;
584 // specify some special variables needed for the INSERT
585 $args['new_multiple_value'] = "";
586 $args['event_date'] = $event_date;
587 $args['duration'] = $duration * 60;
588 $args['recurrspec'] = $recurrspec;
589 $args['starttime'] = $starttime;
590 $args['endtime'] = $endtime;
591 $args['locationspec'] = $locationspec;
592 InsertEvent($args);
595 // ==============================================
596 // DBC Dutch System (insert case)
597 $lid = mysql_insert_id($GLOBALS['dbh']); // obtain last inserted id
599 // larry :: fix dbc
600 if ( $GLOBALS['dutchpc'] ) {
601 $ac = selected_ac();
602 $acid = what_sysid($ac);
603 sqlInsert("INSERT INTO cl_event_activiteit (event_id, activity_sysid) VALUES ('" .$lid. "', '" .$acid. "')");
605 // timing-activity validation
606 if ( vl_activity_travel($activ) ) {
607 $itime = (int)$_POST['form_duration_indirect']; $ttime = 0;
608 } else {
609 $itime = (int)$_POST['form_duration_indirect']; $ttime = (int)$_POST['form_duration_travel'];
611 sqlInsert("INSERT INTO cl_time_activiteit (event_id, indirect_time, travel_time)".
612 " VALUES ('" .$lid. "', '" .$itime. "', '" .$ttime. "')");
614 // DBC Dutch System (insert case)
615 // ==============================================
617 // new ZTN ?
618 $pid1007 = ( $_POST['form_pid'] ) ? $_POST['form_pid'] : $pid;
619 if ( $pid1007 ) {
620 $a = generate_id1007($pid1007, $event_date); //var_dump($a); exit();
623 // end DBC
624 // ==============================================
628 // done with EVENT insert/update statements
630 // Save new DOB if it's there.
631 $patient_dob = trim($_POST['form_dob']);
632 if ($patient_dob && $_POST['form_pid']) {
633 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
634 "pid = '" . $_POST['form_pid'] . "'");
637 // Auto-create a new encounter if appropriate.
639 if ($GLOBALS['auto_create_new_encounters'] &&
640 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
642 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
643 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
644 if ($tmprow['count'] == 0) {
645 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
646 $_POST['form_provider'] . "'");
647 $username = $tmprow['username'];
648 $facility = $tmprow['facility'];
649 // $facility_id = $tmprow['facility_id'];
650 // use the session facility if it is set, otherwise the one from the provider.
651 $facility_id = $_SESSION['pc_facility'] ? $_SESSION['pc_facility'] : $tmprow['facility_id'];
652 $conn = $GLOBALS['adodb']['db'];
653 $encounter = $conn->GenID("sequences");
654 addForm($encounter, "New Patient Encounter",
655 sqlInsert("INSERT INTO form_encounter SET " .
656 "date = '$event_date', " .
657 "onset_date = '$event_date', " .
658 "reason = '" . $_POST['form_comments'] . "', " .
659 "facility = '$facility', " .
660 // "facility_id = '$facility_id', " .
661 "facility_id = '" . (int)$_POST['facility'] . "', " .
662 "pid = '" . $_POST['form_pid'] . "', " .
663 "encounter = '$encounter'"
665 "newpatient", $_POST['form_pid'], "1", "NOW()", $username
667 $info_msg .= "New encounter $encounter was created. ";
672 // =======================================
673 // DELETE EVENT(s)
674 // =======================================
675 else if ($_POST['form_action'] == "delete") {
676 // =======================================
677 // multi providers event
678 // =======================================
679 if ($GLOBALS['select_multi_providers']) {
681 // what is multiple key around this $eid?
682 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
684 // obtain current list of providers regarding the multiple key
685 $providers_current = array();
686 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
687 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
689 // establish a WHERE clause
690 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = {$row['pc_multiple']}"; }
691 else { $whereClause = "pc_eid = $eid"; }
693 if ($_POST['recurr_affect'] == 'current') {
694 // update all existing event records to exlude the current date
695 foreach ($providers_current as $provider) {
696 // update the provider's original event
697 // get the original event's repeat specs
698 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
699 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
700 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
701 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
702 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
703 else { $oldRecurrspec['exdate'] .= $selected_date; }
705 // mod original event recur specs to exclude this date
706 sqlStatement("UPDATE openemr_postcalendar_events SET " .
707 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
708 " WHERE ". $whereClause);
711 else if ($_POST['recurr_affect'] == 'future') {
712 // update all existing event records to stop recurring on this date-1
713 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
714 foreach ($providers_current as $provider) {
715 // update the provider's original event
716 sqlStatement("UPDATE openemr_postcalendar_events SET " .
717 " pc_enddate = '" . $selected_date ."' ".
718 " WHERE ".$whereClause);
721 else {
722 // really delete the event from the database
723 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
727 // =======================================
728 // single provider event
729 // =======================================
730 else {
732 if ($_POST['recurr_affect'] == 'current') {
733 // mod original event recur specs to exclude this date
735 // get the original event's repeat specs
736 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
737 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
738 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
739 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
740 else { $oldRecurrspec['exdate'] .= $selected_date; }
741 sqlStatement("UPDATE openemr_postcalendar_events SET " .
742 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
743 " WHERE pc_eid = '$eid'");
746 else if ($_POST['recurr_affect'] == 'future') {
747 // mod original event to stop recurring on this date-1
748 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
749 sqlStatement("UPDATE openemr_postcalendar_events SET " .
750 " pc_enddate = '" . $selected_date ."' ".
751 " WHERE pc_eid = '$eid'");
754 else {
755 // fully delete the event from the database
756 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
761 if ($_POST['form_action'] != "") {
762 // Close this window and refresh the calendar display.
763 echo "<html>\n<body>\n<script language='JavaScript'>\n";
764 if ($info_msg) echo " alert('$info_msg');\n";
765 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
766 echo " window.close();\n";
767 echo "</script>\n</body>\n</html>\n";
768 exit();
771 //*********************************
772 // If we get this far then we are displaying the form.
773 //*********************************
775 $statuses = array(
776 '-' => '',
777 '*' => xl('* Reminder done'),
778 '+' => xl('+ Chart pulled'),
779 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
780 '?' => xl('? No show'),
781 '@' => xl('@ Arrived'),
782 '~' => xl('~ Arrived late'),
783 '!' => xl('! Left w/o visit'),
784 '#' => xl('# Ins/fin issue'),
785 '<' => xl('< In exam room'),
786 '>' => xl('> Checked out'),
787 '$' => xl('$ Coding done'),
788 '%' => xl('% Cancelled < 24h ')
791 $repeats = 0; // if the event repeats
792 $repeattype = '0';
793 $repeatfreq = '0';
794 $patientid = '';
795 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
796 $patientname = xl('Click to select');
797 $patienttitle = "";
798 $hometext = "";
799 $row = array();
800 $informant = "";
802 // If we are editing an existing event, then get its data.
803 if ($eid) {
804 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
806 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
807 "FROM openemr_postcalendar_events AS e " .
808 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
809 "WHERE pc_eid = $eid");
810 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
812 // instead of using the event's starting date, keep what has been provided
813 // via the GET array, see the top of this file
814 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
815 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
816 $userid = $row['pc_aid'];
817 $patientid = $row['pc_pid'];
818 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
819 $starttimem = substr($row['pc_startTime'], 3, 2);
820 $repeats = $row['pc_recurrtype'];
821 $multiple_value = $row['pc_multiple'];
823 // parse out the repeating data, if any
824 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
825 $repeattype = $rspecs['event_repeat_freq_type'];
826 $repeatfreq = $rspecs['event_repeat_freq'];
827 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
829 $hometext = $row['pc_hometext'];
830 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
832 else {
833 // a NEW event
834 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
836 //-------------------------------------
837 //(CHEMED)
838 //Set default facility for a new event based on the given 'userid'
839 if ($userid) {
840 /*************************************************************
841 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
842 *************************************************************/
843 if ($_SESSION['pc_facility']) {
844 $pref_facility = sqlFetchArray(sqlStatement(sprintf("
845 SELECT f.id as facility_id,
846 f.name as facility
847 FROM facility f
848 WHERE f.id = %d
850 $_SESSION['pc_facility']
851 )));
852 } else {
853 $pref_facility = sqlFetchArray(sqlStatement("
854 SELECT u.facility_id,
855 f.name as facility
856 FROM users u
857 LEFT JOIN facility f on (u.facility_id = f.id)
858 WHERE u.id = $userid
859 "));
861 /************************************************************/
862 $e2f = $pref_facility['facility_id'];
863 $e2f_name = $pref_facility['facility'];
865 //END of CHEMED -----------------------
868 // If we have a patient ID, get the name and phone numbers to display.
869 if ($patientid) {
870 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
871 "FROM patient_data WHERE pid = '" . $patientid . "'");
872 $patientname = $prow['lname'] . ", " . $prow['fname'];
873 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
874 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
877 // Get the providers list.
878 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
879 "authorized != 0 AND active = 1 ORDER BY lname, fname");
881 // Get event categories.
882 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
883 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
885 // Fix up the time format for AM/PM.
886 $startampm = '1';
887 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
888 $startampm = '2';
889 if ($starttimeh > 12) $starttimeh -= 12;
893 <html>
894 <head>
895 <?php html_header_show(); ?>
896 <title><?php echo $eid ? xl('Edit','e') : xl('Add New','e') ?> <?php xl('Event','e');?></title>
897 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
899 <style>
900 td { font-size:0.8em; }
901 </style>
903 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
904 <script type="text/javascript" src="../../../library/topdialog.js"></script>
905 <script type="text/javascript" src="../../../library/dialog.js"></script>
906 <script type="text/javascript" src="../../../library/textformat.js"></script>
907 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
908 <script type="text/javascript" src="../../../library/dynarch_calendar_en.js"></script>
909 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
911 <?php
912 // ============================================================================
913 // DBC SYSTEM JAVASCRIPT FILE
915 if ( $GLOBALS['dutchpc'] ) { ?>
916 <script type="text/javascript" src="../../../library/js/add_edit_event.js"></script>
918 <?php }
919 // ============================================================================
922 <script language="JavaScript">
924 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
926 var durations = new Array();
927 // var rectypes = new Array();
928 <?php
929 // Read the event categories, generate their options list, and get
930 // the default event duration from them if this is a new event.
931 $catoptions = "";
932 $prefcat_options = " <option value='0'>-- None --</option>\n";
933 $thisduration = 0;
934 if ($eid) {
935 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
937 while ($crow = sqlFetchArray($cres)) {
938 $duration = round($crow['pc_duration'] / 60);
939 if ($crow['pc_end_all_day']) $duration = 1440;
940 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
941 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
942 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
943 if ($eid) {
944 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
945 } else {
946 if ($crow['pc_catid'] == $default_catid) {
947 $catoptions .= " selected";
948 $thisduration = $duration;
951 $catoptions .= ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
953 // This section is to build the list of preferred categories:
954 if ($duration) {
955 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
956 if ($eid) {
957 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
959 $prefcat_options .= ">" . xl_appt_category($crow['pc_catname']) . "</option>\n";
965 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
967 // This is for callback by the find-patient popup.
968 function setpatient(pid, lname, fname, dob) {
969 var f = document.forms[0];
970 f.form_patient.value = lname + ', ' + fname;
971 f.form_pid.value = pid;
972 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
973 document.getElementById('dob_row').style.display = dobstyle;
976 // This invokes the find-patient popup.
977 function sel_patient() {
978 dlgopen('find_patient_popup.php', '_blank', 500, 400);
981 // Do whatever is needed when a new event category is selected.
982 // For now this means changing the event title and duration.
983 function set_display() {
984 var f = document.forms[0];
985 var s = f.form_category;
986 if (s.selectedIndex >= 0) {
987 var catid = s.options[s.selectedIndex].value;
988 var style_apptstatus = document.getElementById('title_apptstatus').style;
989 var style_prefcat = document.getElementById('title_prefcat').style;
990 if (catid == '2') { // In Office
991 style_apptstatus.display = 'none';
992 style_prefcat.display = '';
993 f.form_apptstatus.style.display = 'none';
994 f.form_prefcat.style.display = '';
995 } else {
996 style_prefcat.display = 'none';
997 style_apptstatus.display = '';
998 f.form_prefcat.style.display = 'none';
999 f.form_apptstatus.style.display = '';
1004 // Do whatever is needed when a new event category is selected.
1005 // For now this means changing the event title and duration.
1006 function set_category() {
1007 var f = document.forms[0];
1008 var s = f.form_category;
1009 if (s.selectedIndex >= 0) {
1010 var catid = s.options[s.selectedIndex].value;
1011 f.form_title.value = s.options[s.selectedIndex].text;
1012 f.form_duration.value = durations[catid];
1013 set_display();
1017 // Modify some visual attributes when the all-day or timed-event
1018 // radio buttons are clicked.
1019 function set_allday() {
1020 var f = document.forms[0];
1021 var color1 = '#777777';
1022 var color2 = '#777777';
1023 var disabled2 = true;
1024 if (document.getElementById('rballday1').checked) {
1025 color1 = '#000000';
1027 if (document.getElementById('rballday2').checked) {
1028 color2 = '#000000';
1029 disabled2 = false;
1031 document.getElementById('tdallday1').style.color = color1;
1032 document.getElementById('tdallday2').style.color = color2;
1033 document.getElementById('tdallday3').style.color = color2;
1034 document.getElementById('tdallday4').style.color = color2;
1035 document.getElementById('tdallday5').style.color = color2;
1036 f.form_hour.disabled = disabled2;
1037 f.form_minute.disabled = disabled2;
1038 f.form_ampm.disabled = disabled2;
1039 f.form_duration.disabled = disabled2;
1042 // Modify some visual attributes when the Repeat checkbox is clicked.
1043 function set_repeat() {
1044 var f = document.forms[0];
1045 var isdisabled = true;
1046 var mycolor = '#777777';
1047 var myvisibility = 'hidden';
1048 if (f.form_repeat.checked) {
1049 isdisabled = false;
1050 mycolor = '#000000';
1051 myvisibility = 'visible';
1053 f.form_repeat_type.disabled = isdisabled;
1054 f.form_repeat_freq.disabled = isdisabled;
1055 f.form_enddate.disabled = isdisabled;
1056 document.getElementById('tdrepeat1').style.color = mycolor;
1057 document.getElementById('tdrepeat2').style.color = mycolor;
1058 document.getElementById('img_enddate').style.visibility = myvisibility;
1061 // This is for callback by the find-available popup.
1062 function setappt(year,mon,mday,hours,minutes) {
1063 var f = document.forms[0];
1064 f.form_date.value = '' + year + '-' +
1065 ('' + (mon + 100)).substring(1) + '-' +
1066 ('' + (mday + 100)).substring(1);
1067 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
1068 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
1069 f.form_minute.value = ('' + (minutes + 100)).substring(1);
1072 // Invoke the find-available popup.
1073 function find_available() {
1074 top.restoreSession();
1075 // (CHEMED) Conditional value selection, because there is no <select> element
1076 // when making an appointment for a specific provider
1077 var s = document.forms[0].form_provider;
1078 <?php if ($userid != 0) { ?>
1079 s = document.forms[0].form_provider.value;
1080 <?php } else {?>
1081 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1082 <?php }?>
1083 var c = document.forms[0].form_category;
1084 var formDate = document.forms[0].form_date;
1085 dlgopen('find_appt_popup.php?providerid=' + s +
1086 '&facility=' + f.options[f.selectedIndex].value +
1087 '&catid=' + c.options[c.selectedIndex].value +
1088 '&startdate=' + formDate.value, '_blank', 500, 400);
1089 //END (CHEMED) modifications
1092 // ==============================
1093 // DBC BOS
1094 function verify_selecteerbaar (a) {
1095 var f = document.forms[0]; var a;
1096 if (f.box5.value != 0) a = f.box5.value;
1097 else if (f.box4.value != 0) a = f.box4.value;
1098 else if (f.box3.value != 0) a = f.box3.value;
1099 else if (f.box2.value != 0) a = f.box2.value;
1100 else if (f.box1.value != 0) a = f.box1.value;
1101 else { alert('You must choose an activity.'); return false;
1104 var answer = $.ajax({
1105 url: "<?=$link?>",
1106 type: 'POST',
1107 data: 'vcode='+a,
1108 async: false
1109 }).responseText;
1110 if ( answer == 'false') { alert("Please select again"); return false; }
1111 else return true;
1113 // EOS DBC
1115 </script>
1117 <?php
1118 if ( $GLOBALS['dutchpc'])
1119 { ?>
1121 <script type="text/javascript">
1122 boxes();
1124 <?php
1125 if ( $eid ) { // editing case
1127 editcase();
1128 <?php
1129 } // EOS editing case
1132 </script>
1134 <?php
1135 } // EOS DBC DUTCH AJAX PART
1138 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1140 </head>
1142 <body class="body_top" onunload='imclosing()'>
1144 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo $eid ?>' />
1145 <input type="hidden" name="form_action" id="form_action" value="">
1146 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1147 <!-- used for recurring events -->
1148 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo $date; ?>">
1149 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo $eventstartdate; ?>">
1150 <center>
1152 <table border='0' width='100%'>
1154 <tr>
1155 <td width='1%' nowrap>
1156 <b><?php xl('Category','e'); ?>:</b>
1157 </td>
1158 <td nowrap>
1159 <select name='form_category' onchange='set_category()' style='width:100%'>
1160 <?php echo $catoptions ?>
1161 </select>
1162 </td>
1163 <td width='1%' nowrap>
1164 &nbsp;&nbsp;
1165 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1166 <?php if ($thisduration == 1440) echo "checked " ?>/>
1167 </td>
1168 <td colspan='2' nowrap id='tdallday1'>
1169 <?php xl('All day event','e'); ?>
1170 </td>
1171 </tr>
1173 <tr>
1174 <td nowrap>
1175 <b><?php xl('Date','e'); ?>:</b>
1176 </td>
1177 <td nowrap>
1178 <input type='text' size='10' name='form_date' id='form_date'
1179 value='<?php echo $date ?>'
1180 title='<?php xl('yyyy-mm-dd event date or starting date','e'); ?>'
1181 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
1182 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1183 id='img_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1184 title='<?php xl('Click here to choose a date','e'); ?>'>
1185 </td>
1186 <td nowrap>
1187 &nbsp;&nbsp;
1188 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1189 </td>
1190 <td width='1%' nowrap id='tdallday2'>
1191 <?php xl('Time','e'); ?>
1192 </td>
1193 <td width='1%' nowrap id='tdallday3'>
1194 <input type='text' size='2' name='form_hour' value='<?php echo $starttimeh ?>'
1195 title='<?php xl('Event start time','e'); ?>' /> :
1196 <input type='text' size='2' name='form_minute' value='<?php echo $starttimem ?>'
1197 title='<?php xl('Event start time','e'); ?>' />&nbsp;
1198 <select name='form_ampm' title='Note: 12:00 noon is PM, not AM'>
1199 <option value='1'><?php xl('AM','e'); ?></option>
1200 <option value='2'<?php if ($startampm == '2') echo " selected" ?>><?php xl('PM','e'); ?></option>
1201 </select>
1202 </td>
1203 </tr>
1204 <tr>
1205 <td nowrap>
1206 <b><?php xl('Title','e'); ?>:</b>
1207 </td>
1208 <td nowrap>
1209 <input type='text' size='10' name='form_title' value='<?php echo addslashes($row['pc_title']) ?>'
1210 style='width:100%'
1211 title='<?php xl('Event title','e'); ?>' />
1212 </td>
1213 <td nowrap>
1214 &nbsp;
1215 </td>
1216 <td nowrap id='tdallday4'><?php xl('duration','e'); ?>
1217 </td>
1218 <td nowrap id='tdallday5'>
1219 <input type='text' size='4' name='form_duration' value='<?php echo $thisduration ?>' title='<?php xl('Event duration in minutes','e'); ?>' />
1220 <?php xl('minutes','e'); ?>
1221 </td>
1222 </tr>
1224 <?php
1225 // =============================================
1226 // DBC DUTCH SYSTEMS
1227 // minutes issue
1228 if ( $GLOBALS['dutchpc'] ) { ?>
1229 <tr>
1230 <td colspan="3">&nbsp;</td>
1231 <td>indirect</td>
1232 <td><input type='text' name='form_duration_indirect' id='form_duration_indirect' size='4'
1233 value='<?php if ( isset($timerow['indirect_time']) ) echo $timerow['indirect_time']; ?>'/>minutes</td>
1234 </tr>
1235 <tr>
1236 <td colspan="3">&nbsp;</td>
1237 <td>travel</td>
1238 <td><input type='text' name='form_duration_travel' name='form_duration_travel' size='4'
1239 value='<?php if ( isset($timerow['travel_time']) ) echo $timerow['travel_time']; ?>'/>minutes</td>
1240 </tr>
1241 <?php
1242 // =======================================================
1243 // DBC DUTCH SYSTEM
1244 // cascading dropdowns
1245 // =======================================================
1246 if ( $GLOBALS['dutchpc'] ) {
1247 if ( $eid ) { // editing mode
1248 $activ = what_activity( $singleeid );
1250 if ( empty($activ) ) {
1251 $activ = "No activity selected.";
1252 } else {
1253 $activ = what_full_sysid($activ);
1254 $_SESSION['editactiv'] = FALSE;
1258 // end DBC DUTCH SYSTEM
1260 <tr>
1261 <td><b>Current activity:</b><br /><a href="#" id="addc">&lt;&lt;Add/Change&gt;&gt;</a></td>
1262 <td><?=$activ?><br /> <td colspan="3">&nbsp;</td></td>
1263 </tr>
1264 <tr>
1265 <td nowrap><b>Activiteit:</b></td>
1266 <td width='1%' nowrap>
1267 <select name="box1" id="box1">
1268 <?php
1269 $rlvone = records_level1('ev');
1270 foreach ($rlvone as $rlv) {
1271 echo '<option value=\'' .$rlv['cl_activiteit_code']. '\'>' .$rlv['cl_activiteit_element']. '</option>';
1272 } ?>
1273 </select>
1274 </td>
1275 <td colspan="3"><?php if ( $patientid ) $are = has_ztndbc($patientid); else $are = ' '; ?>
1276 <p style="background-color: #78AEBC; padding: 3px; text-align: center"><?=$are['str']?></p>
1277 </td>
1278 </tr>
1280 <tr colspan="2"><td></td><td>
1281 <select id="box2" name="box2">
1282 </select></td></tr>
1284 <tr colspan="2"><td></td><td>
1285 <select id="box3" name="box3"></select>
1286 </td></tr>
1288 <tr colspan="2"><td></td><td>
1289 <select id="box4" name="box4"></select>
1290 </td></tr>
1292 <tr colspan="2"><td></td><td>
1293 <select id="box5" name="box5"></select>
1294 </td></tr>
1296 <?php } ?>
1298 <tr>
1299 <td nowrap><b><?php xl('Facility','e'); ?>:</b></td>
1300 <td>
1301 <?php /*{CHEMED}*/
1302 if ($userid != 0) { ?>
1303 <input type='hidden' name="facility" id="facility" value='<?php echo $e2f; ?>'/>
1304 <input type='input' readonly name="facility_txt" value='<?php echo $e2f_name; ?>'/>
1305 <?php } else {?>
1306 <select name="facility" id="facility" >
1307 <?php
1309 // ===========================
1310 // EVENTS TO FACILITIES
1311 //(CHEMED) added service_location WHERE clause
1312 // get the facilities
1313 /***************************************************************
1314 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1315 ***************************************************************/
1316 $facils = getUserFacilities($_SESSION['authId']);
1317 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1318 /**************************************************************/
1319 while ($facrow = sqlFetchArray($qsql)) {
1320 /*************************************************************
1321 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1322 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1323 *************************************************************/
1324 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1325 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1326 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1328 /************************************************************/
1330 // EOS E2F
1331 // ===========================
1333 <?php }
1334 //END (CHEMED) IF ?>
1335 </td>
1336 </select>
1337 </tr>
1339 <tr>
1340 <td nowrap>
1341 <b><?php xl('Patient','e'); ?>:</b>
1342 </td>
1343 <td nowrap>
1344 <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 />
1345 <input type='hidden' name='form_pid' value='<?php echo $patientid ?>' />
1346 </td>
1347 <td colspan='3' nowrap style='font-size:8pt'>
1348 &nbsp;
1349 <span class="infobox">
1350 <?php if ($patienttitle != "") { echo $patienttitle; } ?>
1351 </span>
1352 </td>
1353 </tr>
1355 <tr>
1356 <td nowrap>
1357 <b><?php xl('Provider','e'); ?>:</b>
1358 </td>
1359 <td nowrap>
1361 <?php
1363 // =======================================
1364 // multi providers
1365 // =======================================
1366 if ($GLOBALS['select_multi_providers']) {
1368 // there are two posible situations: edit and new record
1370 // this is executed only on edit ($eid)
1371 if ($eid) {
1372 if ( $multiple_value ) {
1373 // find all the providers around multiple key
1374 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = $multiple_value");
1375 while ($r = sqlFetchArray($qall)) {
1376 $providers_array[] = $r['providers'];
1378 } else {
1379 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1380 $providers_array = sqlFetchArray($qall);
1384 // build the selection tool
1385 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1387 while ($urow = sqlFetchArray($ures)) {
1388 echo " <option value='" . $urow['id'] . "'";
1390 if ($userid) {
1391 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1394 echo ">" . $urow['lname'];
1395 if ($urow['fname']) echo ", " . $urow['fname'];
1396 echo "</option>\n";
1399 echo '</select>';
1401 // =======================================
1402 // single provider
1403 // =======================================
1404 } else {
1406 if ($eid) {
1407 // get provider from existing event
1408 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1409 $provider = sqlFetchArray($qprov);
1410 $defaultProvider = $provider['pc_aid'];
1412 else {
1413 // this is a new event so smartly choose a default provider
1414 /*****************************************************************
1415 if ($userid) {
1416 // Provider already given to us as a GET parameter.
1417 $defaultProvider = $userid;
1419 else {
1420 // default to the currently logged-in user
1421 $defaultProvider = $_SESSION['authUserID'];
1422 // or, if we have chosen a provider in the calendar, default to them
1423 // choose the first one if multiple have been selected
1424 if (count($_SESSION['pc_username']) >= 1) {
1425 // get the numeric ID of the first provider in the array
1426 $pc_username = $_SESSION['pc_username'];
1427 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1428 $defaultProvider = $firstProvider['id'];
1433 echo "<select name='form_provider' style='width:100%' />";
1434 while ($urow = sqlFetchArray($ures)) {
1435 echo " <option value='" . $urow['id'] . "'";
1436 if ($urow['id'] == $defaultProvider) echo " selected";
1437 echo ">" . $urow['lname'];
1438 if ($urow['fname']) echo ", " . $urow['fname'];
1439 echo "</option>\n";
1441 echo "</select>";
1442 *****************************************************************/
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'];
1453 // if we clicked on a provider's schedule to add the event, use THAT.
1454 if ($userid) $defaultProvider = $userid;
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 /****************************************************************/
1470 </td>
1471 <td nowrap>
1472 &nbsp;&nbsp;
1473 <input type='checkbox' name='form_repeat' onclick='set_repeat(this)' value='1'<?php if ($repeats) echo " checked" ?>/>
1474 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo $repeatexdate; ?>' /> <!-- dates excluded from the repeat -->
1475 </td>
1476 <td nowrap id='tdrepeat1'><?php xl('Repeats','e'); ?>
1477 </td>
1478 <td nowrap>
1480 <select name='form_repeat_freq' title=<?php xl('Every, every other, every 3rd, etc.','e','\'','\''); ?>>
1481 <?php
1482 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1483 as $key => $value)
1485 echo " <option value='$key'";
1486 if ($key == $repeatfreq) echo " selected";
1487 echo ">$value</option>\n";
1490 </select>
1492 <select name='form_repeat_type'>
1493 <?php
1494 // See common.api.php for these:
1495 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'))
1496 as $key => $value)
1498 echo " <option value='$key'";
1499 if ($key == $repeattype) echo " selected";
1500 echo ">$value</option>\n";
1503 </select>
1505 </td>
1506 </tr>
1508 <tr>
1509 <td nowrap>
1510 <span id='title_apptstatus'><b><?php xl('Status','e'); ?>:</b></span>
1511 <span id='title_prefcat' style='display:none'><b><?php xl('Pref Cat','e'); ?>:</b></span>
1512 </td>
1513 <td nowrap>
1515 <select name='form_apptstatus' style='width:100%' title='<?php xl('Appointment status','e'); ?>'>
1516 <?php
1517 foreach ($statuses as $key => $value) {
1518 echo " <option value='$key'";
1519 if ($key == $row['pc_apptstatus']) echo " selected";
1520 echo ">" . htmlspecialchars($value) . "</option>\n";
1523 </select>
1524 <!--
1525 The following list will be invisible unless this is an In Office
1526 event, in which case form_apptstatus (above) is to be invisible.
1528 <select name='form_prefcat' style='width:100%;display:none' title='<?php xl('Preferred Event Category','e');?>'>
1529 <?php echo $prefcat_options ?>
1530 </select>
1532 </td>
1533 <td nowrap>
1534 &nbsp;
1535 </td>
1536 <td nowrap id='tdrepeat2'><?php xl('until','e'); ?>
1537 </td>
1538 <td nowrap>
1539 <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');?>' />
1540 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1541 id='img_enddate' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1542 title='<?php xl('Click here to choose a date','e');?>'>
1543 <?php
1544 if ($repeatexdate != "") {
1545 $tmptitle = "The following dates are excluded from the repeating series";
1546 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1547 else { $tmptitle .= "\n"; }
1548 $exdates = explode(",", $repeatexdate);
1549 foreach ($exdates as $exdate) {
1550 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1552 echo "<a href='#' title='$tmptitle' alt='$tmptitle'><img src='../../pic/warning.gif' title='$tmptitle' alt='*!*' style='border:none;'/></a>";
1555 </td>
1556 </tr>
1558 <tr>
1559 <td nowrap>
1560 <b><?php xl('Comments','e'); ?>:</b>
1561 </td>
1562 <td colspan='4' nowrap>
1563 <input type='text' size='40' name='form_comments' style='width:100%' value='<?php echo $hometext ?>' title='<?php xl('Optional information about this event','e');?>' />
1564 </td>
1565 </tr>
1567 <?php
1568 // DOB is important for the clinic, so if it's missing give them a chance
1569 // to enter it right here. We must display or hide this row dynamically
1570 // in case the patient-select popup is used.
1571 $patient_dob = trim($prow['DOB']);
1572 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00')) ?
1573 '' : 'none';
1575 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1576 <td colspan='4' nowrap>
1577 <b><font color='red'><?php xl('DOB is missing, please enter if possible','e'); ?>:</font></b>
1578 </td>
1579 <td nowrap>
1580 <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)' />
1581 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1582 id='img_dob' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1583 title='<?php xl('Click here to choose a date','e');?>'>
1584 </td>
1585 </tr>
1587 </table>
1590 <input type='button' name='form_save' id='form_save' value='<?php xl('Save','e');?>' />
1591 &nbsp;
1592 <input type='button' id='find_available' value='<?php xl('Find Available','e');?>' />
1593 &nbsp;
1594 <input type='button' name='form_delete' id='form_delete' value='<?php xl('Delete','e');?>'<?php if (!$eid) echo " disabled" ?> />
1595 &nbsp;
1596 <input type='button' id='cancel' value='<?php xl('Cancel','e');?>' />
1597 </p>
1598 <?php if ($informant) echo "<p class='text'>" . xl('Last update by') . " $informant</p>\n"; ?>
1599 </center>
1600 </form>
1602 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1603 Apply the changes to the Current event only, to this and all Future occurrences, or to All occurances?
1604 <br>
1605 <input type="button" name="all_events" id="all_events" value=" All ">
1606 <input type="button" name="future_events" id="future_events" value="Future">
1607 <input type="button" name="current_event" id="current_event" value="Current">
1608 <input type="button" name="recurr_cancel" id="recurr_cancel" value="Cancel">
1609 </div>
1611 </body>
1613 <script language='JavaScript'>
1614 <?php if ($eid) { ?>
1615 set_display();
1616 <?php } else { ?>
1617 set_category();
1618 <?php } ?>
1619 set_allday();
1620 set_repeat();
1622 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
1623 Calendar.setup({inputField:"form_enddate", ifFormat:"%Y-%m-%d", button:"img_enddate"});
1624 Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});
1625 </script>
1627 <script language="javascript">
1628 // jQuery stuff to make the page a little easier to use
1630 $(document).ready(function(){
1631 $("#form_save").click(function() { validate(); });
1632 $("#find_available").click(function() { find_available(); });
1633 $("#form_delete").click(function() { deleteEvent(); });
1634 $("#cancel").click(function() { window.close(); });
1636 // buttons affecting the modification of a repeating event
1637 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1638 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1639 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1640 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1643 // Check for errors when the form is submitted.
1644 function validate() {
1645 var f = document.getElementById('theform');
1646 if (f.form_repeat.checked &&
1647 (! f.form_enddate.value || f.form_enddate.value < f.form_date.value)) {
1648 alert('An end date later than the start date is required for repeated events!');
1649 return false;
1651 $('#form_action').val("save");
1653 <?php if ($repeats): ?>
1654 // existing repeating events need additional prompt
1655 if ($("#recurr_affect").val() == "") {
1656 DisableForm();
1657 // show the current/future/all DIV for the user to choose one
1658 $("#recurr_popup").css("visibility", "visible");
1659 return false;
1661 <?php endif; ?>
1663 return SubmitForm();
1666 // disable all the form elements outside the recurr_popup
1667 function DisableForm() {
1668 $("#theform").children().attr("disabled", "true");
1670 function EnableForm() {
1671 $("#theform").children().removeAttr("disabled");
1673 // hide the recurring popup DIV
1674 function HideRecurrPopup() {
1675 $("#recurr_popup").css("visibility", "hidden");
1678 function deleteEvent() {
1679 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?")) {
1680 $('#form_action').val("delete");
1682 <?php if ($repeats): ?>
1683 // existing repeating events need additional prompt
1684 if ($("#recurr_affect").val() == "") {
1685 DisableForm();
1686 // show the current/future/all DIV for the user to choose one
1687 $("#recurr_popup").css("visibility", "visible");
1688 return false;
1690 <?php endif; ?>
1692 return SubmitForm();
1694 return false;
1697 function SubmitForm() {
1698 // DBC Dutch System validation
1699 <?php if ( $GLOBALS['dutchpc'] && $_SESSION['editactiv']) { ?>
1700 var a = verify_selecteerbaar();
1701 if ( !a ) return false;
1702 <?php } ?>
1703 // DBC EOS
1705 $('#theform').submit();
1706 top.restoreSession();
1707 return true;
1710 </script>
1712 </html>