separating facility from user maintenance, improved support for multiple facilities...
[openemr.git] / interface / main / calendar / modules / PostCalendar / pntemplates / default / views / week / ajax_template.html
blob9598ac83e2431cd1deccdf57df3565ba23e0cb1b
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 + '&starttimem=' + starttimem +
37 '&date=' + eventdate + '&userid=' + providerid + '&catid=' + catid,
38 '_blank', 550, 270);
41 function oldEvt(eventdate, eventid) {
42 dlgopen('add_edit_event.php?date='+eventdate+'&eid=' + eventid, '_blank', 550, 270);
45 function goPid(pid) {
46 top.restoreSession();
47 [-php-]
48 if ($GLOBALS['concurrent_layout'])
50 if( $GLOBALS['dutchpc'] )
52 echo " top.RTop.location = '../../patient_file/summary/demographics_dutch.php' " .
53 "+ '?set_pid=' + pid;\n";
54 } else
56 echo " top.RTop.location = '../../patient_file/summary/demographics.php' " .
57 "+ '?set_pid=' + pid;\n";
60 } else {
61 echo " top.location = '../../patient_file/patient_file.php' " .
62 "+ '?set_pid=' + pid + '&pid=' + pid;\n";
64 [-/php-]
67 function GoToToday(theForm){
68 var todays_date = new Date();
69 var theMonth = todays_date.getMonth() + 1;
70 theMonth = theMonth < 10 ? "0" + theMonth : theMonth;
71 theForm.jumpdate.value = todays_date.getFullYear() + "-" + theMonth + "-" + todays_date.getDate();
72 top.restoreSession();
73 theForm.submit();
76 </script>
78 [-php-]
80 // this is my proposed setting in the globals config file so we don't
81 // need to mess with altering the pn database AND the config file
82 //pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', $GLOBALS['schedule_dow_start']);
84 // build a day-of-week (DOW) list so we may properly build the calendars later in this code
85 $DOWlist = array();
86 $tmpDOW = pnModGetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
87 // bound check and auto-correction
88 if ($tmpDOW <0 || $tmpDOW >6) {
89 pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', '0');
90 $tmpDOW = 0;
92 while (count($DOWlist) < 7) {
93 array_push($DOWlist, $tmpDOW);
94 $tmpDOW++;
95 if ($tmpDOW > 6) $tmpDOW = 0;
98 // A_CATEGORY is an ordered array of associative-array categories.
99 // Keys of interest are: id, name, color, desc, event_duration.
101 // echo "<!-- A_CATEGORY = "; print_r($this->_tpl_vars['A_CATEGORY']); echo " -->\n"; // debugging
102 // echo "<!-- A_EVENTS = "; print_r($this->_tpl_vars['A_EVENTS']); echo " -->\n"; // debugging
104 $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY'];
106 // [-if $PRINT_VIEW != 1-]
107 // [-*Main Navigation*-]
108 // [-include file="$TPL_NAME/views/global/navigation.html"-]
109 // [-/if-]
111 $A_EVENTS =& $this->_tpl_vars['A_EVENTS'];
112 $providers =& $this->_tpl_vars['providers'];
113 $times =& $this->_tpl_vars['times'];
114 $interval = $this->_tpl_vars['interval'];
115 $viewtype = $this->_tpl_vars['VIEW_TYPE'];
116 $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL'];
117 $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL'];
118 $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL'];
119 $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL'];
121 $Date = postcalendar_getDate();
122 if (!isset($y)) $y = substr($Date, 0, 4);
123 if (!isset($m)) $m = substr($Date, 4, 2);
124 if (!isset($d)) $d = substr($Date, 6, 2);
126 // echo "<!-- There are " . count($A_EVENTS) . " A_EVENTS days -->\n";
128 //==================================
129 //FACILITY FILTERING (CHEMED)
130 $facilities = getUserFacilities($_SESSION['authId']); // from users_facility
131 if (count($facilities) == 1 || !$_SESSION['pc_facility']) {
132 $_SESSION['pc_facility'] = $facilities[0]['id'];
134 if ( $_SESSION['pc_facility'] ) {
135 $provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']);
136 } else {
137 $provinfo = getProviderInfo();
139 //EOS FACILITY FILTERING (CHEMED)
140 //==================================
142 [-/php-]
144 <div id="functions">
145 <!-- stuff form element here to avoid the margin padding it introduces into the page in some browsers -->
146 <form name='theform' id='theform' action='index.php?module=PostCalendar&func=view&tplview=default&pc_category=&pc_topic=' method='post' onsubmit='return top.restoreSession()'>
147 <input type="hidden" name="jumpdate" id="jumpdate" value="">
148 <input type="hidden" name="viewtype" id="viewtype" value="[-php-]echo $viewtype;[-/php-]">
149 [-php-]
150 echo " <input type='button' value='" .xl ("Add"). "' onclick='newEvt(1, 9, 00, $Date, 0, 0)' />\n";
151 echo " <input type='button' value='" . xl ("Search") .
152 "' onclick='top.restoreSession();location=\"index.php?module=PostCalendar&func=search\"' />\n";
153 [-/php-]
154 </div>
156 <div id="topToolbarRight"> <!-- this wraps some of the top toolbar items -->
158 <div id="dateNAV">
159 <a href='[-php-]echo $PREV_WEEK_URL[-/php-]' onclick='top.restoreSession()'>
160 <img id="prevweek" src="[-$TPL_IMAGE_PATH-]/leftbtn.gif" border="0" title="[-php-]echo xl("Previous Week")[-/php-]" alt="[-php-]echo xl ("Previous Week")[-/php-]" /></a>
161 <a href='[-php-]echo $NEXT_WEEK_URL[-/php-]' onclick='top.restoreSession()'>
162 <img id="nextweek" src="[-$TPL_IMAGE_PATH-]/rightbtn.gif" border="0" title="[-php-]echo xl("Next Week")[-/php-]" alt="[-php-]echo xl ("Next Week")[-/php-]" /></a>
163 &nbsp;
164 <input type='submit' name='bnsubmit' value='[-php-]echo xl ("Today")[-/php-]' onClick='GoToToday(theform);' />
165 </div>
167 <div id="viewPicker">
168 <img id="printview" src="[-$TPL_IMAGE_PATH-]/print.gif" border="0" title="[-php-]echo xl("Print View")[-/php-]" alt="[-php-]echo xl ("Print View")[-/php-]" />
169 &nbsp;
170 <img id="dayview" src="[-$TPL_IMAGE_PATH-]/day.gif" border="0" title="[-php-]echo xl("Day View")[-/php-]" alt="[-php-]echo xl ("Day View")[-/php-]" />
171 &nbsp;
172 <img id="weekview" class="currentview" src="[-$TPL_IMAGE_PATH-]/week.gif" border="0" title="[-php-]echo xl ("Week View")[-/php-]" alt="[-php-]echo xl ("Week View")[-/php-]" />
173 &nbsp;
174 <img id="monthview" src="[-$TPL_IMAGE_PATH-]/month.gif" border="0" title="[-php-]echo xl ("Month View")[-/php-]" alt="[-php-]echo xl ("Month View")[-/php-]" />
175 </div>
176 </div> <!-- end topToolbarRight -->
178 <div id="datePicker">
180 <table border="0" cellpadding="0" cellspacing="0">
181 <tr>
182 [-php-]
183 $atmp = array_keys($A_EVENTS);
184 $caldate = strtotime($atmp[0]);
185 $cMonth = date("m", $caldate);
186 $cYear = date("Y", $caldate);
187 $cDay = date("d", $caldate);
189 // compute the previous month date
190 // stay on the same day if possible
191 $pDay = $cDay;
192 $pMonth = $cMonth - 1;
193 $pYear = $cYear;
194 if ($pMonth < 1) { $pMonth = 12; $pYear = $cYear - 1; }
195 while (! checkdate($pMonth, $pDay, $pYear)) { $pDay = $pDay - 1; }
196 $prevMonth = sprintf("%d%02d%02d",$pYear,$pMonth,$pDay);
198 // compute the next month
199 // stay on the same day if possible
200 $nDay = $cDay;
201 $nMonth = $cMonth + 1;
202 $nYear = $cYear;
203 if ($nMonth > 12) { $nMonth = 1; $nYear = $cYear + 1; }
204 while (! checkdate($nMonth, $nDay, $nYear)) { $nDay = $nDay - 1; }
205 $nextMonth = sprintf("%d%02d%02d",$nYear,$nMonth,$nDay);
206 [-/php-]
207 <td class="tdDOW-small tdDatePicker tdNav" id="[-php-]echo $prevMonth[-/php-]" title="[-php-]echo date("F", strtotime($prevMonth));[-/php-]">&lt;</td>
208 <td colspan="5" class="tdMonthName-small">
209 [-php-]
210 echo date('F', $caldate);
211 [-/php-]
212 </td>
213 <td class="tdDOW-small tdDatePicker tdNav" id="[-php-]echo $nextMonth[-/php-]" title="[-php-]echo date("F", strtotime($nextMonth));[-/php-]">&gt;</td>
214 <tr>
215 [-php-]
216 foreach ($DOWlist as $dow) {
217 echo "<td class='tdDOW-small'>".$this->_tpl_vars['A_SHORT_DAY_NAMES'][$dow]."</td>";
219 [-/php-]
220 </tr>
221 [-php-]
222 $atmp = array_keys($A_EVENTS);
223 $caldate = strtotime($atmp[0]);
224 $caldateEnd = strtotime($atmp[6]);
226 // to make a complete week row we need to compute the real
227 // start and end dates for the view
228 list ($year, $month, $day) = explode(" ", date('Y m d', $caldate));
229 $startdate = strtotime($year.$month."01");
230 $enddate = strtotime($year.$month.date("t", $startdate)." 23:59");
231 while (date('w', $startdate) != $DOWlist[0]) { $startdate -= 60*60*24; }
232 while (date('w', $enddate) != $DOWlist[6]) { $enddate += 60*60*24; }
234 $currdate = $startdate;
235 while ($currdate <= $enddate) {
236 if (date('w', $currdate) == $DOWlist[0]) {
237 // start of week row
238 $tr = "<tr class='trDateRow'>";
239 echo $tr;
242 // set the TD class
243 $tdClass = "tdMonthDay-small";
244 if (date('m', $currdate) != $month) {
245 $tdClass = "tdOtherMonthDay-small";
247 if ((date('w', $currdate) == 0) || (date('w', $currdate) == 6)) {
248 $tdClass = "tdWeekend-small";
251 if ((date('Ymd',$currdate) >= date('Ymd', $caldate)) &&
252 (date('Ymd',$currdate) <= date('Ymd', $caldateEnd)))
254 // add a class that highlights the 'current date'
255 $tdClass .= " currentWeek";
258 if (date('Ymd',$currdate) == $Date) {
259 // $Date is defined near the top of this file
260 // and is equal to whatever date the user has clicked
261 $tdClass .= " currentDate";
264 // add a class so that jQuery can grab these days for the 'click' event
265 $tdClass .= " tdDatePicker";
267 // output the TD
268 $td = "<td ";
269 $td .= "class=\"".$tdClass."\" ";
270 //$td .= "id=\"".date("Ymd", $currdate)."\" ";
271 $td .= "id=\"".date("Ymd", $currdate)."\" ";
272 $td .= "title=\"Go to week of ".date('M d, Y', $currdate)."\" ";
273 $td .= "> ".date('d', $currdate)."</td>\n";
274 echo $td;
276 // end of week row
277 if (date('w', $currdate) == $DOWlist[6]) echo "</tr>\n";
279 // time correction = plus 1000 seconds, for some unknown reason
280 $currdate += (60*60*24)+1000;
282 [-/php-]
283 </table>
284 </div>
286 <div id="bigCalHeader">
287 [-php-]
288 $atmp = array_keys($A_EVENTS);
289 echo date('d M Y', strtotime($atmp[0]));
290 echo " - ";
291 echo date('d M Y', strtotime($atmp[count($atmp)-1]));
292 [-/php-]
293 </div>
295 <div id="providerPicker">
296 Providers
297 <div>
298 [-php-]
299 // ==============================
300 // FACILITY FILTERING (lemonsoftware)
301 // $facilities = getFacilities();
302 if ($_SESSION['authorizeduser'] == 1) {
303 $facilities = getFacilities();
304 } else {
305 $facilities = getUserFacilities($_SESSION['authId']); // from users_facility
306 if (count($facilities) == 1)
307 $_SESSION['pc_facility'] = key($facilities);
309 if (count($facilities) > 1) {
310 echo " <select name='pc_facility' id='pc_facility'>\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 value='" .$fa['id']. "' $selected>" .$fa['name']. "</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'>\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 ">" . $doc['lname'] . ", " . $doc['fname'] . "</option>\n";
332 echo " </select>\n";
334 [-/php-]
335 </div>
337 </form>
339 [-assign var="dayname" value=$DATE|date_format:"%w"-]
340 [-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-]
341 [-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-]
342 [-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-]
344 <div id="bigCal">
345 [-php-]
346 /* used in debugging
347 foreach ($A_EVENTS as $date => $events) {
348 echo $date." = ";
349 foreach ($events as $oneE) {
350 print_r($oneE);
351 echo "<br><br>";
353 echo "<hr width=100%>";
358 // This loops once for each provider to be displayed.
360 foreach ($providers as $provider) {
361 $providerid = $provider['id'];
363 // to specially handle the IN/OUT events I'm doing something new here
364 // for each IN event it will have a duration lasting until the next
365 // OUT event or until the end of the day
366 $tmpTime = $times[0];
367 $calStartMin = ($tmpTime['hour'] * 60) + $tmpTime['minute'];
368 $tmpTime = $times[count($times)-1];
369 $calEndMin = ($tmpTime['hour'] * 60) + $tmpTime['minute'];
371 echo "<table border='0' cellpadding='1' cellspacing='0' width='100%'>\n";
372 echo " <tr>\n";
373 echo " <td colspan='8' class='providerheader'>";
374 echo $provider['fname'] . " " . $provider['lname'];
375 echo "</td>\n";
376 echo " </tr>\n";
378 // output column (date) headers
379 $colWidth = 100/7; // intentionally '7' and not '8'
380 echo " <tr>\n";
381 echo " <td>&nbsp;</td>"; // blank TD for the header above the Times column
382 $defaultDate = ""; // used when creating link for a 'new' event
383 $in_cat_id = 0; // used when creating link for a 'new' event
384 foreach ($A_EVENTS as $date => $events) {
385 $dateFmt = date("Ymd", strtotime($date));
386 $gotoURL = pnModURL(__POSTCALENDAR__,'user','view',
387 array('tplview'=>$template_view,
388 'viewtype'=>'day',
389 'Date'=> $dateFmt,
390 'pc_username'=>$pc_username,
391 'pc_category'=>$category,
392 'pc_topic'=>$topic));
393 if ($defaultDate == "") $defaultDate = $dateFmt;
394 $currclass = "";
395 if ($Date == $dateFmt) { $currclass= "week_currday"; }
396 echo "<td align='center' class='week_dateheader $currclass' style='width:".$colWidth."%;' >";
397 echo "<a href='$gotoURL'>";
398 echo date("D m/d", strtotime($date));
399 echo "</a></td>";
401 echo " </tr>\n";
403 // output the TD with the times DIV
404 echo "<tr>";
405 echo "<td id='times'><div><table>\n";
406 foreach ($times as $slottime) {
407 $startampm = ($slottime['mer']) == "pm" ? 2 : 1;
408 $starttimeh = $slottime['hour'];
409 $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh;
410 $starttimem = $slottime['minute'];
411 $slotendmins = $starttimeh * 60 + $starttimem + $interval;
413 echo "<tr><td class='timeslot'>";
414 // echo "<a href='javascript:newEvt($startampm,$starttimeh,$starttimem,$Date,$providerid,$in_cat_id)' title='New Appointment' alt='New Appointment'>";
415 echo "<a href='javascript:newEvt($startampm,$starttimeh,$starttimem,$defaultDate,$providerid,$in_cat_id)' title='New Appointment' alt='New Appointment'>";
417 //echo $slottime['hour'] * 60 + $slottime['minute'];
418 echo "$disptimeh:$starttimem</a>";
419 echo "</td></tr>\n";
421 echo "</table></div></td>";
423 // For each day...
424 // output a TD with an inner containing DIV positioned 'relative'
425 // within that DIV we place our event DIVs using 'absolute' positioning
426 foreach ($A_EVENTS as $date => $events) {
427 $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2);
429 // having a 'title' for the TD makes the date appear by the mouse pointer
430 // this is nice when all you see are times on the left side and no head
431 // row with the dates or day-of-week (DOW)
432 echo "<td class='schedule' title='".date("l, d M Y", strtotime($date))."'>";
433 echo "<div class='calendar_day'>";
435 // determine if events overlap and adjust their width and left position as needed
436 // 26 Feb 2008 - This needs fine tuning or total replacement
437 // - it doesn't work as well as I'd like - JRM
438 $eventPositions = array();
439 foreach ($times as $slottime) {
440 $starttimeh = $slottime['hour'];
441 $starttimem = $slottime['minute'];
443 $slotstartmins = $starttimeh * 60 + $starttimem;
444 $slotendmins = $starttimeh * 60 + $starttimem + $interval;
446 $events_in_timeslot = array();
447 foreach ($events as $e1) {
448 // ignore IN and OUT events
449 if (($e1['catid'] == 2) || ($e1['catid'] == 3)) { continue; }
450 // skip events without an ID (why they are in the loop, I have no idea)
451 if ($e1['eid'] == "") { continue; }
452 // skip events for other providers
453 if ($providerid != $e1['aid']) { continue; }
455 // specially handle all-day events
456 if ($e1['alldayevent'] == 1) {
457 $tmpTime = $times[0];
458 if (strlen($tmpTime['hour']) < 2) { $tmpTime['hour'] = "0".$tmpTime['hour']; }
459 if (strlen($tmpTime['minute']) < 2) { $tmpTime['minute'] = "0".$tmpTime['minute']; }
460 $e1['startTime'] = $tmpTime['hour'].":".$tmpTime['minute'].":00";
461 $e1['duration'] = ($calEndMin - $calStartMin) * 60; // measured in seconds
464 // create a numeric start and end for comparison
465 $starth = substr($e1['startTime'], 0, 2);
466 $startm = substr($e1['startTime'], 3, 2);
467 $e1Start = ($starth * 60) + $startm;
468 $e1End = $e1Start + $e1['duration']/60;
470 // three ways to overlap:
471 // start-in, end-in, span
472 if ((($e1Start >= $slotstartmins) && ($e1Start < $slotendmins)) // start-in
473 || (($e1End > $slotstartmins) && ($e1End <= $slotendmins)) // end-in
474 || (($e1Start < $slotstartmins) && ($e1End > $slotendmins))) // span
476 array_push($events_in_timeslot, $e1['eid']);
480 $leftpos = 0;
481 $width = 100 / count($events_in_timeslot);
483 // loop over the events in this timeslot and adjust their width
484 foreach ($events_in_timeslot as $eid) {
485 // set the width if not already set or if the current width is smaller
486 // than was was previously set
487 if (! isset($eventPositions[$eid]->width)) { $eventPositions[$eid]->width = $width; }
488 else if ($eventPositions[$eid]->width > $width) { $eventPositions[$eid]->width = $width; }
490 // set the left position if not already set or if the current left is
491 // greater than what was previously set
492 if (! isset($eventPositions[$eid]->leftpos)) { $eventPositions[$eid]->leftpos = $leftpos; }
493 else if ($eventPositions[$eid]->leftpos < $leftpos) { $eventPositions[$eid]->leftpos = $leftpos; }
495 // increment the leftpos by the width
496 $leftpos += $width;
498 } // end overlap detection
500 // now loop over the events for the day and output their DIVs
501 foreach ($events as $event) {
502 // skip events for other providers
503 // yeah, we've got that sort of overhead here... it ain't perfect
504 if ($providerid != $event['aid']) { continue; }
506 // skip events without an ID (why they are in the loop, I have no idea)
507 if ($event['eid'] == "") { continue; }
509 // specially handle all-day events
510 if ($event['alldayevent'] == 1) {
511 $tmpTime = $times[0];
512 if (strlen($tmpTime['hour']) < 2) { $tmpTime['hour'] = "0".$tmpTime['hour']; }
513 if (strlen($tmpTime['minute']) < 2) { $tmpTime['minute'] = "0".$tmpTime['minute']; }
514 $event['startTime'] = $tmpTime['hour'].":".$tmpTime['minute'].":00";
515 $event['duration'] = ($calEndMin - $calStartMin) * 60; // measured in seconds
518 // figure the start time and minutes (from midnight)
519 $starth = substr($event['startTime'], 0, 2);
520 $startm = substr($event['startTime'], 3, 2);
521 $eStartMin = $starth * 60 + $startm;
522 $dispstarth = ($starth > 12) ? ($starth - 12) : $starth;
524 // determine the class for the event DIV based on the event category
525 $evtClass = "event_appointment";
526 switch ($event['catid']) {
527 case 1: // NO-SHOW appt
528 $evtClass = "event_noshow";
529 break;
530 case 2: // IN office
531 $evtClass = "event_in";
532 break;
533 case 3: // OUT of office
534 $evtClass = "event_out";
535 break;
536 case 4: // VACATION
537 case 8: // LUNCH
538 case 11: // RESERVED
539 $evtClass = "event_reserved";
540 break;
541 default: // some appointment
542 $evtClass = "event_appointment";
543 break;
546 // if this is an IN or OUT event then we have some extra special
547 // processing to be done
548 // the IN event creates a DIV until the OUT event
549 // or, without an OUT DIV matching the IN event
550 // then the IN event runs until the end of the day
551 if ($event['catid'] == 2) {
552 // locate a matching OUT for this specific IN
553 $found = false;
554 $outMins = 0;
555 foreach ($events as $outevent) {
556 // skip events for other providers
557 if ($providerid != $outevent['aid']) { continue; }
558 // skip events with blank IDs
559 if ($outevent['eid'] == "") { continue; }
561 if ($outevent['eid'] == $event['eid']) { $found = true; continue; }
562 if (($found == true) && ($outevent['catid'] == 3)) {
563 // calculate the duration from this event to the outevent
564 $outH = substr($outevent['startTime'], 0, 2);
565 $outM = substr($outevent['startTime'], 3, 2);
566 $outMins = ($outH * 60) + $outM;
567 $event['duration'] = ($outMins - $eStartMin) * 60; // duration is in seconds
568 $found = 2;
569 break;
572 if ($outMins == 0) {
573 // no OUT was found so this event's duration goes
574 // until the end of the day
575 $event['duration'] = ($calEndMin - $eStartMin) * 60; // duration is in seconds
579 // calculate the TOP value for the event DIV
580 // diff between event start and schedule start
581 $eMinDiff = $eStartMin - $calStartMin;
582 // diff divided by the time interval of the schedule
583 $eStartInterval = $eMinDiff / $interval;
584 // times the interval height
585 $eStartPos = $eStartInterval * $timeslotHeightVal;
586 $evtTop = $eStartPos.$timeslotHeightUnit;
588 // calculate the HEIGHT value for the event DIV
589 // diff between end and start of event
590 $eEndMin = $eStartMin + ($event['duration']/60);
591 // prevent the overall height of the event from going beyond the bounds
592 // of the time table
593 if ($eEndMin > $calEndMin) { $eEndMin = $calEndMin + $interval; }
594 $eMinDiff = $eEndMin - $eStartMin;
595 // diff divided by the time interval of the schedule
596 $eEndInterval = $eMinDiff / $interval;
597 // times the interval height
598 $eHeight = $eEndInterval * $timeslotHeightVal;
599 $evtHeight = $eHeight.$timeslotHeightUnit;
601 // determine the DIV width based on any overlapping events
602 // see further above for the overlapping calculation code
603 $divWidth = "";
604 $divLeft = "";
605 if (isset($eventPositions[$event['eid']])) {
606 $divWidth = "width: ".$eventPositions[$event['eid']]->width."%";
607 $divLeft = "left: ".$eventPositions[$event['eid']]->leftpos."%";
610 $eventid = $event['eid'];
611 $patientid = $event['pid'];
612 $commapos = strpos($event['patient_name'], ",");
613 $lname = addslashes(ucfirst(strtolower(substr($event['patient_name'], 0, $commapos))));
614 $fname = addslashes(ucfirst(strtolower(substr($event['patient_name'], $commapos + 2))));
615 $patient_dob = $event['patient_dob'];
616 $patient_age = $event['patient_age'];
617 $catid = $event['catid'];
618 $comment = addslashes($event['hometext']);
619 $catname = $event['catname'];
620 $title = "Age $patient_age ($patient_dob)";
622 $content = "";
624 if ($comment && $GLOBALS['calendar_appt_style'] < 4) $title .= " " . $comment;
626 // the divTitle is what appears when the user hovers the mouse over the DIV
627 $divTitle = date("D, d M Y", strtotime($date));
629 if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) {
630 if ($catid == 2) $catname = "IN";
631 else if ($catid == 3) $catname = "OUT";
632 else if ($catid == 4) $catname = "VACATION";
633 else if ($catid == 8) $catname = "LUNCH";
634 else if ($catid == 11) $catname = "RESERVED";
636 $atitle = $catname;
637 if ($comment) $atitle .= " $comment";
638 //$divTitle .= "\n[".$atitle ."] ".$divTitle;
639 $divTitle .= "\n[".$atitle ."]";
640 //$content .= "<a href='javascript:oldEvt($eventdate,$eventid)' title='$atitle'>";
641 $content .= $catname;
642 if ($event['recurrtype'] == 1) $content .= "<img src='$TPL_IMAGE_PATH/repeating8.png' border='0' style='margin:0px 2px 0px 2px;' title='Repeating event' alt='Repeating event'>";
643 if ($comment) $content .= " $comment";
644 //$content .= "</a>";
646 else {
647 // some sort of patient appointment
648 $divTitle .= "\r\n[".$catname ."] ".$fname." ".$lname;
649 $content .= "<span class='appointment".$apptToggle."'>";
650 $content .= $dispstarth . ':' . $startm;
651 if ($event['recurrtype'] == 1) $content .= "<img src='$TPL_IMAGE_PATH/repeating8.png' border='0' style='margin:0px 2px 0px 2px;' title='Repeating event' alt='Repeating event'>";
652 $content .= htmlspecialchars($event['apptstatus']);
653 if ($patientid) {
654 // include patient name and link to their details
655 $link_title = "$fname $lname\n";
656 $link_title .= "Age: ".$patient_age."\nDOB: ".$patient_dob."\n";
657 $link_title .= "(Click to view)";
658 $content .= "<a href='javascript:goPid($patientid)' title='$link_title'>";
659 $content .= "<img src='$TPL_IMAGE_PATH/user-green.gif' border='0' title='$link_title' alt='View Patient' />";
660 $content .= "</a>";
662 else {
663 // no patient id, just output the category name
664 $content .= $catname;
666 $content .= "</span>";
669 $divTitle .= "\n(double click to edit)";
671 // output the DIV and content
672 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
673 "; background-color:".$event["catcolor"].
674 "; $divWidth".
675 "; $divLeft".
676 "' title='".$divTitle."'".
677 " id='".$eventdate."-".$eventid."'".
678 ">";
679 echo $content;
680 echo "</div>\n";
681 } // end EVENT loop
683 echo "</div>";
684 echo "</td>\n";
686 } // end date
688 echo " </tr>\n";
690 echo "</table>\n";
691 echo "<P>";
692 } // end provider
694 // [-*footer*-]
695 // [-include file="$TPL_NAME/views/global/footer.html"-]
696 // [-include file="$TPL_NAME/views/footer.html"-]
698 [-/php-]
699 </div> <!-- end bigCal DIV -->
701 </body>
703 <script language='JavaScript'>
705 $(document).ready(function(){
706 $("#pc_username").change(function() { ChangeProviders(this); });
707 $("#pc_facility").change(function() { ChangeProviders(this); });
708 $("#dayview").click(function() { ChangeView(this); });
709 //$("#weekview").click(function() { ChangeView(this); });
710 $("#monthview").click(function() { ChangeView(this); });
711 //$("#yearview").click(function() { ChangeView(this); });
712 $(".tdDatePicker").click(function() { ChangeDate(this); });
713 $("#datePicker .trDateRow").mouseover(function() { $(this).children().toggleClass("tdDatePickerHighlight"); });
714 $("#datePicker .trDateRow").mouseout(function() { $(this).children().toggleClass("tdDatePickerHighlight"); });
715 $("#datePicker .tdNav").mouseover(function() { $(this).toggleClass("tdDatePickerHighlight"); });
716 $("#datePicker .tdNav").mouseout(function() { $(this).toggleClass("tdDatePickerHighlight"); });
717 $("#printview").click(function() { PrintView(this); });
718 $(".event").dblclick(function() { EditEvent(this); });
719 $(".event").mouseover(function() { $(this).toggleClass("event_highlight"); });
720 $(".event").mouseout(function() { $(this).toggleClass("event_highlight"); });
723 /* edit an existing event */
724 var EditEvent = function(eObj) {
725 //alert ('editing '+eObj.id);
726 // split the object ID into date and event ID
727 objID = eObj.id;
728 var parts = new Array();
729 parts = objID.split("-");
730 // call the oldEvt function to bring up the event editor
731 oldEvt(parts[0], parts[1]);
732 return true;
735 /* change the current date based upon what the user clicked in
736 * the datepicker DIV
738 var ChangeDate = function(eObj) {
739 baseURL = "[-php-]echo pnModURL(__POSTCALENDAR__,'user','view',
740 array('tplview'=>$template_view,
741 'viewtype'=>$viewtype,
742 'Date'=> '~REPLACEME~',
743 'pc_username'=>$pc_username,
744 'pc_category'=>$category,
745 'pc_topic'=>$topic));[-/php-]";
746 newURL = baseURL.replace(/~REPLACEME~/, eObj.id);
747 document.location.href=newURL;
750 /* pop up a window to print the current view
752 var PrintView = function (eventObject) {
753 printURL = "[-php-]echo pnModURL(__POSTCALENDAR__,'user','view',
754 array('tplview'=>$template_view,
755 'viewtype'=>$viewtype,
756 'Date'=> $Date,
757 'print'=> 1,
758 'pc_username'=>$pc_username,
759 'pc_category'=>$category,
760 'pc_topic'=>$topic));[-/php-]";
761 window.open(printURL,'printwindow','width=740,height=480,toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=no,resizable=yes');
762 return false;
765 /* change the provider(s)
767 var ChangeProviders = function (eventObject) {
768 $('#theform').submit();
771 /* change the calendar view
773 var ChangeView = function (eventObject) {
774 if (eventObject.id == "dayview") {
775 $("#viewtype").val('day');
777 else if (eventObject.id == "weekview") {
778 $("#viewtype").val('week');
780 else if (eventObject.id == "monthview") {
781 $("#viewtype").val('month');
783 else if (eventObject.id == "yearview") {
784 $("#viewtype").val('year');
786 $('#theform').submit();
789 </script>
792 </html>