From 61cc2563c6badc74f18254253335a326a10b1528 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Thu, 3 Jan 2008 18:41:32 +0000
Subject: [PATCH] =?UTF-8?q?New:=20Les=20generateurs=20de=20code=20barre=20?=
 =?UTF-8?q?sont=20externalis=E9s=20en=20modules.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 COPYRIGHT                                     |   4 +
 htdocs/admin/barcode.php                      |  83 ++++++++++---
 htdocs/html.form.class.php                    |  11 +-
 .../barcode/php-barcode/php-barcode.php       |   3 +-
 .../barcode/modules_barcode.php}              |  43 +++----
 .../modules/barcode/phpbarcode.modules.php    | 109 ++++++++++++++++++
 .../modules/barcode/pibarcode.modules.php     | 103 +++++++++++++++++
 htdocs/lib/functions.inc.php                  |  25 ----
 htdocs/product/barcode.php                    |   3 +-
 htdocs/viewimage.php                          |  70 ++++++++---
 htdocs/webcal/webcalexport.php                |   1 +
 mysql/migration/2.2.0-2.4.0.sql               |   4 +-
 mysql/tables/llx_c_barcode_type.sql           |   2 +-
 13 files changed, 367 insertions(+), 94 deletions(-)
 rename htdocs/includes/{barcode/php-barcode/genbarcode.php => modules/barcode/modules_barcode.php} (52%)
 create mode 100644 htdocs/includes/modules/barcode/phpbarcode.modules.php
 create mode 100644 htdocs/includes/modules/barcode/pibarcode.modules.php

diff --git a/COPYRIGHT b/COPYRIGHT
index 6ff57a2d8d3..ba6a79e5c75 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -35,6 +35,10 @@ http://www.fsf.org/licensing/licenses/index_html
 Copyright
 ---------
 
+Copyright (C) 2008
+- Laurent Destailleur <eldy@users.sourceforge.net>
+- Regis Houssin <regis@dolibarr.fr>
+
 Copyright (C) 2007
 - Rodolphe Quiedeville <rodolphe@quiedeville.org>
 - Laurent Destailleur <eldy@users.sourceforge.net>
diff --git a/htdocs/admin/barcode.php b/htdocs/admin/barcode.php
index 4a60d5241b5..ca9d7c67792 100644
--- a/htdocs/admin/barcode.php
+++ b/htdocs/admin/barcode.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2007 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2004-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2007 Regis Houssin        <regis@dolibarr.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,6 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
  * $Id$
- * $Source$
  */
 
 /**	
@@ -30,6 +29,8 @@
 
 require("./pre.inc.php");
 
+$dir = DOL_DOCUMENT_ROOT."/includes/modules/barcode/";
+
 $langs->load("admin");
 
 if (!$user->admin)
@@ -38,29 +39,67 @@ if (!$user->admin)
 if ($_POST["action"] == 'setcoder')
 {
 	$sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type";
-  $sqlp.= " SET coder = " . $_POST["coder"];
-  $sqlp.= " WHERE rowid = ". $_POST["code_id"];
-  $resql=$db->query($sqlp);
+	$sqlp.= " SET coder = '" . $_POST["coder"]."'";
+	$sqlp.= " WHERE rowid = ". $_POST["code_id"];
+	$resql=$db->query($sqlp);
+	//print $sqlp;
 }
 else if ($_POST["action"] == 'setgenbarcodelocation')
 {
 	dolibarr_set_const($db, "GENBARCODE_LOCATION",$_POST["genbarcodelocation"]);
-  Header("Location: barcode.php");
-  exit;
+	Header("Location: barcode.php");
+	exit;
 }
 else if ($_POST["action"] == 'setproductusebarcode')
 {
-  dolibarr_set_const($db, "PRODUIT_USE_BARCODE",$_POST["value"]);
-  Header("Location: barcode.php");
-  exit;
+	dolibarr_set_const($db, "PRODUIT_USE_BARCODE",$_POST["value"]);
+	Header("Location: barcode.php");
+	exit;
 }
 
+
+
 $html = new Form($db);
 
 llxHeader('',$langs->trans("BarcodeSetup"),'BarcodeConfiguration');
 
 print_fiche_titre($langs->trans("BarcodeSetup"),'','setup');
 
+// Detect bar codes modules
+$barcodelist=array();
+
+clearstatcache();
+
+$handle=opendir($dir);
+
+$var=true;
+
+while (($file = readdir($handle))!==false)
+{
+    if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
+    {
+		if (is_readable($dir.$file))
+		{
+			if (eregi('(.*)\.modules\.php',$file,$reg))
+			{
+		        $filebis=$reg[1];
+				
+				// Chargement de la classe de codage
+		        require_once($dir.$file);
+		        $classname = "mod".ucfirst($filebis);
+		        $module = new $classname($db);
+
+				// Show modules according to features level
+			    if ($module->version == 'development'  && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
+			    if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
+
+				$barcodelist[$filebis]=$module->info();
+			}
+		}
+	}
+}
+
+
 /*
  *  CHOIX ENCODAGE
  */
