diff --git a/CHANGELOG.md b/CHANGELOG.md index 432426a..e33699c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,3 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [UNRELEASE] + +### Added + +- New option to use the Branding plugin logo in PDF headers \ No newline at end of file diff --git a/inc/config.class.php b/inc/config.class.php index 2ff2c4a..e218511 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -1,5 +1,37 @@ . + * + * @author Nelly Mahu-Lasson, Remi Collet, Teclib + * @copyright Copyright (c) 2009-2022 PDF plugin team + * @license AGPL License 3.0 or (at your option) any later version + * @link https://github.com/pluginsGLPI/pdf/ + * @link http://www.glpi-project.org/ + * @package pdf + * @since 2009 + * http://www.gnu.org/licenses/agpl-3.0-standalone.html + * -------------------------------------------------------------------------- + */ + +use Glpi\Application\View\TemplateRenderer; + /** * ------------------------------------------------------------------------- * LICENSE @@ -83,6 +115,7 @@ public static function install(Migration $mig) `id` int $default_key_sign NOT NULL, `currency` VARCHAR(15) NULL, `add_text` VARCHAR(255) NULL, + `use_branding_logo` BOOLEAN DEFAULT 0, `date_mod` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET= {$default_charset} @@ -104,38 +137,37 @@ public static function install(Migration $mig) if (!$DB->fieldExists($table, 'add_text')) { $mig->addField($table, 'add_text', 'char(255) DEFAULT NULL', ['after' => 'currency']); } + //4.0.0 + if (!$DB->fieldExists($table, 'use_branding_logo')) { + $mig->addField($table, 'use_branding_logo', 'boolean DEFAULT 0', ['after' => 'add_text']); + } } } public static function showConfigForm($item) { global $PDF_DEVICES; - $config = self::getInstance(); $config->showFormHeader(); + $is_branding_active = Plugin::isPluginActive('branding'); - echo ""; - echo '' . __('Choose your international currency', 'pdf') . ''; + $options = []; foreach ($PDF_DEVICES as $option => $value) { $options[$option] = $option . ' - ' . $value[0] . ' (' . $value[1] . ')'; } - Dropdown::showFromArray( - 'currency', - $options, - ['value' => $config->fields['currency']], + + TemplateRenderer::getInstance()->display( + '@pdf/config.html.twig', + [ + 'currency_options' => $options, + 'selected_currency' => $config->fields['currency'], + 'is_branding_active' => $is_branding_active, + 'use_branding_logo' => (!empty($config->fields['use_branding_logo']) && $is_branding_active), + 'add_text' => $config->fields['add_text'], + ], ); - echo "\n"; - - echo ""; - echo '' . __('Text to add at the end of the PDF generation', 'pdf') . ''; - echo ""; - Html::textarea(['name' => 'add_text', - 'value' => $config->fields['add_text'], - 'rows' => '5', - 'style' => 'width:95%']); - echo ''; $config->showFormButtons(['candel' => false]); diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index ff04ef9..6dabf60 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -32,9 +32,7 @@ //use TCPDF; -define('K_PATH_IMAGES', Plugin::getPhpDir('pdf') . '/pics/'); - - +define('K_PATH_IMAGES', ''); class PluginPdfSimplePDF { // Page orientation @@ -120,17 +118,21 @@ public function setHeader($msg) $this->header = $msg; $this->pdf->resetHeaderTemplate(); $this->pdf->SetTitle($msg); - $configurationValues = Config::getConfigurationValues('core', ['version']); - $current_version = $configurationValues['version']; - switch ($current_version) { - case '0.85.3': - case '0.85.4': - case '0.85.5': - $this->pdf->SetHeaderData('fd_logo.jpg', 15, $msg, ''); - break; - - default: - $this->pdf->SetHeaderData('fd_logo.png', 15, $msg, ''); + $config = PluginPdfConfig::getInstance(); + + $params = [ + 'entities_id' => Session::getActiveEntity(), + 'logo' => '', + ]; + $hook = Plugin::doHookFunction('import_logo', $params); + if ( + !empty($hook['logo_path']) + && $config->getField('use_branding_logo') + ) { + $this->pdf->SetHeaderData($hook['logo_path'], 15, $msg, ''); + } else { + $path = Plugin::getPhpDir('pdf') . '/pics/'; + $this->pdf->SetHeaderData($path . 'fd_logo.png', 15, $msg, ''); } } diff --git a/templates/config.html.twig b/templates/config.html.twig new file mode 100644 index 0000000..a1b4241 --- /dev/null +++ b/templates/config.html.twig @@ -0,0 +1,80 @@ +{# + # ------------------------------------------------------------------------- + # LICENSE + # + # This file is part of PDF plugin for GLPI. + # + # PDF is free software: you can redistribute it and/or modify + # it under the terms of the GNU Affero General Public License as published by + # the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # + # PDF 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 Affero General Public License for more details. + # + # You should have received a copy of the GNU Affero General Public License + # along with Reports. If not, see . + # + # @author Nelly Mahu-Lasson, Remi Collet, Teclib + # @copyright Copyright (c) 2009-2022 PDF plugin team + # @license AGPL License 3.0 or (at your option) any later version + # @link https://github.com/pluginsGLPI/pdf/ + # @link http://www.glpi-project.org/ + # @package pdf + # @since 2009 + # http://www.gnu.org/licenses/agpl-3.0-standalone.html + # -------------------------------------------------------------------------- + #} + +{% import 'components/form/fields_macros.html.twig' as fields %} + +{% set candel = false %} + +{{ fields.dropdownArrayField( + 'currency', + selected_currency, + currency_options, + __('Choose your international currency', 'pdf') +) }} + + +
+ +
+ {% if is_branding_active %} + + + {% else %} + + {% endif %} +
+
+ +{{ fields.textareaField( + 'add_text', + add_text, + __('Text to add at the end of the PDF generation', 'pdf'), + { + 'rows': 5, + 'style': 'width:95%' + } +) }}