/**
  * Link inventory object to another one
  *
  * @param $params    the input parameters
  * @param $protocol  the commonication protocol used
  *
  **/
 static function methodLinkObjects($params, $protocol)
 {
     global $CFG_GLPI;
     if (isset($params['help'])) {
         return array('fields' => 'array, mandatory', 'help' => 'bool, optional');
     }
     if (!Session::getLoginUserID()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     //Must be superadmin to use this method
     if (!Session::haveRight('config', UPDATE)) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
     }
     if (!isset($params['fields']) || empty($params['fields']) || !is_array($params['fields'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'fields');
     }
     if (!isset($_SESSION["glpi_currenttime"])) {
         $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     }
     $resp = array();
     $errors = array();
     foreach ($params['fields'] as $links) {
         if (!in_array($links['from_item']['itemtype'], array('Computer')) && !preg_match("/Device/", $links['from_item']['itemtype'])) {
             $errors[] = self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', self::getDisplayError());
         }
         switch ($links['from_item']['itemtype']) {
             case 'Computer':
                 // Direct connections
                 if (in_array($links['to_item']['itemtype'], array('Monitor', 'Peripheral', 'Phone', 'Printer'))) {
                     $comp_item = new Computer_Item();
                     $data = array();
                     $data['items_id'] = $links['to_item']['id'];
                     $data['computers_id'] = $links['from_item']['id'];
                     $data['itemtype'] = $links['to_item']['itemtype'];
                     if (!$comp_item->can(-1, UPDATE, $data)) {
                         $errors[] = self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', self::getDisplayError());
                     } else {
                         if ($comp_item->add($data)) {
                             $resp['Computer'][$data['computers_id']] = self::methodGetObject(array('itemtype' => 'Computer', 'id' => $data['computers_id'], 'with_printer' => 1, 'with_monitor' => 1, 'with_phone' => 1, 'with_peripheral' => 1), $protocol);
                         } else {
                             $errors[] = self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
                         }
                     }
                 }
                 // Device connection
                 if (preg_match("/Device/", $links['to_item']['itemtype'])) {
                     $comp_device = new Computer_Device();
                     $links_field = getPlural(strtolower($links['to_item']['itemtype'])) . "_id";
                     $data = array();
                     $data['computers_id'] = $links['from_item']['id'];
                     $data[$links_field] = $links['to_item']['id'];
                     $data['itemtype'] = $links['to_item']['itemtype'];
                     if (!isset($links['to_item']['quantity']) || !is_numeric($links['to_item']['quantity'])) {
                         $quantity = 1;
                     } else {
                         $quantity = $links['to_item']['quantity'];
                     }
                     if (isset($links['to_item']['specificity'])) {
                         if (!is_numeric($links['to_item']['specificity'])) {
                             $errors[] = self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'specificity');
                         } else {
                             $data['specificity'] = $links['to_item']['specificity'];
                         }
                     }
                     $linked = false;
                     for ($i = 0; $i < $quantity; $i++) {
                         if (!$comp_device->can(-1, UPDATE, $data)) {
                             $errors[] = self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', self::getDisplayError());
                         } else {
                             if ($comp_device->add($data)) {
                                 $linked = true;
                             }
                         }
                     }
                     if ($linked) {
                         $resp['Computer'][$data['computers_id']] = self::methodGetObject(array('itemtype' => 'Computer', 'id' => $data['computers_id']), $protocol);
                     } else {
                         $errors[] = self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
                     }
                 }
                 //other link object
                 break;
                 //itemtype
         }
     }
     if (count($errors)) {
         $resp = array($resp, $errors);
     }
     return $resp;
 }
 function cleanDBonPurge()
 {
     $compdev = new Computer_Device();
     $compdev->cleanDBonItemDelete($this->getType(), $this->fields['id']);
 }
