dolibarr  9.0.0
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 <http://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','alpha');
37 
38 
39 /*
40  * Actions
41  */
42 
43 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
44 
45 if ($action == 'setbarcodeproducton')
46 {
47  $res=dolibarr_set_const($db, "BARCODE_PRODUCT_ADDON_NUM", GETPOST('value'), 'chaine', 0, '', $conf->entity);
48 }
49 elseif ($action == 'setbarcodeproductoff')
50 {
51  $res=dolibarr_del_const($db, "BARCODE_PRODUCT_ADDON_NUM", $conf->entity);
52 }
53 
54 if ($action == 'setcoder')
55 {
56  $coder = GETPOST('coder','alpha');
57  $code_id = GETPOST('code_id','alpha');
58  $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
59  $sqlp.= " SET coder = '" . $coder."'";
60  $sqlp.= " WHERE rowid = ". $code_id;
61  $sqlp.= " AND entity = ".$conf->entity;
62 
63  $resql=$db->query($sqlp);
64  if (! $resql) dol_print_error($db);
65 }
66 elseif ($action == 'update')
67 {
68  $location = GETPOST('GENBARCODE_LOCATION','alpha');
69  $res = dolibarr_set_const($db, "GENBARCODE_LOCATION",$location,'chaine',0,'',$conf->entity);
70  $coder_id = GETPOST('PRODUIT_DEFAULT_BARCODE_TYPE','alpha');
71  $res = dolibarr_set_const($db, "PRODUIT_DEFAULT_BARCODE_TYPE", $coder_id,'chaine',0,'',$conf->entity);
72  $coder_id = GETPOST('GENBARCODE_BARCODETYPE_THIRDPARTY','alpha');
73  $res = dolibarr_set_const($db, "GENBARCODE_BARCODETYPE_THIRDPARTY", $coder_id,'chaine',0,'',$conf->entity);
74 
75  if ($res > 0)
76  {
77  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
78  }
79  else
80  {
81  setEventMessages($langs->trans("Error"), null, 'errors');
82  }
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 = '" . $coder."'";
108  $sqlp.= " WHERE rowid = ". $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="'.$_SESSION['newtoken'].'">';
195  print '<input type="hidden" name="action" value="updateengine">';
196 }
197 
198 print '<table class="noborder" width="100%">';
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" align="center">'.$langs->trans("Example").'</td>';
203 print '<td align="center" width="60">'.$langs->trans("CodeBarGenerator").'</td>';
204 print "</tr>\n";
205 
206 $sql = "SELECT rowid, code as encoding, libelle, 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->libelle;
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 align="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  }
263  else
264  {
265  print $langs->trans("FormatNotSupportedByGenerator");
266  }
267  }
268  else
269  {
270  print 'ErrorClassNotFoundInModule '.$classname.' '.$obj->coder;
271  }
272  }
273  }
274  else
275  {
276  print $langs->trans("ChooseABarCode");
277  }
278  print '</td>';
279 
280  print '<td align="center">';
281  print $formbarcode->setBarcodeEncoder($obj->coder,$barcodelist,$obj->rowid,'form'.$i);
282  print "</td></tr>\n";
283 
284  $i++;
285  }
286 }
287 print "</table>\n";
288 
289 if (empty($conf->use_javascript_ajax))
290 {
291  print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'"></div>';
292  print '</form>';
293 }
294 
295 print "<br>";
296 
297 
298 /*
299  * Other options
300  */
301 print load_fiche_titre($langs->trans("OtherOptions"),'','');
302 
303 print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
304 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
305 print "<input type=\"hidden\" name=\"action\" value=\"update\">";
306 
307 print '<table class="noborder" width="100%">';
308 print '<tr class="liste_titre">';
309 print '<td>'.$langs->trans("Parameter").'</td>';
310 print '<td width="60" align="center">'.$langs->trans("Value").'</td>';
311 print '<td>&nbsp;</td>';
312 print '</tr>';
313 
314 // Chemin du binaire genbarcode sous linux
315 if (! isset($_SERVER['WINDIR']))
316 {
317 
318  print '<tr class="oddeven">';
319  print '<td>'.$langs->trans("GenbarcodeLocation").'</td>';
320  print '<td width="60" align="center">';
321  print '<input type="text" size="40" name="GENBARCODE_LOCATION" value="'.$conf->global->GENBARCODE_LOCATION.'">';
322  if (! empty($conf->global->GENBARCODE_LOCATION) && ! @file_exists($conf->global->GENBARCODE_LOCATION))
323  {
324  $langs->load("errors");
325  print '<br><font class="error">'.$langs->trans("ErrorFileNotFound",$conf->global->GENBARCODE_LOCATION).'</font>';
326  }
327  print '</td></tr>';
328 }
329 
330 // Module products
331 if (! empty($conf->product->enabled))
332 {
333 
334  print '<tr class="oddeven">';
335  print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
336  print '<td width="60" align="right">';
337  print $formbarcode->selectBarcodeType($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE, "PRODUIT_DEFAULT_BARCODE_TYPE", 1);
338  print '</td></tr>';
339 }
340 
341 // Module thirdparty
342 if (! empty($conf->societe->enabled))
343 {
344 
345  print '<tr class="oddeven">';
346  print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
347  print '<td width="60" align="right">';
348  print $formbarcode->selectBarcodeType($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY, "GENBARCODE_BARCODETYPE_THIRDPARTY", 1);
349  print '</td></tr>';
350 }
351 
352 print "</table>\n";
353 print '<div class="tabsAction">';
354 print '<input type="submit" class="button" name="submit_GENBARCODE_BARCODETYPE_THIRDPARTY" value="'.$langs->trans("Modify").'">';
355 print "</div>";
356 print '</form>';
357 
358 print '<br>';
359 
360 
361 
362 // Select barcode numbering module
363 if ($conf->produit->enabled)
364 {
365  print load_fiche_titre($langs->trans("BarCodeNumberManager")." (".$langs->trans("Product").")",'','');
366 
367  print '<table class="noborder" width="100%">';
368  print '<tr class="liste_titre">';
369  print '<td width="140">'.$langs->trans("Name").'</td>';
370  print '<td>'.$langs->trans("Description").'</td>';
371  print '<td>'.$langs->trans("Example").'</td>';
372  print '<td align="center" width="80">'.$langs->trans("Status").'</td>';
373  print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
374  print "</tr>\n";
375 
376  $dirbarcodenum=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
377 
378  foreach ($dirbarcodenum as $dirroot)
379  {
380  $dir = dol_buildpath($dirroot,0);
381 
382  $handle = @opendir($dir);
383  if (is_resource($handle))
384  {
385  while (($file = readdir($handle))!==false)
386  {
387  if (preg_match('/^mod_barcode_product_.*php$/', $file))
388  {
389  $file = substr($file, 0, dol_strlen($file)-4);
390 
391  try {
392  dol_include_once($dirroot.$file.'.php');
393  }
394  catch(Exception $e)
395  {
396  dol_syslog($e->getMessage(), LOG_ERR);
397  }
398 
399  $modBarCode = new $file();
400 
401  print '<tr class="oddeven">';
402  print '<td>'.(isset($modBarCode->name)?$modBarCode->name:$modBarCode->nom)."</td><td>\n";
403  print $modBarCode->info($langs);
404  print '</td>';
405  print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n";
406 
407  if ($conf->global->BARCODE_PRODUCT_ADDON_NUM == "$file")
408  {
409  print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproductoff&amp;value='.$file.'">';
410  print img_picto($langs->trans("Activated"),'switch_on');
411  print '</a></td>';
412  }
413  else
414  {
415  print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproducton&amp;value='.$file.'">';
416  print img_picto($langs->trans("Disabled"),'switch_off');
417  print '</a></td>';
418  }
419  print '<td align="center">';
420  $s=$modBarCode->getToolTip($langs,null,-1);
421  print $form->textwithpicto('',$s,1);
422  print '</td>';
423  print "</tr>\n";
424  }
425  }
426  closedir($handle);
427  }
428  }
429  print "</table>\n";
430 }
431 
432 //print '</form>';
433 
434 print "<br>";
435 
436 // End of page
437 llxFooter();
438 $db->close();
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
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:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
if(! function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to manage barcode HTML.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.