+ // Alternate header style which also supports a simple footer
+ function Header3()
+ {
+ global $comp_path;
+
+ // Make this header the default for the current report ( used by NewLine() )
+ $this->headerFunc = 'Header3';
+
+ // Turn off cell padding for the main report header, restoring the current setting later
+ $oldcMargin = $this->cMargin;
+ $this->SetCellPadding(0);
+
+ // Set some constants which control header item layout
+ // only set them once or the PHP interpreter gets angry
+ if ($this->pageNumber == 0)
+ {
+ define('COMPANY_WIDTH', 150);
+ define('LOGO_HEIGHT', 50);
+ define('LOGO_Y_POS_ADJ_FACTOR', 0.74);
+ define('LABEL_WIDTH', 80);
+ define('PAGE_NUM_WIDTH', 60);
+ define('TITLE_FONT_SIZE', 14);
+ define('HEADER1_FONT_SIZE', 10);
+ define('HEADER2_FONT_SIZE', 9);
+ define('FOOTER_FONT_SIZE', 10);
+ define('FOOTER_MARGIN', 4);
+ }
+ // Set some variables which control header item layout
+ $companyCol = $this->endLine - COMPANY_WIDTH;
+ $headerFieldCol = $this->leftMargin + LABEL_WIDTH;
+ $pageNumCol = $this->endLine - PAGE_NUM_WIDTH;
+ $footerCol = $this->leftMargin + PAGE_NUM_WIDTH;
+ $footerRow = $this->bottomMargin - FOOTER_MARGIN;
+
+ // Calling this function generates a new PDF page after the first instance
+ $this->pageNumber++;
+ if ($this->pageNumber > 1)
+ {
+// // TODO: experimenting with line drawing to highlight current period
+// $this->SetLineWidth(1);
+// $this->LineTo($this->cols[3], 33, $this->cols[3], 534);
+// $this->LineTo($this->cols[4], 33, $this->cols[4], 534);
+// $this->SetLineWidth(0.1);
+
+ $this->newPage();
+ }
+ $this->row = $this->pageHeight - $this->topMargin;
+
+ // Set the color of dividing lines we'll draw
+ $oldDrawColor = $this->GetDrawColor();
+ $this->SetDrawColor(128, 128, 128);
+
+ // Tell TCPDF that we want to use its alias system to track the total number of pages
+ $this->AliasNbPages();
+
+ // Footer
+ if ($this->footerEnable)
+ {
+ $this->Line($footerRow, 1);
+ $prevFontSize = $this->fontSize;
+ $this->fontSize = FOOTER_FONT_SIZE;
+ $this->TextWrap($footerCol, $footerRow - ($this->fontSize + 1),
+ $pageNumCol - $footerCol, $this->footerText, $align = 'center',
+ $border = 0, $fill = 0, $link = NULL, $stretch = 1);
+ $this->TextWrap($pageNumCol, $footerRow - ($this->fontSize + 1),
+ PAGE_NUM_WIDTH, _("Page") . ' ' . $this->pageNumber . '/' . $this->getAliasNbPages(),
+ $align = 'right', $border = 0, $fill = 0, $link = NULL, $stretch = 1);
+ $this->fontSize = $prevFontSize;
+ }
+
+ //
+ // Header
+ //
+
+ // Print gray line across the page
+ $this->Line($this->row + 8, 1);
+
+ $this->NewLine();
+
+ // Print the report title nice and big
+ $oldFontSize = $this->fontSize;
+ $this->fontSize = TITLE_FONT_SIZE;
+ $this->Font('B');
+ $this->Text($this->leftMargin, $this->title, $companyCol);
+ $this->fontSize = HEADER1_FONT_SIZE;
+
+ // Print company logo if present and requested, or else just print company name
+ if ($this->companyLogoEnable && ($this->company['coy_logo'] != ''))
+ {
+ // Build a string specifying the location of the company logo file
+ $logo = $comp_path .'/'. user_company() . "/images/" . $this->company['coy_logo'];
+
+ // Width being zero means that the image will be scaled to the specified height
+ // keeping its aspect ratio intact.
+ $this->AddImage($logo, $companyCol, $this->row - (LOGO_HEIGHT * LOGO_Y_POS_ADJ_FACTOR), 0, LOGO_HEIGHT);
+ }
+ else
+ $this->Text($companyCol, $this->company['coy_name']);
+
+ // Dimension 1 - optional
+ // - only print if available and not blank
+ if (count($this->params) > 3)
+ if ($this->params[3]['from'] != '')
+ {
+ $this->NewLine(1, 0, $this->fontSize + 2);
+ $str = $this->params[3]['text'] . ':';
+ $this->Text($this->leftMargin, $str, $headerFieldCol);
+ $str = $this->params[3]['from'];
+ $this->Text($headerFieldCol, $str, $companyCol);
+ }
+
+ // Dimension 2 - optional
+ // - only print if available and not blank
+ if (count($this->params) > 4)
+ if ($this->params[4]['from'] != '')
+ {
+ $this->NewLine(1, 0, $this->fontSize + 2);
+ $str = $this->params[4]['text'] . ':';
+ $this->Text($this->leftMargin, $str, $headerFieldCol);
+ $str = $this->params[4]['from'];
+ $this->Text($headerFieldCol, $str, $companyCol);
+ }
+
+ // Tags - optional
+ // if present, it's an array of tag names
+ if (count($this->params) > 5)
+ if ($this->params[5]['from'] != '')
+ {
+ $this->NewLine(1, 0, $this->fontSize + 2);
+ $str = $this->params[5]['text'] . ':';
+ $this->Text($this->leftMargin, $str, $headerFieldCol);
+ $str = '';
+ for ($i = 0; $i < count($this->params[5]['from']); $i++)
+ {
+ if($i != 0)
+ $str .= ', ';
+ $str .= $this->params[5]['from'][$i];
+ }
+ $this->Text($headerFieldCol, $str, $companyCol);
+ }
+
+ // Report Date - time period covered
+ // - can specify a range, or just the end date (and the report contents
+ // should make it obvious what the beginning date is)
+ $this->NewLine(1, 0, $this->fontSize + 2);
+ $str = _("Report Period") . ':';
+ $this->Text($this->leftMargin, $str, $headerFieldCol);
+ $str = '';
+ if ($this->params[1]['from'] != '')
+ $str = $this->params[1]['from'] . ' - ';
+ $str .= $this->params[1]['to'];
+ $this->Text($headerFieldCol, $str, $companyCol);
+
+ // Turn off Bold
+ $this->Font();
+
+ $this->NewLine(1, 0, $this->fontSize + 1);
+
+ // Make the remaining report headings a little less important
+ $this->fontSize = HEADER2_FONT_SIZE;
+
+ // Timestamp of when this copy of the report was generated
+ $str = _("Generated At") . ':';
+ $this->Text($this->leftMargin, $str, $headerFieldCol);
+ $str = Today() . ' ' . Now();
+ if ($this->company['time_zone'])
+ $str .= ' ' . date('O') . ' GMT';
+ $this->Text($headerFieldCol, $str, $companyCol);
+
+ // Name of the user that generated this copy of the report
+ $this->NewLine(1, 0, $this->fontSize + 1);
+ $str = _("Generated By") . ':';
+ $this->Text($this->leftMargin, $str, $headerFieldCol);
+ $str = $this->user;
+ $this->Text($headerFieldCol, $str, $companyCol);
+
+ // Display any user-generated comments for this copy of the report
+ if ($this->params[0] != '') // Comments
+ {
+ $this->NewLine(1, 0, $this->fontSize + 1);
+ $str = _("Comments") . ':';
+ $this->Text($this->leftMargin, $str, $headerFieldCol);
+ $this->Font('B');
+ $this->Text($headerFieldCol, $this->params[0], $companyCol, 0, 0, 'left', 0, 0, $link=NULL, 1);
+ $this->Font();
+ }
+
+ // Add page numbering to header if footer is turned off
+ if (!$this->footerEnable)
+ {
+ $str = _("Page") . ' ' . $this->pageNumber . '/' . $this->getAliasNbPages();
+ $this->Text($pageNumCol, $str, 0, 0, 0, 'right', 0, 0, NULL, 1);
+ }
+
+ // Print gray line across the page
+ $this->Line($this->row - 5, 1);
+
+ // Restore font size to user-defined size
+ $this->fontSize = $oldFontSize;
+
+ // restore user-specified cell padding for column headers
+ $this->SetCellPadding($oldcMargin);
+
+ // scoot down the page a bit
+ $oldLineHeight = $this->lineHeight;
+ $this->lineHeight = $this->fontSize + 1;
+ $this->row -= ($this->lineHeight + 6);
+ $this->lineHeight = $oldLineHeight;
+
+ // Print the column headers!
+ $this->Font('I');
+ if ($this->headers2 != null)
+ {
+ $count = count($this->headers2);
+ for ($i = 0; $i < $count; $i++)
+ $this->TextCol2($i, $i + 1, $this->headers2[$i], $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1);
+ $this->NewLine();
+ }
+ $count = count($this->headers);
+ for ($i = 0; $i < $count; $i++)
+ $this->TextCol($i, $i + 1, $this->headers[$i], $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1);
+ $this->Font();
+
+ $this->NewLine(2);
+
+ // restore user-specified draw color
+ $this->SetDrawColor($oldDrawColor[0], $oldDrawColor[1], $oldDrawColor[2]);
+ }
+
+ /**
+ * Format a numeric string date into something nicer looking.
+ *
+ * @param string $date Date string to be formatted.
+ * @param int $input_format Format of the input string. Possible values are:<ul><li>0: user's default (default)</li></ul>
+ * @param int $output_format Format of the output string. Possible values are:<ul><li>0: Month (word) Day (numeric), 4-digit Year - Example: January 1, 2000 (default)</li><li>1: Month 4-digit Year - Example: January 2000</li><li>2: Month Abbreviation 4-digit Year - Example: Jan 2000</li></ul>
+ * @access public
+ */
+ function DatePrettyPrint($date, $input_format = 0, $output_format = 0)
+ {
+ if ($date != '')
+ {
+ $date = date2sql($date);
+ $year = (int) (substr($date, 0, 4));
+ $month = (int) (substr($date, 5, 2));
+ $day = (int) (substr($date, 8, 2));
+ if ($output_format == 0)
+ return(date('F j, Y', mktime(12, 0, 0, $month, $day, $year)));
+ elseif ($output_format == 1)
+ return(date('F Y', mktime(12, 0, 0, $month, $day, $year)));
+ elseif ($output_format == 2)
+ return(date('M Y', mktime(12, 0, 0, $month, $day, $year)));
+ }
+ else
+ return $date;
+ }
+