barcode.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. /**
  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. $langs->load("admin");
  29. if (!$user->admin) accessforbidden();
  30. $action = GETPOST('action','alpha');
  31. /*
  32. * Actions
  33. */
  34. if ($action == 'setbarcodeproducton')
  35. {
  36. $res=dolibarr_set_const($db, "BARCODE_PRODUCT_ADDON_NUM", GETPOST('value'), 'chaine', 0, '', $conf->entity);
  37. }
  38. elseif ($action == 'setbarcodeproductoff')
  39. {
  40. $res=dolibarr_del_const($db, "BARCODE_PRODUCT_ADDON_NUM", $conf->entity);
  41. }
  42. if ($action == 'setcoder')
  43. {
  44. $coder = GETPOST('coder','alpha');
  45. $code_id = GETPOST('code_id','alpha');
  46. $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
  47. $sqlp.= " SET coder = '" . $coder."'";
  48. $sqlp.= " WHERE rowid = ". $code_id;
  49. $sqlp.= " AND entity = ".$conf->entity;
  50. $resql=$db->query($sqlp);
  51. if (! $resql) dol_print_error($db);
  52. }
  53. else if ($action == 'update')
  54. {
  55. $location = GETPOST('GENBARCODE_LOCATION','alpha');
  56. $res = dolibarr_set_const($db, "GENBARCODE_LOCATION",$location,'chaine',0,'',$conf->entity);
  57. $coder_id = GETPOST('PRODUIT_DEFAULT_BARCODE_TYPE','alpha');
  58. $res = dolibarr_set_const($db, "PRODUIT_DEFAULT_BARCODE_TYPE", $coder_id,'chaine',0,'',$conf->entity);
  59. $coder_id = GETPOST('GENBARCODE_BARCODETYPE_THIRDPARTY','alpha');
  60. $res = dolibarr_set_const($db, "GENBARCODE_BARCODETYPE_THIRDPARTY", $coder_id,'chaine',0,'',$conf->entity);
  61. }
  62. else if ($action == 'updateengine')
  63. {
  64. // TODO Update engines.
  65. }
  66. // define constants for models generator that need parameters
  67. if ($action == 'setModuleOptions')
  68. {
  69. $post_size=count($_POST);
  70. for($i=0;$i < $post_size;$i++)
  71. {
  72. if (array_key_exists('param'.$i,$_POST))
  73. {
  74. $param=GETPOST("param".$i,'alpha');
  75. $value=GETPOST("value".$i,'alpha');
  76. if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
  77. }
  78. }
  79. if (! $res > 0) $error++;
  80. if (! $error)
  81. {
  82. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  83. }
  84. else
  85. {
  86. setEventMessages($langs->trans("Error"), null, 'errors');
  87. }
  88. }
  89. if ($action && $action != 'setcoder' && $action != 'setModuleOptions')
  90. {
  91. if (! $res > 0) $error++;
  92. if (! $error)
  93. {
  94. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  95. }
  96. else
  97. {
  98. setEventMessages($langs->trans("Error"), null, 'errors');
  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">'.$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. $var=true;
  154. print '<br>';
  155. print load_fiche_titre($langs->trans("BarcodeEncodeModule"),'','');
  156. //print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  157. //print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  158. //print "<input type=\"hidden\" name=\"action\" value=\"updateengine\">";
  159. print '<table class="noborder" width="100%">';
  160. print '<tr class="liste_titre">';
  161. print '<td>'.$langs->trans("Name").'</td>';
  162. print '<td>'.$langs->trans("Description").'</td>';
  163. print '<td width="200" align="center">'.$langs->trans("Example").'</td>';
  164. print '<td align="center" width="60">'.$langs->trans("CodeBarGenerator").'</td>';
  165. print "</tr>\n";
  166. $sql = "SELECT rowid, code as encoding, libelle, coder, example";
  167. $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
  168. $sql.= " WHERE entity = ".$conf->entity;
  169. $sql.= " ORDER BY code";
  170. dol_syslog("admin/barcode.php", LOG_DEBUG);
  171. $resql=$db->query($sql);
  172. if ($resql)
  173. {
  174. $num = $db->num_rows($resql);
  175. $i = 0;
  176. $var=true;
  177. while ($i < $num)
  178. {
  179. $obj = $db->fetch_object($resql);
  180. print '<tr class="oddeven"><td width="100">';
  181. print $obj->libelle;
  182. print "</td><td>\n";
  183. print $langs->trans('BarcodeDesc'.$obj->encoding);
  184. //print "L'EAN se compose de 8 caracteres, 7 chiffres plus une cle de controle.<br>";
  185. //print "L'utilisation des symbologies EAN8 impose la souscription et l'abonnement aupres d'organisme tel que GENCOD.<br>";
  186. //print "Codes numeriques utilises exclusivement a l'identification des produits susceptibles d'etre vendus au grand public.";
  187. print '</td>';
  188. // Show example
  189. print '<td align="center">';
  190. if ($obj->coder && $obj->coder != -1)
  191. {
  192. $result=0;
  193. foreach($dirbarcode as $reldir)
  194. {
  195. $dir=dol_buildpath($reldir,0);
  196. $newdir=dol_osencode($dir);
  197. // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
  198. if (! is_dir($newdir)) continue;
  199. $result=@include_once $newdir.$obj->coder.'.modules.php';
  200. if ($result) break;
  201. }
  202. if ($result)
  203. {
  204. $classname = "mod".ucfirst($obj->coder);
  205. if (class_exists($classname))
  206. {
  207. $module = new $classname($db);
  208. if ($module->encodingIsSupported($obj->encoding))
  209. {
  210. // Build barcode on disk (not used, this is done to make debug easier)
  211. $result=$module->writeBarCode($obj->example,$obj->encoding,'Y');
  212. // Generate on the fly and output barcode with generator
  213. $url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&amp;generator='.urlencode($obj->coder).'&amp;code='.urlencode($obj->example).'&amp;encoding='.urlencode($obj->encoding);
  214. //print $url;
  215. print '<img src="'.$url.'" title="'.$obj->example.'" border="0">';
  216. }
  217. else
  218. {
  219. print $langs->trans("FormatNotSupportedByGenerator");
  220. }
  221. }
  222. else
  223. {
  224. print 'ErrorClassNotFoundInModule '.$classname.' '.$obj->coder;
  225. }
  226. }
  227. }
  228. else
  229. {
  230. print $langs->trans("ChooseABarCode");
  231. }
  232. print '</td>';
  233. print '<td align="center">';
  234. print $formbarcode->setBarcodeEncoder($obj->coder,$barcodelist,$obj->rowid,'form'.$i);
  235. print "</td></tr>\n";
  236. $i++;
  237. }
  238. }
  239. print "</table>\n";
  240. if (empty($conf->use_javascript_ajax))
  241. {
  242. // TODO Implement code behind action updateengine
  243. //print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'"></div>';
  244. }
  245. //print '</form>';
  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. $var=true;
  255. print '<table class="noborder" width="100%">';
  256. print '<tr class="liste_titre">';
  257. print '<td>'.$langs->trans("Parameter").'</td>';
  258. print '<td width="60" align="center">'.$langs->trans("Value").'</td>';
  259. print '<td>&nbsp;</td>';
  260. print '</tr>';
  261. // Chemin du binaire genbarcode sous linux
  262. if (! isset($_SERVER['WINDIR']))
  263. {
  264. print '<tr class="oddeven">';
  265. print '<td>'.$langs->trans("GenbarcodeLocation").'</td>';
  266. print '<td width="60" align="center">';
  267. print '<input type="text" size="40" name="GENBARCODE_LOCATION" value="'.$conf->global->GENBARCODE_LOCATION.'">';
  268. if (! empty($conf->global->GENBARCODE_LOCATION) && ! @file_exists($conf->global->GENBARCODE_LOCATION))
  269. {
  270. $langs->load("errors");
  271. print '<br><font class="error">'.$langs->trans("ErrorFileNotFound",$conf->global->GENBARCODE_LOCATION).'</font>';
  272. }
  273. print '</td></tr>';
  274. }
  275. // Module products
  276. if (! empty($conf->product->enabled))
  277. {
  278. print '<tr class="oddeven">';
  279. print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
  280. print '<td width="60" align="right">';
  281. $formbarcode->select_barcode_type($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE,"PRODUIT_DEFAULT_BARCODE_TYPE",1);
  282. print '</td></tr>';
  283. }
  284. // Module thirdparty
  285. if (! empty($conf->societe->enabled))
  286. {
  287. print '<tr class="oddeven">';
  288. print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
  289. print '<td width="60" align="right">';
  290. print $formbarcode->select_barcode_type($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY,"GENBARCODE_BARCODETYPE_THIRDPARTY",1);
  291. print '</td></tr>';
  292. }
  293. print "</table>\n";
  294. print '<div class="tabsAction">';
  295. print '<input type="submit" class="button" name="submit_GENBARCODE_BARCODETYPE_THIRDPARTY" value="'.$langs->trans("Modify").'">';
  296. print "</div>";
  297. print '</form>';
  298. print '<br>';
  299. // Select barcode numbering module
  300. if ($conf->produit->enabled)
  301. {
  302. print load_fiche_titre($langs->trans("BarCodeNumberManager")." (".$langs->trans("Product").")",'','');
  303. print '<table class="noborder" width="100%">';
  304. print '<tr class="liste_titre">';
  305. print '<td width="140">'.$langs->trans("Name").'</td>';
  306. print '<td>'.$langs->trans("Description").'</td>';
  307. print '<td>'.$langs->trans("Example").'</td>';
  308. print '<td align="center" width="80">'.$langs->trans("Status").'</td>';
  309. print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
  310. print "</tr>\n";
  311. $dirbarcodenum=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
  312. foreach ($dirbarcodenum as $dirroot)
  313. {
  314. $dir = dol_buildpath($dirroot,0);
  315. $handle = @opendir($dir);
  316. if (is_resource($handle))
  317. {
  318. while (($file = readdir($handle))!==false)
  319. {
  320. if (preg_match('/^mod_barcode_product_.*php$/', $file))
  321. {
  322. $file = substr($file, 0, dol_strlen($file)-4);
  323. try {
  324. dol_include_once($dirroot.$file.'.php');
  325. }
  326. catch(Exception $e)
  327. {
  328. dol_syslog($e->getMessage(), LOG_ERR);
  329. }
  330. $modBarCode = new $file();
  331. $var = !$var;
  332. print '<tr class="oddeven">';
  333. print '<td>'.(isset($modBarCode->name)?$modBarCode->name:$modBarCode->nom)."</td><td>\n";
  334. print $modBarCode->info($langs);
  335. print '</td>';
  336. print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n";
  337. if ($conf->global->BARCODE_PRODUCT_ADDON_NUM == "$file")
  338. {
  339. print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproductoff&amp;value='.$file.'">';
  340. print img_picto($langs->trans("Activated"),'switch_on');
  341. print '</a></td>';
  342. }
  343. else
  344. {
  345. print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproducton&amp;value='.$file.'">';
  346. print img_picto($langs->trans("Disabled"),'switch_off');
  347. print '</a></td>';
  348. }
  349. print '<td align="center">';
  350. $s=$modBarCode->getToolTip($langs,null,-1);
  351. print $form->textwithpicto('',$s,1);
  352. print '</td>';
  353. print "</tr>\n";
  354. }
  355. }
  356. closedir($handle);
  357. }
  358. }
  359. print "</table>\n";
  360. }
  361. //print '</form>';
  362. print "<br>";
  363. llxFooter();
  364. $db->close();