/**
  * Show rack associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated rack must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID) || !self::canView() || !$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginRacksRack');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $itemtype = $item->getType() . "Model";
     $query = "SELECT `glpi_plugin_racks_racks_items`.`id` AS assocID,\n                       `glpi_plugin_racks_racks_items`.`faces_id`,\n                       `glpi_plugin_racks_racks_items`.`position`,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_racks_racks`.`name` AS assocName,\n                       `glpi_plugin_racks_racks`.*\n                FROM `glpi_plugin_racks_racks_items`\n                LEFT JOIN `glpi_plugin_racks_racks`\n                 ON (`glpi_plugin_racks_racks_items`.`plugin_racks_racks_id`=`glpi_plugin_racks_racks`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_racks_racks`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_racks_racks_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_racks_racks_items`.`itemtype` = '" . $itemtype . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_racks_racks", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $racks = array();
     $rack = new PluginRacksRack();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $racks[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Disposition', 'racks') . "</th>";
     echo "<th>" . __('Position', 'racks') . "</th>";
     echo "<th>" . __('Location') . "</th>";
     echo "<th>" . __('Place', 'racks') . "</th>";
     echo "<th>" . __('Manufacturer') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginRacksRack', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($racks as $data) {
             $rackID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($rack->getFromDB($rackID)) {
                 $link = $rack->getLink();
             }
             Session::addToNavigateListItems('PluginRacksRack', $rackID);
             $used[$rackID] = $rackID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             if ($data["faces_id"] == PluginRacksRack::FRONT_FACE) {
                 $faces_id = __('Front', 'racks');
             } else {
                 $faces_id = _x('Rack enclosure', 'Back', 'racks');
             }
             echo "<td class='center'>" . $faces_id . "</td>";
             echo "<td class='center'>" . $data["position"] . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_locations", $data["locations_id"]) . "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_racks_roomlocations", $data["plugin_racks_roomlocations_id"], 0) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]) . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }