major bug fix for recurrent event deletion when no provider chosen (#384)
[openemr.git] / interface / main / calendar / add_edit_event.php
blobd4fffc7e583264d220ff5c930cc0b62f824f2812
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 require_once($GLOBALS['srcdir'] . "/validation/validate_core.php"); ?>
89 <?php
90 //Gets validation rules from Page Validation list.
91 //Note that for technical reasons, we are bypassing the standard validateUsingPageRules() call.
92 $collectthis = collectValidationPageRules("/interface/main/calendar/add_edit_event.php");
93 if (empty($collectthis)) {
94 $collectthis = "undefined";
96 else {
97 $collectthis = $collectthis["theform"]["rules"];
101 <?php
103 function InsertEventFull()
105 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
106 // =======================================
107 // multi providers case
108 // =======================================
109 if (is_array($_POST['form_provider'])) {
111 // obtain the next available unique key to group multiple providers around some event
112 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
113 $max = sqlFetchArray($q);
114 $new_multiple_value = $max['max'] + 1;
116 foreach ($_POST['form_provider'] as $provider) {
117 $args = $_POST;
118 // specify some special variables needed for the INSERT
119 $args['new_multiple_value'] = $new_multiple_value;
120 $args['form_provider'] = $provider;
121 $args['event_date'] = $event_date;
122 $args['duration'] = $duration * 60;
123 $args['recurrspec'] = $recurrspec;
124 $args['starttime'] = $starttime;
125 $args['endtime'] = $endtime;
126 $args['locationspec'] = $locationspec;
127 InsertEvent($args);
130 // ====================================
131 // single provider
132 // ====================================
133 } else {
134 $args = $_POST;
135 // specify some special variables needed for the INSERT
136 $args['new_multiple_value'] = "";
137 $args['event_date'] = $event_date;
138 $args['duration'] = $duration * 60;
139 $args['recurrspec'] = $recurrspec;
140 $args['starttime'] = $starttime;
141 $args['endtime'] = $endtime;
142 $args['locationspec'] = $locationspec;
143 InsertEvent($args);
146 function DOBandEncounter()
148 global $event_date,$info_msg;
149 // Save new DOB if it's there.
150 $patient_dob = trim($_POST['form_dob']);
151 $tmph = $_POST['form_hour'] + 0;
152 $tmpm = $_POST['form_minute'] + 0;
153 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
154 $appttime = "$tmph:$tmpm:00";
156 if ($patient_dob && $_POST['form_pid']) {
157 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
158 "pid = ?", array($patient_dob,$_POST['form_pid']) );
161 // Manage tracker status.
162 // And auto-create a new encounter if appropriate.
163 if (!empty($_POST['form_pid'])) {
164 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']))
166 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
167 if($encounter){
168 $info_msg .= xl("New encounter created with id");
169 $info_msg .= " $encounter";
171 # Capture the appt status and room number for patient tracker. This will map the encounter to it also.
172 if ( isset($GLOBALS['temporary-eid-for-manage-tracker']) || !empty($_GET['eid']) ) {
173 // Note that the temporary-eid-for-manage-tracker is used to capture the eid for new appointments and when separate a recurring
174 // appointment. It is set in the InsertEvent() function. Note that in the case of spearating a recurrent appointment, the get eid
175 // parameter is actually erroneous(is eid of the recurrent appt and not the new separated appt), so need to use the
176 // temporary-eid-for-manage-tracker global instead.
177 $temp_eid = (isset($GLOBALS['temporary-eid-for-manage-tracker'])) ? $GLOBALS['temporary-eid-for-manage-tracker'] : $_GET['eid'];
178 manage_tracker_status($event_date,$appttime,$temp_eid,$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room'],$encounter);
181 else
183 # Capture the appt status and room number for patient tracker.
184 if (!empty($_GET['eid'])) {
185 manage_tracker_status($event_date,$appttime,$_GET['eid'],$_POST['form_pid'],$_SESSION["authUser"],$_POST['form_apptstatus'],$_POST['form_room']);
193 /*This function is used for setting the date of the first event when using the "day_every_week" repetition mechanism.
194 When the 'start date' is not one of the days chosen for the repetition, the start date needs to be changed to the first
195 occurrence of one of these set days. */
196 function setEventDate($start_date, $recurrence){
197 $timestamp = strtotime($start_date);
198 $day = date('w', $timestamp);
199 //If the 'start date' is one of the set days
200 if(in_array(($day+1), explode(',',$recurrence))){
201 return $start_date;
203 //else: (we need to change start date to first occurrence of one of the set days)
205 $new_date = getTheNextAppointment($start_date, $recurrence);
207 return $new_date;
211 //================================================================================================================
213 // EVENTS TO FACILITIES (lemonsoftware)
214 //(CHEMED) get facility name
215 // edit event case - if there is no association made, then insert one with the first facility
216 if ( $eid ) {
217 $selfacil = '';
218 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
219 FROM openemr_postcalendar_events
220 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
221 WHERE pc_eid = ?", array($eid) );
222 // if ( !$facility['pc_facility'] ) {
223 if ( is_array($facility) && !$facility['pc_facility'] ) {
224 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']) );
225 $min = $qmin['minId'];
226 $min_name = $qmin['facility'];
228 // multiple providers case
229 if ( $GLOBALS['select_multi_providers'] ) {
230 $mul = $facility['pc_multiple'];
231 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min,$mul) );
233 // EOS multiple
235 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min,$eid) );
236 $e2f = $min;
237 $e2f_name = $min_name;
238 } else {
239 // not edit event
240 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
241 $e2f = $_SESSION['pc_facility'];
242 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
243 $e2f = $_COOKIE['pc_facility'];
244 } else {
245 $e2f = $facility['pc_facility'];
246 $e2f_name = $facility['name'];
250 // EOS E2F
251 // ===========================
252 //=============================================================================================================================
253 if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
256 // Compute start and end time strings to be saved.
257 if ($_POST['form_allday']) {
258 $tmph = 0;
259 $tmpm = 0;
260 $duration = 24 * 60;
261 } else {
262 $tmph = $_POST['form_hour'] + 0;
263 $tmpm = $_POST['form_minute'] + 0;
264 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
265 $duration = abs($_POST['form_duration']); // fixes #395
267 $starttime = "$tmph:$tmpm:00";
269 $tmpm += $duration;
270 while ($tmpm >= 60) {
271 $tmpm -= 60;
272 ++$tmph;
274 $endtime = "$tmph:$tmpm:00";
276 // Set up working variables related to repeated events.
277 $my_recurrtype = 0;
278 $my_repeat_freq = 0 + $_POST['form_repeat_freq'];
279 $my_repeat_type = 0 + $_POST['form_repeat_type'];
280 $my_repeat_on_num = 1;
281 $my_repeat_on_day = 0;
282 $my_repeat_on_freq = 0;
284 // the starting date of the event, pay attention with this value
285 // when editing recurring events -- JRM Oct-08
286 $event_date = fixDate($_POST['form_date']);
288 //If used new recurrence mechanism of set days every week
289 if(!empty($_POST['days_every_week'])){
290 $my_recurrtype = 3;
291 //loop through checkboxes and insert encounter days into array
292 $days_every_week_arr = array();
293 for($i=1; $i<=7; $i++){
294 if(!empty($_POST['day_' . $i])){
295 array_push($days_every_week_arr, $i);
298 $my_repeat_freq = implode(",",$days_every_week_arr);
299 $my_repeat_type = 6;
300 $event_date = fixDate(setEventDate($_POST['form_date'], $my_repeat_freq));
303 elseif (!empty($_POST['form_repeat'])){
305 $my_recurrtype = 1;
306 if ($my_repeat_type > 4) {
307 $my_recurrtype = 2;
308 $time = strtotime($event_date);
309 $my_repeat_on_day = 0 + date('w', $time);
310 $my_repeat_on_freq = $my_repeat_freq;
311 if ($my_repeat_type == 5) {
312 $my_repeat_on_num = intval((date('j', $time) - 1) / 7) + 1;
313 } else {
314 // Last occurence of this weekday on the month
315 $my_repeat_on_num = 5;
317 // Maybe not needed, but for consistency with postcalendar:
318 $my_repeat_freq = 0;
319 $my_repeat_type = 0;
324 // Useless garbage that we must save.
325 $locationspecs = array("event_location" => "",
326 "event_street1" => "",
327 "event_street2" => "",
328 "event_city" => "",
329 "event_state" => "",
330 "event_postal" => ""
332 $locationspec = serialize($locationspecs);
334 // capture the recurring specifications
335 $recurrspec = array("event_repeat_freq" => "$my_repeat_freq",
336 "event_repeat_freq_type" => "$my_repeat_type",
337 "event_repeat_on_num" => "$my_repeat_on_num",
338 "event_repeat_on_day" => "$my_repeat_on_day",
339 "event_repeat_on_freq" => "$my_repeat_on_freq",
340 "exdate" => $_POST['form_repeat_exdate']
343 // no recurr specs, this is used for adding a new non-recurring event
344 $noRecurrspec = array("event_repeat_freq" => "",
345 "event_repeat_freq_type" => "",
346 "event_repeat_on_num" => "1",
347 "event_repeat_on_day" => "0",
348 "event_repeat_on_freq" => "0",
349 "exdate" => ""
352 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
353 //=============================================================================================================================
354 if ($_POST['form_action'] == "duplicate") {
356 InsertEventFull();
357 DOBandEncounter();
361 // If we are saving, then save and close the window.
363 if ($_POST['form_action'] == "save") {
364 /* =======================================================
365 * UPDATE EVENTS
366 * =====================================================*/
367 if ($eid) {
369 // what is multiple key around this $eid?
370 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
372 // ====================================
373 // multiple providers
374 // ====================================
375 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
377 // obtain current list of providers regarding the multiple key
378 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
379 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
381 // get the new list of providers from the submitted form
382 $providers_new = $_POST['form_provider'];
384 // ===== Only current event of repeating series =====
385 if ($_POST['recurr_affect'] == 'current') {
387 // update all existing event records to exlude the current date
388 foreach ($providers_current as $provider) {
389 // update the provider's original event
390 // get the original event's repeat specs
391 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
392 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
393 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
394 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
395 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
396 else { $oldRecurrspec['exdate'] .= $selected_date; }
398 // mod original event recur specs to exclude this date
399 sqlStatement("UPDATE openemr_postcalendar_events SET " .
400 " pc_recurrspec = ? ".
401 " WHERE pc_aid = ? AND pc_multiple=?", array(serialize($oldRecurrspec),$provider,$row['pc_multiple']) );
404 // obtain the next available unique key to group multiple providers around some event
405 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
406 $max = sqlFetchArray($q);
407 $new_multiple_value = $max['max'] + 1;
409 // insert a new event record for each provider selected on the form
410 foreach ($providers_new as $provider) {
411 // insert a new event on this date with POST form data
412 $args = $_POST;
413 // specify some special variables needed for the INSERT
414 $args['new_multiple_value'] = $new_multiple_value;
415 $args['form_provider'] = $provider;
416 $args['event_date'] = $event_date;
417 $args['duration'] = $duration * 60;
418 // this event is forced to NOT REPEAT
419 $args['form_repeat'] = "0";
420 $args['days_every_week'] = "0";
421 $args['recurrspec'] = $noRecurrspec;
422 $args['form_enddate'] = "0000-00-00";
423 $args['starttime'] = $starttime;
424 $args['endtime'] = $endtime;
425 $args['locationspec'] = $locationspec;
426 InsertEvent($args);
430 // ===== Future Recurring events of a repeating series =====
431 else if ($_POST['recurr_affect'] == 'future') {
432 // update all existing event records to
433 // stop recurring on this date-1
434 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
435 foreach ($providers_current as $provider) {
436 // mod original event recur specs to end on this date
437 sqlStatement("UPDATE openemr_postcalendar_events SET " .
438 " pc_enddate = ? ".
439 " WHERE pc_aid = ? AND pc_multiple=?", array($selected_date,$provider,$row['pc_multiple']) );
442 // obtain the next available unique key to group multiple providers around some event
443 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
444 $max = sqlFetchArray($q);
445 $new_multiple_value = $max['max'] + 1;
447 // insert a new event record for each provider selected on the form
448 foreach ($providers_new as $provider) {
449 // insert a new event on this date with POST form data
450 $args = $_POST;
451 // specify some special variables needed for the INSERT
452 $args['new_multiple_value'] = $new_multiple_value;
453 $args['form_provider'] = $provider;
454 $args['event_date'] = $event_date;
455 $args['duration'] = $duration * 60;
456 $args['recurrspec'] = $recurrspec;
457 $args['starttime'] = $starttime;
458 $args['endtime'] = $endtime;
459 $args['locationspec'] = $locationspec;
460 InsertEvent($args);
464 else {
465 /* =================================================================== */
466 // ===== a Single event or All events in a repeating series ==========
467 /* =================================================================== */
469 // this difference means that some providers from current was UNCHECKED
470 // so we must delete this event for them
471 $r1 = array_diff ($providers_current, $providers_new);
472 if (count ($r1)) {
473 foreach ($r1 as $to_be_removed) {
474 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']) );
478 // perform a check to see if user changed event date
479 // this is important when editing an existing recurring event
480 // oct-08 JRM
481 if ($_POST['form_date'] == $_POST['selected_date']) {
482 // user has NOT changed the start date of the event (and not recurrtype 3)
483 if($my_recurrtype != 3) $event_date = fixDate($_POST['event_start_date']);
486 // this difference means that some providers were added
487 // so we must insert this event for them
488 $r2 = array_diff ($providers_new, $providers_current);
489 if (count ($r2)) {
490 foreach ($r2 as $to_be_inserted) {
491 $args = $_POST;
492 // specify some special variables needed for the INSERT
493 $args['new_multiple_value'] = $row['pc_multiple'];
494 $args['form_provider'] = $to_be_inserted;
495 $args['event_date'] = $event_date;
496 $args['duration'] = $duration * 60;
497 $args['recurrspec'] = $recurrspec;
498 $args['starttime'] = $starttime;
499 $args['endtime'] = $endtime;
500 $args['locationspec'] = $locationspec;
501 InsertEvent($args);
505 // after the two diffs above, we must update for remaining providers
506 // those who are intersected in $providers_current and $providers_new
507 foreach ($_POST['form_provider'] as $provider) {
508 sqlStatement("UPDATE openemr_postcalendar_events SET " .
509 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
510 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
511 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
512 "pc_time = NOW(), " .
513 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
514 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
515 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
516 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
517 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
518 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
519 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
520 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
521 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
522 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
523 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
524 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
525 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
526 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
527 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
528 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'");
529 } // foreach
532 // ====================================
533 // single provider
534 // ====================================
535 } elseif ( !$row['pc_multiple'] ) {
536 if ( $GLOBALS['select_multi_providers'] ) {
537 $prov = $_POST['form_provider'][0];
538 } else {
539 $prov = $_POST['form_provider'];
542 if ($_POST['recurr_affect'] == 'current') {
543 // get the original event's repeat specs
544 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
545 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
546 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
547 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
548 else { $oldRecurrspec['exdate'] .= $selected_date; }
550 // mod original event recur specs to exclude this date
551 sqlStatement("UPDATE openemr_postcalendar_events SET " .
552 " pc_recurrspec = ? ".
553 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
555 // insert a new event on this date with POST form data
556 $args = $_POST;
557 // specify some special variables needed for the INSERT
558 $args['event_date'] = $event_date;
559 $args['duration'] = $duration * 60;
560 // this event is forced to NOT REPEAT
561 $args['form_repeat'] = "0";
562 $args['days_every_week'] = "0";
563 $args['recurrspec'] = $noRecurrspec;
564 $args['form_enddate'] = "0000-00-00";
565 $args['starttime'] = $starttime;
566 $args['endtime'] = $endtime;
567 $args['locationspec'] = $locationspec;
568 InsertEvent($args);
570 else if ($_POST['recurr_affect'] == 'future') {
571 // mod original event to stop recurring on this date-1
572 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
573 sqlStatement("UPDATE openemr_postcalendar_events SET " .
574 " pc_enddate = ? ".
575 " WHERE pc_eid = ?", array($selected_date,$eid) );
577 // insert a new event starting on this date with POST form data
578 $args = $_POST;
579 // specify some special variables needed for the INSERT
580 $args['event_date'] = $event_date;
581 $args['duration'] = $duration * 60;
582 $args['recurrspec'] = $recurrspec;
583 $args['starttime'] = $starttime;
584 $args['endtime'] = $endtime;
585 $args['locationspec'] = $locationspec;
586 InsertEvent($args);
588 else {
590 // perform a check to see if user changed event date
591 // this is important when editing an existing recurring event
592 // oct-08 JRM
593 if ($_POST['form_date'] == $_POST['selected_date']) {
594 // user has NOT changed the start date of the event (and not recurrtype 3)
595 if($my_recurrtype != 3) $event_date = fixDate($_POST['event_start_date']);
598 // mod the SINGLE event or ALL EVENTS in a repeating series
599 // simple provider case
600 sqlStatement("UPDATE openemr_postcalendar_events SET " .
601 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
602 "pc_aid = '" . add_escape_custom($prov) . "', " .
603 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
604 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
605 "pc_time = NOW(), " .
606 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
607 "pc_room = '" . add_escape_custom($_POST['form_room']) . "', " .
608 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
609 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
610 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
611 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
612 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
613 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
614 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
615 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
616 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
617 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
618 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
619 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
620 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
621 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
625 // =======================================
626 // end Update Multi providers case
627 // =======================================
629 // EVENTS TO FACILITIES
630 $e2f = (int)$eid;
633 } else {
634 /* =======================================================
635 * INSERT NEW EVENT(S)
636 * ======================================================*/
638 InsertEventFull();
642 // done with EVENT insert/update statements
644 DOBandEncounter();
648 // =======================================
649 // DELETE EVENT(s)
650 // =======================================
651 else if ($_POST['form_action'] == "delete") {
652 // =======================================
653 // multi providers event
654 // =======================================
655 if ($GLOBALS['select_multi_providers']) {
657 // what is multiple key around this $eid?
658 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
660 // obtain current list of providers regarding the multiple key
661 $providers_current = array();
662 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
663 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
665 // establish a WHERE clause
666 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = '{$row['pc_multiple']}'"; }
667 else { $whereClause = "pc_eid = '$eid'"; }
669 if ($_POST['recurr_affect'] == 'current') {
670 // update all existing event records to exlude the current date
671 foreach ($providers_current as $provider) {
672 // update the provider's original event
673 // get the original event's repeat specs
674 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
675 " WHERE pc_aid <=> ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
676 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
677 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
678 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
679 else { $oldRecurrspec['exdate'] .= $selected_date; }
681 // mod original event recur specs to exclude this date
682 sqlStatement("UPDATE openemr_postcalendar_events SET " .
683 " pc_recurrspec = ? ".
684 " WHERE ". $whereClause, array(serialize($oldRecurrspec)) );
687 else if ($_POST['recurr_affect'] == 'future') {
688 // update all existing event records to stop recurring on this date-1
689 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
690 foreach ($providers_current as $provider) {
691 // update the provider's original event
692 sqlStatement("UPDATE openemr_postcalendar_events SET " .
693 " pc_enddate = ? ".
694 " WHERE ".$whereClause, array($selected_date) );
697 else {
698 // really delete the event from the database
699 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
703 // =======================================
704 // single provider event
705 // =======================================
706 else {
708 if ($_POST['recurr_affect'] == 'current') {
709 // mod original event recur specs to exclude this date
711 // get the original event's repeat specs
712 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
713 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
714 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
715 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
716 else { $oldRecurrspec['exdate'] .= $selected_date; }
717 sqlStatement("UPDATE openemr_postcalendar_events SET " .
718 " pc_recurrspec = ? ".
719 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
722 else if ($_POST['recurr_affect'] == 'future') {
723 // mod original event to stop recurring on this date-1
724 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
725 sqlStatement("UPDATE openemr_postcalendar_events SET " .
726 " pc_enddate = ? ".
727 " WHERE pc_eid = ?", array($selected_date,$eid) );
730 else {
731 // fully delete the event from the database
732 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
737 if ($_POST['form_action'] != "") {
738 // Close this window and refresh the calendar (or the patient_tracker) display.
739 echo "<html>\n<body>\n<script language='JavaScript'>\n";
740 if ($info_msg) echo " alert('" . addslashes($info_msg) . "');\n";
741 echo " if (opener && !opener.closed && opener.refreshme) {\n " .
742 " opener.refreshme();\n " . // This is for standard calendar page refresh
743 " } else {\n " .
744 " window.opener.pattrk.submit()\n " . // This is for patient flow board page refresh
745 " };\n";
746 echo " window.close();\n";
747 echo "</script>\n</body>\n</html>\n";
748 exit();
751 //*********************************
752 // If we get this far then we are displaying the form.
753 //*********************************
755 /*********************************************************************
756 This has been migrate to the administration->lists
757 $statuses = array(
758 '-' => '',
759 '*' => xl('* Reminder done'),
760 '+' => xl('+ Chart pulled'),
761 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
762 '?' => xl('? No show'),
763 '@' => xl('@ Arrived'),
764 '~' => xl('~ Arrived late'),
765 '!' => xl('! Left w/o visit'),
766 '#' => xl('# Ins/fin issue'),
767 '<' => xl('< In exam room'),
768 '>' => xl('> Checked out'),
769 '$' => xl('$ Coding done'),
770 '%' => xl('% Cancelled < 24h ')
772 *********************************************************************/
774 $repeats = 0; // if the event repeats
775 $repeattype = '0';
776 $repeatfreq = '0';
777 $patientid = '';
778 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
779 $patientname = null;
780 $patienttitle = "";
781 $pcroom = "";
782 $hometext = "";
783 $row = array();
784 $informant = "";
786 // If we are editing an existing event, then get its data.
787 if ($eid) {
788 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
790 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
791 "FROM openemr_postcalendar_events AS e " .
792 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
793 "WHERE pc_eid = ?", array($eid) );
794 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
796 // instead of using the event's starting date, keep what has been provided
797 // via the GET array, see the top of this file
798 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
799 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
800 $userid = $row['pc_aid'];
801 $patientid = $row['pc_pid'];
802 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
803 $starttimem = substr($row['pc_startTime'], 3, 2);
804 $repeats = $row['pc_recurrtype'];
805 $multiple_value = $row['pc_multiple'];
807 // parse out the repeating data, if any
808 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
809 $repeattype = $rspecs['event_repeat_freq_type'];
810 $repeatfreq = $rspecs['event_repeat_freq'];
811 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
813 // Adjustments for repeat type 2, a particular weekday of the month.
814 if ($repeats == 2) {
815 $repeatfreq = $rspecs['event_repeat_on_freq'];
816 if ($rspecs['event_repeat_on_num'] < 5) {
817 $repeattype = 5;
819 else {
820 $repeattype = 6;
823 $pcroom = $row['pc_room'];
824 $hometext = $row['pc_hometext'];
825 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
827 else {
828 // a NEW event
829 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
831 //-------------------------------------
832 //(CHEMED)
833 //Set default facility for a new event based on the given 'userid'
834 if ($userid) {
835 /*************************************************************
836 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
837 *************************************************************/
838 if ($_SESSION['pc_facility']) {
839 $pref_facility = sqlFetchArray(sqlStatement("
840 SELECT f.id as facility_id,
841 f.name as facility
842 FROM facility f
843 WHERE f.id = ?
845 array($_SESSION['pc_facility'])
847 } else {
848 $pref_facility = sqlFetchArray(sqlStatement("
849 SELECT u.facility_id,
850 f.name as facility
851 FROM users u
852 LEFT JOIN facility f on (u.facility_id = f.id)
853 WHERE u.id = ?
854 ", array($userid) ));
856 /************************************************************/
857 $e2f = $pref_facility['facility_id'];
858 $e2f_name = $pref_facility['facility'];
860 //END of CHEMED -----------------------
863 // If we have a patient ID, get the name and phone numbers to display.
864 if ($patientid) {
865 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
866 "FROM patient_data WHERE pid = ?", array($patientid) );
867 $patientname = $prow['lname'] . ", " . $prow['fname'];
868 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
869 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
872 // Get the providers list.
873 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
874 "authorized != 0 AND active = 1 ORDER BY lname, fname");
876 // Get event categories.
877 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
878 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
880 // Fix up the time format for AM/PM.
881 $startampm = '1';
882 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
883 $startampm = '2';
884 if ($starttimeh > 12) $starttimeh -= 12;
888 <html>
889 <head>
890 <?php html_header_show(); ?>
891 <title><?php echo $eid ? xlt('Edit') : xlt('Add New') ?> <?php echo xlt('Event');?></title>
892 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
894 <style>
895 td { font-size:0.8em; }
896 </style>
898 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
899 <script type="text/javascript" src="../../../library/topdialog.js"></script>
900 <script type="text/javascript" src="../../../library/dialog.js"></script>
901 <script type="text/javascript" src="../../../library/textformat.js"></script>
902 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
903 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
904 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
906 <script language="JavaScript">
908 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
910 var durations = new Array();
911 // var rectypes = new Array();
912 <?php
913 // Read the event categories, generate their options list, and get
914 // the default event duration from them if this is a new event.
915 $cattype=0;
916 if($_GET['prov']==true){
917 $cattype=1;
919 $cres = sqlStatement("SELECT pc_catid, pc_cattype, pc_catname, " .
920 "pc_recurrtype, pc_duration, pc_end_all_day " .
921 "FROM openemr_postcalendar_categories where pc_active = 1 ORDER BY pc_seq");
922 $catoptions = "";
923 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
924 $thisduration = 0;
925 if ($eid) {
926 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
928 while ($crow = sqlFetchArray($cres)) {
929 $duration = round($crow['pc_duration'] / 60);
930 if ($crow['pc_end_all_day']) $duration = 1440;
932 // This section is to build the list of preferred categories:
933 if ($duration) {
934 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
935 if ($eid) {
936 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
938 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
941 if ($crow['pc_cattype'] != $cattype) continue;
943 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
944 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
945 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
946 if ($eid) {
947 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
948 } else {
949 if ($crow['pc_catid'] == $default_catid) {
950 $catoptions .= " selected";
951 $thisduration = $duration;
954 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
958 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
960 // This is for callback by the find-patient popup.
961 function setpatient(pid, lname, fname, dob) {
962 var f = document.forms[0];
963 f.form_patient.value = lname + ', ' + fname;
964 f.form_pid.value = pid;
965 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
966 document.getElementById('dob_row').style.display = dobstyle;
969 // This invokes the find-patient popup.
970 function sel_patient() {
971 dlgopen('find_patient_popup.php', '_blank', 500, 400);
974 // Do whatever is needed when a new event category is selected.
975 // For now this means changing the event title and duration.
976 function set_display() {
977 var f = document.forms[0];
978 var s = f.form_category;
979 if (s.selectedIndex >= 0) {
980 var catid = s.options[s.selectedIndex].value;
981 var style_apptstatus = document.getElementById('title_apptstatus').style;
982 var style_prefcat = document.getElementById('title_prefcat').style;
983 if (catid == '2') { // In Office
984 style_apptstatus.display = 'none';
985 style_prefcat.display = '';
986 f.form_apptstatus.style.display = 'none';
987 f.form_prefcat.style.display = '';
988 } else {
989 style_prefcat.display = 'none';
990 style_apptstatus.display = '';
991 f.form_prefcat.style.display = 'none';
992 f.form_apptstatus.style.display = '';
997 // Do whatever is needed when a new event category is selected.
998 // For now this means changing the event title and duration.
999 function set_category() {
1000 var f = document.forms[0];
1001 var s = f.form_category;
1002 if (s.selectedIndex >= 0) {
1003 var catid = s.options[s.selectedIndex].value;
1004 f.form_title.value = s.options[s.selectedIndex].text;
1005 f.form_duration.value = durations[catid];
1006 set_display();
1010 // Modify some visual attributes when the all-day or timed-event
1011 // radio buttons are clicked.
1012 function set_allday() {
1013 var f = document.forms[0];
1014 var color1 = '#777777';
1015 var color2 = '#777777';
1016 var disabled2 = true;
1017 if (document.getElementById('rballday1').checked) {
1018 color1 = '#000000';
1020 if (document.getElementById('rballday2').checked) {
1021 color2 = '#000000';
1022 disabled2 = false;
1024 document.getElementById('tdallday1').style.color = color1;
1025 document.getElementById('tdallday2').style.color = color2;
1026 document.getElementById('tdallday3').style.color = color2;
1027 document.getElementById('tdallday4').style.color = color2;
1028 document.getElementById('tdallday5').style.color = color2;
1029 f.form_hour.disabled = disabled2;
1030 f.form_minute.disabled = disabled2;
1031 f.form_ampm.disabled = disabled2;
1032 f.form_duration.disabled = disabled2;
1035 // Modify some visual attributes when the Repeat checkbox is clicked.
1036 function set_repeat() {
1037 var f = document.forms[0];
1038 var isdisabled = true;
1039 var mycolor = '#777777';
1040 var myvisibility = 'hidden';
1041 if (f.form_repeat.checked) {
1042 f.days_every_week.checked = false;
1043 document.getElementById("days_label").style.color = mycolor;
1044 var days = document.getElementById("days").getElementsByTagName('input');
1045 var labels = document.getElementById("days").getElementsByTagName('label');
1046 for(var i=0; i < days.length; i++){
1047 days[i].disabled = isdisabled;
1048 labels[i].style.color = mycolor;
1050 isdisabled = false;
1051 mycolor = '#000000';
1052 myvisibility = 'visible';
1054 f.form_repeat_type.disabled = isdisabled;
1055 f.form_repeat_freq.disabled = isdisabled;
1056 f.form_enddate.disabled = isdisabled;
1057 document.getElementById('tdrepeat1').style.color = mycolor;
1058 document.getElementById('tdrepeat2').style.color = mycolor;
1059 document.getElementById('img_enddate').style.visibility = myvisibility;
1062 // Event when days_every_week is checked.
1063 function set_days_every_week() {
1064 var f = document.forms[0];
1065 if (f.days_every_week.checked) {
1066 //disable regular repeat
1067 f.form_repeat.checked = false;
1068 f.form_repeat_type.disabled = true;
1069 f.form_repeat_freq.disabled = true;
1070 document.getElementById('tdrepeat1').style.color = '#777777';
1072 //enable end_date setting
1073 document.getElementById('tdrepeat2').style.color = '#000000';
1074 f.form_enddate.disabled = false;
1075 document.getElementById('img_enddate').style.visibility = 'visible';
1077 var isdisabled = false;
1078 var mycolor = '#000000';
1079 var myvisibility = 'visible';
1081 else{
1082 var isdisabled = true;
1083 var mycolor = '#777777';
1084 var myvisibility = 'hidden';
1086 document.getElementById("days_label").style.color = mycolor;
1087 var days = document.getElementById("days").getElementsByTagName('input');
1088 var labels = document.getElementById("days").getElementsByTagName('label');
1089 for(var i=0; i < days.length; i++){
1090 days[i].disabled = isdisabled;
1091 labels[i].style.color = mycolor;
1094 //If no repetition is checked, disable end_date setting.
1095 if(!f.days_every_week.checked && !f.form_repeat.checked){
1096 //disable end_date setting
1097 document.getElementById('tdrepeat2').style.color = mycolor;
1098 f.form_enddate.disabled = isdisabled;
1099 document.getElementById('img_enddate').style.visibility = myvisibility;
1105 // Constants used by dateChanged() function.
1106 var occurNames = new Array(
1107 '<?php echo xls("1st"); ?>',
1108 '<?php echo xls("2nd"); ?>',
1109 '<?php echo xls("3rd"); ?>',
1110 '<?php echo xls("4th"); ?>'
1113 // Monitor start date changes to adjust repeat type options.
1114 function dateChanged() {
1115 var f = document.forms[0];
1116 if (!f.form_date.value) return;
1117 var d = new Date(f.form_date.value);
1118 var downame = Calendar._DN[d.getUTCDay()];
1119 var nthtext = '';
1120 var occur = Math.floor((d.getUTCDate() - 1) / 7);
1121 if (occur < 4) { // 5th is not allowed
1122 nthtext = occurNames[occur] + ' ' + downame;
1124 var lasttext = '';
1125 var tmp = new Date(d.getUTCFullYear(), d.getUTCMonth() + 1, 0);
1126 if (tmp.getDate() - d.getUTCDate() < 7) { // Modified by epsdky 2016 (details in commit)
1127 // This is a last occurrence of the specified weekday in the month,
1128 // so permit that as an option.
1129 lasttext = '<?php echo xls("Last"); ?> ' + downame;
1131 var si = f.form_repeat_type.selectedIndex;
1132 var opts = f.form_repeat_type.options;
1133 opts.length = 5; // remove any nth and Last entries
1134 if (nthtext ) opts[opts.length] = new Option(nthtext , '5');
1135 if (lasttext) opts[opts.length] = new Option(lasttext, '6');
1136 if (si < opts.length) f.form_repeat_type.selectedIndex = si;
1137 else f.form_repeat_type.selectedIndex = 5; // Added by epsdky 2016 (details in commit)
1140 // This is for callback by the find-available popup.
1141 function setappt(year,mon,mday,hours,minutes) {
1142 var f = document.forms[0];
1143 f.form_date.value = '' + year + '-' +
1144 ('' + (mon + 100)).substring(1) + '-' +
1145 ('' + (mday + 100)).substring(1);
1146 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
1147 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
1148 f.form_minute.value = ('' + (minutes + 100)).substring(1);
1151 // Invoke the find-available popup.
1152 function find_available(extra) {
1153 top.restoreSession();
1154 // (CHEMED) Conditional value selection, because there is no <select> element
1155 // when making an appointment for a specific provider
1156 var s = document.forms[0].form_provider;
1157 var f = document.forms[0].facility;
1158 <?php if ($userid != 0) { ?>
1159 s = document.forms[0].form_provider.value;
1160 f = document.forms[0].facility.value;
1161 <?php } else {?>
1162 s = document.forms[0].form_provider.options[s.selectedIndex].value;
1163 f = document.forms[0].facility.options[f.selectedIndex].value;
1164 <?php }?>
1165 var c = document.forms[0].form_category;
1166 var formDate = document.forms[0].form_date;
1167 dlgopen('<?php echo $GLOBALS['web_root']; ?>/interface/main/calendar/find_appt_popup.php' +
1168 '?providerid=' + s +
1169 '&catid=' + c.options[c.selectedIndex].value +
1170 '&facility=' + f +
1171 '&startdate=' + formDate.value +
1172 '&evdur=' + document.forms[0].form_duration.value +
1173 '&eid=<?php echo 0 + $eid; ?>' +
1174 extra,
1175 '_blank', 500, 400);
1180 </script>
1182 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1184 </head>
1186 <body class="body_top main-calendar-add_edit_event" onunload='imclosing()'>
1188 <form method='post' name='theform' id='theform' action='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1189 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1190 <input type='hidden' size='2' name='resname' value='empty' />
1191 <?php
1192 if ($_POST["resname"]=="noresult"){
1193 echo '
1194 <script language="Javascript">
1195 // refresh and redirect the parent window
1196 if (!opener.closed && opener.refreshme) opener.refreshme();
1197 top.restoreSession();
1198 opener.document.location="../../new/new.php";
1199 // Close the window
1200 window.close();
1201 </script>';
1203 $classprov='current';
1204 $classpati='';
1206 <!-- ViSolve : Requirement - Redirect to Create New Patient Page -->
1207 <input type="hidden" name="form_action" id="form_action" value="">
1208 <input type="hidden" name="recurr_affect" id="recurr_affect" value="">
1209 <!-- used for recurring events -->
1210 <input type="hidden" name="selected_date" id="selected_date" value="<?php echo attr($date); ?>">
1211 <input type="hidden" name="event_start_date" id="event_start_date" value="<?php echo attr($eventstartdate); ?>">
1212 <center>
1213 <table border='0' >
1214 <?php
1215 $provider_class='';
1216 $normal='';
1217 if($_GET['prov']==true){
1218 $provider_class="class='current'";
1220 else{
1221 $normal="class='current'";
1224 <tr><th><ul class="tabNav">
1225 <?php
1226 $eid=$_REQUEST["eid"];
1227 $startm=$_REQUEST["startampm"];
1228 $starth=$_REQUEST["starttimeh"];
1229 $uid=$_REQUEST["userid"];
1230 $starttm=$_REQUEST["starttimem"];
1231 $dt=$_REQUEST["date"];
1232 $cid=$_REQUEST["catid"];
1234 <li <?php echo $normal;?>>
1235 <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);?>'>
1236 <?php echo xlt('Patient');?></a>
1237 </li>
1238 <li <?php echo $provider_class;?>>
1239 <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);?>'>
1240 <?php echo xlt('Provider');?></a>
1241 </li>
1242 </ul>
1243 </th></tr>
1244 <tr><td colspan='10'>
1245 <table border='0' width='100%' bgcolor='#DDDDDD'>
1246 <tr>
1247 <td width='1%' nowrap>
1248 <b><?php echo xlt('Category'); ?>:</b>
1249 </td>
1250 <td nowrap>
1251 <select name='form_category' onchange='set_category()' style='width:100%'>
1252 <?php echo $catoptions ?>
1253 </select>
1254 </td>
1255 <td width='1%' nowrap>
1256 &nbsp;&nbsp;
1257 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
1258 <?php if ($thisduration == 1440) echo "checked " ?>/>
1259 </td>
1260 <td colspan='2' nowrap id='tdallday1'>
1261 <?php echo xlt('All day event'); ?>
1262 </td>
1263 </tr>
1264 <tr>
1265 <td nowrap>
1266 <b><?php echo xlt('Date'); ?>:</b>
1267 </td>
1268 <td nowrap>
1269 <input type='text' size='10' name='form_date' id='form_date'
1270 value='<?php echo attr($date) ?>'
1271 title='<?php echo xla('yyyy-mm-dd event date or starting date'); ?>'
1272 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' onchange='dateChanged()' />
1273 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1274 id='img_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1275 title='<?php echo xla('Click here to choose a date'); ?>'>
1276 </td>
1277 <td nowrap>
1278 &nbsp;&nbsp;
1279 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2' <?php if ($thisduration != 1440) echo "checked " ?>/>
1280 </td>
1281 <td width='1%' nowrap id='tdallday2'>
1282 <?php echo xlt('Time'); ?>
1283 </td>
1284 <td width='1%' nowrap id='tdallday3'>
1285 <span>
1286 <input type='text' size='2' name='form_hour' value='<?php echo attr($starttimeh) ?>'
1287 title='<?php echo xla('Event start time'); ?>' /> :
1288 <input type='text' size='2' name='form_minute' value='<?php echo attr($starttimem) ?>'
1289 title='<?php echo xla('Event start time'); ?>' />&nbsp;
1290 </span>
1291 <select name='form_ampm' title='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1292 <option value='1'><?php echo xlt('AM'); ?></option>
1293 <option value='2'<?php if ($startampm == '2') echo " selected" ?>><?php echo xlt('PM'); ?></option>
1294 </select>
1295 </td>
1296 </tr>
1297 <tr>
1298 <td nowrap>
1299 <b><?php echo xlt('Title'); ?>:</b>
1300 </td>
1301 <td nowrap>
1302 <input type='text' size='10' name='form_title' value='<?php echo attr($row['pc_title']); ?>'
1303 style='width:100%'
1304 title='<?php echo xla('Event title'); ?>' />
1305 </td>
1306 <td nowrap>&nbsp;
1308 </td>
1309 <td nowrap id='tdallday4'><?php echo xlt('duration'); ?>
1310 </td>
1311 <td nowrap id='tdallday5'>
1312 <input type='text' size='4' name='form_duration' value='<?php echo attr($thisduration) ?>' title='<?php echo xla('Event duration in minutes'); ?>' />
1313 <?php echo xlt('minutes'); ?>
1314 </td>
1315 </tr>
1317 <tr>
1318 <td nowrap><b><?php echo xlt('Facility'); ?>:</b></td>
1319 <td>
1320 <select name="facility" id="facility" >
1321 <?php
1323 // ===========================
1324 // EVENTS TO FACILITIES
1325 //(CHEMED) added service_location WHERE clause
1326 // get the facilities
1327 /***************************************************************
1328 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1329 ***************************************************************/
1330 $facils = getUserFacilities($_SESSION['authId']);
1331 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1332 /**************************************************************/
1333 while ($facrow = sqlFetchArray($qsql)) {
1334 /*************************************************************
1335 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1336 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1337 *************************************************************/
1338 if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
1339 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1340 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1342 else{
1343 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1344 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1346 /************************************************************/
1348 // EOS E2F
1349 // ===========================
1351 <?php
1352 //END (CHEMED) IF ?>
1353 </td>
1354 </select>
1355 </tr>
1356 <tr>
1357 <td nowrap>
1358 <b><?php echo xlt('Billing Facility'); ?>:</b>
1359 </td>
1360 <td>
1361 <?php
1362 billing_facility('billing_facility',$row['pc_billing_location']);
1364 </td>
1365 </tr>
1366 <?php
1367 if($_GET['prov']!=true){
1369 <tr id="patient_details">
1370 <td nowrap>
1371 <b><?php echo xlt('Patient'); ?>:</b>
1372 </td>
1373 <td nowrap>
1374 <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 />
1375 <input type='hidden' name='form_pid' value='<?php echo attr($patientid) ?>' />
1376 </td>
1377 <td colspan='3' nowrap style='font-size:8pt'>
1378 &nbsp;
1379 <span class="infobox">
1380 <?php if ($patienttitle != "") { echo $patienttitle; } ?>
1381 </span>
1382 </td>
1383 </tr>
1384 <?php
1387 <tr>
1388 <td nowrap>
1389 <b><?php echo xlt('Provider'); ?>:</b>
1390 </td>
1391 <td nowrap>
1393 <?php
1395 // =======================================
1396 // multi providers
1397 // =======================================
1398 if ($GLOBALS['select_multi_providers']) {
1400 // there are two posible situations: edit and new record
1401 $providers_array = array();
1402 // this is executed only on edit ($eid)
1403 if ($eid) {
1404 if ( $multiple_value ) {
1405 // find all the providers around multiple key
1406 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value) );
1407 while ($r = sqlFetchArray($qall)) {
1408 $providers_array[] = $r['providers'];
1410 } else {
1411 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1412 $providers_array = sqlFetchArray($qall);
1416 // build the selection tool
1417 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1419 while ($urow = sqlFetchArray($ures)) {
1420 echo " <option value='" . attr($urow['id']) . "'";
1422 if ($userid) {
1423 if ( in_array($urow['id'], $providers_array) || ($urow['id'] == $userid) ) echo " selected";
1426 echo ">" . text($urow['lname']);
1427 if ($urow['fname']) echo ", " . text($urow['fname']);
1428 echo "</option>\n";
1431 echo '</select>';
1433 // =======================================
1434 // single provider
1435 // =======================================
1436 } else {
1438 if ($eid) {
1439 // get provider from existing event
1440 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1441 $provider = sqlFetchArray($qprov);
1442 $defaultProvider = $provider['pc_aid'];
1444 else {
1445 // this is a new event so smartly choose a default provider
1446 /*****************************************************************
1447 if ($userid) {
1448 // Provider already given to us as a GET parameter.
1449 $defaultProvider = $userid;
1451 else {
1452 // default to the currently logged-in user
1453 $defaultProvider = $_SESSION['authUserID'];
1454 // or, if we have chosen a provider in the calendar, default to them
1455 // choose the first one if multiple have been selected
1456 if (count($_SESSION['pc_username']) >= 1) {
1457 // get the numeric ID of the first provider in the array
1458 $pc_username = $_SESSION['pc_username'];
1459 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1460 $defaultProvider = $firstProvider['id'];
1465 echo "<select name='form_provider' style='width:100%' />";
1466 while ($urow = sqlFetchArray($ures)) {
1467 echo " <option value='" . $urow['id'] . "'";
1468 if ($urow['id'] == $defaultProvider) echo " selected";
1469 echo ">" . $urow['lname'];
1470 if ($urow['fname']) echo ", " . $urow['fname'];
1471 echo "</option>\n";
1473 echo "</select>";
1474 *****************************************************************/
1475 // default to the currently logged-in user
1476 $defaultProvider = $_SESSION['authUserID'];
1477 // or, if we have chosen a provider in the calendar, default to them
1478 // choose the first one if multiple have been selected
1479 if (count($_SESSION['pc_username']) >= 1) {
1480 // get the numeric ID of the first provider in the array
1481 $pc_username = $_SESSION['pc_username'];
1482 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0]) ));
1483 $defaultProvider = $firstProvider['id'];
1485 // if we clicked on a provider's schedule to add the event, use THAT.
1486 if ($userid) $defaultProvider = $userid;
1488 echo "<select name='form_provider' style='width:100%' />";
1489 while ($urow = sqlFetchArray($ures)) {
1490 echo " <option value='" . attr($urow['id']) . "'";
1491 if ($urow['id'] == $defaultProvider) echo " selected";
1492 echo ">" . text($urow['lname']);
1493 if ($urow['fname']) echo ", " . text($urow['fname']);
1494 echo "</option>\n";
1496 echo "</select>";
1497 /****************************************************************/
1502 </td>
1503 <td nowrap>
1504 &nbsp;&nbsp;
1505 <?php
1506 //Check if repeat is using the new 'days every week' mechanism.
1507 function isDaysEveryWeek($repeat){
1508 if($repeat == 3){
1509 return true;
1511 else{
1512 return false;
1516 //Check if using the regular repeat mechanism.
1517 function isRegularRepeat($repeat){
1518 if($repeat == 1 || $repeat == 2){
1519 return true;
1521 else{
1522 return false;
1528 If the appointment was set with the regular (old) repeat mechanism (using 'every', 'every 2', etc.), then will be
1529 checked when editing and will select the proper recurrence pattern. If using the new repeat mechanism, then only that box (and the proper set
1530 days) will be checked. That's why I had to add the functions 'isRegularRepeat' and 'isDaysEveryWeek', to check which
1531 repeating mechanism is being used, and load settings accordingly.
1534 <input type='checkbox' name='form_repeat' id="form_repeat" onclick='set_repeat(this)' value='1'<?php if (isRegularRepeat($repeats)) echo " checked" ?>/>
1535 <input type='hidden' name='form_repeat_exdate' id='form_repeat_exdate' value='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat -->
1536 </td>
1537 <td nowrap id='tdrepeat1'><?php echo xlt('Repeats'); ?>
1538 </td>
1539 <td nowrap>
1541 <select name='form_repeat_freq' title='<?php echo xla('Every, every other, every 3rd, etc.'); ?>'>
1542 <?php
1543 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1544 as $key => $value)
1546 echo " <option value='" . attr($key) . "'";
1547 if ($key == $repeatfreq && isRegularRepeat($repeats)) echo " selected";
1548 echo ">" . text($value) . "</option>\n";
1551 </select>
1553 <select name='form_repeat_type'>
1554 <?php
1555 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1556 // when the start date is set.
1557 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1558 5 => '?', 6 => '?') as $key => $value)
1560 echo " <option value='" . attr($key) . "'";
1561 if ($key == $repeattype && isRegularRepeat($repeats)) echo " selected";
1562 echo ">" . text($value) . "</option>\n";
1565 </select>
1567 </td>
1568 </tr>
1570 <style>
1571 #days_every_week_row input[type="checkbox"]{float:right;}
1572 #days_every_week_row div{display: inline-block; text-align: center; width: 12%;}
1573 #days_every_week_row div input{width: 100%;}
1574 </style>
1576 <tr id="days_every_week_row">
1577 <td></td>
1578 <td></td>
1579 <td><input type='checkbox' id='days_every_week' name='days_every_week' onclick='set_days_every_week()' <?php if (isDaysEveryWeek($repeats)) echo " checked" ?>/></td>
1580 <td id="days_label"><?php echo xlt('Days Of Week') . ": "; ?></td>
1581 <td id="days">
1582 <?php
1583 foreach (array(1 => xl('Su{{Sunday}}') , 2 => xl('Mo{{Monday}}'), 3 => xl('Tu{{Tuesday}}'), 4 => xl('We{{Wednesday}}'),
1584 5 => xl('Th{{Thursday}}'), 6 => xl('Fr{{Friday}}'), 7 => xl('Sa{{Saturday}}')) as $key => $value)
1586 echo " <div><input type='checkbox' name='day_". attr($key) ."'";
1587 //Checks appropriate days according to days in recurrence string.
1588 if (in_array($key, explode(',',$repeatfreq)) && isDaysEveryWeek($repeats)) echo " checked";
1589 echo " /><label>" . text($value) . "</label></div>\n";
1592 </td>
1594 </tr>
1597 <tr>
1598 <td nowrap>
1599 <span id='title_apptstatus'><b><?php echo xlt('Status'); ?>:</b></span>
1600 <span id='title_prefcat' style='display:none'><b><?php echo xlt('Pref Cat'); ?>:</b></span>
1601 </td>
1602 <td nowrap>
1604 <?php
1605 generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'SKIP'), $row['pc_apptstatus']);
1607 <!--
1608 The following list will be invisible unless this is an In Office
1609 event, in which case form_apptstatus (above) is to be invisible.
1611 <select name='form_prefcat' style='width:100%;display:none' title='<?php echo xla('Preferred Event Category');?>'>
1612 <?php echo $prefcat_options ?>
1613 </select>
1615 </td>
1616 <td nowrap>&nbsp;
1618 </td>
1619 <td nowrap id='tdrepeat2'><?php echo xlt('until'); ?>
1620 </td>
1621 <td nowrap>
1622 <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');?>' />
1623 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1624 id='img_enddate' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1625 title='<?php echo xla('Click here to choose a date');?>'>
1626 <?php
1627 if ($repeatexdate != "") {
1628 $tmptitle = "The following dates are excluded from the repeating series";
1629 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1630 else { $tmptitle .= "\n"; }
1631 $exdates = explode(",", $repeatexdate);
1632 foreach ($exdates as $exdate) {
1633 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1635 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1638 </td>
1639 </tr>
1640 <?php
1641 if($_GET['prov']!=true){
1643 <tr>
1644 <td nowrap>
1645 <b><?php echo xlt('Room Number'); ?>:</b>
1646 </td>
1647 <td colspan='4' nowrap>
1648 <?php
1649 echo generate_select_list('form_room', 'patient_flow_board_rooms',$pcroom, xl('Room Number'));
1651 </td>
1652 </tr>
1653 <?php } ?>
1654 <tr>
1655 <td nowrap>
1656 <b><?php echo xlt('Comments'); ?>:</b>
1657 </td>
1658 <td colspan='4' nowrap>
1659 <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');?>' />
1660 </td>
1661 </tr>
1664 <?php
1665 // DOB is important for the clinic, so if it's missing give them a chance
1666 // to enter it right here. We must display or hide this row dynamically
1667 // in case the patient-select popup is used.
1668 $patient_dob = trim($prow['DOB']);
1669 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00')) ?
1670 '' : 'none';
1672 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
1673 <td colspan='4' nowrap>
1674 <b><font color='red'><?php echo xlt('DOB is missing, please enter if possible'); ?>:</font></b>
1675 </td>
1676 <td nowrap>
1677 <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)' />
1678 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
1679 id='img_dob' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
1680 title='<?php echo xla('Click here to choose a date');?>'>
1681 </td>
1682 </tr>
1684 </table></td></tr>
1685 <tr class='text'><td colspan='10' class="buttonbar">
1687 <input type='button' name='form_save' id='form_save' value='<?php echo xla('Save');?>' />
1688 &nbsp;
1690 <?php if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1691 <input type='button' id='find_available' value='<?php echo xla('Find Available');?>' />
1692 <?php } ?>
1694 &nbsp;
1695 <input type='button' name='form_delete' id='form_delete' value='<?php echo xla('Delete');?>'<?php if (!$eid) echo " disabled" ?> />
1696 &nbsp;
1697 <input type='button' id='cancel' value='<?php echo xla('Cancel');?>' />
1698 &nbsp;
1699 <input type='button' name='form_duplicate' id='form_duplicate' value='<?php echo xla('Create Duplicate');?>' />
1700 </p></td></tr></table>
1701 <?php if ($informant) echo "<p class='text'>" . xlt('Last update by') . " " .
1702 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n"; ?>
1703 </center>
1704 </form>
1706 <div id="recurr_popup" style="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1707 <?php echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?>
1708 <br>
1709 <input type="button" name="all_events" id="all_events" value=" <?php echo xla('All'); ?> ">
1710 <input type="button" name="future_events" id="future_events" value="<?php echo xla('Future'); ?>">
1711 <input type="button" name="current_event" id="current_event" value="<?php echo xla('Current'); ?>">
1712 <input type="button" name="recurr_cancel" id="recurr_cancel" value="<?php echo xla('Cancel'); ?>">
1713 </div>
1715 </body>
1717 <script language='JavaScript'>
1718 <?php if ($eid) { ?>
1719 set_display();
1720 <?php } else { ?>
1721 set_category();
1722 <?php } ?>
1723 set_allday();
1724 set_repeat();
1725 set_days_every_week();
1727 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
1728 Calendar.setup({inputField:"form_enddate", ifFormat:"%Y-%m-%d", button:"img_enddate"});
1729 Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});
1730 </script>
1732 <script language="javascript">
1733 // jQuery stuff to make the page a little easier to use
1735 $(document).ready(function(){
1736 $("#form_save").click(function() { validateform("save"); });
1737 $("#form_duplicate").click(function() { validateform("duplicate"); });
1738 $("#find_available").click(function() { find_available(''); });
1739 $("#form_delete").click(function() { deleteEvent(); });
1740 $("#cancel").click(function() { window.close(); });
1742 // buttons affecting the modification of a repeating event
1743 $("#all_events").click(function() { $("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1744 $("#future_events").click(function() { $("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1745 $("#current_event").click(function() { $("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1746 $("#recurr_cancel").click(function() { $("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1748 // Initialize repeat options.
1749 dateChanged();
1752 function are_days_checked(){
1753 var days = document.getElementById("days").getElementsByTagName('input');
1754 var counter = 0;
1755 for(var i=0; i < days.length; i++){
1756 if(days[i].checked){
1757 counter++;
1760 return counter;
1764 * validation on the form with new client side validation (using validate.js).
1765 * this enable to add new rules for this form in the pageValidation list.
1766 * */
1767 var collectvalidation = <?php echo($collectthis); ?>;
1768 function validateform(valu){
1770 //Make sure if days_every_week is checked that at least one weekday is checked.
1771 if($('#days_every_week').is(':checked') && !are_days_checked()){
1772 alert('<?php echo xls("Must choose at least one day!"); ?>');
1773 return false;
1776 //add rule if choose repeating event
1777 if ($('#form_repeat').is(':checked') || $('#days_every_week').is(':checked')){
1778 collectvalidation.form_enddate = {
1779 datetime: {
1780 dateOnly: true,
1781 earliest: $('#form_date').val(),
1782 message: "An end date later than the start date is required for repeated events!"
1784 presence: true
1786 } else {
1787 if(typeof (collectvalidation) != 'undefined'){
1788 delete collectvalidation.form_enddate;
1792 <?php
1793 if($_GET['prov']==true){
1795 //remove rule if it's provider event
1796 if(collectvalidation.form_patient != undefined){
1797 delete collectvalidation.form_patient;
1799 <?php
1803 <?php
1804 if($GLOBALS['select_multi_providers']){
1806 //If multiple providers is enabled, create provider validation (Note: if no provider is chosen it causes bugs when deleting recurrent events).
1807 collectvalidation.form_provider = {presence: true};
1808 <?php
1813 var submit = submitme(1, undefined, 'theform', collectvalidation);
1814 if(!submit)return;
1816 $('#form_action').val(valu);
1818 <?php if ($repeats): ?>
1819 // existing repeating events need additional prompt
1820 if ($("#recurr_affect").val() == "") {
1821 DisableForm();
1822 // show the current/future/all DIV for the user to choose one
1823 $("#recurr_popup").css("visibility", "visible");
1824 return false;
1826 <?php endif; ?>
1828 SubmitForm();
1832 // disable all the form elements outside the recurr_popup
1833 function DisableForm() {
1834 $("#theform").children().attr("disabled", "true");
1836 function EnableForm() {
1837 $("#theform").children().removeAttr("disabled");
1839 // hide the recurring popup DIV
1840 function HideRecurrPopup() {
1841 $("#recurr_popup").css("visibility", "hidden");
1844 function deleteEvent() {
1845 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?')); ?>")) {
1846 $('#form_action').val("delete");
1848 <?php if ($repeats): ?>
1849 // existing repeating events need additional prompt
1850 if ($("#recurr_affect").val() == "") {
1851 DisableForm();
1852 // show the current/future/all DIV for the user to choose one
1853 $("#recurr_popup").css("visibility", "visible");
1854 return false;
1856 <?php endif; ?>
1858 return SubmitForm();
1860 return false;
1863 function SubmitForm() {
1864 var f = document.forms[0];
1865 <?php if (!($GLOBALS['select_multi_providers'])) { // multi providers appt is not supported by check slot avail window, so skip ?>
1866 if (f.form_action.value != 'delete') {
1867 // Check slot availability.
1868 var mins = parseInt(f.form_hour.value) * 60 + parseInt(f.form_minute.value);
1869 if (f.form_ampm.value == '2' && mins < 720) mins += 720;
1870 find_available('&cktime=' + mins);
1872 else {
1873 top.restoreSession();
1874 f.submit();
1876 <?php } else { ?>
1877 top.restoreSession();
1878 f.submit();
1879 <?php } ?>
1881 return true;
1884 </script>
1886 </html>