@@ -76,7 +115,7 @@ print '<td width="200" align="center">'.$langs->trans("Example").'</td>';
 print '<td align="center" width="60">'.$langs->trans("CodeBarGenerator").'</td>';
 print "</tr>\n";
 
-$sql = "SELECT rowid, code, libelle, coder, example";
+$sql = "SELECT rowid, code as encoding, libelle, coder, example";
 $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
 $resql=$db->query($sql);
 if ($resql)
@@ -92,7 +131,7 @@ if ($resql)
 		print '<tr '.$bc[$var].'><td width="100">';
 		print $obj->libelle;
 		print "</td><td>\n";
-		print $langs->trans('BarcodeDesc'.$obj->code);  
+		print $langs->trans('BarcodeDesc'.$obj->encoding);  
 		//print "L'EAN se compose de 8 caract�res, 7 chiffres plus une cl� de contr�le.<br>";
 		//print "L'utilisation des symbologies EAN8 impose la souscription et l'abonnement aupr�s d'organisme tel que GENCOD.<br>";
 		//print "Codes num�riques utilis�s exclusivement � l'identification des produits susceptibles d'�tre vendus au grand public.";
@@ -102,9 +141,21 @@ if ($resql)
 		print '<td align="center">';
 		if ($obj->coder)
 		{
-			$url=dol_genbarcode($obj->example,$obj->code,$obj->coder);
-			if ($url) print '<img src="'.$url.'">';
-			else print $langs->trans("FormatNotSupportedByGenerator");
+			// Chargement de la classe de codage
+			require_once($dir.$obj->coder.".modules.php");
+			$classname = "mod".ucfirst($obj->coder);
+			$module = new $classname($db);
+
+			if ($module->encodingIsSupported($obj->encoding))
+			{
+				$url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($obj->coder).'&code='.urlencode($obj->example).'&encoding='.urlencode($obj->encoding);
+				//print $url;
+				print '<img src="'.$url.'" border="0">';
+			}
+			else
+			{
+				print $langs->trans("FormatNotSupportedByGenerator");
+			}
 		}
 		else
 		{
@@ -113,7 +164,7 @@ if ($resql)
 		print '</td>';
 
 		print '<td align="center">';
-		print $html->setBarcodeEncoder($obj->coder,$obj->rowid,'form'.$i);
+		print $html->setBarcodeEncoder($obj->coder,$barcodelist,$obj->rowid,'form'.$i);
 		print "</td></tr>\n";
 		$var=!$var;
 		$i++;
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index a7f8a726730..0ab7e50a029 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -3559,9 +3559,8 @@ class Form
 	 *    \param      selected          Id code pr�-s�lectionn�
 	 *    \param      code_id           Id du code barre
 	 *    \param      idForm            Id du formulaire
-	 *    Todo : ajouter une v�rification de d�sactivation du code barre si il est d�j� utilis� dans un module
 	 */
-	function setBarcodeEncoder($selected=0,$code_id,$idForm='formbarcode')
+	function setBarcodeEncoder($selected=0,$barcodelist,$code_id,$idForm='formbarcode')
 	{
 		global $conf, $langs;
 		
@@ -3579,10 +3578,12 @@ class Form
 		$select_encoder.= '<select class="flat" name="coder" onChange="barcode_coder_save(\''.$idForm.'\')">';
 		$select_encoder.= '<option value="0"'.($selected==0?' selected="true"':'').' '.$disable.'>'.$langs->trans('Disable').'</option>';
 		$select_encoder.= '<option value="-1" disabled="disabled">--------------------</option>';
-		$select_encoder.= '<option value="1"'.($selected==1?' selected="true"':'').'>PHP-Barcode</option>';
-		$select_encoder.= '<option value="2"'.($selected==2?' selected="true"':'').'>PI_Barcode</option>';
+		foreach($barcodelist as $key => $value)
+		{
+			$select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected="true"':'').'>'.$value.'</option>';
+		}
 		$select_encoder.= '</select></form>';
-		
+
 		return $select_encoder;
 	}
    
diff --git a/htdocs/includes/barcode/php-barcode/php-barcode.php b/htdocs/includes/barcode/php-barcode/php-barcode.php
index 0ffd4813414..952a683dbb2 100644
--- a/htdocs/includes/barcode/php-barcode/php-barcode.php
+++ b/htdocs/includes/barcode/php-barcode/php-barcode.php
@@ -35,7 +35,6 @@
 
  */
 
-require_once('../../../master.inc.php');
 
 /* CONFIGURATION */
 
@@ -86,6 +85,7 @@ else
 	//$genbarcode_loc = "/usr/local/bin/genbarcode";
 	$genbarcode_loc = $conf->global->GENBARCODE_LOCATION;
 }
