function renderTopEditItems()
{
    echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"three/css/item.css\"></link>\n";
    $item = array();
    $item['itemid'] = isset($_REQUEST['item_id']) ? $_REQUEST['item_id'] : -1;
    $item['hostid'] = isset($_REQUEST['hostid']) ? $_REQUEST['hostid'] : -1;
    $item['objectid'] = isset($_REQUEST['objectid']) ? $_REQUEST['objectid'] : -1;
    // Main layout starts.
    printOpFormIntro('updateObjectItems');
    echo '<table border=0 class=objectview cellspacing=0 cellpadding=0><tr>';
    // Left portlet with rack list.
    echo '<td class=pcleft height="1%" width="25%">';
    startPortlet('Objects');
    // object select area
    $disabled = '';
    if ($item['itemid'] >= 0) {
        $disabled = 'disabled';
        $query = "select * from item_information where itemid = '{$item['itemid']}'";
        $result = usePreparedSelectBlade($query);
        $item = $result->fetch(PDO::FETCH_ASSOC);
    }
    echo "<select name=objectid style=width:50%; {$disabled} size=" . getConfigVar('MAXSELSIZE') . " onchange=getElementsByName(\"updateObjectItems\")[0].submit()>\n";
    $allObjects = scanRealmByText('object');
    $objectlist = array();
    foreach ($allObjects as $object) {
        //echo '<option value=' . $object['id'];
        if ($item['objectid'] < 0) {
            $item['objectid'] = $object['id'];
        }
        echo '<option value=' . $object['id'];
        if ($object['id'] == $item['objectid']) {
            echo ' selected';
        }
        echo '>' . $object['name'] . "</option>\n";
    }
    echo "</select>\n";
    echo '<br><br>';
    finishPortlet();
    echo '</td>';
    // item edit area
    echo '<td class=pcright>';
    if ($item['itemid'] >= 0) {
        startPortlet('Update Item');
    } else {
        startPortlet('Add Item');
    }
    echo "<div id=itemFormList>\n";
    echo "<input type=hidden name=item_id value='{$item['itemid']}'>\n";
    echo "<ul class=formlist>\n";
    // name
    echo "<li class=formrow id=row_name>\n";
    echo "<div class='dt right'><label for=name>Name</label></div>\n";
    echo "<div class=dd>";
    echo "<input class='input text' type=text id=name name=name value='{$item['name']}' size=50 maxlength=255 style=width:380px; autofocus=autofocus>\n";
    echo "</div></li>\n";
    // type
    echo "<li class=formrow id=row_type>\n";
    echo "<div class='dt right'><label for=type>Type</label></div>\n";
    echo "<div class=dd>";
    echo "<div style='width:380px;' align=left>";
    global $itemtypelist;
    $typelist = array("other" => $itemtypelist);
    printNiftySelect($typelist, array('name' => 'type'), $item['type']);
    echo "</div></div>";
    echo "</li>\n";
    // key
    echo "<li class=formrow id=row_key_>\n";
    echo "<div class='dt right'><label for=key_>Key</label></div>\n";
    echo "<div class=dd><input class='input text' type=text id=key_ name=key_ value='{$item['key_']}' size=50 maxlength=255 style=width:380px;></div>\n";
    echo "</li>\n";
    // interfaceid
    $object = spotEntity('object', $item['objectid']);
    $item['hostid'] = searchHost($object['name'])[$object['name']];
    // hostid
    echo "<input type=hidden name=hostid value='{$item['hostid']}' />\n";
    echo "<li class=formrow id=row_interfaceid style=display:none;>\n";
    echo "<div class='dt right'><label for=interface>Host interface</label></div>\n";
    echo "<div class=dd>";
    echo "<div style='width:380px;' align=left>";
    $interfacesDatas = searchInterfaces($item['hostid']);
    $agentips = array();
    $snmpips = array();
    $jmxips = array();
    $ipmiips = array();
    foreach ($interfacesDatas as $interface) {
        switch ($interface['type']) {
            case 1:
                array_push($agentips, $interface);
                break;
            case 2:
                array_push($snmpips, $interface);
                break;
            case 4:
                array_push($jmxips, $interface);
                break;
            case 3:
                array_push($ipmiips, $interface);
                break;
        }
    }
    echo "<select name=interfaceid id=interfaceid>";
    if (count($agentips) > 0) {
        echo "<optgroup label=Agent id=agentips>";
        foreach ($agentips as $interface) {
            $selected = '';
            $id = '';
            if ($interface['interfaceid'] == $item['interfaceid']) {
                $selected = 'selected';
                $id = 'interfaceidSelected';
            } else {
                if ($interface['main'] == 1) {
                    $id = 'agentipsInterfaceidMain';
                }
            }
            echo "<option id='{$id}' value='{$interface['interfaceid']}' {$selected}>{$interface['ip']}:{$interface['port']}</option>";
        }
        echo "</optgroup>";
    }
    if (count($snmpips) > 0) {
        echo "<optgroup label=SNMP id=snmpips>";
        foreach ($snmpips as $interface) {
            $selected = '';
            $id = '';
            if ($interface['interfaceid'] == $item['interfaceid']) {
                $selected = 'selected';
                $id = 'interfaceidSelected';
            } else {
                if ($interface['main'] == 1) {
                    $id = 'snmpipsInterfaceidMain';
                }
            }
            echo "<option id='{$id}' value='{$interface['interfaceid']}' {$selected}>{$interface['ip']}:{$interface['port']}</option>";
        }
        echo "</optgroup>";
    }
    if (count($ipmiips) > 0) {
        echo "<optgroup label=IPMI id=ipmiips>";
        foreach ($ipmiips as $interface) {
            $selected = '';
            $id = '';
            if ($interface['interfaceid'] == $item['interfaceid']) {
                $selected = 'selected';
                $id = 'interfaceidSelected';
            } else {
                if ($interface['main'] == 1) {
                    $id = 'ipmiipsInterfaceidMain';
                }
            }
            echo "<option id='{$id}' value='{$interface['interfaceid']}' {$selected}>{$interface['ip']}:{$interface['port']}</option>";
        }
        echo "</optgroup>";
    }
    if (count($jmxips) > 0) {
        echo "<optgroup label=JMX id=jmxips>";
        foreach ($jmxips as $interface) {
            $selected = '';
            $id = '';
            if ($interface['interfaceid'] == $item['interfaceid']) {
                $selected = 'selected';
                $id = 'interfaceidSelected';
            } else {
                if ($interface['main'] == 1) {
                    $id = 'jmxipsInterfaceidMain';
                }
            }
            echo "<option id='{$id}' value='{$interface['interfaceid']}' {$selected}>{$interface['ip']}:{$interface['port']}</option>";
        }
        echo "</optgroup>";
    }
    echo "</select>";
    echo "<span class=red id=interface_not_defined style=color:red;display:none;>No interface found.</span>";
    echo "</div></div>";
    echo "</li>\n";
    // Authentication method
    echo "<li class=formrow id=row_authtype style=display:none;>";
    echo "<div class='dt right'><label for=authtype>Authentication method</label></div>";
    echo "<div class=dd>";
    $authtypes = array("other" => array('0' => 'Password', '1' => 'Public key'));
    printNiftySelect($authtypes, array('name' => 'authtype'), $item['authtype']);
    echo "</div></li>\n";
    // Username
    echo "<li class=formrow id=row_username style=display:none;>";
    echo "<div class='dt right'><label for=username>Username</label></div>";
    echo "<div class=dd><input class='input text' type=text id=username name=username value='{$item['username']}' size=25 maxlength=64 style=display:inline;>";
    echo "</div></li>\n";
    // Password
    echo "<li class=formrow id=row_password style=display:none;>";
    echo "<div class='dt right'><label for=password>password</label></div>";
    echo "<div class=dd><input class='input text' type=text id=password name=password value='{$item['password']}' size=25 maxlength=64 style=display:inline;>";
    echo "</div></li>\n";
    // Public key file
    echo "<li class=formrow id=row_publickey style=display:none;>";
    echo "<div class='dt right'><label for=publickey>Public key file</label></div>";
    echo "<div class=dd><input class='input text' type=text id=publickey name=publickey value='{$item['publickey']}' size=25 maxlength=64 disabled='' style=display:;>";
    echo "</div></li>\n";
    // Private key file
    echo "<li class=formrow id=row_privatekey style=display:none;>";
    echo "<div class='dt right'><label for=privatekey>Private key file</label></div>";
    echo "<div class=dd><input class='input text' type=text id=privatekey name=privatekey value='{$item['privatekey']}' size=25 maxlength=64 disabled='' style=display:;>";
    echo "</div></li>\n";
    // Key passphrase
    echo "<li class=formrow id=row_password_key style=display:none;>";
    echo "<div class='dt right'><label for=password>Key passphrase</label></div>";
    echo "<div class=dd><input class='input text' type=text id=password name=password value='{$item['password']}' size=25 maxlength=64 style=display:inline;>";
    echo "</div></li>\n";
    // Executed script
    echo "<li class=formrow id=row_executed_script style=display:none;>";
    echo "<div class='dt right'><label for=params_es>Executed script</label></div>";
    echo "<div class=dd><textarea class='input textarea_standard' id=params name=params rows=7 style=width:380px;>{$item['params']}</textarea>";
    echo "</div></li>\n";
    // SQL query
    echo "<li class=formrow id=row_params style=display:none;>";
    echo "<div class='dt right'><label for=params_ap>SQL query</label></div>";
    echo "<div class=dd><textarea class='input textarea_standard' id=params name=params rows=7 style=width:380px;>{$item['params']}</textarea>";
    echo "</div></li>";
    // SNMP OID
    echo "<li class=formrow id=row_snmp_oid style=display:none;>";
    echo "<div class='dt right'><label for=snmp_oid>SNMP OID</label></div>";
    echo "<div class=dd>";
    echo "<input class='input text' type=text id=snmp_oid name=snmp_oid value='{$item['snmp_oid']}' size=50 maxlength=255 style=width:380px;display:; disabled=''>";
    echo "</div></li>\n";
    // SNMP community
    echo "<li class=formrow id=row_snmp_community style=display:none;>";
    echo "<div class='dt right'><label for=snmp_community>SNMP community</label></div>";
    echo "<div class=dd><input class='input text' type=text id=snmp_community name=snmp_community value='{$item['snmp_community']}' size=50 maxlength=64 style=width:380px;display:inline;>";
    echo "</div></li>\n";
    // Context name
    echo "<li class=formrow id=row_snmpv3_contextname style=display:none;>";
    echo "<div class='dt right'><label for=snmpv3_contextname>Context name</label></div>";
    echo "<div class=dd>";
    echo "<input class='input text' type=text id=snmpv3_contextname name=snmpv3_contextname value='{$item['snmpv3_contextname']}' size=50 maxlength=255 style=width:380px;display:inline;>";
    echo "</div></li>\n";
    // Security name
    echo "<li class=formrow id=row_snmpv3_securityname style=display:none;>";
    echo "<div class='dt right'><label for=snmpv3_securityname>Security name</label></div>";
    echo "<div class=dd>";
    echo "<input class='input text' type=text id=snmpv3_securityname name=snmpv3_securityname value='{$item['snmpv3_securityname']}' size=50 maxlength=255 style=width:380px;display:inline;>";
    echo "</div></li>\n";
    // Security level
    echo "<div id=snmpv3_securitylevel_rows style=display:none;>";
    echo "<li class=formrow id=row_snmpv3_securitylevel>";
    echo "<div class='dt right'><label for=snmpv3_securitylevel>Security level</label></div>";
    echo "<div class=dd>";
    $snmpv3_securitylevels = array("other" => array('0' => 'noAuthNoPriv', '1' => 'authNoPriv', '2' => 'authPriv'));
    printNiftySelect($snmpv3_securitylevels, array('name' => 'snmpv3_securitylevel'), $item['snmpv3_securitylevel']);
    echo "</div></li>\n";
    // Authentication protocol
    echo "<li class=formrow id=row_snmpv3_authprotocol>";
    echo "<div class='dt right'>Authentication protocol</div>";
    echo "<div class=dd>";
    echo "<div class='jqueryinputset ui-buttonset'>";
    $checked = array();
    if (isset($item['snmpv3_authprotocol'])) {
        $checked[$item['snmpv3_authprotocol']] = 'checked=checked';
    } else {
        $checked[0] = 'checked=checked';
    }
    echo "<input name=snmpv3_authprotocol value=0 id=snmpv3_authprotocol_0 type=radio {$checked['0']} class=ui-helper-hidden-accessible>";
    echo "<label for=snmpv3_authprotocol_0 class='ui-state-active ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left' role=button aria-disabled=false>";
    echo "<span class=ui-button-text>MD5</span></label>";
    echo "<input name=snmpv3_authprotocol value=1 id=snmpv3_authprotocol_1 type=radio {$checked['1']} class=ui-helper-hidden-accessible>";
    echo "<label for=snmpv3_authprotocol_1 class='ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right' role=button aria-disabled=false>";
    echo "<span class=ui-button-text>SHA</span></label>";
    echo "</div></div></li>\n";
    // Authentication passphrase
    echo "<li class=formrow id=row_snmpv3_authpassphrase>";
    echo "<div class='dt right'><label for=snmpv3_authpassphrase>Authentication passphrase</label></div>";
    echo "<div class=dd>";
    echo "<input class='input text' type=text id=snmpv3_authpassphrase name=snmpv3_authpassphrase value='{$item['snmpv3_authpassphrase']}' size=50 maxlength=64 style=width:380px;display:inline;>";
    echo "</div></li>\n";
    // Privacy protocol
    echo "<li class=formrow id=row_snmpv3_privprotocol>";
    echo "<div class='dt right'>Privacy protocol</div>";
    echo "<div class=dd><div class='jqueryinputset ui-buttonset'>";
    $checked = array();
    if (isset($item['snmpv3_privprotocol'])) {
        $checked[$item['snmpv3_privprotocol']] = 'checked=checked';
    } else {
        $checked[0] = 'checked=checked';
    }
    echo "<input name=snmpv3_privprotocol value=0 id=snmpv3_privprotocol_0 type=radio {$checked['0']} class=ui-helper-hidden-accessible>";
    echo "<label for=snmpv3_privprotocol_0 class='ui-state-active ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left' role=button aria-disabled=false>";
    echo "<span class=ui-button-text>DES</span></label>";
    echo "<input name=snmpv3_privprotocol value=1 id=snmpv3_privprotocol_1 type=radio {$checked['1']} class=ui-helper-hidden-accessible>";
    echo "<label for=snmpv3_privprotocol_1 class='ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right' role=button aria-disabled=false>";
    echo "<span class=ui-button-text>AES</span></label>";
    echo "</div></div></li>\n";
    // Privacy passphrase
    echo "<li class=formrow id=row_snmpv3_privpassphrase>";
    echo "<div class='dt right'><label for=snmpv3_privpassphrase>Privacy passphrase</label></div>";
    echo "<div class=dd>";
    echo "<input class='input text' type=text id=snmpv3_privpassphrase name=snmpv3_privpassphrase value='{$item['snmpv3_privpassphrase']}' size=50 maxlength=255 style=width:380px;display:inline;>";
    echo "</div></li>\n";
    echo "</div>\n";
    // Port
    echo "<li class=formrow id=row_port style=display:none;>";
    echo "<div class='dt right'><label for=port>Port</label></div>";
    echo "<div class=dd><input class='input text' type=text id=port name=port value='{$item['port']}' size=25 maxlength=64 disabled='' style=display:;>";
    echo "</div></li>\n";
    // IPMI sensor
    echo "<li class=formrow id=row_ipmi_sensor style=display:none;>";
    echo "<div class='dt right'><label for=ipmi_sensor>IPMI sensor</label></div>";
    echo "<div class=dd><input class='input text' type=text id=ipmi_sensor name=ipmi_sensor value='{$item['ipmi_sensor']}' size=50 maxlength=128 style=width:380px;display:; disabled=''>";
    echo "</div></li>\n";
    // Formula
    echo "<li class=formrow id=row_params_f>";
    echo "<div class='dt right'><label for=params_f>Formula</label></div>";
    echo "<div class=dd><textarea class='input textarea_standard' id=params name=params rows=7 style=width:380px;>{$item['params']}</textarea>";
    echo "</div></li>\n";
    // value_type
    echo "<li class=formrow id=row_value_type>\n";
    echo "<div class='dt right'><label for=value_type>Type of information</label></div>\n";
    echo "<div class=dd>";
    echo "<div style='width:380px;' align=left>";
    global $itemvalue_types;
    echo "<select name=value_type id=value_type>";
    if (!isset($item['value_type'])) {
        $item['value_type'] = 3;
    }
    foreach ($itemvalue_types as $key => $value) {
        $selected = '';
        if ($key == $item['value_type']) {
            $selected = 'selected';
        }
        echo "<option id='value_type_{$key}' value='{$key}' {$selected}>{$value}</option>";
    }
    echo "</select>";
    echo "</div></div>";
    echo "</li>\n";
    // data_type
    echo "<li class=formrow id=row_data_type>\n";
    echo "<div class='dt right'><label for=data_type>Data type</label></div>\n";
    echo "<div class=dd>";
    echo "<div style=width:380px; align=left>";
    global $itemdata_types;
    $data_types = array("other" => $itemdata_types);
    if (!isset($item['data_type'])) {
        $item['data_type'] = 0;
    }
    printNiftySelect($data_types, array('name' => 'data_type'), $item['data_type']);
    echo "</div></div>";
    echo "</li>\n";
    // units
    echo "<li class=formrow id=row_units style=display:none;>\n";
    echo "<div class='dt right'><label for=units>Units</label></div>\n";
    echo "<div class=dd><input class='input text' type=text id=units name=units value='{$item['units']}' size=50 maxlength=255 style=width:380px;></div>\n";
    echo "</li>\n";
    // (formula & multiplier)
    echo "<li class=formrow id=row_formula style=display:none;>\n";
    echo "<div class='dt right'><label for=formula>Use custom multiplier</label></div>\n";
    echo "<div class=dd>";
    echo "<div style=width:380px; align=left>";
    $checked = $item['multiplier'] == 1 ? 'checked=checked' : '';
    echo "<input class='input checkbox pointer' type=checkbox id=multiplier name=multiplier value=1 {$checked} style=display:inline;>&nbsp;";
    $formula = isset($item['formula']) ? $item['formula'] : 1;
    echo "<input class='input text' type=text id=formula name=formula value='{$formula}' size=25 maxlength=255 style=text-align:right; ";
    echo "onchange=\"validateNumericBox(this, false, 1);\"></input>";
    echo "</div></div>";
    echo "</li>\n";
    // delay
    echo "<li class=formrow id=row_delay>\n";
    echo "<div class='dt right'><label for=delay>Update interval (in sec)</label></div>\n";
    echo "<div class=dd>";
    $delay = isset($item['delay']) ? $item['delay'] : 30;
    echo "<input class='input text' type=text id=delay name=delay value='{$delay}' size=50 maxlength=255 style=width:50px;text-align:right;display:inline; ";
    echo "onchange=\"validateNumericBox(this, false, 0);\"></div>\n";
    echo "</li>\n";
    // delay_flex
    echo "<div id=flex_intervals_rows>";
    echo "<li class=formrow id=row_flex_intervals style=display:;>";
    echo "<div class='dt right'>Flexible intervals</div>";
    echo "<div class=dd>";
    echo "<div class='objectgroup inlineblock border_dotted ui-corner-all'>";
    echo "<table class=formElementTable style=width:380px; id=delayFlexTable>";
    echo "<tr class=header><td style=width:25%>INTERVAL</td><td style=width:50%>PERIOD</td><td style=width:25%>ACTION</td></tr>";
    echo "<tr>";
    echo "<td class=message colspan=3 id=delay_flex_message>No flexible intervals defined.</td>";
    echo "</tr>";
    echo "</table>";
    echo "</div></div>";
    echo "</li>\n";
    // New flexible interval
    echo "<li class='new formrow' id=row_new_delay_flex>";
    echo "<div class='dt right'>New flexible interval</div>";
    echo "<div class=dd>";
    echo "<div style=width:380px;>";
    echo "<span id=row-new-delay-flex-fields>";
    echo "<span style=width:20%>Interval (in sec) &nbsp;</span>";
    echo "<input class='input text' type=text id=new_delay_flex_delay name=new_delay_flex value='50' size=5 maxlength=5 style=text-align:right;width:15% ";
    echo "onchange=\"validateNumericBox(this, false, 0);\">";
    echo "<span style=width:15%>Period </span>";
    echo "<input class='input text' type=text id=new_delay_flex_period name=new_delay_flex value='1-7,00:00-24:00' size=20 maxlength=255 style=width:35%>&nbsp;";
    echo "<input class='input formlist' type=button id=add_delay_flex name=add_delay_flex value=Add style=display:inline;width:10%; onclick=javascript:addDelayFlex();>";
    echo "</span></div></div></li>\n";
    echo "</div>\n";
    // History storage period (in days)
    echo "<li class=formrow id=row_history>";
    echo "<div class='dt right'>History storage period (in days)</div>";
    echo "<div class=dd>";
    echo "<div style=width:380px; align=left>";
    $history = isset($item['history']) ? $item['history'] : 90;
    echo "<input class='input text' type=text id=history name=history value='{$history}' size=8 maxlength=8 style=text-align:right; ";
    echo "onchange=\"validateNumericBox(this, false, 0);\">";
    echo "</div></div>";
    echo "</li>\n";
    // Trend storage period (in days)
    echo "<li class=formrow id=row_trends>";
    echo "<div class='dt right'>Trend storage period (in days)</div>";
    echo "<div class=dd>";
    echo "<div style=width:380px; align=left>";
    $trends = isset($item['trends']) ? $item['trends'] : 365;
    echo "<input class='input text' type=text id=trends name=trends value='{$trends}' size=8 maxlength=8 style=text-align:right; ";
    echo "onchange=\"validateNumericBox(this, false, 0);\">";
    echo "</div></div>";
    echo "</li>\n";
    // logtimefmt
    echo "<li class=formrow id=row_logtimefmt style=display:none;>";
    echo "<div class='dt right'><label for=logtimefmt>Log time format</label></div>";
    echo "<div class=dd><input class='input text' type=text id=logtimefmt name=logtimefmt value='' size=25 maxlength=64 disabled='' style=display:;>";
    echo "</div></li>\n";
    // delta
    echo "<li class=formrow id=row_delta>";
    echo "<div class='dt right'><label for=delta>Store value</label></div>";
    echo "<div class=dd>";
    echo "<div style=width:380px; align=left>";
    $deltas = array("other" => array('0' => 'As is', '1' => 'Delta (speed per second)', '2' => 'Delta (simple change)'));
    printNiftySelect($deltas, array('name' => 'delta'), $item['delta']);
    echo "</div></div></li>\n";
    /*
    // Show value
    echo "<li class=formrow id=row_valuemap style=display:none;>";
    echo "<div class='dt right'><label for=valuemap>Show value</label></div>";
    echo "<div class=dd>";
    
    echo "</li>\n";
    */
    // trapper_hosts
    echo "<li class=formrow id=row_trapper_hosts style=display:none;>";
    echo "<div class='dt right'><label for=trapper_hosts>Allowed hosts</label></div>";
    echo "<div class=dd><input class='input text' type=text id=trapper_hosts name=trapper_hosts value='' size=50 maxlength=255 style=width:380px;display:; disabled=''>";
    echo "</div></li>\n";
    /*
    // New application
    echo "<li class=formrow id=row_new_application>";
    echo "<div class='dt right'><label for=new_application>New application</label></div>";
    echo "<div class=dd><input class='input text' type=text id=new_application name=new_application value='${item['trapper_hosts']}' size=50 maxlength=255 style=width:380px;></div>\n";
    echo "</li>\n";
    
    // Applications
    echo "<li class=formrow id=row_applications>";
    echo "<div class='dt right'><label for=applications>Applications</label></div>";
    echo "<div class=dd>";
    
    $result = getApplication($item['hostid']);
    $applicationLists = array('0' => 'None');
    foreach($result["result"] as $application) {
    	$applicationLists[$application['applicationid']] = $application['name'];
    }
    $applicationLists = array("other" => $applicationLists );
    printNiftySelect ($applicationLists, array ('name' => 'applications'), $item['applications']);
    echo "</li>\n";
    */
    // inventory_link
    echo "<li class=formrow id=row_inventory_link>";
    echo "<div class='dt right'><label for=inventory_link>Populates host inventory field</label></div>";
    echo "<div class=dd>";
    echo "<div style=width:380px; align=left>";
    $inventory_links = array("other" => array('0' => '-None-', '1' => 'Type', '2' => 'Type (Full details)', '3' => 'Name', '4' => 'Alias', '5' => 'OS', '6' => 'OS (Full details)', '7' => 'OS (Short)', '8' => 'Serial number A', '9' => 'Serial number B', '10' => 'Tag', '11' => 'Asset tag', '12' => 'MAC address A', '13' => 'MAC address B', '14' => 'Hardware', '15' => 'Hardware (Full details)', '16' => 'Software', '17' => 'Software (Full details)', '18' => 'Software application A', '19' => 'Software application B', '20' => 'Software application C', '21' => 'Software application D', '22' => 'Software application E', '23' => 'Contact', '24' => 'Location', '25' => 'Location latitude', '26' => 'Location longitude', '27' => 'Notes', '28' => 'Chassis', '29' => 'Model', '30' => 'HW architecture', '31' => 'Vendor', '32' => 'Contract number', '33' => 'Installer name', '34' => 'Deployment status', '35' => 'URL A', '36' => 'URL B', '37' => 'URL C', '38' => 'Host networks', '39' => 'Host subnet mask', '40' => 'Host router', '41' => 'OOB IP address', '42' => 'OOB subnet mask', '43' => 'OOB router', '44' => 'Date HW purchased', '45' => 'Date HW installed', '46' => 'Date HW maintenance expires', '47' => 'Date HW decommissioned', '48' => 'Site address A', '49' => 'Site address B', '50' => 'Site address C', '51' => 'Site city', '52' => 'Site state / province', '53' => 'Site country', '54' => 'Site ZIP / postal', '55' => 'Site rack location', '56' => 'Site notes', '57' => 'Primary POC name', '58' => 'Primary POC email', '59' => 'Primary POC phone A', '60' => 'Primary POC phone B', '61' => 'Primary POC cell', '62' => 'Primary POC screen name', '63' => 'Primary POC notes', '64' => 'Secondary POC name', '65' => 'Secondary POC email', '66' => 'Secondary POC phone A', '67' => 'Secondary POC phone B', '68' => 'Secondary POC cell', '69' => 'Secondary POC screen name', '70' => 'Secondary POC notes'));
    printNiftySelect($inventory_links, array('name' => 'inventory_link'), $item['inventory_link']);
    echo "</div></li>\n";
    // description
    echo "<li class=formrow id=row_description>";
    echo "<div class='dt right'><label for=description>Description</label></div>";
    echo "<div class=dd><textarea class='input textarea_standard' id=description name=description rows=7 style=width:380px;margin-top:5px;>{$item['description']}</textarea>";
    echo "</div></li>\n";
    // status
    echo "<li class=formrow id=row_status>";
    echo "<div class='dt right'><label for=status>Enabled</label></div>";
    $checked = $item['status'] == 0 ? 'checked=checked' : '';
    echo "<div class=dd><input class='input checkbox pointer' type=checkbox id=status name=status value=0 {$checked}>";
    echo "</div></li>\n";
    echo "</ul>\n";
    echo "</div>\n";
    // button
    echo '<div>';
    echo '<input style=width:50px;margin:10px; type=submit value=Save name=Save>';
    if ($item['itemid'] >= 0) {
        echo '<input style=width:50px;margin:10px; type=submit value=Delete name=Delete>';
    }
    echo "</div>\n";
    echo '<br><br>';
    finishPortlet();
    echo '</td>';
    // end tag
    echo "</tr></table>\n";
    echo "</form>\n";
    echo "<script type=\"text/javascript\" src=\"three/js/item.js\"></script>\n";
    // create flexible interval
    echo "<script type=\"text/javascript\">";
    $delay_flexs = explode(';', $item['delay_flex']);
    foreach ($delay_flexs as $delay_flex) {
        if ($delay_flex == '') {
            continue;
        }
        $splits = explode('/', $delay_flex);
        echo "addDelayFlex('{$splits[0]}', '{$splits[1]}');";
    }
    echo "</script>";
}
function deleteInterface($hostName, $ip)
{
    # host id
    $hostid = searchHost($hostName)[$hostName];
    # get interface of host
    $interfaces = searchInterfaces($hostid);
    $interfaceid = -1;
    $flag = false;
    $length = count($interfaces);
    for ($i = 0; $i < $length; $i++) {
        if ($interfaces[$i]['ip'] == $ip) {
            # interface id
            $interfaceid = $interfaces[$i]['interfaceid'];
            if ($interfaces[$i]['main'] == 1) {
                # if deleted interface type is main, change main interface into next interface.
                if ($length > 1) {
                    $mainIndex = $i + 1 >= $length ? $i + 1 - $length : $i + 1;
                    updateInterface($interfaces[$mainIndex]['interfaceid'], 1);
                } else {
                    updateInterface($interfaceid, 0, '127.0.0.1');
                    return;
                }
            }
            # delete interface
            $params = array($interfaceid);
            doPost('hostinterface.delete', $params);
            $flag = true;
        }
    }
    if ($flag) {
        return array('result' => 'OK');
    } else {
        return array('error' => "interface {$ip} is not exists.");
    }
}