barcode.php 14 KB

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