Computer_Item::showForComputer PHP Method

showForComputer() static public method

Print the form for computers or templates connections to printers, screens or peripherals
static public showForComputer ( Computer $comp, $withtemplate = '' ) : Nothing
$comp Computer Computer object
$withtemplate boolean Template or basic item (default '')
return Nothing (call to classes members)
    static function showForComputer(Computer $comp, $withtemplate = '')
    {
        global $DB, $CFG_GLPI;
        $ID = $comp->fields['id'];
        $canedit = $comp->canEdit($ID);
        $rand = mt_rand();
        $datas = array();
        $used = array();
        foreach ($CFG_GLPI["directconnect_types"] as $itemtype) {
            $item = new $itemtype();
            if ($item->canView()) {
                $query = "SELECT `glpi_computers_items`.`id` AS assoc_id,\n                      `glpi_computers_items`.`computers_id` AS assoc_computers_id,\n                      `glpi_computers_items`.`itemtype` AS assoc_itemtype,\n                      `glpi_computers_items`.`items_id` AS assoc_items_id,\n                      `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic,\n                      " . getTableForItemType($itemtype) . ".*\n                      FROM `glpi_computers_items`\n                      LEFT JOIN `" . getTableForItemType($itemtype) . "`\n                        ON (`" . getTableForItemType($itemtype) . "`.`id`\n                              = `glpi_computers_items`.`items_id`)\n                      WHERE `computers_id` = '{$ID}'\n                            AND `itemtype` = '" . $itemtype . "'\n                            AND `glpi_computers_items`.`is_deleted` = '0'";
                if ($item->maybetemplate()) {
                    $query .= " AND NOT `" . getTableForItemType($itemtype) . "`.`is_template` ";
                }
                if ($result = $DB->query($query)) {
                    while ($data = $DB->fetch_assoc($result)) {
                        $datas[] = $data;
                        $used[$itemtype][] = $data['assoc_items_id'];
                    }
                }
            }
        }
        $number = count($datas);
        if ($canedit) {
            echo "<div class='firstbloc'>";
            echo "<form name='computeritem_form{$rand}' id='computeritem_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
            echo "<table class='tab_cadre_fixe'>";
            echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Connect an item') . "</th></tr>";
            echo "<tr class='tab_bg_1'><td>";
            if (!empty($withtemplate)) {
                echo "<input type='hidden' name='_no_history' value='1'>";
            }
            self::dropdownAllConnect('Computer', "items_id", $comp->fields["entities_id"], $withtemplate, $used);
            echo "</td><td class='center' width='20%'>";
            echo "<input type='submit' name='add' value=\"" . _sx('button', 'Connect') . "\" class='submit'>";
            echo "<input type='hidden' name='computers_id' value='" . $comp->fields['id'] . "'>";
            echo "</td></tr>";
            echo "</table>";
            Html::closeForm();
            echo "</div>";
        }
        if ($number) {
            echo "<div class='spaced'>";
            if ($canedit) {
                Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
                $massiveactionparams = array('num_displayed' => $number, 'specific_actions' => array('purge' => _x('button', 'Disconnect')), 'container' => 'mass' . __CLASS__ . $rand);
                Html::showMassiveActions($massiveactionparams);
            }
            echo "<table class='tab_cadre_fixehov'>";
            $header_begin = "<tr>";
            $header_top = '';
            $header_bottom = '';
            $header_end = '';
            if ($canedit) {
                $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                $header_top .= "</th>";
                $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                $header_bottom .= "</th>";
            }
            $header_end .= "<th>" . __('Type') . "</th>";
            $header_end .= "<th>" . __('Name') . "</th>";
            if (Plugin::haveImport()) {
                $header_end .= "<th>" . __('Automatic inventory') . "</th>";
            }
            $header_end .= "<th>" . __('Entity') . "</th>";
            $header_end .= "<th>" . __('Serial number') . "</th>";
            $header_end .= "<th>" . __('Inventory number') . "</th>";
            $header_end .= "</tr>";
            echo $header_begin . $header_top . $header_end;
            foreach ($datas as $data) {
                $linkname = $data["name"];
                $itemtype = $data['assoc_itemtype'];
                if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                    $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]);
                }
                $link = Toolbox::getItemTypeFormURL($itemtype);
                $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $linkname . "</a>";
                echo "<tr class='tab_bg_1'>";
                if ($canedit) {
                    echo "<td width='10'>";
                    Html::showMassiveActionCheckBox(__CLASS__, $data["assoc_id"]);
                    echo "</td>";
                }
                echo "<td class='center'>" . $data['assoc_itemtype']::getTypeName(1) . "</td>";
                echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                if (Plugin::haveImport()) {
                    echo "<td>" . Dropdown::getYesNo($data['assoc_is_dynamic']) . "</td>";
                }
                echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']);
                echo "</td>";
                echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                echo "</tr>";
            }
            echo $header_begin . $header_bottom . $header_end;
            echo "</table>";
            if ($canedit && $number) {
                $massiveactionparams['ontop'] = false;
                Html::showMassiveActions($massiveactionparams);
                Html::closeForm();
            }
            echo "</div>";
        }
    }

Usage Example

     NetworkPort::showForItem('Computer', $_POST["id"]);
     Infocom::showForItem($computer);
     Contract::showAssociated($computer, $_POST["withtemplate"]);
     Document::showAssociated($computer);
     Ticket::showListForItem('Computer', $_POST["id"]);
     Link::showForItem('Computer', $_POST["id"]);
     RegistryKey::showForComputer($_POST["id"]);
     ComputerVirtualMachine::showForVirtualMachine($computer);
     ComputerVirtualMachine::showForComputer($computer);
     Plugin::displayAction($computer, $_REQUEST['glpi_tab']);
     break;
 case 2:
     Computer_SoftwareVersion::showForComputer($computer);
     break;
 case 3:
     Computer_Item::showForComputer($_POST['target'], $computer);
     NetworkPort::showForItem('Computer', $_POST["id"]);
     break;
 case 4:
     Infocom::showForItem($computer);
     Contract::showAssociated($computer);
     break;
 case 5:
     Document::showAssociated($computer);
     break;
 case 6:
     Ticket::showListForItem('Computer', $_POST["id"]);
     break;
 case 7:
     Link::showForItem('Computer', $_POST["id"]);
     break;