/**
  * Get ports
  *
  *@return Array of ports instances
  **/
 private function getPortsDB()
 {
     global $DB;
     $ptp = new PluginFusioninventoryPort();
     $query = "SELECT `ID`\n                FROM `glpi_networking_ports`\n                WHERE `on_device` = '" . $this->getValue('ID') . "'\n                      AND `device_type` = '" . NETWORKING_TYPE . "';";
     $portsIds = array();
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             while ($port = $DB->fetch_assoc($result)) {
                 $ptp->load($port['ID']);
                 $portsIds[] = clone $ptp;
             }
         }
     }
     return $portsIds;
 }
 static function networking_ports_addLog($port_id, $new_value, $field)
 {
     include GLPI_ROOT . "/plugins/fusioninventory/inc_constants/snmp.mapping.constant.php";
     $ptp = new PluginFusioninventoryPort();
     $ptsnmph = new PluginFusioninventorySnmphistory();
     $pficsnmph = new PluginFusioninventoryConfigSNMPHistory();
     $db_field = $field;
     switch ($field) {
         case 'ifname':
             $db_field = 'name';
             $field = 'ifName';
             break;
         case 'mac':
             $db_field = 'ifmac';
             $field = 'macaddr';
             break;
         case 'ifnumber':
             $db_field = 'logical_number';
             $field = 'ifIndex';
             break;
         case 'trunk':
             $field = 'vlanTrunkPortDynamicStatus';
             break;
         case 'iftype':
             $field = 'ifType';
             break;
         case 'duplex':
             $field = 'portDuplex';
             break;
     }
     $ptp->load($port_id);
     //echo $ptp->getValue($db_field);
     if ($ptp->getValue($db_field) != $new_value) {
         $days = $pficsnmph->getValue($field);
         if (isset($days) and $days != '-1') {
             $array["FK_ports"] = $port_id;
             $array["field"] = $field;
             $array["old_value"] = $ptp->getValue($db_field);
             $array["new_value"] = $new_value;
             $ptsnmph->insert_connection("field", $array, $_SESSION['glpi_plugin_fusioninventory_processnumber']);
         }
     }
 }
 /**
  * Get index of connection to switch
  *
  *@return index of connection in $this->portsToConnect
  **/
 private function getConnectionToSwitchIndex()
 {
     global $DB;
     $macs = '';
     $ptp = new PluginFusioninventoryPort();
     foreach ($this->portsToConnect as $index => $portConnection) {
         if ($macs != '') {
             $macs .= ', ';
         }
         $ptp->load($portConnection);
         $macs .= "'" . $ptp->getValue('ifmac') . "'";
         $ifmac[$index] = $ptp->getValue('ifmac');
     }
     if ($macs != '') {
         $query = "SELECT `ifmac`\n                   FROM `glpi_networking`\n                   WHERE `ifmac` IN (" . $macs . ");";
         $result = $DB->query($query);
         if ($DB->numrows($result) == 1) {
             $switch = $DB->fetch_assoc($result);
             return array_search($switch['ifmac'], $ifmac);
         }
     }
     return '';
 }
 /**
  * Import PORT Printer
  *@param $p_port PORT code to import
  *
  *@return errors string to be alimented if import ko / '' if ok
  **/
 function importPortPrinter($p_port)
 {
     global $LANG;
     $errors = '';
     $ptp = new PluginFusioninventoryPort(PRINTER_TYPE);
     $ifType = $p_port->IFTYPE;
     if ($ptp->isReal($ifType)) {
         // not virtual port
         $portIndex = $this->ptd->getPortIndex($p_port->MAC, $p_port->IP);
         if (is_int($portIndex)) {
             $oldPort = $this->ptd->getPort($portIndex);
             $ptp->load($oldPort->getValue('ID'));
         } else {
             $ptp->addDB($this->deviceId, TRUE);
         }
         foreach ($p_port->children() as $name => $child) {
             switch ($name) {
                 case 'IFNAME':
                     PluginFusioninventorySnmphistory::networking_ports_addLog($ptp->getValue('ID'), $child, strtolower($name));
                     $ptp->setValue('name', $child);
                     break;
                 case 'MAC':
                     PluginFusioninventorySnmphistory::networking_ports_addLog($ptp->getValue('ID'), $child, strtolower($name));
                     $ptp->setValue('ifmac', $child);
                     break;
                 case 'IP':
                     PluginFusioninventorySnmphistory::networking_ports_addLog($ptp->getValue('ID'), $child, strtolower($name));
                     $ptp->setValue('ifaddr', $child);
                     break;
                 case 'IFNUMBER':
                     PluginFusioninventorySnmphistory::networking_ports_addLog($ptp->getValue('ID'), $child, strtolower($name));
                     $ptp->setValue('logical_number', $child);
                     break;
                 case 'IFTYPE':
                     // already managed
                     break;
                 default:
                     $errors .= $LANG['plugin_fusioninventory']["errors"][22] . ' PORT : ' . $name . "\n";
             }
         }
         $this->ptd->addPort($ptp, $portIndex);
     }
     return $errors;
 }