TransWar File Browser

Path: C:\

<?php
require('fpdf.php');
class PDF extends FPDF
{   
    // Load data
    function LoadData($file)
    {
        // Read file lines
        $lines = file($file);
        $data = array();
        foreach($lines as $line)
            $data[] = explode(';',trim($line));
        return $data;
    }

    function cabec($x)
    {   $if[0]='VAN, 3/4 e TOCO';
        $if[1]='TRUCK';
        $if[2]='CAVALO';
        // Logo
        $this->Image('img/logo.png',5,6,60);
        // Arial bold 15
        $this->SetFont('Arial','B',15);
        // Move to the right
        $this->Cell(68);
        // Title
        $this->Cell(50,8,'Tabela de Viagens','',0,'C');
        $this->Ln();
        $this->Cell(68);
        $this->SetFont('Arial','B',12);
        $this->Cell(50,6,utf8_decode('(Últimos 30 dias)'),'',0,'C');
        $this->SetFont('Arial','B',15);
        $this->SetTextColor(255,0,0);
        $this->Cell(60,0,'('.$if[$x].')','',0,'C');
        // Line break
        $this->Ln(8);
    }

    // Colored table
    function FancyTable($header, $data)
    {   for ($y=0;$y<3;$y++)
        {   $this->cabec($y);
            // Colors, line width and bold font
            $this->SetFillColor(255,0,0);
            $this->SetTextColor(255);
            $this->SetDrawColor(128,0,0);
            $this->SetLineWidth(.2);
            $this->SetFont('Arial','B','12');
            // Header
            $w = array(70,20,40,25,25);
            $this->Cell(70,7,$header[0],1,0,'C',true);
            $this->Cell(20,7,$header[1],1,0,'C',true);
            $this->Cell(40,7,$header[2],1,0,'C',true);
            $this->Cell(25,7,$header[3],1,0,'C',true);
            $this->Cell(25,7,$header[4],1,0,'C',true);
            $this->Ln();
            // Color and font restoration
            $this->SetFillColor(224,235,255);
            $this->SetTextColor(0);
            $this->SetFont('Arial','','9');
            $this->SetFont('');
            // Data
            $fill = false;
            foreach($data as $row)
            {   if($row[0]==$y)
                {
                    $this->Cell($w[0],6,utf8_decode($row[1]),'LR',0,'C',$fill);
                    $this->Cell($w[1],6,$row[2],'LR',0,'C',$fill);
                    $this->Cell($w[2],6,utf8_decode($row[3]),'LR',0,'C',$fill);
                    $this->Cell($w[3],6,$row[4],'LR',0,'C',$fill);
                    $this->Cell($w[4],6,$row[5],'LR',0,'C',$fill);
                    $this->Ln();
                    $fill = !$fill;
                }
            }
            // Closing line
            $this->Cell(array_sum($w),0,'','T');
            date_default_timezone_set('America/Sao_Paulo');
            $dia=date("d-m-Y  ---  G:i");
            $this->SetFont('Arial','I',12);
                $this->Ln();
            $this->Cell(65);
            $this->Cell(65,10,$dia,0,0,'C');
            if($y<2){$this->AddPage();}
        }
    }
}
$pdf = new PDF();
// Column headings
$header = array('MOTORISTA','PLACA','DESTINO',utf8_decode('SAÍDA'),'CHEGADA');
// Data loading
$data = $pdf->LoadData('viagens.txt');
$pdf->SetFont('Arial','','12');
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();
?>