/** * Display form to unlock fields and links * * @param CommonDBTM $item the source item **/ static function showForItem(CommonDBTM $item) { global $DB; $ID = $item->getID(); $itemtype = $item->getType(); $header = false; //If user doesn't have write right on the item, lock form must not be displayed if (!$item->canCreate()) { return false; } echo "<div width='50%'>"; echo "<form method='post' id='lock_form'\n name='lock_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<input type='hidden' name='id' value='{$ID}'>\n"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2''>" . __('Locked items') . "</th></tr>"; //Use a hook to allow external inventory tools to manage per field lock $results = Plugin::doHookFunction('display_locked_fields', array('item' => $item, 'header' => $header)); $header |= $results['header']; //Special locks for computers only if ($itemtype == 'Computer') { //Locks for items recorded in glpi_computers_items table $types = array('Monitor', 'Peripheral', 'Printer'); foreach ($types as $type) { $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID, 'itemtype' => $type); $params['FIELDS'] = array('id', 'items_id'); $first = true; foreach ($DB->request('glpi_computers_items', $params) as $line) { $tmp = new $type(); $tmp->getFromDB($line['items_id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='Computer_Item[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $tmp->getName() . "</td>"; echo "</tr>\n"; } } $types = array('ComputerDisk', 'ComputerVirtualMachine'); foreach ($types as $type) { $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID); $params['FIELDS'] = array('id', 'name'); $first = true; foreach ($DB->request(getTableForItemType($type), $params) as $line) { $header = true; if ($first) { echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='" . $type . "[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $line['name'] . "</td>"; echo "</tr>\n"; } } //Software versions $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID); $first = true; $query = "SELECT `csv`.`id` AS `id`,\n `sv`.`name` AS `version`,\n `s`.`name` AS `software`\n FROM `glpi_computers_softwareversions` AS csv\n LEFT JOIN `glpi_softwareversions` AS sv\n ON (`csv`.`softwareversions_id` = `sv`.`id`)\n LEFT JOIN `glpi_softwares` AS s\n ON (`sv`.`softwares_id` = `s`.`id`)\n WHERE `csv`.`is_deleted` = '1'\n AND `csv`.`is_dynamic` = '1'\n AND `csv`.`computers_id` = '{$ID}'"; foreach ($DB->request($query) as $line) { $header = true; if ($first) { echo "<tr><th colspan='2'>" . Software::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='Computer_SoftwareVersion[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>"; echo "</tr>\n"; } //Software licenses $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID); $first = true; $query = "SELECT `csv`.`id` AS `id`,\n `sv`.`name` AS `version`,\n `s`.`name` AS `software`\n FROM `glpi_computers_softwarelicenses` AS csv\n LEFT JOIN `glpi_softwarelicenses` AS sv\n ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n LEFT JOIN `glpi_softwares` AS s\n ON (`sv`.`softwares_id` = `s`.`id`)\n WHERE `csv`.`is_deleted` = '1'\n AND `csv`.`is_dynamic` = '1'\n AND `csv`.`computers_id` = '{$ID}'"; foreach ($DB->request($query) as $line) { $header = true; if ($first) { echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>"; echo "</tr>\n"; } } $first = true; $item = new NetworkPort(); $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype); $params['FIELDS'] = array('id'); foreach ($DB->request('glpi_networkports', $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $first = true; $item = new NetworkName(); $params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype); $params['FIELDS'] = array('glpi_networknames' => 'id'); foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $first = true; $item = new IPAddress(); $params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype); $params['FIELDS'] = array('glpi_ipaddresses' => 'id'); foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $types = Item_Devices::getDeviceTypes(); $nb = 0; foreach ($types as $old => $type) { $nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n AND `itemtype`='{$itemtype}'\n AND `is_dynamic`='1'\n AND `is_deleted`='1'"); } if ($nb) { $header = true; echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n"; foreach ($types as $old => $type) { $associated_type = str_replace('Item_', '', $type); $associated_table = getTableForItemType($associated_type); $fk = getForeignKeyFieldForTable($associated_table); $query = "SELECT `i`.`id`,\n `t`.`designation` AS `name`\n FROM `" . getTableForItemType($type) . "` AS i\n LEFT JOIN `{$associated_table}` AS t\n ON (`t`.`id` = `i`.`{$fk}`)\n WHERE `itemtype` = '{$itemtype}'\n AND `items_id` = '{$ID}'\n AND `is_dynamic` = '1'\n AND `is_deleted` = '1'"; foreach ($DB->request($query) as $data) { echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>"; echo "<td class='left' width='95%'>"; printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']); echo "</td></tr>\n"; } } } if ($header) { echo "</table>"; Html::openArrowMassives('lock_form', true); Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock'))); } else { echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>"; echo "</table>"; } Html::closeForm(); echo "</div>\n"; }
/** * @test */ public function ImportNetworkEquipment() { global $DB; self::restore_database(); // Load session rights $_SESSION['glpidefault_entity'] = 0; Session::initEntityProfiles(2); Session::changeProfile(4); $pfUnmanaged = new PluginFusioninventoryUnmanaged(); $networkEquipment = new NetworkEquipment(); $networkPort = new NetworkPort(); $networkName = new NetworkName(); $iPAddress = new IPAddress(); $input = array('name' => 'switch', 'entities_id' => 0, 'item_type' => 'NetworkEquipment', 'sysdescr' => 'Cisco machin chose', 'locations_id' => 1, 'is_dynamic' => 1, 'serial' => 'XXS6BEF3', 'comment' => 'this is a comment', 'plugin_fusioninventory_configsecurities_id' => 1); $unmanageds_id = $pfUnmanaged->add($input); // * Add networkport $input = array(); $input['itemtype'] = 'PluginFusioninventoryUnmanaged'; $input['items_id'] = $unmanageds_id; $input['instantiation_type'] = 'NetworkPortEthernet'; $input['name'] = 'general'; $input['mac'] = '00:00:00:43:ae:0f'; $input['is_dynamic'] = 1; $networkports_id = $networkPort->add($input); $input = array(); $input['items_id'] = $networkports_id; $input['itemtype'] = 'NetworkPort'; $input['name'] = ''; $input['is_dynamic'] = 1; $networknames_id = $networkName->add($input); $input = array(); $input['entities_id'] = 0; $input['itemtype'] = 'NetworkName'; $input['items_id'] = $networknames_id; $input['name'] = '192.168.20.1'; $input['is_dynamic'] = 1; $iPAddress->add($input); $pfUnmanaged->import($unmanageds_id); $cnt = countElementsInTable("glpi_networkequipments"); $this->assertEquals(1, $cnt, "May have network equipment added"); $cnt = countElementsInTable("glpi_plugin_fusioninventory_unmanageds"); $this->assertEquals(0, $cnt, "Unknown device may be deleted"); $networkEquipment->getFromDB(1); $this->assertEquals('XXS6BEF3', $networkEquipment->fields['serial'], "Serial"); $this->assertEquals('switch', $networkEquipment->fields['name'], "Name"); $this->assertEquals(1, $networkEquipment->fields['is_dynamic'], "is_dynamic"); $this->assertEquals(1, $networkEquipment->fields['locations_id'], "locations_id"); $this->assertEquals('this is a comment', $networkEquipment->fields['comment'], "comment"); $networkPort->getFromDB(1); $a_reference = array('name' => 'general', 'id' => '1', 'items_id' => '1', 'itemtype' => 'NetworkEquipment', 'entities_id' => '0', 'is_recursive' => '0', 'logical_number' => '0', 'instantiation_type' => 'NetworkPortEthernet', 'mac' => '00:00:00:43:ae:0f', 'comment' => '', 'is_deleted' => '0', 'is_dynamic' => '1'); $this->assertEquals($a_reference, $networkPort->fields, "Networkport"); $networkName->getFromDB(1); $a_reference = array('id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkPort', 'comment' => NULL, 'fqdns_id' => '0', 'is_deleted' => '0', 'is_dynamic' => '1', 'name' => ''); $this->assertEquals($a_reference, $networkName->fields, "Networkname"); $iPAddress->getFromDB(1); $a_reference = array('name' => '192.168.20.1', 'id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkName', 'version' => '4', 'binary_0' => '0', 'binary_1' => '0', 'binary_2' => '65535', 'binary_3' => '3232240641', 'is_deleted' => '0', 'is_dynamic' => '1', 'mainitems_id' => '1', 'mainitemtype' => 'NetworkEquipment'); $this->assertEquals($a_reference, $iPAddress->fields, "IPAddress"); }
static function getIp($items_id, $itemtype, $hostname) { global $DB; $networkPort = new NetworkPort(); $networkName = new NetworkName(); $iPAddress = new IPAddress(); $pmHostaddress = new PluginMonitoringHostaddress(); $ip = ''; $networkports_id = 0; $query = "SELECT * FROM `" . $pmHostaddress->getTable() . "`\n WHERE `items_id`='" . $items_id . "'\n AND `itemtype`='" . $itemtype . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == '1') { $data = $DB->fetch_assoc($result); if ($data['ipaddresses_id'] > 0) { $iPAddress->getFromDB($data['ipaddresses_id']); return $iPAddress->fields['name']; } else { $networkports_id = $data['networkports_id']; } } if ($ip == '') { if ($networkports_id > 0) { $a_listnetwork = $networkPort->find("`id`='" . $networkports_id . "'"); } else { $a_listnetwork = $networkPort->find("`itemtype`='" . $itemtype . "'\n AND `items_id`='" . $items_id . "'", "`id`"); } foreach ($a_listnetwork as $networkports_id => $datanetwork) { $a_networknames_find = current($networkName->find("`items_id`='" . $networkports_id . "'\n AND `itemtype`='NetworkPort'", "", 1)); if (isset($a_networknames_find['id'])) { $networknames_id = $a_networknames_find['id']; $a_ips_fromDB = $iPAddress->find("`itemtype`='NetworkName'\n AND `items_id`='" . $networknames_id . "'"); foreach ($a_ips_fromDB as $data) { if ($data['name'] != '' && $data['name'] != '127.0.0.1' && $data['name'] != '::1') { return $data['name']; } } } } } return $hostname; }
/** * show hardware to be identified, or identified and imported, or just the hardware with agents installed on them * @param type $hardware array * @param type $lim integer * @param int|type $start integer * @param type $ipAdress string * @param type $status string * @param $subnet * @param $action * @global type $CFG_GLPI */ static function showHardware($hardware, $lim, $start = 0, $ipAdress, $status, $subnet, $action) { global $CFG_GLPI, $DB; $output_type = Search::HTML_OUTPUT; //0 $link = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php"; $return = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.php"; $returnargs = "subnetsChoice={$subnet}&action={$action}"; $reload = "ip={$ipAdress}&status={$status}&action={$action}"; $backValues = "?b[]={$ipAdress}&b[]={$status}"; if ($status == "inventoried") { $status_name = __('Inventoried', 'ocsinventoryng'); } elseif ($status == "imported") { $status_name = __('Imported / Linked', 'ocsinventoryng'); } elseif ($status == "noninventoried") { $status_name = __('Non Inventoried', 'ocsinventoryng'); } else { $status_name = __('Identified', 'ocsinventoryng'); } $subnet_name = self::getSubnetNamebyIP($ipAdress); echo "<div class='center'>"; echo "<h2>" . __('Subnet', 'ocsinventoryng') . " " . $subnet_name . " (" . $ipAdress . ") - " . $status_name; echo " "; $refresh = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php?" . $reload; Html::showSimpleForm($refresh, 'refresh', _sx('button', 'Refresh'), array(), $CFG_GLPI["root_doc"] . "/plugins/ocsinventoryng/pics/synchro.png"); echo "</h2>"; echo "</div>"; if ($subnet >= 0) { $back = __('Back'); echo "<div class='center'><a href='{$return}?{$returnargs}'>{$back}</div>"; } echo Html::printPager($start, count($hardware), $link, $reload); echo Search::showNewLine($output_type, true); if (empty($hardware)) { echo "<div class='center b'><br>" . __('No new IPDiscover device to import', 'ocsinventoryng') . "</div>"; Html::displayBackLink(); } else { $header_num = 1; switch ($status) { case "inventoried": echo "<table width='100%'class='tab_cadrehov'>\n"; echo Search::showHeaderItem($output_type, __('User'), $header_num); echo Search::showHeaderItem($output_type, __('Name'), $header_num); echo Search::showHeaderItem($output_type, __('System'), $header_num); echo Search::showHeaderItem($output_type, __('Version of the operating system'), $header_num); echo Search::showHeaderItem($output_type, __('IP address'), $header_num); echo Search::showHeaderItem($output_type, __('Last OCSNG inventory date', 'ocsinventoryng'), $header_num); echo Search::showEndLine($output_type); $row_num = 1; for ($i = $start; $i < $lim + $start; $i++) { if (isset($hardware[$i])) { $row_num++; $item_num = 1; echo Search::showNewLine($output_type, $row_num % 2); echo Search::showItem($output_type, $hardware[$i]["userid"], $item_num, $row_num); echo Search::showItem($output_type, $hardware[$i]["name"], $item_num, $row_num); echo Search::showItem($output_type, $hardware[$i]["osname"], $item_num, $row_num); echo Search::showItem($output_type, $hardware[$i]["osversion"], $item_num, $row_num); echo Search::showItem($output_type, $hardware[$i]["ipaddr"], $item_num, $row_num); echo Search::showItem($output_type, Html::convDateTime($hardware[$i]["lastdate"]), $item_num, $row_num); echo Search::showEndLine($output_type); } } echo "</table>\n"; break; case "imported": $target = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php" . $backValues; self::checkBox($target); echo "<form method='post' id='ipdiscover_form' name='ipdiscover_form' action='{$target}'>"; echo "<div class='center' style=\"width=100%\">"; echo "<input type='submit' class='submit' name='deletelink' value=\"" . _sx('button', 'Delete link', 'ocsinventoryng') . "\"></div>"; echo "<table width='100%'class='tab_cadrehov'>\n"; echo Search::showHeaderItem($output_type, __('Item'), $header_num); echo Search::showHeaderItem($output_type, __('Item type'), $header_num); echo Search::showHeaderItem($output_type, __('MAC address'), $header_num); echo Search::showHeaderItem($output_type, __('IP address'), $header_num); echo Search::showHeaderItem($output_type, __('Location'), $header_num); echo Search::showHeaderItem($output_type, __('Import date in GLPI', 'ocsinventoryng'), $header_num); echo Search::showHeaderItem($output_type, __('Subnet'), $header_num); echo Search::showHeaderItem($output_type, __(' '), $header_num); echo Search::showEndLine($output_type); $row_num = 1; for ($i = $start; $i < $lim + $start; $i++) { if (isset($hardware[$i])) { $row_num++; $item_num = 1; echo Search::showNewLine($output_type, $row_num % 2); $class = getItemForItemtype($hardware[$i]["itemtype"]); $class->getFromDB($hardware[$i]["items_id"]); $iplist = ""; $ip = new IPAddress(); // Update IPAddress foreach ($DB->request('glpi_networkports', array('itemtype' => $hardware[$i]["itemtype"], 'items_id' => $hardware[$i]["items_id"])) as $netname) { foreach ($DB->request('glpi_networknames', array('itemtype' => 'NetworkPort', 'items_id' => $netname['id'])) as $dataname) { foreach ($DB->request('glpi_ipaddresses', array('itemtype' => 'NetworkName', 'items_id' => $dataname['id'])) as $data) { $ip->getFromDB($data['id']); $iplist .= $ip->getName() . "<br>"; } } } echo Search::showItem($output_type, $class->getLink(), $item_num, $row_num); echo Search::showItem($output_type, $class->getTypeName(), $item_num, $row_num); echo Search::showItem($output_type, $hardware[$i]["macaddress"], $item_num, $row_num); echo Search::showItem($output_type, $iplist, $item_num, $row_num); echo Search::showItem($output_type, Dropdown::getDropdownName("glpi_locations", $class->fields["locations_id"]), $item_num, $row_num); echo Search::showItem($output_type, Html::convDateTime($hardware[$i]["last_update"]), $item_num, $row_num); echo Search::showItem($output_type, $hardware[$i]["subnet"], $item_num, $row_num); echo self::showItem($hardware[$i]["id"], "", "", "", true, "", $i); echo Search::showEndLine($output_type); } } echo "<tbody style=\"display:none\">"; echo "<tr><td><input type=\"hidden\" name='subnet' value=\"{$ipAdress}\" ></td></tr>"; echo "</tbody>"; echo "</table>\n"; echo "<div class='center' style=\"width=100%\">"; echo "<input type='submit' class='submit' name='deletelink' value=\"" . _sx('button', 'Delete link', 'ocsinventoryng') . "\"></div>"; Html::closeForm(); self::checkBox($target); break; case "noninventoried": $ocsTypes = array("id" => array(Dropdown::EMPTY_VALUE), "name" => array(Dropdown::EMPTY_VALUE)); $link = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.php"; $target = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php" . $backValues; $macConstructor = ""; self::getOCSTypes($ocsTypes); self::checkBox($target); echo "<form method='post' id='ipdiscover_form' name='ipdiscover_form' action='{$target}'>"; echo "<div class='center' style=\"width=100%\">"; if ($action == "import") { echo "<input type='submit' class='submit' name='IdentifyAndImport' value=\"" . _sx('button', 'Import') . "\">"; echo " "; } else { echo "<input type='submit' class='submit' name='IdentifyAndLink' value=\"" . _sx('button', 'Link', 'ocsinventoryng') . "\">"; echo " "; } echo "<input type='submit' class='submit' name='delete' value=\"" . _sx('button', 'Delete from OCSNG', 'ocsinventoryng') . "\"></div>"; echo "<table width='100%'class='tab_cadrehov'>\n"; echo Search::showHeaderItem($output_type, __('Date'), $header_num); echo Search::showHeaderItem($output_type, __('MAC address'), $header_num); echo Search::showHeaderItem($output_type, __('IP address'), $header_num); echo Search::showHeaderItem($output_type, __('Subnet mask'), $header_num); echo Search::showHeaderItem($output_type, __('DNS', 'ocsinventoryng'), $header_num); echo Search::showHeaderItem($output_type, __('Description') . "<span class='red'>*</span>", $header_num); echo Search::showHeaderItem($output_type, __('OCS Type', 'ocsinventoryng') . "<span class='red'>*</span>", $header_num); if ($action == "import") { echo Search::showHeaderItem($output_type, __('Name'), $header_num); if (Session::isMultiEntitiesMode()) { echo Search::showHeaderItem($output_type, __('Entity'), $header_num); } echo Search::showHeaderItem($output_type, __('GLPI Type', 'ocsinventoryng') . "<span class='red'>*</span>", $header_num); } else { echo Search::showHeaderItem($output_type, __('Item to link', 'ocsinventoryng'), $header_num, "", 0, "", 'width=15%'); } echo Search::showHeaderItem($output_type, __(' '), $header_num); echo Search::showEndLine($output_type); $row_num = 1; $ocstypes = array(); foreach ($ocsTypes["name"] as $items) { $ocstypes[$items] = $items; } $itemstypes = array(Dropdown::EMPTY_VALUE); foreach (self::$hardwareItemTypes as $items) { $class = getItemForItemtype($items); $itemstypes[$items] = $class->getTypeName(); } for ($i = $start; $i < $lim + $start; $i++) { if (isset($hardware[$i])) { $row_num++; echo Search::showNewLine($output_type, $row_num % 2); echo self::showItem(Html::convDateTime($hardware[$i]["date"])); if (isset($_SESSION["OCS"]["IpdiscoverMacConstructors"])) { $macs = unserialize($_SESSION["OCS"]["IpdiscoverMacConstructors"]); if (isset($macs[mb_strtoupper(substr($hardware[$i]["mac"], 0, 8))])) { $macConstructor = $macs[mb_strtoupper(substr($hardware[$i]["mac"], 0, 8))]; } else { $macConstructor = __("unknow"); } } $mac = $hardware[$i]["mac"] . "<small> ( " . $macConstructor . " )</small>"; echo self::showItem($mac); echo self::showItem($ip = $hardware[$i]["ip"]); echo self::showItem($hardware[$i]["mask"]); echo self::showItem($hardware[$i]["DNS"]); echo "<td><input type=\"text\" name='itemsdescription[" . $i . "]' value=\"\" ></td>"; echo "<td>"; Dropdown::showFromArray("ocsitemstype[{$i}]", $ocstypes); echo "</td>"; if ($action == "import") { echo "<td><input type=\"text\" name='itemsname[" . $i . "]' value=\"\"></td>"; if (Session::isMultiEntitiesMode()) { echo "<td>"; Entity::dropdown(array('name' => "entities[{$i}]", 'entity' => $_SESSION["glpiactiveentities"])); echo "</td>"; } echo "<td>"; Dropdown::showFromArray("glpiitemstype[{$i}]", $itemstypes); echo "</td>"; } else { echo "<td width='10'>"; $mtrand = mt_rand(); $mynamei = "itemtype"; $myname = "tolink_items[" . $i . "]"; $rand = Dropdown::showItemTypes($mynamei, self::$hardwareItemTypes, array('rand' => $mtrand)); $p = array('itemtype' => '__VALUE__', 'entity_restrict' => $_SESSION["glpiactiveentities"], 'id' => $i, 'rand' => $rand, 'myname' => $myname); //print_r($p); Ajax::updateItemOnSelectEvent("dropdown_{$mynamei}{$rand}", "results_{$mynamei}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/ocsinventoryng/ajax/dropdownitems.php", $p); echo "<span id='results_{$mynamei}{$rand}'>\n"; echo "</span>\n"; //} echo "</td>"; } echo self::showItem($hardware[$i]["mac"], "", "", "", true, "", $i); echo "<tbody style=\"display:none\">"; echo "<tr><td><input type=\"hidden\" name='itemsip[" . $i . "]' value=\"{$ip}\" >\n <input type=\"hidden\" name='subnet' value=\"{$ipAdress}\" ></td></tr>"; echo "</tbody>"; } } echo "</table>\n"; echo "<div class='center' style=\"width=100%\">"; if ($action == "import") { echo "<input type='submit' class='submit' name='IdentifyAndImport' value=\"" . _sx('button', 'Import') . "\">"; echo " "; } else { echo "<input type='submit' class='submit' name='IdentifyAndLink' value=\"" . _sx('button', 'Link', 'ocsinventoryng') . "\">"; echo " "; } echo "<input type='submit' class='submit' name='delete' value=\"" . _sx('button', 'Delete from OCSNG', 'ocsinventoryng') . "\"></div>"; Html::closeForm(); self::checkBox($target); break; default: $link = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.php"; $target = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php" . $backValues; $macConstructor = ""; self::checkBox($target); echo "<form method='post' id='ipdiscover_form' name='ipdiscover_form' action='{$target}'>"; echo "<div class='center' style=\"width=100%\">"; if ($action == "import") { echo "<input type='submit' class='submit' name='Import' value=\"" . _sx('button', 'Import') . "\">"; echo " "; } else { echo "<input type='submit' class='submit' name='Link' value=\"" . _sx('button', 'Link', 'ocsinventoryng') . "\">"; echo " "; } echo "<input type='submit' class='submit' name='delete' value=\"" . _sx('button', 'Delete from OCSNG', 'ocsinventoryng') . "\"></div>"; echo "<table width='100%'class='tab_cadrehov'>"; echo Search::showHeaderItem($output_type, __('Date'), $header_num); echo Search::showHeaderItem($output_type, __('Description'), $header_num); echo Search::showHeaderItem($output_type, __('OCS Type', 'ocsinventoryng'), $header_num); echo Search::showHeaderItem($output_type, __('IP address'), $header_num); echo Search::showHeaderItem($output_type, __('MAC address'), $header_num); if ($action == "import") { if (Session::isMultiEntitiesMode()) { echo Search::showHeaderItem($output_type, __('Entity'), $header_num); } echo Search::showHeaderItem($output_type, __('Name'), $header_num); echo Search::showHeaderItem($output_type, __('GLPI Type', 'ocsinventoryng') . "<span class='red'>*</span>", $header_num); } else { echo Search::showHeaderItem($output_type, __('Item to link', 'ocsinventoryng'), $header_num, "", 0, "", 'width=15%'); } echo Search::showHeaderItem($output_type, __(' '), $header_num); echo Search::showEndLine($output_type); $row_num = 1; $itemstypes = array(Dropdown::EMPTY_VALUE); foreach (self::$hardwareItemTypes as $items) { $class = getItemForItemtype($items); $itemstypes[$items] = $class->getTypeName(); } for ($i = $start; $i < $lim + $start; $i++) { if (isset($hardware[$i])) { $row_num++; echo Search::showNewLine($output_type, $row_num % 2); echo self::showItem(Html::convDateTime($hardware[$i]["date"])); echo self::showItem($description = $hardware[$i]["description"]); echo self::showItem($hardware[$i]["type"]); echo self::showItem($ip = $hardware[$i]["ip"]); if (isset($_SESSION["OCS"]["IpdiscoverMacConstructors"])) { $macs = unserialize($_SESSION["OCS"]["IpdiscoverMacConstructors"]); if (isset($macs[mb_strtoupper(substr($hardware[$i]["mac"], 0, 8))])) { $macConstructor = $macs[mb_strtoupper(substr($hardware[$i]["mac"], 0, 8))]; } else { $macConstructor = __("unknow"); } } $mac = $hardware[$i]["mac"] . "<small> ( " . $macConstructor . " )</small>"; echo self::showItem($mac); if ($action == "import") { if (Session::isMultiEntitiesMode()) { echo "<td>"; Entity::dropdown(array('name' => "entities[{$i}]", 'entity' => $_SESSION["glpiactiveentities"])); echo "</td>"; } echo "<td><input type=\"text\" name='itemsname[" . $i . "]' value=\"\"></td>"; echo "<td>"; Dropdown::showFromArray("glpiitemstype[{$i}]", $itemstypes); echo "</td>"; } else { echo "<td width='10'>"; $mtrand = mt_rand(); $mynamei = "itemtype"; $myname = "tolink_items[" . $i . "]"; $rand = Dropdown::showItemTypes($mynamei, self::$hardwareItemTypes, array('rand' => $mtrand)); $p = array('itemtype' => '__VALUE__', 'entity_restrict' => $_SESSION["glpiactiveentities"], 'id' => $i, 'rand' => $rand, 'myname' => $myname); Ajax::updateItemOnSelectEvent("dropdown_{$mynamei}{$rand}", "results_{$mynamei}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/ocsinventoryng/ajax/dropdownitems.php", $p); echo "<span id='results_{$mynamei}{$rand}'>\n"; echo "</span>\n"; echo "</td>"; } echo self::showItem($hardware[$i]["mac"], "", "", "", true, "", $i); echo "<tbody style=\"display:none\">"; echo "<tr><td><input type=\"hidden\" name='itemsip[" . $i . "]' value=\"{$ip}\" >"; echo "<input type=\"hidden\" name='itemsdescription[" . $i . "]' value=\"{$description}\" >\n <input type=\"hidden\" name='subnet' value=\"{$ipAdress}\" ></tr>"; echo "</td></tr></tbody>"; } } echo "</table>"; echo "<div class='center' style=\"width=100%\">"; if ($action == "import") { echo "<input type='submit' class='submit' name='Import' value=\"" . _sx('button', 'Import') . "\">"; echo " "; } else { echo "<input type='submit' class='submit' name='Link' value=\"" . _sx('button', 'Link', 'ocsinventoryng') . "\">"; echo " "; } echo "<input type='submit' class='submit' name='delete' value=\"" . _sx('button', 'Delete from OCSNG', 'ocsinventoryng') . "\"></div>"; Html::closeForm(); self::checkBox($target); break; } } if ($subnet >= 0) { $back = __('Back'); echo "<div class='center'><a href='{$return}?{$returnargs}'>{$back}</div>"; } }