2 // Copyright (C) 2005 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 Date ___:___ __V //
14 // Title ___________________ Duration ____ minutes //
15 // Provider __________________V X Repeats _____________V //
16 // Patient ___________________ Until ___________ [?] //
17 // Comments ________________________________________________ //
19 // [Save] [Find Available] [Delete] [Cancel] //
20 //------------------------------------------------------------//
22 include_once("../../globals.php");
23 include_once("$srcdir/patient.inc");
25 // Things that might be passed by our opener.
27 $eid = $_GET['eid']; // only for existing events
28 $date = $_GET['date']; // this and below only for new events
29 $userid = $_GET['userid'];
32 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
34 $date = date("Y-m-d");
37 if (isset($_GET['starttimem']))
38 $starttimem = substr('00' . $_GET['starttimem'], -2);
40 if (isset($_GET['starttimeh'])) {
41 $starttimeh = $_GET['starttimeh'];
42 if (isset($_GET['startampm'])) {
43 if ($_GET['startampm'] == '2' && $starttimeh < 12)
47 $starttimeh = date("G");
53 // If we are saving, then save and close the window.
55 if ($_POST['form_save']) {
57 // Compute start and end time strings to be saved.
58 if ($_POST['form_allday']) {
63 $tmph = $_POST['form_hour'] +
0;
64 $tmpm = $_POST['form_minute'] +
0;
65 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph +
= 12;
66 $duration = $_POST['form_duration'];
68 $starttime = "$tmph:$tmpm:00";
75 $endtime = "$tmph:$tmpm:00";
77 // Useless garbage that we must save.
78 $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' .
79 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}';
81 // More garbage, but this time 1 character of it is used to save the
83 if ($_POST['form_repeat']) {
84 $recurrspec = 'a:5:{' .
85 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' .
86 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' .
87 's:19:"event_repeat_on_num";s:1:"1";' .
88 's:19:"event_repeat_on_day";s:1:"0";' .
89 's:20:"event_repeat_on_freq";s:1:"0";}';
91 $recurrspec = 'a:5:{' .
92 's:17:"event_repeat_freq";N;' .
93 's:22:"event_repeat_freq_type";s:1:"0";' .
94 's:19:"event_repeat_on_num";s:1:"1";' .
95 's:19:"event_repeat_on_day";s:1:"0";' .
96 's:20:"event_repeat_on_freq";s:1:"1";}';
100 sqlStatement("UPDATE openemr_postcalendar_events SET " .
101 "pc_catid = '" . $_POST['form_category'] . "', " .
102 "pc_aid = '" . $_POST['form_provider'] . "', " .
103 "pc_pid = '" . $_POST['form_pid'] . "', " .
104 "pc_title = '" . $_POST['form_title'] . "', " .
105 "pc_time = NOW(), " .
106 "pc_hometext = '" . $_POST['form_comments'] . "', " .
107 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
108 "pc_eventDate = '" . fixDate($_POST['form_date']) . "', " .
109 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
110 "pc_duration = '" . ($duration * 60) . "', " .
111 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
112 "pc_recurrspec = '$recurrspec', " .
113 "pc_startTime = '$starttime', " .
114 "pc_endTime = '$endtime', " .
115 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
116 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "' " .
117 "WHERE pc_eid = '$eid'");
119 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
120 "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
121 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
122 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
123 "pc_apptstatus, pc_location, pc_eventstatus, pc_sharing " .
125 "'" . $_POST['form_category'] . "', " .
126 "'" . $_POST['form_provider'] . "', " .
127 "'" . $_POST['form_pid'] . "', " .
128 "'" . $_POST['form_title'] . "', " .
130 "'" . $_POST['form_comments'] . "', " .
131 "'" . $_SESSION['authUserID'] . "', " .
132 "'" . fixDate($_POST['form_date']) . "', " .
133 "'" . fixDate($_POST['form_enddate']) . "', " .
134 "'" . ($duration * 60) . "', " .
135 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
139 "'" . $_POST['form_allday'] . "', " .
140 "'" . $_POST['form_apptstatus'] . "', " .
141 "'$locationspec', " .
146 else if ($_POST['form_delete']) {
147 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE " .
151 if ($_POST['form_save'] ||
$_POST['form_delete']) {
152 // Close this window and refresh the calendar display.
153 echo "<html>\n<body>\n<script language='JavaScript'>\n";
154 if ($info_msg) echo " alert('$info_msg');\n";
155 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
156 echo " window.close();\n";
157 echo "</script>\n</body>\n</html>\n";
161 // If we get this far then we are displaying the form.
165 '*' => '* Reminder done',
166 '+' => '+ Chart pulled',
169 '~' => '~ Arrived late',
170 '!' => '! Left w/o visit',
171 '#' => '# Ins/fin issue',
172 '<' => '< In exam room',
173 '>' => '> Checked out',
174 '$' => '$ Coding done',
177 $repeats = 0; // if the event repeats
181 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
182 $patientname = " (Click to select)";
187 // If we are editing an existing event, then get its data.
189 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
190 $date = $row['pc_eventDate'];
191 $userid = $row['pc_aid'];
192 $patientid = $row['pc_pid'];
193 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
194 $starttimem = substr($row['pc_startTime'], 3, 2);
195 $repeats = $row['pc_recurrtype'];
196 if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
197 $repeattype = $matches[1];
199 if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
200 $repeatfreq = $matches[1];
202 $hometext = $row['pc_hometext'];
203 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
206 // If we have a patient ID, get the name and phone numbers to display.
208 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz " .
209 "FROM patient_data WHERE pid = '" . $patientid . "'");
210 $patientname = $prow['lname'] . ", " . $prow['fname'];
211 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
212 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
215 // Get the providers list.
216 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
217 "authorized != 0 ORDER BY lname, fname");
219 // Get event categories.
220 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
221 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
223 // Fix up the time format for AM/PM.
225 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
227 if ($starttimeh > 12) $starttimeh -= 12;
232 <title
><?
echo $eid ?
"Edit" : "Add New" ?
> Event
</title
>
233 <link rel
=stylesheet href
='<? echo $css_header ?>' type
='text/css'>
236 td
{ font
-size
:10pt
; }
239 <script type
="text/javascript" src
="../../../library/topdialog.js"></script
>
240 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
241 <script type
="text/javascript" src
="../../../library/overlib_mini.js"></script
>
242 <script type
="text/javascript" src
="../../../library/calendar.js"></script
>
243 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
245 <script language
="JavaScript">
247 var mypcc
= '<? echo $GLOBALS['phone_country_code
'] ?>';
249 var durations
= new Array();
250 // var rectypes = new Array();
252 // Read the event categories, generate their options list, and get
253 // the default event duration from them if this is a new event.
257 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
259 while ($crow = sqlFetchArray($cres)) {
260 $duration = round($crow['pc_duration'] / 60);
261 if ($crow['pc_end_all_day']) $duration = 1440;
262 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
263 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
264 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
266 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
268 if ($crow['pc_catid'] == '5') { // office visit
269 $catoptions .= " selected";
270 $thisduration = $duration;
273 $catoptions .= ">" . $crow['pc_catname'] . "</option>\n";
277 // This is for callback by the find-patient popup.
278 function setpatient(pid
, lname
, fname
) {
279 var f
= document
.forms
[0];
280 f
.form_patient
.value
= lname +
', ' + fname
;
281 f
.form_pid
.value
= pid
;
284 // This invokes the find-patient popup.
285 function sel_patient() {
286 dlgopen('find_patient_popup.php', '_blank', 500, 400);
289 // Do whatever is needed when a new event category is selected.
290 // For now this means changing the event title and duration.
291 function set_category() {
292 var f
= document
.forms
[0];
293 var s
= f
.form_category
;
294 if (s
.selectedIndex
>= 0) {
295 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
296 f
.form_duration
.value
= durations
[s
.options
[s
.selectedIndex
].value
];
300 // Modify some visual attributes when the all-day or timed-event
301 // radio buttons are clicked.
302 function set_allday() {
303 var f
= document
.forms
[0];
304 var color1
= '#777777';
305 var color2
= '#777777';
306 var disabled2
= true;
307 if (document
.getElementById('rballday1').checked
) {
310 if (document
.getElementById('rballday2').checked
) {
314 document
.getElementById('tdallday1').style
.color
= color1
;
315 document
.getElementById('tdallday2').style
.color
= color2
;
316 document
.getElementById('tdallday3').style
.color
= color2
;
317 document
.getElementById('tdallday4').style
.color
= color2
;
318 document
.getElementById('tdallday5').style
.color
= color2
;
319 f
.form_hour
.disabled
= disabled2
;
320 f
.form_minute
.disabled
= disabled2
;
321 f
.form_ampm
.disabled
= disabled2
;
322 f
.form_duration
.disabled
= disabled2
;
325 // Modify some visual attributes when the Repeat checkbox is clicked.
326 function set_repeat() {
327 var f
= document
.forms
[0];
328 var isdisabled
= true;
329 var mycolor
= '#777777';
330 var myvisibility
= 'hidden';
331 if (f
.form_repeat
.checked
) {
334 myvisibility
= 'visible';
336 f
.form_repeat_type
.disabled
= isdisabled
;
337 f
.form_repeat_freq
.disabled
= isdisabled
;
338 f
.form_enddate
.disabled
= isdisabled
;
339 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
340 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
341 document
.getElementById('imgrepeat').style
.visibility
= myvisibility
;
344 // This is for callback by the find-available popup.
345 function setappt(year
,mon
,mday
,hours
,minutes
) {
346 var f
= document
.forms
[0];
347 f
.form_date
.value
= '' + year +
'-' +
348 ('' +
(mon +
100)).substring(1) +
'-' +
349 ('' +
(mday +
100)).substring(1);
350 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
351 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
352 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
355 // Invoke the find-available popup.
356 function find_available() {
357 var s
= document
.forms
[0].form_provider
;
358 dlgopen('find_appt_popup.php?providerid=' + s
.options
[s
.selectedIndex
].value
,
366 <body
<?
echo $top_bg_line;?
> onunload
='imclosing()'>
368 <!-- Required
for the popup date selectors
-->
369 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
371 <form method
='post' name
='theform' action
='add_edit_event.php?eid=<? echo $eid ?>'>
374 <table border
='0' width
='100%'>
377 <td width
='1%' nowrap
>
381 <select name
='form_category' onchange
='set_category()' style
='width:100%'>
382 <?
echo $catoptions ?
>
385 <td width
='1%' nowrap
>
387 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='1' id
='rballday1'
388 <?
if ($thisduration == 1440) echo "checked " ?
>/>
390 <td colspan
='2' nowrap id
='tdallday1'>
400 <input type
='text' size
='10' name
='form_date'
401 value
='<? echo $eid ? $row['pc_eventDate
'] : $date ?>'
402 title
='yyyy-mm-dd event date or starting date'
403 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
404 <a href
="javascript:show_calendar('theform.form_date')"
405 title
="Click here to choose a date"
406 ><img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22' border
='0' alt
='[?]'></a
>
410 <input type
='radio' name
='form_allday' onclick
='set_allday()' value
='0' id
='rballday2'
411 <?
if ($thisduration != 1440) echo "checked " ?
>/>
413 <td width
='1%' nowrap id
='tdallday2'>
416 <td width
='1%' nowrap id
='tdallday3'>
417 <input type
='text' size
='2' name
='form_hour'
418 value
='<? echo $starttimeh ?>'
419 title
='Event start time' /> :
420 <input type
='text' size
='2' name
='form_minute'
421 value
='<? echo $starttimem ?>'
422 title
='Event start time' /> 
;
423 <select name
='form_ampm' title
='Note: 12:00 noon is PM, not AM'>
424 <option value
='1'>AM
</option
>
425 <option value
='2'<?
if ($startampm == '2') echo " selected" ?
>>PM
</option
>
435 <input type
='text' size
='10' name
='form_title'
436 value
='<? echo addslashes($row['pc_title
']) ?>'
438 title
='Event title' />
443 <td nowrap id
='tdallday4'>
446 <td nowrap id
='tdallday5'>
447 <input type
='text' size
='4' name
='form_duration' value
='<? echo $thisduration ?>'
448 title
='Event duration in minutes' /> minutes
457 <input type
='text' size
='10' name
='form_patient' style
='width:100%'
458 value
='<? echo $patientname ?>' onclick
='sel_patient()'
459 title
='Click to select patient' readonly
/>
460 <input type
='hidden' name
='form_pid' value
='<? echo $patientid ?>' />
462 <td colspan
='3' nowrap style
='font-size:8pt'>
463  
;<?
echo $patienttitle ?
>
472 <select name
='form_provider' style
='width:100%'>
474 while ($urow = sqlFetchArray($ures)) {
475 echo " <option value='" . $urow['id'] . "'";
477 if ($urow['id'] == $userid) echo " selected";
479 if ($urow['id'] == $_SESSION['authUserID']) echo " selected";
481 echo ">" . $urow['lname'];
482 if ($urow['fname']) echo ", " . $urow['fname'];
490 <input type
='checkbox' name
='form_repeat' onclick
='set_repeat(this)'
491 value
='1'<?
if ($repeats) echo " checked" ?
>/>
493 <td nowrap id
='tdrepeat1'>
498 <select name
='form_repeat_freq' title
='Every, every other, every 3rd, etc.'>
500 foreach (array(1 => 'every', 2 => '2nd', 3 => '3rd', 4 => '4th', 5 => '5th', 6 => '6th')
503 echo " <option value='$key'";
504 if ($key == $repeatfreq) echo " selected";
505 echo ">$value</option>\n";
510 <select name
='form_repeat_type'>
512 // See common.api.php for these:
513 foreach (array(0 => 'day', 4 => 'workday', 1 => 'week', 2 => 'month', 3 => 'year')
516 echo " <option value='$key'";
517 if ($key == $repeattype) echo " selected";
518 echo ">$value</option>\n";
531 <select name
='form_apptstatus' style
='width:100%' title
='Appointment status'>
533 foreach ($statuses as $key => $value) {
534 echo " <option value='$key'";
535 if ($key == $row['pc_apptstatus']) echo " selected";
536 echo ">" . htmlspecialchars($value) . "</option>\n";
544 <td nowrap id
='tdrepeat2'>
548 <input type
='text' size
='10' name
='form_enddate' value
='<? echo $row['pc_endDate
'] ?>'
549 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
550 title
='yyyy-mm-dd last date of this event' />
551 <a href
="javascript:show_calendar('theform.form_enddate')"
552 title
="Click here to choose a date"
553 ><img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
554 border
='0' alt
='[?]' id
='imgrepeat' /></a
>
562 <td colspan
='4' nowrap
>
563 <input type
='text' size
='40' name
='form_comments' style
='width:100%'
564 value
='<? echo $hometext ?>'
565 title
='Optional information about this event' />
572 <input type
='submit' name
='form_save' value
='Save' />
574 <input type
='button' value
='Find Available' onclick
='find_available()' />
576 <input type
='submit' name
='form_delete' value
='Delete'<?
if (!$eid) echo " disabled" ?
> />
578 <input type
='button' value
='Cancel' onclick
='window.close()' />
582 <script language
='JavaScript'>