X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=topdf.php;h=2be45cc4930173673c9e3f714e14bcfc8c22ca6d;hb=ecf7d911c95935f8cfb2403f645cd12f93d8c3f5;hp=744ef4a2a5907aa41effced4aaa76221b9b3da03;hpb=ed6483fa05ff6f489a7cfc4ff72fdc4d4d8f3889;p=timetracker.git diff --git a/topdf.php b/topdf.php index 744ef4a2..2be45cc4 100644 --- a/topdf.php +++ b/topdf.php @@ -35,6 +35,12 @@ import('form.Form'); import('form.ActionForm'); import('ttReportHelper'); +// Access check. +if (!ttAccessAllowed('view_own_reports')) { + header('Location: access_denied.php'); + exit(); +} + // Check whether TCPDF library is available. if (!file_exists('WEB-INF/lib/tcpdf/')) die('TCPDF library is not found in WEB-INF/lib/tcpdf/'); @@ -42,14 +48,8 @@ if (!file_exists('WEB-INF/lib/tcpdf/')) // Include TCPDF library. require_once('WEB-INF/lib/tcpdf/tcpdf.php'); -// Access check. -if (!ttAccessCheck(right_view_reports)) { - header('Location: access_denied.php'); - exit(); -} - // Use custom fields plugin if it is enabled. -if (in_array('cf', explode(',', $user->plugins))) { +if ($user->isPluginEnabled('cf')) { require_once('plugins/CustomFields.class.php'); $custom_fields = new CustomFields($user->team_id); } @@ -87,6 +87,9 @@ if ($items && 'no_grouping' != $group_by) { $cur_grouped_by = ''; } +// Build a string to use as filename for the files being downloaded. +$filename = strtolower($i18n->getKey('title.report')).'_'.$bean->mValues['start_date'].'_'.$bean->mValues['end_date']; + // Start preparing HTML to build PDF from. $styleHeader = 'style="background-color:#a6ccf7;"'; $styleSubtotal = 'style="background-color:#e0e0e0;"'; @@ -156,10 +159,11 @@ if ($totals_only) { if ($bean->getAttribute('chduration')) { $colspan++; $html .= "".$i18n->getKey('label.duration').''; } if ($bean->getAttribute('chnote')) { $colspan++; $html .= ''.$i18n->getKey('label.note').''; } if ($bean->getAttribute('chcost')) { $colspan++; $html .= "".$i18n->getKey('label.cost').''; } + if ($bean->getAttribute('chpaid')) { $colspan++; $html .= "".$i18n->getKey('label.paid').''; } if ($bean->getAttribute('chinvoice')) { $colspan++; $html .= ''.$i18n->getKey('label.invoice').''; } $html .= ''; $html .= ''; - + foreach ($items as $item) { // Print a subtotal for a block of grouped values. $cur_date = $item['date']; @@ -205,6 +209,7 @@ if ($totals_only) { $html .= $subtotals[$prev_grouped_by]['expenses']; $html .= ''; } + if ($bean->getAttribute('chpaid')) $html .= ''; if ($bean->getAttribute('chinvoice')) $html .= ''; $html .= ''; $html .= ' '; @@ -232,13 +237,18 @@ if ($totals_only) { $html .= $item['expense']; $html .= ''; } + if ($bean->getAttribute('chpaid')) { + $html .= ''; + $html .= $item['paid'] == 1 ? $i18n->getKey('label.yes') : $i18n->getKey('label.no'); + $html .= ''; + } if ($bean->getAttribute('chinvoice')) $html .= ''.htmlspecialchars($item['invoice']).''; $html .= ''; - + $prev_date = $item['date']; if ($print_subtotals) $prev_grouped_by = $item['grouped_by']; } - + // Print a terminating subtotal. if ($print_subtotals) { $html .= ''; @@ -280,10 +290,11 @@ if ($totals_only) { $html .= $subtotals[$prev_grouped_by]['expenses']; $html .= ''; } + if ($bean->getAttribute('chpaid')) $html .= ''; if ($bean->getAttribute('chinvoice')) $html .= ''; $html .= ''; } - + // Print totals. $html .= ' '; $html .= ''; @@ -302,13 +313,19 @@ if ($totals_only) { if ($user->canManageTeam() || $user->isClient()) $html .= $totals['cost']; else - $html .= $totals['expenses']; + $html .= $totals['expenses']; $html .= ''; } + if ($bean->getAttribute('chpaid')) $html .= ''; if ($bean->getAttribute('chinvoice')) $html .= ''; $html .= ''; $html .= ''; } + +// Output footer. +if (!defined('REPORT_FOOTER') || !(REPORT_FOOTER == false)) // By default we print it unless explicitely defined as false. + $html .= '

'.$i18n->getKey('form.mail.footer').'

'; + // By this time we have html ready. // Determine title for report. @@ -322,27 +339,27 @@ header('Cache-Control: post-check=0, pre-check=0', false); header('Cache-Control: private', false); header('Content-Type: application/pdf'); -header('Content-Disposition: attachment; filename="timesheet.pdf"'); +header('Content-Disposition: attachment; filename="'.$filename.'.pdf"'); // Beginning of TCPDF code here. // Extend TCPDF class so that we can use custom header and footer. -class MyyPDF extends TCPDF { +class ttPDF extends TCPDF { public $image_file = 'images/tt_logo.png'; // Image file for the logo in header. public $page_word = 'Page'; // Localized "Page" word in footer, ex: Page 1/2. - + // SetImageFile - sets image file name. public function SetImageFile($imgFile) { $this->image_file = $imgFile; } - + // SetPageWord - sets page word for footer. public function SetPageWord($pageWord) { $this->page_word = $pageWord; } - + // Page header. public function Header() { // Print logo, which is the only element of our custom header. @@ -354,14 +371,14 @@ class MyyPDF extends TCPDF { // Position at 15 mm from bottom. $this->SetY(-15); // Set font. - $this->SetFont('helvetica', 'I', 8); + $this->SetFont('freeserif', 'I', 8); // Print localized page number. $this->Cell(0, 10, $this->page_word.' '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M'); } } // Create new PDF document. -$pdf = new MyyPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); +$pdf = new ttPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // If custom logo file exists - set it. if (file_exists('images/'.$user->team_id.'.png')) @@ -369,8 +386,6 @@ if (file_exists('images/'.$user->team_id.'.png')) // Set page word for the footer. $pdf->SetPageWord($i18n->getKey('label.page')); -// TODO: currently, we have problems rendering PDF in some languages such as Russian (headers, page word). -// Not sure how to fix it... One option is to switch to mPDF - consider. // Set document information. $pdf->SetCreator(PDF_CREATOR); @@ -393,15 +408,14 @@ $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // Add a page. $pdf->AddPage(); -// Set font. -$pdf->SetFont('helvetica', '', 10); +// Set font (freeserif seems to work for all languages). +$pdf->SetFont('freeserif', '', 10); // helvetica here does not work for Russian. // Write HTML. $pdf->writeHTML($html, true, false, false, false, ''); // Close and output PDF document. // $pdf->Output('timesheet.pdf', 'I'); // This will display inline in browser. -$pdf->Output('timesheet.pdf', 'D'); // D is for downloads. +$pdf->Output($filename.'.pdf', 'D'); // D is for downloads. // End of of TCPDF code. -?> \ No newline at end of file