Fix a nasty bug; avoid 0 value for pc_multiple field.
[openemr.git] / interface / main / calendar / add_edit_event.php
blobd1c8b6af1671dcef9747c4d9806e5b4051558ff6
1 <?
2 // Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
3 //
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 ________________________________________________ //
19 // //
20 // [Save] [Find Available] [Delete] [Cancel] //
21 //------------------------------------------------------------//
23 include_once("../../globals.php");
24 include_once("$srcdir/patient.inc");
25 include_once("$srcdir/forms.inc");
27 // Things that might be passed by our opener.
29 $eid = $_GET['eid']; // only for existing events
30 $date = $_GET['date']; // this and below only for new events
31 $userid = $_GET['userid'];
32 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
34 if ($date)
35 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
36 else
37 $date = date("Y-m-d");
39 $starttimem = '00';
40 if (isset($_GET['starttimem']))
41 $starttimem = substr('00' . $_GET['starttimem'], -2);
43 if (isset($_GET['starttimeh'])) {
44 $starttimeh = $_GET['starttimeh'];
45 if (isset($_GET['startampm'])) {
46 if ($_GET['startampm'] == '2' && $starttimeh < 12)
47 $starttimeh += 12;
49 } else {
50 $starttimeh = date("G");
52 $startampm = '';
54 $info_msg = "";
56 // If we are saving, then save and close the window.
58 if ($_POST['form_save']) {
60 $event_date = fixDate($_POST['form_date']);
62 // Compute start and end time strings to be saved.
63 if ($_POST['form_allday']) {
64 $tmph = 0;
65 $tmpm = 0;
66 $duration = 24 * 60;
67 } else {
68 $tmph = $_POST['form_hour'] + 0;
69 $tmpm = $_POST['form_minute'] + 0;
70 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph += 12;
71 $duration = $_POST['form_duration'];
73 $starttime = "$tmph:$tmpm:00";
75 $tmpm += $duration;
76 while ($tmpm >= 60) {
77 $tmpm -= 60;
78 ++$tmph;
80 $endtime = "$tmph:$tmpm:00";
82 // Useless garbage that we must save.
83 $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' .
84 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}';
86 // More garbage, but this time 1 character of it is used to save the
87 // repeat type.
88 if ($_POST['form_repeat']) {
89 $recurrspec = 'a:5:{' .
90 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' .
91 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' .
92 's:19:"event_repeat_on_num";s:1:"1";' .
93 's:19:"event_repeat_on_day";s:1:"0";' .
94 's:20:"event_repeat_on_freq";s:1:"0";}';
95 } else {
96 $recurrspec = 'a:5:{' .
97 's:17:"event_repeat_freq";N;' .
98 's:22:"event_repeat_freq_type";s:1:"0";' .
99 's:19:"event_repeat_on_num";s:1:"1";' .
100 's:19:"event_repeat_on_day";s:1:"0";' .
101 's:20:"event_repeat_on_freq";s:1:"1";}';
104 /* =======================================================
105 // UPDATE EVENTS
106 ========================================================*/
107 if ($eid) {
108 if ($GLOBALS['select_multi_providers']) {
109 /* ==========================================
110 // multi providers BOS
111 ==========================================*/
113 // what is multiple key around this $eid?
114 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
116 // we make sure that we don't get a 0 result (0 is the default value for pc_multiple field)
117 if ( $row['pc_multiple'] ) {
119 // obtain current list of providers regarding the multiple key
120 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
121 while ($current = sqlFetchArray($up)) {
122 $providers_current[] = $current['pc_aid'];
125 $providers_new = $_POST['form_provider'];
127 // this difference means that some providers from current was UNCHECKED
128 // so we must delete this event for them
129 $r1 = array_diff ($providers_current, $providers_new);
130 if (count ($r1)) {
131 foreach ($r1 as $to_be_removed) {
132 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
136 // this difference means that some providers was added
137 // so we must insert this event for them
138 $r2 = array_diff ($providers_new, $providers_current);
139 if (count ($r2)) {
140 foreach ($r2 as $to_be_inserted) {
141 sqlInsert("INSERT INTO openemr_postcalendar_events ( pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing)
142 VALUES ( " .
143 "'" . $_POST['form_category'] . "', " .
144 "'" . $row['pc_multiple'] . "', " .
145 "'" . $to_be_inserted . "', " .
146 "'" . $_POST['form_pid'] . "', " .
147 "'" . $_POST['form_title'] . "', " .
148 "NOW(), " .
149 "'" . $_POST['form_comments'] . "', " .
150 "'" . $_SESSION['authUserID'] . "', " .
151 "'" . $event_date . "', " .
152 "'" . fixDate($_POST['form_enddate']) . "', " .
153 "'" . ($duration * 60) . "', " .
154 "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
155 "'$recurrspec', " .
156 "'$starttime', " .
157 "'$endtime', " .
158 "'" . $_POST['form_allday'] . "', " .
159 "'" . $_POST['form_apptstatus'] . "', " .
160 "'" . $_POST['form_prefcat'] . "', " .
161 "'$locationspec', " .
162 "1, " .
163 "1 )");
164 } // foreach
168 // after the two diffs above, we must update for remaining providers
169 // those who are intersected in $providers_current and $providers_new
170 foreach ($_POST['form_provider'] as $provider) {
171 sqlStatement("UPDATE openemr_postcalendar_events SET " .
172 "pc_catid = '" . $_POST['form_category'] . "', " .
173 "pc_pid = '" . $_POST['form_pid'] . "', " .
174 "pc_title = '" . $_POST['form_title'] . "', " .
175 "pc_time = NOW(), " .
176 "pc_hometext = '" . $_POST['form_comments'] . "', " .
177 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
178 "pc_eventDate = '" . $event_date . "', " .
179 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
180 "pc_duration = '" . ($duration * 60) . "', " .
181 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
182 "pc_recurrspec = '$recurrspec', " .
183 "pc_startTime = '$starttime', " .
184 "pc_endTime = '$endtime', " .
185 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
186 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
187 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' " .
188 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
189 } // foreach
190 } // if ( $row['pc_multiple'] )
191 /* ==========================================
192 // multi providers EOS
193 ==========================================*/
195 } else {
196 // simple provider case
197 sqlStatement("UPDATE openemr_postcalendar_events SET " .
198 "pc_catid = '" . $_POST['form_category'] . "', " .
199 "pc_aid = '" . $_POST['form_provider'] . "', " .
200 "pc_pid = '" . $_POST['form_pid'] . "', " .
201 "pc_title = '" . $_POST['form_title'] . "', " .
202 "pc_time = NOW(), " .
203 "pc_hometext = '" . $_POST['form_comments'] . "', " .
204 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
205 "pc_eventDate = '" . $event_date . "', " .
206 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
207 "pc_duration = '" . ($duration * 60) . "', " .
208 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
209 "pc_recurrspec = '$recurrspec', " .
210 "pc_startTime = '$starttime', " .
211 "pc_endTime = '$endtime', " .
212 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
213 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
214 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' " .
215 "WHERE pc_eid = '$eid'");
218 } else {
220 // =======================================
221 // multi providers case
222 // =======================================
224 if (is_array($_POST['form_provider'])) {
226 // obtain the next available unique key to group multiple providers around some event
227 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
228 $max = sqlFetchArray($q);
229 $new_multiple_value = $max['max'] + 1;
231 foreach ($_POST['form_provider'] as $provider) {
232 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
233 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
234 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
235 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
236 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing " .
237 ") VALUES ( " .
238 "'" . $_POST['form_category'] . "', " .
239 "'" . $new_multiple_value . "', " .
240 "'" . $provider . "', " .
241 "'" . $_POST['form_pid'] . "', " .
242 "'" . $_POST['form_title'] . "', " .
243 "NOW(), " .
244 "'" . $_POST['form_comments'] . "', " .
245 "'" . $_SESSION['authUserID'] . "', " .
246 "'" . $event_date . "', " .
247 "'" . fixDate($_POST['form_enddate']) . "', " .
248 "'" . ($duration * 60) . "', " .
249 "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
250 "'$recurrspec', " .
251 "'$starttime', " .
252 "'$endtime', " .
253 "'" . $_POST['form_allday'] . "', " .
254 "'" . $_POST['form_apptstatus'] . "', " .
255 "'" . $_POST['form_prefcat'] . "', " .
256 "'$locationspec', " .
257 "1, " .
258 "1 )");
260 } // foreach
262 // =======================================
263 // EOS multi providers case
264 // =======================================
266 } else {
267 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
268 "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
269 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
270 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
271 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing " .
272 ") VALUES ( " .
273 "'" . $_POST['form_category'] . "', " .
274 "'" . $_POST['form_provider'] . "', " .
275 "'" . $_POST['form_pid'] . "', " .
276 "'" . $_POST['form_title'] . "', " .
277 "NOW(), " .
278 "'" . $_POST['form_comments'] . "', " .
279 "'" . $_SESSION['authUserID'] . "', " .
280 "'" . $event_date . "', " .
281 "'" . fixDate($_POST['form_enddate']) . "', " .
282 "'" . ($duration * 60) . "', " .
283 "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
284 "'$recurrspec', " .
285 "'$starttime', " .
286 "'$endtime', " .
287 "'" . $_POST['form_allday'] . "', " .
288 "'" . $_POST['form_apptstatus'] . "', " .
289 "'" . $_POST['form_prefcat'] . "', " .
290 "'$locationspec', " .
291 "1, " .
292 "1 )");
297 // Save new DOB if it's there.
298 $patient_dob = trim($_POST['form_dob']);
299 if ($patient_dob && $_POST['form_pid']) {
300 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
301 "pid = '" . $_POST['form_pid'] . "'");
304 // Auto-create a new encounter if appropriate.
306 if ($GLOBALS['auto_create_new_encounters'] &&
307 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
309 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
310 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
311 if ($tmprow['count'] == 0) {
312 $tmprow = sqlQuery("SELECT username, facility FROM users WHERE id = '" .
313 $_POST['form_provider'] . "'");
314 $username = $tmprow['username'];
315 $facility = $tmprow['facility'];
316 $conn = $GLOBALS['adodb']['db'];
317 $encounter = $conn->GenID("sequences");
318 addForm($encounter, "New Patient Encounter",
319 sqlInsert("INSERT INTO form_encounter SET " .
320 "date = '$event_date', " .
321 "onset_date = '$event_date', " .
322 "reason = '" . $_POST['form_comments'] . "', " .
323 "facility = '$facility', " .
324 "pid = '" . $_POST['form_pid'] . "', " .
325 "encounter = '$encounter'"
327 "newpatient", $_POST['form_pid'], "1", "NOW()", $username
329 $info_msg .= "New encounter $encounter was created. ";
334 else if ($_POST['form_delete']) {
335 // =======================================
336 // multi providers case
337 // =======================================
338 if ($GLOBALS['select_multi_providers']) {
339 // what is multiple key around this $eid?
340 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
341 if ( $row['pc_multiple'] ) {
342 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_multiple = {$row['pc_multiple']}");
344 // =======================================
345 // EOS multi providers case
346 // =======================================
347 } else {
348 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
352 if ($_POST['form_save'] || $_POST['form_delete']) {
353 // Close this window and refresh the calendar display.
354 echo "<html>\n<body>\n<script language='JavaScript'>\n";
355 if ($info_msg) echo " alert('$info_msg');\n";
356 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
357 echo " window.close();\n";
358 echo "</script>\n</body>\n</html>\n";
359 exit();
362 // If we get this far then we are displaying the form.
364 $statuses = array(
365 '-' => '',
366 '*' => xl('* Reminder done'),
367 '+' => xl('+ Chart pulled'),
368 '?' => xl('? No show'),
369 '@' => xl('@ Arrived'),
370 '~' => xl('~ Arrived late'),
371 '!' => xl('! Left w/o visit'),
372 '#' => xl('# Ins/fin issue'),
373 '<' => xl('< In exam room'),
374 '>' => xl('> Checked out'),
375 '$' => xl('$ Coding done'),
378 $repeats = 0; // if the event repeats
379 $repeattype = '0';
380 $repeatfreq = '0';
381 $patientid = '';
382 if ($_REQUEST['patientid']) $patientid = $_REQUEST['patientid'];
383 $patientname = xl('Click to select');
384 $patienttitle = "";
385 $hometext = "";
386 $row = array();
388 // If we are editing an existing event, then get its data.
389 if ($eid) {
390 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
391 $date = $row['pc_eventDate'];
392 $userid = $row['pc_aid'];
393 $patientid = $row['pc_pid'];
394 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
395 $starttimem = substr($row['pc_startTime'], 3, 2);
396 $repeats = $row['pc_recurrtype'];
397 $multiple_value = $row['pc_multiple'];
399 if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
400 $repeattype = $matches[1];
402 if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
403 $repeatfreq = $matches[1];
405 $hometext = $row['pc_hometext'];
406 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
409 // If we have a patient ID, get the name and phone numbers to display.
410 if ($patientid) {
411 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
412 "FROM patient_data WHERE pid = '" . $patientid . "'");
413 $patientname = $prow['lname'] . ", " . $prow['fname'];
414 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
415 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
418 // Get the providers list.
419 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
420 "authorized != 0 AND active = 1 ORDER BY lname, fname");
422 // Get event categories.
423 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
424 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
426 // Fix up the time format for AM/PM.
427 $startampm = '1';
428 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
429 $startampm = '2';
430 if ($starttimeh > 12) $starttimeh -= 12;
433 <html>
434 <head>
435 <title><? echo $eid ? "Edit" : "Add New" ?> <?php xl('Event','e');?></title>
436 <link rel=stylesheet href='<? echo $css_header ?>' type='text/css'>
438 <style>
439 td { font-size:10pt; }
440 </style>
442 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
443 <script type="text/javascript" src="../../../library/topdialog.js"></script>
444 <script type="text/javascript" src="../../../library/dialog.js"></script>
445 <script type="text/javascript" src="../../../library/textformat.js"></script>
446 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
447 <script type="text/javascript" src="../../../library/dynarch_calendar_en.js"></script>
448 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
450 <script language="JavaScript">
452 var mypcc = '<? echo $GLOBALS['phone_country_code'] ?>';
454 var durations = new Array();
455 // var rectypes = new Array();
457 // Read the event categories, generate their options list, and get
458 // the default event duration from them if this is a new event.
459 $catoptions = "";
460 $prefcat_options = " <option value='0'>-- None --</option>\n";
461 $thisduration = 0;
462 if ($eid) {
463 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
465 while ($crow = sqlFetchArray($cres)) {
466 $duration = round($crow['pc_duration'] / 60);
467 if ($crow['pc_end_all_day']) $duration = 1440;
468 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
469 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
470 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
471 if ($eid) {
472 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
473 } else {
474 if ($crow['pc_catid'] == $default_catid) {
475 $catoptions .= " selected";
476 $thisduration = $duration;
479 $catoptions .= ">" . $crow['pc_catname'] . "</option>\n";
481 // This section is to build the list of preferred categories:
482 if ($duration) {
483 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
484 if ($eid) {
485 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
487 $prefcat_options .= ">" . $crow['pc_catname'] . "</option>\n";
493 // This is for callback by the find-patient popup.
494 function setpatient(pid, lname, fname, dob) {
495 var f = document.forms[0];
496 f.form_patient.value = lname + ', ' + fname;
497 f.form_pid.value = pid;
498 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
499 document.getElementById('dob_row').style.display = dobstyle;
502 // This invokes the find-patient popup.
503 function sel_patient() {
504 dlgopen('find_patient_popup.php', '_blank', 500, 400);
507 // Do whatever is needed when a new event category is selected.
508 // For now this means changing the event title and duration.
509 function set_display() {
510 var f = document.forms[0];
511 var s = f.form_category;
512 if (s.selectedIndex >= 0) {
513 var catid = s.options[s.selectedIndex].value;
514 var style_apptstatus = document.getElementById('title_apptstatus').style;
515 var style_prefcat = document.getElementById('title_prefcat').style;
516 if (catid == '2') { // In Office
517 style_apptstatus.display = 'none';
518 style_prefcat.display = '';
519 f.form_apptstatus.style.display = 'none';
520 f.form_prefcat.style.display = '';
521 } else {
522 style_prefcat.display = 'none';
523 style_apptstatus.display = '';
524 f.form_prefcat.style.display = 'none';
525 f.form_apptstatus.style.display = '';
530 // Do whatever is needed when a new event category is selected.
531 // For now this means changing the event title and duration.
532 function set_category() {
533 var f = document.forms[0];
534 var s = f.form_category;
535 if (s.selectedIndex >= 0) {
536 var catid = s.options[s.selectedIndex].value;
537 f.form_title.value = s.options[s.selectedIndex].text;
538 f.form_duration.value = durations[catid];
539 set_display();
543 // Modify some visual attributes when the all-day or timed-event
544 // radio buttons are clicked.
545 function set_allday() {
546 var f = document.forms[0];
547 var color1 = '#777777';
548 var color2 = '#777777';
549 var disabled2 = true;
550 if (document.getElementById('rballday1').checked) {
551 color1 = '#000000';
553 if (document.getElementById('rballday2').checked) {
554 color2 = '#000000';
555 disabled2 = false;
557 document.getElementById('tdallday1').style.color = color1;
558 document.getElementById('tdallday2').style.color = color2;
559 document.getElementById('tdallday3').style.color = color2;
560 document.getElementById('tdallday4').style.color = color2;
561 document.getElementById('tdallday5').style.color = color2;
562 f.form_hour.disabled = disabled2;
563 f.form_minute.disabled = disabled2;
564 f.form_ampm.disabled = disabled2;
565 f.form_duration.disabled = disabled2;
568 // Modify some visual attributes when the Repeat checkbox is clicked.
569 function set_repeat() {
570 var f = document.forms[0];
571 var isdisabled = true;
572 var mycolor = '#777777';
573 var myvisibility = 'hidden';
574 if (f.form_repeat.checked) {
575 isdisabled = false;
576 mycolor = '#000000';
577 myvisibility = 'visible';
579 f.form_repeat_type.disabled = isdisabled;
580 f.form_repeat_freq.disabled = isdisabled;
581 f.form_enddate.disabled = isdisabled;
582 document.getElementById('tdrepeat1').style.color = mycolor;
583 document.getElementById('tdrepeat2').style.color = mycolor;
584 document.getElementById('img_enddate').style.visibility = myvisibility;
587 // This is for callback by the find-available popup.
588 function setappt(year,mon,mday,hours,minutes) {
589 var f = document.forms[0];
590 f.form_date.value = '' + year + '-' +
591 ('' + (mon + 100)).substring(1) + '-' +
592 ('' + (mday + 100)).substring(1);
593 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
594 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
595 f.form_minute.value = ('' + (minutes + 100)).substring(1);
598 // Invoke the find-available popup.
599 function find_available() {
600 var s = document.forms[0].form_provider;
601 var c = document.forms[0].form_category;
602 dlgopen('find_appt_popup.php?providerid=' + s.options[s.selectedIndex].value +
603 '&catid=' + c.options[c.selectedIndex].value, '_blank', 500, 400);
606 // Check for errors when the form is submitted.
607 function validate() {
608 var f = document.forms[0];
609 if (f.form_repeat.checked &&
610 (! f.form_enddate.value || f.form_enddate.value < f.form_date.value)) {
611 alert('An end date later than the start date is required for repeated events!');
612 return false;
614 return true;
617 </script>
619 </head>
621 <body <?echo $top_bg_line;?> onunload='imclosing()'>
623 <form method='post' name='theform' action='add_edit_event.php?eid=<? echo $eid ?>'
624 onsubmit='return validate()'>
625 <center>
627 <table border='0' width='100%'>
629 <tr>
630 <td width='1%' nowrap>
631 <b><? xl('Category','e'); ?>:</b>
632 </td>
633 <td nowrap>
634 <select name='form_category' onchange='set_category()' style='width:100%'>
635 <? echo $catoptions ?>
636 </select>
637 </td>
638 <td width='1%' nowrap>
639 &nbsp;&nbsp;
640 <input type='radio' name='form_allday' onclick='set_allday()' value='1' id='rballday1'
641 <? if ($thisduration == 1440) echo "checked " ?>/>
642 </td>
643 <td colspan='2' nowrap id='tdallday1'>
644 <? xl('All day event','e'); ?>
645 </td>
646 </tr>
648 <tr>
649 <td nowrap>
650 <b><? xl('Date','e'); ?>:</b>
651 </td>
652 <td nowrap>
653 <input type='text' size='10' name='form_date' id='form_date'
654 value='<? echo $eid ? $row['pc_eventDate'] : $date ?>'
655 title='<?php xl('yyyy-mm-dd event date or starting date','e'); ?>'
656 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
657 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
658 id='img_date' border='0' alt='[?]' style='cursor:pointer'
659 title='<?php xl('Click here to choose a date','e'); ?>'>
660 </td>
661 <td nowrap>
662 &nbsp;&nbsp;
663 <input type='radio' name='form_allday' onclick='set_allday()' value='0' id='rballday2'
664 <? if ($thisduration != 1440) echo "checked " ?>/>
665 </td>
666 <td width='1%' nowrap id='tdallday2'>
667 <? xl('Time','e'); ?>
668 </td>
669 <td width='1%' nowrap id='tdallday3'>
670 <input type='text' size='2' name='form_hour'
671 value='<? echo $starttimeh ?>'
672 title='<?php xl('Event start time','e'); ?>' /> :
673 <input type='text' size='2' name='form_minute'
674 value='<? echo $starttimem ?>'
675 title='<?php xl('Event start time','e'); ?>' />&nbsp;
676 <select name='form_ampm' title='Note: 12:00 noon is PM, not AM'>
677 <option value='1'><?php xl('AM','e'); ?></option>
678 <option value='2'<? if ($startampm == '2') echo " selected" ?>><?php xl('PM','e'); ?></option>
679 </select>
680 </td>
681 </tr>
683 <tr>
684 <td nowrap>
685 <b><? xl('Title','e'); ?>:</b>
686 </td>
687 <td nowrap>
688 <input type='text' size='10' name='form_title'
689 value='<? echo addslashes($row['pc_title']) ?>'
690 style='width:100%'
691 title='<?php xl('Event title','e'); ?>' />
692 </td>
693 <td nowrap>
694 &nbsp;
695 </td>
696 <td nowrap id='tdallday4'><? xl('duration','e'); ?>
697 </td>
698 <td nowrap id='tdallday5'>
699 <input type='text' size='4' name='form_duration' value='<? echo $thisduration ?>'
700 title='<?php xl('Event duration in minutes','e'); ?>' /> <? xl('minutes','e'); ?>
701 </td>
702 </tr>
704 <tr>
705 <td nowrap>
706 <b><? xl('Patient','e'); ?>:</b>
707 </td>
708 <td nowrap>
709 <input type='text' size='10' name='form_patient' style='width:100%'
710 value='<? echo $patientname ?>' onclick='sel_patient()'
711 title='<?php xl('Click to select patient','e'); ?>' readonly />
712 <input type='hidden' name='form_pid' value='<? echo $patientid ?>' />
713 </td>
714 <td colspan='3' nowrap style='font-size:8pt'>
715 &nbsp;<? echo $patienttitle ?>
716 </td>
717 </tr>
719 <tr>
720 <td nowrap>
721 <b><? xl('Provider','e'); ?>:</b>
722 </td>
723 <td nowrap>
725 <?php
727 // =======================================
728 // multi providers case
729 // =======================================
730 if ($GLOBALS['select_multi_providers']) {
732 // there are two posible situations: edit and new record
734 // this is executed only on edit ($eid)
735 if ($eid) {
736 // find all the providers around multiple key
737 $qall = sqlStatement ("SELECT pc_aid AS providers FROM openemr_postcalendar_events WHERE pc_multiple = $multiple_value");
739 while ($r = sqlFetchArray($qall)) {
740 $providers_array[] = $r['providers'];
744 // build the selection tool
745 echo "<select name='form_provider[]' style='width:100%' multiple='multiple' size='5'>";
747 while ($urow = sqlFetchArray($ures)) {
748 echo " <option value='" . $urow['id'] . "'";
750 if ($userid) {
751 if ( in_array($urow['id'], $providers_array) ) echo " selected";
754 echo ">" . $urow['lname'];
755 if ($urow['fname']) echo ", " . $urow['fname'];
756 echo "</option>\n";
759 echo '</select>';
761 // =======================================
762 // EOS multi providers case
763 // =======================================
764 } else {
766 <select name='form_provider' style='width:100%'>
768 while ($urow = sqlFetchArray($ures)) {
769 echo " <option value='" . $urow['id'] . "'";
770 if ($userid) {
771 if ($urow['id'] == $userid) echo " selected";
772 } else {
773 if ($urow['id'] == $_SESSION['authUserID']) echo " selected";
775 echo ">" . $urow['lname'];
776 if ($urow['fname']) echo ", " . $urow['fname'];
777 echo "</option>\n";
780 </select>
781 <?php } ?>
784 </td>
785 <td nowrap>
786 &nbsp;&nbsp;
787 <input type='checkbox' name='form_repeat' onclick='set_repeat(this)'
788 value='1'<? if ($repeats) echo " checked" ?>/>
789 </td>
790 <td nowrap id='tdrepeat1'><? xl('Repeats','e'); ?>
791 </td>
792 <td nowrap>
794 <select name='form_repeat_freq' title='Every, every other, every 3rd, etc.'>
796 foreach (array(1 => 'every', 2 => '2nd', 3 => '3rd', 4 => '4th', 5 => '5th', 6 => '6th')
797 as $key => $value)
799 echo " <option value='$key'";
800 if ($key == $repeatfreq) echo " selected";
801 echo ">$value</option>\n";
804 </select>
806 <select name='form_repeat_type'>
808 // See common.api.php for these:
809 foreach (array(0 => 'day' , 4 => 'workday', 1 => 'week', 2 => 'month', 3 => 'year')
810 as $key => $value)
812 echo " <option value='$key'";
813 if ($key == $repeattype) echo " selected";
814 echo ">$value</option>\n";
817 </select>
819 </td>
820 </tr>
822 <tr>
823 <td nowrap>
824 <span id='title_apptstatus'><b><? xl('Status','e'); ?>:</b></span>
825 <span id='title_prefcat' style='display:none'><b><? xl('Pref Cat','e'); ?>:</b></span>
826 </td>
827 <td nowrap>
829 <select name='form_apptstatus' style='width:100%' title='<?php xl('Appointment status','e'); ?>'>
831 foreach ($statuses as $key => $value) {
832 echo " <option value='$key'";
833 if ($key == $row['pc_apptstatus']) echo " selected";
834 echo ">" . htmlspecialchars($value) . "</option>\n";
837 </select>
838 <!--
839 The following list will be invisible unless this is an In Office
840 event, in which case form_apptstatus (above) is to be invisible.
842 <select name='form_prefcat' style='width:100%;display:none' title='<?php xl('Preferred Event Category','e');?>'>
843 <? echo $prefcat_options ?>
844 </select>
846 </td>
847 <td nowrap>
848 &nbsp;
849 </td>
850 <td nowrap id='tdrepeat2'><? xl('until','e'); ?>
851 </td>
852 <td nowrap>
853 <input type='text' size='10' name='form_enddate' id='form_enddate'
854 value='<? echo $row['pc_endDate'] ?>'
855 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
856 title='<?php xl('yyyy-mm-dd last date of this event','e');?>' />
857 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
858 id='img_enddate' border='0' alt='[?]' style='cursor:pointer'
859 title='<?php xl('Click here to choose a date','e');?>'>
860 </td>
861 </tr>
863 <tr>
864 <td nowrap>
865 <b><? xl('Comments','e'); ?>:</b>
866 </td>
867 <td colspan='4' nowrap>
868 <input type='text' size='40' name='form_comments' style='width:100%'
869 value='<? echo $hometext ?>'
870 title='<?php xl('Optional information about this event','e');?>' />
871 </td>
872 </tr>
874 <?php
875 // DOB is important for the clinic, so if it's missing give them a chance
876 // to enter it right here. We must display or hide this row dynamically
877 // in case the patient-select popup is used.
878 $patient_dob = trim($prow['DOB']);
879 $dobstyle = ($prow && (!$patient_dob || substr($patient_dob, 5) == '00-00')) ?
880 '' : 'none';
882 <tr id='dob_row' style='display:<?php echo $dobstyle ?>'>
883 <td colspan='4' nowrap>
884 <b><font color='red'><? xl('DOB is missing, please enter if possible','e'); ?>:</font></b>
885 </td>
886 <td nowrap>
887 <input type='text' size='10' name='form_dob' id='form_dob'
888 title='<?php xl('yyyy-mm-dd date of birth','e');?>'
889 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
890 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
891 id='img_dob' border='0' alt='[?]' style='cursor:pointer'
892 title='<?php xl('Click here to choose a date','e');?>'>
893 </td>
894 </tr>
896 </table>
899 <input type='submit' name='form_save' value='<?php xl('Save','e');?>' />
900 &nbsp;
901 <input type='button' value='<?php xl('Find Available','e');?>' onclick='find_available()' />
902 &nbsp;
903 <input type='submit' name='form_delete' value='<?php xl('Delete','e');?>'<? if (!$eid) echo " disabled" ?> />
904 &nbsp;
905 <input type='button' value='<?php xl('Cancel','e');?>' onclick='window.close()' />
906 </p>
907 </center>
908 </form>
910 <script language='JavaScript'>
911 <? if ($eid) { ?>
912 set_display();
913 <? } else { ?>
914 set_category();
915 <? } ?>
916 set_allday();
917 set_repeat();
919 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
920 Calendar.setup({inputField:"form_enddate", ifFormat:"%Y-%m-%d", button:"img_enddate"});
921 Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});
922 </script>
924 </body>
925 </html>