foreach (zbx_objectValues($this->data['hosts']['interfaces'], 'type') as $interfaceType) {
        $interfaceGroups[$interfaceType] = new COptGroup(interfaceType2str($interfaceType));
    }
    // add interfaces to groups
    foreach ($this->data['hosts']['interfaces'] as $interface) {
        $option = new CComboItem($interface['interfaceid'], $interface['useip'] ? $interface['ip'] . ' : ' . $interface['port'] : $interface['dns'] . ' : ' . $interface['port'], $interface['interfaceid'] == $this->data['interfaceid'] ? 'yes' : 'no');
        $option->setAttribute('data-interfacetype', $interface['type']);
        $interfaceGroups[$interface['type']]->addItem($option);
    }
    foreach ($interfaceGroups as $interfaceGroup) {
        $interfacesComboBox->addItem($interfaceGroup);
    }
    $span = new CSpan(_('No interface found'), 'red');
    $span->setAttribute('id', 'interface_not_defined');
    $span->setAttribute('style', 'display: none;');
    $interfaceVisBox = new CVisibilityBox('visible[interface]', isset($this->data['visible']['interface']), 'interfaceDiv', _('Original'));
    $interfaceVisBox->setAttribute('data-multiple-interface-types', $this->data['multiple_interface_types']);
    $itemFormList->addRow(array(_('Host interface'), SPACE, $interfaceVisBox), new CDiv(array($interfacesComboBox, $span), null, 'interfaceDiv'), false, 'interface_row');
    $itemForm->addVar('selectedInterfaceId', $this->data['interfaceid']);
}
// append snmp community to form list
$itemFormList->addRow(array(_('SNMP community'), SPACE, new CVisibilityBox('visible[community]', isset($this->data['visible']['community']), 'snmp_community', _('Original'))), new CTextBox('snmp_community', $this->data['snmp_community'], ZBX_TEXTBOX_SMALL_SIZE));
// append snmpv3 contextname to form list
$itemFormList->addRow(array(_('Context name'), SPACE, new CVisibilityBox('visible[contextname]', isset($this->data['visible']['contextname']), 'snmpv3_contextname', _('Original'))), new CTextBox('snmpv3_contextname', $this->data['snmpv3_contextname'], ZBX_TEXTBOX_STANDARD_SIZE));
// append snmpv3 securityname to form list
$itemFormList->addRow(array(_('Security name'), SPACE, new CVisibilityBox('visible[securityname]', isset($this->data['visible']['securityname']), 'snmpv3_securityname', _('Original'))), new CTextBox('snmpv3_securityname', $this->data['snmpv3_securityname'], ZBX_TEXTBOX_STANDARD_SIZE));
// append snmpv3 securitylevel to form list
$securityLevelComboBox = new CComboBox('snmpv3_securitylevel', $this->data['snmpv3_securitylevel']);
$securityLevelComboBox->addItem(ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV, 'noAuthNoPriv');
$securityLevelComboBox->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV, 'authNoPriv');
$securityLevelComboBox->addItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV, 'authPriv');
Пример #2
0
function insert_mass_update_host_form()
{
    //$elements_array_name){
    global $USER_DETAILS;
    $visible = get_request('visible', array());
    $groups = get_request('groups', array());
    $newgroup = get_request('newgroup', '');
    $host = get_request('host', '');
    $port = get_request('port', CProfile::get('HOST_PORT', 10050));
    $status = get_request('status', HOST_STATUS_MONITORED);
    $useip = get_request('useip', 1);
    $dns = get_request('dns', '');
    $ip = get_request('ip', '0.0.0.0');
    $proxy_hostid = get_request('proxy_hostid', '');
    $useipmi = get_request('useipmi', 'no');
    $ipmi_ip = get_request('ipmi_ip', '');
    $ipmi_port = get_request('ipmi_port', 623);
    $ipmi_authtype = get_request('ipmi_authtype', -1);
    $ipmi_privilege = get_request('ipmi_privilege', 2);
    $ipmi_username = get_request('ipmi_username', '');
    $ipmi_password = get_request('ipmi_password', '');
    $useprofile = get_request('useprofile', 'no');
    $host_profile = get_request('host_profile', array());
    $profile_fields = array('devicetype' => S_DEVICE_TYPE, 'name' => S_NAME, 'os' => S_OS, 'serialno' => S_SERIALNO, 'tag' => S_TAG, 'macaddress' => S_MACADDRESS, 'hardware' => S_HARDWARE, 'software' => S_SOFTWARE, 'contact' => S_CONTACT, 'location' => S_LOCATION, 'notes' => S_NOTES);
    foreach ($profile_fields as $field => $caption) {
        if (!isset($host_profile[$field])) {
            $host_profile[$field] = '';
        }
    }
    // BEGIN: HOSTS PROFILE EXTENDED Section
    $useprofile_ext = get_request('useprofile_ext', 'no');
    $ext_host_profiles = get_request('ext_host_profiles', array());
    $ext_profiles_fields = array('device_alias' => S_DEVICE_ALIAS, 'device_type' => S_DEVICE_TYPE, 'device_chassis' => S_DEVICE_CHASSIS, 'device_os' => S_DEVICE_OS, 'device_os_short' => S_DEVICE_OS_SHORT, 'device_hw_arch' => S_DEVICE_HW_ARCH, 'device_serial' => S_DEVICE_SERIAL, 'device_model' => S_DEVICE_MODEL, 'device_tag' => S_DEVICE_TAG, 'device_vendor' => S_DEVICE_VENDOR, 'device_contract' => S_DEVICE_CONTRACT, 'device_who' => S_DEVICE_WHO, 'device_status' => S_DEVICE_STATUS, 'device_app_01' => S_DEVICE_APP_01, 'device_app_02' => S_DEVICE_APP_02, 'device_app_03' => S_DEVICE_APP_03, 'device_app_04' => S_DEVICE_APP_04, 'device_app_05' => S_DEVICE_APP_05, 'device_url_1' => S_DEVICE_URL_1, 'device_url_2' => S_DEVICE_URL_2, 'device_url_3' => S_DEVICE_URL_3, 'device_networks' => S_DEVICE_NETWORKS, 'device_notes' => S_DEVICE_NOTES, 'device_hardware' => S_DEVICE_HARDWARE, 'device_software' => S_DEVICE_SOFTWARE, 'ip_subnet_mask' => S_IP_SUBNET_MASK, 'ip_router' => S_IP_ROUTER, 'ip_macaddress' => S_IP_MACADDRESS, 'oob_ip' => S_OOB_IP, 'oob_subnet_mask' => S_OOB_SUBNET_MASK, 'oob_router' => S_OOB_ROUTER, 'date_hw_buy' => S_DATE_HW_BUY, 'date_hw_install' => S_DATE_HW_INSTALL, 'date_hw_expiry' => S_DATE_HW_EXPIRY, 'date_hw_decomm' => S_DATE_HW_DECOMM, 'site_street_1' => S_SITE_STREET_1, 'site_street_2' => S_SITE_STREET_2, 'site_street_3' => S_SITE_STREET_3, 'site_city' => S_SITE_CITY, 'site_state' => S_SITE_STATE, 'site_country' => S_SITE_COUNTRY, 'site_zip' => S_SITE_ZIP, 'site_rack' => S_SITE_RACK, 'site_notes' => S_SITE_NOTES, 'poc_1_name' => S_POC_1_NAME, 'poc_1_email' => S_POC_1_EMAIL, 'poc_1_phone_1' => S_POC_1_PHONE_1, 'poc_1_phone_2' => S_POC_1_PHONE_2, 'poc_1_cell' => S_POC_1_CELL, 'poc_1_screen' => S_POC_1_SCREEN, 'poc_1_notes' => S_POC_1_NOTES, 'poc_2_name' => S_POC_2_NAME, 'poc_2_email' => S_POC_2_EMAIL, 'poc_2_phone_1' => S_POC_2_PHONE_1, 'poc_2_phone_2' => S_POC_2_PHONE_2, 'poc_2_cell' => S_POC_2_CELL, 'poc_2_screen' => S_POC_2_SCREEN, 'poc_2_notes' => S_POC_2_NOTES);
    foreach ($ext_profiles_fields as $field => $caption) {
        if (!isset($ext_host_profiles[$field])) {
            $ext_host_profiles[$field] = '';
        }
    }
    // END:   HOSTS PROFILE EXTENDED Section
    $templates = get_request('templates', array());
    natsort($templates);
    $frm_title = S_HOST . SPACE . S_MASS_UPDATE;
    $frmHost = new CFormTable($frm_title, 'hosts.php');
    $frmHost->setHelp('web.hosts.host.php');
    $frmHost->addVar('go', 'massupdate');
    $hosts = $_REQUEST['hosts'];
    foreach ($hosts as $id => $hostid) {
        $frmHost->addVar('hosts[' . $hostid . ']', $hostid);
    }
    //		$frmItem->addRow(array( new CVisibilityBox('visible[type]', isset($visible['type']), 'type', S_ORIGINAL),S_TYPE), $cmbType);
    $frmHost->addRow(S_NAME, S_ORIGINAL);
    $grp_tb = new CTweenBox($frmHost, 'groups', $groups, 6);
    $options = array('output' => API_OUTPUT_EXTEND, 'editable' => 1);
    $all_groups = CHostGroup::get($options);
    order_result($all_groups, 'name');
    foreach ($all_groups as $grp) {
        $grp_tb->addItem($grp['groupid'], $grp['name']);
    }
    $frmHost->addRow(array(new CVisibilityBox('visible[groups]', isset($visible['groups']), $grp_tb->getName(), S_ORIGINAL), S_GROUPS), $grp_tb->get(S_IN . SPACE . S_GROUPS, S_OTHER . SPACE . S_GROUPS));
    $frmHost->addRow(array(new CVisibilityBox('visible[newgroup]', isset($visible['newgroup']), 'newgroup', S_ORIGINAL), S_NEW_GROUP), new CTextBox('newgroup', $newgroup), 'new');
    // onchange does not work on some browsers: MacOS, KDE browser
    $frmHost->addRow(array(new CVisibilityBox('visible[dns]', isset($visible['dns']), 'dns', S_ORIGINAL), S_DNS_NAME), new CTextBox('dns', $dns, '40'));
    $frmHost->addRow(array(new CVisibilityBox('visible[ip]', isset($visible['ip']), 'ip', S_ORIGINAL), S_IP_ADDRESS), new CTextBox('ip', $ip, defined('ZBX_HAVE_IPV6') ? 39 : 15));
    $cmbConnectBy = new CComboBox('useip', $useip);
    $cmbConnectBy->addItem(0, S_DNS_NAME);
    $cmbConnectBy->addItem(1, S_IP_ADDRESS);
    $frmHost->addRow(array(new CVisibilityBox('visible[useip]', isset($visible['useip']), 'useip', S_ORIGINAL), S_CONNECT_TO), $cmbConnectBy);
    $frmHost->addRow(array(new CVisibilityBox('visible[port]', isset($visible['port']), 'port', S_ORIGINAL), S_AGENT_PORT), new CNumericBox('port', $port, 5));
    //Proxy
    $cmbProxy = new CComboBox('proxy_hostid', $proxy_hostid);
    $cmbProxy->addItem(0, S_NO_PROXY);
    $sql = 'SELECT hostid,host ' . ' FROM hosts ' . ' WHERE status IN (' . HOST_STATUS_PROXY_ACTIVE . ',' . HOST_STATUS_PROXY_PASSIVE . ') ' . ' AND ' . DBin_node('hostid') . ' ORDER BY host';
    $db_proxies = DBselect($sql);
    while ($db_proxy = DBfetch($db_proxies)) {
        $cmbProxy->addItem($db_proxy['hostid'], $db_proxy['host']);
    }
    $frmHost->addRow(array(new CVisibilityBox('visible[proxy_hostid]', isset($visible['proxy_hostid']), 'proxy_hostid', S_ORIGINAL), S_MONITORED_BY_PROXY), $cmbProxy);
    //----------
    $cmbStatus = new CComboBox('status', $status);
    $cmbStatus->addItem(HOST_STATUS_MONITORED, S_MONITORED);
    $cmbStatus->addItem(HOST_STATUS_NOT_MONITORED, S_NOT_MONITORED);
    $frmHost->addRow(array(new CVisibilityBox('visible[status]', isset($visible['status']), 'status', S_ORIGINAL), S_STATUS), $cmbStatus);
    // LINK TEMPLATES {{{
    $template_table = new CTable();
    $template_table->setAttribute('name', 'template_table');
    $template_table->setAttribute('id', 'template_table');
    $template_table->setCellPadding(0);
    $template_table->setCellSpacing(0);
    foreach ($templates as $id => $temp_name) {
        $frmHost->addVar('templates[' . $id . ']', $temp_name);
        $template_table->addRow(array(new CCheckBox('templates_rem[' . $id . ']', 'no', null, $id), $temp_name));
    }
    $template_table->addRow(array(new CButton('add_template', S_ADD, "return PopUp('popup.php?dstfrm=" . $frmHost->getName() . "&dstfld1=new_template&srctbl=templates&srcfld1=hostid&srcfld2=host" . url_param($templates, false, 'existed_templates') . "',450,450)"), new CButton('unlink', S_REMOVE)));
    $vbox = new CVisibilityBox('visible[template_table]', isset($visible['template_table']), 'template_table', S_ORIGINAL);
    $vbox->setAttribute('id', 'cb_tpladd');
    if (isset($visible['template_table_r'])) {
        $vbox->setAttribute('disabled', 'disabled');
    }
    $action = $vbox->getAttribute('onclick');
    $action .= 'if($("cb_tplrplc").disabled) $("cb_tplrplc").enable(); else $("cb_tplrplc").disable();';
    $vbox->setAttribute('onclick', $action);
    $frmHost->addRow(array($vbox, S_LINK_ADDITIONAL_TEMPLATES), $template_table, 'T');
    // }}} LINK TEMPLATES
    // RELINK TEMPLATES {{{
    $template_table_r = new CTable();
    $template_table_r->setAttribute('name', 'template_table_r');
    $template_table_r->setAttribute('id', 'template_table_r');
    $template_table_r->setCellPadding(0);
    $template_table_r->setCellSpacing(0);
    foreach ($templates as $id => $temp_name) {
        $frmHost->addVar('templates[' . $id . ']', $temp_name);
        $template_table_r->addRow(array(new CCheckBox('templates_rem[' . $id . ']', 'no', null, $id), $temp_name));
    }
    $template_table_r->addRow(array(new CButton('add_template', S_ADD, "return PopUp('popup.php?dstfrm=" . $frmHost->getName() . "&dstfld1=new_template&srctbl=templates&srcfld1=hostid&srcfld2=host" . url_param($templates, false, 'existed_templates') . "',450,450)"), new CButton('unlink', S_REMOVE)));
    $vbox = new CVisibilityBox('visible[template_table_r]', isset($visible['template_table_r']), 'template_table_r', S_ORIGINAL);
    $vbox->setAttribute('id', 'cb_tplrplc');
    if (isset($visible['template_table'])) {
        $vbox->setAttribute('disabled', 'disabled');
    }
    $action = $vbox->getAttribute('onclick');
    $action .= <<<JAVASCRIPT
if(\$("cb_tpladd").disabled){
\t\$("cb_tpladd").enable();
}
else{
\t\$("cb_tpladd").disable();
}
\$("clrcbdiv").toggle();
JAVASCRIPT;
    $vbox->setAttribute('onclick', $action);
    $clear_cb = new CCheckBox('mass_clear_tpls', get_request('mass_clear_tpls', false));
    $div = new CDiv(array($clear_cb, S_CLEAR_WHEN_UNLINKING));
    $div->setAttribute('id', 'clrcbdiv');
    $div->addStyle('margin-left: 20px;');
    if (!isset($visible['template_table_r'])) {
        $div->addStyle('display: none;');
    }
    $frmHost->addRow(array($vbox, S_RELINK_TEMPLATES, $div), $template_table_r, 'T');
    // }}} RELINK TEMPLATES
    $frmHost->addRow(array(new CVisibilityBox('visible[useipmi]', isset($visible['useipmi']), 'useipmi', S_ORIGINAL), S_USEIPMI), new CCheckBox('useipmi', $useipmi, 'submit()'));
    if ($useipmi == 'yes') {
        $frmHost->addRow(array(new CVisibilityBox('visible[ipmi_ip]', isset($visible['ipmi_ip']), 'ipmi_ip', S_ORIGINAL), S_IPMI_IP_ADDRESS), new CTextBox('ipmi_ip', $ipmi_ip, defined('ZBX_HAVE_IPV6') ? 39 : 15));
        $frmHost->addRow(array(new CVisibilityBox('visible[ipmi_port]', isset($visible['ipmi_port']), 'ipmi_port', S_ORIGINAL), S_IPMI_PORT), new CNumericBox('ipmi_port', $ipmi_port, 15));
        $cmbIPMIAuthtype = new CComboBox('ipmi_authtype', $ipmi_authtype);
        $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_DEFAULT, S_AUTHTYPE_DEFAULT);
        $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_NONE, S_AUTHTYPE_NONE);
        $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_MD2, S_AUTHTYPE_MD2);
        $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_MD5, S_AUTHTYPE_MD5);
        $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_STRAIGHT, S_AUTHTYPE_STRAIGHT);
        $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_OEM, S_AUTHTYPE_OEM);
        $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_RMCP_PLUS, S_AUTHTYPE_RMCP_PLUS);
        $frmHost->addRow(array(new CVisibilityBox('visible[ipmi_authtype]', isset($visible['ipmi_authtype']), 'ipmi_authtype', S_ORIGINAL), S_IPMI_AUTHTYPE), $cmbIPMIAuthtype);
        $cmbIPMIPrivilege = new CComboBox('ipmi_privilege', $ipmi_privilege);
        $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_CALLBACK, S_PRIVILEGE_CALLBACK);
        $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_USER, S_PRIVILEGE_USER);
        $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_OPERATOR, S_PRIVILEGE_OPERATOR);
        $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_ADMIN, S_PRIVILEGE_ADMIN);
        $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_OEM, S_PRIVILEGE_OEM);
        $frmHost->addRow(array(new CVisibilityBox('visible[ipmi_privilege]', isset($visible['ipmi_privilege']), 'ipmi_privilege', S_ORIGINAL), S_IPMI_PRIVILEGE), $cmbIPMIPrivilege);
        $frmHost->addRow(array(new CVisibilityBox('visible[ipmi_username]', isset($visible['ipmi_username']), 'ipmi_username', S_ORIGINAL), S_IPMI_USERNAME), new CTextBox('ipmi_username', $ipmi_username, 16));
        $frmHost->addRow(array(new CVisibilityBox('visible[ipmi_password]', isset($visible['ipmi_password']), 'ipmi_password', S_ORIGINAL), S_IPMI_PASSWORD), new CTextBox('ipmi_password', $ipmi_password, 20));
    }
    $frmHost->addRow(array(new CVisibilityBox('visible[useprofile]', isset($visible['useprofile']), 'useprofile', S_ORIGINAL), S_USE_PROFILE), new CCheckBox('useprofile', $useprofile, 'submit()'));
    // BEGIN: HOSTS PROFILE EXTENDED Section
    $frmHost->addRow(array(new CVisibilityBox('visible[useprofile_ext]', isset($visible['useprofile_ext']), 'useprofile_ext', S_ORIGINAL), S_USE_EXTENDED_PROFILE), new CCheckBox('useprofile_ext', $useprofile_ext, 'submit()'));
    // END:   HOSTS PROFILE EXTENDED Section
    if ($useprofile === 'yes') {
        if ($useprofile === 'yes') {
            foreach ($profile_fields as $field => $caption) {
                $frmHost->addRow(array(new CVisibilityBox('visible[' . $field . ']', isset($visible[$field]), 'host_profile[' . $field . ']', S_ORIGINAL), $caption), new CTextBox('host_profile[' . $field . ']', $host_profile[$field], 80));
            }
        } else {
            foreach ($profile_fields as $field => $caption) {
                $frmHost->addVar('host_profile[' . $field . ']', $host_profile[$field]);
            }
        }
    }
    // BEGIN: HOSTS PROFILE EXTENDED Section
    if ($useprofile_ext == 'yes') {
        foreach ($ext_profiles_fields as $prof_field => $caption) {
            $frmHost->addRow(array(new CVisibilityBox('visible[' . $prof_field . ']', isset($visible[$prof_field]), 'ext_host_profiles[' . $prof_field . ']', S_ORIGINAL), $caption), new CTextBox('ext_host_profiles[' . $prof_field . ']', $ext_host_profiles[$prof_field], 80));
        }
    } else {
        foreach ($ext_profiles_fields as $prof_field => $caption) {
            $frmHost->addVar('ext_host_profiles[' . $prof_field . ']', $ext_host_profiles[$prof_field]);
        }
    }
    // END:   HOSTS PROFILE EXTENDED Section
    $frmHost->addItemToBottomRow(new CButton('masssave', S_SAVE));
    $frmHost->addItemToBottomRow(SPACE);
    $frmHost->addItemToBottomRow(new CButtonCancel(url_param('config') . url_param('groupid')));
    return $frmHost;
}