barcode.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. /**
  21. * \file htdocs/admin/barcode.php
  22. * \ingroup barcode
  23. * \brief Page to setup barcode module
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
  28. // Load translation files required by the page
  29. $langs->load("admin");
  30. if (!$user->admin) accessforbidden();
  31. $action = GETPOST('action','alpha');
  32. /*
  33. * Actions
  34. */
  35. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  36. if ($action == 'setbarcodeproducton')
  37. {
  38. $res=dolibarr_set_const($db, "BARCODE_PRODUCT_ADDON_NUM", GETPOST('value'), 'chaine', 0, '', $conf->entity);
  39. }
  40. elseif ($action == 'setbarcodeproductoff')
  41. {
  42. $res=dolibarr_del_const($db, "BARCODE_PRODUCT_ADDON_NUM", $conf->entity);
  43. }
  44. if ($action == 'setcoder')
  45. {
  46. $coder = GETPOST('coder','alpha');
  47. $code_id = GETPOST('code_id','alpha');
  48. $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
  49. $sqlp.= " SET coder = '" . $coder."'";
  50. $sqlp.= " WHERE rowid = ". $code_id;
  51. $sqlp.= " AND entity = ".$conf->entity;
  52. $resql=$db->query($sqlp);
  53. if (! $resql) dol_print_error($db);
  54. }
  55. elseif ($action == 'update')
  56. {
  57. $location = GETPOST('GENBARCODE_LOCATION','alpha');
  58. $res = dolibarr_set_const($db, "GENBARCODE_LOCATION",$location,'chaine',0,'',$conf->entity);
  59. $coder_id = GETPOST('PRODUIT_DEFAULT_BARCODE_TYPE','alpha');
  60. $res = dolibarr_set_const($db, "PRODUIT_DEFAULT_BARCODE_TYPE", $coder_id,'chaine',0,'',$conf->entity);
  61. $coder_id = GETPOST('GENBARCODE_BARCODETYPE_THIRDPARTY','alpha');
  62. $res = dolibarr_set_const($db, "GENBARCODE_BARCODETYPE_THIRDPARTY", $coder_id,'chaine',0,'',$conf->entity);
  63. if ($res > 0)
  64. {
  65. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  66. }
  67. else
  68. {
  69. setEventMessages($langs->trans("Error"), null, 'errors');
  70. }
  71. }
  72. elseif ($action == 'updateengine')
  73. {
  74. $sql = "SELECT rowid, coder";
  75. $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
  76. $sql.= " WHERE entity = ".$conf->entity;
  77. $sql.= " ORDER BY code";
  78. $resql=$db->query($sql);
  79. if ($resql)
  80. {
  81. $num = $db->num_rows($resql);
  82. $i = 0;
  83. while ($i < $num)
  84. {
  85. $obj = $db->fetch_object($resql);
  86. if (GETPOST('coder'.$obj->rowid, 'alpha'))
  87. {
  88. $coder = GETPOST('coder'.$obj->rowid,'alpha');
  89. $code_id = $obj->rowid;
  90. $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
  91. $sqlp.= " SET coder = '" . $coder."'";
  92. $sqlp.= " WHERE rowid = ". $code_id;
  93. $sqlp.= " AND entity = ".$conf->entity;
  94. $upsql=$db->query($sqlp);
  95. if (! $upsql) dol_print_error($db);
  96. }
  97. $i++;
  98. }
  99. }
  100. }
  101. /*
  102. * View
  103. */
  104. $form = new Form($db);
  105. $formbarcode = new FormBarCode($db);
  106. $help_url='EN:Module_Barcode|FR:Module_Codes_Barre|ES:Módulo Código de barra';
  107. llxHeader('',$langs->trans("BarcodeSetup"),$help_url);
  108. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  109. print load_fiche_titre($langs->trans("BarcodeSetup"),$linkback,'title_setup');
  110. // Detect bar codes modules
  111. $barcodelist=array();
  112. clearstatcache();
  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. foreach($dirbarcode as $reldir)
  116. {
  117. $dir=dol_buildpath($reldir);
  118. $newdir=dol_osencode($dir);
  119. // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
  120. if (! is_dir($newdir)) continue;
  121. $handle=@opendir($newdir);
  122. if (is_resource($handle))
  123. {
  124. while (($file = readdir($handle))!==false)
  125. {
  126. if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
  127. {
  128. if (is_readable($newdir.$file))
  129. {
  130. if (preg_match('/(.*)\.modules\.php$/i',$file,$reg))
  131. {
  132. $filebis=$reg[1];
  133. // Loading encoding class
  134. require_once $newdir.$file;
  135. $classname = "mod".ucfirst($filebis);
  136. $module = new $classname($db);
  137. // Show modules according to features level
  138. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  139. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  140. if ($module->isEnabled())
  141. {
  142. $barcodelist[$filebis]=$module->info();
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. /*
  151. * CHOIX ENCODAGE
  152. */
  153. print '<br>';
  154. print load_fiche_titre($langs->trans("BarcodeEncodeModule"),'','');
  155. if (empty($conf->use_javascript_ajax))
  156. {
  157. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="form_engine">';
  158. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  159. print '<input type="hidden" name="action" value="updateengine">';
  160. }
  161. print '<table class="noborder" width="100%">';
  162. print '<tr class="liste_titre">';
  163. print '<td>'.$langs->trans("Name").'</td>';
  164. print '<td>'.$langs->trans("Description").'</td>';
  165. print '<td width="200" align="center">'.$langs->trans("Example").'</td>';
  166. print '<td align="center" width="60">'.$langs->trans("CodeBarGenerator").'</td>';
  167. print "</tr>\n";
  168. $sql = "SELECT rowid, code as encoding, libelle, coder, example";
  169. $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
  170. $sql.= " WHERE entity = ".$conf->entity;
  171. $sql.= " ORDER BY code";
  172. dol_syslog("admin/barcode.php", LOG_DEBUG);
  173. $resql=$db->query($sql);
  174. if ($resql)
  175. {
  176. $num = $db->num_rows($resql);
  177. $i = 0;
  178. while ($i < $num)
  179. {
  180. $obj = $db->fetch_object($resql);
  181. print '<tr class="oddeven"><td width="100">';
  182. print $obj->libelle;
  183. print "</td><td>\n";
  184. print $langs->trans('BarcodeDesc'.$obj->encoding);
  185. //print "L'EAN se compose de 8 caracteres, 7 chiffres plus une cle de controle.<br>";
  186. //print "L'utilisation des symbologies EAN8 impose la souscription et l'abonnement aupres d'organisme tel que GENCOD.<br>";
  187. //print "Codes numeriques utilises exclusivement a l'identification des produits susceptibles d'etre vendus au grand public.";
  188. print '</td>';
  189. // Show example
  190. print '<td align="center">';
  191. if ($obj->coder && $obj->coder != -1)
  192. {
  193. $result=0;
  194. foreach($dirbarcode as $reldir)
  195. {
  196. $dir=dol_buildpath($reldir,0);
  197. $newdir=dol_osencode($dir);
  198. // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
  199. if (! is_dir($newdir)) continue;
  200. $result=@include_once $newdir.$obj->coder.'.modules.php';
  201. if ($result) break;
  202. }
  203. if ($result)
  204. {
  205. $classname = "mod".ucfirst($obj->coder);
  206. if (class_exists($classname))
  207. {
  208. $module = new $classname($db);
  209. if ($module->encodingIsSupported($obj->encoding))
  210. {
  211. // Build barcode on disk (not used, this is done to make debug easier)
  212. $result=$module->writeBarCode($obj->example,$obj->encoding,'Y');
  213. // Generate on the fly and output barcode with generator
  214. $url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&amp;generator='.urlencode($obj->coder).'&amp;code='.urlencode($obj->example).'&amp;encoding='.urlencode($obj->encoding);
  215. //print $url;
  216. print '<img src="'.$url.'" title="'.$obj->example.'" border="0">';
  217. }
  218. else
  219. {
  220. print $langs->trans("FormatNotSupportedByGenerator");
  221. }
  222. }
  223. else
  224. {
  225. print 'ErrorClassNotFoundInModule '.$classname.' '.$obj->coder;
  226. }
  227. }
  228. }
  229. else
  230. {
  231. print $langs->trans("ChooseABarCode");
  232. }
  233. print '</td>';
  234. print '<td align="center">';
  235. print $formbarcode->setBarcodeEncoder($obj->coder,$barcodelist,$obj->rowid,'form'.$i);
  236. print "</td></tr>\n";
  237. $i++;
  238. }
  239. }
  240. print "</table>\n";
  241. if (empty($conf->use_javascript_ajax))
  242. {
  243. print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'"></div>';
  244. print '</form>';
  245. }
  246. print "<br>";
  247. /*
  248. * Other options
  249. */
  250. print load_fiche_titre($langs->trans("OtherOptions"),'','');
  251. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  252. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  253. print "<input type=\"hidden\" name=\"action\" value=\"update\">";
  254. print '<table class="noborder" width="100%">';
  255. print '<tr class="liste_titre">';
  256. print '<td>'.$langs->trans("Parameter").'</td>';
  257. print '<td width="60" align="center">'.$langs->trans("Value").'</td>';
  258. print '<td>&nbsp;</td>';
  259. print '</tr>';
  260. // Chemin du binaire genbarcode sous linux
  261. if (! isset($_SERVER['WINDIR']))
  262. {
  263. print '<tr class="oddeven">';
  264. print '<td>'.$langs->trans("GenbarcodeLocation").'</td>';
  265. print '<td width="60" align="center">';
  266. print '<input type="text" size="40" name="GENBARCODE_LOCATION" value="'.$conf->global->GENBARCODE_LOCATION.'">';
  267. if (! empty($conf->global->GENBARCODE_LOCATION) && ! @file_exists($conf->global->GENBARCODE_LOCATION))
  268. {
  269. $langs->load("errors");
  270. print '<br><font class="error">'.$langs->trans("ErrorFileNotFound",$conf->global->GENBARCODE_LOCATION).'</font>';
  271. }
  272. print '</td></tr>';
  273. }
  274. // Module products
  275. if (! empty($conf->product->enabled))
  276. {
  277. print '<tr class="oddeven">';
  278. print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
  279. print '<td width="60" align="right">';
  280. print $formbarcode->selectBarcodeType($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE, "PRODUIT_DEFAULT_BARCODE_TYPE", 1);
  281. print '</td></tr>';
  282. }
  283. // Module thirdparty
  284. if (! empty($conf->societe->enabled))
  285. {
  286. print '<tr class="oddeven">';
  287. print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
  288. print '<td width="60" align="right">';
  289. print $formbarcode->selectBarcodeType($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY, "GENBARCODE_BARCODETYPE_THIRDPARTY", 1);
  290. print '</td></tr>';
  291. }
  292. print "</table>\n";
  293. print '<div class="tabsAction">';
  294. print '<input type="submit" class="button" name="submit_GENBARCODE_BARCODETYPE_THIRDPARTY" value="'.$langs->trans("Modify").'">';
  295. print "</div>";
  296. print '</form>';
  297. print '<br>';
  298. // Select barcode numbering module
  299. if ($conf->produit->enabled)
  300. {
  301. print load_fiche_titre($langs->trans("BarCodeNumberManager")." (".$langs->trans("Product").")",'','');
  302. print '<table class="noborder" width="100%">';
  303. print '<tr class="liste_titre">';
  304. print '<td width="140">'.$langs->trans("Name").'</td>';
  305. print '<td>'.$langs->trans("Description").'</td>';
  306. print '<td>'.$langs->trans("Example").'</td>';
  307. print '<td align="center" width="80">'.$langs->trans("Status").'</td>';
  308. print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
  309. print "</tr>\n";
  310. $dirbarcodenum=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
  311. foreach ($dirbarcodenum as $dirroot)
  312. {
  313. $dir = dol_buildpath($dirroot,0);
  314. $handle = @opendir($dir);
  315. if (is_resource($handle))
  316. {
  317. while (($file = readdir($handle))!==false)
  318. {
  319. if (preg_match('/^mod_barcode_product_.*php$/', $file))
  320. {
  321. $file = substr($file, 0, dol_strlen($file)-4);
  322. try {
  323. dol_include_once($dirroot.$file.'.php');
  324. }
  325. catch(Exception $e)
  326. {
  327. dol_syslog($e->getMessage(), LOG_ERR);
  328. }
  329. $modBarCode = new $file();
  330. print '<tr class="oddeven">';
  331. print '<td>'.(isset($modBarCode->name)?$modBarCode->name:$modBarCode->nom)."</td><td>\n";
  332. print $modBarCode->info($langs);
  333. print '</td>';
  334. print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n";
  335. if ($conf->global->BARCODE_PRODUCT_ADDON_NUM == "$file")
  336. {
  337. print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproductoff&amp;value='.$file.'">';
  338. print img_picto($langs->trans("Activated"),'switch_on');
  339. print '</a></td>';
  340. }
  341. else
  342. {
  343. print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproducton&amp;value='.$file.'">';
  344. print img_picto($langs->trans("Disabled"),'switch_off');
  345. print '</a></td>';
  346. }
  347. print '<td align="center">';
  348. $s=$modBarCode->getToolTip($langs,null,-1);
  349. print $form->textwithpicto('',$s,1);
  350. print '</td>';
  351. print "</tr>\n";
  352. }
  353. }
  354. closedir($handle);
  355. }
  356. }
  357. print "</table>\n";
  358. }
  359. //print '</form>';
  360. print "<br>";
  361. // End of page
  362. llxFooter();
  363. $db->close();