From 83daa67cc630cf3d8569a08534c7ecf7ef445fb0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 29 Apr 2015 19:15:14 +0200 Subject: [PATCH 01/36] FIX Description of contract line was not visible. --- htdocs/contrat/card.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index f384390ff06..7affb63b9e9 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1302,19 +1302,28 @@ else $productstatic->id=$objp->fk_product; $productstatic->type=$objp->ptype; $productstatic->ref=$objp->pref; - print $productstatic->getNomUrl(1,'',20); + $text = $productstatic->getNomUrl(1,'',20); if ($objp->label) { - print ' - '; + $text .= ' - '; $productstatic->ref=$objp->label; - print $productstatic->getNomUrl(0,'',16); + $text .= $productstatic->getNomUrl(0,'',16); } - if (! empty($conf->global->PRODUIT_DESC_IN_FORM) && !empty($objp->description)) - print '
'.dol_nl2br($objp->description); + $description = $objp->description; + + // Add description in form + if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) + { + $text .= (! empty($objp->description) && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; + $description = ''; // Already added into main visible desc + } + + echo $form->textwithtooltip($text,$description,3,'','',$cursorline,0,(!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):'')); + print ''; } else - { + { print "".dol_htmlentitiesbr($objp->description)."\n"; } // TVA From 060d8a1a38fb01b763c6c49bbf9bd91f46826875 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 29 Apr 2015 19:57:01 +0200 Subject: [PATCH 02/36] FIX Ref/label of product on contract line was not visible, nor into page, nor into PDF. --- htdocs/contrat/card.php | 8 ++-- htdocs/contrat/class/contrat.class.php | 38 +++++++++++-------- .../contract/doc/pdf_strato.modules.php | 14 ++++++- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 7affb63b9e9..e7075b4f22c 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -36,8 +36,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php'; require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; -require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; -if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; if (! empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; @@ -1240,9 +1240,7 @@ else * Lines of contracts */ - if ($conf->product->enabled || $conf->service->enabled) { - $productstatic=new Product($db); - } + $productstatic=new Product($db); $usemargins=0; if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index d2bbe28726a..76a01b9f0c8 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -260,8 +260,8 @@ class Contrat extends CommonObject /** * Activate a contract line * - * @param User $user Objet User qui active le contrat - * @param int $line_id Id de la ligne de detail a activer + * @param User $user Objet User who activate contract + * @param int $line_id Id of line to activate * @param int $date Date d'ouverture * @param int|string $date_end Date fin prevue * @param string $comment A comment typed by user @@ -307,9 +307,9 @@ class Contrat extends CommonObject /** * Close a contract line * - * @param User $user Objet User qui active le contrat - * @param int $line_id Id de la ligne de detail a activer - * @param int $date_end Date fin + * @param User $user Objet User who close contract + * @param int $line_id Id of line to close + * @param int $date_end Date end * @param string $comment A comment typed by user * @return int <0 if KO, >0 if OK */ @@ -600,7 +600,7 @@ class Contrat extends CommonObject $result=$this->fetch_lines(); if ($result < 0) { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); return -3; } @@ -623,7 +623,7 @@ class Contrat extends CommonObject } /** - * Load lignes array into this->lines + * Load lines array into this->lines * * @return ContratLigne[] Return array of contract lines */ @@ -643,7 +643,7 @@ class Contrat extends CommonObject $this->lines=array(); // Selectionne les lignes contrats liees a un produit - $sql = "SELECT p.label, p.description as product_desc, p.ref,"; + $sql = "SELECT p.label as product_label, p.description as product_desc, p.ref as product_ref,"; $sql.= " d.rowid, d.fk_contrat, d.statut, d.description, d.price_ht, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.remise_percent, d.subprice, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht,"; $sql.= " d.total_ht,"; $sql.= " d.total_tva,"; @@ -701,10 +701,12 @@ class Contrat extends CommonObject $line->fk_user_ouverture= $objp->fk_user_ouverture; $line->fk_user_cloture = $objp->fk_user_cloture; - $line->ref = $objp->ref; - $line->libelle = $objp->label; // Label produit - $line->label = $objp->label; // For backward compatibility - $line->product_desc = $objp->product_desc; // Description produit + $line->ref = $objp->product_ref; // deprecated + $line->label = $objp->product_label; // deprecated + $line->libelle = $objp->product_label; // deprecated + $line->product_ref = $objp->product_ref; // Ref product + $line->product_desc = $objp->product_desc; // Description product + $line->product_label = $objp->product_label; // Label product $line->description = $objp->description; @@ -2245,7 +2247,10 @@ class ContratLigne extends CommonObject $sql.= " t.fk_contrat,"; $sql.= " t.fk_product,"; $sql.= " t.statut,"; - $sql.= " t.label,"; + $sql.= " t.label,"; // This field is not used. Only label of product + $sql.= " p.ref as product_ref,"; + $sql.= " p.label as product_label,"; + $sql.= " p.description as product_desc,"; $sql.= " t.description,"; $sql.= " t.date_commande,"; $sql.= " t.date_ouverture_prevue as date_ouverture_prevue,"; @@ -2273,7 +2278,7 @@ class ContratLigne extends CommonObject $sql.= " t.fk_user_ouverture,"; $sql.= " t.fk_user_cloture,"; $sql.= " t.commentaire"; - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as t"; + $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as t LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = t.fk_product"; if ($id) $sql.= " WHERE t.rowid = ".$id; if ($ref) $sql.= " WHERE t.rowid = '".$this->db->escape($ref)."'"; @@ -2292,7 +2297,10 @@ class ContratLigne extends CommonObject $this->fk_contrat = $obj->fk_contrat; $this->fk_product = $obj->fk_product; $this->statut = $obj->statut; - $this->label = $obj->label; + $this->product_ref = $obj->product_ref; + $this->product_label = $obj->product_label; + $this->product_description = $obj->product_description; + $this->label = $obj->label; // deprecated. We do not use this field. Only ref and label of product, and description of contract line $this->description = $obj->description; $this->date_commande = $this->db->jdate($obj->date_commande); $this->date_ouverture_prevue = $this->db->jdate($obj->date_ouverture_prevue); diff --git a/htdocs/core/modules/contract/doc/pdf_strato.modules.php b/htdocs/core/modules/contract/doc/pdf_strato.modules.php index 46364b23d0d..ea75b7cf171 100644 --- a/htdocs/core/modules/contract/doc/pdf_strato.modules.php +++ b/htdocs/core/modules/contract/doc/pdf_strato.modules.php @@ -30,6 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; /** @@ -253,6 +254,7 @@ class pdf_strato extends ModelePDFContract $objectligne = $object->lines[$i]; $valide = $objectligne->id ? $objectligne->fetch($objectligne->id) : 0; + if ($valide > 0 || $object->specimen) { $curX = $this->posxdesc-1; @@ -278,12 +280,20 @@ class pdf_strato extends ModelePDFContract $durationi = $langs->trans("Unknown"); } + $txtpredefinedservice=''; + $txtpredefinedservice = $objectligne->product_ref; + if ($objectligne->product_label) + { + $txtpredefinedservice .= ' - '; + $txtpredefinedservice .= $objectligne->product_label; + } + $txt=''.dol_htmlentitiesbr($outputlangs->transnoentities("Date")." : ".$datei." - ".$outputlangs->transnoentities("Duration")." : ".$durationi,1,$outputlangs->charset_output).''; $desc=dol_htmlentitiesbr($objectligne->desc,1); - $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt,$desc), 0, 1, 0); + $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt,dol_concatdesc($txtpredefinedservice,$desc)), 0, 1, 0); - $nexY = $pdf->GetY(); + $nexY = $pdf->GetY() + 2; $pageposafter=$pdf->getPage(); $pdf->setPage($pageposbefore); $pdf->setTopMargin($this->marge_haute); From 6b3c060d9c44514a2db8c5c70bf218d514286809 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 30 Apr 2015 00:07:30 +0200 Subject: [PATCH 03/36] Fix doxygen --- htdocs/core/class/extrafields.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 821ada820dc..5545dc7cd5d 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -99,7 +99,7 @@ class ExtraFields * @param string $label label of attribute * @param int $type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour') * @param int $pos Position of attribute - * @param int $size Size/length of attribute + * @param string $size Size/length of attribute * @param string $elementtype Element type ('member', 'product', 'thirdparty', ...) * @param int $unique Is field unique or not * @param int $required Is field required or not @@ -118,7 +118,7 @@ class ExtraFields // Create field into database except for separator type which is not stored in database if ($type != 'separate') { - $result=$this->create($attrname,$type,$size,$elementtype, $unique, $required, $default_value,$param); + $result=$this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param); } $err1=$this->errno; if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate') @@ -146,7 +146,7 @@ class ExtraFields * * @param string $attrname code of attribute * @param int $type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour') - * @param int $length Size/length of attribute + * @param string $length Size/length of attribute ('5', '24,8', ...) * @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...) * @param int $unique Is field unique or not * @param int $required Is field required or not @@ -219,7 +219,7 @@ class ExtraFields * @param string $label label of attribute * @param int $type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour', 'float') * @param int $pos Position of attribute - * @param int $size Size/length of attribute + * @param string $size Size/length of attribute ('5', '24,8', ...) * @param string $elementtype Element type ('member', 'product', 'thirdparty', ...) * @param int $unique Is field unique or not * @param int $required Is field required or not From f762d6d7cbc8f022d77a7ad1d631ac50a485a5ee Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Thu, 30 Apr 2015 16:41:52 +0200 Subject: [PATCH 04/36] Add tcpdfbarcode Add modTcpdfbarcode class Add pdf_label class pdf_standardlabel extends pdf_label --- htdocs/core/class/pdf_label.class.php | 546 ++++++++++++++++++ .../barcode/doc/tcpdfbarcode.modules.php | 252 ++++++++ .../doc/pdf_standardlabel.class.php | 195 +------ 3 files changed, 802 insertions(+), 191 deletions(-) create mode 100644 htdocs/core/class/pdf_label.class.php create mode 100644 htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php diff --git a/htdocs/core/class/pdf_label.class.php b/htdocs/core/class/pdf_label.class.php new file mode 100644 index 00000000000..f6b156bb37a --- /dev/null +++ b/htdocs/core/class/pdf_label.class.php @@ -0,0 +1,546 @@ + + * Copyright (C) 2002-2003 Jean-Louis Bergamo + * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2015 Francis Appels + * + * 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 3 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, see . + */ + +/* Inspire de PDF_Label + * PDF_Label - PDF label editing + * @package PDF_Label + * @author Laurent PASSEBECQ + * @copyright 2003 Laurent PASSEBECQ + * disponible ici : http://www.fpdf.org/fr/script/script29.php + */ + +//------------------------------------------------------------------- +// VERSIONS : +// 1.0 : Initial release +// 1.1 : + : Added unit in the constructor +// + : Now Positions start @ (1,1).. then the first image @top-left of a page is (1,1) +// + : Added in the description of a label : +// font-size : defaut char size (can be changed by calling Set_Char_Size(xx); +// paper-size : Size of the paper for this sheet (thanx to Al Canton) +// metric : type of unit used in this description +// You can define your label properties in inches by setting metric to 'in' +// and printing in millimiter by setting unit to 'mm' in constructor. +// Added some labels : +// 5160, 5161, 5162, 5163,5164 : thanx to Al Canton : acanton@adams-blake.com +// 8600 : thanx to Kunal Walia : kunal@u.washington.edu +// + : Added 3mm to the position of labels to avoid errors +//////////////////////////////////////////////////// + +/** + * \file htdocs/core/class/pdf_label.class.php + * \ingroup core + * \brief generate pdf document with labels or cards in Avery or custom format + */ + +require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php'; + + +/** + * Class to generate stick sheet with format Avery or other personalised + */ +class pdf_label +{ + + var $code; // Code of format + var $format; // Array with informations + + // Proprietes privees + var $_Avery_Name = ''; // Nom du format de l'etiquette + var $_Margin_Left = 0; // Marge de gauche de l'etiquette + var $_Margin_Top = 0; // marge en haut de la page avant la premiere etiquette + var $_X_Space = 0; // Espace horizontal entre 2 bandes d'etiquettes + var $_Y_Space = 0; // Espace vertical entre 2 bandes d'etiquettes + var $_X_Number = 0; // NX Nombre d'etiquettes sur la largeur de la page + var $_Y_Number = 0; // NY Nombre d'etiquettes sur la hauteur de la page + var $_Width = 0; // Largeur de chaque etiquette + var $_Height = 0; // Hauteur de chaque etiquette + var $_Char_Size = 10; // Hauteur des caracteres + var $_Line_Height = 10; // Hauteur par defaut d'une ligne + var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values + var $_Metric_Doc = 'mm'; // Type of metric for the doc.. + + var $_COUNTX = 1; + var $_COUNTY = 1; + var $_First = 1; + + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + } + + /** + * Methode qui permet de modifier la taille des caracteres + * Cela modiera aussi l'espace entre chaque ligne + * + * @param PDF &$pdf PDF reference + * @param int $pt point + * @return void + */ + function Set_Char_Size(&$pdf,$pt) + { + if ($pt > 3) { + $this->_Char_Size = $pt; + $this->_Line_Height = $this->_Get_Height_Chars($pt); + $pdf->SetFont('','',$pt); + } + } + + /** + * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) + * - %LOGO% is replace with company logo + * - %PHOTO% is replace with photo provided as parameter + * + * @param PDF &$pdf PDF reference + * @param string $textleft Text left + * @param string $header Header + * @param string $footer Footer + * @param Translate $outputlangs Output langs + * @param string $textright Text right + * @param string $photo Photo (full path to image file used as replacement for key %PHOTOS% into left, right, header or footer text) + * @return void + */ + function Add_PDF_card(&$pdf,$textleft,$header,$footer,$outputlangs,$textright='',$photo='') + { + global $mysoc,$conf,$langs; + global $forceimgscalewidth,$forceimgscaleheight; + + $imgscalewidth=(empty($forceimgscalewidth)?0.3:$forceimgscalewidth); // Scale of image for width (1=Full width of sticker) + $imgscaleheight=(empty($forceimgscalewidth)?0.5:$forceimgscalewidth); // Scale of image for height (1=Full height of sticker) + + // We are in a new page, then we must add a page + if (($this->_COUNTX ==0) && ($this->_COUNTY==0) and (!$this->_First==1)) { + $pdf->AddPage(); + } + $this->_First=0; + $_PosX = $this->_Margin_Left+($this->_COUNTX*($this->_Width+$this->_X_Space)); + $_PosY = $this->_Margin_Top+($this->_COUNTY*($this->_Height+$this->_Y_Space)); + + // Define logo + $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; + if (! is_readable($logo)) + { + $logo=''; + if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) + { + $logo=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; + } + elseif (! empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) + { + $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; + } + } + + // Define photo + if (! empty($photo)) + { + if (! is_readable($photo)) $photo=''; + } + + // Define background image + $backgroundimage=''; + + // Print lines + if ($this->code == "CARD") + { + $this->Tformat=$this->_Avery_Labels["CARD"]; + //$this->_Pointille($pdf,$_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.3,25); + $this->_Croix($pdf,$_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.1,10); + } + + // Background + if ($backgroundimage) + { + $pdf->image($backgroundimage,$_PosX,$_PosY,$this->_Width,$this->_Height); + } + + $xleft=2; $ytop=2; + + // Top + if ($header!='') + { + if ($this->code == "CARD") + { + $pdf->SetDrawColor(128,128,128); + $pdf->Line($_PosX, $_PosY+$this->_Line_Height+1, $_PosX+$this->_Width, $_PosY+$this->_Line_Height+1); // Only 1 mm and not ytop for top text + $pdf->SetDrawColor(0,0,0); + } + $pdf->SetXY($_PosX+$xleft, $_PosY+1); // Only 1 mm and not ytop for top text + $pdf->Cell($this->_Width-2*$xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header),0,1,'C'); + } + + + $ytop+=(empty($header)?0:(1+$this->_Line_Height)); + + // Define widthtouse and heighttouse + $maxwidthtouse=round(($this->_Width - 2*$xleft)*$imgscalewidth); $maxheighttouse=round(($this->_Height - 2*$ytop)*$imgscaleheight); + $defaultratio=($maxwidthtouse/$maxheighttouse); + $widthtouse=$maxwidthtouse; $heighttouse=0; // old value for image + $tmp=dol_getImageSize($photo, false); + if ($tmp['height']) + { + $imgratio=$tmp['width']/$tmp['height']; + if ($imgratio >= $defaultratio) { $widthtouse = $maxwidthtouse; $heighttouse = round($widthtouse / $imgratio); } + else { $heightouse = $maxheighttouse; $widthtouse = round($heightouse * $imgratio); } + } + //var_dump($this->_Width.'x'.$this->_Height.' with border and scale '.$imgscale.' => max '.$maxwidthtouse.'x'.$maxheighttouse.' => We use '.$widthtouse.'x'.$heighttouse);exit; + + // Center + if ($textright=='') // Only a left part + { + // Output left area + if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); + else if ($textleft == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); + else + { + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); + } + } + else if ($textleft!='' && $textright!='') // + { + if ($textleft == '%LOGO%' || $textleft == '%PHOTO%') + { + if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); + else if ($textleft == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); + $pdf->SetXY($_PosX+$xleft+$widthtouse+1, $_PosY+$ytop); + $pdf->MultiCell($this->_Width-$xleft-$xleft-$widthtouse-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); + } + else if ($textright == '%LOGO%' || $textright == '%PHOTO%') + { + if ($textright == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+$this->_Width-$widthtouse-$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); + else if ($textright == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+$this->_Width-$widthtouse-$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell($this->_Width-$widthtouse-$xleft-$xleft-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); + } + else // text on halft left and text on half right + { + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell(round($this->_Width/2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); + $pdf->SetXY($_PosX+round($this->_Width/2), $_PosY+$ytop); + $pdf->MultiCell(round($this->_Width/2)-2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); + } + } + else // Only a right part + { + // Output right area + if ($textright == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+$this->_Width-$widthtouse-$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); + else if ($textright == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+$this->_Width-$widthtouse-$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); + else + { + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell($this->_Width-$xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); + } + } + + // Bottom + if ($footer!='') + { + if ($this->code == "CARD") + { + $pdf->SetDrawColor(128,128,128); + $pdf->Line($_PosX, $_PosY+$this->_Height-$this->_Line_Height-2, $_PosX+$this->_Width, $_PosY+$this->_Height-$this->_Line_Height-2); + $pdf->SetDrawColor(0,0,0); + } + $pdf->SetXY($_PosX, $_PosY+$this->_Height-$this->_Line_Height-1); + $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer),0,1,'C'); + } + //print "$_PosY+$this->_Height-$this->_Line_Height-1
\n"; + + $this->_COUNTY++; + + if ($this->_COUNTY == $this->_Y_Number) { + // Si on est en bas de page, on remonte le 'curseur' de position + $this->_COUNTX++; + $this->_COUNTY=0; + } + + if ($this->_COUNTX == $this->_X_Number) { + // Si on est en bout de page, alors on repart sur une nouvelle page + $this->_COUNTX=0; + $this->_COUNTY=0; + } + } + + + /** + * Print dot line + * + * @param PDF &$pdf PDF reference + * @param int $x1 X1 + * @param int $y1 Y1 + * @param int $x2 X2 + * @param int $y2 Y2 + * @param int $epaisseur Epaisseur + * @param int $nbPointilles Nb pointilles + * @return void + */ + function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15) + { + $pdf->SetLineWidth($epaisseur); + $length=abs($x1-$x2); + $hauteur=abs($y1-$y2); + if($length>$hauteur) { + $Pointilles=($length/$nbPointilles)/2; // taille des pointilles + } + else { + $Pointilles=($hauteur/$nbPointilles)/2; + } + for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) { + for($j=$i;$j<=($i+$Pointilles);$j++) { + if($j<=($x2-1)) { + $pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point + $pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point + } + } + } + for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) { + for($j=$i;$j<=($i+$Pointilles);$j++) { + if($j<=($y2-1)) { + $pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point + $pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point + } + } + } + } + + /** + * Fonction realisant une croix aux 4 coins des cartes + * + * @param PDF &$pdf PDF reference + * @param int $x1 X1 + * @param int $y1 Y1 + * @param int $x2 X2 + * @param int $y2 Y2 + * @param int $epaisseur Epaisseur + * @param int $taille Size + * @return void + */ + function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4) + { + $pdf->SetDrawColor(192,192,192); + + $pdf->SetLineWidth($epaisseur); + $lg=$taille/2; + // croix haut gauche + $pdf->Line($x1,$y1-$lg,$x1,$y1+$lg); + $pdf->Line($x1-$lg,$y1,$x1+$lg,$y1); + // croix bas gauche + $pdf->Line($x1,$y2-$lg,$x1,$y2+$lg); + $pdf->Line($x1-$lg,$y2,$x1+$lg,$y2); + // croix haut droit + $pdf->Line($x2,$y1-$lg,$x2,$y1+$lg); + $pdf->Line($x2-$lg,$y1,$x2+$lg,$y1); + // croix bas droit + $pdf->Line($x2,$y2-$lg,$x2,$y2+$lg); + $pdf->Line($x2-$lg,$y2,$x2+$lg,$y2); + + $pdf->SetDrawColor(0,0,0); + } + + /** + * Convert units (in to mm, mm to in) + * $src and $dest must be 'in' or 'mm' + * + * @param int $value value + * @param string $src from + * @param string $dest to + * @return float value value after conversion + */ + function _Convert_Metric ($value, $src, $dest) + { + if ($src != $dest) { + $tab['in'] = 39.37008; + $tab['mm'] = 1000; + return $value * $tab[$dest] / $tab[$src]; + } else { + return $value; + } + } + + /** + * Give the height for a char size given. + * + * @param int $pt Point + * @return int Height chars + */ + function _Get_Height_Chars($pt) + { + // Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes + $_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10); + if (in_array($pt, array_keys($_Table_Hauteur_Chars))) { + return $_Table_Hauteur_Chars[$pt]; + } else { + return 100; // There is a prob.. + } + } + + /** + * Set format + * + * @param PDF &$pdf PDF reference + * @param string $format Format + * @return void + */ + function _Set_Format(&$pdf, $format) + { + $this->_Metric = $format['metric']; + $this->_Avery_Name = $format['name']; + $this->_Avery_Code = $format['code']; + $this->_Margin_Left = $this->_Convert_Metric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc); + $this->_Margin_Top = $this->_Convert_Metric($format['marginTop'], $this->_Metric, $this->_Metric_Doc); + $this->_X_Space = $this->_Convert_Metric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc); + $this->_Y_Space = $this->_Convert_Metric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc); + $this->_X_Number = $format['NX']; + $this->_Y_Number = $format['NY']; + $this->_Width = $this->_Convert_Metric($format['width'], $this->_Metric, $this->_Metric_Doc); + $this->_Height = $this->_Convert_Metric($format['height'], $this->_Metric, $this->_Metric_Doc); + $this->Set_Char_Size($pdf, $format['font-size']); + } + + + /** + * Function to build PDF on disk, then output on HTTP strem. + * + * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) + * @param Translate $outputlangs Lang object for output language + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param string $outputdir Output directory for pdf file + * @return int 1=OK, 0=KO + */ + function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='') + { + global $user,$conf,$langs,$mysoc,$_Avery_Labels; + + $this->code=$srctemplatepath; + $this->Tformat = $_Avery_Labels[$this->code]; + if (empty($this->Tformat)) { dol_print_error('','ErrorBadTypeForCard'.$this->code); exit; } + $this->type = 'pdf'; + $this->format = $this->Tformat['paper-size']; + + if (! is_object($outputlangs)) $outputlangs=$langs; + // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO + if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; + + $outputlangs->load("main"); + $outputlangs->load("dict"); + $outputlangs->load("companies"); + $outputlangs->load("admin"); + + $title=$outputlangs->transnoentities('Labels'); + $keywords=$title." ".$outputlangs->convToOutputCharset($mysoc->name); + + $dir = (empty($outputdir)?$conf->adherent->dir_temp:$outputdir); + $filename='tmp_address_sheet.pdf'; + $file = $dir."/".$filename; + + if (! file_exists($dir)) + { + if (dol_mkdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } + + $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); + + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); + + $pdf->SetTitle($title); + $pdf->SetSubject($title); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); + $pdf->SetKeyWords($keywords); + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); + + $pdf->SetMargins(0,0); + $pdf->SetAutoPageBreak(false); + + $this->_Metric_Doc = $this->Tformat['metric']; + // Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie + $posX=1; + $posY=1; + if ($posX > 0) $posX--; else $posX=0; + if ($posY > 0) $posY--; else $posY=0; + $this->_COUNTX = $posX; + $this->_COUNTY = $posY; + $this->_Set_Format($pdf, $this->Tformat); + + + $pdf->Open(); + $pdf->AddPage(); + + + // Add each record + foreach($arrayofrecords as $val) + { + // imprime le texte specifique sur la carte + $this->Add_PDF_card($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright'],$val['photo']); + } + + //$pdf->SetXY(10, 295); + //$pdf->Cell($this->_Width, $this->_Line_Height, 'XXX',0,1,'C'); + + + // Output to file + $pdf->Output($file,'F'); + + if (! empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); + + + + // Output to http stream + clearstatcache(); + + $attachment=true; + if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; + $type=dol_mimetype($filename); + + //if ($encoding) header('Content-Encoding: '.$encoding); + if ($type) header('Content-Type: '.$type); + if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); + else header('Content-Disposition: inline; filename="'.$filename.'"'); + + // Ajout directives pour resoudre bug IE + header('Cache-Control: Public, must-revalidate'); + header('Pragma: public'); + + readfile($file); + + return 1; + } +} diff --git a/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php new file mode 100644 index 00000000000..d608543d5f5 --- /dev/null +++ b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php @@ -0,0 +1,252 @@ + + * Copyright (C) 2005 Regis Houssin + * Copyright (C) 2015 Francis Appels + * + * 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 3 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, see . + */ + +/** + * \file htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php + * \ingroup barcode + * \brief File of class to manage barcode numbering with tcpdf library + */ + +require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/modules_barcode.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // This is to include def like $genbarcode_loc and $font_loc + +/** + * Class to generate barcode images using tcpdf barcode generator + */ +class modTcpdfbarcode extends ModeleBarCode +{ + var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' + var $error=''; + var $is2d = false; + + /** + * Return description of numbering model + * + * @return string Text with description + */ + function info() + { + global $langs; + + return 'TCPDF-barcode'; + } + + /** + * Return if a module can be used or not + * + * @return boolean true if module can be used + */ + function isEnabled() + { + return true; + } + + /** + * Test si les numeros deja en vigueur dans la base ne provoquent pas de + * de conflits qui empechera cette numerotation de fonctionner. + * + * @return boolean false si conflit, true si ok + */ + function canBeActivated() + { + global $langs; + + return true; + } + + /** + * Return true if encoding is supported + * + * @param string $encoding Encoding norm + * @return int >0 if supported, 0 if not + */ + function encodingIsSupported($encoding) + { + $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); + if (empty($tcpdfEncoding)) { + return 0; + } else { + return 1; + } + } + + /** + * Return an image file on the fly (no need to write on disk) + * + * @param String $code Value to encode + * @param String $encoding Mode of encoding + * @param String $readable Code can be read + * @return int <0 if KO, >0 if OK + */ + function buildBarCode($code,$encoding,$readable='Y') + { + global $_GET; + + $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); + if (empty($tcpdfEncoding)) return -1; + + $color = array(0,0,0); + + $_GET["code"]=$code; + $_GET["type"]=$encoding; + $_GET["height"]=$height; + $_GET["readable"]=$readable; + + if ($code) { + // Load the tcpdf barcode class + if ($this->is2d) { + $height = 3; + $width = 3; + require_once TCPDF_PATH.'tcpdf_barcodes_2d.php'; + $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding); + } else { + $height = 50; + $width = 1; + require_once TCPDF_PATH.'tcpdf_barcodes_1d.php'; + $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding); + } + + dol_syslog("buildBarCode::TCPDF.getBarcodePNG"); + $barcodeobj->getBarcodePNG($width, $height, $color); + + return 1; + } else { + return -2; + } + } + + /** + * Save an image file on disk (with no output) + * + * @param String $code Value to encode + * @param String $encoding Mode of encoding + * @param String $readable Code can be read + * @return int <0 if KO, >0 if OK + */ + function writeBarCode($code,$encoding,$readable='Y') + { + global $conf,$_GET; + + dol_mkdir($conf->barcode->dir_temp); + $file=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; + + $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); + if (empty($tcpdfEncoding)) return -1; + + $color = array(0,0,0); + + $_GET["code"]=$code; + $_GET["type"]=$encoding; + $_GET["height"]=$height; + $_GET["readable"]=$readable; + + if ($code) { + // Load the tcpdf barcode class + if ($this->is2d) { + $height = 1; + $width = 1; + require_once TCPDF_PATH.'tcpdf_barcodes_2d.php'; + $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding); + } else { + $height = 50; + $width = 1; + require_once TCPDF_PATH.'tcpdf_barcodes_1d.php'; + $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding); + } + + dol_syslog("writeBarCode::TCPDF.getBarcodePngData"); + if ($imageData = $barcodeobj->getBarcodePngData($width, $height, $color)) { + if (function_exists('imagecreate')) { + $imageData = imagecreatefromstring($imageData); + } + if (imagepng($imageData, $file)) { + return 1; + } else { + return -3; + } + } else { + return -4; + } + } else { + return -2; + } + } + + /** + * get available output_modes for tcpdf class wth its translated description + * + * @param string $dolEncodingType dolibarr barcode encoding type + * @return string tcpdf encoding type + */ + private function getTcpdfEncodingType($dolEncodingType) + { + $tcpdf1dEncodingTypes = array( + 'C39' => 'C39', + 'C39+' => 'C39+', + 'C39E' => 'C39E', + 'C39E+' => 'C39E+', + 'S25' => 'S25', + 'S25+' => 'S25+', + 'I25' => 'I25', + 'I25+' => 'I25+', + 'C128' => 'C128', + 'C128A' => 'C128A', + 'C128B' => 'C128B', + 'C128C' => 'C128C', + 'EAN2' => 'EAN2', + 'EAN5' => 'EAN5', + 'EAN8' => 'EAN8', + 'EAN13' => 'EAN13', + 'ISBN' => 'EAN13', + 'UPC' => 'UPCA', + 'UPCE' => 'UPCE', + 'MSI' => 'MSI', + 'MSI+' => 'MSI+', + 'POSTNET' => 'POSTNET', + 'PLANET' => 'PLANET', + 'RMS4CC' => 'RMS4CC', + 'KIX' => 'KIX', + 'IMB' => 'IMB', + 'CODABAR' => 'CODABAR', + 'CODE11' => 'CODE11', + 'PHARMA' => 'PHARMA', + 'PHARMA2T' => 'PHARMA2T' + ); + + $tcpdf2dEncodingTypes = array( + 'DATAMATRIX' => 'DATAMATRIX', + 'PDF417' => 'PDF417', + 'QRCODE' => 'QRCODE,L', + 'QRCODE,L' => 'QRCODE,L', + 'QRCODE,M' => 'QRCODE,M', + 'QRCODE,Q' => 'QRCODE,Q', + 'QRCODE,H' => 'QRCODE,H' + ); + + if (array_key_exists($dolEncodingType, $tcpdf1dEncodingTypes)) { + $this->is2d = false; + return $tcpdf1dEncodingTypes[$dolEncodingType]; + } else if (array_key_exists($dolEncodingType, $tcpdf2dEncodingTypes)) { + $this->is2d = true; + return $tcpdf2dEncodingTypes[$dolEncodingType]; + } else { + return ''; + } + } +} \ No newline at end of file diff --git a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php index 193de960bb8..e8eaeabf12e 100644 --- a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php +++ b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2001-2003 Rodolphe Quiedeville * Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2015 Francis Appels * * 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 @@ -50,74 +51,20 @@ * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise */ -require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php'; - +require_once DOL_DOCUMENT_ROOT.'/core/class/pdf_label.class.php'; /** * Class to generate stick sheet with format Avery or other personalised */ -class pdf_standardlabel +class pdf_standardlabel extends pdf_label { - var $code; // Code of format - var $format; // Array with informations - - // Proprietes privees - var $_Avery_Name = ''; // Nom du format de l'etiquette - var $_Margin_Left = 0; // Marge de gauche de l'etiquette - var $_Margin_Top = 0; // marge en haut de la page avant la premiere etiquette - var $_X_Space = 0; // Espace horizontal entre 2 bandes d'etiquettes - var $_Y_Space = 0; // Espace vertical entre 2 bandes d'etiquettes - var $_X_Number = 0; // NX Nombre d'etiquettes sur la largeur de la page - var $_Y_Number = 0; // NY Nombre d'etiquettes sur la hauteur de la page - var $_Width = 0; // Largeur de chaque etiquette - var $_Height = 0; // Hauteur de chaque etiquette - var $_Char_Size = 10; // Hauteur des caracteres - var $_Line_Height = 10; // Hauteur par defaut d'une ligne - var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values - var $_Metric_Doc = 'mm'; // Type of metric for the doc.. - - var $_COUNTX = 1; - var $_COUNTY = 1; - var $_First = 1; - - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - } - - /** - * Methode qui permet de modifier la taille des caracteres - * Cela modiera aussi l'espace entre chaque ligne - * - * @param PDF $pdf PDF - * @param int $pt point - * @return void - */ - function Set_Char_Size(&$pdf,$pt) - { - if ($pt > 3) { - $this->_Char_Size = $pt; - $this->_Line_Height = $this->_Get_Height_Chars($pt); - $pdf->SetFont('','',$pt); - } - } - /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - %LOGO% is replace with company logo * - %PHOTO% is replace with photo provided as parameter * - * @param PDF $pdf PDF + * @param PDF &$pdf PDF reference * @param string $textleft Text left * @param string $header Header * @param string $footer Footer @@ -289,140 +236,6 @@ class pdf_standardlabel } - /** - * Print dot line - * - * @param PDF $pdf PDF - * @param int $x1 X1 - * @param int $y1 Y1 - * @param int $x2 X2 - * @param int $y2 Y2 - * @param int $epaisseur Epaisseur - * @param int $nbPointilles Nb pointilles - * @return void - */ - function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15) - { - $pdf->SetLineWidth($epaisseur); - $length=abs($x1-$x2); - $hauteur=abs($y1-$y2); - if($length>$hauteur) { - $Pointilles=($length/$nbPointilles)/2; // taille des pointilles - } - else { - $Pointilles=($hauteur/$nbPointilles)/2; - } - for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) { - for($j=$i;$j<=($i+$Pointilles);$j++) { - if($j<=($x2-1)) { - $pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point - $pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point - } - } - } - for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) { - for($j=$i;$j<=($i+$Pointilles);$j++) { - if($j<=($y2-1)) { - $pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point - $pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point - } - } - } - } - - /** - * Fonction realisant une croix aux 4 coins des cartes - * - * @param PDF $pdf PDF - * @param int $x1 X1 - * @param int $y1 Y1 - * @param int $x2 X2 - * @param int $y2 Y2 - * @param int $epaisseur Epaisseur - * @param int $taille Size - * @return void - */ - function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4) - { - $pdf->SetDrawColor(192,192,192); - - $pdf->SetLineWidth($epaisseur); - $lg=$taille/2; - // croix haut gauche - $pdf->Line($x1,$y1-$lg,$x1,$y1+$lg); - $pdf->Line($x1-$lg,$y1,$x1+$lg,$y1); - // croix bas gauche - $pdf->Line($x1,$y2-$lg,$x1,$y2+$lg); - $pdf->Line($x1-$lg,$y2,$x1+$lg,$y2); - // croix haut droit - $pdf->Line($x2,$y1-$lg,$x2,$y1+$lg); - $pdf->Line($x2-$lg,$y1,$x2+$lg,$y1); - // croix bas droit - $pdf->Line($x2,$y2-$lg,$x2,$y2+$lg); - $pdf->Line($x2-$lg,$y2,$x2+$lg,$y2); - - $pdf->SetDrawColor(0,0,0); - } - - /** - * Convert units (in to mm, mm to in) - * $src and $dest must be 'in' or 'mm' - * - * @param int $value value - * @param string $src from - * @param string $dest to - * @return float value value after conversion - */ - function _Convert_Metric ($value, $src, $dest) - { - if ($src != $dest) { - $tab['in'] = 39.37008; - $tab['mm'] = 1000; - return $value * $tab[$dest] / $tab[$src]; - } else { - return $value; - } - } - - /** - * Give the height for a char size given. - * - * @param int $pt Point - * @return int Height chars - */ - function _Get_Height_Chars($pt) - { - // Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes - $_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10); - if (in_array($pt, array_keys($_Table_Hauteur_Chars))) { - return $_Table_Hauteur_Chars[$pt]; - } else { - return 100; // There is a prob.. - } - } - - /** - * Set format - * - * @param PDF $pdf PDF - * @param string $format Format - * @return void - */ - function _Set_Format(&$pdf, $format) - { - $this->_Metric = $format['metric']; - $this->_Avery_Name = $format['name']; - $this->_Avery_Code = $format['code']; - $this->_Margin_Left = $this->_Convert_Metric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc); - $this->_Margin_Top = $this->_Convert_Metric($format['marginTop'], $this->_Metric, $this->_Metric_Doc); - $this->_X_Space = $this->_Convert_Metric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc); - $this->_Y_Space = $this->_Convert_Metric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc); - $this->_X_Number = $format['NX']; - $this->_Y_Number = $format['NY']; - $this->_Width = $this->_Convert_Metric($format['width'], $this->_Metric, $this->_Metric_Doc); - $this->_Height = $this->_Convert_Metric($format['height'], $this->_Metric, $this->_Metric_Doc); - $this->Set_Char_Size($pdf, $format['font-size']); - } /** From afc582a3696d33653c1324e0c11552d9eee69404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 30 Apr 2015 17:19:21 +0200 Subject: [PATCH 05/36] Fixed SQL table reference for members types in export FIX #2712 --- htdocs/core/modules/modAdherent.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/modAdherent.class.php b/htdocs/core/modules/modAdherent.class.php index 56037c9fb16..c135c22ff8a 100644 --- a/htdocs/core/modules/modAdherent.class.php +++ b/htdocs/core/modules/modAdherent.class.php @@ -174,7 +174,7 @@ class modAdherent extends DolibarrModules $this->export_label[$r]='MembersAndSubscriptions'; $this->export_permission[$r]=array(array("adherent","export")); $this->export_fields_array[$r]=array('a.rowid'=>'Id','a.civility'=>"UserTitle",'a.lastname'=>"Lastname",'a.firstname'=>"Firstname",'a.login'=>"Login",'a.morphy'=>'Nature','a.societe'=>'Company','a.address'=>"Address",'a.zip'=>"Zip",'a.town'=>"Town",'d.nom'=>"State",'co.code'=>"CountryCode",'co.label'=>"Country",'a.phone'=>"PhonePro",'a.phone_perso'=>"PhonePerso",'a.phone_mobile'=>"PhoneMobile",'a.email'=>"Email",'a.birth'=>"Birthday",'a.statut'=>"Status",'a.photo'=>"Photo",'a.note'=>"Note",'a.datec'=>'DateCreation','a.datevalid'=>'DateValidation','a.tms'=>'DateLastModification','a.datefin'=>'DateEndSubscription','ta.rowid'=>'MemberTypeId','ta.libelle'=>'MemberTypeLabel','c.rowid'=>'SubscriptionId','c.dateadh'=>'DateSubscription','c.cotisation'=>'Amount'); - $this->export_TypeFields_array[$r]=array('a.civility'=>"Text",'a.lastname'=>"Text",'a.firstname'=>"Text",'a.login'=>"Text",'a.morphy'=>'Text','a.societe'=>'Text','a.address'=>"Text",'a.zip'=>"Text",'a.town'=>"Text",'d.nom'=>"Text",'co.code'=>'Text','co.label'=>"Text",'a.phone'=>"Text",'a.phone_perso'=>"Text",'a.phone_mobile'=>"Text",'a.email'=>"Text",'a.birth'=>"Date",'a.statut'=>"Status",'a.note'=>"Text",'a.datec'=>'Date','a.datevalid'=>'Date','a.tms'=>'Date','a.datefin'=>'Date','ta.rowid'=>'List:fk_adherent_type:libelle','ta.libelle'=>'Text','c.dateadh'=>'Date','c.cotisation'=>'Number'); + $this->export_TypeFields_array[$r]=array('a.civility'=>"Text",'a.lastname'=>"Text",'a.firstname'=>"Text",'a.login'=>"Text",'a.morphy'=>'Text','a.societe'=>'Text','a.address'=>"Text",'a.zip'=>"Text",'a.town'=>"Text",'d.nom'=>"Text",'co.code'=>'Text','co.label'=>"Text",'a.phone'=>"Text",'a.phone_perso'=>"Text",'a.phone_mobile'=>"Text",'a.email'=>"Text",'a.birth'=>"Date",'a.statut'=>"Status",'a.note'=>"Text",'a.datec'=>'Date','a.datevalid'=>'Date','a.tms'=>'Date','a.datefin'=>'Date','ta.rowid'=>'List:adherent_type:libelle','ta.libelle'=>'Text','c.dateadh'=>'Date','c.cotisation'=>'Number'); $this->export_entities_array[$r]=array('a.rowid'=>'member','a.civility'=>"member",'a.lastname'=>"member",'a.firstname'=>"member",'a.login'=>"member",'a.morphy'=>'member','a.societe'=>'member','a.address'=>"member",'a.zip'=>"member",'a.town'=>"member",'d.nom'=>"member",'co.code'=>"member",'co.label'=>"member",'a.phone'=>"member",'a.phone_perso'=>"member",'a.phone_mobile'=>"member",'a.email'=>"member",'a.birth'=>"member",'a.statut'=>"member",'a.photo'=>"member",'a.note'=>"member",'a.datec'=>'member','a.datevalid'=>'member','a.tms'=>'member','a.datefin'=>'member','ta.rowid'=>'member_type','ta.libelle'=>'member_type','c.rowid'=>'subscription','c.dateadh'=>'subscription','c.cotisation'=>'subscription'); // Add extra fields From 95058607a400c8d4cc6aabadd45e1330f71cc92f Mon Sep 17 00:00:00 2001 From: aspangaro Date: Fri, 1 May 2015 07:13:04 +0200 Subject: [PATCH 06/36] Fix : ER Typo on all variable $_SERVER & traduce of button "Edit" not works --- htdocs/expensereport/card.php | 41 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index fad813a570b..64d47efd23e 100755 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2,6 +2,7 @@ /* Copyright (C) 2003 Rodolphe Quiedeville * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2015 Alexandre Spangaro * * 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 @@ -164,7 +165,7 @@ if ($action == 'update' && $user->rights->expensereport->creer) $result = $object->update($user); if ($result > 0) { - header("Location: ".$_SEVER["PHP_SELF"]."?id=".$_POST['id']); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']); exit; } else @@ -244,7 +245,7 @@ if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user { $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); setEventMessage($mesg); - header("Location: ".$_SEVER["PHP_SELF"]."?id=".$id); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else @@ -349,7 +350,7 @@ if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id // SEND $result=$mailfile->sendfile(); if ($result): - Header("Location: ".$_SEVER["PHP_SELF"]."?id=".$id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; endif; @@ -454,7 +455,7 @@ if ($action == "confirm_approve" && GETPOST("confirm") == "yes" && $id > 0 && $u $result=$mailfile->sendfile(); if ($result): setEventMessage($langs->trans("MailSuccessfulySent",$emailFrom,$emailTo)); - Header("Location: ".$_SEVER["PHP_SELF"]."?id=".$id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; else: setEventMessage($langs->trans("ErrorFailedToSendMail",$emailFrom,$emailTo),'errors'); @@ -540,7 +541,7 @@ if ($action == "confirm_refuse" && GETPOST('confirm')=="yes" && $id > 0 && $user if ($result) { setEventMessage($langs->trans("MailSuccessfulySent",$emailFrom,$emailTo)); - Header("Location: ".$_SEVER["PHP_SELF"]."?id=".$id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else @@ -624,7 +625,7 @@ if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && GETPOST('detail_ $result=$mailfile->sendfile(); if ($result) { - header("Location: ".$_SEVER["PHP_SELF"]."?id=".$id); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else @@ -793,7 +794,7 @@ if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && if ($result > 0) { - header("Location: ".$_SEVER["PHP_SELF"]."?id=".$id); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else @@ -1324,27 +1325,27 @@ else dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip'); if ($action == 'save'): - $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_save","","",1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_save","","",1); if ($ret == 'html') print '
'; endif; if ($action == 'save_from_refuse'): - $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_save_from_refuse","","",1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_save_from_refuse","","",1); if ($ret == 'html') print '
'; endif; if ($action == 'delete'): - $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete","","",1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete","","",1); if ($ret == 'html') print '
'; endif; if ($action == 'validate'): - $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("ValideTrip"),$langs->trans("ConfirmValideTrip"),"confirm_approve","","",1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("ValideTrip"),$langs->trans("ConfirmValideTrip"),"confirm_approve","","",1); if ($ret == 'html') print '
'; endif; if ($action == 'paid'): - $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("PaidTrip"),$langs->trans("ConfirmPaidTrip"),"confirm_paid","","",1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("PaidTrip"),$langs->trans("ConfirmPaidTrip"),"confirm_paid","","",1); if ($ret == 'html') print '
'; endif; @@ -1356,20 +1357,20 @@ else } if ($action == 'brouillonner'): - $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("BrouillonnerTrip"),$langs->trans("ConfirmBrouillonnerTrip"),"confirm_brouillonner","","",1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("BrouillonnerTrip"),$langs->trans("ConfirmBrouillonnerTrip"),"confirm_brouillonner","","",1); if ($ret == 'html') print '
'; endif; if ($action == 'refuse') // Deny { $array_input = array('text'=>$langs->trans("ConfirmRefuseTrip"), array('type'=>"text",'label'=>$langs->trans("Comment"),'name'=>"detail_refuse",'size'=>"50",'value'=>"")); - $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("Deny"),'',"confirm_refuse",$array_input,"yes",1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("Deny"),'',"confirm_refuse",$array_input,"yes",1); if ($ret == 'html') print '
'; } if ($action == 'delete_line') { - $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id."&rowid=".$_GET['rowid'],$langs->trans("DeleteLine"),$langs->trans("ConfirmDeleteLine"),"confirm_delete_line",'','yes',1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id."&rowid=".$_GET['rowid'],$langs->trans("DeleteLine"),$langs->trans("ConfirmDeleteLine"),"confirm_delete_line",'','yes',1); if ($ret == 'html') print '
'; } @@ -1805,18 +1806,18 @@ if ($action != 'create' && $action != 'edit') if ($object->fk_user_author == $user->id) { // Modifier - print ''.$langs->trans('ModifyInfoGen').''; + print ''.$langs->trans('Modify').''; // Validate if (count($object->lines) > 0 || count($object->lignes) > 0) { - print ''.$langs->trans('ValidateAndSubmit').''; + print ''.$langs->trans('ValidateAndSubmit').''; } if ($user->rights->expensereport->supprimer) { // Supprimer - print ''.$langs->trans('Delete').''; + print ''.$langs->trans('Delete').''; } } } @@ -1831,12 +1832,12 @@ if ($action != 'create' && $action != 'edit') if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // Modifier - print ''.$langs->trans('ModifyInfoGen').''; + print ''.$langs->trans('Modify').''; // Brouillonner (le statut refusée est identique à brouillon) //print ''.$langs->trans('BROUILLONNER').''; // Enregistrer depuis le statut "Refusée" - print ''.$langs->trans('ValidateAndSubmit').''; + print ''.$langs->trans('ValidateAndSubmit').''; if ($user->rights->expensereport->supprimer) { From b03a9dffeb78a642b69a7dedb1f91de46a59bdd4 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Fri, 1 May 2015 07:18:19 +0200 Subject: [PATCH 07/36] Fix : ER Correct Link --- htdocs/expensereport/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 64d47efd23e..b66ff15494b 100755 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -218,7 +218,7 @@ if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user $subject = $langs->trans("ExpenseReportWaitingForApproval"); // CONTENT - $link = $urlwithroot.'/expenserecord/card.php?id='.$object->id; + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $message = $langs->trans("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link); // Rebuild pdf From b0eee2976c21f2b567448662fe334c38a2bca0d9 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Fri, 1 May 2015 08:46:37 +0200 Subject: [PATCH 08/36] New: ER add badge on tab document --- htdocs/core/lib/expensereport.lib.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/expensereport.lib.php b/htdocs/core/lib/expensereport.lib.php index 0bd2c0f721b..3b54c43af99 100644 --- a/htdocs/core/lib/expensereport.lib.php +++ b/htdocs/core/lib/expensereport.lib.php @@ -45,8 +45,12 @@ function expensereport_prepare_head($object) // $this->tabs = array('entity:-tabname); to remove a tab complete_head_from_modules($conf,$langs,$object,$head,$h,'expensereport'); + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $upload_dir = $conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/expensereport/document.php?id='.$object->id; - $head[$h][1] = $langs->trans("Documents"); + $head[$h][1] = $langs->trans('Documents'); + if($nbFiles > 0) $head[$h][1].= ' '.$nbFiles.''; $head[$h][2] = 'documents'; $h++; From 93937fe7f3cb4ad097830fdca590f4b7ec9058d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 30 Apr 2015 11:48:32 +0200 Subject: [PATCH 09/36] Allow exporting projects without a third party FIX #2729 --- htdocs/core/modules/modProjet.class.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/modProjet.class.php b/htdocs/core/modules/modProjet.class.php index 6bc21adb445..f76158d3a0c 100644 --- a/htdocs/core/modules/modProjet.class.php +++ b/htdocs/core/modules/modProjet.class.php @@ -286,11 +286,9 @@ class modProjet extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON p.rowid = extra.fk_object'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task as pt ON p.rowid = pt.fk_projet"; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_task_extrafields as extra2 ON pt.rowid = extra2.fk_object'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task,"; - $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'societe as s'; - $this->export_sql_end[$r] .=' WHERE p.fk_soc = s.rowid'; - $this->export_sql_end[$r] .=' AND p.entity = '.$conf->entity; - + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task"; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON p.fk_soc = s.rowid'; + $this->export_sql_end[$r] .=' WHERE p.entity = '.$conf->entity; } From 31a8e38d372b350350515bec894d6d3162502b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 1 May 2015 16:01:57 +0200 Subject: [PATCH 10/36] Allow exporting projects without a third party FIX #2729 Conflicts: htdocs/core/modules/modProjet.class.php --- htdocs/core/modules/modProjet.class.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/modProjet.class.php b/htdocs/core/modules/modProjet.class.php index 7bc9a51c022..e11e801a77b 100644 --- a/htdocs/core/modules/modProjet.class.php +++ b/htdocs/core/modules/modProjet.class.php @@ -292,11 +292,9 @@ class modProjet extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON p.rowid = extra.fk_object'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task as pt ON p.rowid = pt.fk_projet"; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_task_extrafields as extra2 ON pt.rowid = extra2.fk_object'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task,"; - $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'societe as s'; - $this->export_sql_end[$r] .=' WHERE p.fk_soc = s.rowid'; - $this->export_sql_end[$r] .=' AND p.entity IN ('.getEntity('project',1).')'; - + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task"; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON p.fk_soc = s.rowid'; + $this->export_sql_end[$r] .=' WHERE p.entity = '.$conf->entity; } From e3f980e32c0e9b2e38a74bb190d41552cb48d6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 1 May 2015 18:44:27 +0200 Subject: [PATCH 11/36] Typo --- htdocs/commande/class/commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 2f85461887e..ad26b0c409d 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1539,7 +1539,7 @@ class Commande extends CommonOrder if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; - // Retreive all extrafield for invoice + // Retrieve all extrafields for invoice // fetch optionals attributes and labels require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields=new ExtraFields($this->db); From d8af7a45f87f438a569a641e67c7aad04420aea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 1 May 2015 19:10:47 +0200 Subject: [PATCH 12/36] Typo --- htdocs/webservices/server_thirdparty.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index aaed36ac9d8..c7ca5911d62 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -121,7 +121,7 @@ $thirdparty_fields= array( 'vat_used' => array('name'=>'vat_used','type'=>'xsd:string'), 'vat_number' => array('name'=>'vat_number','type'=>'xsd:string')); -//Retreive all extrafield for thirdsparty +// Retrieve all extrafields for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('societe',true); @@ -329,7 +329,7 @@ function getThirdParty($authentication,$id='',$ref='',$ref_ext='') 'note_private' => $thirdparty->note_private, 'note_public' => $thirdparty->note_public); - //Retreive all extrafield for thirdsparty + // Retrieve all extrafields for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('societe',true); @@ -445,7 +445,7 @@ function createThirdParty($authentication,$thirdparty) $newobject->canvas=$thirdparty['canvas']; $newobject->particulier=$thirdparty['individual']; - //Retreive all extrafield for thirdsparty + // Retrieve all extrafields for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('societe',true); @@ -576,7 +576,7 @@ function updateThirdParty($authentication,$thirdparty) $object->canvas=$thirdparty['canvas']; - //Retreive all extrafield for thirdsparty + // Retrieve all extrafields for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('societe',true); From 1174c67b076ad4ea4b6a3981460fefc11989fe44 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sat, 2 May 2015 06:42:06 +0200 Subject: [PATCH 13/36] Accountancy - Add key language & prepare journal for expense report --- htdocs/accountancy/admin/journaux.php | 8 ++++---- htdocs/core/modules/modAccounting.class.php | 7 ++++++- htdocs/langs/en_US/accountancy.lang | 12 +++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/htdocs/accountancy/admin/journaux.php b/htdocs/accountancy/admin/journaux.php index 03fd8684f50..5a305d87f2c 100644 --- a/htdocs/accountancy/admin/journaux.php +++ b/htdocs/accountancy/admin/journaux.php @@ -1,10 +1,10 @@ - * Copyright (C) 2013-2014 Alexandre Spangaro + * Copyright (C) 2013-2015 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * Copyright (C) 2014 Marcos García * Copyright (C) 2014 Juanjo Menent - * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015 Jean-François Ferry * * 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 @@ -48,8 +48,8 @@ $list = array ( 'ACCOUNTING_SELL_JOURNAL', 'ACCOUNTING_PURCHASE_JOURNAL', 'ACCOUNTING_SOCIAL_JOURNAL', - 'ACCOUNTING_CASH_JOURNAL', - 'ACCOUNTING_MISCELLANEOUS_JOURNAL' + 'ACCOUNTING_MISCELLANEOUS_JOURNAL', + 'ACCOUNTING_EXPENSEREPORT_JOURNAL' ); /* diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index 70a52dc90e1..84e18048e84 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -69,7 +69,7 @@ class modAccounting extends DolibarrModules $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array("modComptabilite"); // List of modules are in conflict with this module $this->phpmin = array(5, 3); // Minimum version of PHP required by module - $this->need_dolibarr_version = array(3, 6); // Minimum version of Dolibarr required by module + $this->need_dolibarr_version = array(3, 7); // Minimum version of Dolibarr required by module $this->langfiles = array("accountancy"); // Constants @@ -191,6 +191,11 @@ class modAccounting extends DolibarrModules "yesno", "1" ); + $this->const[22] = array( + "ACCOUNTING_EXPENSEREPORT_JOURNAL", + "chaine", + "ER" + ); // Tabs $this->tabs = array(); diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index b09dab7f764..c119a002641 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -1,6 +1,13 @@ # Dolibarr language file - en_US - Accounting Expert CHARSET=UTF-8 - +ACCOUNTING_EXPORT_SEPARATORCSV=Column separator for export file +ACCOUNTING_EXPORT_DATE=Date format for export file +ACCOUNTING_EXPORT_PIECE=Export the number of piece ? +ACCOUNTING_EXPORT_GLOBAL_ACCOUNT=Export with global account ? +ACCOUNTING_EXPORT_LABEL=Export the label ? +ACCOUNTING_EXPORT_AMOUNT=Export the amount ? +ACCOUNTING_EXPORT_DEVISE=Export the devise ? + Accounting=Accounting Globalparameters=Global parameters Chartofaccounts=Chart of accounts @@ -81,9 +88,8 @@ ACCOUNTING_LENGTH_AACCOUNT=Length of the third party accounts ACCOUNTING_SELL_JOURNAL=Sell journal ACCOUNTING_PURCHASE_JOURNAL=Purchase journal -ACCOUNTING_BANK_JOURNAL=Bank journal -ACCOUNTING_CASH_JOURNAL=Cash journal ACCOUNTING_MISCELLANEOUS_JOURNAL=Miscellaneous journal +ACCOUNTING_EXPENSEREPORT_JOURNAL=Expense report journal ACCOUNTING_SOCIAL_JOURNAL=Social journal ACCOUNTING_ACCOUNT_TRANSFER_CASH=Account of transfer From 816356375310c7754a6b1cf84d08db67b2db719f Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 3 May 2015 06:12:02 +0200 Subject: [PATCH 14/36] New: Add option to show long or short (by default) label in select_month() --- htdocs/admin/company.php | 2 +- htdocs/core/class/html.formother.class.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 561e299b937..d5c78761989 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -543,7 +543,7 @@ if ($action == 'edit' || $action == 'updateedit') $var=!$var; print ''; - print $formother->select_month($conf->global->SOCIETE_FISCAL_MONTH_START,'fiscalmonthstart',1) . ''; + print $formother->select_month($conf->global->SOCIETE_FISCAL_MONTH_START,'fiscalmonthstart',0,1) . ''; print ""; diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 3233b479b6c..7dac2c2e527 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -776,17 +776,19 @@ class FormOther * Return HTML combo list of month * * @param string $selected Preselected value - * @param string $htmlname Nom de la zone select - * @param int $useempty Affiche valeur vide dans liste + * @param string $htmlname Name of HTML select object + * @param int $useempty Show empty in list + * @param int $longlabel Show long label * @return string */ - function select_month($selected='',$htmlname='monthid',$useempty=0) + function select_month($selected='',$htmlname='monthid',$useempty=0,$longlabel=0) { global $langs; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - $montharray = monthArray($langs, 1); // Get array + if ($longlabel) $montharray = monthArray($langs, 0); // Get array + else $montharray = monthArray($langs, 1); $select_month = ''; if ($useempty) From 3a5f6db571b8149ad4653bf8e0609e4eacf5fc06 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 3 May 2015 06:18:21 +0200 Subject: [PATCH 16/36] Spaces 2 : return of the vilains --- htdocs/core/class/html.formother.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index e1cbfd52047..7d93289a2fb 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -773,13 +773,13 @@ class FormOther } /** - * Return HTML combo list of month + * Return HTML combo list of month * - * @param string $selected Preselected value + * @param string $selected Preselected value * @param string $htmlname Name of HTML select object * @param int $useempty Show empty in list * @param int $longlabel Show long label - * @return string + * @return string */ function select_month($selected='',$htmlname='monthid',$useempty=0,$longlabel=0) { From 7062dc7b2edc480e1d2e07e61fe2ddb8d77763e2 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 3 May 2015 06:20:34 +0200 Subject: [PATCH 17/36] Spaces 3 : the darkside --- htdocs/core/class/html.formother.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 7d93289a2fb..d14c748e80e 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -775,10 +775,10 @@ class FormOther /** * Return HTML combo list of month * - * @param string $selected Preselected value - * @param string $htmlname Name of HTML select object - * @param int $useempty Show empty in list - * @param int $longlabel Show long label + * @param string $selected Preselected value + * @param string $htmlname Name of HTML select object + * @param int $useempty Show empty in list + * @param int $longlabel Show long label * @return string */ function select_month($selected='',$htmlname='monthid',$useempty=0,$longlabel=0) From 6dfd125872bc3543282ad3875416b73585f7ac9a Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 3 May 2015 06:25:50 +0200 Subject: [PATCH 18/36] Spaces 4 : Stop Shouting ! --- htdocs/core/class/html.formother.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index d14c748e80e..9266b8aa3a6 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -775,11 +775,11 @@ class FormOther /** * Return HTML combo list of month * - * @param string $selected Preselected value + * @param string $selected Preselected value * @param string $htmlname Name of HTML select object * @param int $useempty Show empty in list * @param int $longlabel Show long label - * @return string + * @return string */ function select_month($selected='',$htmlname='monthid',$useempty=0,$longlabel=0) { From 55eecf3f2510dea54963d710f16f49eb0523a5db Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 3 May 2015 07:05:19 +0200 Subject: [PATCH 19/36] ER add price format in total of list --- htdocs/expensereport/list.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index 9ef9c05a328..4faff0ecbb4 100755 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -249,9 +249,9 @@ if ($resql) print ''; print ''.$langs->trans("Total").''; - print ''.$total_total_ht.''; - print ''.$total_total_tva.''; - print ''.$total_total_ttc.''; + print ''.price($total_total_ht).''; + print ''.price($total_total_tva).''; + print ''.price($total_total_ttc).''; print ''; print ''; print ''; From be302ce5ae0f025e7ed7fa43935da0100fdeeee2 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 3 May 2015 08:10:22 +0200 Subject: [PATCH 20/36] New: ER Add filter on amounts --- htdocs/expensereport/list.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index 4faff0ecbb4..cc48c78f252 100755 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -41,6 +41,8 @@ $result = restrictedArea($user, 'expensereport','',''); $search_ref = GETPOST('search_ref'); $search_user = GETPOST('search_user','int'); +$search_amount_ht = GETPOST('search_amount_ht','alpha'); +$search_amount_ttc = GETPOST('search_amount_ttc','alpha'); $search_status = GETPOST('search_status','int'); $month_start = GETPOST("month_start","int"); $year_start = GETPOST("year_start","int"); @@ -51,6 +53,8 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both { $search_ref=""; $search_user=""; + $search_amount_ht=""; + $search_amount_ttc=""; $search_status=""; $month_start=""; $year_start=""; @@ -126,6 +130,15 @@ else if ($year_end > 0) { $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,1,false))."' AND '".$db->idate(dol_get_last_day($year_end,12,false))."'"; } +// Amount +if ($search_amount_ht != '') +{ + $sql.= natural_search('d.total_ht', $search_amount_ht, 1); +} +if ($search_amount_ttc != '') +{ + $sql.= natural_search('d.total_ttc', $search_amount_ttc, 1); +} // User if ($search_name) { @@ -194,9 +207,13 @@ if ($resql) print ' '; } + // Amount with no taxe + print ''; + print ' '; - print ' '; - print ' '; + + // Amount with all taxes + print ''; // Status print ''; From 2fd4bf10124d1df22b44897557c51aae444a3529 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 3 May 2015 09:54:37 +0200 Subject: [PATCH 21/36] Add commonstickergenerator class Common abstract class for sticker printing. Creates contracts for write_file and addSticker methods --- .../class/commonstickergenerator.class.php | 270 +++++++++ htdocs/core/class/pdf_label.class.php | 546 ------------------ 2 files changed, 270 insertions(+), 546 deletions(-) create mode 100644 htdocs/core/class/commonstickergenerator.class.php delete mode 100644 htdocs/core/class/pdf_label.class.php diff --git a/htdocs/core/class/commonstickergenerator.class.php b/htdocs/core/class/commonstickergenerator.class.php new file mode 100644 index 00000000000..50a0c929a7e --- /dev/null +++ b/htdocs/core/class/commonstickergenerator.class.php @@ -0,0 +1,270 @@ + + * Copyright (C) 2002-2003 Jean-Louis Bergamo + * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2015 Francis Appels + * + * 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 3 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, see . + */ + +/* Inspire de PDF_Label + * PDF_Label - PDF label editing + * @package PDF_Label + * @author Laurent PASSEBECQ + * @copyright 2003 Laurent PASSEBECQ + * disponible ici : http://www.fpdf.org/fr/script/script29.php + */ + +//------------------------------------------------------------------- +// VERSIONS : +// 1.0 : Initial release +// 1.1 : + : Added unit in the constructor +// + : Now Positions start @ (1,1).. then the first image @top-left of a page is (1,1) +// + : Added in the description of a label : +// font-size : defaut char size (can be changed by calling Set_Char_Size(xx); +// paper-size : Size of the paper for this sheet (thanx to Al Canton) +// metric : type of unit used in this description +// You can define your label properties in inches by setting metric to 'in' +// and printing in millimiter by setting unit to 'mm' in constructor. +// Added some labels : +// 5160, 5161, 5162, 5163,5164 : thanx to Al Canton : acanton@adams-blake.com +// 8600 : thanx to Kunal Walia : kunal@u.washington.edu +// + : Added 3mm to the position of labels to avoid errors +//////////////////////////////////////////////////// + +/** + * \file htdocs/core/class/commonstickergenerator.class.php + * \ingroup core + * \brief generate pdf document with labels or cards in Avery or custom format + */ + +require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php'; + + +/** + * Class to generate stick sheet with format Avery or other personalised + */ +abstract class CommonStickerGenerator +{ + + public $code; // Code of format + public $format; // Array with informations + + // protected + var $_Avery_Name = ''; // Nom du format de l'etiquette + var $_Margin_Left = 0; // Marge de gauche de l'etiquette + var $_Margin_Top = 0; // marge en haut de la page avant la premiere etiquette + var $_X_Space = 0; // Espace horizontal entre 2 bandes d'etiquettes + var $_Y_Space = 0; // Espace vertical entre 2 bandes d'etiquettes + var $_X_Number = 0; // NX Nombre d'etiquettes sur la largeur de la page + var $_Y_Number = 0; // NY Nombre d'etiquettes sur la hauteur de la page + var $_Width = 0; // Largeur de chaque etiquette + var $_Height = 0; // Hauteur de chaque etiquette + var $_Char_Size = 10; // Hauteur des caracteres + var $_Line_Height = 10; // Hauteur par defaut d'une ligne + var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values + var $_Metric_Doc = 'mm'; // Type of metric for the doc.. + var $_COUNTX = 1; + var $_COUNTY = 1; + var $_First = 1; + var $Tformat; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + } + + /** + * Function to build PDF on disk, then output on HTTP strem. + * + * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) + * @param Translate $outputlangs Lang object for output language + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param string $outputdir Output directory for pdf file + * @return int 1=OK, 0=KO + */ + abstract function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir=''); + + /** + * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) + * + * @param PDF &$pdf PDF reference + * @param Translate $outputlangs Output langs + * @param array $param Associative array containing label content and optional parameters + * @return void + */ + abstract function addSticker(&$pdf,$outputlangs,$param); + + /** + * Methode qui permet de modifier la taille des caracteres + * Cela modiera aussi l'espace entre chaque ligne + * + * @param PDF &$pdf PDF reference + * @param int $pt point + * @return void + */ + function Set_Char_Size(&$pdf,$pt) + { + if ($pt > 3) { + $this->_Char_Size = $pt; + $this->_Line_Height = $this->_Get_Height_Chars($pt); + $pdf->SetFont('','',$pt); + } + } + + /** + * protected Print dot line + * + * @param PDF &$pdf PDF reference + * @param int $x1 X1 + * @param int $y1 Y1 + * @param int $x2 X2 + * @param int $y2 Y2 + * @param int $epaisseur Epaisseur + * @param int $nbPointilles Nb pointilles + * @return void + */ + function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15) + { + $pdf->SetLineWidth($epaisseur); + $length=abs($x1-$x2); + $hauteur=abs($y1-$y2); + if($length>$hauteur) { + $Pointilles=($length/$nbPointilles)/2; // taille des pointilles + } + else { + $Pointilles=($hauteur/$nbPointilles)/2; + } + for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) { + for($j=$i;$j<=($i+$Pointilles);$j++) { + if($j<=($x2-1)) { + $pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point + $pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point + } + } + } + for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) { + for($j=$i;$j<=($i+$Pointilles);$j++) { + if($j<=($y2-1)) { + $pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point + $pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point + } + } + } + } + + /** + * protected Function realisant une croix aux 4 coins des cartes + * + * @param PDF &$pdf PDF reference + * @param int $x1 X1 + * @param int $y1 Y1 + * @param int $x2 X2 + * @param int $y2 Y2 + * @param int $epaisseur Epaisseur + * @param int $taille Size + * @return void + */ + function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4) + { + $pdf->SetDrawColor(192,192,192); + + $pdf->SetLineWidth($epaisseur); + $lg=$taille/2; + // croix haut gauche + $pdf->Line($x1,$y1-$lg,$x1,$y1+$lg); + $pdf->Line($x1-$lg,$y1,$x1+$lg,$y1); + // croix bas gauche + $pdf->Line($x1,$y2-$lg,$x1,$y2+$lg); + $pdf->Line($x1-$lg,$y2,$x1+$lg,$y2); + // croix haut droit + $pdf->Line($x2,$y1-$lg,$x2,$y1+$lg); + $pdf->Line($x2-$lg,$y1,$x2+$lg,$y1); + // croix bas droit + $pdf->Line($x2,$y2-$lg,$x2,$y2+$lg); + $pdf->Line($x2-$lg,$y2,$x2+$lg,$y2); + + $pdf->SetDrawColor(0,0,0); + } + + /** + * protected Convert units (in to mm, mm to in) + * $src and $dest must be 'in' or 'mm' + * + * @param int $value value + * @param string $src from + * @param string $dest to + * @return float value value after conversion + */ + function _Convert_Metric ($value, $src, $dest) + { + if ($src != $dest) { + $tab['in'] = 39.37008; + $tab['mm'] = 1000; + return $value * $tab[$dest] / $tab[$src]; + } else { + return $value; + } + } + + /** + * protected Give the height for a char size given. + * + * @param int $pt Point + * @return int Height chars + */ + function _Get_Height_Chars($pt) + { + // Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes + $_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10); + if (in_array($pt, array_keys($_Table_Hauteur_Chars))) { + return $_Table_Hauteur_Chars[$pt]; + } else { + return 100; // There is a prob.. + } + } + + /** + * protected Set format + * + * @param PDF &$pdf PDF reference + * @param string $format Format + * @return void + */ + function _Set_Format(&$pdf, $format) + { + $this->_Metric = $format['metric']; + $this->_Avery_Name = $format['name']; + $this->_Avery_Code = $format['code']; + $this->_Margin_Left = $this->_Convert_Metric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc); + $this->_Margin_Top = $this->_Convert_Metric($format['marginTop'], $this->_Metric, $this->_Metric_Doc); + $this->_X_Space = $this->_Convert_Metric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc); + $this->_Y_Space = $this->_Convert_Metric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc); + $this->_X_Number = $format['NX']; + $this->_Y_Number = $format['NY']; + $this->_Width = $this->_Convert_Metric($format['width'], $this->_Metric, $this->_Metric_Doc); + $this->_Height = $this->_Convert_Metric($format['height'], $this->_Metric, $this->_Metric_Doc); + $this->Set_Char_Size($pdf, $format['font-size']); + } + +} diff --git a/htdocs/core/class/pdf_label.class.php b/htdocs/core/class/pdf_label.class.php deleted file mode 100644 index f6b156bb37a..00000000000 --- a/htdocs/core/class/pdf_label.class.php +++ /dev/null @@ -1,546 +0,0 @@ - - * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2006-2013 Laurent Destailleur - * Copyright (C) 2015 Francis Appels - * - * 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 3 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, see . - */ - -/* Inspire de PDF_Label - * PDF_Label - PDF label editing - * @package PDF_Label - * @author Laurent PASSEBECQ - * @copyright 2003 Laurent PASSEBECQ - * disponible ici : http://www.fpdf.org/fr/script/script29.php - */ - -//------------------------------------------------------------------- -// VERSIONS : -// 1.0 : Initial release -// 1.1 : + : Added unit in the constructor -// + : Now Positions start @ (1,1).. then the first image @top-left of a page is (1,1) -// + : Added in the description of a label : -// font-size : defaut char size (can be changed by calling Set_Char_Size(xx); -// paper-size : Size of the paper for this sheet (thanx to Al Canton) -// metric : type of unit used in this description -// You can define your label properties in inches by setting metric to 'in' -// and printing in millimiter by setting unit to 'mm' in constructor. -// Added some labels : -// 5160, 5161, 5162, 5163,5164 : thanx to Al Canton : acanton@adams-blake.com -// 8600 : thanx to Kunal Walia : kunal@u.washington.edu -// + : Added 3mm to the position of labels to avoid errors -//////////////////////////////////////////////////// - -/** - * \file htdocs/core/class/pdf_label.class.php - * \ingroup core - * \brief generate pdf document with labels or cards in Avery or custom format - */ - -require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php'; - - -/** - * Class to generate stick sheet with format Avery or other personalised - */ -class pdf_label -{ - - var $code; // Code of format - var $format; // Array with informations - - // Proprietes privees - var $_Avery_Name = ''; // Nom du format de l'etiquette - var $_Margin_Left = 0; // Marge de gauche de l'etiquette - var $_Margin_Top = 0; // marge en haut de la page avant la premiere etiquette - var $_X_Space = 0; // Espace horizontal entre 2 bandes d'etiquettes - var $_Y_Space = 0; // Espace vertical entre 2 bandes d'etiquettes - var $_X_Number = 0; // NX Nombre d'etiquettes sur la largeur de la page - var $_Y_Number = 0; // NY Nombre d'etiquettes sur la hauteur de la page - var $_Width = 0; // Largeur de chaque etiquette - var $_Height = 0; // Hauteur de chaque etiquette - var $_Char_Size = 10; // Hauteur des caracteres - var $_Line_Height = 10; // Hauteur par defaut d'une ligne - var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values - var $_Metric_Doc = 'mm'; // Type of metric for the doc.. - - var $_COUNTX = 1; - var $_COUNTY = 1; - var $_First = 1; - - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - } - - /** - * Methode qui permet de modifier la taille des caracteres - * Cela modiera aussi l'espace entre chaque ligne - * - * @param PDF &$pdf PDF reference - * @param int $pt point - * @return void - */ - function Set_Char_Size(&$pdf,$pt) - { - if ($pt > 3) { - $this->_Char_Size = $pt; - $this->_Line_Height = $this->_Get_Height_Chars($pt); - $pdf->SetFont('','',$pt); - } - } - - /** - * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) - * - %LOGO% is replace with company logo - * - %PHOTO% is replace with photo provided as parameter - * - * @param PDF &$pdf PDF reference - * @param string $textleft Text left - * @param string $header Header - * @param string $footer Footer - * @param Translate $outputlangs Output langs - * @param string $textright Text right - * @param string $photo Photo (full path to image file used as replacement for key %PHOTOS% into left, right, header or footer text) - * @return void - */ - function Add_PDF_card(&$pdf,$textleft,$header,$footer,$outputlangs,$textright='',$photo='') - { - global $mysoc,$conf,$langs; - global $forceimgscalewidth,$forceimgscaleheight; - - $imgscalewidth=(empty($forceimgscalewidth)?0.3:$forceimgscalewidth); // Scale of image for width (1=Full width of sticker) - $imgscaleheight=(empty($forceimgscalewidth)?0.5:$forceimgscalewidth); // Scale of image for height (1=Full height of sticker) - - // We are in a new page, then we must add a page - if (($this->_COUNTX ==0) && ($this->_COUNTY==0) and (!$this->_First==1)) { - $pdf->AddPage(); - } - $this->_First=0; - $_PosX = $this->_Margin_Left+($this->_COUNTX*($this->_Width+$this->_X_Space)); - $_PosY = $this->_Margin_Top+($this->_COUNTY*($this->_Height+$this->_Y_Space)); - - // Define logo - $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; - if (! is_readable($logo)) - { - $logo=''; - if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) - { - $logo=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; - } - elseif (! empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) - { - $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; - } - } - - // Define photo - if (! empty($photo)) - { - if (! is_readable($photo)) $photo=''; - } - - // Define background image - $backgroundimage=''; - - // Print lines - if ($this->code == "CARD") - { - $this->Tformat=$this->_Avery_Labels["CARD"]; - //$this->_Pointille($pdf,$_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.3,25); - $this->_Croix($pdf,$_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.1,10); - } - - // Background - if ($backgroundimage) - { - $pdf->image($backgroundimage,$_PosX,$_PosY,$this->_Width,$this->_Height); - } - - $xleft=2; $ytop=2; - - // Top - if ($header!='') - { - if ($this->code == "CARD") - { - $pdf->SetDrawColor(128,128,128); - $pdf->Line($_PosX, $_PosY+$this->_Line_Height+1, $_PosX+$this->_Width, $_PosY+$this->_Line_Height+1); // Only 1 mm and not ytop for top text - $pdf->SetDrawColor(0,0,0); - } - $pdf->SetXY($_PosX+$xleft, $_PosY+1); // Only 1 mm and not ytop for top text - $pdf->Cell($this->_Width-2*$xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header),0,1,'C'); - } - - - $ytop+=(empty($header)?0:(1+$this->_Line_Height)); - - // Define widthtouse and heighttouse - $maxwidthtouse=round(($this->_Width - 2*$xleft)*$imgscalewidth); $maxheighttouse=round(($this->_Height - 2*$ytop)*$imgscaleheight); - $defaultratio=($maxwidthtouse/$maxheighttouse); - $widthtouse=$maxwidthtouse; $heighttouse=0; // old value for image - $tmp=dol_getImageSize($photo, false); - if ($tmp['height']) - { - $imgratio=$tmp['width']/$tmp['height']; - if ($imgratio >= $defaultratio) { $widthtouse = $maxwidthtouse; $heighttouse = round($widthtouse / $imgratio); } - else { $heightouse = $maxheighttouse; $widthtouse = round($heightouse * $imgratio); } - } - //var_dump($this->_Width.'x'.$this->_Height.' with border and scale '.$imgscale.' => max '.$maxwidthtouse.'x'.$maxheighttouse.' => We use '.$widthtouse.'x'.$heighttouse);exit; - - // Center - if ($textright=='') // Only a left part - { - // Output left area - if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); - else if ($textleft == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); - else - { - $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); - $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); - } - } - else if ($textleft!='' && $textright!='') // - { - if ($textleft == '%LOGO%' || $textleft == '%PHOTO%') - { - if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); - else if ($textleft == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); - $pdf->SetXY($_PosX+$xleft+$widthtouse+1, $_PosY+$ytop); - $pdf->MultiCell($this->_Width-$xleft-$xleft-$widthtouse-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); - } - else if ($textright == '%LOGO%' || $textright == '%PHOTO%') - { - if ($textright == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+$this->_Width-$widthtouse-$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); - else if ($textright == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+$this->_Width-$widthtouse-$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); - $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); - $pdf->MultiCell($this->_Width-$widthtouse-$xleft-$xleft-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); - } - else // text on halft left and text on half right - { - $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); - $pdf->MultiCell(round($this->_Width/2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); - $pdf->SetXY($_PosX+round($this->_Width/2), $_PosY+$ytop); - $pdf->MultiCell(round($this->_Width/2)-2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); - } - } - else // Only a right part - { - // Output right area - if ($textright == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+$this->_Width-$widthtouse-$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); - else if ($textright == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+$this->_Width-$widthtouse-$xleft,$_PosY+$ytop,$widthtouse,$heighttouse); - else - { - $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); - $pdf->MultiCell($this->_Width-$xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); - } - } - - // Bottom - if ($footer!='') - { - if ($this->code == "CARD") - { - $pdf->SetDrawColor(128,128,128); - $pdf->Line($_PosX, $_PosY+$this->_Height-$this->_Line_Height-2, $_PosX+$this->_Width, $_PosY+$this->_Height-$this->_Line_Height-2); - $pdf->SetDrawColor(0,0,0); - } - $pdf->SetXY($_PosX, $_PosY+$this->_Height-$this->_Line_Height-1); - $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer),0,1,'C'); - } - //print "$_PosY+$this->_Height-$this->_Line_Height-1
\n"; - - $this->_COUNTY++; - - if ($this->_COUNTY == $this->_Y_Number) { - // Si on est en bas de page, on remonte le 'curseur' de position - $this->_COUNTX++; - $this->_COUNTY=0; - } - - if ($this->_COUNTX == $this->_X_Number) { - // Si on est en bout de page, alors on repart sur une nouvelle page - $this->_COUNTX=0; - $this->_COUNTY=0; - } - } - - - /** - * Print dot line - * - * @param PDF &$pdf PDF reference - * @param int $x1 X1 - * @param int $y1 Y1 - * @param int $x2 X2 - * @param int $y2 Y2 - * @param int $epaisseur Epaisseur - * @param int $nbPointilles Nb pointilles - * @return void - */ - function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15) - { - $pdf->SetLineWidth($epaisseur); - $length=abs($x1-$x2); - $hauteur=abs($y1-$y2); - if($length>$hauteur) { - $Pointilles=($length/$nbPointilles)/2; // taille des pointilles - } - else { - $Pointilles=($hauteur/$nbPointilles)/2; - } - for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) { - for($j=$i;$j<=($i+$Pointilles);$j++) { - if($j<=($x2-1)) { - $pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point - $pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point - } - } - } - for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) { - for($j=$i;$j<=($i+$Pointilles);$j++) { - if($j<=($y2-1)) { - $pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point - $pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point - } - } - } - } - - /** - * Fonction realisant une croix aux 4 coins des cartes - * - * @param PDF &$pdf PDF reference - * @param int $x1 X1 - * @param int $y1 Y1 - * @param int $x2 X2 - * @param int $y2 Y2 - * @param int $epaisseur Epaisseur - * @param int $taille Size - * @return void - */ - function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4) - { - $pdf->SetDrawColor(192,192,192); - - $pdf->SetLineWidth($epaisseur); - $lg=$taille/2; - // croix haut gauche - $pdf->Line($x1,$y1-$lg,$x1,$y1+$lg); - $pdf->Line($x1-$lg,$y1,$x1+$lg,$y1); - // croix bas gauche - $pdf->Line($x1,$y2-$lg,$x1,$y2+$lg); - $pdf->Line($x1-$lg,$y2,$x1+$lg,$y2); - // croix haut droit - $pdf->Line($x2,$y1-$lg,$x2,$y1+$lg); - $pdf->Line($x2-$lg,$y1,$x2+$lg,$y1); - // croix bas droit - $pdf->Line($x2,$y2-$lg,$x2,$y2+$lg); - $pdf->Line($x2-$lg,$y2,$x2+$lg,$y2); - - $pdf->SetDrawColor(0,0,0); - } - - /** - * Convert units (in to mm, mm to in) - * $src and $dest must be 'in' or 'mm' - * - * @param int $value value - * @param string $src from - * @param string $dest to - * @return float value value after conversion - */ - function _Convert_Metric ($value, $src, $dest) - { - if ($src != $dest) { - $tab['in'] = 39.37008; - $tab['mm'] = 1000; - return $value * $tab[$dest] / $tab[$src]; - } else { - return $value; - } - } - - /** - * Give the height for a char size given. - * - * @param int $pt Point - * @return int Height chars - */ - function _Get_Height_Chars($pt) - { - // Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes - $_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10); - if (in_array($pt, array_keys($_Table_Hauteur_Chars))) { - return $_Table_Hauteur_Chars[$pt]; - } else { - return 100; // There is a prob.. - } - } - - /** - * Set format - * - * @param PDF &$pdf PDF reference - * @param string $format Format - * @return void - */ - function _Set_Format(&$pdf, $format) - { - $this->_Metric = $format['metric']; - $this->_Avery_Name = $format['name']; - $this->_Avery_Code = $format['code']; - $this->_Margin_Left = $this->_Convert_Metric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc); - $this->_Margin_Top = $this->_Convert_Metric($format['marginTop'], $this->_Metric, $this->_Metric_Doc); - $this->_X_Space = $this->_Convert_Metric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc); - $this->_Y_Space = $this->_Convert_Metric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc); - $this->_X_Number = $format['NX']; - $this->_Y_Number = $format['NY']; - $this->_Width = $this->_Convert_Metric($format['width'], $this->_Metric, $this->_Metric_Doc); - $this->_Height = $this->_Convert_Metric($format['height'], $this->_Metric, $this->_Metric_Doc); - $this->Set_Char_Size($pdf, $format['font-size']); - } - - - /** - * Function to build PDF on disk, then output on HTTP strem. - * - * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) - * @param Translate $outputlangs Lang object for output language - * @param string $srctemplatepath Full path of source filename for generator using a template file - * @param string $outputdir Output directory for pdf file - * @return int 1=OK, 0=KO - */ - function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='') - { - global $user,$conf,$langs,$mysoc,$_Avery_Labels; - - $this->code=$srctemplatepath; - $this->Tformat = $_Avery_Labels[$this->code]; - if (empty($this->Tformat)) { dol_print_error('','ErrorBadTypeForCard'.$this->code); exit; } - $this->type = 'pdf'; - $this->format = $this->Tformat['paper-size']; - - if (! is_object($outputlangs)) $outputlangs=$langs; - // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO - if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; - - $outputlangs->load("main"); - $outputlangs->load("dict"); - $outputlangs->load("companies"); - $outputlangs->load("admin"); - - $title=$outputlangs->transnoentities('Labels'); - $keywords=$title." ".$outputlangs->convToOutputCharset($mysoc->name); - - $dir = (empty($outputdir)?$conf->adherent->dir_temp:$outputdir); - $filename='tmp_address_sheet.pdf'; - $file = $dir."/".$filename; - - if (! file_exists($dir)) - { - if (dol_mkdir($dir) < 0) - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } - - $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); - - if (class_exists('TCPDF')) - { - $pdf->setPrintHeader(false); - $pdf->setPrintFooter(false); - } - $pdf->SetFont(pdf_getPDFFont($outputlangs)); - - $pdf->SetTitle($title); - $pdf->SetSubject($title); - $pdf->SetCreator("Dolibarr ".DOL_VERSION); - $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $pdf->SetKeyWords($keywords); - if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); - - $pdf->SetMargins(0,0); - $pdf->SetAutoPageBreak(false); - - $this->_Metric_Doc = $this->Tformat['metric']; - // Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie - $posX=1; - $posY=1; - if ($posX > 0) $posX--; else $posX=0; - if ($posY > 0) $posY--; else $posY=0; - $this->_COUNTX = $posX; - $this->_COUNTY = $posY; - $this->_Set_Format($pdf, $this->Tformat); - - - $pdf->Open(); - $pdf->AddPage(); - - - // Add each record - foreach($arrayofrecords as $val) - { - // imprime le texte specifique sur la carte - $this->Add_PDF_card($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright'],$val['photo']); - } - - //$pdf->SetXY(10, 295); - //$pdf->Cell($this->_Width, $this->_Line_Height, 'XXX',0,1,'C'); - - - // Output to file - $pdf->Output($file,'F'); - - if (! empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); - - - - // Output to http stream - clearstatcache(); - - $attachment=true; - if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; - $type=dol_mimetype($filename); - - //if ($encoding) header('Content-Encoding: '.$encoding); - if ($type) header('Content-Type: '.$type); - if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); - else header('Content-Disposition: inline; filename="'.$filename.'"'); - - // Ajout directives pour resoudre bug IE - header('Cache-Control: Public, must-revalidate'); - header('Pragma: public'); - - readfile($file); - - return 1; - } -} From 701c85620b5d2dbe7b3d6fddce6cc75d7074af14 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 3 May 2015 10:00:11 +0200 Subject: [PATCH 22/36] Extend sticker classes from abstract class Extend member and printsheet sticker printer classes from new abstract commonsticker generator --- .../modules/member/doc/pdf_standard.class.php | 232 ++---------------- .../doc/pdf_standardlabel.class.php | 46 ++-- 2 files changed, 30 insertions(+), 248 deletions(-) diff --git a/htdocs/core/modules/member/doc/pdf_standard.class.php b/htdocs/core/modules/member/doc/pdf_standard.class.php index 9268a10f3c4..7df37a7c05c 100644 --- a/htdocs/core/modules/member/doc/pdf_standard.class.php +++ b/htdocs/core/modules/member/doc/pdf_standard.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2001-2003 Rodolphe Quiedeville * Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2015 Francis Appels * * 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 @@ -19,106 +20,38 @@ * along with this program. If not, see . */ -/* Inspire de PDF_Label - * PDF_Label - PDF label editing - * @package PDF_Label - * @author Laurent PASSEBECQ - * @copyright 2003 Laurent PASSEBECQ - * disponible ici : http://www.fpdf.org/fr/script/script29.php - */ - -//------------------------------------------------------------------- -// VERSIONS : -// 1.0 : Initial release -// 1.1 : + : Added unit in the constructor -// + : Now Positions start @ (1,1).. then the first image @top-left of a page is (1,1) -// + : Added in the description of a label : -// font-size : defaut char size (can be changed by calling Set_Char_Size(xx); -// paper-size : Size of the paper for this sheet (thanx to Al Canton) -// metric : type of unit used in this description -// You can define your label properties in inches by setting metric to 'in' -// and printing in millimiter by setting unit to 'mm' in constructor. -// Added some labels : -// 5160, 5161, 5162, 5163,5164 : thanx to Al Canton : acanton@adams-blake.com -// 8600 : thanx to Kunal Walia : kunal@u.washington.edu -// + : Added 3mm to the position of labels to avoid errors -//////////////////////////////////////////////////// - /** * \file htdocs/core/modules/member/doc/pdf_standard.class.php * \ingroup member * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise */ -require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php'; - +require_once DOL_DOCUMENT_ROOT.'/core/class/commonstickergenerator.class.php'; /** * Class to generate stick sheet with format Avery or other personalised */ -class pdf_standard +class pdf_standard extends CommonStickerGenerator { - var $code; // Code of format - var $format; // Array with informations - - // Proprietes privees - var $_Avery_Name = ''; // Nom du format de l'etiquette - var $_Margin_Left = 0; // Marge de gauche de l'etiquette - var $_Margin_Top = 0; // marge en haut de la page avant la premiere etiquette - var $_X_Space = 0; // Espace horizontal entre 2 bandes d'etiquettes - var $_Y_Space = 0; // Espace vertical entre 2 bandes d'etiquettes - var $_X_Number = 0; // NX Nombre d'etiquettes sur la largeur de la page - var $_Y_Number = 0; // NY Nombre d'etiquettes sur la hauteur de la page - var $_Width = 0; // Largeur de chaque etiquette - var $_Height = 0; // Hauteur de chaque etiquette - var $_Char_Size = 10; // Hauteur des caracteres - var $_Line_Height = 10; // Hauteur par defaut d'une ligne - var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values - var $_Metric_Doc = 'mm'; // Type of metric for the doc.. - - var $_COUNTX = 1; - var $_COUNTY = 1; - var $_First = 1; - - /** - * Constructor + * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - * @param DoliDB $db Database handler + * @param PDF &$pdf PDF reference + * @param Translate $outputlangs Output langs + * @param array $param Associative array containing label content and optional parameters + * @return void */ - function __construct($db) - { - $this->db = $db; - } - - - /** - * Methode qui permet de modifier la taille des caracteres - * Cela modiera aussi l'espace entre chaque ligne - * - * @param PDF $pdf PDF - * @param int $pt point - * @return void - */ - function Set_Char_Size(&$pdf,$pt) - { - if ($pt > 3) { - $this->_Char_Size = $pt; - $this->_Line_Height = $this->_Get_Height_Chars($pt); - $pdf->SetFont('','',$pt); - } - } - - - /** + function addSticker(&$pdf,$outputlangs,$param) { + // use this method in future refactoring + } + + /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - %LOGO% is replace with company logo * - %PHOTO% is replace with photo provided as parameter * - * @param PDF $pdf PDF + * @param PDF &$pdf PDF * @param string $textleft Text left * @param string $header Header * @param string $footer Footer @@ -297,143 +230,6 @@ class pdf_standard } } - /** - * Print dot line - * - * @param PDF $pdf PDF - * @param int $x1 X1 - * @param int $y1 Y1 - * @param int $x2 X2 - * @param int $y2 Y2 - * @param int $epaisseur Epaisseur - * @param int $nbPointilles Nb pointilles - * @return void - */ - function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15) - { - $pdf->SetLineWidth($epaisseur); - $length=abs($x1-$x2); - $hauteur=abs($y1-$y2); - if($length>$hauteur) { - $Pointilles=($length/$nbPointilles)/2; // taille des pointilles - } - else { - $Pointilles=($hauteur/$nbPointilles)/2; - } - for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) { - for($j=$i;$j<=($i+$Pointilles);$j++) { - if($j<=($x2-1)) { - $pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point - $pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point - } - } - } - for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) { - for($j=$i;$j<=($i+$Pointilles);$j++) { - if($j<=($y2-1)) { - $pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point - $pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point - } - } - } - } - - /** - * Fonction realisant une croix aux 4 coins des cartes - * - * @param PDF $pdf PDF - * @param int $x1 X1 - * @param int $y1 Y1 - * @param int $x2 X2 - * @param int $y2 Y2 - * @param int $epaisseur Epaisseur - * @param int $taille Size - * @return void - */ - function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4) - { - $pdf->SetDrawColor(192,192,192); - - $pdf->SetLineWidth($epaisseur); - $lg=$taille/2; - // croix haut gauche - $pdf->Line($x1,$y1-$lg,$x1,$y1+$lg); - $pdf->Line($x1-$lg,$y1,$x1+$lg,$y1); - // croix bas gauche - $pdf->Line($x1,$y2-$lg,$x1,$y2+$lg); - $pdf->Line($x1-$lg,$y2,$x1+$lg,$y2); - // croix haut droit - $pdf->Line($x2,$y1-$lg,$x2,$y1+$lg); - $pdf->Line($x2-$lg,$y1,$x2+$lg,$y1); - // croix bas droit - $pdf->Line($x2,$y2-$lg,$x2,$y2+$lg); - $pdf->Line($x2-$lg,$y2,$x2+$lg,$y2); - - $pdf->SetDrawColor(0,0,0); - } - - /** - * Convert units (in to mm, mm to in) - * $src and $dest must be 'in' or 'mm' - * - * @param int $value value - * @param string $src from - * @param string $dest to - * @return float value value after conversion - */ - function _Convert_Metric ($value, $src, $dest) - { - if ($src != $dest) { - $tab['in'] = 39.37008; - $tab['mm'] = 1000; - return $value * $tab[$dest] / $tab[$src]; - } else { - return $value; - } - } - - /** - * Give the height for a char size given. - * - * @param int $pt Point - * @return int Height chars - */ - function _Get_Height_Chars($pt) - { - // Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes - $_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10); - if (in_array($pt, array_keys($_Table_Hauteur_Chars))) { - return $_Table_Hauteur_Chars[$pt]; - } else { - return 100; // There is a prob.. - } - } - - /** - * Set format - * - * @param PDF $pdf PDF - * @param string $format Format - * @return void - */ - function _Set_Format(&$pdf, $format) - { - - $this->_Metric = $format['metric']; - $this->_Avery_Name = $format['name']; - $this->_Avery_Code = $format['code']; - $this->_Margin_Left = $this->_Convert_Metric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc); - $this->_Margin_Top = $this->_Convert_Metric($format['marginTop'], $this->_Metric, $this->_Metric_Doc); - $this->_X_Space = $this->_Convert_Metric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc); - $this->_Y_Space = $this->_Convert_Metric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc); - $this->_X_Number = $format['NX']; - $this->_Y_Number = $format['NY']; - $this->_Width = $this->_Convert_Metric($format['width'], $this->_Metric, $this->_Metric_Doc); - $this->_Height = $this->_Convert_Metric($format['height'], $this->_Metric, $this->_Metric_Doc); - $this->Set_Char_Size($pdf, $format['font-size']); - } - - /** * Function to build PDF on disk, then output on HTTP strem. * diff --git a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php index e8eaeabf12e..d9d9b825a4b 100644 --- a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php +++ b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php @@ -20,45 +20,31 @@ * along with this program. If not, see . */ -/* Inspire de PDF_Label - * PDF_Label - PDF label editing - * @package PDF_Label - * @author Laurent PASSEBECQ - * @copyright 2003 Laurent PASSEBECQ - * disponible ici : http://www.fpdf.org/fr/script/script29.php - */ - -//------------------------------------------------------------------- -// VERSIONS : -// 1.0 : Initial release -// 1.1 : + : Added unit in the constructor -// + : Now Positions start @ (1,1).. then the first image @top-left of a page is (1,1) -// + : Added in the description of a label : -// font-size : defaut char size (can be changed by calling Set_Char_Size(xx); -// paper-size : Size of the paper for this sheet (thanx to Al Canton) -// metric : type of unit used in this description -// You can define your label properties in inches by setting metric to 'in' -// and printing in millimiter by setting unit to 'mm' in constructor. -// Added some labels : -// 5160, 5161, 5162, 5163,5164 : thanx to Al Canton : acanton@adams-blake.com -// 8600 : thanx to Kunal Walia : kunal@u.washington.edu -// + : Added 3mm to the position of labels to avoid errors -//////////////////////////////////////////////////// - /** * \file htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php * \ingroup core * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise */ -require_once DOL_DOCUMENT_ROOT.'/core/class/pdf_label.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/commonstickergenerator.class.php'; /** * Class to generate stick sheet with format Avery or other personalised */ -class pdf_standardlabel extends pdf_label +class pdf_standardlabel extends CommonStickerGenerator { - + /** + * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) + * + * @param PDF &$pdf PDF reference + * @param Translate $outputlangs Output langs + * @param array $param Associative array containing label content and optional parameters + * @return void + */ + function addSticker(&$pdf,$outputlangs,$param) { + // use this method in future refactoring + } + /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - %LOGO% is replace with company logo @@ -73,7 +59,7 @@ class pdf_standardlabel extends pdf_label * @param string $photo Photo (full path to image file used as replacement for key %PHOTOS% into left, right, header or footer text) * @return void */ - function Add_PDF_card(&$pdf,$textleft,$header,$footer,$outputlangs,$textright='',$photo='') + function Add_PDF_label(&$pdf,$textleft,$header,$footer,$outputlangs,$textright='',$photo='') { global $mysoc,$conf,$langs; global $forceimgscalewidth,$forceimgscaleheight; @@ -320,7 +306,7 @@ class pdf_standardlabel extends pdf_label foreach($arrayofrecords as $val) { // imprime le texte specifique sur la carte - $this->Add_PDF_card($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright'],$val['photo']); + $this->Add_PDF_label($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright'],$val['photo']); } //$pdf->SetXY(10, 295); From 96dfdfeb73e606043cd84f626e7b7c6044812646 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 3 May 2015 10:05:59 +0200 Subject: [PATCH 23/36] New tcpdf barcode label printing class New tcpdf barcode label printing class and add parameters to printsheet for using this class. Add parameter to modules_xxx.php functions to pass printing templete class to use --- htdocs/barcode/printsheet.php | 69 ++-- htdocs/core/modules/member/modules_cards.php | 17 +- .../printsheet/doc/pdf_tcpdflabel.class.php | 385 ++++++++++++++++++ .../modules/printsheet/modules_labels.php | 12 +- 4 files changed, 441 insertions(+), 42 deletions(-) create mode 100644 htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php diff --git a/htdocs/barcode/printsheet.php b/htdocs/barcode/printsheet.php index fd89390f3db..7cd539bf323 100644 --- a/htdocs/barcode/printsheet.php +++ b/htdocs/barcode/printsheet.php @@ -123,7 +123,7 @@ if ($action == 'builddoc') $code=$forbarcode; $generator=$stdobject->barcode_type_coder; // coder (loaded by fetch_barcode). Engine. $encoding=strtoupper($stdobject->barcode_type_code); // code (loaded by fetch_barcode). Example 'ean', 'isbn', ... - $barcodeimage=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; + $diroutput=$conf->barcode->dir_temp; dol_mkdir($diroutput); @@ -142,27 +142,36 @@ if ($action == 'builddoc') $result=@include_once $newdir.$generator.'.modules.php'; if ($result) break; } - - // Load barcode class - $classname = "mod".ucfirst($generator); - $module = new $classname($db); - if ($module->encodingIsSupported($encoding)) - { - dol_delete_file($barcodeimage); - // File is created with full name $barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; - $result=$module->writeBarCode($code,$encoding,'Y',4); - - if ($result <= 0 || ! dol_is_file($barcodeimage)) - { - $error++; - setEventMessage('Failed to generate image file of barcode for code='.$code.' encoding='.$encoding.' file='.basename($barcodeimage), 'errors'); - } - } - else - { - $error++; - setEventMessage("Error, encoding ".$encoding." is not supported by encoder ".$generator.'. You must choose another barcode type or install a barcode generation engine that support '.$encoding, 'errors'); - } + + // Load barcode class for generating barcode image + $classname = "mod".ucfirst($generator); + $module = new $classname($db); + if ($generator != 'tcpdfbarcode') { + $template = 'standardlabel'; + $is2d = false; + if ($module->encodingIsSupported($encoding)) + { + $barcodeimage=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; + dol_delete_file($barcodeimage); + // File is created with full name $barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; + $result=$module->writeBarCode($code,$encoding,'Y',4); + + if ($result <= 0 || ! dol_is_file($barcodeimage)) + { + $error++; + setEventMessage('Failed to generate image file of barcode for code='.$code.' encoding='.$encoding.' file='.basename($barcodeimage), 'errors'); + } + } + else + { + $error++; + setEventMessage("Error, encoding ".$encoding." is not supported by encoder ".$generator.'. You must choose another barcode type or install a barcode generation engine that support '.$encoding, 'errors'); + } + } else { + $template = 'tcpdflabel'; + $encoding = $module->getTcpdfEncodingType($encoding); //convert to TCPDF compatible encoding types + $is2d = $module->is2d; + } } if (! $error) @@ -188,11 +197,12 @@ if ($action == 'builddoc') // For labels if ($mode == 'label') { - $txtforsticker="%PHOTO%"; - $textleft=make_substitutions($txtforsticker, $substitutionarray); - $textheader=''; - $textfooter=''; - $textright=''; + + $txtforsticker="%PHOTO%"; // Photo will be barcode image, %BARCODE% posible when using TCPDF generator + $textleft=make_substitutions((empty($conf->global->BARCODE_LABEL_LEFT_TEXT)?$txtforsticker:$conf->global->BARCODE_LABEL_LEFT_TEXT), $substitutionarray); + $textheader=make_substitutions((empty($conf->global->BARCODE_LABEL_HEADER_TEXT)?'':$conf->global->BARCODE_LABEL_HEADER_TEXT), $substitutionarray); + $textfooter=make_substitutions((empty($conf->global->BARCODE_LABEL_FOOTER_TEXT)?'':$conf->global->BARCODE_LABEL_FOOTER_TEXT), $substitutionarray); + $textright=make_substitutions((empty($conf->global->BARCODE_LABEL_RIGHT_TEXT)?'':$conf->global->BARCODE_LABEL_RIGHT_TEXT), $substitutionarray); $forceimgscalewidth=(empty($conf->global->BARCODE_FORCEIMGSCALEWIDTH)?1:$conf->global->BARCODE_FORCEIMGSCALEWIDTH); $forceimgscaleheight=(empty($conf->global->BARCODE_FORCEIMGSCALEHEIGHT)?1:$conf->global->BARCODE_FORCEIMGSCALEHEIGHT); @@ -203,6 +213,9 @@ if ($action == 'builddoc') 'textheader'=>$textheader, 'textfooter'=>$textfooter, 'textright'=>$textright, + 'code'=>$code, + 'encoding'=>$encoding, + 'is2d'=>$is2d, 'photo'=>$barcodeimage // Photo must be a file that exists with format supported by TCPDF ); } @@ -222,7 +235,7 @@ if ($action == 'builddoc') { $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE")); } - if (! $mesg) $result=members_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs, $diroutput); + if (! $mesg) $result=members_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs, $diroutput, $template); } if ($result <= 0) diff --git a/htdocs/core/modules/member/modules_cards.php b/htdocs/core/modules/member/modules_cards.php index d7fa0cbaae1..ab5604f2f99 100644 --- a/htdocs/core/modules/member/modules_cards.php +++ b/htdocs/core/modules/member/modules_cards.php @@ -65,10 +65,12 @@ class ModelePDFCards * @param DoliDB $db Database handler * @param array $arrayofmembers Array of members * @param string $modele Force modele to use ('' to not force) - * @param Translate $outputlangs Objet langs to use for translation + * @param Translate $outputlangs Object langs to use for translation + * @param string $outputdir Output directory + * @param string $template pdf generenate document class to use default 'standard' * @return int <0 if KO, >0 if OK */ -function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs) +function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir='', $template='standard') { global $conf,$langs; $langs->load("members"); @@ -97,13 +99,12 @@ function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs) } } else $code=$modele; - $modele='standard'; - + // If selected modele is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); + $tmp=explode(':',$template,2); if (! empty($tmp[1])) { - $modele=$tmp[0]; + $template=$tmp[0]; $srctemplatepath=$tmp[1]; } else $srctemplatepath=$code; @@ -116,14 +117,14 @@ function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs) { foreach(array('doc','pdf') as $prefix) { - $file = $prefix."_".$modele.".class.php"; + $file = $prefix."_".$template.".class.php"; // On verifie l'emplacement du modele $file=dol_buildpath($reldir."core/modules/member/doc/".$file,0); if (file_exists($file)) { $filefound=1; - $classname=$prefix.'_'.$modele; + $classname=$prefix.'_'.$template; break; } } diff --git a/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php b/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php new file mode 100644 index 00000000000..e73c112d26e --- /dev/null +++ b/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php @@ -0,0 +1,385 @@ + + * Copyright (C) 2002-2003 Jean-Louis Bergamo + * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2015 Francis Appels + * + * 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 3 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, see . + */ + +/** + * \file htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php + * \ingroup core + * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise + */ + +require_once DOL_DOCUMENT_ROOT.'/core/class/commonstickergenerator.class.php'; + +/** + * Class to generate stick sheet with format Avery or other personalised + */ +class pdf_tcpdflabel extends CommonStickerGenerator +{ + // define 1d barcode style + private $_style1d = array( + 'position' => '', + 'align' => 'C', + 'stretch' => false, + 'fitwidth' => true, + 'cellfitalign' => '', + 'border' => false, + 'hpadding' => 'auto', + 'vpadding' => 'auto', + 'fgcolor' => array(0,0,0), + 'bgcolor' => false, + 'text' => true, + 'font' => 'helvetica', + 'fontsize' => 8, + 'stretchtext' => 4 + ); + + // set style for 2d barcode + private $_style2d = array( + 'border' => false, + 'vpadding' => 'auto', + 'hpadding' => 'auto', + 'fgcolor' => array(0,0,0), + 'bgcolor' => false, + 'module_width' => 1, // width of a single module in points + 'module_height' => 1 // height of a single module in points + ); + + private $_align2d = 'N'; + + private $_xres = 0.4; + + /** + * write barcode to pdf + * + * @param PDF &$pdf PDF reference + * @param string $code code to print + * @param string $encoding type of barcode + * @param boolean $is2d true if 2d barcode + * @param int $x x position in user units + * @param int $y y position in user units + * @param int $w width in user units + * @param int $h height in user units + */ + private function writeBarcode(&$pdf, $code, $encoding, $is2d, $x, $y, $w, $h) + { + if ($is2d) { + $pdf->write2DBarcode($code, $encoding, $x, $y, $w, $h, $this->_style2d, $this->_align2d); + } else { + $pdf->write1DBarcode($code, $encoding, $x, $y, $w, $h, $this->_xres, $this->_style1d); + } + } + + /** + * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) + * + * @param PDF &$pdf PDF reference + * @param Translate $outputlangs Output langs + * @param array $param Associative array containing label content and optional parameters + * @return void + */ + function addSticker(&$pdf,$outputlangs,$param) + { + global $mysoc,$conf; + + $textleft = $param['textleft']; + $header = $param['textheader']; + $footer = $param['textfooter']; + $textright = $param['textright']; + $code = $param['code']; + $encoding = $param['encoding']; + $is2d = $param['is2d']; + + + + // We are in a new page, then we must add a page + if (($this->_COUNTX ==0) && ($this->_COUNTY==0) and (!$this->_First==1)) { + $pdf->AddPage(); + } + $this->_First=0; + $_PosX = $this->_Margin_Left+($this->_COUNTX*($this->_Width+$this->_X_Space)); + $_PosY = $this->_Margin_Top+($this->_COUNTY*($this->_Height+$this->_Y_Space)); + + // Define logo + $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; + if (! is_readable($logo)) + { + $logo=''; + if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) + { + $logo=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; + } + elseif (! empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) + { + $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; + } + } + + $xleft = 2; + $ytop = 2; + + // Top + if ($header!='') + { + $pdf->SetXY($_PosX+$xleft, $_PosY+1); // Only 1 mm and not ytop for top text + $pdf->Cell($this->_Width-2*$xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header),0,1,'C'); + } + + $ytop += (empty($header)?0:(1+$this->_Line_Height)); + + // Define widthtouse and heighttouse + $pageMargins = $pdf->getMargins(); + $maxwidthtouse = round($this->_Width - 2*$xleft); + $maxheighttouse = round($this->_Height - 2*$ytop); + $maxheighttouse -= (empty($footer)?0:(1+$this->_Line_Height)); + $defaultratio = ($maxwidthtouse/$maxheighttouse); + $widthtouse = $maxwidthtouse; + $heighttouse = $maxheighttouse; + $logoHeight = $heighttouse; + $logoWidth = $heighttouse; + + //var_dump($this->_Width.'x'.$this->_Height.' with border and scale '.$imgscale.' => max '.$maxwidthtouse.'x'.$maxheighttouse.' => We use '.$widthtouse.'x'.$heighttouse);exit; + + // Center + if ($textright=='') // Only a left part + { + // Output left area + if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+$xleft, $_PosY+$ytop, 0, $logoHeight); + else if ($code && !empty($encoding)) + { + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse, $heighttouse); + } + else + { + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); + } + } + else if ($textleft!='' && $textright!='') // left and right part + { + if (($textleft == '%LOGO%' || $textleft == '%PHOTO%' || $textleft == '%BARCODE%') && !strstr($textright, '%') ) // left part logo/barcode right part text + { + if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+$xleft, $_PosY+$ytop, $widthtouse/2, 0); + else if ($code && !empty($encoding)) + { + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse/2, $heighttouse); + } + $pdf->SetXY($_PosX+($widthtouse/2), $_PosY+$ytop); + $pdf->MultiCell($widthtouse/2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); + } + else if (($textright == '%LOGO%' || $textright == '%PHOTO%' || $textright == '%BARCODE%') && !strstr($textleft, '%')) // right part logo/barcode left part text + { + if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+($widthtouse/2), $_PosY+$ytop, $widthtouse/2, 0); + else if ($code && !empty($encoding)) + { + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+($widthtouse/2), $_PosY+$ytop, $widthtouse/2, $heighttouse); + } + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell($widthtouse/2, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); + } + else if ($textleft == '%LOGO%') // left part logo right part text/barcode + { + if ($logo) $pdf->Image($logo, $_PosX+$xleft, $_PosY+$ytop, 0, $logoHeight); + if ($code && !empty($encoding)) + { + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft+$logoWidth+1, $_PosY+$ytop, $widthtouse-$logoWidth-1, $heighttouse); + } else { + $pdf->SetXY($_PosX+$xleft+$logoWidth+1, $_PosY+$ytop); + $pdf->MultiCell($widthtouse-$logoWidth1-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); + } + } + else if ($textright == '%LOGO%') // right part logo left part text/barcode + { + if ($logo) $pdf->Image($logo, $_PosX+$xleft+$widthtouse-$logoWidth+1, $_PosY+$ytop, 0, $logoHeight); + if ($code && !empty($encoding)) + { + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse-$logoWidth-1, $heighttouse); + } else { + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell($widthtouse-$logoWidth-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); + } + } + else // text on halft left and text on half right + { + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell(round($this->_Width/2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); + $pdf->SetXY($_PosX+round($this->_Width/2), $_PosY+$ytop); + $pdf->MultiCell(round($this->_Width/2)-2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); + } + } + else // Only a right part + { + // Output right area + if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+$this->_Width-$widthtouse-$xleft, $_PosY+$ytop, 0, $logoHeight); + else if ($code && !empty($encoding)) + { + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$this->_Width-$widthtouse-$xleft, $_PosY+$ytop, $widthtouse, $heighttouse); + } + else + { + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell($this->_Width-$xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); + } + } + + // Bottom + if ($footer!='') + { + $pdf->SetXY($_PosX, $_PosY+$this->_Height-$this->_Line_Height-1); + $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer),0,1,'C'); + } + //print "$_PosY+$this->_Height-$this->_Line_Height-1
\n"; + + $this->_COUNTY++; + + if ($this->_COUNTY == $this->_Y_Number) { + // Si on est en bas de page, on remonte le 'curseur' de position + $this->_COUNTX++; + $this->_COUNTY=0; + } + + if ($this->_COUNTX == $this->_X_Number) { + // Si on est en bout de page, alors on repart sur une nouvelle page + $this->_COUNTX=0; + $this->_COUNTY=0; + } + } + + + + + /** + * Function to build PDF on disk, then output on HTTP strem. + * + * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) + * @param Translate $outputlangs Lang object for output language + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param string $outputdir Output directory for pdf file + * @return int 1=OK, 0=KO + */ + function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='') + { + global $user,$conf,$langs,$mysoc,$_Avery_Labels; + + $this->code=$srctemplatepath; + $this->Tformat = $_Avery_Labels[$this->code]; + if (empty($this->Tformat)) { dol_print_error('','ErrorBadTypeForCard'.$this->code); exit; } + $this->type = 'pdf'; + $this->format = $this->Tformat['paper-size']; + + if (! is_object($outputlangs)) $outputlangs=$langs; + // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO + if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; + + $outputlangs->load("main"); + $outputlangs->load("dict"); + $outputlangs->load("companies"); + $outputlangs->load("admin"); + + $title=$outputlangs->transnoentities('Labels'); + $keywords=$title." ".$outputlangs->convToOutputCharset($mysoc->name); + + $dir = (empty($outputdir)?$conf->adherent->dir_temp:$outputdir); + $filename='tmp_address_sheet.pdf'; + $file = $dir."/".$filename; + + if (! file_exists($dir)) + { + if (dol_mkdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } + + $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); + + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); + + $pdf->SetTitle($title); + $pdf->SetSubject($title); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); + $pdf->SetKeyWords($keywords); + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); + + $pdf->SetMargins(0,0); + $pdf->SetAutoPageBreak(false); + + $this->_Metric_Doc = $this->Tformat['metric']; + // Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie + $posX=1; + $posY=1; + if ($posX > 0) $posX--; else $posX=0; + if ($posY > 0) $posY--; else $posY=0; + $this->_COUNTX = $posX; + $this->_COUNTY = $posY; + $this->_Set_Format($pdf, $this->Tformat); + + + $pdf->Open(); + $pdf->AddPage(); + + + // Add each record + foreach($arrayofrecords as $val) + { + // imprime le texte specifique sur la carte + $this->addSticker($pdf, $outputlangs, $val); + } + + //$pdf->SetXY(10, 295); + //$pdf->Cell($this->_Width, $this->_Line_Height, 'XXX',0,1,'C'); + + + // Output to file + $pdf->Output($file,'F'); + + if (! empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); + + + + // Output to http stream + clearstatcache(); + + $attachment=true; + if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; + $type=dol_mimetype($filename); + + //if ($encoding) header('Content-Encoding: '.$encoding); + if ($type) header('Content-Type: '.$type); + if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); + else header('Content-Disposition: inline; filename="'.$filename.'"'); + + // Ajout directives pour resoudre bug IE + header('Cache-Control: Public, must-revalidate'); + header('Pragma: public'); + + readfile($file); + + return 1; + } +} diff --git a/htdocs/core/modules/printsheet/modules_labels.php b/htdocs/core/modules/printsheet/modules_labels.php index 15ef011ea04..1b077f8eab5 100644 --- a/htdocs/core/modules/printsheet/modules_labels.php +++ b/htdocs/core/modules/printsheet/modules_labels.php @@ -67,9 +67,10 @@ class ModelePDFLabels * @param string $modele Force le modele a utiliser ('' to not force) * @param Translate $outputlangs Objet lang a utiliser pour traduction * @param string $outputdir Output directory + * @param string $template pdf generenate document class to use default 'standardlabel' * @return int <0 if KO, >0 if OK */ -function members_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $outputdir='') +function members_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $outputdir='', $template='standardlabel') { global $conf,$langs; $langs->load("members"); @@ -98,13 +99,12 @@ function members_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $ } } else $code=$modele; - $modele='standardlabel'; // If selected modele is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); + $tmp=explode(':',$template,2); if (! empty($tmp[1])) { - $modele=$tmp[0]; + $template=$tmp[0]; $srctemplatepath=$tmp[1]; } else $srctemplatepath=$code; @@ -117,14 +117,14 @@ function members_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $ { foreach(array('doc','pdf') as $prefix) { - $file = $prefix."_".$modele.".class.php"; + $file = $prefix."_".$template.".class.php"; // On verifie l'emplacement du modele $file=dol_buildpath($reldir."core/modules/printsheet/doc/".$file,0); if (file_exists($file)) { $filefound=1; - $classname=$prefix.'_'.$modele; + $classname=$prefix.'_'.$template; break; } } From f9908c48cbc2c9db8081b204286ce9ca5f77202e Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 3 May 2015 10:07:04 +0200 Subject: [PATCH 24/36] Add datamatrix en qrcode barcodes --- .../modules/barcode/doc/tcpdfbarcode.modules.php | 2 +- htdocs/core/modules/modBarcode.class.php | 12 ++++++++---- htdocs/langs/en_US/admin.lang | 2 ++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php index d608543d5f5..56acdc704cb 100644 --- a/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php +++ b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php @@ -194,7 +194,7 @@ class modTcpdfbarcode extends ModeleBarCode * @param string $dolEncodingType dolibarr barcode encoding type * @return string tcpdf encoding type */ - private function getTcpdfEncodingType($dolEncodingType) + public function getTcpdfEncodingType($dolEncodingType) { $tcpdf1dEncodingTypes = array( 'C39' => 'C39', diff --git a/htdocs/core/modules/modBarcode.class.php b/htdocs/core/modules/modBarcode.class.php index c9ba87250bb..780a3539bf5 100644 --- a/htdocs/core/modules/modBarcode.class.php +++ b/htdocs/core/modules/modBarcode.class.php @@ -65,9 +65,11 @@ class modBarcode extends DolibarrModules // Constants // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0), // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) ); - $this->const = array( - //0=>array('GENBARCODE_LOCATION','chaine',DOL_DOCUMENT_ROOT.'/includes/barcode/genbarcode/genbarcode','Path to genbarcode command line tool',0) - ); + $this->const = array(); + //$this->const[0] = array('BARCODE_LABEL_LEFT_TEXT','chaine','%BARCODE%','Print barcode on left side of label',1); + //$this->const[1] = array('BARCODE_LABEL_RIGHT_TEXT','chaine','%LOGO%','Print Company logo on right side',1); + //$this->const[2] = array('BARCODE_LABEL_HEADER_TEXT','chaine','My header','Print header text on label',1); + //$this->const[3] = array('BARCODE_LABEL_FOOTER_TEXT','chaine','My footer','Print footer text on label',1); // Boxes $this->boxes = array(); @@ -137,7 +139,9 @@ class modBarcode extends DolibarrModules array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('UPC', 'UPC', 0, '123456789012', __ENTITY__)",'ignoreerror'=>1), array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('ISBN', 'ISBN', 0, '123456789', __ENTITY__)",'ignoreerror'=>1), array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('C39', 'Code 39', 0, '1234567890', __ENTITY__)",'ignoreerror'=>1), - array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('C128', 'Code 128', 0, 'ABCD1234567890', __ENTITY__)",'ignoreerror'=>1) + array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('C128', 'Code 128', 0, 'ABCD1234567890', __ENTITY__)",'ignoreerror'=>1), + array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('DATAMATRIX', 'Datamatrix', 0, '1234567xyz', __ENTITY__)",'ignoreerror'=>1), + array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('QRCODE', 'Qr Code', 0, 'www.dolibarr.org', __ENTITY__)",'ignoreerror'=>1) ); return $this->_init($sql, $options); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index f6041a2abf0..09aafd228f7 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1422,6 +1422,8 @@ BarcodeDescUPC=Barcode of type UPC BarcodeDescISBN=Barcode of type ISBN BarcodeDescC39=Barcode of type C39 BarcodeDescC128=Barcode of type C128 +BarcodeDescDATAMATRIX=Barcode of type Datamatrix +BarcodeDescQRCODE=Barcode of type QR code GenbarcodeLocation=Bar code generation command line tool (used by internal engine for some bar code types). Must be compatible with "genbarcode".
For example: /usr/local/bin/genbarcode BarcodeInternalEngine=Internal engine BarCodeNumberManager=Manager to auto define barcode numbers From ffe767154919204dc7e086d1072b9a07fe23d570 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 3 May 2015 10:08:32 +0200 Subject: [PATCH 25/36] Fix label L7163 X spacing --- htdocs/core/lib/format_cards.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/format_cards.lib.php b/htdocs/core/lib/format_cards.lib.php index 29789791e14..b0b865c89f4 100644 --- a/htdocs/core/lib/format_cards.lib.php +++ b/htdocs/core/lib/format_cards.lib.php @@ -111,7 +111,7 @@ $_Avery_Labels = array ( 'marginTop'=>15, 'NX'=>2, 'NY'=>7, - 'SpaceX'=>25, + 'SpaceX'=>2.5, 'SpaceY'=>0, 'width'=>99.1, 'height'=>38.1, From f9ece24f9572733f9112e50037864178e58ba253 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 3 May 2015 10:09:31 +0200 Subject: [PATCH 26/36] Fix: Member card header/footer text --- htdocs/core/modules/modAdherent.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modAdherent.class.php b/htdocs/core/modules/modAdherent.class.php index a1c90f242a6..fb8d9c01e15 100644 --- a/htdocs/core/modules/modAdherent.class.php +++ b/htdocs/core/modules/modAdherent.class.php @@ -80,8 +80,8 @@ class modAdherent extends DolibarrModules $this->const[21] = array("ADHERENT_MAIL_FROM","chaine","","From des mails"); $this->const[22] = array("ADHERENT_MAIL_COTIS","texte","Bonjour %FIRSTNAME%,\r\nCet email confirme que votre cotisation a été reçue\r\net enregistrée","Mail de validation de cotisation"); $this->const[23] = array("ADHERENT_MAIL_COTIS_SUBJECT","chaine","Reçu de votre cotisation","Sujet du mail de validation de cotisation"); - $this->const[25] = array("ADHERENT_CARD_HEADER_TEXT","chaine","%ANNEE%","Texte imprimé sur le haut de la carte adhérent"); - $this->const[26] = array("ADHERENT_CARD_FOOTER_TEXT","chaine","Association AZERTY","Texte imprimé sur le bas de la carte adhérent"); + $this->const[25] = array("ADHERENT_CARD_HEADER_TEXT","chaine","%YEAR%","Texte imprimé sur le haut de la carte adhérent"); + $this->const[26] = array("ADHERENT_CARD_FOOTER_TEXT","chaine","%COMPANY%","Texte imprimé sur le bas de la carte adhérent"); $this->const[27] = array("ADHERENT_CARD_TEXT","texte","%FULLNAME%\r\nID: %ID%\r\n%EMAIL%\r\n%ADDRESS%\r\n%ZIP% %TOWN%\r\n%COUNTRY%","Text to print on member cards"); $this->const[28] = array("ADHERENT_MAILMAN_ADMINPW","chaine","","Mot de passe Admin des liste mailman"); $this->const[31] = array("ADHERENT_BANK_USE_AUTO","yesno","","Insertion automatique des cotisations dans le compte banquaire"); From fee4c4e0e27ec29659e2ab9aab0a28917336f1e2 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 3 May 2015 10:26:12 +0200 Subject: [PATCH 27/36] Fix: add newline at eof --- htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php index 56acdc704cb..71057359e7c 100644 --- a/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php +++ b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php @@ -249,4 +249,4 @@ class modTcpdfbarcode extends ModeleBarCode return ''; } } -} \ No newline at end of file +} From cb75d0778a9ed850dfe5b958846d3df2cce8dd6b Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 3 May 2015 11:09:33 +0200 Subject: [PATCH 28/36] Fix doc errors --- htdocs/core/class/commonstickergenerator.class.php | 10 +++++----- htdocs/core/modules/member/doc/pdf_standard.class.php | 4 ++-- .../modules/printsheet/doc/pdf_standardlabel.class.php | 4 ++-- .../modules/printsheet/doc/pdf_tcpdflabel.class.php | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/htdocs/core/class/commonstickergenerator.class.php b/htdocs/core/class/commonstickergenerator.class.php index 50a0c929a7e..1091962f6ea 100644 --- a/htdocs/core/class/commonstickergenerator.class.php +++ b/htdocs/core/class/commonstickergenerator.class.php @@ -108,7 +108,7 @@ abstract class CommonStickerGenerator /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param Translate $outputlangs Output langs * @param array $param Associative array containing label content and optional parameters * @return void @@ -119,7 +119,7 @@ abstract class CommonStickerGenerator * Methode qui permet de modifier la taille des caracteres * Cela modiera aussi l'espace entre chaque ligne * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param int $pt point * @return void */ @@ -135,7 +135,7 @@ abstract class CommonStickerGenerator /** * protected Print dot line * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param int $x1 X1 * @param int $y1 Y1 * @param int $x2 X2 @@ -176,7 +176,7 @@ abstract class CommonStickerGenerator /** * protected Function realisant une croix aux 4 coins des cartes * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param int $x1 X1 * @param int $y1 Y1 * @param int $x2 X2 @@ -247,7 +247,7 @@ abstract class CommonStickerGenerator /** * protected Set format * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param string $format Format * @return void */ diff --git a/htdocs/core/modules/member/doc/pdf_standard.class.php b/htdocs/core/modules/member/doc/pdf_standard.class.php index 7df37a7c05c..40d74648ee3 100644 --- a/htdocs/core/modules/member/doc/pdf_standard.class.php +++ b/htdocs/core/modules/member/doc/pdf_standard.class.php @@ -37,7 +37,7 @@ class pdf_standard extends CommonStickerGenerator /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param Translate $outputlangs Output langs * @param array $param Associative array containing label content and optional parameters * @return void @@ -51,7 +51,7 @@ class pdf_standard extends CommonStickerGenerator * - %LOGO% is replace with company logo * - %PHOTO% is replace with photo provided as parameter * - * @param PDF &$pdf PDF + * @param PDF $pdf PDF * @param string $textleft Text left * @param string $header Header * @param string $footer Footer diff --git a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php index d9d9b825a4b..a6e9bce07c8 100644 --- a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php +++ b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php @@ -36,7 +36,7 @@ class pdf_standardlabel extends CommonStickerGenerator /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param Translate $outputlangs Output langs * @param array $param Associative array containing label content and optional parameters * @return void @@ -50,7 +50,7 @@ class pdf_standardlabel extends CommonStickerGenerator * - %LOGO% is replace with company logo * - %PHOTO% is replace with photo provided as parameter * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param string $textleft Text left * @param string $header Header * @param string $footer Footer diff --git a/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php b/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php index e73c112d26e..1e5c74c299a 100644 --- a/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php +++ b/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php @@ -69,7 +69,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator /** * write barcode to pdf * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param string $code code to print * @param string $encoding type of barcode * @param boolean $is2d true if 2d barcode @@ -90,7 +90,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - * @param PDF &$pdf PDF reference + * @param PDF $pdf PDF reference * @param Translate $outputlangs Output langs * @param array $param Associative array containing label content and optional parameters * @return void From 2b32dc4ba89543582d4b7b2279032c5f65416a8e Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 3 May 2015 11:51:54 +0200 Subject: [PATCH 29/36] Apply correct tabulation --- htdocs/barcode/printsheet.php | 121 +++--- .../barcode/doc/tcpdfbarcode.modules.php | 332 +++++++-------- .../modules/member/doc/pdf_standard.class.php | 76 ++-- htdocs/core/modules/member/modules_cards.php | 34 +- htdocs/core/modules/modBarcode.class.php | 108 ++--- .../doc/pdf_standardlabel.class.php | 224 +++++----- .../printsheet/doc/pdf_tcpdflabel.class.php | 382 +++++++++--------- 7 files changed, 638 insertions(+), 639 deletions(-) diff --git a/htdocs/barcode/printsheet.php b/htdocs/barcode/printsheet.php index 7cd539bf323..81af2aafa10 100644 --- a/htdocs/barcode/printsheet.php +++ b/htdocs/barcode/printsheet.php @@ -1,7 +1,7 @@ - * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2006-2013 Laurent Destailleur +/* Copyright (C) 2003 Rodolphe Quiedeville + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2006-2013 Laurent Destailleur * * 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 @@ -10,7 +10,7 @@ * * 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 + * 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 @@ -18,9 +18,9 @@ */ /** - * \file htdocs/barcode/printsheet.php - * \ingroup member - * \brief Page to print sheets with barcodes using the document templates into core/modules/printsheets + * \file htdocs/barcode/printsheet.php + * \ingroup member + * \brief Page to print sheets with barcodes using the document templates into core/modules/printsheets */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php'; @@ -96,13 +96,13 @@ if ($action == 'builddoc') if (empty($forbarcode)) // barcode value { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeValue")),'errors'); - $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeValue")),'errors'); + $error++; } if (empty($fk_barcode_type)) // barcode type = barcode encoding { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeType")),'errors'); - $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeType")),'errors'); + $error++; } if (! $error) @@ -123,55 +123,54 @@ if ($action == 'builddoc') $code=$forbarcode; $generator=$stdobject->barcode_type_coder; // coder (loaded by fetch_barcode). Engine. $encoding=strtoupper($stdobject->barcode_type_code); // code (loaded by fetch_barcode). Example 'ean', 'isbn', ... - $diroutput=$conf->barcode->dir_temp; dol_mkdir($diroutput); // Generate barcode - $dirbarcode=array_merge(array("/core/modules/barcode/doc/"),$conf->modules_parts['barcode']); + $dirbarcode=array_merge(array("/core/modules/barcode/doc/"),$conf->modules_parts['barcode']); - foreach($dirbarcode as $reldir) - { - $dir=dol_buildpath($reldir,0); - $newdir=dol_osencode($dir); + foreach($dirbarcode as $reldir) + { + $dir=dol_buildpath($reldir,0); + $newdir=dol_osencode($dir); - // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php) - if (! is_dir($newdir)) continue; + // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php) + if (! is_dir($newdir)) continue; - $result=@include_once $newdir.$generator.'.modules.php'; - if ($result) break; - } - - // Load barcode class for generating barcode image - $classname = "mod".ucfirst($generator); - $module = new $classname($db); - if ($generator != 'tcpdfbarcode') { - $template = 'standardlabel'; - $is2d = false; - if ($module->encodingIsSupported($encoding)) - { - $barcodeimage=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; - dol_delete_file($barcodeimage); - // File is created with full name $barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; - $result=$module->writeBarCode($code,$encoding,'Y',4); - - if ($result <= 0 || ! dol_is_file($barcodeimage)) - { - $error++; - setEventMessage('Failed to generate image file of barcode for code='.$code.' encoding='.$encoding.' file='.basename($barcodeimage), 'errors'); - } - } - else - { - $error++; - setEventMessage("Error, encoding ".$encoding." is not supported by encoder ".$generator.'. You must choose another barcode type or install a barcode generation engine that support '.$encoding, 'errors'); - } - } else { - $template = 'tcpdflabel'; - $encoding = $module->getTcpdfEncodingType($encoding); //convert to TCPDF compatible encoding types - $is2d = $module->is2d; - } + $result=@include_once $newdir.$generator.'.modules.php'; + if ($result) break; + } + + // Load barcode class for generating barcode image + $classname = "mod".ucfirst($generator); + $module = new $classname($db); + if ($generator != 'tcpdfbarcode') { + $template = 'standardlabel'; + $is2d = false; + if ($module->encodingIsSupported($encoding)) + { + $barcodeimage=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; + dol_delete_file($barcodeimage); + // File is created with full name $barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; + $result=$module->writeBarCode($code,$encoding,'Y',4); + + if ($result <= 0 || ! dol_is_file($barcodeimage)) + { + $error++; + setEventMessage('Failed to generate image file of barcode for code='.$code.' encoding='.$encoding.' file='.basename($barcodeimage), 'errors'); + } + } + else + { + $error++; + setEventMessage("Error, encoding ".$encoding." is not supported by encoder ".$generator.'. You must choose another barcode type or install a barcode generation engine that support '.$encoding, 'errors'); + } + } else { + $template = 'tcpdflabel'; + $encoding = $module->getTcpdfEncodingType($encoding); //convert to TCPDF compatible encoding types + $is2d = $module->is2d; + } } if (! $error) @@ -198,7 +197,7 @@ if ($action == 'builddoc') if ($mode == 'label') { - $txtforsticker="%PHOTO%"; // Photo will be barcode image, %BARCODE% posible when using TCPDF generator + $txtforsticker="%PHOTO%"; // Photo will be barcode image, %BARCODE% posible when using TCPDF generator $textleft=make_substitutions((empty($conf->global->BARCODE_LABEL_LEFT_TEXT)?$txtforsticker:$conf->global->BARCODE_LABEL_LEFT_TEXT), $substitutionarray); $textheader=make_substitutions((empty($conf->global->BARCODE_LABEL_HEADER_TEXT)?'':$conf->global->BARCODE_LABEL_HEADER_TEXT), $substitutionarray); $textfooter=make_substitutions((empty($conf->global->BARCODE_LABEL_FOOTER_TEXT)?'':$conf->global->BARCODE_LABEL_FOOTER_TEXT), $substitutionarray); @@ -213,9 +212,9 @@ if ($action == 'builddoc') 'textheader'=>$textheader, 'textfooter'=>$textfooter, 'textright'=>$textright, - 'code'=>$code, - 'encoding'=>$encoding, - 'is2d'=>$is2d, + 'code'=>$code, + 'encoding'=>$encoding, + 'is2d'=>$is2d, 'photo'=>$barcodeimage // Photo must be a file that exists with format supported by TCPDF ); } @@ -243,11 +242,11 @@ if ($action == 'builddoc') dol_print_error('',$result); } - if (! $mesg) - { - $db->close(); - exit; - } + if (! $mesg) + { + $db->close(); + exit; + } } } diff --git a/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php index 71057359e7c..eb1b801821b 100644 --- a/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php +++ b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php @@ -1,7 +1,7 @@ - * Copyright (C) 2005 Regis Houssin - * Copyright (C) 2015 Francis Appels +/* Copyright (C) 2005-2009 Laurent Destailleur + * Copyright (C) 2005 Regis Houssin + * Copyright (C) 2015 Francis Appels * * 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 @@ -10,7 +10,7 @@ * * 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 + * 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 @@ -18,13 +18,13 @@ */ /** - * \file htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php - * \ingroup barcode - * \brief File of class to manage barcode numbering with tcpdf library + * \file htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php + * \ingroup barcode + * \brief File of class to manage barcode numbering with tcpdf library */ require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/modules_barcode.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // This is to include def like $genbarcode_loc and $font_loc +require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // This is to include def like $genbarcode_loc and $font_loc /** * Class to generate barcode images using tcpdf barcode generator @@ -35,39 +35,39 @@ class modTcpdfbarcode extends ModeleBarCode var $error=''; var $is2d = false; - /** - * Return description of numbering model - * - * @return string Text with description - */ - function info() - { - global $langs; - - return 'TCPDF-barcode'; - } - - /** - * Return if a module can be used or not + /** + * Return description of numbering model * - * @return boolean true if module can be used + * @return string Text with description + */ + function info() + { + global $langs; + + return 'TCPDF-barcode'; + } + + /** + * Return if a module can be used or not + * + * @return boolean true if module can be used */ function isEnabled() { return true; - } + } /** - * Test si les numeros deja en vigueur dans la base ne provoquent pas de - * de conflits qui empechera cette numerotation de fonctionner. + * Test si les numeros deja en vigueur dans la base ne provoquent pas de + * de conflits qui empechera cette numerotation de fonctionner. * - * @return boolean false si conflit, true si ok + * @return boolean false si conflit, true si ok */ function canBeActivated() { - global $langs; + global $langs; - return true; + return true; } /** @@ -78,28 +78,28 @@ class modTcpdfbarcode extends ModeleBarCode */ function encodingIsSupported($encoding) { - $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); - if (empty($tcpdfEncoding)) { - return 0; - } else { - return 1; - } + $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); + if (empty($tcpdfEncoding)) { + return 0; + } else { + return 1; + } } - /** + /** * Return an image file on the fly (no need to write on disk) * - * @param String $code Value to encode - * @param String $encoding Mode of encoding - * @param String $readable Code can be read + * @param String $code Value to encode + * @param String $encoding Mode of encoding + * @param String $readable Code can be read * @return int <0 if KO, >0 if OK - */ - function buildBarCode($code,$encoding,$readable='Y') - { - global $_GET; - - $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); - if (empty($tcpdfEncoding)) return -1; + */ + function buildBarCode($code,$encoding,$readable='Y') + { + global $_GET; + + $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); + if (empty($tcpdfEncoding)) return -1; $color = array(0,0,0); @@ -109,45 +109,45 @@ class modTcpdfbarcode extends ModeleBarCode $_GET["readable"]=$readable; if ($code) { - // Load the tcpdf barcode class - if ($this->is2d) { - $height = 3; - $width = 3; - require_once TCPDF_PATH.'tcpdf_barcodes_2d.php'; - $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding); - } else { - $height = 50; - $width = 1; - require_once TCPDF_PATH.'tcpdf_barcodes_1d.php'; - $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding); - } - - dol_syslog("buildBarCode::TCPDF.getBarcodePNG"); - $barcodeobj->getBarcodePNG($width, $height, $color); - - return 1; + // Load the tcpdf barcode class + if ($this->is2d) { + $height = 3; + $width = 3; + require_once TCPDF_PATH.'tcpdf_barcodes_2d.php'; + $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding); + } else { + $height = 50; + $width = 1; + require_once TCPDF_PATH.'tcpdf_barcodes_1d.php'; + $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding); + } + + dol_syslog("buildBarCode::TCPDF.getBarcodePNG"); + $barcodeobj->getBarcodePNG($width, $height, $color); + + return 1; } else { - return -2; + return -2; } - } + } /** - * Save an image file on disk (with no output) - * - * @param String $code Value to encode - * @param String $encoding Mode of encoding - * @param String $readable Code can be read + * Save an image file on disk (with no output) + * + * @param String $code Value to encode + * @param String $encoding Mode of encoding + * @param String $readable Code can be read * @return int <0 if KO, >0 if OK - */ - function writeBarCode($code,$encoding,$readable='Y') - { - global $conf,$_GET; + */ + function writeBarCode($code,$encoding,$readable='Y') + { + global $conf,$_GET; dol_mkdir($conf->barcode->dir_temp); $file=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); - if (empty($tcpdfEncoding)) return -1; + if (empty($tcpdfEncoding)) return -1; $color = array(0,0,0); @@ -156,97 +156,97 @@ class modTcpdfbarcode extends ModeleBarCode $_GET["height"]=$height; $_GET["readable"]=$readable; - if ($code) { - // Load the tcpdf barcode class - if ($this->is2d) { - $height = 1; - $width = 1; - require_once TCPDF_PATH.'tcpdf_barcodes_2d.php'; - $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding); - } else { - $height = 50; - $width = 1; - require_once TCPDF_PATH.'tcpdf_barcodes_1d.php'; - $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding); - } - - dol_syslog("writeBarCode::TCPDF.getBarcodePngData"); - if ($imageData = $barcodeobj->getBarcodePngData($width, $height, $color)) { - if (function_exists('imagecreate')) { - $imageData = imagecreatefromstring($imageData); - } - if (imagepng($imageData, $file)) { - return 1; - } else { - return -3; - } - } else { - return -4; - } + if ($code) { + // Load the tcpdf barcode class + if ($this->is2d) { + $height = 1; + $width = 1; + require_once TCPDF_PATH.'tcpdf_barcodes_2d.php'; + $barcodeobj = new TCPDF2DBarcode($code, $tcpdfEncoding); + } else { + $height = 50; + $width = 1; + require_once TCPDF_PATH.'tcpdf_barcodes_1d.php'; + $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding); + } + + dol_syslog("writeBarCode::TCPDF.getBarcodePngData"); + if ($imageData = $barcodeobj->getBarcodePngData($width, $height, $color)) { + if (function_exists('imagecreate')) { + $imageData = imagecreatefromstring($imageData); + } + if (imagepng($imageData, $file)) { + return 1; + } else { + return -3; + } + } else { + return -4; + } } else { - return -2; + return -2; } - } - - /** - * get available output_modes for tcpdf class wth its translated description - * - * @param string $dolEncodingType dolibarr barcode encoding type - * @return string tcpdf encoding type - */ - public function getTcpdfEncodingType($dolEncodingType) - { - $tcpdf1dEncodingTypes = array( - 'C39' => 'C39', - 'C39+' => 'C39+', - 'C39E' => 'C39E', - 'C39E+' => 'C39E+', - 'S25' => 'S25', - 'S25+' => 'S25+', - 'I25' => 'I25', - 'I25+' => 'I25+', - 'C128' => 'C128', - 'C128A' => 'C128A', - 'C128B' => 'C128B', - 'C128C' => 'C128C', - 'EAN2' => 'EAN2', - 'EAN5' => 'EAN5', - 'EAN8' => 'EAN8', - 'EAN13' => 'EAN13', - 'ISBN' => 'EAN13', - 'UPC' => 'UPCA', - 'UPCE' => 'UPCE', - 'MSI' => 'MSI', - 'MSI+' => 'MSI+', - 'POSTNET' => 'POSTNET', - 'PLANET' => 'PLANET', - 'RMS4CC' => 'RMS4CC', - 'KIX' => 'KIX', - 'IMB' => 'IMB', - 'CODABAR' => 'CODABAR', - 'CODE11' => 'CODE11', - 'PHARMA' => 'PHARMA', - 'PHARMA2T' => 'PHARMA2T' - ); - - $tcpdf2dEncodingTypes = array( - 'DATAMATRIX' => 'DATAMATRIX', - 'PDF417' => 'PDF417', - 'QRCODE' => 'QRCODE,L', - 'QRCODE,L' => 'QRCODE,L', - 'QRCODE,M' => 'QRCODE,M', - 'QRCODE,Q' => 'QRCODE,Q', - 'QRCODE,H' => 'QRCODE,H' - ); - - if (array_key_exists($dolEncodingType, $tcpdf1dEncodingTypes)) { - $this->is2d = false; - return $tcpdf1dEncodingTypes[$dolEncodingType]; - } else if (array_key_exists($dolEncodingType, $tcpdf2dEncodingTypes)) { - $this->is2d = true; - return $tcpdf2dEncodingTypes[$dolEncodingType]; - } else { - return ''; - } - } + } + + /** + * get available output_modes for tcpdf class wth its translated description + * + * @param string $dolEncodingType dolibarr barcode encoding type + * @return string tcpdf encoding type + */ + public function getTcpdfEncodingType($dolEncodingType) + { + $tcpdf1dEncodingTypes = array( + 'C39' => 'C39', + 'C39+' => 'C39+', + 'C39E' => 'C39E', + 'C39E+' => 'C39E+', + 'S25' => 'S25', + 'S25+' => 'S25+', + 'I25' => 'I25', + 'I25+' => 'I25+', + 'C128' => 'C128', + 'C128A' => 'C128A', + 'C128B' => 'C128B', + 'C128C' => 'C128C', + 'EAN2' => 'EAN2', + 'EAN5' => 'EAN5', + 'EAN8' => 'EAN8', + 'EAN13' => 'EAN13', + 'ISBN' => 'EAN13', + 'UPC' => 'UPCA', + 'UPCE' => 'UPCE', + 'MSI' => 'MSI', + 'MSI+' => 'MSI+', + 'POSTNET' => 'POSTNET', + 'PLANET' => 'PLANET', + 'RMS4CC' => 'RMS4CC', + 'KIX' => 'KIX', + 'IMB' => 'IMB', + 'CODABAR' => 'CODABAR', + 'CODE11' => 'CODE11', + 'PHARMA' => 'PHARMA', + 'PHARMA2T' => 'PHARMA2T' + ); + + $tcpdf2dEncodingTypes = array( + 'DATAMATRIX' => 'DATAMATRIX', + 'PDF417' => 'PDF417', + 'QRCODE' => 'QRCODE,L', + 'QRCODE,L' => 'QRCODE,L', + 'QRCODE,M' => 'QRCODE,M', + 'QRCODE,Q' => 'QRCODE,Q', + 'QRCODE,H' => 'QRCODE,H' + ); + + if (array_key_exists($dolEncodingType, $tcpdf1dEncodingTypes)) { + $this->is2d = false; + return $tcpdf1dEncodingTypes[$dolEncodingType]; + } else if (array_key_exists($dolEncodingType, $tcpdf2dEncodingTypes)) { + $this->is2d = true; + return $tcpdf2dEncodingTypes[$dolEncodingType]; + } else { + return ''; + } + } } diff --git a/htdocs/core/modules/member/doc/pdf_standard.class.php b/htdocs/core/modules/member/doc/pdf_standard.class.php index 40d74648ee3..c421ae1cda4 100644 --- a/htdocs/core/modules/member/doc/pdf_standard.class.php +++ b/htdocs/core/modules/member/doc/pdf_standard.class.php @@ -2,8 +2,8 @@ /* Copyright (C) 2003 Steve Dillon * Copyright (C) 2003 Laurent Passebecq * Copyright (C) 2001-2003 Rodolphe Quiedeville - * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2002-2003 Jean-Louis Bergamo + * Copyright (C) 2006-2013 Laurent Destailleur * Copyright (C) 2015 Francis Appels * * This program is free software; you can redistribute it and/or modify @@ -13,7 +13,7 @@ * * 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 + * 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 @@ -21,9 +21,9 @@ */ /** - * \file htdocs/core/modules/member/doc/pdf_standard.class.php - * \ingroup member - * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise + * \file htdocs/core/modules/member/doc/pdf_standard.class.php + * \ingroup member + * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonstickergenerator.class.php'; @@ -37,37 +37,37 @@ class pdf_standard extends CommonStickerGenerator /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - * @param PDF $pdf PDF reference - * @param Translate $outputlangs Output langs - * @param array $param Associative array containing label content and optional parameters - * @return void + * @param PDF $pdf PDF reference + * @param Translate $outputlangs Output langs + * @param array $param Associative array containing label content and optional parameters + * @return void */ function addSticker(&$pdf,$outputlangs,$param) { - // use this method in future refactoring - } - - /** + // use this method in future refactoring + } + + /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - %LOGO% is replace with company logo * - %PHOTO% is replace with photo provided as parameter * - * @param PDF $pdf PDF - * @param string $textleft Text left - * @param string $header Header - * @param string $footer Footer - * @param Translate $outputlangs Output langs - * @param string $textright Text right - * @param int $idmember Id member - * @param string $photo Photo (full path to image file used as replacement for key %PHOTOS% into left, right, header or footer text) - * @return void + * @param PDF $pdf PDF + * @param string $textleft Text left + * @param string $header Header + * @param string $footer Footer + * @param Translate $outputlangs Output langs + * @param string $textright Text right + * @param int $idmember Id member + * @param string $photo Photo (full path to image file used as replacement for key %PHOTOS% into left, right, header or footer text) + * @return void */ function Add_PDF_card(&$pdf,$textleft,$header,$footer,$outputlangs,$textright='',$idmember=0,$photo='') { global $mysoc,$conf,$langs; global $forceimgscalewidth,$forceimgscaleheight; - $imgscalewidth=(empty($forceimgscalewidth)?0.3:$forceimgscalewidth); // Scale of image for width (1=Full width of sticker) - $imgscaleheight=(empty($forceimgscalewidth)?0.5:$forceimgscalewidth); // Scale of image for height (1=Full height of sticker) + $imgscalewidth=(empty($forceimgscalewidth)?0.3:$forceimgscalewidth); // Scale of image for width (1=Full width of sticker) + $imgscaleheight=(empty($forceimgscalewidth)?0.5:$forceimgscalewidth); // Scale of image for height (1=Full height of sticker) // We are in a new page, then we must add a page if (($this->_COUNTX ==0) && ($this->_COUNTY==0) and (!$this->_First==1)) { @@ -235,9 +235,9 @@ class pdf_standard extends CommonStickerGenerator * * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ...'id'=>,'photo'=>) * @param Translate $outputlangs Lang object for output language - * @param string $srctemplatepath Full path of source filename for generator using a template file - * @param string $mode Tell if doc module is called for 'member', ... - * @return int 1=OK, 0=KO + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param string $mode Tell if doc module is called for 'member', ... + * @return int 1=OK, 0=KO */ function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$mode='member') { @@ -261,8 +261,8 @@ class pdf_standard extends CommonStickerGenerator if (empty($mode) || $mode == 'member') { - $title=$outputlangs->transnoentities('MembersCards'); - $keywords=$outputlangs->transnoentities('MembersCards')." ".$outputlangs->transnoentities("Foundation")." ".$outputlangs->convToOutputCharset($mysoc->name); + $title=$outputlangs->transnoentities('MembersCards'); + $keywords=$outputlangs->transnoentities('MembersCards')." ".$outputlangs->transnoentities("Foundation")." ".$outputlangs->convToOutputCharset($mysoc->name); $outputdir=$conf->adherent->dir_temp; } else @@ -284,14 +284,14 @@ class pdf_standard extends CommonStickerGenerator } } - $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); + $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); - if (class_exists('TCPDF')) - { - $pdf->setPrintHeader(false); - $pdf->setPrintFooter(false); - } - $pdf->SetFont(pdf_getPDFFont($outputlangs)); + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); $pdf->SetTitle($title); $pdf->SetSubject($title); @@ -344,7 +344,7 @@ class pdf_standard extends CommonStickerGenerator $type=dol_mimetype($filename); //if ($encoding) header('Content-Encoding: '.$encoding); - if ($type) header('Content-Type: '.$type); + if ($type) header('Content-Type: '.$type); if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); else header('Content-Disposition: inline; filename="'.$filename.'"'); diff --git a/htdocs/core/modules/member/modules_cards.php b/htdocs/core/modules/member/modules_cards.php index ab5604f2f99..9a8b931125d 100644 --- a/htdocs/core/modules/member/modules_cards.php +++ b/htdocs/core/modules/member/modules_cards.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2009 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -20,9 +20,9 @@ */ /** - * \file htdocs/core/modules/member/modules_cards.php - * \ingroup member - * \brief File of parent class of document generator for members cards. + * \file htdocs/core/modules/member/modules_cards.php + * \ingroup member + * \brief File of parent class of document generator for members cards. */ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; @@ -38,11 +38,11 @@ class ModelePDFCards /** - * Return list of active generation modules + * Return list of active generation modules * - * @param DoliDB $db Database handler - * @param integer $maxfilenamelength Max length of value to show - * @return array List of templates + * @param DoliDB $db Database handler + * @param integer $maxfilenamelength Max length of value to show + * @return array List of templates */ function liste_modeles($db,$maxfilenamelength=0) { @@ -62,13 +62,13 @@ class ModelePDFCards /** * Cree un fichier de cartes de visites en fonction du modele de ADHERENT_CARDS_ADDON_PDF * - * @param DoliDB $db Database handler - * @param array $arrayofmembers Array of members + * @param DoliDB $db Database handler + * @param array $arrayofmembers Array of members * @param string $modele Force modele to use ('' to not force) * @param Translate $outputlangs Object langs to use for translation - * @param string $outputdir Output directory - * @param string $template pdf generenate document class to use default 'standard' - * @return int <0 if KO, >0 if OK + * @param string $outputdir Output directory + * @param string $template pdf generenate document class to use default 'standard' + * @return int <0 if KO, >0 if OK */ function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $outputdir='', $template='standard') { @@ -118,7 +118,7 @@ function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $o foreach(array('doc','pdf') as $prefix) { $file = $prefix."_".$template.".class.php"; - + // On verifie l'emplacement du modele $file=dol_buildpath($reldir."core/modules/member/doc/".$file,0); if (file_exists($file)) diff --git a/htdocs/core/modules/modBarcode.class.php b/htdocs/core/modules/modBarcode.class.php index 780a3539bf5..0d06c1657c2 100644 --- a/htdocs/core/modules/modBarcode.class.php +++ b/htdocs/core/modules/modBarcode.class.php @@ -1,7 +1,7 @@ - * Copyright (C) 2005-2008 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin +/* Copyright (C) 2005 Rodolphe Quiedeville + * Copyright (C) 2005-2008 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -10,7 +10,7 @@ * * 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 + * 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 @@ -18,11 +18,11 @@ */ /** - * \defgroup barcode Module barcode - * \brief Module pour gerer les codes barres - * \file htdocs/core/modules/modBarcode.class.php - * \ingroup barcode,produit - * \brief Fichier de description et activation du module Barcode + * \defgroup barcode Module barcode + * \brief Module pour gerer les codes barres + * \file htdocs/core/modules/modBarcode.class.php + * \ingroup barcode,produit + * \brief Fichier de description et activation du module Barcode */ include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; @@ -34,9 +34,9 @@ class modBarcode extends DolibarrModules { /** - * Constructor. Define names, constants, directories, boxes, permissions + * Constructor. Define names, constants, directories, boxes, permissions * - * @param DoliDB $db Database handler + * @param DoliDB $db Database handler */ function __construct($db) { @@ -56,7 +56,7 @@ class modBarcode extends DolibarrModules $this->dirs = array("/barcode/temp"); // Dependances - $this->depends = array(); // May be used for product or service or third party module + $this->depends = array(); // May be used for product or service or third party module $this->requiredby = array(); // Config pages @@ -64,12 +64,12 @@ class modBarcode extends DolibarrModules // Constants // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0), - // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) ); + // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) ); $this->const = array(); - //$this->const[0] = array('BARCODE_LABEL_LEFT_TEXT','chaine','%BARCODE%','Print barcode on left side of label',1); - //$this->const[1] = array('BARCODE_LABEL_RIGHT_TEXT','chaine','%LOGO%','Print Company logo on right side',1); - //$this->const[2] = array('BARCODE_LABEL_HEADER_TEXT','chaine','My header','Print header text on label',1); - //$this->const[3] = array('BARCODE_LABEL_FOOTER_TEXT','chaine','My footer','Print footer text on label',1); + //$this->const[0] = array('BARCODE_LABEL_LEFT_TEXT','chaine','%BARCODE%','Print barcode on left side of label',1); + //$this->const[1] = array('BARCODE_LABEL_RIGHT_TEXT','chaine','%LOGO%','Print Company logo on right side',1); + //$this->const[2] = array('BARCODE_LABEL_HEADER_TEXT','chaine','My header','Print header text on label',1); + //$this->const[3] = array('BARCODE_LABEL_FOOTER_TEXT','chaine','My footer','Print footer text on label',1); // Boxes $this->boxes = array(); @@ -90,43 +90,43 @@ class modBarcode extends DolibarrModules $this->rights[2][3] = 0; // La permission est-elle une permission par defaut $this->rights[2][4] = 'creer_advance'; - // Main menu entries - $r=0; - $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=tools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode - 'mainmenu'=>'tools', - 'leftmenu'=>'barcodeprint', - 'type'=>'left', // This is a Left menu entry - 'titre'=>'BarCodePrintsheet', - 'url'=>'/barcode/printsheet.php?mainmenu=tools&leftmenu=barcodeprint', - 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - 'position'=>200, - 'enabled'=>'$conf->barcode->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. - 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - 'target'=>'', - 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + // Main menu entries + $r=0; + $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=tools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + 'mainmenu'=>'tools', + 'leftmenu'=>'barcodeprint', + 'type'=>'left', // This is a Left menu entry + 'titre'=>'BarCodePrintsheet', + 'url'=>'/barcode/printsheet.php?mainmenu=tools&leftmenu=barcodeprint', + 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'position'=>200, + 'enabled'=>'$conf->barcode->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. + 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + 'target'=>'', + 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both $r++; - $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode - 'type'=>'left', // This is a Left menu entry + $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + 'type'=>'left', // This is a Left menu entry 'titre'=>'MassBarcodeInit', 'url'=>'/barcode/codeinit.php?mainmenu=home&leftmenu=modulesadmintools', - 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. 'position'=>300, - 'enabled'=>'$conf->barcode->enabled && $leftmenu=="modulesadmintools"', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. - 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + 'enabled'=>'$conf->barcode->enabled && $leftmenu=="modulesadmintools"', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. + 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules 'target'=>'', - 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both + 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both $r++; } - /** - * Function called when module is enabled. - * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. - * It also creates data directories. - * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories. + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO */ function init($options='') { @@ -140,26 +140,26 @@ class modBarcode extends DolibarrModules array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('ISBN', 'ISBN', 0, '123456789', __ENTITY__)",'ignoreerror'=>1), array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('C39', 'Code 39', 0, '1234567890', __ENTITY__)",'ignoreerror'=>1), array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('C128', 'Code 128', 0, 'ABCD1234567890', __ENTITY__)",'ignoreerror'=>1), - array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('DATAMATRIX', 'Datamatrix', 0, '1234567xyz', __ENTITY__)",'ignoreerror'=>1), - array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('QRCODE', 'Qr Code', 0, 'www.dolibarr.org', __ENTITY__)",'ignoreerror'=>1) + array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('DATAMATRIX', 'Datamatrix', 0, '1234567xyz', __ENTITY__)",'ignoreerror'=>1), + array('sql'=>"INSERT INTO ".MAIN_DB_PREFIX."c_barcode_type (code, libelle, coder, example, entity) VALUES ('QRCODE', 'Qr Code', 0, 'www.dolibarr.org', __ENTITY__)",'ignoreerror'=>1) ); return $this->_init($sql, $options); } - /** + /** * Function called when module is disabled. - * Remove from database constants, boxes and permissions from Dolibarr database. + * Remove from database constants, boxes and permissions from Dolibarr database. * Data directories are not deleted * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO - */ - function remove($options='') - { + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + function remove($options='') + { $sql = array(); return $this->_remove($sql, $options); - } + } } diff --git a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php index a6e9bce07c8..0bfb2d849c5 100644 --- a/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php +++ b/htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php @@ -2,8 +2,8 @@ /* Copyright (C) 2003 Steve Dillon * Copyright (C) 2003 Laurent Passebecq * Copyright (C) 2001-2003 Rodolphe Quiedeville - * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2002-2003 Jean-Louis Bergamo + * Copyright (C) 2006-2013 Laurent Destailleur * Copyright (C) 2015 Francis Appels * * This program is free software; you can redistribute it and/or modify @@ -13,7 +13,7 @@ * * 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 + * 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 @@ -21,9 +21,9 @@ */ /** - * \file htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php - * \ingroup core - * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise + * \file htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php + * \ingroup core + * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonstickergenerator.class.php'; @@ -33,41 +33,41 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonstickergenerator.class.php'; */ class pdf_standardlabel extends CommonStickerGenerator { - /** + /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - * @param PDF $pdf PDF reference - * @param Translate $outputlangs Output langs - * @param array $param Associative array containing label content and optional parameters - * @return void + * @param PDF $pdf PDF reference + * @param Translate $outputlangs Output langs + * @param array $param Associative array containing label content and optional parameters + * @return void */ function addSticker(&$pdf,$outputlangs,$param) { - // use this method in future refactoring - } - + // use this method in future refactoring + } + /** * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) * - %LOGO% is replace with company logo * - %PHOTO% is replace with photo provided as parameter * - * @param PDF $pdf PDF reference - * @param string $textleft Text left - * @param string $header Header - * @param string $footer Footer - * @param Translate $outputlangs Output langs - * @param string $textright Text right - * @param string $photo Photo (full path to image file used as replacement for key %PHOTOS% into left, right, header or footer text) - * @return void + * @param PDF $pdf PDF reference + * @param string $textleft Text left + * @param string $header Header + * @param string $footer Footer + * @param Translate $outputlangs Output langs + * @param string $textright Text right + * @param string $photo Photo (full path to image file used as replacement for key %PHOTOS% into left, right, header or footer text) + * @return void */ function Add_PDF_label(&$pdf,$textleft,$header,$footer,$outputlangs,$textright='',$photo='') { global $mysoc,$conf,$langs; global $forceimgscalewidth,$forceimgscaleheight; - $imgscalewidth=(empty($forceimgscalewidth)?0.3:$forceimgscalewidth); // Scale of image for width (1=Full width of sticker) - $imgscaleheight=(empty($forceimgscalewidth)?0.5:$forceimgscalewidth); // Scale of image for height (1=Full height of sticker) + $imgscalewidth=(empty($forceimgscalewidth)?0.3:$forceimgscalewidth); // Scale of image for width (1=Full width of sticker) + $imgscaleheight=(empty($forceimgscalewidth)?0.5:$forceimgscalewidth); // Scale of image for height (1=Full height of sticker) - // We are in a new page, then we must add a page + // We are in a new page, then we must add a page if (($this->_COUNTX ==0) && ($this->_COUNTY==0) and (!$this->_First==1)) { $pdf->AddPage(); } @@ -224,121 +224,121 @@ class pdf_standardlabel extends CommonStickerGenerator - /** - * Function to build PDF on disk, then output on HTTP strem. - * - * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) - * @param Translate $outputlangs Lang object for output language - * @param string $srctemplatepath Full path of source filename for generator using a template file + /** + * Function to build PDF on disk, then output on HTTP strem. + * + * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) + * @param Translate $outputlangs Lang object for output language + * @param string $srctemplatepath Full path of source filename for generator using a template file * @param string $outputdir Output directory for pdf file - * @return int 1=OK, 0=KO - */ - function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='') - { - global $user,$conf,$langs,$mysoc,$_Avery_Labels; + * @return int 1=OK, 0=KO + */ + function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='') + { + global $user,$conf,$langs,$mysoc,$_Avery_Labels; - $this->code=$srctemplatepath; - $this->Tformat = $_Avery_Labels[$this->code]; - if (empty($this->Tformat)) { dol_print_error('','ErrorBadTypeForCard'.$this->code); exit; } - $this->type = 'pdf'; - $this->format = $this->Tformat['paper-size']; + $this->code=$srctemplatepath; + $this->Tformat = $_Avery_Labels[$this->code]; + if (empty($this->Tformat)) { dol_print_error('','ErrorBadTypeForCard'.$this->code); exit; } + $this->type = 'pdf'; + $this->format = $this->Tformat['paper-size']; - if (! is_object($outputlangs)) $outputlangs=$langs; + if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; - $outputlangs->load("main"); - $outputlangs->load("dict"); - $outputlangs->load("companies"); - $outputlangs->load("admin"); + $outputlangs->load("main"); + $outputlangs->load("dict"); + $outputlangs->load("companies"); + $outputlangs->load("admin"); - $title=$outputlangs->transnoentities('Labels'); - $keywords=$title." ".$outputlangs->convToOutputCharset($mysoc->name); + $title=$outputlangs->transnoentities('Labels'); + $keywords=$title." ".$outputlangs->convToOutputCharset($mysoc->name); - $dir = (empty($outputdir)?$conf->adherent->dir_temp:$outputdir); - $filename='tmp_address_sheet.pdf'; - $file = $dir."/".$filename; + $dir = (empty($outputdir)?$conf->adherent->dir_temp:$outputdir); + $filename='tmp_address_sheet.pdf'; + $file = $dir."/".$filename; - if (! file_exists($dir)) - { - if (dol_mkdir($dir) < 0) - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } + if (! file_exists($dir)) + { + if (dol_mkdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } - $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); + $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); - if (class_exists('TCPDF')) - { - $pdf->setPrintHeader(false); - $pdf->setPrintFooter(false); - } - $pdf->SetFont(pdf_getPDFFont($outputlangs)); + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); - $pdf->SetTitle($title); - $pdf->SetSubject($title); - $pdf->SetCreator("Dolibarr ".DOL_VERSION); - $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $pdf->SetKeyWords($keywords); - if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); + $pdf->SetTitle($title); + $pdf->SetSubject($title); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); + $pdf->SetKeyWords($keywords); + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); - $pdf->SetMargins(0,0); - $pdf->SetAutoPageBreak(false); + $pdf->SetMargins(0,0); + $pdf->SetAutoPageBreak(false); - $this->_Metric_Doc = $this->Tformat['metric']; - // Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie - $posX=1; - $posY=1; - if ($posX > 0) $posX--; else $posX=0; - if ($posY > 0) $posY--; else $posY=0; - $this->_COUNTX = $posX; - $this->_COUNTY = $posY; - $this->_Set_Format($pdf, $this->Tformat); + $this->_Metric_Doc = $this->Tformat['metric']; + // Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie + $posX=1; + $posY=1; + if ($posX > 0) $posX--; else $posX=0; + if ($posY > 0) $posY--; else $posY=0; + $this->_COUNTX = $posX; + $this->_COUNTY = $posY; + $this->_Set_Format($pdf, $this->Tformat); - $pdf->Open(); - $pdf->AddPage(); + $pdf->Open(); + $pdf->AddPage(); - // Add each record - foreach($arrayofrecords as $val) - { - // imprime le texte specifique sur la carte - $this->Add_PDF_label($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright'],$val['photo']); - } + // Add each record + foreach($arrayofrecords as $val) + { + // imprime le texte specifique sur la carte + $this->Add_PDF_label($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright'],$val['photo']); + } - //$pdf->SetXY(10, 295); - //$pdf->Cell($this->_Width, $this->_Line_Height, 'XXX',0,1,'C'); + //$pdf->SetXY(10, 295); + //$pdf->Cell($this->_Width, $this->_Line_Height, 'XXX',0,1,'C'); - // Output to file - $pdf->Output($file,'F'); + // Output to file + $pdf->Output($file,'F'); - if (! empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); - // Output to http stream - clearstatcache(); + // Output to http stream + clearstatcache(); - $attachment=true; - if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; - $type=dol_mimetype($filename); + $attachment=true; + if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; + $type=dol_mimetype($filename); - //if ($encoding) header('Content-Encoding: '.$encoding); - if ($type) header('Content-Type: '.$type); - if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); - else header('Content-Disposition: inline; filename="'.$filename.'"'); + //if ($encoding) header('Content-Encoding: '.$encoding); + if ($type) header('Content-Type: '.$type); + if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); + else header('Content-Disposition: inline; filename="'.$filename.'"'); - // Ajout directives pour resoudre bug IE - header('Cache-Control: Public, must-revalidate'); - header('Pragma: public'); + // Ajout directives pour resoudre bug IE + header('Cache-Control: Public, must-revalidate'); + header('Pragma: public'); - readfile($file); + readfile($file); - return 1; - } + return 1; + } } diff --git a/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php b/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php index 1e5c74c299a..dd70c608f07 100644 --- a/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php +++ b/htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php @@ -2,8 +2,8 @@ /* Copyright (C) 2003 Steve Dillon * Copyright (C) 2003 Laurent Passebecq * Copyright (C) 2001-2003 Rodolphe Quiedeville - * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2002-2003 Jean-Louis Bergamo + * Copyright (C) 2006-2013 Laurent Destailleur * Copyright (C) 2015 Francis Appels * * This program is free software; you can redistribute it and/or modify @@ -13,7 +13,7 @@ * * 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 + * 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 @@ -21,9 +21,9 @@ */ /** - * \file htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php - * \ingroup core - * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise + * \file htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php + * \ingroup core + * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonstickergenerator.class.php'; @@ -33,83 +33,83 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonstickergenerator.class.php'; */ class pdf_tcpdflabel extends CommonStickerGenerator { - // define 1d barcode style - private $_style1d = array( - 'position' => '', - 'align' => 'C', - 'stretch' => false, - 'fitwidth' => true, - 'cellfitalign' => '', - 'border' => false, - 'hpadding' => 'auto', - 'vpadding' => 'auto', - 'fgcolor' => array(0,0,0), - 'bgcolor' => false, - 'text' => true, - 'font' => 'helvetica', - 'fontsize' => 8, - 'stretchtext' => 4 - ); - - // set style for 2d barcode - private $_style2d = array( - 'border' => false, - 'vpadding' => 'auto', - 'hpadding' => 'auto', - 'fgcolor' => array(0,0,0), - 'bgcolor' => false, - 'module_width' => 1, // width of a single module in points - 'module_height' => 1 // height of a single module in points - ); - - private $_align2d = 'N'; - - private $_xres = 0.4; - - /** - * write barcode to pdf - * - * @param PDF $pdf PDF reference - * @param string $code code to print - * @param string $encoding type of barcode - * @param boolean $is2d true if 2d barcode - * @param int $x x position in user units - * @param int $y y position in user units - * @param int $w width in user units - * @param int $h height in user units - */ - private function writeBarcode(&$pdf, $code, $encoding, $is2d, $x, $y, $w, $h) - { - if ($is2d) { - $pdf->write2DBarcode($code, $encoding, $x, $y, $w, $h, $this->_style2d, $this->_align2d); - } else { - $pdf->write1DBarcode($code, $encoding, $x, $y, $w, $h, $this->_xres, $this->_style1d); - } - } - - /** - * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) - * - * @param PDF $pdf PDF reference - * @param Translate $outputlangs Output langs - * @param array $param Associative array containing label content and optional parameters - * @return void - */ - function addSticker(&$pdf,$outputlangs,$param) - { - global $mysoc,$conf; - - $textleft = $param['textleft']; - $header = $param['textheader']; - $footer = $param['textfooter']; - $textright = $param['textright']; - $code = $param['code']; - $encoding = $param['encoding']; - $is2d = $param['is2d']; - - + // define 1d barcode style + private $_style1d = array( + 'position' => '', + 'align' => 'C', + 'stretch' => false, + 'fitwidth' => true, + 'cellfitalign' => '', + 'border' => false, + 'hpadding' => 'auto', + 'vpadding' => 'auto', + 'fgcolor' => array(0,0,0), + 'bgcolor' => false, + 'text' => true, + 'font' => 'helvetica', + 'fontsize' => 8, + 'stretchtext' => 4 + ); + + // set style for 2d barcode + private $_style2d = array( + 'border' => false, + 'vpadding' => 'auto', + 'hpadding' => 'auto', + 'fgcolor' => array(0,0,0), + 'bgcolor' => false, + 'module_width' => 1, // width of a single module in points + 'module_height' => 1 // height of a single module in points + ); + + private $_align2d = 'N'; + + private $_xres = 0.4; + + /** + * write barcode to pdf + * + * @param PDF $pdf PDF reference + * @param string $code code to print + * @param string $encoding type of barcode + * @param boolean $is2d true if 2d barcode + * @param int $x x position in user units + * @param int $y y position in user units + * @param int $w width in user units + * @param int $h height in user units + */ + private function writeBarcode(&$pdf, $code, $encoding, $is2d, $x, $y, $w, $h) + { + if ($is2d) { + $pdf->write2DBarcode($code, $encoding, $x, $y, $w, $h, $this->_style2d, $this->_align2d); + } else { + $pdf->write1DBarcode($code, $encoding, $x, $y, $w, $h, $this->_xres, $this->_style1d); + } + } + + /** + * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) + * + * @param PDF $pdf PDF reference + * @param Translate $outputlangs Output langs + * @param array $param Associative array containing label content and optional parameters + * @return void + */ + function addSticker(&$pdf,$outputlangs,$param) + { + global $mysoc,$conf; + + $textleft = $param['textleft']; + $header = $param['textheader']; + $footer = $param['textfooter']; + $textright = $param['textright']; + $code = $param['code']; + $encoding = $param['encoding']; + $is2d = $param['is2d']; + + - // We are in a new page, then we must add a page + // We are in a new page, then we must add a page if (($this->_COUNTX ==0) && ($this->_COUNTY==0) and (!$this->_First==1)) { $pdf->AddPage(); } @@ -164,7 +164,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+$xleft, $_PosY+$ytop, 0, $logoHeight); else if ($code && !empty($encoding)) { - $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse, $heighttouse); + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse, $heighttouse); } else { @@ -174,12 +174,12 @@ class pdf_tcpdflabel extends CommonStickerGenerator } else if ($textleft!='' && $textright!='') // left and right part { - if (($textleft == '%LOGO%' || $textleft == '%PHOTO%' || $textleft == '%BARCODE%') && !strstr($textright, '%') ) // left part logo/barcode right part text + if (($textleft == '%LOGO%' || $textleft == '%PHOTO%' || $textleft == '%BARCODE%') && !strstr($textright, '%') ) // left part logo/barcode right part text { if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+$xleft, $_PosY+$ytop, $widthtouse/2, 0); else if ($code && !empty($encoding)) { - $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse/2, $heighttouse); + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse/2, $heighttouse); } $pdf->SetXY($_PosX+($widthtouse/2), $_PosY+$ytop); $pdf->MultiCell($widthtouse/2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); @@ -189,32 +189,32 @@ class pdf_tcpdflabel extends CommonStickerGenerator if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+($widthtouse/2), $_PosY+$ytop, $widthtouse/2, 0); else if ($code && !empty($encoding)) { - $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+($widthtouse/2), $_PosY+$ytop, $widthtouse/2, $heighttouse); + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+($widthtouse/2), $_PosY+$ytop, $widthtouse/2, $heighttouse); } $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); $pdf->MultiCell($widthtouse/2, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); } - else if ($textleft == '%LOGO%') // left part logo right part text/barcode + else if ($textleft == '%LOGO%') // left part logo right part text/barcode { - if ($logo) $pdf->Image($logo, $_PosX+$xleft, $_PosY+$ytop, 0, $logoHeight); - if ($code && !empty($encoding)) - { - $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft+$logoWidth+1, $_PosY+$ytop, $widthtouse-$logoWidth-1, $heighttouse); - } else { - $pdf->SetXY($_PosX+$xleft+$logoWidth+1, $_PosY+$ytop); - $pdf->MultiCell($widthtouse-$logoWidth1-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); - } + if ($logo) $pdf->Image($logo, $_PosX+$xleft, $_PosY+$ytop, 0, $logoHeight); + if ($code && !empty($encoding)) + { + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft+$logoWidth+1, $_PosY+$ytop, $widthtouse-$logoWidth-1, $heighttouse); + } else { + $pdf->SetXY($_PosX+$xleft+$logoWidth+1, $_PosY+$ytop); + $pdf->MultiCell($widthtouse-$logoWidth1-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R'); + } } else if ($textright == '%LOGO%') // right part logo left part text/barcode { - if ($logo) $pdf->Image($logo, $_PosX+$xleft+$widthtouse-$logoWidth+1, $_PosY+$ytop, 0, $logoHeight); - if ($code && !empty($encoding)) - { - $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse-$logoWidth-1, $heighttouse); - } else { - $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); - $pdf->MultiCell($widthtouse-$logoWidth-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); - } + if ($logo) $pdf->Image($logo, $_PosX+$xleft+$widthtouse-$logoWidth+1, $_PosY+$ytop, 0, $logoHeight); + if ($code && !empty($encoding)) + { + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse-$logoWidth-1, $heighttouse); + } else { + $pdf->SetXY($_PosX+$xleft, $_PosY+$ytop); + $pdf->MultiCell($widthtouse-$logoWidth-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L'); + } } else // text on halft left and text on half right { @@ -230,7 +230,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+$this->_Width-$widthtouse-$xleft, $_PosY+$ytop, 0, $logoHeight); else if ($code && !empty($encoding)) { - $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$this->_Width-$widthtouse-$xleft, $_PosY+$ytop, $widthtouse, $heighttouse); + $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$this->_Width-$widthtouse-$xleft, $_PosY+$ytop, $widthtouse, $heighttouse); } else { @@ -265,121 +265,121 @@ class pdf_tcpdflabel extends CommonStickerGenerator - /** - * Function to build PDF on disk, then output on HTTP strem. - * - * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) - * @param Translate $outputlangs Lang object for output language - * @param string $srctemplatepath Full path of source filename for generator using a template file + /** + * Function to build PDF on disk, then output on HTTP strem. + * + * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) + * @param Translate $outputlangs Lang object for output language + * @param string $srctemplatepath Full path of source filename for generator using a template file * @param string $outputdir Output directory for pdf file - * @return int 1=OK, 0=KO - */ - function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='') - { - global $user,$conf,$langs,$mysoc,$_Avery_Labels; + * @return int 1=OK, 0=KO + */ + function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir='') + { + global $user,$conf,$langs,$mysoc,$_Avery_Labels; - $this->code=$srctemplatepath; - $this->Tformat = $_Avery_Labels[$this->code]; - if (empty($this->Tformat)) { dol_print_error('','ErrorBadTypeForCard'.$this->code); exit; } - $this->type = 'pdf'; - $this->format = $this->Tformat['paper-size']; + $this->code=$srctemplatepath; + $this->Tformat = $_Avery_Labels[$this->code]; + if (empty($this->Tformat)) { dol_print_error('','ErrorBadTypeForCard'.$this->code); exit; } + $this->type = 'pdf'; + $this->format = $this->Tformat['paper-size']; - if (! is_object($outputlangs)) $outputlangs=$langs; + if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; - $outputlangs->load("main"); - $outputlangs->load("dict"); - $outputlangs->load("companies"); - $outputlangs->load("admin"); + $outputlangs->load("main"); + $outputlangs->load("dict"); + $outputlangs->load("companies"); + $outputlangs->load("admin"); - $title=$outputlangs->transnoentities('Labels'); - $keywords=$title." ".$outputlangs->convToOutputCharset($mysoc->name); + $title=$outputlangs->transnoentities('Labels'); + $keywords=$title." ".$outputlangs->convToOutputCharset($mysoc->name); - $dir = (empty($outputdir)?$conf->adherent->dir_temp:$outputdir); - $filename='tmp_address_sheet.pdf'; - $file = $dir."/".$filename; + $dir = (empty($outputdir)?$conf->adherent->dir_temp:$outputdir); + $filename='tmp_address_sheet.pdf'; + $file = $dir."/".$filename; - if (! file_exists($dir)) - { - if (dol_mkdir($dir) < 0) - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } + if (! file_exists($dir)) + { + if (dol_mkdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } - $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); + $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); - if (class_exists('TCPDF')) - { - $pdf->setPrintHeader(false); - $pdf->setPrintFooter(false); - } - $pdf->SetFont(pdf_getPDFFont($outputlangs)); + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); - $pdf->SetTitle($title); - $pdf->SetSubject($title); - $pdf->SetCreator("Dolibarr ".DOL_VERSION); - $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $pdf->SetKeyWords($keywords); - if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); + $pdf->SetTitle($title); + $pdf->SetSubject($title); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); + $pdf->SetKeyWords($keywords); + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); - $pdf->SetMargins(0,0); - $pdf->SetAutoPageBreak(false); + $pdf->SetMargins(0,0); + $pdf->SetAutoPageBreak(false); - $this->_Metric_Doc = $this->Tformat['metric']; - // Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie - $posX=1; - $posY=1; - if ($posX > 0) $posX--; else $posX=0; - if ($posY > 0) $posY--; else $posY=0; - $this->_COUNTX = $posX; - $this->_COUNTY = $posY; - $this->_Set_Format($pdf, $this->Tformat); + $this->_Metric_Doc = $this->Tformat['metric']; + // Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie + $posX=1; + $posY=1; + if ($posX > 0) $posX--; else $posX=0; + if ($posY > 0) $posY--; else $posY=0; + $this->_COUNTX = $posX; + $this->_COUNTY = $posY; + $this->_Set_Format($pdf, $this->Tformat); - $pdf->Open(); - $pdf->AddPage(); + $pdf->Open(); + $pdf->AddPage(); - // Add each record - foreach($arrayofrecords as $val) - { - // imprime le texte specifique sur la carte - $this->addSticker($pdf, $outputlangs, $val); - } + // Add each record + foreach($arrayofrecords as $val) + { + // imprime le texte specifique sur la carte + $this->addSticker($pdf, $outputlangs, $val); + } - //$pdf->SetXY(10, 295); - //$pdf->Cell($this->_Width, $this->_Line_Height, 'XXX',0,1,'C'); + //$pdf->SetXY(10, 295); + //$pdf->Cell($this->_Width, $this->_Line_Height, 'XXX',0,1,'C'); - // Output to file - $pdf->Output($file,'F'); + // Output to file + $pdf->Output($file,'F'); - if (! empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); - // Output to http stream - clearstatcache(); + // Output to http stream + clearstatcache(); - $attachment=true; - if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; - $type=dol_mimetype($filename); + $attachment=true; + if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; + $type=dol_mimetype($filename); - //if ($encoding) header('Content-Encoding: '.$encoding); - if ($type) header('Content-Type: '.$type); - if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); - else header('Content-Disposition: inline; filename="'.$filename.'"'); + //if ($encoding) header('Content-Encoding: '.$encoding); + if ($type) header('Content-Type: '.$type); + if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); + else header('Content-Disposition: inline; filename="'.$filename.'"'); - // Ajout directives pour resoudre bug IE - header('Cache-Control: Public, must-revalidate'); - header('Pragma: public'); + // Ajout directives pour resoudre bug IE + header('Cache-Control: Public, must-revalidate'); + header('Pragma: public'); - readfile($file); + readfile($file); - return 1; - } + return 1; + } } From da272c6aacff5302c72d5f7cab619c5b652345bf Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 3 May 2015 14:24:20 +0200 Subject: [PATCH 30/36] ER Typo --- htdocs/expensereport/class/expensereport.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index c6c638f06f3..d3842411d94 100755 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1693,10 +1693,10 @@ class ExpenseReportLine * Retourne la liste deroulante des differents etats d'une note de frais. * Les valeurs de la liste sont les id de la table c_expensereport_statuts * - * @param int $selected etat pre-selectionne + * @param int $selected preselect status * @param string $htmlname Name of HTML select * @param int $useempty 1=Add empty line - * @return string HTML select with sattus + * @return string HTML select with status */ function select_expensereport_statut($selected='',$htmlname='fk_statut',$useempty=1) { From c6306260c53e849af206ea8f4c08c9b9ce5bac04 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 3 May 2015 14:25:37 +0200 Subject: [PATCH 31/36] Fix: ER Search mode doesn't work --- htdocs/expensereport/list.php | 38 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index cc48c78f252..ca33fc34f0f 100755 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2015 Alexandre Spangaro * * 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 @@ -43,7 +43,7 @@ $search_ref = GETPOST('search_ref'); $search_user = GETPOST('search_user','int'); $search_amount_ht = GETPOST('search_amount_ht','alpha'); $search_amount_ttc = GETPOST('search_amount_ttc','alpha'); -$search_status = GETPOST('search_status','int'); +$search_status = (GETPOST('search_status','alpha')!=''?GETPOST('search_status','alpha'):GETPOST('statut','alpha')); $month_start = GETPOST("month_start","int"); $year_start = GETPOST("year_start","int"); $month_end = GETPOST("month_end","int"); @@ -62,6 +62,9 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both $year_end=""; } +if ($search_status == '') $search_status=-1; +if ($search_user == '') $search_user=-1; + /* * View */ @@ -90,17 +93,16 @@ $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -$sql = "SELECT d.rowid, d.ref, d.total_ht, d.total_tva, d.total_ttc, d.fk_statut as status,"; +$sql = "SELECT d.rowid, d.ref, d.fk_user_author, d.total_ht, d.total_tva, d.total_ttc, d.fk_statut as status,"; $sql.= " d.date_debut, d.date_fin,"; $sql.= " u.rowid as id_user, u.firstname, u.lastname"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON d.fk_user_author = u.rowid"; +$sql.= " WHERE d.entity = ".$conf->entity; -// Where +// Ref if(!empty($search_ref)){ - $sql.= " WHERE d.ref LIKE '%".$db->escape($search_ref)."%'"; -}else{ - $sql.= " WHERE 1 = 1"; + $sql.= " AND d.ref LIKE '%".$db->escape($search_ref)."%'"; } // Date Start if ($month_start > 0) @@ -140,12 +142,16 @@ if ($search_amount_ttc != '') $sql.= natural_search('d.total_ttc', $search_amount_ttc, 1); } // User -if ($search_name) +if ($search_user != '' && $search_user >= 0) { - $sql .= natural_search('u.lastname', $search_name); + $sql.= " AND u.rowid = '".$db->escape($search_user)."'"; } // Status -if($search_status != '') $sql.= " AND d.fk_statut = '".$search_status."'"; +if ($search_status != '' && $search_status >= 0) +{ + if (strstr($search_status, ',')) $sql.=" AND d.fk_statut IN (".$db->escape($search_status).")"; + else $sql.=" AND d.fk_statut = ".$search_status; +} // RESTRICT RIGHTS if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) @@ -163,11 +169,17 @@ $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); - $i = 0; - print_barre_liste($langs->trans("ListTripsAndExpenses"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords); - print '
'."\n"; + $param=""; + if ($search_ref) $param.="&search_ref=".$search_ref; + if ($search_user) $param.="&search_user=".$search_user; + if ($search_amount_ht) $param.="&search_amount_ht=".$search_amount_ht; + if ($search_amount_ttc) $param.="&search_amount_ttc=".$search_amount_ttc; + if ($search_status >= 0) $param.="&search_status=".$search_status; + + print_barre_liste($langs->trans("ListTripsAndExpenses"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords); + print ''."\n"; print ''; print ""; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"d.rowid","",$param,'',$sortfield,$sortorder); From f0b10c14d70d647e44022955e997c7637e9bc464 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 May 2015 15:51:55 +0200 Subject: [PATCH 32/36] NEW Add a new component to select categories/tags from the main edit page of product. The dedicated tab is also removed. --- htdocs/categories/class/categorie.class.php | 4 +- htdocs/core/class/html.form.class.php | 81 ++++++++++++++++++++- htdocs/core/lib/product.lib.php | 3 +- htdocs/langs/fr_FR/other.lang | 1 - htdocs/product/card.php | 26 +++---- htdocs/theme/eldy/style.css.php | 14 +++- 6 files changed, 106 insertions(+), 23 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 8e6772dec5d..6ca5b2fad02 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1064,11 +1064,11 @@ class Categorie extends CommonObject */ function print_all_ways($sep = " >> ", $url='') { - $ways = array (); + $ways = array(); foreach ($this->get_all_ways() as $way) { - $w = array (); + $w = array(); foreach ($way as $cat) { if ($url == '') diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 28f81fc490a..82364874cfe 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4407,13 +4407,15 @@ class Form * @param array $selected Array with key+value preselected * @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value" * @param int $value_as_key 1 to use value as key - * @param string $option Valeur de l'option en fonction du type choisi + * @param string $morecss Add more css style * @param int $translate Translate and encode value - * @param int $width Force width of select box. May be used only when using jquery couch. + * @param int $width Force width of select box. May be used only when using jquery couch. Example: 250, 95% + * @param string $moreattrib Add more options on select component. Example: 'disabled="disabled"' + * @param string $elemtype Type of element we show ('category', ...) * @return string HTML multiselect string * @see selectarray */ - static function multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $option='', $translate=0, $width=0) + static function multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='',$elemtype='') { global $conf, $langs; @@ -4423,8 +4425,36 @@ class Form $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT'):$conf->global->MAIN_USE_JQUERY_MULTISELECT; print ' '; @@ -4433,7 +4463,7 @@ class Form // Try also magic suggest // Add data-role="none" to disable jmobile decoration - $out = ''."\n"; if (is_array($array) && ! empty($array)) { if ($value_as_key) $array=array_combine($array, $array); @@ -4462,6 +4492,49 @@ class Form } + /** + * Render list of categories linked to object with id $id and type $type + * + * @param int $id Id of object + * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode (0, 1, 2, ...) is deprecated. + * @param int $rendermode 0=Default, use multiselect. 1=Use text with link + * @return mixed Array of category objects or < 0 if KO + */ + function showCategories($id, $type, $rendermode=0) + { + global $db; + + $cat = new Categorie($db); + $categories = $cat->containing($id, $type); + + if ($rendermode == 1) + { + $toprint = array(); + foreach($categories as $c) + { + $ways = $c->print_all_ways(); + foreach($ways as $way) + { + $toprint[] = img_object('','category').' '.$way; + } + } + return implode('
', $toprint); + } + + if ($rendermode == 0) + { + $cate_arbo = $this->select_all_categories(0, '', 'parent', 64, 0, 1); + foreach($categories as $c) { + $arrayselected[] = $c->id; + } + + return $this->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%', 'disabled="disabled"', 'category'); + } + + return 'ErrorBadValueForParameterRenderMode'; // Should not happened + } + + /** * Return an html string with a select combo box to choose yes or no * diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 87e22ac8cc9..32e5fa4ba78 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -57,13 +57,14 @@ function product_prepare_head($object) } // Show category tab + /* No more required. Replaced with new multiselect component if (! empty($conf->categorie->enabled) && $user->rights->categorie->lire) { $head[$h][0] = DOL_URL_ROOT."/categories/categorie.php?id=".$object->id.'&type=0'; $head[$h][1] = $langs->trans('Categories'); $head[$h][2] = 'category'; $h++; - } + }*/ // Multilangs if (! empty($conf->global->MAIN_MULTILANGS)) diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang index fd87446570e..b8087ff18c8 100644 --- a/htdocs/langs/fr_FR/other.lang +++ b/htdocs/langs/fr_FR/other.lang @@ -12,7 +12,6 @@ Notify_FICHINTER_VALIDATE=Validation fiche intervention Notify_FICHINTER_SENTBYMAIL=Envoi fiche d'intervention par email Notify_BILL_VALIDATE=Validation facture client Notify_BILL_UNVALIDATE=Dévalidation facture client -Notify_ORDER_SUPPLIER_VALIDATE=Commande fournisseur enregistrée Notify_ORDER_SUPPLIER_APPROVE=Approbation commande fournisseur Notify_ORDER_SUPPLIER_REFUSE=Refus commande fournisseur Notify_ORDER_VALIDATE=Validation commande client diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 33edc83dd85..41cb4f7ab23 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1174,7 +1174,7 @@ else $type = $langs->trans('Product'); if ($object->isservice()) $type = $langs->trans('Service'); - print_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), ""); + //print_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), ""); // Main official, simple, and not duplicated code print ''."\n"; @@ -1182,6 +1182,12 @@ else print ''; print ''; print ''; + + $head=product_prepare_head($object); + $titre=$langs->trans("CardProduct".$object->type); + $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); + dol_fiche_head($head, 'card', $titre, 0, $picto); + print '
'; // Ref @@ -1374,7 +1380,7 @@ else foreach($cats as $cat) { $arrayselected[] = $cat->id; } - print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, 250); + print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%'); print ""; // Units @@ -1409,10 +1415,10 @@ else print ''; print '
'; - - print '
'; //} + dol_fiche_end(); + print '
'; print ''; print '     '; @@ -1688,16 +1694,8 @@ else print ' '."\n"; // Categories - print ''.$langs->trans("Categories").''; - $cat = new Categorie($db); - $categories = $cat->containing($object->id,0); - $catarray = $form->select_all_categories(0, '', 'parent', 64, 0, 1); - - $toprint = array(); - foreach($categories as $c) { - $toprint[] = $catarray[$c->id]; - } - print implode('
', $toprint); + print ''.$langs->trans("Categories").''; + print $form->showCategories($object->id,'product'); print ""; print "\n"; diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index b21c457a1d5..f1598d3a87d 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -3054,11 +3054,23 @@ a span.select2-chosen .select2-container .select2-choice { background-image: none; } +.select2-choices .select2-search-choice { + border: 1px solid #aaa !important; +} .select2-results .select2-no-results, .select2-results .select2-searching, .select2-results .select2-ajax-error, .select2-results .select2-selection-limit { background: #FFFFFF; } - +.select2-container-multi.select2-container-disabled .select2-choices { + background-color: #FFFFFF; + background-image: none; + border: none; + cursor: default; +} +.select2-container-multi .select2-choices .select2-search-choice { + margin-top: 2px; + margin-bottom: 2px; +} /* ============================================================================== */ /* JMobile */ From 0d14cb87099dd03115ea9c6400be5ae285c03784 Mon Sep 17 00:00:00 2001 From: jfefe Date: Sun, 3 May 2015 18:44:42 +0200 Subject: [PATCH 33/36] Modify thirdparty delete() method to pass user object as an argument. --- htdocs/societe/class/societe.class.php | 20 +++++++++++++------- htdocs/societe/soc.php | 4 ++-- test/phpunit/AdherentTest.php | 2 +- test/phpunit/SocieteTest.php | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 93144e155c9..897fab2d676 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1278,12 +1278,14 @@ class Societe extends CommonObject /** * Delete a third party from database and all its dependencies (contacts, rib...) * - * @param int $id Id of third party to delete + * @param int $id Id of third party to delete + * @param User $user User who ask to delete thirparty + * @param int $call_trigger 0=No, 1=yes * @return int <0 if KO, 0 if nothing done, >0 if OK */ - function delete($id) + function delete($id, $user='', $call_trigger=1) { - global $user, $langs, $conf; + global $langs, $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1298,10 +1300,14 @@ class Societe extends CommonObject { $this->db->begin(); - // Call trigger - $result=$this->call_trigger('COMPANY_DELETE',$user); - if ($result < 0) $error++; - // End call triggers + // User is mandatory for trigger call + if ($user && $call_trigger) + { + // Call trigger + $result=$this->call_trigger('COMPANY_DELETE',$user); + if ($result < 0) $error++; + // End call triggers + } if (! $error) { diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 20ebdca3ba2..7ce537bd149 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -169,7 +169,7 @@ if (empty($reshook)) if (!$errors) { //We finally remove the old thirdparty - if ($soc_origin->delete($soc_origin->id) < 1) { + if ($soc_origin->delete($soc_origin->id, $user) < 1) { $db->rollback(); $errors++; } @@ -598,7 +598,7 @@ if (empty($reshook)) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) { $object->fetch($socid); - $result = $object->delete($socid); + $result = $object->delete($socid, $user); if ($result > 0) { diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index 01424d81796..3a19b195b7c 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -416,7 +416,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase $this->assertNull($localobject->fk_soc); //Now we remove the third party - $result = $thirdparty->delete($thirdparty->id); + $result = $thirdparty->delete($thirdparty->id,$user); $this->assertEquals($result, 1); return $localobject; diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php index 34fdee385f7..8bcfb247365 100755 --- a/test/phpunit/SocieteTest.php +++ b/test/phpunit/SocieteTest.php @@ -365,7 +365,7 @@ class SocieteTest extends PHPUnit_Framework_TestCase $localobject=new Societe($this->savdb); $result=$localobject->fetch($id); - $result=$localobject->delete($id); + $result=$localobject->delete($id, $user); print __METHOD__." id=".$id." result=".$result."\n"; $this->assertLessThan($result, 0); From c485b1fe306b19968c0a5f8bb7b0568f2b4a0c68 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 May 2015 20:07:16 +0200 Subject: [PATCH 34/36] Fix When generation of doc is required and generator not provided, we take first entry found. --- htdocs/compta/facture.php | 6 +- htdocs/compta/facture/class/facture.class.php | 16 +- htdocs/core/class/commonobject.class.php | 64 ++- htdocs/core/lib/functions.lib.php | 16 +- htdocs/product/card.php | 472 ++++++------------ htdocs/product/fournisseurs.php | 12 +- htdocs/public/test/test_arrays.php | 42 +- htdocs/theme/eldy/img/sort_asc.png | Bin 176 -> 256 bytes htdocs/theme/eldy/img/sort_asc_disabled.png | Bin 176 -> 236 bytes htdocs/theme/eldy/img/sort_desc.png | Bin 176 -> 264 bytes htdocs/theme/eldy/style.css.php | 174 ++----- 11 files changed, 310 insertions(+), 492 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 152dde9dee3..5541c726d64 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1414,7 +1414,11 @@ if (empty($reshook)) $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + } } unset($_POST['prod_entry_mode']); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 0f90ba6d935..739135b9809 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3504,7 +3504,7 @@ class Facture extends CommonInvoice /** * Create a document onto disk according to template module. * - * @param string $modele Force template to use ('' to not force) + * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example. * @param Translate $outputlangs objet lang a utiliser pour traduction * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description @@ -3532,22 +3532,24 @@ class Facture extends CommonInvoice $modelpath = "core/modules/facture/doc/"; - return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); + $result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); + + return $result; } /** * Gets the smallest reference available for a new cycle * * @return int >= 1 if OK, -1 if error - * - * */ function newCycle() { - $sql = 'SELECT max(situation_cycle_ref) FROM ' . MAIN_DB_PREFIX . 'facture'; + $sql = 'SELECT max(situation_cycle_ref) FROM ' . MAIN_DB_PREFIX . 'facture as f'; + $sql.= " WHERE f.entity in (".getEntity('facture').")"; $resql = $this->db->query($sql); if ($resql) { - if ($resql->num_rows > 0) { + if ($resql->num_rows > 0) + { $res = $this->db->fetch_array($resql); $ref = $res['max(situation_cycle_ref)']; $ref++; @@ -3557,7 +3559,7 @@ class Facture extends CommonInvoice $this->db->free($resql); return $ref; } else { - $this->error = $this->db->error(); + $this->error = $this->db->lasterror(); dol_syslog("Error sql=" . $sql . ", error=" . $this->error, LOG_ERR); return -1; } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 566f887ba52..77877a37cb2 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3406,13 +3406,13 @@ abstract class CommonObject /** * Common function for all objects extending CommonObject for generating documents * - * @param string $modelspath Relative folder where models are placed - * @param string $modele Model to use - * @param Translate $outputlangs Language to use - * @param int $hidedetails 1 to hide details. 0 by default - * @param int $hidedesc 1 to hide product description. 0 by default - * @param int $hideref 1 to hide product reference. 0 by default - * @return int 1 if OK -1 if not OK + * @param string $modelspath Relative folder where generators are placed + * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example. + * @param Translate $outputlangs Language to use + * @param int $hidedetails 1 to hide details. 0 by default + * @param int $hidedesc 1 to hide product description. 0 by default + * @param int $hideref 1 to hide product reference. 0 by default + * @return int >0 if OK, <0 if KO */ protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref) { @@ -3426,7 +3426,7 @@ abstract class CommonObject @set_time_limit(120); error_reporting($err); - // If selected modele is a filename template (then $modele="modelname:filename") + // If selected model is a filename template (then $modele="modelname" or "modelname:filename") $tmp=explode(':',$modele,2); if (! empty($tmp[1])) { @@ -3456,7 +3456,7 @@ abstract class CommonObject if ($filefound) break; } - // Charge le modele + // If generator was found if ($filefound) { require_once $file; @@ -3464,6 +3464,47 @@ abstract class CommonObject $obj = new $classname($this->db); //$obj->message = $message; + // If generator is ODT, we must have srctemplatepath defined, if not we set it. + if ($obj->type == 'odt' && empty($srctemplatepath)) + { + $varfortemplatedir=$obj->scandir; + if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) + { + $dirtoscan=$conf->global->$varfortemplatedir; + + $listoffiles=array(); + + // Now we add first model found in directories scanned + $listofdir=explode(',',$dirtoscan); + foreach($listofdir as $key=>$tmpdir) + { + $tmpdir=trim($tmpdir); + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); + if (! $tmpdir) { unset($listofdir[$key]); continue; } + if (is_dir($tmpdir)) + { + $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); + if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); + } + } + + if (count($listoffiles)) + { + foreach($listoffiles as $record) + { + $srctemplatepath=$record['fullname']; + break; + } + } + } + + if (empty($srctemplatepath)) + { + $this->error='ErrorGenerationAskedForOdtTemplateWithNoSrcFileFound'; + return -1; + } + } + // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. $sav_charset_output=$outputlangs->charset_output; @@ -3483,14 +3524,15 @@ abstract class CommonObject else { $outputlangs->charset_output=$sav_charset_output; - dol_print_error($this->db,"Error generating document for ".__CLASS__.". Error: ".$obj->error); + dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); return -1; } } else { - dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file)); + $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); + dol_print_error('',$this->error); return -1; } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 417c9284f68..7cf0e4ff91c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1649,7 +1649,7 @@ function isValidEmail($address, $acceptsupervisorkey=0) /** * Return true if phone number syntax is ok * TODO Decide what to do with this - * + * * @param string $phone phone (Ex: "0601010101") * @return boolean true if phone syntax is OK, false if KO or empty string */ @@ -2474,10 +2474,11 @@ function info_admin($text, $infoonimgalt = 0, $nodiv=0) * * @param DoliDB $db Database handler * @param mixed $error String or array of errors strings to show + * @param array $errors Array of errors * @return void * @see dol_htmloutput_errors */ -function dol_print_error($db='',$error='') +function dol_print_error($db='',$error='',$errors=null) { global $conf,$langs,$argv; global $dolibarr_main_prod; @@ -2550,12 +2551,15 @@ function dol_print_error($db='',$error='') $syslog.=", db_error=".$db->lasterror(); } - if ($error) + if ($error || $errors) { $langs->load("errors"); - if (is_array($error)) $errors=$error; - else $errors=array($error); + // Merge all into $errors array + if (is_array($error) && is_array($errors)) $errors=array_merge($error,$errors); + elseif (is_array($error)) $errors=$error; + elseif (is_array($errors)) $errors=array_merge(array($error),$errors); + else $errors=array_merge(array($error)); foreach($errors as $msg) { @@ -2564,7 +2568,7 @@ function dol_print_error($db='',$error='') { $out.="".$langs->trans("Message").": ".$msg."
\n" ; } - else // Mode CLI + else // Mode CLI { $out.='> '.$langs->transnoentities("Message").":\n".$msg."\n" ; } diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 41cb4f7ab23..f7da56da39c 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -58,6 +58,7 @@ $id=GETPOST('id', 'int'); $ref=GETPOST('ref', 'alpha'); $type=GETPOST('type','int'); $action=(GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view'); +$cancel=GETPOST('cancel'); $confirm=GETPOST('confirm','alpha'); $socid=GETPOST('socid','int'); if (! empty($user->societe_id)) $socid=$user->societe_id; @@ -98,6 +99,8 @@ $hookmanager->initHooks(array('productcard','globalcard')); * Actions */ +if ($cancel) $action = ''; + $createbarcode=empty($conf->barcode->enabled)?0:1; if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->creer_advance)) $createbarcode=0; @@ -520,19 +523,45 @@ if (empty($reshook)) } - // Add product into proposal - if ($object->id > 0 && $action == 'addinpropal') + // Add product into object + if ($object->id > 0 && $action == 'addin') { - $propal = new Propal($db); - $result=$propal->fetch(GETPOST('propalid')); - if ($result <= 0) + if (GETPOST('propalid') > 0) { - dol_print_error($db,$propal->error); - exit; + $propal = new Propal($db); + $result=$propal->fetch(GETPOST('propalid')); + if ($result <= 0) + { + dol_print_error($db,$propal->error); + exit; + } + $thirpdartyid = $propal->socid; + } + elseif (GETPOST('commandeid') > 0) + { + $commande = new Commande($db); + $result=$commande->fetch(GETPOST('commandeid')); + if ($result <= 0) + { + dol_print_error($db,$commande->error); + exit; + } + $thirpdartyid = $commande->socid; + } + elseif (GETPOST('factureid') > 0) + { + $facture = new Facture($db); + $result=$facture->fetch(GETPOST('factureid')); + if ($result <= 0) + { + dol_print_error($db,$facture->error); + exit; + } + $thirpdartyid = $facture->socid; } $soc = new Societe($db); - $result=$soc->fetch($propal->socid); + $result=$soc->fetch($thirpdartyid); if ($result <= 0) { dol_print_error($db,$soc->error); @@ -589,254 +618,116 @@ if (empty($reshook)) } } - $result = $propal->addline( - $desc, - $pu_ht, - GETPOST('qty'), - $tva_tx, - $localtax1_tx, // localtax1 - $localtax2_tx, // localtax2 - $object->id, - GETPOST('remise_percent'), - $price_base_type, - $pu_ttc, - 0, - 0, - -1, - 0, - 0, - 0, - 0, - '', - '', - '', - 0, - $object->fk_unit - ); - if ($result > 0) + if (GETPOST('propalid') > 0) { - header("Location: ".DOL_URL_ROOT."/comm/propal.php?id=".$propal->id); - return; + $result = $propal->addline( + $desc, + $pu_ht, + GETPOST('qty'), + $tva_tx, + $localtax1_tx, // localtax1 + $localtax2_tx, // localtax2 + $object->id, + GETPOST('remise_percent'), + $price_base_type, + $pu_ttc, + 0, + 0, + -1, + 0, + 0, + 0, + 0, + '', + '', + '', + 0, + $object->fk_unit + ); + if ($result > 0) + { + header("Location: ".DOL_URL_ROOT."/comm/propal.php?id=".$propal->id); + return; + } + + setEventMessage($langs->trans("ErrorUnknown").": $result", 'errors'); } - - setEventMessage($langs->trans("ErrorUnknown").": $result", 'errors'); - } - - // Add product into order - if ($object->id > 0 && $action == 'addincommande') - { - $commande = new Commande($db); - $result=$commande->fetch(GETPOST('commandeid')); - if ($result <= 0) + elseif (GETPOST('commandeid') > 0) { - dol_print_error($db,$commande->error); - exit; + $result = $commande->addline( + $desc, + $pu_ht, + GETPOST('qty'), + $tva_tx, + $localtax1_tx, // localtax1 + $localtax2_tx, // localtax2 + $object->id, + GETPOST('remise_percent'), + '', + '', + $price_base_type, + $pu_ttc, + '', + '', + 0, + -1, + 0, + 0, + null, + 0, + '', + 0, + $object->fk_unit + ); + + if ($result > 0) + { + header("Location: ".DOL_URL_ROOT."/commande/card.php?id=".$commande->id); + exit; + } } - - $soc = new Societe($db); - $result=$soc->fetch($commande->socid); - if ($result <= 0) - { - dol_print_error($db,$soc->error); - exit; - } - - $desc = $object->description; - - $tva_tx = get_default_tva($mysoc, $soc, $object->id); - $localtax1_tx= get_localtax($tva_tx, 1, $soc); - $localtax2_tx= get_localtax($tva_tx, 2, $soc); - - - $pu_ht = $object->price; - $pu_ttc = $object->price_ttc; - $price_base_type = $object->price_base_type; - - // If multiprice - if ($conf->global->PRODUIT_MULTIPRICES && $soc->price_level) - { - $pu_ht = $object->multiprices[$soc->price_level]; - $pu_ttc = $object->multiprices_ttc[$soc->price_level]; - $price_base_type = $object->multiprices_base_type[$soc->price_level]; - } - elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) + elseif (GETPOST('factureid') > 0) { - require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; + $result = $facture->addline( + $desc, + $pu_ht, + GETPOST('qty'), + $tva_tx, + $localtax1_tx, + $localtax2_tx, + $object->id, + GETPOST('remise_percent'), + '', + '', + '', + '', + '', + $price_base_type, + $pu_ttc, + Facture::TYPE_STANDARD, + -1, + 0, + '', + 0, + 0, + null, + 0, + '', + 0, + 100, + '', + $object->fk_unit + ); - $prodcustprice = new Productcustomerprice($db); - - $filter = array('t.fk_product' => $object->id,'t.fk_soc' => $soc->id); - - $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); - if ($result) { - if (count($prodcustprice->lines) > 0) { - $pu_ht = price($prodcustprice->lines [0]->price); - $pu_ttc = price($prodcustprice->lines [0]->price_ttc); - $price_base_type = $prodcustprice->lines [0]->price_base_type; - $prod->tva_tx = $prodcustprice->lines [0]->tva_tx; - } - } + if ($result > 0) + { + header("Location: ".DOL_URL_ROOT."/compta/facture.php?facid=".$facture->id); + exit; + } } - // On reevalue prix selon taux tva car taux tva transaction peut etre different - // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - if ($tva_tx != $object->tva_tx) - { - if ($price_base_type != 'HT') - { - $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); - } - else - { - $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); - } - } - - $result = $commande->addline( - $desc, - $pu_ht, - GETPOST('qty'), - $tva_tx, - $localtax1_tx, // localtax1 - $localtax2_tx, // localtax2 - $object->id, - GETPOST('remise_percent'), - '', - '', - $price_base_type, - $pu_ttc, - '', - '', - 0, - -1, - 0, - 0, - null, - 0, - '', - 0, - $object->fk_unit - ); - - if ($result > 0) - { - header("Location: ".DOL_URL_ROOT."/commande/card.php?id=".$commande->id); - exit; - } - } - - // Add product into invoice - if ($object->id > 0 && $action == 'addinfacture' && $user->rights->facture->creer) - { - $facture = New Facture($db); - $result=$facture->fetch(GETPOST('factureid')); - if ($result <= 0) - { - dol_print_error($db,$facture->error); - exit; - } - - $soc = new Societe($db); - $soc->fetch($facture->socid); - if ($result <= 0) - { - dol_print_error($db,$soc->error); - exit; - } - - $desc = $object->description; - - $tva_tx = get_default_tva($mysoc, $soc, $object->id); - $localtax1_tx= get_localtax($tva_tx, 1, $soc); - $localtax2_tx= get_localtax($tva_tx, 2, $soc); - - $pu_ht = $object->price; - $pu_ttc = $object->price_ttc; - $price_base_type = $object->price_base_type; - - // If multiprice - if ($conf->global->PRODUIT_MULTIPRICES && $soc->price_level) - { - $pu_ht = $object->multiprices[$soc->price_level]; - $pu_ttc = $object->multiprices_ttc[$soc->price_level]; - $price_base_type = $object->multiprices_base_type[$soc->price_level]; - } - elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) - { - require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; - - $prodcustprice = new Productcustomerprice($db); - - $filter = array('t.fk_product' => $object->id,'t.fk_soc' => $soc->id); - - $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); - if ($result) { - if (count($prodcustprice->lines) > 0) { - $pu_ht = price($prodcustprice->lines [0]->price); - $pu_ttc = price($prodcustprice->lines [0]->price_ttc); - $price_base_type = $prodcustprice->lines [0]->price_base_type; - $prod->tva_tx = $prodcustprice->lines [0]->tva_tx; - } - } - } - // On reevalue prix selon taux tva car taux tva transaction peut etre different - // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - if ($tva_tx != $object->tva_tx) - { - if ($price_base_type != 'HT') - { - $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); - } - else - { - $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); - } - } - - $result = $facture->addline( - $desc, - $pu_ht, - GETPOST('qty'), - $tva_tx, - $localtax1_tx, - $localtax2_tx, - $object->id, - GETPOST('remise_percent'), - '', - '', - '', - '', - '', - $price_base_type, - $pu_ttc, - Facture::TYPE_STANDARD, - -1, - 0, - '', - 0, - 0, - null, - 0, - '', - 0, - 100, - '', - $object->fk_unit - ); - - if ($result > 0) - { - header("Location: ".DOL_URL_ROOT."/compta/facture.php?facid=".$facture->id); - exit; - } } } -if (GETPOST("cancel") == $langs->trans("Cancel")) -{ - $action = ''; - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); - exit; -} /* @@ -1815,42 +1706,23 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) $langs->load("propal"); - $html .= ''; - $html .= ''.$langs->trans("AddToDraftProposals").''; - $html .= ''; - $html .= ''; - $var=true; $otherprop = $propal->liste_array(2,1,0); - $html .= ''; - $html .= ''; - $html .= ''; + if (is_array($otherprop) && count($otherprop)) { $var=!$var; $html .= ''; - $html .= ''; } else - { + { $html .= "'; } - $html .= '
'; - $html .= ''; - $html .= $langs->trans("Proposals").''; + $html .= $langs->trans("AddToDraftProposals").''; $html .= $form->selectarray("propalid", $otherprop, 0, 1); $html .= '
'.$langs->trans("Quantity").' '; - $html .= ''.$langs->trans("ReductionShort").'(%) '; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= '
"; $html .= $langs->trans("NoDraftProposals"); $html .= '
'; - $html .= ''; - - $html .= ''; - $html .= ''; } // Commande @@ -1860,30 +1732,15 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) $langs->load("orders"); - $html .= ''; - $html .= ''.$langs->trans("AddToDraftOrders").''; - $html .= ''; - $html .= ''; - $var=true; $othercom = $commande->liste_array(2, 1, null); - $html .= '
'; - $html .= ''; - $html .= ''; if (is_array($othercom) && count($othercom)) { $var=!$var; $html .= ''; - $html .= ''; } else { @@ -1891,11 +1748,6 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) $html .= $langs->trans("NoDraftOrders"); $html .= ''; } - $html .= '
'; - $html .= ''; - $html .= $langs->trans("Orders").''; + $html .= $langs->trans("AddToDraftOrders").''; $html .= $form->selectarray("commandeid", $othercom, 0, 1); $html .= '
'.$langs->trans("Quantity").' '; - $html .= ''.$langs->trans("ReductionShort").'(%) '; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= '
'; - - $html .= ''; - $html .= ''; } // Factures @@ -1905,30 +1757,15 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) $langs->load("bills"); - $html .= ''; - $html .= ''.$langs->trans("AddToDraftInvoices").''; - $html .= ''; - $html .= ''; - $var=true; $otherinvoice = $invoice->liste_array(2, 1, null); - $html .= '
'; - $html .= ''; - $html .= ''; if (is_array($otherinvoice) && count($otherinvoice)) { $var=!$var; $html .= ''; - $html .= ''; } else { @@ -1936,20 +1773,31 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) $html .= $langs->trans("NoDraftInvoices"); $html .= ''; } - $html .= '
'; - $html .= ''; - $html .= $langs->trans("Invoice").''; + $html .= $langs->trans("AddToDraftInvoices").''; $html .= $form->selectarray("factureid", $otherinvoice, 0, 1); $html .= '
'.$langs->trans("Quantity").' '; - $html .= ''.$langs->trans("ReductionShort").'(%) '; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= '
'; - - $html .= ''; - $html .= ''; } //If any text is going to be printed, then we show the table if (!empty($html)) { - print ''; + print ''; + print ''; + print ''; + + print load_fiche_titre($langs->trans("Add"),'',''); + + $html .= ''; + + print '
'.$langs->trans("Quantity").' '; + $html .= ''.$langs->trans("ReductionShort").'(%) '; + $html .= ''; + $html .= '
'; print $html; print '
'; - print '
'; + + print '
'; + print ''; + print '
'; + + print ''; } } diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 9d7a9215ef1..abeb8fdf995 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -523,20 +523,20 @@ if ($id || $ref) $param="&id=".$product->id; print ''; print_liste_field_titre($langs->trans("Suppliers"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder); - print ''.$langs->trans("SupplierRef").''; + print_liste_field_titre($langs->trans("SupplierRef")); if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) print_liste_field_titre($langs->trans("Availability"),$_SERVER["PHP_SELF"],"pfp.fk_availability","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"],"pfp.quantity","",$param,'align="right"',$sortfield,$sortorder); - print ''.$langs->trans("VATRate").''; - print ''.$langs->trans("PriceQtyMinHT").''; + print_liste_field_titre($langs->trans("VATRate")); + print_liste_field_titre($langs->trans("PriceQtyMinHT")); print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder); - print ''.$langs->trans("DiscountQtyMin").''; + print_liste_field_titre($langs->trans("DiscountQtyMin")); print_liste_field_titre($langs->trans("NbDaysToDelivery"),$_SERVER["PHP_SELF"],"pfp.delivery_time_days","",$param,'align="right"',$sortfield,$sortorder); // Charges ???? if ($conf->global->PRODUCT_CHARGES) { - if (! empty($conf->margin->enabled)) print ''.$langs->trans("UnitCharges").''; + if (! empty($conf->margin->enabled)) print_liste_field_titre($langs->trans("UnitCharges")); } - print ''; + print_liste_field_titre(''); print "\n"; $product_fourn = new ProductFournisseur($db); diff --git a/htdocs/public/test/test_arrays.php b/htdocs/public/test/test_arrays.php index 7cbd9898204..2f0e903b8c5 100644 --- a/htdocs/public/test/test_arrays.php +++ b/htdocs/public/test/test_arrays.php @@ -65,7 +65,7 @@ else

