seems_utf8() static public method

Is a string seems to be UTF-8 one ?
static public seems_utf8 ( $str ) : boolean
$str string string to analyze
return boolean
Esempio n. 1
0
 /**
  * CSV File parsing methods
  *
  * @param $fic
  * @param $data
  * @param $encoding  (default 1)
  **/
 static function parseLine($fic, $data, $encoding = 1)
 {
     global $DB;
     $csv = array();
     $num = count($data);
     for ($c = 0; $c < $num; $c++) {
         //If field is not the last, or if field is the last of the line and is not empty
         if ($c < $num - 1 || $c == $num - 1 && $data[$num - 1] != PluginDatainjectionCommonInjectionLib::EMPTY_VALUE) {
             $tmp = trim($DB->escape($data[$c]));
             switch ($encoding) {
                 //If file is ISO8859-1 : encode the datas in utf8
                 case PluginDatainjectionBackend::ENCODING_ISO8859_1:
                     if (!Toolbox::seems_utf8($tmp)) {
                         $csv[0][] = utf8_encode($tmp);
                     } else {
                         $csv[0][] = $tmp;
                     }
                     break;
                 case PluginDatainjectionBackend::ENCODING_UFT8:
                     $csv[0][] = $tmp;
                     break;
                 default:
                     //PluginDatainjectionBackend :: ENCODING_AUTO :
                     $csv[0][] = PluginDatainjectionBackend::toUTF8($tmp);
             }
         }
     }
     return $csv;
 }
