PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/barcode.php

https://github.com/asterix14/dolibarr
PHP | 325 lines | 224 code | 42 blank | 59 comment | 43 complexity | b664c49d497308f81f241b0a23634631 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 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/admin/barcode.php
  21. * \ingroup barcode
  22. * \brief Page to setup barcode module
  23. */
  24. require("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/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. $action = GETPOST("action");
  31. /*
  32. * Actions
  33. */
  34. if ($action == 'setcoder')
  35. {
  36. $coder = GETPOST("coder");
  37. $code_id = GETPOST("code_id");
  38. $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
  39. $sqlp.= " SET coder = '" . $coder."'";
  40. $sqlp.= " WHERE rowid = ". $code_id;
  41. $sqlp.= " AND entity = ".$conf->entity;
  42. $resql=$db->query($sqlp);
  43. //print $sqlp;
  44. }
  45. else if ($action == 'setgenbarcodelocation')
  46. {
  47. $location = GETPOST("genbarcodelocation");
  48. $res = dolibarr_set_const($db, "GENBARCODE_LOCATION",$location,'chaine',0,'',$conf->entity);
  49. }
  50. else if ($action == 'setdefaultbarcodetype')
  51. {
  52. $coder_id = GETPOST("coder_id");
  53. $res = dolibarr_set_const($db, "PRODUIT_DEFAULT_BARCODE_TYPE", $coder_id,'chaine',0,'',$conf->entity);
  54. }
  55. else if ($action == 'GENBARCODE_BARCODETYPE_THIRDPARTY')
  56. {
  57. $coder_id = GETPOST("coder_id");
  58. $res = dolibarr_set_const($db, "GENBARCODE_BARCODETYPE_THIRDPARTY", $coder_id,'chaine',0,'',$conf->entity);
  59. }
  60. /*
  61. else if ($_POST["action"] == 'setproductusebarcode')
  62. {
  63. dolibarr_set_const($db, "PRODUIT_USE_BARCODE",$_POST["value"],'chaine',0,'',$conf->entity);
  64. Header("Location: barcode.php");
  65. exit;
  66. }
  67. */
  68. if($action && $action!='setcoder')
  69. {
  70. if (! $res > 0) $error++;
  71. if (! $error)
  72. {
  73. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  74. }
  75. else
  76. {
  77. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  78. }
  79. }
  80. /*
  81. * View
  82. */
  83. $form = new Form($db);
  84. $formbarcode = new FormBarCode($db);
  85. llxHeader('',$langs->trans("BarcodeSetup"),'BarcodeConfiguration');
  86. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  87. print_fiche_titre($langs->trans("BarcodeSetup"),$linkback,'setup');
  88. // Detect bar codes modules
  89. $barcodelist=array();
  90. clearstatcache();
  91. foreach ($conf->file->dol_document_root as $dirroot)
  92. {
  93. $dir = $dirroot . "/core/modules/barcode/";
  94. $handle=@opendir($dir);
  95. if (is_resource($handle))
  96. {
  97. while (($file = readdir($handle))!==false)
  98. {
  99. if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
  100. {
  101. if (is_readable($dir.$file))
  102. {
  103. if (preg_match('/(.*)\.modules\.php$/i',$file,$reg))
  104. {
  105. $filebis=$reg[1];
  106. // Chargement de la classe de codage
  107. require_once($dir.$file);
  108. $classname = "mod".ucfirst($filebis);
  109. $module = new $classname($db);
  110. // Show modules according to features level
  111. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  112. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  113. if ($module->isEnabled())
  114. {
  115. $barcodelist[$filebis]=$module->info();
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. /*
  124. * CHOIX ENCODAGE
  125. */
  126. $var=true;
  127. print '<br>';
  128. print_titre($langs->trans("BarcodeEncodeModule"));
  129. print '<table class="noborder" width="100%">';
  130. print '<tr class="liste_titre">';
  131. print '<td>'.$langs->trans("Name").'</td>';
  132. print '<td>'.$langs->trans("Description").'</td>';
  133. print '<td width="200" align="center">'.$langs->trans("Example").'</td>';
  134. print '<td align="center" width="60">'.$langs->trans("CodeBarGenerator").'</td>';
  135. print "</tr>\n";
  136. $sql = "SELECT rowid, code as encoding, libelle, coder, example";
  137. $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
  138. $sql.= " WHERE entity = ".$conf->entity;
  139. $sql.= " ORDER BY code";
  140. dol_syslog("admin/barcode.php sql=".$sql);
  141. $resql=$db->query($sql);
  142. if ($resql)
  143. {
  144. $num = $db->num_rows($resql);
  145. $i = 0;
  146. $var=true;
  147. while ($i < $num)
  148. {
  149. $obj = $db->fetch_object($resql);
  150. print '<tr '.$bc[$var].'><td width="100">';
  151. print $obj->libelle;
  152. print "</td><td>\n";
  153. print $langs->trans('BarcodeDesc'.$obj->encoding);
  154. //print "L'EAN se compose de 8 caracteres, 7 chiffres plus une cle de controle.<br>";
  155. //print "L'utilisation des symbologies EAN8 impose la souscription et l'abonnement aupres d'organisme tel que GENCOD.<br>";
  156. //print "Codes numeriques utilises exclusivement a l'identification des produits susceptibles d'etre vendus au grand public.";
  157. print '</td>';
  158. // Show example
  159. print '<td align="center">';
  160. if ($obj->coder && $obj->coder != -1)
  161. {
  162. $result=0;
  163. // Chargement de la classe de codage
  164. foreach ($conf->file->dol_document_root as $dirroot)
  165. {
  166. $dir=$dirroot . "/core/modules/barcode/";
  167. $result=@include_once($dir.$obj->coder.".modules.php");
  168. //print $dir.$obj->coder.".modules.php - ".$result;
  169. if ($result) break;
  170. }
  171. if ($result)
  172. {
  173. $classname = "mod".ucfirst($obj->coder);
  174. if (class_exists($classname))
  175. {
  176. $module = new $classname($db);
  177. if ($module->encodingIsSupported($obj->encoding))
  178. {
  179. // Build barcode on disk (not used, this is done to make debug easier)
  180. $result=$module->writeBarCode($obj->example,$obj->encoding,'Y');
  181. // Generate on the fly and output barcode with generator
  182. $url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($obj->coder).'&code='.urlencode($obj->example).'&encoding='.urlencode($obj->encoding);
  183. //print $url;
  184. print '<img src="'.$url.'" title="'.$obj->example.'" border="0">';
  185. }
  186. else
  187. {
  188. print $langs->trans("FormatNotSupportedByGenerator");
  189. }
  190. }
  191. else
  192. {
  193. print 'ErrorClassNotFoundInModule '.$classname.' '.$obj->coder;
  194. }
  195. }
  196. }
  197. else
  198. {
  199. print $langs->trans("ChooseABarCode");
  200. }
  201. print '</td>';
  202. print '<td align="center">';
  203. print $formbarcode->setBarcodeEncoder($obj->coder,$barcodelist,$obj->rowid,'form'.$i);
  204. print "</td></tr>\n";
  205. $var=!$var;
  206. $i++;
  207. }
  208. }
  209. print "</table>\n";
  210. print "<br>";
  211. /*
  212. * Autres options
  213. *
  214. */
  215. print_titre($langs->trans("OtherOptions"));
  216. $var=true;
  217. print '<table class="noborder" width="100%">';
  218. print '<tr class="liste_titre">';
  219. print '<td>'.$langs->trans("Parameter").'</td>';
  220. print '<td width="60" align="center">'.$langs->trans("Value").'</td>';
  221. print '<td>&nbsp;</td>';
  222. print '</tr>';
  223. // Chemin du binaire genbarcode sous linux
  224. if (! isset($_SERVER['WINDIR']))
  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="setgenbarcodelocation">';
  230. print '<tr '.$bc[$var].'>';
  231. print '<td>'.$langs->trans("GenbarcodeLocation").'</td>';
  232. print '<td width="60" align="center">';
  233. print '<input type="text" size="40" name="genbarcodelocation" value="'.$conf->global->GENBARCODE_LOCATION.'">';
  234. if (! empty($conf->global->GENBARCODE_LOCATION) && ! @file_exists($conf->global->GENBARCODE_LOCATION))
  235. {
  236. $langs->load("errors");
  237. print '<br><font class="error">'.$langs->trans("ErrorFileNotFound",$conf->global->GENBARCODE_LOCATION).'</font>';
  238. }
  239. print '</td>';
  240. print '<td width="60" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  241. print '</tr>';
  242. print '</form>';
  243. }
  244. // Module produits
  245. if ($conf->societe->enabled)
  246. {
  247. $var=!$var;
  248. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  249. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  250. print "<input type=\"hidden\" name=\"action\" value=\"setdefaultbarcodetype\">";
  251. print "<tr ".$bc[$var].">";
  252. print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
  253. print '<td width="60" align="right">';
  254. print $formbarcode->select_barcode_type($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE,"coder_id",1);
  255. print '</td><td align="right">';
  256. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  257. print "</td>";
  258. print '</tr>';
  259. print '</form>';
  260. }
  261. // Module produits
  262. if ($conf->product->enabled)
  263. {
  264. $var=!$var;
  265. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  266. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  267. print "<input type=\"hidden\" name=\"action\" value=\"GENBARCODE_BARCODETYPE_THIRDPARTY\">";
  268. print "<tr ".$bc[$var].">";
  269. print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
  270. print '<td width="60" align="right">';
  271. print $formbarcode->select_barcode_type($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY,"coder_id",1);
  272. print '</td><td align="right">';
  273. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  274. print "</td>";
  275. print '</tr>';
  276. print '</form>';
  277. }
  278. print '</table>';
  279. print "<br>";
  280. dol_htmloutput_mesg($mesg);
  281. $db->close();
  282. llxFooter();
  283. ?>