function getSearchOptions() { $tab = parent::getSearchOptions(); $tab[10]['table'] = $this->getTable(); $tab[10]['field'] = 'version'; $tab[10]['name'] = __('IP version'); $tab[10]['massiveaction'] = false; $tab[10]['datatype'] = 'number'; $tab[11]['table'] = $this->getTable(); $tab[11]['field'] = 'address'; $tab[11]['name'] = IPAddress::getTypeName(1); $tab[11]['massiveaction'] = false; $tab[11]['datatype'] = 'string'; $tab[12]['table'] = $this->getTable(); $tab[12]['field'] = 'netmask'; $tab[12]['name'] = IPNetmask::getTypeName(1); $tab[12]['massiveaction'] = false; $tab[12]['datatype'] = 'string'; $tab[13]['table'] = $this->getTable(); $tab[13]['field'] = 'gateway'; $tab[13]['name'] = __('Gateway'); $tab[13]['massiveaction'] = false; $tab[13]['datatype'] = 'string'; $tab[14]['table'] = $this->getTable(); $tab[14]['field'] = 'addressable'; $tab[14]['name'] = __('Addressable network'); $tab[14]['datatype'] = 'bool'; return $tab; }
/** * Get available display options array * * @since version 0.84 * * @return all the options **/ static function getAvailableDisplayOptions() { $options[__('Global displays')] = array('characteristics' => array('name' => __('Characteristics'), 'default' => true), 'internet' => array('name' => __('Internet information'), 'default' => true), 'dynamic_import' => array('name' => __('Automatic inventory'), 'default' => false)); $options[__('Common options')] = NetworkPortInstantiation::getGlobalInstantiationNetworkPortDisplayOptions(); $options[__('Internet information')] = array('names' => array('name' => NetworkName::getTypeName(2), 'default' => false), 'aliases' => array('name' => NetworkAlias::getTypeName(2), 'default' => false), 'ipaddresses' => array('name' => IPAddress::getTypeName(2), 'default' => true), 'ipnetworks' => array('name' => IPNetwork::getTypeName(2), 'default' => true)); foreach (self::getNetworkPortInstantiations() as $portType) { $portTypeName = $portType::getTypeName(0); $options[$portTypeName] = $portType::getInstantiationNetworkPortDisplayOptions(); } return $options; }
/** * @param $networkPortID **/ static function showFormForNetworkPort($networkPortID) { global $DB, $CFG_GLPI; $name = new self(); $number_names = 0; if ($networkPortID > 0) { $query = "SELECT `id`\n FROM `" . $name->getTable() . "`\n WHERE `itemtype` = 'NetworkPort'\n AND `items_id` = '{$networkPortID}'\n AND `is_deleted` = '0'"; $result = $DB->query($query); if ($DB->numrows($result) > 1) { echo "<tr class='tab_bg_1'><th colspan='4'>" . __("Several network names available! Go to the tab 'Network Name' to manage them.") . "</th></tr>\n"; return; } switch ($DB->numrows($result)) { case 1: $nameID = $DB->fetch_assoc($result); $name->getFromDB($nameID['id']); break; case 0: $name->getEmpty(); break; } } else { $name->getEmpty(); } echo "<tr class='tab_bg_1'><th colspan='4'>"; // If the networkname is defined, we must be able to edit it. So we make a link if ($name->getID() > 0) { echo "<a href='" . $name->getLinkURL() . "'>" . self::getTypeName(1) . "</a>"; echo "<input type='hidden' name='NetworkName_id' value='" . $name->getID() . "'> \n"; Html::showSimpleForm($name->getFormURL(), 'unaffect', _sx('button', 'Dissociate'), array('id' => $name->getID()), $CFG_GLPI["root_doc"] . '/pics/sub_dropdown.png'); } else { echo self::getTypeName(1); } echo "</th>\n"; echo "</tr><tr class='tab_bg_1'>"; echo "<td>" . self::getTypeName(1) . "</td><td>\n"; Html::autocompletionTextField($name, "name", array('name' => 'NetworkName_name')); echo "</td>\n"; echo "<td>" . FQDN::getTypeName(1) . "</td><td>"; Dropdown::show(getItemTypeForTable(getTableNameForForeignKeyField("fqdns_id")), array('value' => $name->fields["fqdns_id"], 'name' => 'NetworkName_fqdns_id', 'entity' => $name->getEntityID(), 'displaywith' => array('view'))); echo "</td>\n"; echo "</tr><tr class='tab_bg_1'>\n"; echo "<td>" . IPAddress::getTypeName(Session::getPluralNumber()); IPAddress::showAddChildButtonForItemForm($name, 'NetworkName__ipaddresses'); echo "</td>"; echo "<td>"; IPAddress::showChildsForItemForm($name, 'NetworkName__ipaddresses'); echo "</td>"; // MoYo : really need to display it here ? // make confure because not updatable // echo "<td>".IPNetwork::getTypeName(Session::getPluralNumber())." "; // Html::showToolTip(__('IP network is not included in the database. However, you can see current available networks.')); // echo "</td><td>"; // IPNetwork::showIPNetworkProperties($name->getEntityID()); // echo "</td>\n"; echo "<td colspan='2'> </td>"; echo "</tr>\n"; }
/** * @since version 0.84 * * @param $networkport_prefix * @param $networkport_crit * @param $where_crit * @param $order (default '') * @param $field (default '') * @param $extra (default '') **/ static function reportForNetworkInformations($networkport_prefix, $networkport_crit, $where_crit, $order = '', $field = '', $extra = '') { global $DB; // This SQL request matches the NetworkPort, then its NetworkName and IPAddreses. It also // match opposite NetworkPort, then its NetworkName and IPAddresses. // Results are groupes by NetworkPort. Then all IPs are concatenated by comma as separator. $query = "SELECT {$field}\n PORT_1.`itemtype` AS itemtype_1,\n PORT_1.`items_id` AS items_id_1,\n PORT_1.`id` AS id_1,\n PORT_1.`name` AS port_1,\n PORT_1.`mac` AS mac_1,\n GROUP_CONCAT(ADDR_1.`name` SEPARATOR ',') AS ip_1,\n PORT_2.`itemtype` AS itemtype_2,\n PORT_2.`items_id` AS items_id_2,\n PORT_2.`id` AS id_2,\n PORT_2.`name` AS port_2,\n PORT_2.`mac` AS mac_2,\n GROUP_CONCAT(ADDR_2.`name` SEPARATOR ',') AS ip_2\n FROM {$networkport_prefix}\n INNER JOIN `glpi_networkports` AS PORT_1\n ON ({$networkport_crit} AND PORT_1.`is_deleted` = 0)\n LEFT JOIN `glpi_networknames` AS NAME_1\n ON (NAME_1.`itemtype` = 'NetworkPort'\n AND PORT_1.`id` = NAME_1.`items_id`\n AND NAME_1.`is_deleted` = 0)\n LEFT JOIN `glpi_ipaddresses` AS ADDR_1\n ON (ADDR_1.`itemtype` = 'NetworkName'\n AND NAME_1.`id` = ADDR_1.`items_id`\n AND ADDR_1.`is_deleted` = 0)\n LEFT JOIN `glpi_networkports_networkports` AS LINK\n ON (LINK.`networkports_id_1` = PORT_1.`id`\n OR LINK.`networkports_id_2` = PORT_1.`id`)\n LEFT JOIN `glpi_networkports` AS PORT_2\n ON (PORT_2.`id`=IF(LINK.`networkports_id_1`=PORT_1.`id`,\n LINK.`networkports_id_2`,\n LINK.`networkports_id_1`))\n LEFT JOIN `glpi_networknames` AS NAME_2\n ON (NAME_2.`itemtype` = 'NetworkPort'\n AND PORT_2.`id` = NAME_2.`items_id`\n AND NAME_2.`is_deleted` = 0)\n LEFT JOIN `glpi_ipaddresses` AS ADDR_2\n ON (ADDR_2.`itemtype` = 'NetworkName'\n AND NAME_2.`id` = ADDR_2.`items_id`\n AND ADDR_2.`is_deleted` = 0)\n WHERE {$where_crit} GROUP BY PORT_1.`id`"; if (!empty($order)) { $query .= "ORDER BY {$order}"; } $result = $DB->request($query); if ($result->numrows() > 0) { echo "<table class='tab_cadre_fixehov'>"; echo "<tr>"; if (!empty($extra)) { echo "<td> </td>"; } echo "<th colspan='5'>" . __('Device 1') . "</th>"; echo "<th colspan='5'>" . __('Device 2') . "</th>"; echo "</tr>\n"; echo "<tr>"; if (!empty($extra)) { echo "<th>{$extra}</th>"; } echo "<th>" . __('Device type') . "</th>"; echo "<th>" . __('Device name') . "</th>"; echo "<th>" . NetworkPort::getTypeName(1) . "</th>"; echo "<th>" . __('MAC address') . "</th>"; echo "<th>" . IPAddress::getTypeName(0) . "</th>"; echo "<th>" . NetworkPort::getTypeName(1) . "</th>"; echo "<th>" . __('MAC address') . "</th>"; echo "<th>" . IPAddress::getTypeName(0) . "</th>"; echo "<th>" . __('Device type') . "</th>"; echo "<th>" . __('Device name') . "</th>"; echo "</tr>\n"; foreach ($result as $line) { echo "<tr class='tab_bg_1'>"; // To ensure that the NetworkEquipment remain the first item, we test its type if ($line['itemtype_2'] == 'NetworkEquipment') { $idx = 2; } else { $idx = 1; } if (!empty($extra)) { echo "<td>" . (empty($line['extra']) ? NOT_AVAILABLE : $line['extra']) . "</td>"; } $itemtype = $line["itemtype_{$idx}"]; if (!empty($itemtype)) { echo "<td>" . $itemtype::getTypeName(1) . "</td>"; $item_name = ''; if ($item = getItemForItemtype($itemtype)) { if ($item->getFromDB($line["items_id_{$idx}"])) { $item_name = $item->getName(); } } echo "<td>" . (empty($item_name) ? NOT_AVAILABLE : $item_name) . "</td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; echo "<td> " . NOT_AVAILABLE . " </td>"; } echo "<td>" . (empty($line["port_{$idx}"]) ? NOT_AVAILABLE : $line["port_{$idx}"]) . "</td>"; echo "<td>" . (empty($line["mac_{$idx}"]) ? NOT_AVAILABLE : $line["mac_{$idx}"]) . "</td>"; echo "<td>" . (empty($line["ip_{$idx}"]) ? NOT_AVAILABLE : $line["ip_{$idx}"]) . "</td>"; if ($idx == 1) { $idx = 2; } else { $idx = 1; } echo "<td>" . (empty($line["port_{$idx}"]) ? NOT_AVAILABLE : $line["port_{$idx}"]) . "</td>"; echo "<td>" . (empty($line["mac_{$idx}"]) ? NOT_AVAILABLE : $line["mac_{$idx}"]) . "</td>"; echo "<td>" . (empty($line["ip_{$idx}"]) ? NOT_AVAILABLE : $line["ip_{$idx}"]) . "</td>"; $itemtype = $line["itemtype_{$idx}"]; if (!empty($itemtype)) { echo "<td>" . $itemtype::getTypeName(1) . "</td>"; $item_name = ''; if ($item = getItemForItemtype($itemtype)) { if ($item->getFromDB($line["items_id_{$idx}"])) { $item_name = $item->getName(); } } echo "<td>" . (empty($item_name) ? NOT_AVAILABLE : $item_name) . "</td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; echo "<td> " . NOT_AVAILABLE . " </td>"; } echo "</tr>\n"; } echo "</table><br><hr><br>"; } }
function getSearchOptions() { global $CFG_GLPI; $tab = parent::getSearchOptions(); $optionIndex = 10; // From 10 to 14 foreach (self::getMotives() as $motive => $name) { $tab[$optionIndex]['table'] = $this->getTable(); $tab[$optionIndex]['field'] = $motive; $tab[$optionIndex]['name'] = $name; $tab[$optionIndex]['datatype'] = 'bool'; $optionIndex++; } $tab[20]['table'] = $this->getTable(); $tab[20]['field'] = 'ip'; $tab[20]['datatype'] = 'ip'; $tab[20]['name'] = IPAddress::getTypeName(1); $tab[21]['table'] = $this->getTable(); $tab[21]['field'] = 'netmask'; $tab[21]['datatype'] = 'string'; $tab[21]['name'] = IPNetmask::getTypeName(1); $tab[22]['table'] = $this->getTable(); $tab[22]['field'] = 'subnet'; $tab[22]['datatype'] = 'string'; $tab[22]['name'] = __('Network address'); $tab[23]['table'] = $this->getTable(); $tab[23]['field'] = 'gateway'; $tab[23]['datatype'] = 'string'; $tab[23]['name'] = IPAddress::getTypeName(1); if (TableExists('glpi_networkinterfaces')) { $tab[24]['table'] = 'glpi_networkinterfaces'; $tab[24]['field'] = 'name'; $tab[24]['datatype'] = 'dropdown'; $tab[24]['name'] = __('Network interface'); } return $tab; }
/** * 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"; }