}
        $mediaUrl = '?dstfrm=' . $userForm->getName() . '&media=' . $id . '&mediatypeid=' . $media['mediatypeid'] . '&sendto=' . urlencode($media['sendto']) . '&period=' . $media['period'] . '&severity=' . $media['severity'] . '&active=' . $media['active'];
        foreach (getSeverityCaption() as $key => $caption) {
            $mediaActive = $media['severity'] & 1 << $key;
            $mediaSeverity[$key] = new CSpan(mb_substr($caption, 0, 1), $mediaActive ? 'enabled' : null);
            $mediaSeverity[$key]->setHint($caption . ($mediaActive ? ' (on)' : ' (off)'));
        }
        $mediaTableInfo->addRow(array(new CCheckBox('user_medias_to_del[' . $id . ']', null, null, $id), new CSpan($media['description'], 'nowrap'), new CSpan($media['sendto'], 'nowrap'), new CSpan($media['period'], 'nowrap'), $mediaSeverity, $status, new CButton('edit_media', _('Edit'), 'return PopUp("popup_media.php' . $mediaUrl . '", 550, 400);', 'link_menu')));
    }
    $userMediaFormList->addRow(_('Media'), array($mediaTableInfo, new CButton('add_media', _('Add'), 'return PopUp("popup_media.php?dstfrm=' . $userForm->getName() . '", 550, 400);', 'link_menu'), SPACE, SPACE, count($this->data['user_medias']) > 0 ? new CSubmit('del_user_media', _('Delete selected'), null, 'link_menu') : null));
}
/*
 * Profile fields
 */
if ($this->data['is_profile']) {
    $zbxSounds = getSounds();
    $userMessagingFormList = new CFormList('userMessagingFormList');
    $userMessagingFormList->addRow(_('Frontend messaging'), new CCheckBox('messages[enabled]', $this->data['messages']['enabled'], null, 1));
    $userMessagingFormList->addRow(_('Message timeout (seconds)'), new CNumericBox('messages[timeout]', $this->data['messages']['timeout'], 5), false, 'timeout_row');
    $repeatSound = new CComboBox('messages[sounds.repeat]', $this->data['messages']['sounds.repeat'], 'javascript: if (IE) { submit(); }');
    $repeatSound->addItem(1, _('Once'));
    $repeatSound->addItem(10, '10 ' . _('Seconds'));
    $repeatSound->addItem(-1, _('Message timeout'));
    $userMessagingFormList->addRow(_('Play sound'), $repeatSound, false, 'repeat_row');
    $soundList = new CComboBox('messages[sounds.recovery]', $this->data['messages']['sounds.recovery']);
    foreach ($zbxSounds as $filename => $file) {
        $soundList->addItem($file, $filename);
    }
    $resolved = array(new CCheckBox('messages[triggers.recovery]', $this->data['messages']['triggers.recovery'], null, 1), _('Recovery'), SPACE, $soundList, new CButton('start', _('Play'), "javascript: testUserSound('messages_sounds.recovery');", 'formlist'), new CButton('stop', _('Stop'), 'javascript: AudioControl.stop();', 'formlist'));
    $triggersTable = new CTable('', 'invisible');
    $triggersTable->addRow($resolved);
Beispiel #2
0
function getUserForm($userid, $profile = 0)
{
    global $ZBX_LOCALES;
    global $USER_DETAILS;
    $config = select_config();
    $frm_title = S_USER;
    if (isset($userid)) {
        /*			if(bccomp($userid,$USER_DETAILS['userid'])==0) $profile = 1;*/
        $options = array('userids' => $userid, 'output' => API_OUTPUT_EXTEND);
        if ($profile) {
            $options['nodeids'] = id2nodeid($userid);
        }
        $users = CUser::get($options);
        $user = reset($users);
        $frm_title = S_USER . ' "' . $user['alias'] . '"';
    }
    if (isset($userid) && (!isset($_REQUEST['form_refresh']) || isset($_REQUEST['register']))) {
        $alias = $user['alias'];
        $name = $user['name'];
        $surname = $user['surname'];
        $password = null;
        $password1 = null;
        $password2 = null;
        $url = $user['url'];
        $autologin = $user['autologin'];
        $autologout = $user['autologout'];
        $lang = $user['lang'];
        $theme = $user['theme'];
        $refresh = $user['refresh'];
        $rows_per_page = $user['rows_per_page'];
        $user_type = $user['type'];
        if ($autologout > 0) {
            $_REQUEST['autologout'] = $autologout;
        }
        $user_groups = array();
        $user_medias = array();
        $options = array('userids' => $userid, 'output' => API_OUTPUT_SHORTEN);
        $user_groups = CUserGroup::get($options);
        $user_groups = zbx_objectValues($user_groups, 'usrgrpid');
        $user_groups = zbx_toHash($user_groups);
        $db_medias = DBselect('SELECT m.* FROM media m WHERE m.userid=' . $userid);
        while ($db_media = DBfetch($db_medias)) {
            $user_medias[] = array('mediaid' => $db_media['mediaid'], 'mediatypeid' => $db_media['mediatypeid'], 'period' => $db_media['period'], 'sendto' => $db_media['sendto'], 'severity' => $db_media['severity'], 'active' => $db_media['active']);
        }
        $messages = getMessageSettings();
    } else {
        $alias = get_request('alias', '');
        $name = get_request('name', '');
        $surname = get_request('surname', '');
        $password = null;
        $password1 = get_request('password1', '');
        $password2 = get_request('password2', '');
        $url = get_request('url', '');
        $autologin = get_request('autologin', 0);
        $autologout = get_request('autologout', 90);
        $lang = get_request('lang', 'en_gb');
        $theme = get_request('theme', 'default.css');
        $refresh = get_request('refresh', 30);
        $rows_per_page = get_request('rows_per_page', 50);
        $user_type = get_request('user_type', USER_TYPE_ZABBIX_USER);
        $user_groups = get_request('user_groups', array());
        $change_password = get_request('change_password', null);
        $user_medias = get_request('user_medias', array());
        $messages = get_request('messages', array());
        if (!isset($messages['enabled'])) {
            $messages['enabled'] = 0;
        }
        if (!isset($messages['sounds.recovery'])) {
            $messages['sounds.recovery'] = 0;
        }
        if (!isset($messages['triggers.recovery'])) {
            $messages['triggers.recovery'] = 0;
        }
        if (!isset($messages['triggers.severities'])) {
            $messages['triggers.severities'] = array();
        }
        $pMsgs = getMessageSettings();
        $messages = array_merge($pMsgs, $messages);
    }
    if ($autologin || !isset($_REQUEST['autologout'])) {
        $autologout = 0;
    } else {
        if (isset($_REQUEST['autologout']) && $autologout < 90) {
            $autologout = 90;
        }
    }
    $perm_details = get_request('perm_details', 0);
    $media_types = array();
    $media_type_ids = array();
    foreach ($user_medias as $one_media) {
        $media_type_ids[$one_media['mediatypeid']] = 1;
    }
    if (count($media_type_ids) > 0) {
        $sql = 'SELECT mt.mediatypeid, mt.description ' . ' FROM media_type mt ' . ' WHERE mt.mediatypeid IN (' . implode(',', array_keys($media_type_ids)) . ')';
        $db_media_types = DBselect($sql);
        while ($db_media_type = DBfetch($db_media_types)) {
            $media_types[$db_media_type['mediatypeid']] = $db_media_type['description'];
        }
    }
    $frmUser = new CFormTable($frm_title);
    $frmUser->setName('user_form');
    $frmUser->setHelp('web.users.php');
    $frmUser->addVar('config', get_request('config', 0));
    if (isset($userid)) {
        $frmUser->addVar('userid', $userid);
    }
    if ($profile == 0) {
        $frmUser->addRow(S_ALIAS, new CTextBox('alias', $alias, 40));
        $frmUser->addRow(S_NAME, new CTextBox('name', $name, 40));
        $frmUser->addRow(S_SURNAME, new CTextBox('surname', $surname, 40));
    }
    $auth_type = isset($userid) ? get_user_system_auth($userid) : $config['authentication_type'];
    if (ZBX_AUTH_INTERNAL == $auth_type) {
        if (!isset($userid) || isset($change_password)) {
            $frmUser->addRow(S_PASSWORD, new CPassBox('password1', $password1, 20));
            $frmUser->addRow(S_PASSWORD_ONCE_AGAIN, new CPassBox('password2', $password2, 20));
            if (isset($change_password)) {
                $frmUser->addVar('change_password', $change_password);
            }
        } else {
            $passwd_but = new CButton('change_password', S_CHANGE_PASSWORD);
            if ($alias == ZBX_GUEST_USER) {
                $passwd_but->setAttribute('disabled', 'disabled');
            }
            $frmUser->addRow(S_PASSWORD, $passwd_but);
        }
    }
    if ($profile == 0) {
        $frmUser->addVar('user_groups', $user_groups);
        if (isset($userid) && bccomp($USER_DETAILS['userid'], $userid) == 0) {
            $frmUser->addVar('user_type', $user_type);
        } else {
            $cmbUserType = new CComboBox('user_type', $user_type, $perm_details ? 'submit();' : null);
            $cmbUserType->addItem(USER_TYPE_ZABBIX_USER, user_type2str(USER_TYPE_ZABBIX_USER));
            $cmbUserType->addItem(USER_TYPE_ZABBIX_ADMIN, user_type2str(USER_TYPE_ZABBIX_ADMIN));
            $cmbUserType->addItem(USER_TYPE_SUPER_ADMIN, user_type2str(USER_TYPE_SUPER_ADMIN));
            $frmUser->addRow(S_USER_TYPE, $cmbUserType);
        }
        $lstGroups = new CListBox('user_groups_to_del[]', null, 10);
        $lstGroups->attributes['style'] = 'width: 320px';
        $options = array('usrgrpids' => $user_groups, 'output' => API_OUTPUT_EXTEND);
        $groups = CUserGroup::get($options);
        order_result($groups, 'name');
        foreach ($groups as $num => $group) {
            $lstGroups->addItem($group['usrgrpid'], $group['name']);
        }
        $frmUser->addRow(S_GROUPS, array($lstGroups, BR(), new CButton('add_group', S_ADD, 'return PopUp("popup_usrgrp.php?dstfrm=' . $frmUser->getName() . '&list_name=user_groups_to_del[]&var_name=user_groups",450, 450);'), SPACE, count($user_groups) > 0 ? new CButton('del_user_group', S_DELETE_SELECTED) : null));
    }
    $cmbLang = new CComboBox('lang', $lang);
    foreach ($ZBX_LOCALES as $loc_id => $loc_name) {
        $cmbLang->addItem($loc_id, $loc_name);
    }
    $frmUser->addRow(S_LANGUAGE, $cmbLang);
    $cmbTheme = new CComboBox('theme', $theme);
    $cmbTheme->addItem(ZBX_DEFAULT_CSS, S_SYSTEM_DEFAULT);
    $cmbTheme->addItem('css_ob.css', S_ORIGINAL_BLUE);
    $cmbTheme->addItem('css_bb.css', S_BLACK_AND_BLUE);
    $cmbTheme->addItem('css_od.css', S_DARK_ORANGE);
    $frmUser->addRow(S_THEME, $cmbTheme);
    $script = "javascript:\n\t\t\tvar autologout_visible = document.getElementById('autologout_visible');\n\t\t\tvar autologout = document.getElementById('autologout');\n\t\t\tif(this.checked){\n\t\t\t\tif(autologout_visible.checked){\n\t\t\t\t\tautologout_visible.checked = false;\n\t\t\t\t\tautologout_visible.onclick();\n\t\t\t\t}\n\t\t\t\tautologout_visible.disabled = true;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tautologout_visible.disabled = false;\n\t\t\t}";
    $chkbx_autologin = new CCheckBox("autologin", $autologin, $script, 1);
    $chkbx_autologin->setAttribute('autocomplete', 'off');
    $frmUser->addRow(S_AUTO_LOGIN, $chkbx_autologin);
    $script = "javascript: var autologout = document.getElementById('autologout');\n\t\t\t\t\tif(this.checked) autologout.disabled = false;\n\t\t\t\t\telse autologout.disabled = true;";
    $autologoutCheckBox = new CCheckBox('autologout_visible', $autologout == 0 ? 'no' : 'yes', $script);
    $autologoutTextBox = new CNumericBox("autologout", $autologout == 0 ? '90' : $autologout, 4);
    // if autologout is disabled
    if ($autologout == 0) {
        $autologoutTextBox->setAttribute('disabled', 'disabled');
    }
    if ($autologin != 0) {
        $autologoutCheckBox->setAttribute('disabled', 'disabled');
    }
    $frmUser->addRow(S_AUTO_LOGOUT, array($autologoutCheckBox, $autologoutTextBox));
    $frmUser->addRow(S_SCREEN_REFRESH, new CNumericBox('refresh', $refresh, 4));
    $frmUser->addRow(S_ROWS_PER_PAGE, new CNumericBox('rows_per_page', $rows_per_page, 6));
    $frmUser->addRow(S_URL_AFTER_LOGIN, new CTextBox("url", $url, 50));
    //view Media Settings for users above "User" +++
    if (uint_in_array($USER_DETAILS['type'], array(USER_TYPE_ZABBIX_ADMIN, USER_TYPE_SUPER_ADMIN))) {
        $frmUser->addVar('user_medias', $user_medias);
        $media_table = new CTableInfo(S_NO_MEDIA_DEFINED);
        foreach ($user_medias as $id => $one_media) {
            if (!isset($one_media['active']) || $one_media['active'] == 0) {
                $status = new CLink(S_ENABLED, '#', 'enabled');
                $status->onClick('return create_var("' . $frmUser->getName() . '","disable_media",' . $id . ', true);');
            } else {
                $status = new CLink(S_DISABLED, '#', 'disabled');
                $status->onClick('return create_var("' . $frmUser->getName() . '","enable_media",' . $id . ', true);');
            }
            $media_url = '?dstfrm=' . $frmUser->getName() . '&media=' . $id . '&mediatypeid=' . $one_media['mediatypeid'] . '&sendto=' . urlencode($one_media['sendto']) . '&period=' . $one_media['period'] . '&severity=' . $one_media['severity'] . '&active=' . $one_media['active'];
            $media_table->addRow(array(new CCheckBox('user_medias_to_del[' . $id . ']', null, null, $id), new CSpan($media_types[$one_media['mediatypeid']], 'nowrap'), new CSpan($one_media['sendto'], 'nowrap'), new CSpan($one_media['period'], 'nowrap'), media_severity2str($one_media['severity']), $status, new CButton('edit_media', S_EDIT, 'javascript: return PopUp("popup_media.php' . $media_url . '",550,400);')));
        }
        $frmUser->addRow(S_MEDIA, array($media_table, new CButton('add_media', S_ADD, 'javascript: return PopUp("popup_media.php?dstfrm=' . $frmUser->getName() . '",550,400);'), SPACE, count($user_medias) > 0 ? new CButton('del_user_media', S_DELETE_SELECTED) : null));
    }
    if (0 == $profile) {
        $frmUser->addVar('perm_details', $perm_details);
        $link = new CSpan($perm_details ? S_HIDE : S_SHOW, 'link');
        $link->onClick("return create_var('" . $frmUser->getName() . "','perm_details'," . ($perm_details ? 0 : 1) . ", true);");
        $resources_list = array(S_RIGHTS_OF_RESOURCES, SPACE . '(', $link, ')');
        $frmUser->addSpanRow($resources_list, 'right_header');
        if ($perm_details) {
            $group_ids = array_values($user_groups);
            if (count($group_ids) == 0) {
                $group_ids = array(-1);
            }
            $db_rights = DBselect('SELECT * FROM rights r WHERE ' . DBcondition('r.groupid', $group_ids));
            $tmp_perm = array();
            while ($db_right = DBfetch($db_rights)) {
                if (isset($tmp_perm[$db_right['id']])) {
                    $tmp_perm[$db_right['id']] = min($tmp_perm[$db_right['id']], $db_right['permission']);
                } else {
                    $tmp_perm[$db_right['id']] = $db_right['permission'];
                }
            }
            $user_rights = array();
            foreach ($tmp_perm as $id => $perm) {
                array_push($user_rights, array('id' => $id, 'permission' => $perm));
            }
            //SDI($user_rights);
            //SDI($user_type);
            $frmUser->addSpanRow(get_rights_of_elements_table($user_rights, $user_type));
        }
    }
    if ($profile) {
        $msgVisibility = array('1' => array('messages[timeout]', 'messages[sounds.repeat]', 'messages[sounds.recovery]', 'messages[triggers.recovery]', 'timeout_row', 'repeat_row', 'triggers_row'));
        $frmUser->addRow(S_GUI_MESSAGING, new CCheckBox('messages[enabled]', $messages['enabled'], null, 1));
        $newRow = $frmUser->addRow(S_MESSAGE_TIMEOUT . SPACE . '(' . S_SECONDS_SMALL . ')', new CNumericBox("messages[timeout]", $messages['timeout'], 5));
        $newRow->setAttribute('id', 'timeout_row');
        $repeatSound = new CComboBox('messages[sounds.repeat]', $messages['sounds.repeat'], 'javascript: if(IE) submit();');
        $repeatSound->setAttribute('id', 'messages[sounds.repeat]');
        $repeatSound->addItem(1, S_ONCE);
        $repeatSound->addItem(10, '10 ' . S_SECONDS);
        $repeatSound->addItem(-1, S_MESSAGE_TIMEOUT);
        $newRow = $frmUser->addRow(S_PLAY_SOUND, $repeatSound);
        $newRow->setAttribute('id', 'repeat_row');
        // trigger sounds
        $severities = array(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER);
        $zbxSounds = getSounds();
        $triggers = new CTable('', 'invisible');
        $soundList = new CComboBox('messages[sounds.recovery]', $messages['sounds.recovery']);
        foreach ($zbxSounds as $filename => $file) {
            $soundList->addItem($file, $filename);
        }
        $resolved = array(new CCheckBox('messages[triggers.recovery]', $messages['triggers.recovery'], null, 1), S_RECOVERY, $soundList, new CButton('start', S_PLAY, "javascript: testUserSound('messages[sounds.recovery]');", false), new CButton('stop', S_STOP, 'javascript: AudioList.stopAll();', false));
        $triggers->addRow($resolved);
        foreach ($severities as $snum => $severity) {
            $soundList = new CComboBox('messages[sounds.' . $severity . ']', $messages['sounds.' . $severity]);
            foreach ($zbxSounds as $filename => $file) {
                $soundList->addItem($file, $filename);
            }
            $triggers->addRow(array(new CCheckBox('messages[triggers.severities][' . $severity . ']', isset($messages['triggers.severities'][$severity]), null, 1), getSeverityCaption($severity), $soundList, new CButton('start', S_PLAY, "javascript: testUserSound('messages[sounds." . $severity . "]');", false), new CButton('stop', S_STOP, 'javascript: AudioList.stopAll();', false)));
            zbx_subarray_push($msgVisibility, 1, 'messages[triggers.severities][' . $severity . ']');
            zbx_subarray_push($msgVisibility, 1, 'messages[sounds.' . $severity . ']');
        }
        $newRow = $frmUser->addRow(S_TRIGGER_SEVERITY, $triggers);
        $newRow->setAttribute('id', 'triggers_row');
        zbx_add_post_js("var userMessageSwitcher = new CViewSwitcher('messages[enabled]', 'click', " . zbx_jsvalue($msgVisibility, true) . ");");
    }
    $frmUser->addItemToBottomRow(new CButton('save', S_SAVE));
    if (isset($userid) && $profile == 0) {
        $frmUser->addItemToBottomRow(SPACE);
        $delete_b = new CButtonDelete(S_DELETE_SELECTED_USER_Q, url_param("form") . url_param("config") . url_param("userid"));
        if (bccomp($USER_DETAILS['userid'], $userid) == 0) {
            $delete_b->setAttribute('disabled', 'disabled');
        }
        $frmUser->addItemToBottomRow($delete_b);
    }
    $frmUser->addItemToBottomRow(SPACE);
    $frmUser->addItemToBottomRow(new CButtonCancel(url_param("config")));
    return $frmUser;
}