function get_capability_enum($p_caption, $p_threshold, $p_enum, $p_all_projects_only = false)
{
    global $t_user, $t_project_id, $t_show_submit, $t_access_levels, $t_colour_project, $t_colour_global;
    $t_file = config_get_global($p_threshold);
    $t_global = config_get($p_threshold, null, null, ALL_PROJECTS);
    $t_project = config_get($p_threshold);
    $t_can_change = access_has_project_level(config_get_access($p_threshold), $t_project_id, $t_user) && (ALL_PROJECTS == $t_project_id || !$p_all_projects_only);
    $t_colour = '';
    if ($t_global != $t_file) {
        $t_colour = ' bgcolor="' . $t_colour_global . '" ';
        # all projects override
        if ($t_can_change) {
            set_overrides($p_threshold);
        }
    }
    if ($t_project != $t_global) {
        $t_colour = ' bgcolor="' . $t_colour_project . '" ';
        # project overrides
        if ($t_can_change) {
            set_overrides($p_threshold);
        }
    }
    echo '<tr ' . helper_alternate_class() . '><td>' . string_display($p_caption) . '</td>';
    if ($t_can_change) {
        echo '<td class="left" colspan="3"' . $t_colour . '><select name="flag_' . $p_threshold . '">';
        print_enum_string_option_list($p_enum, config_get($p_threshold));
        echo '</select></td><td colspan="' . (count($t_access_levels) - 3) . '"></td>';
        $t_show_submit = true;
    } else {
        $t_value = MantisEnum::getLabel(lang_get($p_enum . '_enum_string'), config_get($p_threshold)) . '&nbsp;';
        echo '<td class="left" colspan="3"' . $t_colour . '>' . $t_value . '</td><td colspan="' . (count($t_access_levels) - 3) . '"></td>';
    }
    if ($t_can_change) {
        echo '<td><select name="access_' . $p_threshold . '">';
        print_enum_string_option_list('access_levels', config_get_access($p_threshold));
        echo '</select> </td>';
    } else {
        echo '<td>' . MantisEnum::getLabel(lang_get('access_levels_enum_string'), config_get_access($p_threshold)) . '&nbsp;</td>';
    }
    echo '</tr>' . "\n";
}
/**
 * access row
 * @return void
 */
function access_row()
{
    global $g_access, $g_can_change_flags;
    $t_enum_status = MantisEnum::getAssocArrayIndexedByValues(config_get('status_enum_string'));
    $t_file_new = config_get_global('report_bug_threshold');
    $t_global_new = config_get('report_bug_threshold', null, ALL_USERS, ALL_PROJECTS);
    $t_project_new = config_get('report_bug_threshold');
    $t_file_set = config_get_global('set_status_threshold');
    $t_global_set = config_get('set_status_threshold', null, ALL_USERS, ALL_PROJECTS);
    $t_project_set = config_get('set_status_threshold');
    $t_submit_status = config_get('bug_submit_status');
    # Print the table rows
    foreach ($t_enum_status as $t_status => $t_status_label) {
        echo "\t\t" . '<tr><td class="width30">' . string_no_break(MantisEnum::getLabel(lang_get('status_enum_string'), $t_status)) . '</td>' . "\n";
        if ($t_status == $t_submit_status) {
            # 'NEW' status
            $t_level_project = $t_project_new;
            $t_can_change = $g_access >= config_get_access('report_bug_threshold');
            $t_color = set_color_override($t_file_new, $t_global_new, $t_project_new);
            set_overrides('report_bug_threshold', $t_can_change, $t_color);
        } else {
            # Other statuses
            # File level: fallback if set_status_threshold is not defined
            if (isset($t_file_set[$t_status])) {
                $t_level_file = $t_file_set[$t_status];
            } else {
                $t_level_file = config_get_global('update_bug_status_threshold');
            }
            $t_level_global = isset($t_global_set[$t_status]) ? $t_global_set[$t_status] : $t_level_file;
            $t_level_project = isset($t_project_set[$t_status]) ? $t_project_set[$t_status] : $t_level_global;
            $t_can_change = $g_access >= config_get_access('set_status_threshold');
            $t_color = set_color_override($t_level_file, $t_level_global, $t_level_project);
            set_overrides('set_status_threshold', $t_can_change, $t_color);
        }
        if ($t_can_change) {
            echo '<td class="center ' . $t_color . '"><select name="access_change_' . $t_status . '">' . "\n";
            print_enum_string_option_list('access_levels', $t_level_project);
            echo '</select> </td>' . "\n";
            $g_can_change_flags = true;
        } else {
            echo '<td class="center ' . $t_color . '">' . MantisEnum::getLabel(lang_get('access_levels_enum_string'), $t_level_project) . '</td>' . "\n";
        }
        echo '</tr>' . "\n";
    }
}
/**
 * Defines the cell's background color and sets the overrides
 * @param string  $p_threshold    Configuration option.
 * @param string  $p_file         System default value.
 * @param string  $p_global       All projects value.
 * @param string  $p_project      Current project value.
 * @param boolean $p_set_override If true, will define an override if needed.
 * @return string HTML tag attribute for background color override
 */
