<?php
include ('referrals_fns.php');
session_start();
header("Cache-control: private");
require('fpdf/fpdf.php');
class PDF extends FPDF
{
var $text;
var $catid;
var $orgtitle;
function Header()
{
/* Called by AddPage() */
//Arial bold 15
$this->SetFont('Arial','B',15);
//Move to the right
$this->Cell(0,0,$this->orgtitle,0,1,'c');
//Framed title
#$this->Cell(30,10,$this->orgtitle,1,0,'C');
$this->Ln(20); // Line break
}
//Page footer
function Footer()
{
/* Called by AddPage() */
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFont('Arial','I',8);
//Text color in gray
$this->SetTextColor(128);
//Page number
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
function SetChapterTitle()
{
//Arial 12
$this->SetFont('Arial','',12);
//Background color
$this->SetFillColor(200,220,255);
//Title
$this->Cell(0,6,"Chapter $this->chapnum : $this->title",0,1,'L',1);
$this->Ln(4); // Line break
}
//Simple table
function PrintTable()
{
/* Total page is 130, */
//Header
$this->Cell(140,6,'Name' ,0);
$this->SetX(140);
$this->Cell(45,6,'Phone Num.' ,0, 0, C);
$this->SetX(185);
$this->Cell(0,6,'Ref Code' ,0, 0, C);
$this->Ln(); // Line break
$this->SetFillColor(230);
foreach($this->pdf_orgarray as $row)
{
if (1 == $background) {
$background = 0;
} else {
$background++;
}
$name = $row[0];
$num = $row[1];
$code = $row[2];
$desc = $row[3];
// See http://fpdf.org/en/doc/cell.htm for documentation
// Cell( w,h, text ,b, ln,algn,fill) (b = border)
$y = $this->GetY();
if ($y >= 250) {
$this->AddPage();
}
$this->SetFont('Arial','B',14);
$y = $this->GetY();
$this->MultiCell(130,6,$name,0,L,$background);
$this->SetFont('Arial','',12);
$this->SetY($y);
$this->SetX(140);
$y = $this->GetY();
$this->MultiCell(45,6,$num, 0, C,$background);
$this->SetY($y);
$this->SetX(185);
$this->MultiCell(0,6,$code, 0,C,$background);
$this->MultiCell(0,6,$desc,0,L,$background);
/*// This loops through all, seperate to change values
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln(); // Line break*/
}
}
function CategoryBody()
{
// get the organization info out from db
// from organization_fns.php
unset($this->pdf_orgarray);
$this->organization_array = get_organizations($this->catid);
//Create table
foreach ($this->organization_array as $row)
{
list($id, $code, $name, $refnum, $details) = $row;
$orgrefnum = ez_format_phone($orgrefnum, "517", 1);
$name = html_entity_decode($name, ENT_QUOTES);
$code = html_entity_decode($code, ENT_QUOTES);
$refnum = html_entity_decode($refnum, ENT_QUOTES);
$details = html_entity_decode($details, ENT_QUOTES);
$this->pdf_orgarray[] = array($name, $refnum, $code, $details);
}
}
}
// Instantiation of inherited class
$pdf=new PDF();
$pdf->Open();
$pdf->SetAuthor('Joseph Glass');
$pdf->orgtitle = "Listening Ear Resource Book";
$cat_array = get_categories();
foreach ($cat_array as $category) {
$pdf->chapnum++;
$pdf->AddPage(); // Built-in function; set up page with Header() & Footer()
list($pdf->catid, $pdf->catname) = $category;
$pdf->SetTitle($pdf->catname); // Built-in function
$pdf->SetChapterTitle();
$pdf->CategoryBody();
$pdf->PrintTable();
}
// This function only sets data
#$pdf->SetChapterContents(1); // Pass it the current chapter number
$pdf->Output();
?>