function print_entry_timebar($event, $date) { global $ENTRY_SLOTS, $entrySlots, $eventinfo, $login, $PHP_SELF, $PUBLIC_ACCESS_FULLNAME, $slotValue, $totalHours, $totalSlots, $user, $width, $WORK_DAY_END_HOUR, $WORK_DAY_START_HOUR, $yardSlots, $yardWidth; static $key = 0; $insidespan = false; $ret = ''; if (access_is_enabled()) { $temp = $event->getLogin(); $can_access = access_user_calendar('view', $temp, '', $event->getCalType(), $event->getAccess()); $time_only = access_user_calendar('time', $temp); } else { $can_access = CAN_DOALL; $time_only = 'N'; } $id = $event->getID(); $name = $event->getName(); $linkid = "pop{$id}-{$key}"; $key++; $day_start = $WORK_DAY_START_HOUR * 60; $day_end = $WORK_DAY_END_HOUR * 60; if ($day_end <= $day_start) { $day_end = $day_start + 60; } //Avoid exceptions. $time = date('His', $event->getDateTimeTS()); $startminutes = time_to_minutes($time); $endminutes = time_to_minutes(date('His', $event->getEndDateTimeTS())); $duration = $event->getDuration(); if ($event->isAllDay()) { // All day event. $ev_duration = $totalSlots; $start_padding = 0; } else { if ($event->isUntimed()) { $ev_duration = $start_padding = 0; } else { // Must be timed. $start_padding = round(($startminutes - $day_start) / $slotValue); if ($start_padding < 0) { $start_padding = 0; } if ($startminutes > $day_end || $endminutes < $day_start) { $ev_duration = 1; } else { if ($duration > 0) { $ev_duration = intval($duration / $slotValue); // Event starts before workday. if ($startminutes < $day_start) { $ev_duration = $ev_duration - (int) ($day_start - $startminutes) / $slotValue; } // Event ends after workday. if ($endminutes > $day_end) { $ev_duration = $ev_duration - (int) ($endminutes - $day_end) / $slotValue; } } } } } $end_padding = $totalSlots - $start_padding - $ev_duration + 1; // If event is past viewing area. if ($start_padding >= $totalSlots) { $ev_duration = 1; $start_padding = $totalSlots - 1; } // Choose where to position the text (pos=0->before,pos=1->on,pos=2->after). if ($ev_duration / $totalSlots >= 0.3) { $pos = 1; } elseif ($end_padding / $totalSlots >= 0.3) { $pos = 2; } else { $pos = 0; } $ret .= ' <!-- ENTRY BAR --> <tr class="entrycont">' . ($start_padding > 0 ? ' <td class="alignright" colspan="' . $start_padding . '">' : ''); if ($pos > 0) { if (!$event->isUntimed()) { $ret .= ($start_padding > 0 ? ' </td>' : '') . ' <td class="entry" colspan="' . $ev_duration . '">' . ($pos > 1 ? ' </td> <td class="alignleft" colspan="' . $end_padding . '">' : ''); } else { // Untimed, just display text. $ret .= ' <td colspan="' . $totalSlots . '">'; } } $tempClone = $event->getClone(); $tempPri = $event->getPriority() < 4; return $ret . ($tempPri ? '<strong>' : '') . ($can_access != 0 && $time_only != 'Y' ? ' <a class="entry" id="' . $linkid . '" href="view_entry.php?id=' . $id . '&date=' . ($tempClone ? $tempClone : $date) . (strlen($user) > 0 ? '&user='******'') . '">' : '') . '[' . ($event->getLogin() == '__public__' ? $PUBLIC_ACCESS_FULLNAME : $event->getLogin()) . '] ' . build_entry_label($event, 'eventinfo-' . $linkid, $can_access, $event->isAllDay() ? translate('All day event') : (!$event->isUntimed() ? display_time($event->getDatetime()) . ($event->getDuration() > 0 ? ' - ' . display_time($event->getEndDateTime(), 2) : '') : ''), $time_only) . ($insidespan ? '</span>' : '') . '</a>' . ($tempPri ? '</strong>' : '') . '</td>' . ($pos < 2 ? ($pos < 1 ? ' <td class="entry" colspan="' . $ev_duration . '"> </td>' : '') . ($end_padding > 1 ? ' <td class="alignleft" colspan="' . $end_padding . '"> </td>' : '') : '') . ' </tr>'; }
function calc_time_slot($time, $round_down = false) { global $TIME_SLOTS, $TZ_OFFSET; $interval = 24 * 60 / $TIME_SLOTS; $mins_since_midnight = time_to_minutes($time); $ret = (int) ($mins_since_midnight / $interval); if ($round_down) { if ($ret * $interval == $mins_since_midnight) { $ret--; } } //echo "$mins_since_midnight / $interval = $ret <BR>"; if ($ret > $TIME_SLOTS) { $ret = $TIME_SLOTS; } //echo "<P>calc_time_slot($time) = $ret <BR> TIME_SLOTS = $TIME_SLOTS<BR>"; return $ret; }
function calc_time_slot($time, $round_down = false) { global $TIME_SLOTS; $interval = 1440 / $TIME_SLOTS; $mins_since_midnight = time_to_minutes(sprintf("%06d", $time)); $ret = intval($mins_since_midnight / $interval); if ($round_down && $ret * $interval == $mins_since_midnight) { $ret--; } if ($ret > $TIME_SLOTS) { $ret = $TIME_SLOTS; } return $ret; }