/** * 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 }
/** Generate bigdump : generate global dropdowns **/ function generateGlobalDropdowns() { global $MAX, $DB; $items = array("CD", "CD-RW", "DVD-R", "DVD+R", "DVD-RW", "DVD+RW", "ramette papier", "disk'ette", "ZIP"); $dp = new ConsumableItemType(); for ($i=0 ; $i<$MAX['consumable_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' consommable $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("phone d'power"); $dp = new PhonePowerSupply(); for ($i=0 ; $i<$MAX['phone_power'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "power ' $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Grand", "Moyen", "Mic'ro", "1U", "5U"); $dp = new DeviceCaseType(); for ($i=0 ; $i<$MAX['case_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "power ' $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Laser", "Jet d'Encre", "Encre Solide"); $dp = new CartridgeItemType(); for ($i=0 ; $i<$MAX['cartridge_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' cartouche $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Technicien", "Commercial", "Technico-Commercial", "President", "Secretaire", "Directeur d'agence"); $dp = new ContactType(); for ($i=0 ; $i<$MAX['contact_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' contact $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Maintenance", "Support", "Location", "Adhesion"); $dp = new ContractType(); for ($i=0 ; $i<$MAX['contract_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' crontact $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Fournisseur", "Transporteur", "SSII", "Revendeur d'", "Assembleur", "SSLL", "Financeur", "Assureur"); $dp = new SupplierType(); for ($i=0 ; $i<$MAX['enttype'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d'entreprise $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("H.07.02", "I.07.56", "P51", "P52", "1.60", "4.06", "43-4071299", "1.0.14", "3.0.1", "rev 1.0", "rev 1.1", "rev 1.2", "rev 1.2.1", "rev 2.0", "rev 3.0"); $dp = new NetworkEquipmentFirmware(); for ($i=0 ; $i<$MAX['firmware'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "firmware $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Fire'wire"); $dp = new InterfaceType(); for ($i=0 ; $i<$MAX['interface'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' disque dur $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("100 Base TX", "100 Base T4", "10 base T", "1000 Base SX", "1000 Base LX", "1000 Base T", "ATM", "802.3 10 Base 2", "IEEE 803.3 10 Base 5"); $dp = new NetworkInterface(); for ($i=0 ; $i<$MAX['iface'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type carte reseau $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Non", "Oui - generique", "Oui - specifique d'entite"); $dp = new AutoUpdateSystem(); for ($i=0 ; $i<$MAX['auto_update'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de mise a jour '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Assemble", "Latitude C600", "Latitude C700", "VAIO FX601", "VAIO FX905P", "VAIO TR5MP", "L5000C", "A600K", "PowerBook G4"); $dp = new ComputerModel(); for ($i=0 ; $i<$MAX['model'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "Modele $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment' $val"))); } $items = array("4200 DTN", "4200 DN", "4200 N", "8400 ADP", "7300 ADP", "5550 DN", "PIXMA iP8500", "Stylus Color 3000", "DeskJet 5950"); $dp = new PrinterModel(); for ($i=0 ; $i<$MAX['model_printers'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele imprimante $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("LS902UTG", "MA203DT", "P97F+SB", "G220F", "10-30-75", "PLE438S-B0S", "PLE481S-W", "L1740BQ", "L1920P", "SDM-X73H"); $dp = new MonitorModel(); for ($i=0 ; $i<$MAX['model_monitors'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele moniteur $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("HP 4108GL", "HP 2524", "HP 5308", "7600", "Catalyst 4500", "Catalyst 2950", "Catalyst 3750", "Catalyst 6500"); $dp = new NetworkEquipmentModel(); for ($i=0 ; $i<$MAX['model_networking'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele materiel reseau $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("DCS-2100+", "DCS-2100G", "KD-P35B", "Optical 5000", "Cordless", "ASR 600", "ASR 375", "CS21", "MX5020", "VS4121", "T3030", "T6060"); $dp = new PeripheralModel(); for ($i=0 ; $i<$MAX['model_peripherals'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele peripherique $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Alcatel Temporis 22", "Aastra 5370ip", "Alcatel-Lucent 400 DECT Handset", "BlackBerry Curve 9300"); $dp = new PhoneModel(); for ($i=0 ; $i<$MAX['model_phones'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele phone $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment' $val"))); } $items = array("SIC", "LMS", "LMP", "LEA", "SP2MI", "STIC", "MATH", "ENS-MECA", "POUBELLE", "WIFI"); $dp = new Network(); for ($i=0 ; $i<$MAX['network'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "reseau $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Windows XP Pro SP2", "Linux (Debian)", "Mac OS X", "Linux (Mandriva 2006)", "Linux (Redhat)", "Windows 98", "Windows 2000", "Windows XP Pro SP1", "LINUX (Suse)", "Linux (Mandriva 10.2)"); $dp = new OperatingSystem(); for ($i=0 ; $i<$MAX['os'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "os $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("XP Pro", "XP Home", "10.0", "10.1", "10.2", "2006", "Sarge"); $dp = new operatingSystemVersion(); for ($i=0 ; $i<$MAX['os_version'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "osversion $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Service Pack 1", "Service Pack 2", "Service Pack 3", "Service Pack 4"); $dp = new OperatingSystemServicePack(); for ($i=0 ; $i<$MAX['os_sp'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "ossp $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("DDR2"); $dp = new DeviceMemoryType(); for ($i=0 ; $i<$MAX['ram_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de ram $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment' $val"))); } $items = array('Bureautique', 'Calcul', "logiciel d'antivirus", 'Multimédia'); $dp = new SoftwareCategory(); for ($i=0 ; $i<max(1,pow($MAX['softwarecategory'],1/2)) ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "category $i"; } $newID = $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['softwarecategory'],1/2)) ; $j++) { $newID2 = $dp->add(toolbox::addslashes_deep(array('name' => "s-category '$j", 'comment' => "comment d' $val s-category $j", 'softwarecategories_id' => $newID))); } } $MAX['rubdocs'] = getMaxItem('glpi_softwarecategories'); $dp = new SoftwareLicenseType(); for ($i=0 ; $i<$MAX['licensetype'] ; $i++) { $val = "type ' $i"; $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("SIC", "LMS", "LMP", "LEA", "SP2MI", "STIC", "MATH", "ENS-MECA", "POUBELLE", "WIFI"); $dp = new Vlan(); for ($i=0 ; $i<$MAX['vlan'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "VLAN $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val", 'tag' => $i))); } $items = array("Portable", "Desktop", "Tour"); $dp = new ComputerType(); for ($i=0 ; $i<$MAX['type_computers'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type ordinateur $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Laser A4", "Jet d'Encre", "Laser A3", "Encre Solide A4", "Encre Solide A3"); $dp = new PrinterType(); for ($i=0 ; $i<$MAX['type_printers'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d'imprimante $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("TFT 17", "TFT 19", "TFT 21", "CRT 17", "CRT 19", "CRT 21", "CRT 15"); $dp = new MonitorType(); for ($i=0 ; $i<$MAX['type_monitors'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type ecran $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Switch", "Routeur", "Hub", "Borne Wifi", "borne d'accueil"); $dp = new NetworkEquipmentType(); for ($i=0 ; $i<$MAX['type_networking'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de materiel reseau '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Clavier", "Souris", "Webcam", "Enceintes", "Scanner", "Clef USB", "d'autres"); $dp = new PeripheralType(); for ($i=0 ; $i<$MAX['type_peripherals'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de peripheriques '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Analogique", "IP", ); $dp = new PhoneType(); for ($i=0 ; $i<$MAX['type_phones'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de phone $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("DELL", "HP", "IIYAMA", "CANON", "EPSON", "LEXMARK", "ASUS", "MSI"); $dp = new Manufacturer(); for ($i=0 ; $i<$MAX['manufacturer'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "manufacturer $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Ingénieur", "Stagiaire", "Secrétaire", "ouvrier d'atelier"); $dp = new UserCategory(); for ($i=0 ; $i<$MAX['user_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "user type d'$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Président", "Agent Comptable", "Directeur d'agence"); $dp = new UserTitle(); for ($i=0 ; $i<$MAX['user_title'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "user type '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Documentation", "Facture", "Bon Livraison", "Bon commande", "Capture d'Ecran", "Dossier Technique"); $dp = new DocumentCategory(); for ($i=0 ; $i<max(1,pow($MAX['rubdocs'],1/2)) ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "category $i"; } $newID = $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['rubdocs'],1/2)) ; $j++) { $newID2 = $dp->add(toolbox::addslashes_deep( array('name' => "s-category '$j", 'comment' => "comment d' $val s-category $j", 'documentcategories_id' => $newID))); } } $MAX['rubdocs'] = getMaxItem('glpi_documentcategories'); $dp = new ItilCategory(); // GLobal ticket categories : also specific ones by entity for ($i=0 ; $i<max(1,pow($MAX['tracking_category'],1/3)) ; $i++) { $newID = $dp->add(toolbox::addslashes_deep( array('name' => "category '$i", 'comment' => "comment ' category $i", 'is_recursive' => 1, 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1))); for ($j=0 ; $j<mt_rand(0,pow($MAX['tracking_category'],1/2)) ; $j++) { $newID2 = $dp->add(toolbox::addslashes_deep( array('name' => "s-category '$j", 'comment' => "comment 'category $i s-category $j", 'is_recursive' => 1, 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1, 'itilcategories_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['tracking_category'],1/2)) ; $k++) { $newID3 = $dp->add(toolbox::addslashes_deep( array('name' => "ss-category' $k", 'comment' => "comment ' category $i s-category $j ss-category $k", 'is_recursive' => 1, 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1, 'itilcategories_id' => $newID2))); } } } $query = "OPTIMIZE TABLE `glpi_itilcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_itilcategories"); $MAX['tracking_category'] = getMaxItem('glpi_itilcategories'); // DEVICE $items = array("Textorm 6A19", "ARIA", "SLK3000B-EU", "Sonata II", "TA-212", "TA-551", "TA-581", "TAC-T01", "CS-512", "Li PC-60891", "STT-TJ02S"); $dp = new DeviceCase(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "case $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'devicecasetypes_id' => mt_rand(0,$MAX["case_type"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer'])))); } $items = array("Escalade 8006-2LP", "Escalade 8506-4LP", "2810SA", "1210SA", "DuoConnect", "DU-420", "DUB-A2", "FastTrak SX4100B", "DC-395U", "TFU-H33PI"); $dp = new DeviceControl(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "control $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment ' $val", 'interfacetypes_id' => mt_rand(0,$MAX["interface"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer'])))); } $items = array("DUW1616", "DRW-1608P", "DW1625", "GSA-4160B", "GSA-4165B", "GSA-4167RBB", "SHW-16H5S", "SOHW-1673SX", "DVR-110D", "PX-716AL", "PX-755A"); $dp = new DeviceDrive(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "drive $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'is_writer' => mt_rand(0,1), 'speed' => mt_rand(0,60), 'interfacetypes_id' => mt_rand(0,$MAX["interface"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer'])))); } $items = array("A9250/TD", "AX550/TD", "Extreme N5900", "V9520-X/TD", "All-In-Wonder X800 GT", "GV-NX66256D", "GV-RX80256DE", "Excalibur 9600XT", "X1300 IceQ", "WinFast PX6200 TD", "Millenium 750","NX6600GT"); $dp = new DeviceGraphicCard(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "gfxcard $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment ' $val", 'interfacetypes_id' => mt_rand(0,$MAX["interface"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'memory_default' => 256*mt_rand(0,8)))); } $items = array("Deskstar 7K500", "Deskstar T7K250", "Atlas 15K II", "DiamondMax Plus", "SpinPoint P - SP2514N", "Barracuda 7200.9", "WD2500JS", "WD1600JB", "WD1200JD"); $dp = new DeviceHardDrive(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "hdd $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'interfacetypes_id' => mt_rand(0,$MAX["interface"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'capacity_default' => mt_rand(0,300), 'rpm' => mt_rand(0,15000), 'cache' => 51200*mt_rand(0,10)))); } $items = array("DFE-530TX", "DFE-538TX", "PWLA8492MF", "PWLA8492MT", "USBVPN1", "GA311", "FA511", "TEG-PCBUSR", "3C996-SX", "3C996B-T", "3C905C-TX-M"); $dp = new DeviceNetworkCard(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "iface $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'bandwidth' => mt_rand(0,1000)))); } $items = array("AW8-MAX", "NV8", "AK86-L", "P4V88", "A8N-SLI", "A8N-VM", "K8V-MX", "K8N4-E", "P5LD2", "GA-K8NE", "GA-8I945P Pro", "D945PBLL", "SE7525GP2", "865PE Neo3-F", "K8N Neo4-F", "Thunder i7520 (S5360G2NR)", "Thunder K8SR - S2881UG2NR", "Tiger K8QS Pro - S4882UG2NR", "Tomcat i875PF (S5105G2NR)"); $dp = new DeviceMotherBoard(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "moboard $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'chipset' => 'chipset '.mt_rand(0,1000)))); } $items = array("Instant TV Cardbus", "WinTV Express", "WinTV-NOVA-S-Plus", "WinTV-NOVA-T", "WinTV-PVR-150"); $dp = new DevicePci(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "pci $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer'])))); } $items = array("DB-Killer PW335", "DB-Killer PW385", "NeoHE 380", "NeoHE 450", "Phantom 500-PEC", "TruePower 2.0 550", "Master RS-380", "EG375AX-VE-G-SFMA", "EG495AX"); $dp = new DevicePowerSupply(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "power $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'power' => mt_rand(0,500).'W', 'is_atx' => mt_rand(0,1)))); } $items = array("Athlon 64 FX-57", "Athlon 64 FX-55", "Sempron 2400+", "Sempron 2600+", "Celeron D 325", "Celeron D 330J", "Pentium 4 530J", "Pentium 4 631", "Pentium D 830", "Pentium D 920"); $dp = new DeviceProcessor(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "processor $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'frequence' => mt_rand(1000,3000), 'frequency_default' => 1000+200*mt_rand(0,10), 'nbcores_default' => mt_rand(1,8), 'nbthreads_default' => mt_rand(1,4), ))); } $items = array("CM2X256A-5400C4", "CMX1024-3200C2", "CMXP512-3200XL", "TWIN2X1024-4300C3PRO", "KTD-DM8400/1G", "KTH8348/1G", "KTD4400/256", "D6464D30A", "KTA-G5400/512", "KVR667D2N5/1G", "KVR133X64C3/256"); $dp = new DeviceMemory(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "ram $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'frequence' => 100*mt_rand(0,10), 'size_default' => 1024*mt_rand(0,6), 'devicememorytypes_id' => mt_rand(1,$MAX['ram_type'])))); } $items = array("DDTS-100", "Audigy 2 ZS Platinum", "Audigy SE", "DJ Console Mk2", "Gamesurround Muse Pocket USB", "Phase 22", "X-Fi Platinum", "Live! 24-bit", "X-Fi Elite Pro"); $dp = new DeviceSoundCard(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "sndcard $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'type' => 'type '.mt_rand(0,100)))); } } // Fin generation global dropdowns
/** * Add a new sound card component * * @param type $data * @param type $computers_id * @param type $no_history * * @return nothing */ function addSoundCard($data, $computers_id, $no_history) { $item_DeviceSoundCard = new Item_DeviceSoundCard(); $deviceSoundCard = new DeviceSoundCard(); $sounds_id = $deviceSoundCard->import($data); $data['devicesoundcards_id'] = $sounds_id; $data['itemtype'] = 'Computer'; $data['items_id'] = $computers_id; $data['is_dynamic'] = 1; $data['_no_history'] = $no_history; $item_DeviceSoundCard->add($data, array(), !$no_history); }
/** * Get the Device list name the user is allowed to edit * * @return array (group of dropdown) of array (itemtype => localized name) **/ static function getDeviceItemTypes() { global $CFG_GLPI; static $optgroup = NULL; if (!Session::haveRight('device', 'r')) { return array(); } if (is_null($optgroup)) { $optgroup = array(_n('Component', 'Components', 2) => array('DeviceMotherboard' => DeviceMotherboard::getTypeName(2), 'DeviceProcessor' => DeviceProcessor::getTypeName(2), 'DeviceNetworkCard' => DeviceNetworkCard::getTypeName(2), 'DeviceMemory' => DeviceMemory::getTypeName(2), 'DeviceHardDrive' => DeviceHardDrive::getTypeName(2), 'DeviceDrive' => DeviceDrive::getTypeName(2), 'DeviceControl' => DeviceControl::getTypeName(2), 'DeviceGraphicCard' => DeviceGraphicCard::getTypeName(2), 'DeviceSoundCard' => DeviceSoundCard::getTypeName(2), 'DeviceCase' => DeviceCase::getTypeName(2), 'DevicePowerSupply' => DevicePowerSupply::getTypeName(2), 'DevicePci' => DevicePci::getTypeName(2))); } return $optgroup; }
/** * 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 }
/** * 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 }
/** * 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 }