dolibarr  9.0.0
tcpdfbarcode.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2015 Francis Appels <francis.appels@yahoo.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/modules_barcode.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // This is to include def like $genbarcode_loc and $font_loc
28 
33 {
38  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
39 
43  public $error='';
44 
45  public $is2d = false;
46 
52  function info()
53  {
54  global $langs;
55 
56  return 'TCPDF-barcode';
57  }
58 
64  function isEnabled()
65  {
66  return true;
67  }
68 
75  function canBeActivated()
76  {
77  global $langs;
78 
79  return true;
80  }
81 
88  function encodingIsSupported($encoding)
89  {
90  $tcpdfEncoding = $this->getTcpdfEncodingType($encoding);
91  if (empty($tcpdfEncoding)) {
92  return 0;
93  } else {
94  return 1;
95  }
96  }
97 
108  function buildBarCode($code,$encoding,$readable='Y',$scale=1,$nooutputiferror=0)
109  {
110  global $_GET;
111 
112  $tcpdfEncoding = $this->getTcpdfEncodingType($encoding);
113  if (empty($tcpdfEncoding)) return -1;
114 
115  $color = array(0,0,0);
116 
117  $_GET["code"]=$code;
118  $_GET["type"]=$encoding;
119  $_GET["height"]=$height;
120  $_GET["readable"]=$readable;
121 
122  if ($code) {
123  // Load the tcpdf barcode class
124  if ($this->is2d) {
125  $height = 3;
126  $width = 3;
127  require_once TCPDF_PATH.'tcpdf_barcodes_2d.php';
128  $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding);
129  } else {
130  $height = 50;
131  $width = 1;
132  require_once TCPDF_PATH.'tcpdf_barcodes_1d.php';
133  $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding);
134  }
135 
136  dol_syslog("buildBarCode::TCPDF.getBarcodePNG");
137  $barcodeobj->getBarcodePNG($width, $height, $color);
138 
139  return 1;
140  } else {
141  return -2;
142  }
143  }
144 
155  function writeBarCode($code,$encoding,$readable='Y',$scale=1,$nooutputiferror=0)
156  {
157  global $conf,$_GET;
158 
159  dol_mkdir($conf->barcode->dir_temp);
160  $file=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
161 
162  $tcpdfEncoding = $this->getTcpdfEncodingType($encoding);
163  if (empty($tcpdfEncoding)) return -1;
164 
165  $color = array(0,0,0);
166 
167  $_GET["code"]=$code;
168  $_GET["type"]=$encoding;
169  $_GET["height"]=$height;
170  $_GET["readable"]=$readable;
171 
172  if ($code) {
173  // Load the tcpdf barcode class
174  if ($this->is2d) {
175  $height = 1;
176  $width = 1;
177  require_once TCPDF_PATH.'tcpdf_barcodes_2d.php';
178  $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding);
179  } else {
180  $height = 50;
181  $width = 1;
182  require_once TCPDF_PATH.'tcpdf_barcodes_1d.php';
183  $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding);
184  }
185 
186  dol_syslog("writeBarCode::TCPDF.getBarcodePngData");
187  if ($imageData = $barcodeobj->getBarcodePngData($width, $height, $color)) {
188  if (function_exists('imagecreate')) {
189  $imageData = imagecreatefromstring($imageData);
190  }
191  if (imagepng($imageData, $file)) {
192  return 1;
193  } else {
194  return -3;
195  }
196  } else {
197  return -4;
198  }
199  } else {
200  return -2;
201  }
202  }
203 
210  public function getTcpdfEncodingType($dolEncodingType)
211  {
212  $tcpdf1dEncodingTypes = array(
213  'C39' => 'C39',
214  'C39+' => 'C39+',
215  'C39E' => 'C39E',
216  'C39E+' => 'C39E+',
217  'S25' => 'S25',
218  'S25+' => 'S25+',
219  'I25' => 'I25',
220  'I25+' => 'I25+',
221  'C128' => 'C128',
222  'C128A' => 'C128A',
223  'C128B' => 'C128B',
224  'C128C' => 'C128C',
225  'EAN2' => 'EAN2',
226  'EAN5' => 'EAN5',
227  'EAN8' => 'EAN8',
228  'EAN13' => 'EAN13',
229  'ISBN' => 'EAN13',
230  'UPC' => 'UPCA',
231  'UPCE' => 'UPCE',
232  'MSI' => 'MSI',
233  'MSI+' => 'MSI+',
234  'POSTNET' => 'POSTNET',
235  'PLANET' => 'PLANET',
236  'RMS4CC' => 'RMS4CC',
237  'KIX' => 'KIX',
238  'IMB' => 'IMB',
239  'CODABAR' => 'CODABAR',
240  'CODE11' => 'CODE11',
241  'PHARMA' => 'PHARMA',
242  'PHARMA2T' => 'PHARMA2T'
243  );
244 
245  $tcpdf2dEncodingTypes = array(
246  'DATAMATRIX' => 'DATAMATRIX',
247  'PDF417' => 'PDF417',
248  'QRCODE' => 'QRCODE,L',
249  'QRCODE,L' => 'QRCODE,L',
250  'QRCODE,M' => 'QRCODE,M',
251  'QRCODE,Q' => 'QRCODE,Q',
252  'QRCODE,H' => 'QRCODE,H'
253  );
254 
255  if (array_key_exists($dolEncodingType, $tcpdf1dEncodingTypes)) {
256  $this->is2d = false;
257  return $tcpdf1dEncodingTypes[$dolEncodingType];
258  } else if (array_key_exists($dolEncodingType, $tcpdf2dEncodingTypes)) {
259  $this->is2d = true;
260  return $tcpdf2dEncodingTypes[$dolEncodingType];
261  } else {
262  return '';
263  }
264  }
265 }
canBeActivated()
Test si les numeros deja en vigueur dans la base ne provoquent pas de de conflits qui empechera cette...
isEnabled()
Return if a module can be used or not.
getTcpdfEncodingType($dolEncodingType)
get available output_modes for tcpdf class wth its translated description
writeBarCode($code, $encoding, $readable='Y', $scale=1, $nooutputiferror=0)
Save an image file on disk (with no output)
encodingIsSupported($encoding)
Return true if encoding is supported.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
buildBarCode($code, $encoding, $readable='Y', $scale=1, $nooutputiferror=0)
Return an image file on the fly (no need to write on disk)
info()
Return description of numbering model.
Class to generate barcode images using tcpdf barcode generator.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
$version
Dolibarr version of the loaded document string.
Parent class for barcode document models.