Skip to content
Snippets Groups Projects
Commit 03064edc authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

New: Can add information on current user on odt generation

parent 1779f59b
No related branches found
No related tags found
No related merge requests found
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
......
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
*/
/**
* \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
);
}
}
?>
......@@ -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.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
$dummy=new User($db);
$tmparray=$this->get_substitutionarray_user($dummy);
$nb=0;
foreach($tmparray as $key => $val)
{
$texthelp.='{'.$key.'}<br>';
$nb++;
if ($nb >= 5) { $texthelp.='...<br>'; 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)
{
......
......@@ -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='';
......
......@@ -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.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
$dummy=new User($db);
$tmparray=$this->get_substitutionarray_user($dummy);
$nb=0;
foreach($tmparray as $key => $val)
{
$texthelp.='{'.$key.'}<br>';
$nb++;
if ($nb >= 5) { $texthelp.='...<br>'; 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)
......
......@@ -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='';
......
......@@ -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:
// <text:span text:style-name="T13">{</text:span><text:span text:style-name="T12">aaa</text:span><text:span text:style-name="T13">}</text:span>
// instead of {aaa}.
//print $key.'-'.$value.'-'.strpos($this->contentXml, $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']).'<br>';
if (strpos($this->contentXml, $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']) === false) {
//if (strpos($this->contentXml, '">'. $key . '</text;span>') === false) {
throw new OdfException("var $key not found in the document");
//}
}
$value = $encode ? htmlspecialchars($value) : $value;
$value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment