diff --git a/includes/global.php b/includes/global.php index fa333c2..b5db00f 100644 --- a/includes/global.php +++ b/includes/global.php @@ -84,7 +84,6 @@ header("Pragma: no-cache"); // ** Include generic code and external libraries ** // 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"] . "/polld.php"); diff --git a/includes/layout.js b/includes/layout.js index a311480..3c8c387 100644 --- a/includes/layout.js +++ b/includes/layout.js @@ -1,5 +1,5 @@ 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) diff --git a/includes/pdf.php b/includes/pdf.php index 6953afb..c0ee481 100644 --- a/includes/pdf.php +++ b/includes/pdf.php @@ -35,181 +35,6 @@ require('global.php'); define('FPDF_FONTPATH','font/'); -/** - * - * Class PDF_MySQL_Table - * - */ - -class PDF_MySQL_Table extends FPDF -{ -var $ProcessingTable=false; -var $aCols=array(); -var $TableX; -var $HeaderColor; -var $RowColors; -var $ColorIndex; - - -/** - * Header - class header - * - */ - -function Header() -{ - //Print the table header if necessary - if($this->ProcessingTable) - $this->TableHeader(); -} - - -/** - * - * TableHeader - * - */ - -function TableHeader() -{ - $this->SetFont('Arial','B',6); - $this->SetX($this->TableX); - $fill=!empty($this->HeaderColor); - if($fill) - $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); - foreach($this->aCols as $col) - $this->Cell($col['w'],6,$col['c'],1,0,'C',$fill); - $this->Ln(); -} - - -/** - * Row - * - * @param unknown $date - */ - -function Row($data) -{ - $this->SetX($this->TableX); - $ci=$this->ColorIndex; - $fill=!empty($this->RowColors[$ci]); - if($fill) - $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]); - foreach($this->aCols as $col) - $this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill); - $this->Ln(); - $this->ColorIndex=1-$ci; -} - - - -/** - * CalcWidths - * - * @param string $width - * @param string $align - */ - -function CalcWidths($width,$align) -{ - //Compute the widths of the columns - $TableWidth=0; - foreach($this->aCols as $i=>$col) - { - $w=$col['w']; - if($w==-1) - $w=$width/count($this->aCols); - elseif(substr($w,-1)=='%') - $w=$w/100*$width; - $this->aCols[$i]['w']=$w; - $TableWidth+=$w; - } - //Compute the abscissa of the table - if($align=='C') - $this->TableX=max(($this->w-$TableWidth)/2,0); - elseif($align=='R') - $this->TableX=max($this->w-$this->rMargin-$TableWidth,0); - else - $this->TableX=$this->lMargin; -} - - -/** - * AddCol - * - * @param int $field - * @param int $width - * @param string $caption - * @param string $align - */ - -function AddCol($field=-1,$width=-1,$caption='',$align='L') -{ - //Add a column to the table - if($field==-1) - $field=count($this->aCols); - $this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align); -} - - -/** - * Table - * - * @param string $query - * @param array $prop - */ - -function Table($query,$prop=array(),$dbresult) -{ - //Issue query - //$res=fetchArrayDB($query, $DBconn); - //Add all columns if none was specified - if(count($this->aCols)==0) - { - foreach($dbresult[0] as $colname => $col) { - $this->AddCol(-1,-1,ucfirst($colname)); - } - } - - //Handle properties - if(!isset($prop['width'])) - $prop['width']=0; - if($prop['width']==0) - $prop['width']=$this->w-$this->lMargin-$this->rMargin; - if(!isset($prop['align'])) - $prop['align']='C'; - if(!isset($prop['padding'])) - $prop['padding']=$this->cMargin; - $cMargin=$this->cMargin; - $this->cMargin=$prop['padding']; - if(!isset($prop['HeaderColor'])) - $prop['HeaderColor']=array(); - $this->HeaderColor=$prop['HeaderColor']; - if(!isset($prop['color1'])) - $prop['color1']=array(); - if(!isset($prop['color2'])) - $prop['color2']=array(); - $this->RowColors=array($prop['color1'],$prop['color2']); - //Compute column widths - $this->CalcWidths($prop['width'],$prop['align']); - //Print header - $this->TableHeader(); - //Print rows - $this->SetFont('Arial','',6); - $this->ColorIndex=0; - $this->ProcessingTable=true; - foreach($dbresult as $key => $row) { - $row_num = array_values($row); - $row_comb = array_merge($row, $row_num); - $this->Row($row_comb); -} - $this->ProcessingTable=false; - $this->cMargin=$cMargin; - $this->aCols=array(); -} -} - /** @@ -218,8 +43,14 @@ function Table($query,$prop=array(),$dbresult) * */ -class PDF extends PDF_MySQL_Table +class PDF extends FPDF { + var $ProcessingTable=false; + var $aCols=array(); + var $TableX; + var $HeaderColor; + var $RowColors; + var $ColorIndex; /** @@ -229,36 +60,171 @@ class PDF extends PDF_MySQL_Table 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 != "") { + //Print the table header if necessary + if($this->ProcessingTable) $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(); + } + //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 + * + */ + + function TableHeader() + { + $this->SetFont('Arial','B',6); + $this->SetX($this->TableX); + $fill=!empty($this->HeaderColor); + if($fill) + $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); + foreach($this->aCols as $col) + $this->Cell($col['w'],6,$col['c'],1,0,'C',$fill); + $this->Ln(); + } + + + /** + * Row + * + * @param unknown $date + */ + + function Row($data) + { + $this->SetX($this->TableX); + $ci=$this->ColorIndex; + $fill=!empty($this->RowColors[$ci]); + if($fill) + $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]); + foreach($this->aCols as $col) + $this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill); + $this->Ln(); + $this->ColorIndex=1-$ci; + } + + + + /** + * CalcWidths + * + * @param string $width + * @param string $align + */ + + function CalcWidths($width,$align) + { + //Compute the widths of the columns + $TableWidth=0; + foreach($this->aCols as $i=>$col) + { + $w=$col['w']; + if($w==-1) + $w=$width/count($this->aCols); + elseif(substr($w,-1)=='%') + $w=$w/100*$width; + $this->aCols[$i]['w']=$w; + $TableWidth+=$w; + } + //Compute the abscissa of the table + if($align=='C') + $this->TableX=max(($this->w-$TableWidth)/2,0); + elseif($align=='R') + $this->TableX=max($this->w-$this->rMargin-$TableWidth,0); + else + $this->TableX=$this->lMargin; + } + + + /** + * AddCol + * + * @param int $field + * @param int $width + * @param string $caption + * @param string $align + */ + + function AddCol($field=-1,$width=-1,$caption='',$align='L') + { + //Add a column to the table + if($field==-1) + $field=count($this->aCols); + $this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align); + } + + + /** + * Table + * + * @param string $query + * @param array $prop + */ + + function Table($query,$prop=array(),$dbresult) + { + //Issue query + //$res=fetchArrayDB($query, $DBconn); + //Add all columns if none was specified + if(count($this->aCols)==0) + { + foreach($dbresult[0] as $colname => $col) { + $this->AddCol(-1,-1,ucfirst($colname)); + } + } + + //Handle properties + if(!isset($prop['width'])) + $prop['width']=0; + if($prop['width']==0) + $prop['width']=$this->w-$this->lMargin-$this->rMargin; + if(!isset($prop['align'])) + $prop['align']='C'; + if(!isset($prop['padding'])) + $prop['padding']=$this->cMargin; + $cMargin=$this->cMargin; + $this->cMargin=$prop['padding']; + if(!isset($prop['HeaderColor'])) + $prop['HeaderColor']=array(); + $this->HeaderColor=$prop['HeaderColor']; + if(!isset($prop['color1'])) + $prop['color1']=array(); + if(!isset($prop['color2'])) + $prop['color2']=array(); + $this->RowColors=array($prop['color1'],$prop['color2']); + //Compute column widths + $this->CalcWidths($prop['width'],$prop['align']); + //Print header + $this->TableHeader(); + //Print rows + $this->SetFont('Arial','',6); + $this->ColorIndex=0; + $this->ProcessingTable=true; + foreach($dbresult as $key => $row) { + $row_num = array_values($row); + $row_comb = array_merge($row, $row_num); + $this->Row($row_comb); + } + $this->ProcessingTable=false; + $this->cMargin=$cMargin; + $this->aCols=array(); } } -$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(); ?> diff --git a/includes/show_pdf.php b/includes/show_pdf.php new file mode 100644 index 0000000..9d7b9a5 --- /dev/null +++ b/includes/show_pdf.php @@ -0,0 +1,51 @@ +. +************************************************************************ +**/ + + +/** + * + * 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(); + +?>