/** * \brief Show names for an item from its form * Beware that the rendering can be different if readden from direct item form (ie : add new * NetworkName, remove, ...) or if readden from item of the item (for instance from the computer * form through NetworkPort::ShowForItem). * * @param $item CommonGLPI object * @param $withtemplate integer withtemplate param (default 0) **/ static function showForItem(CommonDBTM $item, $withtemplate = 0) { global $DB, $CFG_GLPI; $ID = $item->getID(); if (!$item->can($ID, READ)) { return false; } $rand = mt_rand(); if ($item->getType() == 'NetworkPort' && Session::haveRight('internet', UPDATE) && $item->canUpdateItem()) { $items_id = $item->getID(); $itemtype = $item->getType(); echo "<div class='firstbloc'>\n"; echo "<form method='post' action='" . static::getFormURL() . "'>\n"; echo "<table class='tab_cadre_fixe'>\n"; echo "<tr><th colspan='4'>" . __('Add a network name') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='right'>"; echo "<input type='hidden' name='items_id' value='{$items_id}'>\n"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n"; _e('Not associated'); echo "</td><td class='left'>"; self::dropdown(array('name' => 'addressID', 'condition' => '`items_id`=0')); echo "</td><td class='left'>"; echo "<input type='submit' name='assign_address' value='" . _sx('button', 'Associate') . "' class='submit'>"; echo "</td>"; if (static::canCreate()) { echo "<td class='right' width='30%'>"; echo "<a href=\"" . static::getFormURL() . "?items_id={$items_id}&itemtype={$itemtype}\">"; echo __('Create a new network name') . "</a>"; echo "</td>"; } echo "</tr>\n"; echo "</table>\n"; Html::closeForm(); echo "</div>\n"; } $table_options = array('createRow' => true); if ($item->getType() == 'FQDN' || $item->getType() == 'NetworkEquipment') { if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (!empty($_GET["order"])) { $table_options['order'] = $_GET["order"]; } else { $table_options['order'] = 'name'; } if ($item->getType() == 'FQDN') { $table_options['column_links'] = array('NetworkName' => 'javascript:reloadTab("order=name");', 'NetworkAlias' => 'javascript:reloadTab("order=alias");', 'IPAddress' => 'javascript:reloadTab("order=ip");'); } $table_options['SQL_options'] = "LIMIT " . $_SESSION['glpilist_limit'] . "\n OFFSET {$start}"; $canedit = false; } else { $canedit = Session::haveRight('internet', UPDATE) && $item->canUpdateItem(); } $table_options['canedit'] = false; $table_options['rand'] = $rand; $table_options['massiveactionnetworkname'] = $canedit; $table = new HTMLTableMain(); $column = $table->addHeader('Internet', self::getTypeName(Session::getPluralNumber())); $t_group = $table->createGroup('Main', ''); self::getHTMLTableHeader(__CLASS__, $t_group, $column, NULL, $table_options); $t_row = $t_group->createRow(); self::getHTMLTableCellsForItem($t_row, $item, NULL, $table_options); if ($table->getNumberOfRows() > 0) { $number = $table->getNumberOfRows(); if ($item->getType() == 'FQDN') { $number = min($_SESSION['glpilist_limit'], $table->getNumberOfRows()); Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item)); } Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } $table->display(array('display_title_for_each_group' => false, 'display_thead' => false, 'display_tfoot' => false, 'display_header_on_foot_for_each_group' => true)); if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } if ($item->getType() == 'FQDN') { Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item)); } } else { echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network name found') . "</th></tr>"; echo "</table>"; } }
static function showForItem(CommonGLPI $item, $withtemplate = 0) { global $DB, $CFG_GLPI; if ($item->getType() == 'IPNetwork') { if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (!empty($_GET["order"])) { $table_options['order'] = $_GET["order"]; } else { $table_options['order'] = 'ip'; } $order_by_itemtype = $table_options['order'] == 'itemtype'; $table_options['SQL_options'] = "LIMIT " . $_SESSION['glpilist_limit'] . "\n OFFSET {$start}"; $table = new HTMLTableMain(); $content = "<a href='javascript:reloadTab(\"order=ip\");'>" . self::getTypeName(Session::getPluralNumber()) . "</a>"; $internet_column = $table->addHeader('IP Address', $content); $content = sprintf(__('%1$s - %2$s'), _n('Item', 'Items', Session::getPluralNumber()), "<a href='javascript:reloadTab(\"order=itemtype\");'>" . __('Order by item type') . "</a>"); $item_column = $table->addHeader('Item', $content); if ($order_by_itemtype) { foreach ($CFG_GLPI["networkport_types"] as $itemtype) { $table_options['group_' . $itemtype] = $table->createGroup($itemtype, $itemtype::getTypeName(Session::getPluralNumber())); self::getHTMLTableHeader($item->getType(), $table_options['group_' . $itemtype], $item_column, NULL, $table_options); } } $table_options['group_None'] = $table->createGroup('Main', __('Other kind of items')); self::getHTMLTableHeader($item->getType(), $table_options['group_None'], $item_column, NULL, $table_options); self::getHTMLTableCellsForItem(NULL, $item, NULL, $table_options); if ($table->getNumberOfRows() > 0) { Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item)); Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); $table->display(array('display_title_for_each_group' => $order_by_itemtype, 'display_super_for_each_group' => false, 'display_tfoot' => false)); Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, self::countForItem($item)); } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No IP address found') . "</th></tr>"; echo "</table>"; } } }