Highway to PSR2
[openemr.git] / interface / main / calendar / add_edit_event.php
blob2ed42ed5d912b0391859140f5bba97d0dcc49c6c
1 <?php
2 /*
3 * Add or edit an event in the calendar.
5 * Can be displayed as a popup window, or as an iframe via
6 * fancybox.
9 * The event editor looks something like this:
11 * //------------------------------------------------------------//
12 * // Category __________________V O All day event //
13 * // Date _____________ [?] O Time ___:___ __V //
14 * // Title ___________________ duration ____ minutes //
15 * // Patient _(Click_to_select)_ //
16 * // Provider __________________V X Repeats ______V ______V //
17 * // Status __________________V until __________ [?] //
18 * // Comments ________________________________________________ //
19 * // //
20 * // [Save] [Find Available] [Delete] [Cancel] //
21 * //------------------------------------------------------------//
24 * Copyright (C) 2005-2013 Rod Roark <rod@sunsetsystems.com>
25 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
27 * LICENSE: This program is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU General Public License
29 * as published by the Free Software Foundation; either version 3
30 * of the License, or (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
38 * @package OpenEMR
39 * @author Rod Roark <rod@sunsetsystems.com>
40 * @author Brady Miller <brady.g.miller@gmail.com>
41 * @link http://www.open-emr.org
45 require_once('../../globals.php');
46 require_once($GLOBALS['srcdir'].'/patient.inc');
47 require_once($GLOBALS['srcdir'].'/forms.inc');
48 require_once($GLOBALS['srcdir'].'/calendar.inc');
49 require_once($GLOBALS['srcdir'].'/options.inc.php');
50 require_once($GLOBALS['srcdir'].'/encounter_events.inc.php');
51 require_once($GLOBALS['srcdir'].'/acl.inc');
52 require_once($GLOBALS['srcdir'].'/patient_tracker.inc.php');
53 require_once($GLOBALS['incdir']."/main/holidays/Holidays_Controller.php");
54 require_once($GLOBALS['srcdir'].'/group.inc');
56 //Check access control
57 if (!acl_check('patients', 'appt', '', array('write','wsome'))) {
58 die(xl('Access not allowed'));
61 /* 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';
67 if ($date) {
68 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
69 } else {
70 $date = date("Y-m-d");
74 $starttimem = '00';
75 if (isset($_GET['starttimem'])) {
76 $starttimem = substr('00' . $_GET['starttimem'], -2);
80 if (isset($_GET['starttimeh'])) {
81 $starttimeh = $_GET['starttimeh'];
82 if (isset($_GET['startampm'])) {
83 if ($_GET['startampm'] == '2' && $starttimeh < 12) {
84 $starttimeh += 12;
87 } else {
88 $starttimeh = date("G");
91 $startampm = '';
93 $info_msg = "";
97 <?php $g_edit = acl_check("groups", "gcalendar", false, 'write');?>
98 <?php $g_view = acl_check("groups", "gcalendar", false, 'view');?>
101 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js?v=<?php echo $v_js_includes; ?>"></script>
102 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative'] ?>/jquery-min-3-1-1/index.js"></script>
104 <!-- validation library -->
105 <!--//Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation-->
106 <?php $use_validate_js = 1;?>
107 <?php require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?>
108 <?php
109 //Gets validation rules from Page Validation list.
110 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
111 $have_group_global_enabled = true;
112 if ((!$g_edit && !$g_view) || (!$GLOBALS['enable_group_therapy'])) {
113 $_GET['group'] = false;
114 $have_group_global_enabled = false;
117 if ($_GET['group'] == true) {
118 //groups tab
119 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php?group=true");
120 } elseif ($_GET['prov']) {
121 //providers tab
122 $collectthis = '';
123 } else { //patient tab
124 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php");
127 if (empty($collectthis)) {
128 $collectthis = "undefined";
129 } else {
130 $collectthis = $collectthis[array_keys($collectthis)[0]]["rules"];
133 <?php $disabled = (!$g_edit && $have_group_global_enabled )?' disabled=true; ':'';?>
134 <?php if ($disabled) {
135 echo '<script>$( document ).ready(function(){
136 $("input").prop("disabled", true);
137 $("select").prop("disabled", true);
138 }) </script>';
141 <?php
145 function InsertEventFull()
147 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
148 // =======================================
149 // multi providers case
150 // =======================================
151 if (is_array($_POST['form_provider'])) {
152 // obtain the next available unique key to group multiple providers around some event
153 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
154 $max = sqlFetchArray($q);
155 $new_multiple_value = $max['max'] + 1;
157 $pc_eid = null;
158 foreach ($_POST['form_provider'] as $provider) {
159 $args = $_POST;
160 // specify some special variables needed for the INSERT
161 $args['new_multiple_value'] = $new_multiple_value;
162 $args['form_provider'] = $provider;
163 $args['event_date'] = $event_date;
164 $args['duration'] = $duration * 60;
165 $args['recurrspec'] = $recurrspec;
166 $args['starttime'] = $starttime;
167 $args['endtime'] = $endtime;
168 $args['locationspec'] = $locationspec;
169 $pc_eid_temp = InsertEvent($args);
170 if ($pc_eid == null) {
171 $pc_eid = $pc_eid_temp;
175 return $pc_eid;
178 // ====================================
179 // single provider
180 // ====================================
181 } else {
182 $args = $_POST;
183 // specify some special variables needed for the INSERT
184 $args['new_multiple_value'] = "";
185 $args['event_date'] = $event_date;
186 $args['duration'] = $duration * 60;
187 $args['recurrspec'] = $recurrspec;
188 $args['starttime'] = $starttime;
189 $args['endtime'] = $endtime;
190 $args['locationspec'] = $locationspec;
191 $pc_eid = InsertEvent($args);
192 return $pc_eid;
195 function DOBandEncounter($pc_eid)
197 global $event_date,$info_msg;
198 // Save new DOB if it's there.
199 $patient_dob = trim($_POST['form_dob']);
200 $tmph = $_POST['form_hour'] + 0;
201 $tmpm = $_POST['form_minute'] + 0;
202 if ($_POST['form_ampm'] == '2' && $tmph < 12) {
203 $tmph += 12;
206 $appttime = "$tmph:$tmpm:00";
208 if ($patient_dob && $_POST['form_pid']) {
209 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
210 "pid = ?", array($patient_dob,$_POST['form_pid']));
213 // Manage tracker status.
214 // And auto-create a new encounter if appropriate.
215 if (!empty($_POST['form_pid'])) {
216 if ($GLOBALS['auto_create_new_encounters'] && $event_date == date('Y-m-d') && (is_checkin($_POST['form_apptstatus']) == '1') && !is_tracker_encounter_exist($event_date, $appttime, $_POST['form_pid'], $_GET['eid'])) {
217 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
218 if ($encounter) {
219 $info_msg .= xl("New encounter created with id");
220 $info_msg .= " $encounter";
223 # Capture the appt status and room number for patient tracker. This will map the encounter to it also.
224 if (isset($GLOBALS['temporary-eid-for-manage-tracker']) || !empty($_GET['eid'])) {
225 // Note that the temporary-eid-for-manage-tracker is used to capture the eid for new appointments and when separate a recurring
226 // appointment. It is set in the InsertEvent() function. Note that in the case of spearating a recurrent appointment, the get eid
227 // parameter is actually erroneous(is eid of the recurrent appt and not the new separated appt), so need to use the
228 // temporary-eid-for-manage-tracker global instead.
229 $temp_eid = (isset($GLOBALS['temporary-eid-for-manage-tracker'])) ? $GLOBALS['temporary-eid-for-manage-tracker'] : $_GET['eid'];
230 manage_tracker_status($event_date, $appttime, $temp_eid, $_POST['form_pid'], $_SESSION["authUser"], $_POST['form_apptstatus'], $_POST['form_room'], $encounter);
232 } else {
233 # Capture the appt status and room number for patient tracker.
234 if (!empty($_GET['eid'])) {
235 manage_tracker_status($event_date, $appttime, $_GET['eid'], $_POST['form_pid'], $_SESSION["authUser"], $_POST['form_apptstatus'], $_POST['form_room']);
240 // auto create encounter for therapy group
241 if (!empty($_POST['form_gid'])) {
242 // status Took Place is the check in of therapy group
243 if ($GLOBALS['auto_create_new_encounters'] && $event_date == date('Y-m-d') && $_POST['form_apptstatus'] == '=') {
244 $encounter = todaysTherapyGroupEncounterCheck($_POST['form_gid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false, $pc_eid);
245 if ($encounter) {
246 $info_msg .= xl("New group encounter created with id");
247 $info_msg .= " $encounter";
254 /*This function is used for setting the date of the first event when using the "day_every_week" repetition mechanism.
255 When the 'start date' is not one of the days chosen for the repetition, the start date needs to be changed to the first
256 occurrence of one of these set days. */
257 function setEventDate($start_date, $recurrence)
259 $timestamp = strtotime($start_date);
260 $day = date('w', $timestamp);
261 //If the 'start date' is one of the set days
262 if (in_array(($day+1), explode(',', $recurrence))) {
263 return $start_date;
266 //else: (we need to change start date to first occurrence of one of the set days)
268 $new_date = getTheNextAppointment($start_date, $recurrence);
270 return $new_date;
272 //================================================================================================================
274 // EVENTS TO FACILITIES (lemonsoftware)
275 //(CHEMED) get facility name
276 // edit event case - if there is no association made, then insert one with the first facility
277 if ($eid) {
278 $selfacil = '';
279 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
280 FROM openemr_postcalendar_events
281 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
282 WHERE pc_eid = ?", array($eid));
283 // if ( !$facility['pc_facility'] ) {
284 if (is_array($facility) && !$facility['pc_facility']) {
285 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']));
286 $min = $qmin['minId'];
287 $min_name = $qmin['facility'];
289 // multiple providers case
290 if ($GLOBALS['select_multi_providers']) {
291 $mul = $facility['pc_multiple'];
292 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min,$mul));
295 // EOS multiple
297 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min,$eid));
298 $e2f = $min;
299 $e2f_name = $min_name;
300 } else {
301 // not edit event
302 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
303 $e2f = $_SESSION['pc_facility'];
304 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
305 $e2f = $_COOKIE['pc_facility'];
306 } else {
307 $e2f = $facility['pc_facility'];
308 $e2f_name = $facility['name'];
313 // EOS E2F
314 // ===========================
315 //=============================================================================================================================
316 if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save") {
317 // Compute start and end time strings to be saved.
318 if ($_POST['form_allday']) {
319 $tmph = 0;
320 $tmpm = 0;
321 $duration = 24 * 60;
322 } else {
323 $tmph = $_POST['form_hour'] + 0;
324 $tmpm = $_POST['form_minute'] + 0;
325 if ($_POST['form_ampm'] == '2' && $tmph < 12) {
326 $tmph += 12;
329 $duration = abs($_POST['form_duration']); // fixes #395
332 $starttime = "$tmph:$tmpm:00";
334 $tmpm += $duration;
335 while ($tmpm >= 60) {
336 $tmpm -= 60;
337 ++$tmph;
340 $endtime = "$tmph:$tmpm:00";
342 // Set up working variables related to repeated events.
343 $my_recurrtype = 0;
344 $my_repeat_freq = 0 + $_POST['form_repeat_freq'];
345 $my_repeat_type = 0 + $_POST['form_repeat_type'];
346 $my_repeat_on_num = 1;
347 $my_repeat_on_day = 0;
348 $my_repeat_on_freq = 0;
350 // the starting date of the event, pay attention with this value
351 // when editing recurring events -- JRM Oct-08
352 $event_date = fixDate($_POST['form_date']);
354 //If used new recurrence mechanism of set days every week
355 if (!empty($_POST['days_every_week'])) {
356 $my_recurrtype = 3;
357 //loop through checkboxes and insert encounter days into array
358 $days_every_week_arr = array();
359 for ($i=1; $i<=7; $i++) {
360 if (!empty($_POST['day_' . $i])) {
361 array_push($days_every_week_arr, $i);
365 $my_repeat_freq = implode(",", $days_every_week_arr);
366 $my_repeat_type = 6;
367 $event_date = fixDate(setEventDate($_POST['form_date'], $my_repeat_freq));
368 } elseif (!empty($_POST['form_repeat'])) {
369 $my_recurrtype = 1;
370 if ($my_repeat_type > 4) {
371 $my_recurrtype = 2;
372 $time = strtotime($event_date);
373 $my_repeat_on_day = 0 + date('w', $time);
374 $my_repeat_on_freq = $my_repeat_freq;
375 if ($my_repeat_type == 5) {
376 $my_repeat_on_num = intval((date('j', $time) - 1) / 7) + 1;
377 } else {
378 // Last occurence of this weekday on the month
379 $my_repeat_on_num = 5;
382 // Maybe not needed, but for consistency with postcalendar:
383 $my_repeat_freq = 0;
384 $my_repeat_type = 0;
389 // Useless garbage that we must save.
390 $locationspecs = array("event_location" => "",
391 "event_street1" => "",
392 "event_street2" => "",
393 "event_city" => "",
394 "event_state" => "",
395 "event_postal" => ""
397 $locationspec = serialize($locationspecs);
399 // capture the recurring specifications
400 $recurrspec = array("event_repeat_freq" => "$my_repeat_freq",
401 "event_repeat_freq_type" => "$my_repeat_type",
402 "event_repeat_on_num" => "$my_repeat_on_num",
403 "event_repeat_on_day" => "$my_repeat_on_day",
404 "event_repeat_on_freq" => "$my_repeat_on_freq",
405 "exdate" => $_POST['form_repeat_exdate']
409 if ($my_recurrtype == 2) { // Added by epsdky 2016 (details in commit)
410 if ($_POST['old_repeats'] == 2) {
411 if ($_POST['rt2_flag2']) {
412 $recurrspec['rt2_pf_flag'] = "1";
414 } else {
415 $recurrspec['rt2_pf_flag'] = "1";
417 } // End of addition by epsdky
419 // no recurr specs, this is used for adding a new non-recurring event
420 $noRecurrspec = array("event_repeat_freq" => "",
421 "event_repeat_freq_type" => "",
422 "event_repeat_on_num" => "1",
423 "event_repeat_on_day" => "0",
424 "event_repeat_on_freq" => "0",
425 "exdate" => ""
427 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
428 //=============================================================================================================================
429 if ($_POST['form_action'] == "duplicate") {
430 $eid = InsertEventFull();
431 DOBandEncounter($eid);
434 // If we are saving, then save and close the window.
436 if ($_POST['form_action'] == "save") {
437 /* =======================================================
438 * UPDATE EVENTS
439 * =====================================================*/
440 if ($eid) {
441 // what is multiple key around this $eid?
442 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
444 // ====================================
445 // multiple providers
446 // ====================================
447 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
448 // obtain current list of providers regarding the multiple key
449 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']));
450 while ($current = sqlFetchArray($up)) {
451 $providers_current[] = $current['pc_aid'];
454 // get the new list of providers from the submitted form
455 $providers_new = $_POST['form_provider'];
457 // ===== Only current event of repeating series =====
458 if ($_POST['recurr_affect'] == 'current') {
459 // update all existing event records to exlude the current date
460 foreach ($providers_current as $provider) {
461 // update the provider's original event
462 // get the original event's repeat specs
463 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
464 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']));
465 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
466 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
467 if ($oldRecurrspec['exdate'] != "") {
468 $oldRecurrspec['exdate'] .= ",".$selected_date;
469 } else {
470 $oldRecurrspec['exdate'] .= $selected_date;
473 // mod original event recur specs to exclude this date
474 sqlStatement("UPDATE openemr_postcalendar_events SET " .
475 " pc_recurrspec = ? ".
476 " WHERE pc_aid = ? AND pc_multiple=?", array(serialize($oldRecurrspec),$provider,$row['pc_multiple']));
479 // obtain the next available unique key to group multiple providers around some event
480 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
481 $max = sqlFetchArray($q);
482 $new_multiple_value = $max['max'] + 1;
484 // insert a new event record for each provider selected on the form
485 foreach ($providers_new as $provider) {
486 // insert a new event on this date with POST form data
487 $args = $_POST;
488 // specify some special variables needed for the INSERT
489 $args['new_multiple_value'] = $new_multiple_value;
490 $args['form_provider'] = $provider;
491 $args['event_date'] = $event_date;
492 $args['duration'] = $duration * 60;
493 // this event is forced to NOT REPEAT
494 $args['form_repeat'] = "0";
495 $args['days_every_week'] = "0";
496 $args['recurrspec'] = $noRecurrspec;
497 $args['form_enddate'] = "0000-00-00";
498 $args['starttime'] = $starttime;
499 $args['endtime'] = $endtime;
500 $args['locationspec'] = $locationspec;
501 InsertEvent($args);
503 } // ===== Future Recurring events of a repeating series =====
504 else if ($_POST['recurr_affect'] == 'future') {
505 // update all existing event records to
506 // stop recurring on this date-1
507 $selected_date = date("Y-m-d", (strtotime($_POST['selected_date'])-24*60*60));
508 foreach ($providers_current as $provider) {
509 // In case of a change in the middle of the event
510 if (strcmp($_POST['event_start_date'], $_POST['selected_date'])!=0) {
511 // mod original event recur specs to end on this date
512 sqlStatement("UPDATE openemr_postcalendar_events SET " .
513 " pc_enddate = ? " .
514 " WHERE pc_aid = ? AND pc_multiple=?", array($selected_date, $provider, $row['pc_multiple']));
515 } // In case of a change in the event head
516 else {
517 sqlStatement("DELETE FROM openemr_postcalendar_events " .
518 " WHERE pc_aid = ? AND pc_multiple=?", array($provider, $row['pc_multiple']));
522 // obtain the next available unique key to group multiple providers around some event
523 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
524 $max = sqlFetchArray($q);
525 $new_multiple_value = $max['max'] + 1;
527 // insert a new event record for each provider selected on the form
528 foreach ($providers_new as $provider) {
529 // insert a new event on this date with POST form data
530 $args = $_POST;
531 // specify some special variables needed for the INSERT
532 $args['new_multiple_value'] = $new_multiple_value;
533 $args['form_provider'] = $provider;
534 $args['event_date'] = $event_date;
535 $args['duration'] = $duration * 60;
536 $args['recurrspec'] = $recurrspec;
537 $args['starttime'] = $starttime;
538 $args['endtime'] = $endtime;
539 $args['locationspec'] = $locationspec;
540 InsertEvent($args);
542 } else {
543 /* =================================================================== */
544 // ===== a Single event or All events in a repeating series ==========
545 /* =================================================================== */
547 // this difference means that some providers from current was UNCHECKED
548 // so we must delete this event for them
549 $r1 = array_diff($providers_current, $providers_new);
550 if (count($r1)) {
551 foreach ($r1 as $to_be_removed) {
552 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']));
556 // perform a check to see if user changed event date
557 // this is important when editing an existing recurring event
558 // oct-08 JRM
559 if ($_POST['form_date'] == $_POST['selected_date']) {
560 // user has NOT changed the start date of the event (and not recurrtype 3)
561 if ($my_recurrtype != 3) {
562 $event_date = fixDate($_POST['event_start_date']);
566 // this difference means that some providers were added
567 // so we must insert this event for them
568 $r2 = array_diff($providers_new, $providers_current);
569 if (count($r2)) {
570 foreach ($r2 as $to_be_inserted) {
571 $args = $_POST;
572 // specify some special variables needed for the INSERT
573 $args['new_multiple_value'] = $row['pc_multiple'];
574 $args['form_provider'] = $to_be_inserted;
575 $args['event_date'] = $event_date;
576 $args['duration'] = $duration * 60;
577 $args['recurrspec'] = $recurrspec;
578 $args['starttime'] = $starttime;
579 $args['endtime'] = $endtime;
580 $args['locationspec'] = $locationspec;
581 InsertEvent($args);
585 // after the two diffs above, we must update for remaining providers
586 // those who are intersected in $providers_current and $providers_new
587 foreach ($_POST['form_provider'] as $provider) {
588 sqlStatement("UPDATE openemr_postcalendar_events SET " .
589 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
590 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
591 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
592 "pc_time = NOW(), " .
593 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
594 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
595 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
596 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
597 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
598 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
599 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
600 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
601 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
602 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
603 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
604 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
605 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
606 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
607 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
608 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'");
609 } // foreach
612 // ====================================
613 // single provider
614 // ====================================
615 } elseif (!$row['pc_multiple']) {
616 if ($GLOBALS['select_multi_providers']) {
617 $prov = $_POST['form_provider'][0];
618 } else {
619 $prov = $_POST['form_provider'];
622 if ($_POST['recurr_affect'] == 'current') {
623 // get the original event's repeat specs
624 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
625 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
626 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
627 if ($oldRecurrspec['exdate'] != "") {
628 $oldRecurrspec['exdate'] .= ",".$selected_date;
629 } else {
630 $oldRecurrspec['exdate'] .= $selected_date;
633 // mod original event recur specs to exclude this date
634 sqlStatement("UPDATE openemr_postcalendar_events SET " .
635 " pc_recurrspec = ? ".
636 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid));
638 // insert a new event on this date with POST form data
639 $args = $_POST;
640 // specify some special variables needed for the INSERT
641 $args['event_date'] = $event_date;
642 $args['duration'] = $duration * 60;
643 // this event is forced to NOT REPEAT
644 $args['form_repeat'] = "0";
645 $args['days_every_week'] = "0";
646 $args['recurrspec'] = $noRecurrspec;
647 $args['form_enddate'] = "0000-00-00";
648 $args['starttime'] = $starttime;
649 $args['endtime'] = $endtime;
650 $args['locationspec'] = $locationspec;
651 InsertEvent($args);
652 } else if ($_POST['recurr_affect'] == 'future') {
653 // mod original event to stop recurring on this date-1
654 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
655 sqlStatement("UPDATE openemr_postcalendar_events SET " .
656 " pc_enddate = ? ".
657 " WHERE pc_eid = ?", array($selected_date,$eid));
659 // insert a new event starting on this date with POST form data
660 $args = $_POST;
661 // specify some special variables needed for the INSERT
662 $args['event_date'] = $event_date;
663 $args['duration'] = $duration * 60;
664 $args['recurrspec'] = $recurrspec;
665 $args['starttime'] = $starttime;
666 $args['endtime'] = $endtime;
667 $args['locationspec'] = $locationspec;
668 InsertEvent($args);
669 } else {
670 // perform a check to see if user changed event date
671 // this is important when editing an existing recurring event
672 // oct-08 JRM
673 if ($_POST['form_date'] == $_POST['selected_date']) {
674 // user has NOT changed the start date of the event (and not recurrtype 3)
675 if ($my_recurrtype != 3) {
676 $event_date = fixDate($_POST['event_start_date']);
680 // mod the SINGLE event or ALL EVENTS in a repeating series
681 // simple provider case
682 sqlStatement("UPDATE openemr_postcalendar_events SET " .
683 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
684 "pc_aid = '" . add_escape_custom($prov) . "', " .
685 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
686 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
687 "pc_time = NOW(), " .
688 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
689 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
690 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
691 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
692 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
693 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
694 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
695 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
696 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
697 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
698 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
699 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
700 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
701 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
702 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
703 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
707 // =======================================
708 // end Update Multi providers case
709 // =======================================
711 // EVENTS TO FACILITIES
712 $e2f = (int)$eid;
713 } else {
714 /* =======================================================
715 * INSERT NEW EVENT(S)
716 * ======================================================*/
718 $eid = InsertEventFull();
721 // done with EVENT insert/update statements
723 DOBandEncounter(isset($eid) ? $eid : null);
724 } // =======================================
725 // DELETE EVENT(s)
726 // =======================================
727 else if ($_POST['form_action'] == "delete") {
728 // =======================================
729 // multi providers event
730 // =======================================
731 if ($GLOBALS['select_multi_providers']) {
732 // what is multiple key around this $eid?
733 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
735 // obtain current list of providers regarding the multiple key
736 $providers_current = array();
737 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']));
738 while ($current = sqlFetchArray($up)) {
739 $providers_current[] = $current['pc_aid'];
742 // establish a WHERE clause
743 if ($row['pc_multiple']) {
744 $whereClause = "pc_multiple = '{$row['pc_multiple']}'";
745 } else {
746 $whereClause = "pc_eid = '$eid'";
749 if ($_POST['recurr_affect'] == 'current') {
750 // update all existing event records to exlude the current date
751 foreach ($providers_current as $provider) {
752 // update the provider's original event
753 // get the original event's repeat specs
754 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
755 " WHERE pc_aid <=> ? AND pc_multiple=?", array($provider,$row['pc_multiple']));
756 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
757 $selected_date = date("Y-m-d", strtotime($_POST['selected_date']));
758 if ($oldRecurrspec['exdate'] != "") {
759 $oldRecurrspec['exdate'] .= ",".$selected_date;
760 } else {
761 $oldRecurrspec['exdate'] .= $selected_date;
764 // mod original event recur specs to exclude this date
765 sqlStatement("UPDATE openemr_postcalendar_events SET " .
766 " pc_recurrspec = ? ".
767 " WHERE ". $whereClause, array(serialize($oldRecurrspec)));
769 } else if ($_POST['recurr_affect'] == 'future') {
770 // update all existing event records to stop recurring on this date-1
771 $selected_date = date("Y-m-d", (strtotime($_POST['selected_date'])-24*60*60));
772 foreach ($providers_current as $provider) {
773 // In case of a change in the middle of the event
774 if (strcmp($_POST['event_start_date'], $_POST['selected_date'])!=0) {
775 // update the provider's original event
776 sqlStatement("UPDATE openemr_postcalendar_events SET " .
777 " pc_enddate = ? " .
778 " WHERE " . $whereClause, array($selected_date));
779 } // In case of a change in the event head
780 else {
781 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
784 } else {
785 // really delete the event from the database
786 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
788 } // =======================================
789 // single provider event
790 // =======================================
791 else {
792 if ($_POST['recurr_affect'] == 'current') {
793 // mod original event recur specs to exclude this date
795 // get the original event's repeat specs
796 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
797 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
798 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
799 if ($oldRecurrspec['exdate'] != "") {
800 $oldRecurrspec['exdate'] .= ",".$selected_date;
801 } else {
802 $oldRecurrspec['exdate'] .= $selected_date;
805 sqlStatement("UPDATE openemr_postcalendar_events SET " .
806 " pc_recurrspec = ? ".
807 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid));
808 } else if ($_POST['recurr_affect'] == 'future') {
809 // mod original event to stop recurring on this date-1
810 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
811 sqlStatement("UPDATE openemr_postcalendar_events SET " .
812 " pc_enddate = ? ".
813 " WHERE pc_eid = ?", array($selected_date,$eid));
814 } else {
815 // fully delete the event from the database
816 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
821 if ($_POST['form_action'] != "") {
822 // Close this window and refresh the calendar (or the patient_tracker) display.
823 echo "<html>\n<body>\n<script language='JavaScript'>\n";
824 if ($info_msg) {
825 echo " alert('" . addslashes($info_msg) . "');\n";
828 echo " if (opener && !opener.closed && opener.refreshme) {\n " .
829 " opener.refreshme();\n " . // This is for standard calendar page refresh
830 " } else {\n " .
831 " if(window.opener.pattrk){" .
832 " window.opener.pattrk.submit()\n " . // This is for patient flow board page refresh}
833 " }};\n";
834 echo " window.close();\n";
835 echo "</script>\n</body>\n</html>\n";
836 exit();
839 //*********************************
840 // If we get this far then we are displaying the form.
841 //*********************************
843 /*********************************************************************
844 This has been migrate to the administration->lists
845 $statuses = array(
846 '-' => '',
847 '*' => xl('* Reminder done'),
848 '+' => xl('+ Chart pulled'),
849 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
850 '?' => xl('? No show'),
851 '@' => xl('@ Arrived'),
852 '~' => xl('~ Arrived late'),
853 '!' => xl('! Left w/o visit'),
854 '#' => xl('# Ins/fin issue'),
855 '<' => xl('< In exam room'),
856 '>' => xl('> Checked out'),
857 '$' => xl('$ Coding done'),
858 '%' => xl('% Cancelled < 24h ')
860 *********************************************************************/
862 $repeats = 0; // if the event repeats
863 $repeattype = '0';
864 $repeatfreq = '0';
865 $patientid = '';
866 if ($_REQUEST['patientid']) {
867 $patientid = $_REQUEST['patientid'];
870 $patientname = null;
871 $patienttitle = array();
872 $pcroom = "";
873 $hometext = "";
874 $row = array();
875 $informant = "";
876 $groupid = '';
877 if ($_REQUEST['groupid']) {
878 $groupid = $_REQUEST['groupid'];
881 $groupname = null;
882 $group_statuses = getGroupStatuses();
885 // If we are editing an existing event, then get its data.
886 if ($eid) {
887 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
889 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
890 "FROM openemr_postcalendar_events AS e " .
891 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
892 "WHERE pc_eid = ?", array($eid));
893 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
895 // instead of using the event's starting date, keep what has been provided
896 // via the GET array, see the top of this file
897 if (empty($_GET['date'])) {
898 $date = $row['pc_eventDate'];
901 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
902 $userid = $row['pc_aid'];
903 $patientid = $row['pc_pid'];
904 $groupid = $row['pc_gid'];
905 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
906 $starttimem = substr($row['pc_startTime'], 3, 2);
907 $repeats = $row['pc_recurrtype'];
908 $multiple_value = $row['pc_multiple'];
910 // parse out the repeating data, if any
911 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
912 $repeattype = $rspecs['event_repeat_freq_type'];
913 $repeatfreq = $rspecs['event_repeat_freq'];
914 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
916 // Adjustments for repeat type 2, a particular weekday of the month.
917 if ($repeats == 2) {
918 $repeatfreq = $rspecs['event_repeat_on_freq'];
919 if ($rspecs['event_repeat_on_num'] < 5) {
920 $repeattype = 5;
921 } else {
922 $repeattype = 6;
926 $recurrence_end_date = ($row['pc_endDate'] && $row['pc_endDate'] != '0000-00-00') ? $row['pc_endDate'] : null;
927 $pcroom = $row['pc_room'];
928 $hometext = $row['pc_hometext'];
929 if (substr($hometext, 0, 6) == ':text:') {
930 $hometext = substr($hometext, 6);
932 } else {
933 // a NEW event
934 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
936 //-------------------------------------
937 //(CHEMED)
938 //Set default facility for a new event based on the given 'userid'
939 if ($userid) {
940 /*************************************************************
941 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
942 *************************************************************/
943 if ($_SESSION['pc_facility']) {
944 $pref_facility = sqlFetchArray(sqlStatement(
946 SELECT f.id as facility_id,
947 f.name as facility
948 FROM facility f
949 WHERE f.id = ?
951 array($_SESSION['pc_facility'])
953 } else {
954 $pref_facility = sqlFetchArray(sqlStatement("
955 SELECT u.facility_id,
956 f.name as facility
957 FROM users u
958 LEFT JOIN facility f on (u.facility_id = f.id)
959 WHERE u.id = ?
960 ", array($userid)));
963 /************************************************************/
964 $e2f = $pref_facility['facility_id'];
965 $e2f_name = $pref_facility['facility'];
968 //END of CHEMED -----------------------
971 // If we have a patient ID, get the name and phone numbers to display.
972 if ($patientid) {
973 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
974 "FROM patient_data WHERE pid = ?", array($patientid));
975 $patientname = $prow['lname'] . ", " . $prow['fname'];
976 if ($prow['phone_home']) {
977 $patienttitle['phone_home'] = xl("Home Phone").": " . $prow['phone_home'];
980 if ($prow['phone_biz']) {
981 $patienttitle['phone_biz'] = xl("Work Phone").": " . $prow['phone_biz'];
985 // If we have a group id, get group data
986 if ($groupid) {
987 $group_data = getGroup($groupid);
988 $groupname = $group_data['group_name'];
989 $group_end_date = $group_data['group_end_date'];
990 if (!$recurrence_end_date && $group_end_date && $group_end_date != '0000-00-00') {
991 $recurrence_end_date = $group_end_date;// If there is no recurr end date get group's end date as default (only if group has an end date)
995 // Get the providers list.
996 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
997 "authorized != 0 AND active = 1 ORDER BY lname, fname");
999 // Get event categories.
1000 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
1001 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
1003 // Fix up the time format for AM/PM.
1004 $startampm = '1';
1005 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
1006 $startampm = '2';
1007 if ($starttimeh > 12) {
1008 $starttimeh -= 12;
1013 <html>
1014 <head>
1015 <?php html_header_show(); ?>
1016 <title><?php echo $eid ? xlt('Edit') : xlt('Add New') ?> <?php echo xlt('Event');?></title>
1017 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
1018 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
1020 <style>
1021 td { font-size:0.8em; }
1022 </style>
1024 <script type="text/javascript" src="../../../library/topdialog.js?v=<?php echo $v_js_includes; ?>"></script>
1025 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
1026 <script type="text/javascript" src="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
1027 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
1029 <script language="JavaScript">
1031 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
1033 var durations = new Array();
1034 // var rectypes = new Array();
1035 <?php
1036 // Read the event categories, generate their options list, and get
1037 // the default event duration from them if this is a new event.
1038 $cattype=0;
1039 if ($_GET['prov']==true) {
1040 $cattype=1;
1043 if ($_GET['group'] == true) {
1044 $cattype=3;
1047 $cres = sqlStatement("SELECT pc_catid, pc_cattype, pc_catname, " .
1048 "pc_recurrtype, pc_duration, pc_end_all_day " .
1049 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
1050 $catoptions = "";
1051 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
1052 $thisduration = 0;
1053 if ($eid) {
1054 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
1057 while ($crow = sqlFetchArray($cres)) {
1058 $duration = round($crow['pc_duration'] / 60);
1059 if ($crow['pc_end_all_day']) {
1060 $duration = 1440;
1063 // This section is to build the list of preferred categories:
1064 if ($duration) {
1065 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
1066 if ($eid) {
1067 if ($crow['pc_catid'] == $row['pc_prefcatid']) {
1068 $prefcat_options .= " selected";
1072 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
1075 if ($crow['pc_cattype'] != $cattype) {
1076 continue;
1079 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
1080 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
1081 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
1082 if ($eid) {
1083 if ($crow['pc_catid'] == $row['pc_catid']) {
1084 $catoptions .= " selected";
1086 } else {
1087 if ($crow['pc_catid'] == $default_catid) {
1088 $catoptions .= " selected";
1089 $thisduration = $duration;
1093 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
1097 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
1099 // This is for callback by the find-patient popup.
1100 function setpatient(pid, lname, fname, dob) {
1101 var f = document.forms[0];
1102 f.form_patient.value = lname + ', ' + fname;
1103 f.form_pid.value = pid;
1104 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
1105 document.getElementById('dob_row').style.display = dobstyle;
1108 // This invokes the find-patient popup.
1109 function sel_patient() {
1110 dlgopen('find_patient_popup.php', '_blank', 500, 400);
1113 // This is for callback by the find-group popup.
1114 function setgroup(gid, name, end_date) {
1115 var f = document.forms[0];
1116 f.form_group.value = name;
1117 f.form_gid.value = gid;
1118 if(f.form_enddate.value == ""){
1119 f.form_enddate.value = end_date;
1124 // This invokes the find-group popup.
1125 function sel_group() {
1126 top.restoreSession();
1127 dlgopen('find_group_popup.php', '_blank', 500, 400);
1130 // Do whatever is needed when a new event category is selected.
1131 // For now this means changing the event title and duration.
1132 function set_display() {
1133 var f = document.forms[0];
1134 var s = f.form_category;
1135 if (s.selectedIndex >= 0) {
1136 var catid = s.options[s.selectedIndex].value;
1137 var style_apptstatus = document.getElementById('title_apptstatus').style;
1138 var style_prefcat = document.getElementById('title_prefcat').style;
1139 if (catid == '2') { // In Office
1140 style_apptstatus.display = 'none';
1141 style_prefcat.display = '';
1142 f.form_apptstatus.style.display = 'none';
1143 f.form_prefcat.style.display = '';
1144 } else {
1145 style_prefcat.display = 'none';
1146 style_apptstatus.display = '';
1147 f.form_prefcat.style.display = 'none';
1148 f.form_apptstatus.style.display = '';
1153 // Do whatever is needed when a new event category is selected.
1154 // For now this means changing the event title and duration.
1155 function set_category() {
1156 var f = document.forms[0];
1157 var s = f.form_category;
1158 if (s.selectedIndex >= 0) {
1159 var catid = s.options[s.selectedIndex].value;
1160 f.form_title.value = s.options[s.selectedIndex].text;
1161 f.form_duration.value = durations[catid];
1162 set_display();
1166 // Modify some visual attributes when the all-day or timed-event
1167 // radio buttons are clicked.
1168 function set_allday() {
1169 var f = document.forms[0];
1170 var color1 = '#777777';
1171 var color2 = '#777777';
1172 var disabled2 = true;
1173 if (document.getElementById('rballday1').checked) {
1174 color1 = '#000000';
1176 if (document.getElementById('rballday2').checked) {
1177 color2 = '#000000';
1178 disabled2 = false;
1180 document.getElementById('tdallday1').style.color = color1;
1181 document.getElementById('tdallday2').style.color = color2;
1182 document.getElementById('tdallday3').style.color = color2;
1183 document.getElementById('tdallday4').style.color = color2;
1184 document.getElementById('tdallday5').style.color = color2;
1185 f.form_hour.disabled = disabled2;
1186 f.form_minute.disabled = disabled2;
1187 f.form_ampm.disabled = disabled2;
1188 f.form_duration.disabled = disabled2;
1191 // Modify some visual attributes when the Repeat checkbox is clicked.
1192 function set_repeat() {
1193 var f = document.forms[0];
1194 var isdisabled = true;
1195 var mycolor = '#777777';
1196 var myvisibility = 'hidden';
1197 if (f.form_repeat.checked) {
1198 f.days_every_week.checked = false;
1199 document.getElementById("days_label").style.color = mycolor;
1200 var days = document.getElementById("days").getElementsByTagName('input');
1201 var labels = document.getElementById("days").getElementsByTagName('label');
1202 for(var i=0; i < days.length; i++){
1203 days[i].disabled = isdisabled;
1204 labels[i].style.color = mycolor;
1206 isdisabled = false;
1207 mycolor = '#000000';
1208 myvisibility = 'visible';
1210 f.form_repeat_type.disabled = isdisabled;
1211 f.form_repeat_freq.disabled = isdisabled;
1212 f.form_enddate.disabled = isdisabled;
1213 document.getElementById('tdrepeat1').style.color = mycolor;
1214 document.getElementById('tdrepeat2').style.color = mycolor;
1217 // Event when days_every_week is checked.
1218 function set_days_every_week() {
1219 var f = document.forms[0];
1220 if (f.days_every_week.checked) {
1221 //disable regular repeat
1222 f.form_repeat.checked = false;
1223 f.form_repeat_type.disabled = true;
1224 f.form_repeat_freq.disabled = true;
1225 document.getElementById('tdrepeat1').style.color = '#777777';
1227 //enable end_date setting
1228 document.getElementById('tdrepeat2').style.color = '#000000';
1229 f.form_enddate.disabled = false;
1231 var isdisabled = false;
1232 var mycolor = '#000000';
1233 var myvisibility = 'visible';
1235 else{
1236 var isdisabled = true;
1237 var mycolor = '#777777';
1238 var myvisibility = 'hidden';
1240 document.getElementById("days_label").style.color = mycolor;
1241 var days = document.getElementById("days").getElementsByTagName('input');
1242 var labels = document.getElementById("days").getElementsByTagName('label');
1243 for(var i=0; i < days.length; i++){
1244 days[i].disabled = isdisabled;
1245 labels[i].style.color = mycolor;
1248 //If no repetition is checked, disable end_date setting.
1249 if(!f.days_every_week.checked && !f.form_repeat.checked){
1250 //disable end_date setting
1251 document.getElementById('tdrepeat2').style.color = mycolor;
1252 f.form_enddate.disabled = isdisabled;
1258 // Constants used by dateChanged() function.
1259 var occurNames = new Array(
1260 '<?php echo xls("1st"); ?>',
1261 '<?php echo xls("2nd"); ?>',
1262 '<?php echo xls("3rd"); ?>',
1263 '<?php echo xls("4th"); ?>'
1266 var weekDays = new Array(
1267 '<?php echo xls("Sunday"); ?>',
1268 '<?php echo xls("Monday"); ?>',
1269 '<?php echo xls("Tuesday"); ?>',
1270 '<?php echo xls("Wednesday"); ?>',
1271 '<?php echo xls("Thursday"); ?>',
1272 '<?php echo xls("Friday"); ?>',
1273 '<?php echo xls("Saturday"); ?>'
1276 // Monitor start date changes to adjust repeat type options.
1277 function dateChanged() {
1278 var f = document.forms[0];
1279 if (!f.form_date.value) return;
1280 var d = new Date(f.form_date.value);
1281 var downame = weekDays[d.getUTCDay()];
1282 var nthtext = '';
1283 var occur = Math.floor((d.getUTCDate() - 1) / 7);
1284 if (occur < 4) { // 5th is not allowed
1285 nthtext = occurNames[occur] + ' ' + downame;
1287 var lasttext = '';
1288 var tmp = new Date(d.getUTCFullYear(), d.getUTCMonth() + 1, 0);
1289 if (tmp.getDate() - d.getUTCDate() < 7) { // Modified by epsdky 2016 (details in commit)
1290 // This is a last occurrence of the specified weekday in the month,
1291 // so permit that as an option.
1292 lasttext = '<?php echo xls("Last"); ?> ' + downame;
1294 var si = f.form_repeat_type.selectedIndex;
1295 var opts = f.form_repeat_type.options;
1296 opts.length = 5; // remove any nth and Last entries
1297 if (nthtext ) opts[opts.length] = new Option(nthtext , '5');
1298 if (lasttext) opts[opts.length] = new Option(lasttext, '6');
1299 if (si < opts.length) f.form_repeat_type.selectedIndex = si;
1300 else f.form_repeat_type.selectedIndex = 5; // Added by epsdky 2016 (details in commit)
1303 // This is for callback by the find-available popup.
1304 function setappt(year,mon,mday,hours,minutes) {
1305 var f = document.forms[0];
1306 f.form_date.value = '' + year + '-' +
1307 ('' + (mon + 100)).substring(1) + '-' +
1308 ('' + (mday + 100)).substring(1);
1309 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
1310 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
1311 f.form_minute.value = ('' + (minutes + 100)).substring(1);
1314 // Invoke the find-available popup.
1315 function find_available(extra) {
1316 top.restoreSession();
1317 // (CHEMED) Conditional value selection, because there is no <select> element
1318 // when making an appointment for a specific provider
1319 var s = document.forms[0].form_provider;
1320 var f = document.forms[0].facility;
1321 <?php if ($userid != 0) { ?>
1322 s = document.forms[0].form_provider.value;
1323 f = document.forms[0].facility.value;
1324 <?php } else {?>
1325 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1326 f = document.forms[0].facility.options[f.selectedIndex].value;
1327 <?php }?>
1328 var c = document.forms[0].form_category;
1329 var formDate = document.forms[0].form_date;
1330 dlgopen('<?php echo $GLOBALS['web_root']; ?>/interface/main/calendar/find_appt_popup.php' +
1331 '?providerid=' + s +
1332 '&catid=' + c.options[c.selectedIndex].value +
1333 '&facility=' + f +
1334 '&startdate=' + formDate.value +
1335 '&evdur=' + document.forms[0].form_duration.value +
1336 '&eid=<?php echo 0 + $eid; ?>' +
1337 extra,
1338 '_blank', 500, 400);
1343 </script>
1345 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1347 </head>
1349 <body class="body_top main-calendar-add_edit_event" onunload='imclosing()'>
1351 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1352 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1353 <input type='hidden' size='2' name='resname' value='empty' />
1354 <?php
1355 if ($_POST["resname"]=="noresult") {
1356 echo '
1357 <script language="Javascript">
1358 // refresh and redirect the parent window
1359 if (!opener.closed && opener.refreshme) opener.refreshme();
1360 top.restoreSession();
1361 opener.document.location="../../new/new.php";
1362 // Close the window
1363 window.close();
1364 </script>';
1367 $classprov='current';
1368 $classpati='';
1370 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1371 <input type="hidden" name="form_action" id="form_action" value="">
1372 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1373 <!-- used for recurring events -->
1374 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo attr($date); ?>">
1375 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo attr($eventstartdate); ?>">
1376 <!-- Following added by epsdky 2016 (details in commit) -->
1377 <input type="hidden" name="old_repeats" id="old_repeats" value="<?php echo attr($repeats); ?>">
1378 <input type="hidden" name="rt2_flag2" id="rt2_flag2" value="<?php echo attr(isset($rspecs['rt2_pf_flag']) ? $rspecs['rt2_pf_flag'] : '0'); ?>">
1379 <!-- End of addition by epsdky -->
1380 <center>
1381 <table border='0' >
1382 <?php
1383 $provider_class='';
1384 $group_class='';
1385 $normal='';
1386 if ($_GET['prov']==true) {
1387 $provider_class="class='current'";
1388 } elseif ($_GET['group']==true) {
1389 $group_class="class='current'";
1390 } else {
1391 $normal="class='current'";
1394 <tr><th><ul class="tabNav">
1395 <?php
1396 $eid=$_REQUEST["eid"];
1397 $startm=$_REQUEST["startampm"];
1398 $starth=$_REQUEST["starttimeh"];
1399 $uid=$_REQUEST["userid"];
1400 $starttm=$_REQUEST["starttimem"];
1401 $dt=$_REQUEST["date"];
1402 $cid=$_REQUEST["catid"];
1404 <li <?php echo $normal;?>>
1405 <a href='add_edit_event.php?startampm=<?php echo attr($startm);?>&starttimeh=<?php echo attr($starth);?>&userid=<?php echo attr($uid);?>&starttimem=<?php echo attr($starttm);?>&date=<?php echo attr($dt);?>&catid=<?php echo attr($cid);?>'>
1406 <?php echo xlt('Patient');?></a>
1407 </li>
1408 <li <?php echo $provider_class;?>>
1409 <a href='add_edit_event.php?prov=true&startampm=<?php echo attr($startm);?>&starttimeh=<?php echo attr($starth);?>&userid=<?php echo attr($uid);?>&starttimem=<?php echo attr($starttm);?>&date=<?php echo attr($dt);?>&catid=<?php echo attr($cid);?>'>
1410 <?php echo xlt('Provider');?></a>
1411 </li>
1412 <?php if ($have_group_global_enabled) :?>
1413 <li <?php echo $group_class ;?>>
1414 <a href='add_edit_event.php?group=true&startampm=<?php echo attr($startm);?>&starttimeh=<?php echo attr($starth);?>&userid=<?php echo attr($uid);?>&starttimem=<?php echo attr($starttm);?>&date=<?php echo attr($dt);?>&catid=<?php echo attr($cid);?>'>
1415 <?php echo xlt('Group');?></a>
1416 </li>
1417 <?php endif ?>
1418 </ul>
1419 </th></tr>
1420 <tr><td colspan='10'>
1421 <table border='0' width='100%' bgcolor='#DDDDDD'>
1422 <tr>
1423 <td width='1%' nowrap>
1424 <b><?php echo xlt('Category'); ?>:</b>
1425 </td>
1426 <td nowrap>
1427 <select name='form_category' onchange='set_category()' style='width:100%'>
1428 <?php echo $catoptions ?>
1429 </select>
1430 </td>
1431 <td width='1%' nowrap>
1432 &nbsp;&nbsp;
1433 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1434 <?php if ($thisduration == 1440) {
1435 echo "checked ";
1436 } ?>/>
1437 </td>
1438 <td colspan='2' nowrap id='tdallday1'>
1439 <?php echo xlt('All day event'); ?>
1440 </td>
1441 </tr>
1442 <tr>
1443 <td nowrap>
1444 <b><?php echo xlt('Date'); ?>:</b>
1445 </td>
1446 <td nowrap>
1447 <input type='text' size='10' class='datepicker' name='form_date' id='form_date'
1448 value='<?php echo attr($date) ?>'
1449 title='<?php echo xla('yyyy-mm-dd event date or starting date'); ?>'
1450 onchange='dateChanged()' />
1451 </td>
1452 <td nowrap>
1453 &nbsp;&nbsp;
1454 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) {
1455 echo "checked ";
1456 } ?>/>
1457 </td>
1458 <td width='1%' nowrap id='tdallday2'>
1459 <?php echo xlt('Time'); ?>
1460 </td>
1461 <td width='1%' nowrap id='tdallday3'>
1462 <span>
1463 <input type='text' size='2' name='form_hour' value='<?php echo attr($starttimeh) ?>'
1464 title='<?php echo xla('Event start time'); ?>' /> :
1465 <input type='text' size='2' name='form_minute' value='<?php echo attr($starttimem) ?>'
1466 title='<?php echo xla('Event start time'); ?>' />&nbsp;
1467 </span>
1468 <select name='form_ampm' title='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1469 <option value='1'><?php echo xlt('AM'); ?></option>
1470 <option value='2'<?php if ($startampm == '2') {
1471 echo " selected";
1472 } ?>><?php echo xlt('PM'); ?></option>
1473 </select>
1474 </td>
1475 </tr>
1476 <tr>
1477 <td nowrap>
1478 <b><?php echo xlt('Title'); ?>:</b>
1479 </td>
1480 <td nowrap>
1481 <input type='text' size='10' name='form_title' value='<?php echo attr($row['pc_title']); ?>'
1482 style='width:100%'
1483 title='<?php echo xla('Event title'); ?>' />
1484 </td>
1485 <td nowrap>&nbsp;
1487 </td>
1488 <td nowrap id='tdallday4'><?php echo xlt('duration'); ?>
1489 </td>
1490 <td nowrap id='tdallday5'>
1491 <input type='text' size='4' name='form_duration' value='<?php echo attr($thisduration) ?>' title='<?php echo xla('Event duration in minutes'); ?>' />
1492 <?php echo xlt('minutes'); ?>
1493 </td>
1494 </tr>
1496 <tr>
1497 <td nowrap><b><?php echo xlt('Facility'); ?>:</b></td>
1498 <td>
1499 <select name="facility" id="facility" >
1500 <?php
1502 // ===========================
1503 // EVENTS TO FACILITIES
1504 //(CHEMED) added service_location WHERE clause
1505 // get the facilities
1506 /***************************************************************
1507 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1508 ***************************************************************/
1509 $facils = getUserFacilities($_SESSION['authId']);
1510 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1511 /**************************************************************/
1512 while ($facrow = sqlFetchArray($qsql)) {
1513 /*************************************************************
1514 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1515 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1516 *************************************************************/
1517 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1518 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1519 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1520 } else {
1521 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1522 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1525 /************************************************************/
1528 // EOS E2F
1529 // ===========================
1531 <?php
1532 //END (CHEMED) IF ?>
1533 </td>
1534 </select>
1535 </tr>
1536 <tr>
1537 <td nowrap>
1538 <b><?php echo xlt('Billing Facility'); ?>:</b>
1539 </td>
1540 <td>
1541 <?php
1542 billing_facility('billing_facility', $row['pc_billing_location']);
1544 </td>
1545 </tr>
1546 <?php
1547 if ($_GET['prov']!=true && $_GET['group']!=true) {
1549 <tr id="patient_details">
1550 <td nowrap>
1551 <b><?php echo xlt('Patient'); ?>:</b>
1552 </td>
1553 <td nowrap>
1554 <input type='text' size='10' name='form_patient' id="form_patient" style='width:100%;cursor:pointer;cursor:hand' placeholder='<?php echo xla('Click to select');?>' value='<?php echo is_null($patientname) ? '' : attr($patientname); ?>' onclick='sel_patient()' title='<?php echo xla('Click to select patient'); ?>' readonly />
1555 <input type='hidden' name='form_pid' value='<?php echo attr($patientid) ?>' />
1556 </td>
1557 <td colspan='3' nowrap style='font-size:8pt'>
1558 <span class="infobox">
1559 <?php foreach ($patienttitle as $value) {
1560 if ($value != "") {
1561 echo text(trim($value));
1564 if (count($patienttitle) > 1) {
1565 echo "<br />";
1569 </span>
1570 </td>
1571 </tr>
1572 <?php
1575 <?php
1576 if ($_GET['group']==true && $have_group_global_enabled) {
1578 <tr id="group_details">
1579 <td nowrap>
1580 <b><?php echo xlt('Group'); ?>:</b>
1581 </td>
1582 <td nowrap>
1583 <input type='text' size='10' name='form_group' id="form_group" style='width:100%;cursor:pointer;cursor:hand' placeholder='<?php echo xla('Click to select');?>' value='<?php echo is_null($groupname) ? '' : attr($groupname); ?>' onclick='sel_group()' title='<?php echo xla('Click to select group'); ?>' readonly />
1584 <input type='hidden' name='form_gid' value='<?php echo attr($groupid) ?>' />
1585 </td>
1586 <td colspan='3' nowrap style='font-size:8pt'>
1587 <span class="infobox">
1588 <?php foreach ($patienttitle as $value) {
1589 if ($value != "") {
1590 echo trim($value);
1593 if (count($patienttitle) > 1) {
1594 echo "<br />";
1598 </span>
1599 </td>
1600 </tr>
1601 <?php
1604 <tr>
1605 <td nowrap>
1606 <b><?php if ($_GET['group']==true) {
1607 echo xlt('Coordinating Counselors');
1608 } else {
1609 echo xlt('Provider');
1610 } ?>:</b>
1611 </td>
1612 <td nowrap>
1614 <?php
1616 // =======================================
1617 // multi providers
1618 // =======================================
1619 if ($GLOBALS['select_multi_providers']) {
1620 // there are two posible situations: edit and new record
1621 $providers_array = array();
1622 // this is executed only on edit ($eid)
1623 if ($eid) {
1624 if ($multiple_value) {
1625 // find all the providers around multiple key
1626 $qall = sqlStatement("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value));
1627 while ($r = sqlFetchArray($qall)) {
1628 $providers_array[] = $r['providers'];
1630 } else {
1631 $qall = sqlStatement("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
1632 $providers_array = sqlFetchArray($qall);
1636 // build the selection tool
1637 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1639 while ($urow = sqlFetchArray($ures)) {
1640 echo " <option value='" . attr($urow['id']) . "'";
1642 if ($userid) {
1643 if (in_array($urow['id'], $providers_array) || ($urow['id'] == $userid)) {
1644 echo " selected";
1648 echo ">" . text($urow['lname']);
1649 if ($urow['fname']) {
1650 echo ", " . text($urow['fname']);
1653 echo "</option>\n";
1656 echo '</select>';
1658 // =======================================
1659 // single provider
1660 // =======================================
1661 } else {
1662 if ($eid) {
1663 // get provider from existing event
1664 $qprov = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
1665 $provider = sqlFetchArray($qprov);
1666 $defaultProvider = $provider['pc_aid'];
1667 } else {
1668 // this is a new event so smartly choose a default provider
1669 /*****************************************************************
1670 if ($userid) {
1671 // Provider already given to us as a GET parameter.
1672 $defaultProvider = $userid;
1674 else {
1675 // default to the currently logged-in user
1676 $defaultProvider = $_SESSION['authUserID'];
1677 // or, if we have chosen a provider in the calendar, default to them
1678 // choose the first one if multiple have been selected
1679 if (count($_SESSION['pc_username']) >= 1) {
1680 // get the numeric ID of the first provider in the array
1681 $pc_username = $_SESSION['pc_username'];
1682 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1683 $defaultProvider = $firstProvider['id'];
1688 echo "<select name='form_provider' style='width:100%' />";
1689 while ($urow = sqlFetchArray($ures)) {
1690 echo " <option value='" . $urow['id'] . "'";
1691 if ($urow['id'] == $defaultProvider) echo " selected";
1692 echo ">" . $urow['lname'];
1693 if ($urow['fname']) echo ", " . $urow['fname'];
1694 echo "</option>\n";
1696 echo "</select>";
1697 *****************************************************************/
1698 // default to the currently logged-in user
1699 $defaultProvider = $_SESSION['authUserID'];
1700 // or, if we have chosen a provider in the calendar, default to them
1701 // choose the first one if multiple have been selected
1702 if (count($_SESSION['pc_username']) >= 1) {
1703 // get the numeric ID of the first provider in the array
1704 $pc_username = $_SESSION['pc_username'];
1705 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0])));
1706 $defaultProvider = $firstProvider['id'];
1709 // if we clicked on a provider's schedule to add the event, use THAT.
1710 if ($userid) {
1711 $defaultProvider = $userid;
1715 echo "<select name='form_provider' style='width:100%' />";
1716 while ($urow = sqlFetchArray($ures)) {
1717 echo " <option value='" . attr($urow['id']) . "'";
1718 if ($urow['id'] == $defaultProvider) {
1719 echo " selected";
1722 echo ">" . text($urow['lname']);
1723 if ($urow['fname']) {
1724 echo ", " . text($urow['fname']);
1727 echo "</option>\n";
1730 echo "</select>";
1731 /****************************************************************/
1736 </td>
1737 <td nowrap>
1738 &nbsp;&nbsp;
1739 <?php
1740 //Check if repeat is using the new 'days every week' mechanism.
1741 function isDaysEveryWeek($repeat)
1743 if ($repeat == 3) {
1744 return true;
1745 } else {
1746 return false;
1750 //Check if using the regular repeat mechanism.
1751 function isRegularRepeat($repeat)
1753 if ($repeat == 1 || $repeat == 2) {
1754 return true;
1755 } else {
1756 return false;
1762 If the appointment was set with the regular (old) repeat mechanism (using 'every', 'every 2', etc.), then will be
1763 checked when editing and will select the proper recurrence pattern. If using the new repeat mechanism, then only that box (and the proper set
1764 days) will be checked. That's why I had to add the functions 'isRegularRepeat' and 'isDaysEveryWeek', to check which
1765 repeating mechanism is being used, and load settings accordingly.
1768 <input type='checkbox' name='form_repeat' id="form_repeat" onclick='set_repeat(this)' value='1'<?php if (isRegularRepeat($repeats)) {
1769 echo " checked";
1770 } ?>/>
1771 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat -->
1772 </td>
1773 <td nowrap id='tdrepeat1'><?php echo xlt('Repeats'); ?>
1774 </td>
1775 <td nowrap>
1777 <select name='form_repeat_freq' title='<?php echo xla('Every, every other, every 3rd, etc.'); ?>'>
1778 <?php
1779 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1780 as $key => $value) {
1781 echo " <option value='" . attr($key) . "'";
1782 if ($key == $repeatfreq && isRegularRepeat($repeats)) {
1783 echo " selected";
1786 echo ">" . text($value) . "</option>\n";
1789 </select>
1791 <select name='form_repeat_type'>
1792 <?php
1793 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1794 // when the start date is set.
1795 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1796 5 => '?', 6 => '?') as $key => $value) {
1797 echo " <option value='" . attr($key) . "'";
1798 if ($key == $repeattype && isRegularRepeat($repeats)) {
1799 echo " selected";
1802 echo ">" . text($value) . "</option>\n";
1805 </select>
1807 </td>
1808 </tr>
1810 <style>
1811 #days_every_week_row input[type="checkbox"]{float:right;}
1812 #days_every_week_row div{display: inline-block; text-align: center; width: 12%;}
1813 #days_every_week_row div input{width: 100%;}
1814 </style>
1816 <tr id="days_every_week_row">
1817 <td></td>
1818 <td></td>
1819 <td><input type='checkbox' id='days_every_week' name='days_every_week' onclick='set_days_every_week()' <?php if (isDaysEveryWeek($repeats)) {
1820 echo " checked";
1821 } ?>/></td>
1822 <td id="days_label"><?php echo xlt('Days Of Week') . ": "; ?></td>
1823 <td id="days">
1824 <?php
1825 foreach (array(1 => xl('Su{{Sunday}}') , 2 => xl('Mo{{Monday}}'), 3 => xl('Tu{{Tuesday}}'), 4 => xl('We{{Wednesday}}'),
1826 5 => xl('Th{{Thursday}}'), 6 => xl('Fr{{Friday}}'), 7 => xl('Sa{{Saturday}}')) as $key => $value) {
1827 echo " <div><input type='checkbox' name='day_". attr($key) ."'";
1828 //Checks appropriate days according to days in recurrence string.
1829 if (in_array($key, explode(',', $repeatfreq)) && isDaysEveryWeek($repeats)) {
1830 echo " checked";
1833 echo " /><label>" . text($value) . "</label></div>\n";
1836 </td>
1838 </tr>
1841 <tr>
1842 <td nowrap>
1843 <span id='title_apptstatus'><b><?php echo xlt('Status'); ?>:</b></span>
1844 <span id='title_prefcat' style='display:none'><b><?php echo xlt('Pref Cat'); ?>:</b></span>
1845 </td>
1846 <td nowrap>
1848 <?php
1849 if ($_GET['group']!=true) {
1850 generate_form_field(array('data_type' => 1, 'field_id' => 'apptstatus', 'list_id' => 'apptstat', 'empty_title' => 'SKIP'), $row['pc_apptstatus']);
1851 } else {
1852 generate_form_field(array('data_type' => 1, 'field_id' => 'apptstatus', 'list_id' => 'groupstat', 'empty_title' => 'SKIP'), $row['pc_apptstatus']);
1856 <!--
1857 The following list will be invisible unless this is an In Office
1858 event, in which case form_apptstatus (above) is to be invisible.
1860 <select name='form_prefcat' style='width:100%;display:none' title='<?php echo xla('Preferred Event Category');?>'>
1861 <?php echo $prefcat_options ?>
1862 </select>
1864 </td>
1865 <td nowrap>&nbsp;
1867 </td>
1868 <td nowrap id='tdrepeat2'><?php echo xlt('until date'); ?>
1869 </td>
1870 <td nowrap>
1871 <input type='text' size='10' class='datepicker' name='form_enddate' id='form_enddate' value='<?php echo attr($recurrence_end_date) ?>' title='<?php echo xla('yyyy-mm-dd last date of this event');?>' />
1872 <?php
1873 if ($repeatexdate != "") {
1874 $tmptitle = "The following dates are excluded from the repeating series";
1875 if ($multiple_value) {
1876 $tmptitle .= " for one or more providers:\n";
1877 } else {
1878 $tmptitle .= "\n";
1881 $max = $GLOBALS['number_of_ex_appts_to_show'];
1883 $exdates = explode(",", $repeatexdate);
1884 if (!empty($exdates)) {
1885 $exdates=array_slice($exdates, 0, $max, true);
1888 foreach ($exdates as $exdate) {
1889 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1892 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1895 </td>
1896 </tr>
1897 <?php
1898 if ($_GET['prov']!=true) {
1900 <tr>
1901 <td nowrap>
1902 <b><?php echo xlt('Room Number'); ?>:</b>
1903 </td>
1904 <td colspan='4' nowrap>
1905 <?php
1906 echo generate_select_list('form_room', 'patient_flow_board_rooms', $pcroom, xl('Room Number'));
1908 </td>
1909 </tr>
1910 <?php
1911 } ?>
1912 <tr>
1913 <td nowrap>
1914 <b><?php echo xlt('Comments'); ?>:</b>
1915 </td>
1916 <td colspan='4' nowrap>
1917 <input type='text' size='40' name='form_comments' style='width:100%' value='<?php echo attr($hometext); ?>' title='<?php echo xla('Optional information about this event');?>' />
1918 </td>
1919 </tr>
1922 <?php
1923 // DOB is important for the clinic, so if it's missing give them a chance
1924 // to enter it right here. We must display or hide this row dynamically
1925 // in case the patient-select popup is used.
1926 $patient_dob = trim($prow['DOB']);
1927 $is_group = $groupname;
1928 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00') && !$is_group) ?
1929 '' : 'none';
1931 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1932 <td colspan='4' nowrap>
1933 <b><font color='red'><?php echo xlt('DOB is missing, please enter if possible'); ?>:</font></b>
1934 </td>
1935 <td nowrap>
1936 <input type='text' size='10' class='datepicker' name='form_dob' id='form_dob' title='<?php echo xla('yyyy-mm-dd date of birth');?>' />
1937 </td>
1938 </tr>
1940 </table></td></tr>
1942 <tr class='text'><td colspan='10' class="buttonbar">
1944 <input type='button' name='form_save' id='form_save' value='<?php echo xla('Save');?>' />
1945 &nbsp;
1947 <?php if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1948 <input type='button' id='find_available' value='<?php echo xla('Find Available');?>' />
1949 <?php } ?>
1951 &nbsp;
1952 <input type='button' name='form_delete' id='form_delete' value='<?php echo xla('Delete');?>'<?php if (!$eid) {
1953 echo " disabled";
1954 } ?> />
1955 &nbsp;
1956 <input type='button' id='cancel' value='<?php echo xla('Cancel');?>' />
1957 &nbsp;
1958 <input type='button' name='form_duplicate' id='form_duplicate' value='<?php echo xla('Create Duplicate');?>' />
1959 </p></td></tr></table>
1960 <?php if ($informant) {
1961 echo "<p class='text'>" . xlt('Last update by') . " " .
1962 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n";
1963 } ?>
1964 </center>
1965 </form>
1967 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1968 <?php echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?>
1969 <br>
1970 <?php if ($GLOBALS['submit_changes_for_all_appts_at_once']) {?>
1971 <input type="button" name="all_events" id="all_events" value=" <?php echo xla('All'); ?> ">
1972 <?php } ?>
1973 <input type="button" name="recurr_cancel" id="recurr_cancel" value="<?php echo xla('Cancel'); ?>">
1974 <input type="button" name="future_events" id="future_events" value="<?php echo xla('Future'); ?>">
1975 <input type="button" name="current_event" id="current_event" value="<?php echo xla('Current'); ?>">
1976 </div>
1978 </body>
1980 <script language='JavaScript'>
1981 <?php if ($eid) { ?>
1982 set_display();
1983 <?php } else { ?>
1984 set_category();
1985 <?php } ?>
1986 set_allday();
1987 set_repeat();
1988 set_days_every_week();
1990 </script>
1992 <script language="javascript">
1993 // jQuery stuff to make the page a little easier to use
1995 $(document).ready(function(){
1996 $("#form_save").click(function(e) { validateform(e,"save"); });
1997 $("#form_duplicate").click(function(e) { validateform(e,"duplicate"); });
1998 $("#find_available").click(function() { find_available(''); });
1999 $("#form_delete").click(function() { deleteEvent(); });
2000 $("#cancel").click(function() { window.close(); });
2002 // buttons affecting the modification of a repeating event
2003 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
2004 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
2005 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
2006 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
2008 // Initialize repeat options.
2009 dateChanged();
2011 $('.datepicker').datetimepicker({
2012 <?php $datetimepicker_timepicker = false; ?>
2013 <?php $datetimepicker_showseconds = false; ?>
2014 <?php $datetimepicker_formatInput = false; ?>
2015 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
2016 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
2021 function are_days_checked(){
2022 var days = document.getElementById("days").getElementsByTagName('input');
2023 var counter = 0;
2024 for(var i=0; i < days.length; i++){
2025 if(days[i].checked){
2026 counter++;
2029 return counter;
2033 * validation on the form with new client side validation (using validate.js).
2034 * this enable to add new rules for this form in the pageValidation list.
2035 * */
2036 var collectvalidation = <?php echo($collectthis); ?>;
2037 function validateform(event,valu){
2039 $('#form_save').attr('disabled', true);
2041 //Make sure if days_every_week is checked that at least one weekday is checked.
2042 if($('#days_every_week').is(':checked') && !are_days_checked()){
2043 alert('<?php echo xls("Must choose at least one day!"); ?>');
2044 $('#form_save').attr('disabled', false);
2045 return false;
2048 <?php if (!$GLOBALS['allow_early_check_in']) { ?>
2049 //Prevent from user to change status to Arrive before the time
2050 //Dependent in globals setting - allow_early_check_in
2051 if($('#form_apptstatus').val() == '@' && new Date($('#form_date').val()).getTime() > new Date().getTime()){
2052 alert('<?php echo xls("You can not change status to 'Arrive' before the appointment's time") .'.'; ?>');
2053 $('#form_save').attr('disabled', false);
2054 return false;
2056 <?php } ?>
2058 //add rule if choose repeating event
2059 if ($('#form_repeat').is(':checked') || $('#days_every_week').is(':checked')){
2060 collectvalidation.form_enddate = {
2061 datetime: {
2062 dateOnly: true,
2063 earliest: $('#form_date').val(),
2064 message: "An end date later than the start date is required for repeated events!"
2066 presence: true
2068 } else {
2069 if(typeof (collectvalidation) != 'undefined'){
2070 delete collectvalidation.form_enddate;
2075 <?php
2076 if ($GLOBALS['select_multi_providers']) {
2078 //If multiple providers is enabled, create provider validation (Note: if no provider is chosen it causes bugs when deleting recurrent events).
2079 if(typeof (collectvalidation) == 'undefined'){
2080 collectvalidation = {form_provider:{presence: true}};
2082 else{
2083 collectvalidation.form_provider = {presence: true};
2085 <?php
2090 var submit = submitme(1, event, 'theform', collectvalidation);
2091 if(!submit)return $('#form_save').attr('disabled', false);
2093 $('#form_action').val(valu);
2095 <?php if ($repeats) : ?>
2096 // existing repeating events need additional prompt
2097 if ($("#recurr_affect").val() == "") {
2098 DisableForm();
2099 // show the current/future/all DIV for the user to choose one
2100 $("#recurr_popup").css("visibility", "visible");
2101 $('#form_save').attr('disabled', false);
2102 return false;
2104 <?php endif; ?>
2106 SubmitForm();
2110 // disable all the form elements outside the recurr_popup
2111 function DisableForm() {
2112 $("#theform").children().attr("disabled", "true");
2114 function EnableForm() {
2115 $("#theform").children().removeAttr("disabled");
2117 // hide the recurring popup DIV
2118 function HideRecurrPopup() {
2119 $("#recurr_popup").css("visibility", "hidden");
2122 function deleteEvent() {
2123 if (confirm("<?php echo addslashes(xl('Deleting this event cannot be undone. It cannot be recovered once it is gone. Are you sure you wish to delete this event?')); ?>")) {
2124 $('#form_action').val("delete");
2126 <?php if ($repeats) : ?>
2127 // existing repeating events need additional prompt
2128 if ($("#recurr_affect").val() == "") {
2129 DisableForm();
2130 // show the current/future/all DIV for the user to choose one
2131 $("#recurr_popup").css("visibility", "visible");
2132 return false;
2134 <?php endif; ?>
2136 return SubmitForm();
2138 return false;
2141 function SubmitForm() {
2142 var f = document.forms[0];
2143 <?php if (!($GLOBALS['select_multi_providers']) && !$_GET['prov']) { // multi providers appt is not supported by check slot avail window, so skip. && is not provider tab. ?>
2144 if (f.form_action.value != 'delete') {
2145 // Check slot availability.
2146 var mins = parseInt(f.form_hour.value) * 60 + parseInt(f.form_minute.value);
2147 if (f.form_ampm.value == '2' && mins < 720) mins += 720;
2148 find_available('&cktime=' + mins);
2150 else {
2151 top.restoreSession();
2152 f.submit();
2154 <?php } else { ?>
2155 <?php
2156 /*Support Multi-Provider Events in features*/
2157 $sdate=$date;
2158 $edate=new DateTime($date);
2159 $edate->modify('tomorrow');
2160 $edate=$edate->format('Y-m-d');
2161 $is_holiday=false;
2162 $holidays_controller = new Holidays_Controller();
2163 $holidays = $holidays_controller->get_holidays_by_date_range($sdate, $edate);
2164 if (in_array($sdate, $holidays)) {
2165 $is_holiday=true;
2167 if (f.form_action.value != 'delete') {
2168 <?php if ($is_holiday) {?>
2169 if (!confirm('<?php echo xls('On this date there is a holiday, use it anyway?'); ?>')) {
2170 top.restoreSession();
2172 <?php }?>
2174 top.restoreSession();
2175 f.submit();
2176 <?php } ?>
2178 return true;
2181 </script>
2183 </html>