dolibarr  7.0.0-beta
phpbarcode.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005 Regis Houssin <regis.houssin@capnetworks.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * or see http://www.gnu.org/
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 
29 
34 {
35  var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
36  var $error='';
37 
38 
44  function isEnabled()
45  {
46  return true;
47  }
48 
49 
55  function info()
56  {
57  global $langs;
58 
59  $key = 'BarcodeInternalEngine';
60  $trans = $langs->trans('BarcodeInternalEngine');
61 
62  return ($trans != $key) ? $trans : 'Internal engine';
63  }
64 
71  function canBeActivated()
72  {
73  global $langs;
74 
75  return true;
76  }
77 
78 
85  function encodingIsSupported($encoding)
86  {
87  global $genbarcode_loc;
88  //print 'genbarcode_loc='.$genbarcode_loc.' encoding='.$encoding;exit;
89 
90  $supported=0;
91  if ($encoding == 'EAN13') $supported=1;
92  if ($encoding == 'ISBN') $supported=1;
93  // Formats that hangs on Windows (when genbarcode.exe for Windows is called, so they are not
94  // activated on Windows)
95  if (file_exists($genbarcode_loc) && empty($_SERVER["WINDIR"]))
96  {
97  if ($encoding == 'EAN8') $supported=1;
98  if ($encoding == 'UPC') $supported=1;
99  if ($encoding == 'C39') $supported=1;
100  if ($encoding == 'C128') $supported=1;
101  }
102  return $supported;
103  }
104 
115  function buildBarCode($code,$encoding,$readable='Y',$scale=1,$nooutputiferror=0)
116  {
117  global $_GET,$_SERVER;
118  global $conf;
119  global $genbarcode_loc, $bar_color, $bg_color, $text_color, $font_loc;
120 
121  if (! $this->encodingIsSupported($encoding)) return -1;
122 
123  if ($encoding == 'EAN8' || $encoding == 'EAN13') $encoding = 'EAN';
124  if ($encoding == 'C39' || $encoding == 'C128') $encoding = substr($encoding,1);
125 
126  $mode='png';
127 
128  $_GET["code"]=$code;
129  $_GET["encoding"]=$encoding;
130  $_GET["scale"]=$scale;
131  $_GET["mode"]=$mode;
132 
133  dol_syslog(get_class($this)."::buildBarCode $code,$encoding,$scale,$mode");
134  if ($code) $result=barcode_print($code,$encoding,$scale,$mode);
135 
136  if (! is_array($result))
137  {
138  $this->error=$result;
139  if (empty($nooutputiferror)) print $this->error;
140  return -1;
141  }
142 
143  return 1;
144  }
145 
156  function writeBarCode($code,$encoding,$readable='Y',$scale=1,$nooutputiferror=0)
157  {
158  global $conf,$filebarcode;
159 
160  dol_mkdir($conf->barcode->dir_temp);
161 
162  $file=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
163 
164  $filebarcode=$file; // global var to be used in barcode_outimage called by barcode_print in buildBarCode
165 
166  $result=$this->buildBarCode($code,$encoding,$readable,$scale,$nooutputiferror);
167 
168  return $result;
169  }
170 
171 }
172 
Class to generate barcode images using php barcode generator.
barcode_print($code, $encoding="ANY", $scale=2, $mode="png")
Print barcode.
Definition: barcode.lib.php:68
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.
isEnabled()
Return if a module can be used or not.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
info()
Return description.
buildBarCode($code, $encoding, $readable='Y', $scale=1, $nooutputiferror=0)
Return an image file on the fly (no need to write on disk)
print
Draft customers invoices.
Definition: index.php:91
canBeActivated()
Test si les numeros deja en vigueur dans la base ne provoquent pas de de conflits qui empechera cette...
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Parent class for barcode document models.