/** * Prepare input datas for adding the relation * * Overloaded to check is Disconnect needed (during OCS sync) * and to manage autoupdate feature * *@param $input datas used to add the item * *@return the modified $input array * **/ function prepareInputForAdd($input) { global $DB, $CFG_GLPI, $LANG; switch ($input['itemtype']) { case 'Monitor': $item = new Monitor(); $ocstab = 'import_monitor'; break; case 'Phone': // shoul really never occurs as OCS doesn't sync phone $item = new Phone(); $ocstab = ''; break; case 'Printer': $item = new Printer(); $ocstab = 'import_printer'; break; case 'Peripheral': $item = new Peripheral(); $ocstab = 'import_peripheral'; break; default: return false; } if (!$item->getFromDB($input['items_id'])) { return false; } if (!$item->getField('is_global')) { // Handle case where already used, should never happen (except from OCS sync) $query = "SELECT `id`, `computers_id`\n FROM `glpi_computers_items`\n WHERE `glpi_computers_items`.`items_id` = '" . $input['items_id'] . "'\n AND `glpi_computers_items`.`itemtype` = '" . $input['itemtype'] . "'"; $result = $DB->query($query); while ($data = $DB->fetch_assoc($result)) { $temp = clone $this; $temp->delete($data); if ($ocstab) { OcsServer::deleteInOcsArray($data["computers_id"], $data["id"], $ocstab); } } // Autoupdate some fields - should be in post_addItem (here to avoid more DB access) $comp = new Computer(); if ($comp->getFromDB($input['computers_id'])) { $updates = array(); if ($CFG_GLPI["is_location_autoupdate"] && $comp->fields['locations_id'] != $item->getField('locations_id')) { $updates['locations_id'] = addslashes($comp->fields['locations_id']); addMessageAfterRedirect($LANG['computers'][48], true); } if ($CFG_GLPI["is_user_autoupdate"] && $comp->fields['users_id'] != $item->getField('users_id') || $CFG_GLPI["is_group_autoupdate"] && $comp->fields['groups_id'] != $item->getField('groups_id')) { if ($CFG_GLPI["is_user_autoupdate"]) { $updates['users_id'] = $comp->fields['users_id']; } if ($CFG_GLPI["is_group_autoupdate"]) { $updates['groups_id'] = $comp->fields['groups_id']; } addMessageAfterRedirect($LANG['computers'][50], true); } if ($CFG_GLPI["is_contact_autoupdate"] && ($comp->fields['contact'] != $item->getField('contact') || $comp->fields['contact_num'] != $item->getField('contact_num'))) { $updates['contact'] = addslashes($comp->fields['contact']); $updates['contact_num'] = addslashes($comp->fields['contact_num']); addMessageAfterRedirect($LANG['computers'][49], true); } if ($CFG_GLPI["state_autoupdate_mode"] < 0 && $comp->fields['states_id'] != $item->getField('states_id')) { $updates['states_id'] = $comp->fields['states_id']; addMessageAfterRedirect($LANG['computers'][56], true); } if ($CFG_GLPI["state_autoupdate_mode"] > 0 && $item->getField('states_id') != $CFG_GLPI["state_autoupdate_mode"]) { $updates['states_id'] = $CFG_GLPI["state_autoupdate_mode"]; } if (count($updates)) { $updates['id'] = $input['items_id']; $item->update($updates); } } } return $input; }
foreach ($_POST["item"] as $key => $val) { if ($val == 1) { $ids[] = $key; } } User::changeAuthMethod($ids, $_POST["authtype"], $_POST["auths_id"]); break; case "unlock_ocsng_field": $fields = OcsServer::getLockableFields(); if ($_POST['field'] == 'all' || isset($fields[$_POST['field']])) { foreach ($_POST["item"] as $key => $val) { if ($val == 1) { if ($_POST['field'] == 'all') { OcsServer::replaceOcsArray($key, array(), "computer_update"); } else { OcsServer::deleteInOcsArray($key, $_POST['field'], "computer_update", true); } } } } break; case "unlock_ocsng_monitor": case "unlock_ocsng_printer": case "unlock_ocsng_peripheral": case "unlock_ocsng_software": case "unlock_ocsng_ip": case "unlock_ocsng_disk": foreach ($_POST["item"] as $key => $val) { if ($val == 1) { switch ($_POST["action"]) { case "unlock_ocsng_monitor":
glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["unlock_ip"])) { $computer->check($_POST['id'], 'w'); if (isset($_POST["lockip"]) && count($_POST["lockip"])) { foreach ($_POST["lockip"] as $key => $val) { OcsServer::deleteInOcsArray($_POST["id"], $key, "import_ip"); } } glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["unlock_field"])) { $computer->check($_POST['id'], 'w'); if (isset($_POST["lockfield"]) && count($_POST["lockfield"])) { foreach ($_POST["lockfield"] as $key => $val) { OcsServer::deleteInOcsArray($_POST["id"], $key, "computer_update"); } } glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["force_ocs_resynch"])) { $computer->check($_POST['id'], 'w'); //Get the ocs server id associated with the machine $ocsservers_id = OcsServer::getByMachineID($_POST["id"]); //Update the computer OcsServer::updateComputer($_POST["resynch_id"], $ocsservers_id, 1, 1); glpi_header($_SERVER['HTTP_REFERER']); } else { //print computer informations commonHeader($LANG['Menu'][0], $_SERVER['PHP_SELF'], "inventory", "computer"); //show computer form to add