This page is a sample of page using tables. It is designed to make test with
-- css (edit page to change to test another css)
+- css (add parameter &theme=newthem to test another theme or edit css of current theme)
- jmobile (add parameter dol_use_jmobile=1&dol_optimize_smallscreen=1 to enable view with jmobile)
- dataTables
- tablednd
@@ -115,9 +115,13 @@ This page is a sample of page using tables. It is designed to make test with
-


Example 1 : Standard table => Use this if you need the drag and drop for lines
+


Example 1 : Standard table/thead/tbody/tr/th-td (no class pair/impair on td) => Use this if you need the drag and drop for lines
initAsSpecimen(); + $sortfield='aaa'; $sortorder='ASC'; $tasksarray=array(1,2,3); // To force having several lines @@ -130,14 +134,14 @@ if (! empty($conf->use_javascript_ajax)) include DOL_DOCUMENT_ROOT.'/core/tpl/aj trans('title2'),0,$_SERVER["PHP_SELF"],'bbb','','','align="right"',$sortfield,$sortorder); ?> trans('title3'),0,$_SERVER["PHP_SELF"],'ccc','','','align="center"',$sortfield,$sortorder); ?> -a1b1c1 -a2b2c2 +getNomUrl(1); ?>b1c1 +a2b2c2
-


