Protection on using non embended code format with windows (it hangs)

This commit is contained in:
Laurent Destailleur 2009-05-04 00:12:55 +00:00
parent ed33882ca3
commit 42a32481a2

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -19,76 +19,80 @@
*/ */
/** /**
\file htdocs/includes/modules/barcode/phpbarcode.modules.php * \file htdocs/includes/modules/barcode/phpbarcode.modules.php
\ingroup facture * \ingroup facture
\brief Fichier contenant la classe du modèle de generation code barre phpbarcode * \brief Fichier contenant la classe du modèle de generation code barre phpbarcode
\version $Id$ * \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/barcode/modules_barcode.php"); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/barcode/modules_barcode.php");
/** \class modPhpbarcode /** \class modPhpbarcode
\brief Classe du modèle de numérotation de generation code barre phpbarcode * \brief Classe du modèle de numérotation de generation code barre phpbarcode
*/ */
class modPhpbarcode extends ModeleBarCode class modPhpbarcode extends ModeleBarCode
{ {
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $error=''; var $error='';
/** \brief Return if a module can be used or not /** \brief Return if a module can be used or not
* \return boolean true if module can be used * \return boolean true if module can be used
*/ */
function isEnabled() function isEnabled()
{ {
return true; return true;
} }
/** \brief Renvoi la description du modele de numérotation /** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif * \return string Texte descripif
*/ */
function info() function info()
{ {
global $langs; global $langs;
return 'Php-barcode'; return 'Php-barcode';
} }
/** \brief Test si les numéros déjà en vigueur dans la base ne provoquent pas de /** \brief Test si les numéros déjà en vigueur dans la base ne provoquent pas de
* de conflits qui empechera cette numérotation de fonctionner. * de conflits qui empechera cette numérotation de fonctionner.
* \return boolean false si conflit, true si ok * \return boolean false si conflit, true si ok
*/ */
function canBeActivated() function canBeActivated()
{ {
global $langs; global $langs;
return true;
}
return true;
}
/** /**
\brief Return true if encodinf is supported * \brief Return true if encodinf is supported
\return int >0 if supported, 0 if not * \return int >0 if supported, 0 if not
*/ */
function encodingIsSupported($encoding) function encodingIsSupported($encoding)
{ {
$supported=0; $supported=0;
if ($encoding == 'EAN8') $supported=1;
if ($encoding == 'EAN13') $supported=1; if ($encoding == 'EAN13') $supported=1;
if ($encoding == 'UPC') $supported=1;
if ($encoding == 'ISBN') $supported=1; if ($encoding == 'ISBN') $supported=1;
if ($encoding == 'C39') $supported=1; // Formats that hangs on Windows (when genbarcode.exe for Windows is called, so they are not
if ($encoding == 'C128') $supported=1; // activated on Windows)
if ($encoding == 'EAN8' && empty($_SERVER["WINDIR"])) $supported=1;
if ($encoding == 'UPC' && empty($_SERVER["WINDIR"])) $supported=1;
if ($encoding == 'C39' && empty($_SERVER["WINDIR"])) $supported=1;
if ($encoding == 'C128' && empty($_SERVER["WINDIR"])) $supported=1;
return $supported; return $supported;
} }
/** /**
* \brief Return an image file on output * \brief Return an image file on output
* \param $code Valeur numérique a coder * \param $code Valeur numérique a coder
* \param $encoding Mode de codage * \param $encoding Mode de codage
* \param $readable Code lisible * \param $readable Code lisible
*/ */
function buildBarCode($code,$encoding,$readable='Y') function buildBarCode($code,$encoding,$readable='Y')
{ {
global $_GET,$_ENV,$_SERVER; global $_GET,$_ENV,$_SERVER;
global $conf; global $conf;
global $genbarcode_loc, $bar_color, $bg_color, $text_color, $font_loc; global $genbarcode_loc, $bar_color, $bg_color, $text_color, $font_loc;
@ -106,20 +110,21 @@ class modPhpbarcode extends ModeleBarCode
$_GET["mode"]=$mode; $_GET["mode"]=$mode;
require_once(DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/php-barcode.php'); require_once(DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/php-barcode.php');
dol_syslog("modPhpbarcode::buildBarCode $code,$encoding,$scale,$mode");
if ($code) barcode_print($code,$encoding,$scale,$mode); if ($code) barcode_print($code,$encoding,$scale,$mode);
return 1; return 1;
} }
/** /**
* \brief Save an image file on disk * \brief Save an image file on disk
* \param $code Valeur numérique a coder * \param $code Valeur numérique a coder
* \param $encoding Mode de codage * \param $encoding Mode de codage
* \param $readable Code lisible * \param $readable Code lisible
*/ */
function writeBarCode($code,$encoding,$readable='Y') function writeBarCode($code,$encoding,$readable='Y')
{ {
global $conf,$filebarcode; global $conf,$filebarcode;
create_exdir($conf->barcode->dir_temp); create_exdir($conf->barcode->dir_temp);
@ -130,7 +135,7 @@ class modPhpbarcode extends ModeleBarCode
$result=$this->buildBarCode($code,$encoding,$readable); $result=$this->buildBarCode($code,$encoding,$readable);
return $result; return $result;
} }
} }