4 * Modified from interface/main/calendar/add_edit_event.php for
8 * @link http://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Jerry Padgett <sjpadgett@gmail.com>
11 * @author Brady Miller <brady.g.miller@gmail.com>
12 * @copyright Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
13 * @copyright Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
14 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
21 //landing page definition -- where to go if something goes wrong
22 $landingpage = "index.php?site=".$_SESSION['site_id'];
25 // kick out if patient not authenticated
26 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
27 $pid = $_SESSION['pid'];
30 header('Location: '.$landingpage.'&w');
39 require_once("../interface/globals.php");
40 require_once("$srcdir/patient.inc");
41 require_once("$srcdir/forms.inc");
43 // Exit if the modify calendar for portal flag is not set-pulled for v5
44 /* if (!($GLOBALS['portal_onsite_appt_modify'])) {
45 echo add_escape_custom( xl('You are not authorized to schedule appointments.'),ENT_NOQUOTES);
49 // Things that might be passed by our opener.
51 $eid = $_GET['eid']; // only for existing events
52 $date = $_GET['date']; // this and below only for new events
53 $userid = $_GET['userid'];
54 $default_catid = $_GET['catid'] ?
$_GET['catid'] : '5';
55 $patientid = $_GET['patid'];
59 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
61 $date = date("Y-m-d");
66 if (isset($_GET['starttimem'])) {
67 $starttimem = substr('00' . $_GET['starttimem'], -2);
71 if (isset($_GET['starttimeh'])) {
72 $starttimeh = $_GET['starttimeh'];
73 if (isset($_GET['startampm'])) {
74 if ($_GET['startampm'] == '2' && $starttimeh < 12) {
79 $starttimeh = date("G");
86 // ===========================
87 // EVENTS TO FACILITIES (lemonsoftware)
88 // edit event case - if there is no association made, then insert one with the first facility
91 $facility = sqlQuery("SELECT pc_facility, pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
92 if ( !$facility['pc_facility'] ) {
93 $qmin = sqlQuery("SELECT MIN(id) as minId FROM facility");
94 $min = $qmin['minId'];
96 // multiple providers case
97 if ( $GLOBALS['select_multi_providers'] ) {
98 $mul = $facility['pc_multiple'];
99 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
103 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
106 $e2f = $facility['pc_facility'];
110 // ===========================
111 // ===========================
113 // EVENTS TO FACILITIES (lemonsoftware)
114 //(CHEMED) get facility name
115 // edit event case - if there is no association made, then insert one with the first facility
118 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
119 FROM openemr_postcalendar_events
120 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
121 WHERE pc_eid = $eid");
122 if (!$facility['pc_facility']) {
123 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
124 $min = $qmin['minId'];
125 $min_name = $qmin['facility'];
127 // multiple providers case
128 if ($GLOBALS['select_multi_providers']) {
129 $mul = $facility['pc_multiple'];
130 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
135 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
137 $e2f_name = $min_name;
139 $e2f = $facility['pc_facility'];
140 $e2f_name = $facility['name'];
145 // ===========================
148 // If we are saving, then save and close the window.
150 if ($_POST['form_action'] == "save") {
153 $event_date = fixDate($_POST['form_date']);
155 // Compute start and end time strings to be saved.
156 if ($_POST['form_allday']) {
161 $tmph = $_POST['form_hour'] +
0;
162 $tmpm = $_POST['form_minute'] +
0;
163 if ($_POST['form_ampm'] == '2' && $tmph < 12) {
167 $duration = $_POST['form_duration'];
170 $starttime = "$tmph:$tmpm:00";
173 while ($tmpm >= 60) {
178 $endtime = "$tmph:$tmpm:00";
180 // Useless garbage that we must save.
181 $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' .
182 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}';
184 // More garbage, but this time 1 character of it is used to save the
186 if ($_POST['form_repeat']) {
187 $recurrspec = 'a:5:{' .
188 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' .
189 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' .
190 's:19:"event_repeat_on_num";s:1:"1";' .
191 's:19:"event_repeat_on_day";s:1:"0";' .
192 's:20:"event_repeat_on_freq";s:1:"0";}';
194 $recurrspec = 'a:5:{' .
195 's:17:"event_repeat_freq";N;' .
196 's:22:"event_repeat_freq_type";s:1:"0";' .
197 's:19:"event_repeat_on_num";s:1:"1";' .
198 's:19:"event_repeat_on_day";s:1:"0";' .
199 's:20:"event_repeat_on_freq";s:1:"1";}';
202 //The modification of the start date for events that take place on one day of the week
203 //for example monday, or thursday. We set the start date on the first day of the week
204 //that the event is scheduled. For example if you set the event to repeat on each monday
205 //the start date of the event will be set on the first monday after the day the event is scheduled
206 if ($_POST['form_repeat_type'] == 5) {
207 $exploded_date= explode("-", $event_date);
208 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
210 $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]));
213 } elseif ($edate=="Thu") {
214 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
215 } elseif ($edate=="Fri") {
216 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
217 } elseif ($edate=="Sat") {
218 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
219 } elseif ($edate=="Sun") {
220 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
222 } elseif ($_POST['form_repeat_type'] == 6) {
223 $exploded_date= explode("-", $event_date);
224 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
226 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
227 } elseif ($edate=="Thu") {
228 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
229 } elseif ($edate=="Fri") {
230 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
231 } elseif ($edate=="Sat") {
232 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
233 } elseif ($edate=="Sun") {
234 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
235 } elseif ($edate=="Mon") {
236 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
238 } elseif ($_POST['form_repeat_type'] == 7) {
239 $exploded_date= explode("-", $event_date);
240 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
242 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
243 } elseif ($edate=="Fri") {
244 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
245 } elseif ($edate=="Sat") {
246 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
247 } elseif ($edate=="Sun") {
248 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
249 } elseif ($edate=="Mon") {
250 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
251 } elseif ($edate=="Tue") {
252 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
254 } elseif ($_POST['form_repeat_type'] == 8) {
255 $exploded_date= explode("-", $event_date);
256 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
258 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
259 } elseif ($edate=="Sat") {
260 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
261 } elseif ($edate=="Sun") {
262 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
263 } elseif ($edate=="Mon") {
264 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
265 } elseif ($edate=="Tue") {
266 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
267 } elseif ($edate=="Wed") {
268 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
270 } elseif ($_POST['form_repeat_type'] == 9) {
271 $exploded_date= explode("-", $event_date);
272 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
274 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
275 } elseif ($edate=="Sun") {
276 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
277 } elseif ($edate=="Mon") {
278 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
279 } elseif ($edate=="Tue") {
280 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
281 } elseif ($edate=="Wed") {
282 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
283 } elseif ($edate=="Thu") {
284 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
287 /* =======================================================
289 ========================================================*/
291 // what is multiple key around this $eid?
292 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
294 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
295 /* ==========================================
296 // multi providers BOS
297 ==========================================*/
299 // obtain current list of providers regarding the multiple key
300 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
301 while ($current = sqlFetchArray($up)) {
302 $providers_current[] = $current['pc_aid'];
305 $providers_new = $_POST['form_provider_ae'];
307 // this difference means that some providers from current was UNCHECKED
308 // so we must delete this event for them
309 $r1 = array_diff($providers_current, $providers_new);
311 foreach ($r1 as $to_be_removed) {
312 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
316 // this difference means that some providers was added
317 // so we must insert this event for them
318 $r2 = array_diff($providers_new, $providers_current);
320 foreach ($r2 as $to_be_inserted) {
321 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)
323 "'" . $_POST['form_category'] . "', " .
324 "'" . $row['pc_multiple'] . "', " .
325 "'" . $to_be_inserted . "', " .
326 "'" . $_POST['form_pid'] . "', " .
327 "'" . add_escape_custom($_POST['form_title']) . "', " .
329 "'" . add_escape_custom($_POST['form_comments']) . "', " .
330 "'" . $_SESSION['providerId'] . "', " .
331 "'" . $event_date . "', " .
332 "'" . fixDate($_POST['form_enddate']) . "', " .
333 "'" . ($duration * 60) . "', " .
334 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
338 "'" . $_POST['form_allday'] . "', " .
339 "'" . $_POST['form_apptstatus'] . "', " .
340 "'" . $_POST['form_prefcat'] . "', " .
341 "'$locationspec', " .
343 "1, " .(int)$_POST['facility']. " )"); // FF stuff
348 // after the two diffs above, we must update for remaining providers
349 // those who are intersected in $providers_current and $providers_new
350 foreach ($_POST['form_provider_ae'] as $provider) {
351 sqlStatement("UPDATE openemr_postcalendar_events SET " .
352 "pc_catid = '" . $_POST['form_category'] . "', " .
353 "pc_pid = '" . $_POST['form_pid'] . "', " .
354 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
355 "pc_time = NOW(), " .
356 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
357 "pc_informant = '" . $_SESSION['providerId'] . "', " .
358 "pc_eventDate = '" . $event_date . "', " .
359 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
360 "pc_duration = '" . ($duration * 60) . "', " .
361 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
362 "pc_recurrspec = '$recurrspec', " .
363 "pc_startTime = '$starttime', " .
364 "pc_endTime = '$endtime', " .
365 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
366 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
367 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
368 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
369 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
372 /* ==========================================
373 // multi providers EOS
374 ==========================================*/
375 } elseif (!$row['pc_multiple']) {
376 if ($GLOBALS['select_multi_providers']) {
377 $prov = $_POST['form_provider_ae'][0];
379 $prov = $_POST['form_provider_ae'];
382 // simple provider case
383 sqlStatement("UPDATE openemr_postcalendar_events SET " .
384 "pc_catid = '" . $_POST['form_category'] . "', " .
385 "pc_aid = '" . $prov . "', " .
386 "pc_pid = '" . $_POST['form_pid'] . "', " .
387 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
388 "pc_time = NOW(), " .
389 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
390 "pc_informant = '" . $_SESSION['providerId'] . "', " .
391 "pc_eventDate = '" . $event_date . "', " .
392 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
393 "pc_duration = '" . ($duration * 60) . "', " .
394 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
395 "pc_recurrspec = '$recurrspec', " .
396 "pc_startTime = '$starttime', " .
397 "pc_endTime = '$endtime', " .
398 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
399 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
400 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
401 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
402 "WHERE pc_eid = '$eid'");
405 // =======================================
406 // EOS multi providers case
407 // =======================================
409 // EVENTS TO FACILITIES
413 /* =======================================================
415 ========================================================*/
417 // =======================================
418 // multi providers case
419 // =======================================
421 if (is_array($_POST['form_provider_ae'])) {
422 // obtain the next available unique key to group multiple providers around some event
423 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
424 $max = sqlFetchArray($q);
425 $new_multiple_value = $max['max'] +
1;
427 foreach ($_POST['form_provider_ae'] as $provider) {
428 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
429 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
430 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
431 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
432 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
434 "'" . $_POST['form_category'] . "', " .
435 "'" . $new_multiple_value . "', " .
436 "'" . $provider . "', " .
437 "'" . $_POST['form_pid'] . "', " .
438 "'" . add_escape_custom($_POST['form_title']) . "', " .
440 "'" . add_escape_custom($_POST['form_comments']) . "', " .
441 "'" . $_SESSION['providerId'] . "', " .
442 "'" . $event_date . "', " .
443 "'" . fixDate($_POST['form_enddate']) . "', " .
444 "'" . ($duration * 60) . "', " .
445 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
449 "'" . $_POST['form_allday'] . "', " .
450 "'" . $_POST['form_apptstatus'] . "', " .
451 "'" . $_POST['form_prefcat'] . "', " .
452 "'$locationspec', " .
454 "1, " .(int)$_POST['facility']. " )"); // FF stuff
457 $_POST['form_apptstatus'] = '^';
458 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
459 "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
460 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
461 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
462 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
464 "'" . $_POST['form_category'] . "', " .
465 "'" . $_POST['form_provider_ae'] . "', " .
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
487 // Save new DOB if it's there.
488 $patient_dob = trim($_POST['form_dob']);
489 if ($patient_dob && $_POST['form_pid']) {
490 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
491 "pid = '" . $_POST['form_pid'] . "'");
494 // Auto-create a new encounter if appropriate.
497 /* if ($GLOBALS['auto_create_new_encounters'] &&
498 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
501 // We decided not to auto-create blank enconter when user arrives. Todd's decision 18 Jun 2010
502 // Applied by Cassian Lup (cassian.lup@clinicdr.com)
505 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
506 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
507 if ($tmprow['count'] == 0) {
508 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
509 $_POST['form_provider_ae'] . "'");
510 $username = $tmprow['username'];
511 $facility = $tmprow['facility'];
512 $facility_id = $tmprow['facility_id'];
513 $conn = $GLOBALS['adodb']['db'];
514 $encounter = $conn->GenID("sequences");
517 "New Patient Encounter",
518 sqlInsert("INSERT INTO form_encounter SET " .
519 "date = '$event_date', " .
520 "onset_date = '$event_date', " .
521 "reason = '" . add_escape_custom($_POST['form_comments']) . "', " .
522 "facility = '$facility', " .
523 "facility_id = '$facility_id', " .
524 "pid = '" . $_POST['form_pid'] . "', " .
525 "encounter = '$encounter'"),
532 $info_msg .= "New encounter $encounter was created. ";
535 } else if ($_POST['form_action'] == "delete") {
536 // =======================================
537 // multi providers case
538 // =======================================
539 if ($GLOBALS['select_multi_providers']) {
540 // what is multiple key around this $eid?
541 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
542 if ($row['pc_multiple']) {
543 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_multiple = {$row['pc_multiple']}");
545 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = $eid");
548 // =======================================
549 // EOS multi providers case
550 // =======================================
552 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
556 if ($_POST['form_action'] != "") {
558 $_SESSION['whereto'] = 'appointmentpanel';
559 header('Location:./home.php');
563 // If we get this far then we are displaying the form.
567 '*' => xl('* Reminder done'),
568 '+' => xl('+ Chart pulled'),
569 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
570 '?' => xl('? No show'),
571 '@' => xl('@ Arrived'),
572 '~' => xl('~ Arrived late'),
573 '!' => xl('! Left w/o visit'),
574 '#' => xl('# Ins/fin issue'),
575 '<' => xl('< In exam room'),
576 '>' => xl('> Checked out'),
577 '$' => xl('$ Coding done'),
578 '^' => xl('^ Pending'),
581 $repeats = 0; // if the event repeats
588 // If we are editing an existing event, then get its data.
590 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
591 $date = $row['pc_eventDate'];
592 $userid = $row['pc_aid'];
593 $patientid = $row['pc_pid'];
594 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
595 $starttimem = substr($row['pc_startTime'], 3, 2);
596 $repeats = $row['pc_recurrtype'];
597 $multiple_value = $row['pc_multiple'];
599 if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
600 $repeattype = $matches[1];
603 if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
604 $repeatfreq = $matches[1];
607 $hometext = $row['pc_hometext'];
608 if (substr($hometext, 0, 6) == ':text:') {
609 $hometext = substr($hometext, 6);
612 $patientid=$_GET['pid'];
615 // If we have a patient ID, get the name and phone numbers to display.
617 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
618 "FROM patient_data WHERE pid = '" . $patientid . "'");
619 $patientname = $prow['lname'] . ", " . $prow['fname'];
620 if ($prow['phone_home']) {
621 $patienttitle .= " H=" . $prow['phone_home'];
624 if ($prow['phone_biz']) {
625 $patienttitle .= " W=" . $prow['phone_biz'];
629 // Get the providers list.
630 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
631 "authorized != 0 AND active = 1 ORDER BY lname, fname");
633 //-------------------------------------
635 //Set default facility for a new event based on the given 'userid'
637 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
638 $e2f = $pref_facility['facility_id'];
639 $e2f_name = $pref_facility['facility'];
642 //END of CHEMED -----------------------
644 // Get event categories.
645 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
646 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
648 // Fix up the time format for AM/PM.
650 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
652 if ($starttimeh > 12) {
660 <?php
//html_header_show(); ?>
661 <title
><?php
echo $eid ?
"Edit" : "Add New" ?
> <?php
xl('Event', 'e');?
></title
>
662 <link href
="assets/css/style.css?v=<?php echo $v_js_includes; ?>" rel
="stylesheet" type
="text/css" />
663 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
665 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
666 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
667 <script type
="text/javascript" src
="../library/topdialog.js?v=<?php echo $v_js_includes; ?>"></script
>
668 <script type
="text/javascript" src
="../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
669 <script type
="text/javascript" src
="../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
673 <body
class="body_top" >
675 <form method
='post' name
='theaddform' id
='theaddform' action
='add_edit_event_user.php?eid=<?php echo $eid ?>'>
676 <input type
="hidden" name
="form_action" id
="form_action" value
="">
677 <input type
='hidden' name
='form_category' id
='form_category' value
='<?php echo $row['pc_catid
'] ? $row['pc_catid
'] : '5'; ?>' />
678 <input type
='hidden' name
='form_apptstatus' id
='form_apptstatus' value
='<?php echo $row['pc_apptstatus
'] ? $row['pc_apptstatus
'] : "^" ?>' />
679 <table border
='0' width
='100%'>
681 <td width
='1%' nowrap
>
682 <b
><?php
xl('Visit', 'e'); ?
>: </b
>
684 <td nowrap style
='padding:0px 5px 5px 0'>
685 <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'/>
688 <td width
='1%' nowrap
>
689 <b
><?php
xl('Date', 'e'); ?
>:</b
>
691 <td colspan
='2' nowrap id
='tdallday1'>
692 <input
class="form-control input-md" type
='text' size
='10' name
='form_date' readonly id
='form_date'
693 value
='<?php echo (isset($eid) && $eid) ? $row['pc_eventDate
'] : $date; ?>' />
698 <b
><?php
//xl('Title','e'); ?></b>
700 <td style
='padding:0px 5px 5px 0' nowrap
>
701 <!-- <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
'); ?>' /> -->
705 <td width
='1%' nowrap id
='tdallday2'>
706 <b
><?php
xl('Time', 'e');?
>:</b
>
708 <td width
='1%' nowrap id
='tdallday3'>
709 <input
class="form-control inline" type
='text' size
='2' name
='form_hour' value
='<?php echo (isset($eid)) ? $starttimeh : ''; ?>'
710 title
='<?php xl('Event start time
', 'e
'); ?>' readonly
/> :
711 <input
class="form-control inline" type
='text' size
='2' name
='form_minute' value
='<?php echo (isset($eid)) ? $starttimem : ''; ?>'
712 title
='<?php xl('Event start time
', 'e
'); ?>' readonly
/> 
; <!-- -->
713 <select
class="form-control" name
='form_ampm' title
='Note: 12:00 noon is PM, not AM' readonly
>
714 <option value
='1'><?php
xl('AM', 'e'); ?
></option
>
715 <option value
='2'<?php
echo ($startampm == '2') ?
" selected" : ""; ?
>><?php
xl('PM', 'e'); ?
></option
>
721 <b
><?php
xl('Patient', 'e'); ?
>:</b
>
723 <td style
='padding:0px 5px 5px 0' nowrap
>
724 <input
class="form-control input-md" type
='text' size
='10' id
='form_patient' name
='form_patient' value
='<?php echo $patientname ?>' title
='Patient' readonly
/>
725 <input type
='hidden' name
='form_pid' value
='<?php echo $patientid ?>' />
730 <td nowrap id
='tdallday4'><?php
xl('Duration', 'e'); ?
></td
>
731 <td nowrap id
='tdallday5'>
732 <!-- --> <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'); ?
>
739 <b
><?php
xl('Provider', 'e'); ?
>:</b
>
741 <td style
='padding:0px 5px 5px 0' nowrap
>
742 <select
class="form-control input-md" name
='form_provider_ae' id
='form_provider_ae' onchange
='change_provider();'>
744 // present a list of providers to choose from
745 // default to the currently logged-in user
746 while ($urow = sqlFetchArray($ures)) {
747 echo " <option value='" . $urow['id'] . "'";
748 if (($urow['id'] == $_GET['userid'])||
($urow['id']== $userid)) {
752 echo ">" . $urow['lname'];
753 if ($urow['fname']) {
754 echo ", " . $urow['fname'];
762 <td nowrap style
='font-size:8pt'>
764 <td
><input type
='button' class='btn btn-danger btn-sm' value
='<?php xl('Openings
', 'e
');?>' onclick
='find_available()' /></td
>
769 <b
><?php
xl('Reason', 'e'); ?
>:</b
>
771 <td style
='padding:0px 5px 5px 0' colspan
='4' nowrap
>
772 <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
');?>' />
777 <input type
='button' name
='form_save' class='btn btn-success btn-md' onsubmit
='return false' value
='<?php xl('Save
', 'e
');?>' onclick
="validate()" />
783 var durations
= new Array();
784 // var rectypes = new Array();
786 // Read the event categories, generate their options list, and get
787 // the default event duration from them if this is a new event.
789 $prefcat_options = " <option value='0'>-- None --</option>\n";
792 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
795 while ($crow = sqlFetchArray($cres)) {
796 $duration = round($crow['pc_duration'] / 60);
797 if ($crow['pc_end_all_day']) {
801 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
802 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
803 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
805 if ($crow['pc_catid'] == $row['pc_catid']) {
806 $catoptions .= " selected";
809 if ($crow['pc_catid'] == $default_catid) {
810 $catoptions .= " selected";
811 $thisduration = $duration;
815 $catoptions .= ">" . $crow['pc_catname'] . "</option>\n";
817 // This section is to build the list of preferred categories:
819 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
821 if ($crow['pc_catid'] == $row['pc_prefcatid']) {
822 $prefcat_options .= " selected";
826 $prefcat_options .= ">" . $crow['pc_catname'] . "</option>\n";
831 <?php
// require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
833 // This is for callback by the find-patient popup.
834 function setpatient(pid
, lname
, fname
, dob
) {
835 var f
= document
.forms
.namedItem("theaddform");
836 f
.form_patient
.value
= lname +
', ' + fname
;
837 f
.form_pid
.value
= pid
;
838 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
839 document
.getElementById('dob_row').style
.display
= dobstyle
;
841 function change_provider(){
842 var f
= document
.forms
.namedItem("theaddform");
843 f
.form_date
.value
='';
844 f
.form_hour
.value
='';
845 f
.form_minute
.value
='';
847 // This is for callback by the find-patient popup.
848 function unsetpatient() {
849 var f
= document
.forms
.namedItem("theaddform");
850 f
.form_patient
.value
= '';
851 f
.form_pid
.value
= '';
854 // This invokes the find-patient popup.
855 function sel_patient() {
856 dlgopen('find_patient_popup.php', '_blank', 500, 400);
859 // Do whatever is needed when a new event category is selected.
860 // For now this means changing the event title and duration.
861 function set_display() {
862 var f
= document
.forms
.namedItem("theaddform");
863 var si
= document
.getElementById('form_category');
864 if (si
.selectedIndex
>= 0) {
865 var catid
= si
.options
[si
.selectedIndex
].value
;
866 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
867 var style_prefcat
= document
.getElementById('title_prefcat').style
;
868 if (catid
== '2') { // In Office
869 style_apptstatus
.display
= 'none';
870 style_prefcat
.display
= '';
871 f
.form_apptstatus
.style
.display
= 'none';
872 f
.form_prefcat
.style
.display
= '';
874 style_prefcat
.display
= 'none';
875 style_apptstatus
.display
= '';
876 f
.form_prefcat
.style
.display
= 'none';
877 f
.form_apptstatus
.style
.display
= '';
882 // Gray out certain fields according to selection of Category DDL
883 function categoryChanged() {
886 document
.getElementById("form_patient").disabled
=false;
887 //document.getElementById("form_apptstatus").disabled=false;
888 //document.getElementById("form_prefcat").disabled=false;
892 // Do whatever is needed when a new event category is selected.
893 // For now this means changing the event title and duration.
894 function set_category() {
895 var f
= document
.forms
.namedItem("theaddform");
896 var s
= f
.form_category
;
897 if (s
.selectedIndex
>= 0) {
898 var catid
= s
.options
[s
.selectedIndex
].value
;
899 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
900 f
.form_duration
.value
= durations
[catid
];
905 // Modify some visual attributes when the all-day or timed-event
906 // radio buttons are clicked.
907 function set_allday() {
908 var f
= document
.forms
.namedItem("theaddform");
909 var color1
= '#777777';
910 var color2
= '#777777';
911 var disabled2
= true;
912 /*if (document.getElementById('rballday1').checked) {
915 if (document.getElementById('rballday2').checked) {
919 document
.getElementById('tdallday1').style
.color
= color1
;
920 document
.getElementById('tdallday2').style
.color
= color2
;
921 document
.getElementById('tdallday3').style
.color
= color2
;
922 document
.getElementById('tdallday4').style
.color
= color2
;
923 document
.getElementById('tdallday5').style
.color
= color2
;
924 f
.form_hour
.disabled
= disabled2
;
925 f
.form_minute
.disabled
= disabled2
;
926 f
.form_ampm
.disabled
= disabled2
;
927 f
.form_duration
.disabled
= disabled2
;
930 // Modify some visual attributes when the Repeat checkbox is clicked.
931 function set_repeat() {
932 var f
= document
.forms
.namedItem("theaddform");
933 var isdisabled
= true;
934 var mycolor
= '#777777';
935 var myvisibility
= 'hidden';
936 /*if (f.form_repeat.checked) {
939 myvisibility = 'visible';
941 //f.form_repeat_type.disabled = isdisabled;
942 //f.form_repeat_freq.disabled = isdisabled;
943 //f.form_enddate.disabled = isdisabled;
944 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
945 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
946 document
.getElementById('img_enddate').style
.visibility
= myvisibility
;
949 // This is for callback by the find-available popup.
950 function setappt(year
,mon
,mday
,hours
,minutes
) {
951 var f
= document
.forms
.namedItem("theaddform");
952 f
.form_date
.value
= '' + year +
'-' +
953 ('' +
(mon +
100)).substring(1) +
'-' +
954 ('' +
(mday +
100)).substring(1);
955 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
956 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
957 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
960 // Invoke the find-available popup.
961 function find_available() {
963 // (CHEMED) Conditional value selection, because there is no <select> element
964 // when making an appointment for a specific provider
965 var se
= document
.getElementById('form_provider_ae');
966 <?php
if ($userid != 0) { ?
>
969 s
= se
.options
[se
.selectedIndex
].value
;
971 var formDate
= document
.getElementById('form_date');
972 window
.open('find_appt_popup_user.php?bypatient&providerid=' + s +
974 '&startdate=' + formDate
.value
, '_blank', "width=900,height=800");
977 // Check for errors when the form is submitted.
978 function validate() {
979 var f
= document
.getElementById('theaddform');
980 if (!f
.form_date
.value ||
!f
.form_hour
.value ||
!f
.form_minute
.value
) {
981 alert('Please click on "Openings" to select a time.');
985 // in lunch outofoffice reserved vacation
986 // f.form_category.value='2';
987 if (f
.form_patient
.value
=='Click to select' && (!(
988 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'
989 || f
.form_category
.value
=='10'))) {
990 alert('Please select a patient.');
992 } else if (f
.form_category
.value
=='10') {
995 var form_action
= document
.getElementById('form_action');
996 form_action
.value
="save";
1001 function deleteEvent() {
1002 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?")) {
1003 var f
= document
.getElementById('theaddform');
1004 var form_action
= document
.getElementById('form_action');
1005 form_action
.value
="delete";
1012 <?php
if ($eid) { ?
>
1016 $
(document
).ready(function() {
1017 $
('.datepicker').datetimepicker({
1018 <?php
$datetimepicker_timepicker = false; ?
>
1019 <?php
$datetimepicker_showseconds = false; ?
>
1020 <?php
$datetimepicker_formatInput = false; ?
>
1021 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
1022 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>