2 // Copyright (C) 2005-2013 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // The event editor looks something like this:
11 //------------------------------------------------------------//
12 // Category __________________V O All day event //
13 // Date _____________ [?] O Time ___:___ __V //
14 // Title ___________________ duration ____ minutes //
15 // Patient _(Click_to_select)_ //
16 // Provider __________________V X Repeats ______V ______V //
17 // Status __________________V until __________ [?] //
18 // Comments ________________________________________________ //
20 // [Save] [Find Available] [Delete] [Cancel] //
21 //------------------------------------------------------------//
23 $fake_register_globals=false;
24 $sanitize_all_escapes=true;
26 require_once('../../globals.php');
27 require_once("$srcdir/patient.inc");
28 require_once("$srcdir/forms.inc");
29 require_once("$srcdir/calendar.inc");
30 require_once("$srcdir/formdata.inc.php");
31 require_once("$srcdir/options.inc.php");
32 require_once("$srcdir/encounter_events.inc.php");
33 require_once("$srcdir/acl.inc");
35 //Check access control
36 if (!acl_check('patients','appt','',array('write','wsome') ))
37 die(xl('Access not allowed'));
39 /* Things that might be passed by our opener. */
40 $eid = $_GET['eid']; // only for existing events
41 $date = $_GET['date']; // this and below only for new events
42 $userid = $_GET['userid'];
43 $default_catid = $_GET['catid'] ?
$_GET['catid'] : '5';
46 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
48 $date = date("Y-m-d");
51 if (isset($_GET['starttimem']))
52 $starttimem = substr('00' . $_GET['starttimem'], -2);
54 if (isset($_GET['starttimeh'])) {
55 $starttimeh = $_GET['starttimeh'];
56 if (isset($_GET['startampm'])) {
57 if ($_GET['startampm'] == '2' && $starttimeh < 12)
61 $starttimeh = date("G");
69 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
73 function InsertEventFull()
75 global $new_multiple_value,$provider,$event_date,$duration,$recurrspec,$starttime,$endtime,$locationspec;
76 // =======================================
77 // multi providers case
78 // =======================================
79 if (is_array($_POST['form_provider'])) {
81 // obtain the next available unique key to group multiple providers around some event
82 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
83 $max = sqlFetchArray($q);
84 $new_multiple_value = $max['max'] +
1;
86 foreach ($_POST['form_provider'] as $provider) {
88 // specify some special variables needed for the INSERT
89 $args['new_multiple_value'] = $new_multiple_value;
90 $args['form_provider'] = $provider;
91 $args['event_date'] = $event_date;
92 $args['duration'] = $duration * 60;
93 $args['recurrspec'] = $recurrspec;
94 $args['starttime'] = $starttime;
95 $args['endtime'] = $endtime;
96 $args['locationspec'] = $locationspec;
100 // ====================================
102 // ====================================
105 // specify some special variables needed for the INSERT
106 $args['new_multiple_value'] = "";
107 $args['event_date'] = $event_date;
108 $args['duration'] = $duration * 60;
109 $args['recurrspec'] = $recurrspec;
110 $args['starttime'] = $starttime;
111 $args['endtime'] = $endtime;
112 $args['locationspec'] = $locationspec;
116 function DOBandEncounter()
118 global $event_date,$info_msg;
119 // Save new DOB if it's there.
120 $patient_dob = trim($_POST['form_dob']);
121 if ($patient_dob && $_POST['form_pid']) {
122 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
123 "pid = ?", array($patient_dob,$_POST['form_pid']) );
126 // Auto-create a new encounter if appropriate.
128 if ($GLOBALS['auto_create_new_encounters'] && $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
130 $encounter = todaysEncounterCheck($_POST['form_pid'], $event_date, $_POST['form_comments'], $_POST['facility'], $_POST['billing_facility'], $_POST['form_provider'], $_POST['form_category'], false);
132 $info_msg .= xl("New encounter created with id");
133 $info_msg .= " $encounter";
137 //================================================================================================================
139 // EVENTS TO FACILITIES (lemonsoftware)
140 //(CHEMED) get facility name
141 // edit event case - if there is no association made, then insert one with the first facility
144 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
145 FROM openemr_postcalendar_events
146 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
147 WHERE pc_eid = ?", array($eid) );
148 // if ( !$facility['pc_facility'] ) {
149 if ( is_array($facility) && !$facility['pc_facility'] ) {
150 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']) );
151 $min = $qmin['minId'];
152 $min_name = $qmin['facility'];
154 // multiple providers case
155 if ( $GLOBALS['select_multi_providers'] ) {
156 $mul = $facility['pc_multiple'];
157 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min,$mul) );
161 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min,$eid) );
163 $e2f_name = $min_name;
166 if (!$facility['pc_facility'] && $_SESSION['pc_facility']) {
167 $e2f = $_SESSION['pc_facility'];
168 } elseif (!$facility['pc_facility'] && $_COOKIE['pc_facility'] && $GLOBALS['set_facility_cookie']) {
169 $e2f = $_COOKIE['pc_facility'];
171 $e2f = $facility['pc_facility'];
172 $e2f_name = $facility['name'];
177 // ===========================
178 //=============================================================================================================================
179 if ($_POST['form_action'] == "duplicate" ||
$_POST['form_action'] == "save")
181 // the starting date of the event, pay attention with this value
182 // when editing recurring events -- JRM Oct-08
183 $event_date = fixDate($_POST['form_date']);
185 // Compute start and end time strings to be saved.
186 if ($_POST['form_allday']) {
191 $tmph = $_POST['form_hour'] +
0;
192 $tmpm = $_POST['form_minute'] +
0;
193 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph +
= 12;
194 $duration = $_POST['form_duration'];
196 $starttime = "$tmph:$tmpm:00";
199 while ($tmpm >= 60) {
203 $endtime = "$tmph:$tmpm:00";
205 // Set up working variables related to repeated events.
207 $my_repeat_freq = 0 +
$_POST['form_repeat_freq'];
208 $my_repeat_type = 0 +
$_POST['form_repeat_type'];
209 $my_repeat_on_num = 1;
210 $my_repeat_on_day = 0;
211 $my_repeat_on_freq = 0;
212 if (!empty($_POST['form_repeat'])) {
214 if ($my_repeat_type > 4) {
216 $time = strtotime($event_date);
217 $my_repeat_on_day = 0 +
date('w', $time);
218 $my_repeat_on_freq = $my_repeat_freq;
219 if ($my_repeat_type == 5) {
220 $my_repeat_on_num = intval((date('j', $time) - 1) / 7) +
1;
223 // Last occurence of this weekday on the month
224 $my_repeat_on_num = 5;
226 // Maybe not needed, but for consistency with postcalendar:
232 // Useless garbage that we must save.
233 $locationspecs = array("event_location" => "",
234 "event_street1" => "",
235 "event_street2" => "",
240 $locationspec = serialize($locationspecs);
242 // capture the recurring specifications
243 $recurrspec = array("event_repeat_freq" => "$my_repeat_freq",
244 "event_repeat_freq_type" => "$my_repeat_type",
245 "event_repeat_on_num" => "$my_repeat_on_num",
246 "event_repeat_on_day" => "$my_repeat_on_day",
247 "event_repeat_on_freq" => "$my_repeat_on_freq",
248 "exdate" => $_POST['form_repeat_exdate']
251 // no recurr specs, this is used for adding a new non-recurring event
252 $noRecurrspec = array("event_repeat_freq" => "",
253 "event_repeat_freq_type" => "",
254 "event_repeat_on_num" => "1",
255 "event_repeat_on_day" => "0",
256 "event_repeat_on_freq" => "0",
260 }//if ($_POST['form_action'] == "duplicate" || $_POST['form_action'] == "save")
261 //=============================================================================================================================
262 if ($_POST['form_action'] == "duplicate") {
269 // If we are saving, then save and close the window.
271 if ($_POST['form_action'] == "save") {
272 /* =======================================================
274 * =====================================================*/
277 // what is multiple key around this $eid?
278 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
280 // ====================================
281 // multiple providers
282 // ====================================
283 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
285 // obtain current list of providers regarding the multiple key
286 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
287 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
289 // get the new list of providers from the submitted form
290 $providers_new = $_POST['form_provider'];
292 // ===== Only current event of repeating series =====
293 if ($_POST['recurr_affect'] == 'current') {
295 // update all existing event records to exlude the current date
296 foreach ($providers_current as $provider) {
297 // update the provider's original event
298 // get the original event's repeat specs
299 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
300 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
301 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
302 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
303 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
304 else { $oldRecurrspec['exdate'] .= $selected_date; }
306 // mod original event recur specs to exclude this date
307 sqlStatement("UPDATE openemr_postcalendar_events SET " .
308 " pc_recurrspec = ? ".
309 " WHERE pc_aid = ? AND pc_multiple=?", array(serialize($oldRecurrspec),$provider,$row['pc_multiple']) );
312 // obtain the next available unique key to group multiple providers around some event
313 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
314 $max = sqlFetchArray($q);
315 $new_multiple_value = $max['max'] +
1;
317 // insert a new event record for each provider selected on the form
318 foreach ($providers_new as $provider) {
319 // insert a new event on this date with POST form data
321 // specify some special variables needed for the INSERT
322 $args['new_multiple_value'] = $new_multiple_value;
323 $args['form_provider'] = $provider;
324 $args['event_date'] = $event_date;
325 $args['duration'] = $duration * 60;
326 // this event is forced to NOT REPEAT
327 $args['form_repeat'] = "0";
328 $args['recurrspec'] = $noRecurrspec;
329 $args['form_enddate'] = "0000-00-00";
330 $args['starttime'] = $starttime;
331 $args['endtime'] = $endtime;
332 $args['locationspec'] = $locationspec;
337 // ===== Future Recurring events of a repeating series =====
338 else if ($_POST['recurr_affect'] == 'future') {
339 // update all existing event records to
340 // stop recurring on this date-1
341 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
342 foreach ($providers_current as $provider) {
343 // mod original event recur specs to end on this date
344 sqlStatement("UPDATE openemr_postcalendar_events SET " .
346 " WHERE pc_aid = ? AND pc_multiple=?", array($selected_date,$provider,$row['pc_multiple']) );
349 // obtain the next available unique key to group multiple providers around some event
350 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
351 $max = sqlFetchArray($q);
352 $new_multiple_value = $max['max'] +
1;
354 // insert a new event record for each provider selected on the form
355 foreach ($providers_new as $provider) {
356 // insert a new event on this date with POST form data
358 // specify some special variables needed for the INSERT
359 $args['new_multiple_value'] = $new_multiple_value;
360 $args['form_provider'] = $provider;
361 $args['event_date'] = $event_date;
362 $args['duration'] = $duration * 60;
363 $args['recurrspec'] = $recurrspec;
364 $args['starttime'] = $starttime;
365 $args['endtime'] = $endtime;
366 $args['locationspec'] = $locationspec;
372 /* =================================================================== */
373 // ===== a Single event or All events in a repeating series ==========
374 /* =================================================================== */
376 // this difference means that some providers from current was UNCHECKED
377 // so we must delete this event for them
378 $r1 = array_diff ($providers_current, $providers_new);
380 foreach ($r1 as $to_be_removed) {
381 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid=? AND pc_multiple=?", array($to_be_removed,$row['pc_multiple']) );
385 // perform a check to see if user changed event date
386 // this is important when editing an existing recurring event
388 if ($_POST['form_date'] == $_POST['selected_date']) {
389 // user has NOT changed the start date of the event
390 $event_date = fixDate($_POST['event_start_date']);
393 // this difference means that some providers were added
394 // so we must insert this event for them
395 $r2 = array_diff ($providers_new, $providers_current);
397 foreach ($r2 as $to_be_inserted) {
399 // specify some special variables needed for the INSERT
400 $args['new_multiple_value'] = $row['pc_multiple'];
401 $args['form_provider'] = $to_be_inserted;
402 $args['event_date'] = $event_date;
403 $args['duration'] = $duration * 60;
404 $args['recurrspec'] = $recurrspec;
405 $args['starttime'] = $starttime;
406 $args['endtime'] = $endtime;
407 $args['locationspec'] = $locationspec;
412 // after the two diffs above, we must update for remaining providers
413 // those who are intersected in $providers_current and $providers_new
414 foreach ($_POST['form_provider'] as $provider) {
415 sqlStatement("UPDATE openemr_postcalendar_events SET " .
416 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
417 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
418 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
419 "pc_time = NOW(), " .
420 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
421 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
422 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
423 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
424 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
425 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
426 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
427 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
428 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
429 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
430 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
431 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
432 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
433 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
434 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple = '" . add_escape_custom($row['pc_multiple']) . "'");
438 // ====================================
440 // ====================================
441 } elseif ( !$row['pc_multiple'] ) {
442 if ( $GLOBALS['select_multi_providers'] ) {
443 $prov = $_POST['form_provider'][0];
445 $prov = $_POST['form_provider'];
448 if ($_POST['recurr_affect'] == 'current') {
449 // get the original event's repeat specs
450 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
451 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
452 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
453 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
454 else { $oldRecurrspec['exdate'] .= $selected_date; }
456 // mod original event recur specs to exclude this date
457 sqlStatement("UPDATE openemr_postcalendar_events SET " .
458 " pc_recurrspec = ? ".
459 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
461 // insert a new event on this date with POST form data
463 // specify some special variables needed for the INSERT
464 $args['event_date'] = $event_date;
465 $args['duration'] = $duration * 60;
466 // this event is forced to NOT REPEAT
467 $args['form_repeat'] = "0";
468 $args['recurrspec'] = $noRecurrspec;
469 $args['form_enddate'] = "0000-00-00";
470 $args['starttime'] = $starttime;
471 $args['endtime'] = $endtime;
472 $args['locationspec'] = $locationspec;
475 else if ($_POST['recurr_affect'] == 'future') {
476 // mod original event to stop recurring on this date-1
477 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
478 sqlStatement("UPDATE openemr_postcalendar_events SET " .
480 " WHERE pc_eid = ?", array($selected_date,$eid) );
482 // insert a new event starting on this date with POST form data
484 // specify some special variables needed for the INSERT
485 $args['event_date'] = $event_date;
486 $args['duration'] = $duration * 60;
487 $args['recurrspec'] = $recurrspec;
488 $args['starttime'] = $starttime;
489 $args['endtime'] = $endtime;
490 $args['locationspec'] = $locationspec;
495 // perform a check to see if user changed event date
496 // this is important when editing an existing recurring event
498 if ($_POST['form_date'] == $_POST['selected_date']) {
499 // user has NOT changed the start date of the event
500 $event_date = fixDate($_POST['event_start_date']);
503 // mod the SINGLE event or ALL EVENTS in a repeating series
504 // simple provider case
505 sqlStatement("UPDATE openemr_postcalendar_events SET " .
506 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
507 "pc_aid = '" . add_escape_custom($prov) . "', " .
508 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
509 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
510 "pc_time = NOW(), " .
511 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
512 "pc_informant = '" . add_escape_custom($_SESSION['authUserID']) . "', " .
513 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
514 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
515 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
516 "pc_recurrtype = '" . add_escape_custom($my_recurrtype) . "', " .
517 "pc_recurrspec = '" . add_escape_custom(serialize($recurrspec)) . "', " .
518 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
519 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
520 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
521 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
522 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "' ," .
523 "pc_facility = '" . add_escape_custom((int)$_POST['facility']) ."' ," . // FF stuff
524 "pc_billing_location = '" . add_escape_custom((int)$_POST['billing_facility']) ."' " .
525 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
529 // =======================================
530 // end Update Multi providers case
531 // =======================================
533 // EVENTS TO FACILITIES
538 /* =======================================================
539 * INSERT NEW EVENT(S)
540 * ======================================================*/
546 // done with EVENT insert/update statements
552 // =======================================
554 // =======================================
555 else if ($_POST['form_action'] == "delete") {
556 // =======================================
557 // multi providers event
558 // =======================================
559 if ($GLOBALS['select_multi_providers']) {
561 // what is multiple key around this $eid?
562 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
564 // obtain current list of providers regarding the multiple key
565 $providers_current = array();
566 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple=?", array($row['pc_multiple']) );
567 while ($current = sqlFetchArray($up)) { $providers_current[] = $current['pc_aid']; }
569 // establish a WHERE clause
570 if ( $row['pc_multiple'] ) { $whereClause = "pc_multiple = '{$row['pc_multiple']}'"; }
571 else { $whereClause = "pc_eid = '$eid'"; }
573 if ($_POST['recurr_affect'] == 'current') {
574 // update all existing event records to exlude the current date
575 foreach ($providers_current as $provider) {
576 // update the provider's original event
577 // get the original event's repeat specs
578 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events ".
579 " WHERE pc_aid = ? AND pc_multiple=?", array($provider,$row['pc_multiple']) );
580 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
581 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
582 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
583 else { $oldRecurrspec['exdate'] .= $selected_date; }
585 // mod original event recur specs to exclude this date
586 sqlStatement("UPDATE openemr_postcalendar_events SET " .
587 " pc_recurrspec = ? ".
588 " WHERE ". $whereClause, array(serialize($oldRecurrspec)) );
591 else if ($_POST['recurr_affect'] == 'future') {
592 // update all existing event records to stop recurring on this date-1
593 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
594 foreach ($providers_current as $provider) {
595 // update the provider's original event
596 sqlStatement("UPDATE openemr_postcalendar_events SET " .
598 " WHERE ".$whereClause, array($selected_date) );
602 // really delete the event from the database
603 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE ".$whereClause);
607 // =======================================
608 // single provider event
609 // =======================================
612 if ($_POST['recurr_affect'] == 'current') {
613 // mod original event recur specs to exclude this date
615 // get the original event's repeat specs
616 $origEvent = sqlQuery("SELECT pc_recurrspec FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
617 $oldRecurrspec = unserialize($origEvent['pc_recurrspec']);
618 $selected_date = date("Ymd", strtotime($_POST['selected_date']));
619 if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= ",".$selected_date; }
620 else { $oldRecurrspec['exdate'] .= $selected_date; }
621 sqlStatement("UPDATE openemr_postcalendar_events SET " .
622 " pc_recurrspec = ? ".
623 " WHERE pc_eid = ?", array(serialize($oldRecurrspec),$eid) );
626 else if ($_POST['recurr_affect'] == 'future') {
627 // mod original event to stop recurring on this date-1
628 $selected_date = date("Ymd", (strtotime($_POST['selected_date'])-24*60*60));
629 sqlStatement("UPDATE openemr_postcalendar_events SET " .
631 " WHERE pc_eid = ?", array($selected_date,$eid) );
635 // fully delete the event from the database
636 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
641 if ($_POST['form_action'] != "") {
642 // Close this window and refresh the calendar display.
643 echo "<html>\n<body>\n<script language='JavaScript'>\n";
644 if ($info_msg) echo " alert('" . addslashes($info_msg) . "');\n";
645 echo " if (opener && !opener.closed && opener.refreshme) opener.refreshme();\n";
646 echo " window.close();\n";
647 echo "</script>\n</body>\n</html>\n";
651 //*********************************
652 // If we get this far then we are displaying the form.
653 //*********************************
655 /*********************************************************************
656 This has been migrate to the administration->lists
659 '*' => xl('* Reminder done'),
660 '+' => xl('+ Chart pulled'),
661 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
662 '?' => xl('? No show'),
663 '@' => xl('@ Arrived'),
664 '~' => xl('~ Arrived late'),
665 '!' => xl('! Left w/o visit'),
666 '#' => xl('# Ins/fin issue'),
667 '<' => xl('< In exam room'),
668 '>' => xl('> Checked out'),
669 '$' => xl('$ Coding done'),
670 '%' => xl('% Cancelled < 24h ')
672 *********************************************************************/
674 $repeats = 0; // if the event repeats
678 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
679 $patientname = xl('Click to select');
685 // If we are editing an existing event, then get its data.
687 // $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
689 $row = sqlQuery("SELECT e.*, u.fname, u.mname, u.lname " .
690 "FROM openemr_postcalendar_events AS e " .
691 "LEFT OUTER JOIN users AS u ON u.id = e.pc_informant " .
692 "WHERE pc_eid = ?", array($eid) );
693 $informant = $row['fname'] . ' ' . $row['mname'] . ' ' . $row['lname'];
695 // instead of using the event's starting date, keep what has been provided
696 // via the GET array, see the top of this file
697 if (empty($_GET['date'])) $date = $row['pc_eventDate'];
698 $eventstartdate = $row['pc_eventDate']; // for repeating event stuff - JRM Oct-08
699 $userid = $row['pc_aid'];
700 $patientid = $row['pc_pid'];
701 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
702 $starttimem = substr($row['pc_startTime'], 3, 2);
703 $repeats = $row['pc_recurrtype'];
704 $multiple_value = $row['pc_multiple'];
706 // parse out the repeating data, if any
707 $rspecs = unserialize($row['pc_recurrspec']); // extract recurring data
708 $repeattype = $rspecs['event_repeat_freq_type'];
709 $repeatfreq = $rspecs['event_repeat_freq'];
710 $repeatexdate = $rspecs['exdate']; // repeating date exceptions
712 // Adjustments for repeat type 2, a particular weekday of the month.
714 $repeatfreq = $rspecs['event_repeat_on_freq'];
715 if ($rspecs['event_repeat_on_num'] < 5) {
723 $hometext = $row['pc_hometext'];
724 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
728 $eventstartdate = $date; // for repeating event stuff - JRM Oct-08
730 //-------------------------------------
732 //Set default facility for a new event based on the given 'userid'
734 /*************************************************************
735 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
736 *************************************************************/
737 if ($_SESSION['pc_facility']) {
738 $pref_facility = sqlFetchArray(sqlStatement("
739 SELECT f.id as facility_id,
744 array($_SESSION['pc_facility'])
747 $pref_facility = sqlFetchArray(sqlStatement("
748 SELECT u.facility_id,
751 LEFT JOIN facility f on (u.facility_id = f.id)
753 ", array($userid) ));
755 /************************************************************/
756 $e2f = $pref_facility['facility_id'];
757 $e2f_name = $pref_facility['facility'];
759 //END of CHEMED -----------------------
762 // If we have a patient ID, get the name and phone numbers to display.
764 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
765 "FROM patient_data WHERE pid = ?", array($patientid) );
766 $patientname = $prow['lname'] . ", " . $prow['fname'];
767 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
768 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
771 // Get the providers list.
772 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
773 "authorized != 0 AND active = 1 ORDER BY lname, fname");
775 // Get event categories.
776 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
777 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
779 // Fix up the time format for AM/PM.
781 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
783 if ($starttimeh > 12) $starttimeh -= 12;
789 <?php
html_header_show(); ?
>
790 <title
><?php
echo $eid ?
xlt('Edit') : xlt('Add New') ?
> <?php
echo xlt('Event');?
></title
>
791 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
794 td
{ font
-size
:0.8em
; }
797 <style type
="text/css">@import
url(../../../library
/dynarch_calendar
.css
);</style
>
798 <script type
="text/javascript" src
="../../../library/topdialog.js"></script
>
799 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
800 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
801 <script type
="text/javascript" src
="../../../library/dynarch_calendar.js"></script
>
802 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
803 <script type
="text/javascript" src
="../../../library/dynarch_calendar_setup.js"></script
>
805 <script language
="JavaScript">
807 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
809 var durations
= new Array();
810 // var rectypes = new Array();
812 // Read the event categories, generate their options list, and get
813 // the default event duration from them if this is a new event.
815 if($_GET['prov']==true){
818 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
819 "FROM openemr_postcalendar_categories WHERE pc_cattype=? ORDER BY pc_catname", array($cattype) );
821 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
824 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
826 while ($crow = sqlFetchArray($cres)) {
827 $duration = round($crow['pc_duration'] / 60);
828 if ($crow['pc_end_all_day']) $duration = 1440;
829 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
830 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
831 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
833 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
835 if ($crow['pc_catid'] == $default_catid) {
836 $catoptions .= " selected";
837 $thisduration = $duration;
840 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
842 // This section is to build the list of preferred categories:
844 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
846 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
848 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
854 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
856 // This is for callback by the find-patient popup.
857 function setpatient(pid
, lname
, fname
, dob
) {
858 var f
= document
.forms
[0];
859 f
.form_patient
.value
= lname +
', ' + fname
;
860 f
.form_pid
.value
= pid
;
861 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
862 document
.getElementById('dob_row').style
.display
= dobstyle
;
865 // This invokes the find-patient popup.
866 function sel_patient() {
867 dlgopen('find_patient_popup.php', '_blank', 500, 400);
870 // Do whatever is needed when a new event category is selected.
871 // For now this means changing the event title and duration.
872 function set_display() {
873 var f
= document
.forms
[0];
874 var s
= f
.form_category
;
875 if (s
.selectedIndex
>= 0) {
876 var catid
= s
.options
[s
.selectedIndex
].value
;
877 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
878 var style_prefcat
= document
.getElementById('title_prefcat').style
;
879 if (catid
== '2') { // In Office
880 style_apptstatus
.display
= 'none';
881 style_prefcat
.display
= '';
882 f
.form_apptstatus
.style
.display
= 'none';
883 f
.form_prefcat
.style
.display
= '';
885 style_prefcat
.display
= 'none';
886 style_apptstatus
.display
= '';
887 f
.form_prefcat
.style
.display
= 'none';
888 f
.form_apptstatus
.style
.display
= '';
893 // Do whatever is needed when a new event category is selected.
894 // For now this means changing the event title and duration.
895 function set_category() {
896 var f
= document
.forms
[0];
897 var s
= f
.form_category
;
898 if (s
.selectedIndex
>= 0) {
899 var catid
= s
.options
[s
.selectedIndex
].value
;
900 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
901 f
.form_duration
.value
= durations
[catid
];
906 // Modify some visual attributes when the all-day or timed-event
907 // radio buttons are clicked.
908 function set_allday() {
909 var f
= document
.forms
[0];
910 var color1
= '#777777';
911 var color2
= '#777777';
912 var disabled2
= true;
913 if (document
.getElementById('rballday1').checked
) {
916 if (document
.getElementById('rballday2').checked
) {
920 document
.getElementById('tdallday1').style
.color
= color1
;
921 document
.getElementById('tdallday2').style
.color
= color2
;
922 document
.getElementById('tdallday3').style
.color
= color2
;
923 document
.getElementById('tdallday4').style
.color
= color2
;
924 document
.getElementById('tdallday5').style
.color
= color2
;
925 f
.form_hour
.disabled
= disabled2
;
926 f
.form_minute
.disabled
= disabled2
;
927 f
.form_ampm
.disabled
= disabled2
;
928 f
.form_duration
.disabled
= disabled2
;
931 // Modify some visual attributes when the Repeat checkbox is clicked.
932 function set_repeat() {
933 var f
= document
.forms
[0];
934 var isdisabled
= true;
935 var mycolor
= '#777777';
936 var myvisibility
= 'hidden';
937 if (f
.form_repeat
.checked
) {
940 myvisibility
= 'visible';
942 f
.form_repeat_type
.disabled
= isdisabled
;
943 f
.form_repeat_freq
.disabled
= isdisabled
;
944 f
.form_enddate
.disabled
= isdisabled
;
945 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
946 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
947 document
.getElementById('img_enddate').style
.visibility
= myvisibility
;
950 // Constants used by dateChanged() function.
951 var occurNames
= new Array(
952 '<?php echo xls("1st"); ?>',
953 '<?php echo xls("2nd"); ?>',
954 '<?php echo xls("3rd"); ?>',
955 '<?php echo xls("4th"); ?>'
958 // Monitor start date changes to adjust repeat type options.
959 function dateChanged() {
960 var f
= document
.forms
[0];
961 if (!f
.form_date
.value
) return;
962 var d
= new Date(f
.form_date
.value
);
963 var downame
= Calendar
._DN
[d
.getUTCDay()];
965 var occur
= Math
.floor((d
.getUTCDate() - 1) / 7);
966 if (occur
< 4) { // 5th is not allowed
967 nthtext
= occurNames
[occur
] +
' ' + downame
;
970 var tmp
= new Date(d
.getUTCFullYear(), d
.getUTCMonth() +
1, 0);
971 if (tmp
.getUTCDate() - d
.getUTCDate() < 7) {
972 // This is a last occurrence of the specified weekday in the month,
973 // so permit that as an option.
974 lasttext
= '<?php echo xls("Last"); ?> ' + downame
;
976 var si
= f
.form_repeat_type
.selectedIndex
;
977 var opts
= f
.form_repeat_type
.options
;
978 opts
.length
= 5; // remove any nth and Last entries
979 if (nthtext
) opts
[opts
.length
] = new Option(nthtext
, '5');
980 if (lasttext
) opts
[opts
.length
] = new Option(lasttext
, '6');
981 if (si
< opts
.length
) f
.form_repeat_type
.selectedIndex
= si
;
984 // This is for callback by the find-available popup.
985 function setappt(year
,mon
,mday
,hours
,minutes
) {
986 var f
= document
.forms
[0];
987 f
.form_date
.value
= '' + year +
'-' +
988 ('' +
(mon +
100)).substring(1) +
'-' +
989 ('' +
(mday +
100)).substring(1);
990 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
991 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
992 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
995 // Invoke the find-available popup.
996 function find_available(extra
) {
997 top
.restoreSession();
998 // (CHEMED) Conditional value selection, because there is no <select> element
999 // when making an appointment for a specific provider
1000 var s
= document
.forms
[0].form_provider
;
1001 var f
= document
.forms
[0].facility
;
1002 <?php
if ($userid != 0) { ?
>
1003 s
= document
.forms
[0].form_provider
.value
;
1004 f
= document
.forms
[0].facility
.value
;
1006 s
= document
.forms
[0].form_provider
.options
[s
.selectedIndex
].value
;
1007 f
= document
.forms
[0].facility
.options
[f
.selectedIndex
].value
;
1009 var c
= document
.forms
[0].form_category
;
1010 var formDate
= document
.forms
[0].form_date
;
1011 dlgopen('<?php echo $GLOBALS['web_root
']; ?>/interface/main/calendar/find_appt_popup.php' +
1012 '?providerid=' + s +
1013 '&catid=' + c
.options
[c
.selectedIndex
].value +
1015 '&startdate=' + formDate
.value +
1016 '&evdur=' + document
.forms
[0].form_duration
.value +
1017 '&eid=<?php echo 0 + $eid; ?>' +
1019 '_blank', 500, 400);
1024 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8" />
1028 <body
class="body_top" onunload
='imclosing()'>
1030 <form method
='post' name
='theform' id
='theform' action
='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1031 <!-- ViSolve
: Requirement
- Redirect to Create
New Patient Page
-->
1032 <input type
='hidden' size
='2' name
='resname' value
='empty' />
1034 if ($_POST["resname"]=="noresult"){
1036 <script language="Javascript">
1037 // refresh and redirect the parent window
1038 if (!opener.closed && opener.refreshme) opener.refreshme();
1039 top.restoreSession();
1040 opener.document.location="../../new/new.php";
1045 $classprov='current';
1048 <!-- ViSolve
: Requirement
- Redirect to Create
New Patient Page
-->
1049 <input type
="hidden" name
="form_action" id
="form_action" value
="">
1050 <input type
="hidden" name
="recurr_affect" id
="recurr_affect" value
="">
1051 <!-- used
for recurring events
-->
1052 <input type
="hidden" name
="selected_date" id
="selected_date" value
="<?php echo attr($date); ?>">
1053 <input type
="hidden" name
="event_start_date" id
="event_start_date" value
="<?php echo attr($eventstartdate); ?>">
1059 if($_GET['prov']==true){
1060 $provider_class="class='current'";
1063 $normal="class='current'";
1066 <tr
><th
><ul
class="tabNav">
1068 $eid=$_REQUEST["eid"];
1069 $startm=$_REQUEST["startampm"];
1070 $starth=$_REQUEST["starttimeh"];
1071 $uid=$_REQUEST["userid"];
1072 $starttm=$_REQUEST["starttimem"];
1073 $dt=$_REQUEST["date"];
1074 $cid=$_REQUEST["catid"];
1076 <li
<?php
echo $normal;?
>>
1077 <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);?>'>
1078 <?php
echo xlt('Patient');?
></a
>
1080 <li
<?php
echo $provider_class;?
>>
1081 <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);?>'>
1082 <?php
echo xlt('Provider');?
></a
>
1086 <tr
><td colspan
='10'>
1087 <table border
='0' width
='100%' bgcolor
='#DDDDDD' >
1090 <td width
='1%' nowrap
>
1091 <b
><?php
echo ($GLOBALS['athletic_team'] ?
xlt('Team/Squad') : xlt('Category')); ?
>:</b
>
1094 <select name
='form_category' onchange
='set_category()' style
='width:100%'>
1095 <?php
echo $catoptions ?
>
1098 <td width
='1%' nowrap
>
1100 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='1' id
='rballday1'
1101 <?php
if ($thisduration == 1440) echo "checked " ?
>/>
1103 <td colspan
='2' nowrap id
='tdallday1'>
1104 <?php
echo xlt('All day event'); ?
>
1110 <b
><?php
echo xlt('Date'); ?
>:</b
>
1113 <input type
='text' size
='10' name
='form_date' id
='form_date'
1114 value
='<?php echo attr($date) ?>'
1115 title
='<?php echo xla('yyyy
-mm
-dd event date
or starting date
'); ?>'
1116 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' onchange
='dateChanged()' />
1117 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1118 id
='img_date' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1119 title
='<?php echo xla('Click here to choose a date
'); ?>'>
1123 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='0' id
='rballday2' <?php
if ($thisduration != 1440) echo "checked " ?
>/>
1125 <td width
='1%' nowrap id
='tdallday2'>
1126 <?php
echo xlt('Time'); ?
>
1128 <td width
='1%' nowrap id
='tdallday3'>
1129 <input type
='text' size
='2' name
='form_hour' value
='<?php echo attr($starttimeh) ?>'
1130 title
='<?php echo xla('Event start time
'); ?>' /> :
1131 <input type
='text' size
='2' name
='form_minute' value
='<?php echo attr($starttimem) ?>'
1132 title
='<?php echo xla('Event start time
'); ?>' /> 
;
1133 <select name
='form_ampm' title
='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1134 <option value
='1'><?php
echo xlt('AM'); ?
></option
>
1135 <option value
='2'<?php
if ($startampm == '2') echo " selected" ?
>><?php
echo xlt('PM'); ?
></option
>
1142 <b
><?php
echo ($GLOBALS['athletic_team'] ?
xlt('Team/Squad') : xlt('Title')); ?
>:</b
>
1145 <input type
='text' size
='10' name
='form_title' value
='<?php echo attr($row['pc_title
']); ?>'
1147 title
='<?php echo xla('Event title
'); ?>' />
1152 <td nowrap id
='tdallday4'><?php
echo xlt('duration'); ?
>
1154 <td nowrap id
='tdallday5'>
1155 <input type
='text' size
='4' name
='form_duration' value
='<?php echo attr($thisduration) ?>' title
='<?php echo xla('Event duration in minutes
'); ?>' />
1156 <?php
echo xlt('minutes'); ?
>
1161 <td nowrap
><b
><?php
echo xlt('Facility'); ?
>:</b
></td
>
1163 <select name
="facility" id
="facility" >
1166 // ===========================
1167 // EVENTS TO FACILITIES
1168 //(CHEMED) added service_location WHERE clause
1169 // get the facilities
1170 /***************************************************************
1171 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1172 ***************************************************************/
1173 $facils = getUserFacilities($_SESSION['authId']);
1174 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1175 /**************************************************************/
1176 while ($facrow = sqlFetchArray($qsql)) {
1177 /*************************************************************
1178 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1179 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1180 *************************************************************/
1181 if ($_SESSION['authorizedUser'] ||
in_array($facrow, $facils)) {
1182 $selected = ( $facrow['id'] == $e2f ) ?
'selected="selected"' : '' ;
1183 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1186 $selected = ( $facrow['id'] == $e2f ) ?
'selected="selected"' : '' ;
1187 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1189 /************************************************************/
1192 // ===========================
1195 //END (CHEMED) IF ?>
1201 <b
><?php
echo xlt('Billing Facility'); ?
>:</b
>
1205 billing_facility('billing_facility',$row['pc_billing_location']);
1210 if($_GET['prov']!=true){
1212 <tr id
="patient_details">
1214 <b
><?php
echo xlt('Patient'); ?
>:</b
>
1217 <input type
='text' size
='10' name
='form_patient' style
='width:100%;cursor:pointer;cursor:hand' value
='<?php echo attr($patientname); ?>' onclick
='sel_patient()' title
='<?php echo xla('Click to select patient
'); ?>' readonly
/>
1218 <input type
='hidden' name
='form_pid' value
='<?php echo attr($patientid) ?>' />
1220 <td colspan
='3' nowrap style
='font-size:8pt'>
1222 <span
class="infobox">
1223 <?php
if ($patienttitle != "") { echo $patienttitle; } ?
>
1232 <b
><?php
echo xlt('Provider'); ?
>:</b
>
1238 // =======================================
1240 // =======================================
1241 if ($GLOBALS['select_multi_providers']) {
1243 // there are two posible situations: edit and new record
1245 // this is executed only on edit ($eid)
1247 if ( $multiple_value ) {
1248 // find all the providers around multiple key
1249 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value) );
1250 while ($r = sqlFetchArray($qall)) {
1251 $providers_array[] = $r['providers'];
1254 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1255 $providers_array = sqlFetchArray($qall);
1259 // build the selection tool
1260 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1262 while ($urow = sqlFetchArray($ures)) {
1263 echo " <option value='" . attr($urow['id']) . "'";
1266 if ( in_array($urow['id'], $providers_array) ||
($urow['id'] == $userid) ) echo " selected";
1269 echo ">" . text($urow['lname']);
1270 if ($urow['fname']) echo ", " . text($urow['fname']);
1276 // =======================================
1278 // =======================================
1282 // get provider from existing event
1283 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1284 $provider = sqlFetchArray($qprov);
1285 $defaultProvider = $provider['pc_aid'];
1288 // this is a new event so smartly choose a default provider
1289 /*****************************************************************
1291 // Provider already given to us as a GET parameter.
1292 $defaultProvider = $userid;
1295 // default to the currently logged-in user
1296 $defaultProvider = $_SESSION['authUserID'];
1297 // or, if we have chosen a provider in the calendar, default to them
1298 // choose the first one if multiple have been selected
1299 if (count($_SESSION['pc_username']) >= 1) {
1300 // get the numeric ID of the first provider in the array
1301 $pc_username = $_SESSION['pc_username'];
1302 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1303 $defaultProvider = $firstProvider['id'];
1308 echo "<select name='form_provider' style='width:100%' />";
1309 while ($urow = sqlFetchArray($ures)) {
1310 echo " <option value='" . $urow['id'] . "'";
1311 if ($urow['id'] == $defaultProvider) echo " selected";
1312 echo ">" . $urow['lname'];
1313 if ($urow['fname']) echo ", " . $urow['fname'];
1317 *****************************************************************/
1318 // default to the currently logged-in user
1319 $defaultProvider = $_SESSION['authUserID'];
1320 // or, if we have chosen a provider in the calendar, default to them
1321 // choose the first one if multiple have been selected
1322 if (count($_SESSION['pc_username']) >= 1) {
1323 // get the numeric ID of the first provider in the array
1324 $pc_username = $_SESSION['pc_username'];
1325 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0]) ));
1326 $defaultProvider = $firstProvider['id'];
1328 // if we clicked on a provider's schedule to add the event, use THAT.
1329 if ($userid) $defaultProvider = $userid;
1331 echo "<select name='form_provider' style='width:100%' />";
1332 while ($urow = sqlFetchArray($ures)) {
1333 echo " <option value='" . attr($urow['id']) . "'";
1334 if ($urow['id'] == $defaultProvider) echo " selected";
1335 echo ">" . text($urow['lname']);
1336 if ($urow['fname']) echo ", " . text($urow['fname']);
1340 /****************************************************************/
1348 <input type
='checkbox' name
='form_repeat' onclick
='set_repeat(this)' value
='1'<?php
if ($repeats) echo " checked" ?
>/>
1349 <input type
='hidden' name
='form_repeat_exdate' id
='form_repeat_exdate' value
='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat
-->
1351 <td nowrap id
='tdrepeat1'><?php
echo xlt('Repeats'); ?
>
1355 <select name
='form_repeat_freq' title
='<?php echo xla('Every
, every other
, every
3rd
, etc
.'); ?>'>
1357 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1360 echo " <option value='" . attr($key) . "'";
1361 if ($key == $repeatfreq) echo " selected";
1362 echo ">" . text($value) . "</option>\n";
1367 <select name
='form_repeat_type'>
1369 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1370 // when the start date is set.
1371 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1372 5 => '?', 6 => '?') as $key => $value)
1374 echo " <option value='" . attr($key) . "'";
1375 if ($key == $repeattype) echo " selected";
1376 echo ">" . text($value) . "</option>\n";
1386 <span id
='title_apptstatus'><b
><?php
echo ($GLOBALS['athletic_team'] ?
xlt('Session Type') : xlt('Status')); ?
>:</b
></span
>
1387 <span id
='title_prefcat' style
='display:none'><b
><?php
echo xlt('Pref Cat'); ?
>:</b
></span
>
1392 generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'SKIP'), $row['pc_apptstatus']);
1395 The following
list will be invisible unless this is an In Office
1396 event
, in which
case form_apptstatus (above
) is to be invisible
.
1398 <select name
='form_prefcat' style
='width:100%;display:none' title
='<?php echo xla('Preferred Event Category
');?>'>
1399 <?php
echo $prefcat_options ?
>
1406 <td nowrap id
='tdrepeat2'><?php
echo xlt('until'); ?
>
1409 <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
');?>' />
1410 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1411 id
='img_enddate' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1412 title
='<?php echo xla('Click here to choose a date
');?>'>
1414 if ($repeatexdate != "") {
1415 $tmptitle = "The following dates are excluded from the repeating series";
1416 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1417 else { $tmptitle .= "\n"; }
1418 $exdates = explode(",", $repeatexdate);
1419 foreach ($exdates as $exdate) {
1420 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1422 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1430 <b
><?php
echo xlt('Comments'); ?
>:</b
>
1432 <td colspan
='4' nowrap
>
1433 <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
');?>' />
1438 // DOB is important for the clinic, so if it's missing give them a chance
1439 // to enter it right here. We must display or hide this row dynamically
1440 // in case the patient-select popup is used.
1441 $patient_dob = trim($prow['DOB']);
1442 $dobstyle = ($prow && (!$patient_dob ||
substr($patient_dob, 5) == '00-00')) ?
1445 <tr id
='dob_row' style
='display:<?php echo $dobstyle ?>'>
1446 <td colspan
='4' nowrap
>
1447 <b
><font color
='red'><?php
echo xlt('DOB is missing, please enter if possible'); ?
>:</font
></b
>
1450 <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)' />
1451 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1452 id
='img_dob' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1453 title
='<?php echo xla('Click here to choose a date
');?>'>
1458 <tr
class='text'><td colspan
='10'>
1460 <input type
='button' name
='form_save' id
='form_save' value
='<?php echo xla('Save
');?>' />
1463 <?php
if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1464 <input type
='button' id
='find_available' value
='<?php echo xla('Find Available
');?>' />
1468 <input type
='button' name
='form_delete' id
='form_delete' value
='<?php echo xla('Delete
');?>'<?php
if (!$eid) echo " disabled" ?
> />
1470 <input type
='button' id
='cancel' value
='<?php echo xla('Cancel
');?>' />
1472 <input type
='button' name
='form_duplicate' id
='form_duplicate' value
='<?php echo xla('Create Duplicate
');?>' />
1473 </p
></td
></tr
></table
>
1474 <?php
if ($informant) echo "<p class='text'>" . xlt('Last update by') . " " .
1475 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n"; ?
>
1479 <div id
="recurr_popup" style
="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1480 <?php
echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?
>
1482 <input type
="button" name
="all_events" id
="all_events" value
=" All ">
1483 <input type
="button" name
="future_events" id
="future_events" value
="Future">
1484 <input type
="button" name
="current_event" id
="current_event" value
="Current">
1485 <input type
="button" name
="recurr_cancel" id
="recurr_cancel" value
="Cancel">
1490 <script language
='JavaScript'>
1491 <?php
if ($eid) { ?
>
1499 Calendar
.setup({inputField
:"form_date", ifFormat
:"%Y-%m-%d", button
:"img_date"});
1500 Calendar
.setup({inputField
:"form_enddate", ifFormat
:"%Y-%m-%d", button
:"img_enddate"});
1501 Calendar
.setup({inputField
:"form_dob", ifFormat
:"%Y-%m-%d", button
:"img_dob"});
1504 <script language
="javascript">
1505 // jQuery stuff to make the page a little easier to use
1507 $
(document
).ready(function(){
1508 $
("#form_save").click(function() { validate("save"); });
1509 $
("#form_duplicate").click(function() { validate("duplicate"); });
1510 $
("#find_available").click(function() { find_available(''); });
1511 $
("#form_delete").click(function() { deleteEvent(); });
1512 $
("#cancel").click(function() { window
.close(); });
1514 // buttons affecting the modification of a repeating event
1515 $
("#all_events").click(function() { $
("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1516 $
("#future_events").click(function() { $
("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1517 $
("#current_event").click(function() { $
("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1518 $
("#recurr_cancel").click(function() { $
("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1520 // Initialize repeat options.
1524 // Check for errors when the form is submitted.
1525 function validate(valu
) {
1526 var f
= document
.getElementById('theform');
1527 if (f
.form_repeat
.checked
&&
1528 (! f
.form_enddate
.value || f
.form_enddate
.value
< f
.form_date
.value
)) {
1529 alert('<?php echo addslashes(xl("An end date later than the start date is required for repeated events!")); ?>');
1533 if($_GET['prov']!=true){
1535 if(f
.form_pid
.value
== ''){
1536 alert('<?php echo addslashes(xl('Patient Name Required
'));?>');
1542 $
('#form_action').val(valu
);
1544 <?php
if ($repeats): ?
>
1545 // existing repeating events need additional prompt
1546 if ($
("#recurr_affect").val() == "") {
1548 // show the current/future/all DIV for the user to choose one
1549 $
("#recurr_popup").css("visibility", "visible");
1554 return SubmitForm();
1557 // disable all the form elements outside the recurr_popup
1558 function DisableForm() {
1559 $
("#theform").children().attr("disabled", "true");
1561 function EnableForm() {
1562 $
("#theform").children().removeAttr("disabled");
1564 // hide the recurring popup DIV
1565 function HideRecurrPopup() {
1566 $
("#recurr_popup").css("visibility", "hidden");
1569 function deleteEvent() {
1570 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?')); ?>")) {
1571 $
('#form_action').val("delete");
1573 <?php
if ($repeats): ?
>
1574 // existing repeating events need additional prompt
1575 if ($
("#recurr_affect").val() == "") {
1577 // show the current/future/all DIV for the user to choose one
1578 $
("#recurr_popup").css("visibility", "visible");
1583 return SubmitForm();
1588 function SubmitForm() {
1589 var f
= document
.forms
[0];
1590 <?php
if (!($GLOBALS['select_multi_providers'])) { // multi providers appt is not supported by check slot avail window, so skip ?>
1591 if (f
.form_action
.value
!= 'delete') {
1592 // Check slot availability.
1593 var mins
= parseInt(f
.form_hour
.value
) * 60 +
parseInt(f
.form_minute
.value
);
1594 if (f
.form_ampm
.value
== '2' && mins
< 720) mins +
= 720;
1595 find_available('&cktime=' + mins
);
1598 top
.restoreSession();
1602 top
.restoreSession();