dolibarr  16.0.5
barcode.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
30 
31 // Load translation files required by the page
32 $langs->load("admin");
33 
34 if (!$user->admin) {
36 }
37 
38 $action = GETPOST('action', 'aZ09');
39 $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
40 
41 
42 /*
43  * Actions
44  */
45 
46 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
47 
48 if ($action == 'setbarcodeproducton') {
49  $barcodenumberingmodule = GETPOST('value', 'alpha');
50  $res = dolibarr_set_const($db, "BARCODE_PRODUCT_ADDON_NUM", $barcodenumberingmodule, 'chaine', 0, '', $conf->entity);
51  if ($barcodenumberingmodule == 'mod_barcode_product_standard' && empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) {
52  $res = dolibarr_set_const($db, "BARCODE_STANDARD_PRODUCT_MASK", '020{000000000}', 'chaine', 0, '', $conf->entity);
53  }
54 } elseif ($action == 'setbarcodeproductoff') {
55  $res = dolibarr_del_const($db, "BARCODE_PRODUCT_ADDON_NUM", $conf->entity);
56 }
57 
58 if ($action == 'setcoder') {
59  $coder = GETPOST('coder', 'alpha');
60  $code_id = GETPOST('code_id', 'int');
61  $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
62  $sqlp .= " SET coder = '".$db->escape($coder)."'";
63  $sqlp .= " WHERE rowid = ".((int) $code_id);
64  $sqlp .= " AND entity = ".$conf->entity;
65 
66  $resql = $db->query($sqlp);
67  if (!$resql) {
68  dol_print_error($db);
69  }
70 } elseif ($action == 'update') {
71  $location = GETPOST('GENBARCODE_LOCATION', 'alpha');
72  $res = dolibarr_set_const($db, "GENBARCODE_LOCATION", $location, 'chaine', 0, '', $conf->entity);
73  $coder_id = GETPOST('PRODUIT_DEFAULT_BARCODE_TYPE', 'alpha');
74  $res = dolibarr_set_const($db, "PRODUIT_DEFAULT_BARCODE_TYPE", $coder_id, 'chaine', 0, '', $conf->entity);
75  $coder_id = GETPOST('GENBARCODE_BARCODETYPE_THIRDPARTY', 'alpha');
76  $res = dolibarr_set_const($db, "GENBARCODE_BARCODETYPE_THIRDPARTY", $coder_id, 'chaine', 0, '', $conf->entity);
77 
78  if ($res > 0) {
79  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
80  } else {
81  setEventMessages($langs->trans("Error"), null, 'errors');
82  }
83 } elseif ($action == 'updateengine') {
84  $sql = "SELECT rowid, coder";
85  $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
86  $sql .= " WHERE entity = ".$conf->entity;
87  $sql .= " ORDER BY code";
88 
89  $resql = $db->query($sql);
90  if ($resql) {
91  $num = $db->num_rows($resql);
92  $i = 0;
93 
94  while ($i < $num) {
95  $obj = $db->fetch_object($resql);
96 
97  if (GETPOST('coder'.$obj->rowid, 'alpha')) {
98  $coder = GETPOST('coder'.$obj->rowid, 'alpha');
99  $code_id = $obj->rowid;
100 
101  $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
102  $sqlp .= " SET coder = '".$db->escape($coder)."'";
103  $sqlp .= " WHERE rowid = ".((int) $code_id);
104  $sqlp .= " AND entity = ".$conf->entity;
105 
106  $upsql = $db->query($sqlp);
107  if (!$upsql) {
108  dol_print_error($db);
109  }
110  }
111 
112  $i++;
113  }
114  }
115 }
116 
117 
118 /*
119  * View
120  */
121 
122 $form = new Form($db);
123 $formbarcode = new FormBarCode($db);
124 
125 $help_url = 'EN:Module_Barcode|FR:Module_Codes_Barre|ES:Módulo Código de barra|DE:Modul_Barcode';
126 llxHeader('', $langs->trans("BarcodeSetup"), $help_url);
127 
128 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
129 print load_fiche_titre($langs->trans("BarcodeSetup"), $linkback, 'title_setup');
130 
131 // Detect bar codes modules
132 $barcodelist = array();
133 
134 clearstatcache();
135 
136 
137 // Scan list of all barcode included provided by external modules
138 $dirbarcode = array_merge(array("/core/modules/barcode/doc/"), $conf->modules_parts['barcode']);
139 
140 foreach ($dirbarcode as $reldir) {
141  $dir = dol_buildpath($reldir);
142  $newdir = dol_osencode($dir);
143 
144  // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
145  if (!is_dir($newdir)) {
146  continue;
147  }
148 
149  $handle = @opendir($newdir);
150  if (is_resource($handle)) {
151  while (($file = readdir($handle)) !== false) {
152  if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') {
153  if (is_readable($newdir.$file)) {
154  if (preg_match('/(.*)\.modules\.php$/i', $file, $reg)) {
155  $filebis = $reg[1];
156 
157  // Loading encoding class
158  require_once $newdir.$file;
159  $classname = "mod".ucfirst($filebis);
160  $module = new $classname($db);
161 
162  // Show modules according to features level
163  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
164  continue;
165  }
166  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
167  continue;
168  }
169 
170  if ($module->isEnabled()) {
171  $barcodelist[$filebis] = $module->info();
172  }
173  }
174  }
175  }
176  }
177  }
178 }
179 
180 
181 
182 // Select barcode numbering module
183 if ($conf->product->enabled) {
184  print load_fiche_titre($langs->trans("BarCodeNumberManager")." (".$langs->trans("Product").")", '', '');
185 
186  print '<div class="div-table-responsive-no-min">';
187  print '<table class="noborder centpercent">';
188  print '<tr class="liste_titre">';
189  print '<td width="140">'.$langs->trans("Name").'</td>';
190  print '<td>'.$langs->trans("Description").'</td>';
191  print '<td>'.$langs->trans("Example").'</td>';
192  print '<td class="center" width="80">'.$langs->trans("Status").'</td>';
193  print '<td class="center" width="60">'.$langs->trans("ShortInfo").'</td>';
194  print "</tr>\n";
195 
196  $dirbarcodenum = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
197 
198  foreach ($dirbarcodenum as $dirroot) {
199  $dir = dol_buildpath($dirroot, 0);
200 
201  $handle = @opendir($dir);
202  if (is_resource($handle)) {
203  while (($file = readdir($handle)) !== false) {
204  if (preg_match('/^mod_barcode_product_.*php$/', $file)) {
205  $file = substr($file, 0, dol_strlen($file) - 4);
206 
207  try {
208  dol_include_once($dirroot.$file.'.php');
209  } catch (Exception $e) {
210  dol_syslog($e->getMessage(), LOG_ERR);
211  }
212 
213  $modBarCode = new $file();
214 
215  print '<tr class="oddeven">';
216  print '<td>'.(isset($modBarCode->name) ? $modBarCode->name : $modBarCode->nom)."</td><td>\n";
217  print $modBarCode->info($langs);
218  print '</td>';
219  print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n";
220 
221  if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM) && $conf->global->BARCODE_PRODUCT_ADDON_NUM == "$file") {
222  print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproductoff&token='.newToken().'&amp;value='.urlencode($file).'">';
223  print img_picto($langs->trans("Activated"), 'switch_on');
224  print '</a></td>';
225  } else {
226  print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproducton&token='.newToken().'&amp;value='.urlencode($file).'">';
227  print img_picto($langs->trans("Disabled"), 'switch_off');
228  print '</a></td>';
229  }
230  print '<td class="center">';
231  $s = $modBarCode->getToolTip($langs, null, -1);
232  print $form->textwithpicto('', $s, 1);
233  print '</td>';
234  print "</tr>\n";
235  }
236  }
237  closedir($handle);
238  }
239  }
240  print "</table>\n";
241  print '</div>';
242 }
243 
244 
245 /*
246  * CHOIX ENCODAGE
247  */
248 
249 print '<br>';
250 print load_fiche_titre($langs->trans("BarcodeEncodeModule"), '', '');
251 
252 if (empty($conf->use_javascript_ajax)) {
253  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="form_engine">';
254  print '<input type="hidden" name="token" value="'.newToken().'">';
255  print '<input type="hidden" name="action" value="updateengine">';
256 }
257 
258 print '<div class="div-table-responsive-no-min">';
259 print '<table class="noborder centpercent">';
260 print '<tr class="liste_titre">';
261 print '<td>'.$langs->trans("Name").'</td>';
262 print '<td>'.$langs->trans("Description").'</td>';
263 print '<td width="200" class="center">'.$langs->trans("Example").'</td>';
264 print '<td class="center" width="60">'.$langs->trans("CodeBarGenerator").'</td>';
265 print "</tr>\n";
266 
267 $sql = "SELECT rowid, code as encoding, libelle as label, coder, example";
268 $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
269 $sql .= " WHERE entity = ".$conf->entity;
270 $sql .= " ORDER BY code";
271 
272 dol_syslog("admin/barcode.php", LOG_DEBUG);
273 $resql = $db->query($sql);
274 if ($resql) {
275  $num = $db->num_rows($resql);
276  $i = 0;
277 
278  while ($i < $num) {
279  $obj = $db->fetch_object($resql);
280 
281  print '<tr class="oddeven">';
282  print '<td width="100">';
283  print dol_escape_htmltag($obj->label);
284  print "</td><td>\n";
285  print $langs->trans('BarcodeDesc'.$obj->encoding);
286  //print "L'EAN se compose de 8 caracteres, 7 chiffres plus une cle de controle.<br>";
287  //print "L'utilisation des symbologies EAN8 impose la souscription et l'abonnement aupres d'organisme tel que GENCOD.<br>";
288  //print "Codes numeriques utilises exclusivement a l'identification des produits susceptibles d'etre vendus au grand public.";
289  print '</td>';
290 
291  // Show example
292  print '<td class="center">';
293  if ($obj->coder && $obj->coder != -1) {
294  $result = 0;
295 
296  foreach ($dirbarcode as $reldir) {
297  $dir = dol_buildpath($reldir, 0);
298  $newdir = dol_osencode($dir);
299 
300  // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
301  if (!is_dir($newdir)) {
302  continue;
303  }
304 
305  $result = @include_once $newdir.$obj->coder.'.modules.php';
306  if ($result) {
307  break;
308  }
309  }
310  if ($result) {
311  $classname = "mod".ucfirst($obj->coder);
312  if (class_exists($classname)) {
313  $module = new $classname($db);
314  if ($module->encodingIsSupported($obj->encoding)) {
315  // Build barcode on disk (not used, this is done to make debug easier)
316  $result = $module->writeBarCode($obj->example, $obj->encoding, 'Y');
317  // Generate on the fly and output barcode with generator
318  $url = DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&amp;generator='.urlencode($obj->coder).'&amp;code='.urlencode($obj->example).'&amp;encoding='.urlencode($obj->encoding);
319  //print $url;
320  print '<img src="'.$url.'" title="'.$obj->example.'" border="0">';
321  } else {
322  print $langs->trans("FormatNotSupportedByGenerator");
323  }
324  } else {
325  print 'ErrorClassNotFoundInModule '.$classname.' '.$obj->coder;
326  }
327  }
328  } else {
329  print '<span class="opacitymedium">'.$langs->trans("ChooseABarCode").'</span>';
330  }
331  print '</td>';
332 
333  print '<td class="center">';
334  print $formbarcode->setBarcodeEncoder($obj->coder, $barcodelist, $obj->rowid, 'form'.$i);
335  print "</td></tr>\n";
336 
337  $i++;
338  }
339 }
340 print "</table>\n";
341 print '</div>';
342 
343 if (empty($conf->use_javascript_ajax)) {
344  print $form->buttonsSaveCancel("Save", '');
345 }
346 
347 print "<br>";
348 
349 
350 /*
351  * Other options
352  */
353 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
354 
355 print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
356 print '<input type="hidden" name="token" value="'.newToken().'">';
357 print "<input type=\"hidden\" name=\"action\" value=\"update\">";
358 
359 print '<div class="div-table-responsive-no-min">';
360 print '<table class="noborder centpercent">';
361 print '<tr class="liste_titre">';
362 print '<td>'.$langs->trans("Parameter").'</td>';
363 print '<td width="60" class="center">'.$langs->trans("Value").'</td>';
364 print '<td>&nbsp;</td>';
365 print '</tr>';
366 
367 // Chemin du binaire genbarcode sous linux
368 if (!isset($_SERVER['WINDIR'])) {
369  print '<tr class="oddeven">';
370  print '<td>'.$langs->trans("GenbarcodeLocation").'</td>';
371  print '<td width="60" class="center">';
372  print '<input type="text" size="40" name="GENBARCODE_LOCATION" value="'.getDolGlobalString('GENBARCODE_LOCATION').'">';
373  if (!empty($conf->global->GENBARCODE_LOCATION) && !@file_exists($conf->global->GENBARCODE_LOCATION)) {
374  $langs->load("errors");
375  print '<br><span class="error">'.$langs->trans("ErrorFileNotFound", $conf->global->GENBARCODE_LOCATION).'</span>';
376  }
377  print '</td>';
378  print '<td>&nbsp;</td>';
379  print '</tr>';
380 }
381 
382 // Module products
383 if (!empty($conf->product->enabled)) {
384  print '<tr class="oddeven">';
385  print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
386  print '<td width="60" class="right">';
387  print $formbarcode->selectBarcodeType($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE, "PRODUIT_DEFAULT_BARCODE_TYPE", 1);
388  print '</td>';
389  print '<td>&nbsp;</td>';
390  print '</tr>';
391 }
392 
393 // Module thirdparty
394 if (!empty($conf->societe->enabled)) {
395  print '<tr class="oddeven">';
396  print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
397  print '<td width="60" class="right">';
398  print $formbarcode->selectBarcodeType($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY, "GENBARCODE_BARCODETYPE_THIRDPARTY", 1);
399  print '</td>';
400  print '<td>&nbsp;</td>';
401  print '</tr>';
402 }
403 
404 print "</table>\n";
405 print '</div>';
406 
407 print '<div class="tabsAction">';
408 print '<input type="submit" class="button" name="submit_GENBARCODE_BARCODETYPE_THIRDPARTY" value="'.$langs->trans("Modify").'">';
409 print "</div>";
410 print '</form>';
411 
412 print '<br>';
413 
414 
415 // End of page
416 llxFooter();
417 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
FormBarCode
Class to manage barcode HTML.
Definition: html.formbarcode.class.php:30
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
dol_osencode
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
Definition: functions.lib.php:8499
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
Exception
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59