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
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions front/config.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@

Html::back();
}

/** @var array $CFG_GLPI */
global $CFG_GLPI;

Html::redirect($CFG_GLPI['root_doc'] . '/front/config.form.php?forcetab=' .
urlencode('PluginPdfConfig$1'));
3 changes: 3 additions & 0 deletions front/export.massive.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
$tab_id = unserialize($_SESSION['plugin_pdf']['tab_id']);
unset($_SESSION['plugin_pdf']['tab_id']);

/** @var \DBmysql $DB */
global $DB;

$result = $DB->request(
'glpi_plugin_pdf_preferences',
['SELECT' => 'tabref',
Expand Down
9 changes: 6 additions & 3 deletions front/preference.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,27 @@

include_once('../../../inc/includes.php');

/** @var \DBmysql $DB */
global $DB;

//Save user preferences
if (isset($_POST['plugin_pdf_user_preferences_save'])
&& isset($_POST['plugin_pdf_inventory_type'])) {
$DB->query("DELETE
$DB->doQuery("DELETE
FROM `glpi_plugin_pdf_preferences`
WHERE `users_id` ='" . $_SESSION['glpiID'] . "'
AND `itemtype`='" . $_POST['plugin_pdf_inventory_type'] . "'");

if (isset($_POST['item'])) {
foreach ($_POST['item'] as $key => $val) {
$DB->query("INSERT INTO `glpi_plugin_pdf_preferences`
$DB->doQuery("INSERT INTO `glpi_plugin_pdf_preferences`
(`id` ,`users_id` ,`itemtype` ,`tabref`)
VALUES (NULL , '" . $_SESSION['glpiID'] . "',
'" . $_POST['plugin_pdf_inventory_type'] . "', '$key')");
}
}
if (isset($_POST['page']) && $_POST['page']) {
$DB->query("INSERT INTO `glpi_plugin_pdf_preferences`
$DB->doQuery("INSERT INTO `glpi_plugin_pdf_preferences`
(`id` ,`users_id` ,`itemtype` ,`tabref`)
VALUES (NULL , '" . $_SESSION['glpiID'] . "',
'" . $_POST['plugin_pdf_inventory_type'] . "', 'landscape')");
Expand Down
127 changes: 64 additions & 63 deletions inc/appliance.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,29 @@ public function defineAllTabsPDF($options = [])
**/
public static function displayTabContentForPDF(PluginPdfSimplePDF $pdf, CommonGLPI $item, $tab)
{
switch ($tab) {
case 'Appliance_Item$1':
$plugin = new Plugin();
if (
$plugin->isActivated('appliances')
&& class_exists('PluginAppliancesAppliance_Item')
) {
PluginAppliancesAppliance_Item::pdfForAppliance($pdf, $item);
} else {
self::pdfForAppliance($pdf, $item);
}
break;
if ($item instanceof Appliance) {
switch ($tab) {
case 'Appliance_Item$1':
$plugin = new Plugin();
if (
$plugin->isActivated('appliances')
&& class_exists('PluginAppliancesAppliance_Item')
) {
PluginAppliancesAppliance_Item::pdfForAppliance($pdf, $item);
} else {
self::pdfForAppliance($pdf, $item);
}
break;

case 'PluginAppliancesOptvalue$1':
if (class_exists('PluginAppliancesOptvalue')) {
PluginAppliancesOptvalue::pdfForAppliance($pdf, $item);
}
break;
case 'PluginAppliancesOptvalue$1':
if (class_exists('PluginAppliancesOptvalue')) {
PluginAppliancesOptvalue::pdfForAppliance($pdf, $item);
}
break;

default:
return false;
default:
return false;
}
}

return true;
Expand Down Expand Up @@ -283,49 +285,48 @@ public static function pdfForAppliance(PluginPdfSimplePDF $pdf, Appliance $appli
}
$query['ORDER'] = ['glpi_entities.completename', $item->getTable() . '.' . $column];

if ($result_linked = $DB->request($query)) {
if (count($result_linked)) {
foreach ($result_linked as $id => $data) {
if (!$item->getFromDB($data['id'])) {
continue;
}

if ($type == 'Ticket') {
$data['name'] = sprintf(__('%1$s %2$s'), __('Ticket'), $data['id']);
}
if ($type == 'KnowbaseItem') {
$data['name'] = $data['question'];
}
$name = $data['name'];
if ($_SESSION['glpiis_ids_visible'] || empty($data['name'])) {
$name = sprintf(__('%1$s (%2$s)'), $name, $data['id']);
}

if (Session::isMultiEntitiesMode()) {
$pdf->setColumnsSize(12, 27, 25, 18, 18);
$pdf->displayLine(
$item->getTypeName(1),
$name,
Dropdown::getDropdownName(
'glpi_entities',
$data['entities_id'],
),
(isset($data['serial']) ? $data['serial'] : '-'),
(isset($data['otherserial']) ? $data['otherserial'] : '-'),
);
} else {
$pdf->setColumnsSize(25, 31, 22, 22);
$pdf->displayTitle(
$item->getTypeName(1),
$name,
(isset($data['serial']) ? $data['serial'] : '-'),
(isset($data['otherserial']) ? $data['otherserial'] : '-'),
);
}

if (!empty($data['IDD'])) {
self::showList_relation($pdf, $data['IDD']);
}
$result_linked = $DB->request($query);
if (count($result_linked)) {
foreach ($result_linked as $id => $data) {
if (!$item->getFromDB($data['id'])) {
continue;
}

if ($type == 'Ticket') {
$data['name'] = sprintf(__('%1$s %2$s'), __('Ticket'), $data['id']);
}
if ($type == 'KnowbaseItem') {
$data['name'] = $data['question'];
}
$name = $data['name'];
if (empty($data['name'])) {
$name = sprintf(__('%1$s (%2$s)'), $name, $data['id']);
}

if (Session::isMultiEntitiesMode()) {
$pdf->setColumnsSize(12, 27, 25, 18, 18);
$pdf->displayLine(
$item->getTypeName(1),
$name,
Dropdown::getDropdownName(
'glpi_entities',
$data['entities_id'],
),
(isset($data['serial']) ? $data['serial'] : '-'),
(isset($data['otherserial']) ? $data['otherserial'] : '-'),
);
} else {
$pdf->setColumnsSize(25, 31, 22, 22);
$pdf->displayTitle(
$item->getTypeName(1),
$name,
(isset($data['serial']) ? $data['serial'] : '-'),
(isset($data['otherserial']) ? $data['otherserial'] : '-'),
);
}

if (!empty($data['IDD'])) {
self::showList_relation($pdf, $data['IDD']);
}
}
}
Expand Down Expand Up @@ -425,7 +426,7 @@ public static function showList_PDF($pdf, $ID, $appliancesID)
));
}

public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonGLPI $item)
public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
{
/** @var DBmysql $DB */
global $DB;
Expand Down
27 changes: 13 additions & 14 deletions inc/cartridge.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,24 @@ public static function pdfForPrinter(PluginPdfSimplePDF $pdf, Printer $p, $old =

$col1 = $data['id'];
$col2 = sprintf(__('%1$s - %2$s'), $data['type'], $data['ref']);
$col6 = $data['pages'];
$col7 = '';

$tmp_dbeg = explode('-', $data['date_in']);
$tmp_dend = explode('-', $data['date_use']);

$stock_time_tmp = mktime(0, 0, 0, $tmp_dend[1], $tmp_dend[2], $tmp_dend[0])
- mktime(0, 0, 0, $tmp_dbeg[1], $tmp_dbeg[2], $tmp_dbeg[0]);
$stock_time_tmp = mktime(0, 0, 0, (int) $tmp_dend[1], (int) $tmp_dend[2], (int) $tmp_dend[0])
- mktime(0, 0, 0, (int) $tmp_dbeg[1], (int) $tmp_dbeg[2], (int) $tmp_dbeg[0]);
$stock_time += $stock_time_tmp;

if ($old) {
$tmp_dbeg = explode('-', $data['date_use']);
$tmp_dend = explode('-', $data['date_out']);

$use_time_tmp = mktime(0, 0, 0, $tmp_dend[1], $tmp_dend[2], $tmp_dend[0])
- mktime(0, 0, 0, $tmp_dbeg[1], $tmp_dbeg[2], $tmp_dbeg[0]);
$use_time_tmp = mktime(0, 0, 0, (int) $tmp_dend[1], (int) $tmp_dend[2], (int) $tmp_dend[0])
- mktime(0, 0, 0, (int) $tmp_dbeg[1], (int) $tmp_dbeg[2], (int) $tmp_dbeg[0]);
$use_time += $use_time_tmp;

$col6 = $data['pages'];
$col7 = '';

if ($pages < $data['pages']) {
$pages_printed += $data['pages'] - $pages;
$nb_pages_printed++;
Expand Down Expand Up @@ -195,12 +194,12 @@ public static function pdfForPrinter(PluginPdfSimplePDF $pdf, Printer $p, $old =
'<b><i>' . sprintf(
__('%1$s: %2$s'),
__('Average time in stock') . '</i></b>',
sprintf(_n('%d month', '%d months', $time_stock), $time_stock),
sprintf(_n('%d month', '%d months', (int) $time_stock), $time_stock),
),
'<b><i>' . sprintf(
__('%1$s: %2$s'),
__('Average time in use') . '</i></b>',
sprintf(_n('%d month', '%d months', $time_use), $time_use),
sprintf(_n('%d month', '%d months', (int) $time_use), $time_use),
),
'<b><i>' . sprintf(
__('%1$s: %2$s'),
Expand Down Expand Up @@ -328,16 +327,16 @@ public static function pdfForCartridgeItem(PluginPdfSimplePDF $pdf, CartridgeIte
if (!is_null($date_use)) {
$tmp_dbeg = explode('-', $data['date_in']);
$tmp_dend = explode('-', $data['date_use']);
$stock_time_tmp = mktime(0, 0, 0, $tmp_dend[1], $tmp_dend[2], $tmp_dend[0])
- mktime(0, 0, 0, $tmp_dbeg[1], $tmp_dbeg[2], $tmp_dbeg[0]);
$stock_time_tmp = mktime(0, 0, 0, (int) $tmp_dend[1], (int) $tmp_dend[2], (int) $tmp_dend[0])
- mktime(0, 0, 0, (int) $tmp_dbeg[1], (int) $tmp_dbeg[2], (int) $tmp_dbeg[0]);
$stock_time += $stock_time_tmp;
}
$pdfpages = '';
if ($state == 'old') {
$tmp_dbeg = explode('-', $data['date_use']);
$tmp_dend = explode('-', $data['date_out']);
$use_time_tmp = mktime(0, 0, 0, $tmp_dend[1], $tmp_dend[2], $tmp_dend[0])
- mktime(0, 0, 0, $tmp_dbeg[1], $tmp_dbeg[2], $tmp_dbeg[0]);
$use_time_tmp = mktime(0, 0, 0, (int) $tmp_dend[1], (int) $tmp_dend[2], (int) $tmp_dend[0])
- mktime(0, 0, 0, (int) $tmp_dbeg[1], (int) $tmp_dbeg[2], (int) $tmp_dbeg[0]);
$use_time += $use_time_tmp;

// Get initial counter page
Expand Down Expand Up @@ -365,7 +364,7 @@ public static function pdfForCartridgeItem(PluginPdfSimplePDF $pdf, CartridgeIte
);
}

if (($state == 'old') && ($number > 0)) {
if ($state == 'old') {
if ($nb_pages_printed == 0) {
$nb_pages_printed = 1;
}
Expand Down
31 changes: 17 additions & 14 deletions inc/cartridgeitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,21 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, CartridgeItem $cartitem)

public static function displayTabContentForPDF(PluginPdfSimplePDF $pdf, CommonGLPI $item, $tab)
{
switch ($tab) {
case 'Cartridge$1':
PluginPdfCartridge::pdfForCartridgeItem($pdf, $item, 'new');
PluginPdfCartridge::pdfForCartridgeItem($pdf, $item, 'used');
PluginPdfCartridge::pdfForCartridgeItem($pdf, $item, 'old');
break;

case 'CartridgeItem_PrinterModel$1':
self::pdfForPrinterModel($pdf, $item);
break;

default:
return false;
if ($item instanceof CartridgeItem) {
switch ($tab) {
case 'Cartridge$1':
PluginPdfCartridge::pdfForCartridgeItem($pdf, $item, 'new');
PluginPdfCartridge::pdfForCartridgeItem($pdf, $item, 'used');
PluginPdfCartridge::pdfForCartridgeItem($pdf, $item, 'old');
break;

case 'CartridgeItem_PrinterModel$1':
self::pdfForPrinterModel($pdf, $item);
break;

default:
return false;
}
}

return true;
Expand All @@ -152,6 +154,7 @@ public static function pdfForPrinterModel(PluginPdfSimplePDF $pdf, CartridgeItem

$iterator = CartridgeItem_PrinterModel::getListForItem($item);
$number = count($iterator);
$datas = [];

foreach ($iterator as $data) {
$datas[$data['linkid']] = $data;
Expand All @@ -160,7 +163,7 @@ public static function pdfForPrinterModel(PluginPdfSimplePDF $pdf, CartridgeItem
$pdf->setColumnsSize(100);
$title = '<b>' . _n('Printer model', 'Printer models', $number) . '</b>';
if (!$number) {
$pdf->displayTitle(_('No printel model associated', 'pdf'));
$pdf->displayTitle(__('No printel model associated', 'pdf'));
} else {
if ($number > $_SESSION['glpilist_limit']) {
$title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number);
Expand Down
Loading