Exemplo n.º 3
0
 function cleanDBonPurge()
 {
     global $DB;
     $query = "DELETE\n                FROM `glpi_computers_softwareversions`\n                WHERE `computers_id` = '" . $this->fields['id'] . "'";
     $result = $DB->query($query);
     $query = "SELECT `id`\n                FROM `glpi_computers_items`\n                WHERE `computers_id` = '" . $this->fields['id'] . "'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) > 0) {
             $conn = new Computer_Item();
             while ($data = $DB->fetch_array($result)) {
                 $data['_no_auto_action'] = true;
                 $conn->delete($data);
             }
         }
     }
     $query = "DELETE\n                FROM `glpi_registrykeys`\n                WHERE `computers_id` = '" . $this->fields['id'] . "'";
     $result = $DB->query($query);
     $compdev = new Computer_Device();
     $compdev->cleanDBonItemDelete('Computer', $this->fields['id']);
     $query = "DELETE\n                FROM `glpi_ocslinks`\n                WHERE `computers_id` = '" . $this->fields['id'] . "'";
     $result = $DB->query($query);
     $disk = new ComputerDisk();
     $disk->cleanDBonItemDelete('Computer', $this->fields['id']);
     $vm = new ComputerVirtualMachine();
     $vm->cleanDBonItemDelete('Computer', $this->fields['id']);
 }
