Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed

- Fix PDF export of tabs renamed in GLPI 11

## [4.1.4] - 2026-07-30

### Fixed
Expand Down
15 changes: 13 additions & 2 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* --------------------------------------------------------------------------
*/

use Glpi\Asset\Asset_PeripheralAsset;

abstract class PluginPdfCommon extends CommonGLPI
{
protected $obj = null;
Expand Down Expand Up @@ -180,7 +182,8 @@ final public static function displayCommonTabForPDF(PluginPdfSimplePDF $pdf, Com
}
break;

case 'Ticket$1':
case 'Item_Ticket$1': // tab added on assets
case 'Ticket$1': // tab added on User, Group and SLA
if (Ticket::canView()) {
PluginPdfItem_Ticket::pdfForItem($pdf, $item);
}
Expand Down Expand Up @@ -230,10 +233,18 @@ final public static function displayCommonTabForPDF(PluginPdfSimplePDF $pdf, Com
PluginPdfItem_Disk::pdfForItem($pdf, $item);
break;

case 'Computer_Item$1':
case Asset_PeripheralAsset::class . '$1':
PluginPdfComputer_Item::pdfForItem($pdf, $item);
break;

case 'ItemAntivirus$1': // registered on Computer and Phone
PluginPdfItemAntivirus::pdfForItem($pdf, $item);
break;

case 'ItemVirtualMachine$1':
PluginPdfItemVirtualMachine::pdfForItem($pdf, $item);
break;

case 'Item_SoftwareVersion$1':
PluginPdfItem_SoftwareVersion::pdfForItem($pdf, $item);
break;
Expand Down
12 changes: 3 additions & 9 deletions inc/computer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* --------------------------------------------------------------------------
*/

use Glpi\Asset\Asset_PeripheralAsset;

class PluginPdfComputer extends PluginPdfCommon
{
public static $rightname = 'plugin_pdf';
Expand Down Expand Up @@ -188,15 +190,7 @@ public static function displayTabContentForPDF(PluginPdfSimplePDF $pdf, CommonGL
{
if ($item instanceof Computer) {
switch ($tab) {
case 'ComputerVirtualMachine$1':
PluginPdfComputerVirtualMachine::pdfForComputer($pdf, $item);
break;

case 'ComputerAntivirus$1':
PluginPdfComputerAntivirus::pdfForComputer($pdf, $item);
break;

case 'Computer_Item$1':
case Asset_PeripheralAsset::class . '$1':
PluginPdfComputer_Item::pdfForComputer($pdf, $item);
break;

Expand Down
62 changes: 35 additions & 27 deletions inc/computer_item.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,51 +41,48 @@ public function __construct(?CommonGLPI $obj = null)
$this->obj = ($obj ?: new Asset_PeripheralAsset());
}

public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp)
public static function pdfForComputer(PluginPdfSimplePDF $pdf, CommonDBTM $comp)
{
/** @var DBmysql $DB */
global $DB;
/** @var array $CFG_GLPI */
global $DB, $CFG_GLPI;

$dbu = new DbUtils();

$ID = $comp->getField('id');

$items = ['Printer' => _sn('Printer', 'Printers', 2),
'Monitor' => _sn('Monitor', 'Monitors', 2),
'Peripheral' => _sn('Device', 'Devices', 2),
'Phone' => _sn('Phone', 'Phones', 2)];

$info = new Infocom();

$pdf->setColumnsSize(100);
$pdf->displayTitle('<b>' . __s('Direct connections') . '</b>');

foreach (array_keys($items) as $type) {
foreach ($CFG_GLPI['directconnect_types'] as $type) {
$item = $dbu->getItemForItemtype($type);
if (!$item->canView()) {
if (!$item || !$item->canView()) {
continue;
}
$itemTable = $dbu->getTableForItemType($type);
$query = [
'SELECT' => [
'glpi_assets_assets_peripheralassets.id AS assoc_id',
'glpi_assets_assets_peripheralassets.computers_id AS assoc_computers_id',
'glpi_assets_assets_peripheralassets.itemtype',
'glpi_assets_assets_peripheralassets.items_id',
'glpi_assets_assets_peripheralassets.items_id_asset AS assoc_items_id_asset',
'glpi_assets_assets_peripheralassets.itemtype_peripheral',
'glpi_assets_assets_peripheralassets.items_id_peripheral',
'glpi_assets_assets_peripheralassets.is_dynamic AS assoc_is_dynamic',
],
'FROM' => 'glpi_assets_assets_peripheralassets',
'LEFT JOIN' => [
$itemTable => [
'FKEY' => [
$itemTable => 'id',
'glpi_assets_assets_peripheralassets' => 'items_id',
'glpi_assets_assets_peripheralassets' => 'items_id_peripheral',
],
],
],
'WHERE' => [
'computers_id' => $ID,
'itemtype' => $type,
'itemtype_asset' => $comp->getType(),
'items_id_asset' => $ID,
'itemtype_peripheral' => $type,
'glpi_assets_assets_peripheralassets.is_deleted' => 0,
],
];
Expand All @@ -98,8 +95,7 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp)
$resultnum = count($result);
if ($resultnum > 0) {
foreach ($result as $row) {
$tID = $row['items_id'];
$connID = $row['id'];
$tID = $row['items_id_peripheral'];
$item->getFromDB($tID);
if (!$info->getFromDBforDevice($type, $tID)) {
$info->getEmpty();
Expand Down Expand Up @@ -177,6 +173,13 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp)
case 'Phone':
$pdf->displayLine(__s('No phone', 'pdf'));
break;

default:
$pdf->displayLine(sprintf(
__s('%1$s: %2$s'),
$item->getTypeName(1),
__s('No item to display'),
));
}
} // No row
} // each type
Expand All @@ -188,18 +191,21 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
/** @var DBmysql $DB */
global $DB;

$dbu = new DbUtils();

$ID = $item->getField('id');
$type = $item->getType();

$info = new Infocom();
$comp = new Computer();

$pdf->setColumnsSize(100);
$title = '<b>' . __s('Direct connections') . '</b>';

$result = $DB->request(
['FROM' => 'glpi_assets_assets_peripheralassets'] + ['items_id' => $ID,
'itemtype' => $type],
['FROM' => 'glpi_assets_assets_peripheralassets',
'WHERE' => ['itemtype_peripheral' => $type,
'items_id_peripheral' => $ID,
'is_deleted' => 0]],
);
$resultnum = count($result);

Expand All @@ -209,10 +215,12 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
$pdf->displayTitle($title);

foreach ($result as $row) {
$tID = $row['computers_id'];
$connID = $row['id'];
$comp->getFromDB($tID);
if (!$info->getFromDBforDevice('Computer', $tID)) {
$tID = $row['items_id_asset'];
$comp = $dbu->getItemForItemtype($row['itemtype_asset']);
if (!$comp || !$comp->getFromDB($tID)) {
continue;
}
if (!$info->getFromDBforDevice($row['itemtype_asset'], $tID)) {
$info->getEmpty();
}

Expand Down Expand Up @@ -251,7 +259,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
sprintf(
__s('%1$s: %2$s'),
'<b>' . __s('Inventory number') . '</b>',
$item->getField('otherserial'),
$comp->fields['otherserial'],
),
);
}
Expand All @@ -269,13 +277,13 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
}
if ($line2 !== '' && $line2 !== '0') {
$pdf->displayText(
'<b>' . sprintf(__s('%1$s: %2$s'), __s('Computer') . '</b>', ''),
'<b>' . sprintf(__s('%1$s: %2$s'), $comp->getTypeName(1) . '</b>', ''),
$line1 . "\n" . $line2,
2,
);
} else {
$pdf->displayText(
'<b>' . sprintf(__s('%1$s: %2$s'), __s('Computer') . '</b>', ''),
'<b>' . sprintf(__s('%1$s: %2$s'), $comp->getTypeName(1) . '</b>', ''),
$line1,
1,
);
Expand Down
13 changes: 6 additions & 7 deletions inc/computerantivirus.class.php → inc/itemantivirus.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* --------------------------------------------------------------------------
*/

class PluginPdfComputerAntivirus extends PluginPdfCommon
class PluginPdfItemAntivirus extends PluginPdfCommon
{
public static $rightname = 'plugin_pdf';

Expand All @@ -39,15 +39,15 @@ public function __construct(?CommonGLPI $obj = null)
$this->obj = ($obj ?: new ItemAntivirus());
}

public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)
public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
{
/** @var DBmysql $DB */
global $DB;

$ID = $item->getField('id');

$result = $DB->request(['FROM' => 'glpi_itemantiviruses'] + ['computers_id' => $ID,
'is_deleted' => 0]);
$result = $DB->request(['FROM' => 'glpi_itemantiviruses',
'WHERE' => ['itemtype' => $item->getType(),
'items_id' => $item->getID(),
'is_deleted' => 0]]);
$number = count($result);

$pdf->setColumnsSize(100);
Expand All @@ -74,7 +74,6 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)
__s('Expiration date'),
);

$antivirus = new ItemAntivirus();
foreach ($result as $data) {
$pdf->displayLine(
$data['name'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* --------------------------------------------------------------------------
*/

class PluginPdfComputerVirtualMachine extends PluginPdfCommon
class PluginPdfItemVirtualMachine extends PluginPdfCommon
{
public static $rightname = 'plugin_pdf';

Expand All @@ -39,24 +39,26 @@ public function __construct(?CommonGLPI $obj = null)
$this->obj = ($obj ?: new ItemVirtualMachine());
}

public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)
public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
{
$dbu = new DbUtils();

$ID = $item->getField('id');

// From ComputerVirtualMachine::showForComputer()
// From ItemVirtualMachine::showForAsset()
$virtualmachines = $dbu->getAllDataFromTable(
'glpi_itemvirtualmachines',
['computers_id' => $ID],
['WHERE' => ['itemtype' => $item->getType(),
'items_id' => $ID],
'ORDER' => 'name'],
);
$pdf->setColumnsSize(100);
$title = '<b>' . __s('List of virtualized environments') . '</b>';

$number = count($virtualmachines);

if ($number === 0) {
$pdf->displayTitle('<b>' . __s('No virtualized environment associated with the computer') . '</b>');
$pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display')));
} else {
if ($number > $_SESSION['glpilist_limit']) {
$title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number);
Expand All @@ -80,10 +82,10 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)

foreach ($virtualmachines as $virtualmachine) {
$name = '';
if ($link_computer = ItemVirtualMachine::findVirtualMachine($virtualmachine)) {
$computer = new Computer();
if ($computer->getFromDB($link_computer)) {
$name = $computer->getName();
if ($link_item = ItemVirtualMachine::findVirtualMachine($virtualmachine)) {
$linked = $dbu->getItemForItemtype($virtualmachine['itemtype']);
if ($linked && $linked->getFromDB($link_item)) {
$name = $linked->getName();
}
}
$pdf->displayLine(
Expand All @@ -108,10 +110,11 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)
}
}

// From ComputerVirtualMachine::showForVirtualMachine()
if ($item->fields['uuid']) {
// From ItemVirtualMachine::showForVirtualMachine()
// The exported item may itself be a guest: look for the host(s) declaring a virtual machine having its UUID.
if (!empty($item->fields['uuid'])) {
$hosts = $dbu->getAllDataFromTable(
$item::getTable(),
'glpi_itemvirtualmachines',
['RAW'
=> ['LOWER(uuid)'
=> ItemVirtualMachine::getUUIDRestrictCriteria($item->fields['uuid']),
Expand All @@ -121,21 +124,18 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item)

if (count($hosts)) {
$pdf->setColumnsSize(100);
$pdf->displayTitle('<b>' . __s('List of virtualized environments') . '</b>');
$pdf->displayTitle('<b>' . __s('List of hosts') . '</b>');

$pdf->setColumnsSize(26, 37, 37);
$pdf->displayTitle(__s('Name'), __s('Operating system'), __s('Entity'));
$pdf->displayTitle(__s('Name'), __s('Serial number'), __s('Entity'));

$computer = new Computer();
foreach ($hosts as $host) {
if ($computer->getFromDB($host['id'])) {
$host_item = $dbu->getItemForItemtype($host['itemtype']);
if ($host_item && $host_item->getFromDB($host['items_id'])) {
$pdf->displayLine(
$computer->getName(),
Toolbox::stripTags(Dropdown::getDropdownName(
'glpi_operatingsystems',
$computer->getField('operatingsystems_id'),
)),
Dropdown::getDropdownName('glpi_entities', $computer->getEntityID()),
$host_item->getName(),
Toolbox::stripTags((string) $host_item->getField('serial')),
Dropdown::getDropdownName('glpi_entities', $host_item->getEntityID()),
);
}
}
Expand Down