4 * Modified from interface/main/calendar/add_edit_event.php for
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Jerry Padgett <sjpadgett@gmail.com>
10 * @copyright Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
12 * @link http://www.open-emr.org
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
19 //landing page definition -- where to go if something goes wrong
20 $landingpage = "index.php?site=".$_SESSION['site_id'];
23 // kick out if patient not authenticated
24 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
25 $pid = $_SESSION['pid'];
28 header('Location: '.$landingpage.'&w');
37 include_once("../interface/globals.php");
38 include_once("$srcdir/patient.inc");
39 include_once("$srcdir/forms.inc");
41 // Exit if the modify calendar for portal flag is not set-pulled for v5
42 /* if (!($GLOBALS['portal_onsite_appt_modify'])) {
43 echo add_escape_custom( xl('You are not authorized to schedule appointments.'),ENT_NOQUOTES);
47 // Things that might be passed by our opener.
49 $eid = $_GET['eid']; // only for existing events
50 $date = $_GET['date']; // this and below only for new events
51 $userid = $_GET['userid'];
52 $default_catid = $_GET['catid'] ?
$_GET['catid'] : '5';
53 $patientid = $_GET['patid'];
57 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
59 $date = date("Y-m-d");
64 if (isset($_GET['starttimem'])) {
65 $starttimem = substr('00' . $_GET['starttimem'], -2);
69 if (isset($_GET['starttimeh'])) {
70 $starttimeh = $_GET['starttimeh'];
71 if (isset($_GET['startampm'])) {
72 if ($_GET['startampm'] == '2' && $starttimeh < 12) {
77 $starttimeh = date("G");
84 // ===========================
85 // EVENTS TO FACILITIES (lemonsoftware)
86 // edit event case - if there is no association made, then insert one with the first facility
89 $facility = sqlQuery("SELECT pc_facility, pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
90 if ( !$facility['pc_facility'] ) {
91 $qmin = sqlQuery("SELECT MIN(id) as minId FROM facility");
92 $min = $qmin['minId'];
94 // multiple providers case
95 if ( $GLOBALS['select_multi_providers'] ) {
96 $mul = $facility['pc_multiple'];
97 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
101 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
104 $e2f = $facility['pc_facility'];
108 // ===========================
109 // ===========================
111 // EVENTS TO FACILITIES (lemonsoftware)
112 //(CHEMED) get facility name
113 // edit event case - if there is no association made, then insert one with the first facility
116 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
117 FROM openemr_postcalendar_events
118 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
119 WHERE pc_eid = $eid");
120 if (!$facility['pc_facility']) {
121 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
122 $min = $qmin['minId'];
123 $min_name = $qmin['facility'];
125 // multiple providers case
126 if ($GLOBALS['select_multi_providers']) {
127 $mul = $facility['pc_multiple'];
128 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
133 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
135 $e2f_name = $min_name;
137 $e2f = $facility['pc_facility'];
138 $e2f_name = $facility['name'];
143 // ===========================
146 // If we are saving, then save and close the window.
148 if ($_POST['form_action'] == "save") {
151 $event_date = fixDate($_POST['form_date']);
153 // Compute start and end time strings to be saved.
154 if ($_POST['form_allday']) {
159 $tmph = $_POST['form_hour'] +
0;
160 $tmpm = $_POST['form_minute'] +
0;
161 if ($_POST['form_ampm'] == '2' && $tmph < 12) {
165 $duration = $_POST['form_duration'];
168 $starttime = "$tmph:$tmpm:00";
171 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) {
205 $exploded_date= explode("-", $event_date);
206 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
208 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
209 } elseif ($edate=="Wed") {
210 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
211 } elseif ($edate=="Thu") {
212 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
213 } elseif ($edate=="Fri") {
214 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
215 } elseif ($edate=="Sat") {
216 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
217 } elseif ($edate=="Sun") {
218 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
220 } elseif ($_POST['form_repeat_type'] == 6) {
221 $exploded_date= explode("-", $event_date);
222 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
224 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
225 } elseif ($edate=="Thu") {
226 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
227 } elseif ($edate=="Fri") {
228 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
229 } elseif ($edate=="Sat") {
230 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
231 } elseif ($edate=="Sun") {
232 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
233 } elseif ($edate=="Mon") {
234 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
236 } elseif ($_POST['form_repeat_type'] == 7) {
237 $exploded_date= explode("-", $event_date);
238 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
240 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
241 } elseif ($edate=="Fri") {
242 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
243 } elseif ($edate=="Sat") {
244 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
245 } elseif ($edate=="Sun") {
246 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
247 } elseif ($edate=="Mon") {
248 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
249 } elseif ($edate=="Tue") {
250 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
252 } elseif ($_POST['form_repeat_type'] == 8) {
253 $exploded_date= explode("-", $event_date);
254 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
256 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
257 } elseif ($edate=="Sat") {
258 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
259 } elseif ($edate=="Sun") {
260 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
261 } elseif ($edate=="Mon") {
262 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
263 } elseif ($edate=="Tue") {
264 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
265 } elseif ($edate=="Wed") {
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'] == 9) {
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]));
273 } elseif ($edate=="Sun") {
274 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
275 } elseif ($edate=="Mon") {
276 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
277 } elseif ($edate=="Tue") {
278 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
279 } elseif ($edate=="Wed") {
280 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
281 } elseif ($edate=="Thu") {
282 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
285 /* =======================================================
287 ========================================================*/
289 // what is multiple key around this $eid?
290 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
292 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
293 /* ==========================================
294 // multi providers BOS
295 ==========================================*/
297 // obtain current list of providers regarding the multiple key
298 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
299 while ($current = sqlFetchArray($up)) {
300 $providers_current[] = $current['pc_aid'];
303 $providers_new = $_POST['form_provider_ae'];
305 // this difference means that some providers from current was UNCHECKED
306 // so we must delete this event for them
307 $r1 = array_diff($providers_current, $providers_new);
309 foreach ($r1 as $to_be_removed) {
310 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
314 // this difference means that some providers was added
315 // so we must insert this event for them
316 $r2 = array_diff($providers_new, $providers_current);
318 foreach ($r2 as $to_be_inserted) {
319 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)
321 "'" . $_POST['form_category'] . "', " .
322 "'" . $row['pc_multiple'] . "', " .
323 "'" . $to_be_inserted . "', " .
324 "'" . $_POST['form_pid'] . "', " .
325 "'" . add_escape_custom($_POST['form_title']) . "', " .
327 "'" . add_escape_custom($_POST['form_comments']) . "', " .
328 "'" . $_SESSION['providerId'] . "', " .
329 "'" . $event_date . "', " .
330 "'" . fixDate($_POST['form_enddate']) . "', " .
331 "'" . ($duration * 60) . "', " .
332 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
336 "'" . $_POST['form_allday'] . "', " .
337 "'" . $_POST['form_apptstatus'] . "', " .
338 "'" . $_POST['form_prefcat'] . "', " .
339 "'$locationspec', " .
341 "1, " .(int)$_POST['facility']. " )"); // FF stuff
346 // after the two diffs above, we must update for remaining providers
347 // those who are intersected in $providers_current and $providers_new
348 foreach ($_POST['form_provider_ae'] as $provider) {
349 sqlStatement("UPDATE openemr_postcalendar_events SET " .
350 "pc_catid = '" . $_POST['form_category'] . "', " .
351 "pc_pid = '" . $_POST['form_pid'] . "', " .
352 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
353 "pc_time = NOW(), " .
354 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
355 "pc_informant = '" . $_SESSION['providerId'] . "', " .
356 "pc_eventDate = '" . $event_date . "', " .
357 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
358 "pc_duration = '" . ($duration * 60) . "', " .
359 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
360 "pc_recurrspec = '$recurrspec', " .
361 "pc_startTime = '$starttime', " .
362 "pc_endTime = '$endtime', " .
363 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
364 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
365 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
366 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
367 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
370 /* ==========================================
371 // multi providers EOS
372 ==========================================*/
373 } elseif (!$row['pc_multiple']) {
374 if ($GLOBALS['select_multi_providers']) {
375 $prov = $_POST['form_provider_ae'][0];
377 $prov = $_POST['form_provider_ae'];
380 // simple provider case
381 sqlStatement("UPDATE openemr_postcalendar_events SET " .
382 "pc_catid = '" . $_POST['form_category'] . "', " .
383 "pc_aid = '" . $prov . "', " .
384 "pc_pid = '" . $_POST['form_pid'] . "', " .
385 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
386 "pc_time = NOW(), " .
387 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
388 "pc_informant = '" . $_SESSION['providerId'] . "', " .
389 "pc_eventDate = '" . $event_date . "', " .
390 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
391 "pc_duration = '" . ($duration * 60) . "', " .
392 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
393 "pc_recurrspec = '$recurrspec', " .
394 "pc_startTime = '$starttime', " .
395 "pc_endTime = '$endtime', " .
396 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
397 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
398 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
399 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
400 "WHERE pc_eid = '$eid'");
403 // =======================================
404 // EOS multi providers case
405 // =======================================
407 // EVENTS TO FACILITIES
411 /* =======================================================
413 ========================================================*/
415 // =======================================
416 // multi providers case
417 // =======================================
419 if (is_array($_POST['form_provider_ae'])) {
420 // obtain the next available unique key to group multiple providers around some event
421 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
422 $max = sqlFetchArray($q);
423 $new_multiple_value = $max['max'] +
1;
425 foreach ($_POST['form_provider_ae'] as $provider) {
426 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
427 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
428 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
429 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
430 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
432 "'" . $_POST['form_category'] . "', " .
433 "'" . $new_multiple_value . "', " .
434 "'" . $provider . "', " .
435 "'" . $_POST['form_pid'] . "', " .
436 "'" . add_escape_custom($_POST['form_title']) . "', " .
438 "'" . add_escape_custom($_POST['form_comments']) . "', " .
439 "'" . $_SESSION['providerId'] . "', " .
440 "'" . $event_date . "', " .
441 "'" . fixDate($_POST['form_enddate']) . "', " .
442 "'" . ($duration * 60) . "', " .
443 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
447 "'" . $_POST['form_allday'] . "', " .
448 "'" . $_POST['form_apptstatus'] . "', " .
449 "'" . $_POST['form_prefcat'] . "', " .
450 "'$locationspec', " .
452 "1, " .(int)$_POST['facility']. " )"); // FF stuff
455 $_POST['form_apptstatus'] = '^';
456 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
457 "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
458 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
459 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
460 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
462 "'" . $_POST['form_category'] . "', " .
463 "'" . $_POST['form_provider_ae'] . "', " .
464 "'" . $_POST['form_pid'] . "', " .
465 "'" . add_escape_custom($_POST['form_title']) . "', " .
467 "'" . add_escape_custom($_POST['form_comments']) . "', " .
468 "'" . $_SESSION['providerId'] . "', " .
469 "'" . $event_date . "', " .
470 "'" . fixDate($_POST['form_enddate']) . "', " .
471 "'" . ($duration * 60) . "', " .
472 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
476 "'" . $_POST['form_allday'] . "', " .
477 "'" . $_POST['form_apptstatus'] . "', " .
478 "'" . $_POST['form_prefcat'] . "', " .
479 "'$locationspec', " .
481 "1," .(int)$_POST['facility']. ")"); // FF stuff
485 // Save new DOB if it's there.
486 $patient_dob = trim($_POST['form_dob']);
487 if ($patient_dob && $_POST['form_pid']) {
488 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
489 "pid = '" . $_POST['form_pid'] . "'");
492 // Auto-create a new encounter if appropriate.
495 /* if ($GLOBALS['auto_create_new_encounters'] &&
496 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
499 // We decided not to auto-create blank enconter when user arrives. Todd's decision 18 Jun 2010
500 // Applied by Cassian Lup (cassian.lup@clinicdr.com)
503 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
504 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
505 if ($tmprow['count'] == 0) {
506 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
507 $_POST['form_provider_ae'] . "'");
508 $username = $tmprow['username'];
509 $facility = $tmprow['facility'];
510 $facility_id = $tmprow['facility_id'];
511 $conn = $GLOBALS['adodb']['db'];
512 $encounter = $conn->GenID("sequences");
515 "New Patient Encounter",
516 sqlInsert("INSERT INTO form_encounter SET " .
517 "date = '$event_date', " .
518 "onset_date = '$event_date', " .
519 "reason = '" . add_escape_custom($_POST['form_comments']) . "', " .
520 "facility = '$facility', " .
521 "facility_id = '$facility_id', " .
522 "pid = '" . $_POST['form_pid'] . "', " .
523 "encounter = '$encounter'"),
530 $info_msg .= "New encounter $encounter was created. ";
533 } else if ($_POST['form_action'] == "delete") {
534 // =======================================
535 // multi providers case
536 // =======================================
537 if ($GLOBALS['select_multi_providers']) {
538 // what is multiple key around this $eid?
539 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
540 if ($row['pc_multiple']) {
541 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_multiple = {$row['pc_multiple']}");
543 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = $eid");
546 // =======================================
547 // EOS multi providers case
548 // =======================================
550 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
554 if ($_POST['form_action'] != "") {
556 $_SESSION['whereto'] = 'appointmentpanel';
557 header('Location:./home.php');
561 // If we get this far then we are displaying the form.
565 '*' => xl('* Reminder done'),
566 '+' => xl('+ Chart pulled'),
567 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
568 '?' => xl('? No show'),
569 '@' => xl('@ Arrived'),
570 '~' => xl('~ Arrived late'),
571 '!' => xl('! Left w/o visit'),
572 '#' => xl('# Ins/fin issue'),
573 '<' => xl('< In exam room'),
574 '>' => xl('> Checked out'),
575 '$' => xl('$ Coding done'),
576 '^' => xl('^ Pending'),
579 $repeats = 0; // if the event repeats
586 // If we are editing an existing event, then get its data.
588 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
589 $date = $row['pc_eventDate'];
590 $userid = $row['pc_aid'];
591 $patientid = $row['pc_pid'];
592 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
593 $starttimem = substr($row['pc_startTime'], 3, 2);
594 $repeats = $row['pc_recurrtype'];
595 $multiple_value = $row['pc_multiple'];
597 if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
598 $repeattype = $matches[1];
601 if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
602 $repeatfreq = $matches[1];
605 $hometext = $row['pc_hometext'];
606 if (substr($hometext, 0, 6) == ':text:') {
607 $hometext = substr($hometext, 6);
610 $patientid=$_GET['pid'];
613 // If we have a patient ID, get the name and phone numbers to display.
615 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
616 "FROM patient_data WHERE pid = '" . $patientid . "'");
617 $patientname = $prow['lname'] . ", " . $prow['fname'];
618 if ($prow['phone_home']) {
619 $patienttitle .= " H=" . $prow['phone_home'];
622 if ($prow['phone_biz']) {
623 $patienttitle .= " W=" . $prow['phone_biz'];
627 // Get the providers list.
628 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
629 "authorized != 0 AND active = 1 ORDER BY lname, fname");
631 //-------------------------------------
633 //Set default facility for a new event based on the given 'userid'
635 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
636 $e2f = $pref_facility['facility_id'];
637 $e2f_name = $pref_facility['facility'];
640 //END of CHEMED -----------------------
642 // Get event categories.
643 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
644 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
646 // Fix up the time format for AM/PM.
648 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
650 if ($starttimeh > 12) {
658 <?php
//html_header_show(); ?>
659 <title
><?php
echo $eid ?
"Edit" : "Add New" ?
> <?php
xl('Event', 'e');?
></title
>
660 <link href
="assets/css/style.css?v=<?php echo $v_js_includes; ?>" rel
="stylesheet" type
="text/css" />
661 <style type
="text/css">@import
url(../library
/dynarch_calendar
.css
);</style
>
662 <script type
="text/javascript" src
="../library/topdialog.js?v=<?php echo $v_js_includes; ?>"></script
>
663 <script type
="text/javascript" src
="../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
664 <script type
="text/javascript" src
="../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
665 <script type
="text/javascript" src
="../library/dynarch_calendar.js"></script
>
666 <script type
="text/javascript" src
="../library/dynarch_calendar_en.js"></script
>
667 <script type
="text/javascript" src
="../library/dynarch_calendar_setup.js"></script
>
671 <body
class="body_top" >
673 <form method
='post' name
='theaddform' id
='theaddform' action
='add_edit_event_user.php?eid=<?php echo $eid ?>'>
674 <input type
="hidden" name
="form_action" id
="form_action" value
="">
675 <input type
='hidden' name
='form_category' id
='form_category' value
='<?php echo $row['pc_catid
'] ? $row['pc_catid
'] : '5'; ?>' />
676 <input type
='hidden' name
='form_apptstatus' id
='form_apptstatus' value
='<?php echo $row['pc_apptstatus
'] ? $row['pc_apptstatus
'] : "^" ?>' />
677 <table border
='0' width
='100%'>
679 <td width
='1%' nowrap
>
680 <b
><?php
xl('Visit', 'e'); ?
>: </b
>
682 <td nowrap style
='padding:0px 5px 5px 0'>
683 <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'/>
686 <td width
='1%' nowrap
>
687 <b
><?php
xl('Date', 'e'); ?
>:</b
>
689 <td colspan
='2' nowrap id
='tdallday1'>
690 <input
class="form-control input-md" type
='text' size
='10' name
='form_date' readonly id
='form_date'
691 value
='<?php if (isset($eid)) {
692 echo $eid ? $row['pc_eventDate
'] : $date;
694 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
699 <b
><?php
//xl('Title','e'); ?></b>
701 <td style
='padding:0px 5px 5px 0' nowrap
>
702 <!-- <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
'); ?>' /> -->
706 <td width
='1%' nowrap id
='tdallday2'>
707 <b
><?php
xl('Time', 'e');?
>:</b
>
709 <td width
='1%' nowrap id
='tdallday3'>
710 <input
class="form-control inline" type
='text' size
='2' name
='form_hour' value
='<?php if (isset($eid)) {
713 title
='<?php xl('Event start time
', 'e
'); ?>' readonly
/> :
714 <input
class="form-control inline" type
='text' size
='2' name
='form_minute' value
='<?php if (isset($eid)) {
717 title
='<?php xl('Event start time
', 'e
'); ?>' readonly
/> 
; <!-- -->
718 <select
class="form-control" name
='form_ampm' title
='Note: 12:00 noon is PM, not AM' readonly
>
719 <option value
='1'><?php
xl('AM', 'e'); ?
></option
>
720 <option value
='2'<?php
if ($startampm == '2') {
722 } ?
>><?php
xl('PM', 'e'); ?
></option
>
728 <b
><?php
xl('Patient', 'e'); ?
>:</b
>
730 <td style
='padding:0px 5px 5px 0' nowrap
>
731 <input
class="form-control input-md" type
='text' size
='10' id
='form_patient' name
='form_patient' value
='<?php echo $patientname ?>' title
='Patient' readonly
/>
732 <input type
='hidden' name
='form_pid' value
='<?php echo $patientid ?>' />
737 <td nowrap id
='tdallday4'><?php
xl('Duration', 'e'); ?
></td
>
738 <td nowrap id
='tdallday5'>
739 <!-- --> <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'); ?
>
746 <b
><?php
xl('Provider', 'e'); ?
>:</b
>
748 <td style
='padding:0px 5px 5px 0' nowrap
>
749 <select
class="form-control input-md" name
='form_provider_ae' id
='form_provider_ae' onchange
='change_provider();'>
751 // present a list of providers to choose from
752 // default to the currently logged-in user
753 while ($urow = sqlFetchArray($ures)) {
754 echo " <option value='" . $urow['id'] . "'";
755 if (($urow['id'] == $_GET['userid'])||
($urow['id']== $userid)) {
759 echo ">" . $urow['lname'];
760 if ($urow['fname']) {
761 echo ", " . $urow['fname'];
769 <td nowrap style
='font-size:8pt'>
771 <td
><input type
='button' class='btn btn-danger btn-sm' value
='<?php xl('Openings
', 'e
');?>' onclick
='find_available()' /></td
>
776 <b
><?php
xl('Reason', 'e'); ?
>:</b
>
778 <td style
='padding:0px 5px 5px 0' colspan
='4' nowrap
>
779 <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
');?>' />
784 <input type
='button' name
='form_save' class='btn btn-success btn-md' onsubmit
='return false' value
='<?php xl('Save
', 'e
');?>' onclick
="validate()" />
789 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
791 var durations
= new Array();
792 // var rectypes = new Array();
794 // Read the event categories, generate their options list, and get
795 // the default event duration from them if this is a new event.
797 $prefcat_options = " <option value='0'>-- None --</option>\n";
800 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
803 while ($crow = sqlFetchArray($cres)) {
804 $duration = round($crow['pc_duration'] / 60);
805 if ($crow['pc_end_all_day']) {
809 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
810 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
811 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
813 if ($crow['pc_catid'] == $row['pc_catid']) {
814 $catoptions .= " selected";
817 if ($crow['pc_catid'] == $default_catid) {
818 $catoptions .= " selected";
819 $thisduration = $duration;
823 $catoptions .= ">" . $crow['pc_catname'] . "</option>\n";
825 // This section is to build the list of preferred categories:
827 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
829 if ($crow['pc_catid'] == $row['pc_prefcatid']) {
830 $prefcat_options .= " selected";
834 $prefcat_options .= ">" . $crow['pc_catname'] . "</option>\n";
839 <?php
// require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
841 // This is for callback by the find-patient popup.
842 function setpatient(pid
, lname
, fname
, dob
) {
843 var f
= document
.forms
.namedItem("theaddform");
844 f
.form_patient
.value
= lname +
', ' + fname
;
845 f
.form_pid
.value
= pid
;
846 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
847 document
.getElementById('dob_row').style
.display
= dobstyle
;
849 function change_provider(){
850 var f
= document
.forms
.namedItem("theaddform");
851 f
.form_date
.value
='';
852 f
.form_hour
.value
='';
853 f
.form_minute
.value
='';
855 // This is for callback by the find-patient popup.
856 function unsetpatient() {
857 var f
= document
.forms
.namedItem("theaddform");
858 f
.form_patient
.value
= '';
859 f
.form_pid
.value
= '';
862 // This invokes the find-patient popup.
863 function sel_patient() {
864 dlgopen('find_patient_popup.php', '_blank', 500, 400);
867 // Do whatever is needed when a new event category is selected.
868 // For now this means changing the event title and duration.
869 function set_display() {
870 var f
= document
.forms
.namedItem("theaddform");
871 var si
= document
.getElementById('form_category');
872 if (si
.selectedIndex
>= 0) {
873 var catid
= si
.options
[si
.selectedIndex
].value
;
874 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
875 var style_prefcat
= document
.getElementById('title_prefcat').style
;
876 if (catid
== '2') { // In Office
877 style_apptstatus
.display
= 'none';
878 style_prefcat
.display
= '';
879 f
.form_apptstatus
.style
.display
= 'none';
880 f
.form_prefcat
.style
.display
= '';
882 style_prefcat
.display
= 'none';
883 style_apptstatus
.display
= '';
884 f
.form_prefcat
.style
.display
= 'none';
885 f
.form_apptstatus
.style
.display
= '';
890 // Gray out certain fields according to selection of Category DDL
891 function categoryChanged() {
894 document
.getElementById("form_patient").disabled
=false;
895 //document.getElementById("form_apptstatus").disabled=false;
896 //document.getElementById("form_prefcat").disabled=false;
900 // Do whatever is needed when a new event category is selected.
901 // For now this means changing the event title and duration.
902 function set_category() {
903 var f
= document
.forms
.namedItem("theaddform");
904 var s
= f
.form_category
;
905 if (s
.selectedIndex
>= 0) {
906 var catid
= s
.options
[s
.selectedIndex
].value
;
907 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
908 f
.form_duration
.value
= durations
[catid
];
913 // Modify some visual attributes when the all-day or timed-event
914 // radio buttons are clicked.
915 function set_allday() {
916 var f
= document
.forms
.namedItem("theaddform");
917 var color1
= '#777777';
918 var color2
= '#777777';
919 var disabled2
= true;
920 /*if (document.getElementById('rballday1').checked) {
923 if (document.getElementById('rballday2').checked) {
927 document
.getElementById('tdallday1').style
.color
= color1
;
928 document
.getElementById('tdallday2').style
.color
= color2
;
929 document
.getElementById('tdallday3').style
.color
= color2
;
930 document
.getElementById('tdallday4').style
.color
= color2
;
931 document
.getElementById('tdallday5').style
.color
= color2
;
932 f
.form_hour
.disabled
= disabled2
;
933 f
.form_minute
.disabled
= disabled2
;
934 f
.form_ampm
.disabled
= disabled2
;
935 f
.form_duration
.disabled
= disabled2
;
938 // Modify some visual attributes when the Repeat checkbox is clicked.
939 function set_repeat() {
940 var f
= document
.forms
.namedItem("theaddform");
941 var isdisabled
= true;
942 var mycolor
= '#777777';
943 var myvisibility
= 'hidden';
944 /*if (f.form_repeat.checked) {
947 myvisibility = 'visible';
949 //f.form_repeat_type.disabled = isdisabled;
950 //f.form_repeat_freq.disabled = isdisabled;
951 //f.form_enddate.disabled = isdisabled;
952 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
953 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
954 document
.getElementById('img_enddate').style
.visibility
= myvisibility
;
957 // This is for callback by the find-available popup.
958 function setappt(year
,mon
,mday
,hours
,minutes
) {
959 var f
= document
.forms
.namedItem("theaddform");
960 f
.form_date
.value
= '' + year +
'-' +
961 ('' +
(mon +
100)).substring(1) +
'-' +
962 ('' +
(mday +
100)).substring(1);
963 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
964 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
965 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
968 // Invoke the find-available popup.
969 function find_available() {
971 // (CHEMED) Conditional value selection, because there is no <select> element
972 // when making an appointment for a specific provider
973 var se
= document
.getElementById('form_provider_ae');
974 <?php
if ($userid != 0) { ?
>
977 s
= se
.options
[se
.selectedIndex
].value
;
979 var formDate
= document
.getElementById('form_date');
980 window
.open('find_appt_popup_user.php?bypatient&providerid=' + s +
982 '&startdate=' + formDate
.value
, '_blank', "width=900,height=800");
985 // Check for errors when the form is submitted.
986 function validate() {
987 var f
= document
.getElementById('theaddform');
988 if (!f
.form_date
.value ||
!f
.form_hour
.value ||
!f
.form_minute
.value
) {
989 alert('Please click on "Openings" to select a time.');
993 // in lunch outofoffice reserved vacation
994 // f.form_category.value='2';
995 if (f
.form_patient
.value
=='Click to select' && (!(
996 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'
997 || f
.form_category
.value
=='10'))) {
998 alert('Please select a patient.');
1000 } else if (f
.form_category
.value
=='10') {
1003 var form_action
= document
.getElementById('form_action');
1004 form_action
.value
="save";
1009 function deleteEvent() {
1010 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?")) {
1011 var f
= document
.getElementById('theaddform');
1012 var form_action
= document
.getElementById('form_action');
1013 form_action
.value
="delete";
1023 <?php
if ($eid) { ?
>
1031 //Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});