function print_day_at_a_glance($date, $user, $hide_icons, $can_add = 0) { global $first_slot, $last_slot, $hour_arr, $rowspan_arr, $rowspan; global $CELLBG, $TODAYCELLBG, $THFG, $THBG, $TIME_SLOTS, $TZ_OFFSET; global $WORK_DAY_START_HOUR, $WORK_DAY_END_HOUR; global $repeated_events; $get_unapproved = $GLOBALS["DISPLAY_UNAPPROVED"] == "Y"; if ($user == "__public__") { $get_unapproved = false; } if (empty($TIME_SLOTS)) { echo "Error: TIME_SLOTS undefined!<P>"; return; } // $interval is number of minutes per slot $interval = 24 * 60 / $TIME_SLOTS; $rowspan_arr = array(); for ($i = 0; $i < $TIME_SLOTS; $i++) { $rowspan_arr[$i] = 0; } // get all the repeating events for this date and store in array $rep $rep = get_repeating_entries($user, $date); $cur_rep = 0; // Get static non-repeating events $ev = get_entries($user, $date); $hour_arr = array(); $interval = 24 * 60 / $TIME_SLOTS; $first_slot = (int) (($WORK_DAY_START_HOUR - $TZ_OFFSET) * 60 / $interval); $last_slot = (int) (($WORK_DAY_END_HOUR - $TZ_OFFSET) * 60 / $interval); //echo "first_slot = $first_slot <BR> last_slot = $last_slot <BR> interval = $interval <BR> TIME_SLOTS = $TIME_SLOTS <BR>"; $rowspan_arr = array(); $all_day = 0; for ($i = 0; $i < count($ev); $i++) { // print out any repeating events that are before this one... while ($cur_rep < count($rep) && $rep[$cur_rep]['cal_time'] < $ev[$i]['cal_time']) { if ($get_unapproved || $rep[$cur_rep]['cal_status'] == 'A') { if (!empty($rep[$cur_rep]['cal_ext_for_id'])) { $viewid = $rep[$cur_rep]['cal_ext_for_id']; $viewname = $rep[$cur_rep]['cal_name'] . " (" . translate("cont.") . ")"; } else { $viewid = $rep[$cur_rep]['cal_id']; $viewname = $rep[$cur_rep]['cal_name']; } if ($rep['cal_duration'] == 24 * 60) { $all_day = 1; } html_for_event_day_at_a_glance($viewid, $date, $rep[$cur_rep]['cal_time'], $viewname, $rep[$cur_rep]['cal_description'], $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'], $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_duration'], $rep[$cur_rep]['cal_login'], $hide_icons); } $cur_rep++; } if ($get_unapproved || $ev[$i]['cal_status'] == 'A') { if (!empty($ev[$i]['cal_ext_for_id'])) { $viewid = $ev[$i]['cal_ext_for_id']; $viewname = $ev[$i]['cal_name'] . " (" . translate("cont.") . ")"; } else { $viewid = $ev[$i]['cal_id']; $viewname = $ev[$i]['cal_name']; } if ($ev[$i]['cal_duration'] == 24 * 60) { $all_day = 1; } html_for_event_day_at_a_glance($viewid, $date, $ev[$i]['cal_time'], $viewname, $ev[$i]['cal_description'], $ev[$i]['cal_status'], $ev[$i]['cal_priority'], $ev[$i]['cal_access'], $ev[$i]['cal_duration'], $ev[$i]['cal_login'], $hide_icons); } } // print out any remaining repeating events while ($cur_rep < count($rep)) { if ($get_unapproved || $rep[$cur_rep]['cal_status'] == 'A') { if (!empty($rep[$cur_rep]['cal_ext_for_id'])) { $viewid = $rep[$cur_rep]['cal_ext_for_id']; $viewname = $rep[$cur_rep]['cal_name'] . " (" . translate("cont.") . ")"; } else { $viewid = $rep[$cur_rep]['cal_id']; $viewname = $rep[$cur_rep]['cal_name']; } if ($rep['cal_duration'] == 24 * 60) { $all_day = 1; } html_for_event_day_at_a_glance($viewid, $date, $rep[$cur_rep]['cal_time'], $viewname, $rep[$cur_rep]['cal_description'], $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'], $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_duration'], $rep[$cur_rep]['cal_login'], $hide_icons); } $cur_rep++; } // squish events that use the same cell into the same cell. // For example, an event from 8:00-9:15 and another from 9:30-9:45 both // want to show up in the 8:00-9:59 cell. $rowspan = 0; $last_row = -1; //echo "First SLot: $first_slot; Last Slot: $last_slot <BR>"; $i = 0; if ($first_slot < 0) { $i = $first_slot; } for (; $i < $TIME_SLOTS; $i++) { if ($rowspan > 1) { if (!empty($hour_arr[$i])) { if ($rowspan_arr[$i] > 1) { $rowspan_arr[$last_row] += $rowspan_arr[$i] - 1; $rowspan += $rowspan_arr[$i] - 1; } else { $rowspan_arr[$last_row] += $rowspan_arr[$i]; } // this will move entries apart that appear in one field, // yet start on different hours $start_time = $i; $diff_start_time = $start_time - $last_row; for ($u = $diff_start_time; $u > 0; $u--) { $hour_arr[$last_row] .= "<BR>"; } $hour_arr[$last_row] .= $hour_arr[$i]; $hour_arr[$i] = ""; $rowspan_arr[$i] = 0; } $rowspan--; } else { if (!empty($rowspan_arr[$i]) && $rowspan_arr[$i] > 1) { $rowspan = $rowspan_arr[$i]; $last_row = $i; } } } if (!empty($hour_arr[9999])) { echo "<TR><TD HEIGHT=\"40\" BGCOLOR=\"{$TODAYCELLBG}\"> </TD><TD VALIGN=\"top\" HEIGHT=\"40\" BGCOLOR=\"{$TODAYCELLBG}\">{$hour_arr['9999']}</TD></TR>\n"; } $rowspan = 0; //echo "first_slot = $first_slot <BR> last_slot = $last_slot <BR> interval = $interval <BR>"; for ($i = $first_slot; $i <= $last_slot; $i++) { $time_h = (int) ($i * $interval / 60); $time_m = $i * $interval % 60; $time = display_time(($time_h * 100 + $time_m) * 100); echo "<TR><TH VALIGN=\"top\" HEIGHT=\"40\" WIDTH=\"14%\" BGCOLOR=\"{$THBG}\" CLASS=\"tableheader\">" . "<FONT COLOR=\"{$THFG}\">" . $time . "</FONT></TH>\n"; if ($rowspan > 1) { // this might mean there's an overlap, or it could mean one event // ends at 11:15 and another starts at 11:30. if (strlen($hour_arr[$i])) { echo "<TD VALIGN=\"top\" HEIGHT=\"40\" BGCOLOR=\"{$TODAYCELLBG}\">"; if ($can_add && !$hide_icons) { echo html_for_add_icon($date, $time_h, $time_m); } echo "{$hour_arr[$i]}</TD>"; } $rowspan--; } else { $color = $all_day ? $TODAYCELLBG : $CELLBG; if (empty($hour_arr[$i])) { echo "<TD HEIGHT=\"40\" BGCOLOR=\"{$color}\">"; if ($can_add && !$hide_icons) { echo html_for_add_icon($date, $time_h, $time_m); } echo " </TD></TR>\n"; } else { $rowspan = $rowspan_arr[$i]; if ($rowspan > 1) { echo "<TD VALIGN=\"top\" BGCOLOR=\"{$TODAYCELLBG}\" ROWSPAN=\"{$rowspan}\">"; if ($can_add && !$hide_icons) { echo html_for_add_icon($date, $time_h, $time_m); } echo "{$hour_arr[$i]}</TD></TR>\n"; } else { echo "<TD VALIGN=\"top\" HEIGHT=\"40\" BGCOLOR=\"{$TODAYCELLBG}\">"; if ($can_add && !$hide_icons) { echo html_for_add_icon($date, $time_h, $time_m); } echo "{$hour_arr[$i]}</TD></TR>\n"; } } } } }
function print_day_at_a_glance($date, $user, $can_add = 0) { global $CELLBG, $DISPLAY_TASKS_IN_GRID, $DISPLAY_UNAPPROVED, $first_slot, $hour_arr, $last_slot, $rowspan, $rowspan_arr, $TABLEBG, $THBG, $THFG, $TIME_SLOTS, $today, $TODAYCELLBG, $WORK_DAY_END_HOUR, $WORK_DAY_START_HOUR; if (empty($TIME_SLOTS)) { return translate('Error TIME_SLOTS undefined!') . "<br />\n"; } $get_unapproved = $DISPLAY_UNAPPROVED == 'Y'; // Get, combine and sort the events for this date. $ev = combine_and_sort_events(get_entries($date, $get_unapproved), get_repeating_entries($user, $date)); if ($date >= date('Ymd') && (empty($DISPLAY_TASKS_IN_GRID) || $DISPLAY_TASKS_IN_GRID == 'Y')) { $ev = combine_and_sort_events($ev, get_tasks($date, $get_unapproved)); } $hour_arr = $rowspan_arr = array(); $interval = 1440 / $TIME_SLOTS; // Number of minutes per slot $first_slot = intval($WORK_DAY_START_HOUR * 60 / $interval); $last_slot = intval($WORK_DAY_END_HOUR * 60 / $interval); for ($i = 0, $cnt = count($ev); $i < $cnt; $i++) { if ($get_unapproved || $ev[$i]->getStatus() == 'A') { html_for_event_day_at_a_glance($ev[$i], $date); } } $last_row = -1; $ret = ''; $rowspan = 0; // Squish events that use the same cell into the same cell. // For example, an event from 8:00-9:15 and another from 9:30-9:45 both // want to show up in the 8:00-9:59 cell. for ($i = $first_slot < 0 ? $first_slot : 0; $i < $TIME_SLOTS; $i++) { if ($rowspan > 1) { if (!empty($hour_arr[$i])) { $diff_start_time = $i - $last_row; if (!empty($rowspan_arr[$i])) { if ($rowspan_arr[$i] > 1 && $rowspan_arr[$i] + $diff_start_time > $rowspan_arr[$last_row]) { $rowspan_arr[$last_row] = $rowspan_arr[$i] + $diff_start_time; } $rowspan += $rowspan_arr[$i] - 1; } else { $rowspan_arr[$last_row] += $rowspan_arr[$i]; } // This will move entries apart that appear in one field, // yet start on different hours. for ($u = $diff_start_time; $u > 0; $u--) { $hour_arr[$last_row] .= "<br />\n"; } $hour_arr[$last_row] .= $hour_arr[$i]; $hour_arr[$i] = ''; $rowspan_arr[$i] = 0; } $rowspan--; } else { if (!empty($rowspan_arr[$i]) && $rowspan_arr[$i] > 1) { $last_row = $i; $rowspan = $rowspan_arr[$i]; } } } $ret .= ' <table class="main glance" cellspacing="0" cellpadding="0">' . (empty($hour_arr[9999]) ? '' : ' <tr> <th class="empty"> </th> <td class="hasevents">' . $hour_arr[9999] . '</td> </tr>'); $rowspan = 0; for ($i = $first_slot; $i <= $last_slot; $i++) { $time_h = intval($i * $interval / 60); $time_m = $i * $interval % 60; $addIcon = $can_add ? html_for_add_icon($date, $time_h, $time_m, $user) : ''; $ret .= ' <tr> <th class="row">' . display_time(($time_h * 100 + $time_m) * 100) . '</th>'; if ($rowspan > 1) { // This might mean there's an overlap, or it could mean one event // ends at 11:15 and another starts at 11:30. if (!empty($hour_arr[$i])) { $ret .= ' <td class="hasevents">' . $addIcon . $hour_arr[$i] . '</td>'; } $rowspan--; } else { $ret .= ' <td '; if (empty($hour_arr[$i])) { $ret .= ($date == date('Ymd', $today) ? ' class="today"' : '') . '>' . ($can_add ? $addIcon : ' '); } else { $rowspan = empty($rowspan_arr[$i]) ? '' : $rowspan_arr[$i]; $ret .= ($rowspan > 1 ? 'rowspan="' . $rowspan . '"' : '') . 'class="hasevents">' . $addIcon . $hour_arr[$i]; } $ret .= '</td>'; } $ret .= ' </tr>'; } return $ret . ' </table>'; }