dolibarr  13.0.2
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) accessforbidden();
35 
36 $action = GETPOST('action', 'aZ09');
37 
38 
39 /*
40  * Actions
41  */
42 
43 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
44 
45 if ($action == 'setbarcodeproducton')
46 {
47  $barcodenumberingmodule = GETPOST('value', 'alpha');
48  $res = dolibarr_set_const($db, "BARCODE_PRODUCT_ADDON_NUM", $barcodenumberingmodule, 'chaine', 0, '', $conf->entity);
49  if ($barcodenumberingmodule == 'mod_barcode_product_standard' && empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK))
50  {
51  $res = dolibarr_set_const($db, "BARCODE_STANDARD_PRODUCT_MASK", '020{000000000}', 'chaine', 0, '', $conf->entity);
52  }
53 } elseif ($action == 'setbarcodeproductoff')
54 {
55  $res = dolibarr_del_const($db, "BARCODE_PRODUCT_ADDON_NUM", $conf->entity);
56 }
57 
58 if ($action == 'setcoder')
59 {
60  $coder = GETPOST('coder', 'alpha');
61  $code_id = GETPOST('code_id', 'int');
62  $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
63  $sqlp .= " SET coder = '".$db->escape($coder)."'";
64  $sqlp .= " WHERE rowid = ".((int) $code_id);
65  $sqlp .= " AND entity = ".$conf->entity;
66 
67  $resql = $db->query($sqlp);
68  if (!$resql) dol_print_error($db);
69 } elseif ($action == 'update')
70 {
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  {
80  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
81  } else {
82  setEventMessages($langs->trans("Error"), null, 'errors');
83  }
84 } elseif ($action == 'updateengine')
85 {
86  $sql = "SELECT rowid, coder";
87  $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
88  $sql .= " WHERE entity = ".$conf->entity;
89  $sql .= " ORDER BY code";
90 
91  $resql = $db->query($sql);
92  if ($resql)
93  {
94  $num = $db->num_rows($resql);
95  $i = 0;
96 
97  while ($i < $num)
98  {
99  $obj = $db->fetch_object($resql);
100 
101  if (GETPOST('coder'.$obj->rowid, 'alpha'))
102  {
103  $coder = GETPOST('coder'.$obj->rowid, 'alpha');
104  $code_id = $obj->rowid;
105 
106  $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
107  $sqlp .= " SET coder = '".$db->escape($coder)."'";
108  $sqlp .= " WHERE rowid = ".((int) $code_id);
109  $sqlp .= " AND entity = ".$conf->entity;
110 
111  $upsql = $db->query($sqlp);
112  if (!$upsql) dol_print_error($db);
113  }
114 
115  $i++;
116  }
117  }
118 }
119 
120 
121 /*
122  * View
123  */
124 
125 $form = new Form($db);
126 $formbarcode = new FormBarCode($db);
127 
128 $help_url = 'EN:Module_Barcode|FR:Module_Codes_Barre|ES:Módulo Código de barra';
129 llxHeader('', $langs->trans("BarcodeSetup"), $help_url);
130 
131 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
132 print load_fiche_titre($langs->trans("BarcodeSetup"), $linkback, 'title_setup');
133 
134 // Detect bar codes modules
135 $barcodelist = array();
136 
137 clearstatcache();
138 
139 
140 // Scan list of all barcode included provided by external modules
141 $dirbarcode = array_merge(array("/core/modules/barcode/doc/"), $conf->modules_parts['barcode']);
142 
143 foreach ($dirbarcode as $reldir)
144 {
145  $dir = dol_buildpath($reldir);
146  $newdir = dol_osencode($dir);
147 
148  // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
149  if (!is_dir($newdir)) continue;
150 
151  $handle = @opendir($newdir);
152  if (is_resource($handle))
153  {
154  while (($file = readdir($handle)) !== false)
155  {
156  if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
157  {
158  if (is_readable($newdir.$file))
159  {
160  if (preg_match('/(.*)\.modules\.php$/i', $file, $reg))
161  {
162  $filebis = $reg[1];
163 
164  // Loading encoding class
165  require_once $newdir.$file;
166  $classname = "mod".ucfirst($filebis);
167  $module = new $classname($db);
168 
169  // Show modules according to features level
170  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
171  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
172 
173  if ($module->isEnabled())
174  {
175  $barcodelist[$filebis] = $module->info();
176  }
177  }
178  }
179  }
180  }
181  }
182 }
183 
184 /*
185  * CHOIX ENCODAGE
186  */
187 
188 print '<br>';
189 print load_fiche_titre($langs->trans("BarcodeEncodeModule"), '', '');
190 
191 if (empty($conf->use_javascript_ajax))
192 {
193  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="form_engine">';
194  print '<input type="hidden" name="token" value="'.newToken().'">';
195  print '<input type="hidden" name="action" value="updateengine">';
196 }
197 
198 print '<table class="noborder centpercent">';
199 print '<tr class="liste_titre">';
200 print '<td>'.$langs->trans("Name").'</td>';
201 print '<td>'.$langs->trans("Description").'</td>';
202 print '<td width="200" class="center">'.$langs->trans("Example").'</td>';
203 print '<td class="center" width="60">'.$langs->trans("CodeBarGenerator").'</td>';
204 print "</tr>\n";
205 
206 $sql = "SELECT rowid, code as encoding, libelle as label, coder, example";
207 $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
208 $sql .= " WHERE entity = ".$conf->entity;
209 $sql .= " ORDER BY code";
210 
211 dol_syslog("admin/barcode.php", LOG_DEBUG);
212 $resql = $db->query($sql);
213 if ($resql)
214 {
215  $num = $db->num_rows($resql);
216  $i = 0;
217 
218  while ($i < $num)
219  {
220  $obj = $db->fetch_object($resql);
221 
222  print '<tr class="oddeven"><td width="100">';
223  print $obj->label;
224  print "</td><td>\n";
225  print $langs->trans('BarcodeDesc'.$obj->encoding);
226  //print "L'EAN se compose de 8 caracteres, 7 chiffres plus une cle de controle.<br>";
227  //print "L'utilisation des symbologies EAN8 impose la souscription et l'abonnement aupres d'organisme tel que GENCOD.<br>";
228  //print "Codes numeriques utilises exclusivement a l'identification des produits susceptibles d'etre vendus au grand public.";
229  print '</td>';
230 
231  // Show example
232  print '<td class="center">';
233  if ($obj->coder && $obj->coder != -1)
234  {
235  $result = 0;
236 
237  foreach ($dirbarcode as $reldir)
238  {
239  $dir = dol_buildpath($reldir, 0);
240  $newdir = dol_osencode($dir);
241 
242  // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
243  if (!is_dir($newdir)) continue;
244 
245  $result = @include_once $newdir.$obj->coder.'.modules.php';
246  if ($result) break;
247  }
248  if ($result)
249  {
250  $classname = "mod".ucfirst($obj->coder);
251  if (class_exists($classname))
252  {
253  $module = new $classname($db);
254  if ($module->encodingIsSupported($obj->encoding))
255  {
256  // Build barcode on disk (not used, this is done to make debug easier)
257  $result = $module->writeBarCode($obj->example, $obj->encoding, 'Y');
258  // Generate on the fly and output barcode with generator
259  $url = DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&amp;generator='.urlencode($obj->coder).'&amp;code='.urlencode($obj->example).'&amp;encoding='.urlencode($obj->encoding);
260  //print $url;
261  print '<img src="'.$url.'" title="'.$obj->example.'" border="0">';
262  } else {
263  print $langs->trans("FormatNotSupportedByGenerator");
264  }
265  } else {
266  print 'ErrorClassNotFoundInModule '.$classname.' '.$obj->coder;
267  }
268  }
269  } else {
270  print $langs->trans("ChooseABarCode");
271  }
272  print '</td>';
273 
274  print '<td class="center">';
275  print $formbarcode->setBarcodeEncoder($obj->coder, $barcodelist, $obj->rowid, 'form'.$i);
276  print "</td></tr>\n";
277 
278  $i++;
279  }
280 }
281 print "</table>\n";
282 
283 if (empty($conf->use_javascript_ajax))
284 {
285  print '<div class="center"><input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'"></div>';
286  print '</form>';
287 }
288 
289 print "<br>";
290 
291 
292 /*
293  * Other options
294  */
295 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
296 
297 print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
298 print '<input type="hidden" name="token" value="'.newToken().'">';
299 print "<input type=\"hidden\" name=\"action\" value=\"update\">";
300 
301 print '<table class="noborder centpercent">';
302 print '<tr class="liste_titre">';
303 print '<td>'.$langs->trans("Parameter").'</td>';
304 print '<td width="60" class="center">'.$langs->trans("Value").'</td>';
305 print '<td>&nbsp;</td>';
306 print '</tr>';
307 
308 // Chemin du binaire genbarcode sous linux
309 if (!isset($_SERVER['WINDIR']))
310 {
311  print '<tr class="oddeven">';
312  print '<td>'.$langs->trans("GenbarcodeLocation").'</td>';
313  print '<td width="60" class="center">';
314  print '<input type="text" size="40" name="GENBARCODE_LOCATION" value="'.$conf->global->GENBARCODE_LOCATION.'">';
315  if (!empty($conf->global->GENBARCODE_LOCATION) && !@file_exists($conf->global->GENBARCODE_LOCATION))
316  {
317  $langs->load("errors");
318  print '<br><font class="error">'.$langs->trans("ErrorFileNotFound", $conf->global->GENBARCODE_LOCATION).'</font>';
319  }
320  print '</td></tr>';
321 }
322 
323 // Module products
324 if (!empty($conf->product->enabled))
325 {
326  print '<tr class="oddeven">';
327  print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
328  print '<td width="60" class="right">';
329  print $formbarcode->selectBarcodeType($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE, "PRODUIT_DEFAULT_BARCODE_TYPE", 1);
330  print '</td></tr>';
331 }
332 
333 // Module thirdparty
334 if (!empty($conf->societe->enabled))
335 {
336  print '<tr class="oddeven">';
337  print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
338  print '<td width="60" class="right">';
339  print $formbarcode->selectBarcodeType($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY, "GENBARCODE_BARCODETYPE_THIRDPARTY", 1);
340  print '</td></tr>';
341 }
342 
343 print "</table>\n";
344 print '<div class="tabsAction">';
345 print '<input type="submit" class="button" name="submit_GENBARCODE_BARCODETYPE_THIRDPARTY" value="'.$langs->trans("Modify").'">';
346 print "</div>";
347 print '</form>';
348 
349 print '<br>';
350 
351 
352 
353 // Select barcode numbering module
354 if ($conf->product->enabled)
355 {
356  print load_fiche_titre($langs->trans("BarCodeNumberManager")." (".$langs->trans("Product").")", '', '');
357 
358  print '<table class="noborder centpercent">';
359  print '<tr class="liste_titre">';
360  print '<td width="140">'.$langs->trans("Name").'</td>';
361  print '<td>'.$langs->trans("Description").'</td>';
362  print '<td>'.$langs->trans("Example").'</td>';
363  print '<td class="center" width="80">'.$langs->trans("Status").'</td>';
364  print '<td class="center" width="60">'.$langs->trans("ShortInfo").'</td>';
365  print "</tr>\n";
366 
367  $dirbarcodenum = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
368 
369  foreach ($dirbarcodenum as $dirroot)
370  {
371  $dir = dol_buildpath($dirroot, 0);
372 
373  $handle = @opendir($dir);
374  if (is_resource($handle))
375  {
376  while (($file = readdir($handle)) !== false)
377  {
378  if (preg_match('/^mod_barcode_product_.*php$/', $file))
379  {
380  $file = substr($file, 0, dol_strlen($file) - 4);
381 
382  try {
383  dol_include_once($dirroot.$file.'.php');
384  } catch (Exception $e)
385  {
386  dol_syslog($e->getMessage(), LOG_ERR);
387  }
388 
389  $modBarCode = new $file();
390 
391  print '<tr class="oddeven">';
392  print '<td>'.(isset($modBarCode->name) ? $modBarCode->name : $modBarCode->nom)."</td><td>\n";
393  print $modBarCode->info($langs);
394  print '</td>';
395  print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n";
396 
397  if ($conf->global->BARCODE_PRODUCT_ADDON_NUM == "$file")
398  {
399  print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproductoff&amp;token='.newToken().'&amp;value='.urlencode($file).'">';
400  print img_picto($langs->trans("Activated"), 'switch_on');
401  print '</a></td>';
402  } else {
403  print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproducton&amp;token='.newToken().'&amp;value='.urlencode($file).'">';
404  print img_picto($langs->trans("Disabled"), 'switch_off');
405  print '</a></td>';
406  }
407  print '<td class="center">';
408  $s = $modBarCode->getToolTip($langs, null, -1);
409  print $form->textwithpicto('', $s, 1);
410  print '</td>';
411  print "</tr>\n";
412  }
413  }
414  closedir($handle);
415  }
416  }
417  print "</table>\n";
418 }
419 
420 //print '</form>';
421 
422 print "<br>";
423 
424 // End of page
425 llxFooter();
426 $db->close();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:575
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:499
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage barcode HTML.
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
llxFooter()
Empty footer.
Definition: wrapper.php:59