- if ($report['show_totals_only']) {
- // Totals only report. Output subtotals.
-
- // Determine group_by header.
- if ('cf_1' == $group_by)
- $group_by_header = htmlspecialchars($custom_fields->fields[0]['label']);
- else {
- $key = 'label.'.$group_by;
- $group_by_header = $i18n->getKey($key);
- }
-
- $body .= '<table border="0" cellpadding="4" cellspacing="0" width="100%">';
- $body .= '<tr>';
- $body .= '<td style="'.$tableHeader.'">'.$group_by_header.'</td>';
- if ($report['show_duration'])
- $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.duration').'</td>';
- if ($report['show_cost'])
- $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.cost').'</td>';
- $body .= '</tr>';
- foreach($subtotals as $subtotal) {
- $body .= '<tr style="'.$rowSubtotal.'">';
- $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($subtotal['name'] ? htmlspecialchars($subtotal['name']) : ' ').'</td>';
- if ($report['show_duration']) {
- $body .= '<td style="'.$cellRightAlignedSubtotal.'">';
- if ($subtotal['time'] <> '0:00') $body .= $subtotal['time'];
- $body .= '</td>';
- }
- if ($report['show_cost']) {
- $body .= '<td style="'.$cellRightAlignedSubtotal.'">';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotal['cost'] : $subtotal['expenses'];
- $body .= '</td>';
- }
- $body .= '</tr>';
- }
-
- // Print totals.
- $body .= '<tr><td> </td></tr>';
- $body .= '<tr style="'.$rowSubtotal.'">';
- $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.$i18n->getKey('label.total').'</td>';
- if ($report['show_duration']) {
- $body .= '<td style="'.$cellRightAlignedSubtotal.'">';
- if ($totals['time'] <> '0:00') $body .= $totals['time'];
- $body .= '</td>';
- }
- if ($report['show_cost']) {
- $body .= '<td nowrap style="'.$cellRightAlignedSubtotal.'">'.htmlspecialchars($user->currency).' ';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $totals['cost'] : $totals['expenses'];
- $body .= '</td>';
- }
- $body .= '</tr>';
-
- $body .= '</table>';
- } else {
- // Regular report.
-
- // Print table header.
- $body .= '<table border="0" cellpadding="4" cellspacing="0" width="100%">';
- $body .= '<tr>';
- $body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.date').'</td>';
- if ($user->canManageTeam() || $user->isClient())
- $body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.user').'</td>';
- if ($report['show_client'])
- $body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.client').'</td>';
- if ($report['show_project'])
- $body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.project').'</td>';
- if ($report['show_task'])
- $body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.task').'</td>';
- if ($report['show_custom_field_1'])
- $body .= '<td style="'.$tableHeader.'">'.htmlspecialchars($custom_fields->fields[0]['label']).'</td>';
- if ($report['show_start'])
- $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.start').'</td>';
- if ($report['show_end'])
- $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.finish').'</td>';
- if ($report['show_duration'])
- $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.duration').'</td>';
- if ($report['show_note'])
- $body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.note').'</td>';
- if ($report['show_cost'])
- $body .= '<td style="'.$tableHeaderCentered.'" width="5%">'.$i18n->getKey('label.cost').'</td>';
- if ($report['show_invoice'])
- $body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.invoice').'</td>';
- $body .= '</tr>';
-
- // Initialize variables to print subtotals.
- if ($items && 'no_grouping' != $group_by) {
- $print_subtotals = true;
- $first_pass = true;
- $prev_grouped_by = '';
- $cur_grouped_by = '';
- }
- // Initialize variables to alternate color of rows for different dates.
- $prev_date = '';
- $cur_date = '';
- $row_style = $rowItem;
-
- // Print report items.
- if (is_array($items)) {
- foreach ($items as $record) {
- $cur_date = $record['date'];
- // Print a subtotal row after a block of grouped items.
- if ($print_subtotals) {
- $cur_grouped_by = $record['grouped_by'];
- if ($cur_grouped_by != $prev_grouped_by && !$first_pass) {
- $body .= '<tr style="'.$rowSubtotal.'">';
- $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.$i18n->getKey('label.subtotal').'</td>';
- $subtotal_name = htmlspecialchars($subtotals[$prev_grouped_by]['name']);
- if ($user->canManageTeam() || $user->isClient()) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'user' ? $subtotal_name : '').'</td>';
- if ($report['show_client']) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'client' ? $subtotal_name : '').'</td>';
- if ($report['show_project']) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'project' ? $subtotal_name : '').'</td>';
- if ($report['show_task']) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'task' ? $subtotal_name : '').'</td>';
- if ($report['show_custom_field_1']) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'cf_1' ? $subtotal_name : '').'</td>';
- if ($report['show_start']) $body .= '<td></td>';
- if ($report['show_end']) $body .= '<td></td>';
- if ($report['show_duration']) $body .= '<td style="'.$cellRightAlignedSubtotal.'">'.$subtotals[$prev_grouped_by]['time'].'</td>';
- if ($report['show_note']) $body .= '<td></td>';
- if ($report['show_cost']) {
- $body .= '<td style="'.$cellRightAlignedSubtotal.'">';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$prev_grouped_by]['cost'] : $subtotals[$prev_grouped_by]['expenses'];
- $body .= '</td>';
- }
- if ($report['show_invoice']) $body .= '<td></td>';
- $body .= '</tr>';
- $body .= '<tr><td> </td></tr>';
- }
- $first_pass = false;
- }
-
- // Print a regular row.
- if ($cur_date != $prev_date)
- $row_style = ($row_style == $rowItem) ? $rowItemAlt : $rowItem;
- $body .= '<tr style="'.$row_style.'">';
- $body .= '<td style="'.$cellLeftAligned.'">'.$record['date'].'</td>';
- if ($user->canManageTeam() || $user->isClient())
- $body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['user']).'</td>';
- if ($report['show_client'])
- $body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['client']).'</td>';
- if ($report['show_project'])
- $body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['project']).'</td>';
- if ($report['show_task'])
- $body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['task']).'</td>';
- if ($report['show_custom_field_1'])
- $body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['cf_1']).'</td>';
- if ($report['show_start'])
- $body .= '<td nowrap style="'.$cellRightAligned.'">'.$record['start'].'</td>';
- if ($report['show_end'])
- $body .= '<td nowrap style="'.$cellRightAligned.'">'.$record['finish'].'</td>';
- if ($report['show_duration'])
- $body .= '<td style="'.$cellRightAligned.'">'.$record['duration'].'</td>';
- if ($report['show_note'])
- $body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['note']).'</td>';
- if ($report['show_cost'])
- $body .= '<td style="'.$cellRightAligned.'">'.$record['cost'].'</td>';
- if ($report['show_invoice'])
- $body .= '<td style="'.$cellRightAligned.'">'.htmlspecialchars($record['invoice']).'</td>';
- $body .= '</tr>';
-
- $prev_date = $record['date'];
- if ($print_subtotals)
- $prev_grouped_by = $record['grouped_by'];
- }
- }
-
- // Print a terminating subtotal.
- if ($print_subtotals) {
- $body .= '<tr style="'.$rowSubtotal.'">';
- $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.$i18n->getKey('label.subtotal').'</td>';
- $subtotal_name = htmlspecialchars($subtotals[$cur_grouped_by]['name']);
- if ($user->canManageTeam() || $user->isClient()) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'user' ? $subtotal_name : '').'</td>';
- if ($report['show_client']) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'client' ? $subtotal_name : '').'</td>';
- if ($report['show_project']) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'project' ? $subtotal_name : '').'</td>';
- if ($report['show_task']) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'task' ? $subtotal_name : '').'</td>';
- if ($report['show_custom_field_1']) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'cf_1' ? $subtotal_name : '').'</td>';
- if ($report['show_start']) $body .= '<td></td>';
- if ($report['show_end']) $body .= '<td></td>';
- if ($report['show_duration']) $body .= '<td style="'.$cellRightAlignedSubtotal.'">'.$subtotals[$cur_grouped_by]['time'].'</td>';
- if ($report['show_note']) $body .= '<td></td>';
- if ($report['show_cost']) {
- $body .= '<td style="'.$cellRightAlignedSubtotal.'">';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$cur_grouped_by]['cost'] : $subtotals[$cur_grouped_by]['expenses'];
- $body .= '</td>';
- }
- if ($report['show_invoice']) $body .= '<td></td>';
- $body .= '</tr>';
- }
-
- // Print totals.
- $body .= '<tr><td> </td></tr>';
- $body .= '<tr style="'.$rowSubtotal.'">';
- $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.$i18n->getKey('label.total').'</td>';
- if ($user->canManageTeam() || $user->isClient()) $body .= '<td></td>';
- if ($report['show_client']) $body .= '<td></td>';
- if ($report['show_project']) $body .= '<td></td>';
- if ($report['show_task']) $body .= '<td></td>';
- if ($report['show_custom_field_1']) $body .= '<td></td>';
- if ($report['show_start']) $body .= '<td></td>';
- if ($report['show_end']) $body .= '<td></td>';
- if ($report['show_duration']) $body .= '<td style="'.$cellRightAlignedSubtotal.'">'.$totals['time'].'</td>';
- if ($report['show_note']) $body .= '<td></td>';
- if ($report['show_cost']) {
- $body .= '<td nowrap style="'.$cellRightAlignedSubtotal.'">'.htmlspecialchars($user->currency).' ';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $totals['cost'] : $totals['expenses'];
- $body .= '</td>';
- }
- if ($report['show_invoice']) $body .= '<td></td>';
- $body .= '</tr>';
-
- $body .= '</table>';
- }
-
- // Output footer.
- if (!defined('REPORT_FOOTER') || !(REPORT_FOOTER == false))
- $body .= '<p style="text-align: center;">'.$i18n->getKey('form.mail.footer').'</p>';