示例#1
0
/**
* Prints all reservations for a given day
* @param array $reservations array of all reservation data for this day
* @param int $datestamp the unix datestamp for the first day shown
* @param array $fields fields of the reservation to print after the times appear
* @param bool $ownerParticipantImage whether to show the owner/participant images
* @param bool $is_private if we are in privacy mode and should hide user details
*/
function print_month_reservations($reservations, $datestamp, $fields = array('name'), $ownerParticipantImage = true, $is_private = false, $scheduleid = null)
{
    global $conf;
    global $days_full;
    $today = getdate(mktime());
    $date_vars = explode(' ', date('d m Y t w W', $datestamp));
    $last_month_num_days = date('t', mktime(0, 0, 0, $date_vars[1] - 1, $date_vars[0], $date_vars[2]));
    // Number of days in the last month
    $week_start = $conf['app']['calFirstDay'];
    $firstWeekDay = (7 + (date('w', $datestamp) - $week_start)) % 7;
    // Put all reservations in a new array stored by date
    $reservations_by_date = array();
    for ($i = 0; $i < count($reservations); $i++) {
        $start_date = $reservations[$i]['start_date'];
        if ($reservations[$i]['start_date'] != $reservations[$i]['end_date']) {
            // This makes sure that the reservation appears on every day that it is part of
            list($month, $day, $year) = split(' ', date('m j Y', $reservations[$i]['start_date']));
            $day_diff = ($reservations[$i]['end_date'] - $reservations[$i]['start_date']) / 86400;
            for ($d = 0; $d <= $day_diff; $d++) {
                $date = mktime(0, 0, 0, $month, $day + $d, $year);
                $reservations_by_date[$date][] =& $reservations[$i];
            }
        } else {
            $date = $reservations[$i]['start_date'];
            $reservations_by_date[$date][] =& $reservations[$i];
        }
    }
    echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tr><td class=\"tableBorder\">\n<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"0\"><tr>\n";
    for ($day = $week_start; $day < $week_start + 7; $day++) {
        echo '<td class="scheduleDateHeader">' . $days_full[$day % 7] . '</td>';
    }
    echo '</tr>';
    $day = $week_start;
    // Initialize day
    $printRow = false;
    // Initialize printRow
    // Print out days for all weeks
    for ($currentDay = -$firstWeekDay; $currentDay < $date_vars[3];) {
        echo "<tr>\n";
        // Print out each day of this week
        for (; $day < $week_start + 7; $day++) {
            // If there are still more days to print, do it
            ++$currentDay;
            $actualCurrentDay = $currentDay;
            $actualCurrentMonth = $date_vars['1'];
            $actualCurrentYear = $date_vars['2'];
            if ($currentDay == $today['mday'] && $date_vars[1] == $today['mon'] && $date_vars[2] == $today['year']) {
                $class = 'MyCalCurrentDayBox';
            } elseif ($currentDay <= 0 or $currentDay > $date_vars['3']) {
                $class = 'MyCalEmptyDayBox';
                $actualCurrentDay = date('j', mktime(0, 0, 0, $date_vars['1'], $currentDay, $date_vars['2']));
                $actualCurrentMonth = date('m', mktime(0, 0, 0, $date_vars['1'], $currentDay, $date_vars['2']));
                $actualCurrentYear = date('Y', mktime(0, 0, 0, $date_vars['1'], $currentDay, $date_vars['2']));
            } else {
                $class = 'MyCalDayBox';
            }
            echo "<td class=\"{$class}\"><p align=\"right\"><a class=\"MyCalDateNumber\" href=\"schedule.php?date={$actualCurrentMonth}-{$actualCurrentDay}-{$actualCurrentYear}&amp;scheduleid={$scheduleid}\">{$actualCurrentDay}</a></p>\n";
            $currentDate = mktime(0, 0, 0, $date_vars['1'], $currentDay, $date_vars['2']);
            if (isset($reservations_by_date[$currentDate])) {
                for ($resCount = 0; $resCount < count($reservations_by_date[$currentDate]); $resCount++) {
                    $res = $reservations_by_date[$currentDate][$resCount];
                    if ($is_private) {
                        $res['fname'] = 'Private';
                        $res['lname'] = '';
                        $res['summary'] = '';
                    }
                    $js = "onmouseover=\"showsummary('details', event, '" . build_reservation_detail_div($res) . "');\" onmouseout=\"hideSummary('details');\" onmousemove=\"moveSummary('details', event);\"";
                    echo "<p align=\"left\">&#8226; <a {$js} href=\"javascript:reserve('" . RES_TYPE_MODIFY . "','','','{$res['resid']}','{$res['scheduleid']}');\">" . Time::formatTime($res['starttime']) . ($res['start_date'] < $currentDate ? ' [' . translate_date('general_date', $res['start_date']) . ']' : '') . ' - ' . Time::formatTime($res['endtime']) . ($res['end_date'] > $currentDate ? ' [' . translate_date('general_date', $res['end_date']) . ']' : '');
                    foreach ($fields as $field) {
                        echo ' ' . $res[$field];
                    }
                    echo '</a>';
                    if ($ownerParticipantImage) {
                        echo $res['owner'] == 1 ? ' <img src="img/owner.gif" alt="' . translate('Owner') . '" title="' . translate('Owner') . '"/>' : ' <img src="img/participant.gif" alt="' . translate('Participant') . '" title="' . translate('Participant') . '"/>';
                    }
                    if (!empty($res['parentid'])) {
                        echo ' <img src="img/recurring.gif" width="15" height="15" alt="' . translate('Recurring') . '" title="' . translate('Recurring') . '"/>';
                    }
                    if ($res['start_date'] != $res['end_date']) {
                        echo ' <img src="img/multiday.gif" width="8" height="9" alt="' . translate('Multiple Day') . '" title="' . translate('Multiple Day') . '"/>';
                    }
                    echo "</p>\n";
                }
            }
            echo "</td>\n";
        }
        // Reset day counter
        $day = $week_start;
        echo "</tr>\n";
    }
    echo "</table>\n</td></tr></table>\n";
}
示例#2
0
/**
* Prints all reservations for a given day
* @param array $reservations array of all reservation data for this day
* @param int $datestamp the unix datestamp for the first day shown
* @param int $days number of days to print out
* @param string $scheduleid id of the this resource's schedule
* @param int $start_time starting time of the day for this reservation's schedule
* @param int $end_time ending time of the day for this reservation's schedule
* @param int $time_span the time span interval for this reservation's schedule
* @param bool $is_private if we are in privacy mode and should hide user details
*/
function print_day_resource_reservations($reservations, $datestamp, $days, $scheduleid, $start_time, $end_time, $time_span, $is_private = false)
{
    echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td class=\"tableBorder\">\n<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"0\">\n";
    $date_vars = getdate($datestamp);
    $col_width = intval(100 / $days);
    $hour_line = array();
    $date_cells_taken = array();
    $datestamps = array();
    // This will store the datestamp for each date on the calendar
    // Print out a date header for each date in the calendar view
    echo '<tr><td class="scheduleDateHeader">&nbsp;</td>';
    for ($day_count = 0; $day_count < $days; $day_count++) {
        $datestamps[$day_count] = mktime(0, 0, 0, $date_vars['mon'], $date_vars['mday'] + $day_count, $date_vars['year']);
        echo '<td width="' . $col_width . '%" class="scheduleDateHeader"><a href="schedule.php?scheduleid=' . $scheduleid . '&amp;date=' . sprintf('%d-%d-%d', $date_vars['mon'], $date_vars['mday'], $date_vars['year']) . '">' . translate_date('schedule_daily', $datestamps[$day_count]) . '</a></td>';
    }
    echo "</tr>\n";
    for ($i = 0; $i < count($reservations); $i++) {
        $reservations[$i]['starttime'] = Time::getAdjustedMinutes($reservations[$i]['starttime']);
        $reservations[$i]['endtime'] = Time::getAdjustedMinutes($reservations[$i]['endtime']);
        // If the reservation starts on a day other than the first day shown then just show it at the start time of the first day
        $day = $reservations[$i]['start_date'] >= $datestamp ? round(($reservations[$i]['start_date'] - $datestamp) / SECONDS_IN_DAY) : 0;
        // This will tell how many days ahead of the first day this reservation occurs
        // If the reseravtion ends on a day further from the last day shown, then make the endday equal to the last day
        $endday = $reservations[$i]['end_date'] <= $datestamps[$days - 1] ? round(($reservations[$i]['end_date'] - $datestamp) / SECONDS_IN_DAY) : $days - 1;
        // This will tell how many days ahead of the first day this reservation occurs
        // Get temporary start and end times for dates that are off the viewable days
        $starttime = $reservations[$i]['start_date'] >= $datestamp ? $reservations[$i]['starttime'] : $start_time;
        $endtime = $reservations[$i]['end_date'] <= $datestamps[$days - 1] ? $reservations[$i]['endtime'] : $end_time;
        $hour_line[$starttime][$day] =& $reservations[$i];
        // If this is a multi day reservation, make sure we populate the $hour_line of the last day/time for this reservation
        if ($day != $endday) {
            for ($d = $day + 1; $d <= $endday; $d++) {
                if ($datestamps[$d] == $reservations[$i]['end_date']) {
                    // If this is the last day of the reservation, we need to make sure that the end time is late enough to appear on the calendar
                    if ($endtime > $start_time) {
                        $hour_line[$start_time][$d] =& $reservations[$i];
                    }
                } else {
                    $hour_line[$start_time][$d] =& $reservations[$i];
                }
            }
        }
        // Keep an array of the cells that are taken by the rowspan of another reservation
        if ($day != $endday) {
            // MULTIDAY
            for ($d = $day; $d <= $endday; $d++) {
                if ($d == $day) {
                    for ($time = $starttime; $time < $end_time; $time += $time_span) {
                        $date_cells_taken[$d][$time] = 1;
                    }
                } else {
                    if ($d == $endday) {
                        for ($time = $start_time; $time < $endtime; $time += $time_span) {
                            $date_cells_taken[$d][$time] = 1;
                        }
                    } else {
                        for ($time = $start_time; $time < $end_time; $time += $time_span) {
                            $date_cells_taken[$d][$time] = 1;
                        }
                    }
                }
            }
        } else {
            // SINGLE DAY
            for ($time = $starttime; $time < $endtime; $time += $time_span) {
                $date_cells_taken[$day][$time] = 1;
            }
        }
    }
    // The reservation data is stored in a 2D array of time (x axis) and date (y axis)
    // This simply loops through all time/date possibilities and prints out the reservation data for each cell
    for ($time = $start_time; $time < $end_time; $time += $time_span) {
        echo '<tr><td valign="top" class="resourceName">' . Time::formatTime($time, false) . '</td>';
        for ($date = 0; $date < $days; $date++) {
            if (isset($hour_line[$time][$date])) {
                $res = $hour_line[$time][$date];
                if ($is_private) {
                    $res['fname'] = 'Private';
                    $res['lname'] = '';
                }
                $starttime = $res['starttime'];
                $endtime = $res['endtime'];
                // Set temporary start/end times for multiday reservations so that the rowspan is correct
                if ($res['start_date'] != $res['end_date']) {
                    if ($res['start_date'] != $datestamps[$date]) {
                        // If the res starts on a day other than today, then make the temp starting time equal to the day start
                        $starttime = $start_time;
                    }
                    if ($res['end_date'] != $datestamps[$date]) {
                        // If the res ends on a day other than today, then make the temp ending time equal to the day end
                        $endtime = $end_time;
                    }
                }
                $rowspan = intval(($endtime - $starttime) / $time_span);
                $js = "onmouseover=\"showSummary('details', event, '" . build_reservation_detail_div($res) . "');\" onmouseout=\"hideSummary('details');\" onmousemove=\"moveSummary('details', event);\"";
                echo "<td valign=\"top\" class=\"MyCalCellColor\" rowspan=\"{$rowspan}\" {$js}>&#8226; ";
                echo "<a href=\"javascript:reserve('" . RES_TYPE_MODIFY . "','','','{$res['resid']}','{$res['scheduleid']}');\">{$res['fname']} {$res['lname']}</a>";
                if (!empty($res['parentid'])) {
                    echo ' <img src="img/recurring.gif" width="15" height="15" alt="' . translate('Recurring') . '" title="' . translate('Recurring') . '"/>';
                }
                if ($res['start_date'] != $res['end_date']) {
                    echo ' <img src="img/multiday.gif" width="8" height="9" alt="' . translate('Multiple Day') . '" title="' . translate('Multiple Day') . '"/>';
                }
                echo '</td>';
            } else {
                if (!isset($date_cells_taken[$date][$time])) {
                    echo '<td valign="top" class="MyCalCellColorEmpty">&nbsp;</td>';
                    // There is no reservation for this time, print out an empty cell
                }
            }
        }
        echo "</tr>\n";
        // End the time row
    }
    echo "</table>\n</td></tr><table>\n";
}