PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/modules/barcode/phpbarcode.modules.php

https://github.com/asterix14/dolibarr
PHP | 154 lines | 70 code | 29 blank | 55 comment | 25 complexity | f2f1e8434bb422677fbc13b1a2fb1440 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/barcode/phpbarcode.modules.php
  21. * \ingroup facture
  22. * \brief Fichier contenant la classe du modele de generation code barre phpbarcode
  23. */
  24. require_once(DOL_DOCUMENT_ROOT ."/core/modules/barcode/modules_barcode.php");
  25. /** \class modPhpbarcode
  26. * \brief Classe du modele de numerotation de generation code barre phpbarcode
  27. */
  28. class modPhpbarcode extends ModeleBarCode
  29. {
  30. var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
  31. var $error='';
  32. /** \brief Return if a module can be used or not
  33. * \return boolean true if module can be used
  34. */
  35. function isEnabled()
  36. {
  37. return true;
  38. }
  39. /** \brief Return description
  40. * \return string Texte descripif
  41. */
  42. function info()
  43. {
  44. global $langs;
  45. return 'Php-barcode';
  46. }
  47. /** \brief Test si les numeros deja en vigueur dans la base ne provoquent pas de
  48. * de conflits qui empechera cette numerotation de fonctionner.
  49. * \return boolean false si conflit, true si ok
  50. */
  51. function canBeActivated()
  52. {
  53. global $langs;
  54. return true;
  55. }
  56. /**
  57. * \brief Return true if encodinf is supported
  58. * \return int >0 if supported, 0 if not
  59. */
  60. function encodingIsSupported($encoding)
  61. {
  62. global $genbarcode_loc;
  63. $supported=0;
  64. if ($encoding == 'EAN13') $supported=1;
  65. if ($encoding == 'ISBN') $supported=1;
  66. // Formats that hangs on Windows (when genbarcode.exe for Windows is called, so they are not
  67. // activated on Windows)
  68. if (file_exists($genbarcode_loc) && empty($_SERVER["WINDIR"]))
  69. {
  70. if ($encoding == 'EAN8') $supported=1;
  71. if ($encoding == 'UPC') $supported=1;
  72. if ($encoding == 'C39') $supported=1;
  73. if ($encoding == 'C128') $supported=1;
  74. }
  75. return $supported;
  76. }
  77. /**
  78. * Return an image file on the fly (no need to write on disk)
  79. *
  80. * @param string $code Value to encode
  81. * @param string $encoding Mode of encoding
  82. * @param string $readable Code can be read
  83. */
  84. function buildBarCode($code,$encoding,$readable='Y')
  85. {
  86. global $_GET,$_SERVER;
  87. global $conf;
  88. global $genbarcode_loc, $bar_color, $bg_color, $text_color, $font_loc;
  89. if (! $this->encodingIsSupported($encoding)) return -1;
  90. if ($encoding == 'EAN8' || $encoding == 'EAN13') $encoding = 'EAN';
  91. if ($encoding == 'C39' || $encoding == 'C128') $encoding = substr($encoding,1);
  92. $scale=1; $mode='png';
  93. $_GET["code"]=$code;
  94. $_GET["encoding"]=$encoding;
  95. $_GET["scale"]=$scale;
  96. $_GET["mode"]=$mode;
  97. require_once(DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/php-barcode.php');
  98. dol_syslog("modPhpbarcode::buildBarCode $code,$encoding,$scale,$mode");
  99. if ($code) $result=barcode_print($code,$encoding,$scale,$mode);
  100. if (! is_array($result))
  101. {
  102. $this->error=$result;
  103. print $this->error;
  104. return -1;
  105. }
  106. return 1;
  107. }
  108. /**
  109. * Save an image file on disk (with no output)
  110. *
  111. * @param string $code Value to encode
  112. * @param string $encoding Mode of encoding
  113. * @param string $readable Code can be read
  114. */
  115. function writeBarCode($code,$encoding,$readable='Y')
  116. {
  117. global $conf,$filebarcode;
  118. create_exdir($conf->barcode->dir_temp);
  119. $file=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
  120. $filebarcode=$file; // global var to be used in barcode_outimage called by barcode_print in buildBarCode
  121. $result=$this->buildBarCode($code,$encoding,$readable);
  122. return $result;
  123. }
  124. }
  125. ?>