/** * Activates custom fields for all devices of a specific type * * @param $itemtype Type of item */ function plugin_customfields_activate_all($itemtype) { global $DB; // Only if there are fields $query = "SELECT `id`\r\n FROM `glpi_plugin_customfields_fields`\r\n WHERE `itemtype` = '{$itemtype}'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { // Create data table for the itemtype plugin_customfields_create_data_table($itemtype); // Item table $table1 = getTableForItemType($itemtype); // Customfields data table $table2 = plugin_customfields_table($itemtype); if ($itemtype == 'Entity') { // Add a row for the Root Entity $sql = "INSERT INTO `{$table2}` (`id`) VALUES ('0')"; $DB->query($sql); } // Add empty data for all existing objects $query = "SELECT a.`id`, b.`id` AS skip\r\n FROM {$table1} AS a\r\n LEFT JOIN {$table2} AS b\r\n ON a.`id` = b.`id`"; $result = $DB->query($query); while ($data = $DB->fetch_assoc($result)) { if (is_null($data['skip'])) { $sql = "INSERT INTO `{$table2}`\r\n (`id`)\r\n VALUES ('" . intval($data['id']) . "')"; $DB->query($sql); } } } }
$sopt_pos = $data['next_sopt_pos']; if (!$sopt_pos) { $sopt_pos = 1; } // Insert field $sql = "INSERT INTO `glpi_plugin_customfields_fields`\n (`itemtype`, `system_name`, `label`, `data_type`,\n `sort_order`, `dropdown_table`, `deleted`,\n `sopt_pos`, `restricted`)\n VALUES ('{$itemtype}', '{$system_name}', '{$label}',\n '{$data_type}', '{$sort}', '{$dd_table}', 0,\n '{$sopt_pos}', 0)"; $result = $DB->query($sql); if ($data_type != 'sectionhead') { // add the field to the data table if it isn't a section header $table = plugin_customfields_table($itemtype); if (CUSTOMFIELDS_AUTOACTIVATE) { // creates table and activates IF necessary plugin_customfields_activate_all($itemtype); } else { // creates table if it doesn't alreay exist plugin_customfields_create_data_table($itemtype); } switch ($data_type) { case 'general': $db_data_type = 'VARCHAR(255) collate utf8_unicode_ci default NULL'; break; case 'yesno': $db_data_type = 'SMALLINT(6) NOT NULL default \'0\''; break; case 'text': $db_data_type = 'TEXT collate utf8_unicode_ci'; break; case 'notes': $db_data_type = 'LONGTEXT collate utf8_unicode_ci'; break; case 'date':