function post_updateItem($history = 1) { global $DB, $LANG, $CFG_GLPI; // Manage changes for OCS if more than 1 element (date_mod) // Need dohistory==1 if dohistory==2 no locking fields if ($this->fields["is_ocs_import"] && $history == 1 && count($this->updates) > 1) { OcsServer::mergeOcsArray($this->fields["id"], $this->updates, "computer_update"); } if (isset($this->input["_auto_update_ocs"])) { $query = "UPDATE `glpi_ocslinks`\n SET `use_auto_update` = '" . $this->input["_auto_update_ocs"] . "'\n WHERE `computers_id` = '" . $this->input["id"] . "'"; $DB->query($query); } for ($i = 0; $i < count($this->updates); $i++) { // Update contact of attached items if (($this->updates[$i] == "contact" || $this->updates[$i] == "contact_num") && $CFG_GLPI["is_contact_autoupdate"]) { $items = array('Monitor', 'Peripheral', 'Phone', 'Printer'); $update_done = false; $updates3[0] = "contact"; $updates3[1] = "contact_num"; foreach ($items as $t) { $query = "SELECT *\n FROM `glpi_computers_items`\n WHERE `computers_id` = '" . $this->fields["id"] . "'\n AND `itemtype` = '" . $t . "'"; if ($result = $DB->query($query)) { $resultnum = $DB->numrows($result); $item = new $t(); if ($resultnum > 0) { for ($j = 0; $j < $resultnum; $j++) { $tID = $DB->result($result, $j, "items_id"); $item->getFromDB($tID); if (!$item->getField('is_global')) { if ($item->getField('contact') != $this->fields['contact'] || $item->getField('contact_num') != $this->fields['contact_num']) { $tmp["id"] = $item->getField('id'); $tmp['contact'] = $this->fields['contact']; $tmp['contact_num'] = $this->fields['contact_num']; $item->update($tmp); $update_done = true; } } } } } } if ($update_done) { addMessageAfterRedirect($LANG['computers'][49], true); } } // Update users and groups of attached items if ($this->updates[$i] == "users_id" && $this->fields["users_id"] != 0 && $CFG_GLPI["is_user_autoupdate"] || $this->updates[$i] == "groups_id" && $this->fields["groups_id"] != 0 && $CFG_GLPI["is_group_autoupdate"]) { $items = array('Monitor', 'Peripheral', 'Phone', 'Printer'); $update_done = false; $updates4[0] = "users_id"; $updates4[1] = "groups_id"; foreach ($items as $t) { $query = "SELECT *\n FROM `glpi_computers_items`\n WHERE `computers_id` = '" . $this->fields["id"] . "'\n AND `itemtype` = '" . $t . "'"; if ($result = $DB->query($query)) { $resultnum = $DB->numrows($result); $item = new $t(); if ($resultnum > 0) { for ($j = 0; $j < $resultnum; $j++) { $tID = $DB->result($result, $j, "items_id"); $item->getFromDB($tID); if (!$item->getField('is_global')) { if ($item->getField('users_id') != $this->fields["users_id"] || $item->getField('groups_id') != $this->fields["groups_id"]) { $tmp["id"] = $item->getField('id'); if ($CFG_GLPI["is_user_autoupdate"]) { $tmp["users_id"] = $this->fields["users_id"]; } if ($CFG_GLPI["is_group_autoupdate"]) { $tmp["groups_id"] = $this->fields["groups_id"]; } $item->update($tmp); $update_done = true; } } } } } } if ($update_done) { addMessageAfterRedirect($LANG['computers'][50], true); } } // Update state of attached items if ($this->updates[$i] == "states_id" && $CFG_GLPI["state_autoupdate_mode"] < 0) { $items = array('Monitor', 'Peripheral', 'Phone', 'Printer'); $update_done = false; foreach ($items as $t) { $query = "SELECT *\n FROM `glpi_computers_items`\n WHERE `computers_id` = '" . $this->fields["id"] . "'\n AND `itemtype` = '" . $t . "'"; if ($result = $DB->query($query)) { $resultnum = $DB->numrows($result); $item = new $t(); if ($resultnum > 0) { for ($j = 0; $j < $resultnum; $j++) { $tID = $DB->result($result, $j, "items_id"); $item->getFromDB($tID); if (!$item->getField('is_global')) { if ($item->getField('states_id') != $this->fields["states_id"]) { $tmp["id"] = $item->getField('id'); $tmp["states_id"] = $this->fields["states_id"]; $item->update($tmp); $update_done = true; } } } } } } if ($update_done) { addMessageAfterRedirect($LANG['computers'][56], true); } } // Update loction of attached items if ($this->updates[$i] == "locations_id" && $this->fields["locations_id"] != 0 && $CFG_GLPI["is_location_autoupdate"]) { $items = array('Monitor', 'Peripheral', 'Phone', 'Printer'); $update_done = false; $updates2[0] = "locations_id"; foreach ($items as $t) { $query = "SELECT *\n FROM `glpi_computers_items`\n WHERE `computers_id` = '" . $this->fields["id"] . "'\n AND `itemtype` = '" . $t . "'"; if ($result = $DB->query($query)) { $resultnum = $DB->numrows($result); $item = new $t(); if ($resultnum > 0) { for ($j = 0; $j < $resultnum; $j++) { $tID = $DB->result($result, $j, "items_id"); $item->getFromDB($tID); if (!$item->getField('is_global')) { if ($item->getField('locations_id') != $this->fields["locations_id"]) { $tmp["id"] = $item->getField('id'); $tmp["locations_id"] = $this->fields["locations_id"]; $item->update($tmp); $update_done = true; } } } } } } if ($update_done) { addMessageAfterRedirect($LANG['computers'][48], true); } } } }