eticket.inc.php 3.56 KB
Newer Older
jlaval's avatar
jlaval committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php
/* Copyright 2011
 * - Jérémie Laval < jeremie dot laval at gmail dot com >
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program 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 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

define('FPDF_FONTPATH', $topdir . 'font/');

require_once($topdir . "include/lib/barcodefpdf.inc.php");
Aiguille's avatar
Aiguille committed
27
require_once($topdir . "include/lib/phpqrcode/qrlib.php");
jlaval's avatar
jlaval committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

class eticket_pdf extends FPDF
{
    var $bandeau_partenaires;
    var $img_header;

    function eticket_pdf ($imgheader)
    {
        global $topdir;

        $this->FPDF ();

        $this->bandeau_partenaires = $topdir."images/eticket/bandeau_partenaires.jpg";
        $this->img_header = $imgheader;
        $this->SetAutoPageBreak (false);
    }

    function renderize($user_infos, $code)
    {
        /* $user_infos is a map containing:
             - 'prenom' : First name of the dude
             - 'nom': Family name
             - 'nickname': Nickname
             - 'avatar' : file path to the guy identity avatar
           $code is a string containing the whatever encoded thing we have to print as barcode
        */
        $this->AddPage ();
        $this->SetFont('Times','',14);

        $this->SetX (87);
        $this->Image ($user_infos['avatar'], null, null, 30, 35);
Aiguille's avatar
Aiguille committed
59
		
jlaval's avatar
jlaval committed
60 61 62 63 64 65
        $this->Ln(5);

        $this->add_line ('Prénom:', $user_infos['prenom']);
        $this->add_line ('Nom:', $user_infos['nom']);
        $this->add_line ('Surnom:', $user_infos['nickname']);

Aiguille's avatar
Aiguille committed
66 67
        $this->Ln(20);
		
jlaval's avatar
jlaval committed
68 69
        $this->SetX (70);
        $this->add_code ($code);
Aiguille's avatar
Aiguille committed
70 71 72 73 74
		
		$this->Ln(20);
		
		$this->SetX (80);
		$this->add_QRcode ($code);
jlaval's avatar
jlaval committed
75 76 77 78 79 80 81 82 83
    }

    function add_line($key, $value)
    {
        $this->SetX (60);
        $this->Cell(20,9,utf8_decode($key), "B", 0, "");
        $this->Cell(60,9,utf8_decode($value), "B", 1, "R");
    }

Aiguille's avatar
Aiguille committed
84
	// Add barcode
jlaval's avatar
jlaval committed
85 86 87 88 89 90 91 92
    function add_code ($code)
    {
        /* We try to use the same informations as carteae.inc.php */
        $code = strtoupper ($code);
        $barcode = new PDF_C128AObject(67, 25, BCS_ALIGN_CENTER | BCS_DRAW_TEXT, $code, &$this, $this->GetX (), $this->GetY ());
        if (!$barcode->DrawObject (0.25))
            echo "Error occured with barcode : ".$barcode->GetError ()."\n";
    }
Aiguille's avatar
Aiguille committed
93 94 95 96 97 98
	
	// Add QRcode
	function add_QRcode ($code)
    {
        /* We try to use the same informations as carteae.inc.php */
        $code = strtoupper ($code);
Aiguille's avatar
Aiguille committed
99
		$tmpfname = uniqid('qrc_') . '.png';
Aiguille's avatar
Aiguille committed
100 101 102 103 104
		QRcode::png($code, $tmpfname, 'H', 4, 2);
		$this->Image ($tmpfname);
		unlink($tmpfname);
    }
	
jlaval's avatar
jlaval committed
105 106 107 108
    function Header ()
    {
        $this->SetFont('Arial','',12);

jlaval's avatar
jlaval committed
109
        $this->Image ($this->img_header, null, null, 0, 0, 'JPG');
Aiguille's avatar
Aiguille committed
110
        $this->Ln(30);
jlaval's avatar
jlaval committed
111 112 113 114 115 116 117 118 119 120 121 122
    }

    /* Met le bandeau des partenaires en footer */
    function Footer ()
    {
        // Positionnement à 1,5 cm du bas
        $this->SetY(-25);
        $this->Image ($this->bandeau_partenaires, 0, $this->GetY(), 210, 20);
    }
}

?>