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