7b06e445ecb9acb88b7a9d064da9dd62fe6cb631
[openemr.git] / interface / main / calendar / modules / PostCalendar / pntemplates / default / views / day / ajax_template.html
blob7b06e445ecb9acb88b7a9d064da9dd62fe6cb631
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 and OUT events
431 if (($e1['catid'] == 2) || ($e1['catid'] == 3)) { continue; }
432 // skip events without an ID (why they are in the loop, I have no idea)
433 if ($e1['eid'] == "") { continue; }
434 // skip events for other providers
435 if ($providerid != $e1['aid']) { continue; }
437 // specially handle all-day events
438 if ($e1['alldayevent'] == 1) {
439 $tmpTime = $times[0];
440 if (strlen($tmpTime['hour']) < 2) { $tmpTime['hour'] = "0".$tmpTime['hour']; }
441 if (strlen($tmpTime['minute']) < 2) { $tmpTime['minute'] = "0".$tmpTime['minute']; }
442 $e1['startTime'] = $tmpTime['hour'].":".$tmpTime['minute'].":00";
443 $e1['duration'] = ($calEndMin - $calStartMin) * 60; // measured in seconds
446 // create a numeric start and end for comparison
447 $starth = substr($e1['startTime'], 0, 2);
448 $startm = substr($e1['startTime'], 3, 2);
449 $e1Start = ($starth * 60) + $startm;
450 $e1End = $e1Start + $e1['duration']/60;
452 // three ways to overlap:
453 // start-in, end-in, span
454 if ((($e1Start >= $slotstartmins) && ($e1Start < $slotendmins)) // start-in
455 || (($e1End > $slotstartmins) && ($e1End <= $slotendmins)) // end-in
456 || (($e1Start < $slotstartmins) && ($e1End > $slotendmins))) // span
458 array_push($events_in_timeslot, $e1['eid']);
461 $leftpos = 0;
462 $width = 100 / count($events_in_timeslot);
464 // loop over the events in this timeslot and adjust their width
465 foreach ($events_in_timeslot as $eid) {
466 // set the width if not already set or if the current width is smaller
467 // than was was previously set
468 if (! isset($eventPositions[$eid]->width)) { $eventPositions[$eid]->width = $width; }
469 else if ($eventPositions[$eid]->width > $width) { $eventPositions[$eid]->width = $width; }
471 // set the left position if not already set or if the current left is
472 // greater than what was previously set
473 if (! isset($eventPositions[$eid]->leftpos)) { $eventPositions[$eid]->leftpos = $leftpos; }
474 else if ($eventPositions[$eid]->leftpos < $leftpos) { $eventPositions[$eid]->leftpos = $leftpos; }
476 // increment the leftpos by the width
477 $leftpos += $width;
479 } // end overlap detection
481 // now loop over the events for the day and output their DIVs
482 foreach ($events as $event) {
483 // skip events for other providers
484 // yeah, we've got that sort of overhead here... it ain't perfect
485 if ($providerid != $event['aid']) { continue; }
487 // skip events without an ID (why they are in the loop, I have no idea)
488 if ($event['eid'] == "") { continue; }
490 // specially handle all-day events
491 if ($event['alldayevent'] == 1) {
492 $tmpTime = $times[0];
493 if (strlen($tmpTime['hour']) < 2) { $tmpTime['hour'] = "0".$tmpTime['hour']; }
494 if (strlen($tmpTime['minute']) < 2) { $tmpTime['minute'] = "0".$tmpTime['minute']; }
495 $event['startTime'] = $tmpTime['hour'].":".$tmpTime['minute'].":00";
496 $event['duration'] = ($calEndMin - $calStartMin) * 60; // measured in seconds
499 // figure the start time and minutes (from midnight)
500 $starth = substr($event['startTime'], 0, 2);
501 $startm = substr($event['startTime'], 3, 2);
502 $eStartMin = $starth * 60 + $startm;
503 $dispstarth = ($starth > 12) ? ($starth - 12) : $starth; // used to display the hour
505 // determine the class for the event DIV based on the event category
506 $evtClass = "event_appointment";
507 switch ($event['catid']) {
508 case 1: // NO-SHOW appt
509 $evtClass = "event_noshow";
510 break;
511 case 2: // IN office
512 $evtClass = "event_in";
513 break;
514 case 3: // OUT of office
515 $evtClass = "event_out";
516 break;
517 case 4: // VACATION
518 case 8: // LUNCH
519 case 11: // RESERVED
520 $evtClass = "event_reserved";
521 break;
522 default: // some appointment
523 $evtClass = "event_appointment";
524 break;
527 // if this is an IN or OUT event then we have some extra special
528 // processing to be done
529 // the IN event creates a DIV until the OUT event
530 // or, without an OUT DIV matching the IN event
531 // then the IN event runs until the end of the day
532 if ($event['catid'] == 2) {
533 // locate a matching OUT for this specific IN
534 $found = false;
535 $outMins = 0;
536 foreach ($events as $outevent) {
537 // skip events for other providers
538 if ($providerid != $outevent['aid']) { continue; }
539 // skip events with blank IDs
540 if ($outevent['eid'] == "") { continue; }
542 if ($outevent['eid'] == $event['eid']) { $found = true; continue; }
543 if (($found == true) && ($outevent['catid'] == 3)) {
544 // calculate the duration from this event to the outevent
545 $outH = substr($outevent['startTime'], 0, 2);
546 $outM = substr($outevent['startTime'], 3, 2);
547 $outMins = ($outH * 60) + $outM;
548 $event['duration'] = ($outMins - $eStartMin) * 60; // duration is in seconds
549 $found = 2;
550 break;
553 if ($outMins == 0) {
554 // no OUT was found so this event's duration goes
555 // until the end of the day
556 $event['duration'] = ($calEndMin - $eStartMin) * 60; // duration is in seconds
560 // calculate the TOP value for the event DIV
561 // diff between event start and schedule start
562 $eMinDiff = $eStartMin - $calStartMin;
563 // diff divided by the time interval of the schedule
564 $eStartInterval = $eMinDiff / $interval;
565 // times the interval height
566 $eStartPos = $eStartInterval * $timeslotHeightVal;
567 $evtTop = $eStartPos.$timeslotHeightUnit;
569 // calculate the HEIGHT value for the event DIV
570 // diff between end and start of event
571 $eEndMin = $eStartMin + ($event['duration']/60);
572 // prevent the overall height of the event from going beyond the bounds
573 // of the time table
574 if ($eEndMin > $calEndMin) { $eEndMin = $calEndMin + $interval; }
575 $eMinDiff = $eEndMin - $eStartMin;
576 // diff divided by the time interval of the schedule
577 $eEndInterval = $eMinDiff / $interval;
578 // times the interval height
579 $eHeight = $eEndInterval * $timeslotHeightVal;
580 $evtHeight = $eHeight.$timeslotHeightUnit;
582 // determine the DIV width based on any overlapping events
583 // see further above for the overlapping calculation code
584 $divWidth = "";
585 $divLeft = "";
586 if (isset($eventPositions[$event['eid']])) {
587 $divWidth = "width: ".$eventPositions[$event['eid']]->width."%";
588 $divLeft = "left: ".$eventPositions[$event['eid']]->leftpos."%";
591 $eventid = $event['eid'];
592 $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."'");
593 $pccattype = '';
594 if($eventtype['pc_cattype']==1)
595 $pccattype = 'true';
596 $patientid = $event['pid'];
597 $commapos = strpos($event['patient_name'], ",");
598 $lname = substr($event['patient_name'], 0, $commapos);
599 $fname = substr($event['patient_name'], $commapos + 2);
600 $patient_dob = $event['patient_dob'];
601 $patient_age = $event['patient_age'];
602 $catid = $event['catid'];
603 $comment = addslashes($event['hometext']);
604 $catname = $event['catname'];
605 $title = "Age $patient_age ($patient_dob)";
607 $content = "";
609 if ($comment && $GLOBALS['calendar_appt_style'] < 4) $title .= " " . $comment;
611 // the divTitle is what appears when the user hovers the mouse over the DIV
612 $divTitle = htmlspecialchars($provider["fname"],ENT_QUOTES)." ".htmlspecialchars($provider["lname"],ENT_QUOTES);
613 $result = sqlStatement("SELECT name,id,color FROM facility WHERE id=(SELECT pc_facility FROM openemr_postcalendar_events WHERE pc_eid=".$eventid.")");
614 $row = sqlFetchArray($result);
615 $color=$event["catcolor"];
616 if($GLOBALS['event_color']==2)
617 $color=$row['color'];
618 $divTitle .= "\n" .htmlspecialchars($row['name'],ENT_QUOTES);
620 if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) {
621 if ($catid == 2) $catname = xl("IN");
622 else if ($catid == 3) $catname = xl("OUT");
623 else if ($catid == 4) $catname = xl("VACATION");
624 else if ($catid == 8) $catname = xl("LUNCH");
625 else if ($catid == 11) $catname = xl("RESERVED");
627 $atitle = $catname;
628 if ($comment) $atitle .= " $comment";
629 $divTitle .= "\n[".$atitle ."]";
630 $content .= $catname;
631 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)."'>";
632 if ($comment) $content .= " $comment";
634 else {
635 // some sort of patient appointment
636 $divTitle .= "\r\n[".$catname.' '.htmlspecialchars($comment, ENT_QUOTES) ."]".htmlspecialchars($fname, ENT_QUOTES)." ".htmlspecialchars($lname, ENT_QUOTES);
637 $content .= "<span class='appointment'>";
638 $content .= $dispstarth . ':' . $startm;
639 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)."'>";
640 // $content .= htmlspecialchars($event['apptstatus']);
641 $content .= '&nbsp;'.htmlspecialchars($event['apptstatus']);
642 if ($patientid) {
643 $link_title = htmlspecialchars($fname,ENT_QUOTES)." ".htmlspecialchars($lname,ENT_QUOTES). " \n";
644 $link_title .= xl('Age') . ": ".$patient_age."\n" . xl('DOB') . ": ".$patient_dob.htmlspecialchars($comment, ENT_QUOTES)."\n";
645 $link_title .= "(" . xl('Click to view') . ")";
646 $content .= "<a href='javascript:goPid($patientid)' title='$link_title'>";
647 $content .= "<img src='$TPL_IMAGE_PATH/user-green.gif' border='0' title='$link_title' alt='View Patient' />";
648 if ($catid == 1) $content .= "<strike>";
649 $content .= htmlspecialchars($lname);
650 if ($GLOBALS['calendar_appt_style'] != 1) {
651 $content .= "," . htmlspecialchars($fname);
652 if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) {
653 $content .= "(" . $event['title'];
654 if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4)
655 $content .= ": <font color='green'>" . htmlspecialchars(trim($event['hometext'])) . "</font>";
656 $content .= ")";
659 if ($catid == 1) $content .= "</strike>";
660 $content .= "</a>";
662 else {
663 // no patient id, just output the category name
664 $content .= $catname;
666 $content .= "</span>";
669 $divTitle .= "\n(" . xl('double click to edit') . ")";
671 if($_SESSION['pc_facility'] == 0){
672 // a special case for the 'IN' event this puts the time ABOVE
673 // the normal DIV so it doesn't overlap another event DIV and include the time
674 if ($event['catid'] == 2) {
675 $inTop = ($eStartPos - $timeslotHeightVal).$timeslotHeightUnit;
676 echo "<div class='".$evtClass." event' style='top:".$inTop.
677 "; height:".$timeslotHeightVal.$timeslotHeightUnit.
678 "; $divWidth".
679 "; $divLeft".
680 "; background:transparent".
681 "; border: none".
682 "' title='".$divTitle."'".
683 " id='".$eventdate."-".$eventid."-".$pccattype."'".
684 ">";
685 $content = $dispstarth . ':' . $startm . " " . $content;
686 echo $content;
687 echo "</div>\n";
690 // output the DIV and content
691 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
692 "; background-color:".$color.
693 "; $divWidth".
694 "; $divLeft".
695 "' title='".$divTitle."'".
696 " id='".$eventdate."-".$eventid."-".$pccattype."'".
697 ">";
698 // second part for the special IN event
699 if ($event['catid'] != 2) { echo $content; }
700 echo "</div>\n";
702 elseif($_SESSION['pc_facility'] == $row['id']){
703 if ($event['catid'] == 2) {
704 $inTop = ($eStartPos - $timeslotHeightVal).$timeslotHeightUnit;
705 echo "<div class='".$evtClass." event' style='top:".$inTop.
706 "; height:".$timeslotHeightVal.$timeslotHeightUnit.
707 "; $divWidth".
708 "; $divLeft".
709 "; background:transparent".
710 "; border: none".
711 "' title='".$divTitle."'".
712 " id='".$eventdate."-".$eventid."-".$pccattype."'".
713 ">";
714 $content = $dispstarth . ':' . $startm . " " . $content;
715 echo $content;
716 echo "</div>\n";
719 // output the DIV and content
720 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
721 "; background-color:".$event["catcolor"].
722 "; $divWidth".
723 "; $divLeft".
724 "' title='".$divTitle."'".
725 " id='".$eventdate."-".$eventid."-".$pccattype."'".
726 ">";
727 // second part for the special IN event
728 if ($event['catid'] != 2) { echo $content; }
729 echo "</div>\n";
731 else{
733 if ($event['catid'] == 2) {
734 $inTop = ($eStartPos - $timeslotHeightVal).$timeslotHeightUnit;
735 echo "<div class='".$evtClass." event' style='top:".$inTop.
736 "; height:".$timeslotHeightVal.$timeslotHeightUnit.
737 "; $divWidth".
738 "; $divLeft".
739 "; background:#DDDDDD".
740 "; border: none".
741 "' title='".$divTitle."'".
742 " id='".$eventdate."-".$eventid."-".$pccattype."'".
743 ">";
744 $content = "<span style='color:red;text-align:center;font-weight:bold'>".htmlspecialchars($row['name'],ENT_QUOTES)."</span>";
745 echo $content;
746 echo "</div>\n";
749 // output the DIV and content
750 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
751 "; background-color:#DDDDDD".
752 "; $divWidth".
753 "; $divLeft".
754 "' title='".$divTitle."'".
755 " id='".$eventdate."-".$eventid."-".$pccattype."'".
756 ">";
757 // second part for the special IN event
758 if ($event['catid'] != 2) { echo "<span style='color:red;text-align:center;font-weight:bold'>".htmlspecialchars($row['name'],ENT_QUOTES)."</span>"; }
759 echo "</div>\n";
761 } // end EVENT loop
763 echo "</div>";
765 } // end date
767 echo "</td>\n";
769 } // end provider loop
770 //============================================================================================================================
771 echo " </tr>\n";
772 echo "</table>\n";
773 echo "<P>";
775 // [-*footer*-]
776 // [-include file="$TPL_NAME/views/global/footer.html"-]
777 // [-include file="$TPL_NAME/views/footer.html"-]
779 [-/php-]
780 </div> <!-- end bigCal DIV -->
781 </div> <!-- end bottom DIV -->
782 </body>
784 <script language='JavaScript'>
785 var tsHeight='[-php-] echo $timeslotHeightVal.$timeslotHeightUnit; [-/php-]';
786 var tsHeightNum=[-php-] echo $timeslotHeightVal; [-/php-];
788 $(document).ready(function(){
789 setupDirectTime();
790 $("#pc_username").change(function() { ChangeProviders(this); });
791 $("#pc_facility").change(function() { ChangeProviders(this); });
792 //$("#dayview").click(function() { ChangeView(this); });
793 $("#weekview").click(function() { ChangeView(this); });
794 $("#monthview").click(function() { ChangeView(this); });
795 //$("#yearview").click(function() { ChangeView(this); });
796 $(".tdDatePicker").click(function() { ChangeDate(this); });
797 $(".tdDatePicker").mouseover(function() { $(this).toggleClass("tdDatePickerHighlight"); });
798 $(".tdDatePicker").mouseout(function() { $(this).toggleClass("tdDatePickerHighlight"); });
799 $("#printview").click(function() { PrintView(this); });
800 $(".event").dblclick(function() { EditEvent(this); });
801 $(".event").mouseover(function() { $(this).toggleClass("event_highlight"); });
802 $(".event").mouseout(function() { $(this).toggleClass("event_highlight"); });
803 $(".tdMonthName-small").click(function() {
805 dpCal=$("#datePicker>table");
806 mp = $("#monthPicker"); mp.width(dpCal.width()); mp.toggle();});
809 /* edit an existing event */
810 var EditEvent = function(eObj) {
811 //alert ('editing '+eObj.id);
812 // split the object ID into date and event ID
813 objID = eObj.id;
814 var parts = new Array();
815 parts = objID.split("-");
816 // call the oldEvt function to bring up the event editor
817 oldEvt(parts[0], parts[1], parts[2]);
818 return true;
821 /* change the current date based upon what the user clicked in
822 * the datepicker DIV
824 var ChangeDate = function(eObj) {
825 baseURL = "[-php-]echo pnModURL(__POSTCALENDAR__,'user','view',
826 array('tplview'=>$template_view,
827 'viewtype'=>$viewtype,
828 'Date'=> '~REPLACEME~',
829 'pc_username'=>$pc_username,
830 'pc_category'=>$category,
831 'pc_topic'=>$topic));[-/php-]";
832 newURL = baseURL.replace(/~REPLACEME~/, eObj.id);
833 document.location.href=newURL;
836 /* pop up a window to print the current view
838 var PrintView = function (eventObject) {
839 printURL = "[-php-]echo pnModURL(__POSTCALENDAR__,'user','view',
840 array('tplview'=>$template_view,
841 'viewtype'=>$viewtype,
842 'Date'=> $Date,
843 'print'=> 1,
844 'pc_username'=>$pc_username,
845 'pc_category'=>$category,
846 'pc_topic'=>$topic));[-/php-]";
847 window.open(printURL,'printwindow','width=740,height=480,toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=no,resizable=yes');
848 return false;
851 /* change the provider(s)
853 var ChangeProviders = function (eventObject) {
854 $('#theform').submit();
857 /* change the calendar view
859 var ChangeView = function (eventObject) {
860 if (eventObject.id == "dayview") {
861 $("#viewtype").val('day');
863 else if (eventObject.id == "weekview") {
864 $("#viewtype").val('week');
866 else if (eventObject.id == "monthview") {
867 $("#viewtype").val('month');
869 else if (eventObject.id == "yearview") {
870 $("#viewtype").val('year');
872 $('#theform').submit();
875 </script>
878 </html>