barcode.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/includes/modules/barcode/admin/barcode.php
  21. * \ingroup barcode
  22. * \brief Page d'administration/configuration du module Code barre
  23. */
  24. require("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT."/includes/barcode/html.formbarcode.class.php");
  27. $langs->load("admin");
  28. if (!$user->admin)
  29. accessforbidden();
  30. if ($_POST["action"] == 'setcoder')
  31. {
  32. $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
  33. $sqlp.= " SET coder = '" . $_POST["coder"]."'";
  34. $sqlp.= " WHERE rowid = ". $_POST["code_id"];
  35. $sqlp.= " AND entity = ".$conf->entity;
  36. $resql=$db->query($sqlp);
  37. //print $sqlp;
  38. }
  39. else if ($_POST["action"] == 'setgenbarcodelocation')
  40. {
  41. dolibarr_set_const($db, "GENBARCODE_LOCATION",$_POST["genbarcodelocation"],'chaine',0,'',$conf->entity);
  42. }
  43. else if ($_POST["action"] == 'setdefaultbarcodetype')
  44. {
  45. dolibarr_set_const($db, "PRODUIT_DEFAULT_BARCODE_TYPE", $_POST["coder_id"],'chaine',0,'',$conf->entity);
  46. }
  47. else if ($_POST["action"] == 'GENBARCODE_BARCODETYPE_THIRDPARTY')
  48. {
  49. dolibarr_set_const($db, "GENBARCODE_BARCODETYPE_THIRDPARTY", $_POST["coder_id"],'chaine',0,'',$conf->entity);
  50. }
  51. /*
  52. else if ($_POST["action"] == 'setproductusebarcode')
  53. {
  54. dolibarr_set_const($db, "PRODUIT_USE_BARCODE",$_POST["value"],'chaine',0,'',$conf->entity);
  55. Header("Location: barcode.php");
  56. exit;
  57. }
  58. */
  59. /*
  60. * Actions
  61. */
  62. $html = new Form($db);
  63. $formbarcode = new FormBarCode($db);
  64. llxHeader('',$langs->trans("BarcodeSetup"),'BarcodeConfiguration');
  65. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  66. print_fiche_titre($langs->trans("BarcodeSetup"),$linkback,'setup');
  67. // Detect bar codes modules
  68. $barcodelist=array();
  69. clearstatcache();
  70. foreach ($conf->file->dol_document_root as $dirroot)
  71. {
  72. $dir = $dirroot . "/includes/modules/barcode/";
  73. $handle=@opendir($dir);
  74. if (is_resource($handle))
  75. {
  76. while (($file = readdir($handle))!==false)
  77. {
  78. if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
  79. {
  80. if (is_readable($dir.$file))
  81. {
  82. if (preg_match('/(.*)\.modules\.php$/i',$file,$reg))
  83. {
  84. $filebis=$reg[1];
  85. // Chargement de la classe de codage
  86. require_once($dir.$file);
  87. $classname = "mod".ucfirst($filebis);
  88. $module = new $classname($db);
  89. // Show modules according to features level
  90. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  91. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  92. if ($module->isEnabled())
  93. {
  94. $barcodelist[$filebis]=$module->info();
  95. }
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }
  102. /*
  103. * CHOIX ENCODAGE
  104. */
  105. $var=true;
  106. print '<br>';
  107. print_titre($langs->trans("BarcodeEncodeModule"));
  108. print '<table class="noborder" width="100%">';
  109. print '<tr class="liste_titre">';
  110. print '<td>'.$langs->trans("Name").'</td>';
  111. print '<td>'.$langs->trans("Description").'</td>';
  112. print '<td width="200" align="center">'.$langs->trans("Example").'</td>';
  113. print '<td align="center" width="60">'.$langs->trans("CodeBarGenerator").'</td>';
  114. print "</tr>\n";
  115. $sql = "SELECT rowid, code as encoding, libelle, coder, example";
  116. $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
  117. $sql.= " WHERE entity = ".$conf->entity;
  118. $sql.= " ORDER BY code";
  119. dol_syslog("admin/barcode.php sql=".$sql);
  120. $resql=$db->query($sql);
  121. if ($resql)
  122. {
  123. $num = $db->num_rows($resql);
  124. $i = 0;
  125. $var=true;
  126. while ($i < $num)
  127. {
  128. $obj = $db->fetch_object($resql);
  129. print '<tr '.$bc[$var].'><td width="100">';
  130. print $obj->libelle;
  131. print "</td><td>\n";
  132. print $langs->trans('BarcodeDesc'.$obj->encoding);
  133. //print "L'EAN se compose de 8 caracteres, 7 chiffres plus une cle de controle.<br>";
  134. //print "L'utilisation des symbologies EAN8 impose la souscription et l'abonnement aupres d'organisme tel que GENCOD.<br>";
  135. //print "Codes numeriques utilises exclusivement a l'identification des produits susceptibles d'etre vendus au grand public.";
  136. print '</td>';
  137. // Show example
  138. print '<td align="center">';
  139. if ($obj->coder && $obj->coder != -1)
  140. {
  141. $result=0;
  142. // Chargement de la classe de codage
  143. foreach ($conf->file->dol_document_root as $dirroot)
  144. {
  145. $dir=$dirroot . "/includes/modules/barcode/";
  146. $result=@include_once($dir.$obj->coder.".modules.php");
  147. //print $dir.$obj->coder.".modules.php - ".$result;
  148. if ($result) break;
  149. }
  150. if ($result)
  151. {
  152. $classname = "mod".ucfirst($obj->coder);
  153. if (class_exists($classname))
  154. {
  155. $module = new $classname($db);
  156. if ($module->encodingIsSupported($obj->encoding))
  157. {
  158. // Build barcode on disk (not used, this is done to make debug easier)
  159. $result=$module->writeBarCode($obj->example,$obj->encoding,'Y');
  160. // Generate on the fly and output barcode with generator
  161. $url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($obj->coder).'&code='.urlencode($obj->example).'&encoding='.urlencode($obj->encoding);
  162. //print $url;
  163. print '<img src="'.$url.'" title="'.$obj->example.'" border="0">';
  164. }
  165. else
  166. {
  167. print $langs->trans("FormatNotSupportedByGenerator");
  168. }
  169. }
  170. else
  171. {
  172. print 'ErrorClassNotFoundInModule '.$classname.' '.$obj->coder;
  173. }
  174. }
  175. }
  176. else
  177. {
  178. print $langs->trans("ChooseABarCode");
  179. }
  180. print '</td>';
  181. print '<td align="center">';
  182. print $formbarcode->setBarcodeEncoder($obj->coder,$barcodelist,$obj->rowid,'form'.$i);
  183. print "</td></tr>\n";
  184. $var=!$var;
  185. $i++;
  186. }
  187. }
  188. print "</table>\n";
  189. print "<br>";
  190. /*
  191. * Autres options
  192. *
  193. */
  194. print_titre($langs->trans("OtherOptions"));
  195. $var=true;
  196. print '<table class="noborder" width="100%">';
  197. print '<tr class="liste_titre">';
  198. print '<td>'.$langs->trans("Parameter").'</td>';
  199. print '<td width="60" align="center">'.$langs->trans("Value").'</td>';
  200. print '<td>&nbsp;</td>';
  201. print '</tr>';
  202. // Chemin du binaire genbarcode sous linux
  203. if (! isset($_SERVER['WINDIR']))
  204. {
  205. $var=!$var;
  206. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  207. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  208. print '<input type="hidden" name="action" value="setgenbarcodelocation">';
  209. print '<tr '.$bc[$var].'>';
  210. print '<td>'.$langs->trans("GenbarcodeLocation").'</td>';
  211. print '<td width="60" align="center">';
  212. print '<input type="text" size="40" name="genbarcodelocation" value="'.$conf->global->GENBARCODE_LOCATION.'">';
  213. if (! empty($conf->global->GENBARCODE_LOCATION) && ! @file_exists($conf->global->GENBARCODE_LOCATION))
  214. {
  215. $langs->load("errors");
  216. print '<br><font class="error">'.$langs->trans("ErrorFileNotFound",$conf->global->GENBARCODE_LOCATION).'</font>';
  217. }
  218. print '</td>';
  219. print '<td width="60" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  220. print '</tr>';
  221. print '</form>';
  222. }
  223. // Module produits
  224. if ($conf->societe->enabled)
  225. {
  226. $var=!$var;
  227. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  228. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  229. print "<input type=\"hidden\" name=\"action\" value=\"setdefaultbarcodetype\">";
  230. print "<tr ".$bc[$var].">";
  231. print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
  232. print '<td width="60" align="right">';
  233. print $formbarcode->select_barcode_type($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE,"coder_id",1);
  234. print '</td><td align="right">';
  235. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  236. print "</td>";
  237. print '</tr>';
  238. print '</form>';
  239. }
  240. // Module produits
  241. if ($conf->product->enabled)
  242. {
  243. $var=!$var;
  244. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  245. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  246. print "<input type=\"hidden\" name=\"action\" value=\"GENBARCODE_BARCODETYPE_THIRDPARTY\">";
  247. print "<tr ".$bc[$var].">";
  248. print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
  249. print '<td width="60" align="right">';
  250. print $formbarcode->select_barcode_type($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY,"coder_id",1);
  251. print '</td><td align="right">';
  252. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  253. print "</td>";
  254. print '</tr>';
  255. print '</form>';
  256. }
  257. print '</table>';
  258. print "<br>";
  259. $db->close();
  260. llxFooter();
  261. ?>