assignVlan() 공개 메소드

public assignVlan ( $port, $vlan, $tagged )
$port
$vlan
$tagged
예제 #1
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;
 }
예제 #2
0
This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkCentralAccess();
$npv = new NetworkPort_Vlan();
if (isset($_POST["add"])) {
    $npv->check(-1, UPDATE, $_POST);
    if (isset($_POST["vlans_id"]) && $_POST["vlans_id"] > 0) {
        $npv->assignVlan($_POST["networkports_id"], $_POST["vlans_id"], isset($_POST['tagged']) ? '1' : '0');
        Event::log(0, "networkport", 5, "inventory", sprintf(__('%s associates a VLAN to a network port'), $_SESSION["glpiname"]));
    }
    Html::back();
}
Html::displayErrorAndDie('Lost');
예제 #3
0
 function post_addItem()
 {
     global $DB, $CFG_GLPI;
     // Manage add from template
     if (isset($this->input["_oldID"])) {
         // ADD Infocoms
         $ic = new Infocom();
         $ic->cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Ports
         $query = "SELECT `id`\n                   FROM `glpi_networkports`\n                   WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                         AND `itemtype` = '" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             while ($data = $DB->fetch_array($result)) {
                 $np = new NetworkPort();
                 $npv = new NetworkPort_Vlan();
                 $np->getFromDB($data["id"]);
                 unset($np->fields["id"]);
                 unset($np->fields["ip"]);
                 unset($np->fields["mac"]);
                 unset($np->fields["netpoints_id"]);
                 $np->fields["items_id"] = $this->fields['id'];
                 $portid = $np->addToDB();
                 foreach ($DB->request('glpi_networkports_vlans', array('networkports_id' => $data["id"])) as $vlan) {
                     $npv->assignVlan($portid, $vlan['vlans_id']);
                 }
             }
         }
         // ADD Contract
         $query = "SELECT `contracts_id`\n                   FROM `glpi_contracts_items`\n                   WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                         AND `itemtype` = '" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             $contractitem = new Contract_Item();
             while ($data = $DB->fetch_array($result)) {
                 $contractitem->add(array('contracts_id' => $data["contracts_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
             }
         }
         // ADD Documents
         $query = "SELECT `documents_id`\n                   FROM `glpi_documents_items`\n                   WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                         AND `itemtype` = '" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             $docitem = new Document_Item();
             while ($data = $DB->fetch_array($result)) {
                 $docitem->add(array('documents_id' => $data["documents_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
             }
         }
     }
 }
예제 #4
0
 function post_addItem()
 {
     global $DB;
     // Manage add from template
     if (isset($this->input["_oldID"])) {
         // ADD Infocoms
         $ic = new Infocom();
         if ($this->canUseInfocoms() && $ic->getFromDBforDevice($this->type, $this->input["_oldID"])) {
             $ic->fields["items_id"] = $this->fields['id'];
             unset($ic->fields["id"]);
             if (isset($ic->fields["immo_number"])) {
                 $ic->fields["immo_number"] = autoName($ic->fields["immo_number"], "immo_number", 1, 'Infocom', $this->input['entities_id']);
             }
             if (empty($ic->fields['use_date'])) {
                 unset($ic->fields['use_date']);
             }
             if (empty($ic->fields['buy_date'])) {
                 unset($ic->fields['buy_date']);
             }
             $ic->addToDB();
         }
         foreach (array('Document_Item' => 'documents_id', 'Contract_Item' => 'contracts_id') as $type => $fk) {
             $item = new $type();
             foreach ($item->find("items_id='" . $this->input["_oldID"] . "'\n                                 AND itemtype='" . $this->type . "'") as $tmpid => $data) {
                 $tmp = array();
                 $tmp['items_id'] = $this->input["_oldID"];
                 $tmp['itemtype'] = $type;
                 $tmp[$fk] = $data[$fk];
                 $item->add($tmp);
             }
         }
         if ($this->canUseNetworkPorts()) {
             // ADD Ports
             $query = "SELECT `id`\n                       FROM `glpi_networkports`\n                       WHERE `items_id` = '" . $this->input["_oldID"] . "'\n                          AND `itemtype` = '" . get_called_class() . "';";
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 while ($data = $DB->fetch_array($result)) {
                     $np = new NetworkPort();
                     $npv = new NetworkPort_Vlan();
                     $np->getFromDB($data["id"]);
                     unset($np->fields["id"]);
                     unset($np->fields["ip"]);
                     unset($np->fields["mac"]);
                     unset($np->fields["netpoints_id"]);
                     $np->fields["items_id"] = $this->fields['id'];
                     $portid = $np->addToDB();
                     foreach ($DB->request('glpi_networkports_vlans', array('networkports_id' => $data["id"])) as $vlan) {
                         $npv->assignVlan($portid, $vlan['vlans_id']);
                     }
                 }
             }
         }
     }
 }
예제 #5
0
     if (isset($_GET["id"])) {
         $nn->delete($_GET);
         $fin = "";
         if (isset($_GET["sport"])) {
             $fin = "?sport=" . $_GET["sport"];
         }
         glpi_header($_SERVER['HTTP_REFERER'] . $fin);
     }
     glpi_header($_SERVER['HTTP_REFERER']);
 } else {
     if (isset($_POST["assign_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) {
                     $npv->assignVlan($port_id, $_POST["vlans_id"]);
                 }
             }
             Event::log(0, "networkport", 5, "inventory", $_SESSION["glpiname"] . "  " . $LANG['log'][78]);
         }
         glpi_header($_SERVER['HTTP_REFERER']);
     } else {
         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"])) {