/** * Show the relation for a device/applicatif * * Called from PluginAppliancesAppliance->showItem and PluginAppliancesAppliance::showAssociated * * @param $drelation_type : type of the relation * @param $relID ID of the relation * @param $entity, ID of the entity of the device * @param $canedit, if user is allowed to edit the relation * - canedit the device if called from the device form * - must be false if called from the applicatif form **/ static function showList($relationtype, $relID, $entity, $canedit) { global $DB, $CFG_GLPI; if (!$relationtype) { return false; } // selects all the attached relations $itemtype = PluginAppliancesRelation::getItemType($relationtype); $title = PluginAppliancesRelation::getTypeName($relationtype); if ($itemtype == 'Location') { $sql_loc = "SELECT `glpi_plugin_appliances_relations`.`id`,\n `completename` AS dispname "; } else { $sql_loc = "SELECT `glpi_plugin_appliances_relations`.`id`,\n `name` AS dispname "; } $sql_loc .= "FROM `" . getTableForItemType($itemtype) . "` ,\n `glpi_plugin_appliances_relations`,\n `glpi_plugin_appliances_appliances_items`\n WHERE `" . getTableForItemType($itemtype) . "`.`id`\n = `glpi_plugin_appliances_relations`.`relations_id`\n AND `glpi_plugin_appliances_relations`.`plugin_appliances_appliances_items_id`\n = `glpi_plugin_appliances_appliances_items`.`id`\n AND `glpi_plugin_appliances_appliances_items`.`id` = '" . $relID . "'"; $result_loc = $DB->query($sql_loc); $number_loc = $DB->numrows($result_loc); if ($canedit) { echo "<form method='post' name='relation' action='" . $CFG_GLPI["root_doc"] . "/plugins/appliances/front/appliance.form.php'>"; echo "<br><input type='hidden' name='deviceID' value='" . $relID . "'>"; $i = 0; $itemlist = ""; $used = array(); if ($number_loc > 0) { echo "<table>"; while ($i < $number_loc) { $res = $DB->fetch_array($result_loc); echo "<tr><td class=top>"; // when the value of the checkbox is changed, the corresponding hidden variable value // is also changed by javascript echo "<input type='checkbox' name='itemrelation[" . $res["id"] . "]' value='1'></td><td>"; echo $res["dispname"]; echo "</td></tr>"; $i++; } echo "</table>"; echo "<input type='submit' name='dellieu' value='" . _sx('button', 'Delete permanently') . "'\n class='submit'>" . "<br><br>"; } echo "{$title} : "; Dropdown::show($itemtype, array('name' => "tablekey[" . $relID . "]", 'entity' => $entity, 'used' => $used)); echo " <input type='submit' name='addlieu' value=\"" . _sx('button', 'Add') . "\" class='submit'><br> "; Html::closeForm(); } else { if ($number_loc > 0) { while ($res = $DB->fetch_array($result_loc)) { echo $res["dispname"] . "<br>"; } } else { echo " "; } } }