towards PEAR coding standards

This commit is contained in:
Marc Delisle
2005-12-04 19:28:28 +00:00
parent 88ff1c4181
commit 4a89855656

View File

@@ -7,11 +7,12 @@
*/ */
define('FPDF_FONTPATH','./libraries/fpdf/font/'); define('FPDF_FONTPATH', './libraries/fpdf/font/');
//if ($charset == 'utf-8') { //if ($charset == 'utf-8') {
define('PMA_PDF_FONT', 'FreeSans'); define('PMA_PDF_FONT', 'FreeSans');
require_once('./libraries/fpdf/ufpdf.php'); require_once('./libraries/fpdf/ufpdf.php');
class PMA_FPDF extends UFPDF { class PMA_FPDF extends UFPDF
{
}; };
//} else { //} else {
// define('PMA_PDF_FONT', 'Arial'); // define('PMA_PDF_FONT', 'Arial');
@@ -23,104 +24,108 @@ define('FPDF_FONTPATH','./libraries/fpdf/font/');
// Adapted from a LGPL script by Philip Clarke // Adapted from a LGPL script by Philip Clarke
class PMA_PDF extends PMA_FPDF { class PMA_PDF extends PMA_FPDF
{
var $tablewidths; var $tablewidths;
var $headerset; var $headerset;
var $footerset; var $footerset;
// overloading of a fpdf function: // overloading of a fpdf function:
function _beginpage($orientation) { function _beginpage($orientation)
{
$this->page++; $this->page++;
// solved the problem of overwriting a page, if it already exists // solved the problem of overwriting a page, if it already exists
if(!isset($this->pages[$this->page])) { if (!isset($this->pages[$this->page])) {
$this->pages[$this->page]=''; $this->pages[$this->page] = '';
} }
$this->state=2; $this->state = 2;
$this->x=$this->lMargin; $this->x = $this->lMargin;
$this->y=$this->tMargin; $this->y = $this->tMargin;
$this->lasth=0; $this->lasth = 0;
$this->FontFamily=''; $this->FontFamily = '';
//Page orientation //Page orientation
if (!$orientation) { if (!$orientation) {
$orientation=$this->DefOrientation; $orientation = $this->DefOrientation;
} else { } else {
$orientation=strtoupper($orientation{0}); $orientation = strtoupper($orientation{0});
if ($orientation!=$this->DefOrientation){ if ($orientation != $this->DefOrientation) {
$this->OrientationChanges[$this->page]=true; $this->OrientationChanges[$this->page] = true;
} }
} }
if ($orientation!=$this->CurOrientation) { if ($orientation != $this->CurOrientation) {
//Change orientation //Change orientation
if ($orientation=='P') { if ($orientation == 'P') {
$this->wPt=$this->fwPt; $this->wPt = $this->fwPt;
$this->hPt=$this->fhPt; $this->hPt = $this->fhPt;
$this->w=$this->fw; $this->w = $this->fw;
$this->h=$this->fh; $this->h = $this->fh;
} else { } else {
$this->wPt=$this->fhPt; $this->wPt = $this->fhPt;
$this->hPt=$this->fwPt; $this->hPt = $this->fwPt;
$this->w=$this->fh; $this->w = $this->fh;
$this->h=$this->fw; $this->h = $this->fw;
}
$this->PageBreakTrigger = $this->h - $this->bMargin;
$this->CurOrientation = $orientation;
} }
$this->PageBreakTrigger=$this->h-$this->bMargin;
$this->CurOrientation=$orientation;
} }
}
function Header() { function Header()
{
global $maxY; global $maxY;
// Check if header for this page already exists // Check if header for this page already exists
if (!isset($this->headerset[$this->page])) { if (!isset($this->headerset[$this->page])) {
$fullwidth = 0; $fullwidth = 0;
foreach($this->tablewidths as $width) { foreach ($this->tablewidths as $width) {
$fullwidth += $width; $fullwidth += $width;
} }
$this->SetY(($this->tMargin) - ($this->FontSizePt/$this->k)*2); $this->SetY(($this->tMargin) - ($this->FontSizePt/$this->k)*2);
$this->cellFontSize = $this->FontSizePt ; $this->cellFontSize = $this->FontSizePt ;
$this->SetFont(PMA_PDF_FONT,'',( ( $this->titleFontSize) ? $this->titleFontSize : $this->FontSizePt )); $this->SetFont(PMA_PDF_FONT, '' ,($this->titleFontSize ? $this->titleFontSize : $this->FontSizePt ));
$this->Cell(0,$this->FontSizePt,$this->titleText,0,1,'C'); $this->Cell(0, $this->FontSizePt, $this->titleText, 0, 1, 'C');
$l = ($this->lMargin); $l = ($this->lMargin);
$this->SetFont(PMA_PDF_FONT,'',$this->cellFontSize); $this->SetFont(PMA_PDF_FONT, '', $this->cellFontSize);
foreach($this->colTitles as $col => $txt) { foreach ($this->colTitles as $col => $txt) {
$this->SetXY($l,($this->tMargin)); $this->SetXY($l, ($this->tMargin));
$this->MultiCell($this->tablewidths[$col], $this->FontSizePt,$txt); $this->MultiCell($this->tablewidths[$col], $this->FontSizePt, $txt);
$l += $this->tablewidths[$col] ; $l += $this->tablewidths[$col] ;
$maxY = ($maxY < $this->getY()) ? $this->getY() : $maxY ; $maxY = ($maxY < $this->getY()) ? $this->getY() : $maxY ;
} }
$this->SetXY($this->lMargin,$this->tMargin); $this->SetXY($this->lMargin, $this->tMargin);
$this->setFillColor(200,200,200); $this->setFillColor(200, 200, 200);
$l = ($this->lMargin); $l = ($this->lMargin);
foreach($this->colTitles as $col => $txt) { foreach ($this->colTitles as $col => $txt) {
$this->SetXY($l,$this->tMargin); $this->SetXY($l, $this->tMargin);
$this->cell($this->tablewidths[$col],$maxY-($this->tMargin),'',1,0,'L',1); $this->cell($this->tablewidths[$col], $maxY-($this->tMargin), '', 1, 0, 'L', 1);
$this->SetXY($l,$this->tMargin); $this->SetXY($l, $this->tMargin);
$this->MultiCell($this->tablewidths[$col],$this->FontSizePt,$txt,0,'C'); $this->MultiCell($this->tablewidths[$col], $this->FontSizePt, $txt, 0, 'C');
$l += $this->tablewidths[$col]; $l += $this->tablewidths[$col];
} }
$this->setFillColor(255,255,255); $this->setFillColor(255, 255, 255);
// set headerset // set headerset
$this->headerset[$this->page] = 1; $this->headerset[$this->page] = 1;
} }
$this->SetY($maxY); $this->SetY($maxY);
} }
function Footer() { function Footer()
{
// Check if footer for this page already exists // Check if footer for this page already exists
if (!isset($this->footerset[$this->page])) { if (!isset($this->footerset[$this->page])) {
$this->SetY(-15); $this->SetY(-15);
//Page number //Page number
$this->Cell(0,10, $GLOBALS['strPageNumber'] .' '.$this->PageNo() .'/{nb}','T',0,'C'); $this->Cell(0, 10, $GLOBALS['strPageNumber'] .' '.$this->PageNo() .'/{nb}', 'T', 0, 'C');
// set footerset // set footerset
$this->footerset[$this->page] = 1; $this->footerset[$this->page] = 1;
} }
} }
function morepagestable($lineheight=8) { function morepagestable($lineheight=8)
{
// some things to set and 'remember' // some things to set and 'remember'
$l = $this->lMargin; $l = $this->lMargin;
$startheight = $h = $this->GetY(); $startheight = $h = $this->GetY();
@@ -140,13 +145,12 @@ function morepagestable($lineheight=8) {
while ($data = PMA_DBI_fetch_row($this->results)) { while ($data = PMA_DBI_fetch_row($this->results)) {
$this->page = $currpage; $this->page = $currpage;
// write the horizontal borders // write the horizontal borders
$this->Line($l,$h,$fullwidth+$l,$h); $this->Line($l, $h, $fullwidth+$l, $h);
// write the content and remember the height of the highest col // write the content and remember the height of the highest col
foreach($data as $col => $txt) { foreach ($data as $col => $txt) {
$this->page = $currpage; $this->page = $currpage;
$this->SetXY($l,$h); $this->SetXY($l, $h);
$this->MultiCell($this->tablewidths[$col],$lineheight,$txt,0,$this->colAlign[$col]); $this->MultiCell($this->tablewidths[$col], $lineheight, $txt, 0, $this->colAlign[$col]);
$l += $this->tablewidths[$col]; $l += $this->tablewidths[$col];
@@ -169,32 +173,32 @@ function morepagestable($lineheight=8) {
// set the $currpage to the last page // set the $currpage to the last page
$currpage = $maxpage; $currpage = $maxpage;
unset($data[$row]); unset($data[$row]);
$row++ ; $row++;
} }
// draw the borders // draw the borders
// we start adding a horizontal line on the last page // we start adding a horizontal line on the last page
$this->page = $maxpage; $this->page = $maxpage;
$this->Line($l,$h,$fullwidth+$l,$h); $this->Line($l, $h, $fullwidth+$l, $h);
// now we start at the top of the document and walk down // now we start at the top of the document and walk down
for ($i = $startpage; $i <= $maxpage; $i++) { for ($i = $startpage; $i <= $maxpage; $i++) {
$this->page = $i; $this->page = $i;
$l = $this->lMargin; $l = $this->lMargin;
$t = ($i == $startpage) ? $startheight : $this->tMargin; $t = ($i == $startpage) ? $startheight : $this->tMargin;
$lh = ($i == $maxpage) ? $h : $this->h-$this->bMargin; $lh = ($i == $maxpage) ? $h : $this->h-$this->bMargin;
$this->Line($l,$t,$l,$lh); $this->Line($l, $t, $l, $lh);
foreach($this->tablewidths as $width) { foreach ($this->tablewidths as $width) {
$l += $width; $l += $width;
$this->Line($l,$t,$l,$lh); $this->Line($l, $t, $l, $lh);
} }
} }
// set it to the last page, if not it'll cause some problems // set it to the last page, if not it'll cause some problems
$this->page = $maxpage; $this->page = $maxpage;
} }
function mysql_report($query,$attr=array()){ function mysql_report($query, $attr = array())
{
foreach($attr as $key=>$val){ foreach ($attr as $key => $val){
$this->$key = $val ; $this->$key = $val ;
} }
@@ -208,11 +212,11 @@ function mysql_report($query,$attr=array()){
if (!isset($this->tablewidths)){ if (!isset($this->tablewidths)){
// starting col width // starting col width
$this->sColWidth = (($this->w-$this->lMargin-$this->rMargin))/$this->numFields; $this->sColWidth = ($this->w - $this->lMargin - $this->rMargin) / $this->numFields;
// loop through results header and set initial col widths/ titles/ alignment // loop through results header and set initial col widths/ titles/ alignment
// if a col title is less than the starting col width / reduce that column size // if a col title is less than the starting col width / reduce that column size
for($i=0;$i<$this->numFields;$i++){ for ($i=0; $i < $this->numFields; $i++){
$stringWidth = $this->getstringwidth($this->fields[$i]->name) + 6 ; $stringWidth = $this->getstringwidth($this->fields[$i]->name) + 6 ;
// set any column titles less than the start width to the column title width // set any column titles less than the start width to the column title width
if (($stringWidth) < $this->sColWidth){ if (($stringWidth) < $this->sColWidth){
@@ -231,14 +235,14 @@ function mysql_report($query,$attr=array()){
// loop through the data, any column whose contents is bigger i // loop through the data, any column whose contents is bigger i
// that the col size is resized // that the col size is resized
while ($row = PMA_DBI_fetch_row($this->results)) { while ($row = PMA_DBI_fetch_row($this->results)) {
foreach($colFits as $key=>$val){ foreach ($colFits as $key => $val) {
$stringWidth = $this->getstringwidth($row[$key]) + 6 ; $stringWidth = $this->getstringwidth($row[$key]) + 6 ;
if( ($stringWidth) > $this->sColWidth ){ if ($stringWidth > $this->sColWidth) {
// any col where row is bigger than the start width is now discarded // any col where row is bigger than the start width is now discarded
unset($colFits[$key]); unset($colFits[$key]);
} else{ } else {
// if text is not bigger than the current column width setting enlarge the column // if text is not bigger than the current column width setting enlarge the column
if( ($stringWidth) > $val ){ if ($stringWidth > $val) {
$colFits[$key] = ($stringWidth) ; $colFits[$key] = ($stringWidth) ;
} }
} }
@@ -246,17 +250,17 @@ function mysql_report($query,$attr=array()){
} }
$totAlreadyFitted = 0; $totAlreadyFitted = 0;
foreach($colFits as $key=>$val){ foreach ($colFits as $key => $val){
// set fitted columns to smallest size // set fitted columns to smallest size
$this->tablewidths[$key] = $val; $this->tablewidths[$key] = $val;
// to work out how much (if any) space has been freed up // to work out how much (if any) space has been freed up
$totAlreadyFitted += $val; $totAlreadyFitted += $val;
} }
$surplus = (sizeof($colFits)*$this->sColWidth) - ($totAlreadyFitted); $surplus = (sizeof($colFits) * $this->sColWidth) - $totAlreadyFitted;
for($i=0; $i<$this->numFields; $i++){ for ($i=0; $i < $this->numFields; $i++) {
if (!in_array($i,array_keys($colFits))){ if (!in_array($i, array_keys($colFits))) {
$this->tablewidths[$i] = $this->sColWidth + ($surplus/(($this->numFields)-sizeof($colFits))); $this->tablewidths[$i] = $this->sColWidth + ($surplus / ($this->numFields - sizeof($colFits)));
} }
} }
@@ -275,7 +279,7 @@ function mysql_report($query,$attr=array()){
$this->morepagestable($this->FontSizePt); $this->morepagestable($this->FontSizePt);
PMA_DBI_free_result($this->results); PMA_DBI_free_result($this->results);
} // end of mysql_report function } // end of mysql_report function
} // end of PMA_PDF class } // end of PMA_PDF class
@@ -286,7 +290,8 @@ function mysql_report($query,$attr=array()){
* *
* @return bool Whether it suceeded * @return bool Whether it suceeded
*/ */
function PMA_exportComment($text) { function PMA_exportComment($text)
{
return TRUE; return TRUE;
} }
@@ -297,7 +302,8 @@ function PMA_exportComment($text) {
* *
* @access public * @access public
*/ */
function PMA_exportFooter() { function PMA_exportFooter()
{
return TRUE; return TRUE;
} }
@@ -308,7 +314,8 @@ function PMA_exportFooter() {
* *
* @access public * @access public
*/ */
function PMA_exportHeader() { function PMA_exportHeader()
{
return TRUE; return TRUE;
} }
@@ -321,7 +328,8 @@ function PMA_exportHeader() {
* *
* @access public * @access public
*/ */
function PMA_exportDBHeader($db) { function PMA_exportDBHeader($db)
{
return TRUE; return TRUE;
} }
@@ -334,7 +342,8 @@ function PMA_exportDBHeader($db) {
* *
* @access public * @access public
*/ */
function PMA_exportDBFooter($db) { function PMA_exportDBFooter($db)
{
return TRUE; return TRUE;
} }
@@ -347,7 +356,8 @@ function PMA_exportDBFooter($db) {
* *
* @access public * @access public
*/ */
function PMA_exportDBCreate($db) { function PMA_exportDBCreate($db)
{
return TRUE; return TRUE;
} }
@@ -364,19 +374,20 @@ function PMA_exportDBCreate($db) {
* *
* @access public * @access public
*/ */
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $what; global $what;
global $pdf_report_title; global $pdf_report_title;
// TODO: user-defined page orientation, paper size // TODO: user-defined page orientation, paper size
$pdf = new PMA_PDF('L','pt','A3'); $pdf = new PMA_PDF('L', 'pt', 'A3');
$pdf->AddFont('FreeSans','','FreeSans.php'); $pdf->AddFont('FreeSans', '', 'FreeSans.php');
$pdf->AddFont('FreeSans','B','FreeSansBold.php'); $pdf->AddFont('FreeSans', 'B', 'FreeSansBold.php');
$pdf->SetFont(PMA_PDF_FONT,'',11.5); $pdf->SetFont(PMA_PDF_FONT, '', 11.5);
$pdf->AliasNbPages(); $pdf->AliasNbPages();
$attr=array('titleFontSize'=>18,'titleText'=>$pdf_report_title); $attr=array('titleFontSize' => 18, 'titleText' => $pdf_report_title);
$pdf->mysql_report($sql_query,$attr); $pdf->mysql_report($sql_query, $attr);
// instead of $pdf->Output(): // instead of $pdf->Output():
if ($pdf->state < 3) { if ($pdf->state < 3) {