unassignVlan() public method

public unassignVlan ( $portID, $vlanID )
$portID
$vlanID
function plugin_item_purge_fusioninventory($parm)
{
    switch (get_class($parm)) {
        case 'NetworkPort_NetworkPort':
            // If remove connection of a hub port (unknown device), we must delete this port too
            $NetworkPort = new NetworkPort();
            $NetworkPort_Vlan = new NetworkPort_Vlan();
            $pfUnmanaged = new PluginFusioninventoryUnmanaged();
            $networkPort_NetworkPort = new NetworkPort_NetworkPort();
            $a_hubs = array();
            $port_id = $NetworkPort->getContact($parm->getField('networkports_id_1'));
            $NetworkPort->getFromDB($parm->getField('networkports_id_1'));
            if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
                $pfUnmanaged->getFromDB($NetworkPort->fields['items_id']);
                if ($pfUnmanaged->fields['hub'] == '1') {
                    $a_hubs[$NetworkPort->fields['items_id']] = 1;
                    $NetworkPort->delete($NetworkPort->fields);
                }
            }
            $NetworkPort->getFromDB($port_id);
            if ($port_id) {
                if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
                    $pfUnmanaged->getFromDB($NetworkPort->fields['items_id']);
                    if ($pfUnmanaged->fields['hub'] == '1') {
                        $a_hubs[$NetworkPort->fields['items_id']] = 1;
                    }
                }
            }
            $port_id = $NetworkPort->getContact($parm->getField('networkports_id_2'));
            $NetworkPort->getFromDB($parm->getField('networkports_id_2'));
            if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
                if ($pfUnmanaged->getFromDB($NetworkPort->fields['items_id'])) {
                    if ($pfUnmanaged->fields['hub'] == '1') {
                        $a_vlans = $NetworkPort_Vlan->getVlansForNetworkPort($NetworkPort->fields['id']);
                        foreach ($a_vlans as $vlan_id) {
                            $NetworkPort_Vlan->unassignVlan($NetworkPort->fields['id'], $vlan_id);
                        }
                        $a_hubs[$NetworkPort->fields['items_id']] = 1;
                        $NetworkPort->delete($NetworkPort->fields);
                    }
                }
            }
            if ($port_id) {
                $NetworkPort->getFromDB($port_id);
                if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') {
                    $pfUnmanaged->getFromDB($NetworkPort->fields['items_id']);
                    if ($pfUnmanaged->fields['hub'] == '1') {
                        $a_hubs[$NetworkPort->fields['items_id']] = 1;
                    }
                }
            }
            // If hub have no port, delete it
            foreach (array_keys($a_hubs) as $unkowndevice_id) {
                $a_networkports = $NetworkPort->find("`itemtype`='PluginFusioninventoryUnmanaged'\n               AND `items_id`='" . $unkowndevice_id . "' ");
                if (count($a_networkports) < 2) {
                    $pfUnmanaged->delete(array('id' => $unkowndevice_id), 1);
                } else {
                    if (count($a_networkports) == '2') {
                        $switchPorts_id = 0;
                        $otherPorts_id = 0;
                        foreach ($a_networkports as $data) {
                            if ($data['name'] == 'Link') {
                                $switchPorts_id = $NetworkPort->getContact($data['id']);
                            } else {
                                if ($otherPorts_id == '0') {
                                    $otherPorts_id = $NetworkPort->getContact($data['id']);
                                } else {
                                    $switchPorts_id = $NetworkPort->getContact($data['id']);
                                }
                            }
                        }
                        $pfUnmanaged->disconnectDB($switchPorts_id);
                        // disconnect this port
                        $pfUnmanaged->disconnectDB($otherPorts_id);
                        // disconnect destination port
                        $networkPort_NetworkPort->add(array('networkports_id_1' => $switchPorts_id, 'networkports_id_2' => $otherPorts_id));
                    }
                }
            }
            break;
        case 'NetworkEquipment':
            // Delete all ports
            $query_delete = "DELETE FROM `glpi_plugin_fusioninventory_networkequipments`\n                          WHERE `networkequipments_id`='" . $parm->fields["id"] . "';";
            $DB->query($query_delete);
            $query_select = "SELECT `glpi_plugin_fusioninventory_networkports`.`id`,\n                              `glpi_networkports`.`id` as nid\n                          FROM `glpi_plugin_fusioninventory_networkports`\n                               LEFT JOIN `glpi_networkports`\n                                         ON `glpi_networkports`.`id` = `networkports_id`\n                          WHERE `items_id`='" . $parm->fields["id"] . "'\n                                AND `itemtype`='NetworkEquipment';";
            $result = $DB->query($query_select);
            while ($data = $DB->fetch_array($result)) {
                $query_delete = "DELETE FROM `glpi_plugin_fusioninventory_networkports`\n                             WHERE `id`='" . $data["id"] . "';";
                $DB->query($query_delete);
                $query_delete = "DELETE FROM `glpi_plugin_fusinvsnmp_networkportlogs`\n                           WHERE `networkports_id`='" . $data['nid'] . "'";
                $DB->query($query_delete);
            }
            break;
        case "Printer":
            $query_delete = "DELETE FROM `glpi_plugin_fusioninventory_printers`\n                          WHERE `printers_id`='" . $parm->fields["id"] . "';";
            $DB->query($query_delete);
            $query_delete = "DELETE FROM `glpi_plugin_fusioninventory_printercartridges`\n                          WHERE `printers_id`='" . $parm->fields["id"] . "';";
            $DB->query($query_delete);
            $query_delete = "DELETE FROM `glpi_plugin_fusioninventory_printerlogs`\n                          WHERE `printers_id`='" . $parm->fields["id"] . "';";
            $DB->query($query_delete);
            break;
        case 'PluginFusioninventoryUnmanaged':
            $query_delete = "DELETE FROM `glpi_plugin_fusinvsnmp_unmanageds`\n                          WHERE `plugin_fusioninventory_unmanageds_id`='" . $parm->fields["id"] . "';";
            $DB->query($query_delete);
            break;
    }
    return $parm;
}
示例#2
0
 /**
  * @see CommonDBTM::doSpecificMassiveActions()
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     switch ($input['action']) {
         case "assign_vlan":
             if (!empty($input["vlans_id"])) {
                 $networkportvlan = new NetworkPort_Vlan();
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         if ($this->can($key, 'w')) {
                             if ($networkportvlan->assignVlan($key, $input["vlans_id"], isset($input['tagged']) ? '1' : '0')) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['noright']++;
                         }
                     }
                 }
             } else {
                 $res['ko']++;
             }
             break;
         case "unassign_vlan":
             if (!empty($input["vlans_id"])) {
                 $networkportvlan = new NetworkPort_Vlan();
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         if ($this->can($key, 'w')) {
                             if ($networkportvlan->unassignVlan($key, $input["vlans_id"])) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['noright']++;
                         }
                     }
                 }
             } else {
                 $nbko++;
             }
             break;
             // Interest of this massive action ? Replace switch by another : don't re-create manually all ports
         // Interest of this massive action ? Replace switch by another : don't re-create manually all ports
         case "move_port":
             if (isset($input["items_id"]) && !empty($input["items_id"])) {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         if ($this->getFromDB($key)) {
                             $input2 = array();
                             $input2['id'] = $key;
                             $input2['items_id'] = $input["items_id"];
                             $input2['itemtype'] = 'NetworkEquipment';
                             if ($this->can($input2['id'], 'w')) {
                                 if ($this->update($input2)) {
                                     $res['ok']++;
                                 } else {
                                     $res['ko']++;
                                 }
                             } else {
                                 $res['noright']++;
                             }
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             } else {
                 $res['ko']++;
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
 if (isset($_POST['assign_vlan'])) {
     $npv->check(-1, 'w', $_POST);
     if (isset($_POST["vlans_id"]) && $_POST["vlans_id"] > 0) {
         $npv->assignVlan($_POST["networkports_id"], $_POST["vlans_id"]);
         Event::log(0, "networkport", 5, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][77]);
     }
     glpi_header($_SERVER['HTTP_REFERER']);
 } else {
     if (isset($_POST["unassign_vlan_several"])) {
         checkRight("networking", "w");
         if ($_POST["vlans_id"] > 0) {
             if (isset($_POST["del_port"]) && count($_POST["del_port"])) {
                 foreach ($_POST["del_port"] as $port_id => $val) {
                     // Check port write access
                     if ($np->can($port_id, 'w')) {
                         $npv->unassignVlan($port_id, $_POST["vlans_id"]);
                     }
                 }
             }
             Event::log(0, "networkport", 5, "inventory", $_SESSION["glpiname"] . "  " . $LANG['log'][80]);
         }
         glpi_header($_SERVER['HTTP_REFERER']);
     } else {
         if (isset($_GET['unassign_vlan'])) {
             $npv->check($_GET['id'], 'd');
             $npv->unassignVlanbyID($_GET['id']);
             Event::log(0, "networkport", 5, "inventory", $_SESSION["glpiname"] . "  " . $LANG['log'][79]);
             glpi_header($_SERVER['HTTP_REFERER']);
         } else {
             if (empty($_GET["items_id"])) {
                 $_GET["items_id"] = "";