2 // Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // The event editor looks something like this:
11 //------------------------------------------------------------//
12 // Category __________________V O All day event //
13 // Date _____________ [?] O Time ___:___ __V //
14 // Title ___________________ duration ____ minutes //
15 // Patient _(Click_to_select)_ //
16 // Provider __________________V X Repeats ______V ______V //
17 // Status __________________V until __________ [?] //
18 // Comments ________________________________________________ //
20 // [Save] [Find Available] [Delete] [Cancel] //
21 //------------------------------------------------------------//
23 include_once("../../globals.php");
24 include_once("$srcdir/patient.inc");
25 include_once("$srcdir/forms.inc");
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';
35 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
37 $date = date("Y-m-d");
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)
50 $starttimeh = date("G");
56 // used for DBC Dutch System
57 $_SESSION['event_date'] = $date;
58 $link = '../../../library/DBC_functions.php'; // ajax stuff and db work
61 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
66 // $args is mainly filled with content from the POST http var
67 function InsertEvent($args) {
68 return sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
69 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
70 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
71 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
72 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
74 "'" . $args['form_category'] . "', " .
75 "'" . $args['new_multiple_value'] . "', " .
76 "'" . $args['form_provider'] . "', " .
77 "'" . $args['form_pid'] . "', " .
78 "'" . $args['form_title'] . "', " .
80 "'" . $args['form_comments'] . "', " .
81 "'" . $_SESSION['authUserID'] . "', " .
82 "'" . $args['event_date'] . "', " .
83 "'" . fixDate($args['form_enddate']) . "', " .
84 "'" . $args['duration'] . "', " .
85 "'" . ($args['form_repeat'] ?
'1' : '0') . "', " .
86 "'" . serialize($args['recurrspec']) . "', " .
87 "'" . $args['starttime'] ."', " .
88 "'" . $args['endtime'] ."', " .
89 "'" . $args['form_allday'] . "', " .
90 "'" . $args['form_apptstatus'] . "', " .
91 "'" . $args['form_prefcat'] . "', " .
92 "'" . $args['locationspec'] ."', " .
94 "1, " .(int)$args['facility']. " )"
98 // =====================================
100 // ACTIVITIES / TIMES
101 if ( $GLOBALS['dutchpc'] ) {
103 if ( $GLOBALS['select_multi_providers'] ) {
104 // ------------------------------------------
105 // what is multiple key around this $eid?
106 $rowmulti = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
108 // what are all pc_eid's grouped by multiple key
109 $eventsrow = array();
110 $rezev = mysql_query("SELECT pc_eid FROM openemr_postcalendar_events WHERE pc_multiple = {$rowmulti['pc_multiple']}");
111 while ( $row = mysql_fetch_array($rezev) ) {
112 $eventsrow[] = $row['pc_eid'];
115 // we look in cl_event_activiteit / cl_time_activiteit for a matching record
116 foreach ( $eventsrow as $ev) {
117 $activ = sqlQuery("SELECT * FROM cl_event_activiteit WHERE event_id = $ev");
118 if ( $activ['event_id'] ) $singleeid = $activ['event_id'];
120 $time = sqlQuery("SELECT * FROM cl_time_activiteit WHERE event_id = $ev");
121 if ( $time ) $timerow = $time;
124 // prevent blank values for $singleeid
125 if ( !$singleeid) $singleeid = $eid;
127 // ------------------------------------------
129 // ------------------------------------------
130 // single providers case
131 $timerow = sqlQuery("SELECT * FROM cl_time_activiteit WHERE event_id = $eid");
133 // ------------------------------------------
138 // EVENTS TO FACILITIES (lemonsoftware)
139 //(CHEMED) get facility name
140 // edit event case - if there is no association made, then insert one with the first facility
143 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
144 FROM openemr_postcalendar_events
145 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
146 WHERE pc_eid = $eid");
147 if ( !$facility['pc_facility'] ) {
148 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
149 $min = $qmin['minId'];
150 $min_name = $qmin['facility'];
152 // multiple providers case
153 if ( $GLOBALS['select_multi_providers'] ) {
154 $mul = $facility['pc_multiple'];
155 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
159 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
161 $e2f_name = $min_name;
163 $e2f = $facility['pc_facility'];
164 $e2f_name = $facility['name'];
168 // ===========================
171 // If we are saving, then save and close the window.
173 if ($_POST['form_action'] == "save") {
175 // ========================================
177 // check if for activity act_3.2 we have times completed
179 if ( $GLOBALS['dutchpc'] ) {
181 if ( $sa == 'act_3.2') {
182 $duration = (int)$_POST['form_duration'];
183 if ( empty($duration) ) exit();
186 // ========================================
188 // the starting date of the event, pay attention with this value
189 // when editing recurring events -- JRM Oct-08
190 $event_date = fixDate($_POST['form_date']);
192 // Compute start and end time strings to be saved.
193 if ($_POST['form_allday']) {
198 $tmph = $_POST['form_hour'] +
0;
199 $tmpm = $_POST['form_minute'] +
0;
200 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph +
= 12;
201 $duration = $_POST['form_duration'];
203 $starttime = "$tmph:$tmpm:00";
206 while ($tmpm >= 60) {
210 $endtime = "$tmph:$tmpm:00";
212 // Useless garbage that we must save.
213 $locationspecs = array("event_location" => "",
214 "event_street1" => "",
215 "event_street2" => "",
220 $locationspec = serialize($locationspecs);
222 // capture the recurring specifications
223 $recurrspec = array("event_repeat_freq" => $_POST['form_repeat_freq'],
224 "event_repeat_freq_type" => $_POST['form_repeat_type'],
225 "event_repeat_on_num" => "1",
226 "event_repeat_on_day" => "0",
227 "event_repeat_on_freq" => "0",
228 "exdate" => $_POST['form_repeat_exdate']
231 // no recurr specs, this is used for adding a new non-recurring event
232 $noRecurrspec = array("event_repeat_freq" => "",
233 "event_repeat_freq_type" => "",
234 "event_repeat_on_num" => "1",
235 "event_repeat_on_day" => "0",
236 "event_repeat_on_freq" => "0",
240 /* =======================================================
242 * =====================================================*/
245 // what is multiple key around this $eid?
246 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
248 // timing-activity validation - larry :: DBC ????
250 if ( $GLOBALS['dutchpc'] ) {
251 if ( $_SESSION['editactiv'] ) { $activ = selected_ac(); }
252 else { $activ = what_activity($eid); }
256 // ====================================
257 // multiple providers
258 // ====================================
259 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
261 // obtain current list of providers regarding the multiple key
262 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
263 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
265 // get the new list of providers from the submitted form
266 $providers_new = $_POST['form_provider'];
268 // ===== Only current event of repeating series =====
269 if ($_POST['recurr_affect'] == 'current') {
271 // update all existing event records to exlude the current date
272 foreach ($providers_current as $provider) {
273 // update the provider's original event
274 // get the original event's repeat specs
275 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
276 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
277 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
278 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
279 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
280 else { $oldRecurrspec['exdate'] .= $selected_date; }
282 // mod original event recur specs to exclude this date
283 sqlStatement("UPDATE openemr_postcalendar_events SET " .
284 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
285 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
288 // obtain the next available unique key to group multiple providers around some event
289 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
290 $max = sqlFetchArray($q);
291 $new_multiple_value = $max['max'] +
1;
293 // insert a new event record for each provider selected on the form
294 foreach ($providers_new as $provider) {
295 // insert a new event on this date with POST form data
297 // specify some special variables needed for the INSERT
298 $args['new_multiple_value'] = $new_multiple_value;
299 $args['form_provider'] = $provider;
300 $args['event_date'] = $event_date;
301 $args['duration'] = $duration * 60;
302 // this event is forced to NOT REPEAT
303 $args['form_repeat'] = "0";
304 $args['recurrspec'] = $noRecurrspec;
305 $args['form_enddate'] = "0000-00-00";
306 $args['starttime'] = $starttime;
307 $args['endtime'] = $endtime;
308 $args['locationspec'] = $locationspec;
313 // ===== Future Recurring events of a repeating series =====
314 else if ($_POST['recurr_affect'] == 'future') {
315 // update all existing event records to
316 // stop recurring on this date-1
317 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
318 foreach ($providers_current as $provider) {
319 // mod original event recur specs to end on this date
320 sqlStatement("UPDATE openemr_postcalendar_events SET " .
321 " pc_enddate = '" . $selected_date ."' ".
322 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
325 // obtain the next available unique key to group multiple providers around some event
326 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
327 $max = sqlFetchArray($q);
328 $new_multiple_value = $max['max'] +
1;
330 // insert a new event record for each provider selected on the form
331 foreach ($providers_new as $provider) {
332 // insert a new event on this date with POST form data
334 // specify some special variables needed for the INSERT
335 $args['new_multiple_value'] = $new_multiple_value;
336 $args['form_provider'] = $provider;
337 $args['event_date'] = $event_date;
338 $args['duration'] = $duration * 60;
339 $args['recurrspec'] = $recurrspec;
340 $args['starttime'] = $starttime;
341 $args['endtime'] = $endtime;
342 $args['locationspec'] = $locationspec;
348 // ===== a Single event or All events in a repeating series ==========
350 // this difference means that some providers from current was UNCHECKED
351 // so we must delete this event for them
352 $r1 = array_diff ($providers_current, $providers_new);
354 foreach ($r1 as $to_be_removed) {
355 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
359 // perform a check to see if user changed event date
360 // this is important when editing an existing recurring event
362 if ($_POST['form_date'] == $_POST['selected_date']) {
363 // user has NOT changed the start date of the event
364 $event_date = fixDate($_POST['event_start_date']);
368 // this difference means that some providers were added
369 // so we must insert this event for them
370 $r2 = array_diff ($providers_new, $providers_current);
372 foreach ($r2 as $to_be_inserted) {
374 // specify some special variables needed for the INSERT
375 $args['new_multiple_value'] = $row['pc_multiple'];
376 $args['form_provider'] = $to_be_inserted;
377 $args['event_date'] = $event_date;
378 $args['duration'] = $duration * 60;
379 $args['recurrspec'] = $recurrspec;
380 $args['starttime'] = $starttime;
381 $args['endtime'] = $endtime;
382 $args['locationspec'] = $locationspec;
387 // after the two diffs above, we must update for remaining providers
388 // those who are intersected in $providers_current and $providers_new
389 foreach ($_POST['form_provider'] as $provider) {
390 sqlStatement("UPDATE openemr_postcalendar_events SET " .
391 "pc_catid = '" . $_POST['form_category'] . "', " .
392 "pc_pid = '" . $_POST['form_pid'] . "', " .
393 "pc_title = '" . $_POST['form_title'] . "', " .
394 "pc_time = NOW(), " .
395 "pc_hometext = '" . $_POST['form_comments'] . "', " .
396 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
397 "pc_eventDate = '" . $event_date . "', " .
398 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
399 "pc_duration = '" . ($duration * 60) . "', " .
400 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
401 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
402 "pc_startTime = '$starttime', " .
403 "pc_endTime = '$endtime', " .
404 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
405 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
406 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
407 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
408 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
413 // ====================================
415 // ====================================
416 } elseif ( !$row['pc_multiple'] ) {
417 if ( $GLOBALS['select_multi_providers'] ) {
418 $prov = $_POST['form_provider'][0];
420 $prov = $_POST['form_provider'];
423 if ($_POST['recurr_affect'] == 'current') {
424 // get the original event's repeat specs
425 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
426 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
427 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
428 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
429 else { $oldRecurrspec['exdate'] .= $selected_date; }
431 // mod original event recur specs to exclude this date
432 sqlStatement("UPDATE openemr_postcalendar_events SET " .
433 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
434 " WHERE pc_eid = '$eid'");
436 // insert a new event on this date with POST form data
438 // specify some special variables needed for the INSERT
439 $args['event_date'] = $event_date;
440 $args['duration'] = $duration * 60;
441 // this event is forced to NOT REPEAT
442 $args['form_repeat'] = "0";
443 $args['recurrspec'] = $noRecurrspec;
444 $args['form_enddate'] = "0000-00-00";
445 $args['starttime'] = $starttime;
446 $args['endtime'] = $endtime;
447 $args['locationspec'] = $locationspec;
450 else if ($_POST['recurr_affect'] == 'future') {
451 // mod original event to stop recurring on this date-1
452 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
453 sqlStatement("UPDATE openemr_postcalendar_events SET " .
454 " pc_enddate = '" . $selected_date ."' ".
455 " WHERE pc_eid = '$eid'");
457 // insert a new event starting on this date with POST form data
459 // specify some special variables needed for the INSERT
460 $args['event_date'] = $event_date;
461 $args['duration'] = $duration * 60;
462 $args['recurrspec'] = $recurrspec;
463 $args['starttime'] = $starttime;
464 $args['endtime'] = $endtime;
465 $args['locationspec'] = $locationspec;
470 // perform a check to see if user changed event date
471 // this is important when editing an existing recurring event
473 if ($_POST['form_date'] == $_POST['selected_date']) {
474 // user has NOT changed the start date of the event
475 $event_date = fixDate($_POST['event_start_date']);
478 // mod the SINGLE event or ALL EVENTS in a repeating series
479 // simple provider case
480 sqlStatement("UPDATE openemr_postcalendar_events SET " .
481 "pc_catid = '" . $_POST['form_category'] . "', " .
482 "pc_aid = '" . $prov . "', " .
483 "pc_pid = '" . $_POST['form_pid'] . "', " .
484 "pc_title = '" . $_POST['form_title'] . "', " .
485 "pc_time = NOW(), " .
486 "pc_hometext = '" . $_POST['form_comments'] . "', " .
487 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
488 "pc_eventDate = '" . $event_date . "', " .
489 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
490 "pc_duration = '" . ($duration * 60) . "', " .
491 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
492 "pc_recurrspec = '" . serialize($recurrspec) . "', " .
493 "pc_startTime = '$starttime', " .
494 "pc_endTime = '$endtime', " .
495 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
496 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
497 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
498 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
499 "WHERE pc_eid = '$eid'");
503 // ===================================
504 // DBC change activity / times
505 $activ = ''; // activity could be an old value or a new one
506 if ( $GLOBALS['dutchpc'] ) {
507 if ( $_SESSION['editactiv'] ) {
508 $ac = selected_ac(); $activ = $ac;
509 $acid = what_sysid($ac);
511 if ( $acid ) sqlInsert("INSERT INTO cl_event_activiteit (event_id, activity_sysid)".
512 " VALUES ('" .$singleeid. "', '" .$acid. "') ON DUPLICATE KEY UPDATE activity_sysid = " .$acid );
514 $_SESSION['editactiv'] = FALSE; // otherwise you'll get a nasty bug!
516 $activcode = what_activity($singleeid);
517 $activ = what_code_activity($activcode);
520 // timing-activity validation
521 if ( vl_activity_travel($activ) ) {
522 $itime = (int)$_POST['form_duration_indirect']; $ttime = 0;
524 $itime = (int)$_POST['form_duration_indirect']; $ttime = (int)$_POST['form_duration_travel'];
526 sqlInsert("INSERT INTO cl_time_activiteit (event_id, indirect_time, travel_time)".
527 " VALUES ('" .$singleeid. "', '" .$itime. "', '" .$ttime. "') ON DUPLICATE KEY UPDATE indirect_time = " .$itime.
528 ", travel_time = " . $ttime);
531 // end DBC change activity / times
532 // ===================================
534 // =======================================
535 // end Update Multi providers case
536 // =======================================
538 // EVENTS TO FACILITIES
543 /* =======================================================
544 * INSERT NEW EVENT(S)
545 * ======================================================*/
547 // =======================================
548 // multi providers case
549 // =======================================
550 if (is_array($_POST['form_provider'])) {
552 // obtain the next available unique key to group multiple providers around some event
553 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
554 $max = sqlFetchArray($q);
555 $new_multiple_value = $max['max'] +
1;
557 foreach ($_POST['form_provider'] as $provider) {
559 // specify some special variables needed for the INSERT
560 $args['new_multiple_value'] = $new_multiple_value;
561 $args['form_provider'] = $provider;
562 $args['event_date'] = $event_date;
563 $args['duration'] = $duration * 60;
564 $args['recurrspec'] = $recurrspec;
565 $args['starttime'] = $starttime;
566 $args['endtime'] = $endtime;
567 $args['locationspec'] = $locationspec;
571 // ====================================
573 // ====================================
576 // specify some special variables needed for the INSERT
577 $args['new_multiple_value'] = "";
578 $args['event_date'] = $event_date;
579 $args['duration'] = $duration * 60;
580 $args['recurrspec'] = $recurrspec;
581 $args['starttime'] = $starttime;
582 $args['endtime'] = $endtime;
583 $args['locationspec'] = $locationspec;
587 // ==============================================
588 // DBC Dutch System (insert case)
589 $lid = mysql_insert_id($GLOBALS['dbh']); // obtain last inserted id
592 if ( $GLOBALS['dutchpc'] ) {
594 $acid = what_sysid($ac);
595 sqlInsert("INSERT INTO cl_event_activiteit (event_id, activity_sysid) VALUES ('" .$lid. "', '" .$acid. "')");
597 // timing-activity validation
598 if ( vl_activity_travel($activ) ) {
599 $itime = (int)$_POST['form_duration_indirect']; $ttime = 0;
601 $itime = (int)$_POST['form_duration_indirect']; $ttime = (int)$_POST['form_duration_travel'];
603 sqlInsert("INSERT INTO cl_time_activiteit (event_id, indirect_time, travel_time)".
604 " VALUES ('" .$lid. "', '" .$itime. "', '" .$ttime. "')");
606 // DBC Dutch System (insert case)
607 // ==============================================
610 $pid1007 = ( $_POST['form_pid'] ) ?
$_POST['form_pid'] : $pid;
612 $a = generate_id1007($pid1007, $event_date); //var_dump($a); exit();
616 // ==============================================
620 // done with EVENT insert/update statements
622 // Save new DOB if it's there.
623 $patient_dob = trim($_POST['form_dob']);
624 if ($patient_dob && $_POST['form_pid']) {
625 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
626 "pid = '" . $_POST['form_pid'] . "'");
629 // Auto-create a new encounter if appropriate.
631 if ($GLOBALS['auto_create_new_encounters'] &&
632 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
634 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
635 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
636 if ($tmprow['count'] == 0) {
637 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
638 $_POST['form_provider'] . "'");
639 $username = $tmprow['username'];
640 $facility = $tmprow['facility'];
641 $facility_id = $tmprow['facility_id'];
642 $conn = $GLOBALS['adodb']['db'];
643 $encounter = $conn->GenID("sequences");
644 addForm($encounter, "New Patient Encounter",
645 sqlInsert("INSERT INTO form_encounter SET " .
646 "date = '$event_date', " .
647 "onset_date = '$event_date', " .
648 "reason = '" . $_POST['form_comments'] . "', " .
649 "facility = '$facility', " .
650 "facility_id = '$facility_id', " .
651 "pid = '" . $_POST['form_pid'] . "', " .
652 "encounter = '$encounter'"
654 "newpatient", $_POST['form_pid'], "1", "NOW()", $username
656 $info_msg .= "New encounter $encounter was created. ";
661 // =======================================
663 // =======================================
664 else if ($_POST['form_action'] == "delete") {
665 // =======================================
666 // multi providers event
667 // =======================================
668 if ($GLOBALS['select_multi_providers']) {
670 // what is multiple key around this $eid?
671 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
673 // obtain current list of providers regarding the multiple key
674 $providers_current = array();
675 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
676 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
678 // establish a WHERE clause
679 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = {$row['pc_multiple']}"; }
680 else { $whereClause = "pc_eid = $eid"; }
682 if ($_POST['recurr_affect'] == 'current') {
683 // update all existing event records to exlude the current date
684 foreach ($providers_current as $provider) {
685 // update the provider's original event
686 // get the original event's repeat specs
687 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
688 " WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
689 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
690 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
691 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
692 else { $oldRecurrspec['exdate'] .= $selected_date; }
694 // mod original event recur specs to exclude this date
695 sqlStatement("UPDATE openemr_postcalendar_events SET " .
696 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
697 " WHERE ". $whereClause);
700 else if ($_POST['recurr_affect'] == 'future') {
701 // update all existing event records to stop recurring on this date-1
702 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
703 foreach ($providers_current as $provider) {
704 // update the provider's original event
705 sqlStatement("UPDATE openemr_postcalendar_events SET " .
706 " pc_enddate = '" . $selected_date ."' ".
707 " WHERE ".$whereClause);
711 // really delete the event from the database
712 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
716 // =======================================
717 // single provider event
718 // =======================================
721 if ($_POST['recurr_affect'] == 'current') {
722 // mod original event recur specs to exclude this date
724 // get the original event's repeat specs
725 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = $eid");
726 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
727 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
728 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
729 else { $oldRecurrspec['exdate'] .= $selected_date; }
730 sqlStatement("UPDATE openemr_postcalendar_events SET " .
731 " pc_recurrspec = '" . serialize($oldRecurrspec) ."' ".
732 " WHERE pc_eid = '$eid'");
735 else if ($_POST['recurr_affect'] == 'future') {
736 // mod original event to stop recurring on this date-1
737 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
738 sqlStatement("UPDATE openemr_postcalendar_events SET " .
739 " pc_enddate = '" . $selected_date ."' ".
740 " WHERE pc_eid = '$eid'");
744 // fully delete the event from the database
745 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
750 if ($_POST['form_action'] != "") {
751 // Close this window and refresh the calendar display.
752 echo "<html>\n<body>\n<script language='JavaScript'>\n";
753 if ($info_msg) echo " alert('$info_msg');\n";
754 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
755 echo " window.close();\n";
756 echo "</script>\n</body>\n</html>\n";
760 //*********************************
761 // If we get this far then we are displaying the form.
762 //*********************************
766 '*' => xl('* Reminder done'),
767 '+' => xl('+ Chart pulled'),
768 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
769 '?' => xl('? No show'),
770 '@' => xl('@ Arrived'),
771 '~' => xl('~ Arrived late'),
772 '!' => xl('! Left w/o visit'),
773 '#' => xl('# Ins/fin issue'),
774 '<' => xl('< In exam room'),
775 '>' => xl('> Checked out'),
776 '$' => xl('$ Coding done'),
777 '%' => xl('% Cancelled < 24h ')
780 $repeats = 0; // if the event repeats
784 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
785 $patientname = xl('Click to select');
790 // If we are editing an existing event, then get its data.
792 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
793 // instead of using the event's starting date, keep what has been provided
794 // via the GET array, see the top of this file
795 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
796 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
797 $userid = $row['pc_aid'];
798 $patientid = $row['pc_pid'];
799 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
800 $starttimem = substr($row['pc_startTime'], 3, 2);
801 $repeats = $row['pc_recurrtype'];
802 $multiple_value = $row['pc_multiple'];
804 // parse out the repeating data, if any
805 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
806 $repeattype = $rspecs['event_repeat_freq_type'];
807 $repeatfreq = $rspecs['event_repeat_freq'];
808 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
810 $hometext = $row['pc_hometext'];
811 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
815 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
817 //-------------------------------------
819 //Set default facility for a new event based on the given 'userid'
821 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
822 $e2f = $pref_facility['facility_id'];
823 $e2f_name = $pref_facility['facility'];
825 //END of CHEMED -----------------------
828 // If we have a patient ID, get the name and phone numbers to display.
830 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
831 "FROM patient_data WHERE pid = '" . $patientid . "'");
832 $patientname = $prow['lname'] . ", " . $prow['fname'];
833 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
834 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
837 // Get the providers list.
838 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
839 "authorized != 0 AND active = 1 ORDER BY lname, fname");
841 // Get event categories.
842 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
843 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
845 // Fix up the time format for AM/PM.
847 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
849 if ($starttimeh > 12) $starttimeh -= 12;
855 <?php
html_header_show(); ?
>
856 <title
><?php
echo $eid ?
"Edit" : "Add New" ?
> <?php
xl('Event','e');?
></title
>
857 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
860 td
{ font
-size
:0.8em
; }
863 <style type
="text/css">@import
url(../../../library
/dynarch_calendar
.css
);</style
>
864 <script type
="text/javascript" src
="../../../library/topdialog.js"></script
>
865 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
866 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
867 <script type
="text/javascript" src
="../../../library/dynarch_calendar.js"></script
>
868 <script type
="text/javascript" src
="../../../library/dynarch_calendar_en.js"></script
>
869 <script type
="text/javascript" src
="../../../library/dynarch_calendar_setup.js"></script
>
872 // ============================================================================
873 // DBC SYSTEM JAVASCRIPT FILE
875 if ( $GLOBALS['dutchpc'] ) { ?
>
876 <script type
="text/javascript" src
="../../../library/js/add_edit_event.js"></script
>
879 // ============================================================================
882 <script language
="JavaScript">
884 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
886 var durations
= new Array();
887 // var rectypes = new Array();
889 // Read the event categories, generate their options list, and get
890 // the default event duration from them if this is a new event.
892 $prefcat_options = " <option value='0'>-- None --</option>\n";
895 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
897 while ($crow = sqlFetchArray($cres)) {
898 $duration = round($crow['pc_duration'] / 60);
899 if ($crow['pc_end_all_day']) $duration = 1440;
900 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
901 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
902 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
904 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
906 if ($crow['pc_catid'] == $default_catid) {
907 $catoptions .= " selected";
908 $thisduration = $duration;
911 $catoptions .= ">" . $crow['pc_catname'] . "</option>\n";
913 // This section is to build the list of preferred categories:
915 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
917 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
919 $prefcat_options .= ">" . $crow['pc_catname'] . "</option>\n";
925 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
927 // This is for callback by the find-patient popup.
928 function setpatient(pid
, lname
, fname
, dob
) {
929 var f
= document
.forms
[0];
930 f
.form_patient
.value
= lname +
', ' + fname
;
931 f
.form_pid
.value
= pid
;
932 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
933 document
.getElementById('dob_row').style
.display
= dobstyle
;
936 // This invokes the find-patient popup.
937 function sel_patient() {
938 dlgopen('find_patient_popup.php', '_blank', 500, 400);
941 // Do whatever is needed when a new event category is selected.
942 // For now this means changing the event title and duration.
943 function set_display() {
944 var f
= document
.forms
[0];
945 var s
= f
.form_category
;
946 if (s
.selectedIndex
>= 0) {
947 var catid
= s
.options
[s
.selectedIndex
].value
;
948 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
949 var style_prefcat
= document
.getElementById('title_prefcat').style
;
950 if (catid
== '2') { // In Office
951 style_apptstatus
.display
= 'none';
952 style_prefcat
.display
= '';
953 f
.form_apptstatus
.style
.display
= 'none';
954 f
.form_prefcat
.style
.display
= '';
956 style_prefcat
.display
= 'none';
957 style_apptstatus
.display
= '';
958 f
.form_prefcat
.style
.display
= 'none';
959 f
.form_apptstatus
.style
.display
= '';
964 // Do whatever is needed when a new event category is selected.
965 // For now this means changing the event title and duration.
966 function set_category() {
967 var f
= document
.forms
[0];
968 var s
= f
.form_category
;
969 if (s
.selectedIndex
>= 0) {
970 var catid
= s
.options
[s
.selectedIndex
].value
;
971 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
972 f
.form_duration
.value
= durations
[catid
];
977 // Modify some visual attributes when the all-day or timed-event
978 // radio buttons are clicked.
979 function set_allday() {
980 var f
= document
.forms
[0];
981 var color1
= '#777777';
982 var color2
= '#777777';
983 var disabled2
= true;
984 if (document
.getElementById('rballday1').checked
) {
987 if (document
.getElementById('rballday2').checked
) {
991 document
.getElementById('tdallday1').style
.color
= color1
;
992 document
.getElementById('tdallday2').style
.color
= color2
;
993 document
.getElementById('tdallday3').style
.color
= color2
;
994 document
.getElementById('tdallday4').style
.color
= color2
;
995 document
.getElementById('tdallday5').style
.color
= color2
;
996 f
.form_hour
.disabled
= disabled2
;
997 f
.form_minute
.disabled
= disabled2
;
998 f
.form_ampm
.disabled
= disabled2
;
999 f
.form_duration
.disabled
= disabled2
;
1002 // Modify some visual attributes when the Repeat checkbox is clicked.
1003 function set_repeat() {
1004 var f
= document
.forms
[0];
1005 var isdisabled
= true;
1006 var mycolor
= '#777777';
1007 var myvisibility
= 'hidden';
1008 if (f
.form_repeat
.checked
) {
1010 mycolor
= '#000000';
1011 myvisibility
= 'visible';
1013 f
.form_repeat_type
.disabled
= isdisabled
;
1014 f
.form_repeat_freq
.disabled
= isdisabled
;
1015 f
.form_enddate
.disabled
= isdisabled
;
1016 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
1017 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
1018 document
.getElementById('img_enddate').style
.visibility
= myvisibility
;
1021 // This is for callback by the find-available popup.
1022 function setappt(year
,mon
,mday
,hours
,minutes
) {
1023 var f
= document
.forms
[0];
1024 f
.form_date
.value
= '' + year +
'-' +
1025 ('' +
(mon +
100)).substring(1) +
'-' +
1026 ('' +
(mday +
100)).substring(1);
1027 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
1028 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
1029 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
1032 // Invoke the find-available popup.
1033 function find_available() {
1034 top
.restoreSession();
1035 // (CHEMED) Conditional value selection, because there is no <select> element
1036 // when making an appointment for a specific provider
1037 var s
= document
.forms
[0].form_provider
;
1038 <?php
if ($userid != 0) { ?
>
1039 s
= document
.forms
[0].form_provider
.value
;
1041 s
= document
.forms
[0].form_provider
.options
[s
.selectedIndex
].value
;
1043 var c
= document
.forms
[0].form_category
;
1044 var formDate
= document
.forms
[0].form_date
;
1045 dlgopen('find_appt_popup.php?providerid=' + s +
1046 '&catid=' + c
.options
[c
.selectedIndex
].value +
1047 '&startdate=' + formDate
.value
, '_blank', 500, 400);
1048 //END (CHEMED) modifications
1051 // ==============================
1053 function verify_selecteerbaar (a
) {
1054 var f
= document
.forms
[0]; var a
;
1055 if (f
.box5
.value
!= 0) a
= f
.box5
.value
;
1056 else if (f
.box4
.value
!= 0) a
= f
.box4
.value
;
1057 else if (f
.box3
.value
!= 0) a
= f
.box3
.value
;
1058 else if (f
.box2
.value
!= 0) a
= f
.box2
.value
;
1059 else if (f
.box1
.value
!= 0) a
= f
.box1
.value
;
1060 else { alert('You must choose an activity.'); return false;
1063 var answer
= $
.ajax({
1069 if ( answer
== 'false') { alert("Please select again"); return false; }
1077 if ( $GLOBALS['dutchpc'])
1080 <script type
="text/javascript">
1084 if ( $eid ) { // editing case
1088 } // EOS editing case
1094 } // EOS DBC DUTCH AJAX PART
1097 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8" />
1101 <body
class="body_top" onunload
='imclosing()'>
1103 <form method
='post' name
='theform' id
='theform' action
='add_edit_event.php?eid=<?php echo $eid ?>' />
1104 <input type
="hidden" name
="form_action" id
="form_action" value
="">
1105 <input type
="hidden" name
="recurr_affect" id
="recurr_affect" value
="">
1106 <!-- used
for recurring events
-->
1107 <input type
="hidden" name
="selected_date" id
="selected_date" value
="<?php echo $date; ?>">
1108 <input type
="hidden" name
="event_start_date" id
="event_start_date" value
="<?php echo $eventstartdate; ?>">
1111 <table border
='0' width
='100%'>
1114 <td width
='1%' nowrap
>
1115 <b
><?php
xl('Category','e'); ?
>:</b
>
1118 <select name
='form_category' onchange
='set_category()' style
='width:100%'>
1119 <?php
echo $catoptions ?
>
1122 <td width
='1%' nowrap
>
1124 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='1' id
='rballday1'
1125 <?php
if ($thisduration == 1440) echo "checked " ?
>/>
1127 <td colspan
='2' nowrap id
='tdallday1'>
1128 <?php
xl('All day event','e'); ?
>
1134 <b
><?php
xl('Date','e'); ?
>:</b
>
1137 <input type
='text' size
='10' name
='form_date' id
='form_date'
1138 value
='<?php echo $date ?>'
1139 title
='<?php xl('yyyy
-mm
-dd event date
or starting date
','e
'); ?>'
1140 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
1141 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1142 id
='img_date' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1143 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
1147 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='0' id
='rballday2' <?php
if ($thisduration != 1440) echo "checked " ?
>/>
1149 <td width
='1%' nowrap id
='tdallday2'>
1150 <?php
xl('Time','e'); ?
>
1152 <td width
='1%' nowrap id
='tdallday3'>
1153 <input type
='text' size
='2' name
='form_hour' value
='<?php echo $starttimeh ?>'
1154 title
='<?php xl('Event start time
','e
'); ?>' /> :
1155 <input type
='text' size
='2' name
='form_minute' value
='<?php echo $starttimem ?>'
1156 title
='<?php xl('Event start time
','e
'); ?>' /> 
;
1157 <select name
='form_ampm' title
='Note: 12:00 noon is PM, not AM'>
1158 <option value
='1'><?php
xl('AM','e'); ?
></option
>
1159 <option value
='2'<?php
if ($startampm == '2') echo " selected" ?
>><?php
xl('PM','e'); ?
></option
>
1165 <b
><?php
xl('Title','e'); ?
>:</b
>
1168 <input type
='text' size
='10' name
='form_title' value
='<?php echo addslashes($row['pc_title
']) ?>'
1170 title
='<?php xl('Event title
','e
'); ?>' />
1175 <td nowrap id
='tdallday4'><?php
xl('duration','e'); ?
>
1177 <td nowrap id
='tdallday5'>
1178 <input type
='text' size
='4' name
='form_duration' value
='<?php echo $thisduration ?>' title
='<?php xl('Event duration in minutes
','e
'); ?>' />
1179 <?php
xl('minutes','e'); ?
>
1184 // =============================================
1185 // DBC DUTCH SYSTEMS
1187 if ( $GLOBALS['dutchpc'] ) { ?
>
1189 <td colspan
="3"> 
;</td
>
1191 <td
><input type
='text' name
='form_duration_indirect' id
='form_duration_indirect' size
='4'
1192 value
='<?php if ( isset($timerow['indirect_time
']) ) echo $timerow['indirect_time
']; ?>'/>minutes
</td
>
1195 <td colspan
="3"> 
;</td
>
1197 <td
><input type
='text' name
='form_duration_travel' name
='form_duration_travel' size
='4'
1198 value
='<?php if ( isset($timerow['travel_time
']) ) echo $timerow['travel_time
']; ?>'/>minutes
</td
>
1201 // =======================================================
1203 // cascading dropdowns
1204 // =======================================================
1205 if ( $GLOBALS['dutchpc'] ) {
1206 if ( $eid ) { // editing mode
1207 $activ = what_activity( $singleeid );
1209 if ( empty($activ) ) {
1210 $activ = "No activity selected.";
1212 $activ = what_full_sysid($activ);
1213 $_SESSION['editactiv'] = FALSE;
1217 // end DBC DUTCH SYSTEM
1220 <td
><b
>Current activity
:</b
><br
/><a href
="#" id
="addc"><
;<
;Add
/Change
>
;>
;</a
></td
>
1221 <td
><?
=$activ?
><br
/> <td colspan
="3"> 
;</td
></td
>
1224 <td nowrap
><b
>Activiteit
:</b
></td
>
1225 <td width
='1%' nowrap
>
1226 <select name
="box1" id
="box1">
1228 $rlvone = records_level1('ev');
1229 foreach ($rlvone as $rlv) {
1230 echo '<option value=\'' .$rlv['cl_activiteit_code']. '\'>' .$rlv['cl_activiteit_element']. '</option>';
1234 <td colspan
="3"><?php
if ( $patientid ) $are = has_ztndbc($patientid); else $are = ' '; ?
>
1235 <p style
="background-color: #78AEBC; padding: 3px; text-align: center"><?
=$are['str']?
></p
>
1239 <tr colspan
="2"><td
></td
><td
>
1240 <select id
="box2" name
="box2">
1243 <tr colspan
="2"><td
></td
><td
>
1244 <select id
="box3" name
="box3"></select
>
1247 <tr colspan
="2"><td
></td
><td
>
1248 <select id
="box4" name
="box4"></select
>
1251 <tr colspan
="2"><td
></td
><td
>
1252 <select id
="box5" name
="box5"></select
>
1258 <td nowrap
><b
><?php
xl('Facility','e'); ?
>:</b
></td
>
1261 if ($userid != 0) { ?
>
1262 <input type
='hidden' name
="facility" id
="facility" value
='<?php echo $e2f; ?>'/>
1263 <input type
='input' readonly name
="facility_txt" value
='<?php echo $e2f_name; ?>'/>
1265 <select name
="facility" id
="facility" >
1268 // ===========================
1269 // EVENTS TO FACILITIES
1270 //(CHEMED) added service_location WHERE clause
1271 // get the facilities
1272 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1273 while ($facrow = sqlFetchArray($qsql)) {
1274 $selected = ( $facrow['id'] == $e2f ) ?
'selected="selected"' : '' ;
1275 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1278 // ===========================
1281 //END (CHEMED) IF ?>
1288 <b
><?php
xl('Patient','e'); ?
>:</b
>
1291 <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
/>
1292 <input type
='hidden' name
='form_pid' value
='<?php echo $patientid ?>' />
1294 <td colspan
='3' nowrap style
='font-size:8pt'>
1296 <span
class="infobox">
1297 <?php
if ($patienttitle != "") { echo $patienttitle; } ?
>
1304 <b
><?php
xl('Provider','e'); ?
>:</b
>
1310 // =======================================
1312 // =======================================
1313 if ($GLOBALS['select_multi_providers']) {
1315 // there are two posible situations: edit and new record
1317 // this is executed only on edit ($eid)
1319 if ( $multiple_value ) {
1320 // find all the providers around multiple key
1321 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = $multiple_value");
1322 while ($r = sqlFetchArray($qall)) {
1323 $providers_array[] = $r['providers'];
1326 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1327 $providers_array = sqlFetchArray($qall);
1331 // build the selection tool
1332 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1334 while ($urow = sqlFetchArray($ures)) {
1335 echo " <option value='" . $urow['id'] . "'";
1338 if ( in_array($urow['id'], $providers_array) ||
($urow['id'] == $userid) ) echo " selected";
1341 echo ">" . $urow['lname'];
1342 if ($urow['fname']) echo ", " . $urow['fname'];
1348 // =======================================
1350 // =======================================
1354 // get provider from existing event
1355 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = $eid");
1356 $provider = sqlFetchArray($qprov);
1357 $defaultProvider = $provider['pc_aid'];
1360 // this is a new event so smartly choose a default provider
1362 // default to the currently logged-in user
1363 $defaultProvider = $_SESSION['authUserID'];
1365 // or, if we have chosen a provider in the calendar, default to them
1366 // choose the first one if multiple have been selected
1367 if (count($_SESSION['pc_username']) >= 1) {
1368 // get the numeric ID of the first provider in the array
1369 $pc_username = $_SESSION['pc_username'];
1370 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1371 $defaultProvider = $firstProvider['id'];
1375 echo "<select name='form_provider' style='width:100%' />";
1376 while ($urow = sqlFetchArray($ures)) {
1377 echo " <option value='" . $urow['id'] . "'";
1378 if ($urow['id'] == $defaultProvider) echo " selected";
1379 echo ">" . $urow['lname'];
1380 if ($urow['fname']) echo ", " . $urow['fname'];
1391 <input type
='checkbox' name
='form_repeat' onclick
='set_repeat(this)' value
='1'<?php
if ($repeats) echo " checked" ?
>/>
1392 <input type
='hidden' name
='form_repeat_exdate' id
='form_repeat_exdate' value
='<?php echo $repeatexdate; ?>' /> <!-- dates excluded from the repeat
-->
1394 <td nowrap id
='tdrepeat1'><?php
xl('Repeats','e'); ?
>
1398 <select name
='form_repeat_freq' title
='Every, every other, every 3rd, etc.'>
1400 foreach (array(1 => 'every', 2 => '2nd', 3 => '3rd', 4 => '4th', 5 => '5th', 6 => '6th')
1403 echo " <option value='$key'";
1404 if ($key == $repeatfreq) echo " selected";
1405 echo ">$value</option>\n";
1410 <select name
='form_repeat_type'>
1412 // See common.api.php for these:
1413 foreach (array(0 => 'day' , 4 => 'workday', 1 => 'week', 2 => 'month', 3 => 'year')
1416 echo " <option value='$key'";
1417 if ($key == $repeattype) echo " selected";
1418 echo ">$value</option>\n";
1428 <span id
='title_apptstatus'><b
><?php
xl('Status','e'); ?
>:</b
></span
>
1429 <span id
='title_prefcat' style
='display:none'><b
><?php
xl('Pref Cat','e'); ?
>:</b
></span
>
1433 <select name
='form_apptstatus' style
='width:100%' title
='<?php xl('Appointment status
','e
'); ?>'>
1435 foreach ($statuses as $key => $value) {
1436 echo " <option value='$key'";
1437 if ($key == $row['pc_apptstatus']) echo " selected";
1438 echo ">" . htmlspecialchars($value) . "</option>\n";
1443 The following
list will be invisible unless this is an In Office
1444 event
, in which
case form_apptstatus (above
) is to be invisible
.
1446 <select name
='form_prefcat' style
='width:100%;display:none' title
='<?php xl('Preferred Event Category
','e
');?>'>
1447 <?php
echo $prefcat_options ?
>
1454 <td nowrap id
='tdrepeat2'><?php
xl('until','e'); ?
>
1457 <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
');?>' />
1458 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1459 id
='img_enddate' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1460 title
='<?php xl('Click here to choose a date
','e
');?>'>
1462 if ($repeatexdate != "") {
1463 $tmptitle = "The following dates are excluded from the repeating series";
1464 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1465 else { $tmptitle .= "\n"; }
1466 $exdates = explode(",", $repeatexdate);
1467 foreach ($exdates as $exdate) {
1468 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1470 echo "<a href='#' title='$tmptitle' alt='$tmptitle'><img src='../../pic/warning.gif' title='$tmptitle' alt='*!*' style='border:none;'/></a>";
1478 <b
><?php
xl('Comments','e'); ?
>:</b
>
1480 <td colspan
='4' nowrap
>
1481 <input type
='text' size
='40' name
='form_comments' style
='width:100%' value
='<?php echo $hometext ?>' title
='<?php xl('Optional information about this event
','e
');?>' />
1486 // DOB is important for the clinic, so if it's missing give them a chance
1487 // to enter it right here. We must display or hide this row dynamically
1488 // in case the patient-select popup is used.
1489 $patient_dob = trim($prow['DOB']);
1490 $dobstyle = ($prow && (!$patient_dob ||
substr($patient_dob, 5) == '00-00')) ?
1493 <tr id
='dob_row' style
='display:<?php echo $dobstyle ?>'>
1494 <td colspan
='4' nowrap
>
1495 <b
><font color
='red'><?php
xl('DOB is missing, please enter if possible','e'); ?
>:</font
></b
>
1498 <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)' />
1499 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1500 id
='img_dob' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1501 title
='<?php xl('Click here to choose a date
','e
');?>'>
1508 <input type
='button' name
='form_save' id
='form_save' value
='<?php xl('Save
','e
');?>' />
1510 <input type
='button' id
='find_available' value
='<?php xl('Find Available
','e
');?>' />
1512 <input type
='button' name
='form_delete' id
='form_delete' value
='<?php xl('Delete
','e
');?>'<?php
if (!$eid) echo " disabled" ?
> />
1514 <input type
='button' id
='cancel' value
='<?php xl('Cancel
','e
');?>' />
1519 <div id
="recurr_popup" style
="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1520 Apply the changes to the Current event only
, to this
and all Future occurrences
, or to All occurances?
1522 <input type
="button" name
="all_events" id
="all_events" value
=" All ">
1523 <input type
="button" name
="future_events" id
="future_events" value
="Future">
1524 <input type
="button" name
="current_event" id
="current_event" value
="Current">
1525 <input type
="button" name
="recurr_cancel" id
="recurr_cancel" value
="Cancel">
1530 <script language
='JavaScript'>
1531 <?php
if ($eid) { ?
>
1539 Calendar
.setup({inputField
:"form_date", ifFormat
:"%Y-%m-%d", button
:"img_date"});
1540 Calendar
.setup({inputField
:"form_enddate", ifFormat
:"%Y-%m-%d", button
:"img_enddate"});
1541 Calendar
.setup({inputField
:"form_dob", ifFormat
:"%Y-%m-%d", button
:"img_dob"});
1544 <script language
="javascript">
1545 // jQuery stuff to make the page a little easier to use
1547 $
(document
).ready(function(){
1548 $
("#form_save").click(function() { validate(); });
1549 $
("#find_available").click(function() { find_available(); });
1550 $
("#form_delete").click(function() { deleteEvent(); });
1551 $
("#cancel").click(function() { window
.close(); });
1553 // buttons affecting the modification of a repeating event
1554 $
("#all_events").click(function() { $
("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1555 $
("#future_events").click(function() { $
("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1556 $
("#current_event").click(function() { $
("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1557 $
("#recurr_cancel").click(function() { $
("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1560 // Check for errors when the form is submitted.
1561 function validate() {
1562 var f
= document
.getElementById('theform');
1563 if (f
.form_repeat
.checked
&&
1564 (! f
.form_enddate
.value || f
.form_enddate
.value
< f
.form_date
.value
)) {
1565 alert('An end date later than the start date is required for repeated events!');
1568 $
('#form_action').val("save");
1570 <?php
if ($repeats): ?
>
1571 // existing repeating events need additional prompt
1572 if ($
("#recurr_affect").val() == "") {
1574 // show the current/future/all DIV for the user to choose one
1575 $
("#recurr_popup").css("visibility", "visible");
1580 return SubmitForm();
1583 // disable all the form elements outside the recurr_popup
1584 function DisableForm() {
1585 $
("#theform").children().attr("disabled", "true");
1587 function EnableForm() {
1588 $
("#theform").children().removeAttr("disabled");
1590 // hide the recurring popup DIV
1591 function HideRecurrPopup() {
1592 $
("#recurr_popup").css("visibility", "hidden");
1595 function deleteEvent() {
1596 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?")) {
1597 $
('#form_action').val("delete");
1599 <?php
if ($repeats): ?
>
1600 // existing repeating events need additional prompt
1601 if ($
("#recurr_affect").val() == "") {
1603 // show the current/future/all DIV for the user to choose one
1604 $
("#recurr_popup").css("visibility", "visible");
1609 return SubmitForm();
1614 function SubmitForm() {
1615 // DBC Dutch System validation
1616 <?php
if ( $GLOBALS['dutchpc'] && $_SESSION['editactiv']) { ?
>
1617 var a
= verify_selecteerbaar();
1618 if ( !a
) return false;
1622 $
('#theform').submit();
1623 top
.restoreSession();