function post_updateItem($history = 1) { global $DB, $CFG_GLPI; $changes = []; for ($i = 0; $i < count($this->updates); $i++) { // Update contact of attached items if ($this->updates[$i] == 'contact_num' && $CFG_GLPI['is_contact_autoupdate']) { $changes['contact_num'] = $this->fields['contact_num']; } if ($this->updates[$i] == 'contact' && $CFG_GLPI['is_contact_autoupdate']) { $changes['contact'] = $this->fields['contact']; } // Update users and groups of attached items if ($this->updates[$i] == 'users_id' && $this->fields['users_id'] && $CFG_GLPI['is_user_autoupdate']) { $changes['users_id'] = $this->fields['users_id']; } if ($this->updates[$i] == 'groups_id' && $this->fields['groups_id'] && $CFG_GLPI['is_group_autoupdate']) { $changes['groups_id'] = $this->fields['groups_id']; } // Update state of attached items if ($this->updates[$i] == 'states_id' && $CFG_GLPI['state_autoupdate_mode'] < 0) { $changes['states_id'] = $this->fields['states_id']; } // Update loction of attached items if ($this->updates[$i] == 'locations_id' && $this->fields['locations_id'] && $CFG_GLPI['is_location_autoupdate']) { $changes['locations_id'] = $this->fields['locations_id']; } } // Propagates the changes to linked item if (count($changes)) { $update_done = false; foreach (['Monitor', 'Peripheral', 'Phone', 'Printer'] as $t) { $crit = ['FIELDS' => ['items_id'], 'itemtype' => $t, 'computers_id' => $this->fields["id"], 'is_deleted' => 0]; $item = new $t(); foreach ($DB->request('glpi_computers_items', $crit) as $data) { $tID = $data['items_id']; $item->getFromDB($tID); if (!$item->getField('is_global')) { $changes['id'] = $item->getField('id'); if ($item->update($changes)) { $update_done = true; } } } } if ($update_done) { if (isset($changes['contact']) || isset($changes['contact_num'])) { Session::addMessageAfterRedirect(__('Alternate username updated. The connected items have been updated using this alternate username.'), true); } if (isset($changes['groups_id']) || isset($changes['users_id'])) { Session::addMessageAfterRedirect(__('User or group updated. The connected items have been moved in the same values.'), true); } if (isset($changes['states_id'])) { Session::addMessageAfterRedirect(__('Status updated. The connected items have been updated using this status.'), true); } if (isset($changes['locations_id'])) { Session::addMessageAfterRedirect(__('Location updated. The connected items have been moved in the same location.'), true); } } } }