migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / main / calendar / add_edit_event.php
blob51a22ef25334442e1103ca9f9ccb66901a2c7eff
1 <?php
3 /**
4 * Add or edit an event in the calendar.
6 * Can be displayed as a popup window, or as an iframe via
7 * fancybox.
9 * Copyright (C) 2005-2013 Rod Roark <rod@sunsetsystems.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * @package OpenEMR
17 * @author Rod Roark <rod@sunsetsystems.com>
18 * @link http://www.open-emr.org
21 // The event editor looks something like this:
23 //------------------------------------------------------------//
24 // Category __________________V O All day event //
25 // Date _____________ [?] O Time ___:___ __V //
26 // Title ___________________ duration ____ minutes //
27 // Patient _(Click_to_select)_ //
28 // Provider __________________V X Repeats ______V ______V //
29 // Status __________________V until __________ [?] //
30 // Comments ________________________________________________ //
31 // //
32 // [Save] [Find Available] [Delete] [Cancel] //
33 //------------------------------------------------------------//
35 $fake_register_globals=false;
36 $sanitize_all_escapes=true;
38 require_once('../../globals.php');
39 require_once($GLOBALS['srcdir'].'/patient.inc');
40 require_once($GLOBALS['srcdir'].'/forms.inc');
41 require_once($GLOBALS['srcdir'].'/calendar.inc');
42 require_once($GLOBALS['srcdir'].'/options.inc.php');
43 require_once($GLOBALS['srcdir'].'/encounter_events.inc.php');
44 require_once($GLOBALS['srcdir'].'/acl.inc');
45 require_once($GLOBALS['srcdir'].'/patient_tracker.inc.php');
46 require_once($GLOBALS['incdir']."/main/holidays/Holidays_Controller.php");
48 //Check access control
49 if (!acl_check('patients','appt','',array('write','wsome') ))
50 die(xl('Access not allowed'));
52 /* Things that might be passed by our opener. */
53 $eid = $_GET['eid']; // only for existing events
54 $date = $_GET['date']; // this and below only for new events
55 $userid = $_GET['userid'];
56 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
58 if ($date)
59 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
60 else
61 $date = date("Y-m-d");
63 $starttimem = '00';
64 if (isset($_GET['starttimem']))
65 $starttimem = substr('00' . $_GET['starttimem'], -2);
67 if (isset($_GET['starttimeh'])) {
68 $starttimeh = $_GET['starttimeh'];
69 if (isset($_GET['startampm'])) {
70 if ($_GET['startampm'] == '2' && $starttimeh < 12)
71 $starttimeh += 12;
73 } else {
74 $starttimeh = date("G");
76 $startampm = '';
78 $info_msg = "";
81 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
82 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative'] ?>/jquery-min-1-9-1/index.js"></script>
84 <!-- validation library -->
85 <!--//Not lbf forms use the new validation, please make sure you have the corresponding values in the list Page validation-->
86 <?php $use_validate_js = 1;?>
87 <?php require_once($GLOBALS['srcdir'] . "/validation/validation_script.js.php"); ?>
88 <?php
89 //Gets validation rules from Page Validation list.
90 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
91 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php");
92 if (empty($collectthis)) {
93 $collectthis = "undefined";
95 else {
96 $collectthis = $collectthis["theform"]["rules"];
100 <?php
102 function InsertEventFull()
104 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
105 // =======================================
106 // multi providers case
107 // =======================================
108 if (is_array($_POST['form_provider'])) {
110 // obtain the next available unique key to group multiple providers around some event
111 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
112 $max = sqlFetchArray($q);
113 $new_multiple_value = $max['max'] + 1;
115 foreach ($_POST['form_provider'] as $provider) {
116 $args = $_POST;
117 // specify some special variables needed for the INSERT
118 $args['new_multiple_value'] = $new_multiple_value;
119 $args['form_provider'] = $provider;
120 $args['event_date'] = $event_date;
121 $args['duration'] = $duration * 60;
122 $args['recurrspec'] = $recurrspec;
123 $args['starttime'] = $starttime;
124 $args['endtime'] = $endtime;
125 $args['locationspec'] = $locationspec;
126 InsertEvent($args);
129 // ====================================
130 // single provider
131 // ====================================
132 } else {
133 $args = $_POST;
134 // specify some special variables needed for the INSERT
135 $args['new_multiple_value'] = "";
136 $args['event_date'] = $event_date;
137 $args['duration'] = $duration * 60;
138 $args['recurrspec'] = $recurrspec;
139 $args['starttime'] = $starttime;
140 $args['endtime'] = $endtime;
141 $args['locationspec'] = $locationspec;
142 InsertEvent($args);
145 function DOBandEncounter()
147 global $event_date,$info_msg;
148 // Save new DOB if it's there.
149 $patient_dob = trim($_POST['form_dob']);
150 $tmph = $_POST['form_hour'] + 0;
151 $tmpm = $_POST['form_minute'] + 0;
152 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
153 $appttime = "$tmph:$tmpm:00";
155 if ($patient_dob && $_POST['form_pid']) {
156 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
157 "pid = ?", array($patient_dob,$_POST['form_pid']) );
160 // Manage tracker status.
161 // And auto-create a new encounter if appropriate.
162 if (!empty($_POST['form_pid'])) {
163 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']))
165 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
166 if($encounter){
167 $info_msg .= xl("New encounter created with id");
168 $info_msg .= " $encounter";
170 # Capture the appt status and room number for patient tracker. This will map the encounter to it also.
171 if ( isset($GLOBALS['temporary-eid-for-manage-tracker']) || !empty($_GET['eid']) ) {
172 // Note that the temporary-eid-for-manage-tracker is used to capture the eid for new appointments and when separate a recurring
173 // appointment. It is set in the InsertEvent() function. Note that in the case of spearating a recurrent appointment, the get eid
174 // parameter is actually erroneous(is eid of the recurrent appt and not the new separated appt), so need to use the
175 // temporary-eid-for-manage-tracker global instead.
176 $temp_eid = (isset($GLOBALS['temporary-eid-for-manage-tracker'])) ? $GLOBALS['temporary-eid-for-manage-tracker'] : $_GET['eid'];
177 manage_tracker_status($event_date,$appttime,$temp_eid,$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room'],$encounter);
180 else
182 # Capture the appt status and room number for patient tracker.
183 if (!empty($_GET['eid'])) {
184 manage_tracker_status($event_date,$appttime,$_GET['eid'],$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room']);
192 /*This function is used for setting the date of the first event when using the "day_every_week" repetition mechanism.
193 When the 'start date' is not one of the days chosen for the repetition, the start date needs to be changed to the first
194 occurrence of one of these set days. */
195 function setEventDate($start_date, $recurrence){
196 $timestamp = strtotime($start_date);
197 $day = date('w', $timestamp);
198 //If the 'start date' is one of the set days
199 if(in_array(($day+1), explode(',',$recurrence))){
200 return $start_date;
202 //else: (we need to change start date to first occurrence of one of the set days)
204 $new_date = getTheNextAppointment($start_date, $recurrence);
206 return $new_date;
210 //================================================================================================================
212 // EVENTS TO FACILITIES (lemonsoftware)
213 //(CHEMED) get facility name
214 // edit event case - if there is no association made, then insert one with the first facility
215 if ( $eid ) {
216 $selfacil = '';
217 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
218 FROM openemr_postcalendar_events
219 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
220 WHERE pc_eid = ?", array($eid) );
221 // if ( !$facility['pc_facility'] ) {
222 if ( is_array($facility) && !$facility['pc_facility'] ) {
223 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']) );
224 $min = $qmin['minId'];
225 $min_name = $qmin['facility'];
227 // multiple providers case
228 if ( $GLOBALS['select_multi_providers'] ) {
229 $mul = $facility['pc_multiple'];
230 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min,$mul) );
232 // EOS multiple
234 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min,$eid) );
235 $e2f = $min;
236 $e2f_name = $min_name;
237 } else {
238 // not edit event
239 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
240 $e2f = $_SESSION['pc_facility'];
241 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
242 $e2f = $_COOKIE['pc_facility'];
243 } else {
244 $e2f = $facility['pc_facility'];
245 $e2f_name = $facility['name'];
249 // EOS E2F
250 // ===========================
251 //=============================================================================================================================
252 if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
255 // Compute start and end time strings to be saved.
256 if ($_POST['form_allday']) {
257 $tmph = 0;
258 $tmpm = 0;
259 $duration = 24 * 60;
260 } else {
261 $tmph = $_POST['form_hour'] + 0;
262 $tmpm = $_POST['form_minute'] + 0;
263 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
264 $duration = abs($_POST['form_duration']); // fixes #395
266 $starttime = "$tmph:$tmpm:00";
268 $tmpm += $duration;
269 while ($tmpm >= 60) {
270 $tmpm -= 60;
271 ++$tmph;
273 $endtime = "$tmph:$tmpm:00";
275 // Set up working variables related to repeated events.
276 $my_recurrtype = 0;
277 $my_repeat_freq = 0 + $_POST['form_repeat_freq'];
278 $my_repeat_type = 0 + $_POST['form_repeat_type'];
279 $my_repeat_on_num = 1;
280 $my_repeat_on_day = 0;
281 $my_repeat_on_freq = 0;
283 // the starting date of the event, pay attention with this value
284 // when editing recurring events -- JRM Oct-08
285 $event_date = fixDate($_POST['form_date']);
287 //If used new recurrence mechanism of set days every week
288 if(!empty($_POST['days_every_week'])){
289 $my_recurrtype = 3;
290 //loop through checkboxes and insert encounter days into array
291 $days_every_week_arr = array();
292 for($i=1; $i<=7; $i++){
293 if(!empty($_POST['day_' . $i])){
294 array_push($days_every_week_arr, $i);
297 $my_repeat_freq = implode(",",$days_every_week_arr);
298 $my_repeat_type = 6;
299 $event_date = fixDate(setEventDate($_POST['form_date'], $my_repeat_freq));
302 elseif (!empty($_POST['form_repeat'])){
304 $my_recurrtype = 1;
305 if ($my_repeat_type > 4) {
306 $my_recurrtype = 2;
307 $time = strtotime($event_date);
308 $my_repeat_on_day = 0 + date('w', $time);
309 $my_repeat_on_freq = $my_repeat_freq;
310 if ($my_repeat_type == 5) {
311 $my_repeat_on_num = intval((date('j', $time) - 1) / 7) + 1;
312 } else {
313 // Last occurence of this weekday on the month
314 $my_repeat_on_num = 5;
316 // Maybe not needed, but for consistency with postcalendar:
317 $my_repeat_freq = 0;
318 $my_repeat_type = 0;
323 // Useless garbage that we must save.
324 $locationspecs = array("event_location" => "",
325 "event_street1" => "",
326 "event_street2" => "",
327 "event_city" => "",
328 "event_state" => "",
329 "event_postal" => ""
331 $locationspec = serialize($locationspecs);
333 // capture the recurring specifications
334 $recurrspec = array("event_repeat_freq" => "$my_repeat_freq",
335 "event_repeat_freq_type" => "$my_repeat_type",
336 "event_repeat_on_num" => "$my_repeat_on_num",
337 "event_repeat_on_day" => "$my_repeat_on_day",
338 "event_repeat_on_freq" => "$my_repeat_on_freq",
339 "exdate" => $_POST['form_repeat_exdate']
343 if($my_recurrtype == 2) { // Added by epsdky 2016 (details in commit)
344 if($_POST['old_repeats'] == 2) {
345 if($_POST['rt2_flag2']) $recurrspec['rt2_pf_flag'] = "1";
346 } else $recurrspec['rt2_pf_flag'] = "1";
347 } // End of addition by epsdky
349 // no recurr specs, this is used for adding a new non-recurring event
350 $noRecurrspec = array("event_repeat_freq" => "",
351 "event_repeat_freq_type" => "",
352 "event_repeat_on_num" => "1",
353 "event_repeat_on_day" => "0",
354 "event_repeat_on_freq" => "0",
355 "exdate" => ""
358 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
359 //=============================================================================================================================
360 if ($_POST['form_action'] == "duplicate") {
362 InsertEventFull();
363 DOBandEncounter();
367 // If we are saving, then save and close the window.
369 if ($_POST['form_action'] == "save") {
370 /* =======================================================
371 * UPDATE EVENTS
372 * =====================================================*/
373 if ($eid) {
375 // what is multiple key around this $eid?
376 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
378 // ====================================
379 // multiple providers
380 // ====================================
381 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
383 // obtain current list of providers regarding the multiple key
384 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
385 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
387 // get the new list of providers from the submitted form
388 $providers_new = $_POST['form_provider'];
390 // ===== Only current event of repeating series =====
391 if ($_POST['recurr_affect'] == 'current') {
393 // update all existing event records to exlude the current date
394 foreach ($providers_current as $provider) {
395 // update the provider's original event
396 // get the original event's repeat specs
397 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
398 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
399 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
400 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
401 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
402 else { $oldRecurrspec['exdate'] .= $selected_date; }
404 // mod original event recur specs to exclude this date
405 sqlStatement("UPDATE openemr_postcalendar_events SET " .
406 " pc_recurrspec = ? ".
407 " WHERE pc_aid = ? AND pc_multiple=?", array(serialize($oldRecurrspec),$provider,$row['pc_multiple']) );
410 // obtain the next available unique key to group multiple providers around some event
411 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
412 $max = sqlFetchArray($q);
413 $new_multiple_value = $max['max'] + 1;
415 // insert a new event record for each provider selected on the form
416 foreach ($providers_new as $provider) {
417 // insert a new event on this date with POST form data
418 $args = $_POST;
419 // specify some special variables needed for the INSERT
420 $args['new_multiple_value'] = $new_multiple_value;
421 $args['form_provider'] = $provider;
422 $args['event_date'] = $event_date;
423 $args['duration'] = $duration * 60;
424 // this event is forced to NOT REPEAT
425 $args['form_repeat'] = "0";
426 $args['days_every_week'] = "0";
427 $args['recurrspec'] = $noRecurrspec;
428 $args['form_enddate'] = "0000-00-00";
429 $args['starttime'] = $starttime;
430 $args['endtime'] = $endtime;
431 $args['locationspec'] = $locationspec;
432 InsertEvent($args);
436 // ===== Future Recurring events of a repeating series =====
437 else if ($_POST['recurr_affect'] == 'future') {
438 // update all existing event records to
439 // stop recurring on this date-1
440 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
441 foreach ($providers_current as $provider) {
442 // mod original event recur specs to end on this date
443 sqlStatement("UPDATE openemr_postcalendar_events SET " .
444 " pc_enddate = ? ".
445 " WHERE pc_aid = ? AND pc_multiple=?", array($selected_date,$provider,$row['pc_multiple']) );
448 // obtain the next available unique key to group multiple providers around some event
449 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
450 $max = sqlFetchArray($q);
451 $new_multiple_value = $max['max'] + 1;
453 // insert a new event record for each provider selected on the form
454 foreach ($providers_new as $provider) {
455 // insert a new event on this date with POST form data
456 $args = $_POST;
457 // specify some special variables needed for the INSERT
458 $args['new_multiple_value'] = $new_multiple_value;
459 $args['form_provider'] = $provider;
460 $args['event_date'] = $event_date;
461 $args['duration'] = $duration * 60;
462 $args['recurrspec'] = $recurrspec;
463 $args['starttime'] = $starttime;
464 $args['endtime'] = $endtime;
465 $args['locationspec'] = $locationspec;
466 InsertEvent($args);
470 else {
471 /* =================================================================== */
472 // ===== a Single event or All events in a repeating series ==========
473 /* =================================================================== */
475 // this difference means that some providers from current was UNCHECKED
476 // so we must delete this event for them
477 $r1 = array_diff ($providers_current, $providers_new);
478 if (count ($r1)) {
479 foreach ($r1 as $to_be_removed) {
480 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']) );
484 // perform a check to see if user changed event date
485 // this is important when editing an existing recurring event
486 // oct-08 JRM
487 if ($_POST['form_date'] == $_POST['selected_date']) {
488 // user has NOT changed the start date of the event (and not recurrtype 3)
489 if($my_recurrtype != 3) $event_date = fixDate($_POST['event_start_date']);
492 // this difference means that some providers were added
493 // so we must insert this event for them
494 $r2 = array_diff ($providers_new, $providers_current);
495 if (count ($r2)) {
496 foreach ($r2 as $to_be_inserted) {
497 $args = $_POST;
498 // specify some special variables needed for the INSERT
499 $args['new_multiple_value'] = $row['pc_multiple'];
500 $args['form_provider'] = $to_be_inserted;
501 $args['event_date'] = $event_date;
502 $args['duration'] = $duration * 60;
503 $args['recurrspec'] = $recurrspec;
504 $args['starttime'] = $starttime;
505 $args['endtime'] = $endtime;
506 $args['locationspec'] = $locationspec;
507 InsertEvent($args);
511 // after the two diffs above, we must update for remaining providers
512 // those who are intersected in $providers_current and $providers_new
513 foreach ($_POST['form_provider'] as $provider) {
514 sqlStatement("UPDATE openemr_postcalendar_events SET " .
515 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
516 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
517 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
518 "pc_time = NOW(), " .
519 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
520 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
521 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
522 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
523 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
524 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
525 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
526 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
527 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
528 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
529 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
530 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
531 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
532 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
533 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
534 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'");
535 } // foreach
538 // ====================================
539 // single provider
540 // ====================================
541 } elseif ( !$row['pc_multiple'] ) {
542 if ( $GLOBALS['select_multi_providers'] ) {
543 $prov = $_POST['form_provider'][0];
544 } else {
545 $prov = $_POST['form_provider'];
548 if ($_POST['recurr_affect'] == 'current') {
549 // get the original event's repeat specs
550 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
551 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
552 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
553 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
554 else { $oldRecurrspec['exdate'] .= $selected_date; }
556 // mod original event recur specs to exclude this date
557 sqlStatement("UPDATE openemr_postcalendar_events SET " .
558 " pc_recurrspec = ? ".
559 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
561 // insert a new event on this date with POST form data
562 $args = $_POST;
563 // specify some special variables needed for the INSERT
564 $args['event_date'] = $event_date;
565 $args['duration'] = $duration * 60;
566 // this event is forced to NOT REPEAT
567 $args['form_repeat'] = "0";
568 $args['days_every_week'] = "0";
569 $args['recurrspec'] = $noRecurrspec;
570 $args['form_enddate'] = "0000-00-00";
571 $args['starttime'] = $starttime;
572 $args['endtime'] = $endtime;
573 $args['locationspec'] = $locationspec;
574 InsertEvent($args);
576 else if ($_POST['recurr_affect'] == 'future') {
577 // mod original event to stop recurring on this date-1
578 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
579 sqlStatement("UPDATE openemr_postcalendar_events SET " .
580 " pc_enddate = ? ".
581 " WHERE pc_eid = ?", array($selected_date,$eid) );
583 // insert a new event starting on this date with POST form data
584 $args = $_POST;
585 // specify some special variables needed for the INSERT
586 $args['event_date'] = $event_date;
587 $args['duration'] = $duration * 60;
588 $args['recurrspec'] = $recurrspec;
589 $args['starttime'] = $starttime;
590 $args['endtime'] = $endtime;
591 $args['locationspec'] = $locationspec;
592 InsertEvent($args);
594 else {
596 // perform a check to see if user changed event date
597 // this is important when editing an existing recurring event
598 // oct-08 JRM
599 if ($_POST['form_date'] == $_POST['selected_date']) {
600 // user has NOT changed the start date of the event (and not recurrtype 3)
601 if($my_recurrtype != 3) $event_date = fixDate($_POST['event_start_date']);
604 // mod the SINGLE event or ALL EVENTS in a repeating series
605 // simple provider case
606 sqlStatement("UPDATE openemr_postcalendar_events SET " .
607 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
608 "pc_aid = '" . add_escape_custom($prov) . "', " .
609 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
610 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
611 "pc_time = NOW(), " .
612 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
613 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
614 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
615 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
616 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
617 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
618 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
619 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
620 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
621 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
622 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
623 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
624 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
625 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
626 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
627 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
631 // =======================================
632 // end Update Multi providers case
633 // =======================================
635 // EVENTS TO FACILITIES
636 $e2f = (int)$eid;
639 } else {
640 /* =======================================================
641 * INSERT NEW EVENT(S)
642 * ======================================================*/
644 InsertEventFull();
648 // done with EVENT insert/update statements
650 DOBandEncounter();
654 // =======================================
655 // DELETE EVENT(s)
656 // =======================================
657 else if ($_POST['form_action'] == "delete") {
658 // =======================================
659 // multi providers event
660 // =======================================
661 if ($GLOBALS['select_multi_providers']) {
663 // what is multiple key around this $eid?
664 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
666 // obtain current list of providers regarding the multiple key
667 $providers_current = array();
668 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
669 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
671 // establish a WHERE clause
672 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = '{$row['pc_multiple']}'"; }
673 else { $whereClause = "pc_eid = '$eid'"; }
675 if ($_POST['recurr_affect'] == 'current') {
676 // update all existing event records to exlude the current date
677 foreach ($providers_current as $provider) {
678 // update the provider's original event
679 // get the original event's repeat specs
680 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
681 " WHERE pc_aid <=> ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
682 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
683 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
684 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
685 else { $oldRecurrspec['exdate'] .= $selected_date; }
687 // mod original event recur specs to exclude this date
688 sqlStatement("UPDATE openemr_postcalendar_events SET " .
689 " pc_recurrspec = ? ".
690 " WHERE ". $whereClause, array(serialize($oldRecurrspec)) );
693 else if ($_POST['recurr_affect'] == 'future') {
694 // update all existing event records to stop recurring on this date-1
695 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
696 foreach ($providers_current as $provider) {
697 // update the provider's original event
698 sqlStatement("UPDATE openemr_postcalendar_events SET " .
699 " pc_enddate = ? ".
700 " WHERE ".$whereClause, array($selected_date) );
703 else {
704 // really delete the event from the database
705 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
709 // =======================================
710 // single provider event
711 // =======================================
712 else {
714 if ($_POST['recurr_affect'] == 'current') {
715 // mod original event recur specs to exclude this date
717 // get the original event's repeat specs
718 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
719 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
720 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
721 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
722 else { $oldRecurrspec['exdate'] .= $selected_date; }
723 sqlStatement("UPDATE openemr_postcalendar_events SET " .
724 " pc_recurrspec = ? ".
725 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
728 else if ($_POST['recurr_affect'] == 'future') {
729 // mod original event to stop recurring on this date-1
730 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
731 sqlStatement("UPDATE openemr_postcalendar_events SET " .
732 " pc_enddate = ? ".
733 " WHERE pc_eid = ?", array($selected_date,$eid) );
736 else {
737 // fully delete the event from the database
738 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
743 if ($_POST['form_action'] != "") {
744 // Close this window and refresh the calendar (or the patient_tracker) display.
745 echo "<html>\n<body>\n<script language='JavaScript'>\n";
746 if ($info_msg) echo " alert('" . addslashes($info_msg) . "');\n";
747 echo " if (opener && !opener.closed && opener.refreshme) {\n " .
748 " opener.refreshme();\n " . // This is for standard calendar page refresh
749 " } else {\n " .
750 " window.opener.pattrk.submit()\n " . // This is for patient flow board page refresh
751 " };\n";
752 echo " window.close();\n";
753 echo "</script>\n</body>\n</html>\n";
754 exit();
757 //*********************************
758 // If we get this far then we are displaying the form.
759 //*********************************
761 /*********************************************************************
762 This has been migrate to the administration->lists
763 $statuses = array(
764 '-' => '',
765 '*' => xl('* Reminder done'),
766 '+' => xl('+ Chart pulled'),
767 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
768 '?' => xl('? No show'),
769 '@' => xl('@ Arrived'),
770 '~' => xl('~ Arrived late'),
771 '!' => xl('! Left w/o visit'),
772 '#' => xl('# Ins/fin issue'),
773 '<' => xl('< In exam room'),
774 '>' => xl('> Checked out'),
775 '$' => xl('$ Coding done'),
776 '%' => xl('% Cancelled < 24h ')
778 *********************************************************************/
780 $repeats = 0; // if the event repeats
781 $repeattype = '0';
782 $repeatfreq = '0';
783 $patientid = '';
784 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
785 $patientname = null;
786 $patienttitle = "";
787 $pcroom = "";
788 $hometext = "";
789 $row = array();
790 $informant = "";
792 // If we are editing an existing event, then get its data.
793 if ($eid) {
794 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
796 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
797 "FROM openemr_postcalendar_events AS e " .
798 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
799 "WHERE pc_eid = ?", array($eid) );
800 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
802 // instead of using the event's starting date, keep what has been provided
803 // via the GET array, see the top of this file
804 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
805 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
806 $userid = $row['pc_aid'];
807 $patientid = $row['pc_pid'];
808 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
809 $starttimem = substr($row['pc_startTime'], 3, 2);
810 $repeats = $row['pc_recurrtype'];
811 $multiple_value = $row['pc_multiple'];
813 // parse out the repeating data, if any
814 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
815 $repeattype = $rspecs['event_repeat_freq_type'];
816 $repeatfreq = $rspecs['event_repeat_freq'];
817 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
819 // Adjustments for repeat type 2, a particular weekday of the month.
820 if ($repeats == 2) {
821 $repeatfreq = $rspecs['event_repeat_on_freq'];
822 if ($rspecs['event_repeat_on_num'] < 5) {
823 $repeattype = 5;
825 else {
826 $repeattype = 6;
829 $pcroom = $row['pc_room'];
830 $hometext = $row['pc_hometext'];
831 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
833 else {
834 // a NEW event
835 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
837 //-------------------------------------
838 //(CHEMED)
839 //Set default facility for a new event based on the given 'userid'
840 if ($userid) {
841 /*************************************************************
842 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
843 *************************************************************/
844 if ($_SESSION['pc_facility']) {
845 $pref_facility = sqlFetchArray(sqlStatement("
846 SELECT f.id as facility_id,
847 f.name as facility
848 FROM facility f
849 WHERE f.id = ?
851 array($_SESSION['pc_facility'])
853 } else {
854 $pref_facility = sqlFetchArray(sqlStatement("
855 SELECT u.facility_id,
856 f.name as facility
857 FROM users u
858 LEFT JOIN facility f on (u.facility_id = f.id)
859 WHERE u.id = ?
860 ", array($userid) ));
862 /************************************************************/
863 $e2f = $pref_facility['facility_id'];
864 $e2f_name = $pref_facility['facility'];
866 //END of CHEMED -----------------------
869 // If we have a patient ID, get the name and phone numbers to display.
870 if ($patientid) {
871 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
872 "FROM patient_data WHERE pid = ?", array($patientid) );
873 $patientname = $prow['lname'] . ", " . $prow['fname'];
874 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
875 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
878 // Get the providers list.
879 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
880 "authorized != 0 AND active = 1 ORDER BY lname, fname");
882 // Get event categories.
883 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
884 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
886 // Fix up the time format for AM/PM.
887 $startampm = '1';
888 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
889 $startampm = '2';
890 if ($starttimeh > 12) $starttimeh -= 12;
894 <html>
895 <head>
896 <?php html_header_show(); ?>
897 <title><?php echo $eid ? xlt('Edit') : xlt('Add New') ?> <?php echo xlt('Event');?></title>
898 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
900 <style>
901 td { font-size:0.8em; }
902 </style>
904 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
905 <script type="text/javascript" src="../../../library/topdialog.js"></script>
906 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
907 <script type="text/javascript" src="../../../library/textformat.js"></script>
908 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
909 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
910 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
912 <script language="JavaScript">
914 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
916 var durations = new Array();
917 // var rectypes = new Array();
918 <?php
919 // Read the event categories, generate their options list, and get
920 // the default event duration from them if this is a new event.
921 $cattype=0;
922 if($_GET['prov']==true){
923 $cattype=1;
925 $cres = sqlStatement("SELECT pc_catid, pc_cattype, pc_catname, " .
926 "pc_recurrtype, pc_duration, pc_end_all_day " .
927 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
928 $catoptions = "";
929 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
930 $thisduration = 0;
931 if ($eid) {
932 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
934 while ($crow = sqlFetchArray($cres)) {
935 $duration = round($crow['pc_duration'] / 60);
936 if ($crow['pc_end_all_day']) $duration = 1440;
938 // This section is to build the list of preferred categories:
939 if ($duration) {
940 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
941 if ($eid) {
942 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
944 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
947 if ($crow['pc_cattype'] != $cattype) continue;
949 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
950 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
951 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
952 if ($eid) {
953 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
954 } else {
955 if ($crow['pc_catid'] == $default_catid) {
956 $catoptions .= " selected";
957 $thisduration = $duration;
960 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
964 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
966 // This is for callback by the find-patient popup.
967 function setpatient(pid, lname, fname, dob) {
968 var f = document.forms[0];
969 f.form_patient.value = lname + ', ' + fname;
970 f.form_pid.value = pid;
971 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
972 document.getElementById('dob_row').style.display = dobstyle;
975 // This invokes the find-patient popup.
976 function sel_patient() {
977 dlgopen('find_patient_popup.php', '_blank', 500, 400);
980 // Do whatever is needed when a new event category is selected.
981 // For now this means changing the event title and duration.
982 function set_display() {
983 var f = document.forms[0];
984 var s = f.form_category;
985 if (s.selectedIndex >= 0) {
986 var catid = s.options[s.selectedIndex].value;
987 var style_apptstatus = document.getElementById('title_apptstatus').style;
988 var style_prefcat = document.getElementById('title_prefcat').style;
989 if (catid == '2') { // In Office
990 style_apptstatus.display = 'none';
991 style_prefcat.display = '';
992 f.form_apptstatus.style.display = 'none';
993 f.form_prefcat.style.display = '';
994 } else {
995 style_prefcat.display = 'none';
996 style_apptstatus.display = '';
997 f.form_prefcat.style.display = 'none';
998 f.form_apptstatus.style.display = '';
1003 // Do whatever is needed when a new event category is selected.
1004 // For now this means changing the event title and duration.
1005 function set_category() {
1006 var f = document.forms[0];
1007 var s = f.form_category;
1008 if (s.selectedIndex >= 0) {
1009 var catid = s.options[s.selectedIndex].value;
1010 f.form_title.value = s.options[s.selectedIndex].text;
1011 f.form_duration.value = durations[catid];
1012 set_display();
1016 // Modify some visual attributes when the all-day or timed-event
1017 // radio buttons are clicked.
1018 function set_allday() {
1019 var f = document.forms[0];
1020 var color1 = '#777777';
1021 var color2 = '#777777';
1022 var disabled2 = true;
1023 if (document.getElementById('rballday1').checked) {
1024 color1 = '#000000';
1026 if (document.getElementById('rballday2').checked) {
1027 color2 = '#000000';
1028 disabled2 = false;
1030 document.getElementById('tdallday1').style.color = color1;
1031 document.getElementById('tdallday2').style.color = color2;
1032 document.getElementById('tdallday3').style.color = color2;
1033 document.getElementById('tdallday4').style.color = color2;
1034 document.getElementById('tdallday5').style.color = color2;
1035 f.form_hour.disabled = disabled2;
1036 f.form_minute.disabled = disabled2;
1037 f.form_ampm.disabled = disabled2;
1038 f.form_duration.disabled = disabled2;
1041 // Modify some visual attributes when the Repeat checkbox is clicked.
1042 function set_repeat() {
1043 var f = document.forms[0];
1044 var isdisabled = true;
1045 var mycolor = '#777777';
1046 var myvisibility = 'hidden';
1047 if (f.form_repeat.checked) {
1048 f.days_every_week.checked = false;
1049 document.getElementById("days_label").style.color = mycolor;
1050 var days = document.getElementById("days").getElementsByTagName('input');
1051 var labels = document.getElementById("days").getElementsByTagName('label');
1052 for(var i=0; i < days.length; i++){
1053 days[i].disabled = isdisabled;
1054 labels[i].style.color = mycolor;
1056 isdisabled = false;
1057 mycolor = '#000000';
1058 myvisibility = 'visible';
1060 f.form_repeat_type.disabled = isdisabled;
1061 f.form_repeat_freq.disabled = isdisabled;
1062 f.form_enddate.disabled = isdisabled;
1063 document.getElementById('tdrepeat1').style.color = mycolor;
1064 document.getElementById('tdrepeat2').style.color = mycolor;
1065 document.getElementById('img_enddate').style.visibility = myvisibility;
1068 // Event when days_every_week is checked.
1069 function set_days_every_week() {
1070 var f = document.forms[0];
1071 if (f.days_every_week.checked) {
1072 //disable regular repeat
1073 f.form_repeat.checked = false;
1074 f.form_repeat_type.disabled = true;
1075 f.form_repeat_freq.disabled = true;
1076 document.getElementById('tdrepeat1').style.color = '#777777';
1078 //enable end_date setting
1079 document.getElementById('tdrepeat2').style.color = '#000000';
1080 f.form_enddate.disabled = false;
1081 document.getElementById('img_enddate').style.visibility = 'visible';
1083 var isdisabled = false;
1084 var mycolor = '#000000';
1085 var myvisibility = 'visible';
1087 else{
1088 var isdisabled = true;
1089 var mycolor = '#777777';
1090 var myvisibility = 'hidden';
1092 document.getElementById("days_label").style.color = mycolor;
1093 var days = document.getElementById("days").getElementsByTagName('input');
1094 var labels = document.getElementById("days").getElementsByTagName('label');
1095 for(var i=0; i < days.length; i++){
1096 days[i].disabled = isdisabled;
1097 labels[i].style.color = mycolor;
1100 //If no repetition is checked, disable end_date setting.
1101 if(!f.days_every_week.checked && !f.form_repeat.checked){
1102 //disable end_date setting
1103 document.getElementById('tdrepeat2').style.color = mycolor;
1104 f.form_enddate.disabled = isdisabled;
1105 document.getElementById('img_enddate').style.visibility = myvisibility;
1111 // Constants used by dateChanged() function.
1112 var occurNames = new Array(
1113 '<?php echo xls("1st"); ?>',
1114 '<?php echo xls("2nd"); ?>',
1115 '<?php echo xls("3rd"); ?>',
1116 '<?php echo xls("4th"); ?>'
1119 // Monitor start date changes to adjust repeat type options.
1120 function dateChanged() {
1121 var f = document.forms[0];
1122 if (!f.form_date.value) return;
1123 var d = new Date(f.form_date.value);
1124 var downame = Calendar._DN[d.getUTCDay()];
1125 var nthtext = '';
1126 var occur = Math.floor((d.getUTCDate() - 1) / 7);
1127 if (occur < 4) { // 5th is not allowed
1128 nthtext = occurNames[occur] + ' ' + downame;
1130 var lasttext = '';
1131 var tmp = new Date(d.getUTCFullYear(), d.getUTCMonth() + 1, 0);
1132 if (tmp.getDate() - d.getUTCDate() < 7) { // Modified by epsdky 2016 (details in commit)
1133 // This is a last occurrence of the specified weekday in the month,
1134 // so permit that as an option.
1135 lasttext = '<?php echo xls("Last"); ?> ' + downame;
1137 var si = f.form_repeat_type.selectedIndex;
1138 var opts = f.form_repeat_type.options;
1139 opts.length = 5; // remove any nth and Last entries
1140 if (nthtext ) opts[opts.length] = new Option(nthtext , '5');
1141 if (lasttext) opts[opts.length] = new Option(lasttext, '6');
1142 if (si < opts.length) f.form_repeat_type.selectedIndex = si;
1143 else f.form_repeat_type.selectedIndex = 5; // Added by epsdky 2016 (details in commit)
1146 // This is for callback by the find-available popup.
1147 function setappt(year,mon,mday,hours,minutes) {
1148 var f = document.forms[0];
1149 f.form_date.value = '' + year + '-' +
1150 ('' + (mon + 100)).substring(1) + '-' +
1151 ('' + (mday + 100)).substring(1);
1152 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
1153 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
1154 f.form_minute.value = ('' + (minutes + 100)).substring(1);
1157 // Invoke the find-available popup.
1158 function find_available(extra) {
1159 top.restoreSession();
1160 // (CHEMED) Conditional value selection, because there is no <select> element
1161 // when making an appointment for a specific provider
1162 var s = document.forms[0].form_provider;
1163 var f = document.forms[0].facility;
1164 <?php if ($userid != 0) { ?>
1165 s = document.forms[0].form_provider.value;
1166 f = document.forms[0].facility.value;
1167 <?php } else {?>
1168 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1169 f = document.forms[0].facility.options[f.selectedIndex].value;
1170 <?php }?>
1171 var c = document.forms[0].form_category;
1172 var formDate = document.forms[0].form_date;
1173 dlgopen('<?php echo $GLOBALS['web_root']; ?>/interface/main/calendar/find_appt_popup.php' +
1174 '?providerid=' + s +
1175 '&catid=' + c.options[c.selectedIndex].value +
1176 '&facility=' + f +
1177 '&startdate=' + formDate.value +
1178 '&evdur=' + document.forms[0].form_duration.value +
1179 '&eid=<?php echo 0 + $eid; ?>' +
1180 extra,
1181 '_blank', 500, 400);
1186 </script>
1188 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1190 </head>
1192 <body class="body_top main-calendar-add_edit_event" onunload='imclosing()'>
1194 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1195 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1196 <input type='hidden' size='2' name='resname' value='empty' />
1197 <?php
1198 if ($_POST["resname"]=="noresult"){
1199 echo '
1200 <script language="Javascript">
1201 // refresh and redirect the parent window
1202 if (!opener.closed && opener.refreshme) opener.refreshme();
1203 top.restoreSession();
1204 opener.document.location="../../new/new.php";
1205 // Close the window
1206 window.close();
1207 </script>';
1209 $classprov='current';
1210 $classpati='';
1212 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1213 <input type="hidden" name="form_action" id="form_action" value="">
1214 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1215 <!-- used for recurring events -->
1216 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo attr($date); ?>">
1217 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo attr($eventstartdate); ?>">
1218 <!-- Following added by epsdky 2016 (details in commit) -->
1219 <input type="hidden" name="old_repeats" id="old_repeats" value="<?php echo attr($repeats); ?>">
1220 <input type="hidden" name="rt2_flag2" id="rt2_flag2" value="<?php echo attr(isset($rspecs['rt2_pf_flag']) ? $rspecs['rt2_pf_flag'] : '0'); ?>">
1221 <!-- End of addition by epsdky -->
1222 <center>
1223 <table border='0' >
1224 <?php
1225 $provider_class='';
1226 $normal='';
1227 if($_GET['prov']==true){
1228 $provider_class="class='current'";
1230 else{
1231 $normal="class='current'";
1234 <tr><th><ul class="tabNav">
1235 <?php
1236 $eid=$_REQUEST["eid"];
1237 $startm=$_REQUEST["startampm"];
1238 $starth=$_REQUEST["starttimeh"];
1239 $uid=$_REQUEST["userid"];
1240 $starttm=$_REQUEST["starttimem"];
1241 $dt=$_REQUEST["date"];
1242 $cid=$_REQUEST["catid"];
1244 <li <?php echo $normal;?>>
1245 <a href='add_edit_event.php?eid=<?php echo attr($eid);?>&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);?>'>
1246 <?php echo xlt('Patient');?></a>
1247 </li>
1248 <li <?php echo $provider_class;?>>
1249 <a href='add_edit_event.php?prov=true&eid=<?php echo attr($eid);?>&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);?>'>
1250 <?php echo xlt('Provider');?></a>
1251 </li>
1252 </ul>
1253 </th></tr>
1254 <tr><td colspan='10'>
1255 <table border='0' width='100%' bgcolor='#DDDDDD'>
1256 <tr>
1257 <td width='1%' nowrap>
1258 <b><?php echo xlt('Category'); ?>:</b>
1259 </td>
1260 <td nowrap>
1261 <select name='form_category' onchange='set_category()' style='width:100%'>
1262 <?php echo $catoptions ?>
1263 </select>
1264 </td>
1265 <td width='1%' nowrap>
1266 &nbsp;&nbsp;
1267 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1268 <?php if ($thisduration == 1440) echo "checked " ?>/>
1269 </td>
1270 <td colspan='2' nowrap id='tdallday1'>
1271 <?php echo xlt('All day event'); ?>
1272 </td>
1273 </tr>
1274 <tr>
1275 <td nowrap>
1276 <b><?php echo xlt('Date'); ?>:</b>
1277 </td>
1278 <td nowrap>
1279 <input type='text' size='10' name='form_date' id='form_date'
1280 value='<?php echo attr($date) ?>'
1281 title='<?php echo xla('yyyy-mm-dd event date or starting date'); ?>'
1282 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' onchange='dateChanged()' />
1283 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1284 id='img_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1285 title='<?php echo xla('Click here to choose a date'); ?>'>
1286 </td>
1287 <td nowrap>
1288 &nbsp;&nbsp;
1289 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1290 </td>
1291 <td width='1%' nowrap id='tdallday2'>
1292 <?php echo xlt('Time'); ?>
1293 </td>
1294 <td width='1%' nowrap id='tdallday3'>
1295 <span>
1296 <input type='text' size='2' name='form_hour' value='<?php echo attr($starttimeh) ?>'
1297 title='<?php echo xla('Event start time'); ?>' /> :
1298 <input type='text' size='2' name='form_minute' value='<?php echo attr($starttimem) ?>'
1299 title='<?php echo xla('Event start time'); ?>' />&nbsp;
1300 </span>
1301 <select name='form_ampm' title='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1302 <option value='1'><?php echo xlt('AM'); ?></option>
1303 <option value='2'<?php if ($startampm == '2') echo " selected" ?>><?php echo xlt('PM'); ?></option>
1304 </select>
1305 </td>
1306 </tr>
1307 <tr>
1308 <td nowrap>
1309 <b><?php echo xlt('Title'); ?>:</b>
1310 </td>
1311 <td nowrap>
1312 <input type='text' size='10' name='form_title' value='<?php echo attr($row['pc_title']); ?>'
1313 style='width:100%'
1314 title='<?php echo xla('Event title'); ?>' />
1315 </td>
1316 <td nowrap>&nbsp;
1318 </td>
1319 <td nowrap id='tdallday4'><?php echo xlt('duration'); ?>
1320 </td>
1321 <td nowrap id='tdallday5'>
1322 <input type='text' size='4' name='form_duration' value='<?php echo attr($thisduration) ?>' title='<?php echo xla('Event duration in minutes'); ?>' />
1323 <?php echo xlt('minutes'); ?>
1324 </td>
1325 </tr>
1327 <tr>
1328 <td nowrap><b><?php echo xlt('Facility'); ?>:</b></td>
1329 <td>
1330 <select name="facility" id="facility" >
1331 <?php
1333 // ===========================
1334 // EVENTS TO FACILITIES
1335 //(CHEMED) added service_location WHERE clause
1336 // get the facilities
1337 /***************************************************************
1338 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1339 ***************************************************************/
1340 $facils = getUserFacilities($_SESSION['authId']);
1341 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1342 /**************************************************************/
1343 while ($facrow = sqlFetchArray($qsql)) {
1344 /*************************************************************
1345 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1346 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1347 *************************************************************/
1348 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1349 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1350 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1352 else{
1353 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1354 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1356 /************************************************************/
1358 // EOS E2F
1359 // ===========================
1361 <?php
1362 //END (CHEMED) IF ?>
1363 </td>
1364 </select>
1365 </tr>
1366 <tr>
1367 <td nowrap>
1368 <b><?php echo xlt('Billing Facility'); ?>:</b>
1369 </td>
1370 <td>
1371 <?php
1372 billing_facility('billing_facility',$row['pc_billing_location']);
1374 </td>
1375 </tr>
1376 <?php
1377 if($_GET['prov']!=true){
1379 <tr id="patient_details">
1380 <td nowrap>
1381 <b><?php echo xlt('Patient'); ?>:</b>
1382 </td>
1383 <td nowrap>
1384 <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 />
1385 <input type='hidden' name='form_pid' value='<?php echo attr($patientid) ?>' />
1386 </td>
1387 <td colspan='3' nowrap style='font-size:8pt'>
1388 &nbsp;
1389 <span class="infobox">
1390 <?php if ($patienttitle != "") { echo $patienttitle; } ?>
1391 </span>
1392 </td>
1393 </tr>
1394 <?php
1397 <tr>
1398 <td nowrap>
1399 <b><?php echo xlt('Provider'); ?>:</b>
1400 </td>
1401 <td nowrap>
1403 <?php
1405 // =======================================
1406 // multi providers
1407 // =======================================
1408 if ($GLOBALS['select_multi_providers']) {
1410 // there are two posible situations: edit and new record
1411 $providers_array = array();
1412 // this is executed only on edit ($eid)
1413 if ($eid) {
1414 if ( $multiple_value ) {
1415 // find all the providers around multiple key
1416 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value) );
1417 while ($r = sqlFetchArray($qall)) {
1418 $providers_array[] = $r['providers'];
1420 } else {
1421 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1422 $providers_array = sqlFetchArray($qall);
1426 // build the selection tool
1427 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1429 while ($urow = sqlFetchArray($ures)) {
1430 echo " <option value='" . attr($urow['id']) . "'";
1432 if ($userid) {
1433 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1436 echo ">" . text($urow['lname']);
1437 if ($urow['fname']) echo ", " . text($urow['fname']);
1438 echo "</option>\n";
1441 echo '</select>';
1443 // =======================================
1444 // single provider
1445 // =======================================
1446 } else {
1448 if ($eid) {
1449 // get provider from existing event
1450 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1451 $provider = sqlFetchArray($qprov);
1452 $defaultProvider = $provider['pc_aid'];
1454 else {
1455 // this is a new event so smartly choose a default provider
1456 /*****************************************************************
1457 if ($userid) {
1458 // Provider already given to us as a GET parameter.
1459 $defaultProvider = $userid;
1461 else {
1462 // default to the currently logged-in user
1463 $defaultProvider = $_SESSION['authUserID'];
1464 // or, if we have chosen a provider in the calendar, default to them
1465 // choose the first one if multiple have been selected
1466 if (count($_SESSION['pc_username']) >= 1) {
1467 // get the numeric ID of the first provider in the array
1468 $pc_username = $_SESSION['pc_username'];
1469 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1470 $defaultProvider = $firstProvider['id'];
1475 echo "<select name='form_provider' style='width:100%' />";
1476 while ($urow = sqlFetchArray($ures)) {
1477 echo " <option value='" . $urow['id'] . "'";
1478 if ($urow['id'] == $defaultProvider) echo " selected";
1479 echo ">" . $urow['lname'];
1480 if ($urow['fname']) echo ", " . $urow['fname'];
1481 echo "</option>\n";
1483 echo "</select>";
1484 *****************************************************************/
1485 // default to the currently logged-in user
1486 $defaultProvider = $_SESSION['authUserID'];
1487 // or, if we have chosen a provider in the calendar, default to them
1488 // choose the first one if multiple have been selected
1489 if (count($_SESSION['pc_username']) >= 1) {
1490 // get the numeric ID of the first provider in the array
1491 $pc_username = $_SESSION['pc_username'];
1492 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0]) ));
1493 $defaultProvider = $firstProvider['id'];
1495 // if we clicked on a provider's schedule to add the event, use THAT.
1496 if ($userid) $defaultProvider = $userid;
1498 echo "<select name='form_provider' style='width:100%' />";
1499 while ($urow = sqlFetchArray($ures)) {
1500 echo " <option value='" . attr($urow['id']) . "'";
1501 if ($urow['id'] == $defaultProvider) echo " selected";
1502 echo ">" . text($urow['lname']);
1503 if ($urow['fname']) echo ", " . text($urow['fname']);
1504 echo "</option>\n";
1506 echo "</select>";
1507 /****************************************************************/
1512 </td>
1513 <td nowrap>
1514 &nbsp;&nbsp;
1515 <?php
1516 //Check if repeat is using the new 'days every week' mechanism.
1517 function isDaysEveryWeek($repeat){
1518 if($repeat == 3){
1519 return true;
1521 else{
1522 return false;
1526 //Check if using the regular repeat mechanism.
1527 function isRegularRepeat($repeat){
1528 if($repeat == 1 || $repeat == 2){
1529 return true;
1531 else{
1532 return false;
1538 If the appointment was set with the regular (old) repeat mechanism (using 'every', 'every 2', etc.), then will be
1539 checked when editing and will select the proper recurrence pattern. If using the new repeat mechanism, then only that box (and the proper set
1540 days) will be checked. That's why I had to add the functions 'isRegularRepeat' and 'isDaysEveryWeek', to check which
1541 repeating mechanism is being used, and load settings accordingly.
1544 <input type='checkbox' name='form_repeat' id="form_repeat" onclick='set_repeat(this)' value='1'<?php if (isRegularRepeat($repeats)) echo " checked" ?>/>
1545 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat -->
1546 </td>
1547 <td nowrap id='tdrepeat1'><?php echo xlt('Repeats'); ?>
1548 </td>
1549 <td nowrap>
1551 <select name='form_repeat_freq' title='<?php echo xla('Every, every other, every 3rd, etc.'); ?>'>
1552 <?php
1553 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1554 as $key => $value)
1556 echo " <option value='" . attr($key) . "'";
1557 if ($key == $repeatfreq && isRegularRepeat($repeats)) echo " selected";
1558 echo ">" . text($value) . "</option>\n";
1561 </select>
1563 <select name='form_repeat_type'>
1564 <?php
1565 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1566 // when the start date is set.
1567 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1568 5 => '?', 6 => '?') as $key => $value)
1570 echo " <option value='" . attr($key) . "'";
1571 if ($key == $repeattype && isRegularRepeat($repeats)) echo " selected";
1572 echo ">" . text($value) . "</option>\n";
1575 </select>
1577 </td>
1578 </tr>
1580 <style>
1581 #days_every_week_row input[type="checkbox"]{float:right;}
1582 #days_every_week_row div{display: inline-block; text-align: center; width: 12%;}
1583 #days_every_week_row div input{width: 100%;}
1584 </style>
1586 <tr id="days_every_week_row">
1587 <td></td>
1588 <td></td>
1589 <td><input type='checkbox' id='days_every_week' name='days_every_week' onclick='set_days_every_week()' <?php if (isDaysEveryWeek($repeats)) echo " checked" ?>/></td>
1590 <td id="days_label"><?php echo xlt('Days Of Week') . ": "; ?></td>
1591 <td id="days">
1592 <?php
1593 foreach (array(1 => xl('Su{{Sunday}}') , 2 => xl('Mo{{Monday}}'), 3 => xl('Tu{{Tuesday}}'), 4 => xl('We{{Wednesday}}'),
1594 5 => xl('Th{{Thursday}}'), 6 => xl('Fr{{Friday}}'), 7 => xl('Sa{{Saturday}}')) as $key => $value)
1596 echo " <div><input type='checkbox' name='day_". attr($key) ."'";
1597 //Checks appropriate days according to days in recurrence string.
1598 if (in_array($key, explode(',',$repeatfreq)) && isDaysEveryWeek($repeats)) echo " checked";
1599 echo " /><label>" . text($value) . "</label></div>\n";
1602 </td>
1604 </tr>
1607 <tr>
1608 <td nowrap>
1609 <span id='title_apptstatus'><b><?php echo xlt('Status'); ?>:</b></span>
1610 <span id='title_prefcat' style='display:none'><b><?php echo xlt('Pref Cat'); ?>:</b></span>
1611 </td>
1612 <td nowrap>
1614 <?php
1615 generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'SKIP'), $row['pc_apptstatus']);
1617 <!--
1618 The following list will be invisible unless this is an In Office
1619 event, in which case form_apptstatus (above) is to be invisible.
1621 <select name='form_prefcat' style='width:100%;display:none' title='<?php echo xla('Preferred Event Category');?>'>
1622 <?php echo $prefcat_options ?>
1623 </select>
1625 </td>
1626 <td nowrap>&nbsp;
1628 </td>
1629 <td nowrap id='tdrepeat2'><?php echo xlt('until'); ?>
1630 </td>
1631 <td nowrap>
1632 <input type='text' size='10' name='form_enddate' id='form_enddate' value='<?php echo attr($row['pc_endDate']) ?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo xla('yyyy-mm-dd last date of this event');?>' />
1633 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1634 id='img_enddate' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1635 title='<?php echo xla('Click here to choose a date');?>'>
1636 <?php
1637 if ($repeatexdate != "") {
1638 $tmptitle = "The following dates are excluded from the repeating series";
1639 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1640 else { $tmptitle .= "\n"; }
1641 $exdates = explode(",", $repeatexdate);
1642 foreach ($exdates as $exdate) {
1643 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1645 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1648 </td>
1649 </tr>
1650 <?php
1651 if($_GET['prov']!=true){
1653 <tr>
1654 <td nowrap>
1655 <b><?php echo xlt('Room Number'); ?>:</b>
1656 </td>
1657 <td colspan='4' nowrap>
1658 <?php
1659 echo generate_select_list('form_room', 'patient_flow_board_rooms',$pcroom, xl('Room Number'));
1661 </td>
1662 </tr>
1663 <?php } ?>
1664 <tr>
1665 <td nowrap>
1666 <b><?php echo xlt('Comments'); ?>:</b>
1667 </td>
1668 <td colspan='4' nowrap>
1669 <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');?>' />
1670 </td>
1671 </tr>
1674 <?php
1675 // DOB is important for the clinic, so if it's missing give them a chance
1676 // to enter it right here. We must display or hide this row dynamically
1677 // in case the patient-select popup is used.
1678 $patient_dob = trim($prow['DOB']);
1679 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00')) ?
1680 '' : 'none';
1682 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1683 <td colspan='4' nowrap>
1684 <b><font color='red'><?php echo xlt('DOB is missing, please enter if possible'); ?>:</font></b>
1685 </td>
1686 <td nowrap>
1687 <input type='text' size='10' name='form_dob' id='form_dob' title='<?php echo xla('yyyy-mm-dd date of birth');?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
1688 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1689 id='img_dob' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1690 title='<?php echo xla('Click here to choose a date');?>'>
1691 </td>
1692 </tr>
1694 </table></td></tr>
1695 <tr class='text'><td colspan='10' class="buttonbar">
1697 <input type='button' name='form_save' id='form_save' value='<?php echo xla('Save');?>' />
1698 &nbsp;
1700 <?php if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1701 <input type='button' id='find_available' value='<?php echo xla('Find Available');?>' />
1702 <?php } ?>
1704 &nbsp;
1705 <input type='button' name='form_delete' id='form_delete' value='<?php echo xla('Delete');?>'<?php if (!$eid) echo " disabled" ?> />
1706 &nbsp;
1707 <input type='button' id='cancel' value='<?php echo xla('Cancel');?>' />
1708 &nbsp;
1709 <input type='button' name='form_duplicate' id='form_duplicate' value='<?php echo xla('Create Duplicate');?>' />
1710 </p></td></tr></table>
1711 <?php if ($informant) echo "<p class='text'>" . xlt('Last update by') . " " .
1712 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n"; ?>
1713 </center>
1714 </form>
1716 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1717 <?php echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?>
1718 <br>
1719 <input type="button" name="all_events" id="all_events" value=" <?php echo xla('All'); ?> ">
1720 <input type="button" name="future_events" id="future_events" value="<?php echo xla('Future'); ?>">
1721 <input type="button" name="current_event" id="current_event" value="<?php echo xla('Current'); ?>">
1722 <input type="button" name="recurr_cancel" id="recurr_cancel" value="<?php echo xla('Cancel'); ?>">
1723 </div>
1725 </body>
1727 <script language='JavaScript'>
1728 <?php if ($eid) { ?>
1729 set_display();
1730 <?php } else { ?>
1731 set_category();
1732 <?php } ?>
1733 set_allday();
1734 set_repeat();
1735 set_days_every_week();
1737 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
1738 Calendar.setup({inputField:"form_enddate", ifFormat:"%Y-%m-%d", button:"img_enddate"});
1739 Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});
1740 </script>
1742 <script language="javascript">
1743 // jQuery stuff to make the page a little easier to use
1745 $(document).ready(function(){
1746 $("#form_save").click(function(e) { validateform(e,"save"); });
1747 $("#form_duplicate").click(function(e) { validateform(e,"duplicate"); });
1748 $("#find_available").click(function() { find_available(''); });
1749 $("#form_delete").click(function() { deleteEvent(); });
1750 $("#cancel").click(function() { window.close(); });
1752 // buttons affecting the modification of a repeating event
1753 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1754 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1755 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1756 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1758 // Initialize repeat options.
1759 dateChanged();
1762 function are_days_checked(){
1763 var days = document.getElementById("days").getElementsByTagName('input');
1764 var counter = 0;
1765 for(var i=0; i < days.length; i++){
1766 if(days[i].checked){
1767 counter++;
1770 return counter;
1774 * validation on the form with new client side validation (using validate.js).
1775 * this enable to add new rules for this form in the pageValidation list.
1776 * */
1777 var collectvalidation = <?php echo($collectthis); ?>;
1778 function validateform(event,valu){
1780 //Make sure if days_every_week is checked that at least one weekday is checked.
1781 if($('#days_every_week').is(':checked') && !are_days_checked()){
1782 alert('<?php echo xls("Must choose at least one day!"); ?>');
1783 return false;
1786 //add rule if choose repeating event
1787 if ($('#form_repeat').is(':checked') || $('#days_every_week').is(':checked')){
1788 collectvalidation.form_enddate = {
1789 datetime: {
1790 dateOnly: true,
1791 earliest: $('#form_date').val(),
1792 message: "An end date later than the start date is required for repeated events!"
1794 presence: true
1796 } else {
1797 if(typeof (collectvalidation) != 'undefined'){
1798 delete collectvalidation.form_enddate;
1802 <?php
1803 if($_GET['prov']==true){
1805 //remove rule if it's provider event
1806 if(collectvalidation.form_patient != undefined){
1807 delete collectvalidation.form_patient;
1809 <?php
1813 <?php
1814 if($GLOBALS['select_multi_providers']){
1816 //If multiple providers is enabled, create provider validation (Note: if no provider is chosen it causes bugs when deleting recurrent events).
1817 collectvalidation.form_provider = {presence: true};
1818 <?php
1823 var submit = submitme(1, event, 'theform', collectvalidation);
1824 if(!submit)return;
1826 $('#form_action').val(valu);
1828 <?php if ($repeats): ?>
1829 // existing repeating events need additional prompt
1830 if ($("#recurr_affect").val() == "") {
1831 DisableForm();
1832 // show the current/future/all DIV for the user to choose one
1833 $("#recurr_popup").css("visibility", "visible");
1834 return false;
1836 <?php endif; ?>
1838 SubmitForm();
1842 // disable all the form elements outside the recurr_popup
1843 function DisableForm() {
1844 $("#theform").children().attr("disabled", "true");
1846 function EnableForm() {
1847 $("#theform").children().removeAttr("disabled");
1849 // hide the recurring popup DIV
1850 function HideRecurrPopup() {
1851 $("#recurr_popup").css("visibility", "hidden");
1854 function deleteEvent() {
1855 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?')); ?>")) {
1856 $('#form_action').val("delete");
1858 <?php if ($repeats): ?>
1859 // existing repeating events need additional prompt
1860 if ($("#recurr_affect").val() == "") {
1861 DisableForm();
1862 // show the current/future/all DIV for the user to choose one
1863 $("#recurr_popup").css("visibility", "visible");
1864 return false;
1866 <?php endif; ?>
1868 return SubmitForm();
1870 return false;
1873 function SubmitForm() {
1874 var f = document.forms[0];
1875 <?php if (!($GLOBALS['select_multi_providers'])) { // multi providers appt is not supported by check slot avail window, so skip ?>
1876 if (f.form_action.value != 'delete') {
1877 // Check slot availability.
1878 var mins = parseInt(f.form_hour.value) * 60 + parseInt(f.form_minute.value);
1879 if (f.form_ampm.value == '2' && mins < 720) mins += 720;
1880 find_available('&cktime=' + mins);
1882 else {
1883 top.restoreSession();
1884 f.submit();
1886 <?php } else { ?>
1887 top.restoreSession();
1888 f.submit();
1889 <?php } ?>
1891 return true;
1894 </script>
1896 </html>