Exemplo n.º 4
0
            case 10:
                showNotesForm($_POST['target'], 'Computer', $_POST["id"]);
                break;
            case 11:
                Reservation::showForItem('Computer', $_POST["id"]);
                break;
            case 12:
                Log::showForItem($computer);
                break;
            case 13:
                OcsLink::showForItem($computer);
                OcsServer::editLock($_POST['target'], $_POST["id"]);
                break;
            case 14:
                RegistryKey::showForComputer($_POST["id"]);
                break;
            case 20:
                ComputerDisk::showForComputer($computer);
                break;
            case 21:
                ComputerVirtualMachine::showForVirtualMachine($computer);
                ComputerVirtualMachine::showForComputer($computer);
                break;
            default:
                if (!Plugin::displayAction($computer, $_REQUEST['glpi_tab'])) {
                    Computer_Device::showForComputer($computer);
                }
        }
    }
}
ajaxFooter();
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file: Remi Collet
// Purpose of file:
// ----------------------------------------------------------------------
define('GLPI_ROOT', '..');
include GLPI_ROOT . "/inc/includes.php";
$compdev = new Computer_Device();
if (isset($_POST["add"])) {
    $compdev->check(-1, 'w', $_POST);
    $compdev->add($_POST);
    glpi_header($_SERVER['HTTP_REFERER']);
} else {
    if (isset($_POST["updateall"])) {
        $compdev->check(-1, 'w', $_POST);
        $compdev->updateAll($_POST);
        Event::log($_POST["computers_id"], "computers", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][28]);
        glpi_header($_SERVER['HTTP_REFERER']);
    }
}
displayErrorAndDie('Lost');
Exemplo n.º 6
0
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI, $LANG;
     if (!isset($options['several'])) {
         $options['several'] = false;
     }
     if (!haveRight("networking", "r")) {
         return false;
     }
     if ($ID > 0) {
         $this->check($ID, 'r');
     } else {
         $input = array('itemtype' => $options["itemtype"], 'items_id' => $options["items_id"]);
         // Create item
         $this->check(-1, 'w', $input);
     }
     $type = $this->fields['itemtype'];
     $link = NOT_AVAILABLE;
     if (class_exists($this->fields['itemtype'])) {
         $item = new $this->fields['itemtype']();
         $type = $item->getTypeName();
         if ($item->getFromDB($this->fields["items_id"])) {
             $link = $item->getLink();
         } else {
             return false;
         }
     } else {
         // item is mandatory (for entity)
         return false;
     }
     // Ajout des infos deja remplies
     if (isset($_POST) && !empty($_POST)) {
         foreach ($netport->fields as $key => $val) {
             if ($key != 'id' && isset($_POST[$key])) {
                 $netport->fields[$key] = $_POST[$key];
             }
         }
     }
     $this->showTabs($ID);
     $options['entities_id'] = $item->getField('entities_id');
     $this->showFormHeader($options);
     $show_computer_mac = false;
     if ((!empty($this->fields['itemtype']) || !$options['several']) && $this->fields['itemtype'] == 'Computer') {
         $show_computer_mac = true;
     }
     echo "<tr class='tab_bg_1'><td>{$type}&nbsp;:</td>\n<td>";
     if (!($ID > 0)) {
         echo "<input type='hidden' name='items_id' value='" . $this->fields["items_id"] . "'>\n";
         echo "<input type='hidden' name='itemtype' value='" . $this->fields["itemtype"] . "'>\n";
     }
     echo $link . "</td>\n";
     $colspan = 9;
     if ($show_computer_mac) {
         $colspan += 2;
     }
     if (!$options['several']) {
         $colspan++;
     }
     echo "<td rowspan='{$colspan}'>" . $LANG['common'][25] . "&nbsp;:</td>";
     echo "<td rowspan='{$colspan}' class='middle'>";
     echo "<textarea cols='45' rows='11' name='comment' >" . $this->fields["comment"] . "</textarea>";
     echo "</td></tr>\n";
     if (!$options['several']) {
         echo "<tr class='tab_bg_1'><td>" . $LANG['networking'][21] . "&nbsp;:</td>\n";
         echo "<td>";
         autocompletionTextField($this, "logical_number", array('size' => 5));
         echo "</td></tr>\n";
     } else {
         echo "<tr class='tab_bg_1'><td>" . $LANG['networking'][21] . "&nbsp;:</td>\n";
         echo "<td>";
         echo "<input type='hidden' name='several' value='yes'>";
         echo "<input type='hidden' name='logical_number' value=''>\n";
         echo $LANG['networking'][47] . "&nbsp;:&nbsp;";
         Dropdown::showInteger('from_logical_number', 0, 0, 100);
         echo "&nbsp;" . $LANG['networking'][48] . "&nbsp;:&nbsp;";
         Dropdown::showInteger('to_logical_number', 0, 0, 100);
         echo "</td></tr>\n";
     }
     echo "<tr class='tab_bg_1'><td>" . $LANG['common'][16] . "&nbsp;:</td>\n";
     echo "<td>";
     autocompletionTextField($this, "name");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['common'][65] . "&nbsp;:</td>\n<td>";
     Dropdown::show('NetworkInterface', array('value' => $this->fields["networkinterfaces_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['networking'][14] . "&nbsp;:</td>\n<td>";
     autocompletionTextField($this, "ip");
     echo "</td></tr>\n";
     // Show device MAC adresses
     if ($show_computer_mac) {
         $comp = new Computer();
         $comp->getFromDB($this->fields['items_id']);
         $macs = Computer_Device::getMacAddr($comp);
         if (count($macs) > 0) {
             echo "<tr class='tab_bg_1'><td>" . $LANG['networking'][15] . "&nbsp;:</td>\n<td>";
             echo "<select name='pre_mac'>\n";
             echo "<option value=''>" . DROPDOWN_EMPTY_VALUE . "</option>\n";
             foreach ($macs as $key => $val) {
                 echo "<option value='" . $val . "' >{$val}</option>\n";
             }
             echo "</select></td></tr>\n";
             echo "<tr class='tab_bg_2'>";
             echo "<td colspan='2' class='center'>" . $LANG['networking'][57];
             echo "</td></tr>\n";
         }
     }
     echo "<tr class='tab_bg_1'><td>" . $LANG['networking'][15] . "&nbsp;:</td>\n<td>";
     autocompletionTextField($this, "mac");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['networking'][60] . "&nbsp;:</td>\n<td>";
     autocompletionTextField($this, "netmask");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['networking'][59] . "&nbsp;:</td>\n<td>";
     autocompletionTextField($this, "gateway");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'><td>" . $LANG['networking'][61] . "&nbsp;:</td>\n<td>";
     autocompletionTextField($this, "subnet");
     echo "</td></tr>\n";
     if (!$options['several']) {
         echo "<tr class='tab_bg_1'><td>" . $LANG['networking'][51] . "&nbsp;:</td>\n";
         echo "<td>";
         Netpoint::dropdownNetpoint("netpoints_id", $this->fields["netpoints_id"], $item->fields['locations_id'], 1, $item->getEntityID(), $this->fields["itemtype"]);
         echo "</td></tr>\n";
     }
     $this->showFormButtons($options);
     $this->addDivForTabs();
 }
Exemplo n.º 7
0
 /**
  * Import the devices for a computer
  *
  * @param $devicetype integer : device type
  * @param $computers_id integer : glpi computer id.
  * @param $ocsid integer : ocs computer id (ID).
  * @param $ocsservers_id integer : ocs server id
  * @param $cfg_ocs array : ocs config
  * @param $import_device array : already imported devices
  * @param $import_ip array : already imported ip
  * @param $dohistory boolean : log changes ?
  *
  * @return Nothing (void).
  **/
 static function updateDevices($devicetype, $computers_id, $ocsid, $ocsservers_id, $cfg_ocs, $import_device, $import_ip, $dohistory)
 {
     global $DBocs, $DB;
     $prevalue = $devicetype . self::FIELD_SEPARATOR;
     self::checkOCSconnection($ocsservers_id);
     $types = Computer_Device::getDeviceTypes();
     $CompDevice = new Computer_Device($types[$devicetype]);
     $do_clean = false;
     switch ($devicetype) {
         case self::RAM_DEVICE:
             //Memoire
             if ($cfg_ocs["import_device_memory"]) {
                 $do_clean = true;
                 $query2 = "SELECT *\n                          FROM `memories`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 if ($DBocs->numrows($result2) > 0) {
                     // Drop all memories and force no history
                     if (!in_array(self::IMPORT_TAG_078, $import_device)) {
                         self::addToOcsArray($computers_id, array(0 => self::IMPORT_TAG_078), "import_device");
                         // Clean memories for this computer
                         if (count($import_device)) {
                             $dohistory = false;
                             foreach ($import_device as $key => $val) {
                                 $tmp = explode(self::FIELD_SEPARATOR, $key);
                                 if (isset($tmp[1]) && $tmp[0] == self::RAM_DEVICE) {
                                     $CompDevice->delete(array('id' => $tmp[1], '_no_history' => true, '_itemtype' => 'DeviceMemory'));
                                     self::deleteInOcsArray($computers_id, $key, "import_device");
                                     unset($import_device[$key]);
                                 }
                             }
                         }
                     }
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         if (!empty($line2["CAPACITY"]) && $line2["CAPACITY"] != "No") {
                             $ram["designation"] = "";
                             if ($line2["TYPE"] != "Empty Slot" && $line2["TYPE"] != "Unknown") {
                                 $ram["designation"] = $line2["TYPE"];
                             }
                             if ($line2["DESCRIPTION"]) {
                                 if (!empty($ram["designation"])) {
                                     $ram["designation"] .= " - ";
                                 }
                                 $ram["designation"] .= $line2["DESCRIPTION"];
                             }
                             if (!is_numeric($line2["CAPACITY"])) {
                                 $line2["CAPACITY"] = 0;
                             }
                             $ram["specif_default"] = $line2["CAPACITY"];
                             if (!in_array(stripslashes($prevalue . $ram["designation"]), $import_device)) {
                                 $ram["frequence"] = $line2["SPEED"];
                                 $ram["devicememorytypes_id"] = Dropdown::importExternal('DeviceMemoryType', $line2["TYPE"]);
                                 $DeviceMemory = new DeviceMemory();
                                 $ram_id = $DeviceMemory->import($ram);
                                 if ($ram_id) {
                                     $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DeviceMemory', 'devicememories_id' => $ram_id, 'specificity' => $line2["CAPACITY"], '_no_history' => !$dohistory));
                                     self::addToOcsArray($computers_id, array($prevalue . $devID => $prevalue . $ram["designation"]), "import_device");
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $ram["designation"]), $import_device);
                                 list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                                 $CompDevice->update(array('id' => $id, 'specificity' => $line2["CAPACITY"], '_itemtype' => 'DeviceMemory'));
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case self::HDD_DEVICE:
             //Disque Dur
             if ($cfg_ocs["import_device_hdd"]) {
                 $do_clean = true;
                 $query2 = "SELECT *\n                          FROM `storages`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 if ($DBocs->numrows($result2) > 0) {
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         if (!empty($line2["DISKSIZE"]) && preg_match("/disk|spare\\sdrive/i", $line2["TYPE"])) {
                             if ($line2["NAME"]) {
                                 $dd["designation"] = $line2["NAME"];
                             } else {
                                 if ($line2["MODEL"]) {
                                     $dd["designation"] = $line2["MODEL"];
                                 } else {
                                     $dd["designation"] = "Unknown";
                                 }
                             }
                             if (!is_numeric($line2["DISKSIZE"])) {
                                 $line2["DISKSIZE"] = 0;
                             }
                             if (!in_array(stripslashes($prevalue . $dd["designation"]), $import_device)) {
                                 $dd["specif_default"] = $line2["DISKSIZE"];
                                 $DeviceHardDrive = new DeviceHardDrive();
                                 $dd_id = $DeviceHardDrive->import($dd);
                                 if ($dd_id) {
                                     $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DeviceHardDrive', 'deviceharddrives_id' => $dd_id, 'specificity' => $line2["DISKSIZE"], '_no_history' => !$dohistory));
                                     self::addToOcsArray($computers_id, array($prevalue . $devID => $prevalue . $dd["designation"]), "import_device");
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $dd["designation"]), $import_device);
                                 list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                                 $CompDevice->update(array('id' => $id, 'specificity' => $line2["DISKSIZE"], '_itemtype' => 'DeviceHardDrive'));
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case self::DRIVE_DEVICE:
             //lecteurs
             if ($cfg_ocs["import_device_drive"]) {
                 $do_clean = true;
                 $query2 = "SELECT *\n                          FROM `storages`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 if ($DBocs->numrows($result2) > 0) {
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         if (empty($line2["DISKSIZE"]) || !preg_match("/disk/i", $line2["TYPE"])) {
                             if ($line2["NAME"]) {
                                 $stor["designation"] = $line2["NAME"];
                             } else {
                                 if ($line2["MODEL"]) {
                                     $stor["designation"] = $line2["MODEL"];
                                 } else {
                                     $stor["designation"] = "Unknown";
                                 }
                             }
                             if (!in_array(stripslashes($prevalue . $stor["designation"]), $import_device)) {
                                 $stor["specif_default"] = $line2["DISKSIZE"];
                                 $DeviceDrive = new DeviceDrive();
                                 $stor_id = $DeviceDrive->import($stor);
                                 if ($stor_id) {
                                     $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DeviceDrive', 'devicedrives_id' => $stor_id, '_no_history' => !$dohistory));
                                     self::addToOcsArray($computers_id, array($prevalue . $devID => $prevalue . $stor["designation"]), "import_device");
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $stor["designation"]), $import_device);
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case self::PCI_DEVICE:
             //Modems
             if ($cfg_ocs["import_device_modem"]) {
                 $do_clean = true;
                 $query2 = "SELECT *\n                          FROM `modems`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 if ($DBocs->numrows($result2) > 0) {
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         $mdm["designation"] = $line2["NAME"];
                         if (!in_array(stripslashes($prevalue . $mdm["designation"]), $import_device)) {
                             if (!empty($line2["DESCRIPTION"])) {
                                 $mdm["comment"] = $line2["TYPE"] . "\r\n" . $line2["DESCRIPTION"];
                             }
                             $DevicePci = new DevicePci();
                             $mdm_id = $DevicePci->import($mdm);
                             if ($mdm_id) {
                                 $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DevicePci', 'devicepcis_id' => $mdm_id, '_no_history' => !$dohistory));
                                 self::addToOcsArray($computers_id, array($prevalue . $devID => $prevalue . $mdm["designation"]), "import_device");
                             }
                         } else {
                             $tmp = array_search(stripslashes($prevalue . $mdm["designation"]), $import_device);
                             unset($import_device[$tmp]);
                         }
                     }
                 }
             }
             //Ports
             if ($cfg_ocs["import_device_port"]) {
                 $query2 = "SELECT *\n                          FROM `ports`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 if ($DBocs->numrows($result2) > 0) {
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         $port["designation"] = "";
                         if ($line2["TYPE"] != "Other") {
                             $port["designation"] .= $line2["TYPE"];
                         }
                         if ($line2["NAME"] != "Not Specified") {
                             $port["designation"] .= " " . $line2["NAME"];
                         } else {
                             if ($line2["CAPTION"] != "None") {
                                 $port["designation"] .= " " . $line2["CAPTION"];
                             }
                         }
                         if (!empty($port["designation"])) {
                             if (!in_array(stripslashes($prevalue . $port["designation"]), $import_device)) {
                                 if (!empty($line2["DESCRIPTION"]) && $line2["DESCRIPTION"] != "None") {
                                     $port["comment"] = $line2["DESCRIPTION"];
                                 }
                                 $DevicePci = new DevicePci();
                                 $port_id = $DevicePci->import($port);
                                 if ($port_id) {
                                     $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DevicePci', 'devicepcis_id' => $port_id, '_no_history' => !$dohistory));
                                     self::addToOcsArray($computers_id, array($prevalue . $devID => $prevalue . $port["designation"]), "import_device");
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $port["designation"]), $import_device);
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case self::PROCESSOR_DEVICE:
             //Processeurs :
             if ($cfg_ocs["import_device_processor"]) {
                 $do_clean = true;
                 $query = "SELECT *\n                         FROM `hardware`\n                         WHERE `ID` = '{$ocsid}'\n                         ORDER BY `ID`";
                 $result = $DBocs->query($query);
                 if ($DBocs->numrows($result) == 1) {
                     $line = $DBocs->fetch_array($result);
                     $line = clean_cross_side_scripting_deep(addslashes_deep($line));
                     for ($i = 0; $i < $line["PROCESSORN"]; $i++) {
                         $processor = array();
                         $processor["designation"] = $line["PROCESSORT"];
                         if (!is_numeric($line["PROCESSORS"])) {
                             $line["PROCESSORS"] = 0;
                         }
                         $processor["specif_default"] = $line["PROCESSORS"];
                         if (!in_array(stripslashes($prevalue . $processor["designation"]), $import_device)) {
                             $DeviceProcessor = new DeviceProcessor();
                             $proc_id = $DeviceProcessor->import($processor);
                             if ($proc_id) {
                                 $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DeviceProcessor', 'deviceprocessors_id' => $proc_id, 'specificity' => $line["PROCESSORS"], '_no_history' => !$dohistory));
                                 self::addToOcsArray($computers_id, array($prevalue . $devID => $prevalue . $processor["designation"]), "import_device");
                             }
                         } else {
                             $tmp = array_search(stripslashes($prevalue . $processor["designation"]), $import_device);
                             list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                             $CompDevice->update(array('id' => $id, 'specificity' => $line["PROCESSORS"], '_itemtype' => 'DeviceProcessor'));
                             unset($import_device[$tmp]);
                         }
                     }
                 }
             }
             break;
         case self::NETWORK_DEVICE:
             //Carte reseau
             if ($cfg_ocs["import_device_iface"] || $cfg_ocs["import_ip"]) {
                 $do_clean = true;
                 //If import_ip doesn't contain _VERSION_072_, then migrate it to the new architecture
                 if (!in_array(self::IMPORT_TAG_072, $import_ip)) {
                     $import_ip = self::migrateImportIP($computers_id, $import_ip);
                 }
                 $query2 = "SELECT *\n                          FROM `networks`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 $i = 0;
                 $manually_link = false;
                 //Count old ip in GLPI
                 $count_ip = count($import_ip);
                 // Add network device
                 if ($DBocs->numrows($result2) > 0) {
                     $mac_already_imported = array();
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         if ($cfg_ocs["import_device_iface"]) {
                             $network["designation"] = $line2["DESCRIPTION"];
                             if (!in_array($line2["MACADDR"], $mac_already_imported)) {
                                 $mac_already_imported[] = $line2["MACADDR"];
                                 if (!in_array(stripslashes($prevalue . $network["designation"]), $import_device)) {
                                     if (!empty($line2["SPEED"])) {
                                         $network["bandwidth"] = $line2["SPEED"];
                                     }
                                     $DeviceNetworkCard = new DeviceNetworkCard();
                                     $net_id = $DeviceNetworkCard->import($network);
                                     if ($net_id) {
                                         $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DeviceNetworkCard', 'devicenetworkcards_id' => $net_id, 'specificity' => $line2["MACADDR"], '_no_history' => !$dohistory));
                                         self::addToOcsArray($computers_id, array($prevalue . $devID > $prevalue . $network["designation"]), "import_device");
                                     }
                                 } else {
                                     $tmp = array_search(stripslashes($prevalue . $network["designation"]), $import_device);
                                     list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                                     $CompDevice->update(array('id' => $id, 'specificity' => $line2["MACADDR"], '_itemtype' => 'DeviceNetworkCard'));
                                     unset($import_device[$tmp]);
                                 }
                             }
                         }
                         if (!empty($line2["IPADDRESS"]) && $cfg_ocs["import_ip"]) {
                             $ocs_ips = explode(",", $line2["IPADDRESS"]);
                             $ocs_ips = array_unique($ocs_ips);
                             sort($ocs_ips);
                             //if never imported (only 0.72 tag in array), check if existing ones match
                             if ($count_ip == 1) {
                                 //get old IP in DB
                                 $querySelectIDandIP = "SELECT `id`, `ip`\n                                                  FROM `glpi_networkports`\n                                                  WHERE `itemtype` = 'Computer'\n                                                        AND `items_id` = '{$computers_id}'\n                                                        AND `mac` = '" . $line2["MACADDR"] . "'\n                                                        AND `name` = '" . $line2["DESCRIPTION"] . "'";
                                 $result = $DB->query($querySelectIDandIP);
                                 if ($DB->numrows($result) > 0) {
                                     while ($data = $DB->fetch_array($result)) {
                                         //Upate import_ip column and import_ip array
                                         self::addToOcsArray($computers_id, array($data["id"] => $data["ip"] . self::FIELD_SEPARATOR . $line2["MACADDR"]), "import_ip");
                                         $import_ip[$data["id"]] = $data["ip"] . self::FIELD_SEPARATOR . $line2["MACADDR"];
                                     }
                                 }
                             }
                             $netport = array();
                             $netport["mac"] = $line2["MACADDR"];
                             $netport["networkinterfaces_id"] = Dropdown::importExternal('NetworkInterface', $line2["TYPE"]);
                             $netport["name"] = $line2["DESCRIPTION"];
                             $netport["items_id"] = $computers_id;
                             $netport["itemtype"] = 'Computer';
                             $netport["netmask"] = $line2["IPMASK"];
                             $netport["gateway"] = $line2["IPGATEWAY"];
                             $netport["subnet"] = $line2["IPSUBNET"];
                             $np = new NetworkPort();
                             for ($j = 0; $j < count($ocs_ips); $j++) {
                                 //First search : look for the same port (same IP and same MAC)
                                 $id_ip = array_search($ocs_ips[$j] . self::FIELD_SEPARATOR . $line2["MACADDR"], $import_ip);
                                 //Second search : IP may have change, so look only for mac address
                                 if (!$id_ip) {
                                     //Browse the whole import_ip array
                                     foreach ($import_ip as $ID => $ip) {
                                         if ($ID > 0) {
                                             $tmp = explode(self::FIELD_SEPARATOR, $ip);
                                             //Port was found by looking at the mac address
                                             if (isset($tmp[1]) && $tmp[1] == $line2["MACADDR"]) {
                                                 //Remove port in import_ip
                                                 self::deleteInOcsArray($computers_id, $ID, "import_ip");
                                                 self::addToOcsArray($computers_id, array($ID => $ocs_ips[$j] . self::FIELD_SEPARATOR . $line2["MACADDR"]), "import_ip");
                                                 $import_ip[$ID] = $ocs_ips[$j] . self::FIELD_SEPARATOR . $line2["MACADDR"];
                                                 $id_ip = $ID;
                                                 break;
                                             }
                                         }
                                     }
                                 }
                                 $netport['_no_history'] = !$dohistory;
                                 //Update already in DB
                                 if ($id_ip > 0) {
                                     $netport["ip"] = $ocs_ips[$j];
                                     $netport["logical_number"] = $j;
                                     $netport["id"] = $id_ip;
                                     $np->update($netport);
                                     unset($import_ip[$id_ip]);
                                     $count_ip++;
                                 } else {
                                     //If new IP found
                                     unset($np->fields["netpoints_id"]);
                                     unset($netport["id"]);
                                     unset($np->fields["id"]);
                                     $netport["ip"] = $ocs_ips[$j];
                                     $netport["logical_number"] = $j;
                                     $newID = $np->add($netport);
                                     //ADD to array
                                     self::addToOcsArray($computers_id, array($newID => $ocs_ips[$j] . self::FIELD_SEPARATOR . $line2["MACADDR"]), "import_ip");
                                     $count_ip++;
                                 }
                             }
                         }
                     }
                 }
             }
             break;
         case self::GFX_DEVICE:
             //carte graphique
             if ($cfg_ocs["import_device_gfxcard"]) {
                 $do_clean = true;
                 $query2 = "SELECT DISTINCT(`NAME`) AS NAME,\n                                 `MEMORY`\n                          FROM `videos`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                                AND `NAME` != ''\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 if ($DBocs->numrows($result2) > 0) {
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         $video["designation"] = $line2["NAME"];
                         if (!is_numeric($line2["MEMORY"])) {
                             $line2["MEMORY"] = 0;
                         }
                         if (!in_array(stripslashes($prevalue . $video["designation"]), $import_device)) {
                             $video["specif_default"] = $line2["MEMORY"];
                             $DeviceGraphicCard = new DeviceGraphicCard();
                             $video_id = $DeviceGraphicCard->import($video);
                             if ($video_id) {
                                 $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DeviceGraphicCard', 'devicegraphiccards_id' => $video_id, 'specificity' => $line2["MEMORY"], '_no_history' => !$dohistory));
                                 self::addToOcsArray($computers_id, array($prevalue . $devID => $prevalue . $video["designation"]), "import_device");
                             }
                         } else {
                             $tmp = array_search(stripslashes($prevalue . $video["designation"]), $import_device);
                             list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                             $CompDevice->update(array('id' => $id, 'specificity' => $line2["MEMORY"], '_itemtype' => 'DeviceGraphicCard'));
                             unset($import_device[$tmp]);
                         }
                     }
                 }
             }
             break;
         case self::SND_DEVICE:
             //carte son
             if ($cfg_ocs["import_device_sound"]) {
                 $do_clean = true;
                 $query2 = "SELECT DISTINCT(`NAME`) AS NAME,\n                                 `DESCRIPTION`\n                          FROM `sounds`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                                AND `NAME` != ''\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 if ($DBocs->numrows($result2) > 0) {
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         if (!$cfg_ocs["ocs_db_utf8"] && !seems_utf8($line2["NAME"])) {
                             $line2["NAME"] = encodeInUtf8($line2["NAME"]);
                         }
                         $snd["designation"] = $line2["NAME"];
                         if (!in_array(stripslashes($prevalue . $snd["designation"]), $import_device)) {
                             if (!empty($line2["DESCRIPTION"])) {
                                 $snd["comment"] = $line2["DESCRIPTION"];
                             }
                             $DeviceSoundCard = new DeviceSoundCard();
                             $snd_id = $DeviceSoundCard->import($snd);
                             if ($snd_id) {
                                 $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DeviceSoundCard', 'devicesoundcards_id' => $snd_id, '_no_history' => !$dohistory));
                                 self::addToOcsArray($computers_id, array($prevalue . $devID => $prevalue . $snd["designation"]), "import_device");
                             }
                         } else {
                             $id = array_search(stripslashes($prevalue . $snd["designation"]), $import_device);
                             unset($import_device[$id]);
                         }
                     }
                 }
             }
             break;
     }
     // Delete Unexisting Items not found in OCS
     if ($do_clean && count($import_device)) {
         foreach ($import_device as $key => $val) {
             if (!(strpos($key, $devicetype . '$$') === false)) {
                 list($type, $id) = explode(self::FIELD_SEPARATOR, $key);
                 $CompDevice->delete(array('id' => $id, '_itemtype' => $types[$devicetype], '_no_history' => !$dohistory));
                 self::deleteInOcsArray($computers_id, $key, "import_device");
             }
         }
     }
     if ($do_clean && count($import_ip) && $devicetype == self::NETWORK_DEVICE) {
         foreach ($import_ip as $key => $val) {
             if ($key > 0) {
                 $netport = new NetworkPort();
                 $netport->delete(array('id' => $key));
                 self::deleteInOcsArray($computers_id, $key, "import_ip");
             }
         }
     }
     //Alimentation
     //Carte mere
 }