예제 #1
0
 /**
  * Show items links to a routetables
  *
  * @since version 0.84
  *
  * @param $routetable PluginRoutetablesRoutetable object
  *
  * @return nothing (HTML display)
  * */
 public static function showForRoutetables(PluginRoutetablesRoutetable $routetable)
 {
     global $DB;
     $instID = $routetable->fields['id'];
     if (!$routetable->can($instID, 'r')) {
         return false;
     }
     $rand = mt_rand();
     $canedit = $routetable->can($instID, 'w');
     $query = "SELECT DISTINCT `itemtype`\n             FROM `glpi_plugin_routetables_routetables_items`\n             WHERE `plugin_routetables_routetables_id` = '{$instID}'\n             ORDER BY `itemtype`\n             LIMIT " . count(PluginRoutetablesRoutetable::getTypes(true));
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form method='post' name='routetable_form{$rand}' id='routetable_form{$rand}'\n         action='" . Toolbox::getItemTypeFormURL("PluginRoutetablesRoutetable") . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='" . ($canedit ? 5 + $colsup : 4 + $colsup) . "'>" . __('Add an item') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td colspan='" . (3 + $colsup) . "' class='center'>";
         echo "<input type='hidden' name='plugin_routetables_routetables_id' value='{$instID}'>";
         Dropdown::showAllItems("items_id", 0, 0, -1, PluginRoutetablesRoutetable::getTypes());
         echo "</td>";
         echo "<td colspan='2' class='tab_bg_2'>";
         echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" 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();
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Serial number') . "</th>";
     echo "<th>" . __('Inventory number') . "</th>";
     echo "</tr>";
     for ($i = 0; $i < $number; $i++) {
         $itemType = $DB->result($result, $i, "itemtype");
         if (!($item = getItemForItemtype($itemType))) {
             continue;
         }
         if ($item->canView()) {
             $column = "name";
             $itemTable = getTableForItemType($itemType);
             $query = "SELECT `" . $itemTable . "`.*,\n                             `glpi_plugin_routetables_routetables_items`.`id` AS items_id,\n                             `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_routetables_routetables_items`, `" . $itemTable . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemTable . "`.`entities_id`) " . " WHERE `" . $itemTable . "`.`id` = `glpi_plugin_routetables_routetables_items`.`items_id`\n                AND `glpi_plugin_routetables_routetables_items`.`itemtype` = '{$itemType}'\n                AND `glpi_plugin_routetables_routetables_items`.`plugin_routetables_routetables_id` = '{$instID}' " . getEntitiesRestrictRequest(" AND ", $itemTable, '', '', $item->maybeRecursive());
             if ($item->maybeTemplate()) {
                 $query .= " AND `" . $itemTable . "`.`is_template` = '0'";
             }
             $query .= " ORDER BY `glpi_entities`.`completename`, `" . $itemTable . "`.`{$column}`";
             if ($result_linked = $DB->query($query)) {
                 if ($DB->numrows($result_linked)) {
                     Session::initNavigateListItems($itemType, PluginRoutetablesRoutetable::getTypeName(2) . " = " . $routetable->fields['name']);
                     while ($data = $DB->fetch_assoc($result_linked)) {
                         $item->getFromDB($data["id"]);
                         Session::addToNavigateListItems($itemType, $data["id"]);
                         $ID = "";
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $ID = " (" . $data["id"] . ")";
                         }
                         $link = Toolbox::getItemTypeFormURL($itemType);
                         $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $data["name"] . "{$ID}</a>";
                         echo "<tr class='tab_bg_1'>";
                         if ($canedit) {
                             echo "<td width='10'>";
                             Html::showMassiveActionCheckBox(__CLASS__, $data["items_id"]);
                             echo "</td>";
                         }
                         echo "<td class='center'>" . $item::getTypeName(1) . "</td>";
                         echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                         if (Session::isMultiEntitiesMode()) {
                             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>";
                         }
                         echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                         echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                         echo "</tr>";
                     }
                 }
             }
         }
     }
     echo "</table>";
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }