/**
  * 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;
 }