NetworkName::showForItem PHP Method

showForItem() static public method

..) or if readden from item of the item (for instance from the computer form through NetworkPort::ShowForItem).
static public showForItem ( CommonDBTM $item, $withtemplate )
$item CommonDBTM CommonGLPI object
$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}&amp;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>";
        }
    }