dolibarr  13.0.2
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@inodbox.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 <https://www.gnu.org/licenses/>.
17  * or see https://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 {
39  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
40 
44  public $error = '';
45 
46 
52  public function isEnabled()
53  {
54  return true;
55  }
56 
57 
63  public function info()
64  {
65  global $langs;
66 
67  $key = 'BarcodeInternalEngine';
68  $trans = $langs->trans('BarcodeInternalEngine');
69 
70  return ($trans != $key) ? $trans : 'Internal engine';
71  }
72 
79  public function canBeActivated()
80  {
81  global $langs;
82 
83  return true;
84  }
85 
86 
93  public function encodingIsSupported($encoding)
94  {
95  global $genbarcode_loc;
96  //print 'genbarcode_loc='.$genbarcode_loc.' encoding='.$encoding;exit;
97 
98  $supported = 0;
99  if ($encoding == 'EAN13') $supported = 1;
100  if ($encoding == 'ISBN') $supported = 1;
101  // Formats that hangs on Windows (when genbarcode.exe for Windows is called, so they are not
102  // activated on Windows)
103  if (file_exists($genbarcode_loc) && empty($_SERVER["WINDIR"])) {
104  if ($encoding == 'EAN8') $supported = 1;
105  if ($encoding == 'UPC') $supported = 1;
106  if ($encoding == 'C39') $supported = 1;
107  if ($encoding == 'C128') $supported = 1;
108  }
109  return $supported;
110  }
111 
122  public function buildBarCode($code, $encoding, $readable = 'Y', $scale = 1, $nooutputiferror = 0)
123  {
124  global $_GET, $_SERVER;
125  global $conf;
126  global $genbarcode_loc, $bar_color, $bg_color, $text_color, $font_loc;
127 
128  if (!$this->encodingIsSupported($encoding)) return -1;
129 
130  if ($encoding == 'EAN8' || $encoding == 'EAN13') $encoding = 'EAN';
131  if ($encoding == 'C39' || $encoding == 'C128') $encoding = substr($encoding, 1);
132 
133  $mode = 'png';
134 
135  $_GET["code"] = $code;
136  $_GET["encoding"] = $encoding;
137  $_GET["scale"] = $scale;
138  $_GET["mode"] = $mode;
139 
140  dol_syslog(get_class($this)."::buildBarCode $code,$encoding,$scale,$mode");
141  if ($code) $result = barcode_print($code, $encoding, $scale, $mode);
142 
143  if (!is_array($result))
144  {
145  $this->error = $result;
146  if (empty($nooutputiferror)) print $this->error;
147  return -1;
148  }
149 
150  return 1;
151  }
152 
163  public function writeBarCode($code, $encoding, $readable = 'Y', $scale = 1, $nooutputiferror = 0)
164  {
165  global $conf, $filebarcode;
166 
167  dol_mkdir($conf->barcode->dir_temp);
168 
169  $file = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
170 
171  $filebarcode = $file; // global var to be used in barcode_outimage called by barcode_print in buildBarCode
172 
173  $result = $this->buildBarCode($code, $encoding, $readable, $scale, $nooutputiferror);
174 
175  return $result;
176  }
177 }
Class to generate barcode images using php barcode generator.
writeBarCode($code, $encoding, $readable= 'Y', $scale=1, $nooutputiferror=0)
Save an image file on disk (with no output)
barcode_print($code, $encoding="ANY", $scale=2, $mode="png")
Print barcode.
Definition: barcode.lib.php:68
buildBarCode($code, $encoding, $readable= 'Y', $scale=1, $nooutputiferror=0)
Return an image file on the fly (no need to write on disk)
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= '', $logcontext=null)
Write log message into outputs.
info()
Return description.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
Parent class for barcode document models.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)