function set_color($p_threshold, $p_file, $p_global, $p_project, $p_set_override)
{
    global $g_color_project, $g_color_global, $g_project_id;
    $t_color = false;
    # all projects override
    if ($p_global != $p_file) {
        $t_color = $g_color_global;
        if ($p_set_override && ALL_PROJECTS == $g_project_id) {
            set_overrides($p_threshold);
        }
    }
    # project overrides
    if ($p_project != $p_global) {
        $t_color = $g_color_project;
        if ($p_set_override && ALL_PROJECTS != $g_project_id) {
            set_overrides($p_threshold);
        }
    }
    if (false === $t_color) {
        return '';
    }
    return ' bgcolor="' . $t_color . '" ';
}
function access_row()
{
    global $t_access, $t_can_change_flags, $t_colour_project, $t_colour_global;
    $t_enum_status = get_enum_to_array(config_get('status_enum_string'));
    $t_file_new = config_get_global('report_bug_threshold');
    $t_global_new = config_get('report_bug_threshold', null, null, ALL_PROJECTS);
    $t_project_new = config_get('report_bug_threshold');
    $t_file_set = config_get_global('set_status_threshold');
    foreach ($t_enum_status as $t_status => $t_status_label) {
        if (!isset($t_file_set[$t_status])) {
            $t_file_set[$t_status] = config_get_global('update_bug_status_threshold');
        }
    }
    $t_global_set = config_get('set_status_threshold', null, null, ALL_PROJECTS);
    foreach ($t_enum_status as $t_status => $t_status_label) {
        if (!isset($t_file_set[$t_status])) {
            $t_file_set[$t_status] = config_get('update_bug_status_threshold', null, null, ALL_PROJECTS);
        }
    }
    $t_project_set = config_get('set_status_threshold');
    foreach ($t_enum_status as $t_status => $t_status_label) {
        if (!isset($t_file_set[$t_status])) {
            $t_file_set[$t_status] = config_get('update_bug_status_threshold');
        }
    }
    foreach ($t_enum_status as $t_status => $t_status_label) {
        echo '<tr ' . helper_alternate_class() . '><td width="30%">' . string_no_break(get_enum_to_string(lang_get('status_enum_string'), $t_status)) . '</td>';
        if (NEW_ == $t_status) {
            $t_level = $t_project_new;
            $t_can_change = $t_access >= config_get_access('report_bug_threshold');
            $t_colour = '';
            if ($t_global_new != $t_file_new) {
                $t_colour = ' bgcolor="' . $t_colour_global . '" ';
                # all projects override
                if ($t_can_change) {
                    set_overrides('report_bug_threshold');
                }
            }
            if ($t_project_new != $t_global_new) {
                $t_colour = ' bgcolor="' . $t_colour_project . '" ';
                # project overrides
                if ($t_can_change) {
                    set_overrides('report_bug_threshold');
                }
            }
        } else {
            $t_level = isset($t_project_set[$t_status]) ? $t_project_set[$t_status] : false;
            $t_level_global = isset($t_global_set[$t_status]) ? $t_global_set[$t_status] : false;
            $t_level_file = isset($t_file_set[$t_status]) ? $t_file_set[$t_status] : false;
            $t_can_change = $t_access >= config_get_access('set_status_threshold');
            $t_colour = '';
            if ($t_level_global != $t_level_file) {
                $t_colour = ' bgcolor="' . $t_colour_global . '" ';
                # all projects override
                if ($t_can_change) {
                    set_overrides('set_status_threshold');
                }
            }
            if ($t_level != $t_level_global) {
                $t_colour = ' bgcolor="' . $t_colour_project . '" ';
                # project overrides
                if ($t_can_change) {
                    set_overrides('set_status_threshold');
                }
            }
        }
        if ($t_can_change) {
            echo '<td' . $t_colour . '><select name="access_change_' . $t_status . '">';
            print_enum_string_option_list('access_levels', $t_level);
            echo '</select> </td>';
            $t_can_change_flags = true;
        } else {
            echo '<td class="center"' . $t_colour . '>' . get_enum_to_string(config_get('access_levels_enum_string'), $t_level) . '</td>';
        }
        echo '</tr>' . "\n";
    }
}
/**
 * Defines the cell's background color and sets the overrides
 * @param string  $p_threshold    Configuration option.
 * @param string  $p_file         System default value.
 * @param string  $p_global       All projects value.
 * @param string  $p_project      Current project value.
 * @param boolean $p_set_override If true, will define an override if needed.
 * @return string HTML tag attribute for background color override
 */
function set_color($p_threshold, $p_file, $p_global, $p_project, $p_set_override)
{
    global $g_project_id;
    $t_color = '';
    # all projects override
    if ($p_global != $p_file) {
        $t_color = 'color-global';
        if ($p_set_override && ALL_PROJECTS == $g_project_id) {
            set_overrides($p_threshold);
        }
    }
    # project overrides
    if ($p_project != $p_global) {
        $t_color = 'color-project';
        if ($p_set_override && ALL_PROJECTS != $g_project_id) {
            set_overrides($p_threshold);
        }
    }
    return $t_color;
}