barcode.php 17 KB

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