From ec542f5ee5427a2bb5d64e74bb19e1d9797862a1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 28 Mar 2012 20:12:25 +0200 Subject: [PATCH] New: Support tags into header and footer into ODT templates --- ChangeLog | 1 + htdocs/includes/odtphp/odf.php | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8601ff5c2bc..b8c81a65160 100644 --- a/ChangeLog +++ b/ChangeLog @@ -62,6 +62,7 @@ For users: - New: Add hidden option MAIN_ADD_PDF_BACKGROUND to add a PDF as background of invoice/order generated PDF. - New: Can convert a product/service into service/product. - New: Show delivery date into proposal template azur. +- New: Support tags into header and footer into ODT templates. - Fix: Can use POS module with several concurrent users. - Fix: Installer don't fails with Mysql version that added a ssl_cypher field. - Fix: Sanitize input parameters. diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 66902811d7f..96d2f48010b 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -23,6 +23,7 @@ class Odf ); protected $file; protected $contentXml; // To store content of content.xml file + protected $stylesXml; // To store content of styles.xml file protected $manifestXml; // To store content of META-INF/manifest.xml file protected $tmpfile; protected $tmpdir=''; @@ -83,6 +84,9 @@ class Odf if (($this->manifestXml = $this->file->getFromName('META-INF/manifest.xml')) === false) { throw new OdfException("Something is wrong with META-INF/manifest.xm in source file '$filename'"); } + if (($this->stylesXml = $this->file->getFromName('styles.xml')) === false) { + throw new OdfException("Nothing to parse - Check that the styles.xml file is correctly formed in source file '$filename'"); + } $this->file->close(); @@ -181,11 +185,13 @@ IMG; * Merge template variables * Called automatically for a save * + * @param string $type 'content' or 'styles' * @return void */ - private function _parse() + private function _parse($type='content') { - $this->contentXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->contentXml); + if ($type == 'content') $this->contentXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->contentXml); + if ($type == 'styles') $this->stylesXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->stylesXml); } /** @@ -286,11 +292,16 @@ IMG; */ private function _save() { - $res=$this->file->open($this->tmpfile); - $this->_parse(); + $res=$this->file->open($this->tmpfile); // tmpfile is odt template + $this->_parse('content'); + $this->_parse('styles'); + if (! $this->file->addFromString('content.xml', $this->contentXml)) { throw new OdfException('Error during file export addFromString'); } + if (! $this->file->addFromString('styles.xml', $this->stylesXml)) { + throw new OdfException('Error during file export addFromString'); + } foreach ($this->images as $imageKey => $imageValue) { $this->file->addFile($imageKey, 'Pictures/' . $imageValue); $this->addImageToManifest($imageValue);