当前位置: 首页>>代码示例>>PHP>>正文


PHP NetworkPort::update方法代码示例

本文整理汇总了PHP中NetworkPort::update方法的典型用法代码示例。如果您正苦于以下问题:PHP NetworkPort::update方法的具体用法?PHP NetworkPort::update怎么用?PHP NetworkPort::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkPort的用法示例。


在下文中一共展示了NetworkPort::update方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: NetworkPort

 function _updateNetworkInfo($arrayinventory, $item_type, $id, $instanciation_type, $check_addresses)
 {
     $NetworkPort = new NetworkPort();
     $port = current($NetworkPort->find("`itemtype`='{$item_type}' AND `items_id`='{$id}'" . " AND `instantiation_type`='{$instanciation_type}'", "", 1));
     $port_id = 0;
     if (isset($port['id'])) {
         if (isset($arrayinventory['MAC']) and !empty($arrayinventory['MAC'])) {
             $input = array();
             $input['id'] = $port['id'];
             $input['mac'] = $arrayinventory['MAC'];
             $NetworkPort->update($input);
         }
         $port_id = $port['id'];
     } else {
         $input = array();
         $input['itemtype'] = $item_type;
         $input['items_id'] = $id;
         $input['instantiation_type'] = $instanciation_type;
         $input['name'] = "management";
         if (isset($arrayinventory['MAC']) && !empty($arrayinventory['MAC'])) {
             $input['mac'] = $arrayinventory['MAC'];
         }
         $port_id = $NetworkPort->add($input);
     }
     $NetworkName = new NetworkName();
     $name = current($NetworkName->find("`itemtype`='NetworkPort' AND `items_id`='" . $port_id . "'", "", 1));
     $name_id = 0;
     if (isset($name['id'])) {
         $name_id = $name['id'];
     } else {
         $input = array();
         $input['itemtype'] = 'NetworkPort';
         $input['items_id'] = $port_id;
         $name_id = $NetworkName->add($input);
     }
     if (isset($arrayinventory['IP'])) {
         $IPAddress = new IPAddress();
         if ($check_addresses) {
             $addresses = $IPAddress->find("`itemtype`='NetworkName'\n               AND `items_id`='" . $name_id . "'", '', 1);
         } else {
             // Case of NetworkEquipment
             $a_ips = $IPAddress->find("`itemtype`='NetworkName'\n               AND `items_id`='" . $name_id . "'\n               AND `name`='" . $arrayinventory['IP'] . "'", '', 1);
             if (count($a_ips) > 0) {
                 $addresses = $a_ips;
             } else {
                 $addresses = array();
             }
         }
         if (count($addresses) == 0) {
             $input = array();
             $input['itemtype'] = 'NetworkName';
             $input['items_id'] = $name_id;
             $input['name'] = $arrayinventory['IP'];
             $IPAddress->add($input);
         } else {
             $address = current($addresses);
             if ($address['name'] != $arrayinventory['IP']) {
                 $input = array();
                 $input['id'] = $address['id'];
                 $input['name'] = $arrayinventory['IP'];
                 $IPAddress->update($input);
             }
         }
     }
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:65,代码来源:communicationnetworkdiscovery.class.php

示例2: transferNetworkLink

 /**
  * Transfer network links
  *
  * @param $itemtype original type of transfered item
  * @param $ID original ID of the item
  * @param $newID new ID of the item
  * @param $ocs_computer if computer type OCS ID of the item if available
  **/
 function transferNetworkLink($itemtype, $ID, $newID, $ocs_computer = false)
 {
     global $DB;
     $np = new NetworkPort();
     $nn = new NetworkPort_NetworkPort();
     $query = "SELECT *\n                FROM `glpi_networkports`\n                WHERE `items_id` = '{$ID}'\n                      AND `itemtype` = '{$itemtype}'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             switch ($this->options['keep_networklink']) {
                 // Delete netport
                 case 0:
                     // Not a copy -> delete
                     if ($ID == $newID) {
                         while ($data = $DB->fetch_array($result)) {
                             $np->delete(array('id' => $data['id']));
                         }
                         // Only case of ocs link update is needed (if netports are keep nothing to do)
                         if ($ocs_computer) {
                             $query = "UPDATE `glpi_ocslinks`\n                                  SET `import_ip` = NULL\n                                  WHERE `computers_id` = '{$ID}'";
                             $DB->query($query);
                         }
                     }
                     // Copy -> do nothing
                     break;
                     // Disconnect
                 // Disconnect
                 case 1:
                     // Not a copy -> disconnect
                     if ($ID == $newID) {
                         while ($data = $DB->fetch_array($result)) {
                             if ($nn->getFromDBForNetworkPort($data['id'])) {
                                 $nn->delete($data);
                             }
                             if ($data['netpoints_id']) {
                                 $netpointID = $this->transferDropdownNetpoint($data['netpoints_id']);
                                 $input['id'] = $data['id'];
                                 $input['netpoints_id'] = $netpointID;
                                 $np->update($input);
                             }
                         }
                     } else {
                         // Copy -> copy netports
                         while ($data = $DB->fetch_array($result)) {
                             $data = addslashes_deep($data);
                             unset($data['id']);
                             $data['items_id'] = $newID;
                             $data['netpoints_id'] = $this->transferDropdownNetpoint($data['netpoints_id']);
                             unset($np->fields);
                             $np->add($data);
                         }
                     }
                     break;
                     // Keep network links
                 // Keep network links
                 default:
                     // Copy -> Copy netpoints (do not keep links)
                     if ($ID != $newID) {
                         while ($data = $DB->fetch_array($result)) {
                             unset($data['id']);
                             $data['items_id'] = $newID;
                             $data['netpoints_id'] = $this->transferDropdownNetpoint($data['netpoints_id']);
                             unset($np->fields);
                             $np->add($data);
                         }
                     } else {
                         while ($data = $DB->fetch_array($result)) {
                             // Not a copy -> only update netpoint
                             if ($data['netpoints_id']) {
                                 $netpointID = $this->transferDropdownNetpoint($data['netpoints_id']);
                                 $input['id'] = $data['id'];
                                 $input['netpoints_id'] = $netpointID;
                                 $np->update($input);
                             }
                         }
                     }
             }
         }
     }
 }
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:87,代码来源:transfer.class.php

