Пример #1
0
function insert_user_form($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;*/
        $user = get_user_by_userid($userid);
        $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'];
        $user_type = $user['type'];
        $user_groups = array();
        $user_medias = array();
        $sql = 'SELECT g.* ' . ' FROM usrgrp g, users_groups ug ' . ' WHERE ug.usrgrpid=g.usrgrpid ' . ' AND ug.userid=' . $userid;
        $db_user_groups = DBselect($sql);
        while ($db_group = DBfetch($db_user_groups)) {
            $user_groups[$db_group['usrgrpid']] = $db_group['name'];
        }
        $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']);
        }
        $new_group_id = 0;
        $new_group_name = '';
    } 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);
        $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());
        $new_group_id = get_request('new_group_id', 0);
        $new_group_name = get_request('new_group_name', '');
    }
    if ($autologin) {
        $autologout = 0;
        zbx_add_post_js("document.getElementById('autologout_visible').disabled = true;");
    } 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) {
        $db_media_types = DBselect('SELECT mt.mediatypeid, mt.description ' . ' FROM media_type mt ' . ' WHERE mt.mediatypeid IN (' . implode(',', array_keys($media_type_ids)) . ')');
        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->addOption('disabled', 'disabled');
            }
            $frmUser->addRow(S_PASSWORD, $passwd_but);
        }
    } else {
        if (!isset($userid) || isset($change_password)) {
            $frmUser->addVar('password1', '');
            $frmUser->addVar('password2', '');
        }
    }
    if ($profile == 0) {
        global $USER_DETAILS;
        $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[]');
        $lstGroups->options['style'] = 'width: 320px';
        foreach ($user_groups as $groupid => $group_name) {
            $lstGroups->addItem($groupid, $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));
        $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=' . $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));
    }
    $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);
    $frmUser->addRow(S_THEME, $cmbTheme);
    $chkbx_autologin = new CCheckBox("autologin", $autologin, new CScript("var autologout_visible = document.getElementById('autologout_visible');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar autologout = document.getElementById('autologout');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (this.checked) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (autologout_visible.checked) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tautologout_visible.checked = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tautologout_visible.onclick();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tautologout_visible.disabled = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tautologout_visible.disabled = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}"), 1);
    $chkbx_autologin->AddOption('autocomplete', 'off');
    $frmUser->AddRow(S_AUTO_LOGIN, $chkbx_autologin);
    $autologoutCheckBox = new CCheckBox('autologout_visible', isset($autologout) && $autologout != 0 ? 'yes' : 'no', new CScript("var autologout = document.getElementById('autologout');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (this.checked) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tautologout.disabled = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tautologout.disabled = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}"));
    // if autologout is disabled
    if (isset($autologout) && $autologout == 0) {
        zbx_add_post_js('document.getElementById("autologout").disabled = true;');
    }
    $autologoutTextBox = new CNumericBox("autologout", $autologout == 0 ? '90' : $autologout, 4);
    $frmUser->AddRow(S_AUTO_LOGOUT, array($autologoutCheckBox, $autologoutTextBox));
    $frmUser->AddRow(S_URL_AFTER_LOGIN, new CTextBox("url", $url, 50));
    $frmUser->AddRow(S_SCREEN_REFRESH, new CNumericBox("refresh", $refresh, 4));
    if (0 == $profile) {
        $frmUser->addVar('perm_details', $perm_details);
        $link = new CLink($perm_details ? S_HIDE : S_SHOW, '#', 'action');
        $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_keys($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));
        }
    }
    $frmUser->addItemToBottomRow(new CButton('save', S_SAVE));
    if (isset($userid) && $profile == 0) {
        $frmUser->addItemToBottomRow(SPACE);
        $delete_b = new CButtonDelete("Delete selected user?", url_param("form") . url_param("config") . url_param("userid"));
        if (bccomp($USER_DETAILS['userid'], $userid) == 0) {
            $delete_b->addOption('disabled', 'disabled');
        }
        $frmUser->addItemToBottomRow($delete_b);
    }
    $frmUser->addItemToBottomRow(SPACE);
    $frmUser->addItemToBottomRow(new CButtonCancel(url_param("config")));
    $frmUser->Show();
}