5 * Modified from interface/main/calendar/add_edit_event.php for
8 * Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
9 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
23 * @author Rod Roark <rod@sunsetsystems.com>
24 * @author Jerry Padgett <sjpadgett@gmail.com>
25 * @link http://www.open-emr.org
32 //landing page definition -- where to go if something goes wrong
33 $landingpage = "index.php?site=".$_SESSION['site_id'];
36 // kick out if patient not authenticated
37 if ( isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two']) ) {
38 $pid = $_SESSION['pid'];
42 header('Location: '.$landingpage.'&w');
50 include_once("../interface/globals.php");
51 include_once("$srcdir/patient.inc");
52 include_once("$srcdir/forms.inc");
54 // Exit if the modify calendar for portal flag is not set-pulled for v5
55 /* if (!($GLOBALS['portal_onsite_appt_modify'])) {
56 echo add_escape_custom( xl('You are not authorized to schedule appointments.'),ENT_NOQUOTES);
60 // Things that might be passed by our opener.
62 $eid = $_GET['eid']; // only for existing events
63 $date = $_GET['date']; // this and below only for new events
64 $userid = $_GET['userid'];
65 $default_catid = $_GET['catid'] ?
$_GET['catid'] : '5';
66 $patientid = $_GET['patid'];
70 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
72 $date = date("Y-m-d");
75 if (isset($_GET['starttimem']))
76 $starttimem = substr('00' . $_GET['starttimem'], -2);
78 if (isset($_GET['starttimeh'])) {
79 $starttimeh = $_GET['starttimeh'];
80 if (isset($_GET['startampm'])) {
81 if ($_GET['startampm'] == '2' && $starttimeh < 12)
85 $starttimeh = date("G");
91 // ===========================
92 // EVENTS TO FACILITIES (lemonsoftware)
93 // edit event case - if there is no association made, then insert one with the first facility
96 $facility = sqlQuery("SELECT pc_facility, pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
97 if ( !$facility['pc_facility'] ) {
98 $qmin = sqlQuery("SELECT MIN(id) as minId FROM facility");
99 $min = $qmin['minId'];
101 // multiple providers case
102 if ( $GLOBALS['select_multi_providers'] ) {
103 $mul = $facility['pc_multiple'];
104 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
108 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
111 $e2f = $facility['pc_facility'];
115 // ===========================
116 // ===========================
118 // EVENTS TO FACILITIES (lemonsoftware)
119 //(CHEMED) get facility name
120 // edit event case - if there is no association made, then insert one with the first facility
123 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
124 FROM openemr_postcalendar_events
125 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
126 WHERE pc_eid = $eid");
127 if ( !$facility['pc_facility'] ) {
128 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
129 $min = $qmin['minId'];
130 $min_name = $qmin['facility'];
132 // multiple providers case
133 if ( $GLOBALS['select_multi_providers'] ) {
134 $mul = $facility['pc_multiple'];
135 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
139 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
141 $e2f_name = $min_name;
143 $e2f = $facility['pc_facility'];
144 $e2f_name = $facility['name'];
148 // ===========================
151 // If we are saving, then save and close the window.
153 if ($_POST['form_action'] == "save") {
156 $event_date = fixDate($_POST['form_date']);
158 // Compute start and end time strings to be saved.
159 if ($_POST['form_allday']) {
164 $tmph = $_POST['form_hour'] +
0;
165 $tmpm = $_POST['form_minute'] +
0;
166 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph +
= 12;
167 $duration = $_POST['form_duration'];
169 $starttime = "$tmph:$tmpm:00";
172 while ($tmpm >= 60) {
176 $endtime = "$tmph:$tmpm:00";
178 // Useless garbage that we must save.
179 $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' .
180 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}';
182 // More garbage, but this time 1 character of it is used to save the
184 if ($_POST['form_repeat']) {
185 $recurrspec = 'a:5:{' .
186 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' .
187 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' .
188 's:19:"event_repeat_on_num";s:1:"1";' .
189 's:19:"event_repeat_on_day";s:1:"0";' .
190 's:20:"event_repeat_on_freq";s:1:"0";}';
192 $recurrspec = 'a:5:{' .
193 's:17:"event_repeat_freq";N;' .
194 's:22:"event_repeat_freq_type";s:1:"0";' .
195 's:19:"event_repeat_on_num";s:1:"1";' .
196 's:19:"event_repeat_on_day";s:1:"0";' .
197 's:20:"event_repeat_on_freq";s:1:"1";}';
200 //The modification of the start date for events that take place on one day of the week
201 //for example monday, or thursday. We set the start date on the first day of the week
202 //that the event is scheduled. For example if you set the event to repeat on each monday
203 //the start date of the event will be set on the first monday after the day the event is scheduled
204 if($_POST['form_repeat_type'] == 5)
206 $exploded_date= explode("-",$event_date);
207 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
209 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
211 elseif($edate=="Wed") {
212 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
214 elseif($edate=="Thu") {
215 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
217 elseif($edate=="Fri") {
218 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
220 elseif($edate=="Sat") {
221 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
223 elseif($edate=="Sun") {
224 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
226 } elseif($_POST['form_repeat_type'] == 6) {
227 $exploded_date= explode("-",$event_date);
228 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
230 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
232 elseif($edate=="Thu") {
233 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
235 elseif($edate=="Fri") {
236 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
238 elseif($edate=="Sat") {
239 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
241 elseif($edate=="Sun") {
242 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
244 elseif($edate=="Mon") {
245 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
247 } elseif($_POST['form_repeat_type'] == 7) {
248 $exploded_date= explode("-",$event_date);
249 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
251 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
253 elseif($edate=="Fri") {
254 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
256 elseif($edate=="Sat") {
257 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
259 elseif($edate=="Sun") {
260 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
262 elseif($edate=="Mon") {
263 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
265 elseif($edate=="Tue") {
266 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
268 } elseif($_POST['form_repeat_type'] == 8) {
269 $exploded_date= explode("-",$event_date);
270 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
272 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
274 elseif($edate=="Sat") {
275 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
277 elseif($edate=="Sun") {
278 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
280 elseif($edate=="Mon") {
281 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
283 elseif($edate=="Tue") {
284 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
286 elseif($edate=="Wed") {
287 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
289 } elseif($_POST['form_repeat_type'] == 9) {
290 $exploded_date= explode("-",$event_date);
291 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
293 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
295 elseif($edate=="Sun") {
296 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
298 elseif($edate=="Mon") {
299 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
301 elseif($edate=="Tue") {
302 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
304 elseif($edate=="Wed") {
305 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
307 elseif($edate=="Thu") {
308 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
311 /* =======================================================
313 ========================================================*/
316 // what is multiple key around this $eid?
317 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
319 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
320 /* ==========================================
321 // multi providers BOS
322 ==========================================*/
324 // obtain current list of providers regarding the multiple key
325 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
326 while ($current = sqlFetchArray($up)) {
327 $providers_current[] = $current['pc_aid'];
330 $providers_new = $_POST['form_provider_ae'];
332 // this difference means that some providers from current was UNCHECKED
333 // so we must delete this event for them
334 $r1 = array_diff ($providers_current, $providers_new);
336 foreach ($r1 as $to_be_removed) {
337 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
341 // this difference means that some providers was added
342 // so we must insert this event for them
343 $r2 = array_diff ($providers_new, $providers_current);
345 foreach ($r2 as $to_be_inserted) {
346 sqlInsert("INSERT INTO openemr_postcalendar_events ( pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility)
348 "'" . $_POST['form_category'] . "', " .
349 "'" . $row['pc_multiple'] . "', " .
350 "'" . $to_be_inserted . "', " .
351 "'" . $_POST['form_pid'] . "', " .
352 "'" . add_escape_custom($_POST['form_title']) . "', " .
354 "'" . add_escape_custom($_POST['form_comments']) . "', " .
355 "'" . $_SESSION['providerId'] . "', " .
356 "'" . $event_date . "', " .
357 "'" . fixDate($_POST['form_enddate']) . "', " .
358 "'" . ($duration * 60) . "', " .
359 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
363 "'" . $_POST['form_allday'] . "', " .
364 "'" . $_POST['form_apptstatus'] . "', " .
365 "'" . $_POST['form_prefcat'] . "', " .
366 "'$locationspec', " .
368 "1, " .(int)$_POST['facility']. " )"); // FF stuff
373 // after the two diffs above, we must update for remaining providers
374 // those who are intersected in $providers_current and $providers_new
375 foreach ($_POST['form_provider_ae'] as $provider) {
376 sqlStatement("UPDATE openemr_postcalendar_events SET " .
377 "pc_catid = '" . $_POST['form_category'] . "', " .
378 "pc_pid = '" . $_POST['form_pid'] . "', " .
379 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
380 "pc_time = NOW(), " .
381 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
382 "pc_informant = '" . $_SESSION['providerId'] . "', " .
383 "pc_eventDate = '" . $event_date . "', " .
384 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
385 "pc_duration = '" . ($duration * 60) . "', " .
386 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
387 "pc_recurrspec = '$recurrspec', " .
388 "pc_startTime = '$starttime', " .
389 "pc_endTime = '$endtime', " .
390 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
391 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
392 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
393 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
394 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
397 /* ==========================================
398 // multi providers EOS
399 ==========================================*/
401 } elseif ( !$row['pc_multiple'] ) {
402 if ( $GLOBALS['select_multi_providers'] ) {
403 $prov = $_POST['form_provider_ae'][0];
405 $prov = $_POST['form_provider_ae'];
408 // simple provider case
409 sqlStatement("UPDATE openemr_postcalendar_events SET " .
410 "pc_catid = '" . $_POST['form_category'] . "', " .
411 "pc_aid = '" . $prov . "', " .
412 "pc_pid = '" . $_POST['form_pid'] . "', " .
413 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
414 "pc_time = NOW(), " .
415 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
416 "pc_informant = '" . $_SESSION['providerId'] . "', " .
417 "pc_eventDate = '" . $event_date . "', " .
418 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
419 "pc_duration = '" . ($duration * 60) . "', " .
420 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
421 "pc_recurrspec = '$recurrspec', " .
422 "pc_startTime = '$starttime', " .
423 "pc_endTime = '$endtime', " .
424 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
425 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
426 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
427 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
428 "WHERE pc_eid = '$eid'");
432 // =======================================
433 // EOS multi providers case
434 // =======================================
436 // EVENTS TO FACILITIES
440 /* =======================================================
442 ========================================================*/
445 // =======================================
446 // multi providers case
447 // =======================================
449 if (is_array($_POST['form_provider_ae'])) {
451 // obtain the next available unique key to group multiple providers around some event
452 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
453 $max = sqlFetchArray($q);
454 $new_multiple_value = $max['max'] +
1;
456 foreach ($_POST['form_provider_ae'] as $provider) {
457 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
458 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
459 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
460 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
461 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
463 "'" . $_POST['form_category'] . "', " .
464 "'" . $new_multiple_value . "', " .
465 "'" . $provider . "', " .
466 "'" . $_POST['form_pid'] . "', " .
467 "'" . add_escape_custom($_POST['form_title']) . "', " .
469 "'" . add_escape_custom($_POST['form_comments']) . "', " .
470 "'" . $_SESSION['providerId'] . "', " .
471 "'" . $event_date . "', " .
472 "'" . fixDate($_POST['form_enddate']) . "', " .
473 "'" . ($duration * 60) . "', " .
474 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
478 "'" . $_POST['form_allday'] . "', " .
479 "'" . $_POST['form_apptstatus'] . "', " .
480 "'" . $_POST['form_prefcat'] . "', " .
481 "'$locationspec', " .
483 "1, " .(int)$_POST['facility']. " )"); // FF stuff
488 $_POST['form_apptstatus'] = '^';
489 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
490 "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
491 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
492 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
493 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
495 "'" . $_POST['form_category'] . "', " .
496 "'" . $_POST['form_provider_ae'] . "', " .
497 "'" . $_POST['form_pid'] . "', " .
498 "'" . add_escape_custom($_POST['form_title']) . "', " .
500 "'" . add_escape_custom($_POST['form_comments']) . "', " .
501 "'" . $_SESSION['providerId'] . "', " .
502 "'" . $event_date . "', " .
503 "'" . fixDate($_POST['form_enddate']) . "', " .
504 "'" . ($duration * 60) . "', " .
505 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
509 "'" . $_POST['form_allday'] . "', " .
510 "'" . $_POST['form_apptstatus'] . "', " .
511 "'" . $_POST['form_prefcat'] . "', " .
512 "'$locationspec', " .
514 "1," .(int)$_POST['facility']. ")"); // FF stuff
518 // Save new DOB if it's there.
519 $patient_dob = trim($_POST['form_dob']);
520 if ($patient_dob && $_POST['form_pid']) {
521 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
522 "pid = '" . $_POST['form_pid'] . "'");
525 // Auto-create a new encounter if appropriate.
528 /* if ($GLOBALS['auto_create_new_encounters'] &&
529 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
532 // We decided not to auto-create blank enconter when user arrives. Todd's decision 18 Jun 2010
533 // Applied by Cassian Lup (cassian.lup@clinicdr.com)
536 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
537 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
538 if ($tmprow['count'] == 0) {
539 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
540 $_POST['form_provider_ae'] . "'");
541 $username = $tmprow['username'];
542 $facility = $tmprow['facility'];
543 $facility_id = $tmprow['facility_id'];
544 $conn = $GLOBALS['adodb']['db'];
545 $encounter = $conn->GenID("sequences");
546 addForm($encounter, "New Patient Encounter",
547 sqlInsert("INSERT INTO form_encounter SET " .
548 "date = '$event_date', " .
549 "onset_date = '$event_date', " .
550 "reason = '" . add_escape_custom($_POST['form_comments']) . "', " .
551 "facility = '$facility', " .
552 "facility_id = '$facility_id', " .
553 "pid = '" . $_POST['form_pid'] . "', " .
554 "encounter = '$encounter'"
556 "newpatient", $_POST['form_pid'], "1", "NOW()", $username
558 $info_msg .= "New encounter $encounter was created. ";
563 else if ($_POST['form_action'] == "delete") {
564 // =======================================
565 // multi providers case
566 // =======================================
567 if ($GLOBALS['select_multi_providers']) {
568 // what is multiple key around this $eid?
569 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
570 if ( $row['pc_multiple'] ) {
571 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_multiple = {$row['pc_multiple']}");
573 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = $eid");
575 // =======================================
576 // EOS multi providers case
577 // =======================================
579 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
583 if ($_POST['form_action'] != "") {
585 $_SESSION['whereto'] = 'appointmentpanel';
586 header('Location:./home.php');
589 // If we get this far then we are displaying the form.
593 '*' => xl('* Reminder done'),
594 '+' => xl('+ Chart pulled'),
595 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
596 '?' => xl('? No show'),
597 '@' => xl('@ Arrived'),
598 '~' => xl('~ Arrived late'),
599 '!' => xl('! Left w/o visit'),
600 '#' => xl('# Ins/fin issue'),
601 '<' => xl('< In exam room'),
602 '>' => xl('> Checked out'),
603 '$' => xl('$ Coding done'),
604 '^' => xl('^ Pending'),
607 $repeats = 0; // if the event repeats
614 // If we are editing an existing event, then get its data.
616 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
617 $date = $row['pc_eventDate'];
618 $userid = $row['pc_aid'];
619 $patientid = $row['pc_pid'];
620 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
621 $starttimem = substr($row['pc_startTime'], 3, 2);
622 $repeats = $row['pc_recurrtype'];
623 $multiple_value = $row['pc_multiple'];
625 if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
626 $repeattype = $matches[1];
628 if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
629 $repeatfreq = $matches[1];
631 $hometext = $row['pc_hometext'];
632 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
635 $patientid=$_GET['pid'];
638 // If we have a patient ID, get the name and phone numbers to display.
640 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
641 "FROM patient_data WHERE pid = '" . $patientid . "'");
642 $patientname = $prow['lname'] . ", " . $prow['fname'];
643 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
644 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
647 // Get the providers list.
648 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
649 "authorized != 0 AND active = 1 ORDER BY lname, fname");
651 //-------------------------------------
653 //Set default facility for a new event based on the given 'userid'
655 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
656 $e2f = $pref_facility['facility_id'];
657 $e2f_name = $pref_facility['facility'];
659 //END of CHEMED -----------------------
661 // Get event categories.
662 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
663 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
665 // Fix up the time format for AM/PM.
667 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
669 if ($starttimeh > 12) $starttimeh -= 12;
675 <?php
//html_header_show(); ?>
676 <title
><?php
echo $eid ?
"Edit" : "Add New" ?
> <?php
xl('Event','e');?
></title
>
677 <link href
="assets/css/style.css?v=<?php echo $v_js_includes; ?>" rel
="stylesheet" type
="text/css" />
678 <style type
="text/css">@import
url(../library
/dynarch_calendar
.css
);</style
>
679 <script type
="text/javascript" src
="../library/topdialog.js?v=<?php echo $v_js_includes; ?>"></script
>
680 <script type
="text/javascript" src
="../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
681 <script type
="text/javascript" src
="../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
682 <script type
="text/javascript" src
="../library/dynarch_calendar.js"></script
>
683 <script type
="text/javascript" src
="../library/dynarch_calendar_en.js"></script
>
684 <script type
="text/javascript" src
="../library/dynarch_calendar_setup.js"></script
>
688 <body
class="body_top" >
690 <form method
='post' name
='theaddform' id
='theaddform' action
='add_edit_event_user.php?eid=<?php echo $eid ?>'>
691 <input type
="hidden" name
="form_action" id
="form_action" value
="">
692 <input type
='hidden' name
='form_category' id
='form_category' value
='<?php echo $row['pc_catid
'] ? $row['pc_catid
'] : '5'; ?>' />
693 <input type
='hidden' name
='form_apptstatus' id
='form_apptstatus' value
='<?php echo $row['pc_apptstatus
'] ? $row['pc_apptstatus
'] : "^" ?>' />
694 <table border
='0' width
='100%'>
696 <td width
='1%' nowrap
>
697 <b
><?php
xl('Visit','e'); ?
>: </b
>
699 <td nowrap style
='padding:0px 5px 5px 0'>
700 <input
class="form-control input-md" type
="text" id
='form_title' name
='form_title' value
='<?php echo htmlspecialchars($row['pc_title
'],ENT_QUOTES) ? htmlspecialchars(['pc_title
'],ENT_QUOTES) : 'Office Visit
'; ?>' readonly
='readonly'/>
703 <td width
='1%' nowrap
>
704 <b
><?php
xl('Date','e'); ?
>:</b
>
706 <td colspan
='2' nowrap id
='tdallday1'>
707 <input
class="form-control input-md" type
='text' size
='10' name
='form_date' readonly id
='form_date'
708 value
='<?php if (isset($eid)) { echo $eid ? $row['pc_eventDate
'] : $date; } ?>'
709 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
714 <b
><?php
//xl('Title','e'); ?></b>
716 <td style
='padding:0px 5px 5px 0' nowrap
>
717 <!-- <input
class="form-control input-md" type
='text' size
='10' name
='form_title' readonly value
='<?php //echo htmlspecialchars($row['pc_title
'],ENT_QUOTES) ?>' title
='<?php //xl('Event title
','e
'); ?>' /> -->
721 <td width
='1%' nowrap id
='tdallday2'>
722 <b
><?php
xl('Time','e');?
>:</b
>
724 <td width
='1%' nowrap id
='tdallday3'>
725 <input
class="form-control inline" type
='text' size
='2' name
='form_hour' value
='<?php if(isset($eid)) { echo $starttimeh; } ?>'
726 title
='<?php xl('Event start time
','e
'); ?>' readonly
/> :
727 <input
class="form-control inline" type
='text' size
='2' name
='form_minute' value
='<?php if(isset($eid)) { echo $starttimem; } ?>'
728 title
='<?php xl('Event start time
','e
'); ?>' readonly
/> 
; <!-- -->
729 <select
class="form-control" name
='form_ampm' title
='Note: 12:00 noon is PM, not AM' readonly
>
730 <option value
='1'><?php
xl('AM','e'); ?
></option
>
731 <option value
='2'<?php
if ($startampm == '2') echo " selected" ?
>><?php
xl('PM','e'); ?
></option
>
737 <b
><?php
xl('Patient','e'); ?
>:</b
>
739 <td style
='padding:0px 5px 5px 0' nowrap
>
740 <input
class="form-control input-md" type
='text' size
='10' id
='form_patient' name
='form_patient'' value='<?php
echo $patientname ?
>' title='Patient
' readonly />
741 <input type='hidden
' name='form_pid
' value='<?php
echo $patientid ?
>' />
746 <td nowrap id='tdallday4
'><?php xl('Duration
','e
'); ?></td>
747 <td nowrap id='tdallday5
'>
748 <!-- --> <input class="form-control input-md" type='text
' size='1' name='form_duration
' value='<?php
echo $row['pc_duration'] ?
($row['pc_duration']*1/60) : "0" ?
>' readonly /><?php echo xl('minutes
'); ?>
755 <b><?php xl('Provider
','e
'); ?>:</b>
757 <td style='padding
:0px
5px
5px
0' nowrap>
758 <select class="form-control input-md" name='form_provider_ae
' id='form_provider_ae
' onchange='change_provider();'>
760 // present a list of providers to choose from
761 // default to the currently logged-in user
762 while ($urow = sqlFetchArray($ures)) {
763 echo " <option value='" . $urow['id'] . "'";
764 if (($urow['id
'] == $_GET['userid
'])||($urow['id
']== $userid)) echo " selected";
765 echo ">" . $urow['lname
'];
766 if ($urow['fname
']) echo ", " . $urow['fname
'];
772 <td nowrap style='font
-size
:8pt
'>
774 <td><input type='button
' class='btn btn
-danger btn
-sm
' value='<?php
xl('Openings','e');?
>' onclick='find_available()' /></td>
779 <b><?php xl('Reason
','e
'); ?>:</b>
781 <td style='padding
:0px
5px
5px
0' colspan='4' nowrap>
782 <input class="form-control input-md" type='text
' size='40' name='form_comments
' style='width
:100%
' value='<?php
echo htmlspecialchars($hometext,ENT_QUOTES
) ?
>' title='<?php
xl('Optional information about this event','e');?
>' />
787 <input type='button
' name='form_save
' class='btn btn
-success btn
-md
' onsubmit='return false' value='<?php
xl('Save','e');?
>' onclick="validate()" />
792 var mypcc = '<?php
echo $GLOBALS['phone_country_code'] ?
>';
794 var durations = new Array();
795 // var rectypes = new Array();
797 // Read the event categories, generate their options list, and get
798 // the default event duration from them if this is a new event.
800 $prefcat_options = " <option value='0'>-- None --</option>\n";
803 $thisduration = $row['pc_alldayevent
'] ? 1440 : round($row['pc_duration
'] / 60);
805 while ($crow = sqlFetchArray($cres)) {
806 $duration = round($crow['pc_duration
'] / 60);
807 if ($crow['pc_end_all_day
']) $duration = 1440;
808 echo " durations[" . $crow['pc_catid
'] . "] = $duration\n";
809 // echo " rectypes[" . $crow['pc_catid
'] . "] = " . $crow['pc_recurrtype
'] . "\n";
810 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
812 if ($crow['pc_catid
'] == $row['pc_catid
']) $catoptions .= " selected";
814 if ($crow['pc_catid
'] == $default_catid) {
815 $catoptions .= " selected";
816 $thisduration = $duration;
819 $catoptions .= ">" . $crow['pc_catname
'] . "</option>\n";
821 // This section is to build the list of preferred categories:
823 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
825 if ($crow['pc_catid
'] == $row['pc_prefcatid
']) $prefcat_options .= " selected";
827 $prefcat_options .= ">" . $crow['pc_catname
'] . "</option>\n";
833 <?php // require($GLOBALS['srcdir
'] . "/restoreSession.php"); ?>
835 // This is for callback by the find-patient popup.
836 function setpatient(pid, lname, fname, dob) {
837 var f = document.forms.namedItem("theaddform");
838 f.form_patient.value = lname + ', ' + fname;
839 f.form_pid.value = pid;
840 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none
';
841 document.getElementById('dob_row
').style.display = dobstyle;
843 function change_provider(){
844 var f = document.forms.namedItem("theaddform");
845 f.form_date.value='';
846 f.form_hour.value='';
847 f.form_minute.value='';
849 // This is for callback by the find-patient popup.
850 function unsetpatient() {
851 var f = document.forms.namedItem("theaddform");
852 f.form_patient.value = '';
853 f.form_pid.value = '';
856 // This invokes the find-patient popup.
857 function sel_patient() {
858 dlgopen('find_patient_popup
.php
', '_blank
', 500, 400);
861 // Do whatever is needed when a new event category is selected.
862 // For now this means changing the event title and duration.
863 function set_display() {
864 var f = document.forms.namedItem("theaddform");
865 var si = document.getElementById('form_category
');
866 if (si.selectedIndex >= 0) {
867 var catid = si.options[si.selectedIndex].value;
868 var style_apptstatus = document.getElementById('title_apptstatus
').style;
869 var style_prefcat = document.getElementById('title_prefcat
').style;
870 if (catid == '2') { // In Office
871 style_apptstatus.display = 'none
';
872 style_prefcat.display = '';
873 f.form_apptstatus.style.display = 'none
';
874 f.form_prefcat.style.display = '';
876 style_prefcat.display = 'none
';
877 style_apptstatus.display = '';
878 f.form_prefcat.style.display = 'none
';
879 f.form_apptstatus.style.display = '';
884 // Gray out certain fields according to selection of Category DDL
885 function categoryChanged() {
888 document.getElementById("form_patient").disabled=false;
889 //document.getElementById("form_apptstatus").disabled=false;
890 //document.getElementById("form_prefcat").disabled=false;
894 // Do whatever is needed when a new event category is selected.
895 // For now this means changing the event title and duration.
896 function set_category() {
897 var f = document.forms.namedItem("theaddform");
898 var s = f.form_category;
899 if (s.selectedIndex >= 0) {
900 var catid = s.options[s.selectedIndex].value;
901 f.form_title.value = s.options[s.selectedIndex].text;
902 f.form_duration.value = durations[catid];
907 // Modify some visual attributes when the all-day or timed-event
908 // radio buttons are clicked.
909 function set_allday() {
910 var f = document.forms.namedItem("theaddform");
911 var color1 = '#777777';
912 var color2
= '#777777';
913 var disabled2
= true;
914 /*if (document.getElementById('rballday1').checked) {
917 if (document.getElementById('rballday2').checked) {
921 document
.getElementById('tdallday1').style
.color
= color1
;
922 document
.getElementById('tdallday2').style
.color
= color2
;
923 document
.getElementById('tdallday3').style
.color
= color2
;
924 document
.getElementById('tdallday4').style
.color
= color2
;
925 document
.getElementById('tdallday5').style
.color
= color2
;
926 f
.form_hour
.disabled
= disabled2
;
927 f
.form_minute
.disabled
= disabled2
;
928 f
.form_ampm
.disabled
= disabled2
;
929 f
.form_duration
.disabled
= disabled2
;
932 // Modify some visual attributes when the Repeat checkbox is clicked.
933 function set_repeat() {
934 var f
= document
.forms
.namedItem("theaddform");
935 var isdisabled
= true;
936 var mycolor
= '#777777';
937 var myvisibility
= 'hidden';
938 /*if (f.form_repeat.checked) {
941 myvisibility = 'visible';
943 //f.form_repeat_type.disabled = isdisabled;
944 //f.form_repeat_freq.disabled = isdisabled;
945 //f.form_enddate.disabled = isdisabled;
946 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
947 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
948 document
.getElementById('img_enddate').style
.visibility
= myvisibility
;
951 // This is for callback by the find-available popup.
952 function setappt(year
,mon
,mday
,hours
,minutes
) {
953 var f
= document
.forms
.namedItem("theaddform");
954 f
.form_date
.value
= '' + year +
'-' +
955 ('' +
(mon +
100)).substring(1) +
'-' +
956 ('' +
(mday +
100)).substring(1);
957 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
958 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
959 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
962 // Invoke the find-available popup.
963 function find_available() {
965 // (CHEMED) Conditional value selection, because there is no <select> element
966 // when making an appointment for a specific provider
967 var se
= document
.getElementById('form_provider_ae');
968 <?php
if ($userid != 0) { ?
>
971 s
= se
.options
[se
.selectedIndex
].value
;
973 var formDate
= document
.getElementById('form_date');
974 window
.open('find_appt_popup_user.php?bypatient&providerid=' + s +
976 '&startdate=' + formDate
.value
, '_blank', "width=900,height=800");
979 // Check for errors when the form is submitted.
980 function validate() {
981 var f
= document
.getElementById('theaddform');
982 if (!f
.form_date
.value ||
!f
.form_hour
.value ||
!f
.form_minute
.value
) {
983 alert('Please click on "Openings" to select a time.');
987 // in lunch outofoffice reserved vacation
988 // f.form_category.value='2';
989 if (f
.form_patient
.value
=='Click to select' && (!(
990 f
.form_category
.value
=='2' || f
.form_category
.value
=='8' || f
.form_category
.value
=='3' || f
.form_category
.value
=='4' || f
.form_category
.value
=='11'
991 || f
.form_category
.value
=='10'))) {
992 alert('Please select a patient.');
994 } else if (f
.form_category
.value
=='10') {
997 var form_action
= document
.getElementById('form_action');
998 form_action
.value
="save";
1003 function deleteEvent() {
1004 if (confirm("Deleting this event cannot be undone. It cannot be recovered once it is gone. Are you sure you wish to delete this event?")) {
1005 var f
= document
.getElementById('theaddform');
1006 var form_action
= document
.getElementById('form_action');
1007 form_action
.value
="delete";
1017 <?php
if ($eid) { ?
>
1025 //Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});