Esempio n. 2
0
 /** function buildTicket - Builds,and returns, the major structure of the ticket to be entered.
  *
  * @param $i                  mail ID
  * @param $options   array    of possible options
  *
  * @return ticket fields array
  */
 function buildTicket($i, $options = array())
 {
     global $CFG_GLPI;
     $play_rules = isset($options['play_rules']) && $options['play_rules'];
     $head = $this->getHeaders($i);
     // Get Header Info Return Array Of Headers
     // **Key Are (subject,to,toOth,toNameOth,from,fromName)
     $tkt = array();
     $tkt['_blacklisted'] = false;
     // For RuleTickets
     $tkt['_mailgate'] = $options['mailgates_id'];
     // Use mail date if it's defined
     if ($this->fields['use_mail_date']) {
         $tkt['date'] = $head['date'];
     }
     // Detect if it is a mail reply
     $glpi_message_match = "/GLPI-([0-9]+)\\.[0-9]+\\.[0-9]+@\\w*/";
     // Check if email not send by GLPI : if yes -> blacklist
     if (!isset($head['message_id']) || preg_match($glpi_message_match, $head['message_id'], $match)) {
         $tkt['_blacklisted'] = true;
         return $tkt;
     }
     // manage blacklist
     $blacklisted_emails = Blacklist::getEmails();
     // Add name of the mailcollector as blacklisted
     $blacklisted_emails[] = $this->fields['name'];
     if (Toolbox::inArrayCaseCompare($head['from'], $blacklisted_emails)) {
         $tkt['_blacklisted'] = true;
         return $tkt;
     }
     // max size = 0 : no import attachments
     if ($this->fields['filesize_max'] > 0) {
         if (is_writable(GLPI_TMP_DIR)) {
             $tkt['_filename'] = $this->getAttached($i, GLPI_TMP_DIR . "/", $this->fields['filesize_max']);
             $tkt['_tag'] = $this->tags;
         } else {
             //TRANS: %s is a directory
             Toolbox::logInFile('mailgate', sprintf(__('%s is not writable'), GLPI_TMP_DIR . "/"));
         }
     }
     //  Who is the user ?
     $tkt['_users_id_requester'] = User::getOrImportByEmail($head['from']);
     $tkt["_users_id_requester_notif"]['use_notification'] = 1;
     // Set alternative email if user not found / used if anonymous mail creation is enable
     if (!$tkt['_users_id_requester']) {
         $tkt["_users_id_requester_notif"]['alternative_email'] = $head['from'];
     }
     // Add to and cc as additional observer if user found
     if (count($head['ccs'])) {
         foreach ($head['ccs'] as $cc) {
             if ($cc != $head['from'] && !Toolbox::inArrayCaseCompare($cc, $blacklisted_emails) && ($tmp = User::getOrImportByEmail($cc)) > 0) {
                 $tkt['_additional_observers'][] = array('users_id' => $tmp, 'use_notification' => 1);
             }
         }
     }
     if (count($head['tos'])) {
         foreach ($head['tos'] as $to) {
             if ($to != $head['from'] && !Toolbox::inArrayCaseCompare($to, $blacklisted_emails) && ($tmp = User::getOrImportByEmail($to)) > 0) {
                 $tkt['_additional_observers'][] = array('users_id' => $tmp, 'use_notification' => 1);
             }
         }
     }
     // Auto_import
     $tkt['_auto_import'] = 1;
     // For followup : do not check users_id = login user
     $tkt['_do_not_check_users_id'] = 1;
     $body = $this->getBody($i);
     // Do it before using charset variable
     $head['subject'] = $this->decodeMimeString($head['subject']);
     $tkt['_head'] = $head;
     if (!empty($this->charset) && !$this->body_converted) {
         $body = Toolbox::encodeInUtf8($body, $this->charset);
         $this->body_converted = true;
     }
     if (!Toolbox::seems_utf8($body)) {
         $tkt['content'] = Toolbox::encodeInUtf8($body);
     } else {
         $tkt['content'] = $body;
     }
     // See In-Reply-To field
     if (isset($head['in_reply_to'])) {
         if (preg_match($glpi_message_match, $head['in_reply_to'], $match)) {
             $tkt['tickets_id'] = intval($match[1]);
         }
     }
     // See in References
     if (!isset($tkt['tickets_id']) && isset($head['references'])) {
         if (preg_match($glpi_message_match, $head['references'], $match)) {
             $tkt['tickets_id'] = intval($match[1]);
         }
     }
     // See in title
     if (!isset($tkt['tickets_id']) && preg_match('/\\[.+#(\\d+)\\]/', $head['subject'], $match)) {
         $tkt['tickets_id'] = intval($match[1]);
     }
     $is_html = false;
     //If files are present and content is html
     if (isset($this->files) && count($this->files) && $tkt['content'] != strip_tags($tkt['content']) && !isset($tkt['tickets_id'])) {
         $is_html = true;
         $tkt['content'] = Ticket::convertContentForTicket($tkt['content'], array_merge($this->files, $this->altfiles), $this->tags);
     }
     $tkt['content'] = $this->cleanMailContent($tkt['content']);
     if ($is_html && !isset($tkt['tickets_id'])) {
         $tkt['content'] = nl2br($tkt['content']);
     }
     $tkt['_supplier_email'] = false;
     // Found ticket link
     if (isset($tkt['tickets_id'])) {
         // it's a reply to a previous ticket
         $job = new Ticket();
         $tu = new Ticket_User();
         $st = new Supplier_Ticket();
         // Check if ticket  exists and users_id exists in GLPI
         /// TODO check if users_id have right to add a followup to the ticket
         if ($job->getFromDB($tkt['tickets_id']) && $job->fields['status'] != CommonITILObject::CLOSED && ($CFG_GLPI['use_anonymous_followups'] || $tkt['_users_id_requester'] > 0 || $tu->isAlternateEmailForITILObject($tkt['tickets_id'], $head['from']) || ($tkt['_supplier_email'] = $st->isSupplierEmail($tkt['tickets_id'], $head['from'])))) {
             if ($tkt['_supplier_email']) {
                 $tkt['content'] = sprintf(__('From %s'), $head['from']) . "\n\n" . $tkt['content'];
             }
             $content = explode("\n", $tkt['content']);
             $tkt['content'] = "";
             $to_keep = array();
             // Move requester to author of followup :
             $tkt['users_id'] = $tkt['_users_id_requester'];
             $begin_strip = -1;
             $end_strip = -1;
             $begin_match = "/" . NotificationTargetTicket::HEADERTAG . ".*" . NotificationTargetTicket::HEADERTAG . "/";
             $end_match = "/" . NotificationTargetTicket::FOOTERTAG . ".*" . NotificationTargetTicket::FOOTERTAG . "/";
             foreach ($content as $ID => $val) {
                 // Get first tag for begin
                 if ($begin_strip < 0) {
                     if (preg_match($begin_match, $val)) {
                         $begin_strip = $ID;
                     }
                 }
                 // Get last tag for end
                 if ($begin_strip >= 0) {
                     if (preg_match($end_match, $val)) {
                         $end_strip = $ID;
                         continue;
                     }
                 }
             }
             if ($begin_strip >= 0) {
                 // Clean first and last lines
                 $content[$begin_strip] = preg_replace($begin_match, '', $content[$begin_strip]);
             }
             if ($end_strip >= 0) {
                 // Clean first and last lines
                 $content[$end_strip] = preg_replace($end_match, '', $content[$end_strip]);
             }
             if ($begin_strip >= 0) {
                 $length = count($content);
                 // Use end strip if set
                 if ($end_strip >= 0 && $end_strip < $length) {
                     $length = $end_strip;
                 }
                 for ($i = $begin_strip + 1; $i < $length; $i++) {
                     unset($content[$i]);
                 }
             }
             $to_keep = array();
             // Aditional clean for thunderbird
             foreach ($content as $ID => $val) {
                 if (!isset($val[0]) || $val[0] != '>') {
                     $to_keep[$ID] = $ID;
                 }
             }
             $tkt['content'] = "";
             foreach ($to_keep as $ID) {
                 $tkt['content'] .= $content[$ID] . "\n";
             }
             // Do not play rules for followups : WRONG : play rules only for refuse options
             //$play_rules = false;
         } else {
             // => to handle link in Ticket->post_addItem()
             $tkt['_linkedto'] = $tkt['tickets_id'];
             unset($tkt['tickets_id']);
         }
     }
     // Add message from getAttached
     if ($this->addtobody) {
         $tkt['content'] .= $this->addtobody;
     }
     $tkt['name'] = $this->textCleaner($head['subject']);
     if (!isset($tkt['tickets_id'])) {
         // Which entity ?
         //$tkt['entities_id']=$this->fields['entities_id'];
         //$tkt['Subject']= $head['subject'];   // not use for the moment
         // Medium
         $tkt['urgency'] = "3";
         // No hardware associated
         $tkt['itemtype'] = "";
         // Mail request type
     } else {
         // Reopen if needed
         $tkt['add_reopen'] = 1;
     }
     $tkt['requesttypes_id'] = RequestType::getDefault('mail');
     if ($play_rules) {
         $rule_options['ticket'] = $tkt;
         $rule_options['headers'] = $head;
         $rule_options['mailcollector'] = $options['mailgates_id'];
         $rule_options['_users_id_requester'] = $tkt['_users_id_requester'];
         $rulecollection = new RuleMailCollectorCollection();
         $output = $rulecollection->processAllRules(array(), array(), $rule_options);
         // New ticket : compute all
         if (!isset($tkt['tickets_id'])) {
             foreach ($output as $key => $value) {
                 $tkt[$key] = $value;
             }
         } else {
             // Followup only copy refuse data
             $tobecopied = array('_refuse_email_no_response', '_refuse_email_with_response');
             foreach ($tobecopied as $val) {
                 if (isset($output[$val])) {
                     $tkt[$val] = $output[$val];
                 }
             }
         }
     }
     $tkt = Toolbox::addslashes_deep($tkt);
     return $tkt;
 }
