/** * \brief Show aliases for an item from its form * Beware that the rendering can be different if readden from direct item form (ie : add new * NetworkAlias, remove, ...) or if readden from item of the item (for instance from the computer * form through NetworkPort::ShowForItem and NetworkName::ShowForItem). * * @param $item NetworkName object * @param $withtemplate integer withtemplate param (default 0) **/ static function showForNetworkName(NetworkName $item, $withtemplate = 0) { global $DB, $CFG_GLPI; $ID = $item->getID(); if (!$item->can($ID, READ)) { return false; } $canedit = $item->canEdit($ID); $rand = mt_rand(); $query = "SELECT *\n FROM `glpi_networkaliases`\n WHERE `networknames_id` = '{$ID}'"; $result = $DB->query($query); $aliases = array(); if ($number = $DB->numrows($result)) { while ($line = $DB->fetch_assoc($result)) { $aliases[$line["id"]] = $line; } } if ($canedit) { echo "\n<div class='firstbloc'>"; echo "<script type='text/javascript' >\n"; echo "function viewAddAlias{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'NetworkName', 'networknames_id' => $ID, 'id' => -1); Ajax::updateItemJsCode("viewnetworkalias{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>"; echo "<a class='vsubmit' href='javascript:viewAddAlias{$rand}();'>"; echo __('Add a network alias') . "</a>\n"; echo "</div>\n"; } echo "<div id='viewnetworkalias{$rand}'></div>"; echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && $number) { $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_top .= "</th>"; $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= "</th>"; } $header_end .= "<th>" . __('Name') . "</th>"; $header_end .= "<th>" . _n('Internet domain', 'Internet domains', 1) . "</th>"; $header_end .= "<th>" . __('Entity') . "</th>"; $header_end .= "</tr>"; echo $header_begin . $header_top . $header_end; $used = array(); foreach ($aliases as $data) { $showviewjs = $canedit ? "style='cursor:pointer' onClick=\"viewEditAlias" . $data['id'] . "{$rand}();\"" : ''; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td>"; Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); echo "</td>"; } $name = $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]); } echo "<td class='center b' {$showviewjs}>"; if ($canedit) { echo "\n<script type='text/javascript' >\n"; echo "function viewEditAlias" . $data["id"] . "{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'NetworkName', 'networknames_id' => $ID, 'id' => $data["id"]); Ajax::updateItemJsCode("viewnetworkalias{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; } echo "<a href='" . static::getFormURL() . "?id=" . $data["id"] . "'>" . $name . "</a>"; echo "</td>"; echo "<td class='center' {$showviewjs}>" . Dropdown::getDropdownName("glpi_fqdns", $data["fqdns_id"]); echo "<td class='center' {$showviewjs}>" . Dropdown::getDropdownName("glpi_entities", $data["entities_id"]); echo "</tr>"; } if ($number) { echo $header_begin . $header_bottom . $header_end; } echo "</table>"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }