From 03e2d06f69caa7c7481aae7d3be305549d713c8b Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Wed, 15 Jan 2025 15:00:36 +0100 Subject: [PATCH 01/13] Load logo from Branding when activated --- inc/simplepdf.class.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index ff04ef9..94c7f32 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,29 @@ 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; + if (Plugin::isPluginActive('branding')) { + try { + $reflectionClass = new ReflectionClass('PluginBrandingUtils'); + $brandingUtils = $reflectionClass->newInstance(); + $logo = $brandingUtils->getFilePath(Session::getActiveEntity(), 'main_logo'); + $this->pdf->SetHeaderData($logo, 15, $msg, ''); + } catch (ReflectionException $e) { + return; + } + } else { + $configurationValues = Config::getConfigurationValues('core', ['version']); + $current_version = $configurationValues['version']; + $path = Plugin::getPhpDir('pdf') . '/pics/'; + switch ($current_version) { + case '0.85.3': + case '0.85.4': + case '0.85.5': + $this->pdf->SetHeaderData($path . 'fd_logo.jpg', 15, $msg, ''); + break; - default: - $this->pdf->SetHeaderData('fd_logo.png', 15, $msg, ''); + default: + $this->pdf->SetHeaderData($path . 'fd_logo.png', 15, $msg, ''); + } } } From 0cc2bc7a696351ed9446fc80359390afe843022a Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Wed, 15 Jan 2025 16:47:38 +0100 Subject: [PATCH 02/13] Remove ReflectionClass method --- inc/simplepdf.class.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 94c7f32..e85e2e9 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -119,14 +119,9 @@ public function setHeader($msg) $this->pdf->resetHeaderTemplate(); $this->pdf->SetTitle($msg); if (Plugin::isPluginActive('branding')) { - try { - $reflectionClass = new ReflectionClass('PluginBrandingUtils'); - $brandingUtils = $reflectionClass->newInstance(); - $logo = $brandingUtils->getFilePath(Session::getActiveEntity(), 'main_logo'); - $this->pdf->SetHeaderData($logo, 15, $msg, ''); - } catch (ReflectionException $e) { - return; - } + $brandingUtils = new \PluginBrandingUtils(); + $logo = $brandingUtils->getFilePath(Session::getActiveEntity(), 'main_logo'); + $this->pdf->SetHeaderData($logo, 15, $msg, ''); } else { $configurationValues = Config::getConfigurationValues('core', ['version']); $current_version = $configurationValues['version']; From 5d1cfda89ac33a32fa42ca4b697f40dca0d55cd4 Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Wed, 15 Jan 2025 17:15:29 +0100 Subject: [PATCH 03/13] Add toggle in config to enable Branding logo use --- inc/config.class.php | 37 +++++++++++++++++++++++++++++++++++++ inc/simplepdf.class.php | 6 +++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/inc/config.class.php b/inc/config.class.php index 2ff2c4a..3c418c8 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -83,6 +83,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,6 +105,10 @@ 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']); + } } } @@ -115,6 +120,7 @@ public static function showConfigForm($item) $config->showFormHeader(); + $is_branding_active = Plugin::isPluginActive('branding'); echo ""; echo '' . __('Choose your international currency', 'pdf') . ''; @@ -128,6 +134,37 @@ public static function showConfigForm($item) ); echo "\n"; + echo ""; + echo '' . __('Use logo from Branding plugin', 'pdf') . ''; + + echo ''; + + if ($is_branding_active) { + echo ''; + + // Script pour synchroniser la valeur du champ caché avec la case à cocher + echo ''; + } else { + echo ''; + } + echo ''; + + echo ""; echo '' . __('Text to add at the end of the PDF generation', 'pdf') . ''; echo ""; diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index e85e2e9..78b92b7 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -118,7 +118,11 @@ public function setHeader($msg) $this->header = $msg; $this->pdf->resetHeaderTemplate(); $this->pdf->SetTitle($msg); - if (Plugin::isPluginActive('branding')) { + $config = PluginPdfConfig::getInstance(); + if ( + Plugin::isPluginActive('branding') + && $config->getField('use_branding_logo') + ) { $brandingUtils = new \PluginBrandingUtils(); $logo = $brandingUtils->getFilePath(Session::getActiveEntity(), 'main_logo'); $this->pdf->SetHeaderData($logo, 15, $msg, ''); From 6e2a0dddb2fdc940fdcb22c6da2ffb2441dacdcd Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Thu, 16 Jan 2025 09:47:46 +0100 Subject: [PATCH 04/13] In english please --- inc/config.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/inc/config.class.php b/inc/config.class.php index 3c418c8..1290dee 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -149,7 +149,6 @@ public static function showConfigForm($item) . (!empty($config->fields['use_branding_logo']) ? 'checked' : '') . ' />'; echo ''; - // Script pour synchroniser la valeur du champ caché avec la case à cocher echo ''; - } else { - echo ''; - } - echo ''; - - 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 ''; + 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'] + ] + ); $config->showFormButtons(['candel' => false]); diff --git a/templates/config.html.twig b/templates/config.html.twig new file mode 100644 index 0000000..b911146 --- /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%' + } +) }} From 9696e6e027fcaf0b3b4987cb48eb4be8f90e5b4d Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Fri, 21 Feb 2025 17:57:03 +0100 Subject: [PATCH 10/13] Fix cs fixer --- inc/config.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index ed6c48e..e218511 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -165,8 +165,8 @@ public static function showConfigForm($item) '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'] - ] + 'add_text' => $config->fields['add_text'], + ], ); $config->showFormButtons(['candel' => false]); From 0815f03f8dc8aadc2687a5753fff9d9fe83ef5e6 Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Fri, 21 Feb 2025 17:59:32 +0100 Subject: [PATCH 11/13] Fix headers --- templates/config.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/config.html.twig b/templates/config.html.twig index b911146..a1b4241 100644 --- a/templates/config.html.twig +++ b/templates/config.html.twig @@ -1,4 +1,4 @@ -{## +{# # ------------------------------------------------------------------------- # LICENSE # @@ -27,7 +27,7 @@ # http://www.gnu.org/licenses/agpl-3.0-standalone.html # -------------------------------------------------------------------------- #} - + {% import 'components/form/fields_macros.html.twig' as fields %} {% set candel = false %} From 4fb321f1de439794beafdfb5a8bff004642801eb Mon Sep 17 00:00:00 2001 From: Romain Lecouvreur <102067890+RomainLvr@users.noreply.github.com> Date: Mon, 24 Feb 2025 09:27:54 +0100 Subject: [PATCH 12/13] Update inc/simplepdf.class.php Co-authored-by: Stanislas --- inc/simplepdf.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 904727c..d0db2c8 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -126,7 +126,7 @@ public function setHeader($msg) ]; $hook = Plugin::doHookFunction('import_logo', $params); if ( - !empty($hook['logo']) + !empty($hook['logo_path']) && $config->getField('use_branding_logo') ) { $this->pdf->SetHeaderData($hook['logo'], 15, $msg, ''); From 4b08be0de92e8f9ff2376fb860bff6b104ed9db4 Mon Sep 17 00:00:00 2001 From: Romain Lecouvreur <102067890+RomainLvr@users.noreply.github.com> Date: Mon, 24 Feb 2025 09:28:21 +0100 Subject: [PATCH 13/13] Update inc/simplepdf.class.php Co-authored-by: Stanislas --- inc/simplepdf.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index d0db2c8..6dabf60 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -129,7 +129,7 @@ public function setHeader($msg) !empty($hook['logo_path']) && $config->getField('use_branding_logo') ) { - $this->pdf->SetHeaderData($hook['logo'], 15, $msg, ''); + $this->pdf->SetHeaderData($hook['logo_path'], 15, $msg, ''); } else { $path = Plugin::getPhpDir('pdf') . '/pics/'; $this->pdf->SetHeaderData($path . 'fd_logo.png', 15, $msg, '');