2 // Copyright (C) 2005-2006 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 include_once("../../globals.php");
24 include_once("$srcdir/patient.inc");
26 // Things that might be passed by our opener.
28 $eid = $_GET['eid']; // only for existing events
29 $date = $_GET['date']; // this and below only for new events
30 $userid = $_GET['userid'];
31 $default_catid = $_GET['catid'] ?
$_GET['catid'] : '5';
34 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
36 $date = date("Y-m-d");
39 if (isset($_GET['starttimem']))
40 $starttimem = substr('00' . $_GET['starttimem'], -2);
42 if (isset($_GET['starttimeh'])) {
43 $starttimeh = $_GET['starttimeh'];
44 if (isset($_GET['startampm'])) {
45 if ($_GET['startampm'] == '2' && $starttimeh < 12)
49 $starttimeh = date("G");
55 // If we are saving, then save and close the window.
57 if ($_POST['form_save']) {
59 // Compute start and end time strings to be saved.
60 if ($_POST['form_allday']) {
65 $tmph = $_POST['form_hour'] +
0;
66 $tmpm = $_POST['form_minute'] +
0;
67 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph +
= 12;
68 $duration = $_POST['form_duration'];
70 $starttime = "$tmph:$tmpm:00";
77 $endtime = "$tmph:$tmpm:00";
79 // Useless garbage that we must save.
80 $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' .
81 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}';
83 // More garbage, but this time 1 character of it is used to save the
85 if ($_POST['form_repeat']) {
86 $recurrspec = 'a:5:{' .
87 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' .
88 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' .
89 's:19:"event_repeat_on_num";s:1:"1";' .
90 's:19:"event_repeat_on_day";s:1:"0";' .
91 's:20:"event_repeat_on_freq";s:1:"0";}';
93 $recurrspec = 'a:5:{' .
94 's:17:"event_repeat_freq";N;' .
95 's:22:"event_repeat_freq_type";s:1:"0";' .
96 's:19:"event_repeat_on_num";s:1:"1";' .
97 's:19:"event_repeat_on_day";s:1:"0";' .
98 's:20:"event_repeat_on_freq";s:1:"1";}';
102 sqlStatement("UPDATE openemr_postcalendar_events SET " .
103 "pc_catid = '" . $_POST['form_category'] . "', " .
104 "pc_aid = '" . $_POST['form_provider'] . "', " .
105 "pc_pid = '" . $_POST['form_pid'] . "', " .
106 "pc_title = '" . $_POST['form_title'] . "', " .
107 "pc_time = NOW(), " .
108 "pc_hometext = '" . $_POST['form_comments'] . "', " .
109 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
110 "pc_eventDate = '" . fixDate($_POST['form_date']) . "', " .
111 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
112 "pc_duration = '" . ($duration * 60) . "', " .
113 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
114 "pc_recurrspec = '$recurrspec', " .
115 "pc_startTime = '$starttime', " .
116 "pc_endTime = '$endtime', " .
117 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
118 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
119 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' " .
120 "WHERE pc_eid = '$eid'");
122 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
123 "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
124 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
125 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
126 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing " .
128 "'" . $_POST['form_category'] . "', " .
129 "'" . $_POST['form_provider'] . "', " .
130 "'" . $_POST['form_pid'] . "', " .
131 "'" . $_POST['form_title'] . "', " .
133 "'" . $_POST['form_comments'] . "', " .
134 "'" . $_SESSION['authUserID'] . "', " .
135 "'" . fixDate($_POST['form_date']) . "', " .
136 "'" . fixDate($_POST['form_enddate']) . "', " .
137 "'" . ($duration * 60) . "', " .
138 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
142 "'" . $_POST['form_allday'] . "', " .
143 "'" . $_POST['form_apptstatus'] . "', " .
144 "'" . $_POST['form_prefcat'] . "', " .
145 "'$locationspec', " .
150 // Save new DOB if it's there.
151 $patient_dob = trim($_POST['form_dob']);
152 if ($patient_dob && $_POST['form_pid']) {
153 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
154 "pid = '" . $_POST['form_pid'] . "'");
158 else if ($_POST['form_delete']) {
159 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE " .
163 if ($_POST['form_save'] ||
$_POST['form_delete']) {
164 // Close this window and refresh the calendar display.
165 echo "<html>\n<body>\n<script language='JavaScript'>\n";
166 if ($info_msg) echo " alert('$info_msg');\n";
167 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
168 echo " window.close();\n";
169 echo "</script>\n</body>\n</html>\n";
173 // If we get this far then we are displaying the form.
177 '*' => '* Reminder done',
178 '+' => '+ Chart pulled',
181 '~' => '~ Arrived late',
182 '!' => '! Left w/o visit',
183 '#' => '# Ins/fin issue',
184 '<' => '< In exam room',
185 '>' => '> Checked out',
186 '$' => '$ Coding done',
189 $repeats = 0; // if the event repeats
193 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
194 $patientname = " (Click to select)";
199 // If we are editing an existing event, then get its data.
201 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
202 $date = $row['pc_eventDate'];
203 $userid = $row['pc_aid'];
204 $patientid = $row['pc_pid'];
205 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
206 $starttimem = substr($row['pc_startTime'], 3, 2);
207 $repeats = $row['pc_recurrtype'];
208 if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
209 $repeattype = $matches[1];
211 if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
212 $repeatfreq = $matches[1];
214 $hometext = $row['pc_hometext'];
215 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
218 // If we have a patient ID, get the name and phone numbers to display.
220 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
221 "FROM patient_data WHERE pid = '" . $patientid . "'");
222 $patientname = $prow['lname'] . ", " . $prow['fname'];
223 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
224 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
227 // Get the providers list.
228 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
229 "authorized != 0 ORDER BY lname, fname");
231 // Get event categories.
232 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
233 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
235 // Fix up the time format for AM/PM.
237 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
239 if ($starttimeh > 12) $starttimeh -= 12;
244 <title
><?
echo $eid ?
"Edit" : "Add New" ?
> Event
</title
>
245 <link rel
=stylesheet href
='<? echo $css_header ?>' type
='text/css'>
248 td
{ font
-size
:10pt
; }
251 <script type
="text/javascript" src
="../../../library/topdialog.js"></script
>
252 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
253 <script type
="text/javascript" src
="../../../library/overlib_mini.js"></script
>
254 <script type
="text/javascript" src
="../../../library/calendar.js"></script
>
255 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
257 <script language
="JavaScript">
259 var mypcc
= '<? echo $GLOBALS['phone_country_code
'] ?>';
261 var durations
= new Array();
262 // var rectypes = new Array();
264 // Read the event categories, generate their options list, and get
265 // the default event duration from them if this is a new event.
267 $prefcat_options = " <option value='0'>-- None --</option>\n";
270 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
272 while ($crow = sqlFetchArray($cres)) {
273 $duration = round($crow['pc_duration'] / 60);
274 if ($crow['pc_end_all_day']) $duration = 1440;
275 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
276 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
277 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
279 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
281 if ($crow['pc_catid'] == $default_catid) {
282 $catoptions .= " selected";
283 $thisduration = $duration;
286 $catoptions .= ">" . $crow['pc_catname'] . "</option>\n";
288 // This section is to build the list of preferred categories:
290 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
292 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
294 $prefcat_options .= ">" . $crow['pc_catname'] . "</option>\n";
300 // This is for callback by the find-patient popup.
301 function setpatient(pid
, lname
, fname
, dob
) {
302 var f
= document
.forms
[0];
303 f
.form_patient
.value
= lname +
', ' + fname
;
304 f
.form_pid
.value
= pid
;
305 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
306 document
.getElementById('dob_row').style
.display
= dobstyle
;
309 // This invokes the find-patient popup.
310 function sel_patient() {
311 dlgopen('find_patient_popup.php', '_blank', 500, 400);
314 // Do whatever is needed when a new event category is selected.
315 // For now this means changing the event title and duration.
316 function set_display() {
317 var f
= document
.forms
[0];
318 var s
= f
.form_category
;
319 if (s
.selectedIndex
>= 0) {
320 var catid
= s
.options
[s
.selectedIndex
].value
;
321 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
322 var style_prefcat
= document
.getElementById('title_prefcat').style
;
323 if (catid
== '2') { // In Office
324 style_apptstatus
.display
= 'none';
325 style_prefcat
.display
= '';
326 f
.form_apptstatus
.style
.display
= 'none';
327 f
.form_prefcat
.style
.display
= '';
329 style_prefcat
.display
= 'none';
330 style_apptstatus
.display
= '';
331 f
.form_prefcat
.style
.display
= 'none';
332 f
.form_apptstatus
.style
.display
= '';
337 // Do whatever is needed when a new event category is selected.
338 // For now this means changing the event title and duration.
339 function set_category() {
340 var f
= document
.forms
[0];
341 var s
= f
.form_category
;
342 if (s
.selectedIndex
>= 0) {
343 var catid
= s
.options
[s
.selectedIndex
].value
;
344 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
345 f
.form_duration
.value
= durations
[catid
];
350 // Modify some visual attributes when the all-day or timed-event
351 // radio buttons are clicked.
352 function set_allday() {
353 var f
= document
.forms
[0];
354 var color1
= '#777777';
355 var color2
= '#777777';
356 var disabled2
= true;
357 if (document
.getElementById('rballday1').checked
) {
360 if (document
.getElementById('rballday2').checked
) {
364 document
.getElementById('tdallday1').style
.color
= color1
;
365 document
.getElementById('tdallday2').style
.color
= color2
;
366 document
.getElementById('tdallday3').style
.color
= color2
;
367 document
.getElementById('tdallday4').style
.color
= color2
;
368 document
.getElementById('tdallday5').style
.color
= color2
;
369 f
.form_hour
.disabled
= disabled2
;
370 f
.form_minute
.disabled
= disabled2
;
371 f
.form_ampm
.disabled
= disabled2
;
372 f
.form_duration
.disabled
= disabled2
;
375 // Modify some visual attributes when the Repeat checkbox is clicked.
376 function set_repeat() {
377 var f
= document
.forms
[0];
378 var isdisabled
= true;
379 var mycolor
= '#777777';
380 var myvisibility
= 'hidden';
381 if (f
.form_repeat
.checked
) {
384 myvisibility
= 'visible';
386 f
.form_repeat_type
.disabled
= isdisabled
;
387 f
.form_repeat_freq
.disabled
= isdisabled
;
388 f
.form_enddate
.disabled
= isdisabled
;
389 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
390 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
391 document
.getElementById('imgrepeat').style
.visibility
= myvisibility
;
394 // This is for callback by the find-available popup.
395 function setappt(year
,mon
,mday
,hours
,minutes
) {
396 var f
= document
.forms
[0];
397 f
.form_date
.value
= '' + year +
'-' +
398 ('' +
(mon +
100)).substring(1) +
'-' +
399 ('' +
(mday +
100)).substring(1);
400 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
401 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
402 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
405 // Invoke the find-available popup.
406 function find_available() {
407 var s
= document
.forms
[0].form_provider
;
408 var c
= document
.forms
[0].form_category
;
409 dlgopen('find_appt_popup.php?providerid=' + s
.options
[s
.selectedIndex
].value +
410 '&catid=' + c
.options
[c
.selectedIndex
].value
, '_blank', 500, 400);
413 // Check for errors when the form is submitted.
414 function validate() {
415 var f
= document
.forms
[0];
416 if (f
.form_repeat
.checked
&&
417 (! f
.form_enddate
.value || f
.form_enddate
.value
< f
.form_date
.value
)) {
418 alert('An end date later than the start date is required for repeated events!');
428 <body
<?
echo $top_bg_line;?
> onunload
='imclosing()'>
430 <!-- Required
for the popup date selectors
-->
431 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
433 <form method
='post' name
='theform' action
='add_edit_event.php?eid=<? echo $eid ?>'
434 onsubmit
='return validate()'>
437 <table border
='0' width
='100%'>
440 <td width
='1%' nowrap
>
441 <b
><?
xl('Category','e'); ?
>:</b
>
444 <select name
='form_category' onchange
='set_category()' style
='width:100%'>
445 <?
echo $catoptions ?
>
448 <td width
='1%' nowrap
>
450 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='1' id
='rballday1'
451 <?
if ($thisduration == 1440) echo "checked " ?
>/>
453 <td colspan
='2' nowrap id
='tdallday1'>
454 <?
xl('All day event','e'); ?
>
460 <b
><?
xl('Date','e'); ?
>:</b
>
463 <input type
='text' size
='10' name
='form_date'
464 value
='<? echo $eid ? $row['pc_eventDate
'] : $date ?>'
465 title
='yyyy-mm-dd event date or starting date'
466 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
467 <a href
="javascript:show_calendar('theform.form_date')"
468 title
="Click here to choose a date"
469 ><img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22' border
='0' alt
='[?]'></a
>
473 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='0' id
='rballday2'
474 <?
if ($thisduration != 1440) echo "checked " ?
>/>
476 <td width
='1%' nowrap id
='tdallday2'>
477 <?
xl('Time','e'); ?
>
479 <td width
='1%' nowrap id
='tdallday3'>
480 <input type
='text' size
='2' name
='form_hour'
481 value
='<? echo $starttimeh ?>'
482 title
='Event start time' /> :
483 <input type
='text' size
='2' name
='form_minute'
484 value
='<? echo $starttimem ?>'
485 title
='Event start time' /> 
;
486 <select name
='form_ampm' title
='Note: 12:00 noon is PM, not AM'>
487 <option value
='1'>AM
</option
>
488 <option value
='2'<?
if ($startampm == '2') echo " selected" ?
>>PM
</option
>
495 <b
><?
xl('Title','e'); ?
>:</b
>
498 <input type
='text' size
='10' name
='form_title'
499 value
='<? echo addslashes($row['pc_title
']) ?>'
501 title
='Event title' />
506 <td nowrap id
='tdallday4'><?
xl('duration','e'); ?
>
508 <td nowrap id
='tdallday5'>
509 <input type
='text' size
='4' name
='form_duration' value
='<? echo $thisduration ?>'
510 title
='Event duration in minutes' /> <?
xl('minutes','e'); ?
>
516 <b
><?
xl('Patient','e'); ?
>:</b
>
519 <input type
='text' size
='10' name
='form_patient' style
='width:100%'
520 value
='<? echo $patientname ?>' onclick
='sel_patient()'
521 title
='Click to select patient' readonly
/>
522 <input type
='hidden' name
='form_pid' value
='<? echo $patientid ?>' />
524 <td colspan
='3' nowrap style
='font-size:8pt'>
525  
;<?
echo $patienttitle ?
>
531 <b
><?
xl('Provider','e'); ?
>:</b
>
534 <select name
='form_provider' style
='width:100%'>
536 while ($urow = sqlFetchArray($ures)) {
537 echo " <option value='" . $urow['id'] . "'";
539 if ($urow['id'] == $userid) echo " selected";
541 if ($urow['id'] == $_SESSION['authUserID']) echo " selected";
543 echo ">" . $urow['lname'];
544 if ($urow['fname']) echo ", " . $urow['fname'];
552 <input type
='checkbox' name
='form_repeat' onclick
='set_repeat(this)'
553 value
='1'<?
if ($repeats) echo " checked" ?
>/>
555 <td nowrap id
='tdrepeat1'><?
xl('Repeats','e'); ?
>
559 <select name
='form_repeat_freq' title
='Every, every other, every 3rd, etc.'>
561 foreach (array(1 => 'every', 2 => '2nd', 3 => '3rd', 4 => '4th', 5 => '5th', 6 => '6th')
564 echo " <option value='$key'";
565 if ($key == $repeatfreq) echo " selected";
566 echo ">$value</option>\n";
571 <select name
='form_repeat_type'>
573 // See common.api.php for these:
574 foreach (array(0 => 'day' , 4 => 'workday', 1 => 'week', 2 => 'month', 3 => 'year')
577 echo " <option value='$key'";
578 if ($key == $repeattype) echo " selected";
579 echo ">$value</option>\n";
589 <span id
='title_apptstatus'><b
><?
xl('Status','e'); ?
>:</b
></span
>
590 <span id
='title_prefcat' style
='display:none'><b
><?
xl('Pref Cat','e'); ?
>:</b
></span
>
594 <select name
='form_apptstatus' style
='width:100%' title
='Appointment status'>
596 foreach ($statuses as $key => $value) {
597 echo " <option value='$key'";
598 if ($key == $row['pc_apptstatus']) echo " selected";
599 echo ">" . htmlspecialchars($value) . "</option>\n";
604 The following
list will be invisible unless this is an In Office
605 event
, in which
case form_apptstatus (above
) is to be invisible
.
607 <select name
='form_prefcat' style
='width:100%;display:none' title
='Preferred Event Category'>
608 <?
echo $prefcat_options ?
>
615 <td nowrap id
='tdrepeat2'><?
xl('until','e'); ?
>
618 <input type
='text' size
='10' name
='form_enddate' value
='<? echo $row['pc_endDate
'] ?>'
619 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
620 title
='yyyy-mm-dd last date of this event' />
621 <a href
="javascript:show_calendar('theform.form_enddate')"
622 title
="Click here to choose a date"
623 ><img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
624 border
='0' alt
='[?]' id
='imgrepeat' /></a
>
630 <b
><?
xl('Comments','e'); ?
>:</b
>
632 <td colspan
='4' nowrap
>
633 <input type
='text' size
='40' name
='form_comments' style
='width:100%'
634 value
='<? echo $hometext ?>'
635 title
='Optional information about this event' />
640 // DOB is important for the clinic, so if it's missing give them a chance
641 // to enter it right here. We must display or hide this row dynamically
642 // in case the patient-select popup is used.
643 $patient_dob = trim($prow['DOB']);
644 $dobstyle = ($prow && (!$patient_dob ||
substr($patient_dob, 5) == '00-00')) ?
647 <tr id
='dob_row' style
='display:<?php echo $dobstyle ?>'>
648 <td colspan
='4' nowrap
>
649 <b
><font color
='red'><?
xl('DOB is missing, please enter if possible','e'); ?
>:</font
></b
>
652 <input type
='text' size
='10' name
='form_dob'
653 title
='yyyy-mm-dd date of birth'
654 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
655 <a href
="javascript:show_calendar('theform.form_dob')"
656 title
="Click here to choose a date"
657 ><img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22' border
='0' alt
='[?]'></a
>
664 <input type
='submit' name
='form_save' value
='Save' />
666 <input type
='button' value
='Find Available' onclick
='find_available()' />
668 <input type
='submit' name
='form_delete' value
='Delete'<?
if (!$eid) echo " disabled" ?
> />
670 <input type
='button' value
='Cancel' onclick
='window.close()' />
674 <script language
='JavaScript'>