Example 2 : Table using tags: table/thead/tbody/tr/td + dataTable => Use this for long result tables
+


Example 2 : Table using tags: table/thead/tbody/tr/th-td + dataTable => Use this for long result tables
@@ -221,9 +225,11 @@ $('xxxth').replaceWith( - - - trans('zzz'),1,$_SERVER["PHP_SELF"],'','','','align="center" class="tagtd"',$sortfield,$sortorder); ?> + + + trans('Column C'),1,$_SERVER["PHP_SELF"],'','','','align="center" class="tagtd"',$sortfield,$sortorder); + ?> @@ -292,7 +298,7 @@ $('xxxth').replaceWith(
-


Example 3 : Table using tags: div.tagtable+div.tagtr+div or div.tagtable+div.tagtr+div.tagtd => Use this, but AVOID IT if possible, for tables that need to have a different form for each line (drag and drop of lines does not work for this case, also height of title can't be forced to a minimum)

+


Example 3 : Table using tags: div.tagtable+div.tagtr+div or div.tagtable+div.tagtr+div.tagtd => Use this for tables that need to have a different form for each line, but AVOID IT if possible (drag and drop of lines does not work for this case, also height of title can't be forced to a minimum)

-
line3
-
dfsdf
-
ffdsfsd
-
aaaa
+
Title A
+
title B
+
title C
+
title D
-
+
line4
dfsdf
bbbb
-
+
line5
dfsdf
bbbb
+
+
line6
+
jghjgh
+
5
+
lll
+
snakeColumn A