grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } // Relation between CartridgeItem and PrinterModel // since version 0.84 class CartridgeItem_PrinterModel extends CommonDBRelation { // From CommonDBRelation static public $itemtype_1 = 'CartridgeItem'; static public $items_id_1 = 'cartridgeitems_id'; static public $itemtype_2 = 'PrinterModel'; static public $items_id_2 = 'printermodels_id'; static public $checkItem_2_Rights = self::DONT_CHECK_ITEM_RIGHTS; function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { switch ($item->getType()) { case 'CartridgeItem' : self::showForCartridgeItem($item); break; } return true; } function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { if (!$withtemplate && Printer::canView()) { $nb = 0; switch ($item->getType()) { case 'CartridgeItem' : if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForCartridgeItem($item); } return self::createTabEntry(PrinterModel::getTypeName(Session::getPluralNumber()),$nb); } } return ''; } /** * @param $item CartridgeItem object **/ static function countForCartridgeItem(CartridgeItem $item) { $restrict = "`".static::getTable()."`.`cartridgeitems_id` = '".$item->getField('id') ."' AND `".static::getTable()."`.`printermodels_id` = `glpi_printermodels`.`id`"; return countElementsInTable(array('glpi_printermodels', static::getTable()), $restrict); } /** * Show the printer types that are compatible with a cartridge type * * @param $item CartridgeItem object * * @return nothing (display) **/ static function showForCartridgeItem(CartridgeItem $item) { global $DB, $CFG_GLPI; $instID = $item->getField('id'); if (!$item->can($instID, READ)) { return false; } $canedit = $item->canEdit($instID); $rand = mt_rand(); $query = "SELECT `".static::getTable()."`.`id`, `glpi_printermodels`.`name` AS `type`, `glpi_printermodels`.`id` AS `pmid` FROM `".static::getTable()."`, `glpi_printermodels` WHERE `".static::getTable()."`.`printermodels_id` = `glpi_printermodels`.`id` AND `".static::getTable()."`.`cartridgeitems_id` = '$instID' ORDER BY `glpi_printermodels`.`name`"; $result = $DB->query($query); $i = 0; $used = array(); $datas = array(); if ($number = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $used[$data["pmid"]] = $data["pmid"]; $datas[$data["id"]] = $data; } } if ($canedit) { echo "
"; echo "
"; echo ""; echo ""; echo ""; echo ""; echo "
".__('Add a compatible printer model')."
"; echo ""; PrinterModel::dropdown(array('used' => $used)); echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } if ($number) { echo "
"; if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = array('num_displayed' => min($_SESSION['glpilist_limit'], count($used)), 'container' => 'mass'.__CLASS__.$rand); Html::showMassiveActions($massiveactionparams); } echo ""; $header_begin = ""; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= ""; } $header_end .= ""; echo $header_begin.$header_top.$header_end; foreach ($datas as $data) { echo ""; if ($canedit) { echo ""; } echo ""; echo ""; } echo $header_begin.$header_bottom.$header_end; echo "
"; $header_top .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_end .= "".__('Model')."
"; Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); echo "".$data['type']."
"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "
"; } else { echo "

".__('No item found')."

"; } } } ?>