Skip to content

Commit

Permalink
Merge pull request #2752 from fappels/develop-tcpdfbarcode
Browse files Browse the repository at this point in the history
NEW add tcpdf barcode generator and printing, add 2d Datamatrix and QRcode CLOSE #2655
  • Loading branch information
eldy committed May 3, 2015
2 parents a566ec3 + 2b32dc4 commit 8a7728f
Show file tree
Hide file tree
Showing 12 changed files with 1,220 additions and 699 deletions.
124 changes: 68 additions & 56 deletions htdocs/barcode/printsheet.php
@@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2006-2013 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
Expand All @@ -10,17 +10,17 @@
*
* 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
* 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, see <http://www.gnu.org/licenses/>.
*/

/**
* \file htdocs/barcode/printsheet.php
* \ingroup member
* \brief Page to print sheets with barcodes using the document templates into core/modules/printsheets
* \file htdocs/barcode/printsheet.php
* \ingroup member
* \brief Page to print sheets with barcodes using the document templates into core/modules/printsheets
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
Expand Down Expand Up @@ -96,13 +96,13 @@

if (empty($forbarcode)) // barcode value
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeValue")),'errors');
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeValue")),'errors');
$error++;
}
if (empty($fk_barcode_type)) // barcode type = barcode encoding
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeType")),'errors');
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeType")),'errors');
$error++;
}

if (! $error)
Expand All @@ -123,46 +123,54 @@
$code=$forbarcode;
$generator=$stdobject->barcode_type_coder; // coder (loaded by fetch_barcode). Engine.
$encoding=strtoupper($stdobject->barcode_type_code); // code (loaded by fetch_barcode). Example 'ean', 'isbn', ...
$barcodeimage=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';

$diroutput=$conf->barcode->dir_temp;
dol_mkdir($diroutput);

// Generate barcode
$dirbarcode=array_merge(array("/core/modules/barcode/doc/"),$conf->modules_parts['barcode']);

foreach($dirbarcode as $reldir)
{
$dir=dol_buildpath($reldir,0);
$newdir=dol_osencode($dir);

// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
if (! is_dir($newdir)) continue;

$result=@include_once $newdir.$generator.'.modules.php';
if ($result) break;
}

// Load barcode class
$classname = "mod".ucfirst($generator);
$module = new $classname($db);
if ($module->encodingIsSupported($encoding))
{
dol_delete_file($barcodeimage);
// File is created with full name $barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
$result=$module->writeBarCode($code,$encoding,'Y',4);

if ($result <= 0 || ! dol_is_file($barcodeimage))
{
$error++;
setEventMessage('Failed to generate image file of barcode for code='.$code.' encoding='.$encoding.' file='.basename($barcodeimage), 'errors');
}
}
else
$dirbarcode=array_merge(array("/core/modules/barcode/doc/"),$conf->modules_parts['barcode']);

foreach($dirbarcode as $reldir)
{
$error++;
setEventMessage("Error, encoding ".$encoding." is not supported by encoder ".$generator.'. You must choose another barcode type or install a barcode generation engine that support '.$encoding, 'errors');
}
$dir=dol_buildpath($reldir,0);
$newdir=dol_osencode($dir);

// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
if (! is_dir($newdir)) continue;

$result=@include_once $newdir.$generator.'.modules.php';
if ($result) break;
}

// Load barcode class for generating barcode image
$classname = "mod".ucfirst($generator);
$module = new $classname($db);
if ($generator != 'tcpdfbarcode') {
$template = 'standardlabel';
$is2d = false;
if ($module->encodingIsSupported($encoding))
{
$barcodeimage=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
dol_delete_file($barcodeimage);
// File is created with full name $barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
$result=$module->writeBarCode($code,$encoding,'Y',4);

if ($result <= 0 || ! dol_is_file($barcodeimage))
{
$error++;
setEventMessage('Failed to generate image file of barcode for code='.$code.' encoding='.$encoding.' file='.basename($barcodeimage), 'errors');
}
}
else
{
$error++;
setEventMessage("Error, encoding ".$encoding." is not supported by encoder ".$generator.'. You must choose another barcode type or install a barcode generation engine that support '.$encoding, 'errors');
}
} else {
$template = 'tcpdflabel';
$encoding = $module->getTcpdfEncodingType($encoding); //convert to TCPDF compatible encoding types
$is2d = $module->is2d;
}
}

if (! $error)
Expand All @@ -188,11 +196,12 @@
// For labels
if ($mode == 'label')
{
$txtforsticker="%PHOTO%";
$textleft=make_substitutions($txtforsticker, $substitutionarray);
$textheader='';
$textfooter='';
$textright='';

$txtforsticker="%PHOTO%"; // Photo will be barcode image, %BARCODE% posible when using TCPDF generator
$textleft=make_substitutions((empty($conf->global->BARCODE_LABEL_LEFT_TEXT)?$txtforsticker:$conf->global->BARCODE_LABEL_LEFT_TEXT), $substitutionarray);
$textheader=make_substitutions((empty($conf->global->BARCODE_LABEL_HEADER_TEXT)?'':$conf->global->BARCODE_LABEL_HEADER_TEXT), $substitutionarray);
$textfooter=make_substitutions((empty($conf->global->BARCODE_LABEL_FOOTER_TEXT)?'':$conf->global->BARCODE_LABEL_FOOTER_TEXT), $substitutionarray);
$textright=make_substitutions((empty($conf->global->BARCODE_LABEL_RIGHT_TEXT)?'':$conf->global->BARCODE_LABEL_RIGHT_TEXT), $substitutionarray);
$forceimgscalewidth=(empty($conf->global->BARCODE_FORCEIMGSCALEWIDTH)?1:$conf->global->BARCODE_FORCEIMGSCALEWIDTH);
$forceimgscaleheight=(empty($conf->global->BARCODE_FORCEIMGSCALEHEIGHT)?1:$conf->global->BARCODE_FORCEIMGSCALEHEIGHT);

Expand All @@ -203,6 +212,9 @@
'textheader'=>$textheader,
'textfooter'=>$textfooter,
'textright'=>$textright,
'code'=>$code,
'encoding'=>$encoding,
'is2d'=>$is2d,
'photo'=>$barcodeimage // Photo must be a file that exists with format supported by TCPDF
);
}
Expand All @@ -222,19 +234,19 @@
{
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
}
if (! $mesg) $result=members_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs, $diroutput);
if (! $mesg) $result=members_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs, $diroutput, $template);
}

if ($result <= 0)
{
dol_print_error('',$result);
}

if (! $mesg)
{
$db->close();
exit;
}
if (! $mesg)
{
$db->close();
exit;
}
}
}

Expand Down

0 comments on commit 8a7728f

Please sign in to comment.