/**
  * 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;
 }
 /**
  * Get port OID list for the SNMP model && create ports in DB if they don't exists
  *
  * @param $ID_Device : ID of device
  * @param $type : type of device (NETWORKING_TYPE, PRINTER_TYPE ...)
  * @param $oidsModel : oid list from model SNMP
  * @param $oidvalues : list of values from agent query
  * @param $ArrayPort_LogicalNum_SNMPNum : array logical port number => SNMP port number (ifindex)
  * @param $ArrayPort_LogicalNum_SNMPName : array logical port number => SNMP Port name
  *
  * @return $oidList : array with logic number => portsID from snmp
  *
  **/
 static function getOIDPorts($ID_Device, $type, $oidsModel, $oidvalues, $ArrayPort_LogicalNum_SNMPName, $ArrayPort_LogicalNum_SNMPNum)
 {
     global $DB, $LANG;
     if ($_SESSION['fusioninventory_logs'] == "1") {
         $logs = new PluginFusioninventoryLogs();
     }
     $manufCisco = new PluginFusioninventoryManufacturerCisco();
     $netwire = new Netwire();
     $np = new Netport();
     $ptp = new PluginFusioninventoryPort();
     if ($_SESSION['fusioninventory_logs'] == "1") {
         $logs->write("fusioninventory_fullsync", ">>>>>>>>>> Get OID ports list (SNMP model) and create ports in DB if not exists <<<<<<<<<<", $type, $ID_Device, 1);
     }
     $portcounter = $oidvalues[$oidsModel[1][0][""]][""];
     if ($_SESSION['fusioninventory_logs'] == "1") {
         $logs->write("fusioninventory_fullsync", "oid port counter : " . $oidsModel[1][0][""] . " = " . $portcounter, $type, $ID_Device, 1);
     }
     $oid_ifType = $oidsModel[0][1]['ifType'];
     if ($_SESSION['fusioninventory_logs'] == "1") {
         $logs->write("fusioninventory_fullsync", "type of port : " . $oid_ifType, $type, $ID_Device, 1);
     }
     asort($ArrayPort_LogicalNum_SNMPNum);
     // Reorder ports with good logic number
     $query = "SELECT `last_PID_update`\n             FROM `glpi_plugin_fusioninventory_networking`\n             WHERE `FK_networking`='" . $ID_Device . "'\n                   AND `last_PID_update`='0';";
     $result = $DB->query($query);
     if ($DB->numrows($result) == 1) {
         foreach ($ArrayPort_LogicalNum_SNMPNum as $num => $ifIndex) {
             $query_update = "UPDATE `glpi_networking_ports`\n                          SET `logical_number`='" . $ifIndex . "'\n                          WHERE `on_device`='" . $ID_Device . "'\n                                AND `device_type`='" . $type . "'\n                                AND `name`='" . $ArrayPort_LogicalNum_SNMPName[$num] . "';";
             $DB->query($query_update);
         }
     }
     // Get query SNMP to have number of ports
     if (isset($portcounter) and !empty($portcounter)) {
         // ** Add ports in DataBase if they don't exists
         $logicalnumberlist = "(";
         foreach ($ArrayPort_LogicalNum_SNMPNum as $num => $ifIndex) {
             //$i is the logical number
             $logicalnumberlist .= $ifIndex . ",";
             //for ($i=0 ; $i < $portcounter ; $i++) {
             // Get type of port
             $ifType = $oidvalues[$oid_ifType . "." . $ArrayPort_LogicalNum_SNMPNum[$num]][""];
             $oidList[$i] = $ArrayPort_LogicalNum_SNMPNum[$num];
             if (strstr($ifType, "ethernetCsmacd") or $ifType == "6" or $ifType == "ethernet-csmacd(6)" or strstr($ifType, "iso88023Csmacd") or $ifType == "7") {
                 $goodname = 1;
                 if ($manufCisco->ListVirtualPorts($oidvalues[".1.3.6.1.2.1.1.1.0"][""], $ArrayPort_LogicalNum_SNMPName[$num]) == true) {
                     $goodname = 0;
                     $deleteportname[] = $ifIndex;
                     unset($oidList[$ifIndex]);
                 }
                 if ($goodname == 1) {
                     $query = "SELECT `ID`, `name`\n                         FROM `glpi_networking_ports`\n                         WHERE `on_device`='" . $ID_Device . "'\n                               AND `device_type`='" . $type . "'\n                               AND `logical_number`='" . $ifIndex . "';";
                     $result = $DB->query($query);
                     if ($DB->numrows($result) == 0) {
                         unset($array);
                         $array["logical_number"] = $ifIndex;
                         $array["name"] = $ArrayPort_LogicalNum_SNMPName[$num];
                         $array["on_device"] = $ID_Device;
                         $array["device_type"] = $type;
                         $IDport = $np->add($array);
                         Event::log(0, "networking", 5, "inventory", "FusionInventory " . $LANG["log"][70]);
                         if ($_SESSION['fusioninventory_logs'] == "1") {
                             $logs->write("fusioninventory_fullsync", "Add port in DB (glpi_networking_ports) : " . $ArrayPort_LogicalNum_SNMPName[$i], $type, $ID_Device, 1);
                         }
                     } else {
                         $IDport = $DB->result($result, 0, "ID");
                         if ($DB->result($result, 0, "name") != $ArrayPort_LogicalNum_SNMPName[$num]) {
                             unset($array);
                             $array["name"] = $ArrayPort_LogicalNum_SNMPName[$num];
                             $array["ID"] = $DB->result($result, 0, "ID");
                             $np->update($array);
                             if ($_SESSION['fusioninventory_logs'] == "1") {
                                 $logs->write("fusioninventory_fullsync", "Update port in DB (glpi_networking_ports) : ID" . $DB->result($result, 0, "ID") . " & name " . $ArrayPort_LogicalNum_SNMPName[$i], $type, $ID_Device, 1);
                             }
                         }
                     }
                     if ($type == NETWORKING_TYPE) {
                         $queryFusionInventoryPort = "SELECT `ID`\n                                       FROM `glpi_plugin_fusioninventory_networking_ports`\n                                       WHERE `FK_networking_ports`='" . $IDport . "';";
                         $resultFusionInventoryPort = $DB->query($queryFusionInventoryPort);
                         if ($DB->numrows($resultFusionInventoryPort) == 0) {
                             $queryInsert = "INSERT INTO `glpi_plugin_fusioninventory_networking_ports`\n                                                 (`FK_networking_ports`)\n                                     VALUES ('" . $IDport . "');";
                             $DB->query($queryInsert);
                             if ($_SESSION['fusioninventory_logs'] == "1") {
                                 $logs->write("fusioninventory_fullsync", "Add port in DB (glpi_plugin_fusioninventory_networking_ports) : ID " . $IDport, $type, $ID_Device, 1);
                             }
                         }
                     }
                 }
             }
         }
         $logicalnumberlist .= ")";
     }
     // Delete all ports that will be not here
     $nn = new NetworkPort_NetworkPort();
     foreach ($deleteportname as $id => $i) {
         $query = "SELECT *\n                FROM `glpi_networking_ports`\n                WHERE `on_device`='" . $ID_Device . "'\n                      AND `device_type`='" . $type . "'\n                      AND `logical_number`='" . $i . "';";
         $result = $DB->query($query);
         $data = $DB->fetch_assoc($result);
         PluginFusioninventorySnmphistory::addLogConnection("remove", $netwire->getOppositeContact($data['ID']), $FK_process);
         PluginFusioninventorySnmphistory::addLogConnection("remove", $data['ID'], $FK_process);
         if ($nn->getFromDBForNetworkPort($data['ID'])) {
             $nn->delete($data);
         }
         $ptp->deleteFromDB($data["ID"], 1);
         $np->delete($data);
     }
     // Delete ports where logical number in glpi_plugin_fusioninventory_networking_ports
     // not exist on switch : it's ports reorder not well
     $logicalnumberlist = str_replace(",)", ")", $logicalnumberlist);
     $query = "SELECT *\n             FROM `glpi_networking_ports`\n             WHERE `on_device`='" . $ID_Device . "'\n                   AND `device_type`='" . $type . "'\n                   AND `logical_number` NOT IN " . $logicalnumberlist . ";";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         PluginFusioninventorySnmphistory::addLogConnection("remove", $netwire->getOppositeContact($data['ID']), $FK_process);
         PluginFusioninventorySnmphistory::addLogConnection("remove", $data['ID'], $FK_process);
         if ($nn->getFromDBForNetworkPort($data['ID'])) {
             $nn->delete($data);
         }
         $np->delete($data);
         $query_delete = "DELETE FROM `glpi_plugin_fusioninventory_networking_ports`\n                       WHERE `FK_networking_ports`='" . $data["ID"] . "';";
         $DB->query($query_delete);
     }
     return $oidList;
 }
 /**
  * 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 '';
 }
 static function clean_db()
 {
     global $DB;
     $ptp = new PluginFusioninventoryPort();
     $pti = new PluginFusioninventoryIfaddr();
     $ptn = new PluginFusioninventoryNetworking2();
     $ptpr = new PluginFusioninventoryPrinters();
     $ptpc = new PluginFusioninventoryPrintersCartridges();
     $ptph = new PluginFusioninventoryPrintersHistory();
     // * Clean glpi_plugin_fusioninventory_networking_ports
     $query_select = "SELECT `glpi_plugin_fusioninventory_networking_ports`.`ID`\n                       FROM `glpi_plugin_fusioninventory_networking_ports`\n                             LEFT JOIN `glpi_networking_ports`\n                                       ON `glpi_networking_ports`.`ID` = `FK_networking_ports`\n                             LEFT JOIN `glpi_networking` ON `glpi_networking`.`ID` = `on_device`\n                       WHERE `glpi_networking`.`ID` IS NULL";
     $result = $DB->query($query_select);
     while ($data = $DB->fetch_array($result)) {
         $ptp->deleteFromDB($data["ID"], 1);
     }
     // * Clean glpi_plugin_fusioninventory_networking_ifaddr
     $query_select = "SELECT `glpi_plugin_fusioninventory_networking_ifaddr`.`ID`\n                       FROM `glpi_plugin_fusioninventory_networking_ifaddr`\n                             LEFT JOIN `glpi_networking` ON `glpi_networking`.`ID` = `FK_networking`\n                       WHERE `glpi_networking`.`ID` IS NULL";
     $result = $DB->query($query_select);
     while ($data = $DB->fetch_array($result)) {
         $pti->deleteFromDB($data["ID"], 1);
     }
     // * Clean glpi_plugin_fusioninventory_networking
     $query_select = "SELECT `glpi_plugin_fusioninventory_networking`.`ID`\n                       FROM `glpi_plugin_fusioninventory_networking`\n                             LEFT JOIN `glpi_networking` ON `glpi_networking`.`ID` = `FK_networking`\n                       WHERE `glpi_networking`.`ID` IS NULL";
     $result = $DB->query($query_select);
     while ($data = $DB->fetch_array($result)) {
         $ptn->deleteFromDB($data["ID"], 1);
     }
     // * Clean glpi_plugin_fusioninventory_printers
     $query_select = "SELECT `glpi_plugin_fusioninventory_printers`.`ID`\n                       FROM `glpi_plugin_fusioninventory_printers`\n                             LEFT JOIN `glpi_printers` ON `glpi_printers`.`ID` = `FK_printers`\n                       WHERE `glpi_printers`.`ID` IS NULL";
     $result = $DB->query($query_select);
     while ($data = $DB->fetch_array($result)) {
         $ptpr->deleteFromDB($data["ID"], 1);
     }
     // * Clean glpi_plugin_fusioninventory_printers_cartridges
     $query_select = "SELECT `glpi_plugin_fusioninventory_printers_cartridges`.`ID`\n                       FROM `glpi_plugin_fusioninventory_printers_cartridges`\n                             LEFT JOIN `glpi_printers` ON `glpi_printers`.`ID` = `FK_printers`\n                       WHERE `glpi_printers`.`ID` IS NULL";
     $result = $DB->query($query_select);
     while ($data = $DB->fetch_array($result)) {
         $ptpc->deleteFromDB($data["ID"], 1);
     }
     // * Clean glpi_plugin_fusioninventory_printers_history
     $query_select = "SELECT `glpi_plugin_fusioninventory_printers_history`.`ID`\n                       FROM `glpi_plugin_fusioninventory_printers_history`\n                             LEFT JOIN `glpi_printers` ON `glpi_printers`.`ID` = `FK_printers`\n                       WHERE `glpi_printers`.`ID` IS NULL";
     $result = $DB->query($query_select);
     while ($data = $DB->fetch_array($result)) {
         $ptph->deleteFromDB($data["ID"], 1);
     }
 }
 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']);
         }
     }
 }
function plugin_fusioninventory_giveItem($type, $ID, $data, $num)
{
    global $CFG_GLPI, $DB, $INFOFORM_PAGES, $LINK_ID_TABLE, $LANG, $SEARCH_OPTION, $FUSIONINVENTORY_MAPPING;
    $table = $SEARCH_OPTION[$type][$ID]["table"];
    $field = $SEARCH_OPTION[$type][$ID]["field"];
    //	echo "GiveItem : ".$field."<br/>";
    switch ($type) {
        // * Computer List (front/computer.php)
        case COMPUTER_TYPE:
            switch ($table . '.' . $field) {
                // ** FusionInventory - switch
                case "glpi_plugin_fusioninventory_networking.ID":
                    $out = '';
                    include_once GLPI_ROOT . "/inc/networking.class.php";
                    $netport = new Netport();
                    $list = explode("\$\$\$\$", $data["ITEM_{$num}"]);
                    foreach ($list as $numtmp => $vartmp) {
                        $netport->getDeviceData($vartmp, NETWORKING_TYPE);
                        $out .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/" . $INFOFORM_PAGES[NETWORKING_TYPE] . "?ID=" . $vartmp . "\">";
                        $out .= $netport->device_name;
                        $out .= $vartmp;
                        if ($CFG_GLPI["view_ID"]) {
                            $out .= " (" . $vartmp . ")";
                        }
                        $out .= "</a><br/>";
                    }
                    return "<center>" . $out . "</center>";
                    break;
                    // ** FusionInventory - switch port
                // ** FusionInventory - switch port
                case "glpi_plugin_fusioninventory_networking_ports.ID":
                    $out = '';
                    include_once GLPI_ROOT . "/inc/networking.class.php";
                    if (!empty($data["ITEM_{$num}"])) {
                        $list = explode("\$\$\$\$", $data["ITEM_{$num}"]);
                        $np = new Netport();
                        foreach ($list as $numtmp => $vartmp) {
                            $np->getFromDB($vartmp);
                            $out .= "<a href='" . GLPI_ROOT . "/front/networking.port.php?ID=" . $vartmp . "'>" . $np->fields["name"] . "</a><br/>";
                        }
                    }
                    return "<center>" . $out . "</center>";
                    break;
            }
            break;
            // * Networking List (front/networking.php)
        // * Networking List (front/networking.php)
        case NETWORKING_TYPE:
            switch ($table . '.' . $field) {
                // ** FusionInventory - last inventory
                case "glpi_plugin_fusioninventory_networking.FK_networking":
                    $query = "SELECT *\n                         FROM `glpi_plugin_fusioninventory_networking`\n                         WHERE `FK_networking` = '" . $data["ID"] . "';";
                    if ($result = $DB->query($query)) {
                        $data2 = $DB->fetch_array($result);
                    }
                    $last_date = "";
                    if (isset($data2["last_fusioninventory_update"])) {
                        $last_date = $data2["last_fusioninventory_update"];
                    }
                    $out = "<div align='center'>" . convDateTime($last_date) . "</div>";
                    return $out;
                    break;
                    // ** FusionInventory - SNMP models
                // ** FusionInventory - SNMP models
                case "glpi_plugin_fusioninventory_model_infos.ID":
                    $plugin_fusioninventory_snmp = new PluginFusioninventorySNMP();
                    $FK_model_DB = $plugin_fusioninventory_snmp->GetSNMPModel($data["ID"], $type);
                    $out = "<a href=\"" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/front/models.form.php?ID=" . $FK_model_DB . "\">";
                    $out .= Dropdown::getDropdownName("glpi_plugin_fusioninventory_model_infos", $FK_model_DB, 0);
                    $out .= "</a>";
                    return "<center>" . $out . "</center>";
                    break;
                    // ** FusionInventory - SNMP authentification
                // ** FusionInventory - SNMP authentification
                case "glpi_plugin_fusioninventory_snmpauths.name":
                    $plugin_fusioninventory_snmp = new PluginFusioninventorySnmpauth();
                    $FK_auth_DB = $plugin_fusioninventory_snmp->GetSNMPAuth($data["ID"], $type);
                    $out = "<a href=\"" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/front/snmp_auth.form.php?ID=" . $FK_auth_DB . "\">";
                    $out .= Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpauths", $FK_auth_DB, 0);
                    $out .= "</a>";
                    return "<center>" . $out . "</center>";
                    break;
            }
            break;
            // * Printer List (front/printer.php)
        // * Printer List (front/printer.php)
        case PRINTER_TYPE:
            switch ($table . '.' . $field) {
                // ** FusionInventory - switch
                case "glpi_plugin_fusioninventory_networking.ID":
                    $out = '';
                    include_once GLPI_ROOT . "/inc/networking.class.php";
                    $netport = new Netport();
                    $list = explode("\$\$\$\$", $data["ITEM_{$num}"]);
                    foreach ($list as $numtmp => $vartmp) {
                        $netport->getDeviceData($vartmp, NETWORKING_TYPE);
                        $out .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/" . $INFOFORM_PAGES[NETWORKING_TYPE] . "?ID=" . $vartmp . "\">";
                        $out .= $netport->device_name;
                        if ($CFG_GLPI["view_ID"]) {
                            $out .= " (" . $vartmp . ")";
                        }
                        $out .= "</a><br/>";
                    }
                    return "<center>" . $out . "</center>";
                    break;
                    // ** FusionInventory - switch port
                // ** FusionInventory - switch port
                case "glpi_plugin_fusioninventory_networking_ports.ID":
                    $out = '';
                    include_once GLPI_ROOT . "/inc/networking.class.php";
                    if (!empty($data["ITEM_{$num}"])) {
                        $list = explode("\$\$\$\$", $data["ITEM_{$num}"]);
                        $np = new Netport();
                        foreach ($list as $numtmp => $vartmp) {
                            $np->getFromDB($vartmp);
                            $out .= "<a href='" . GLPI_ROOT . "/front/networking.port.php?ID=" . $vartmp . "'>" . $np->fields["name"] . "</a><br/>";
                        }
                    }
                    return "<center>" . $out . "</center>";
                    break;
                    // ** FusionInventory - last inventory
                // ** FusionInventory - last inventory
                case "glpi_plugin_fusioninventory_printers.FK_printers":
                    $query = "SELECT *\n                         FROM `glpi_plugin_fusioninventory_printers`\n                         WHERE `FK_printers` = '" . $data["ID"] . "';";
                    if ($result = $DB->query($query)) {
                        $data2 = $DB->fetch_array($result);
                    }
                    $last_date = "";
                    if (isset($data2["last_fusioninventory_update"])) {
                        $last_date = $data2["last_fusioninventory_update"];
                    }
                    $out = "<div align='center'>" . convDateTime($last_date) . "</div>";
                    return $out;
                    break;
                    // ** FusionInventory - SNMP models
                // ** FusionInventory - SNMP models
                case "glpi_plugin_fusioninventory_model_infos.ID":
                    $plugin_fusioninventory_snmp = new PluginFusioninventorySNMP();
                    $FK_model_DB = $plugin_fusioninventory_snmp->GetSNMPModel($data["ID"], $type);
                    $out = "<a href=\"" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/front/models.form.php?ID=" . $FK_model_DB . "\">";
                    $out .= Dropdown::getDropdownName("glpi_plugin_fusioninventory_model_infos", $FK_model_DB, 0);
                    $out .= "</a>";
                    return "<center>" . $out . "</center>";
                    break;
                    // ** FusionInventory - SNMP authentification
                // ** FusionInventory - SNMP authentification
                case "glpi_plugin_fusioninventory_snmpauths.ID":
                    $plugin_fusioninventory_snmp = new PluginFusioninventorySnmpauth();
                    $FK_auth_DB = $plugin_fusioninventory_snmp->GetSNMPAuth($data["ID"], $type);
                    $out = "<a href=\"" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/front/snmp_auth.form.php?ID=" . $FK_auth_DB . "\">";
                    $out .= Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpauths", $FK_auth_DB, 0);
                    $out .= "</a>";
                    return "<center>" . $out . "</center>";
                    break;
            }
            break;
            // * Model List (plugins/fusioninventory/front/models.php)
        // * Model List (plugins/fusioninventory/front/models.php)
        case PLUGIN_FUSIONINVENTORY_MODEL:
            switch ($table . '.' . $field) {
                // ** Name of type of model (network, printer...)
                case "glpi_plugin_fusioninventory_model_infos.device_type":
                    $out = '<center> ';
                    switch ($data["ITEM_{$num}"]) {
                        case COMPUTER_TYPE:
                            $out .= $LANG["Menu"][0];
                            break;
                        case NETWORKING_TYPE:
                            $out .= $LANG["Menu"][1];
                            break;
                        case PRINTER_TYPE:
                            $out .= $LANG["Menu"][2];
                            break;
                        case PERIPHERAL_TYPE:
                            $out .= $LANG["Menu"][16];
                            break;
                        case PHONE_TYPE:
                            $out .= $LANG["Menu"][34];
                            break;
                    }
                    $out .= '</center>';
                    return $out;
                    break;
                    // ** Display pic / link for exporting model
                // ** Display pic / link for exporting model
                case "glpi_plugin_fusioninventory_model_infos.ID":
                    $out = "<div align='center'><form></form><form method='get' action='" . GLPI_ROOT . "/plugins/fusioninventory/front/models.export.php' target='_blank'>\n\t\t\t\t\t\t<input type='hidden' name='model' value='" . $data["ID"] . "' />\n\t\t\t\t\t\t<input name='export' src='" . GLPI_ROOT . "/pics/right.png' title='Exporter' value='Exporter' type='image'>\n\t\t\t\t\t\t</form></div>";
                    return "<center>" . $out . "</center>";
                    break;
            }
            break;
            // * Authentification List (plugins/fusioninventory/front/snmp_auth.php)
        // * Authentification List (plugins/fusioninventory/front/snmp_auth.php)
        case PLUGIN_FUSIONINVENTORY_SNMP_AUTH:
            switch ($table . '.' . $field) {
                // ** Hidden auth passphrase (SNMP v3)
                case "glpi_plugin_fusioninventory_snmpauths.auth_passphrase":
                    $out = "";
                    if (empty($data["ITEM_{$num}"])) {
                    } else {
                        $out = "********";
                    }
                    return $out;
                    break;
                    // ** Hidden priv passphrase (SNMP v3)
                // ** Hidden priv passphrase (SNMP v3)
                case "glpi_plugin_fusioninventory_snmpauths.priv_passphrase":
                    $out = "";
                    if (empty($data["ITEM_{$num}"])) {
                    } else {
                        $out = "********";
                    }
                    return $out;
                    break;
            }
            break;
            // * Unknown mac addresses connectd on switch - report (plugins/fusioninventory/report/unknown_mac.php)
        // * Unknown mac addresses connectd on switch - report (plugins/fusioninventory/report/unknown_mac.php)
        case PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN:
            switch ($table . '.' . $field) {
                // ** FusionInventory - switch
                case "glpi_plugin_fusioninventory_networking.ID":
                    $out = '';
                    include_once GLPI_ROOT . "/inc/networking.class.php";
                    $netport = new Netport();
                    $list = explode("\$\$\$\$", $data["ITEM_{$num}"]);
                    foreach ($list as $numtmp => $vartmp) {
                        $netport->getDeviceData($vartmp, PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN);
                        $out .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/" . $INFOFORM_PAGES[PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN] . "?ID=" . $vartmp . "\">";
                        $out .= $netport->device_name;
                        if ($CFG_GLPI["view_ID"]) {
                            $out .= " (" . $vartmp . ")";
                        }
                        $out .= "</a><br/>";
                    }
                    return "<center>" . $out . "</center>";
                    break;
                    // ** FusionInventory - switch port
                // ** FusionInventory - switch port
                case "glpi_plugin_fusioninventory_networking_ports.ID":
                    $out = '';
                    include_once GLPI_ROOT . "/inc/networking.class.php";
                    if (!empty($data["ITEM_{$num}"])) {
                        $list = explode("\$\$\$\$", $data["ITEM_{$num}"]);
                        $np = new Netport();
                        foreach ($list as $numtmp => $vartmp) {
                            $np->getFromDB($vartmp);
                            $out .= "<a href='" . GLPI_ROOT . "/front/networking.port.php?ID=" . $vartmp . "'>" . $np->fields["name"] . "</a><br/>";
                        }
                    }
                    return "<center>" . $out . "</center>";
                    break;
                case "glpi_plugin_fusioninventory_unknown_device.type":
                    $out = '<center> ';
                    switch ($data["ITEM_{$num}"]) {
                        case COMPUTER_TYPE:
                            $out .= $LANG["Menu"][0];
                            break;
                        case NETWORKING_TYPE:
                            $out .= $LANG["Menu"][1];
                            break;
                        case PRINTER_TYPE:
                            $out .= $LANG["Menu"][2];
                            break;
                        case PERIPHERAL_TYPE:
                            $out .= $LANG["Menu"][16];
                            break;
                        case PHONE_TYPE:
                            $out .= $LANG["Menu"][34];
                            break;
                    }
                    $out .= '</center>';
                    return $out;
                    break;
            }
            break;
            // *
        // *
        case PLUGIN_FUSIONINVENTORY_SNMP_NETWORKING_PORTS:
            switch ($table . '.' . $field) {
            }
            break;
            // * Ports date connection - report (plugins/fusioninventory/report/ports_date_connections.php)
        // * Ports date connection - report (plugins/fusioninventory/report/ports_date_connections.php)
        case PLUGIN_FUSIONINVENTORY_SNMP_NETWORKING_PORTS2:
            switch ($table . '.' . $field) {
                // ** Name and link of networking device (switch)
                case "glpi_plugin_fusioninventory_networking_ports.ID":
                    $query = "SELECT `glpi_networking`.`name` AS `name`, `glpi_networking`.`ID` AS `ID`\n                         FROM `glpi_networking`\n                              LEFT JOIN `glpi_networking_ports`\n                                        ON `on_device` = `glpi_networking`.`ID`\n                              LEFT JOIN `glpi_plugin_fusioninventory_networking_ports`\n                                        ON `glpi_networking_ports`.`ID`=`FK_networking_ports`\n                         WHERE `glpi_plugin_fusioninventory_networking_ports`.`ID`='" . $data["ITEM_{$num}"] . "'\n                         LIMIT 0,1;";
                    $result = $DB->query($query);
                    $data2 = $DB->fetch_assoc($result);
                    $out = "<a href='" . GLPI_ROOT . "/front/networking.form.php?ID=" . $data2["ID"] . "'>" . $data2["name"] . "</a>";
                    return "<center>" . $out . "</center>";
                    break;
                    // ** Name and link of port of networking device (port of switch)
                // ** Name and link of port of networking device (port of switch)
                case "glpi_plugin_fusioninventory_networking_ports.FK_networking_ports":
                    $netport = new Netport();
                    $netport->getFromDB($data["ITEM_{$num}"]);
                    $name = "";
                    if (isset($netport->fields["name"])) {
                        $name = $netport->fields["name"];
                    }
                    $out = "<a href='" . GLPI_ROOT . "/front/networking.port.php?ID=" . $data["ITEM_{$num}"] . "'>" . $name . "</a>";
                    return "<center>" . $out . "</center>";
                    break;
                    // ** Location of switch
                // ** Location of switch
                case "glpi_dropdown_locations.ID":
                    $out = Dropdown::getDropdownName("glpi_dropdown_locations", $data["ITEM_{$num}"]);
                    return "<center>" . $out . "</center>";
                    break;
            }
            break;
            // * FusionInventory Agents list (plugins/fusioninventory/front/agents.php)
        // * FusionInventory Agents list (plugins/fusioninventory/front/agents.php)
        case PLUGIN_FUSIONINVENTORY_SNMP_AGENTS:
            break;
            // * range IP list (plugins/fusioninventory/front/rangeip.php)
        // * range IP list (plugins/fusioninventory/front/rangeip.php)
        case PLUGIN_FUSIONINVENTORY_SNMP_RANGEIP:
            switch ($table . '.' . $field) {
                // ** Display entity name
                case "glpi_entities.name":
                    if ($data["ITEM_{$num}"] == '') {
                        $out = Dropdown::getDropdownName("glpi_entities", $data["ITEM_{$num}"]);
                        return "<center>" . $out . "</center>";
                    }
                    break;
            }
            break;
            // * Detail of ports history (plugins/fusioninventory/report/switch_ports.history.php)
        // * Detail of ports history (plugins/fusioninventory/report/switch_ports.history.php)
        case PLUGIN_FUSIONINVENTORY_SNMP_HISTORY:
            switch ($table . '.' . $field) {
                // ** Display switch and Port
                case "glpi_networking_ports.ID":
                    $Array_device = PluginFusioninventoryPort::getUniqueObjectfieldsByportID($data["ITEM_{$num}"]);
                    $CommonItem = new CommonItem();
                    $CommonItem->getFromDB($Array_device["device_type"], $Array_device["on_device"]);
                    $out = "<div align='center'>" . $CommonItem->getLink(1);
                    $query = "SELECT *\n                         FROM `glpi_networking_ports`\n                         WHERE `ID`='" . $data["ITEM_{$num}"] . "';";
                    $result = $DB->query($query);
                    if ($DB->numrows($result) != "0") {
                        $out .= "<br/><a href='" . GLPI_ROOT . "/front/networking.port.php?ID=" . $data["ITEM_{$num}"] . "'>" . $DB->result($result, 0, "name") . "</a>";
                    }
                    $out .= "</td>";
                    return $out;
                    break;
                    // ** Display GLPI field of device
                // ** Display GLPI field of device
                case "glpi_plugin_fusioninventory_snmphistories.Field":
                    $out = $FUSIONINVENTORY_MAPPING[NETWORKING_TYPE][$data["ITEM_{$num}"]]['name'];
                    return $out;
                    break;
                    // ** Display Old Value (before changement of value)
                // ** Display Old Value (before changement of value)
                case "glpi_plugin_fusioninventory_snmphistories.old_value":
                    // TODO ADD LINK TO DEVICE
                    if (substr_count($data["ITEM_{$num}"], ":") == 5 and empty($data["ITEM_3"])) {
                        return "<center><b>" . $data["ITEM_{$num}"] . "</b></center>";
                    }
                    break;
                    // ** Display New Value (new value modified)
                // ** Display New Value (new value modified)
                case "glpi_plugin_fusioninventory_snmphistories.new_value":
                    if (substr_count($data["ITEM_{$num}"], ":") == 5 and empty($data["ITEM_3"])) {
                        return "<center><b>" . $data["ITEM_{$num}"] . "</b></center>";
                    }
                    break;
            }
            break;
    }
    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;
 }