static function showForItem(CommonDBTM $item, $withtemplate = '')
{
// Prints a direct connection to a computer
global $DB;
$comp = new Computer();
$ID = $item->getField('id');
if (!$item->can($ID, READ)) {
return false;
}
$canedit = $item->canEdit($ID);
$rand = mt_rand();
// Is global connection ?
$global = $item->getField('is_global');
$used = array();
$compids = array();
$crit = array('FIELDS' => array('id', 'computers_id', 'is_dynamic'), 'itemtype' => $item->getType(), 'items_id' => $ID, 'is_deleted' => 0);
foreach ($DB->request('glpi_computers_items', $crit) as $data) {
$compids[$data['id']] = $data['computers_id'];
$dynamic[$data['id']] = $data['is_dynamic'];
$used['Computer'][] = $data['computers_id'];
}
$number = count($compids);
if ($canedit && ($global || !$number)) {
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 a computer') . "</th></tr>";
echo "<tr class='tab_bg_1'><td class='right'>";
echo "<input type='hidden' name='items_id' value='{$ID}'>";
echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
if ($item->isRecursive()) {
self::dropdownConnect('Computer', $item->getType(), "computers_id", getSonsOf("glpi_entities", $item->getEntityID()), 0, $used);
} else {
self::dropdownConnect('Computer', $item->getType(), "computers_id", $item->getEntityID(), 0, $used);
}
echo "</td><td class='center'>";
echo "<input type='submit' name='add' value=\"" . _sx('button', 'Connect') . "\" class='submit'>";
echo "</td></tr>";
echo "</table>";
Html::closeForm();
echo "</div>";
}
echo "<div class='spaced'>";
if ($canedit && $number) {
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'>";
if ($number > 0) {
$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>" . __('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 ($compids as $key => $compid) {
$comp->getFromDB($compid);
echo "<tr class='tab_bg_1'>";
if ($canedit) {
echo "<td width='10'>";
Html::showMassiveActionCheckBox(__CLASS__, $key);
echo "</td>";
}
echo "<td " . ($comp->getField('is_deleted') ? "class='tab_bg_2_2'" : "") . ">" . $comp->getLink() . "</td>";
if (Plugin::haveImport()) {
echo "<td>" . Dropdown::getYesNo($dynamic[$key]) . "</td>";
}
echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $comp->getField('entities_id'));
echo "</td>";
echo "<td class='center'>" . $comp->getField('serial') . "</td>";
echo "<td class='center'>" . $comp->getField('otherserial') . "</td>";
echo "</tr>";
}
echo $header_begin . $header_bottom . $header_end;
} else {
echo "<tr><td class='tab_bg_1 b'><i>" . __('Not connected') . "</i>";
echo "</td></tr>";
}
echo "</table>";
if ($canedit && $number) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
}
echo "</div>";
}