Hi StamfordRob,
I've made a fairly large change to the way the function is handled since the original post. The original code relied on the user's permission to add a booking, meaning that past reservations could not be viewed. This revision fixes that issue. Below is the entire function:
/**
* Print out the reservations for each resource on each day
* @param none
*/
function print_reservations() {
global $conf;
if (!$this->machids)
return;
$current_date = $this->_date['current']; // Store current_date so we dont have to access the array every time
// Repeat this whole process for each resource in the database
for ($count = 0; $count < count($this->machids); $count++) {
$prevTime = $this->startDay; // Previous time holder
$totCol = intval(($this->endDay - $this->startDay) / $this->timespan); // Total columns holder
$cur_resource = $this->machids[$count];
// Store info about this current resource in local vars
$id = $cur_resource['machid'];
$name = $cur_resource['name'];
$status = $cur_resource['status'];
$approval = $cur_resource['approval'];
$shown = false; // Default resource visiblilty to not shown
$viewable_date = $this->isViewableDate($current_date, $cur_resource['min_notice_time'], $cur_resource['max_notice_time']);
// If the date has not passed, resource is active and user has permission,
// or the user is the admin allow reservations to be made
$has_permission = $this->user->has_perm($cur_resource['machid']);
if ($shown = $this->canShowReservation($viewable_date, $cur_resource) && $has_permission) {
$color = 'cellColor' . ($count%2);
print_name_cell($current_date, $id, $name, $shown, $this->scheduleType == BLACKOUT_ONLY, $this->scheduleid, $approval, $color);
$index = $id;
if (isset($this->res[$index])) {
for ($i = 0; $i < count($this->res[$index]); $i++) {
$rs = $this->res[$index][$i];
// If it doesnt start sometime today, end sometime today, or surround today, just skip over it
if (
!(($rs['start_date'] >= $current_date && $rs['start_date'] <= $current_date)
|| ($rs['end_date'] >= $current_date && $rs['end_date'] <= $current_date)
|| ($rs['start_date'] <= $current_date && $rs['end_date'] >= $current_date))
) {
continue;
}
// Just skip the reservation if the ending date/time is todays start time
if ($rs['end_date'] == $current_date && $rs['endtime'] == $this->startDay) { continue; }
// If the reservation starts before or ends after todays date, just pretend it ends today so it shows correctly
if ($rs['start_date'] < $current_date) {
$rs['starttime'] = $this->startDay;
}
if ($rs['end_date'] > $current_date) {
$rs['endtime'] = $this->endDay;
}
// Print out row of reservations
$thisStart = $rs['starttime'];
$thisEnd = $rs['endtime'];
if ($thisStart < $this->startDay && $thisEnd > $this->startDay)
$thisStart = $this->startDay;
else if ($thisStart < $this->startDay && $thisEnd <= $this->startDay)
continue; // Ignore reservation, its off the schedule
if ($thisStart < $this->endDay && $thisEnd > $this->endDay)
$thisEnd = $this->endDay;
else if ($thisStart >= $this->endDay && $thisEnd > $this->startDay)
continue; // Ignore reservation, its off the schedule
$colspan = intval(($thisEnd - $thisStart) / $this->timespan);
$this->move_to_starting_col($rs, $thisStart, $prevTime, $this->timespan, $id, $current_date, $shown, $color);
if ($rs['is_blackout'] == 1)
$this->write_blackout($rs, $colspan);
else
$this->write_reservation($rs, $colspan, $viewable_date);
// Set prevTime to this reservation's ending time
$prevTime = $thisEnd;
}
}
$this->finish_row($this->endDay, $prevTime, $this->timespan, $id, $current_date, $shown, $color);
}
}}