Qual: Uniformize code for member PDF business card generation
This commit is contained in:
parent
0a3a188eac
commit
8230ccc51a
@ -190,10 +190,7 @@ class PDF_card extends FPDF {
|
|||||||
'SpaceY'=>0,
|
'SpaceY'=>0,
|
||||||
'width'=>85,
|
'width'=>85,
|
||||||
'height'=>54,
|
'height'=>54,
|
||||||
'font-size'=>10,
|
'font-size'=>10)
|
||||||
'logo1'=>'logo1.jpg',
|
|
||||||
'logo2'=>'logo2.jpg',
|
|
||||||
'fond'=>'fond.jpg')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -448,7 +445,7 @@ class PDF_card extends FPDF {
|
|||||||
// Give the height for a char size given.
|
// Give the height for a char size given.
|
||||||
function _Get_Height_Chars($pt) {
|
function _Get_Height_Chars($pt) {
|
||||||
// Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes
|
// Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes
|
||||||
$_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>4, 10=>5, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10);
|
$_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10);
|
||||||
if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
|
if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
|
||||||
return $_Table_Hauteur_Chars[$pt];
|
return $_Table_Hauteur_Chars[$pt];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
154
htdocs/includes/modules/member/cards/modules_cards.php
Normal file
154
htdocs/includes/modules/member/cards/modules_cards.php
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||||
|
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.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.
|
||||||
|
* or see http://www.gnu.org/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file htdocs/includes/modules/facture/modules_facture.php
|
||||||
|
* \ingroup facture
|
||||||
|
* \brief Fichier contenant la classe mere de generation des factures en PDF
|
||||||
|
* et la classe mere de numerotation des factures
|
||||||
|
* \version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php');
|
||||||
|
require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php');
|
||||||
|
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class ModelePDFFactures
|
||||||
|
* \brief Classe mere des modeles de facture
|
||||||
|
*/
|
||||||
|
class ModelePDFCards extends FPDF
|
||||||
|
{
|
||||||
|
var $error='';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Renvoi le dernier message d'erreur de creation de facture
|
||||||
|
*/
|
||||||
|
function pdferror()
|
||||||
|
{
|
||||||
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Renvoi la liste des modeles actifs
|
||||||
|
* \param db Handler de base
|
||||||
|
*/
|
||||||
|
function liste_modeles($db)
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$type='members_card';
|
||||||
|
$liste=array();
|
||||||
|
$sql = "SELECT nom as id, nom as lib";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."document_model";
|
||||||
|
$sql.= " WHERE type = '".$type."'";
|
||||||
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num = $db->num_rows($resql);
|
||||||
|
$i = 0;
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$row = $db->fetch_row($resql);
|
||||||
|
$liste[$row[0]]=$row[1];
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_print_error($db);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return $liste;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Cree un fichier de cartes de visites en fonction du modele de ADHERENT_CARDS_ADDON_PDF
|
||||||
|
* \param db objet base de donnee
|
||||||
|
* \param id id de la facture a creer
|
||||||
|
* \param message message
|
||||||
|
* \param modele force le modele a utiliser ('' to not force)
|
||||||
|
* \param outputlangs objet lang a utiliser pour traduction
|
||||||
|
* \return int <0 if KO, >0 if OK
|
||||||
|
*/
|
||||||
|
function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs)
|
||||||
|
{
|
||||||
|
global $conf,$langs;
|
||||||
|
$langs->load("members");
|
||||||
|
|
||||||
|
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/member/cards/";
|
||||||
|
|
||||||
|
// Positionne modele sur le nom du modele a utiliser
|
||||||
|
if (! strlen($modele))
|
||||||
|
{
|
||||||
|
if ($conf->global->ADHERENT_CARDS_ADDON_PDF)
|
||||||
|
{
|
||||||
|
$modele = $conf->global->ADHERENT_CARDS_ADDON_PDF;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$modele = 'standard';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Charge le modele
|
||||||
|
$file = "pdf_".$modele.".class.php";
|
||||||
|
if (file_exists($dir.$file))
|
||||||
|
{
|
||||||
|
$classname = "pdf_".$modele;
|
||||||
|
require_once($dir.$file);
|
||||||
|
|
||||||
|
$obj = new $classname($db);
|
||||||
|
|
||||||
|
// We save charset_output to restore it because write_file can change it if needed for
|
||||||
|
// output format that does not support UTF8.
|
||||||
|
$sav_charset_output=$outputlangs->charset_output;
|
||||||
|
if ($obj->write_file($arrayofmembers, $outputlangs) > 0)
|
||||||
|
{
|
||||||
|
$outputlangs->charset_output=$sav_charset_output;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$outputlangs->charset_output=$sav_charset_output;
|
||||||
|
dol_print_error($db,"members_card_pdf_create Error: ".$obj->error);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
546
htdocs/includes/modules/member/cards/pdf_standard.class.php
Normal file
546
htdocs/includes/modules/member/cards/pdf_standard.class.php
Normal file
@ -0,0 +1,546 @@
|
|||||||
|
<?php
|
||||||
|
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
|
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
|
||||||
|
* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Inspire de PDF_Label
|
||||||
|
* PDF_Label - PDF label editing
|
||||||
|
* @package PDF_Label
|
||||||
|
* @author Laurent PASSEBECQ <lpasseb@numericable.fr>
|
||||||
|
* @copyright 2003 Laurent PASSEBECQ
|
||||||
|
* disponible ici : http://www.fpdf.org/fr/script/script29.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////
|
||||||
|
// PDF_Label
|
||||||
|
//
|
||||||
|
// Classe afin d'editer au format PDF des etiquettes
|
||||||
|
// au format Avery ou personnalise
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Copyright (C) 2003 Laurent PASSEBECQ (LPA)
|
||||||
|
// Base sur les fonctions de Steve Dillon : steved@mad.scientist.com
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// VERSIONS :
|
||||||
|
// 1.0 : Initial release
|
||||||
|
// 1.1 : + : Added unit in the constructor
|
||||||
|
// + : Now Positions start @ (1,1).. then the first image @top-left of a page is (1,1)
|
||||||
|
// + : Added in the description of a label :
|
||||||
|
// font-size : defaut char size (can be changed by calling Set_Char_Size(xx);
|
||||||
|
// paper-size : Size of the paper for this sheet (thanx to Al Canton)
|
||||||
|
// metric : type of unit used in this description
|
||||||
|
// You can define your label properties in inches by setting metric to 'in'
|
||||||
|
// and printing in millimiter by setting unit to 'mm' in constructor.
|
||||||
|
// Added some labels :
|
||||||
|
// 5160, 5161, 5162, 5163,5164 : thanx to Al Canton : acanton@adams-blake.com
|
||||||
|
// 8600 : thanx to Kunal Walia : kunal@u.washington.edu
|
||||||
|
// + : Added 3mm to the position of labels to avoid errors
|
||||||
|
////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file htdocs/includes/modules/member/card/pdf_standard.class.php
|
||||||
|
* \ingroup adherent
|
||||||
|
* \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise
|
||||||
|
* \author Steve Dillon
|
||||||
|
* \author Laurent Passebecq
|
||||||
|
* \author Rodolphe Quiedville
|
||||||
|
* \author Jean Louis Bergamo.
|
||||||
|
* \version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php');
|
||||||
|
require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class pdf_standard
|
||||||
|
* \brief Classe afin d'editer au format PDF des etiquettes au format Avery ou personnalise
|
||||||
|
*/
|
||||||
|
class pdf_standard {
|
||||||
|
|
||||||
|
// Proprietes privees
|
||||||
|
var $_Avery_Name = ''; // Nom du format de l'etiquette
|
||||||
|
var $_Margin_Left = 0; // Marge de gauche de l'etiquette
|
||||||
|
var $_Margin_Top = 0; // marge en haut de la page avant la premiere etiquette
|
||||||
|
var $_X_Space = 0; // Espace horizontal entre 2 bandes d'etiquettes
|
||||||
|
var $_Y_Space = 0; // Espace vertical entre 2 bandes d'etiquettes
|
||||||
|
var $_X_Number = 0; // Nombre d'etiquettes sur la largeur de la page
|
||||||
|
var $_Y_Number = 0; // Nombre d'etiquettes sur la hauteur de la page
|
||||||
|
var $_Width = 0; // Largeur de chaque etiquette
|
||||||
|
var $_Height = 0; // Hauteur de chaque etiquette
|
||||||
|
var $_Char_Size = 10; // Hauteur des caracteres
|
||||||
|
var $_Line_Height = 10; // Hauteur par defaut d'une ligne
|
||||||
|
var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values
|
||||||
|
var $_Metric_Doc = 'mm'; // Type of metric for the doc..
|
||||||
|
|
||||||
|
var $_COUNTX = 1;
|
||||||
|
var $_COUNTY = 1;
|
||||||
|
var $_First = 1;
|
||||||
|
|
||||||
|
// Listing of labels size
|
||||||
|
var $_Avery_Labels = array (
|
||||||
|
'5160'=>array('name'=>'5160',
|
||||||
|
'paper-size'=>'letter',
|
||||||
|
'metric'=>'mm',
|
||||||
|
'marginLeft'=>1.762,
|
||||||
|
'marginTop'=>10.7,
|
||||||
|
'NX'=>3,
|
||||||
|
'NY'=>10,
|
||||||
|
'SpaceX'=>3.175,
|
||||||
|
'SpaceY'=>0,
|
||||||
|
'width'=>66.675,
|
||||||
|
'height'=>25.4,
|
||||||
|
'font-size'=>8),
|
||||||
|
'5161'=>array('name'=>'5161',
|
||||||
|
'paper-size'=>'letter',
|
||||||
|
'metric'=>'mm',
|
||||||
|
'marginLeft'=>0.967,
|
||||||
|
'marginTop'=>10.7,
|
||||||
|
'NX'=>2,
|
||||||
|
'NY'=>10,
|
||||||
|
'SpaceX'=>3.967,
|
||||||
|
'SpaceY'=>0,
|
||||||
|
'width'=>101.6,
|
||||||
|
'height'=>25.4,
|
||||||
|
'font-size'=>8),
|
||||||
|
'5162'=>array('name'=>'5162',
|
||||||
|
'paper-size'=>'letter',
|
||||||
|
'metric'=>'mm',
|
||||||
|
'marginLeft'=>0.97,
|
||||||
|
'marginTop'=>20.224,
|
||||||
|
'NX'=>2,
|
||||||
|
'NY'=>7,
|
||||||
|
'SpaceX'=>4.762,
|
||||||
|
'SpaceY'=>0,
|
||||||
|
'width'=>100.807,
|
||||||
|
'height'=>35.72,
|
||||||
|
'font-size'=>8),
|
||||||
|
'5163'=>array('name'=>'5163',
|
||||||
|
'paper-size'=>'letter',
|
||||||
|
'metric'=>'mm',
|
||||||
|
'marginLeft'=>1.762,
|
||||||
|
'marginTop'=>10.7,
|
||||||
|
'NX'=>2,
|
||||||
|
'NY'=>5,
|
||||||
|
'SpaceX'=>3.175,
|
||||||
|
'SpaceY'=>0,
|
||||||
|
'width'=>101.6,
|
||||||
|
'height'=>50.8,
|
||||||
|
'font-size'=>8),
|
||||||
|
'5164'=>array('name'=>'5164',
|
||||||
|
'paper-size'=>'letter',
|
||||||
|
'metric'=>'in',
|
||||||
|
'marginLeft'=>0.148,
|
||||||
|
'marginTop'=>0.5,
|
||||||
|
'NX'=>2,
|
||||||
|
'NY'=>3,
|
||||||
|
'SpaceX'=>0.2031,
|
||||||
|
'SpaceY'=>0,
|
||||||
|
'width'=>4.0,
|
||||||
|
'height'=>3.33,
|
||||||
|
'font-size'=>12),
|
||||||
|
'8600'=>array('name'=>'8600',
|
||||||
|
'paper-size'=>'letter',
|
||||||
|
'metric'=>'mm',
|
||||||
|
'marginLeft'=>7.1,
|
||||||
|
'marginTop'=>19,
|
||||||
|
'NX'=>3,
|
||||||
|
'NY'=>10,
|
||||||
|
'SpaceX'=>9.5,
|
||||||
|
'SpaceY'=>3.1,
|
||||||
|
'width'=>66.6,
|
||||||
|
'height'=>25.4,
|
||||||
|
'font-size'=>8),
|
||||||
|
'L7163'=>array('name'=>'L7163',
|
||||||
|
'paper-size'=>'A4',
|
||||||
|
'metric'=>'mm',
|
||||||
|
'marginLeft'=>5,
|
||||||
|
'marginTop'=>15,
|
||||||
|
'NX'=>2,
|
||||||
|
'NY'=>7,
|
||||||
|
'SpaceX'=>25,
|
||||||
|
'SpaceY'=>0,
|
||||||
|
'width'=>99.1,
|
||||||
|
'height'=>38.1,
|
||||||
|
'font-size'=>10),
|
||||||
|
'CARD'=>array('name'=>'CARD',
|
||||||
|
'paper-size'=>'A4',
|
||||||
|
'metric'=>'mm',
|
||||||
|
'marginLeft'=>15,
|
||||||
|
'marginTop'=>15,
|
||||||
|
'NX'=>2,
|
||||||
|
'NY'=>5,
|
||||||
|
'SpaceX'=>0,
|
||||||
|
'SpaceY'=>0,
|
||||||
|
'width'=>85,
|
||||||
|
'height'=>54,
|
||||||
|
'font-size'=>10)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param unknown_type $format Avery format of label paper. For example 5160, 5161, 5162, 5163, 5164, 8600, L7163, CARD
|
||||||
|
* @param unknown_type $posX
|
||||||
|
* @param unknown_type $posY
|
||||||
|
* @param unknown_type $unit
|
||||||
|
* @return PDF_card
|
||||||
|
*/
|
||||||
|
function pdf_standard($db, $format='CARD', $posX=1, $posY=1, $unit='mm')
|
||||||
|
{
|
||||||
|
global $conf,$langs,$mysoc;
|
||||||
|
|
||||||
|
$this->db = $db;
|
||||||
|
|
||||||
|
$this->Tformat = $this->_Avery_Labels[$format];
|
||||||
|
|
||||||
|
// Dimension page pour format A4
|
||||||
|
$this->type = 'pdf';
|
||||||
|
$this->format = $this->Tformat['paper-size'];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Methode qui permet de modifier la taille des caracteres
|
||||||
|
// Cela modiera aussi l'espace entre chaque ligne
|
||||||
|
function Set_Char_Size(&$pdf,$pt) {
|
||||||
|
if ($pt > 3) {
|
||||||
|
$this->_Char_Size = $pt;
|
||||||
|
$this->_Line_Height = $this->_Get_Height_Chars($pt);
|
||||||
|
$pdf->SetFont('Arial','',$pt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// On imprime une etiquette
|
||||||
|
function Add_PDF_card(&$pdf,$textleft,$header='',$footer='',$outputlangs,$textright='')
|
||||||
|
{
|
||||||
|
global $mysoc,$conf,$langs;
|
||||||
|
|
||||||
|
// We are in a new page, then we must add a page
|
||||||
|
if (($this->_COUNTX ==0) and ($this->_COUNTY==0) and (!$this->_First==1)) {
|
||||||
|
$pdf->AddPage();
|
||||||
|
}
|
||||||
|
$this->_First=0;
|
||||||
|
$_PosX = $this->_Margin_Left+($this->_COUNTX*($this->_Width+$this->_X_Space));
|
||||||
|
$_PosY = $this->_Margin_Top+($this->_COUNTY*($this->_Height+$this->_Y_Space));
|
||||||
|
|
||||||
|
$logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
|
||||||
|
if (! is_readable($logo))
|
||||||
|
{
|
||||||
|
if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small))
|
||||||
|
{
|
||||||
|
$logo=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
|
||||||
|
}
|
||||||
|
elseif (! empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo))
|
||||||
|
{
|
||||||
|
$logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->_Avery_Name == "CARD")
|
||||||
|
{
|
||||||
|
$this->Tformat=$this->_Avery_Labels["CARD"];
|
||||||
|
//$this->_Pointille($pdf,$_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.3,25);
|
||||||
|
$this->_Croix($pdf,$_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.1,10);
|
||||||
|
if($this->Tformat['fond'] != '' and file_exists($this->Tformat['fond'])){
|
||||||
|
$this->image($this->Tformat['fond'],$_PosX,$_PosY,$this->_Width,$this->_Height);
|
||||||
|
}
|
||||||
|
/*if($this->Tformat['logo1'] != '' and file_exists($this->Tformat['logo1'])){
|
||||||
|
$this->image($this->Tformat['logo1'],$_PosX+$this->_Width-21,$_PosY+1,20,20);
|
||||||
|
}
|
||||||
|
if($this->Tformat['logo2'] != '' and file_exists($this->Tformat['logo2'])){
|
||||||
|
$this->image($this->Tformat['logo2'],$_PosX+$this->_Width-21,$_PosY+25,20,20);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// Top
|
||||||
|
if ($header!=''){
|
||||||
|
$pdf->SetXY($_PosX, $_PosY+1);
|
||||||
|
$pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($header),0,1,'C');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Center
|
||||||
|
if ($textright=='') // Only a left part
|
||||||
|
{
|
||||||
|
if ($textleft == '%LOGO%') $this->Image($logo,$_PosX+$this->_Width-21,$_PosY+3+$this->_Line_Height,20);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pdf->SetXY($_PosX+3, $_PosY+3+$this->_Line_Height);
|
||||||
|
$pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ($textleft!='' && $textright!='') //
|
||||||
|
{
|
||||||
|
if ($textleft == '%LOGO%')
|
||||||
|
{
|
||||||
|
$pdf->Image($logo,$_PosX+$this->_Width-21,$_PosY+3+$this->_Line_Height,20);
|
||||||
|
$pdf->SetXY($_PosX+22, $_PosY+3+$this->_Line_Height);
|
||||||
|
$pdf->MultiCell($this->_Width-20, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R');
|
||||||
|
}
|
||||||
|
else if ($textright == '%LOGO%')
|
||||||
|
{
|
||||||
|
$pdf->Image($logo,$_PosX+$this->_Width-21,$_PosY+3+$this->_Line_Height,20);
|
||||||
|
$pdf->SetXY($_PosX+2, $_PosY+3+$this->_Line_Height);
|
||||||
|
$pdf->MultiCell($this->_Width-22, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pdf->SetXY($_PosX+round($this->_Width/2), $_PosY+3+$this->_Line_Height);
|
||||||
|
$pdf->MultiCell(round($this->_Width/2)-2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R');
|
||||||
|
$pdf->SetXY($_PosX+2, $_PosY+3+$this->_Line_Height);
|
||||||
|
$pdf->MultiCell(round($this->_Width/2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else // Only a right part
|
||||||
|
{
|
||||||
|
if ($textright == '%LOGO%') $this->Image($logo,$_PosX+$this->_Width-21,$_PosY+1,20);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pdf->SetXY($_PosX+2, $_PosY+3+$this->_Line_Height);
|
||||||
|
$pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bottom
|
||||||
|
if ($footer!='')
|
||||||
|
{
|
||||||
|
$pdf->SetXY($_PosX, $_PosY+$this->_Height-$this->_Line_Height-1);
|
||||||
|
$pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer),0,1,'C');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pdf->SetXY($_PosX+3, $_PosY+3);
|
||||||
|
$pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft));
|
||||||
|
}
|
||||||
|
$this->_COUNTY++;
|
||||||
|
|
||||||
|
if ($this->_COUNTY == $this->_Y_Number) {
|
||||||
|
// Si on est en bas de page, on remonte le 'curseur' de position
|
||||||
|
$this->_COUNTX++;
|
||||||
|
$this->_COUNTY=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->_COUNTX == $this->_X_Number) {
|
||||||
|
// Si on est en bout de page, alors on repart sur une nouvelle page
|
||||||
|
$this->_COUNTX=0;
|
||||||
|
$this->_COUNTY=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15)
|
||||||
|
{
|
||||||
|
$pdf->SetLineWidth($epaisseur);
|
||||||
|
$longueur=abs($x1-$x2);
|
||||||
|
$hauteur=abs($y1-$y2);
|
||||||
|
if($longueur>$hauteur) {
|
||||||
|
$Pointilles=($longueur/$nbPointilles)/2; // taille des pointilles
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$Pointilles=($hauteur/$nbPointilles)/2;
|
||||||
|
}
|
||||||
|
for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) {
|
||||||
|
for($j=$i;$j<=($i+$Pointilles);$j++) {
|
||||||
|
if($j<=($x2-1)) {
|
||||||
|
$pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point
|
||||||
|
$pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) {
|
||||||
|
for($j=$i;$j<=($i+$Pointilles);$j++) {
|
||||||
|
if($j<=($y2-1)) {
|
||||||
|
$pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point
|
||||||
|
$pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fonction realisant une croix aux 4 coins des cartes
|
||||||
|
*/
|
||||||
|
function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4)
|
||||||
|
{
|
||||||
|
$pdf->SetDrawColor(192,192,192);
|
||||||
|
|
||||||
|
$pdf->SetLineWidth($epaisseur);
|
||||||
|
$lg=$taille/2;
|
||||||
|
// croix haut gauche
|
||||||
|
$pdf->Line($x1,$y1-$lg,$x1,$y1+$lg);
|
||||||
|
$pdf->Line($x1-$lg,$y1,$x1+$lg,$y1);
|
||||||
|
// croix bas gauche
|
||||||
|
$pdf->Line($x1,$y2-$lg,$x1,$y2+$lg);
|
||||||
|
$pdf->Line($x1-$lg,$y2,$x1+$lg,$y2);
|
||||||
|
// croix haut droit
|
||||||
|
$pdf->Line($x2,$y1-$lg,$x2,$y1+$lg);
|
||||||
|
$pdf->Line($x2-$lg,$y1,$x2+$lg,$y1);
|
||||||
|
// croix bas droit
|
||||||
|
$pdf->Line($x2,$y2-$lg,$x2,$y2+$lg);
|
||||||
|
$pdf->Line($x2-$lg,$y2,$x2+$lg,$y2);
|
||||||
|
|
||||||
|
$pdf->SetDrawColor(0,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert units (in to mm, mm to in)
|
||||||
|
// $src and $dest must be 'in' or 'mm'
|
||||||
|
function _Convert_Metric ($value, $src, $dest) {
|
||||||
|
if ($src != $dest) {
|
||||||
|
$tab['in'] = 39.37008;
|
||||||
|
$tab['mm'] = 1000;
|
||||||
|
return $value * $tab[$dest] / $tab[$src];
|
||||||
|
} else {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Give the height for a char size given.
|
||||||
|
function _Get_Height_Chars($pt) {
|
||||||
|
// Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes
|
||||||
|
$_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10);
|
||||||
|
if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
|
||||||
|
return $_Table_Hauteur_Chars[$pt];
|
||||||
|
} else {
|
||||||
|
return 100; // There is a prob..
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _Set_Format(&$pdf, $format) {
|
||||||
|
|
||||||
|
$this->_Metric = $format['metric'];
|
||||||
|
$this->_Avery_Name = $format['name'];
|
||||||
|
$this->_Margin_Left = $this->_Convert_Metric ($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
|
||||||
|
$this->_Margin_Top = $this->_Convert_Metric ($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
|
||||||
|
$this->_X_Space = $this->_Convert_Metric ($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
|
||||||
|
$this->_Y_Space = $this->_Convert_Metric ($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
|
||||||
|
$this->_X_Number = $format['NX'];
|
||||||
|
$this->_Y_Number = $format['NY'];
|
||||||
|
$this->_Width = $this->_Convert_Metric ($format['width'], $this->_Metric, $this->_Metric_Doc);
|
||||||
|
$this->_Height = $this->_Convert_Metric ($format['height'], $this->_Metric, $this->_Metric_Doc);
|
||||||
|
$this->Set_Char_Size($pdf, $format['font-size']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Function to build PDF on disk, then output on HTTP strem.
|
||||||
|
* \param arrayofmembers Array of members informations
|
||||||
|
* \param outputlangs Lang object for output language
|
||||||
|
* \return int 1=ok, 0=ko
|
||||||
|
*/
|
||||||
|
function write_file($arrayofmembers,$outputlangs)
|
||||||
|
{
|
||||||
|
global $user,$langs,$conf;
|
||||||
|
|
||||||
|
if (! is_object($outputlangs)) $outputlangs=$langs;
|
||||||
|
// Force output charset to ISO, because, FPDF expect text encoded in ISO
|
||||||
|
$outputlangs->charset_output='ISO-8859-1';
|
||||||
|
|
||||||
|
$outputlangs->load("main");
|
||||||
|
$outputlangs->load("dict");
|
||||||
|
$outputlangs->load("companies");
|
||||||
|
$outputlangs->load("members");
|
||||||
|
|
||||||
|
|
||||||
|
$dir = $conf->adherent->dir_temp;
|
||||||
|
$file = $dir . "/tmpcard.pdf";
|
||||||
|
|
||||||
|
if (! file_exists($dir))
|
||||||
|
{
|
||||||
|
if (create_exdir($dir) < 0)
|
||||||
|
{
|
||||||
|
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Protection et encryption du pdf
|
||||||
|
if ($conf->global->PDF_SECURITY_ENCRYPTION)
|
||||||
|
{
|
||||||
|
$pdf=new FPDI_Protection('P','mm',$this->format);
|
||||||
|
$pdfrights = array('print'); // Ne permet que l'impression du document
|
||||||
|
$pdfuserpass = ''; // Mot de passe pour l'utilisateur final
|
||||||
|
$pdfownerpass = NULL; // Mot de passe du proprietaire, cree aleatoirement si pas defini
|
||||||
|
$pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pdf=new FPDI('P','mm',$this->format);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$pdf->SetMargins(0,0);
|
||||||
|
$pdf->SetAutoPageBreak(false);
|
||||||
|
|
||||||
|
$this->_Metric_Doc = 'mm';
|
||||||
|
// Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie
|
||||||
|
if ($posX > 0) $posX--; else $posX=0;
|
||||||
|
if ($posY > 0) $posY--; else $posY=0;
|
||||||
|
$this->_COUNTX = $posX;
|
||||||
|
$this->_COUNTY = $posY;
|
||||||
|
$this->_Set_Format($pdf, $this->Tformat);
|
||||||
|
|
||||||
|
|
||||||
|
$pdf->Open();
|
||||||
|
$pdf->AddPage();
|
||||||
|
|
||||||
|
|
||||||
|
// Add each record
|
||||||
|
foreach($arrayofmembers as $val)
|
||||||
|
{
|
||||||
|
// imprime le texte specifique sur la carte
|
||||||
|
$this->Add_PDF_card($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Output to file
|
||||||
|
$pdf->Output($file);
|
||||||
|
|
||||||
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
|
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Output to http stream
|
||||||
|
clearstatcache();
|
||||||
|
|
||||||
|
$attachment=true;
|
||||||
|
if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false;
|
||||||
|
$filename='tmpcards.pdf';
|
||||||
|
$type=dol_mimetype($filename);
|
||||||
|
|
||||||
|
if ($encoding) header('Content-Encoding: '.$encoding);
|
||||||
|
if ($type) header('Content-Type: '.$type);
|
||||||
|
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
|
||||||
|
else header('Content-Disposition: inline; filename="'.$filename.'"');
|
||||||
|
|
||||||
|
// Ajout directives pour resoudre bug IE
|
||||||
|
header('Cache-Control: Public, must-revalidate');
|
||||||
|
header('Pragma: public');
|
||||||
|
|
||||||
|
readfile($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue
Block a user