consolidated PDF classes to one class

added show_pdf.php
This commit is contained in:
Michael Clemens 2009-05-12 00:51:21 +00:00
parent 19d46e48b4
commit d7f826c831
4 changed files with 221 additions and 205 deletions

View File

@ -84,7 +84,6 @@ header("Pragma: no-cache");
// ** Include generic code and external libraries ** // // ** Include generic code and external libraries ** //
include ($config["library_path"] . "/adodb5/adodb.inc.php"); include ($config["library_path"] . "/adodb5/adodb.inc.php");
//include_once($config["include_path"] . "/functions.php");
include_once($config["include_path"] . "/tsmmonitor.php"); include_once($config["include_path"] . "/tsmmonitor.php");
include_once($config["include_path"] . "/polld.php"); include_once($config["include_path"] . "/polld.php");

View File

@ -1,5 +1,5 @@
function genPDF() { function genPDF() {
window.open( "includes/pdf.php", "myWindow", "status = 1, fullscreen=yes,scrollbars=yes" ) window.open( "includes/show_pdf.php", "myWindow", "status = 1, fullscreen=yes,scrollbars=yes" )
} }
function show_confirm($url, $id, $action) function show_confirm($url, $id, $action)

View File

@ -35,43 +35,59 @@ require('global.php');
define('FPDF_FONTPATH','font/'); define('FPDF_FONTPATH','font/');
/** /**
* *
* Class PDF_MySQL_Table * Class PDF
* *
*/ */
class PDF_MySQL_Table extends FPDF class PDF extends FPDF
{ {
var $ProcessingTable=false; var $ProcessingTable=false;
var $aCols=array(); var $aCols=array();
var $TableX; var $TableX;
var $HeaderColor; var $HeaderColor;
var $RowColors; var $RowColors;
var $ColorIndex; var $ColorIndex;
/** /**
* Header - class header * Header - class header
* *
*/ */
function Header() function Header()
{ {
//Print the table header if necessary //Print the table header if necessary
if($this->ProcessingTable) if($this->ProcessingTable) $this->TableHeader();
$this->TableHeader(); $configarray = $_SESSION["configarray"];
} $queryarray = $configarray["queryarray"];
$qq = $_SESSION["GETVars"]["qq"];
$server = $_SESSION["GETVars"]["server"];
$label = $queryarray[$qq]["label"];
$snapshotdate = $_SESSION['timemachine']['time'];
if ($snapshotdate != "") {
$snapshotdate = " (".strftime("%Y/%m/%d %H:%m", $snapshotdate).")";
}
//Title
$this->SetFont('Arial','',12);
$this->Cell(0,6,$server.": ".$label.$snapshotdate,0,1,'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
/** /**
* *
* TableHeader * TableHeader
* *
*/ */
function TableHeader() function TableHeader()
{ {
$this->SetFont('Arial','B',6); $this->SetFont('Arial','B',6);
$this->SetX($this->TableX); $this->SetX($this->TableX);
$fill=!empty($this->HeaderColor); $fill=!empty($this->HeaderColor);
@ -80,17 +96,17 @@ function TableHeader()
foreach($this->aCols as $col) foreach($this->aCols as $col)
$this->Cell($col['w'],6,$col['c'],1,0,'C',$fill); $this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
$this->Ln(); $this->Ln();
} }
/** /**
* Row * Row
* *
* @param unknown $date * @param unknown $date
*/ */
function Row($data) function Row($data)
{ {
$this->SetX($this->TableX); $this->SetX($this->TableX);
$ci=$this->ColorIndex; $ci=$this->ColorIndex;
$fill=!empty($this->RowColors[$ci]); $fill=!empty($this->RowColors[$ci]);
@ -100,19 +116,19 @@ function Row($data)
$this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill); $this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);
$this->Ln(); $this->Ln();
$this->ColorIndex=1-$ci; $this->ColorIndex=1-$ci;
} }
/** /**
* CalcWidths * CalcWidths
* *
* @param string $width * @param string $width
* @param string $align * @param string $align
*/ */
function CalcWidths($width,$align) function CalcWidths($width,$align)
{ {
//Compute the widths of the columns //Compute the widths of the columns
$TableWidth=0; $TableWidth=0;
foreach($this->aCols as $i=>$col) foreach($this->aCols as $i=>$col)
@ -132,10 +148,10 @@ function CalcWidths($width,$align)
$this->TableX=max($this->w-$this->rMargin-$TableWidth,0); $this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
else else
$this->TableX=$this->lMargin; $this->TableX=$this->lMargin;
} }
/** /**
* AddCol * AddCol
* *
* @param int $field * @param int $field
@ -144,24 +160,24 @@ function CalcWidths($width,$align)
* @param string $align * @param string $align
*/ */
function AddCol($field=-1,$width=-1,$caption='',$align='L') function AddCol($field=-1,$width=-1,$caption='',$align='L')
{ {
//Add a column to the table //Add a column to the table
if($field==-1) if($field==-1)
$field=count($this->aCols); $field=count($this->aCols);
$this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align); $this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
} }
/** /**
* Table * Table
* *
* @param string $query * @param string $query
* @param array $prop * @param array $prop
*/ */
function Table($query,$prop=array(),$dbresult) function Table($query,$prop=array(),$dbresult)
{ {
//Issue query //Issue query
//$res=fetchArrayDB($query, $DBconn); //$res=fetchArrayDB($query, $DBconn);
//Add all columns if none was specified //Add all columns if none was specified
@ -203,62 +219,12 @@ function Table($query,$prop=array(),$dbresult)
$row_num = array_values($row); $row_num = array_values($row);
$row_comb = array_merge($row, $row_num); $row_comb = array_merge($row, $row_num);
$this->Row($row_comb); $this->Row($row_comb);
} }
$this->ProcessingTable=false; $this->ProcessingTable=false;
$this->cMargin=$cMargin; $this->cMargin=$cMargin;
$this->aCols=array(); $this->aCols=array();
}
}
/**
*
* Class PDF
*
*/
class PDF extends PDF_MySQL_Table
{
/**
* Header - class header
*
*/
function Header()
{
$configarray = $_SESSION["configarray"];
$queryarray = $configarray["queryarray"];
$qq = $_SESSION["GETVars"]["qq"];
$server = $_SESSION["GETVars"]["server"];
$label = $queryarray[$qq]["label"];
$snapshotdate = $_SESSION['timemachine']['time'];
if ($snapshotdate != "") {
$snapshotdate = " (".strftime("%Y/%m/%d %H:%m", $snapshotdate).")";
}
//Title
$this->SetFont('Arial','',12);
$this->Cell(0,6,$server.": ".$label.$snapshotdate,0,1,'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
} }
} }
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
//First table: put all columns automatically
$prop=array('HeaderColor'=>array(180,180,180),
'color1'=>array(255,255,255),
'color2'=>array(230,230,230),
'padding'=>2);
//$pdf->Table('select * from res_'.$_SESSION["GETVars"]["qq"].'_'.$_SESSION["GETVars"]["server"],$prop);
$res = $tsmmonitor->fetchArrayDB($_SESSION["lastsql"], $tsmmonitor->conn);
//var_dump($res);
$pdf->Table($_SESSION["lastsql"],$prop,$res);
$pdf->Output();
?> ?>

51
includes/show_pdf.php Normal file
View File

@ -0,0 +1,51 @@
<?php
/**
************************************************************************
This file is part of TSM Monitor.
TSM Monitor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TSM Monitor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TSM Monitor. If not, see <http://www.gnu.org/licenses/>.
************************************************************************
**/
/**
*
* showpdf.php, TSM Monitor
*
* used for PDF popup window, calls class PDF
*
* @author Michael Clemens
* @package tsmmonitor
*/
require('global.php');
require('pdf.php');
define('FPDF_FONTPATH','font/');
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
//First table: put all columns automatically
$prop=array('HeaderColor'=>array(180,180,180),
'color1'=>array(255,255,255),
'color2'=>array(230,230,230),
'padding'=>2);
$res = $tsmmonitor->fetchArrayDB($_SESSION["lastsql"], $tsmmonitor->conn);
$pdf->Table($_SESSION["lastsql"],$prop,$res);
$pdf->Output();
?>