/** * Show items links to a database * * @since version 0.84 * * @param $database PluginDatabasesDatabase object * * @return nothing (HTML display) **/ public static function showForDatabase(PluginDatabasesDatabase $database) { global $DB; $instID = $database->fields['id']; if (!$database->can($instID, READ)) { return false; } $rand = mt_rand(); $canedit = $database->can($instID, UPDATE); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_plugin_databases_databases_items`\n WHERE `plugin_databases_databases_id` = '{$instID}'\n ORDER BY `itemtype`\n LIMIT " . count(PluginDatabasesDatabase::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='databases_form{$rand}' id='databases_form{$rand}'\n action='" . Toolbox::getItemTypeFormURL("PluginDatabasesDatabase") . "'>"; 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_databases_databases_id' value='{$instID}'>"; Dropdown::showAllItems("items_id", 0, 0, $database->fields['is_recursive'] ? -1 : $database->fields['entities_id'], PluginDatabasesDatabase::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($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_databases_databases_items`.`id` AS items_id,\n `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_databases_databases_items`, `" . $itemTable . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemTable . "`.`entities_id`) " . " WHERE `" . $itemTable . "`.`id` = `glpi_plugin_databases_databases_items`.`items_id`\n AND `glpi_plugin_databases_databases_items`.`itemtype` = '{$itemType}'\n AND `glpi_plugin_databases_databases_items`.`plugin_databases_databases_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, PluginDatabasesDatabase::getTypeName(2) . " = " . $database->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($paramsma); Html::closeForm(); } echo "</div>"; }
function plugin_databases_MassiveActions($type) { if (in_array($type, PluginDatabasesDatabase::getTypes(true))) { return array('PluginDatabasesDatabase' . MassiveAction::CLASS_ACTION_SEPARATOR . 'plugin_databases__add_item' => __('Associate to the database', 'databases')); } return array(); }
function plugin_databases_MassiveActionsDisplay($options = array()) { $database = new PluginDatabasesDatabase(); if (in_array($options['itemtype'], PluginDatabasesDatabase::getTypes(true))) { $database->dropdownDatabases("plugin_databases_databases_id"); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . __s('Post') . "\" >"; } return ""; }