+//dolibarr_syslog("genbarcode_loc=".$genbarcode_loc);
 
 
 /* CONFIGURATION ENDS HERE */
@@ -432,6 +432,7 @@ function barcode_encode($code,$encoding){
 
 function barcode_print($code, $encoding="ANY", $scale = 2 ,$mode = "png" ){
     $bars=barcode_encode($code,$encoding);
+	dolibarr_syslog("$code $encoding $scale $mode ".join(',',$bars));
     if (!$bars) return;
     if (!$mode) $mode="png";
     if (eregi($mode,"^(text|txt|plain)$")) print barcode_outtext($bars['text'],$bars['bars']);
diff --git a/htdocs/includes/barcode/php-barcode/genbarcode.php b/htdocs/includes/modules/barcode/modules_barcode.php
similarity index 52%
rename from htdocs/includes/barcode/php-barcode/genbarcode.php
rename to htdocs/includes/modules/barcode/modules_barcode.php
index 2b87b0b15b0..b99d6366110 100644
--- a/htdocs/includes/barcode/php-barcode/genbarcode.php
+++ b/htdocs/includes/modules/barcode/modules_barcode.php
@@ -1,5 +1,8 @@
 <?php
-/* Copyright (C) 2005-2007 Regis Houssin      <regis@dolibarr.fr>
+/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ * Copyright (C) 2004-2007 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2004      Eric Seigne          <eric.seigne@ryxeo.com>
+ * Copyright (C) 2005      Regis Houssin        <regis@dolibarr.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -14,40 +17,30 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * or see http://www.gnu.org/
  *
  * $Id$
- * $Source$
  */
 
 /**
-   \file       htdocs/genbarcode.php
-   \brief      G�n�rateur de codes barres
+   \file       htdocs/includes/modules/barcode/modules_barcode.php
    \ingroup    barcode
+   \brief      Fichier contenant la classe m�re de generation des codes barres
    \version    $Revision$
 */
 
-require_once('php-barcode.php');
+require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php');
 
-function getvar($name){
-    global $_GET, $_POST;
-    if (isset($_GET[$name])) return $_GET[$name];
-    else if (isset($_POST[$name])) return $_POST[$name];
-    else return false;
-}
 
-if (get_magic_quotes_gpc()){
-    $code=stripslashes(getvar('code'));
-} else {
-    $code=getvar('code');
-}
-if ($code) barcode_print($code,getvar('encoding'),getvar('scale'),getvar('mode'));
+/**
+   \class      ModeleBarCode
+   \brief      Classe m�re des mod�les de code barre
+*/
 
-/*
- * call
- * http://........./barcode.php?code=012345678901
- *   or
- * http://........./barcode.php?code=012345678901&encoding=EAN&scale=4&mode=png
- *
- */
+class ModeleBarCode
+{
+	var $error='';
+
+}
 
-?>
\ No newline at end of file
+?>
diff --git a/htdocs/includes/modules/barcode/phpbarcode.modules.php b/htdocs/includes/modules/barcode/phpbarcode.modules.php
new file mode 100644
index 00000000000..881e7c181c2
--- /dev/null
+++ b/htdocs/includes/modules/barcode/phpbarcode.modules.php
@@ -0,0 +1,109 @@
+<?php
+/* Copyright (C) 2005-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2005      Regis Houssin        <regis@dolibarr.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * or see http://www.gnu.org/
+ *
+ * $Id$
+ */
+
+/**
+        \file       htdocs/includes/modules/barcode/phpbarcode.modules.php
+		\ingroup    facture
+		\brief      Fichier contenant la classe du mod�le de generation code barre phpbarcode
+		\version    $Revision$
+*/
+
+require_once(DOL_DOCUMENT_ROOT ."/includes/modules/barcode/modules_barcode.php");
+
+/**	    \class      modPhpbarcode
+		\brief      Classe du mod�le de num�rotation de generation code barre phpbarcode
+*/
+
+class modPhpbarcode extends ModeleBarCode
+{
+	var $version='dolibarr';		// 'development', 'experimental', 'dolibarr'
+	var $error='';
+	
+    /**     \brief      Renvoi la description du modele de num�rotation
+     *      \return     string      Texte descripif
+     */
+    function info()
+    {
+	 	global $langs;
+
+    	return 'Php-barcode';
+    }
+
+    /**     \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.
+     *      \return     boolean     false si conflit, true si ok
+     */
+    function canBeActivated()
+    {
+        global $langs;
+
+        return true;
+    }
+
+	/**
+		\brief		Return true if encodinf is supported
+		\return		int		>0 if supported, 0 if not
+	*/
+    function encodingIsSupported($encoding)
+	{
+		$supported=0;
+		if ($encoding == 'EAN8')  $supported=1;
+		if ($encoding == 'EAN13') $supported=1;
+		if ($encoding == 'ISBN')  $supported=1;
+		if ($encoding == 'C39')   $supported=1;
+		if ($encoding == 'C128')  $supported=1;
+		return $supported;
+	}
+	
+    /**
+			\brief      Retourne fichier image
+			\param   	$code			Valeur num�rique a coder
+			\param   	$encoding		Mode de codage
+			\param   	$readable		Code lisible
+     */
+    function buildBarCode($code,$encoding,$readable='Y')
+    { 
+		global $_GET,$_ENV,$_SERVER;
+		global $conf;
+		global $genbarcode_loc, $bar_color, $bg_color, $text_color, $font_loc;
+		
+		if (! $this->encodingIsSupported($encoding)) return -1;
+		
+		if ($encoding == 'EAN8' || $encoding == 'EAN13') $encoding = 'EAN';
+		if ($encoding == 'C39' || $encoding == 'C128')   $encoding = substr($encoding,1);
+
+		$scale=1; $mode='png';
+
+		$_GET["code"]=$code;
+		$_GET["encoding"]=$encoding;
+		$_GET["scale"]=$scale;
+		$_GET["mode"]=$mode;
+
+		require_once(DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/php-barcode.php');
+		if ($code) barcode_print($code,$encoding,$scale,$mode);
+
+		return 1;
+    }
+    
+}
+
+?>
diff --git a/htdocs/includes/modules/barcode/pibarcode.modules.php b/htdocs/includes/modules/barcode/pibarcode.modules.php
new file mode 100644
index 00000000000..1bd95c772a1
--- /dev/null
+++ b/htdocs/includes/modules/barcode/pibarcode.modules.php
@@ -0,0 +1,103 @@
+<?php
+/* Copyright (C) 2005-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2005      Regis Houssin        <regis@dolibarr.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * or see http://www.gnu.org/
+ *
+ * $Id$
+ */
+
+/**
+        \file       htdocs/includes/modules/barcode/pibarcode.modules.php
+		\ingroup    facture
+		\brief      Fichier contenant la classe du mod�le de generation code barre pibarcode
+		\version    $Revision$
+*/
+
+require_once(DOL_DOCUMENT_ROOT ."/includes/modules/barcode/modules_barcode.php");
+
+/**	    \class      modPibarcode
+		\brief      Classe du mod�le de generation code barre pibarcode
+*/
+
+class modPibarcode extends ModeleBarCode
+{
+	var $version='dolibarr';		// 'development', 'experimental', 'dolibarr'
+	var $error='';
+	
+    /**     \brief      Renvoi la description du modele de num�rotation
+     *      \return     string      Texte descripif
+     */
+    function info()
+    {
+	 	global $langs;
+
+    	return 'Pi-barcode';
+    }
+
+    /**     \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.
+     *      \return     boolean     false si conflit, true si ok
+     */
+    function canBeActivated()
+    {
+        global $langs;
+
+        return true;
+    }
+
+	/**
+		\brief		Return true if encodinf is supported
+		\return		int		>0 if supported, 0 if not
+	*/
+    function encodingIsSupported($encoding)
+	{
+		$supported=0;
+		if ($encoding == 'EAN8')  $supported=1;
+		if ($encoding == 'EAN13') $supported=1;
+		if ($encoding == 'UPC')   $supported=1;
+		if ($encoding == 'C39')   $supported=1;
+		if ($encoding == 'C128')  $supported=1;
+		return $supported;
+	}
+	
+    /**
+			\brief      Retourne fichier image
+			\param   	$code			Valeur num�rique a coder
+			\param   	$encoding		Mode de codage
+			\param   	$readable		Code lisible
+     */
+    function buildBarCode($code,$encoding,$readable='Y')
+    {
+		global $_GET;
+		
+		if (! $this->encodingIsSupported($encoding)) return -1;
+
+		if ($encoding == 'EAN8' || $encoding == 'EAN13') $encoding = 'EAN';
+
+		$_GET["code"]=$code;
+		$_GET["type"]=$encoding;
+		$_GET["height"]=50;
+		$_GET["readable"]=$readable;
+
+		require_once(DOL_DOCUMENT_ROOT.'/includes/barcode/pi_barcode/pi_barcode.php');
+		
+		return 1;
+    }
+
+}
+
+?>
diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php
index 5fdd096e32d..cb133f09f0b 100644
--- a/htdocs/lib/functions.inc.php
+++ b/htdocs/lib/functions.inc.php
@@ -3506,31 +3506,6 @@ function viewExcelFileContent($file_to_include='',$max_rows=0,$max_cols=0)
   </SCRIPT>";
 }
 
-/**
-   \brief   G�n�rateur de codes barres
-   \param   $code			  Valeur num�rique a coder
-   \param   $encoding		Mode de codage
-   \param   $generator  G�n�rateur utilis� (1=php-barcode, 2=pi_barcode)
-   \param   $readable		Code lisible
-   \return  url
-*/
-function dol_genbarcode($code,$encoding,$generator=1,$readable='Y')
-{
-	$url='';
-	
-	if ($encoding == 'EAN8' || $encoding == 'EAN13') $encoding = 'EAN';
-	
-	if ($generator == 1)
-	{
-		if ($encoding == 'C39' || $encoding == 'C128') $encoding = substr($encoding,1);
-		$url = DOL_URL_ROOT.'/includes/barcode/php-barcode/genbarcode.php?code='.$code.'&encoding='.$encoding.'&scale=1';
-	}
-	else if ($generator == 2)
-	{
-		$url = DOL_URL_ROOT.'/includes/barcode/pi_barcode/pi_barcode.php?code='.$code.'&type='.$encoding.'&height=50&readable='.$readable;
-	}
-	return $url;
-}
 
 /**
    \brief   Retourne un tableau des mois ou le mois s�lectionn�
diff --git a/htdocs/product/barcode.php b/htdocs/product/barcode.php
index 1ef4f11d48b..2a2ff1c186e 100644
--- a/htdocs/product/barcode.php
+++ b/htdocs/product/barcode.php
@@ -100,7 +100,8 @@ print '</tr>';
 print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td>';
 
 // Barcode image
-print '<td width="300" align="center" rowspan="5"><img src="'.dol_genbarcode($product->barcode,$product->barcode_type_code,$product->barcode_type_coder).'"></td>';
+$url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($product->barcode_type_coder).'&code='.urlencode($product->barcode).'&encoding='.urlencode($product->barcode_type_code);
+print '<td width="300" align="center" rowspan="5"><img src="'.$url.'"></td>';
 
 print '</tr>';
 
diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php
index 330a5107082..3dcbcaf35e3 100644
--- a/htdocs/viewimage.php
+++ b/htdocs/viewimage.php
@@ -260,6 +260,7 @@ if ($modulepart)
       $accessallowed=1;
       $original_file=DOL_DATA_ROOT.'/graph/fournisseur/'.$original_file;
     }
+
     // Wrapping pour les graph des produits
     if ($modulepart == 'graph_product')
     {
@@ -267,6 +268,13 @@ if ($modulepart)
       $original_file=DOL_DATA_ROOT.'/graph/product/'.$original_file;
     }
 
+    // Wrapping pour les code barre
+    if ($modulepart == 'barcode')
+    {
+		$accessallowed=1;
+		$original_file='';
+    }
+
 }
 
 // Security:
@@ -290,29 +298,53 @@ if (eregi('\.\.',$original_file) || eregi('[<>|]',$original_file))
 
 
 
-// Ouvre et renvoi fichier
-clearstatcache(); 
-$filename = basename($original_file);
-
-dolibarr_syslog("viewimage.php return file $original_file $filename content-type=$type");
-
-if (! file_exists($original_file))
+if ($modulepart == 'barcode')
 {
-	$langs->load("main");
-	dolibarr_print_error(0,$langs->trans("ErrorFileDoesNotExists",$_GET["file"]));
-	exit;
-}
-
-// Les drois sont ok et fichier trouv�
-if ($type)
-{
-  header('Content-type: '.$type);
+	// Output files with barcode generators
+	$dir = DOL_DOCUMENT_ROOT."/includes/modules/barcode/";
+
+	$generator=$_GET["generator"];
+	$code=$_GET["code"];
+	$encoding=$_GET["encoding"];
+	$readable=$_GET["readable"];
+
+	// Chargement de la classe de codage
+	require_once($dir.$generator.".modules.php");
+	$classname = "mod".ucfirst($generator);
+	$module = new $classname($db);
+	if ($module->encodingIsSupported($encoding))
+	{
+		$result=$module->buildBarCode($code,$encoding,$readable);
+	}
 }
 else
 {
-  header('Content-type: image/png');
+	// Ouvre et renvoi fichier
+	clearstatcache(); 
+
+	// Output files on disk
+	$filename = basename($original_file);
+
+	dolibarr_syslog("viewimage.php return file $original_file $filename content-type=$type");
+
+	if (! file_exists($original_file))
+	{
+		$langs->load("main");
+		dolibarr_print_error(0,$langs->trans("ErrorFileDoesNotExists",$_GET["file"]));
+		exit;
+	}
+
+	// Les drois sont ok et fichier trouv�
+	if ($type)
+	{
+	  header('Content-type: '.$type);
+	}
+	else
+	{
+	  header('Content-type: image/png');
+	}
+
+	readfile($original_file);
 }
 
-readfile($original_file);
-
 ?>
diff --git a/htdocs/webcal/webcalexport.php b/htdocs/webcal/webcalexport.php
index dc8423819c6..a391455f470 100644
--- a/htdocs/webcal/webcalexport.php
+++ b/htdocs/webcal/webcalexport.php
@@ -48,6 +48,7 @@ if (empty($conf->global->PHPWEBCALENDAR_URL))
 $webcal=new WebCal();
 if (! $webcal->localdb->connected || ! $webcal->localdb->database_selected)
 {
+	$langs->load("admin");
 	llxHeader();
 	if ($webcal->localdb->connected == 1 && $webcal->localdb->database_selected != 1)
     {
diff --git a/mysql/migration/2.2.0-2.4.0.sql b/mysql/migration/2.2.0-2.4.0.sql
index 99c6f78ee25..dcda79a5ccc 100644
--- a/mysql/migration/2.2.0-2.4.0.sql
+++ b/mysql/migration/2.2.0-2.4.0.sql
@@ -8,4 +8,6 @@
 delete from llx_const where name='MAIN_GRAPH_LIBRARY' and (value like 'phplot%' or value like 'artichow%');
 
 ALTER TABLE llx_societe_adresse_livraison ADD COLUMN tel varchar(20) after fk_pays;
-ALTER TABLE llx_societe_adresse_livraison ADD COLUMN fax varchar(20) after tel;
\ No newline at end of file
+ALTER TABLE llx_societe_adresse_livraison ADD COLUMN fax varchar(20) after tel;
+
+alter table llx_c_barcode_type modify coder varchar(16) NOT NULL;
diff --git a/mysql/tables/llx_c_barcode_type.sql b/mysql/tables/llx_c_barcode_type.sql
index 29d7eb2a510..30dbd8b3420 100644
--- a/mysql/tables/llx_c_barcode_type.sql
+++ b/mysql/tables/llx_c_barcode_type.sql
@@ -23,6 +23,6 @@ create table llx_c_barcode
   rowid    integer            AUTO_INCREMENT PRIMARY KEY,
   code     varchar(16)        NOT NULL,
   libelle  varchar(50)        NOT NULL,
-  coder    integer            NOT NULL DEFAULT 0,
+  coder    varchar(16)        NOT NULL,
   example  varchar(16)        NOT NULL
 )type=innodb;
-- 
GitLab