/** * Display list of Optvalues for an appliance * * @param $appli PluginAppliancesAppliance instance * * @return nothing (display form) */ static function showForAppliance(PluginAppliancesAppliance $appli) { global $DB, $CFG_GLPI; if (!$appli->can($appli->fields['id'], 'r')) { return false; } $canedit = $appli->can($appli->fields['id'], 'w'); $rand = mt_rand(); if ($canedit) { echo "<form method='post' name='optvalues_form{$rand}' id='optvalues_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/appliances/front/appliance.form.php\">"; } echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . __('User fields', 'appliances') . "</th></tr>\n"; $query_app = "SELECT *\n FROM `glpi_plugin_appliances_optvalues`\n WHERE `plugin_appliances_appliances_id` = '" . $appli->fields['id'] . "'\n ORDER BY `vvalues`"; $result_app = $DB->query($query_app); $number_champs = $DB->numrows($result_app); $number_champs++; for ($i = 1; $i <= $number_champs; $i++) { if ($data = $DB->fetch_array($result_app)) { $champ = $data["champ"]; $ddefault = $data["ddefault"]; } else { $champ = ''; $ddefault = ''; } echo "<tr class='top tab_bg_1'>"; if ($i == 1) { echo "<td rowspan='" . $number_champs . "'>" . _n('Field', 'Fields', 1) . "</td>"; } echo "<td><input type='text' name='champ{$i}' value=\"" . $champ . "\" size='35'></td>\n"; if ($i == 1) { echo "<td rowspan='" . $number_champs . "'>" . __('Default', 'appliances') . "</td>"; } echo "<td><input type='text' name='ddefault{$i}' value=\"" . $ddefault . "\" size='35'></td></tr>\n"; } if ($canedit) { echo "<tr class='tab_bg_2'><td colspan='4' class='center'>"; echo "<input type='hidden' name='plugin_appliances_appliances_id' value='" . $appli->fields['id'] . "'>\n"; echo "<input type='hidden' name='number_champs' value='" . $number_champs . "'>\n"; echo "<input type='submit' name='update_optvalues' value=\"" . _sx('button', 'Update') . "\"\n class='submit'>"; echo "</td></tr>\n</table></div>"; Html::closeForm(); } else { echo "</table></div>"; } return true; }
/** * Show the Device associated with an applicatif * * Called from the applicatif form **/ static function showForAppliance(PluginAppliancesAppliance $appli) { global $DB, $CFG_GLPI; $instID = $appli->fields['id']; if (!$appli->can($instID, "r")) { return false; } $rand = mt_rand(); $canedit = $appli->can($instID, 'w'); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_plugin_appliances_appliances_items`\n WHERE `plugin_appliances_appliances_id` = '" . $instID . "'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } echo "<form method='post' name='appliances_form{$rand}' id='appliances_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/appliances/front/appliance.form.php\">"; echo "<div class='center'><table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='" . ($canedit ? 6 + $colsup : 5 + $colsup) . "'>" . __('Associated items', 'appliances') . "</th></tr><tr>"; if ($canedit) { echo "<th> </th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } if ($appli->fields["relationtype"]) { echo "<th>" . __('Item to link', 'appliances') . "<br>" . __('User fields', 'appliances') . "</th>"; } echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $type = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($type))) { continue; } if ($item->canView()) { $column = "name"; if ($type == 'Ticket') { $column = "id"; } if ($type == 'KnowbaseItem') { $column = "question"; } $query = "SELECT `" . $item->getTable() . "`.*,\n `glpi_plugin_appliances_appliances_items`.`id` AS IDD,\n `glpi_entities`.`id` AS entity\n FROM `glpi_plugin_appliances_appliances_items`, " . getTableForItemType($type) . "\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `" . $item->getTable() . "`.`entities_id`)\n WHERE `" . $item->getTable() . "`.`id`\n = `glpi_plugin_appliances_appliances_items`.`items_id`\n AND `glpi_plugin_appliances_appliances_items`.`itemtype` = '" . $type . "'\n AND `glpi_plugin_appliances_appliances_items`.`plugin_appliances_appliances_id`\n = '" . $instID . "' " . getEntitiesRestrictRequest(" AND ", $item->getTable()); if ($item->maybeTemplate()) { $query .= " AND `" . $item->getTable() . "`.`is_template` = '0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $item->getTable() . "`.{$column}"; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { Session::initNavigateListItems($type, _n('Appliance', 'Appliances', 2, 'appliances') . "\n = " . $appli->getNameID()); while ($data = $DB->fetch_assoc($result_linked)) { $item->getFromDB($data["id"]); Session::addToNavigateListItems($type, $data["id"]); //TODO $ID never user - why this part ? $ID = ""; if ($type == 'Ticket') { $data["name"] = sprintf(__('%1$s %2$s'), __('Ticket'), $data["id"]); } if ($type == 'KnowbaseItem') { $data["name"] = $data["question"]; } if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $name = $item->getLink(); echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } echo "<input type='checkbox' name='item[" . $data["IDD"] . "]' value='1' {$sel}>"; echo "</td>"; } echo "<td class='center'>" . $item->getTypeName() . "</td>"; echo "<td class='center' " . (isset($data['deleted']) && $data['deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>"; } if ($appli->fields["relationtype"]) { echo "<td class='center'>" . PluginAppliancesRelation::getTypeName($appli->fields["relationtype"]) . " : "; PluginAppliancesRelation::showList($appli->fields["relationtype"], $data["IDD"], $item->fields["entities_id"], false); PluginAppliancesOptvalue_Item::showList($type, $data["id"], $instID, false); echo "</td>"; } echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } } } if ($canedit) { echo "<tr class='tab_bg_1'><td colspan='" . (3 + $colsup) . "' class='center'>"; echo "<input type='hidden' name='conID' value='{$instID}'>"; Dropdown::showAllItems("item", 0, 0, $appli->fields['is_recursive'] ? -1 : $appli->fields['entities_id'], $appli->getTypes()); echo "</td>"; echo "<td colspan='3' class='center' class='tab_bg_2'>"; echo "<input type='submit' name='additem' value='" . __('Add') . "' class='submit'>"; echo "</td></tr>"; echo "</table></div>"; Html::openArrowMassives("appliances_form{$rand}", true); Html::closeArrowMassives(array('deleteitem' => __('Delete permanently'))); } else { echo "</table></div>"; } Html::closeForm(); }