if (isset($_POST["delete_several"])) {
     Session::checkRight("networking", UPDATE);
     if (isset($_POST["del_port"]) && count($_POST["del_port"])) {
         foreach ($_POST["del_port"] as $port_id => $val) {
             if ($np->can($port_id, PURGE)) {
                 $np->delete(array("id" => $port_id));
             }
         }
     }
     Event::log(0, "networkport", 5, "inventory", sprintf(__('%s deletes several network ports'), $_SESSION["glpiname"]));
     Html::back();
 } else {
     if (isset($_POST["update"])) {
         $np->check($_POST['id'], PURGE);
         $networkport = new NetworkPort();
         if ($networkport->can($_POST['id'], UPDATE)) {
             if ($networkport->switchInstantiationType($_POST['transform_to']) !== false) {
                 $instantiation = $networkport->getInstantiation();
                 $input = $np->fields;
                 $input['networkports_id'] = $input['id'];
                 unset($input['id']);
                 if ($instantiation->add($input)) {
                     $np->delete($_POST);
                 }
             } else {
                 Session::addMessageAfterRedirect(__('Cannot change a migration network port to an unknown one'));
             }
         } else {
             Session::addMessageAfterRedirect(__('Network port is not available...'));
             $np->delete($_POST);
         }
 /**
  * @param $port   NetworkPort object
  **/
 static function showForNetworkPort(NetworkPort $port)
 {
     global $DB, $CFG_GLPI;
     $ID = $port->getID();
     if (!$port->can($ID, READ)) {
         return false;
     }
     $canedit = $port->canEdit($ID);
     $rand = mt_rand();
     $query = "SELECT `glpi_networkports_vlans`.id as assocID,\n                       `glpi_networkports_vlans`.tagged ,\n                       `glpi_vlans`.*\n                FROM `glpi_networkports_vlans`\n                LEFT JOIN `glpi_vlans`\n                        ON (`glpi_networkports_vlans`.`vlans_id` = `glpi_vlans`.`id`)\n                WHERE `networkports_id` = '{$ID}'";
     $result = $DB->query($query);
     $vlans = array();
     $used = array();
     if ($number = $DB->numrows($result)) {
         while ($line = $DB->fetch_assoc($result)) {
             $used[$line["id"]] = $line["id"];
             $vlans[$line["assocID"]] = $line;
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>\n";
         echo "<form method='post' action='" . static::getFormURL() . "'>\n";
         echo "<table class='tab_cadre_fixe'>\n";
         echo "<tr><th colspan='4'>" . __('Associate a VLAN') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         echo "<input type='hidden' name='networkports_id' value='{$ID}'>";
         Vlan::dropdown(array('used' => $used));
         echo "</td>";
         echo "<td class='right'>" . __('Tagged') . "</td>";
         echo "<td class='left'><input type='checkbox' name='tagged' value='1'></td>";
         echo "<td><input type='submit' name='add' value='" . _sx('button', 'Associate') . "' class='submit'>";
         echo "</td></tr>\n";
         echo "</table>\n";
         Html::closeForm();
         echo "</div>\n";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     $header_begin = "<tr>";
     $header_top = '';
     $header_bottom = '';
     $header_end = '';
     if ($canedit && $number) {
         $header_top .= "<th width='10'>";
         $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
         $header_bottom .= "<th width='10'>";
         $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     $header_end .= "<th>" . __('Name') . "</th>";
     $header_end .= "<th>" . __('Entity') . "</th>";
     $header_end .= "<th>" . __('Tagged') . "</th>";
     $header_end .= "<th>" . __('ID TAG') . "</th>";
     $header_end .= "</tr>";
     echo $header_begin . $header_top . $header_end;
     $used = array();
     foreach ($vlans as $data) {
         echo "<tr class='tab_bg_1'>";
         if ($canedit) {
             echo "<td>";
             Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
             echo "</td>";
         }
         $name = $data["name"];
         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
             $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
         }
         echo "<td class='center b'>\n               <a href='" . $CFG_GLPI["root_doc"] . "/front/vlan.form.php?id=" . $data["id"] . "'>" . $name . "</a>";
         echo "</td>";
         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entities_id"]);
         echo "</td><td class='center'>" . Dropdown::getYesNo($data["tagged"]) . "</td>";
         echo "<td class='numeric'>" . $data["tag"] . "</td>";
         echo "</tr>";
     }
     if ($number) {
         echo $header_begin . $header_top . $header_end;
     }
     echo "</table>";
     if ($canedit && $number) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
        Html::back();
    } else {
        Session::checkRight("networking", "w");
        $input = $_POST;
        unset($input['several']);
        unset($input['from_logical_number']);
        unset($input['to_logical_number']);
        for ($i = $_POST["from_logical_number"]; $i <= $_POST["to_logical_number"]; $i++) {
            $add = "";
            if ($i < 10) {
                $add = "0";
            }
            $input["logical_number"] = $i;
            $input["name"] = $_POST["name"] . $add . $i;
            unset($np->fields["id"]);
            if ($np->can(-1, 'w', $input)) {
                $np->splitInputForElements($input);
                $np->add($input);
                $np->updateDependencies(1);
            }
        }
        Event::log(0, "networkport", 5, "inventory", sprintf(__('%s adds several network ports'), $_SESSION["glpiname"]));
        Html::back();
    }
} else {
    if (isset($_POST["delete"])) {
        $np->check($_POST['id'], 'd');
        $np->delete($_POST);
        Event::log($_POST['id'], "networkport", 5, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
        if ($item = getItemForItemtype($np->fields['itemtype'])) {
            Html::redirect($item->getFormURL() . '?id=' . $np->fields['items_id']);
 static function showForNetworkPortForm($ID)
 {
     global $DB, $CFG_GLPI, $LANG;
     $port = new NetworkPort();
     if ($ID && $port->can($ID, 'w')) {
         echo "\n<div class='center'>";
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php'>";
         echo "<input type='hidden' name='networkports_id' value='{$ID}'>\n";
         echo "<table class='tab_cadre'>";
         echo "<tr><th>" . $LANG['setup'][90] . "</th></tr>\n";
         echo "<tr class='tab_bg_2'><td>";
         $used = self::showForNetworkPort($ID, true, 0);
         echo "</td></tr>\n";
         echo "<tr class='tab_bg_2'><td>";
         echo $LANG['networking'][55] . "&nbsp;:&nbsp;";
         Dropdown::show('Vlan', array('used' => $used));
         echo "&nbsp;<input type='submit' name='assign_vlan' value='" . $LANG['buttons'][3] . "' class='submit'>";
         echo "</td></tr>\n";
         echo "</table></form>";
     }
 }
 if (isset($_POST["delete_several"])) {
     Session::checkRight("networking", "w");
     if (isset($_POST["del_port"]) && count($_POST["del_port"])) {
         foreach ($_POST["del_port"] as $port_id => $val) {
             if ($np->can($port_id, 'd')) {
                 $np->delete(array("id" => $port_id));
             }
         }
     }
     Event::log(0, "networkport", 5, "inventory", sprintf(__('%s deletes several network ports'), $_SESSION["glpiname"]));
     Html::back();
 } else {
     if (isset($_POST["update"])) {
         $np->check($_POST['id'], 'd');
         $networkport = new NetworkPort();
         if ($networkport->can($_POST['id'], 'w')) {
             if ($networkport->switchInstantiationType($_POST['transform_to']) !== false) {
                 $instantiation = $networkport->getInstantiation();
                 $input = $np->fields;
                 $input['networkports_id'] = $input['id'];
                 unset($input['id']);
                 if ($instantiation->add($input)) {
                     $np->delete($_POST);
                 }
             } else {
                 Session::addMessageAfterRedirect(__('Cannot change a migration network port to an unknown one'));
             }
         } else {
             Session::addMessageAfterRedirect(__('Network port is not available...'));
             $np->delete($_POST);
         }
        Html::back();
    } else {
        Session::checkRight("networking", UPDATE);
        $input = $_POST;
        unset($input['several']);
        unset($input['from_logical_number']);
        unset($input['to_logical_number']);
        for ($i = $_POST["from_logical_number"]; $i <= $_POST["to_logical_number"]; $i++) {
            $add = "";
            if ($i < 10) {
                $add = "0";
            }
            $input["logical_number"] = $i;
            $input["name"] = $_POST["name"] . $add . $i;
            unset($np->fields["id"]);
            if ($np->can(-1, CREATE, $input)) {
                $np->splitInputForElements($input);
                $np->add($input);
                $np->updateDependencies(1);
            }
        }
        Event::log(0, "networkport", 5, "inventory", sprintf(__('%s adds several network ports'), $_SESSION["glpiname"]));
        Html::back();
    }
} else {
    if (isset($_POST["purge"])) {
        $np->check($_POST['id'], PURGE);
        $np->delete($_POST, 1);
        Event::log($_POST['id'], "networkport", 5, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
        if ($item = getItemForItemtype($np->fields['itemtype'])) {
            Html::redirect($item->getFormURL() . '?id=' . $np->fields['items_id']);
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// ----------------------------------------------------------------------
define('GLPI_ROOT', '..');
include GLPI_ROOT . "/inc/includes.php";
if (!isset($_POST['id'])) {
    exit;
}
if (!isset($_REQUEST['glpi_tab'])) {
    exit;
}
$port = new NetworkPort();
if ($_POST["id"] > 0 && $port->can($_POST["id"], 'r')) {
    switch ($_REQUEST['glpi_tab']) {
        case -1:
            // All
            NetworkPort_Vlan::showForNetworkPortForm($_POST["id"]);
            Plugin::displayAction($port, $_REQUEST['glpi_tab']);
            Log::showForItem($port);
            break;
        case 12:
            Log::showForItem($port);
            break;
        default:
            if (!Plugin::displayAction($port, $_REQUEST['glpi_tab'])) {
                NetworkPort_Vlan::showForNetworkPortForm($_POST["id"]);
            }
    }
        glpi_header($_SERVER['HTTP_REFERER']);
    } else {
        checkRight("networking", "w");
        $input = $_POST;
        unset($input['several']);
        unset($input['from_logical_number']);
        unset($input['to_logical_number']);
        for ($i = $_POST["from_logical_number"]; $i <= $_POST["to_logical_number"]; $i++) {
            $add = "";
            if ($i < 10) {
                $add = "0";
            }
            $input["logical_number"] = $i;
            $input["name"] = $_POST["name"] . $add . $i;
            unset($np->fields["id"]);
            if ($np->can(-1, 'w', $input)) {
                $np->add($input);
            }
        }
        Event::log(0, "networkport", 5, "inventory", $_SESSION["glpiname"] . "  " . ($_POST["to_logical_number"] - $_POST["from_logical_number"] + 1) . "  " . $LANG['log'][71]);
        glpi_header($_SERVER['HTTP_REFERER']);
    }
} else {
    if (isset($_POST["delete"])) {
        $np->check($_POST['id'], 'd');
        $np->delete($_POST);
        Event::log($_POST['id'], "networkport", 5, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][73]);
        if (class_exists($np->fields['itemtype'])) {
            $item = new $np->fields['itemtype']();
            glpi_header($item->getFormURL() . '?id=' . $np->fields['items_id']);
        }
 /**
  * @see CommonDBTM::doSpecificMassiveActions()
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     switch ($input['action']) {
         case "transform_to":
             if (isset($input["transform_to"]) && !empty($input["transform_to"])) {
                 $networkport = new NetworkPort();
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         if ($networkport->can($key, 'w') && $this->can($key, 'd')) {
                             // Don't try to migrate already affected ports
                             if (empty($networkport->fields['instantiation_type'])) {
                                 if ($networkport->switchInstantiationType($input['transform_to']) !== false) {
                                     $instantiation = $networkport->getInstantiation();
                                     $input2 = $this->fields;
                                     $input2['networkports_id'] = $input2['id'];
                                     unset($input2['id']);
                                     if ($instantiation->add($input2)) {
                                         $this->delete(array('id' => $key));
                                         $res['ok']++;
                                     } else {
                                         $res['ko']++;
                                     }
                                 } else {
                                     $res['ko']++;
                                 }
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['noright']++;
                         }
                     }
                 }
             } else {
                 $res['ko']++;
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }