本文整理匯總了PHP中Item_Devices::getDeviceTypes方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item_Devices::getDeviceTypes方法的具體用法?PHP Item_Devices::getDeviceTypes怎麽用?PHP Item_Devices::getDeviceTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Item_Devices
的用法示例。
在下文中一共展示了Item_Devices::getDeviceTypes方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: pdfDevice
static function pdfDevice(PluginPdfSimplePDF $pdf, Computer $computer)
{
global $DB;
$devtypes = Item_Devices::getDeviceTypes();
$ID = $computer->getField('id');
if (!$computer->can($ID, 'r')) {
return false;
}
$pdf->setColumnsSize(100);
$pdf->displayTitle('<b>' . Toolbox::ucfirst(_n('Component', 'Components', 2)) . '</b>');
$pdf->setColumnsSize(3, 14, 42, 41);
foreach ($devtypes as $itemtype) {
$devicetypes = new $itemtype();
$specificities = $devicetypes->getSpecificities();
$specif_fields = array_keys($specificities);
$specif_text = implode(',', $specif_fields);
if (!empty($specif_text)) {
$specif_text = " ," . $specif_text . " ";
}
$associated_type = str_replace('Item_', '', $itemtype);
$linktable = getTableForItemType($itemtype);
$fk = getForeignKeyFieldForTable(getTableForItemType($associated_type));
$query = "SELECT count(*) AS NB, `id`, `" . $fk . "`" . $specif_text . "\n FROM `" . $linktable . "`\n WHERE `items_id` = '" . $ID . "'\n AND `itemtype` = 'Computer'\n GROUP BY `" . $fk . "`" . $specif_text;
$device = new $associated_type();
foreach ($DB->request($query) as $data) {
if ($device->getFromDB($data[$fk])) {
$spec = $device->getAdditionalFields();
$col4 = '';
if (count($spec)) {
$colspan = 60 / count($spec);
foreach ($spec as $i => $label) {
if (isset($device->fields[$label["name"]]) && !empty($device->fields[$label["name"]])) {
if ($label["type"] == "dropdownValue" && $device->fields[$label["name"]] != 0) {
$table = getTableNameForForeignKeyField($label["name"]);
$value = Dropdown::getDropdownName($table, $device->fields[$label["name"]]);
$col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', Html::clean($value) . " ");
} else {
$value = $device->fields[$label["name"]];
$col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $value . " ");
}
} else {
if (isset($device->fields[$label["name"] . "_default"]) && !empty($device->fields[$label["name"] . "_default"])) {
$col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $device->fields[$label["name"] . "_default"] . " ");
}
}
}
}
$pdf->displayLine($data['NB'], $device->getTypeName(), $device->getName(), $col4);
}
}
}
$pdf->displaySpace();
}
示例2: update084to085
//.........這裏部分代碼省略.........
$DB->queryOrDie($query, "0.85 fix tags usage for storestatus");
}
}
}
// Upgrade ticket bookmarks
$query = "SELECT *\n FROM `glpi_bookmarks`";
if ($result = $DB->query($query)) {
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_assoc($result)) {
$num = 0;
$num2 = 0;
$options = array();
parse_str($data["query"], $options);
if (isset($options['field'])) {
// update ticket statuses
if (($data['itemtype'] = 'Ticket') && $data['type'] == Bookmark::SEARCH) {
foreach ($options['field'] as $key => $val) {
if (($val == 55 || $val == 52) && isset($options['contains'][$key])) {
if (isset($status[$options['contains'][$key]])) {
$options['contains'][$key] = $status[$options['contains'][$key]];
}
}
}
}
}
$query2 = "UPDATE `glpi_bookmarks`\n SET `query` = '" . addslashes(Toolbox::append_params($options)) . "'\n WHERE `id` = '" . $data['id'] . "'";
$DB->queryOrDie($query2, "0.85 update bookmarks");
}
}
}
//////////////////////////////////////////////////
// Device update
$migration->displayMessage(sprintf(__('Data migration - %s'), 'Devices'));
foreach (array_merge(CommonDevice::getDeviceTypes(), Item_Devices::getDeviceTypes()) as $itemtype) {
$table = $itemtype::getTable();
if (!FieldExists($table, 'entities_id')) {
$migration->addField($table, 'entities_id', 'integer');
$migration->addKey($table, array('entities_id'), 'entities_id');
}
if (!FieldExists($table, 'is_recursive')) {
$migration->addField($table, 'is_recursive', 'bool', array('update' => '1', 'after' => 'entities_id'));
$migration->addKey($table, array('is_recursive'), 'is_recursive');
}
}
// Adding the Registered ID class that contains PCI IDs and USB IDs for vendors
// as well devices
if (!TableExists('glpi_registeredids')) {
$query = "CREATE TABLE `glpi_registeredids` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(255) DEFAULT NULL,\n `items_id` int(11) NOT NULL DEFAULT '0',\n `itemtype` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n `device_type` varchar(100) COLLATE utf8_unicode_ci NOT NULL COMMENT 'USB, PCI ...',\n PRIMARY KEY (`id`),\n KEY `name` (`name`),\n KEY `item` (`items_id`, `itemtype`),\n KEY `device_type` (`device_type`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "0.85 add table glpi_registeredids");
}
// Complete the item_devices
foreach (array('glpi_items_devicecases', 'glpi_items_devicecontrols', 'glpi_items_devicedrives', 'glpi_items_devicegraphiccards', 'glpi_items_devicemotherboards', 'glpi_items_devicenetworkcards', 'glpi_items_devicepcis', 'glpi_items_devicepowersupplies', 'glpi_items_devicesoundcards') as $table) {
if (!FieldExists($table, 'serial')) {
$migration->addField($table, 'serial', 'string');
$migration->addKey($table, 'serial');
}
}
foreach (array('glpi_items_devicecontrols', 'glpi_items_devicedrives', 'glpi_items_devicegraphiccards', 'glpi_items_deviceharddrives', 'glpi_items_devicememories', 'glpi_items_devicenetworkcards', 'glpi_items_devicepcis', 'glpi_items_deviceprocessors', 'glpi_items_devicesoundcards') as $table) {
if (!FieldExists($table, 'busID')) {
$migration->addField($table, 'busID', 'string');
$migration->addKey($table, 'busID');
}
}
// Add key
foreach (array('glpi_items_devicecases', 'glpi_items_devicecontrols', 'glpi_items_devicedrives', 'glpi_items_devicegraphiccards', 'glpi_items_deviceharddrives', 'glpi_items_devicememories', 'glpi_items_devicemotherboards', 'glpi_items_devicenetworkcards', 'glpi_items_devicepcis', 'glpi_items_devicepowersupplies', 'glpi_items_deviceprocessors', 'glpi_items_devicesoundcards') as $table) {
$migration->dropKey($table, 'item');
示例3: update0831to084
//.........這裏部分代碼省略.........
}
}
$query = "UPDATE `glpi_notifications`\n SET `itemtype` = 'CartridgeItem'\n WHERE `itemtype` = 'Cartridge'";
$DB->queryOrDie($query, "0.83 update glpi_notifications for Cartridge");
$query = "UPDATE `glpi_notificationtemplates`\n SET `itemtype` = 'CartridgeItem'\n WHERE `itemtype` = 'Cartridge'";
$DB->queryOrDie($query, "0.83 update glpi_notificationtemplates for Cartridge");
$query = "UPDATE `glpi_notifications`\n SET `itemtype` = 'ConsumableItem'\n WHERE `itemtype` = 'Consumable'";
$DB->queryOrDie($query, "0.83 update glpi_notifications for Consumable");
$query = "UPDATE `glpi_notificationtemplates`\n SET `itemtype` = 'ConsumableItem'\n WHERE `itemtype` = 'Consumable'";
$DB->queryOrDie($query, "0.83 update glpi_notificationtemplates for Consumable");
$migration->createRule(array('sub_type' => 'RuleTicket', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 0, 'match' => 'AND', 'name' => 'Ticket location from item'), array(array('criteria' => 'locations_id', 'condition' => Rule::PATTERN_DOES_NOT_EXISTS, 'pattern' => 1), array('criteria' => 'items_locations', 'condition' => Rule::PATTERN_EXISTS, 'pattern' => 1)), array(array('field' => 'locations_id', 'action_type' => 'fromitem', 'value' => 1)));
$migration->createRule(array('sub_type' => 'RuleTicket', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 0, 'match' => 'AND', 'name' => 'Ticket location from user'), array(array('criteria' => 'locations_id', 'condition' => Rule::PATTERN_DOES_NOT_EXISTS, 'pattern' => 1), array('criteria' => 'users_locations', 'condition' => Rule::PATTERN_EXISTS, 'pattern' => 1)), array(array('field' => 'locations_id', 'action_type' => 'fromuser', 'value' => 1)));
// Change begin_date id for budget
$query = "UPDATE `glpi_displaypreferences`\n SET `num` = '5'\n WHERE `itemtype` = 'Budget'\n AND `num` = '2'";
$DB->query($query);
migrateComputerDevice('DeviceProcessor', 'frequency', 'integer', array('serial' => 'string'));
migrateComputerDevice('DeviceMemory', 'size', 'integer', array('serial' => 'string'));
migrateComputerDevice('DeviceHardDrive', 'capacity', 'integer', array('serial' => 'string'));
migrateComputerDevice('DeviceGraphicCard', 'memory', 'integer');
migrateComputerDevice('DeviceNetworkCard', 'mac', 'string');
migrateComputerDevice('DeviceSoundCard');
migrateComputerDevice('DeviceMotherBoard');
migrateComputerDevice('DeviceDrive');
migrateComputerDevice('DeviceControl');
migrateComputerDevice('DevicePci');
migrateComputerDevice('DeviceCase');
migrateComputerDevice('DevicePowerSupply');
$migration->migrationOneTable('glpi_computers_softwareversions');
//Rename fields in glpi_computers_softwareversions with inaproprious signification
$migration->changeField('glpi_computers_softwareversions', 'is_deleted', 'is_deleted_computer', 'bool');
$migration->changeField('glpi_computers_softwareversions', 'is_template', 'is_template_computer', 'bool');
$migration->migrationOneTable('glpi_computers_softwareversions');
$types = array('glpi_computers_items', 'glpi_computervirtualmachines', 'glpi_computers_softwareversions', 'glpi_computerdisks', 'glpi_networkports', 'glpi_computers_softwarelicenses', 'glpi_networknames', 'glpi_ipaddresses');
foreach (Item_Devices::getDeviceTypes() as $id => $type) {
$types[] = getTableForItemType($type);
}
//Add is_deleted for relations
foreach ($types as $table) {
if ($migration->addField($table, 'is_deleted', 'bool', array('value' => 0))) {
$migration->migrationOneTable($table);
$migration->addKey($table, 'is_deleted');
}
}
///For computers, rename is is_ocs_import to is_dynamic
$migration->changeField('glpi_computers', 'is_ocs_import', 'is_dynamic', 'bool');
$migration->migrationOneTable('glpi_computers');
$migration->dropKey("glpi_computers", 'is_ocs_import');
$migration->addKey("glpi_computers", 'is_dynamic');
//Add field is_dynamic
$types = array_merge($types, array('glpi_printers', 'glpi_phones', 'glpi_peripherals', 'glpi_networkequipments', 'glpi_networkports', 'glpi_monitors', 'glpi_networknames', 'glpi_ipaddresses'));
foreach ($types as $table) {
if ($migration->addField($table, 'is_dynamic', 'bool')) {
$migration->migrationOneTable($table);
$migration->addKey($table, 'is_dynamic');
}
}
$ADDTODISPLAYPREF['ReservationItem'] = array(5);
// split validation rights in both
$migration->changeField('glpi_profiles', 'validate_ticket', 'validate_request', 'char');
$migration->changeField('glpi_profiles', 'create_validation', 'create_request_validation', 'char');
$migration->migrationOneTable('glpi_profiles');
$migration->addField('glpi_profiles', 'validate_incident', 'char', array('update' => 'validate_request'));
$migration->addField('glpi_profiles', 'create_incident_validation', 'char', array('update' => 'create_request_validation'));
// add rights to delete all validation
$migration->addField('glpi_profiles', 'delete_validations', 'char', array('update' => 'delete_ticket'));
// add rights to manage public rssfeed
示例4: showForItem
//.........這裏部分代碼省略.........
echo "</tr>\n";
}
//Software licenses
$params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
$first = true;
$query = "SELECT `csv`.`id` AS `id`,\n `sv`.`name` AS `version`,\n `s`.`name` AS `software`\n FROM `glpi_computers_softwarelicenses` AS csv\n LEFT JOIN `glpi_softwarelicenses` AS sv\n ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n LEFT JOIN `glpi_softwares` AS s\n ON (`sv`.`softwares_id` = `s`.`id`)\n WHERE `csv`.`is_deleted` = '1'\n AND `csv`.`is_dynamic` = '1'\n AND `csv`.`computers_id` = '{$ID}'";
foreach ($DB->request($query) as $line) {
$header = true;
if ($first) {
echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n";
$first = false;
}
echo "<tr class='tab_bg_1'><td class='center' width='10'>";
echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>";
echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
echo "</tr>\n";
}
}
$first = true;
$item = new NetworkPort();
$params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype);
$params['FIELDS'] = array('id');
foreach ($DB->request('glpi_networkports', $params) as $line) {
$item->getFromDB($line['id']);
$header = true;
if ($first) {
echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n";
$first = false;
}
echo "<tr class='tab_bg_1'><td class='center' width='10'>";
echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>";
echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
echo "</tr>\n";
}
$first = true;
$item = new NetworkName();
$params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
$params['FIELDS'] = array('glpi_networknames' => 'id');
foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) {
$item->getFromDB($line['id']);
$header = true;
if ($first) {
echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n";
$first = false;
}
echo "<tr class='tab_bg_1'><td class='center' width='10'>";
echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>";
echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
echo "</tr>\n";
}
$first = true;
$item = new IPAddress();
$params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
$params['FIELDS'] = array('glpi_ipaddresses' => 'id');
foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) {
$item->getFromDB($line['id']);
$header = true;
if ($first) {
echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n";
$first = false;
}
echo "<tr class='tab_bg_1'><td class='center' width='10'>";
echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>";
echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
echo "</tr>\n";
}
$types = Item_Devices::getDeviceTypes();
$nb = 0;
foreach ($types as $old => $type) {
$nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n AND `itemtype`='{$itemtype}'\n AND `is_dynamic`='1'\n AND `is_deleted`='1'");
}
if ($nb) {
$header = true;
echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n";
foreach ($types as $old => $type) {
$associated_type = str_replace('Item_', '', $type);
$associated_table = getTableForItemType($associated_type);
$fk = getForeignKeyFieldForTable($associated_table);
$query = "SELECT `i`.`id`,\n `t`.`designation` AS `name`\n FROM `" . getTableForItemType($type) . "` AS i\n LEFT JOIN `{$associated_table}` AS t\n ON (`t`.`id` = `i`.`{$fk}`)\n WHERE `itemtype` = '{$itemtype}'\n AND `items_id` = '{$ID}'\n AND `is_dynamic` = '1'\n AND `is_deleted` = '1'";
foreach ($DB->request($query) as $data) {
echo "<tr class='tab_bg_1'><td class='center' width='10'>";
echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>";
echo "<td class='left' width='95%'>";
printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']);
echo "</td></tr>\n";
}
}
}
if ($header) {
echo "</table>";
Html::openArrowMassives('lock_form', true);
Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock')));
} else {
echo "<tr class='tab_bg_2'>";
echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>";
echo "</table>";
}
Html::closeForm();
echo "</div>\n";
}
示例5: processMassiveActionsForOneItemtype
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $baseitem, array $ids)
{
global $DB;
switch ($ma->getAction()) {
case 'unlock':
$input = $ma->getInput();
if (isset($input['attached_item'])) {
$attached_items = $input['attached_item'];
if (($device_key = array_search('Device', $attached_items)) !== false) {
unset($attached_items[$device_key]);
$attached_items = array_merge($attached_items, Item_Devices::getDeviceTypes());
}
$links = array();
foreach ($attached_items as $attached_item) {
$infos = self::getLocksQueryInfosByItemType($attached_item, $baseitem->getType());
if ($item = getItemForItemtype($infos['type'])) {
$infos['item'] = $item;
$links[$attached_item] = $infos;
}
}
foreach ($ids as $id) {
$action_valid = false;
foreach ($links as $infos) {
$infos['condition'][$infos['field']] = $id;
foreach ($DB->request($infos['table'], $infos['condition']) as $data) {
// Restore without history
$action_valid = $infos['item']->restore(array('id' => $data['id']));
}
}
if ($action_valid) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($infos['item']->getErrorMessage(ERROR_ON_ACTION));
}
}
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $baseitem, $ids);
}
示例6: getItemtypesThatCanHave
/**
* Get all the types that can have a document
*
* @since version 0.85
*
* @return array of the itemtypes
**/
static function getItemtypesThatCanHave()
{
global $CFG_GLPI;
return array_merge($CFG_GLPI['document_types'], CommonDevice::getDeviceTypes(), Item_Devices::getDeviceTypes());
}
示例7: updateComputer
/** Update a ocs computer
*
* @param $ID integer : ID of ocslinks row
* @param $plugin_ocsinventoryng_ocsservers_id integer : ocs server ID
* @param $dohistory bool : do history ?
* @param $force bool : force update ?
*
* @return action done
**/
static function updateComputer($ID, $plugin_ocsinventoryng_ocsservers_id, $dohistory, $force = 0)
{
global $DB, $PluginOcsinventoryngDBocs, $CFG_GLPI;
self::checkOCSconnection($plugin_ocsinventoryng_ocsservers_id);
$cfg_ocs = self::getConfig($plugin_ocsinventoryng_ocsservers_id);
$query = "SELECT *\n FROM `glpi_plugin_ocsinventoryng_ocslinks`\n WHERE `id` = '{$ID}'\n AND `plugin_ocsinventoryng_ocsservers_id`\n = '{$plugin_ocsinventoryng_ocsservers_id}'";
$result = $DB->query($query);
if ($DB->numrows($result) == 1) {
$line = $DB->fetch_assoc($result);
$comp = new Computer();
$comp->getFromDB($line["computers_id"]);
// Get OCS ID
$query_ocs = "SELECT *\n FROM `hardware`\n WHERE `ID` = '" . $line['ocsid'] . "'";
$result_ocs = $PluginOcsinventoryngDBocs->query($query_ocs);
// Need do history to be 2 not to lock fields
if ($dohistory) {
$dohistory = 2;
}
if ($PluginOcsinventoryngDBocs->numrows($result_ocs) == 1) {
$data_ocs = Toolbox::addslashes_deep($PluginOcsinventoryngDBocs->fetch_array($result_ocs));
// automatic transfer computer
if ($CFG_GLPI['transfers_id_auto'] > 0 && Session::isMultiEntitiesMode()) {
self::transferComputer($line, $data_ocs);
$comp->getFromDB($line["computers_id"]);
}
// update last_update and and last_ocs_update
$query = "UPDATE `glpi_plugin_ocsinventoryng_ocslinks`\n SET `last_update` = '" . $_SESSION["glpi_currenttime"] . "',\n `last_ocs_update` = '" . $data_ocs["LASTDATE"] . "',\n `ocs_agent_version` = '" . $data_ocs["USERAGENT"] . " '\n WHERE `id` = '{$ID}'";
$DB->query($query);
if ($force) {
$ocs_checksum = self::MAX_CHECKSUM;
self::setChecksumForComputer($line['ocsid'], $ocs_checksum);
} else {
$ocs_checksum = $data_ocs["CHECKSUM"];
}
$mixed_checksum = intval($ocs_checksum) & intval($cfg_ocs["checksum"]);
//By default log history
$loghistory["history"] = 1;
// Is an update to do ?
if ($mixed_checksum) {
// Get updates on computers :
$computer_updates = importArrayFromDB($line["computer_update"]);
if (!in_array(self::IMPORT_TAG_078, $computer_updates)) {
$computer_updates = self::migrateComputerUpdates($line["computers_id"], $computer_updates);
}
// Update Administrative informations
self::updateAdministrativeInfo($line['computers_id'], $line['ocsid'], $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $computer_updates, $comp->fields['entities_id'], $dohistory);
if ($mixed_checksum & pow(2, self::HARDWARE_FL)) {
$p = array('computers_id' => $line['computers_id'], 'ocs_id' => $line['ocsid'], 'plugin_ocsinventoryng_ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id, 'cfg_ocs' => $cfg_ocs, 'computers_updates' => $computer_updates, 'dohistory' => $dohistory, 'check_history' => true, 'entities_id' => $comp->fields['entities_id']);
$loghistory = self::updateHardware($p);
}
if ($mixed_checksum & pow(2, self::BIOS_FL)) {
self::updateBios($line['computers_id'], $line['ocsid'], $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $computer_updates, $dohistory, $comp->fields['entities_id']);
}
// Get import devices
$import_device = array();
$types = Item_Devices::getDeviceTypes();
foreach ($types as $old => $type) {
$associated_type = str_replace('Item_', '', $type);
$associated_table = getTableForItemType($associated_type);
$fk = getForeignKeyFieldForTable($associated_table);
$query = "SELECT `i`.`id`, `t`.`designation` as `name`\n FROM `" . getTableForItemType($type) . "` as i\n LEFT JOIN `{$associated_table}` as t ON (`t`.`id`=`i`.`{$fk}`)\n WHERE `itemtype`='Computer'\n AND `items_id`='" . $line['computers_id'] . "'\n AND `is_dynamic`";
$prevalue = $type . self::FIELD_SEPARATOR;
foreach ($DB->request($query) as $data) {
$import_device[$prevalue . $data['id']] = $prevalue . $data["name"];
// TODO voir si il ne serait pas plus simple propre
// en adaptant updateDevices
// $import_device[$type][$data['id']] = $data["name"];
}
}
if ($mixed_checksum & pow(2, self::MEMORIES_FL)) {
self::updateDevices("Item_DeviceMemory", $line['computers_id'], $line['ocsid'], $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, '', $dohistory);
}
if ($mixed_checksum & pow(2, self::STORAGES_FL)) {
self::updateDevices("Item_DeviceHardDrive", $line['computers_id'], $line['ocsid'], $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, '', $dohistory);
self::updateDevices("Item_DeviceDrive", $line['computers_id'], $line['ocsid'], $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, '', $dohistory);
}
if ($mixed_checksum & pow(2, self::HARDWARE_FL)) {
self::updateDevices("Item_DeviceProcessor", $line['computers_id'], $line['ocsid'], $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, '', $dohistory);
}
if ($mixed_checksum & pow(2, self::VIDEOS_FL)) {
self::updateDevices("Item_DeviceGraphicCard", $line['computers_id'], $line['ocsid'], $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, '', $dohistory);
}
if ($mixed_checksum & pow(2, self::SOUNDS_FL)) {
self::updateDevices("Item_DeviceSoundCard", $line['computers_id'], $line['ocsid'], $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, '', $dohistory);
}
if ($mixed_checksum & pow(2, self::NETWORKS_FL)) {
//TODO import_ip ?
//$import_ip = importArrayFromDB($line["import_ip"]);
self::updateDevices("Item_DeviceNetworkCard", $line['computers_id'], $line['ocsid'], $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, array(), $dohistory);
}
if ($mixed_checksum & pow(2, self::MODEMS_FL) || $mixed_checksum & pow(2, self::PORTS_FL)) {
//.........這裏部分代碼省略.........
示例8: getItemtypesThatCanHave
/**
* Get all the types that can have an infocom
*
* @since version 0.85
*
* @return array of the itemtypes
**/
static function getItemtypesThatCanHave()
{
global $CFG_GLPI;
return array_merge($CFG_GLPI['infocom_types'], Item_Devices::getDeviceTypes());
}
示例9: array
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
* @since version 0.84
*/
include '../inc/includes.php';
if (isset($_POST['itemtype']) && isset($_POST["unlock"])) {
$itemtype = $_POST['itemtype'];
$source_item = new $itemtype();
if ($source_item->canCreate()) {
$source_item->check($_POST['id'], UPDATE);
$actions = array("Computer_Item", "Computer_SoftwareLicense", "Computer_SoftwareVersion", "ComputerDisk", "ComputerVirtualMachine", "NetworkPort", "NetworkName", "IPAddress");
$devices = Item_Devices::getDeviceTypes();
$actions = array_merge($actions, array_values($devices));
foreach ($actions as $type) {
if (isset($_POST[$type]) && count($_POST[$type])) {
$item = new $type();
foreach ($_POST[$type] as $key => $val) {
//Force unlock
$item->restore(array('id' => $key));
}
}
}
}
}
//Execute hook to unlock fields managed by a plugin, if needed
Plugin::doHookFunction('unlock_fields', $_POST);
Html::back();
示例10: simulateTransfer
/**
* simulate the transfer to know which items need to be transfer
*
* @param $items Array of the items to transfer
**/
function simulateTransfer($items)
{
global $DB, $CFG_GLPI;
// Init types :
$types = array('CartridgeItem', 'Change', 'Computer', 'ConsumableItem', 'Contact', 'Contract', 'Document', 'Link', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer', 'Problem', 'Software', 'SoftwareLicense', 'SoftwareVersion', 'Supplier', 'Ticket');
$types = array_merge($types, $CFG_GLPI['device_types']);
$types = array_merge($types, Item_Devices::getDeviceTypes());
foreach ($types as $t) {
if (!isset($this->needtobe_transfer[$t])) {
$this->needtobe_transfer[$t] = array();
}
if (!isset($this->noneedtobe_transfer[$t])) {
$this->noneedtobe_transfer[$t] = array();
}
$this->item_search[$t] = $this->createSearchConditionUsingArray($this->needtobe_transfer[$t]);
$this->item_recurs[$t] = $this->createSearchConditionUsingArray($this->noneedtobe_transfer[$t]);
}
$to_entity_ancestors = getAncestorsOf("glpi_entities", $this->to);
// Copy items to needtobe_transfer
foreach ($items as $key => $tab) {
if (count($tab)) {
foreach ($tab as $ID) {
$this->addToBeTransfer($key, $ID);
}
}
}
// Computer first
$this->item_search['Computer'] = $this->createSearchConditionUsingArray($this->needtobe_transfer['Computer']);
// DIRECT CONNECTIONS
$DC_CONNECT = array();
if ($this->options['keep_dc_monitor']) {
$DC_CONNECT[] = 'Monitor';
}
if ($this->options['keep_dc_phone']) {
$DC_CONNECT[] = 'Phone';
}
if ($this->options['keep_dc_peripheral']) {
$DC_CONNECT[] = 'Peripheral';
}
if ($this->options['keep_dc_printer']) {
$DC_CONNECT[] = 'Printer';
}
if (count($DC_CONNECT) && count($this->needtobe_transfer['Computer']) > 0) {
foreach ($DC_CONNECT as $itemtype) {
$itemtable = getTableForItemType($itemtype);
// Clean DB / Search unexisting links and force disconnect
$query = "SELECT `glpi_computers_items`.`id`\n FROM `glpi_computers_items`\n LEFT JOIN `{$itemtable}`\n ON (`glpi_computers_items`.`items_id` = `{$itemtable}`.`id` )\n WHERE `glpi_computers_items`.`itemtype` = '{$itemtype}'\n AND `{$itemtable}`.`id` IS NULL";
if ($result = $DB->query($query)) {
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_assoc($result)) {
$conn = new Computer_Item();
$conn->delete(array('id' => $data['id'], '_no_history' => true, '_no_auto_action' => true));
}
}
}
if (!($item = getItemForItemtype($itemtype))) {
continue;
}
$query = "SELECT DISTINCT `items_id`\n FROM `glpi_computers_items`\n WHERE `itemtype` = '{$itemtype}'\n AND `computers_id` IN " . $this->item_search['Computer'];
if ($result = $DB->query($query)) {
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_assoc($result)) {
if ($item->getFromDB($data['items_id']) && $item->isRecursive() && in_array($item->getEntityID(), $to_entity_ancestors)) {
$this->addNotToBeTransfer($itemtype, $data['items_id']);
} else {
$this->addToBeTransfer($itemtype, $data['items_id']);
}
}
}
}
$this->item_search[$itemtype] = $this->createSearchConditionUsingArray($this->needtobe_transfer[$itemtype]);
if ($item->maybeRecursive()) {
$this->item_recurs[$itemtype] = $this->createSearchConditionUsingArray($this->noneedtobe_transfer[$itemtype]);
}
}
}
// End of direct connections
// License / Software : keep / delete + clean unused / keep unused
if ($this->options['keep_software']) {
// Clean DB
$query = "SELECT DISTINCT `glpi_computers_softwareversions`.`computers_id`\n FROM `glpi_computers_softwareversions`\n WHERE `glpi_computers_softwareversions`.`computers_id`\n NOT IN (SELECT id FROM `glpi_computers`)";
if ($result = $DB->query($query)) {
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_assoc($result)) {
$query = "DELETE\n FROM `glpi_computers_softwareversions`\n WHERE `computers_id` = '" . $data['computers_id'] . "'";
$DB->query($query);
}
}
}
// Clean DB
$query = "SELECT DISTINCT `glpi_computers_softwareversions`.`softwareversions_id`\n FROM `glpi_computers_softwareversions`\n WHERE `glpi_computers_softwareversions`.`softwareversions_id`\n NOT IN (SELECT id FROM `glpi_softwareversions`)";
if ($result = $DB->query($query)) {
if ($DB->numrows($result) > 0) {
while ($data = $DB->fetch_assoc($result)) {
$query = "DELETE\n FROM `glpi_computers_softwareversions`\n WHERE `softwareversions_id` = '" . $data['softwareversions_id'] . "'";
//.........這裏部分代碼省略.........
示例11: plugin_ocsinventoryng_migrateComputerLocks
/**
* Move locks from ocslink.import_* to is_dynamic in related tables
*
* @param $migration
**/
function plugin_ocsinventoryng_migrateComputerLocks(Migration $migration)
{
global $DB;
$import = array('import_printer' => 'Printer', 'import_monitor' => 'Monitor', 'import_peripheral' => 'Peripheral');
foreach ($import as $field => $itemtype) {
foreach ($DB->request('ocs_glpi_ocslinks', '', array('computers_id', $field)) as $data) {
if (FieldExists('ocs_glpi_ocslinks', $field)) {
$import_field = importArrayFromDB($data[$field]);
//If array is not empty
if (!empty($import_field)) {
$query_update = "UPDATE `glpi_computers_items`\n SET `is_dynamic`='1'\n WHERE `id` IN (" . implode(',', array_keys($import_field)) . ")\n AND `itemtype`='{$itemtype}'";
$DB->query($query_update);
}
}
}
$migration->dropField('ocs_glpi_ocslinks', $field);
}
//Migration disks and vms
$import = array('import_disk' => 'glpi_computerdisks', 'import_vm' => 'glpi_computervirtualmachines', 'import_software' => 'glpi_computers_softwareversions', 'import_ip' => 'glpi_networkports');
foreach ($import as $field => $table) {
if (FieldExists('ocs_glpi_ocslinks', $field)) {
foreach ($DB->request('ocs_glpi_ocslinks', '', array('computers_id', $field)) as $data) {
$import_field = importArrayFromDB($data[$field]);
//If array is not empty
if (!empty($import_field)) {
$in_where = "(" . implode(',', array_keys($import_field)) . ")";
$query_update = "UPDATE `{$table}`\n SET `is_dynamic`='1'\n WHERE `id` IN {$in_where}";
$DB->query($query_update);
if ($table == 'glpi_networkports') {
$query_update = "UPDATE `glpi_networkports` AS PORT,\n `glpi_networknames` AS NAME\n SET NAME.`is_dynamic` = 1\n WHERE PORT.`id` IN {$in_where}\n AND NAME.`itemtype` = 'NetworkPort'\n AND NAME.`items_id` = PORT.`id`";
$DB->query($query_update);
$query_update = "UPDATE `glpi_networkports` AS PORT,\n `glpi_networknames` AS NAME,\n `glpi_ipaddresses` AS ADDR\n SET ADDR.`is_dynamic` = 1\n WHERE PORT.`id` IN {$in_where}\n AND NAME.`itemtype` = 'NetworkPort'\n AND NAME.`items_id` = PORT.`id`\n AND ADDR.`itemtype` = 'NetworkName'\n AND ADDR.`items_id` = NAME.`id`";
$DB->query($query_update);
}
}
}
$migration->dropField('ocs_glpi_ocslinks', $field);
}
}
if (FieldExists('ocs_glpi_ocslinks', 'import_device')) {
foreach ($DB->request('ocs_glpi_ocslinks', '', array('computers_id', 'import_device')) as $data) {
$import_device = importArrayFromDB($data['import_device']);
if (!in_array('_version_078_', $import_device)) {
$import_device = plugin_ocsinventoryng_migrateImportDevice($import_device);
}
$devices = array();
$types = Item_Devices::getDeviceTypes();
foreach ($import_device as $key => $val) {
if (!$key) {
// OcsServer::IMPORT_TAG_078
continue;
}
list($type, $nomdev) = explode('$$$$$', $val);
list($type, $iddev) = explode('$$$$$', $key);
if (!isset($types[$type])) {
// should never happen
continue;
}
$devices[$types[$type]][] = $iddev;
}
foreach ($devices as $type => $data) {
//If array is not empty
$query_update = "UPDATE `" . getTableForItemType($type) . "`\n SET `is_dynamic`='1'\n WHERE `id` IN (" . implode(',', $data) . ")";
$DB->query($query_update);
}
}
$migration->dropField('ocs_glpi_ocslinks', 'import_device');
}
$migration->migrationOneTable('ocs_glpi_ocslinks');
}
示例12: doMassiveActions
//.........這裏部分代碼省略.........
foreach ($input["item"] as $key => $val) {
if (isset($input['items_id'])) {
// Add items to contracts
$input = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'contracts_id' => $key);
}
if (isset($input['contracts_id'])) {
// Add contract to item
$input = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'contracts_id' => $input['contracts_id']);
} else {
return false;
}
if ($contractitem->can(-1, 'w', $input)) {
if ($contractitem->add($input)) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
break;
case "remove_contract_item":
foreach ($input["item"] as $key => $val) {
if (isset($input['items_id'])) {
// Remove item to contracts
$input = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'contracts_id' => $key);
} else {
// Remove contract to items
$input = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'contracts_id' => $input['contracts_id']);
}
$contractitem = new Contract_Item();
if ($contractitem->can(-1, 'w', $input)) {
if ($item = getItemForItemtype($input["itemtype"])) {
if ($item->getFromDB($input['items_id'])) {
$contract = new Contract();
if ($contract->getFromDB($input['contracts_id'])) {
if ($contractitem->getFromDBForItems($contract, $item)) {
if ($contractitem->delete(array('id' => $contractitem->getID()))) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['ko']++;
}
} else {
$res['ko']++;
}
} else {
$res['ko']++;
}
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
break;
//Lock management
//Lock management
case 'unlock_Printer':
case 'unlock_Monitor':
case 'unlock_NetworkPort':
case 'unlock_NetworkName':
case 'unlock_IPAddress':
case 'unlock_ComputerDisk':
case 'unlock_ComputerVirtualMachine':
case 'unlock_Peripheral':
case 'unlock_SoftwareVersion':
$itemtype = Lock::getItemTypeForMassiveAction($input["action"]);
if ($itemtype) {
$res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]);
}
break;
case 'unlock_Device':
foreach (Item_Devices::getDeviceTypes() as $itemtype) {
$res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]);
}
break;
default:
// Plugin specific actions
$split = explode('_', $input["action"]);
$res = '';
if ($split[0] == 'plugin' && isset($split[1])) {
// Normalized name plugin_name_action
// Allow hook from any plugin on any (core or plugin) type
$res = Plugin::doOneHook($split[1], 'MassiveActionsProcess', $input);
// } else if ($plug=isPluginItemType($input["itemtype"])) {
// non-normalized name
// hook from the plugin defining the type
// $res = Plugin::doOneHook($plug['plugin'], 'MassiveActionsProcess', $input);
} else {
$res = $this->doSpecificMassiveActions($input);
}
break;
}
return $res;
}
示例13: resetOCSLocks
static function resetOCSLocks($objectId, $entities)
{
global $DB;
$res = array('ok' => 0, 'ko' => 0);
$object = new $objectId();
$objecttable = getTableForItemType($objectId);
$restrict = "";
if ($object->maybeTemplate()) {
$restrict = "`is_template` = '0'";
}
if ($object->isEntityAssign() && $entities != -1) {
$restrict .= getEntitiesRestrictRequest(" AND ", $objecttable, '', $entities, $object->maybeRecursive());
}
$count = countElementsInTable($objecttable, $restrict);
$items = getAllDatasFromTable($objecttable, $restrict);
$computers = array();
if (!empty($items)) {
echo "<div class='center'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_2'><td>";
Html::createProgressBar(__('Work in progress...'));
echo "</td></tr></table></div></br>\n";
$i = 0;
foreach ($items as $item) {
//Fields
if (PluginOcsinventoryngOcsServer::deleteInOcsArray($item['id'], 'all', "computer_update", true)) {
$res['ok']++;
}
$i++;
$computers[$item['id']] = 1;
Html::changeProgressBarPosition($i, $count);
}
foreach (Item_Devices::getDeviceTypes() as $itemtype) {
$res[] = Lock::unlockItems($itemtype, 'Computer', $computers);
}
$res[] = Lock::unlockItems('Monitor', 'Monitor', $computers);
$res[] = Lock::unlockItems('Printer', 'Printer', $computers);
$res[] = Lock::unlockItems('Peripheral', 'Peripheral', $computers);
$res[] = Lock::unlockItems('SoftwareVersion', 'SoftwareVersion', $computers);
$res[] = Lock::unlockItems('NetworkPort', 'Computer', $computers);
$res[] = Lock::unlockItems('NetworkName', 'NetworkPort', $computers);
$res[] = Lock::unlockItems('IPAddress', 'NetworkName', $computers);
$res[] = Lock::unlockItems('ComputerDisk', 'ComputerDisk', $computers);
$res[] = Lock::unlockItems('ComputerVirtualMachine', 'ComputerVirtualMachine', $computers);
Html::changeProgressBarPosition($i, $count, __('Task completed.'));
}
return $res;
}