dolibarr  7.0.0-beta
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@capnetworks.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 {
34  var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
35  var $error='';
36  var $is2d = false;
37 
43  function info()
44  {
45  global $langs;
46 
47  return 'TCPDF-barcode';
48  }
49 
55  function isEnabled()
56  {
57  return true;
58  }
59 
66  function canBeActivated()
67  {
68  global $langs;
69 
70  return true;
71  }
72 
79  function encodingIsSupported($encoding)
80  {
81  $tcpdfEncoding = $this->getTcpdfEncodingType($encoding);
82  if (empty($tcpdfEncoding)) {
83  return 0;
84  } else {
85  return 1;
86  }
87  }
88 
99  function buildBarCode($code,$encoding,$readable='Y',$scale=1,$nooutputiferror=0)
100  {
101  global $_GET;
102 
103  $tcpdfEncoding = $this->getTcpdfEncodingType($encoding);
104  if (empty($tcpdfEncoding)) return -1;
105 
106  $color = array(0,0,0);
107 
108  $_GET["code"]=$code;
109  $_GET["type"]=$encoding;
110  $_GET["height"]=$height;
111  $_GET["readable"]=$readable;
112 
113  if ($code) {
114  // Load the tcpdf barcode class
115  if ($this->is2d) {
116  $height = 3;
117  $width = 3;
118  require_once TCPDF_PATH.'tcpdf_barcodes_2d.php';
119  $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding);
120  } else {
121  $height = 50;
122  $width = 1;
123  require_once TCPDF_PATH.'tcpdf_barcodes_1d.php';
124  $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding);
125  }
126 
127  dol_syslog("buildBarCode::TCPDF.getBarcodePNG");
128  $barcodeobj->getBarcodePNG($width, $height, $color);
129 
130  return 1;
131  } else {
132  return -2;
133  }
134  }
135 
146  function writeBarCode($code,$encoding,$readable='Y',$scale=1,$nooutputiferror=0)
147  {
148  global $conf,$_GET;
149 
150  dol_mkdir($conf->barcode->dir_temp);
151  $file=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
152 
153  $tcpdfEncoding = $this->getTcpdfEncodingType($encoding);
154  if (empty($tcpdfEncoding)) return -1;
155 
156  $color = array(0,0,0);
157 
158  $_GET["code"]=$code;
159  $_GET["type"]=$encoding;
160  $_GET["height"]=$height;
161  $_GET["readable"]=$readable;
162 
163  if ($code) {
164  // Load the tcpdf barcode class
165  if ($this->is2d) {
166  $height = 1;
167  $width = 1;
168  require_once TCPDF_PATH.'tcpdf_barcodes_2d.php';
169  $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding);
170  } else {
171  $height = 50;
172  $width = 1;
173  require_once TCPDF_PATH.'tcpdf_barcodes_1d.php';
174  $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding);
175  }
176 
177  dol_syslog("writeBarCode::TCPDF.getBarcodePngData");
178  if ($imageData = $barcodeobj->getBarcodePngData($width, $height, $color)) {
179  if (function_exists('imagecreate')) {
180  $imageData = imagecreatefromstring($imageData);
181  }
182  if (imagepng($imageData, $file)) {
183  return 1;
184  } else {
185  return -3;
186  }
187  } else {
188  return -4;
189  }
190  } else {
191  return -2;
192  }
193  }
194 
201  public function getTcpdfEncodingType($dolEncodingType)
202  {
203  $tcpdf1dEncodingTypes = array(
204  'C39' => 'C39',
205  'C39+' => 'C39+',
206  'C39E' => 'C39E',
207  'C39E+' => 'C39E+',
208  'S25' => 'S25',
209  'S25+' => 'S25+',
210  'I25' => 'I25',
211  'I25+' => 'I25+',
212  'C128' => 'C128',
213  'C128A' => 'C128A',
214  'C128B' => 'C128B',
215  'C128C' => 'C128C',
216  'EAN2' => 'EAN2',
217  'EAN5' => 'EAN5',
218  'EAN8' => 'EAN8',
219  'EAN13' => 'EAN13',
220  'ISBN' => 'EAN13',
221  'UPC' => 'UPCA',
222  'UPCE' => 'UPCE',
223  'MSI' => 'MSI',
224  'MSI+' => 'MSI+',
225  'POSTNET' => 'POSTNET',
226  'PLANET' => 'PLANET',
227  'RMS4CC' => 'RMS4CC',
228  'KIX' => 'KIX',
229  'IMB' => 'IMB',
230  'CODABAR' => 'CODABAR',
231  'CODE11' => 'CODE11',
232  'PHARMA' => 'PHARMA',
233  'PHARMA2T' => 'PHARMA2T'
234  );
235 
236  $tcpdf2dEncodingTypes = array(
237  'DATAMATRIX' => 'DATAMATRIX',
238  'PDF417' => 'PDF417',
239  'QRCODE' => 'QRCODE,L',
240  'QRCODE,L' => 'QRCODE,L',
241  'QRCODE,M' => 'QRCODE,M',
242  'QRCODE,Q' => 'QRCODE,Q',
243  'QRCODE,H' => 'QRCODE,H'
244  );
245 
246  if (array_key_exists($dolEncodingType, $tcpdf1dEncodingTypes)) {
247  $this->is2d = false;
248  return $tcpdf1dEncodingTypes[$dolEncodingType];
249  } else if (array_key_exists($dolEncodingType, $tcpdf2dEncodingTypes)) {
250  $this->is2d = true;
251  return $tcpdf2dEncodingTypes[$dolEncodingType];
252  } else {
253  return '';
254  }
255  }
256 }
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)
Parent class for barcode document models.