d2bd5c30a1d89239e355ccfcd7d2c6eff863a404
[openemr.git] / interface / main / calendar / modules / PostCalendar / pntemplates / default / views / week / ajax_template.html
blobd2bd5c30a1d89239e355ccfcd7d2c6eff863a404
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[-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 {
63 echo " top.location = '../../patient_file/patient_file.php' " .
64 "+ '?set_pid=' + pid + '&pid=' + pid;\n";
66 [-/php-]
69 function GoToToday(theForm){
70 var todays_date = new Date();
71 var theMonth = todays_date.getMonth() + 1;
72 theMonth = theMonth < 10 ? "0" + theMonth : theMonth;
73 theForm.jumpdate.value = todays_date.getFullYear() + "-" + theMonth + "-" + todays_date.getDate();
74 top.restoreSession();
75 theForm.submit();
78 </script>
80 [-php-]
82 // this is my proposed setting in the globals config file so we don't
83 // need to mess with altering the pn database AND the config file
84 //pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', $GLOBALS['schedule_dow_start']);
86 // build a day-of-week (DOW) list so we may properly build the calendars later in this code
87 $DOWlist = array();
88 $tmpDOW = pnModGetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
89 // bound check and auto-correction
90 if ($tmpDOW <0 || $tmpDOW >6) {
91 pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', '0');
92 $tmpDOW = 0;
94 while (count($DOWlist) < 7) {
95 array_push($DOWlist, $tmpDOW);
96 $tmpDOW++;
97 if ($tmpDOW > 6) $tmpDOW = 0;
100 // A_CATEGORY is an ordered array of associative-array categories.
101 // Keys of interest are: id, name, color, desc, event_duration.
103 // echo "<!-- A_CATEGORY = "; print_r($this->_tpl_vars['A_CATEGORY']); echo " -->\n"; // debugging
104 // echo "<!-- A_EVENTS = "; print_r($this->_tpl_vars['A_EVENTS']); echo " -->\n"; // debugging
106 $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY'];
108 // [-if $PRINT_VIEW != 1-]
109 // [-*Main Navigation*-]
110 // [-include file="$TPL_NAME/views/global/navigation.html"-]
111 // [-/if-]
113 $A_EVENTS =& $this->_tpl_vars['A_EVENTS'];
114 $providers =& $this->_tpl_vars['providers'];
115 $times =& $this->_tpl_vars['times'];
116 $interval = $this->_tpl_vars['interval'];
117 $viewtype = $this->_tpl_vars['VIEW_TYPE'];
118 $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL'];
119 $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL'];
120 $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL'];
121 $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL'];
123 $Date = postcalendar_getDate();
124 if (!isset($y)) $y = substr($Date, 0, 4);
125 if (!isset($m)) $m = substr($Date, 4, 2);
126 if (!isset($d)) $d = substr($Date, 6, 2);
128 // echo "<!-- There are " . count($A_EVENTS) . " A_EVENTS days -->\n";
130 //==================================
131 //FACILITY FILTERING (CHEMED)
132 $facilities = getUserFacilities($_SESSION['authId']); // from users_facility
133 if ( $_SESSION['pc_facility'] ) {
134 $provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']);
135 } else {
136 $provinfo = getProviderInfo();
138 //EOS FACILITY FILTERING (CHEMED)
139 //==================================
141 [-/php-]
142 <div id="topToolbarRight"> <!-- this wraps some of the top toolbar items -->
143 <div id="functions">
144 <!-- stuff form element here to avoid the margin padding it introduces into the page in some browsers -->
145 <form name='theform' id='theform' action='index.php?module=PostCalendar&func=view&tplview=default&pc_category=&pc_topic=' method='post' onsubmit='return top.restoreSession()'>
146 <input type="hidden" name="jumpdate" id="jumpdate" value="">
147 <input type="hidden" name="viewtype" id="viewtype" value="[-php-]echo $viewtype;[-/php-]">
148 [-php-]
149 echo " <a href='#' value='" .xl ("Add"). "' onclick='newEvt(1, 9, 00, $Date, 0, 0)' class='css_button'/><span>".xl("Add")."</span></a>\n";
150 echo " <a href='#' value='" . xl ("Search") .
151 "' onclick='top.restoreSession();location=\"index.php?module=PostCalendar&func=search\"' class='css_button'/><span>".xl("Search")."</span></a>\n";
152 [-/php-]
153 </div>
156 <div id="dateNAV"">
157 <a href='#' name='bnsubmit' value='[-php-]echo xl ("Today")[-/php-]' onClick='GoToToday(theform);' class='css_button'/><span>[-php-] echo xl("Today")[-/php-]</span></a>
158 <a href='[-php-]echo $PREV_WEEK_URL[-/php-]' onclick='top.restoreSession()'>
159 <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-]" style="padding-top:5px"/></a>
160 <a href='[-php-]echo $NEXT_WEEK_URL[-/php-]' onclick='top.restoreSession()'>
161 <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>
162 &nbsp;
163 [-php-]
164 $atmp = array_keys($A_EVENTS);
165 echo date('d M Y', strtotime($atmp[0]));
166 echo " - ";
167 echo date('d M Y', strtotime($atmp[count($atmp)-1]));
168 [-/php-]
169 </div>
171 <div id="viewPicker">
172 [-php-]
173 echo " <a href='#' type='button' id='printview' title='" .xl ("Print View"). "' class='css_button'/><span>".xl("Print")."</span></a>\n";
174 echo " <a href='#' type='button' value='" .xl ("Refresh"). "' onclick='javascript:refreshme()' class='css_button'/><span>".xl("Refresh")."</span></a>\n";
175 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";
176 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";
177 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";
178 [-/php-]
179 </div>
180 </div> <!-- end topToolbarRight -->
181 <div id="bottom">
182 <div id="bottomLeft">
183 <div id="datePicker">
184 [-php-]
185 $atmp = array_keys($A_EVENTS);
186 $caldate = strtotime($atmp[0]);
187 $cMonth = date("m", $caldate);
188 $cYear = date("Y", $caldate);
189 $cDay = date("d", $caldate);
191 include_once($GLOBALS['webserver_root'].'/interface/main/calendar/modules/PostCalendar/pntemplates/default/views/monthSelector.php');
192 [-/php-]
194 <table border="0" cellpadding="0" cellspacing="0">
195 <tr>
196 [-php-]
198 // compute the previous month date
199 // stay on the same day if possible
200 $pDay = $cDay;
201 $pMonth = $cMonth - 1;
202 $pYear = $cYear;
203 if ($pMonth < 1) { $pMonth = 12; $pYear = $cYear - 1; }
204 while (! checkdate($pMonth, $pDay, $pYear)) { $pDay = $pDay - 1; }
205 $prevMonth = sprintf("%d%02d%02d",$pYear,$pMonth,$pDay);
207 // compute the next month
208 // stay on the same day if possible
209 $nDay = $cDay;
210 $nMonth = $cMonth + 1;
211 $nYear = $cYear;
212 if ($nMonth > 12) { $nMonth = 1; $nYear = $cYear + 1; }
213 while (! checkdate($nMonth, $nDay, $nYear)) { $nDay = $nDay - 1; }
214 $nextMonth = sprintf("%d%02d%02d",$nYear,$nMonth,$nDay);
215 [-/php-]
216 <td class="tdDOW-small tdDatePicker tdNav" id="[-php-]echo $prevMonth[-/php-]" title="[-php-]echo xl(date("F", strtotime($prevMonth)));[-/php-]">&lt;</td>
217 <td colspan="5" class="tdMonthName-small">
218 [-php-]
219 echo xl(date('F', $caldate));
220 [-/php-]
221 </td>
222 <td class="tdDOW-small tdDatePicker tdNav" id="[-php-]echo $nextMonth[-/php-]" title="[-php-]echo xl(date("F", strtotime($nextMonth)));[-/php-]">&gt;</td>
223 <tr>
224 [-php-]
225 foreach ($DOWlist as $dow) {
226 echo "<td class='tdDOW-small'>".$this->_tpl_vars['A_SHORT_DAY_NAMES'][$dow]."</td>";
228 [-/php-]
229 </tr>
230 [-php-]
231 $atmp = array_keys($A_EVENTS);
232 $caldate = strtotime($atmp[0]);
233 $caldateEnd = strtotime($atmp[6]);
235 // to make a complete week row we need to compute the real
236 // start and end dates for the view
237 list ($year, $month, $day) = explode(" ", date('Y m d', $caldate));
238 $startdate = strtotime($year.$month."01");
239 $enddate = strtotime($year.$month.date("t", $startdate)." 23:59");
240 while (date('w', $startdate) != $DOWlist[0]) { $startdate -= 60*60*24; }
241 while (date('w', $enddate) != $DOWlist[6]) { $enddate += 60*60*24; }
243 $currdate = $startdate;
244 while ($currdate <= $enddate) {
245 if (date('w', $currdate) == $DOWlist[0]) {
246 // start of week row
247 $tr = "<tr class='trDateRow'>";
248 echo $tr;
251 // set the TD class
252 $tdClass = "tdMonthDay-small";
253 if (date('m', $currdate) != $month) {
254 $tdClass = "tdOtherMonthDay-small";
256 if ((date('w', $currdate) == 0) || (date('w', $currdate) == 6)) {
257 $tdClass = "tdWeekend-small";
260 if ((date('Ymd',$currdate) >= date('Ymd', $caldate)) &&
261 (date('Ymd',$currdate) <= date('Ymd', $caldateEnd)))
263 // add a class that highlights the 'current date'
264 $tdClass .= " currentWeek";
267 if (date('Ymd',$currdate) == $Date) {
268 // $Date is defined near the top of this file
269 // and is equal to whatever date the user has clicked
270 $tdClass .= " currentDate";
273 // add a class so that jQuery can grab these days for the 'click' event
274 $tdClass .= " tdDatePicker";
276 // output the TD
277 $td = "<td ";
278 $td .= "class=\"".$tdClass."\" ";
279 //$td .= "id=\"".date("Ymd", $currdate)."\" ";
280 $td .= "id=\"".date("Ymd", $currdate)."\" ";
281 $td .= "title=\"" . xl('Go to week of') . " ".date('M d, Y', $currdate)."\" ";
282 $td .= "> ".date('d', $currdate)."</td>\n";
283 echo $td;
285 // end of week row
286 if (date('w', $currdate) == $DOWlist[6]) echo "</tr>\n";
288 // time correction = plus 1000 seconds, for some unknown reason
289 $currdate += (60*60*24)+1000;
291 [-/php-]
292 </table>
293 </div>
295 <div id="bigCalHeader">
296 </div>
298 <div id="providerPicker">
299 [-php-] xl('Providers','e'); [-/php-]
300 <div>
301 [-php-]
302 // ==============================
303 // FACILITY FILTERING (lemonsoftware)
304 // $facilities = getFacilities();
305 if ($_SESSION['authorizeduser'] == 1) {
306 $facilities = getFacilities();
307 } else {
308 $facilities = getUserFacilities($_SESSION['authId']); // from users_facility
309 if (count($facilities) == 1)
310 $_SESSION['pc_facility'] = key($facilities);
312 if (count($facilities) > 1) {
313 echo " <select name='pc_facility' id='pc_facility' class='view1' >\n";
314 if ( !$_SESSION['pc_facility'] ) $selected = "selected='selected'";
315 // echo " <option value='0' $selected>" .xl('All Facilities'). "</option>\n";
316 if (!$GLOBALS['restrict_user_facility']) echo " <option value='0' $selected>" . xl('All Facilities') . "</option>\n";
317 foreach ($facilities as $fa) {
318 $selected = ( $_SESSION['pc_facility'] == $fa['id']) ? "selected='selected'" : "" ;
319 echo " <option style=background-color:".htmlspecialchars($fa['color'],ENT_QUOTES)." value='" .htmlspecialchars($fa['id'],ENT_QUOTES). "' $selected>" .htmlspecialchars($fa['name'],ENT_QUOTES). "</option>\n";
321 echo " </select>\n";
323 // EOS FF
324 // ==============================
325 echo "</div>";
326 echo " <select multiple size='5' name='pc_username[]' id='pc_username' class='view2'>\n";
327 echo " <option value='__PC_ALL__'>" .xl ("All Users"). "</option>\n";
328 foreach ($provinfo as $doc) {
329 $username = $doc['username'];
330 echo " <option value='$username'";
331 foreach ($providers as $provider)
332 if ($provider['username'] == $username) echo " selected";
333 echo ">" . htmlspecialchars($doc['lname'],ENT_QUOTES) . ", " . htmlspecialchars($doc['fname'],ENT_QUOTES) . "</option>\n";
335 echo " </select>\n";
337 [-/php-]
338 </div>
339 [-php-]
340 if($_SESSION['pc_facility'] == 0){
341 [-/php-]
342 <div id="facilityColor">
343 <table>
344 [-php-]
345 foreach ($facilities as $f){
346 echo " <tr><td><div class='view1' style=background-color:".$f['color'].";font-weight:bold>".htmlspecialchars($f['name'],ENT_QUOTES)."</div></td></tr>";
348 [-/php-]
349 </table>
350 </div>
351 [-php-]
353 [-/php-]
354 </form>
356 [-assign var="dayname" value=$DATE|date_format:"%w"-]
357 [-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-]
358 [-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-]
359 [-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-]
361 </div> <!-- end bottomLeft -->
362 <div id="bigCal">
363 [-php-]
364 /* used in debugging
365 foreach ($A_EVENTS as $date => $events) {
366 echo $date." = ";
367 foreach ($events as $oneE) {
368 print_r($oneE);
369 echo "<br><br>";
371 echo "<hr width=100%>";
376 // This loops once for each provider to be displayed.
378 foreach ($providers as $provider) {
379 $providerid = $provider['id'];
381 // to specially handle the IN/OUT events I'm doing something new here
382 // for each IN event it will have a duration lasting until the next
383 // OUT event or until the end of the day
384 $tmpTime = $times[0];
385 $calStartMin = ($tmpTime['hour'] * 60) + $tmpTime['minute'];
386 $tmpTime = $times[count($times)-1];
387 $calEndMin = ($tmpTime['hour'] * 60) + $tmpTime['minute'];
389 echo "<table border='0' cellpadding='1' cellspacing='0' width='100%'>\n";
390 echo " <tr>\n";
391 echo " <td colspan='8' class='providerheader'>";
392 echo htmlspecialchars($provider['fname'],ENT_QUOTES) . " " . htmlspecialchars($provider['lname'],ENT_QUOTES);
393 echo "</td>\n";
394 echo " </tr>\n";
396 // output column (date) headers
397 $colWidth = 100/7; // intentionally '7' and not '8'
398 echo " <tr>\n";
399 echo " <td>&nbsp;</td>"; // blank TD for the header above the Times column
400 $defaultDate = ""; // used when creating link for a 'new' event
401 $in_cat_id = 0; // used when creating link for a 'new' event
402 foreach ($A_EVENTS as $date => $events) {
403 $dateFmt = date("Ymd", strtotime($date));
404 $gotoURL = pnModURL(__POSTCALENDAR__,'user','view',
405 array('tplview'=>$template_view,
406 'viewtype'=>'day',
407 'Date'=> $dateFmt,
408 'pc_username'=>$pc_username,
409 'pc_category'=>$category,
410 'pc_topic'=>$topic));
411 if ($defaultDate == "") $defaultDate = $dateFmt;
412 $currclass = "";
413 if ($Date == $dateFmt) { $currclass= "week_currday"; }
414 echo "<td align='center' class='week_dateheader $currclass' style='width:".$colWidth."%;' >";
415 echo "<a href='$gotoURL'>";
416 echo xl(date("D", strtotime($date))) . " " . date("m/d", strtotime($date));
417 echo "</a></td>";
419 echo " </tr>\n";
421 // output the TD with the times DIV
422 echo "<tr>";
423 echo "<td id='times'><div><table>\n";
424 //==================================================================================================================
425 foreach ($times as $slottime) {
426 $startampm = ($slottime['mer']) == "pm" ? 2 : 1;
427 $starttimeh = $slottime['hour'];
428 $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh;
429 $starttimem = $slottime['minute'];
430 $slotendmins = $starttimeh * 60 + $starttimem + $interval;
432 echo "<tr><td class='timeslot'>";
433 // echo "<a href='javascript:newEvt($startampm,$starttimeh,$starttimem,$Date,$providerid,$in_cat_id)' title='New Appointment' alt='New Appointment'>";
434 echo "<a href='javascript:newEvt($startampm,$starttimeh,$starttimem,$defaultDate,$providerid,$in_cat_id)' title='" . htmlspecialchars(xl("New Appointment"),ENT_QUOTES) . "' alt='".htmlspecialchars(xl("New Appointment"),ENT_QUOTES)."'>";
436 //echo $slottime['hour'] * 60 + $slottime['minute'];
437 echo "$disptimeh:$starttimem</a>";
438 echo "</td></tr>\n";
440 echo "</table></div></td>";
442 // For each day...
443 // output a TD with an inner containing DIV positioned 'relative'
444 // within that DIV we place our event DIVs using 'absolute' positioning
445 foreach ($A_EVENTS as $date => $events) {
446 $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2);
448 // having a 'title' for the TD makes the date appear by the mouse pointer
449 // this is nice when all you see are times on the left side and no head
450 // row with the dates or day-of-week (DOW)
451 $headDate=strtotime($date);
452 echo "<td class='schedule' title='".date("l, d M Y",$headDate )."' date='".date("Ymd",$headDate )."' provider='$providerid'>";
453 echo "<div class='calendar_day'>";
455 // determine if events overlap and adjust their width and left position as needed
456 // 26 Feb 2008 - This needs fine tuning or total replacement
457 // - it doesn't work as well as I'd like - JRM
458 $eventPositions = array();
459 foreach ($times as $slottime) {
460 $starttimeh = $slottime['hour'];
461 $starttimem = $slottime['minute'];
463 $slotstartmins = $starttimeh * 60 + $starttimem;
464 $slotendmins = $starttimeh * 60 + $starttimem + $interval;
466 $events_in_timeslot = array();
467 foreach ($events as $e1) {
468 // ignore IN and OUT events
469 if (($e1['catid'] == 2) || ($e1['catid'] == 3)) { continue; }
470 // skip events without an ID (why they are in the loop, I have no idea)
471 if ($e1['eid'] == "") { continue; }
472 // skip events for other providers
473 if ($providerid != $e1['aid']) { continue; }
475 // specially handle all-day events
476 if ($e1['alldayevent'] == 1) {
477 $tmpTime = $times[0];
478 if (strlen($tmpTime['hour']) < 2) { $tmpTime['hour'] = "0".$tmpTime['hour']; }
479 if (strlen($tmpTime['minute']) < 2) { $tmpTime['minute'] = "0".$tmpTime['minute']; }
480 $e1['startTime'] = $tmpTime['hour'].":".$tmpTime['minute'].":00";
481 $e1['duration'] = ($calEndMin - $calStartMin) * 60; // measured in seconds
484 // create a numeric start and end for comparison
485 $starth = substr($e1['startTime'], 0, 2);
486 $startm = substr($e1['startTime'], 3, 2);
487 $e1Start = ($starth * 60) + $startm;
488 $e1End = $e1Start + $e1['duration']/60;
490 // three ways to overlap:
491 // start-in, end-in, span
492 if ((($e1Start >= $slotstartmins) && ($e1Start < $slotendmins)) // start-in
493 || (($e1End > $slotstartmins) && ($e1End <= $slotendmins)) // end-in
494 || (($e1Start < $slotstartmins) && ($e1End > $slotendmins))) // span
496 array_push($events_in_timeslot, $e1['eid']);
500 $leftpos = 0;
501 $width = 100 / count($events_in_timeslot);
503 // loop over the events in this timeslot and adjust their width
504 foreach ($events_in_timeslot as $eid) {
505 // set the width if not already set or if the current width is smaller
506 // than was was previously set
507 if (! isset($eventPositions[$eid]->width)) { $eventPositions[$eid]->width = $width; }
508 else if ($eventPositions[$eid]->width > $width) { $eventPositions[$eid]->width = $width; }
510 // set the left position if not already set or if the current left is
511 // greater than what was previously set
512 if (! isset($eventPositions[$eid]->leftpos)) { $eventPositions[$eid]->leftpos = $leftpos; }
513 else if ($eventPositions[$eid]->leftpos < $leftpos) { $eventPositions[$eid]->leftpos = $leftpos; }
515 // increment the leftpos by the width
516 $leftpos += $width;
518 } // end overlap detection
520 // now loop over the events for the day and output their DIVs
521 foreach ($events as $event) {
522 // skip events for other providers
523 // yeah, we've got that sort of overhead here... it ain't perfect
524 if ($providerid != $event['aid']) { continue; }
526 // skip events without an ID (why they are in the loop, I have no idea)
527 if ($event['eid'] == "") { continue; }
529 // specially handle all-day events
530 if ($event['alldayevent'] == 1) {
531 $tmpTime = $times[0];
532 if (strlen($tmpTime['hour']) < 2) { $tmpTime['hour'] = "0".$tmpTime['hour']; }
533 if (strlen($tmpTime['minute']) < 2) { $tmpTime['minute'] = "0".$tmpTime['minute']; }
534 $event['startTime'] = $tmpTime['hour'].":".$tmpTime['minute'].":00";
535 $event['duration'] = ($calEndMin - $calStartMin) * 60; // measured in seconds
538 // figure the start time and minutes (from midnight)
539 $starth = substr($event['startTime'], 0, 2);
540 $startm = substr($event['startTime'], 3, 2);
541 $eStartMin = $starth * 60 + $startm;
542 $dispstarth = ($starth > 12) ? ($starth - 12) : $starth;
544 // determine the class for the event DIV based on the event category
545 $evtClass = "event_appointment";
546 switch ($event['catid']) {
547 case 1: // NO-SHOW appt
548 $evtClass = "event_noshow";
549 break;
550 case 2: // IN office
551 $evtClass = "event_in";
552 break;
553 case 3: // OUT of office
554 $evtClass = "event_out";
555 break;
556 case 4: // VACATION
557 case 8: // LUNCH
558 case 11: // RESERVED
559 $evtClass = "event_reserved";
560 break;
561 default: // some appointment
562 $evtClass = "event_appointment";
563 break;
566 // if this is an IN or OUT event then we have some extra special
567 // processing to be done
568 // the IN event creates a DIV until the OUT event
569 // or, without an OUT DIV matching the IN event
570 // then the IN event runs until the end of the day
571 if ($event['catid'] == 2) {
572 // locate a matching OUT for this specific IN
573 $found = false;
574 $outMins = 0;
575 foreach ($events as $outevent) {
576 // skip events for other providers
577 if ($providerid != $outevent['aid']) { continue; }
578 // skip events with blank IDs
579 if ($outevent['eid'] == "") { continue; }
581 if ($outevent['eid'] == $event['eid']) { $found = true; continue; }
582 if (($found == true) && ($outevent['catid'] == 3)) {
583 // calculate the duration from this event to the outevent
584 $outH = substr($outevent['startTime'], 0, 2);
585 $outM = substr($outevent['startTime'], 3, 2);
586 $outMins = ($outH * 60) + $outM;
587 $event['duration'] = ($outMins - $eStartMin) * 60; // duration is in seconds
588 $found = 2;
589 break;
592 if ($outMins == 0) {
593 // no OUT was found so this event's duration goes
594 // until the end of the day
595 $event['duration'] = ($calEndMin - $eStartMin) * 60; // duration is in seconds
599 // calculate the TOP value for the event DIV
600 // diff between event start and schedule start
601 $eMinDiff = $eStartMin - $calStartMin;
602 // diff divided by the time interval of the schedule
603 $eStartInterval = $eMinDiff / $interval;
604 // times the interval height
605 $eStartPos = $eStartInterval * $timeslotHeightVal;
606 $evtTop = $eStartPos.$timeslotHeightUnit;
608 // calculate the HEIGHT value for the event DIV
609 // diff between end and start of event
610 $eEndMin = $eStartMin + ($event['duration']/60);
611 // prevent the overall height of the event from going beyond the bounds
612 // of the time table
613 if ($eEndMin > $calEndMin) { $eEndMin = $calEndMin + $interval; }
614 $eMinDiff = $eEndMin - $eStartMin;
615 // diff divided by the time interval of the schedule
616 $eEndInterval = $eMinDiff / $interval;
617 // times the interval height
618 $eHeight = $eEndInterval * $timeslotHeightVal;
619 $evtHeight = $eHeight.$timeslotHeightUnit;
621 // determine the DIV width based on any overlapping events
622 // see further above for the overlapping calculation code
623 $divWidth = "";
624 $divLeft = "";
625 if (isset($eventPositions[$event['eid']])) {
626 $divWidth = "width: ".$eventPositions[$event['eid']]->width."%";
627 $divLeft = "left: ".$eventPositions[$event['eid']]->leftpos."%";
630 $eventid = $event['eid'];
631 $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."'");
632 $pccattype = '';
633 if($eventtype['pc_cattype']==1)
634 $pccattype = 'true';
635 $patientid = $event['pid'];
636 $commapos = strpos($event['patient_name'], ",");
637 $lname = substr($event['patient_name'], 0, $commapos);
638 $fname = substr($event['patient_name'], $commapos + 2);
639 $patient_dob = $event['patient_dob'];
640 $patient_age = $event['patient_age'];
641 $catid = $event['catid'];
642 $comment = addslashes($event['hometext']);
643 $catname = $event['catname'];
644 $title = "Age $patient_age ($patient_dob)";
646 $content = "";
648 if ($comment && $GLOBALS['calendar_appt_style'] < 4) $title .= " " . $comment;
650 // the divTitle is what appears when the user hovers the mouse over the DIV
651 $divTitle = date("D, d M Y", strtotime($date));
652 $result = sqlStatement("SELECT name,id,color FROM facility WHERE id=(SELECT pc_facility FROM openemr_postcalendar_events WHERE pc_eid=".$eventid.")");
653 $row = sqlFetchArray($result);
654 $color=$event["catcolor"];
655 if($GLOBALS['event_color']==2)
656 $color=$row['color'];
657 $divTitle .= "\n" .htmlspecialchars($row['name'],ENT_QUOTES);
658 if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) {
659 if ($catid == 2) $catname = xl("IN");
660 else if ($catid == 3) $catname = xl("OUT");
661 else if ($catid == 4) $catname = xl("VACATION");
662 else if ($catid == 8) $catname = xl("LUNCH");
663 else if ($catid == 11) $catname = xl("RESERVED");
665 $atitle = $catname;
666 if ($comment) $atitle .= " $comment";
667 //$divTitle .= "\n[".$atitle ."] ".$divTitle;
668 $divTitle .= "\n[".$atitle ."]";
669 //$content .= "<a href='javascript:oldEvt($eventdate,$eventid)' title='$atitle'>";
670 $content .= $catname;
671 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'>";
672 if ($comment) $content .= " $comment";
673 //$content .= "</a>";
675 else {
676 // some sort of patient appointment
677 $divTitle .= "\r\n[".$catname.' '.htmlspecialchars($comment, ENT_QUOTES) ."] ".htmlspecialchars($fname,ENT_QUOTES)." ".htmlspecialchars($lname,ENT_QUOTES);
678 $content .= "<span class='appointment".$apptToggle."'>";
679 $content .= $dispstarth . ':' . $startm;
680 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'>";
681 $content .= htmlspecialchars($event['apptstatus']);
682 if ($patientid) {
683 // include patient name and link to their details
684 $link_title = htmlspecialchars($fname,ENT_QUOTES)." ".htmlspecialchars($lname,ENT_QUOTES). " \n";
685 $link_title .= xl('Age') . ": ".$patient_age."\n" . xl('DOB') . ": ".$patient_dob.htmlspecialchars($comment, ENT_QUOTES)."\n";
686 $link_title .= "(" . xl('Click to view') . ")";
687 $content .= "<a href='javascript:goPid($patientid)' title='$link_title'>";
688 $content .= "<img src='$TPL_IMAGE_PATH/user-green.gif' border='0' title='$link_title' alt='View Patient' />";
690 if ($catid == 1) $content .= "<strike>";
691 $content .= htmlspecialchars($lname);
692 if ($GLOBALS['calendar_appt_style'] != 1) {
693 $content .= "," . htmlspecialchars($fname);
694 if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) {
695 $content .= "(" . $event['title'];
696 if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4)
697 $content .= ": <font color='green'>" . htmlspecialchars(trim($event['hometext'])) . "</font>";
698 $content .= ")";
701 if ($catid == 1) $content .= "</strike>";
703 $content .= "</a>";
705 else {
706 // no patient id, just output the category name
707 $content .= $catname;
709 $content .= "</span>";
712 $divTitle .= "\n(" . xl('double click to edit') . ")";
714 // output the DIV and content
715 if($_SESSION['pc_facility'] == 0){
716 // output the DIV and content
717 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
718 "; background-color:".$color.
719 "; $divWidth".
720 "; $divLeft".
721 "' title='".$divTitle."'".
722 " id='".$eventdate."-".$eventid."-".$pccattype."'".
723 ">";
724 echo $content;
725 echo "</div>\n";
727 elseif($_SESSION['pc_facility'] == $row['id']){
728 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
729 "; background-color:".$event["catcolor"].
730 "; $divWidth".
731 "; $divLeft".
732 "' title='".$divTitle."'".
733 " id='".$eventdate."-".$eventid."-".$pccattype."'".
734 ">";
735 echo $content;
736 echo "</div>\n";
738 else{
739 echo "<div class='".$evtClass." event' style='top:".$evtTop."; height:".$evtHeight.
740 "; background-color:#DDDDDD".
741 "; $divWidth".
742 "; $divLeft".
743 "' title='".$divTitle."'".
744 " id='".$eventdate."-".$eventid."-".$pccattype."'".
745 ">";
746 echo "<span style='color:red;text-align:center;font-weight:bold'>".htmlspecialchars($row['name'],ENT_QUOTES)."</span>";
747 echo "</div>\n";
749 } // end EVENT loop
751 echo "</div>";
752 echo "</td>\n";
754 } // end date
755 //==================================================================================================================
756 echo " </tr>\n";
758 echo "</table>\n";
759 } // end provider
761 // [-*footer*-]
762 // [-include file="$TPL_NAME/views/global/footer.html"-]
763 // [-include file="$TPL_NAME/views/footer.html"-]
765 [-/php-]
766 </div> <!-- end bigCal DIV -->
767 </div> <!-- end bottom DIV -->
768 </body>
770 <script language='JavaScript'>
771 var tsHeight='[-php-] echo $timeslotHeightVal.$timeslotHeightUnit; [-/php-]';
772 var tsHeightNum=[-php-] echo $timeslotHeightVal; [-/php-];
774 $(document).ready(function(){
775 setupDirectTime();
776 $("#pc_username").change(function() { ChangeProviders(this); });
777 $("#pc_facility").change(function() { ChangeProviders(this); });
778 $("#dayview").click(function() { ChangeView(this); });
779 //$("#weekview").click(function() { ChangeView(this); });
780 $("#monthview").click(function() { ChangeView(this); });
781 //$("#yearview").click(function() { ChangeView(this); });
782 $(".tdDatePicker").click(function() { ChangeDate(this); });
783 $("#datePicker .trDateRow").mouseover(function() { $(this).children().toggleClass("tdDatePickerHighlight"); });
784 $("#datePicker .trDateRow").mouseout(function() { $(this).children().toggleClass("tdDatePickerHighlight"); });
785 $("#datePicker .tdNav").mouseover(function() { $(this).toggleClass("tdDatePickerHighlight"); });
786 $("#datePicker .tdNav").mouseout(function() { $(this).toggleClass("tdDatePickerHighlight"); });
787 $("#printview").click(function() { PrintView(this); });
788 $(".event").dblclick(function() { EditEvent(this); });
789 $(".event").mouseover(function() { $(this).toggleClass("event_highlight"); });
790 $(".event").mouseout(function() { $(this).toggleClass("event_highlight"); });
793 $(".tdMonthName-small").click(function() {
795 dpCal=$("#datePicker>table");
796 mp = $("#monthPicker"); mp.width(dpCal.width()); mp.toggle();});
799 /* edit an existing event */
800 var EditEvent = function(eObj) {
801 //alert ('editing '+eObj.id);
802 // split the object ID into date and event ID
803 objID = eObj.id;
804 var parts = new Array();
805 parts = objID.split("-");
806 // call the oldEvt function to bring up the event editor
807 oldEvt(parts[0], parts[1], parts[2]);
808 return true;
811 /* change the current date based upon what the user clicked in
812 * the datepicker DIV
814 var ChangeDate = function(eObj) {
815 baseURL = "[-php-]echo pnModURL(__POSTCALENDAR__,'user','view',
816 array('tplview'=>$template_view,
817 'viewtype'=>$viewtype,
818 'Date'=> '~REPLACEME~',
819 'pc_username'=>$pc_username,
820 'pc_category'=>$category,
821 'pc_topic'=>$topic));[-/php-]";
822 newURL = baseURL.replace(/~REPLACEME~/, eObj.id);
823 document.location.href=newURL;
826 /* pop up a window to print the current view
828 var PrintView = function (eventObject) {
829 printURL = "[-php-]echo pnModURL(__POSTCALENDAR__,'user','view',
830 array('tplview'=>$template_view,
831 'viewtype'=>$viewtype,
832 'Date'=> $Date,
833 'print'=> 1,
834 'pc_username'=>$pc_username,
835 'pc_category'=>$category,
836 'pc_topic'=>$topic));[-/php-]";
837 window.open(printURL,'printwindow','width=740,height=480,toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=no,resizable=yes');
838 return false;
841 /* change the provider(s)
843 var ChangeProviders = function (eventObject) {
844 $('#theform').submit();
847 /* change the calendar view
849 var ChangeView = function (eventObject) {
850 if (eventObject.id == "dayview") {
851 $("#viewtype").val('day');
853 else if (eventObject.id == "weekview") {
854 $("#viewtype").val('week');
856 else if (eventObject.id == "monthview") {
857 $("#viewtype").val('month');
859 else if (eventObject.id == "yearview") {
860 $("#viewtype").val('year');
862 $('#theform').submit();
865 </script>
868 </html>