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