function getAdditionalFields()
 {
     if ($this->isNewItem() && isset($_GET['plugin_ocsinventoryng_networkports_id'])) {
         $network_port = new PluginOcsinventoryngNetworkPort();
         if ($network_port->getFromDB($_GET['plugin_ocsinventoryng_networkports_id'])) {
             $this->fields['OCS_TYPE'] = $network_port->fields['TYPE'];
             $this->fields['OCS_TYPEMIB'] = $network_port->fields['TYPEMIB'];
         }
     }
     return array(array('name' => 'OCS_TYPE', 'label' => __('OCS TYPE', 'ocsinventoryng'), 'type' => 'text'), array('name' => 'OCS_TYPEMIB', 'label' => __('OCS TYPE MIB', 'ocsinventoryng'), 'type' => 'text'), array('name' => 'instantiation_type', 'label' => __('Corresponding Network Port type', 'ocsinventoryng'), 'type' => 'instantiation_type'), array('name' => 'type', 'label' => __('Ethernet medium type', 'ocsinventoryng'), 'type' => 'type'), array('name' => 'speed', 'label' => __('Ethernet medium speed', 'ocsinventoryng'), 'type' => 'speed'), array('name' => 'version', 'label' => __('Wifi card Version', 'ocsinventoryng'), 'type' => 'version'));
 }
 function post_addItem()
 {
     global $DB;
     if (isset($this->input['transform_unknown_ports_that_match']) && $this->input['transform_unknown_ports_that_match']) {
         $networkport = new PluginOcsinventoryngNetworkPort();
         $query = "SELECT `id`\n                     FROM `" . $networkport->getTable() . "`\n                    WHERE `TYPE` = '" . $this->fields['OCS_TYPE'] . "'";
         if ($this->fields['OCS_TYPEMIB'] != '*') {
             $query .= " AND `TYPEMIB` = '" . $this->fields['OCS_TYPEMIB'] . "'";
         }
         foreach ($DB->request($query) as $line) {
             if ($networkport->getFromDBByQuery("WHERE `id`='" . $line['id'] . "'")) {
                 $networkport->transformAccordingTypes();
             }
         }
     }
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  * @param MassiveAction $ma
  * @param CommonDBTM $item
  * @param array $ids
  * @return nothing|void
  */
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case "plugin_ocsinventoryng_update_networkport_type":
             $networkport = new PluginOcsinventoryngNetworkPort();
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 if ($networkport->getFromDBByQuery("WHERE `networkports_id` = '{$id}'")) {
                     if ($networkport->transformAccordingTypes()) {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                     }
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Beispiel #4
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 $plugin_ocsinventoryng_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, $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, $import_ip, $dohistory)
 {
     global $PluginOcsinventoryngDBocs, $DB;
     $prevalue = $devicetype . self::FIELD_SEPARATOR;
     self::checkOCSconnection($plugin_ocsinventoryng_ocsservers_id);
     $do_clean = false;
     switch ($devicetype) {
         case "Item_DeviceMemory":
             $CompDevice = new $devicetype();
             //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 = $PluginOcsinventoryngDBocs->query($query2);
                 if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
                     // TODO a revoir
                     // pourquoi supprimer tous les importés ?
                     // En 0.83 cette suppression était lié à la présence du tag
                     // IMPORT_TAG_078, et donc exécuté 1 seule fois pour redressement
                     // Cela pete, je pense, tous les lock
                     //if (count($import_device)){
                     //   $dohistory = false;
                     //   foreach ($import_device as $key => $val) {
                     //      $tmp = explode(self::FIELD_SEPARATOR,$key);
                     //      if (isset($tmp[1]) && $tmp[0] == "Item_DeviceMemory") {
                     //         $CompDevice->delete(array('id'          => $tmp[1],
                     //                                   '_no_history' => true), 1);
                     //         unset($import_device[$key]);
                     //      }
                     //   }
                     //}
                     while ($line2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                         if (isset($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["size_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('items_id' => $computers_id, 'itemtype' => 'Computer', 'devicememories_id' => $ram_id, 'size' => $line2["CAPACITY"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $ram["designation"]), $import_device);
                                 list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                                 $CompDevice->update(array('id' => $id, 'size' => $line2["CAPACITY"]));
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceHardDrive":
             $CompDevice = new $devicetype();
             //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 = $PluginOcsinventoryngDBocs->query($query2);
                 if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
                     while ($line2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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["capacity_default"] = $line2["DISKSIZE"];
                                 $DeviceHardDrive = new DeviceHardDrive();
                                 $dd_id = $DeviceHardDrive->import($dd);
                                 if ($dd_id) {
                                     $devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'deviceharddrives_id' => $dd_id, 'capacity' => $line2["DISKSIZE"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $dd["designation"]), $import_device);
                                 list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                                 $CompDevice->update(array('id' => $id, 'capacity' => $line2["DISKSIZE"]));
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceDrive":
             $CompDevice = new $devicetype();
             //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 = $PluginOcsinventoryngDBocs->query($query2);
                 if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
                     while ($line2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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)) {
                                 $DeviceDrive = new DeviceDrive();
                                 $stor_id = $DeviceDrive->import($stor);
                                 if ($stor_id) {
                                     $devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'devicedrives_id' => $stor_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $stor["designation"]), $import_device);
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case "Item_DevicePci":
             $CompDevice = new $devicetype();
             //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 = $PluginOcsinventoryngDBocs->query($query2);
                 if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
                     while ($line2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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('items_id' => $computers_id, 'itemtype' => 'Computer', 'devicepcis_id' => $mdm_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
                             }
                         } 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 = $PluginOcsinventoryngDBocs->query($query2);
                 if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
                     while ($line2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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('items_id' => $computers_id, 'itemtype' => 'Computer', 'devicepcis_id' => $port_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $port["designation"]), $import_device);
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceProcessor":
             $CompDevice = new $devicetype();
             //Processeurs:
             if ($cfg_ocs["import_device_processor"]) {
                 $do_clean = true;
                 $query = "SELECT*\n                         FROM `hardware`\n                         WHERE `ID` = '{$ocsid}'\n                         ORDER BY `ID`";
                 $result = $PluginOcsinventoryngDBocs->query($query);
                 if ($PluginOcsinventoryngDBocs->numrows($result) == 1) {
                     $line = $PluginOcsinventoryngDBocs->fetch_array($result);
                     $line = Toolbox::clean_cross_side_scripting_deep(Toolbox::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["frequency_default"] = $line["PROCESSORS"];
                         $processor["frequence"] = $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('items_id' => $computers_id, 'itemtype' => 'Computer', 'deviceprocessors_id' => $proc_id, 'frequency' => $line["PROCESSORS"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
                             }
                         } else {
                             $tmp = array_search(stripslashes($prevalue . $processor["designation"]), $import_device);
                             list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                             $CompDevice->update(array('id' => $id, 'frequency' => $line["PROCESSORS"]));
                             unset($import_device[$tmp]);
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceNetworkCard":
             //Carte reseau
             if ($cfg_ocs["import_device_iface"] || $cfg_ocs["import_ip"]) {
                 PluginOcsinventoryngNetworkPort::importNetwork($PluginOcsinventoryngDBocs, $cfg_ocs, $ocsid, $computers_id, $dohistory);
             }
             break;
         case "Item_DeviceGraphicCard":
             $CompDevice = new $devicetype();
             //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 = $PluginOcsinventoryngDBocs->query($query2);
                 if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
                     while ($line2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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["memory_default"] = $line2["MEMORY"];
                             $DeviceGraphicCard = new DeviceGraphicCard();
                             $video_id = $DeviceGraphicCard->import($video);
                             if ($video_id) {
                                 $devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'devicegraphiccards_id' => $video_id, 'memory' => $line2["MEMORY"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
                             }
                         } else {
                             $tmp = array_search(stripslashes($prevalue . $video["designation"]), $import_device);
                             list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                             $CompDevice->update(array('id' => $id, 'memory' => $line2["MEMORY"]));
                             unset($import_device[$tmp]);
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceSoundCard":
             $CompDevice = new $devicetype();
             //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 = $PluginOcsinventoryngDBocs->query($query2);
                 if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
                     while ($line2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                         if (!$cfg_ocs["ocs_db_utf8"] && !Toolbox::seems_utf8($line2["NAME"])) {
                             $line2["NAME"] = Toolbox::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('items_id' => $computers_id, 'itemtype' => 'Computer', 'devicesoundcards_id' => $snd_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
                             }
                         } 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, '_no_history' => !$dohistory, 1), true);
             }
         }
     }
     //TODO Import IP
     if ($do_clean && count($import_ip) && $devicetype == "Item_DeviceNetworkCard") {
         foreach ($import_ip as $key => $val) {
             if ($key > 0) {
                 $netport = new NetworkPort();
                 $netport->delete(array('id' => $key));
             }
         }
     }
     //Alimentation
     //Carte mere
 }
Beispiel #5
0
/**
 * @return array
 */
function plugin_ocsinventoryng_getDropdown()
{
    // Table => Name
    return array('PluginOcsinventoryngNetworkPortType' => PluginOcsinventoryngNetworkPortType::getTypeName(2), 'PluginOcsinventoryngNetworkPort' => PluginOcsinventoryngNetworkPort::getTypeName(2), "PluginOcsinventoryngNotimportedcomputer" => __('Computers not imported by automatic actions', 'ocsinventoryng'));
}
 /**
  * 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 $plugin_ocsinventoryng_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, $ocsComputer, $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, $import_ip, $dohistory)
 {
     global $DB;
     $prevalue = $devicetype . self::FIELD_SEPARATOR;
     $do_clean = false;
     $comp = new Computer();
     $comp->getFromDB($computers_id);
     $entities_id = $comp->fields['entities_id'];
     switch ($devicetype) {
         case "Item_DeviceMemory":
             $CompDevice = new $devicetype();
             //Memoire
             $do_clean = true;
             if ($ocsComputer) {
                 // TODO a revoir
                 // pourquoi supprimer tous les importés ?
                 // En 0.83 cette suppression était lié à la présence du tag
                 // IMPORT_TAG_078, et donc exécuté 1 seule fois pour redressement
                 // Cela pete, je pense, tous les lock
                 //if (count($import_device)){
                 //   $dohistory = false;
                 //   foreach ($import_device as $key => $val) {
                 //      $tmp = explode(self::FIELD_SEPARATOR,$key);
                 //      if (isset($tmp[1]) && $tmp[0] == "Item_DeviceMemory") {
                 //         $CompDevice->delete(array('id'          => $tmp[1],
                 //                                   '_no_history' => true), 1);
                 //         unset($import_device[$key]);
                 //      }
                 //   }
                 //}
                 if (isset($ocsComputer['MEMORIES'])) {
                     foreach ($ocsComputer['MEMORIES'] as $line2) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                         if (isset($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["size_default"] = $line2["CAPACITY"];
                             $ram["entities_id"] = $entities_id;
                             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('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicememories_id' => $ram_id, 'size' => $line2["CAPACITY"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $ram["designation"]), $import_device);
                                 list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                                 $CompDevice->update(array('id' => $id, 'size' => $line2["CAPACITY"]));
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceHardDrive":
             $CompDevice = new $devicetype();
             //Disque Dur
             $do_clean = true;
             if ($ocsComputer) {
                 if (isset($ocsComputer['STORAGES'])) {
                     foreach ($ocsComputer['STORAGES'] as $line2) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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;
                             }
                             $dd["entities_id"] = $entities_id;
                             if (!in_array(stripslashes($prevalue . $dd["designation"]), $import_device)) {
                                 $dd["capacity_default"] = $line2["DISKSIZE"];
                                 $DeviceHardDrive = new DeviceHardDrive();
                                 $dd_id = $DeviceHardDrive->import($dd);
                                 if ($dd_id) {
                                     $devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'deviceharddrives_id' => $dd_id, 'serial' => $line2["SERIALNUMBER"], 'capacity' => $line2["DISKSIZE"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $dd["designation"]), $import_device);
                                 list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                                 $CompDevice->update(array('id' => $id, 'capacity' => $line2["DISKSIZE"], 'serial' => $line2["SERIALNUMBER"]));
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceDrive":
             $CompDevice = new $devicetype();
             //lecteurs
             $do_clean = true;
             if ($ocsComputer) {
                 if (isset($ocsComputer['STORAGES'])) {
                     foreach ($ocsComputer['STORAGES'] as $line2) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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";
                                 }
                             }
                             $stor["entities_id"] = $entities_id;
                             if (!in_array(stripslashes($prevalue . $stor["designation"]), $import_device)) {
                                 $DeviceDrive = new DeviceDrive();
                                 $stor_id = $DeviceDrive->import($stor);
                                 if ($stor_id) {
                                     $devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicedrives_id' => $stor_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $stor["designation"]), $import_device);
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case "Item_DevicePci":
             $CompDevice = new $devicetype();
             //Modems
             $do_clean = true;
             if ($ocsComputer) {
                 if (isset($ocsComputer['MODEMS'])) {
                     foreach ($ocsComputer['MODEMS'] as $line2) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                         $mdm["designation"] = $line2["NAME"];
                         $mdm["entities_id"] = $entities_id;
                         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('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicepcis_id' => $mdm_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
                             }
                         } else {
                             $tmp = array_search(stripslashes($prevalue . $mdm["designation"]), $import_device);
                             unset($import_device[$tmp]);
                         }
                     }
                 }
             }
             //Ports
             if ($ocsComputer) {
                 if (isset($ocsComputer['PORTS'])) {
                     foreach ($ocsComputer['PORTS'] as $line2) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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"];
                             }
                         }
                         $port["entities_id"] = $entities_id;
                         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('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicepcis_id' => $port_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $port["designation"]), $import_device);
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceProcessor":
             $CompDevice = new $devicetype();
             //Processeurs:
             $do_clean = true;
             if ($ocsComputer) {
                 if (isset($ocsComputer['HARDWARE'])) {
                     $line = $ocsComputer['HARDWARE'];
                     $line = Toolbox::clean_cross_side_scripting_deep(Toolbox::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["frequency_default"] = $line["PROCESSORS"];
                         $processor["frequence"] = $line["PROCESSORS"];
                         $processor["entities_id"] = $entities_id;
                         if (!in_array(stripslashes($prevalue . $processor["designation"]), $import_device)) {
                             $DeviceProcessor = new DeviceProcessor();
                             $proc_id = $DeviceProcessor->import($processor);
                             if ($proc_id) {
                                 $devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'deviceprocessors_id' => $proc_id, 'frequency' => $line["PROCESSORS"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
                             }
                         } else {
                             $tmp = array_search(stripslashes($prevalue . $processor["designation"]), $import_device);
                             list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                             $CompDevice->update(array('id' => $id, 'frequency' => $line["PROCESSORS"]));
                             unset($import_device[$tmp]);
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceNetworkCard":
             //Carte reseau
             PluginOcsinventoryngNetworkPort::importNetwork($plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $ocsComputer, $computers_id, $dohistory, $entities_id);
             break;
         case "Item_DeviceGraphicCard":
             $CompDevice = new $devicetype();
             //carte graphique
             $do_clean = true;
             if ($ocsComputer) {
                 if (isset($ocsComputer['VIDEOS'])) {
                     foreach ($ocsComputer['VIDEOS'] as $line2) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                         if ($line2['NAME']) {
                             $video["designation"] = $line2["NAME"];
                             $video["entities_id"] = $entities_id;
                             if (!is_numeric($line2["MEMORY"])) {
                                 $line2["MEMORY"] = 0;
                             }
                             if (!in_array(stripslashes($prevalue . $video["designation"]), $import_device)) {
                                 $video["memory_default"] = $line2["MEMORY"];
                                 $DeviceGraphicCard = new DeviceGraphicCard();
                                 $video_id = $DeviceGraphicCard->import($video);
                                 if ($video_id) {
                                     $devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicegraphiccards_id' => $video_id, 'memory' => $line2["MEMORY"], 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $video["designation"]), $import_device);
                                 list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                                 $CompDevice->update(array('id' => $id, 'memory' => $line2["MEMORY"]));
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceSoundCard":
             $CompDevice = new $devicetype();
             //carte son
             $do_clean = true;
             if ($ocsComputer) {
                 if (isset($ocsComputer['SOUNDS'])) {
                     foreach ($ocsComputer['SOUNDS'] as $line2) {
                         $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                         if ($line2['NAME']) {
                             if (!$cfg_ocs["ocs_db_utf8"] && !Toolbox::seems_utf8($line2["NAME"])) {
                                 $line2["NAME"] = Toolbox::encodeInUtf8($line2["NAME"]);
                             }
                             $snd["entities_id"] = $entities_id;
                             $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('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicesoundcards_id' => $snd_id, 'is_dynamic' => 1, '_no_history' => !$dohistory));
                                 }
                             } else {
                                 $id = array_search(stripslashes($prevalue . $snd["designation"]), $import_device);
                                 unset($import_device[$id]);
                             }
                         }
                     }
                 }
             }
             break;
         case "PluginOcsinventoryngItem_DeviceBiosdata":
             $CompDevice = new $devicetype();
             //Bios
             $do_clean = true;
             if ($ocsComputer) {
                 if (isset($ocsComputer['BIOS'])) {
                     $bios["designation"] = $ocsComputer['BIOS']["BVERSION"];
                     $bios["assettag"] = $ocsComputer['BIOS']["ASSETTAG"];
                     $bios["entities_id"] = $entities_id;
                     //$date = str_replace("/", "-", $ocsComputer['BIOS']["BDATE"]);
                     //$date = date("Y-m-d", strtotime($date));
                     $bios["date"] = $ocsComputer['BIOS']["BDATE"];
                     $bios["manufacturers_id"] = Dropdown::importExternal('Manufacturer', self::encodeOcsDataInUtf8($cfg_ocs['ocs_db_utf8'], $ocsComputer['BIOS']["SMANUFACTURER"]));
                     if (!in_array(stripslashes($prevalue . $bios["designation"]), $import_device)) {
                         $DeviceBios = new PluginOcsinventoryngDeviceBiosdata();
                         $bios_id = $DeviceBios->import($bios);
                         if ($bios_id) {
                             $devID = $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'plugin_ocsinventoryng_devicebiosdatas_id' => $bios_id, 'is_dynamic' => 1, 'entities_id' => $entities_id, '_no_history' => !$dohistory));
                         }
                     } else {
                         $tmp = array_search(stripslashes($prevalue . $bios["designation"]), $import_device);
                         unset($import_device[$tmp]);
                     }
                 }
             }
             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, '_no_history' => !$dohistory, 1), true);
             }
         }
     }
     //TODO Import IP
     if ($do_clean && count($import_ip) && $devicetype == "Item_DeviceNetworkCard") {
         foreach ($import_ip as $key => $val) {
             if ($key > 0) {
                 $netport = new NetworkPort();
                 $netport->delete(array('id' => $key));
             }
         }
     }
     //Alimentation
     //Carte mere
 }
Beispiel #7
0
/*
 * @version $Id: networkport.php 467 2015-01-15 20:41:38Z tsmr $
-------------------------------------------------------------------------
Ocsinventoryng plugin for GLPI
Copyright (C) 2012-2013 by the ocsinventoryng plugin Development Team.

https://forge.indepnet.net/projects/ocsinventoryng
-------------------------------------------------------------------------

LICENSE

This file is part of ocsinventoryng.

Ocsinventoryng plugin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Ocsinventoryng plugin 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 ocsinventoryng. If not, see <http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------- */
include '../../../inc/includes.php';
Session::checkRight('networking', READ);
Html::header(__('Unknown imported network ports', 'ocsinventory'), '', "tools", "pluginocsinventoryngmenu", 'networkport');
PluginOcsinventoryngNetworkPort::displayInvalidList();
Html::footer();
Beispiel #8
0
function plugin_ocsinventoryng_getDropdown()
{
    // Table => Name
    return array('PluginOcsinventoryngNetworkPortType' => PluginOcsinventoryngNetworkPortType::getTypeName(2), 'PluginOcsinventoryngNetworkPort' => PluginOcsinventoryngNetworkPort::getTypeName(2));
}
 /**
  * Import the devices for a computer
  *
  * @param $devicetype integer : device type
  * @param $computers_id integer : glpi computer id.
  * @param $ocsComputer
  * @param $plugin_ocsinventoryng_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
  * @return Nothing .
  * @internal param int $ocsid : ocs computer id (ID).
  * @internal param bool $dohistory : log changes?
  *
  */
 static function updateDevices($devicetype, $computers_id, $ocsComputer, $plugin_ocsinventoryng_ocsservers_id, $cfg_ocs, $import_device, $import_ip)
 {
     $prevalue = $devicetype . self::FIELD_SEPARATOR;
     $do_clean = false;
     $comp = new Computer();
     $comp->getFromDB($computers_id);
     $entities_id = $comp->fields['entities_id'];
     switch ($devicetype) {
         case "PluginOcsinventoryngItem_DeviceBiosdata":
             $CompDevice = new $devicetype();
             //Bios
             $do_clean = true;
             $bios["designation"] = $ocsComputer["BVERSION"];
             $bios["assettag"] = $ocsComputer["ASSETTAG"];
             $bios["entities_id"] = $entities_id;
             //$date = str_replace("/", "-", $ocsComputer['BIOS']["BDATE"]);
             //$date = date("Y-m-d", strtotime($date));
             $bios["date"] = $ocsComputer["BDATE"];
             $bios["manufacturers_id"] = Dropdown::importExternal('Manufacturer', self::encodeOcsDataInUtf8($cfg_ocs['ocs_db_utf8'], $ocsComputer["SMANUFACTURER"]));
             if (!in_array(stripslashes($prevalue . $bios["designation"]), $import_device)) {
                 $DeviceBios = new PluginOcsinventoryngDeviceBiosdata();
                 $bios_id = $DeviceBios->import($bios);
                 if ($bios_id) {
                     $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'plugin_ocsinventoryng_devicebiosdatas_id' => $bios_id, 'is_dynamic' => 1, 'entities_id' => $entities_id), array(), $cfg_ocs['history_devices']);
                 }
             } else {
                 $tmp = array_search(stripslashes($prevalue . $bios["designation"]), $import_device);
                 unset($import_device[$tmp]);
             }
             break;
         case "Item_DeviceMemory":
             //MEMORIES
             $CompDevice = new $devicetype();
             $do_clean = true;
             foreach ($ocsComputer as $line2) {
                 $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                 if (isset($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["size_default"] = $line2["CAPACITY"];
                     $ram["entities_id"] = $entities_id;
                     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) {
                             $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicememories_id' => $ram_id, 'size' => $line2["CAPACITY"], 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                         }
                     } else {
                         $tmp = array_search(stripslashes($prevalue . $ram["designation"]), $import_device);
                         list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                         $CompDevice->update(array('id' => $id, 'size' => $line2["CAPACITY"]), $cfg_ocs['history_devices']);
                         unset($import_device[$tmp]);
                     }
                 }
             }
             break;
         case "Item_DeviceHardDrive":
             $CompDevice = new $devicetype();
             //Disque Dur
             $do_clean = true;
             foreach ($ocsComputer as $line2) {
                 $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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;
                     }
                     $dd["entities_id"] = $entities_id;
                     if (!in_array(stripslashes($prevalue . $dd["designation"]), $import_device)) {
                         $dd["capacity_default"] = $line2["DISKSIZE"];
                         $DeviceHardDrive = new DeviceHardDrive();
                         $dd_id = $DeviceHardDrive->import($dd);
                         if ($dd_id) {
                             $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'deviceharddrives_id' => $dd_id, 'serial' => $line2["SERIALNUMBER"], 'capacity' => $line2["DISKSIZE"], 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                         }
                     } else {
                         $tmp = array_search(stripslashes($prevalue . $dd["designation"]), $import_device);
                         list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                         $CompDevice->update(array('id' => $id, 'capacity' => $line2["DISKSIZE"], 'serial' => $line2["SERIALNUMBER"]), $cfg_ocs['history_devices']);
                         unset($import_device[$tmp]);
                     }
                 }
             }
             break;
         case "Item_DeviceDrive":
             $CompDevice = new $devicetype();
             //lecteurs
             $do_clean = true;
             foreach ($ocsComputer as $line2) {
                 $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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";
                         }
                     }
                     $stor["entities_id"] = $entities_id;
                     if (!in_array(stripslashes($prevalue . $stor["designation"]), $import_device)) {
                         $DeviceDrive = new DeviceDrive();
                         $stor_id = $DeviceDrive->import($stor);
                         if ($stor_id) {
                             $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicedrives_id' => $stor_id, 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                         }
                     } else {
                         $tmp = array_search(stripslashes($prevalue . $stor["designation"]), $import_device);
                         unset($import_device[$tmp]);
                     }
                 }
             }
             break;
         case "Item_DevicePci":
             if (isset($ocsComputer['MODEMS'])) {
                 $CompDevice = new $devicetype();
                 //Modems
                 $do_clean = true;
                 foreach ($ocsComputer['MODEMS'] as $line2) {
                     $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                     $mdm["designation"] = $line2["NAME"];
                     $mdm["entities_id"] = $entities_id;
                     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) {
                             $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicepcis_id' => $mdm_id, 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                         }
                     } else {
                         $tmp = array_search(stripslashes($prevalue . $mdm["designation"]), $import_device);
                         unset($import_device[$tmp]);
                     }
                 }
             }
             //Ports
             if (isset($ocsComputer['PORTS'])) {
                 $CompDevice = new $devicetype();
                 foreach ($ocsComputer['PORTS'] as $line2) {
                     $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::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"];
                         }
                     }
                     $port["entities_id"] = $entities_id;
                     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) {
                                 $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicepcis_id' => $port_id, 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                             }
                         } else {
                             $tmp = array_search(stripslashes($prevalue . $port["designation"]), $import_device);
                             unset($import_device[$tmp]);
                         }
                     }
                 }
             }
             //Slots
             if (isset($ocsComputer['SLOTS'])) {
                 $CompDevice = new $devicetype();
                 $do_clean = true;
                 foreach ($ocsComputer['SLOTS'] as $line2) {
                     $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                     if ($line2['NAME']) {
                         if (!$cfg_ocs["ocs_db_utf8"] && !Toolbox::seems_utf8($line2["NAME"])) {
                             $line2["NAME"] = Toolbox::encodeInUtf8($line2["NAME"]);
                         }
                         $pci["entities_id"] = $entities_id;
                         $pci["designation"] = $line2["NAME"];
                         if (!in_array(stripslashes($prevalue . $pci["designation"]), $import_device)) {
                             if (!empty($line2["DESCRIPTION"])) {
                                 $pci["comment"] = $line2["DESCRIPTION"];
                             }
                             $DevicePci = new DevicePci();
                             $pci_id = $DevicePci->import($pci);
                             if ($pci_id) {
                                 $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicepcis_id' => $pci_id, 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                             }
                         } else {
                             $id = array_search(stripslashes($prevalue . $pci["designation"]), $import_device);
                             unset($import_device[$id]);
                         }
                     }
                 }
             }
             break;
         case "Item_DeviceProcessor":
             $CompDevice = new $devicetype();
             //Processeurs:
             $do_clean = true;
             foreach ($ocsComputer as $line2) {
                 $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                 $processor = array();
                 $processor["designation"] = $line2["TYPE"];
                 if (!is_numeric($line2["SPEED"])) {
                     $line2["SPEED"] = 0;
                 }
                 $processor["manufacturers_id"] = Dropdown::importExternal('Manufacturer', self::encodeOcsDataInUtf8($cfg_ocs['ocs_db_utf8'], $line2["MANUFACTURER"]));
                 $processor["frequency_default"] = $line2["SPEED"];
                 $processor["nbcores_default"] = $line2["CORES"];
                 //$processor["nbthreads_default"] = $line2["LOGICAL_CPUS"];
                 $processor["frequence"] = $line2["CURRENT_SPEED"];
                 $processor["entities_id"] = $entities_id;
                 if (!in_array(stripslashes($prevalue . $processor["designation"]), $import_device)) {
                     $DeviceProcessor = new DeviceProcessor();
                     $proc_id = $DeviceProcessor->import($processor);
                     if ($proc_id) {
                         $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'deviceprocessors_id' => $proc_id, 'frequency' => $line2["SPEED"], 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                     }
                 } else {
                     $tmp = array_search(stripslashes($prevalue . $processor["designation"]), $import_device);
                     list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                     $CompDevice->update(array('id' => $id, 'frequency' => $line2["SPEED"]), $cfg_ocs['history_devices']);
                     unset($import_device[$tmp]);
                 }
             }
             break;
         case "Item_DeviceNetworkCard":
             //Carte reseau
             PluginOcsinventoryngNetworkPort::importNetwork($cfg_ocs, $ocsComputer, $computers_id, $entities_id);
             break;
         case "Item_DeviceGraphicCard":
             $CompDevice = new $devicetype();
             //carte graphique
             $do_clean = true;
             foreach ($ocsComputer as $line2) {
                 $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                 if ($line2['NAME']) {
                     $video["designation"] = $line2["NAME"];
                     $video["entities_id"] = $entities_id;
                     if (!is_numeric($line2["MEMORY"])) {
                         $line2["MEMORY"] = 0;
                     }
                     if (!in_array(stripslashes($prevalue . $video["designation"]), $import_device)) {
                         $video["memory_default"] = $line2["MEMORY"];
                         $DeviceGraphicCard = new DeviceGraphicCard();
                         $video_id = $DeviceGraphicCard->import($video);
                         if ($video_id) {
                             $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicegraphiccards_id' => $video_id, 'memory' => $line2["MEMORY"], 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                         }
                     } else {
                         $tmp = array_search(stripslashes($prevalue . $video["designation"]), $import_device);
                         list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                         $CompDevice->update(array('id' => $id, 'memory' => $line2["MEMORY"]), $cfg_ocs['history_devices']);
                         unset($import_device[$tmp]);
                     }
                 }
             }
             break;
         case "Item_DeviceSoundCard":
             $CompDevice = new $devicetype();
             //carte son
             $do_clean = true;
             foreach ($ocsComputer as $line2) {
                 $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                 if ($line2['NAME']) {
                     if (!$cfg_ocs["ocs_db_utf8"] && !Toolbox::seems_utf8($line2["NAME"])) {
                         $line2["NAME"] = Toolbox::encodeInUtf8($line2["NAME"]);
                     }
                     $snd["entities_id"] = $entities_id;
                     $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) {
                             $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicesoundcards_id' => $snd_id, 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                         }
                     } else {
                         $id = array_search(stripslashes($prevalue . $snd["designation"]), $import_device);
                         unset($import_device[$id]);
                     }
                 }
             }
             break;
         case "Item_DeviceMotherboard":
             $CompDevice = new $devicetype();
             //Bios
             $do_clean = true;
             $mb["designation"] = $ocsComputer["MMODEL"];
             $mb["entities_id"] = $entities_id;
             $mb["manufacturers_id"] = Dropdown::importExternal('Manufacturer', self::encodeOcsDataInUtf8($cfg_ocs['ocs_db_utf8'], $ocsComputer["MMANUFACTURER"]));
             if (!in_array(stripslashes($prevalue . $mb["designation"]), $import_device)) {
                 $DeviceMB = new DeviceMotherboard();
                 $devicemotherboards_id = $DeviceMB->import($mb);
                 if ($devicemotherboards_id) {
                     $serial = $ocsComputer["MSN"];
                     $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'devicemotherboards_id' => $devicemotherboards_id, 'is_dynamic' => 1, 'serial' => $serial, 'entities_id' => $entities_id), array(), $cfg_ocs['history_devices']);
                 }
             } else {
                 $tmp = array_search(stripslashes($prevalue . $mb["designation"]), $import_device);
                 unset($import_device[$tmp]);
             }
             break;
         case "Item_DeviceControl":
             //controllers
             $do_clean = true;
             $CompDevice = new $devicetype();
             foreach ($ocsComputer as $line2) {
                 $line2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line2));
                 if ($line2['NAME']) {
                     if (!$cfg_ocs["ocs_db_utf8"] && !Toolbox::seems_utf8($line2["NAME"])) {
                         $line2["NAME"] = Toolbox::encodeInUtf8($line2["NAME"]);
                     }
                     $ctrl["entities_id"] = $entities_id;
                     $ctrl["designation"] = $line2["NAME"];
                     //TODO : OCS TYPE = IDE Controller
                     // GLPI : interface = IDE
                     //$ctrl["interfacetypes_id"] = $line2["TYPE"];
                     $ctrl["manufacturers_id"] = Dropdown::importExternal('Manufacturer', self::encodeOcsDataInUtf8($cfg_ocs['ocs_db_utf8'], $line2["MANUFACTURER"]));
                     if (!in_array(stripslashes($prevalue . $ctrl["designation"]), $import_device)) {
                         if (!empty($line2["DESCRIPTION"])) {
                             $ctrl["comment"] = $line2["DESCRIPTION"];
                         }
                         $DeviceControl = new DeviceControl();
                         $ctrl_id = $DeviceControl->import($ctrl);
                         if ($ctrl_id) {
                             $CompDevice->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'entities_id' => $entities_id, 'devicecontrols_id' => $ctrl_id, 'is_dynamic' => 1), array(), $cfg_ocs['history_devices']);
                         }
                     } else {
                         $id = array_search(stripslashes($prevalue . $ctrl["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 = new $devicetype();
                 $CompDevice->delete(array('id' => $id, '_no_history' => !$cfg_ocs['history_devices']), true, $cfg_ocs['history_devices']);
             }
         }
     }
     //TODO Import IP
     if ($do_clean && count($import_ip) && $devicetype == "Item_DeviceNetworkCard") {
         foreach ($import_ip as $key => $val) {
             if ($key > 0) {
                 $netport = new NetworkPort();
                 $netport->delete(array('id' => $key, '_no_history' => !$cfg_ocs['history_network']), 0, $cfg_ocs['history_network']);
             }
         }
     }
     //Alimentation
     //Carte mere
 }