<?php
/**
* object_print.php
*
* PHP version 4
*
* phpWAFr version 1.1.2
* copyright (c) 2007 Associação SoftwareLivre.org
*
* phpWAFr is an open source PHP library designed to accelerate
* the development of transactional database Web applications.
*
* phpWAFr is released under the terms of the LGPL license 2.1
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPL License 2.1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* @package phpWAFr
* @version 1.1.2
* @author Marcelo Rezende <hide@address.com>
* @copyright copyright (c) 2007 Associação SoftwareLivre.org
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPL License 2.1
*/
require_once("../inc/common.php");
/*
classe para a manipulação de elementos PDF
*/
require("../inc/pdf/fpdf.php");
define('FPDF_FONTPATH','../inc/pdf/font/');
/*
verifica se o usuário pode acessar esta página
*/
verifyUser(1);
/*
conexão com o banco de dados
*/
$conn = new db();
$conn->open();
/*
definição de cabeçalho e rodapé (extendendo a classe FPDF),
configure conforme a sua necessidade
*/
class PDF extends FPDF {
function Header() {
$this->SetFont('Arial', 'B', 14);
$this->Cell(50, 6, "Nome do Sistema", 0, 0);
$this->SetFont('Arial', 'I', 8);
$this->Cell(0, 6, "Identificação do relatório", 0, 1, "R");
$this->SetFont('Arial', 'B', 14);
$this->Cell(0, 6, "Título do relatório", "B");
$this->Ln(10);
$this->SetFont('Arial', 'B', 10);
$this->Cell(70, 4, "Nome de usuário", 0, 0, "L");
$this->Cell(35, 4, "Departamento", 0, 0, "L");
$this->Cell( 0, 4, "Descrição", 0, 1, "L");
}
function Footer() {
$this->SetY(-15);
$this->SetFont('Arial', 'I', 8);
$this->Cell(10, 10, "", "T");
$this->Cell(30,10, date("d/m/Y - H:i"), "T", 0, 'L');
$this->Cell( 0, 10,'Página ' . $this->PageNo(), "T", 0, 'R');
}
}
/*
cria documento
*/
$pdf=new PDF("P","mm","A4");
$pdf->setAuthor("Fulano");
$pdf->setTitle("Nome do relatório");
$pdf->setCreator("PHP/FPDF 1.51");
/*
abre documento
*/
$pdf->Open();
/*
primeira página (as demais são automáticas)
*/
$pdf->AddPage();
/*
fonte padrão
*/
$pdf->SetFont('Arial', '', 9);
/*
expressão SQL responsável pela iteração,
configure conforme sua necessidade, inclusive
recebendo parâmetros do template object_search
*/
$sql = "SELECT usuario.*, departamento.nome_departamento "
. "FROM usuario, departamento "
. "WHERE usuario.departamento_id=departamento.departamento_id "
. "ORDER BY usuario.nome_usuario";
$rs = new query($conn, $sql);
/*
início da iteração
*/
while ($rs->getrow()) {
$pdf->Cell(70, 4, $rs->field("nome_usuario"), "T", 0, "L");
$pdf->Cell(35, 4, $rs->field("nome_departamento"), "T", 0, "L");
$pdf->MultiCell(0,4,$rs->field("descricao"), "T");
}
/*
encerra a conexão com o banco de dados
*/
$conn->close();
/*
comandos HEADER que disponibiliza o documento
para download
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: public"); // HTTP/1.0
/*
cria o documento,
altere o nome do arquivo conforme sua necessidade
*/
$pdf->Output("relatorio.pdf", true);
?>