From 03064edc59bb8c6d759630e5d4cf7d7e1f3d7dd4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 23 Jan 2011 18:04:53 +0000 Subject: [PATCH] New: Can add information on current user on odt generation --- ChangeLog | 2 + .../core/class/commondocgenerator.class.php | 105 ++++++++++++++++++ .../doc/doc_generic_invoice_odt.modules.php | 71 +++++------- .../modules/facture/modules_facture.php | 4 +- .../societe/doc/doc_generic_odt.modules.php | 72 ++++++------ .../modules/societe/modules_societe.class.php | 3 +- htdocs/includes/odtphp/odf.php | 10 +- 7 files changed, 181 insertions(+), 86 deletions(-) create mode 100755 htdocs/core/class/commondocgenerator.class.php diff --git a/ChangeLog b/ChangeLog index ed0366d8bbe..d7300dd42bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ English Dolibarr ChangeLog ***** ChangeLog for 3.1 compared to 3.0 ***** +For users: +- New: Can add information on current user on odt generation For developers: - New: External modules can add their menu manager diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php new file mode 100755 index 00000000000..c6797cb2b43 --- /dev/null +++ b/htdocs/core/class/commondocgenerator.class.php @@ -0,0 +1,105 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2007 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/htdocs/core/class/commondocgenerator.class.php + * \ingroup core + * \brief File of parent class for documents generators + * \version $Id$ + */ + + +/** + * \class CommonDocGenerator + * \brief Parent class for documents generators + */ +class CommonDocGenerator +{ + var $error=''; + + + /** + * Define array with couple subtitution key => subtitution value + * + * @param $mysoc + */ + function get_substitutionarray_user($user) + { + global $conf; + + return array( + 'myuser_lastname'=>$user->lastname, + 'myuser_firstname'=>$user->firstname, + /*'myuser_login'=>$user->login, + 'myuser_phone'=>$user->officephone, + 'myuser_fax'=>$user->officefax, + 'myuser_mobile'=>$user->user_mobile, + 'myuser_email'=>$user->user_email, + 'myuser_web'=>$user->url, + 'myuser_note'=>$user->note*/ + ); + } + + + /** + * Define array with couple subtitution key => subtitution value + * + * @param $mysoc + */ + function get_substitutionarray_mysoc($mysoc) + { + global $conf; + + if (empty($mysoc->forme_juridique) && ! empty($mysoc->forme_juridique_code)) + { + $mysoc->forme_juridique=getFormeJuridiqueLabel($mysoc->forme_juridique_code); + } + + $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; + + return array( + 'mycompany_logo'=>$logotouse, + 'mycompany_name'=>$mysoc->name, + 'mycompany_email'=>$mysoc->email, + 'mycompany_phone'=>$mysoc->phone, + 'mycompany_fax'=>$mysoc->fax, + 'mycompany_address'=>$mysoc->address, + 'mycompany_zip'=>$mysoc->zip, + 'mycompany_town'=>$mysoc->town, + 'mycompany_country'=>$mysoc->country, + 'mycompany_web'=>$mysoc->url, + 'mycompany_juridicalstatus'=>$mysoc->forme_juridique, + 'mycompany_capital'=>$mysoc->capital, + 'mycompany_barcode'=>$mysoc->gencod, + 'mycompany_idprof1'=>$mysoc->idprof1, + 'mycompany_idprof2'=>$mysoc->idprof2, + 'mycompany_idprof3'=>$mysoc->idprof3, + 'mycompany_idprof4'=>$mysoc->idprof4, + 'mycompany_vatnumber'=>$mysoc->tva_intra, + 'mycompany_note'=>$mysoc->note + ); + } + + +} + +?> diff --git a/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php index 44d48188fe3..16ee26fa186 100644 --- a/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -86,46 +86,6 @@ class doc_generic_invoice_odt extends ModelePDFFactures } - /** - * Define array with couple subtitution key => subtitution value - * - * @param $mysoc - */ - function get_substitutionarray_mysoc($mysoc) - { - global $conf; - - if (empty($mysoc->forme_juridique) && ! empty($mysoc->forme_juridique_code)) - { - $mysoc->forme_juridique=getFormeJuridiqueLabel($mysoc->forme_juridique_code); - } - - $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; - - return array( - 'mycompany_logo'=>$logotouse, - 'mycompany_name'=>$mysoc->name, - 'mycompany_email'=>$mysoc->email, - 'mycompany_phone'=>$mysoc->phone, - 'mycompany_fax'=>$mysoc->fax, - 'mycompany_address'=>$mysoc->address, - 'mycompany_zip'=>$mysoc->zip, - 'mycompany_town'=>$mysoc->town, - 'mycompany_country'=>$mysoc->country, - 'mycompany_web'=>$mysoc->url, - 'mycompany_juridicalstatus'=>$mysoc->forme_juridique, - 'mycompany_capital'=>$mysoc->capital, - 'mycompany_barcode'=>$mysoc->gencod, - 'mycompany_idprof1'=>$mysoc->idprof1, - 'mycompany_idprof2'=>$mysoc->idprof2, - 'mycompany_idprof3'=>$mysoc->idprof3, - 'mycompany_idprof4'=>$mysoc->idprof4, - 'mycompany_vatnumber'=>$mysoc->tva_intra, - 'mycompany_note'=>$mysoc->note - ); - } - - /** * Define array with couple subtitution key => subtitution value * @@ -200,6 +160,15 @@ class doc_generic_invoice_odt extends ModelePDFFactures $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); // Add list of substitution keys $texthelp.='
'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'
'; + $dummy=new User($db); + $tmparray=$this->get_substitutionarray_user($dummy); + $nb=0; + foreach($tmparray as $key => $val) + { + $texthelp.='{'.$key.'}
'; + $nb++; + if ($nb >= 5) { $texthelp.='...
'; break; } + } $dummy=new Societe($db); $tmparray=$this->get_substitutionarray_mysoc($dummy); $nb=0; @@ -328,7 +297,27 @@ class doc_generic_invoice_odt extends ModelePDFFactures ); // Make substitutions - $tmparray=$this->get_substitutionarray_mysoc($mysoc); + $tmparray=$this->get_substitutionarray_user($user); + //var_dump($tmparray); exit; + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + //var_dump($value);exit; + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } + $tmparray=$this->get_substitutionarray_mysoc($mysoc); //var_dump($tmparray); exit; foreach($tmparray as $key=>$value) { diff --git a/htdocs/includes/modules/facture/modules_facture.php b/htdocs/includes/modules/facture/modules_facture.php index e21a5e12811..0124abc0362 100644 --- a/htdocs/includes/modules/facture/modules_facture.php +++ b/htdocs/includes/modules/facture/modules_facture.php @@ -32,14 +32,14 @@ require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php'); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); // Requis car utilise dans les classes qui heritent require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); -//require_once(DOL_DOCUMENT_ROOT.'/includes/tcpdf/tcpdf.php'); +require_once(DOL_DOCUMENT_ROOT."/core/class/commondocgenerator.class.php"); /** * \class ModelePDFFactures * \brief Classe mere des modeles de facture */ -class ModelePDFFactures +class ModelePDFFactures extends CommonDocGenerator { var $error=''; diff --git a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php index 705cc2423c5..3d5741e1211 100644 --- a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php @@ -76,46 +76,6 @@ class doc_generic_odt extends ModeleThirdPartyDoc } - /** - * Define array with couple subtitution key => subtitution value - * - * @param $mysoc - */ - function get_substitutionarray_mysoc($mysoc) - { - global $conf; - - if (empty($mysoc->forme_juridique) && ! empty($mysoc->forme_juridique_code)) - { - $mysoc->forme_juridique=getFormeJuridiqueLabel($mysoc->forme_juridique_code); - } - - $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; - - return array( - 'mycompany_logo'=>$logotouse, - 'mycompany_name'=>$mysoc->name, - 'mycompany_email'=>$mysoc->email, - 'mycompany_phone'=>$mysoc->phone, - 'mycompany_fax'=>$mysoc->fax, - 'mycompany_address'=>$mysoc->address, - 'mycompany_zip'=>$mysoc->zip, - 'mycompany_town'=>$mysoc->town, - 'mycompany_country'=>$mysoc->country, - 'mycompany_web'=>$mysoc->url, - 'mycompany_juridicalstatus'=>$mysoc->forme_juridique, - 'mycompany_capital'=>$mysoc->capital, - 'mycompany_barcode'=>$mysoc->gencod, - 'mycompany_idprof1'=>$mysoc->idprof1, - 'mycompany_idprof2'=>$mysoc->idprof2, - 'mycompany_idprof3'=>$mysoc->idprof3, - 'mycompany_idprof4'=>$mysoc->idprof4, - 'mycompany_vatnumber'=>$mysoc->tva_intra, - 'mycompany_note'=>$mysoc->note - ); - } - - /** * Define array with couple subtitution key => subtitution value * @@ -190,6 +150,15 @@ class doc_generic_odt extends ModeleThirdPartyDoc $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); // Add list of substitution keys $texthelp.='
'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'
'; + $dummy=new User($db); + $tmparray=$this->get_substitutionarray_user($dummy); + $nb=0; + foreach($tmparray as $key => $val) + { + $texthelp.='{'.$key.'}
'; + $nb++; + if ($nb >= 5) { $texthelp.='...
'; break; } + } $dummy=new Societe($db); $tmparray=$this->get_substitutionarray_mysoc($dummy); $nb=0; @@ -317,7 +286,30 @@ class doc_generic_odt extends ModeleThirdPartyDoc 'DELIMITER_RIGHT' => '}') ); + //print $odfHandler->__toString()."\n"; + // Make substitutions + $tmparray=$this->get_substitutionarray_user($user); + //var_dump($tmparray); exit; + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + //var_dump($value);exit; + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + //print $key.' '.$value;exit; + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } $tmparray=$this->get_substitutionarray_mysoc($mysoc); //var_dump($tmparray); exit; foreach($tmparray as $key=>$value) diff --git a/htdocs/includes/modules/societe/modules_societe.class.php b/htdocs/includes/modules/societe/modules_societe.class.php index 8147c97596e..4deaeb30e21 100644 --- a/htdocs/includes/modules/societe/modules_societe.class.php +++ b/htdocs/includes/modules/societe/modules_societe.class.php @@ -26,13 +26,14 @@ * \brief Fichier contenant la classe mere de module de generation societes * \version $Id$ */ +require_once(DOL_DOCUMENT_ROOT."/core/class/commondocgenerator.class.php"); /** * \class ModeleThirdPartyDoc * \brief Parent class for third parties models of doc generators */ -class ModeleThirdPartyDoc +class ModeleThirdPartyDoc extends CommonDocGenerator { var $error=''; diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 9acd0d0cc4b..cdcbae0c414 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -110,8 +110,14 @@ class Odf */ public function setVars($key, $value, $encode = true, $charset = 'ISO-8859') { - if (strpos($this->contentXml, $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']) === false) { - throw new OdfException("var $key not found in the document"); + // TODO Warning string may be: + // {aaa} + // instead of {aaa}. + //print $key.'-'.$value.'-'.strpos($this->contentXml, $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']).'
'; + if (strpos($this->contentXml, $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']) === false) { + //if (strpos($this->contentXml, '">'. $key . '') === false) { + throw new OdfException("var $key not found in the document"); + //} } $value = $encode ? htmlspecialchars($value) : $value; $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value;