Esempio n. 3
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
 }
Esempio n. 4
0
function get_update_content($DB, $table, $from, $limit, $conv_utf8)
{
    $content = "";
    $DB->query("SET NAMES latin1");
    $result = $DB->query("SELECT *\n                         FROM `{$table}`\n                         LIMIT {$from}, {$limit}");
    if ($result) {
        while ($row = $DB->fetch_assoc($result)) {
            if (isset($row["id"])) {
                $insert = "UPDATE `{$table}`\n                       SET ";
                foreach ($row as $key => $val) {
                    $insert .= " `" . $key . "` = ";
                    if (!isset($val)) {
                        $insert .= "NULL,";
                    } else {
                        if ($val != "") {
                            if ($conv_utf8) {
                                // Gestion users AD qui sont deja en UTF8
                                if ($table != "glpi_users" || !Toolbox::seems_utf8($val)) {
                                    $val = Toolbox::encodeInUtf8($val);
                                }
                            }
                            $insert .= "'" . addslashes($val) . "',";
                        } else {
                            $insert .= "'',";
                        }
                    }
                }
                $insert = preg_replace("/,\$/", "", $insert);
                $insert .= " WHERE `id` = '" . $row["id"] . "' ";
                $insert .= ";\n";
                $content .= $insert;
            }
        }
    }
    return $content;
}
Esempio n. 5
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, $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
 }