Example #1
0
/**
 * Gather the permissions for the specified category as a form field input matrix.
 *
 * @param  ID_TEXT		The ID code for the module being checked for category access
 * @param  ID_TEXT		The ID code for the category being checked for access (often, a number cast to a string)
 * @param  ?ID_TEXT		The page this is for (NULL: current page)
 * @param  ?tempcode		Extra help to show in interface (NULL: none)
 * @param  boolean		Whether this is a new category (don't load permissions, default to on)
 * @param  ?tempcode		Label for view permissions (NULL: default)
 * @return tempcode		The form field matrix
 */
function get_category_permissions_for_environment($module, $category, $page = NULL, $help = NULL, $new_category = false, $pinterface_view = NULL)
{
    if (is_null($page)) {
        $page = get_page_name();
    }
    if ($category == '-1') {
        $category = NULL;
    }
    if ($category == '') {
        $category = NULL;
    }
    $server_id = get_module_zone($page) . ':' . $page;
    // $category is not of interest to us because we use this to find our inheritance settings
    $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
    $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, true);
    // View access
    $access = array();
    foreach (array_keys($groups) as $id) {
        $access[$id] = $new_category ? 1 : 0;
    }
    if (!$new_category) {
        $access_rows = $GLOBALS[$module == 'forums' ? 'FORUM_DB' : 'SITE_DB']->query_select('group_category_access', array('group_id'), array('module_the_name' => $module, 'category_name' => $category));
        foreach ($access_rows as $row) {
            $access[$row['group_id']] = 1;
        }
    }
    // privileges
    $specific_permissions = array();
    $access_rows = $GLOBALS[$module == 'forums' ? 'FORUM_DB' : 'SITE_DB']->query_select('gsp', array('group_id', 'specific_permission', 'the_value'), array('module_the_name' => $module, 'category_name' => $category));
    foreach ($access_rows as $row) {
        $specific_permissions[$row['specific_permission']][$row['group_id']] = strval($row['the_value']);
    }
    // Heading
    require_code('zones2');
    $_overridables = extract_module_functions_page(get_module_zone($page), $page, array('get_sp_overrides'));
    $out = new ocp_tempcode();
    if (is_null($_overridables[0])) {
        $temp = do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('PERMISSIONS'), 'HELP' => $help, 'SECTION_HIDDEN' => true));
        $overridables = array();
    } else {
        require_lang('permissions');
        $temp = do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('PERMISSIONS'), 'HELP' => do_lang_tempcode('PINTERACE_HELP'), 'SECTION_HIDDEN' => true));
        $overridables = is_array($_overridables[0]) ? call_user_func_array($_overridables[0][0], $_overridables[0][1]) : eval($_overridables[0]);
    }
    $out->attach($temp);
    // Find out inherited permissions
    $default_access = array();
    $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true);
    foreach (array_keys($access) as $id) {
        if (!array_key_exists($id, $groups) && array_key_exists($id, $all_groups)) {
            $groups[$id] = $all_groups[$id];
        }
    }
    foreach ($groups as $id => $group_name) {
        $default_access[$id] = array();
        if (!in_array($id, $admin_groups)) {
            foreach ($overridables as $override => $cat_support) {
                if (is_array($cat_support)) {
                    $cat_support = $cat_support[0];
                }
                $default_access[$id][$override] = array();
                if ($cat_support == 0) {
                    continue;
                }
                $default_access[$id][$override] = has_specific_permission_group($id, $override, $page) ? '1' : '0';
            }
        }
    }
    // Render actual permissions matrix
    $out->attach(get_permissions_matrix($server_id, $access, $overridables, $specific_permissions, $default_access, false, $pinterface_view));
    return $out;
}
Example #2
0
/**
 * AJAX script for finding out privileges for the queried resource.
 */
function find_permissions_script()
{
    header("Cache-Control: no-cache, must-revalidate");
    // HTTP/1.1
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    // Date in the past
    header('Content-Type: text/plain');
    require_code('zones2');
    require_code('permissions2');
    $serverid = get_param('serverid');
    $x = get_param('x');
    $matches = array();
    preg_match('#^access_(\\d+)_sp_(.+)$#', $x, $matches);
    $group_id = intval($matches[1]);
    $sp = $matches[2];
    require_all_lang();
    echo do_lang('PT_' . $sp) . '=';
    if ($serverid == '_root') {
        echo has_specific_permission_group($group_id, $sp) ? do_lang('YES') : do_lang('NO');
    } else {
        preg_match('#^([^:]*):([^:]*)(:|$)#', $serverid, $matches);
        $zone = $matches[1];
        $page = $matches[2];
        $_pagelinks = extract_module_functions_page($zone, $page, array('get_page_links'), array(NULL, false, NULL, true));
        $bits = is_null($_pagelinks[0]) ? array('!', '') : (is_array($_pagelinks[0]) ? call_user_func_array($_pagelinks[0][0], $_pagelinks[0][1]) : eval($_pagelinks[0]));
        // If $_pagelinks[0] is NULL then it's an error: extract_page_link_permissions is always there when there are cat permissions
        $module = $bits[1];
        echo has_specific_permission_group($group_id, $sp, $module) ? do_lang('YES') : do_lang('NO');
    }
}