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