. * --------------------------------------------------------------------- **/ class Pdu_Plug extends CommonDBRelation { static public $itemtype_1 = 'PDU'; static public $items_id_1 = 'pdus_id'; static public $itemtype_2 = 'Plug'; static public $items_id_2 = 'plugs_id'; static public $checkItem_1_Rights = self::DONT_CHECK_ITEM_RIGHTS; static public $mustBeAttached_1 = false; static public $mustBeAttached_2 = false; static function getTypeName($nb = 0) { return _n('PDU plug', 'PDU plugs', $nb); } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { $nb = 0; switch ($item->getType()) { default: $field = $item->getType() == PDU::getType() ? 'pdus_id' : 'plugs_id'; if ($_SESSION['glpishow_count_on_tabs']) { $nb = countElementsInTable( self::getTable(), [$field => $item->getID()] ); } return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb); } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { self::showItems($item, $withtemplate); } /** * Print items * * @param PDU $pdu PDU instance * * @return void */ static function showItems(PDU $pdu) { global $DB; $ID = $pdu->getID(); $rand = mt_rand(); if (!$pdu->getFromDB($ID) || !$pdu->can($ID, READ)) { return false; } $canedit = $pdu->canEdit($ID); $items = $DB->request([ 'FROM' => self::getTable(), 'WHERE' => [ 'pdus_id' => $pdu->getID() ] ]); $link = new self(); Session::initNavigateListItems( self::getType(), //TRANS : %1$s is the itemtype name, // %2$s is the name of the item (used for headings of a list) sprintf( __('%1$s = %2$s'), $pdu->getTypeName(1), $pdu->getName() ) ); $items = iterator_to_array($items); if ($canedit) { $rand = mt_rand(); echo "\n
\n"; echo "\t\n"; //echo "\t\n"; echo "
"; echo ""; Plug::dropdown([ 'name' => "plugs_id", 'rand' => $rand ]); echo ""; echo ""; echo Html::input( 'number_plugs', [ 'id' => 'number_plugs', 'type' => 'number', 'min' => 1 ] ); echo ""; echo ""; echo "
"; Html::closeForm(); } if (!count($items)) { echo ""; echo "
".__('No plug found')."
"; } else { if ($canedit) { $massiveactionparams = [ 'num_displayed' => min($_SESSION['glpilist_limit'], count($items)), 'container' => 'mass'.__CLASS__.$rand ]; Html::showMassiveActions($massiveactionparams); } echo ""; $header = ""; if ($canedit) { $header .= ""; } $header .= ""; $header .= ""; $header .= ""; echo $header; foreach ($items as $row) { $item = new Plug; $item->getFromDB($row['plugs_id']); echo ""; if ($canedit) { echo ""; } echo ""; echo ""; echo ""; } echo $header; echo "
"; $header .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header .= "".__('Name')."".__('Number')."
"; Html::showMassiveActionCheckBox(__CLASS__, $row["id"]); echo "" . $item->getLink() . "{$row['number_plugs']}
"; if ($canedit && count($items)) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); } if ($canedit) { Html::closeForm(); } } } }