$sql = "UPDATE `glpi_plugin_customfields_fields`\n SET `deleted` = 1,\n `system_name` = 'DELETED',\n `sort_order` = 0,\n `dropdown_table` = ''\n WHERE `itemtype` = '{$itemtype}'\n AND `id` = '" . intval($id) . "'\n AND `system_name` = '{$system_name}'"; } else { // Nothing in the history log, so delete the field completely $sql = "DELETE\n FROM `glpi_plugin_customfields_fields`\n WHERE `itemtype` = '{$itemtype}'\n AND `id` = '" . intval($id) . "'\n AND `system_name` = '{$system_name}'"; } // Remove the custom field from the data table $result = $DB->query($sql); $table = plugin_customfields_table($itemtype); $sql = "SELECT COUNT(`id`) AS num_left\n FROM `glpi_plugin_customfields_fields`\n WHERE `itemtype` = '{$itemtype}'\n AND `data_type` <> 'sectionhead'\n AND `deleted` = 0"; $result = $DB->query($sql); $data = $DB->fetch_assoc($result); if ($data['num_left'] == 0) { // If no more fields, drop the data table $sql = "DROP TABLE IF EXISTS `{$table}`"; // ...and disable the device plugin_customfields_disable_device($itemtype); } else { // Remove the column from the data table $sql = "ALTER TABLE `{$table}`\n DROP `{$system_name}`"; } $result = $DB->query($sql); } // Done. Reload. Html::redirect($_SERVER['HTTP_REFERER']); } else { if (isset($_POST['add'])) { // Add a field $data_ok = false; $sort = intval($_POST['sort']); if (isset($_POST['dropdown_id'])) { // Add a drop down menu
/** * Unregister an item type brought by an other plugin * * @param $itemtype * */ static function unregisterItemType($itemType) { global $DB; // Check if the itemtype has already been registered $query = "SELECT `enabled`\n FROM `glpi_plugin_customfields_itemtypes`\n WHERE `itemtype` = '{$itemType}'"; $result = $DB->query($query); if ($DB->numrows($result) != 0) { // The itemtype must be disabled before unregistration // Has no effect if the itemtype is not enabled plugin_customfields_disable_device($itemType); // The new item type needs to be unregistered // Remove the fields definition for the itemtype being deleted $query = "DELETE FROM `glpi_plugin_customfields_fields`\n WHERE `itemtype` = '{$itemType}'"; $result = $DB->query($query) or die($DB->error()); // Remove the itemtype from the itemtypes supported by the plugin $query = "DELETE FROM `glpi_plugin_customfields_itemtypes`\n WHERE `itemtype` = '{$itemType}'"; $result = $DB->query($query) or die($DB->error()); // Remove all data for the itemtype $table = plugin_customfields_table($itemType); if ($table) { $query = "DROP TABLE IF EXISTS `{$table}`"; $DB->query($query) or die($DB->error()); } // Unregister the itemtype $query = "DELETE FROM `glpi_plugin_customfields_itemtypes`\n WHERE `itemtype` = '{$itemType}'"; $DB->query($query) or die($DB->error()); } }