示例3: replace

 /**
  * @param $type
  * @param $model_id
  * @param $tab_ids
  * @param $location
  **/
 static function replace($type, $model_id, $tab_ids, $location)
 {
     global $DB, $CFG_GLPI, $PLUGIN_HOOKS;
     $model = new PluginUninstallModel();
     $model->getConfig($model_id);
     $overwrite = $model->fields["overwrite"];
     echo "<div class='center'>";
     echo "<table class='tab_cadre_fixe'><tr><th>" . __('Replacement', 'uninstall') . "</th></tr>";
     echo "<tr class='tab_bg_2'><td>";
     $count = 0;
     $tot = count($tab_ids);
     Html::createProgressBar(__('Please wait, replacement is running...', 'uninstall'));
     foreach ($tab_ids as $olditem_id => $newitem_id) {
         $count++;
         $olditem = new $type();
         $olditem->getFromDB($olditem_id);
         $newitem = new $type();
         $newitem->getFromDB($newitem_id);
         //Hook to perform actions before item is being replaced
         $olditem->fields['_newid'] = $newitem_id;
         $olditem->fields['_uninstall_event'] = $model_id;
         $olditem->fields['_action'] = 'replace';
         Plugin::doHook("plugin_uninstall_replace_before", $olditem);
         // Retrieve informations
         //States
         if ($model->fields['states_id'] != 0) {
             $olditem->update(array('id' => $olditem_id, 'states_id' => $model->fields['states_id']), false);
         }
         // METHOD REPLACEMENT 1 : Archive
         if ($model->fields['replace_method'] == self::METHOD_PURGE) {
             $name_out = str_shuffle(Toolbox::getRandomString(5) . time());
             $plugin = new Plugin();
             if ($plugin->isActivated('PDF')) {
                 // USE PDF EXPORT
                 $plugin->load('pdf', true);
                 include_once GLPI_ROOT . "/lib/ezpdf/class.ezpdf.php";
                 //Get all item's tabs
                 $tab = array_keys($olditem->defineTabs());
                 //Tell PDF to also export item's main tab, and in first position
                 array_unshift($tab, "_main_");
                 $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($olditem);
                 $out = $itempdf->generatePDF(array($olditem_id), $tab, 1, false);
                 $name_out .= ".pdf";
             } else {
                 //TODO Which datas ? Add Defaults...
                 $out = __('Replacement', 'uninstall') . "\r\n";
                 $datas = $olditem->fields;
                 unset($datas['comment']);
                 foreach ($datas as $k => $v) {
                     $out .= $k . ";";
                 }
                 $out .= "\r\n";
                 foreach ($datas as $k => $v) {
                     $out .= $v . ";";
                 }
                 // USE CSV EXPORT
                 $name_out .= ".csv";
             }
             // Write document
             $out_file = GLPI_DOC_DIR . "/_uploads/" . $name_out;
             $open_file = fopen($out_file, 'a');
             fwrite($open_file, $out);
             fclose($open_file);
             // Compute comment text
             $comment = __('This document is the archive of this replaced item', 'uninstall') . " " . self::getCommentsForReplacement($olditem, false, false);
             // Create & Attach new document to current item
             $doc = new Document();
             $input = array('name' => addslashes(__('Archive of old material', 'uninstall')), 'upload_file' => $name_out, 'comment' => addslashes($comment), 'add' => __('Add'), 'entities_id' => $newitem->getEntityID(), 'is_recursive' => $newitem->isRecursive(), 'link' => "", 'documentcategories_id' => 0, 'items_id' => $olditem_id, 'itemtype' => $type);
             //Attached the document to the old item, to generate an accurate name
             $document_added = $doc->add($input);
             //Attach the document to the new item, once the document's name is correct
             $docItem = new Document_Item();
             $docItemId = $docItem->add(array('documents_id' => $document_added, 'itemtype' => $type, 'items_id' => (int) $newitem_id));
         }
         // General Informations - NAME
         if ($model->fields["replace_name"]) {
             if ($overwrite || empty($newitem->fields['name'])) {
                 $newitem->update(array('id' => $newitem_id, 'name' => $olditem->getField('name')), false);
             }
         }
         $data['id'] = $newitem->getID();
         // General Informations - SERIAL
         if ($model->fields["replace_serial"]) {
             if ($overwrite || empty($newitem->fields['serial'])) {
                 $newitem->update(array('id' => $newitem_id, 'serial' => $olditem->getField('serial')), false);
             }
         }
         // General Informations - OTHERSERIAL
         if ($model->fields["replace_otherserial"]) {
             if ($overwrite || empty($newitem->fields['otherserial'])) {
                 $newitem->update(array('id' => $newitem_id, 'otherserial' => $olditem->getField('otherserial')), false);
             }
         }
         // Documents
//.........这里部分代码省略.........
开发者ID:pluginsGLPI,项目名称:uninstall,代码行数:101,代码来源:replace.class.php

示例4: importPorts

 function importPorts($a_inventory, $items_id)
 {
     $networkPort = new NetworkPort();
     $pfNetworkPort = new PluginFusioninventoryNetworkPort();
     $networkports_id = 0;
     foreach ($a_inventory['networkport'] as $a_port) {
         $a_ports_DB = current($networkPort->find("`itemtype`='Printer'\n                       AND `items_id`='" . $items_id . "'\n                       AND `instantiation_type`='NetworkPortEthernet'\n                       AND `logical_number` = '" . $a_port['logical_number'] . "'", '', 1));
         if (!isset($a_ports_DB['id'])) {
             // Add port
             $a_port['instantiation_type'] = 'NetworkPortEthernet';
             $a_port['items_id'] = $items_id;
             $a_port['itemtype'] = 'Printer';
             $networkports_id = $networkPort->add($a_port);
             unset($a_port['id']);
             $a_pfnetworkport_DB = current($pfNetworkPort->find("`networkports_id`='" . $networkports_id . "'", '', 1));
             $a_port['id'] = $a_pfnetworkport_DB['id'];
             $pfNetworkPort->update($a_port);
         } else {
             // Update port
             $networkports_id = $a_ports_DB['id'];
             $a_port['id'] = $a_ports_DB['id'];
             $networkPort->update($a_port);
             unset($a_port['id']);
             // Check if pfnetworkport exist.
             $a_pfnetworkport_DB = current($pfNetworkPort->find("`networkports_id`='" . $networkports_id . "'", '', 1));
             $a_port['networkports_id'] = $networkports_id;
             if (isset($a_pfnetworkport_DB['id'])) {
                 $a_port['id'] = $a_pfnetworkport_DB['id'];
                 $pfNetworkPort->update($a_port);
             } else {
                 $a_port['networkports_id'] = $networkports_id;
                 $pfNetworkPort->add($a_port);
             }
         }
     }
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:36,代码来源:inventoryprinterlib.class.php

示例5: updateNetworkPort

 /**
  * @param $mac
  * @param $name
  * @param $computers_id
  * @param $instantiation_type
  * @param $inst_input
  * @param $ips
  * @param $check_name
  * @param $dohistory
  * @param $already_known_ports
  * @return ID
  */
 private static function updateNetworkPort($mac, $name, $computers_id, $instantiation_type, $inst_input, $ips, $check_name, $dohistory, $already_known_ports)
 {
     global $DB;
     $network_port = new NetworkPort();
     // Then, find or create the base NetworkPort
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networkports`\n                WHERE `itemtype` = 'Computer'\n                   AND `items_id` = '{$computers_id}'\n                   AND `mac` = '{$mac}'";
     // If there is virtual ports, then, filter by port's name
     if ($check_name) {
         $query .= " AND `name` = '{$name}'";
     }
     if (count($already_known_ports) > 0) {
         $query .= " AND `id` NOT IN (" . implode(',', $already_known_ports) . ")";
     }
     // We order by is_dynamic to be sure to get the static ones first !
     $query .= " ORDER BY `is_dynamic`, `id`";
     $ports = $DB->request($query);
     if ($ports->numrows() == 0) {
         $port_input = array('name' => $name, 'mac' => $mac, 'items_id' => $computers_id, 'itemtype' => 'Computer', '_no_history' => !$dohistory, 'instantiation_type' => $instantiation_type, '_create_children' => 1, 'is_dynamic' => 1, 'is_deleted' => 0);
         $networkports_id = $network_port->add($port_input, array(), $dohistory);
         if ($networkports_id === false) {
             return -1;
         }
         $inst_input['networkports_id'] = $networkports_id;
         $instantiation = $network_port->getInstantiation();
         $instantiation->update($inst_input);
         unset($instantiation);
     } else {
         $line = $ports->next();
         $networkports_id = $line['id'];
         $network_port->getFromDB($networkports_id);
         if (!$check_name && $network_port->fields['name'] != $name) {
             $port_input = array('id' => $network_port->getID(), 'name' => $name, 'is_dynamic' => 1);
             $network_port->update($port_input);
         }
         if ($network_port->fields['instantiation_type'] != $instantiation_type && $network_port->fields['is_dynamic'] == 1) {
             $network_port->switchInstantiationType($instantiation_type);
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation = $network_port->getInstantiation();
             $instantiation->add($inst_input);
             unset($instantiation);
         }
         if ($network_port->fields['instantiation_type'] == $instantiation_type) {
             $instantiation = $network_port->getInstantiation();
             $inst_input['id'] = $instantiation->getID();
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation->update($inst_input);
             unset($instantiation);
         }
     }
     if ($network_port->isNewItem()) {
         return -1;
     }
     $network_name = new NetworkName();
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networknames`\n                WHERE `itemtype` = 'NetworkPort'\n                   AND `items_id` = '{$networkports_id}'\n                ORDER BY `is_dynamic`";
     if (!$ips || count($ips) == 0) {
         foreach ($DB->request($query) as $line) {
             if ($line['is_dynamic']) {
                 $network_name->delete($line, true, $dohistory);
             }
         }
     } else {
         $names = $DB->request($query);
         if ($names->numrows() == 0) {
             $name_input = array('itemtype' => 'NetworkPort', 'items_id' => $networkports_id, 'is_dynamic' => 1, 'is_deleted' => 0, '_no_history' => !$dohistory, 'name' => 'OCS-INVENTORY-NG');
             $networknames_id = $network_name->add($name_input);
         } else {
             $line = $names->next();
             $networknames_id = $line['id'];
             foreach ($names as $line) {
                 if ($line['is_dynamic'] == 1 && $line['id'] != $networknames_id) {
                     $network_port->delete($line, true, $dohistory);
                 }
             }
         }
         $ip_address = new IPAddress();
         $already_known_addresses = array();
         $query = "SELECT `id`, `name`, `is_dynamic`, `mainitems_id`\n                   FROM `glpi_ipaddresses`\n                   WHERE `itemtype` = 'NetworkName'\n                     AND `items_id` = '{$networknames_id}'\n                   ORDER BY `is_dynamic`";
         foreach ($DB->request($query) as $line) {
             if (in_array($line['name'], $ips) && !empty($line['mainitems_id'])) {
                 $already_known_addresses[] = $line['id'];
                 $ips = array_diff($ips, array($line['name']));
             } elseif ($line['is_dynamic'] == 1) {
                 $ip_address->delete($line, true, $dohistory);
             }
         }
     }
     if ($ips) {
         foreach ($ips as $ip) {
//.........这里部分代码省略.........
开发者ID:pluginsGLPI,项目名称:ocsinventoryng,代码行数:101,代码来源:networkport.class.php

示例6: transferNetworkLink

 /**
  * Transfer network links
  *
  * @param $itemtype     original type of transfered item
  * @param $ID           original ID of the item
  * @param $newID        new ID of the item
  **/
 function transferNetworkLink($itemtype, $ID, $newID)
 {
     global $DB;
     /// TODO manage with new network system
     $np = new NetworkPort();
     $nn = new NetworkPort_NetworkPort();
     $query = "SELECT `glpi_networkports`.*, `glpi_networkportethernets`.`netpoints_id`\n                FROM `glpi_networkports`\n                LEFT JOIN `glpi_networkportethernets`\n                  ON (`glpi_networkports`.`id` = `glpi_networkportethernets`.`networkports_id`)\n                WHERE `glpi_networkports`.`items_id` = '{$ID}'\n                      AND `glpi_networkports`.`itemtype` = '{$itemtype}'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             switch ($this->options['keep_networklink']) {
                 // Delete netport
                 case 0:
                     // Not a copy -> delete
                     if ($ID == $newID) {
                         while ($data = $DB->fetch_assoc($result)) {
                             $np->delete(array('id' => $data['id']));
                         }
                     }
                     // Copy -> do nothing
                     break;
                     // Disconnect
                 // Disconnect
                 case 1:
                     // Not a copy -> disconnect
                     if ($ID == $newID) {
                         while ($data = $DB->fetch_assoc($result)) {
                             if ($nn->getFromDBForNetworkPort($data['id'])) {
                                 $nn->delete($data);
                             }
                             if ($data['netpoints_id']) {
                                 $netpointID = $this->transferDropdownNetpoint($data['netpoints_id']);
                                 $input['id'] = $data['id'];
                                 $input['netpoints_id'] = $netpointID;
                                 $np->update($input);
                             }
                         }
                     } else {
                         // Copy -> copy netports
                         while ($data = $DB->fetch_assoc($result)) {
                             $data = Toolbox::addslashes_deep($data);
                             unset($data['id']);
                             $data['items_id'] = $newID;
                             $data['netpoints_id'] = $this->transferDropdownNetpoint($data['netpoints_id']);
                             unset($np->fields);
                             $np->add(toolbox::addslashes_deep($data));
                         }
                     }
                     break;
                     // Keep network links
                 // Keep network links
                 default:
                     // Copy -> Copy netpoints (do not keep links)
                     if ($ID != $newID) {
                         while ($data = $DB->fetch_assoc($result)) {
                             unset($data['id']);
                             $data['items_id'] = $newID;
                             $data['netpoints_id'] = $this->transferDropdownNetpoint($data['netpoints_id']);
                             unset($np->fields);
                             $np->add(toolbox::addslashes_deep($data));
                         }
                     } else {
                         while ($data = $DB->fetch_assoc($result)) {
                             // Not a copy -> only update netpoint
                             if ($data['netpoints_id']) {
                                 $netpointID = $this->transferDropdownNetpoint($data['netpoints_id']);
                                 $input['id'] = $data['id'];
                                 $input['netpoints_id'] = $netpointID;
                                 $np->update($input);
                             }
                         }
                     }
             }
         }
     }
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:82,代码来源:transfer.class.php

示例7: sprintf

        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']);
        }
        Html::redirect($CFG_GLPI["root_doc"] . "/front/central.php");
    } else {
        if (isset($_POST["update"])) {
            $np->check($_POST['id'], 'w');
            $np->splitInputForElements($_POST);
            $np->update($_POST);
            $np->updateDependencies(1);
            Event::log($_POST["id"], "networkport", 4, "inventory", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
            Html::back();
        } else {
            if (isset($_POST["disconnect"])) {
                $nn->check($_POST['id'], 'd');
                if (isset($_POST["id"])) {
                    $nn->delete($_POST);
                }
                Html::back();
            } else {
                if (empty($_GET["items_id"])) {
                    $_GET["items_id"] = "";
                }
                if (empty($_GET["itemtype"])) {
开发者ID:geldarr,项目名称:hack-space,代码行数:31,代码来源:networkport.form.php

示例8: import

 /**
  * Function to import discovered device
  *
  * @param $items_id id of the device to import
  *
  * @return nothing
  *
  **/
 function import($items_id, $Import = 0, $NoImport = 0)
 {
     global $DB;
     $NetworkPort = new NetworkPort();
     $a_NetworkPorts = $NetworkPort->find("`items_id` = '" . $items_id . "'\n                      AND `itemtype` = 'PluginFusioninventoryUnmanaged'");
     $this->getFromDB($items_id);
     $this->fields = Toolbox::addslashes_deep($this->fields);
     $data = array();
     switch ($this->fields['item_type']) {
         case 'Printer':
             $Printer = new Printer();
             $data["entities_id"] = $this->fields["entities_id"];
             if (!empty($this->fields["name"])) {
                 $data["name"] = $this->fields["name"];
             }
             $data["locations_id"] = $this->fields["locations_id"];
             $data["serial"] = $this->fields["serial"];
             $data["otherserial"] = $this->fields["otherserial"];
             $data["contact"] = $this->fields["contact"];
             $data["domain"] = $this->fields["domain"];
             $data["comment"] = $this->fields["comment"];
             $data["is_dynamic"] = 1;
             $printer_id = $Printer->add($data);
             foreach ($a_NetworkPorts as $data_Port) {
                 $data_Port['items_id'] = $printer_id;
                 $data_Port['itemtype'] = $Printer->getType();
                 $NetworkPort->update($data_Port);
             }
             // Import SNMP
             $pfPrinter = new PluginFusioninventoryPrinter();
             $_SESSION['glpi_plugins_fusinvsnmp_table'] = "glpi_plugin_fusioninventory_printers";
             $query = "SELECT *\n                      FROM `glpi_plugin_fusioninventory_printers`\n                      WHERE `printers_id`='" . $printer_id . "' ";
             $result = $DB->query($query);
             $data = array();
             if ($DB->numrows($result) > 0) {
                 $data = $DB->fetch_assoc($result);
             }
             $data['sysdescr'] = $this->fields['sysdescr'];
             $data['plugin_fusioninventory_configsecurities_id'] = $this->fields['plugin_fusioninventory_configsecurities_id'];
             if ($DB->numrows($result) == 0) {
                 $data['printers_id'] = $printer_id;
                 $pfPrinter->add($data);
             } else {
                 $pfPrinter->update($data);
             }
             $this->deleteFromDB($items_id, 1);
             $Import++;
             break;
         case 'NetworkEquipment':
             $NetworkEquipment = new NetworkEquipment();
             $data["entities_id"] = $this->fields["entities_id"];
             if (!empty($this->fields["name"])) {
                 $data["name"] = $this->fields["name"];
             }
             $data["locations_id"] = $this->fields["locations_id"];
             $data["serial"] = $this->fields["serial"];
             $data["otherserial"] = $this->fields["otherserial"];
             $data["contact"] = $this->fields["contact"];
             $data["domain"] = $this->fields["domain"];
             $data["comment"] = $this->fields["comment"];
             $data["is_dynamic"] = 1;
             //            $data_Port = current($a_NetworkPorts);
             //            $data["ip"] = $data_Port["ip"];
             //            $data["mac"] = $data_Port["mac"];
             $NetworkEquipment_id = $NetworkEquipment->add($data);
             foreach ($a_NetworkPorts as $data_Port) {
                 $data_Port['items_id'] = $NetworkEquipment_id;
                 $data_Port['itemtype'] = $NetworkEquipment->getType();
                 $NetworkPort->update($data_Port);
             }
             $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment();
             $_SESSION['glpi_plugins_fusinvsnmp_table'] = "glpi_plugin_fusioninventory_networkequipments";
             $query = "SELECT *\n                      FROM `glpi_plugin_fusioninventory_networkequipments`\n                      WHERE `networkequipments_id`='" . $NetworkEquipment_id . "' ";
             $result = $DB->query($query);
             $data = array();
             if ($DB->numrows($result) > 0) {
                 $data = $DB->fetch_assoc($result);
             }
             $data['sysdescr'] = $this->fields['sysdescr'];
             $data['plugin_fusioninventory_configsecurities_id'] = $this->fields['plugin_fusioninventory_configsecurities_id'];
             if ($DB->numrows($result) == 0) {
                 $data['networkequipments_id'] = $NetworkEquipment_id;
                 $pfNetworkEquipment->add($data);
             } else {
                 $pfNetworkEquipment->update($data);
             }
             $this->deleteFromDB($items_id, 1);
             $Import++;
             break;
         case 'Peripheral':
             $Peripheral = new Peripheral();
             $data["entities_id"] = $this->fields["entities_id"];
//.........这里部分代码省略.........
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:101,代码来源:unmanaged.class.php

示例9: manageNetworkPort

 function manageNetworkPort($inventory_networkports, $computers_id, $no_history)
 {
     global $DB;
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $iPNetwork = new IPNetwork();
     $networkPortEthernet = new NetworkPortEthernet();
     $item_DeviceNetworkCard = new Item_DeviceNetworkCard();
     foreach ($inventory_networkports as $a_networkport) {
         if ($a_networkport['mac'] != '') {
             $a_networkports = $networkPort->find("`mac`='" . $a_networkport['mac'] . "'\n               AND `itemtype`='PluginFusioninventoryUnmanaged'", "", 1);
             if (count($a_networkports) > 0) {
                 $input = current($a_networkports);
                 $unmanageds_id = $input['items_id'];
                 $input['logical_number'] = $a_networkport['logical_number'];
                 $input['itemtype'] = 'Computer';
                 $input['items_id'] = $computers_id;
                 $input['is_dynamic'] = 1;
                 $input['name'] = $a_networkport['name'];
                 $networkPort->update($input, !$no_history);
                 $pfUnmanaged = new PluginFusioninventoryUnmanaged();
                 $pfUnmanaged->delete(array('id' => $unmanageds_id), 1);
             }
         }
     }
     // end get port from unknwon device
     $db_networkport = array();
     if ($no_history === FALSE) {
         $query = "SELECT `id`, `name`, `mac`, `instantiation_type`, `logical_number`\n             FROM `glpi_networkports`\n             WHERE `items_id` = '{$computers_id}'\n               AND `itemtype`='Computer'\n               AND `is_dynamic`='1'";
         $result = $DB->query($query);
         while ($data = $DB->fetch_assoc($result)) {
             $idtmp = $data['id'];
             unset($data['id']);
             if (is_null($data['mac'])) {
                 $data['mac'] = '';
             }
             if (preg_match("/[^a-zA-Z0-9 \\-_\\(\\)]+/", $data['name'])) {
                 $data['name'] = Toolbox::addslashes_deep($data['name']);
             }
             $db_networkport[$idtmp] = array_map('strtolower', $data);
         }
     }
     $simplenetworkport = array();
     foreach ($inventory_networkports as $key => $a_networkport) {
         // Add ipnetwork if not exist
         if ($a_networkport['gateway'] != '' && $a_networkport['netmask'] != '' && $a_networkport['subnet'] != '') {
             if (countElementsInTable('glpi_ipnetworks', "`address`='" . $a_networkport['subnet'] . "'\n                                     AND `netmask`='" . $a_networkport['netmask'] . "'\n                                     AND `gateway`='" . $a_networkport['gateway'] . "'\n                                     AND `entities_id`='" . $_SESSION["plugin_fusioninventory_entity"] . "'") == 0) {
                 $input_ipanetwork = array('name' => $a_networkport['subnet'] . '/' . $a_networkport['netmask'] . ' - ' . $a_networkport['gateway'], 'network' => $a_networkport['subnet'] . ' / ' . $a_networkport['netmask'], 'gateway' => $a_networkport['gateway'], 'entities_id' => $_SESSION["plugin_fusioninventory_entity"]);
                 $iPNetwork->add($input_ipanetwork, array(), !$no_history);
             }
         }
         // End add ipnetwork
         $a_field = array('name', 'mac', 'instantiation_type');
         foreach ($a_field as $field) {
             if (isset($a_networkport[$field])) {
                 $simplenetworkport[$key][$field] = $a_networkport[$field];
             }
         }
     }
     foreach ($simplenetworkport as $key => $arrays) {
         $arrayslower = array_map('strtolower', $arrays);
         foreach ($db_networkport as $keydb => $arraydb) {
             $logical_number = $arraydb['logical_number'];
             unset($arraydb['logical_number']);
             if ($arrayslower == $arraydb) {
                 if ($inventory_networkports[$key]['logical_number'] != $logical_number) {
                     $input = array();
                     $input['id'] = $keydb;
                     $input['logical_number'] = $inventory_networkports[$key]['logical_number'];
                     $networkPort->update($input, !$no_history);
                 }
                 // Add / update instantiation_type
                 if (isset($inventory_networkports[$key]['instantiation_type'])) {
                     if ($inventory_networkports[$key]['instantiation_type'] == 'NetworkPortEthernet') {
                         $portsethernet = $networkPortEthernet->find("`networkports_id`='" . $keydb . "'", '', 1);
                         if (count($portsethernet) == 1) {
                             $portethernet = current($portsethernet);
                             $input = $portethernet;
                         } else {
                             $input = array('networkports_id' => $keydb);
                         }
                         if (isset($inventory_networkports[$key]['speed'])) {
                             $input['speed'] = $inventory_networkports[$key]['speed'];
                             $input['speed_other_value'] = $inventory_networkports[$key]['speed'];
                         }
                         if (isset($inventory_networkports[$key]['mac'])) {
                             $networkcards = $item_DeviceNetworkCard->find("`mac`='" . $inventory_networkports[$key]['mac'] . "' " . " AND `itemtype`='Computer'" . " AND `items_id`='" . $computers_id . "'", '', 1);
                             if (count($networkcards) == 1) {
                                 $networkcard = current($networkcards);
                                 $input['items_devicenetworkcards_id'] = $networkcard['id'];
                             }
                         }
                         $input['_no_history'] = $no_history;
                         if (isset($input['id'])) {
                             $networkPortEthernet->update($input);
                         } else {
                             $networkPortEthernet->add($input);
                         }
                     }
//.........这里部分代码省略.........
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:101,代码来源:inventorycomputerlib.class.php

示例10: importPorts

 function importPorts($a_inventory, $items_id)
 {
     $pfNetworkporttype = new PluginFusioninventoryNetworkporttype();
     $networkPort = new NetworkPort();
     $pfNetworkPort = new PluginFusioninventoryNetworkPort();
     $networkports_id = 0;
     foreach ($a_inventory['networkport'] as $a_port) {
         $ifType = $a_port['iftype'];
         if ($pfNetworkporttype->isImportType($ifType) || isset($a_inventory['aggregate'][$a_port['logical_number']]) || $ifType == '') {
             $a_ports_DB = current($networkPort->find("`itemtype`='NetworkEquipment'\n                          AND `items_id`='" . $items_id . "'\n                          AND `logical_number` = '" . $a_port['logical_number'] . "'", '', 1));
             if (!isset($a_ports_DB['id'])) {
                 // Add port
                 if (isset($a_inventory['aggregate']) && isset($a_inventory['aggregate'][$a_port['logical_number']])) {
                     $a_port['instantiation_type'] = 'NetworkPortAggregate';
                 } else {
                     $a_port['instantiation_type'] = 'NetworkPortEthernet';
                 }
                 $a_port['items_id'] = $items_id;
                 $a_port['itemtype'] = 'NetworkEquipment';
                 $networkports_id = $networkPort->add($a_port);
                 unset($a_port['id']);
                 $a_pfnetworkport_DB = current($pfNetworkPort->find("`networkports_id`='" . $networkports_id . "'", '', 1));
                 $a_port['id'] = $a_pfnetworkport_DB['id'];
                 $a_port['lastup'] = date('Y-m-d H:i:s');
                 $pfNetworkPort->update($a_port);
             } else {
                 // Update port
                 $networkports_id = $a_ports_DB['id'];
                 $a_port['id'] = $a_ports_DB['id'];
                 $networkPort->update($a_port);
                 unset($a_port['id']);
                 // Check if pfnetworkport exist.
                 $a_pfnetworkport_DB = current($pfNetworkPort->find("`networkports_id`='" . $networkports_id . "'", '', 1));
                 $a_port['networkports_id'] = $networkports_id;
                 if (isset($a_pfnetworkport_DB['id'])) {
                     $a_port['id'] = $a_pfnetworkport_DB['id'];
                     if ($a_port['ifstatus'] == 0 && $a_pfnetworkport_DB['ifstatus'] == 1) {
                         $a_port['lastup'] = date('Y-m-d H:i:s');
                     }
                     $pfNetworkPort->update($a_port);
                 } else {
                     $a_port['networkports_id'] = $networkports_id;
                     $a_port['lastup'] = date('Y-m-d H:i:s');
                     $pfNetworkPort->add($a_port);
                 }
             }
             // Connections
             if (isset($a_inventory['connection-lldp'][$a_port['logical_number']])) {
                 $this->importConnectionLLDP($a_inventory['connection-lldp'][$a_port['logical_number']], $networkports_id);
             } else {
                 if (isset($a_inventory['connection-mac'][$a_port['logical_number']])) {
                     $this->importConnectionMac($a_inventory['connection-mac'][$a_port['logical_number']], $networkports_id);
                 }
             }
             // Vlan
             if (isset($a_inventory['vlans'][$a_port['logical_number']])) {
                 $this->importPortVlan($a_inventory['vlans'][$a_port['logical_number']], $networkports_id);
             }
             // Aggegation
             if (isset($a_inventory['aggregate']) && isset($a_inventory['aggregate'][$a_port['logical_number']])) {
                 $this->importPortAggregate($a_inventory['aggregate'][$a_port['logical_number']], $networkports_id, $items_id);
             }
         } else {
             // Delete the port
             $a_ports_DB = current($networkPort->find("`itemtype`='NetworkEquipment'\n                          AND `items_id`='" . $items_id . "'\n                          AND `logical_number` = '" . $a_port['logical_number'] . "'", '', 1));
             if (count($a_ports_DB) > 0) {
                 $networkPort->delete($a_ports_DB);
             }
         }
     }
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:71,代码来源:inventorynetworkequipmentlib.class.php

示例11: updateDevices

 /**
  * Import the devices for a computer
  *
  * @param $devicetype integer : device type
  * @param $computers_id integer : glpi computer id.
  * @param $ocsid integer : ocs computer id (ID).
  * @param $ocsservers_id integer : ocs server id
  * @param $cfg_ocs array : ocs config
  * @param $import_device array : already imported devices
  * @param $import_ip array : already imported ip
  * @param $dohistory boolean : log changes ?
  *
  * @return Nothing (void).
  **/
 static function updateDevices($devicetype, $computers_id, $ocsid, $ocsservers_id, $cfg_ocs, $import_device, $import_ip, $dohistory)
 {
     global $DBocs, $DB;
     $prevalue = $devicetype . self::FIELD_SEPARATOR;
     self::checkOCSconnection($ocsservers_id);
     $types = Computer_Device::getDeviceTypes();
     $CompDevice = new Computer_Device($types[$devicetype]);
     $do_clean = false;
     switch ($devicetype) {
         case self::RAM_DEVICE:
             //Memoire
             if ($cfg_ocs["import_device_memory"]) {
                 $do_clean = true;
                 $query2 = "SELECT *\n                          FROM `memories`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 if ($DBocs->numrows($result2) > 0) {
                     // Drop all memories and force no history
                     if (!in_array(self::IMPORT_TAG_078, $import_device)) {
                         self::addToOcsArray($computers_id, array(0 => self::IMPORT_TAG_078), "import_device");
                         // Clean memories for this computer
                         if (count($import_device)) {
                             $dohistory = false;
                             foreach ($import_device as $key => $val) {
                                 $tmp = explode(self::FIELD_SEPARATOR, $key);
                                 if (isset($tmp[1]) && $tmp[0] == self::RAM_DEVICE) {
                                     $CompDevice->delete(array('id' => $tmp[1], '_no_history' => true, '_itemtype' => 'DeviceMemory'));
                                     self::deleteInOcsArray($computers_id, $key, "import_device");
                                     unset($import_device[$key]);
                                 }
                             }
                         }
                     }
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         if (!empty($line2["CAPACITY"]) && $line2["CAPACITY"] != "No") {
                             $ram["designation"] = "";
                             if ($line2["TYPE"] != "Empty Slot" && $line2["TYPE"] != "Unknown") {
                                 $ram["designation"] = $line2["TYPE"];
                             }
                             if ($line2["DESCRIPTION"]) {
                                 if (!empty($ram["designation"])) {
                                     $ram["designation"] .= " - ";
                                 }
                                 $ram["designation"] .= $line2["DESCRIPTION"];
                             }
                             if (!is_numeric($line2["CAPACITY"])) {
                                 $line2["CAPACITY"] = 0;
                             }
                             $ram["specif_default"] = $line2["CAPACITY"];
                             if (!in_array(stripslashes($prevalue . $ram["designation"]), $import_device)) {
                                 $ram["frequence"] = $line2["SPEED"];
                                 $ram["devicememorytypes_id"] = Dropdown::importExternal('DeviceMemoryType', $line2["TYPE"]);
                                 $DeviceMemory = new DeviceMemory();
                                 $ram_id = $DeviceMemory->import($ram);
                                 if ($ram_id) {
                                     $devID = $CompDevice->add(array('computers_id' => $computers_id, '_itemtype' => 'DeviceMemory', 'devicememories_id' => $ram_id, 'specificity' => $line2["CAPACITY"], '_no_history' => !$dohistory));
                                     self::addToOcsArray($computers_id, array($prevalue . $devID => $prevalue . $ram["designation"]), "import_device");
                                 }
                             } else {
                                 $tmp = array_search(stripslashes($prevalue . $ram["designation"]), $import_device);
                                 list($type, $id) = explode(self::FIELD_SEPARATOR, $tmp);
                                 $CompDevice->update(array('id' => $id, 'specificity' => $line2["CAPACITY"], '_itemtype' => 'DeviceMemory'));
                                 unset($import_device[$tmp]);
                             }
                         }
                     }
                 }
             }
             break;
         case self::HDD_DEVICE:
             //Disque Dur
             if ($cfg_ocs["import_device_hdd"]) {
                 $do_clean = true;
                 $query2 = "SELECT *\n                          FROM `storages`\n                          WHERE `HARDWARE_ID` = '{$ocsid}'\n                          ORDER BY `ID`";
                 $result2 = $DBocs->query($query2);
                 if ($DBocs->numrows($result2) > 0) {
                     while ($line2 = $DBocs->fetch_array($result2)) {
                         $line2 = clean_cross_side_scripting_deep(addslashes_deep($line2));
                         if (!empty($line2["DISKSIZE"]) && preg_match("/disk|spare\\sdrive/i", $line2["TYPE"])) {
                             if ($line2["NAME"]) {
                                 $dd["designation"] = $line2["NAME"];
                             } else {
                                 if ($line2["MODEL"]) {
                                     $dd["designation"] = $line2["MODEL"];
                                 } else {
                                     $dd["designation"] = "Unknown";
//.........这里部分代码省略.........
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:101,代码来源:ocsserver.class.php


注:本文中的NetworkPort::update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。