This fixes bug #368. Forced the OUT event to act like a regular
[openemr.git] / interface / main / calendar / modules / PostCalendar / pntemplates / default / views / day / ajax_template.html
blobdda11e61f23b2a5e5d8b1930d0c7fa1b9c46a51d
1 [-*Smarty*-]
2 [-*****************************************************************************-]
3 [-* Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com> and others *-]
4 [-* *-]
5 [-* This program is free software; you can redistribute it and/or *-]
6 [-* modify it under the terms of the GNU General Public License *-]
7 [-* as published by the Free Software Foundation; either version 2 *-]
8 [-* of the License, or (at your option) any later version. *-]
9 [-*****************************************************************************-]
10 [-config_load file="default.conf"-]
11 [-*Load the Language Definitions*-]
12 [-config_load file="lang.$USER_LANG"-]
13 [-include file="$TPL_NAME/views/header.html"-]
15 [-*Values used in setting timeslot and event heights*-]
16 [-php-]
17 /* if you change these be sure to change their matching values in
18 * the CSS for the calendar, found in interface/themes/ajax_calendar.css
20 $timeslotHeightVal=20;
21 $timeslotHeightUnit="px";
22 [-/php-]
24 <script language='JavaScript'>
26 var mypcc = '[-php-] echo $GLOBALS['phone_country_code'] [-/php-]';
28 // This is called from the event editor popup.
29 function refreshme() {
30 top.restoreSession();
31 document.forms[0].submit();
34 function newEvt(startampm, starttimeh, starttimem, eventdate, providerid, catid) {
35 dlgopen('add_edit_event.php?startampm=' + startampm +
36 '&starttimeh=' + starttimeh + '&userid=' + providerid + '&starttimem=' + starttimem +
37 '&date=' + eventdate + '&catid=' + catid[-php-]
38 if(isset($_SESSION[pid]))
40 if($_SESSION[pid]>0)
42 echo "+'&patientid=$_SESSION[pid]'";
45 [-/php-]
46 ,'_blank', 575, 375);
49 function oldEvt(eventdate, eventid, pccattype) {
50 dlgopen('add_edit_event.php?date='+eventdate+'&eid=' + eventid+'&prov=' + pccattype, '_blank', 575, 375);
53 function goPid(pid) {
54 top.restoreSession();
55 [-php-]
56 if ($GLOBALS['concurrent_layout'])
59 echo " top.RTop.location = '../../patient_file/summary/demographics.php' " .
60 "+ '?set_pid=' + pid;\n";
62 } else
64 echo " top.location = '../../patient_file/patient_file.php' " .
65 "+ '?set_pid=' + pid + '&pid=' + pid;\n";
67 [-/php-]
70 function GoToToday(theForm){
71 var todays_date = new Date();
72 var theMonth = todays_date.getMonth() + 1;
73 theMonth = theMonth < 10 ? "0" + theMonth : theMonth;
74 theForm.jumpdate.value = todays_date.getFullYear() + "-" + theMonth + "-" + todays_date.getDate();
75 top.restoreSession();
76 theForm.submit();
79 </script>
81 [-php-]
83 // this is my proposed setting in the globals config file so we don't
84 // need to mess with altering the pn database AND the config file
85 //pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', $GLOBALS['schedule_dow_start']);
87 // build a day-of-week (DOW) list so we may properly build the calendars later in this code
88 $DOWlist = array();
89 $tmpDOW = pnModGetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
90 // bound check and auto-correction
91 if ($tmpDOW <0 || $tmpDOW >6) {
92 pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', '0');
93 $tmpDOW = 0;
95 while (count($DOWlist) < 7) {
96 array_push($DOWlist, $tmpDOW);
97 $tmpDOW++;
98 if ($tmpDOW > 6) $tmpDOW = 0;
101 // A_CATEGORY is an ordered array of associative-array categories.
102 // Keys of interest are: id, name, color, desc, event_duration.
104 // echo "<!-- A_CATEGORY = "; print_r($this->_tpl_vars['A_CATEGORY']); echo " -->\n"; // debugging
105 // echo "<!-- A_EVENTS = "; print_r($this->_tpl_vars['A_EVENTS']); echo " -->\n"; // debugging
107 $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY'];
109 // [-if $PRINT_VIEW != 1-]
110 // [-*Main Navigation*-]
111 // [-include file="$TPL_NAME/views/global/navigation.html"-]
112 // [-/if-]
114 $A_EVENTS =& $this->_tpl_vars['A_EVENTS'];
115 // $S_EVENTS =& $this->_tpl_vars['S_EVENTS']; // Deleted by Rod
116 $providers =& $this->_tpl_vars['providers'];
117 $times =& $this->_tpl_vars['times'];
118 $interval = $this->_tpl_vars['interval'];
119 $viewtype = $this->_tpl_vars['VIEW_TYPE'];
120 $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL'];
121 $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL'];
122 $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL'];
123 $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL'];
125 $Date = postcalendar_getDate();
126 if (!isset($y)) $y = substr($Date, 0, 4);
127 if (!isset($m)) $m = substr($Date, 4, 2);
128 if (!isset($d)) $d = substr($Date, 6, 2);
130 // echo "<!-- There are " . count($A_EVENTS) . " A_EVENTS days -->\n";
132 $MULTIDAY = count($A_EVENTS) > 1;
134 //==================================
135 //FACILITY FILTERING (CHEMED)
136 $facilities = getUserFacilities($_SESSION['authId']); // from users_facility
137 if ( $_SESSION['pc_facility'] ) {
138 $provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']);
139 } else {
140 $provinfo = getProviderInfo();
142 //EOS FACILITY FILTERING (CHEMED)
143 //==================================
145 [-/php-]
146 <div id="topToolbarRight"> <!-- this wraps some of the top toolbar items -->
147 <div id="functions">
148 <!-- stuff form element here to avoid the margin padding it introduces into the page in some browsers -->
149 <form name='theform' id='theform' action='index.php?module=PostCalendar&func=view&tplview=default&pc_category=&pc_topic=' method='post' onsubmit='return top.restoreSession()'>
150 <input type="hidden" name="jumpdate" id="jumpdate" value="">
151 <input type="hidden" name="viewtype" id="viewtype" value="[-php-]echo $viewtype;[-/php-]">
152 [-php-]
153 echo " <a href='#' value='" .xl ("Add"). "' onclick='newEvt(1, 9, 00, $Date, 0, 0)' class='css_button'/><span>".xl("Add")."</span></a>\n";
154 echo " <a href='#' value='" . xl ("Search") .
155 "' onclick='top.restoreSession();location=\"index.php?module=PostCalendar&func=search\"' class='css_button'/><span>".xl("Search")."</span></a>\n";
156 [-/php-]
157 </div>
160 <div id="dateNAV"">
161 <a href='#' name='bnsubmit' value='[-php-]echo xl ("Today")[-/php-]' onClick='GoToToday(theform);' class='css_button'/><span>[-php-] echo xl("Today")[-/php-]</span></a>
162 <a href='[-php-]echo $PREV_DAY_URL[-/php-]' onclick='top.restoreSession()'>
163 <img id="prevday" src="[-$TPL_IMAGE_PATH-]/leftbtn.gif" border="0" title="[-php-]echo xl("Previous Day")[-/php-]" alt="[-php-]echo xl ("Previous Day")[-/php-]" style="padding-top:5px"/></a>
164 <a href='[-php-]echo $NEXT_DAY_URL[-/php-]' onclick='top.restoreSession()'>
165 <img id="nextday" src="[-$TPL_IMAGE_PATH-]/rightbtn.gif" border="0" title="[-php-]echo xl("Next Day")[-/php-]" alt="[-php-]echo xl ("Next Day")[-/php-]" /></a>
166 &nbsp;
167 [-php-]
168 $atmp = array_keys($A_EVENTS);
169 echo dateformat (strtotime($atmp[0]),true);
170 [-/php-]
171 </div>
173 <div id="viewPicker">
174 [-php-]
175 echo " <a href='#' type='button' id='printview' title='" .xl ("Print View"). "' class='css_button'/><span>".xl("Print")."</span></a>\n";
176 echo " <a href='#' type='button' value='" .xl ("Refresh"). "' onclick='javascript:refreshme()' class='css_button'/><span>".xl("Refresh")."</span></a>\n";
177 echo " <a href='#' type='button' id='dayview' title='" .htmlspecialchars( xl('Day View'), ENT_QUOTES). "' class='css_button'/><span>".htmlspecialchars( xl('Day'), ENT_QUOTES)."</span></a>\n";
178 echo " <a href='#' type='button' id='weekview' title='" .htmlspecialchars( xl('Week View'), ENT_QUOTES). "' class='css_button'/><span>".htmlspecialchars( xl('Week'), ENT_QUOTES)."</span></a>\n";
179 echo " <a href='#' type='button' id='monthview' title='" .htmlspecialchars( xl('Month View'), ENT_QUOTES). "' class='css_button'/><span>".htmlspecialchars( xl('Month'), ENT_QUOTES)."</span></a>\n";
180 [-/php-]
181 </div>
182 </div> <!-- end topToolbarRight -->
183 <div id="bottom">
184 <div id="bottomLeft">
185 <div id="datePicker">
186 [-php-]
187 $atmp = array_keys($A_EVENTS);
188 $caldate = strtotime($atmp[0]);
189 $cMonth = date("m", $caldate);
190 $cYear = date("Y", $caldate);
191 $cDay = date("d", $caldate);
193 include_once($GLOBALS['webserver_root'].'/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/monthSelector.php');
194 [-/php-]
195 <table border="0" cellpadding="0" cellspacing="0">
196 <tr>
197 [-php-]
199 // compute the previous month date
200 // stay on the same day if possible
201 $pDay = $cDay;
202 $pMonth = $cMonth - 1;
203 $pYear = $cYear;
204 if ($pMonth < 1) { $pMonth = 12; $pYear = $cYear - 1; }
205 while (! checkdate($pMonth, $pDay, $pYear)) { $pDay = $pDay - 1; }
206 $prevMonth = sprintf("%d%02d%02d",$pYear,$pMonth,$pDay);
208 // compute the next month
209 // stay on the same day if possible
210 $nDay = $cDay;
211 $nMonth = $cMonth + 1;
212 $nYear = $cYear;
213 if ($nMonth > 12) { $nMonth = 1; $nYear = $cYear + 1; }
214 while (! checkdate($nMonth, $nDay, $nYear)) { $nDay = $nDay - 1; }
215 $nextMonth = sprintf("%d%02d%02d",$nYear,$nMonth,$nDay);
216 [-/php-]
217 <td class="tdDOW-small tdDatePicker" id="[-php-]echo $prevMonth[-/php-]" title="[-php-]echo xl(date("F", strtotime($prevMonth)));[-/php-]">&lt;</td>
218 <td colspan="5" class="tdMonthName-small">
219 [-php-]
220 echo xl(date('F', $caldate));
221 [-/php-]
222 </td>
223 <td class="tdDOW-small tdDatePicker" id="[-php-]echo $nextMonth[-/php-]" title="[-php-]echo xl(date("F", strtotime($nextMonth)));[-/php-]">&gt;</td>
224 <tr>
225 [-php-]
226 foreach ($DOWlist as $dow) {
227 echo "<td class='tdDOW-small'>".$this->_tpl_vars['A_SHORT_DAY_NAMES'][$dow]."</td>";
229 [-/php-]
230 </tr>
231 [-php-]
232 $atmp = array_keys($A_EVENTS);
233 $caldate = strtotime($atmp[0]);
234 $caldateEnd = strtotime($atmp[6]);
236 // to make a complete week row we need to compute the real
237 // start and end dates for the view
238 list ($year, $month, $day) = explode(" ", date('Y m d', $caldate));
239 $startdate = strtotime($year.$month."01");
240 $enddate = strtotime($year.$month.date("t", $startdate)." 23:59");
241 while (date('w', $startdate) != $DOWlist[0]) { $startdate -= 60*60*24; }
242 while (date('w', $enddate) != $DOWlist[6]) { $enddate += 60*60*24; }
244 $currdate = $startdate;
245 while ($currdate <= $enddate) {
246 if (date('w', $currdate) == $DOWlist[0]) {
247 // start of week row
248 $tr = "<tr>";
249 echo $tr;
252 // set the TD class
253 $tdClass = "tdMonthDay-small";
254 if (date('m', $currdate) != $month) {
255 $tdClass = "tdOtherMonthDay-small";
257 if ((date('w', $currdate) == 0) || (date('w', $currdate) == 6)) {
258 $tdClass = "tdWeekend-small";
261 if (date('Ymd',$currdate) == $Date) {
262 // $Date is defined near the top of this file
263 // and is equal to whatever date the user has clicked
264 $tdClass .= " currentDate";
267 // add a class so that jQuery can grab these days for the 'click' event
268 $tdClass .= " tdDatePicker";
270 // output the TD
271 $td = "<td ";
272 $td .= "class=\"".$tdClass."\" ";
273 //$td .= "id=\"".date("Ymd", $currdate)."\" ";
274 $td .= "id=\"".date("Ymd", $currdate)."\" ";
275 $td .= "title=\"" . xl('Go to') . " ".date('M d, Y', $currdate)."\" ";
276 $td .= "> ".date('d', $currdate)."</td>\n";
277 echo $td;
279 // end of week row
280 if (date('w', $currdate) == $DOWlist[6]) echo "</tr>\n";
282 // time correction = plus 1000 seconds, for some unknown reason
283 $currdate += (60*60*24)+1000;
285 [-/php-]
286 </table>
287 </div>
289 <div id="bigCalHeader">
290 </div>
292 <div id="providerPicker">
293 [-php-] xl('Providers','e'); [-/php-]
294 <div>
295 [-php-]
296 // ==============================
297 // FACILITY FILTERING (lemonsoftware)
298 /*********************************************************************
299 $facilities = getFacilities();
300 *********************************************************************/
301 if ($_SESSION['authorizeduser'] == 1) {
302 $facilities = getFacilities();
303 } else {
304 $facilities = getUserFacilities($_SESSION['authId']); // from users_facility
305 if (count($facilities) == 1)
306 $_SESSION['pc_facility'] = key($facilities);
308 /********************************************************************/
309 if (count($facilities) > 1) {
310 echo " <select name='pc_facility' id='pc_facility' class='view1' >\n";
311 if ( !$_SESSION['pc_facility'] ) $selected = "selected='selected'";
312 // echo " <option value='0' $selected>" .xl('All Facilities'). "</option>\n";
313 if (!$GLOBALS['restrict_user_facility']) echo " <option value='0' $selected>" . xl('All Facilities') . "</option>\n";
314 foreach ($facilities as $fa) {
315 $selected = ( $_SESSION['pc_facility'] == $fa['id']) ? "selected='selected'" : "" ;
316 echo " <option style=background-color:".htmlspecialchars($fa['color'],ENT_QUOTES)." value='" .htmlspecialchars($fa['id'],ENT_QUOTES). "' $selected>" .htmlspecialchars($fa['name'],ENT_QUOTES). "</option>\n";
318 echo " </select>\n";
320 // EOS FF
321 // ==============================
322 echo "</div>";
323 echo " <select multiple size='5' name='pc_username[]' id='pc_username' class='view2'>\n";
324 echo " <option value='__PC_ALL__'>" .xl ("All Users"). "</option>\n";
325 foreach ($provinfo as $doc) {
326 $username = $doc['username'];
327 echo " <option value='$username'";
328 foreach ($providers as $provider)
329 if ($provider['username'] == $username) echo " selected";
330 echo ">" . htmlspecialchars($doc['lname'],ENT_QUOTES) . ", " . htmlspecialchars($doc['fname'],ENT_QUOTES) . "</option>\n";
332 echo " </select>\n";
334 [-/php-]
335 </div>
336 [-php-]
337 if($_SESSION['pc_facility'] == 0){
338 [-/php-]
339 <div id="facilityColor">
340 <table>
341 [-php-]
342 foreach ($facilities as $f){
343 echo " <tr><td><div class='view1' style=background-color:".$f['color'].";font-weight:bold>".htmlspecialchars($f['name'],ENT_QUOTES)."</div></td></tr>";
345 [-/php-]
346 </table>
347 </div>
348 [-php-]
350 [-/php-]
352 </form>
354 [-assign var="dayname" value=$DATE|date_format:"%w"-]
355 [-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-]
356 [-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-]
357 [-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-]
359 [-pc_sort_events var="S_EVENTS" sort="time" order="asc" value=$A_EVENTS-]
360 </div> <!-- end bottomLeft -->
361 <div id="bigCal">
362 [-php-]
364 echo "<table border='0' cellpadding='1' cellspacing='0' width='100%'>\n";
366 // output the TD with the times DIV
367 echo "<tr>";
368 echo "<td id='times'><div><table>\n";
369 echo "<td class='timeslot'>&nbsp;</td>";
370 //============================================================================================================================
371 foreach ($times as $slottime) {
372 $startampm = ($slottime['mer']) == "pm" ? 2 : 1;
373 $starttimeh = $slottime['hour'];
374 $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh;
375 $starttimem = $slottime['minute'];
376 $slotendmins = $starttimeh * 60 + $starttimem + $interval;
378 // default to the first displayed provider
379 $providerid = $providers[0]['id'];
381 echo "<tr><td class='timeslot'>";
382 echo "<a href='javascript:newEvt($startampm,$starttimeh,$starttimem,$Date,$providerid,0)' title='" . htmlspecialchars(xl("New Appointment"),ENT_QUOTES) . "' alt='" .htmlspecialchars(xl("New Appointment"),ENT_QUOTES). "'>";
383 echo "$disptimeh:$starttimem";
384 echo "</a>";
385 echo "</td></tr>\n";
387 echo "</table></div></td>";
390 // This loops once for each provider to be displayed.
392 foreach ($providers as $provider) {
393 $providerid = $provider['id'];
395 // to specially handle the IN/OUT events I'm doing something new here
396 // for each IN event it will have a duration lasting until the next
397 // OUT event or until the end of the day
398 $tmpTime = $times[0];
399 $calStartMin = ($tmpTime['hour'] * 60) + $tmpTime['minute'];
400 $tmpTime = $times[count($times)-1];
401 $calEndMin = ($tmpTime['hour'] * 60) + $tmpTime['minute'];
403 // having a 'title' for the TD makes the date appear by the mouse pointer
404 // this is nice when all you see are times on the left side and no head
405 // row with the dates or day-of-week (DOW)
406 echo "<td class='schedule' title='".htmlspecialchars($provider["fname"],ENT_QUOTES)." ".htmlspecialchars($provider["lname"],ENT_QUOTES)."' date='".date("Ymd",$caldate )."' provider='$providerid'>";
407 echo "<div class='providerheader'>";
408 echo htmlspecialchars($provider['fname'],ENT_QUOTES)." ".htmlspecialchars($provider['lname'],ENT_QUOTES)."</div>";
409 echo "<div class='calendar_day'>";
411 // For each event...
412 // output a TD with an inner containing DIV positioned 'relative'
413 // within that DIV we place our event DIVs using 'absolute' positioning
414 foreach ($A_EVENTS as $date => $events) {
415 $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2);
417 // determine if events overlap and adjust their width and left position as needed
418 // 26 Feb 2008 - This needs fine tuning or total replacement
419 // - it doesn't work as well as I'd like - JRM
420 $eventPositions = array();
421 foreach ($times as $slottime) {
422 $starttimeh = $slottime['hour'];
423 $starttimem = $slottime['minute'];
425 $slotstartmins = $starttimeh * 60 + $starttimem;
426 $slotendmins = $starttimeh * 60 + $starttimem + $interval;
428 $events_in_timeslot = array();
429 foreach ($events as $e1) {
430 // ignore IN event
431 if (($e1['catid'] == 2)) { continue; }
433 // skip events without an ID (why they are in the loop, I have no idea)
434 if ($e1['eid'] == "") { continue; }
436 // skip events for other providers
437 if ($providerid != $e1['aid']) { continue; }
439 // specially handle all-day events
440 if ($e1['alldayevent'] == 1) {
441 $tmpTime = $times[0];
442 if (strlen($tmpTime['hour']) < 2) { $tmpTime['hour'] = "0".$tmpTime['hour']; }
443 if (strlen($tmpTime['minute']) < 2) { $tmpTime['minute'] = "0".$tmpTime['minute']; }
444 $e1['startTime'] = $tmpTime['hour'].":".$tmpTime['minute'].":00";
445 $e1['duration'] = ($calEndMin - $calStartMin) * 60; // measured in seconds
448 // create a numeric start and end for comparison
449 $starth = substr($e1['startTime'], 0, 2);
450 $startm = substr($e1['startTime'], 3, 2);
451 $e1Start = ($starth * 60) + $startm;
452 $e1End = $e1Start + $e1['duration']/60;
454 // three ways to overlap:
455 // start-in, end-in, span
456 if ((($e1Start >= $slotstartmins) && ($e1Start < $slotendmins)) // start-in
457 || (($e1End > $slotstartmins) && ($e1End <= $slotendmins)) // end-in
458 || (($e1Start < $slotstartmins) && ($e1End > $slotendmins))) // span
460 array_push($events_in_timeslot, $e1['eid']);
461 if($e1['catid'] == 3)
463 array_pop($events_in_timeslot);
464 array_unshift($events_in_timeslot, $e1['eid']);
469 $leftpos = 0;
470 $width = 100 / count($events_in_timeslot);
472 // loop over the events in this timeslot and adjust their width
473 foreach ($events_in_timeslot as $eid) {
474 // set the width if not already set or if the current width is smaller
475 // than was was previously set
476 if (!isset($eventPositions[$eid]->width))
478 $eventPositions[$eid]->width = $width;
479 } else if ($eventPositions[$eid]->width > $width)
481 $eventPositions[$eid]->width = $width;
484 // set the left position if not already set or if the current left is
485 // greater than what was previously set
486 if (!isset($eventPositions[$eid]->leftpos))
488 $eventPositions[$eid]->leftpos = $leftpos;
489 } else if ($eventPositions[$eid]->leftpos < $leftpos)
491 $eventPositions[$eid]->leftpos = $leftpos;
494 // increment the leftpos by the width
495 $leftpos += $width;
497 } // end overlap detection
499 // now loop over the events for the day and output their DIVs
500 foreach ($events as $event) {
501 // skip events for other providers
502 // yeah, we've got that sort of overhead here... it ain't perfect
503 if ($providerid != $event['aid']) { continue; }
505 // skip events without an ID (why they are in the loop, I have no idea)
506 if ($event['eid'] == "") { continue; }
508 // specially handle all-day events
509 if ($event['alldayevent'] == 1) {
510 $tmpTime = $times[0];
511 if (strlen($tmpTime['hour']) < 2) { $tmpTime['hour'] = "0".$tmpTime['hour']; }
512 if (strlen($tmpTime['minute']) < 2) { $tmpTime['minute'] = "0".$tmpTime['minute']; }
513 $event['startTime'] = $tmpTime['hour'].":".$tmpTime['minute'].":00";
514 $event['duration'] = ($calEndMin - $calStartMin) * 60; // measured in seconds
517 // figure the start time and minutes (from midnight)
518 $starth = substr($event['startTime'], 0, 2);
519 $startm = substr($event['startTime'], 3, 2);
520 $eStartMin = $starth * 60 + $startm;
521 $dispstarth = ($starth > 12) ? ($starth - 12) : $starth; // used to display the hour
523 // determine the class for the event DIV based on the event category
524 $evtClass = "event_appointment";
525 switch ($event['catid']) {
526 case 1: // NO-SHOW appt
527 $evtClass = "event_noshow";
528 break;
529 case 2: // IN office
530 $evtClass = "event_in";
531 break;
532 case 3: // OUT of office
533 $evtClass = "event_out";
534 break;
535 case 4: // VACATION
536 case 8: // LUNCH
537 case 11: // RESERVED
538 $evtClass = "event_reserved";
539 break;
540 default: // some appointment
541 $evtClass = "event_appointment";
542 break;
545 // if this is an IN or OUT event then we have some extra special
546 // processing to be done
547 // the IN event creates a DIV until the OUT event
548 // or, without an OUT DIV matching the IN event
549 // then the IN event runs until the end of the day
550 if ($event['catid'] == 2) {
551 // locate a matching OUT for this specific IN
552 $found = false;
553 $outMins = 0;
554 foreach ($events as $outevent) {
555 // skip events for other providers
556 if ($providerid != $outevent['aid']) { continue; }
557 // skip events with blank IDs
558 if ($outevent['eid'] == "") { continue; }
560 if ($outevent['eid'] == $event['eid']) { $found = true; continue; }
561 if (($found == true) && ($outevent['catid'] == 3)) {
562 // calculate the duration from this event to the outevent
563 $outH = substr($outevent['startTime'], 0, 2);
564 $outM = substr($outevent['startTime'], 3, 2);
565 $outMins = ($outH * 60) + $outM;
566 $event['duration'] = ($outMins - $eStartMin) * 60; // duration is in seconds
567 $found = 2;
568 break;
571 if ($outMins == 0) {
572 // no OUT was found so this event's duration goes
573 // until the end of the day
574 $event['duration'] = ($calEndMin - $eStartMin) * 60; // duration is in seconds
578 // calculate the TOP value for the event DIV
579 // diff between event start and schedule start
580 $eMinDiff = $eStartMin - $calStartMin;
581 // diff divided by the time interval of the schedule
582 $eStartInterval = $eMinDiff / $interval;
583 // times the interval height
584 $eStartPos = $eStartInterval * $timeslotHeightVal;
585 $evtTop = $eStartPos.$timeslotHeightUnit;
587 // calculate the HEIGHT value for the event DIV
588 // diff between end and start of event
589 $eEndMin = $eStartMin + ($event['duration']/60);
590 // prevent the overall height of the event from going beyond the bounds
591 // of the time table
592 if ($eEndMin > $calEndMin) { $eEndMin = $calEndMin + $interval; }
593 $eMinDiff = $eEndMin - $eStartMin;
594 // diff divided by the time interval of the schedule
595 $eEndInterval = $eMinDiff / $interval;
596 // times the interval height
597 $eHeight = $eEndInterval * $timeslotHeightVal;
598 if($event['catid']==3)
600 // An "OUT" that is "zero duration" still needs height so we can click it.
601 $eHeight = $eEndInterval==0 ? $timeslotHeightVal : $eHeight ;
603 $evtHeight = $eHeight.$timeslotHeightUnit;
605 // determine the DIV width based on any overlapping events
606 // see further above for the overlapping calculation code
607 $divWidth = "";
608 $divLeft = "";
609 if (isset($eventPositions[$event['eid']])) {
610 $divWidth = "width: ".$eventPositions[$event['eid']]->width."%";
611 $divLeft = "left: ".$eventPositions[$event['eid']]->leftpos."%";
614 $eventid = $event['eid'];
615 $eventtype = sqlQuery("SELECT pc_cattype FROM openemr_postcalendar_categories as oc LEFT OUTER JOIN openemr_postcalendar_events as oe ON oe.pc_catid=oc.pc_catid WHERE oe.pc_eid='".$eventid."'");
616 $pccattype = '';
617 if($eventtype['pc_cattype']==1)
618 $pccattype = 'true';
619 $patientid = $event['pid'];
620 $commapos = strpos($event['patient_name'], ",");
621 $lname = substr($event['patient_name'], 0, $commapos);
622 $fname = substr($event['patient_name'], $commapos + 2);
623 $patient_dob = $event['patient_dob'];
624 $patient_age = $event['patient_age'];
625 $catid = $event['catid'];
626 $comment = addslashes($event['hometext']);
627 $catname = $event['catname'];
628 $title = "Age $patient_age ($patient_dob)";
630 $content = "";
632 if ($comment && $GLOBALS['calendar_appt_style'] < 4) $title .= " " . $comment;
634 // the divTitle is what appears when the user hovers the mouse over the DIV
635 $divTitle = htmlspecialchars($provider["fname"],ENT_QUOTES)." ".htmlspecialchars($provider["lname"],ENT_QUOTES);
636 $result = sqlStatement("SELECT name,id,color FROM facility WHERE id=(SELECT pc_facility FROM openemr_postcalendar_events WHERE pc_eid=".$eventid.")");
637 $row = sqlFetchArray($result);
638 $color=$event["catcolor"];
639 if($GLOBALS['event_color']==2)
640 $color=$row['color'];
641 $divTitle .= "\n" .htmlspecialchars($row['name'],ENT_QUOTES);
643 if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) {
644 if ($catid == 2) $catname = xl("IN");
645 else if ($catid == 3) $catname = xl("OUT");
646 else if ($catid == 4) $catname = xl("VACATION");
647 else if ($catid == 8) $catname = xl("LUNCH");
648 else if ($catid == 11) $catname = xl("RESERVED");
650 $atitle = $catname;
651 if ($comment) $atitle .= " $comment";
652 $divTitle .= "\n[".$atitle ."]";
653 $content .= $catname;
654 if ($event['recurrtype'] == 1) $content .= "<img src='$TPL_IMAGE_PATH/repeating8.png' border='0' style='margin:0px 2px 0px 2px;' title='".htmlspecialchars(xl("Repeating event"),ENT_QUOTES)."' alt='".htmlspecialchars(xl("Repeating event"),ENT_QUOTES)."'>";
655 if ($comment) $content .= " $comment";
657 else {
658 // some sort of patient appointment
659 $divTitle .= "\r\n[".$catname.' '.htmlspecialchars($comment, ENT_QUOTES) ."]".htmlspecialchars($fname, ENT_QUOTES)." ".htmlspecialchars($lname, ENT_QUOTES);
660 $content .= "<span class='appointment'>";
661 $content .= create_event_time_anchor($dispstarth.":".$startm);
662 if ($event['recurrtype'] == 1) $content .= "<img src='$TPL_IMAGE_PATH/repeating8.png' border='0' style='margin:0px 2px 0px 2px;' title='".htmlspecialchars(xl("Repeating event"),ENT_QUOTES)."' alt='".htmlspecialchars(xl("Repeating event"),ENT_QUOTES)."'>";
663 // $content .= htmlspecialchars($event['apptstatus']);
664 $content .= '&nbsp;'.htmlspecialchars($event['apptstatus']);
665 if ($patientid) {
666 $link_title = htmlspecialchars($fname,ENT_QUOTES)." ".htmlspecialchars($lname,ENT_QUOTES). " \n";
667 $link_title .= xl('Age') . ": ".$patient_age."\n" . xl('DOB') . ": ".$patient_dob.htmlspecialchars($comment, ENT_QUOTES)."\n";
668 $link_title .= "(" . xl('Click to view') . ")";
669 $content .= "<a href='javascript:goPid($patientid)' title='$link_title'>";
670 $content .= "<img src='$TPL_IMAGE_PATH/user-green.gif' border='0' title='$link_title' alt='View Patient' />";
671 if ($catid == 1) $content .= "<strike>";
672 $content .= htmlspecialchars($lname);
673 if ($GLOBALS['calendar_appt_style'] != 1) {
674 $content .= "," . htmlspecialchars($fname);
675 if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) {
676 $content .= "(" . $event['title'];
677 if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4)
678 $content .= ": <font color='green'>" . htmlspecialchars(trim($event['hometext'])) . "</font>";
679 $content .= ")";
682 if ($catid == 1) $content .= "</strike>";
683 $content .= "</a>";
685 else {
686 // no patient id, just output the category name
687 $content .= $catname;
689 $content .= "</span>";
692 $divTitle .= "\n(" . xl('double click to edit') . ")";
694 if($_SESSION['pc_facility'] == 0){
695 // a special case for the 'IN' event this puts the time ABOVE
696 // the normal DIV so it doesn't overlap another event DIV and include the time
697 if ($event['catid'] == 2) {
698 $inTop = ($eStartPos - $timeslotHeightVal).$timeslotHeightUnit;
699 echo "<div class='".$evtClass." event in_start' style='top:".$inTop.
700 "; height:".$timeslotHeightVal.$timeslotHeightUnit.
701 "; $divWidth".
702 "; $divLeft".
703 "; border: none".
704 "' title='".$divTitle."'".
705 " id='".$eventdate."-".$eventid."-".$pccattype."'".
706 ">";
707 $content = $dispstarth . ':' . $startm . " " . $content;
708 echo $content;
709 echo "</div>\n";
712 // output the DIV and content
713 // For "OUT" events, applying the background color in CSS.
714 $background_string= ($event['catid'] == 3) ? "" : "; background-color:".$event["catcolor"];
715 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
716 $background_string.
717 "; $divWidth".
718 "; $divLeft".
719 "' title='".$divTitle."'".
720 " id='".$eventdate."-".$eventid."-".$pccattype."'".
721 ">";
722 // second part for the special IN event
723 if ($event['catid'] != 2) { echo $content; }
724 echo "</div>\n";
726 elseif($_SESSION['pc_facility'] == $row['id']){
727 if ($event['catid'] == 2) {
728 $inTop = ($eStartPos - $timeslotHeightVal).$timeslotHeightUnit;
729 echo "<div class='".$evtClass." event in_start' style='top:".$inTop.
730 "; height:".$timeslotHeightVal.$timeslotHeightUnit.
731 "; $divWidth".
732 "; $divLeft".
733 "; border: none".
734 "' title='".$divTitle."'".
735 " id='".$eventdate."-".$eventid."-".$pccattype."'".
736 ">";
737 $content = $dispstarth . ':' . $startm . " " . $content;
738 echo $content;
739 echo "</div>\n";
742 // output the DIV and content
743 // For "OUT" events, applying the background color in CSS.
744 $background_string= ($event['catid'] == 3) ? "" : "; background-color:".$event["catcolor"];
745 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
746 $background_string.
747 "; $divWidth".
748 "; $divLeft".
749 "' title='".$divTitle."'".
750 " id='".$eventdate."-".$eventid."-".$pccattype."'".
751 ">";
752 // second part for the special IN event
753 if ($event['catid'] != 2) { echo $content; }
754 echo "</div>\n";
756 else{
758 if ($event['catid'] == 2) {
759 $inTop = ($eStartPos - $timeslotHeightVal).$timeslotHeightUnit;
760 echo "<div class='".$evtClass." event in_start' style='top:".$inTop.
761 "; height:".$timeslotHeightVal.$timeslotHeightUnit.
762 "; $divWidth".
763 "; $divLeft".
764 "; background:#DDDDDD".
765 "; border: none".
766 "' title='".$divTitle."'".
767 " id='".$eventdate."-".$eventid."-".$pccattype."'".
768 ">";
769 $content = "<span style='color:red;text-align:center;font-weight:bold'>".htmlspecialchars($row['name'],ENT_QUOTES)."</span>";
770 echo $content;
771 echo "</div>\n";
774 // output the DIV and content
775 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
776 "; background-color:#DDDDDD".
777 "; $divWidth".
778 "; $divLeft".
779 "' title='".$divTitle."'".
780 " id='".$eventdate."-".$eventid."-".$pccattype."'".
781 ">";
782 // second part for the special IN event
783 if ($event['catid'] != 2) { echo "<span style='color:red;text-align:center;font-weight:bold'>".htmlspecialchars($row['name'],ENT_QUOTES)."</span>"; }
784 echo "</div>\n";
786 } // end EVENT loop
788 echo "</div>";
790 } // end date
792 echo "</td>\n";
794 } // end provider loop
795 //============================================================================================================================
796 echo " </tr>\n";
797 echo "</table>\n";
798 echo "<P>";
800 // [-*footer*-]
801 // [-include file="$TPL_NAME/views/global/footer.html"-]
802 // [-include file="$TPL_NAME/views/footer.html"-]
804 [-/php-]
805 </div> <!-- end bigCal DIV -->
806 </div> <!-- end bottom DIV -->
807 </body>
809 <script language='JavaScript'>
810 var tsHeight='[-php-] echo $timeslotHeightVal.$timeslotHeightUnit; [-/php-]';
811 var tsHeightNum=[-php-] echo $timeslotHeightVal; [-/php-];
813 $(document).ready(function(){
814 setupDirectTime();
815 $("#pc_username").change(function() { ChangeProviders(this); });
816 $("#pc_facility").change(function() { ChangeProviders(this); });
817 //$("#dayview").click(function() { ChangeView(this); });
818 $("#weekview").click(function() { ChangeView(this); });
819 $("#monthview").click(function() { ChangeView(this); });
820 //$("#yearview").click(function() { ChangeView(this); });
821 $(".tdDatePicker").click(function() { ChangeDate(this); });
822 $(".tdDatePicker").mouseover(function() { $(this).toggleClass("tdDatePickerHighlight"); });
823 $(".tdDatePicker").mouseout(function() { $(this).toggleClass("tdDatePickerHighlight"); });
824 $("#printview").click(function() { PrintView(this); });
825 $(".event").dblclick(function() { EditEvent(this); });
826 $(".event").mouseover(function() { $(this).toggleClass("event_highlight"); });
827 $(".event").mouseout(function() { $(this).toggleClass("event_highlight"); });
828 $(".tdMonthName-small").click(function() {
830 dpCal=$("#datePicker>table");
831 mp = $("#monthPicker"); mp.width(dpCal.width()); mp.toggle();});
834 /* edit an existing event */
835 var EditEvent = function(eObj) {
836 //alert ('editing '+eObj.id);
837 // split the object ID into date and event ID
838 objID = eObj.id;
839 var parts = new Array();
840 parts = objID.split("-");
841 // call the oldEvt function to bring up the event editor
842 oldEvt(parts[0], parts[1], parts[2]);
843 return true;
846 /* change the current date based upon what the user clicked in
847 * the datepicker DIV
849 var ChangeDate = function(eObj) {
850 baseURL = "[-php-]echo pnModURL(__POSTCALENDAR__,'user','view',
851 array('tplview'=>$template_view,
852 'viewtype'=>$viewtype,
853 'Date'=> '~REPLACEME~',
854 'pc_username'=>$pc_username,
855 'pc_category'=>$category,
856 'pc_topic'=>$topic));[-/php-]";
857 newURL = baseURL.replace(/~REPLACEME~/, eObj.id);
858 document.location.href=newURL;
861 /* pop up a window to print the current view
863 var PrintView = function (eventObject) {
864 printURL = "[-php-]echo pnModURL(__POSTCALENDAR__,'user','view',
865 array('tplview'=>$template_view,
866 'viewtype'=>$viewtype,
867 'Date'=> $Date,
868 'print'=> 1,
869 'pc_username'=>$pc_username,
870 'pc_category'=>$category,
871 'pc_topic'=>$topic));[-/php-]";
872 window.open(printURL,'printwindow','width=740,height=480,toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=no,resizable=yes');
873 return false;
876 /* change the provider(s)
878 var ChangeProviders = function (eventObject) {
879 $('#theform').submit();
882 /* change the calendar view
884 var ChangeView = function (eventObject) {
885 if (eventObject.id == "dayview") {
886 $("#viewtype").val('day');
888 else if (eventObject.id == "weekview") {
889 $("#viewtype").val('week');
891 else if (eventObject.id == "monthview") {
892 $("#viewtype").val('month');
894 else if (eventObject.id == "yearview") {
895 $("#viewtype").val('year');
897 $('#theform').submit();
900 </script>
903 </html>