Skip to content
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
66 changes: 49 additions & 17 deletions inc/config.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
<?php

/**
* -------------------------------------------------------------------------
* 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 <http://www.gnu.org/licenses/>.
*
* @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
Expand Down Expand Up @@ -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}
Expand All @@ -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 "<tr class='tab_bg_1'>";
echo '<td>' . __('Choose your international currency', 'pdf') . '</td><td>';
$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 "</td></tr>\n";

echo "<tr class='tab_bg_1'>";
echo '<td>' . __('Text to add at the end of the PDF generation', 'pdf') . '</td>';
echo "<td rowspan='5' class='middle' colspan='3'>";
Html::textarea(['name' => 'add_text',
'value' => $config->fields['add_text'],
'rows' => '5',
'style' => 'width:95%']);
echo '</textarea>';

$config->showFormButtons(['candel' => false]);

Expand Down
30 changes: 16 additions & 14 deletions inc/simplepdf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@

//use TCPDF;

define('K_PATH_IMAGES', Plugin::getPhpDir('pdf') . '/pics/');


define('K_PATH_IMAGES', '');
class PluginPdfSimplePDF
{
// Page orientation
Expand Down Expand Up @@ -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, '');
}
}

Expand Down
80 changes: 80 additions & 0 deletions templates/config.html.twig
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
#
# @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')
) }}

<input type="hidden" id="use_branding_logo_hidden" name="use_branding_logo" value="{{ (use_branding_logo and is_branding_active) ? 1 : 0 }}" />
<div class="form-field row align-items-center col-12 col-sm-6 mb-2">
<label class="col-form-label col-xxl-5 text-xxl-end ">
<span class="d-inline-flex align-items-center">
<span>{{ __('Use logo from Branding plugin', 'pdf') }}</span>
</span>
</label>
<div class ="col-1 field-container">
{% if is_branding_active %}
<label class="form-switch mt-1" style="padding-left: 1rem;"
data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-trigger="hover"
title="{{ __('The logo will be used in the header of generated PDFs.', 'pdf') }}">
<input type="checkbox" class="form-check-input ms-0 me-1 mt-0" id="use_branding_logo_checkbox"
{{ use_branding_logo ? 'checked' : '' }} />
</label>
<script>
document.getElementById("use_branding_logo_checkbox").addEventListener("change", function () {
document.getElementById("use_branding_logo_hidden").value = this.checked ? 1 : 0;
});
</script>
{% else %}
<label class="form-switch mt-1" style="padding-left: 1rem;"
data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-trigger="hover"
title="{{ __('The Branding plugin is disabled or non-existent', 'pdf') }}">
<input type="checkbox" class="form-check-input ms-0 me-1 mt-0" disabled />
</label>
{% endif %}
</div>
</div>

{{ fields.textareaField(
'add_text',
add_text,
__('Text to add at the end of the PDF generation', 'pdf'),
{
'rows': 5,
'style': 'width:95%'
}
) }}