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_cattype, pc_catname, " .
819 "pc_recurrtype, pc_duration, pc_end_all_day " .
820 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
822 $prefcat_options = " <option value='0'>-- " . xlt("None") . " --</option>\n";
825 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
827 while ($crow = sqlFetchArray($cres)) {
828 $duration = round($crow['pc_duration'] / 60);
829 if ($crow['pc_end_all_day']) $duration = 1440;
831 // This section is to build the list of preferred categories:
833 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
835 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
837 $prefcat_options .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
840 if ($crow['pc_cattype'] != $cattype) continue;
842 echo " durations[" . attr($crow['pc_catid']) . "] = " . attr($duration) . "\n";
843 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
844 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
846 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
848 if ($crow['pc_catid'] == $default_catid) {
849 $catoptions .= " selected";
850 $thisduration = $duration;
853 $catoptions .= ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>\n";
857 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
859 // This is for callback by the find-patient popup.
860 function setpatient(pid
, lname
, fname
, dob
) {
861 var f
= document
.forms
[0];
862 f
.form_patient
.value
= lname +
', ' + fname
;
863 f
.form_pid
.value
= pid
;
864 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
865 document
.getElementById('dob_row').style
.display
= dobstyle
;
868 // This invokes the find-patient popup.
869 function sel_patient() {
870 dlgopen('find_patient_popup.php', '_blank', 500, 400);
873 // Do whatever is needed when a new event category is selected.
874 // For now this means changing the event title and duration.
875 function set_display() {
876 var f
= document
.forms
[0];
877 var s
= f
.form_category
;
878 if (s
.selectedIndex
>= 0) {
879 var catid
= s
.options
[s
.selectedIndex
].value
;
880 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
881 var style_prefcat
= document
.getElementById('title_prefcat').style
;
882 if (catid
== '2') { // In Office
883 style_apptstatus
.display
= 'none';
884 style_prefcat
.display
= '';
885 f
.form_apptstatus
.style
.display
= 'none';
886 f
.form_prefcat
.style
.display
= '';
888 style_prefcat
.display
= 'none';
889 style_apptstatus
.display
= '';
890 f
.form_prefcat
.style
.display
= 'none';
891 f
.form_apptstatus
.style
.display
= '';
896 // Do whatever is needed when a new event category is selected.
897 // For now this means changing the event title and duration.
898 function set_category() {
899 var f
= document
.forms
[0];
900 var s
= f
.form_category
;
901 if (s
.selectedIndex
>= 0) {
902 var catid
= s
.options
[s
.selectedIndex
].value
;
903 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
904 f
.form_duration
.value
= durations
[catid
];
909 // Modify some visual attributes when the all-day or timed-event
910 // radio buttons are clicked.
911 function set_allday() {
912 var f
= document
.forms
[0];
913 var color1
= '#777777';
914 var color2
= '#777777';
915 var disabled2
= true;
916 if (document
.getElementById('rballday1').checked
) {
919 if (document
.getElementById('rballday2').checked
) {
923 document
.getElementById('tdallday1').style
.color
= color1
;
924 document
.getElementById('tdallday2').style
.color
= color2
;
925 document
.getElementById('tdallday3').style
.color
= color2
;
926 document
.getElementById('tdallday4').style
.color
= color2
;
927 document
.getElementById('tdallday5').style
.color
= color2
;
928 f
.form_hour
.disabled
= disabled2
;
929 f
.form_minute
.disabled
= disabled2
;
930 f
.form_ampm
.disabled
= disabled2
;
931 f
.form_duration
.disabled
= disabled2
;
934 // Modify some visual attributes when the Repeat checkbox is clicked.
935 function set_repeat() {
936 var f
= document
.forms
[0];
937 var isdisabled
= true;
938 var mycolor
= '#777777';
939 var myvisibility
= 'hidden';
940 if (f
.form_repeat
.checked
) {
943 myvisibility
= 'visible';
945 f
.form_repeat_type
.disabled
= isdisabled
;
946 f
.form_repeat_freq
.disabled
= isdisabled
;
947 f
.form_enddate
.disabled
= isdisabled
;
948 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
949 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
950 document
.getElementById('img_enddate').style
.visibility
= myvisibility
;
953 // Constants used by dateChanged() function.
954 var occurNames
= new Array(
955 '<?php echo xls("1st"); ?>',
956 '<?php echo xls("2nd"); ?>',
957 '<?php echo xls("3rd"); ?>',
958 '<?php echo xls("4th"); ?>'
961 // Monitor start date changes to adjust repeat type options.
962 function dateChanged() {
963 var f
= document
.forms
[0];
964 if (!f
.form_date
.value
) return;
965 var d
= new Date(f
.form_date
.value
);
966 var downame
= Calendar
._DN
[d
.getUTCDay()];
968 var occur
= Math
.floor((d
.getUTCDate() - 1) / 7);
969 if (occur
< 4) { // 5th is not allowed
970 nthtext
= occurNames
[occur
] +
' ' + downame
;
973 var tmp
= new Date(d
.getUTCFullYear(), d
.getUTCMonth() +
1, 0);
974 if (tmp
.getUTCDate() - d
.getUTCDate() < 7) {
975 // This is a last occurrence of the specified weekday in the month,
976 // so permit that as an option.
977 lasttext
= '<?php echo xls("Last"); ?> ' + downame
;
979 var si
= f
.form_repeat_type
.selectedIndex
;
980 var opts
= f
.form_repeat_type
.options
;
981 opts
.length
= 5; // remove any nth and Last entries
982 if (nthtext
) opts
[opts
.length
] = new Option(nthtext
, '5');
983 if (lasttext
) opts
[opts
.length
] = new Option(lasttext
, '6');
984 if (si
< opts
.length
) f
.form_repeat_type
.selectedIndex
= si
;
987 // This is for callback by the find-available popup.
988 function setappt(year
,mon
,mday
,hours
,minutes
) {
989 var f
= document
.forms
[0];
990 f
.form_date
.value
= '' + year +
'-' +
991 ('' +
(mon +
100)).substring(1) +
'-' +
992 ('' +
(mday +
100)).substring(1);
993 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
994 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
995 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
998 // Invoke the find-available popup.
999 function find_available(extra
) {
1000 top
.restoreSession();
1001 // (CHEMED) Conditional value selection, because there is no <select> element
1002 // when making an appointment for a specific provider
1003 var s
= document
.forms
[0].form_provider
;
1004 var f
= document
.forms
[0].facility
;
1005 <?php
if ($userid != 0) { ?
>
1006 s
= document
.forms
[0].form_provider
.value
;
1007 f
= document
.forms
[0].facility
.value
;
1009 s
= document
.forms
[0].form_provider
.options
[s
.selectedIndex
].value
;
1010 f
= document
.forms
[0].facility
.options
[f
.selectedIndex
].value
;
1012 var c
= document
.forms
[0].form_category
;
1013 var formDate
= document
.forms
[0].form_date
;
1014 dlgopen('<?php echo $GLOBALS['web_root
']; ?>/interface/main/calendar/find_appt_popup.php' +
1015 '?providerid=' + s +
1016 '&catid=' + c
.options
[c
.selectedIndex
].value +
1018 '&startdate=' + formDate
.value +
1019 '&evdur=' + document
.forms
[0].form_duration
.value +
1020 '&eid=<?php echo 0 + $eid; ?>' +
1022 '_blank', 500, 400);
1027 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8" />
1031 <body
class="body_top" onunload
='imclosing()'>
1033 <form method
='post' name
='theform' id
='theform' action
='add_edit_event.php?eid=<?php echo attr($eid) ?>' />
1034 <!-- ViSolve
: Requirement
- Redirect to Create
New Patient Page
-->
1035 <input type
='hidden' size
='2' name
='resname' value
='empty' />
1037 if ($_POST["resname"]=="noresult"){
1039 <script language="Javascript">
1040 // refresh and redirect the parent window
1041 if (!opener.closed && opener.refreshme) opener.refreshme();
1042 top.restoreSession();
1043 opener.document.location="../../new/new.php";
1048 $classprov='current';
1051 <!-- ViSolve
: Requirement
- Redirect to Create
New Patient Page
-->
1052 <input type
="hidden" name
="form_action" id
="form_action" value
="">
1053 <input type
="hidden" name
="recurr_affect" id
="recurr_affect" value
="">
1054 <!-- used
for recurring events
-->
1055 <input type
="hidden" name
="selected_date" id
="selected_date" value
="<?php echo attr($date); ?>">
1056 <input type
="hidden" name
="event_start_date" id
="event_start_date" value
="<?php echo attr($eventstartdate); ?>">
1062 if($_GET['prov']==true){
1063 $provider_class="class='current'";
1066 $normal="class='current'";
1069 <tr
><th
><ul
class="tabNav">
1071 $eid=$_REQUEST["eid"];
1072 $startm=$_REQUEST["startampm"];
1073 $starth=$_REQUEST["starttimeh"];
1074 $uid=$_REQUEST["userid"];
1075 $starttm=$_REQUEST["starttimem"];
1076 $dt=$_REQUEST["date"];
1077 $cid=$_REQUEST["catid"];
1079 <li
<?php
echo $normal;?
>>
1080 <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);?>'>
1081 <?php
echo xlt('Patient');?
></a
>
1083 <li
<?php
echo $provider_class;?
>>
1084 <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);?>'>
1085 <?php
echo xlt('Provider');?
></a
>
1089 <tr
><td colspan
='10'>
1090 <table border
='0' width
='100%' bgcolor
='#DDDDDD' >
1093 <td width
='1%' nowrap
>
1094 <b
><?php
echo ($GLOBALS['athletic_team'] ?
xlt('Team/Squad') : xlt('Category')); ?
>:</b
>
1097 <select name
='form_category' onchange
='set_category()' style
='width:100%'>
1098 <?php
echo $catoptions ?
>
1101 <td width
='1%' nowrap
>
1103 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='1' id
='rballday1'
1104 <?php
if ($thisduration == 1440) echo "checked " ?
>/>
1106 <td colspan
='2' nowrap id
='tdallday1'>
1107 <?php
echo xlt('All day event'); ?
>
1113 <b
><?php
echo xlt('Date'); ?
>:</b
>
1116 <input type
='text' size
='10' name
='form_date' id
='form_date'
1117 value
='<?php echo attr($date) ?>'
1118 title
='<?php echo xla('yyyy
-mm
-dd event date
or starting date
'); ?>'
1119 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' onchange
='dateChanged()' />
1120 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1121 id
='img_date' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1122 title
='<?php echo xla('Click here to choose a date
'); ?>'>
1126 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='0' id
='rballday2' <?php
if ($thisduration != 1440) echo "checked " ?
>/>
1128 <td width
='1%' nowrap id
='tdallday2'>
1129 <?php
echo xlt('Time'); ?
>
1131 <td width
='1%' nowrap id
='tdallday3'>
1132 <input type
='text' size
='2' name
='form_hour' value
='<?php echo attr($starttimeh) ?>'
1133 title
='<?php echo xla('Event start time
'); ?>' /> :
1134 <input type
='text' size
='2' name
='form_minute' value
='<?php echo attr($starttimem) ?>'
1135 title
='<?php echo xla('Event start time
'); ?>' /> 
;
1136 <select name
='form_ampm' title
='<?php echo xla("Note: 12:00 noon is PM, not AM"); ?>'>
1137 <option value
='1'><?php
echo xlt('AM'); ?
></option
>
1138 <option value
='2'<?php
if ($startampm == '2') echo " selected" ?
>><?php
echo xlt('PM'); ?
></option
>
1145 <b
><?php
echo ($GLOBALS['athletic_team'] ?
xlt('Team/Squad') : xlt('Title')); ?
>:</b
>
1148 <input type
='text' size
='10' name
='form_title' value
='<?php echo attr($row['pc_title
']); ?>'
1150 title
='<?php echo xla('Event title
'); ?>' />
1155 <td nowrap id
='tdallday4'><?php
echo xlt('duration'); ?
>
1157 <td nowrap id
='tdallday5'>
1158 <input type
='text' size
='4' name
='form_duration' value
='<?php echo attr($thisduration) ?>' title
='<?php echo xla('Event duration in minutes
'); ?>' />
1159 <?php
echo xlt('minutes'); ?
>
1164 <td nowrap
><b
><?php
echo xlt('Facility'); ?
>:</b
></td
>
1166 <select name
="facility" id
="facility" >
1169 // ===========================
1170 // EVENTS TO FACILITIES
1171 //(CHEMED) added service_location WHERE clause
1172 // get the facilities
1173 /***************************************************************
1174 $qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
1175 ***************************************************************/
1176 $facils = getUserFacilities($_SESSION['authId']);
1177 $qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
1178 /**************************************************************/
1179 while ($facrow = sqlFetchArray($qsql)) {
1180 /*************************************************************
1181 $selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
1182 echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
1183 *************************************************************/
1184 if ($_SESSION['authorizedUser'] ||
in_array($facrow, $facils)) {
1185 $selected = ( $facrow['id'] == $e2f ) ?
'selected="selected"' : '' ;
1186 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1189 $selected = ( $facrow['id'] == $e2f ) ?
'selected="selected"' : '' ;
1190 echo "<option value='" . attr($facrow['id']) . "' $selected>" . text($facrow['name']) . "</option>";
1192 /************************************************************/
1195 // ===========================
1198 //END (CHEMED) IF ?>
1204 <b
><?php
echo xlt('Billing Facility'); ?
>:</b
>
1208 billing_facility('billing_facility',$row['pc_billing_location']);
1213 if($_GET['prov']!=true){
1215 <tr id
="patient_details">
1217 <b
><?php
echo xlt('Patient'); ?
>:</b
>
1220 <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
/>
1221 <input type
='hidden' name
='form_pid' value
='<?php echo attr($patientid) ?>' />
1223 <td colspan
='3' nowrap style
='font-size:8pt'>
1225 <span
class="infobox">
1226 <?php
if ($patienttitle != "") { echo $patienttitle; } ?
>
1235 <b
><?php
echo xlt('Provider'); ?
>:</b
>
1241 // =======================================
1243 // =======================================
1244 if ($GLOBALS['select_multi_providers']) {
1246 // there are two posible situations: edit and new record
1248 // this is executed only on edit ($eid)
1250 if ( $multiple_value ) {
1251 // find all the providers around multiple key
1252 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($multiple_value) );
1253 while ($r = sqlFetchArray($qall)) {
1254 $providers_array[] = $r['providers'];
1257 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1258 $providers_array = sqlFetchArray($qall);
1262 // build the selection tool
1263 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5' >";
1265 while ($urow = sqlFetchArray($ures)) {
1266 echo " <option value='" . attr($urow['id']) . "'";
1269 if ( in_array($urow['id'], $providers_array) ||
($urow['id'] == $userid) ) echo " selected";
1272 echo ">" . text($urow['lname']);
1273 if ($urow['fname']) echo ", " . text($urow['fname']);
1279 // =======================================
1281 // =======================================
1285 // get provider from existing event
1286 $qprov = sqlStatement ("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid) );
1287 $provider = sqlFetchArray($qprov);
1288 $defaultProvider = $provider['pc_aid'];
1291 // this is a new event so smartly choose a default provider
1292 /*****************************************************************
1294 // Provider already given to us as a GET parameter.
1295 $defaultProvider = $userid;
1298 // default to the currently logged-in user
1299 $defaultProvider = $_SESSION['authUserID'];
1300 // or, if we have chosen a provider in the calendar, default to them
1301 // choose the first one if multiple have been selected
1302 if (count($_SESSION['pc_username']) >= 1) {
1303 // get the numeric ID of the first provider in the array
1304 $pc_username = $_SESSION['pc_username'];
1305 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
1306 $defaultProvider = $firstProvider['id'];
1311 echo "<select name='form_provider' style='width:100%' />";
1312 while ($urow = sqlFetchArray($ures)) {
1313 echo " <option value='" . $urow['id'] . "'";
1314 if ($urow['id'] == $defaultProvider) echo " selected";
1315 echo ">" . $urow['lname'];
1316 if ($urow['fname']) echo ", " . $urow['fname'];
1320 *****************************************************************/
1321 // default to the currently logged-in user
1322 $defaultProvider = $_SESSION['authUserID'];
1323 // or, if we have chosen a provider in the calendar, default to them
1324 // choose the first one if multiple have been selected
1325 if (count($_SESSION['pc_username']) >= 1) {
1326 // get the numeric ID of the first provider in the array
1327 $pc_username = $_SESSION['pc_username'];
1328 $firstProvider = sqlFetchArray(sqlStatement("select id from users where username=?", array($pc_username[0]) ));
1329 $defaultProvider = $firstProvider['id'];
1331 // if we clicked on a provider's schedule to add the event, use THAT.
1332 if ($userid) $defaultProvider = $userid;
1334 echo "<select name='form_provider' style='width:100%' />";
1335 while ($urow = sqlFetchArray($ures)) {
1336 echo " <option value='" . attr($urow['id']) . "'";
1337 if ($urow['id'] == $defaultProvider) echo " selected";
1338 echo ">" . text($urow['lname']);
1339 if ($urow['fname']) echo ", " . text($urow['fname']);
1343 /****************************************************************/
1351 <input type
='checkbox' name
='form_repeat' onclick
='set_repeat(this)' value
='1'<?php
if ($repeats) echo " checked" ?
>/>
1352 <input type
='hidden' name
='form_repeat_exdate' id
='form_repeat_exdate' value
='<?php echo attr($repeatexdate); ?>' /> <!-- dates excluded from the repeat
-->
1354 <td nowrap id
='tdrepeat1'><?php
echo xlt('Repeats'); ?
>
1358 <select name
='form_repeat_freq' title
='<?php echo xla('Every
, every other
, every
3rd
, etc
.'); ?>'>
1360 foreach (array(1 => xl('every'), 2 => xl('2nd'), 3 => xl('3rd'), 4 => xl('4th'), 5 => xl('5th'), 6 => xl('6th'))
1363 echo " <option value='" . attr($key) . "'";
1364 if ($key == $repeatfreq) echo " selected";
1365 echo ">" . text($value) . "</option>\n";
1370 <select name
='form_repeat_type'>
1372 // See common.api.php for these. Options 5 and 6 will be dynamically filled in
1373 // when the start date is set.
1374 foreach (array(0 => xl('day') , 4 => xl('workday'), 1 => xl('week'), 2 => xl('month'), 3 => xl('year'),
1375 5 => '?', 6 => '?') as $key => $value)
1377 echo " <option value='" . attr($key) . "'";
1378 if ($key == $repeattype) echo " selected";
1379 echo ">" . text($value) . "</option>\n";
1389 <span id
='title_apptstatus'><b
><?php
echo ($GLOBALS['athletic_team'] ?
xlt('Session Type') : xlt('Status')); ?
>:</b
></span
>
1390 <span id
='title_prefcat' style
='display:none'><b
><?php
echo xlt('Pref Cat'); ?
>:</b
></span
>
1395 generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'SKIP'), $row['pc_apptstatus']);
1398 The following
list will be invisible unless this is an In Office
1399 event
, in which
case form_apptstatus (above
) is to be invisible
.
1401 <select name
='form_prefcat' style
='width:100%;display:none' title
='<?php echo xla('Preferred Event Category
');?>'>
1402 <?php
echo $prefcat_options ?
>
1409 <td nowrap id
='tdrepeat2'><?php
echo xlt('until'); ?
>
1412 <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
');?>' />
1413 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1414 id
='img_enddate' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1415 title
='<?php echo xla('Click here to choose a date
');?>'>
1417 if ($repeatexdate != "") {
1418 $tmptitle = "The following dates are excluded from the repeating series";
1419 if ($multiple_value) { $tmptitle .= " for one or more providers:\n"; }
1420 else { $tmptitle .= "\n"; }
1421 $exdates = explode(",", $repeatexdate);
1422 foreach ($exdates as $exdate) {
1423 $tmptitle .= date("d M Y", strtotime($exdate))."\n";
1425 echo "<a href='#' title='" . attr($tmptitle) . "' alt='" . attr($tmptitle) . "'><img src='../../pic/warning.gif' title='" . attr($tmptitle) . "' alt='*!*' style='border:none;'/></a>";
1433 <b
><?php
echo xlt('Comments'); ?
>:</b
>
1435 <td colspan
='4' nowrap
>
1436 <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
');?>' />
1441 // DOB is important for the clinic, so if it's missing give them a chance
1442 // to enter it right here. We must display or hide this row dynamically
1443 // in case the patient-select popup is used.
1444 $patient_dob = trim($prow['DOB']);
1445 $dobstyle = ($prow && (!$patient_dob ||
substr($patient_dob, 5) == '00-00')) ?
1448 <tr id
='dob_row' style
='display:<?php echo $dobstyle ?>'>
1449 <td colspan
='4' nowrap
>
1450 <b
><font color
='red'><?php
echo xlt('DOB is missing, please enter if possible'); ?
>:</font
></b
>
1453 <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)' />
1454 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1455 id
='img_dob' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand'
1456 title
='<?php echo xla('Click here to choose a date
');?>'>
1461 <tr
class='text'><td colspan
='10'>
1463 <input type
='button' name
='form_save' id
='form_save' value
='<?php echo xla('Save
');?>' />
1466 <?php
if (!($GLOBALS['select_multi_providers'])) { //multi providers appt is not supported by check slot avail window, so skip ?>
1467 <input type
='button' id
='find_available' value
='<?php echo xla('Find Available
');?>' />
1471 <input type
='button' name
='form_delete' id
='form_delete' value
='<?php echo xla('Delete
');?>'<?php
if (!$eid) echo " disabled" ?
> />
1473 <input type
='button' id
='cancel' value
='<?php echo xla('Cancel
');?>' />
1475 <input type
='button' name
='form_duplicate' id
='form_duplicate' value
='<?php echo xla('Create Duplicate
');?>' />
1476 </p
></td
></tr
></table
>
1477 <?php
if ($informant) echo "<p class='text'>" . xlt('Last update by') . " " .
1478 text($informant) . " " . xlt('on') . " " . text($row['pc_time']) . "</p>\n"; ?
>
1482 <div id
="recurr_popup" style
="visibility: hidden; position: absolute; top: 50px; left: 50px; width: 400px; border: 3px outset yellow; background-color: yellow; padding: 5px;">
1483 <?php
echo xlt('Apply the changes to the Current event only, to this and all Future occurrences, or to All occurrences?') ?
>
1485 <input type
="button" name
="all_events" id
="all_events" value
=" All ">
1486 <input type
="button" name
="future_events" id
="future_events" value
="Future">
1487 <input type
="button" name
="current_event" id
="current_event" value
="Current">
1488 <input type
="button" name
="recurr_cancel" id
="recurr_cancel" value
="Cancel">
1493 <script language
='JavaScript'>
1494 <?php
if ($eid) { ?
>
1502 Calendar
.setup({inputField
:"form_date", ifFormat
:"%Y-%m-%d", button
:"img_date"});
1503 Calendar
.setup({inputField
:"form_enddate", ifFormat
:"%Y-%m-%d", button
:"img_enddate"});
1504 Calendar
.setup({inputField
:"form_dob", ifFormat
:"%Y-%m-%d", button
:"img_dob"});
1507 <script language
="javascript">
1508 // jQuery stuff to make the page a little easier to use
1510 $
(document
).ready(function(){
1511 $
("#form_save").click(function() { validate("save"); });
1512 $
("#form_duplicate").click(function() { validate("duplicate"); });
1513 $
("#find_available").click(function() { find_available(''); });
1514 $
("#form_delete").click(function() { deleteEvent(); });
1515 $
("#cancel").click(function() { window
.close(); });
1517 // buttons affecting the modification of a repeating event
1518 $
("#all_events").click(function() { $
("#recurr_affect").val("all"); EnableForm(); SubmitForm(); });
1519 $
("#future_events").click(function() { $
("#recurr_affect").val("future"); EnableForm(); SubmitForm(); });
1520 $
("#current_event").click(function() { $
("#recurr_affect").val("current"); EnableForm(); SubmitForm(); });
1521 $
("#recurr_cancel").click(function() { $
("#recurr_affect").val(""); EnableForm(); HideRecurrPopup(); });
1523 // Initialize repeat options.
1527 // Check for errors when the form is submitted.
1528 function validate(valu
) {
1529 var f
= document
.getElementById('theform');
1530 if (f
.form_repeat
.checked
&&
1531 (! f
.form_enddate
.value || f
.form_enddate
.value
< f
.form_date
.value
)) {
1532 alert('<?php echo addslashes(xl("An end date later than the start date is required for repeated events!")); ?>');
1536 if($_GET['prov']!=true){
1538 if(f
.form_pid
.value
== ''){
1539 alert('<?php echo addslashes(xl('Patient Name Required
'));?>');
1545 $
('#form_action').val(valu
);
1547 <?php
if ($repeats): ?
>
1548 // existing repeating events need additional prompt
1549 if ($
("#recurr_affect").val() == "") {
1551 // show the current/future/all DIV for the user to choose one
1552 $
("#recurr_popup").css("visibility", "visible");
1557 return SubmitForm();
1560 // disable all the form elements outside the recurr_popup
1561 function DisableForm() {
1562 $
("#theform").children().attr("disabled", "true");
1564 function EnableForm() {
1565 $
("#theform").children().removeAttr("disabled");
1567 // hide the recurring popup DIV
1568 function HideRecurrPopup() {
1569 $
("#recurr_popup").css("visibility", "hidden");
1572 function deleteEvent() {
1573 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?')); ?>")) {
1574 $
('#form_action').val("delete");
1576 <?php
if ($repeats): ?
>
1577 // existing repeating events need additional prompt
1578 if ($
("#recurr_affect").val() == "") {
1580 // show the current/future/all DIV for the user to choose one
1581 $
("#recurr_popup").css("visibility", "visible");
1586 return SubmitForm();
1591 function SubmitForm() {
1592 var f
= document
.forms
[0];
1593 <?php
if (!($GLOBALS['select_multi_providers'])) { // multi providers appt is not supported by check slot avail window, so skip ?>
1594 if (f
.form_action
.value
!= 'delete') {
1595 // Check slot availability.
1596 var mins
= parseInt(f
.form_hour
.value
) * 60 +
parseInt(f
.form_minute
.value
);
1597 if (f
.form_ampm
.value
== '2' && mins
< 720) mins +
= 720;
1598 find_available('&cktime=' + mins
);
1601 top
.restoreSession();
1605 top
.restoreSession();