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
 /**
  * The UI to for the permissions-tree-editor (advanced substitute for the combination of the page permissions screen and various other structure/content-attached screens).
  *
  * @return tempcode		The UI
  */
 function tree_editor()
 {
     $title = get_page_title('PERMISSIONS_TREE');
     if (!has_js()) {
         // Send them to the page permissions screen
         $url = build_url(array('page' => '_SELF', 'type' => 'page'), '_SELF');
         require_code('site2');
         assign_refresh($url, 5.0);
         return do_template('REDIRECT_SCREEN', array('_GUID' => 'a376167acf6d0f5ac80ca743a2c728d9', 'URL' => $url, 'TITLE' => $title, 'TEXT' => do_lang_tempcode('NO_JS_ADVANCED_SCREEN_PERMISSIONS')));
     }
     require_javascript('javascript_ajax');
     require_javascript('javascript_tree_list');
     require_javascript('javascript_more');
     require_code('form_templates');
     $groups = new ocp_tempcode();
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
     $initial_group = NULL;
     foreach ($all_groups as $id => $group_name) {
         if (is_null($initial_group)) {
             $initial_group = $group_name;
         }
         if (!in_array($id, $admin_groups)) {
             $groups->attach(form_input_list_entry(strval($id), $id == $GLOBALS['FORUM_DRIVER']->get_guest_group(), $group_name));
         }
     }
     $css_path = get_custom_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_cached/' . user_lang() . '/global.css';
     $color = 'FF00FF';
     if (file_exists($css_path)) {
         $tmp_file = file_get_contents($css_path);
         $matches = array();
         if (preg_match('#\\nth[\\s,][^\\}]*\\sbackground-color:\\s*\\#([\\dA-Fa-f]*);#sU', $tmp_file, $matches) != 0) {
             $color = $matches[1];
         }
     }
     // Standard editing matrix
     // NB: For permissions tree editor, default access is shown as -1 in editor for clarity (because the parent permissions are easily findable which implies the default access would mean something else which would confuse [+ this would be hard to do due to the dynamicness of the interface])
     require_code('permissions2');
     $editor = get_permissions_matrix('', array(), array(), array(), array(), true);
     return do_template('PERMISSIONS_TREE_EDITOR_SCREEN', array('_GUID' => '08bb679a7cfab45c0c29b5393666dd57', 'USERGROUPS' => $all_groups, 'TITLE' => $title, 'INITIAL_GROUP' => $initial_group, 'COLOR' => $color, 'GROUPS' => $groups, 'EDITOR' => $editor));
 }