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 // Show modules according to features level
177 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
178 continue;
179 }
180 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
181 continue;
182 }
183
184 if ($module->isEnabled()) {
185 $barcodelist[$filebis] = $module->info($langs);
186 }
187 }
188 }
189 }
190 }
191 }
192}
193'@phan-var-force array<string,ModeleBarCode> $barcodelist';
194
195
196// Select barcode numbering module
197if (isModEnabled('product')) {
198 print load_fiche_titre($langs->trans("BarCodeNumberManager")." (".$langs->trans("Product").")", '', '');
199
200 print '<div class="div-table-responsive-no-min">';
201 print '<table class="noborder centpercent">';
202 print '<tr class="liste_titre">';
203 print '<td width="140">'.$langs->trans("Name").'</td>';
204 print '<td>'.$langs->trans("Description").'</td>';
205 print '<td>'.$langs->trans("Example").'</td>';
206 print '<td class="center" width="80">'.$langs->trans("Status").'</td>';
207 print '<td class="center" width="60">'.$langs->trans("ShortInfo").'</td>';
208 print "</tr>\n";
209
210 $dirbarcodenum = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
211
212 foreach ($dirbarcodenum as $dirroot) {
213 $dir = dol_buildpath($dirroot, 0);
214
215 $handle = @opendir($dir);
216 if (is_resource($handle)) {
217 while (($file = readdir($handle)) !== false) {
218 if (preg_match('/^mod_barcode_product_.*php$/', $file)) {
219 $file = substr($file, 0, dol_strlen($file) - 4);
220
221 try {
222 dol_include_once($dirroot.$file.'.php');
223 } catch (Exception $e) {
224 dol_syslog($e->getMessage(), LOG_ERR);
225 }
226
227 $modBarCode = new $file();
228 '@phan-var-force ModeleNumRefBarCode $modBarCode';
229
230 print '<tr class="oddeven">';
231 print '<td>'.(isset($modBarCode->name) ? $modBarCode->name : $modBarCode->nom)."</td><td>\n";
232 print $modBarCode->info($langs);
233 print '</td>';
234 print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n";
235
236 if (getDolGlobalString('BARCODE_PRODUCT_ADDON_NUM') == "$file") {
237 print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproductoff&token='.newToken().'&amp;value='.urlencode($file).'">';
238 print img_picto($langs->trans("Activated"), 'switch_on');
239 print '</a></td>';
240 } else {
241 print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproducton&token='.newToken().'&amp;value='.urlencode($file).'">';
242 print img_picto($langs->trans("Disabled"), 'switch_off');
243 print '</a></td>';
244 }
245 print '<td class="center">';
246 $s = $modBarCode->getToolTip($langs, null, -1);
247 print $form->textwithpicto('', $s, 1);
248 print '</td>';
249 print "</tr>\n";
250 }
251 }
252 closedir($handle);
253 }
254 }
255 print "</table>\n";
256 print '</div>';
257}
258
259// Select barcode numbering module
260if (isModEnabled('societe')) {
261 print load_fiche_titre($langs->trans("BarCodeNumberManager")." (".$langs->trans("ThirdParty").")", '', '');
262
263 print '<div class="div-table-responsive-no-min">';
264 print '<table class="noborder centpercent">';
265 print '<tr class="liste_titre">';
266 print '<td width="140">'.$langs->trans("Name").'</td>';
267 print '<td>'.$langs->trans("Description").'</td>';
268 print '<td>'.$langs->trans("Example").'</td>';
269 print '<td class="center" width="80">'.$langs->trans("Status").'</td>';
270 print '<td class="center" width="60">'.$langs->trans("ShortInfo").'</td>';
271 print "</tr>\n";
272
273 $dirbarcodenum = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
274
275 foreach ($dirbarcodenum as $dirroot) {
276 $dir = dol_buildpath($dirroot, 0);
277
278 $handle = @opendir($dir);
279 if (is_resource($handle)) {
280 while (($file = readdir($handle)) !== false) {
281 if (preg_match('/^mod_barcode_thirdparty_.*php$/', $file)) {
282 $file = substr($file, 0, dol_strlen($file) - 4);
283
284 try {
285 dol_include_once($dirroot.$file.'.php');
286 } catch (Exception $e) {
287 dol_syslog($e->getMessage(), LOG_ERR);
288 }
289
290 $modBarCode = new $file();
291 print '<tr class="oddeven">';
292 print '<td>'.(isset($modBarCode->name) ? $modBarCode->name : $modBarCode->nom)."</td><td>\n";
293 print $modBarCode->info($langs);
294 print '</td>';
295 print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n";
296
297 if (getDolGlobalString('BARCODE_THIRDPARTY_ADDON_NUM') && $conf->global->BARCODE_THIRDPARTY_ADDON_NUM == "$file") {
298 print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setbarcodethirdpartyoff&token='.newToken().'&amp;value='.urlencode($file).'">';
299 print img_picto($langs->trans("Activated"), 'switch_on');
300 print '</a></td>';
301 } else {
302 print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setbarcodethirdpartyon&token='.newToken().'&amp;value='.urlencode($file).'">';
303 print img_picto($langs->trans("Disabled"), 'switch_off');
304 print '</a></td>';
305 }
306 print '<td class="center">';
307 $s = $modBarCode->getToolTip($langs, null, -1);
308 print $form->textwithpicto('', $s, 1);
309 print '</td>';
310 print "</tr>\n";
311 }
312 }
313 closedir($handle);
314 }
315 }
316 print "</table>\n";
317 print '</div>';
318}
319
320/*
321 * CHOIX ENCODAGE
322 */
323
324print '<br>';
325print load_fiche_titre($langs->trans("BarcodeEncodeModule"), '', '');
326
327if (empty($conf->use_javascript_ajax)) {
328 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="form_engine">';
329 print '<input type="hidden" name="token" value="'.newToken().'">';
330 print '<input type="hidden" name="action" value="updateengine">';
331}
332
333print '<div class="div-table-responsive-no-min">';
334print '<table class="noborder centpercent">';
335print '<tr class="liste_titre">';
336print '<td>'.$langs->trans("Name").'</td>';
337print '<td>'.$langs->trans("Description").'</td>';
338print '<td width="200" class="center">'.$langs->trans("Example").'</td>';
339print '<td class="center" width="60">'.$langs->trans("CodeBarGenerator").'</td>';
340print "</tr>\n";
341
342$sql = "SELECT rowid, code as encoding, libelle as label, coder, example";
343$sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
344$sql .= " WHERE entity = ".$conf->entity;
345$sql .= " ORDER BY code";
346
347dol_syslog("admin/barcode.php", LOG_DEBUG);
348$resql = $db->query($sql);
349if ($resql) {
350 $num = $db->num_rows($resql);
351 $i = 0;
352
353 while ($i < $num) {
354 $obj = $db->fetch_object($resql);
355
356 print '<tr class="oddeven">';
357 print '<td width="100">';
358 print dol_escape_htmltag($obj->label);
359 print "</td><td>\n";
360 print $langs->trans('BarcodeDesc'.$obj->encoding);
361 //print "L'EAN se compose de 8 characters, 7 chiffres plus une cle de verification.<br>";
362 //print "L'utilisation des symbologies EAN8 impose la souscription et l'abonnement aupres d'organismes comme GENCOD.<br>";
363 //print "Codes numeriques utilises exclusivement a l'identification des produits susceptibles d'etre vendus au grand public.";
364 print '</td>';
365
366 // Show example
367 print '<td class="center">';
368 if ($obj->coder && $obj->coder != -1) {
369 $result = 0;
370
371 foreach ($dirbarcode as $reldir) {
372 $dir = dol_buildpath($reldir, 0);
373 $newdir = dol_osencode($dir);
374
375 // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
376 if (!is_dir($newdir)) {
377 continue;
378 }
379
380 $result = @include_once $newdir.$obj->coder.'.modules.php';
381 if ($result) {
382 break;
383 }
384 }
385 if ($result) {
386 $classname = "mod".ucfirst($obj->coder);
387 if (class_exists($classname)) {
388 $module = new $classname($db);
389 if ($module->encodingIsSupported($obj->encoding)) {
390 // Build barcode on disk (not used, this is done to make debug easier)
391 $result = $module->writeBarCode($obj->example, $obj->encoding, 'Y');
392 // Generate on the fly and output barcode with generator
393 $url = DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&amp;generator='.urlencode($obj->coder).'&amp;code='.urlencode($obj->example).'&amp;encoding='.urlencode($obj->encoding);
394 //print $url;
395 print '<img src="'.$url.'" title="'.$obj->example.'" border="0">';
396 } else {
397 print $langs->trans("FormatNotSupportedByGenerator");
398 }
399 } else {
400 print 'ErrorClassNotFoundInModule '.$classname.' '.$obj->coder;
401 }
402 }
403 } else {
404 print '<span class="opacitymedium">'.$langs->trans("ChooseABarCode").'</span>';
405 }
406 print '</td>';
407
408 print '<td class="center">';
409 print $formbarcode->setBarcodeEncoder($obj->coder, $barcodelist, $obj->rowid, 'form'.$i);
410 print "</td></tr>\n";
411
412 $i++;
413 }
414}
415print "</table>\n";
416print '</div>';
417
418if (empty($conf->use_javascript_ajax)) {
419 print $form->buttonsSaveCancel("Save", '');
420}
421
422print "<br>";
423
424
425/*
426 * Other options
427 */
428print load_fiche_titre($langs->trans("OtherOptions"), '', '');
429
430print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
431print '<input type="hidden" name="token" value="'.newToken().'">';
432print "<input type=\"hidden\" name=\"action\" value=\"update\">";
433
434print '<div class="div-table-responsive-no-min">';
435print '<table class="noborder centpercent">';
436print '<tr class="liste_titre">';
437print '<td>'.$langs->trans("Parameter").'</td>';
438print '<td width="60" class="center">'.$langs->trans("Value").'</td>';
439print '<td>&nbsp;</td>';
440print '</tr>';
441
442// Chemin du binaire genbarcode sous linux
443if (!isset($_SERVER['WINDIR'])) {
444 print '<tr class="oddeven">';
445 print '<td>'.$langs->trans("GenbarcodeLocation").'</td>';
446 print '<td width="60" class="center">';
447 print '<input type="text" size="40" name="GENBARCODE_LOCATION" value="'.getDolGlobalString('GENBARCODE_LOCATION').'">';
448 if (getDolGlobalString('GENBARCODE_LOCATION') && !@file_exists($conf->global->GENBARCODE_LOCATION)) {
449 $langs->load("errors");
450 print '<br><span class="error">'.$langs->trans("ErrorFileNotFound", getDolGlobalString('GENBARCODE_LOCATION')).'</span>';
451 }
452 print '</td>';
453 print '<td>&nbsp;</td>';
454 print '</tr>';
455}
456
457// Module products
458if (isModEnabled('product')) {
459 print '<tr class="oddeven">';
460 print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
461 print '<td width="60" class="right">';
462 print $formbarcode->selectBarcodeType(getDolGlobalString('PRODUIT_DEFAULT_BARCODE_TYPE'), "PRODUIT_DEFAULT_BARCODE_TYPE", 1);
463 print '</td>';
464 print '<td>&nbsp;</td>';
465 print '</tr>';
466}
467
468// Module thirdparty
469if (isModEnabled('societe')) {
470 print '<tr class="oddeven">';
471 print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
472 print '<td width="60" class="right">';
473 print $formbarcode->selectBarcodeType(getDolGlobalString('GENBARCODE_BARCODETYPE_THIRDPARTY'), "GENBARCODE_BARCODETYPE_THIRDPARTY", 1);
474 print '</td>';
475 print '<td>&nbsp;</td>';
476 print '</tr>';
477}
478
479print "</table>\n";
480print '</div>';
481
482print '<div class="tabsAction">';
483print '<input type="submit" class="button" name="submit_GENBARCODE_BARCODETYPE_THIRDPARTY" value="'.$langs->trans("Modify").'">';
484print "</div>";
485print '</form>';
486
487print '<br>';
488
489
490// End of page
491llxFooter();
492$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.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.